linux/include
Oleg Nesterov b89deed32c implement flush_work()
A basic problem with flush_scheduled_work() is that it blocks behind _all_
presently-queued works, rather than just the work whcih the caller wants to
flush.  If the caller holds some lock, and if one of the queued work happens
to want that lock as well then accidental deadlocks can occur.

One example of this is the phy layer: it wants to flush work while holding
rtnl_lock().  But if a linkwatch event happens to be queued, the phy code will
deadlock because the linkwatch callback function takes rtnl_lock.

So we implement a new function which will flush a *single* work - just the one
which the caller wants to free up.  Thus we avoid the accidental deadlocks
which can arise from unrelated subsystems' callbacks taking shared locks.

flush_work() non-blockingly dequeues the work_struct which we want to kill,
then it waits for its handler to complete on all CPUs.

Add ->current_work to the "struct cpu_workqueue_struct", it points to
currently running "struct work_struct". When flush_work(work) detects
->current_work == work, it inserts a barrier at the _head_ of ->worklist
(and thus right _after_ that work) and waits for completition. This means
that the next work fired on that CPU will be this barrier, or another
barrier queued by concurrent flush_work(), so the caller of flush_work()
will be woken before any "regular" work has a chance to run.

When wait_on_work() unlocks workqueue_mutex (or whatever we choose to protect
against CPU hotplug), CPU may go away. But in that case take_over_work() will
move a barrier we queued to another CPU, it will be fired sometime, and
wait_on_work() will be woken.

Actually, we are doing cleanup_workqueue_thread()->kthread_stop() before
take_over_work(), so cwq->thread should complete its ->worklist (and thus
the barrier), because currently we don't check kthread_should_stop() in
run_workqueue(). But even if we did, everything should be ok.

[akpm@osdl.org: cleanup]
[akpm@osdl.org: add flush_work_keventd() wrapper]
Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-09 12:30:50 -07:00
..
acpi PNPACPI sets pnpdev->dev.archdata 2007-05-08 11:15:08 -07:00
asm-alpha Remove hardcoding of hard_smp_processor_id on UP systems 2007-05-09 12:30:48 -07:00
asm-arm Use common cpu_is_xxx() macros on AT91 and AVR32 2007-05-09 12:30:50 -07:00
asm-arm26 Remove tas() 2007-05-08 11:15:20 -07:00
asm-avr32 Use common cpu_is_xxx() macros on AT91 and AVR32 2007-05-09 12:30:50 -07:00
asm-blackfin Remove tas() 2007-05-08 11:15:20 -07:00
asm-cris move die notifier handling to common code 2007-05-08 11:15:04 -07:00
asm-frv FRV: Replace pgd management via slabs through quicklists 2007-05-09 12:30:46 -07:00
asm-generic local_t: architecture independent extension 2007-05-08 11:15:20 -07:00
asm-h8300 Remove tas() 2007-05-08 11:15:20 -07:00
asm-i386 Use the APIC to determine the hardware processor id - i386 2007-05-09 12:30:48 -07:00
asm-ia64 Always ask the hardware to obtain hardware processor id - ia64 2007-05-09 12:30:49 -07:00
asm-m32r Remove hardcoding of hard_smp_processor_id on UP systems 2007-05-09 12:30:48 -07:00
asm-m68k m68k: <asm/scatterlist.h> needs <linux/types.h> 2007-05-08 20:41:14 -07:00
asm-m68knommu Remove tas() 2007-05-08 11:15:20 -07:00
asm-mips Remove tas() 2007-05-08 11:15:20 -07:00
asm-parisc local_t: parisc cleanup 2007-05-08 11:15:20 -07:00
asm-powerpc Remove hardcoding of hard_smp_processor_id on UP systems 2007-05-09 12:30:48 -07:00
asm-ppc Remove tas() 2007-05-08 11:15:20 -07:00
asm-s390 Remove hardcoding of hard_smp_processor_id on UP systems 2007-05-09 12:30:48 -07:00
asm-sh Remove tas() 2007-05-08 11:15:20 -07:00
asm-sh64 Remove tas() 2007-05-08 11:15:20 -07:00
asm-sparc Remove hardcoding of hard_smp_processor_id on UP systems 2007-05-09 12:30:48 -07:00
asm-sparc64 Remove hardcoding of hard_smp_processor_id on UP systems 2007-05-09 12:30:48 -07:00
asm-um Remove hardcoding of hard_smp_processor_id on UP systems 2007-05-09 12:30:48 -07:00
asm-v850 Remove tas() 2007-05-08 11:15:20 -07:00
asm-x86_64 Use the APIC to determine the hardware processor id - x86_64 2007-05-09 12:30:48 -07:00
asm-xtensa Remove tas() 2007-05-08 11:15:20 -07:00
crypto [CRYPTO] cryptd: Add software async crypto daemon 2007-05-02 14:38:32 +10:00
keys [AF_RXRPC]: Provide secure RxRPC sockets for use by userspace and kernel both 2007-04-26 15:48:28 -07:00
linux implement flush_work() 2007-05-09 12:30:50 -07:00
math-emu Delete unused header file math-emu/extended.h 2007-05-08 11:15:05 -07:00
media i2c: Cleanup the includes of <linux/i2c.h> 2007-05-01 23:26:29 +02:00
mtd UBI: Unsorted Block Images 2007-04-27 14:23:33 +03:00
net cleanup compat ioctl handling 2007-05-08 11:15:09 -07:00
pcmcia add new_id to PCMCIA drivers 2007-05-07 12:12:50 -07:00
rdma Merge branch 'for-linus' of master.kernel.org:/pub/scm/linux/kernel/git/roland/infiniband 2007-05-07 12:18:21 -07:00
rxrpc [AF_RXRPC]: Delete the old RxRPC code. 2007-04-26 15:55:48 -07:00
scsi [SCSI] sas_scsi_host: Convert to use the kthread API 2007-05-06 09:33:17 -05:00
sound [ALSA] version 1.0.14rc3 2007-03-14 08:25:52 +01:00
video atyfb: halve XCLK with Mobility and 32bit memory 2007-05-08 11:15:32 -07:00
Kbuild