workqueue.c subtle fix and core extraction
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 8 lines · Linux Kernel Mailing List
ChangeSet 1.1384, 2003/06/20 22:14:56-07:00, [email protected]
[PATCH]
workqueue.csubtle fix and core extractionFrom: Rusty Russell <[email protected]>
A barrier is needed on workqueue shutdown: there's a chance that the thead could see the
wq->threadset to NULL before the completion is initialized.
Look at the larger problem.
The completion initialization should be done before you call kernel_thread to start the worker.
Otherwise, there is a still the general problem: if any event occurs to cause worker_thread to exit its main loop, you hit an uninitialized completion.
Just initialize it before you start the kernel thread -- like all the other driver kernel thread code does -- and forget about barriers :) Needing a barrier here just signals you need further changes.
Quoted 2 lines
Also extracts functions which actually create and destroy workqueues, for use by hotplug CPU patch.
Please do this in separate patches next time. I'm looking into the above change, and including this second change just obfuscated matters and slowed down analysis of the first change.
Jeff
In message <[email protected]> you write:
Quoted 10 lines
Quoted 8 lines · Linux Kernel Mailing List
ChangeSet 1.1384, 2003/06/20 22:14:56-07:00, [email protected]
[PATCH]
workqueue.csubtle fix and core extractionFrom: Rusty Russell <[email protected]>
A barrier is needed on workqueue shutdown: there's a chance that the thead could see the
wq->threadset to NULL before the completion is initialized.
Quoted 8 lines
Look at the larger problem.
The completion initialization should be done before you call
kernel_threadto start the worker.Otherwise, there is a still the general problem: if any event occurs to cause
worker_threadto exit its main loop, you hit an uninitialized completion.
Agreed. While I don't believe that can ever happen, your suggested fix is *much* cleaner. Below.
Quoted 3 lines
Please do this in separate patches next time. I'm looking into the above change, and including this second change just obfuscated matters and slowed down analysis of the first change.
Guilty of laziness as changed. Follows on as a separate patch below.
Thanks!
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
Name: Workqueue Exit Completion Race Fix
Author: Rusty Russell
Status: Trivial
D: Initializing the exit-completion at exit time without a barrier leaves
D: a potential race: it is much cleaner to do it at thread creation time
D: when everything else is initialized (the workqueue can only be destroyed
D: once, so it is only used once).
D:
D: Initial barrier implementation rightly trashed by Jeff Garzik.
kernel/workqueue.c +2 -4
@@ -286,6 +286,7 @@ struct workqueue_struct *create_workqueuINIT_LIST_HEAD (&cwq->worklist);init_waitqueue_head (&cwq->more_work);init_waitqueue_head (&cwq->work_done); +init_completion (&cwq->exit);init_completion (&startup.done); startup.cwq = cwq;
@@ -321,10 +322,7 @@ void destroy_workqueue(struct workqueue_ cwq = wq->cpu_wq + cpu;if (!cwq->thread)continue ; -/* -* Initiate an exit and wait for it: -*/ -init_completion (&cwq->exit); +/* Tell thread to exit and and wait for it: */ cwq->thread =NULL ;wake_up (&cwq->more_work);
Name: workqueue.c Neatening
Author: Rusty Russell
Status: Tested on 2.5.70-bk16
Depends: Misc/workqueue-exit-race.patch.gz
D: Extracts functions which actually create and destroy workqueues,
D: for use by hotplug CPU patch.
kernel/workqueue.c +46 -34
114 lines not on this page · raw message