mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Stopping Kernel Threads at module unload time
@ 2005-11-09 15:49 Aritz Bastida
  2005-11-09 16:16 ` linux-os (Dick Johnson)
  0 siblings, 1 reply; 10+ messages in thread
From: Aritz Bastida @ 2005-11-09 15:49 UTC (permalink / raw)
  To: linux-kernel

Hello

I've got some questions about kernel threads.I am writing a module
which spawns some kernel threads, which would be removed when the
module unloads. For that purpose i call kthread_stop() at module
unload time. When issuing rmmod on the module, it deadlocks at that
point (in the call to kthread_stop), and never returns.

In the thread main function the code was something like this (it's of
course simplified).

thread_main()
{
     while( ! kthread_should_stop())
     {
           .............
           wait_event_interruptible(stop_wq, kthread_should_stop() );
     }

     return 0;
}

So if kthread_stop() first sets the thread "closing flag", and then
calls wake_up_process(), the thread should wake up, see he should
stop, and
end the loop. That doesnt actually never happen.

I have also tried what it is done in kernel/sched.c to finish:

	/* wait for kthread_stop */
	set_current_state(TASK_INTERRUPTIBLE);
	while (!kthread_should_stop()) {	
		schedule();
		set_current_state(TASK_INTERRUPTIBLE);
	}
	__set_current_state(TASK_RUNNING);
                return 0;

I have ensured it actually arrives to that point by using printks, but
when the thread goes to sleep, it does never wake up again, so the
call to kthread_stop() lasts forever.

I dont know why this happens. Is the module cleanup code in the
context of a user process just like system calls? Can that code sleep?
If it can't sleep then the answer would be quite easy: kthread_stop()
wakes up the processes and then waits for the threads to finish (on
call wait_for_completion), but doesnt actually let them execute,
because it cannot sleep, so it deadlocks.

So I would be grateful if anyone can help me in this matter.
Regards

Aritz

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2005-11-09 18:10 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-09 15:49 Stopping Kernel Threads at module unload time Aritz Bastida
2005-11-09 16:16 ` linux-os (Dick Johnson)
2005-11-09 16:56   ` Aritz Bastida
2005-11-09 17:05     ` linux-os (Dick Johnson)
2005-11-09 17:24       ` Aritz Bastida
2005-11-09 18:09         ` linux-os (Dick Johnson)
2005-11-09 17:27     ` Arnd Bergmann
2005-11-09 17:49       ` Aritz Bastida
2005-11-09 17:54         ` Aritz Bastida
2005-11-09 18:10         ` linux-os (Dick Johnson)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®