Kernel module/kthread question

Daniel Lezcano daniel.lezcano at linaro.org
Wed Feb 1 12:15:13 UTC 2012


On 02/01/2012 01:08 PM, Dmitry Antipov wrote:
> On 02/01/2012 03:49 PM, Daniel Lezcano wrote:
>
>> IMO, you have a race condition with nrunning. What guarantee do you
>> have atomic_dec_and_test is called after atomic_inc ?
>
> Nothing (but I believe ~1s is pretty enough for the kernel thread to get
> woken up). I also tried to to atomic_inc() at the beginning of test(),
> like:
>
> ...
> static int test(void *unused)
> {
> int i;
> ktime_t expires = ktime_set(0, NSEC_PER_MSEC);
>
> atomic_inc(&nrunning);
>
> for (i = 0; !kthread_should_stop() && i < loopcount; i++)
> schedule_hrtimeout_range(&expires, 50000, HRTIMER_MODE_REL);
>
> if (atomic_dec_and_test(&nrunning))
> complete(&done);
> return 0;
> }
> ...
>
> Results are the same.

Yes, but the problem is the same also. Did you try by removing 
atomic_inc and set nrunnings to nrkthread ?



-- 
  <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog




More information about the linaro-dev mailing list