Re: Module/kthread/printk question/problem

From: Dmitry Antipov
Date: Thu Feb 02 2012 - 04:20:23 EST


On 02/02/2012 11:45 AM, Eric Dumazet wrote:

Remove the wait_for_completion(), this brings nothing at all, as you
already discovered.

I want to get the module 'locked' until all threads are completed.

Then you need cooperation from worker threads : they must wait for
kthread_should_stop(), or else your kthread_stop(arg) pass an already
freed "arg" memory block.

I designed the cooperation in another way: after each successful call
of X = kthread_run(...), I do get_task_struct(X), and the module exit
code is something like:

...
wait_for_completion(&done);
for (i = 0; i < nrthreads; i++) {
kthread_stop(threads[i]);
put_task_struct(threads[i]);
}
kfree(threads);
...

The crash is go away, so I believe this is reasonable. Anyway, it would
be nice to have a debug option to detect such a suspicious errors.

Thanks,
Dmitry
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/