Re: [PATCH v3 4/4] selftests: kmod: Add tests for merging same-name module load requests
From: Petr Mladek
Date: Mon Oct 17 2022 - 09:51:45 EST
On Sun 2022-10-16 14:30:31, Petr Pavlu wrote:
> Add two tests to check that loading the same module multiple times in
> parallel results only in one real attempt to initialize it.
> Synchronization of the loads is done by waiting 1000 ms in the init
I do not have a good experience with this kind of synchronization.
It usually is not reliable. The test might be very slow especially when
false positives are solved by prolonging the delay.
Alternative solution would be to have two modules:
1st module would provide a counter, for example:
int modB_load_cnt;
module_param(modB_load_cnt, int, 0444);
EXPORT_SYMBOL(modB_load_cnt);
EXPORT_SYMBOL() should allow to directly increment the counter
from the 2nd module.
module_param() should make the value readable via
/sys/module/modA/parameters/modB_load_cnt. It can be
checked by kmod_sh.
> function of a sample module kmod_test_0014. The tests measure time
> needed to perform all inserts to verify that the loads get merged by the
> module loader and are not serialized.
>
> * Case 0014 checks a situation when the load is successful. It should
> result in one insert returning 0 and remaining inserts returning
> EEXIST.
> * Case 0015 checks a situation when the load is failing because the
> module init function returns ENODEV. It should result in one insert
> returning this error code and remaining inserts returning EBUSY.
>
> The tests use a simple init_module program to load kmod_test_0014.ko. It
> enables to obtain directly a return code from the finit_module syscall.
The tested scenarios look good.
Best Regards,
Petr