2 * linux/kernel/workqueue.c
4 * Generic mechanism for defining kernel helper threads for running
5 * arbitrary tasks in process context.
7 * Started by Ingo Molnar, Copyright (C) 2002
9 * Derived from the taskqueue/keventd code by:
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>
16 * Made to use alloc_percpu by Christoph Lameter <clameter@sgi.com>.
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>
30 #include <linux/hardirq.h>
31 #include <linux/mempolicy.h>
32 #include <linux/freezer.h>
33 #include <linux/kallsyms.h>
34 #include <linux/debug_locks.h>
37 * The per-CPU workqueue (if single thread, we always use the first
40 struct cpu_workqueue_struct {
44 struct list_head worklist;
45 wait_queue_head_t more_work;
47 struct workqueue_struct *wq;
48 struct task_struct *thread;
49 struct work_struct *current_work;
51 int run_depth; /* Detect run_workqueue() recursion depth */
52 } ____cacheline_aligned;
55 * The externally visible workqueue abstraction is an array of
58 struct workqueue_struct {
59 struct cpu_workqueue_struct *cpu_wq;
61 struct list_head list; /* Empty if single thread */
62 int freezeable; /* Freeze threads during suspend */
65 /* All the per-cpu workqueues on the system, for hotplug cpu to add/remove
66 threads to each one as cpus come/go. */
67 static long migrate_sequence __read_mostly;
68 static DEFINE_MUTEX(workqueue_mutex);
69 static LIST_HEAD(workqueues);
71 static int singlethread_cpu;
73 /* If it's single threaded, it isn't in the list of workqueues. */
74 static inline int is_single_threaded(struct workqueue_struct *wq)
76 return list_empty(&wq->list);
80 * Set the workqueue on which a work item is to be run
81 * - Must *only* be called if the pending flag is set
83 static inline void set_wq_data(struct work_struct *work, void *wq)
87 BUG_ON(!work_pending(work));
89 new = (unsigned long) wq | (1UL << WORK_STRUCT_PENDING);
90 new |= WORK_STRUCT_FLAG_MASK & *work_data_bits(work);
91 atomic_long_set(&work->data, new);
94 static inline void *get_wq_data(struct work_struct *work)
96 return (void *) (atomic_long_read(&work->data) & WORK_STRUCT_WQ_DATA_MASK);
99 static int __run_work(struct cpu_workqueue_struct *cwq, struct work_struct *work)
104 spin_lock_irqsave(&cwq->lock, flags);
106 * We need to re-validate the work info after we've gotten
107 * the cpu_workqueue lock. We can run the work now iff:
109 * - the wq_data still matches the cpu_workqueue_struct
110 * - AND the work is still marked pending
111 * - AND the work is still on a list (which will be this
112 * workqueue_struct list)
114 * All these conditions are important, because we
115 * need to protect against the work being run right
116 * now on another CPU (all but the last one might be
117 * true if it's currently running and has not been
118 * released yet, for example).
120 if (get_wq_data(work) == cwq
121 && work_pending(work)
122 && !list_empty(&work->entry)) {
123 work_func_t f = work->func;
124 cwq->current_work = work;
125 list_del_init(&work->entry);
126 spin_unlock_irqrestore(&cwq->lock, flags);
128 if (!test_bit(WORK_STRUCT_NOAUTOREL, work_data_bits(work)))
132 spin_lock_irqsave(&cwq->lock, flags);
133 cwq->current_work = NULL;
136 spin_unlock_irqrestore(&cwq->lock, flags);
141 * run_scheduled_work - run scheduled work synchronously
144 * This checks if the work was pending, and runs it
145 * synchronously if so. It returns a boolean to indicate
146 * whether it had any scheduled work to run or not.
148 * NOTE! This _only_ works for normal work_structs. You
149 * CANNOT use this for delayed work, because the wq data
150 * for delayed work will not point properly to the per-
151 * CPU workqueue struct, but will change!
153 int fastcall run_scheduled_work(struct work_struct *work)
156 struct cpu_workqueue_struct *cwq;
158 if (!work_pending(work))
160 if (list_empty(&work->entry))
162 /* NOTE! This depends intimately on __queue_work! */
163 cwq = get_wq_data(work);
166 if (__run_work(cwq, work))
170 EXPORT_SYMBOL(run_scheduled_work);
172 static void insert_work(struct cpu_workqueue_struct *cwq,
173 struct work_struct *work, int tail)
175 set_wq_data(work, cwq);
177 list_add_tail(&work->entry, &cwq->worklist);
179 list_add(&work->entry, &cwq->worklist);
180 wake_up(&cwq->more_work);
183 /* Preempt must be disabled. */
184 static void __queue_work(struct cpu_workqueue_struct *cwq,
185 struct work_struct *work)
189 spin_lock_irqsave(&cwq->lock, flags);
190 insert_work(cwq, work, 1);
191 spin_unlock_irqrestore(&cwq->lock, flags);
195 * queue_work - queue work on a workqueue
196 * @wq: workqueue to use
197 * @work: work to queue
199 * Returns 0 if @work was already on a queue, non-zero otherwise.
201 * We queue the work to the CPU it was submitted, but there is no
202 * guarantee that it will be processed by that CPU.
204 int fastcall queue_work(struct workqueue_struct *wq, struct work_struct *work)
206 int ret = 0, cpu = get_cpu();
208 if (!test_and_set_bit(WORK_STRUCT_PENDING, work_data_bits(work))) {
209 if (unlikely(is_single_threaded(wq)))
210 cpu = singlethread_cpu;
211 BUG_ON(!list_empty(&work->entry));
212 __queue_work(per_cpu_ptr(wq->cpu_wq, cpu), work);
218 EXPORT_SYMBOL_GPL(queue_work);
220 void delayed_work_timer_fn(unsigned long __data)
222 struct delayed_work *dwork = (struct delayed_work *)__data;
223 struct workqueue_struct *wq = get_wq_data(&dwork->work);
224 int cpu = smp_processor_id();
226 if (unlikely(is_single_threaded(wq)))
227 cpu = singlethread_cpu;
229 __queue_work(per_cpu_ptr(wq->cpu_wq, cpu), &dwork->work);
233 * queue_delayed_work - queue work on a workqueue after delay
234 * @wq: workqueue to use
235 * @dwork: delayable work to queue
236 * @delay: number of jiffies to wait before queueing
238 * Returns 0 if @work was already on a queue, non-zero otherwise.
240 int fastcall queue_delayed_work(struct workqueue_struct *wq,
241 struct delayed_work *dwork, unsigned long delay)
244 struct timer_list *timer = &dwork->timer;
245 struct work_struct *work = &dwork->work;
247 timer_stats_timer_set_start_info(timer);
249 return queue_work(wq, work);
251 if (!test_and_set_bit(WORK_STRUCT_PENDING, work_data_bits(work))) {
252 BUG_ON(timer_pending(timer));
253 BUG_ON(!list_empty(&work->entry));
255 /* This stores wq for the moment, for the timer_fn */
256 set_wq_data(work, wq);
257 timer->expires = jiffies + delay;
258 timer->data = (unsigned long)dwork;
259 timer->function = delayed_work_timer_fn;
265 EXPORT_SYMBOL_GPL(queue_delayed_work);
268 * queue_delayed_work_on - queue work on specific CPU after delay
269 * @cpu: CPU number to execute work on
270 * @wq: workqueue to use
271 * @dwork: work to queue
272 * @delay: number of jiffies to wait before queueing
274 * Returns 0 if @work was already on a queue, non-zero otherwise.
276 int queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
277 struct delayed_work *dwork, unsigned long delay)
280 struct timer_list *timer = &dwork->timer;
281 struct work_struct *work = &dwork->work;
283 if (!test_and_set_bit(WORK_STRUCT_PENDING, work_data_bits(work))) {
284 BUG_ON(timer_pending(timer));
285 BUG_ON(!list_empty(&work->entry));
287 /* This stores wq for the moment, for the timer_fn */
288 set_wq_data(work, wq);
289 timer->expires = jiffies + delay;
290 timer->data = (unsigned long)dwork;
291 timer->function = delayed_work_timer_fn;
292 add_timer_on(timer, cpu);
297 EXPORT_SYMBOL_GPL(queue_delayed_work_on);
299 static void run_workqueue(struct cpu_workqueue_struct *cwq)
304 * Keep taking off work from the queue until
307 spin_lock_irqsave(&cwq->lock, flags);
309 if (cwq->run_depth > 3) {
310 /* morton gets to eat his hat */
311 printk("%s: recursion depth exceeded: %d\n",
312 __FUNCTION__, cwq->run_depth);
315 while (!list_empty(&cwq->worklist)) {
316 struct work_struct *work = list_entry(cwq->worklist.next,
317 struct work_struct, entry);
318 work_func_t f = work->func;
320 cwq->current_work = work;
321 list_del_init(cwq->worklist.next);
322 spin_unlock_irqrestore(&cwq->lock, flags);
324 BUG_ON(get_wq_data(work) != cwq);
325 if (!test_bit(WORK_STRUCT_NOAUTOREL, work_data_bits(work)))
329 if (unlikely(in_atomic() || lockdep_depth(current) > 0)) {
330 printk(KERN_ERR "BUG: workqueue leaked lock or atomic: "
332 current->comm, preempt_count(),
334 printk(KERN_ERR " last function: ");
335 print_symbol("%s\n", (unsigned long)f);
336 debug_show_held_locks(current);
340 spin_lock_irqsave(&cwq->lock, flags);
341 cwq->current_work = NULL;
344 spin_unlock_irqrestore(&cwq->lock, flags);
347 static int worker_thread(void *__cwq)
349 struct cpu_workqueue_struct *cwq = __cwq;
350 DECLARE_WAITQUEUE(wait, current);
351 struct k_sigaction sa;
354 if (!cwq->wq->freezeable)
355 current->flags |= PF_NOFREEZE;
357 set_user_nice(current, -5);
359 /* Block and flush all signals */
360 sigfillset(&blocked);
361 sigprocmask(SIG_BLOCK, &blocked, NULL);
362 flush_signals(current);
365 * We inherited MPOL_INTERLEAVE from the booting kernel.
366 * Set MPOL_DEFAULT to insure node local allocations.
368 numa_default_policy();
370 /* SIG_IGN makes children autoreap: see do_notify_parent(). */
371 sa.sa.sa_handler = SIG_IGN;
373 siginitset(&sa.sa.sa_mask, sigmask(SIGCHLD));
374 do_sigaction(SIGCHLD, &sa, (struct k_sigaction *)0);
376 set_current_state(TASK_INTERRUPTIBLE);
377 while (!kthread_should_stop()) {
378 if (cwq->wq->freezeable)
381 add_wait_queue(&cwq->more_work, &wait);
382 if (list_empty(&cwq->worklist))
385 __set_current_state(TASK_RUNNING);
386 remove_wait_queue(&cwq->more_work, &wait);
388 if (!list_empty(&cwq->worklist))
390 set_current_state(TASK_INTERRUPTIBLE);
392 __set_current_state(TASK_RUNNING);
397 struct work_struct work;
398 struct completion done;
401 static void wq_barrier_func(struct work_struct *work)
403 struct wq_barrier *barr = container_of(work, struct wq_barrier, work);
404 complete(&barr->done);
407 static void insert_wq_barrier(struct cpu_workqueue_struct *cwq,
408 struct wq_barrier *barr, int tail)
410 INIT_WORK(&barr->work, wq_barrier_func);
411 __set_bit(WORK_STRUCT_PENDING, work_data_bits(&barr->work));
413 init_completion(&barr->done);
415 insert_work(cwq, &barr->work, tail);
418 static void flush_cpu_workqueue(struct cpu_workqueue_struct *cwq)
420 if (cwq->thread == current) {
422 * Probably keventd trying to flush its own queue. So simply run
423 * it by hand rather than deadlocking.
427 struct wq_barrier barr;
430 spin_lock_irq(&cwq->lock);
431 if (!list_empty(&cwq->worklist) || cwq->current_work != NULL) {
432 insert_wq_barrier(cwq, &barr, 1);
435 spin_unlock_irq(&cwq->lock);
438 wait_for_completion(&barr.done);
443 * flush_workqueue - ensure that any scheduled work has run to completion.
444 * @wq: workqueue to flush
446 * Forces execution of the workqueue and blocks until its completion.
447 * This is typically used in driver shutdown handlers.
449 * We sleep until all works which were queued on entry have been handled,
450 * but we are not livelocked by new incoming ones.
452 * This function used to run the workqueues itself. Now we just wait for the
453 * helper threads to do it.
455 void fastcall flush_workqueue(struct workqueue_struct *wq)
457 if (is_single_threaded(wq)) {
458 /* Always use first cpu's area. */
459 flush_cpu_workqueue(per_cpu_ptr(wq->cpu_wq, singlethread_cpu));
464 sequence = migrate_sequence;
466 for_each_possible_cpu(cpu)
467 flush_cpu_workqueue(per_cpu_ptr(wq->cpu_wq, cpu));
469 if (unlikely(sequence != migrate_sequence))
473 EXPORT_SYMBOL_GPL(flush_workqueue);
475 static void wait_on_work(struct cpu_workqueue_struct *cwq,
476 struct work_struct *work)
478 struct wq_barrier barr;
481 spin_lock_irq(&cwq->lock);
482 if (unlikely(cwq->current_work == work)) {
483 insert_wq_barrier(cwq, &barr, 0);
486 spin_unlock_irq(&cwq->lock);
488 if (unlikely(running)) {
489 mutex_unlock(&workqueue_mutex);
490 wait_for_completion(&barr.done);
491 mutex_lock(&workqueue_mutex);
496 * flush_work - block until a work_struct's callback has terminated
497 * @wq: the workqueue on which the work is queued
498 * @work: the work which is to be flushed
500 * flush_work() will attempt to cancel the work if it is queued. If the work's
501 * callback appears to be running, flush_work() will block until it has
504 * flush_work() is designed to be used when the caller is tearing down data
505 * structures which the callback function operates upon. It is expected that,
506 * prior to calling flush_work(), the caller has arranged for the work to not
509 void flush_work(struct workqueue_struct *wq, struct work_struct *work)
511 struct cpu_workqueue_struct *cwq;
513 mutex_lock(&workqueue_mutex);
514 cwq = get_wq_data(work);
515 /* Was it ever queued ? */
520 * This work can't be re-queued, and the lock above protects us
521 * from take_over_work(), no need to re-check that get_wq_data()
522 * is still the same when we take cwq->lock.
524 spin_lock_irq(&cwq->lock);
525 list_del_init(&work->entry);
527 spin_unlock_irq(&cwq->lock);
529 if (is_single_threaded(wq)) {
530 /* Always use first cpu's area. */
531 wait_on_work(per_cpu_ptr(wq->cpu_wq, singlethread_cpu), work);
535 for_each_online_cpu(cpu)
536 wait_on_work(per_cpu_ptr(wq->cpu_wq, cpu), work);
539 mutex_unlock(&workqueue_mutex);
541 EXPORT_SYMBOL_GPL(flush_work);
543 static void init_cpu_workqueue(struct workqueue_struct *wq, int cpu)
545 struct cpu_workqueue_struct *cwq = per_cpu_ptr(wq->cpu_wq, cpu);
548 spin_lock_init(&cwq->lock);
549 INIT_LIST_HEAD(&cwq->worklist);
550 init_waitqueue_head(&cwq->more_work);
553 static struct task_struct *create_workqueue_thread(struct workqueue_struct *wq,
556 struct cpu_workqueue_struct *cwq = per_cpu_ptr(wq->cpu_wq, cpu);
557 struct task_struct *p;
559 if (is_single_threaded(wq))
560 p = kthread_create(worker_thread, cwq, "%s", wq->name);
562 p = kthread_create(worker_thread, cwq, "%s/%d", wq->name, cpu);
569 struct workqueue_struct *__create_workqueue(const char *name,
570 int singlethread, int freezeable)
572 int cpu, destroy = 0;
573 struct workqueue_struct *wq;
574 struct task_struct *p;
576 wq = kzalloc(sizeof(*wq), GFP_KERNEL);
580 wq->cpu_wq = alloc_percpu(struct cpu_workqueue_struct);
587 wq->freezeable = freezeable;
589 mutex_lock(&workqueue_mutex);
591 INIT_LIST_HEAD(&wq->list);
592 init_cpu_workqueue(wq, singlethread_cpu);
593 p = create_workqueue_thread(wq, singlethread_cpu);
599 list_add(&wq->list, &workqueues);
600 for_each_possible_cpu(cpu) {
601 init_cpu_workqueue(wq, cpu);
602 if (!cpu_online(cpu))
605 p = create_workqueue_thread(wq, cpu);
607 kthread_bind(p, cpu);
613 mutex_unlock(&workqueue_mutex);
616 * Was there any error during startup? If yes then clean up:
619 destroy_workqueue(wq);
624 EXPORT_SYMBOL_GPL(__create_workqueue);
626 static void cleanup_workqueue_thread(struct workqueue_struct *wq, int cpu)
628 struct cpu_workqueue_struct *cwq;
630 struct task_struct *p;
632 cwq = per_cpu_ptr(wq->cpu_wq, cpu);
633 spin_lock_irqsave(&cwq->lock, flags);
636 spin_unlock_irqrestore(&cwq->lock, flags);
642 * destroy_workqueue - safely terminate a workqueue
643 * @wq: target workqueue
645 * Safely destroy a workqueue. All work currently pending will be done first.
647 void destroy_workqueue(struct workqueue_struct *wq)
653 /* We don't need the distraction of CPUs appearing and vanishing. */
654 mutex_lock(&workqueue_mutex);
655 if (is_single_threaded(wq))
656 cleanup_workqueue_thread(wq, singlethread_cpu);
658 for_each_online_cpu(cpu)
659 cleanup_workqueue_thread(wq, cpu);
662 mutex_unlock(&workqueue_mutex);
663 free_percpu(wq->cpu_wq);
666 EXPORT_SYMBOL_GPL(destroy_workqueue);
668 static struct workqueue_struct *keventd_wq;
671 * schedule_work - put work task in global workqueue
672 * @work: job to be done
674 * This puts a job in the kernel-global workqueue.
676 int fastcall schedule_work(struct work_struct *work)
678 return queue_work(keventd_wq, work);
680 EXPORT_SYMBOL(schedule_work);
683 * schedule_delayed_work - put work task in global workqueue after delay
684 * @dwork: job to be done
685 * @delay: number of jiffies to wait or 0 for immediate execution
687 * After waiting for a given time this puts a job in the kernel-global
690 int fastcall schedule_delayed_work(struct delayed_work *dwork,
693 timer_stats_timer_set_start_info(&dwork->timer);
694 return queue_delayed_work(keventd_wq, dwork, delay);
696 EXPORT_SYMBOL(schedule_delayed_work);
699 * schedule_delayed_work_on - queue work in global workqueue on CPU after delay
701 * @dwork: job to be done
702 * @delay: number of jiffies to wait
704 * After waiting for a given time this puts a job in the kernel-global
705 * workqueue on the specified CPU.
707 int schedule_delayed_work_on(int cpu,
708 struct delayed_work *dwork, unsigned long delay)
710 return queue_delayed_work_on(cpu, keventd_wq, dwork, delay);
712 EXPORT_SYMBOL(schedule_delayed_work_on);
715 * schedule_on_each_cpu - call a function on each online CPU from keventd
716 * @func: the function to call
718 * Returns zero on success.
719 * Returns -ve errno on failure.
721 * Appears to be racy against CPU hotplug.
723 * schedule_on_each_cpu() is very slow.
725 int schedule_on_each_cpu(work_func_t func)
728 struct work_struct *works;
730 works = alloc_percpu(struct work_struct);
734 preempt_disable(); /* CPU hotplug */
735 for_each_online_cpu(cpu) {
736 struct work_struct *work = per_cpu_ptr(works, cpu);
738 INIT_WORK(work, func);
739 set_bit(WORK_STRUCT_PENDING, work_data_bits(work));
740 __queue_work(per_cpu_ptr(keventd_wq->cpu_wq, cpu), work);
743 flush_workqueue(keventd_wq);
748 void flush_scheduled_work(void)
750 flush_workqueue(keventd_wq);
752 EXPORT_SYMBOL(flush_scheduled_work);
754 void flush_work_keventd(struct work_struct *work)
756 flush_work(keventd_wq, work);
758 EXPORT_SYMBOL(flush_work_keventd);
761 * cancel_rearming_delayed_workqueue - reliably kill off a delayed work whose handler rearms the delayed work.
762 * @wq: the controlling workqueue structure
763 * @dwork: the delayed work struct
765 void cancel_rearming_delayed_workqueue(struct workqueue_struct *wq,
766 struct delayed_work *dwork)
768 while (!cancel_delayed_work(dwork))
771 EXPORT_SYMBOL(cancel_rearming_delayed_workqueue);
774 * cancel_rearming_delayed_work - reliably kill off a delayed keventd work whose handler rearms the delayed work.
775 * @dwork: the delayed work struct
777 void cancel_rearming_delayed_work(struct delayed_work *dwork)
779 cancel_rearming_delayed_workqueue(keventd_wq, dwork);
781 EXPORT_SYMBOL(cancel_rearming_delayed_work);
784 * execute_in_process_context - reliably execute the routine with user context
785 * @fn: the function to execute
786 * @ew: guaranteed storage for the execute work structure (must
787 * be available when the work executes)
789 * Executes the function immediately if process context is available,
790 * otherwise schedules the function for delayed execution.
792 * Returns: 0 - function was executed
793 * 1 - function was scheduled for execution
795 int execute_in_process_context(work_func_t fn, struct execute_work *ew)
797 if (!in_interrupt()) {
802 INIT_WORK(&ew->work, fn);
803 schedule_work(&ew->work);
807 EXPORT_SYMBOL_GPL(execute_in_process_context);
811 return keventd_wq != NULL;
814 int current_is_keventd(void)
816 struct cpu_workqueue_struct *cwq;
817 int cpu = smp_processor_id(); /* preempt-safe: keventd is per-cpu */
822 cwq = per_cpu_ptr(keventd_wq->cpu_wq, cpu);
823 if (current == cwq->thread)
830 /* Take the work from this (downed) CPU. */
831 static void take_over_work(struct workqueue_struct *wq, unsigned int cpu)
833 struct cpu_workqueue_struct *cwq = per_cpu_ptr(wq->cpu_wq, cpu);
834 struct list_head list;
835 struct work_struct *work;
837 spin_lock_irq(&cwq->lock);
838 list_replace_init(&cwq->worklist, &list);
841 while (!list_empty(&list)) {
842 printk("Taking work for %s\n", wq->name);
843 work = list_entry(list.next,struct work_struct,entry);
844 list_del(&work->entry);
845 __queue_work(per_cpu_ptr(wq->cpu_wq, smp_processor_id()), work);
847 spin_unlock_irq(&cwq->lock);
850 /* We're holding the cpucontrol mutex here */
851 static int __devinit workqueue_cpu_callback(struct notifier_block *nfb,
852 unsigned long action,
855 unsigned int hotcpu = (unsigned long)hcpu;
856 struct workqueue_struct *wq;
860 mutex_lock(&workqueue_mutex);
861 /* Create a new workqueue thread for it. */
862 list_for_each_entry(wq, &workqueues, list) {
863 if (!create_workqueue_thread(wq, hotcpu)) {
864 printk("workqueue for %i failed\n", hotcpu);
871 /* Kick off worker threads. */
872 list_for_each_entry(wq, &workqueues, list) {
873 struct cpu_workqueue_struct *cwq;
875 cwq = per_cpu_ptr(wq->cpu_wq, hotcpu);
876 kthread_bind(cwq->thread, hotcpu);
877 wake_up_process(cwq->thread);
879 mutex_unlock(&workqueue_mutex);
882 case CPU_UP_CANCELED:
883 list_for_each_entry(wq, &workqueues, list) {
884 if (!per_cpu_ptr(wq->cpu_wq, hotcpu)->thread)
886 /* Unbind so it can run. */
887 kthread_bind(per_cpu_ptr(wq->cpu_wq, hotcpu)->thread,
888 any_online_cpu(cpu_online_map));
889 cleanup_workqueue_thread(wq, hotcpu);
891 mutex_unlock(&workqueue_mutex);
894 case CPU_DOWN_PREPARE:
895 mutex_lock(&workqueue_mutex);
898 case CPU_DOWN_FAILED:
899 mutex_unlock(&workqueue_mutex);
903 list_for_each_entry(wq, &workqueues, list)
904 cleanup_workqueue_thread(wq, hotcpu);
905 list_for_each_entry(wq, &workqueues, list)
906 take_over_work(wq, hotcpu);
907 mutex_unlock(&workqueue_mutex);
914 void init_workqueues(void)
916 singlethread_cpu = first_cpu(cpu_possible_map);
917 hotcpu_notifier(workqueue_cpu_callback, 0);
918 keventd_wq = create_workqueue("events");