blob: ad9656886daa4edae2b4eca58dcf4e22eecc5a99 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/kernel/workqueue.c
3 *
4 * Generic mechanism for defining kernel helper threads for running
5 * arbitrary tasks in process context.
6 *
7 * Started by Ingo Molnar, Copyright (C) 2002
8 *
9 * Derived from the taskqueue/keventd code by:
10 *
11 * David Woodhouse <dwmw2@infradead.org>
12 * Andrew Morton <andrewm@uow.edu.au>
13 * Kai Petzke <wpp@marie.physik.tu-berlin.de>
14 * Theodore Ts'o <tytso@mit.edu>
Christoph Lameter89ada672005-10-30 15:01:59 -080015 *
16 * Made to use alloc_percpu by Christoph Lameter <clameter@sgi.com>.
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
18
19#include <linux/module.h>
20#include <linux/kernel.h>
21#include <linux/sched.h>
22#include <linux/init.h>
23#include <linux/signal.h>
24#include <linux/completion.h>
25#include <linux/workqueue.h>
26#include <linux/slab.h>
27#include <linux/cpu.h>
28#include <linux/notifier.h>
29#include <linux/kthread.h>
James Bottomley1fa44ec2006-02-23 12:43:43 -060030#include <linux/hardirq.h>
Christoph Lameter46934022006-10-11 01:21:26 -070031#include <linux/mempolicy.h>
Rafael J. Wysocki341a5952006-12-06 20:34:49 -080032#include <linux/freezer.h>
Peter Zijlstrad5abe662006-12-06 20:37:26 -080033#include <linux/kallsyms.h>
34#include <linux/debug_locks.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36/*
Nathan Lynchf756d5e2006-01-08 01:05:12 -080037 * The per-CPU workqueue (if single thread, we always use the first
38 * possible cpu).
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 */
40struct cpu_workqueue_struct {
41
42 spinlock_t lock;
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 struct list_head worklist;
45 wait_queue_head_t more_work;
Oleg Nesterov3af244332007-05-09 02:34:09 -070046 struct work_struct *current_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48 struct workqueue_struct *wq;
Ingo Molnar36c8b582006-07-03 00:25:41 -070049 struct task_struct *thread;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51 int run_depth; /* Detect run_workqueue() recursion depth */
52} ____cacheline_aligned;
53
54/*
55 * The externally visible workqueue abstraction is an array of
56 * per-CPU workqueues:
57 */
58struct workqueue_struct {
Christoph Lameter89ada672005-10-30 15:01:59 -080059 struct cpu_workqueue_struct *cpu_wq;
Oleg Nesterovcce1a162007-05-09 02:34:13 -070060 struct list_head list;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 const char *name;
Oleg Nesterovcce1a162007-05-09 02:34:13 -070062 int singlethread;
Oleg Nesterov319c2a92007-05-09 02:34:06 -070063 int freezeable; /* Freeze threads during suspend */
Linus Torvalds1da177e2005-04-16 15:20:36 -070064};
65
66/* All the per-cpu workqueues on the system, for hotplug cpu to add/remove
67 threads to each one as cpus come/go. */
Andrew Morton9b41ea72006-08-13 23:24:26 -070068static DEFINE_MUTEX(workqueue_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069static LIST_HEAD(workqueues);
70
Oleg Nesterov3af244332007-05-09 02:34:09 -070071static int singlethread_cpu __read_mostly;
Oleg Nesterovb1f4ec12007-05-09 02:34:12 -070072static cpumask_t cpu_singlethread_map __read_mostly;
Oleg Nesterov14441962007-05-23 13:57:57 -070073/*
74 * _cpu_down() first removes CPU from cpu_online_map, then CPU_DEAD
75 * flushes cwq->worklist. This means that flush_workqueue/wait_on_work
76 * which comes in between can't use for_each_online_cpu(). We could
77 * use cpu_possible_map, the cpumask below is more a documentation
78 * than optimization.
79 */
Oleg Nesterov3af244332007-05-09 02:34:09 -070080static cpumask_t cpu_populated_map __read_mostly;
Nathan Lynchf756d5e2006-01-08 01:05:12 -080081
Linus Torvalds1da177e2005-04-16 15:20:36 -070082/* If it's single threaded, it isn't in the list of workqueues. */
83static inline int is_single_threaded(struct workqueue_struct *wq)
84{
Oleg Nesterovcce1a162007-05-09 02:34:13 -070085 return wq->singlethread;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086}
87
Oleg Nesterovb1f4ec12007-05-09 02:34:12 -070088static const cpumask_t *wq_cpu_map(struct workqueue_struct *wq)
89{
90 return is_single_threaded(wq)
91 ? &cpu_singlethread_map : &cpu_populated_map;
92}
93
Oleg Nesterova848e3b2007-05-09 02:34:17 -070094static
95struct cpu_workqueue_struct *wq_per_cpu(struct workqueue_struct *wq, int cpu)
96{
97 if (unlikely(is_single_threaded(wq)))
98 cpu = singlethread_cpu;
99 return per_cpu_ptr(wq->cpu_wq, cpu);
100}
101
David Howells4594bf12006-12-07 11:33:26 +0000102/*
103 * Set the workqueue on which a work item is to be run
104 * - Must *only* be called if the pending flag is set
105 */
Oleg Nesteroved7c0fe2007-05-09 02:34:16 -0700106static inline void set_wq_data(struct work_struct *work,
107 struct cpu_workqueue_struct *cwq)
David Howells365970a2006-11-22 14:54:49 +0000108{
David Howells4594bf12006-12-07 11:33:26 +0000109 unsigned long new;
David Howells365970a2006-11-22 14:54:49 +0000110
David Howells4594bf12006-12-07 11:33:26 +0000111 BUG_ON(!work_pending(work));
112
Oleg Nesteroved7c0fe2007-05-09 02:34:16 -0700113 new = (unsigned long) cwq | (1UL << WORK_STRUCT_PENDING);
Linus Torvaldsa08727b2006-12-16 09:53:50 -0800114 new |= WORK_STRUCT_FLAG_MASK & *work_data_bits(work);
115 atomic_long_set(&work->data, new);
David Howells365970a2006-11-22 14:54:49 +0000116}
117
Oleg Nesteroved7c0fe2007-05-09 02:34:16 -0700118static inline
119struct cpu_workqueue_struct *get_wq_data(struct work_struct *work)
David Howells365970a2006-11-22 14:54:49 +0000120{
Linus Torvaldsa08727b2006-12-16 09:53:50 -0800121 return (void *) (atomic_long_read(&work->data) & WORK_STRUCT_WQ_DATA_MASK);
David Howells365970a2006-11-22 14:54:49 +0000122}
123
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700124static void insert_work(struct cpu_workqueue_struct *cwq,
125 struct work_struct *work, int tail)
126{
127 set_wq_data(work, cwq);
Oleg Nesterov6e84d642007-05-09 02:34:46 -0700128 /*
129 * Ensure that we get the right work->data if we see the
130 * result of list_add() below, see try_to_grab_pending().
131 */
132 smp_wmb();
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700133 if (tail)
134 list_add_tail(&work->entry, &cwq->worklist);
135 else
136 list_add(&work->entry, &cwq->worklist);
137 wake_up(&cwq->more_work);
138}
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140/* Preempt must be disabled. */
141static void __queue_work(struct cpu_workqueue_struct *cwq,
142 struct work_struct *work)
143{
144 unsigned long flags;
145
146 spin_lock_irqsave(&cwq->lock, flags);
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700147 insert_work(cwq, work, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 spin_unlock_irqrestore(&cwq->lock, flags);
149}
150
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700151/**
152 * queue_work - queue work on a workqueue
153 * @wq: workqueue to use
154 * @work: work to queue
155 *
Alan Stern057647f2006-10-28 10:38:58 -0700156 * Returns 0 if @work was already on a queue, non-zero otherwise.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 *
158 * We queue the work to the CPU it was submitted, but there is no
159 * guarantee that it will be processed by that CPU.
160 */
161int fastcall queue_work(struct workqueue_struct *wq, struct work_struct *work)
162{
Oleg Nesterova848e3b2007-05-09 02:34:17 -0700163 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
Linus Torvaldsa08727b2006-12-16 09:53:50 -0800165 if (!test_and_set_bit(WORK_STRUCT_PENDING, work_data_bits(work))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 BUG_ON(!list_empty(&work->entry));
Oleg Nesterova848e3b2007-05-09 02:34:17 -0700167 __queue_work(wq_per_cpu(wq, get_cpu()), work);
168 put_cpu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 ret = 1;
170 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 return ret;
172}
Dave Jonesae90dd52006-06-30 01:40:45 -0400173EXPORT_SYMBOL_GPL(queue_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Ingo Molnar82f67cd2007-02-16 01:28:13 -0800175void delayed_work_timer_fn(unsigned long __data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176{
David Howells52bad642006-11-22 14:54:01 +0000177 struct delayed_work *dwork = (struct delayed_work *)__data;
Oleg Nesteroved7c0fe2007-05-09 02:34:16 -0700178 struct cpu_workqueue_struct *cwq = get_wq_data(&dwork->work);
179 struct workqueue_struct *wq = cwq->wq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Oleg Nesterova848e3b2007-05-09 02:34:17 -0700181 __queue_work(wq_per_cpu(wq, smp_processor_id()), &dwork->work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182}
183
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700184/**
185 * queue_delayed_work - queue work on a workqueue after delay
186 * @wq: workqueue to use
Randy Dunlapaf9997e2006-12-22 01:06:52 -0800187 * @dwork: delayable work to queue
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700188 * @delay: number of jiffies to wait before queueing
189 *
Alan Stern057647f2006-10-28 10:38:58 -0700190 * Returns 0 if @work was already on a queue, non-zero otherwise.
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700191 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192int fastcall queue_delayed_work(struct workqueue_struct *wq,
David Howells52bad642006-11-22 14:54:01 +0000193 struct delayed_work *dwork, unsigned long delay)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194{
Oleg Nesterov63bc0362007-05-09 02:34:16 -0700195 timer_stats_timer_set_start_info(&dwork->timer);
David Howells52bad642006-11-22 14:54:01 +0000196 if (delay == 0)
Oleg Nesterov63bc0362007-05-09 02:34:16 -0700197 return queue_work(wq, &dwork->work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
Oleg Nesterov63bc0362007-05-09 02:34:16 -0700199 return queue_delayed_work_on(-1, wq, dwork, delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200}
Dave Jonesae90dd52006-06-30 01:40:45 -0400201EXPORT_SYMBOL_GPL(queue_delayed_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700203/**
204 * queue_delayed_work_on - queue work on specific CPU after delay
205 * @cpu: CPU number to execute work on
206 * @wq: workqueue to use
Randy Dunlapaf9997e2006-12-22 01:06:52 -0800207 * @dwork: work to queue
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700208 * @delay: number of jiffies to wait before queueing
209 *
Alan Stern057647f2006-10-28 10:38:58 -0700210 * Returns 0 if @work was already on a queue, non-zero otherwise.
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700211 */
Venkatesh Pallipadi7a6bc1c2006-06-28 13:50:33 -0700212int queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
David Howells52bad642006-11-22 14:54:01 +0000213 struct delayed_work *dwork, unsigned long delay)
Venkatesh Pallipadi7a6bc1c2006-06-28 13:50:33 -0700214{
215 int ret = 0;
David Howells52bad642006-11-22 14:54:01 +0000216 struct timer_list *timer = &dwork->timer;
217 struct work_struct *work = &dwork->work;
Venkatesh Pallipadi7a6bc1c2006-06-28 13:50:33 -0700218
Linus Torvaldsa08727b2006-12-16 09:53:50 -0800219 if (!test_and_set_bit(WORK_STRUCT_PENDING, work_data_bits(work))) {
Venkatesh Pallipadi7a6bc1c2006-06-28 13:50:33 -0700220 BUG_ON(timer_pending(timer));
221 BUG_ON(!list_empty(&work->entry));
222
Oleg Nesteroved7c0fe2007-05-09 02:34:16 -0700223 /* This stores cwq for the moment, for the timer_fn */
Oleg Nesterova848e3b2007-05-09 02:34:17 -0700224 set_wq_data(work, wq_per_cpu(wq, raw_smp_processor_id()));
Venkatesh Pallipadi7a6bc1c2006-06-28 13:50:33 -0700225 timer->expires = jiffies + delay;
David Howells52bad642006-11-22 14:54:01 +0000226 timer->data = (unsigned long)dwork;
Venkatesh Pallipadi7a6bc1c2006-06-28 13:50:33 -0700227 timer->function = delayed_work_timer_fn;
Oleg Nesterov63bc0362007-05-09 02:34:16 -0700228
229 if (unlikely(cpu >= 0))
230 add_timer_on(timer, cpu);
231 else
232 add_timer(timer);
Venkatesh Pallipadi7a6bc1c2006-06-28 13:50:33 -0700233 ret = 1;
234 }
235 return ret;
236}
Dave Jonesae90dd52006-06-30 01:40:45 -0400237EXPORT_SYMBOL_GPL(queue_delayed_work_on);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Arjan van de Ven858119e2006-01-14 13:20:43 -0800239static void run_workqueue(struct cpu_workqueue_struct *cwq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240{
Oleg Nesterovf293ea92007-05-09 02:34:10 -0700241 spin_lock_irq(&cwq->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 cwq->run_depth++;
243 if (cwq->run_depth > 3) {
244 /* morton gets to eat his hat */
245 printk("%s: recursion depth exceeded: %d\n",
246 __FUNCTION__, cwq->run_depth);
247 dump_stack();
248 }
249 while (!list_empty(&cwq->worklist)) {
250 struct work_struct *work = list_entry(cwq->worklist.next,
251 struct work_struct, entry);
David Howells6bb49e52006-11-22 14:54:45 +0000252 work_func_t f = work->func;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700254 cwq->current_work = work;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 list_del_init(cwq->worklist.next);
Oleg Nesterovf293ea92007-05-09 02:34:10 -0700256 spin_unlock_irq(&cwq->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
David Howells365970a2006-11-22 14:54:49 +0000258 BUG_ON(get_wq_data(work) != cwq);
Oleg Nesterov23b2e592007-05-09 02:34:19 -0700259 work_clear_pending(work);
David Howells65f27f32006-11-22 14:55:48 +0000260 f(work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
Peter Zijlstrad5abe662006-12-06 20:37:26 -0800262 if (unlikely(in_atomic() || lockdep_depth(current) > 0)) {
263 printk(KERN_ERR "BUG: workqueue leaked lock or atomic: "
264 "%s/0x%08x/%d\n",
265 current->comm, preempt_count(),
266 current->pid);
267 printk(KERN_ERR " last function: ");
268 print_symbol("%s\n", (unsigned long)f);
269 debug_show_held_locks(current);
270 dump_stack();
271 }
272
Oleg Nesterovf293ea92007-05-09 02:34:10 -0700273 spin_lock_irq(&cwq->lock);
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700274 cwq->current_work = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 }
276 cwq->run_depth--;
Oleg Nesterovf293ea92007-05-09 02:34:10 -0700277 spin_unlock_irq(&cwq->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278}
279
280static int worker_thread(void *__cwq)
281{
282 struct cpu_workqueue_struct *cwq = __cwq;
Oleg Nesterov3af244332007-05-09 02:34:09 -0700283 DEFINE_WAIT(wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
Oleg Nesterov319c2a92007-05-09 02:34:06 -0700285 if (!cwq->wq->freezeable)
Rafael J. Wysocki341a5952006-12-06 20:34:49 -0800286 current->flags |= PF_NOFREEZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
288 set_user_nice(current, -5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
Oleg Nesterov3af244332007-05-09 02:34:09 -0700290 for (;;) {
Oleg Nesterov3af244332007-05-09 02:34:09 -0700291 prepare_to_wait(&cwq->more_work, &wait, TASK_INTERRUPTIBLE);
Oleg Nesterov14441962007-05-23 13:57:57 -0700292 if (!freezing(current) &&
293 !kthread_should_stop() &&
294 list_empty(&cwq->worklist))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 schedule();
Oleg Nesterov3af244332007-05-09 02:34:09 -0700296 finish_wait(&cwq->more_work, &wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
Oleg Nesterov85f41862007-05-09 02:34:20 -0700298 try_to_freeze();
299
Oleg Nesterov14441962007-05-23 13:57:57 -0700300 if (kthread_should_stop())
Oleg Nesterov3af244332007-05-09 02:34:09 -0700301 break;
302
303 run_workqueue(cwq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 }
Oleg Nesterov3af244332007-05-09 02:34:09 -0700305
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 return 0;
307}
308
Oleg Nesterovfc2e4d72007-05-09 02:33:51 -0700309struct wq_barrier {
310 struct work_struct work;
311 struct completion done;
312};
313
314static void wq_barrier_func(struct work_struct *work)
315{
316 struct wq_barrier *barr = container_of(work, struct wq_barrier, work);
317 complete(&barr->done);
318}
319
Oleg Nesterov83c22522007-05-09 02:33:54 -0700320static void insert_wq_barrier(struct cpu_workqueue_struct *cwq,
321 struct wq_barrier *barr, int tail)
Oleg Nesterovfc2e4d72007-05-09 02:33:51 -0700322{
323 INIT_WORK(&barr->work, wq_barrier_func);
324 __set_bit(WORK_STRUCT_PENDING, work_data_bits(&barr->work));
325
326 init_completion(&barr->done);
Oleg Nesterov83c22522007-05-09 02:33:54 -0700327
328 insert_work(cwq, &barr->work, tail);
Oleg Nesterovfc2e4d72007-05-09 02:33:51 -0700329}
330
Oleg Nesterov14441962007-05-23 13:57:57 -0700331static int flush_cpu_workqueue(struct cpu_workqueue_struct *cwq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332{
Oleg Nesterov14441962007-05-23 13:57:57 -0700333 int active;
334
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 if (cwq->thread == current) {
336 /*
337 * Probably keventd trying to flush its own queue. So simply run
338 * it by hand rather than deadlocking.
339 */
340 run_workqueue(cwq);
Oleg Nesterov14441962007-05-23 13:57:57 -0700341 active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 } else {
Oleg Nesterovfc2e4d72007-05-09 02:33:51 -0700343 struct wq_barrier barr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
Oleg Nesterov14441962007-05-23 13:57:57 -0700345 active = 0;
Oleg Nesterov83c22522007-05-09 02:33:54 -0700346 spin_lock_irq(&cwq->lock);
347 if (!list_empty(&cwq->worklist) || cwq->current_work != NULL) {
348 insert_wq_barrier(cwq, &barr, 1);
349 active = 1;
350 }
351 spin_unlock_irq(&cwq->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
Oleg Nesterovd7213042007-05-09 02:34:07 -0700353 if (active)
Oleg Nesterov83c22522007-05-09 02:33:54 -0700354 wait_for_completion(&barr.done);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 }
Oleg Nesterov14441962007-05-23 13:57:57 -0700356
357 return active;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358}
359
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700360/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 * flush_workqueue - ensure that any scheduled work has run to completion.
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700362 * @wq: workqueue to flush
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 *
364 * Forces execution of the workqueue and blocks until its completion.
365 * This is typically used in driver shutdown handlers.
366 *
Oleg Nesterovfc2e4d72007-05-09 02:33:51 -0700367 * We sleep until all works which were queued on entry have been handled,
368 * but we are not livelocked by new incoming ones.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 *
370 * This function used to run the workqueues itself. Now we just wait for the
371 * helper threads to do it.
372 */
373void fastcall flush_workqueue(struct workqueue_struct *wq)
374{
Oleg Nesterovb1f4ec12007-05-09 02:34:12 -0700375 const cpumask_t *cpu_map = wq_cpu_map(wq);
Oleg Nesterovcce1a162007-05-09 02:34:13 -0700376 int cpu;
Oleg Nesterovb1f4ec12007-05-09 02:34:12 -0700377
Oleg Nesterovf293ea92007-05-09 02:34:10 -0700378 might_sleep();
Oleg Nesterovb1f4ec12007-05-09 02:34:12 -0700379 for_each_cpu_mask(cpu, *cpu_map)
380 flush_cpu_workqueue(per_cpu_ptr(wq->cpu_wq, cpu));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381}
Dave Jonesae90dd52006-06-30 01:40:45 -0400382EXPORT_SYMBOL_GPL(flush_workqueue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
Oleg Nesterov6e84d642007-05-09 02:34:46 -0700384/*
385 * Upon a successful return, the caller "owns" WORK_STRUCT_PENDING bit,
386 * so this work can't be re-armed in any way.
387 */
388static int try_to_grab_pending(struct work_struct *work)
389{
390 struct cpu_workqueue_struct *cwq;
391 int ret = 0;
392
393 if (!test_and_set_bit(WORK_STRUCT_PENDING, work_data_bits(work)))
394 return 1;
395
396 /*
397 * The queueing is in progress, or it is already queued. Try to
398 * steal it from ->worklist without clearing WORK_STRUCT_PENDING.
399 */
400
401 cwq = get_wq_data(work);
402 if (!cwq)
403 return ret;
404
405 spin_lock_irq(&cwq->lock);
406 if (!list_empty(&work->entry)) {
407 /*
408 * This work is queued, but perhaps we locked the wrong cwq.
409 * In that case we must see the new value after rmb(), see
410 * insert_work()->wmb().
411 */
412 smp_rmb();
413 if (cwq == get_wq_data(work)) {
414 list_del_init(&work->entry);
415 ret = 1;
416 }
417 }
418 spin_unlock_irq(&cwq->lock);
419
420 return ret;
421}
422
423static void wait_on_cpu_work(struct cpu_workqueue_struct *cwq,
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700424 struct work_struct *work)
425{
426 struct wq_barrier barr;
427 int running = 0;
428
429 spin_lock_irq(&cwq->lock);
430 if (unlikely(cwq->current_work == work)) {
Oleg Nesterov83c22522007-05-09 02:33:54 -0700431 insert_wq_barrier(cwq, &barr, 0);
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700432 running = 1;
433 }
434 spin_unlock_irq(&cwq->lock);
435
Oleg Nesterov3af244332007-05-09 02:34:09 -0700436 if (unlikely(running))
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700437 wait_for_completion(&barr.done);
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700438}
439
Oleg Nesterov6e84d642007-05-09 02:34:46 -0700440static void wait_on_work(struct work_struct *work)
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700441{
442 struct cpu_workqueue_struct *cwq;
Oleg Nesterov28e53bd2007-05-09 02:34:22 -0700443 struct workqueue_struct *wq;
444 const cpumask_t *cpu_map;
Oleg Nesterovb1f4ec12007-05-09 02:34:12 -0700445 int cpu;
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700446
Oleg Nesterovf293ea92007-05-09 02:34:10 -0700447 might_sleep();
448
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700449 cwq = get_wq_data(work);
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700450 if (!cwq)
Oleg Nesterov3af244332007-05-09 02:34:09 -0700451 return;
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700452
Oleg Nesterov28e53bd2007-05-09 02:34:22 -0700453 wq = cwq->wq;
454 cpu_map = wq_cpu_map(wq);
455
Oleg Nesterovb1f4ec12007-05-09 02:34:12 -0700456 for_each_cpu_mask(cpu, *cpu_map)
Oleg Nesterov6e84d642007-05-09 02:34:46 -0700457 wait_on_cpu_work(per_cpu_ptr(wq->cpu_wq, cpu), work);
458}
459
460/**
461 * cancel_work_sync - block until a work_struct's callback has terminated
462 * @work: the work which is to be flushed
463 *
464 * cancel_work_sync() will cancel the work if it is queued. If the work's
465 * callback appears to be running, cancel_work_sync() will block until it
466 * has completed.
467 *
468 * It is possible to use this function if the work re-queues itself. It can
469 * cancel the work even if it migrates to another workqueue, however in that
470 * case it only guarantees that work->func() has completed on the last queued
471 * workqueue.
472 *
473 * cancel_work_sync(&delayed_work->work) should be used only if ->timer is not
474 * pending, otherwise it goes into a busy-wait loop until the timer expires.
475 *
476 * The caller must ensure that workqueue_struct on which this work was last
477 * queued can't be destroyed before this function returns.
478 */
479void cancel_work_sync(struct work_struct *work)
480{
481 while (!try_to_grab_pending(work))
482 cpu_relax();
483 wait_on_work(work);
484 work_clear_pending(work);
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700485}
Oleg Nesterov28e53bd2007-05-09 02:34:22 -0700486EXPORT_SYMBOL_GPL(cancel_work_sync);
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700487
Oleg Nesterov6e84d642007-05-09 02:34:46 -0700488/**
Oleg Nesterovf5a421a2007-07-15 23:41:44 -0700489 * cancel_delayed_work_sync - reliably kill off a delayed work.
Oleg Nesterov6e84d642007-05-09 02:34:46 -0700490 * @dwork: the delayed work struct
491 *
492 * It is possible to use this function if @dwork rearms itself via queue_work()
493 * or queue_delayed_work(). See also the comment for cancel_work_sync().
494 */
Oleg Nesterovf5a421a2007-07-15 23:41:44 -0700495void cancel_delayed_work_sync(struct delayed_work *dwork)
Oleg Nesterov6e84d642007-05-09 02:34:46 -0700496{
497 while (!del_timer(&dwork->timer) &&
498 !try_to_grab_pending(&dwork->work))
499 cpu_relax();
500 wait_on_work(&dwork->work);
501 work_clear_pending(&dwork->work);
502}
Oleg Nesterovf5a421a2007-07-15 23:41:44 -0700503EXPORT_SYMBOL(cancel_delayed_work_sync);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
Oleg Nesterov6e84d642007-05-09 02:34:46 -0700505static struct workqueue_struct *keventd_wq __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700507/**
508 * schedule_work - put work task in global workqueue
509 * @work: job to be done
510 *
511 * This puts a job in the kernel-global workqueue.
512 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513int fastcall schedule_work(struct work_struct *work)
514{
515 return queue_work(keventd_wq, work);
516}
Dave Jonesae90dd52006-06-30 01:40:45 -0400517EXPORT_SYMBOL(schedule_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700519/**
520 * schedule_delayed_work - put work task in global workqueue after delay
David Howells52bad642006-11-22 14:54:01 +0000521 * @dwork: job to be done
522 * @delay: number of jiffies to wait or 0 for immediate execution
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700523 *
524 * After waiting for a given time this puts a job in the kernel-global
525 * workqueue.
526 */
Ingo Molnar82f67cd2007-02-16 01:28:13 -0800527int fastcall schedule_delayed_work(struct delayed_work *dwork,
528 unsigned long delay)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529{
Ingo Molnar82f67cd2007-02-16 01:28:13 -0800530 timer_stats_timer_set_start_info(&dwork->timer);
David Howells52bad642006-11-22 14:54:01 +0000531 return queue_delayed_work(keventd_wq, dwork, delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532}
Dave Jonesae90dd52006-06-30 01:40:45 -0400533EXPORT_SYMBOL(schedule_delayed_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700535/**
536 * schedule_delayed_work_on - queue work in global workqueue on CPU after delay
537 * @cpu: cpu to use
David Howells52bad642006-11-22 14:54:01 +0000538 * @dwork: job to be done
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700539 * @delay: number of jiffies to wait
540 *
541 * After waiting for a given time this puts a job in the kernel-global
542 * workqueue on the specified CPU.
543 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544int schedule_delayed_work_on(int cpu,
David Howells52bad642006-11-22 14:54:01 +0000545 struct delayed_work *dwork, unsigned long delay)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546{
David Howells52bad642006-11-22 14:54:01 +0000547 return queue_delayed_work_on(cpu, keventd_wq, dwork, delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548}
Dave Jonesae90dd52006-06-30 01:40:45 -0400549EXPORT_SYMBOL(schedule_delayed_work_on);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
Andrew Mortonb6136772006-06-25 05:47:49 -0700551/**
552 * schedule_on_each_cpu - call a function on each online CPU from keventd
553 * @func: the function to call
Andrew Mortonb6136772006-06-25 05:47:49 -0700554 *
555 * Returns zero on success.
556 * Returns -ve errno on failure.
557 *
558 * Appears to be racy against CPU hotplug.
559 *
560 * schedule_on_each_cpu() is very slow.
561 */
David Howells65f27f32006-11-22 14:55:48 +0000562int schedule_on_each_cpu(work_func_t func)
Christoph Lameter15316ba2006-01-08 01:00:43 -0800563{
564 int cpu;
Andrew Mortonb6136772006-06-25 05:47:49 -0700565 struct work_struct *works;
Christoph Lameter15316ba2006-01-08 01:00:43 -0800566
Andrew Mortonb6136772006-06-25 05:47:49 -0700567 works = alloc_percpu(struct work_struct);
568 if (!works)
Christoph Lameter15316ba2006-01-08 01:00:43 -0800569 return -ENOMEM;
Andrew Mortonb6136772006-06-25 05:47:49 -0700570
Andrew Mortone18f3ff2007-05-09 02:33:50 -0700571 preempt_disable(); /* CPU hotplug */
Christoph Lameter15316ba2006-01-08 01:00:43 -0800572 for_each_online_cpu(cpu) {
Ingo Molnar9bfb1832006-12-18 20:05:09 +0100573 struct work_struct *work = per_cpu_ptr(works, cpu);
574
575 INIT_WORK(work, func);
576 set_bit(WORK_STRUCT_PENDING, work_data_bits(work));
577 __queue_work(per_cpu_ptr(keventd_wq->cpu_wq, cpu), work);
Christoph Lameter15316ba2006-01-08 01:00:43 -0800578 }
Andrew Mortone18f3ff2007-05-09 02:33:50 -0700579 preempt_enable();
Christoph Lameter15316ba2006-01-08 01:00:43 -0800580 flush_workqueue(keventd_wq);
Andrew Mortonb6136772006-06-25 05:47:49 -0700581 free_percpu(works);
Christoph Lameter15316ba2006-01-08 01:00:43 -0800582 return 0;
583}
584
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585void flush_scheduled_work(void)
586{
587 flush_workqueue(keventd_wq);
588}
Dave Jonesae90dd52006-06-30 01:40:45 -0400589EXPORT_SYMBOL(flush_scheduled_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
591/**
James Bottomley1fa44ec2006-02-23 12:43:43 -0600592 * execute_in_process_context - reliably execute the routine with user context
593 * @fn: the function to execute
James Bottomley1fa44ec2006-02-23 12:43:43 -0600594 * @ew: guaranteed storage for the execute work structure (must
595 * be available when the work executes)
596 *
597 * Executes the function immediately if process context is available,
598 * otherwise schedules the function for delayed execution.
599 *
600 * Returns: 0 - function was executed
601 * 1 - function was scheduled for execution
602 */
David Howells65f27f32006-11-22 14:55:48 +0000603int execute_in_process_context(work_func_t fn, struct execute_work *ew)
James Bottomley1fa44ec2006-02-23 12:43:43 -0600604{
605 if (!in_interrupt()) {
David Howells65f27f32006-11-22 14:55:48 +0000606 fn(&ew->work);
James Bottomley1fa44ec2006-02-23 12:43:43 -0600607 return 0;
608 }
609
David Howells65f27f32006-11-22 14:55:48 +0000610 INIT_WORK(&ew->work, fn);
James Bottomley1fa44ec2006-02-23 12:43:43 -0600611 schedule_work(&ew->work);
612
613 return 1;
614}
615EXPORT_SYMBOL_GPL(execute_in_process_context);
616
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617int keventd_up(void)
618{
619 return keventd_wq != NULL;
620}
621
622int current_is_keventd(void)
623{
624 struct cpu_workqueue_struct *cwq;
625 int cpu = smp_processor_id(); /* preempt-safe: keventd is per-cpu */
626 int ret = 0;
627
628 BUG_ON(!keventd_wq);
629
Christoph Lameter89ada672005-10-30 15:01:59 -0800630 cwq = per_cpu_ptr(keventd_wq->cpu_wq, cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 if (current == cwq->thread)
632 ret = 1;
633
634 return ret;
635
636}
637
Oleg Nesterov3af244332007-05-09 02:34:09 -0700638static struct cpu_workqueue_struct *
639init_cpu_workqueue(struct workqueue_struct *wq, int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640{
Christoph Lameter89ada672005-10-30 15:01:59 -0800641 struct cpu_workqueue_struct *cwq = per_cpu_ptr(wq->cpu_wq, cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
Oleg Nesterov3af244332007-05-09 02:34:09 -0700643 cwq->wq = wq;
644 spin_lock_init(&cwq->lock);
645 INIT_LIST_HEAD(&cwq->worklist);
646 init_waitqueue_head(&cwq->more_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
Oleg Nesterov3af244332007-05-09 02:34:09 -0700648 return cwq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649}
650
Oleg Nesterov3af244332007-05-09 02:34:09 -0700651static int create_workqueue_thread(struct cpu_workqueue_struct *cwq, int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652{
Oleg Nesterov3af244332007-05-09 02:34:09 -0700653 struct workqueue_struct *wq = cwq->wq;
654 const char *fmt = is_single_threaded(wq) ? "%s" : "%s/%d";
655 struct task_struct *p;
656
657 p = kthread_create(worker_thread, cwq, fmt, wq->name, cpu);
658 /*
659 * Nobody can add the work_struct to this cwq,
660 * if (caller is __create_workqueue)
661 * nobody should see this wq
662 * else // caller is CPU_UP_PREPARE
663 * cpu is not on cpu_online_map
664 * so we can abort safely.
665 */
666 if (IS_ERR(p))
667 return PTR_ERR(p);
668
669 cwq->thread = p;
Oleg Nesterov3af244332007-05-09 02:34:09 -0700670
671 return 0;
672}
673
Oleg Nesterov06ba38a2007-05-09 02:34:15 -0700674static void start_workqueue_thread(struct cpu_workqueue_struct *cwq, int cpu)
675{
676 struct task_struct *p = cwq->thread;
677
678 if (p != NULL) {
679 if (cpu >= 0)
680 kthread_bind(p, cpu);
681 wake_up_process(p);
682 }
683}
684
Oleg Nesterov3af244332007-05-09 02:34:09 -0700685struct workqueue_struct *__create_workqueue(const char *name,
686 int singlethread, int freezeable)
687{
688 struct workqueue_struct *wq;
689 struct cpu_workqueue_struct *cwq;
690 int err = 0, cpu;
691
692 wq = kzalloc(sizeof(*wq), GFP_KERNEL);
693 if (!wq)
694 return NULL;
695
696 wq->cpu_wq = alloc_percpu(struct cpu_workqueue_struct);
697 if (!wq->cpu_wq) {
698 kfree(wq);
699 return NULL;
700 }
701
702 wq->name = name;
Oleg Nesterovcce1a162007-05-09 02:34:13 -0700703 wq->singlethread = singlethread;
Oleg Nesterov3af244332007-05-09 02:34:09 -0700704 wq->freezeable = freezeable;
Oleg Nesterovcce1a162007-05-09 02:34:13 -0700705 INIT_LIST_HEAD(&wq->list);
Oleg Nesterov3af244332007-05-09 02:34:09 -0700706
707 if (singlethread) {
Oleg Nesterov3af244332007-05-09 02:34:09 -0700708 cwq = init_cpu_workqueue(wq, singlethread_cpu);
709 err = create_workqueue_thread(cwq, singlethread_cpu);
Oleg Nesterov06ba38a2007-05-09 02:34:15 -0700710 start_workqueue_thread(cwq, -1);
Oleg Nesterov3af244332007-05-09 02:34:09 -0700711 } else {
712 mutex_lock(&workqueue_mutex);
713 list_add(&wq->list, &workqueues);
714
715 for_each_possible_cpu(cpu) {
716 cwq = init_cpu_workqueue(wq, cpu);
717 if (err || !cpu_online(cpu))
718 continue;
719 err = create_workqueue_thread(cwq, cpu);
Oleg Nesterov06ba38a2007-05-09 02:34:15 -0700720 start_workqueue_thread(cwq, cpu);
Oleg Nesterov3af244332007-05-09 02:34:09 -0700721 }
722 mutex_unlock(&workqueue_mutex);
723 }
724
725 if (err) {
726 destroy_workqueue(wq);
727 wq = NULL;
728 }
729 return wq;
730}
731EXPORT_SYMBOL_GPL(__create_workqueue);
732
733static void cleanup_workqueue_thread(struct cpu_workqueue_struct *cwq, int cpu)
734{
Oleg Nesterov14441962007-05-23 13:57:57 -0700735 /*
736 * Our caller is either destroy_workqueue() or CPU_DEAD,
737 * workqueue_mutex protects cwq->thread
738 */
739 if (cwq->thread == NULL)
740 return;
Oleg Nesterov3af244332007-05-09 02:34:09 -0700741
Oleg Nesterov14441962007-05-23 13:57:57 -0700742 /*
743 * If the caller is CPU_DEAD the single flush_cpu_workqueue()
744 * is not enough, a concurrent flush_workqueue() can insert a
745 * barrier after us.
746 * When ->worklist becomes empty it is safe to exit because no
747 * more work_structs can be queued on this cwq: flush_workqueue
748 * checks list_empty(), and a "normal" queue_work() can't use
749 * a dead CPU.
750 */
751 while (flush_cpu_workqueue(cwq))
752 ;
Oleg Nesterov3af244332007-05-09 02:34:09 -0700753
Oleg Nesterov14441962007-05-23 13:57:57 -0700754 kthread_stop(cwq->thread);
755 cwq->thread = NULL;
Oleg Nesterov3af244332007-05-09 02:34:09 -0700756}
757
758/**
759 * destroy_workqueue - safely terminate a workqueue
760 * @wq: target workqueue
761 *
762 * Safely destroy a workqueue. All work currently pending will be done first.
763 */
764void destroy_workqueue(struct workqueue_struct *wq)
765{
Oleg Nesterovb1f4ec12007-05-09 02:34:12 -0700766 const cpumask_t *cpu_map = wq_cpu_map(wq);
Oleg Nesterov3af244332007-05-09 02:34:09 -0700767 struct cpu_workqueue_struct *cwq;
Oleg Nesterovb1f4ec12007-05-09 02:34:12 -0700768 int cpu;
Oleg Nesterov3af244332007-05-09 02:34:09 -0700769
Oleg Nesterovb1f4ec12007-05-09 02:34:12 -0700770 mutex_lock(&workqueue_mutex);
771 list_del(&wq->list);
772 mutex_unlock(&workqueue_mutex);
Oleg Nesterov3af244332007-05-09 02:34:09 -0700773
Oleg Nesterovb1f4ec12007-05-09 02:34:12 -0700774 for_each_cpu_mask(cpu, *cpu_map) {
775 cwq = per_cpu_ptr(wq->cpu_wq, cpu);
776 cleanup_workqueue_thread(cwq, cpu);
Oleg Nesterov3af244332007-05-09 02:34:09 -0700777 }
778
779 free_percpu(wq->cpu_wq);
780 kfree(wq);
781}
782EXPORT_SYMBOL_GPL(destroy_workqueue);
783
784static int __devinit workqueue_cpu_callback(struct notifier_block *nfb,
785 unsigned long action,
786 void *hcpu)
787{
788 unsigned int cpu = (unsigned long)hcpu;
789 struct cpu_workqueue_struct *cwq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 struct workqueue_struct *wq;
791
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700792 action &= ~CPU_TASKS_FROZEN;
793
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 switch (action) {
Oleg Nesterov3af244332007-05-09 02:34:09 -0700795 case CPU_LOCK_ACQUIRE:
796 mutex_lock(&workqueue_mutex);
797 return NOTIFY_OK;
798
799 case CPU_LOCK_RELEASE:
800 mutex_unlock(&workqueue_mutex);
801 return NOTIFY_OK;
802
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 case CPU_UP_PREPARE:
Oleg Nesterov3af244332007-05-09 02:34:09 -0700804 cpu_set(cpu, cpu_populated_map);
805 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
Oleg Nesterov3af244332007-05-09 02:34:09 -0700807 list_for_each_entry(wq, &workqueues, list) {
808 cwq = per_cpu_ptr(wq->cpu_wq, cpu);
Christoph Lameter89ada672005-10-30 15:01:59 -0800809
Oleg Nesterov3af244332007-05-09 02:34:09 -0700810 switch (action) {
811 case CPU_UP_PREPARE:
812 if (!create_workqueue_thread(cwq, cpu))
813 break;
814 printk(KERN_ERR "workqueue for %i failed\n", cpu);
815 return NOTIFY_BAD;
816
817 case CPU_ONLINE:
Oleg Nesterov06ba38a2007-05-09 02:34:15 -0700818 start_workqueue_thread(cwq, cpu);
Oleg Nesterov3af244332007-05-09 02:34:09 -0700819 break;
820
821 case CPU_UP_CANCELED:
Oleg Nesterov06ba38a2007-05-09 02:34:15 -0700822 start_workqueue_thread(cwq, -1);
Oleg Nesterov3af244332007-05-09 02:34:09 -0700823 case CPU_DEAD:
824 cleanup_workqueue_thread(cwq, cpu);
825 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 }
828
829 return NOTIFY_OK;
830}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
Oleg Nesterovc12920d2007-05-09 02:34:14 -0700832void __init init_workqueues(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833{
Oleg Nesterov3af244332007-05-09 02:34:09 -0700834 cpu_populated_map = cpu_online_map;
Nathan Lynchf756d5e2006-01-08 01:05:12 -0800835 singlethread_cpu = first_cpu(cpu_possible_map);
Oleg Nesterovb1f4ec12007-05-09 02:34:12 -0700836 cpu_singlethread_map = cpumask_of_cpu(singlethread_cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 hotcpu_notifier(workqueue_cpu_callback, 0);
838 keventd_wq = create_workqueue("events");
839 BUG_ON(!keventd_wq);
840}