blob: d107e1c3b071a01201e1f570d70e5b02b76bb481 [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 Lameter469340232006-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;
Oleg Nesterov3af244332007-05-09 02:34:09 -070050 int should_stop;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52 int run_depth; /* Detect run_workqueue() recursion depth */
53} ____cacheline_aligned;
54
55/*
56 * The externally visible workqueue abstraction is an array of
57 * per-CPU workqueues:
58 */
59struct workqueue_struct {
Christoph Lameter89ada672005-10-30 15:01:59 -080060 struct cpu_workqueue_struct *cpu_wq;
Oleg Nesterovcce1a162007-05-09 02:34:13 -070061 struct list_head list;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 const char *name;
Oleg Nesterovcce1a162007-05-09 02:34:13 -070063 int singlethread;
Oleg Nesterov319c2a92007-05-09 02:34:06 -070064 int freezeable; /* Freeze threads during suspend */
Linus Torvalds1da177e2005-04-16 15:20:36 -070065};
66
67/* All the per-cpu workqueues on the system, for hotplug cpu to add/remove
68 threads to each one as cpus come/go. */
Andrew Morton9b41ea72006-08-13 23:24:26 -070069static DEFINE_MUTEX(workqueue_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070static LIST_HEAD(workqueues);
71
Oleg Nesterov3af244332007-05-09 02:34:09 -070072static int singlethread_cpu __read_mostly;
Oleg Nesterovb1f4ec172007-05-09 02:34:12 -070073static cpumask_t cpu_singlethread_map __read_mostly;
Oleg Nesterov3af244332007-05-09 02:34:09 -070074/* optimization, we could use cpu_possible_map */
75static cpumask_t cpu_populated_map __read_mostly;
Nathan Lynchf756d5e2006-01-08 01:05:12 -080076
Linus Torvalds1da177e2005-04-16 15:20:36 -070077/* If it's single threaded, it isn't in the list of workqueues. */
78static inline int is_single_threaded(struct workqueue_struct *wq)
79{
Oleg Nesterovcce1a162007-05-09 02:34:13 -070080 return wq->singlethread;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081}
82
Oleg Nesterovb1f4ec172007-05-09 02:34:12 -070083static const cpumask_t *wq_cpu_map(struct workqueue_struct *wq)
84{
85 return is_single_threaded(wq)
86 ? &cpu_singlethread_map : &cpu_populated_map;
87}
88
David Howells4594bf12006-12-07 11:33:26 +000089/*
90 * Set the workqueue on which a work item is to be run
91 * - Must *only* be called if the pending flag is set
92 */
Oleg Nesteroved7c0fe2007-05-09 02:34:16 -070093static inline void set_wq_data(struct work_struct *work,
94 struct cpu_workqueue_struct *cwq)
David Howells365970a2006-11-22 14:54:49 +000095{
David Howells4594bf12006-12-07 11:33:26 +000096 unsigned long new;
David Howells365970a2006-11-22 14:54:49 +000097
David Howells4594bf12006-12-07 11:33:26 +000098 BUG_ON(!work_pending(work));
99
Oleg Nesteroved7c0fe2007-05-09 02:34:16 -0700100 new = (unsigned long) cwq | (1UL << WORK_STRUCT_PENDING);
Linus Torvaldsa08727b2006-12-16 09:53:50 -0800101 new |= WORK_STRUCT_FLAG_MASK & *work_data_bits(work);
102 atomic_long_set(&work->data, new);
David Howells365970a2006-11-22 14:54:49 +0000103}
104
Oleg Nesteroved7c0fe2007-05-09 02:34:16 -0700105static inline
106struct cpu_workqueue_struct *get_wq_data(struct work_struct *work)
David Howells365970a2006-11-22 14:54:49 +0000107{
Linus Torvaldsa08727b2006-12-16 09:53:50 -0800108 return (void *) (atomic_long_read(&work->data) & WORK_STRUCT_WQ_DATA_MASK);
David Howells365970a2006-11-22 14:54:49 +0000109}
110
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700111static void insert_work(struct cpu_workqueue_struct *cwq,
112 struct work_struct *work, int tail)
113{
114 set_wq_data(work, cwq);
115 if (tail)
116 list_add_tail(&work->entry, &cwq->worklist);
117 else
118 list_add(&work->entry, &cwq->worklist);
119 wake_up(&cwq->more_work);
120}
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122/* Preempt must be disabled. */
123static void __queue_work(struct cpu_workqueue_struct *cwq,
124 struct work_struct *work)
125{
126 unsigned long flags;
127
128 spin_lock_irqsave(&cwq->lock, flags);
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700129 insert_work(cwq, work, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 spin_unlock_irqrestore(&cwq->lock, flags);
131}
132
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700133/**
134 * queue_work - queue work on a workqueue
135 * @wq: workqueue to use
136 * @work: work to queue
137 *
Alan Stern057647f2006-10-28 10:38:58 -0700138 * Returns 0 if @work was already on a queue, non-zero otherwise.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 *
140 * We queue the work to the CPU it was submitted, but there is no
141 * guarantee that it will be processed by that CPU.
142 */
143int fastcall queue_work(struct workqueue_struct *wq, struct work_struct *work)
144{
145 int ret = 0, cpu = get_cpu();
146
Linus Torvaldsa08727b2006-12-16 09:53:50 -0800147 if (!test_and_set_bit(WORK_STRUCT_PENDING, work_data_bits(work))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 if (unlikely(is_single_threaded(wq)))
Nathan Lynchf756d5e2006-01-08 01:05:12 -0800149 cpu = singlethread_cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 BUG_ON(!list_empty(&work->entry));
Christoph Lameter89ada672005-10-30 15:01:59 -0800151 __queue_work(per_cpu_ptr(wq->cpu_wq, cpu), work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 ret = 1;
153 }
154 put_cpu();
155 return ret;
156}
Dave Jonesae90dd52006-06-30 01:40:45 -0400157EXPORT_SYMBOL_GPL(queue_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Ingo Molnar82f67cd2007-02-16 01:28:13 -0800159void delayed_work_timer_fn(unsigned long __data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160{
David Howells52bad642006-11-22 14:54:01 +0000161 struct delayed_work *dwork = (struct delayed_work *)__data;
Oleg Nesteroved7c0fe2007-05-09 02:34:16 -0700162 struct cpu_workqueue_struct *cwq = get_wq_data(&dwork->work);
163 struct workqueue_struct *wq = cwq->wq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 int cpu = smp_processor_id();
165
166 if (unlikely(is_single_threaded(wq)))
Nathan Lynchf756d5e2006-01-08 01:05:12 -0800167 cpu = singlethread_cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
David Howells52bad642006-11-22 14:54:01 +0000169 __queue_work(per_cpu_ptr(wq->cpu_wq, cpu), &dwork->work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170}
171
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700172/**
173 * queue_delayed_work - queue work on a workqueue after delay
174 * @wq: workqueue to use
Randy Dunlapaf9997e2006-12-22 01:06:52 -0800175 * @dwork: delayable work to queue
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700176 * @delay: number of jiffies to wait before queueing
177 *
Alan Stern057647f2006-10-28 10:38:58 -0700178 * Returns 0 if @work was already on a queue, non-zero otherwise.
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700179 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180int fastcall queue_delayed_work(struct workqueue_struct *wq,
David Howells52bad642006-11-22 14:54:01 +0000181 struct delayed_work *dwork, unsigned long delay)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182{
183 int ret = 0;
David Howells52bad642006-11-22 14:54:01 +0000184 struct timer_list *timer = &dwork->timer;
185 struct work_struct *work = &dwork->work;
186
Ingo Molnar82f67cd2007-02-16 01:28:13 -0800187 timer_stats_timer_set_start_info(timer);
David Howells52bad642006-11-22 14:54:01 +0000188 if (delay == 0)
189 return queue_work(wq, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Linus Torvaldsa08727b2006-12-16 09:53:50 -0800191 if (!test_and_set_bit(WORK_STRUCT_PENDING, work_data_bits(work))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 BUG_ON(timer_pending(timer));
193 BUG_ON(!list_empty(&work->entry));
194
Oleg Nesteroved7c0fe2007-05-09 02:34:16 -0700195 /* This stores cwq for the moment, for the timer_fn */
196 set_wq_data(work,
197 per_cpu_ptr(wq->cpu_wq, raw_smp_processor_id()));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 timer->expires = jiffies + delay;
David Howells52bad642006-11-22 14:54:01 +0000199 timer->data = (unsigned long)dwork;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 timer->function = delayed_work_timer_fn;
201 add_timer(timer);
202 ret = 1;
203 }
204 return ret;
205}
Dave Jonesae90dd52006-06-30 01:40:45 -0400206EXPORT_SYMBOL_GPL(queue_delayed_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700208/**
209 * queue_delayed_work_on - queue work on specific CPU after delay
210 * @cpu: CPU number to execute work on
211 * @wq: workqueue to use
Randy Dunlapaf9997e2006-12-22 01:06:52 -0800212 * @dwork: work to queue
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700213 * @delay: number of jiffies to wait before queueing
214 *
Alan Stern057647f2006-10-28 10:38:58 -0700215 * Returns 0 if @work was already on a queue, non-zero otherwise.
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700216 */
Venkatesh Pallipadi7a6bc1c2006-06-28 13:50:33 -0700217int queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
David Howells52bad642006-11-22 14:54:01 +0000218 struct delayed_work *dwork, unsigned long delay)
Venkatesh Pallipadi7a6bc1c2006-06-28 13:50:33 -0700219{
220 int ret = 0;
David Howells52bad642006-11-22 14:54:01 +0000221 struct timer_list *timer = &dwork->timer;
222 struct work_struct *work = &dwork->work;
Venkatesh Pallipadi7a6bc1c2006-06-28 13:50:33 -0700223
Linus Torvaldsa08727b2006-12-16 09:53:50 -0800224 if (!test_and_set_bit(WORK_STRUCT_PENDING, work_data_bits(work))) {
Venkatesh Pallipadi7a6bc1c2006-06-28 13:50:33 -0700225 BUG_ON(timer_pending(timer));
226 BUG_ON(!list_empty(&work->entry));
227
Oleg Nesteroved7c0fe2007-05-09 02:34:16 -0700228 /* This stores cwq for the moment, for the timer_fn */
229 set_wq_data(work,
230 per_cpu_ptr(wq->cpu_wq, raw_smp_processor_id()));
Venkatesh Pallipadi7a6bc1c2006-06-28 13:50:33 -0700231 timer->expires = jiffies + delay;
David Howells52bad642006-11-22 14:54:01 +0000232 timer->data = (unsigned long)dwork;
Venkatesh Pallipadi7a6bc1c2006-06-28 13:50:33 -0700233 timer->function = delayed_work_timer_fn;
234 add_timer_on(timer, cpu);
235 ret = 1;
236 }
237 return ret;
238}
Dave Jonesae90dd52006-06-30 01:40:45 -0400239EXPORT_SYMBOL_GPL(queue_delayed_work_on);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
Arjan van de Ven858119e2006-01-14 13:20:43 -0800241static void run_workqueue(struct cpu_workqueue_struct *cwq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242{
Oleg Nesterovf293ea92007-05-09 02:34:10 -0700243 spin_lock_irq(&cwq->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 cwq->run_depth++;
245 if (cwq->run_depth > 3) {
246 /* morton gets to eat his hat */
247 printk("%s: recursion depth exceeded: %d\n",
248 __FUNCTION__, cwq->run_depth);
249 dump_stack();
250 }
251 while (!list_empty(&cwq->worklist)) {
252 struct work_struct *work = list_entry(cwq->worklist.next,
253 struct work_struct, entry);
David Howells6bb49e52006-11-22 14:54:45 +0000254 work_func_t f = work->func;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700256 cwq->current_work = work;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 list_del_init(cwq->worklist.next);
Oleg Nesterovf293ea92007-05-09 02:34:10 -0700258 spin_unlock_irq(&cwq->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
David Howells365970a2006-11-22 14:54:49 +0000260 BUG_ON(get_wq_data(work) != cwq);
Linus Torvaldsa08727b2006-12-16 09:53:50 -0800261 if (!test_bit(WORK_STRUCT_NOAUTOREL, work_data_bits(work)))
David Howells65f27f32006-11-22 14:55:48 +0000262 work_release(work);
263 f(work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
Peter Zijlstrad5abe662006-12-06 20:37:26 -0800265 if (unlikely(in_atomic() || lockdep_depth(current) > 0)) {
266 printk(KERN_ERR "BUG: workqueue leaked lock or atomic: "
267 "%s/0x%08x/%d\n",
268 current->comm, preempt_count(),
269 current->pid);
270 printk(KERN_ERR " last function: ");
271 print_symbol("%s\n", (unsigned long)f);
272 debug_show_held_locks(current);
273 dump_stack();
274 }
275
Oleg Nesterovf293ea92007-05-09 02:34:10 -0700276 spin_lock_irq(&cwq->lock);
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700277 cwq->current_work = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 }
279 cwq->run_depth--;
Oleg Nesterovf293ea92007-05-09 02:34:10 -0700280 spin_unlock_irq(&cwq->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281}
282
Oleg Nesterov3af244332007-05-09 02:34:09 -0700283/*
284 * NOTE: the caller must not touch *cwq if this func returns true
285 */
286static int cwq_should_stop(struct cpu_workqueue_struct *cwq)
287{
288 int should_stop = cwq->should_stop;
289
290 if (unlikely(should_stop)) {
291 spin_lock_irq(&cwq->lock);
292 should_stop = cwq->should_stop && list_empty(&cwq->worklist);
293 if (should_stop)
294 cwq->thread = NULL;
295 spin_unlock_irq(&cwq->lock);
296 }
297
298 return should_stop;
299}
300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301static int worker_thread(void *__cwq)
302{
303 struct cpu_workqueue_struct *cwq = __cwq;
Oleg Nesterov3af244332007-05-09 02:34:09 -0700304 DEFINE_WAIT(wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 struct k_sigaction sa;
306 sigset_t blocked;
307
Oleg Nesterov319c2a92007-05-09 02:34:06 -0700308 if (!cwq->wq->freezeable)
Rafael J. Wysocki341a5952006-12-06 20:34:49 -0800309 current->flags |= PF_NOFREEZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
311 set_user_nice(current, -5);
312
313 /* Block and flush all signals */
314 sigfillset(&blocked);
315 sigprocmask(SIG_BLOCK, &blocked, NULL);
316 flush_signals(current);
317
Christoph Lameter469340232006-10-11 01:21:26 -0700318 /*
319 * We inherited MPOL_INTERLEAVE from the booting kernel.
320 * Set MPOL_DEFAULT to insure node local allocations.
321 */
322 numa_default_policy();
323
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 /* SIG_IGN makes children autoreap: see do_notify_parent(). */
325 sa.sa.sa_handler = SIG_IGN;
326 sa.sa.sa_flags = 0;
327 siginitset(&sa.sa.sa_mask, sigmask(SIGCHLD));
328 do_sigaction(SIGCHLD, &sa, (struct k_sigaction *)0);
329
Oleg Nesterov3af244332007-05-09 02:34:09 -0700330 for (;;) {
Oleg Nesterov319c2a92007-05-09 02:34:06 -0700331 if (cwq->wq->freezeable)
Rafael J. Wysocki341a5952006-12-06 20:34:49 -0800332 try_to_freeze();
333
Oleg Nesterov3af244332007-05-09 02:34:09 -0700334 prepare_to_wait(&cwq->more_work, &wait, TASK_INTERRUPTIBLE);
335 if (!cwq->should_stop && list_empty(&cwq->worklist))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 schedule();
Oleg Nesterov3af244332007-05-09 02:34:09 -0700337 finish_wait(&cwq->more_work, &wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
Oleg Nesterov3af244332007-05-09 02:34:09 -0700339 if (cwq_should_stop(cwq))
340 break;
341
342 run_workqueue(cwq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 }
Oleg Nesterov3af244332007-05-09 02:34:09 -0700344
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 return 0;
346}
347
Oleg Nesterovfc2e4d72007-05-09 02:33:51 -0700348struct wq_barrier {
349 struct work_struct work;
350 struct completion done;
351};
352
353static void wq_barrier_func(struct work_struct *work)
354{
355 struct wq_barrier *barr = container_of(work, struct wq_barrier, work);
356 complete(&barr->done);
357}
358
Oleg Nesterov83c22522007-05-09 02:33:54 -0700359static void insert_wq_barrier(struct cpu_workqueue_struct *cwq,
360 struct wq_barrier *barr, int tail)
Oleg Nesterovfc2e4d72007-05-09 02:33:51 -0700361{
362 INIT_WORK(&barr->work, wq_barrier_func);
363 __set_bit(WORK_STRUCT_PENDING, work_data_bits(&barr->work));
364
365 init_completion(&barr->done);
Oleg Nesterov83c22522007-05-09 02:33:54 -0700366
367 insert_work(cwq, &barr->work, tail);
Oleg Nesterovfc2e4d72007-05-09 02:33:51 -0700368}
369
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370static void flush_cpu_workqueue(struct cpu_workqueue_struct *cwq)
371{
372 if (cwq->thread == current) {
373 /*
374 * Probably keventd trying to flush its own queue. So simply run
375 * it by hand rather than deadlocking.
376 */
377 run_workqueue(cwq);
378 } else {
Oleg Nesterovfc2e4d72007-05-09 02:33:51 -0700379 struct wq_barrier barr;
Oleg Nesterov83c22522007-05-09 02:33:54 -0700380 int active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Oleg Nesterov83c22522007-05-09 02:33:54 -0700382 spin_lock_irq(&cwq->lock);
383 if (!list_empty(&cwq->worklist) || cwq->current_work != NULL) {
384 insert_wq_barrier(cwq, &barr, 1);
385 active = 1;
386 }
387 spin_unlock_irq(&cwq->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Oleg Nesterovd7213042007-05-09 02:34:07 -0700389 if (active)
Oleg Nesterov83c22522007-05-09 02:33:54 -0700390 wait_for_completion(&barr.done);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 }
392}
393
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700394/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 * flush_workqueue - ensure that any scheduled work has run to completion.
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700396 * @wq: workqueue to flush
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 *
398 * Forces execution of the workqueue and blocks until its completion.
399 * This is typically used in driver shutdown handlers.
400 *
Oleg Nesterovfc2e4d72007-05-09 02:33:51 -0700401 * We sleep until all works which were queued on entry have been handled,
402 * but we are not livelocked by new incoming ones.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 *
404 * This function used to run the workqueues itself. Now we just wait for the
405 * helper threads to do it.
406 */
407void fastcall flush_workqueue(struct workqueue_struct *wq)
408{
Oleg Nesterovb1f4ec172007-05-09 02:34:12 -0700409 const cpumask_t *cpu_map = wq_cpu_map(wq);
Oleg Nesterovcce1a162007-05-09 02:34:13 -0700410 int cpu;
Oleg Nesterovb1f4ec172007-05-09 02:34:12 -0700411
Oleg Nesterovf293ea92007-05-09 02:34:10 -0700412 might_sleep();
Oleg Nesterovb1f4ec172007-05-09 02:34:12 -0700413 for_each_cpu_mask(cpu, *cpu_map)
414 flush_cpu_workqueue(per_cpu_ptr(wq->cpu_wq, cpu));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415}
Dave Jonesae90dd52006-06-30 01:40:45 -0400416EXPORT_SYMBOL_GPL(flush_workqueue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700418static void wait_on_work(struct cpu_workqueue_struct *cwq,
419 struct work_struct *work)
420{
421 struct wq_barrier barr;
422 int running = 0;
423
424 spin_lock_irq(&cwq->lock);
425 if (unlikely(cwq->current_work == work)) {
Oleg Nesterov83c22522007-05-09 02:33:54 -0700426 insert_wq_barrier(cwq, &barr, 0);
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700427 running = 1;
428 }
429 spin_unlock_irq(&cwq->lock);
430
Oleg Nesterov3af244332007-05-09 02:34:09 -0700431 if (unlikely(running))
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700432 wait_for_completion(&barr.done);
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700433}
434
435/**
436 * flush_work - block until a work_struct's callback has terminated
437 * @wq: the workqueue on which the work is queued
438 * @work: the work which is to be flushed
439 *
440 * flush_work() will attempt to cancel the work if it is queued. If the work's
441 * callback appears to be running, flush_work() will block until it has
442 * completed.
443 *
444 * flush_work() is designed to be used when the caller is tearing down data
445 * structures which the callback function operates upon. It is expected that,
446 * prior to calling flush_work(), the caller has arranged for the work to not
447 * be requeued.
448 */
449void flush_work(struct workqueue_struct *wq, struct work_struct *work)
450{
Oleg Nesterovb1f4ec172007-05-09 02:34:12 -0700451 const cpumask_t *cpu_map = wq_cpu_map(wq);
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700452 struct cpu_workqueue_struct *cwq;
Oleg Nesterovb1f4ec172007-05-09 02:34:12 -0700453 int cpu;
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700454
Oleg Nesterovf293ea92007-05-09 02:34:10 -0700455 might_sleep();
456
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700457 cwq = get_wq_data(work);
458 /* Was it ever queued ? */
459 if (!cwq)
Oleg Nesterov3af244332007-05-09 02:34:09 -0700460 return;
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700461
462 /*
Oleg Nesterov3af244332007-05-09 02:34:09 -0700463 * This work can't be re-queued, no need to re-check that
464 * get_wq_data() is still the same when we take cwq->lock.
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700465 */
466 spin_lock_irq(&cwq->lock);
467 list_del_init(&work->entry);
468 work_release(work);
469 spin_unlock_irq(&cwq->lock);
470
Oleg Nesterovb1f4ec172007-05-09 02:34:12 -0700471 for_each_cpu_mask(cpu, *cpu_map)
472 wait_on_work(per_cpu_ptr(wq->cpu_wq, cpu), work);
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700473}
474EXPORT_SYMBOL_GPL(flush_work);
475
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
477static struct workqueue_struct *keventd_wq;
478
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700479/**
480 * schedule_work - put work task in global workqueue
481 * @work: job to be done
482 *
483 * This puts a job in the kernel-global workqueue.
484 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485int fastcall schedule_work(struct work_struct *work)
486{
487 return queue_work(keventd_wq, work);
488}
Dave Jonesae90dd52006-06-30 01:40:45 -0400489EXPORT_SYMBOL(schedule_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700491/**
492 * schedule_delayed_work - put work task in global workqueue after delay
David Howells52bad642006-11-22 14:54:01 +0000493 * @dwork: job to be done
494 * @delay: number of jiffies to wait or 0 for immediate execution
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700495 *
496 * After waiting for a given time this puts a job in the kernel-global
497 * workqueue.
498 */
Ingo Molnar82f67cd2007-02-16 01:28:13 -0800499int fastcall schedule_delayed_work(struct delayed_work *dwork,
500 unsigned long delay)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501{
Ingo Molnar82f67cd2007-02-16 01:28:13 -0800502 timer_stats_timer_set_start_info(&dwork->timer);
David Howells52bad642006-11-22 14:54:01 +0000503 return queue_delayed_work(keventd_wq, dwork, delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504}
Dave Jonesae90dd52006-06-30 01:40:45 -0400505EXPORT_SYMBOL(schedule_delayed_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700507/**
508 * schedule_delayed_work_on - queue work in global workqueue on CPU after delay
509 * @cpu: cpu to use
David Howells52bad642006-11-22 14:54:01 +0000510 * @dwork: job to be done
Rolf Eike Beer0fcb78c2006-07-30 03:03:42 -0700511 * @delay: number of jiffies to wait
512 *
513 * After waiting for a given time this puts a job in the kernel-global
514 * workqueue on the specified CPU.
515 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516int schedule_delayed_work_on(int cpu,
David Howells52bad642006-11-22 14:54:01 +0000517 struct delayed_work *dwork, unsigned long delay)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518{
David Howells52bad642006-11-22 14:54:01 +0000519 return queue_delayed_work_on(cpu, keventd_wq, dwork, delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520}
Dave Jonesae90dd52006-06-30 01:40:45 -0400521EXPORT_SYMBOL(schedule_delayed_work_on);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
Andrew Mortonb6136772006-06-25 05:47:49 -0700523/**
524 * schedule_on_each_cpu - call a function on each online CPU from keventd
525 * @func: the function to call
Andrew Mortonb6136772006-06-25 05:47:49 -0700526 *
527 * Returns zero on success.
528 * Returns -ve errno on failure.
529 *
530 * Appears to be racy against CPU hotplug.
531 *
532 * schedule_on_each_cpu() is very slow.
533 */
David Howells65f27f32006-11-22 14:55:48 +0000534int schedule_on_each_cpu(work_func_t func)
Christoph Lameter15316ba2006-01-08 01:00:43 -0800535{
536 int cpu;
Andrew Mortonb6136772006-06-25 05:47:49 -0700537 struct work_struct *works;
Christoph Lameter15316ba2006-01-08 01:00:43 -0800538
Andrew Mortonb6136772006-06-25 05:47:49 -0700539 works = alloc_percpu(struct work_struct);
540 if (!works)
Christoph Lameter15316ba2006-01-08 01:00:43 -0800541 return -ENOMEM;
Andrew Mortonb6136772006-06-25 05:47:49 -0700542
Andrew Mortone18f3ff2007-05-09 02:33:50 -0700543 preempt_disable(); /* CPU hotplug */
Christoph Lameter15316ba2006-01-08 01:00:43 -0800544 for_each_online_cpu(cpu) {
Ingo Molnar9bfb1832006-12-18 20:05:09 +0100545 struct work_struct *work = per_cpu_ptr(works, cpu);
546
547 INIT_WORK(work, func);
548 set_bit(WORK_STRUCT_PENDING, work_data_bits(work));
549 __queue_work(per_cpu_ptr(keventd_wq->cpu_wq, cpu), work);
Christoph Lameter15316ba2006-01-08 01:00:43 -0800550 }
Andrew Mortone18f3ff2007-05-09 02:33:50 -0700551 preempt_enable();
Christoph Lameter15316ba2006-01-08 01:00:43 -0800552 flush_workqueue(keventd_wq);
Andrew Mortonb6136772006-06-25 05:47:49 -0700553 free_percpu(works);
Christoph Lameter15316ba2006-01-08 01:00:43 -0800554 return 0;
555}
556
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557void flush_scheduled_work(void)
558{
559 flush_workqueue(keventd_wq);
560}
Dave Jonesae90dd52006-06-30 01:40:45 -0400561EXPORT_SYMBOL(flush_scheduled_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Oleg Nesterovb89deed2007-05-09 02:33:52 -0700563void flush_work_keventd(struct work_struct *work)
564{
565 flush_work(keventd_wq, work);
566}
567EXPORT_SYMBOL(flush_work_keventd);
568
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569/**
Oleg Nesteroved7c0fe2007-05-09 02:34:16 -0700570 * cancel_rearming_delayed_workqueue - kill off a delayed work whose handler rearms the delayed work.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 * @wq: the controlling workqueue structure
David Howells52bad642006-11-22 14:54:01 +0000572 * @dwork: the delayed work struct
Oleg Nesteroved7c0fe2007-05-09 02:34:16 -0700573 *
574 * Note that the work callback function may still be running on return from
575 * cancel_delayed_work(). Run flush_workqueue() or flush_work() to wait on it.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 */
James Bottomley81ddef72005-04-16 15:23:59 -0700577void cancel_rearming_delayed_workqueue(struct workqueue_struct *wq,
David Howells52bad642006-11-22 14:54:01 +0000578 struct delayed_work *dwork)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579{
Oleg Nesterovdfb4b822007-05-09 02:34:11 -0700580 /* Was it ever queued ? */
581 if (!get_wq_data(&dwork->work))
582 return;
583
David Howells52bad642006-11-22 14:54:01 +0000584 while (!cancel_delayed_work(dwork))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 flush_workqueue(wq);
586}
James Bottomley81ddef72005-04-16 15:23:59 -0700587EXPORT_SYMBOL(cancel_rearming_delayed_workqueue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
589/**
Oleg Nesteroved7c0fe2007-05-09 02:34:16 -0700590 * cancel_rearming_delayed_work - kill off a delayed keventd work whose handler rearms the delayed work.
David Howells52bad642006-11-22 14:54:01 +0000591 * @dwork: the delayed work struct
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 */
David Howells52bad642006-11-22 14:54:01 +0000593void cancel_rearming_delayed_work(struct delayed_work *dwork)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594{
David Howells52bad642006-11-22 14:54:01 +0000595 cancel_rearming_delayed_workqueue(keventd_wq, dwork);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596}
597EXPORT_SYMBOL(cancel_rearming_delayed_work);
598
James Bottomley1fa44ec2006-02-23 12:43:43 -0600599/**
600 * execute_in_process_context - reliably execute the routine with user context
601 * @fn: the function to execute
James Bottomley1fa44ec2006-02-23 12:43:43 -0600602 * @ew: guaranteed storage for the execute work structure (must
603 * be available when the work executes)
604 *
605 * Executes the function immediately if process context is available,
606 * otherwise schedules the function for delayed execution.
607 *
608 * Returns: 0 - function was executed
609 * 1 - function was scheduled for execution
610 */
David Howells65f27f32006-11-22 14:55:48 +0000611int execute_in_process_context(work_func_t fn, struct execute_work *ew)
James Bottomley1fa44ec2006-02-23 12:43:43 -0600612{
613 if (!in_interrupt()) {
David Howells65f27f32006-11-22 14:55:48 +0000614 fn(&ew->work);
James Bottomley1fa44ec2006-02-23 12:43:43 -0600615 return 0;
616 }
617
David Howells65f27f32006-11-22 14:55:48 +0000618 INIT_WORK(&ew->work, fn);
James Bottomley1fa44ec2006-02-23 12:43:43 -0600619 schedule_work(&ew->work);
620
621 return 1;
622}
623EXPORT_SYMBOL_GPL(execute_in_process_context);
624
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625int keventd_up(void)
626{
627 return keventd_wq != NULL;
628}
629
630int current_is_keventd(void)
631{
632 struct cpu_workqueue_struct *cwq;
633 int cpu = smp_processor_id(); /* preempt-safe: keventd is per-cpu */
634 int ret = 0;
635
636 BUG_ON(!keventd_wq);
637
Christoph Lameter89ada672005-10-30 15:01:59 -0800638 cwq = per_cpu_ptr(keventd_wq->cpu_wq, cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 if (current == cwq->thread)
640 ret = 1;
641
642 return ret;
643
644}
645
Oleg Nesterov3af244332007-05-09 02:34:09 -0700646static struct cpu_workqueue_struct *
647init_cpu_workqueue(struct workqueue_struct *wq, int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648{
Christoph Lameter89ada672005-10-30 15:01:59 -0800649 struct cpu_workqueue_struct *cwq = per_cpu_ptr(wq->cpu_wq, cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
Oleg Nesterov3af244332007-05-09 02:34:09 -0700651 cwq->wq = wq;
652 spin_lock_init(&cwq->lock);
653 INIT_LIST_HEAD(&cwq->worklist);
654 init_waitqueue_head(&cwq->more_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
Oleg Nesterov3af244332007-05-09 02:34:09 -0700656 return cwq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657}
658
Oleg Nesterov3af244332007-05-09 02:34:09 -0700659static int create_workqueue_thread(struct cpu_workqueue_struct *cwq, int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660{
Oleg Nesterov3af244332007-05-09 02:34:09 -0700661 struct workqueue_struct *wq = cwq->wq;
662 const char *fmt = is_single_threaded(wq) ? "%s" : "%s/%d";
663 struct task_struct *p;
664
665 p = kthread_create(worker_thread, cwq, fmt, wq->name, cpu);
666 /*
667 * Nobody can add the work_struct to this cwq,
668 * if (caller is __create_workqueue)
669 * nobody should see this wq
670 * else // caller is CPU_UP_PREPARE
671 * cpu is not on cpu_online_map
672 * so we can abort safely.
673 */
674 if (IS_ERR(p))
675 return PTR_ERR(p);
676
677 cwq->thread = p;
678 cwq->should_stop = 0;
Oleg Nesterov3af244332007-05-09 02:34:09 -0700679
680 return 0;
681}
682
Oleg Nesterov06ba38a2007-05-09 02:34:15 -0700683static void start_workqueue_thread(struct cpu_workqueue_struct *cwq, int cpu)
684{
685 struct task_struct *p = cwq->thread;
686
687 if (p != NULL) {
688 if (cpu >= 0)
689 kthread_bind(p, cpu);
690 wake_up_process(p);
691 }
692}
693
Oleg Nesterov3af244332007-05-09 02:34:09 -0700694struct workqueue_struct *__create_workqueue(const char *name,
695 int singlethread, int freezeable)
696{
697 struct workqueue_struct *wq;
698 struct cpu_workqueue_struct *cwq;
699 int err = 0, cpu;
700
701 wq = kzalloc(sizeof(*wq), GFP_KERNEL);
702 if (!wq)
703 return NULL;
704
705 wq->cpu_wq = alloc_percpu(struct cpu_workqueue_struct);
706 if (!wq->cpu_wq) {
707 kfree(wq);
708 return NULL;
709 }
710
711 wq->name = name;
Oleg Nesterovcce1a162007-05-09 02:34:13 -0700712 wq->singlethread = singlethread;
Oleg Nesterov3af244332007-05-09 02:34:09 -0700713 wq->freezeable = freezeable;
Oleg Nesterovcce1a162007-05-09 02:34:13 -0700714 INIT_LIST_HEAD(&wq->list);
Oleg Nesterov3af244332007-05-09 02:34:09 -0700715
716 if (singlethread) {
Oleg Nesterov3af244332007-05-09 02:34:09 -0700717 cwq = init_cpu_workqueue(wq, singlethread_cpu);
718 err = create_workqueue_thread(cwq, singlethread_cpu);
Oleg Nesterov06ba38a2007-05-09 02:34:15 -0700719 start_workqueue_thread(cwq, -1);
Oleg Nesterov3af244332007-05-09 02:34:09 -0700720 } else {
721 mutex_lock(&workqueue_mutex);
722 list_add(&wq->list, &workqueues);
723
724 for_each_possible_cpu(cpu) {
725 cwq = init_cpu_workqueue(wq, cpu);
726 if (err || !cpu_online(cpu))
727 continue;
728 err = create_workqueue_thread(cwq, cpu);
Oleg Nesterov06ba38a2007-05-09 02:34:15 -0700729 start_workqueue_thread(cwq, cpu);
Oleg Nesterov3af244332007-05-09 02:34:09 -0700730 }
731 mutex_unlock(&workqueue_mutex);
732 }
733
734 if (err) {
735 destroy_workqueue(wq);
736 wq = NULL;
737 }
738 return wq;
739}
740EXPORT_SYMBOL_GPL(__create_workqueue);
741
742static void cleanup_workqueue_thread(struct cpu_workqueue_struct *cwq, int cpu)
743{
744 struct wq_barrier barr;
745 int alive = 0;
746
747 spin_lock_irq(&cwq->lock);
748 if (cwq->thread != NULL) {
749 insert_wq_barrier(cwq, &barr, 1);
750 cwq->should_stop = 1;
751 alive = 1;
752 }
753 spin_unlock_irq(&cwq->lock);
754
755 if (alive) {
756 wait_for_completion(&barr.done);
757
758 while (unlikely(cwq->thread != NULL))
759 cpu_relax();
760 /*
761 * Wait until cwq->thread unlocks cwq->lock,
762 * it won't touch *cwq after that.
763 */
764 smp_rmb();
765 spin_unlock_wait(&cwq->lock);
766 }
767}
768
769/**
770 * destroy_workqueue - safely terminate a workqueue
771 * @wq: target workqueue
772 *
773 * Safely destroy a workqueue. All work currently pending will be done first.
774 */
775void destroy_workqueue(struct workqueue_struct *wq)
776{
Oleg Nesterovb1f4ec172007-05-09 02:34:12 -0700777 const cpumask_t *cpu_map = wq_cpu_map(wq);
Oleg Nesterov3af244332007-05-09 02:34:09 -0700778 struct cpu_workqueue_struct *cwq;
Oleg Nesterovb1f4ec172007-05-09 02:34:12 -0700779 int cpu;
Oleg Nesterov3af244332007-05-09 02:34:09 -0700780
Oleg Nesterovb1f4ec172007-05-09 02:34:12 -0700781 mutex_lock(&workqueue_mutex);
782 list_del(&wq->list);
783 mutex_unlock(&workqueue_mutex);
Oleg Nesterov3af244332007-05-09 02:34:09 -0700784
Oleg Nesterovb1f4ec172007-05-09 02:34:12 -0700785 for_each_cpu_mask(cpu, *cpu_map) {
786 cwq = per_cpu_ptr(wq->cpu_wq, cpu);
787 cleanup_workqueue_thread(cwq, cpu);
Oleg Nesterov3af244332007-05-09 02:34:09 -0700788 }
789
790 free_percpu(wq->cpu_wq);
791 kfree(wq);
792}
793EXPORT_SYMBOL_GPL(destroy_workqueue);
794
795static int __devinit workqueue_cpu_callback(struct notifier_block *nfb,
796 unsigned long action,
797 void *hcpu)
798{
799 unsigned int cpu = (unsigned long)hcpu;
800 struct cpu_workqueue_struct *cwq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 struct workqueue_struct *wq;
802
803 switch (action) {
Oleg Nesterov3af244332007-05-09 02:34:09 -0700804 case CPU_LOCK_ACQUIRE:
805 mutex_lock(&workqueue_mutex);
806 return NOTIFY_OK;
807
808 case CPU_LOCK_RELEASE:
809 mutex_unlock(&workqueue_mutex);
810 return NOTIFY_OK;
811
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 case CPU_UP_PREPARE:
Oleg Nesterov3af244332007-05-09 02:34:09 -0700813 cpu_set(cpu, cpu_populated_map);
814 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
Oleg Nesterov3af244332007-05-09 02:34:09 -0700816 list_for_each_entry(wq, &workqueues, list) {
817 cwq = per_cpu_ptr(wq->cpu_wq, cpu);
Christoph Lameter89ada672005-10-30 15:01:59 -0800818
Oleg Nesterov3af244332007-05-09 02:34:09 -0700819 switch (action) {
820 case CPU_UP_PREPARE:
821 if (!create_workqueue_thread(cwq, cpu))
822 break;
823 printk(KERN_ERR "workqueue for %i failed\n", cpu);
824 return NOTIFY_BAD;
825
826 case CPU_ONLINE:
Oleg Nesterov06ba38a2007-05-09 02:34:15 -0700827 start_workqueue_thread(cwq, cpu);
Oleg Nesterov3af244332007-05-09 02:34:09 -0700828 break;
829
830 case CPU_UP_CANCELED:
Oleg Nesterov06ba38a2007-05-09 02:34:15 -0700831 start_workqueue_thread(cwq, -1);
Oleg Nesterov3af244332007-05-09 02:34:09 -0700832 case CPU_DEAD:
833 cleanup_workqueue_thread(cwq, cpu);
834 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 }
837
838 return NOTIFY_OK;
839}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
Oleg Nesterovc12920d2007-05-09 02:34:14 -0700841void __init init_workqueues(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842{
Oleg Nesterov3af244332007-05-09 02:34:09 -0700843 cpu_populated_map = cpu_online_map;
Nathan Lynchf756d5e2006-01-08 01:05:12 -0800844 singlethread_cpu = first_cpu(cpu_possible_map);
Oleg Nesterovb1f4ec172007-05-09 02:34:12 -0700845 cpu_singlethread_map = cpumask_of_cpu(singlethread_cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 hotcpu_notifier(workqueue_cpu_callback, 0);
847 keventd_wq = create_workqueue("events");
848 BUG_ON(!keventd_wq);
849}