1 /* SPDX-License-Identifier: GPL-2.0 */
3 * workqueue.h --- work queue handling for Linux.
6 #ifndef _LINUX_WORKQUEUE_H
7 #define _LINUX_WORKQUEUE_H
9 #include <linux/timer.h>
10 #include <linux/linkage.h>
11 #include <linux/bitops.h>
12 #include <linux/lockdep.h>
13 #include <linux/threads.h>
14 #include <linux/atomic.h>
15 #include <linux/cpumask.h>
16 #include <linux/rcupdate.h>
17 #include <linux/workqueue_types.h>
20 * The first word is the work queue pointer and the flags rolled into
23 #define work_data_bits(work) ((unsigned long *)(&(work)->data))
26 WORK_STRUCT_PENDING_BIT = 0, /* work item is pending execution */
27 WORK_STRUCT_INACTIVE_BIT= 1, /* work item is inactive */
28 WORK_STRUCT_PWQ_BIT = 2, /* data points to pwq */
29 WORK_STRUCT_LINKED_BIT = 3, /* next work is linked to this one */
30 #ifdef CONFIG_DEBUG_OBJECTS_WORK
31 WORK_STRUCT_STATIC_BIT = 4, /* static initializer (debugobjects) */
32 WORK_STRUCT_COLOR_SHIFT = 5, /* color for workqueue flushing */
34 WORK_STRUCT_COLOR_SHIFT = 4, /* color for workqueue flushing */
37 WORK_STRUCT_COLOR_BITS = 4,
39 WORK_STRUCT_PENDING = 1 << WORK_STRUCT_PENDING_BIT,
40 WORK_STRUCT_INACTIVE = 1 << WORK_STRUCT_INACTIVE_BIT,
41 WORK_STRUCT_PWQ = 1 << WORK_STRUCT_PWQ_BIT,
42 WORK_STRUCT_LINKED = 1 << WORK_STRUCT_LINKED_BIT,
43 #ifdef CONFIG_DEBUG_OBJECTS_WORK
44 WORK_STRUCT_STATIC = 1 << WORK_STRUCT_STATIC_BIT,
46 WORK_STRUCT_STATIC = 0,
49 WORK_NR_COLORS = (1 << WORK_STRUCT_COLOR_BITS),
51 /* not bound to any CPU, prefer the local CPU */
52 WORK_CPU_UNBOUND = NR_CPUS,
55 * Reserve 8 bits off of pwq pointer w/ debugobjects turned off.
56 * This makes pwqs aligned to 256 bytes and allows 16 workqueue
59 WORK_STRUCT_FLAG_BITS = WORK_STRUCT_COLOR_SHIFT +
60 WORK_STRUCT_COLOR_BITS,
62 /* data contains off-queue information when !WORK_STRUCT_PWQ */
63 WORK_OFFQ_FLAG_BASE = WORK_STRUCT_COLOR_SHIFT,
65 __WORK_OFFQ_CANCELING = WORK_OFFQ_FLAG_BASE,
68 * When a work item is off queue, its high bits point to the last
69 * pool it was on. Cap at 31 bits and use the highest number to
70 * indicate that no pool is associated.
72 WORK_OFFQ_FLAG_BITS = 1,
73 WORK_OFFQ_POOL_SHIFT = WORK_OFFQ_FLAG_BASE + WORK_OFFQ_FLAG_BITS,
74 WORK_OFFQ_LEFT = BITS_PER_LONG - WORK_OFFQ_POOL_SHIFT,
75 WORK_OFFQ_POOL_BITS = WORK_OFFQ_LEFT <= 31 ? WORK_OFFQ_LEFT : 31,
77 /* bit mask for work_busy() return values */
78 WORK_BUSY_PENDING = 1 << 0,
79 WORK_BUSY_RUNNING = 1 << 1,
81 /* maximum string length for set_worker_desc() */
85 /* Convenience constants - of type 'unsigned long', not 'enum'! */
86 #define WORK_OFFQ_CANCELING (1ul << __WORK_OFFQ_CANCELING)
87 #define WORK_OFFQ_POOL_NONE ((1ul << WORK_OFFQ_POOL_BITS) - 1)
88 #define WORK_STRUCT_NO_POOL (WORK_OFFQ_POOL_NONE << WORK_OFFQ_POOL_SHIFT)
90 #define WORK_STRUCT_FLAG_MASK ((1ul << WORK_STRUCT_FLAG_BITS) - 1)
91 #define WORK_STRUCT_WQ_DATA_MASK (~WORK_STRUCT_FLAG_MASK)
93 #define WORK_DATA_INIT() ATOMIC_LONG_INIT((unsigned long)WORK_STRUCT_NO_POOL)
94 #define WORK_DATA_STATIC_INIT() \
95 ATOMIC_LONG_INIT((unsigned long)(WORK_STRUCT_NO_POOL | WORK_STRUCT_STATIC))
98 struct work_struct work;
99 struct timer_list timer;
101 /* target workqueue and CPU ->timer uses to queue ->work */
102 struct workqueue_struct *wq;
107 struct work_struct work;
110 /* target workqueue ->rcu uses to queue ->work */
111 struct workqueue_struct *wq;
115 WQ_AFFN_DFL, /* use system default */
116 WQ_AFFN_CPU, /* one pod per CPU */
117 WQ_AFFN_SMT, /* one pod poer SMT */
118 WQ_AFFN_CACHE, /* one pod per LLC */
119 WQ_AFFN_NUMA, /* one pod per NUMA node */
120 WQ_AFFN_SYSTEM, /* one pod across the whole system */
126 * struct workqueue_attrs - A struct for workqueue attributes.
128 * This can be used to change attributes of an unbound workqueue.
130 struct workqueue_attrs {
137 * @cpumask: allowed CPUs
139 * Work items in this workqueue are affine to these CPUs and not allowed
140 * to execute on other CPUs. A pool serving a workqueue must have the
143 cpumask_var_t cpumask;
146 * @__pod_cpumask: internal attribute used to create per-pod pools
150 * Per-pod unbound worker pools are used to improve locality. Always a
151 * subset of ->cpumask. A workqueue can be associated with multiple
152 * worker pools with disjoint @__pod_cpumask's. Whether the enforcement
153 * of a pool's @__pod_cpumask is strict depends on @affn_strict.
155 cpumask_var_t __pod_cpumask;
158 * @affn_strict: affinity scope is strict
160 * If clear, workqueue will make a best-effort attempt at starting the
161 * worker inside @__pod_cpumask but the scheduler is free to migrate it
164 * If set, workers are only allowed to run inside @__pod_cpumask.
169 * Below fields aren't properties of a worker_pool. They only modify how
170 * :c:func:`apply_workqueue_attrs` select pools and thus don't
171 * participate in pool hash calculations or equality comparisons.
175 * @affn_scope: unbound CPU affinity scope
177 * CPU pods are used to improve execution locality of unbound work
178 * items. There are multiple pod types, one for each wq_affn_scope, and
179 * every CPU in the system belongs to one pod in every pod type. CPUs
180 * that belong to the same pod share the worker pool. For example,
181 * selecting %WQ_AFFN_NUMA makes the workqueue use a separate worker
182 * pool for each NUMA node.
184 enum wq_affn_scope affn_scope;
187 * @ordered: work items must be executed one by one in queueing order
192 static inline struct delayed_work *to_delayed_work(struct work_struct *work)
194 return container_of(work, struct delayed_work, work);
197 static inline struct rcu_work *to_rcu_work(struct work_struct *work)
199 return container_of(work, struct rcu_work, work);
202 struct execute_work {
203 struct work_struct work;
206 #ifdef CONFIG_LOCKDEP
208 * NB: because we have to copy the lockdep_map, setting _key
209 * here is required, otherwise it could get initialised to the
210 * copy of the lockdep_map!
212 #define __WORK_INIT_LOCKDEP_MAP(n, k) \
213 .lockdep_map = STATIC_LOCKDEP_MAP_INIT(n, k),
215 #define __WORK_INIT_LOCKDEP_MAP(n, k)
218 #define __WORK_INITIALIZER(n, f) { \
219 .data = WORK_DATA_STATIC_INIT(), \
220 .entry = { &(n).entry, &(n).entry }, \
222 __WORK_INIT_LOCKDEP_MAP(#n, &(n)) \
225 #define __DELAYED_WORK_INITIALIZER(n, f, tflags) { \
226 .work = __WORK_INITIALIZER((n).work, (f)), \
227 .timer = __TIMER_INITIALIZER(delayed_work_timer_fn,\
228 (tflags) | TIMER_IRQSAFE), \
231 #define DECLARE_WORK(n, f) \
232 struct work_struct n = __WORK_INITIALIZER(n, f)
234 #define DECLARE_DELAYED_WORK(n, f) \
235 struct delayed_work n = __DELAYED_WORK_INITIALIZER(n, f, 0)
237 #define DECLARE_DEFERRABLE_WORK(n, f) \
238 struct delayed_work n = __DELAYED_WORK_INITIALIZER(n, f, TIMER_DEFERRABLE)
240 #ifdef CONFIG_DEBUG_OBJECTS_WORK
241 extern void __init_work(struct work_struct *work, int onstack);
242 extern void destroy_work_on_stack(struct work_struct *work);
243 extern void destroy_delayed_work_on_stack(struct delayed_work *work);
244 static inline unsigned int work_static(struct work_struct *work)
246 return *work_data_bits(work) & WORK_STRUCT_STATIC;
249 static inline void __init_work(struct work_struct *work, int onstack) { }
250 static inline void destroy_work_on_stack(struct work_struct *work) { }
251 static inline void destroy_delayed_work_on_stack(struct delayed_work *work) { }
252 static inline unsigned int work_static(struct work_struct *work) { return 0; }
256 * initialize all of a work item in one go
258 * NOTE! No point in using "atomic_long_set()": using a direct
259 * assignment of the work data initializer allows the compiler
260 * to generate better code.
262 #ifdef CONFIG_LOCKDEP
263 #define __INIT_WORK_KEY(_work, _func, _onstack, _key) \
265 __init_work((_work), _onstack); \
266 (_work)->data = (atomic_long_t) WORK_DATA_INIT(); \
267 lockdep_init_map(&(_work)->lockdep_map, "(work_completion)"#_work, (_key), 0); \
268 INIT_LIST_HEAD(&(_work)->entry); \
269 (_work)->func = (_func); \
272 #define __INIT_WORK_KEY(_work, _func, _onstack, _key) \
274 __init_work((_work), _onstack); \
275 (_work)->data = (atomic_long_t) WORK_DATA_INIT(); \
276 INIT_LIST_HEAD(&(_work)->entry); \
277 (_work)->func = (_func); \
281 #define __INIT_WORK(_work, _func, _onstack) \
283 static __maybe_unused struct lock_class_key __key; \
285 __INIT_WORK_KEY(_work, _func, _onstack, &__key); \
288 #define INIT_WORK(_work, _func) \
289 __INIT_WORK((_work), (_func), 0)
291 #define INIT_WORK_ONSTACK(_work, _func) \
292 __INIT_WORK((_work), (_func), 1)
294 #define INIT_WORK_ONSTACK_KEY(_work, _func, _key) \
295 __INIT_WORK_KEY((_work), (_func), 1, _key)
297 #define __INIT_DELAYED_WORK(_work, _func, _tflags) \
299 INIT_WORK(&(_work)->work, (_func)); \
300 __init_timer(&(_work)->timer, \
301 delayed_work_timer_fn, \
302 (_tflags) | TIMER_IRQSAFE); \
305 #define __INIT_DELAYED_WORK_ONSTACK(_work, _func, _tflags) \
307 INIT_WORK_ONSTACK(&(_work)->work, (_func)); \
308 __init_timer_on_stack(&(_work)->timer, \
309 delayed_work_timer_fn, \
310 (_tflags) | TIMER_IRQSAFE); \
313 #define INIT_DELAYED_WORK(_work, _func) \
314 __INIT_DELAYED_WORK(_work, _func, 0)
316 #define INIT_DELAYED_WORK_ONSTACK(_work, _func) \
317 __INIT_DELAYED_WORK_ONSTACK(_work, _func, 0)
319 #define INIT_DEFERRABLE_WORK(_work, _func) \
320 __INIT_DELAYED_WORK(_work, _func, TIMER_DEFERRABLE)
322 #define INIT_DEFERRABLE_WORK_ONSTACK(_work, _func) \
323 __INIT_DELAYED_WORK_ONSTACK(_work, _func, TIMER_DEFERRABLE)
325 #define INIT_RCU_WORK(_work, _func) \
326 INIT_WORK(&(_work)->work, (_func))
328 #define INIT_RCU_WORK_ONSTACK(_work, _func) \
329 INIT_WORK_ONSTACK(&(_work)->work, (_func))
332 * work_pending - Find out whether a work item is currently pending
333 * @work: The work item in question
335 #define work_pending(work) \
336 test_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))
339 * delayed_work_pending - Find out whether a delayable work item is currently
341 * @w: The work item in question
343 #define delayed_work_pending(w) \
344 work_pending(&(w)->work)
347 * Workqueue flags and constants. For details, please refer to
348 * Documentation/core-api/workqueue.rst.
351 WQ_UNBOUND = 1 << 1, /* not bound to any cpu */
352 WQ_FREEZABLE = 1 << 2, /* freeze during suspend */
353 WQ_MEM_RECLAIM = 1 << 3, /* may be used for memory reclaim */
354 WQ_HIGHPRI = 1 << 4, /* high priority */
355 WQ_CPU_INTENSIVE = 1 << 5, /* cpu intensive workqueue */
356 WQ_SYSFS = 1 << 6, /* visible in sysfs, see workqueue_sysfs_register() */
359 * Per-cpu workqueues are generally preferred because they tend to
360 * show better performance thanks to cache locality. Per-cpu
361 * workqueues exclude the scheduler from choosing the CPU to
362 * execute the worker threads, which has an unfortunate side effect
363 * of increasing power consumption.
365 * The scheduler considers a CPU idle if it doesn't have any task
366 * to execute and tries to keep idle cores idle to conserve power;
367 * however, for example, a per-cpu work item scheduled from an
368 * interrupt handler on an idle CPU will force the scheduler to
369 * execute the work item on that CPU breaking the idleness, which in
370 * turn may lead to more scheduling choices which are sub-optimal
371 * in terms of power consumption.
373 * Workqueues marked with WQ_POWER_EFFICIENT are per-cpu by default
374 * but become unbound if workqueue.power_efficient kernel param is
375 * specified. Per-cpu workqueues which are identified to
376 * contribute significantly to power-consumption are identified and
377 * marked with this flag and enabling the power_efficient mode
378 * leads to noticeable power saving at the cost of small
379 * performance disadvantage.
381 * http://thread.gmane.org/gmane.linux.kernel/1480396
383 WQ_POWER_EFFICIENT = 1 << 7,
385 __WQ_DESTROYING = 1 << 15, /* internal: workqueue is destroying */
386 __WQ_DRAINING = 1 << 16, /* internal: workqueue is draining */
387 __WQ_ORDERED = 1 << 17, /* internal: workqueue is ordered */
388 __WQ_LEGACY = 1 << 18, /* internal: create*_workqueue() */
389 __WQ_ORDERED_EXPLICIT = 1 << 19, /* internal: alloc_ordered_workqueue() */
391 WQ_MAX_ACTIVE = 512, /* I like 512, better ideas? */
392 WQ_UNBOUND_MAX_ACTIVE = WQ_MAX_ACTIVE,
393 WQ_DFL_ACTIVE = WQ_MAX_ACTIVE / 2,
397 * System-wide workqueues which are always present.
399 * system_wq is the one used by schedule[_delayed]_work[_on]().
400 * Multi-CPU multi-threaded. There are users which expect relatively
401 * short queue flush time. Don't queue works which can run for too
404 * system_highpri_wq is similar to system_wq but for work items which
405 * require WQ_HIGHPRI.
407 * system_long_wq is similar to system_wq but may host long running
408 * works. Queue flushing might take relatively long.
410 * system_unbound_wq is unbound workqueue. Workers are not bound to
411 * any specific CPU, not concurrency managed, and all queued works are
412 * executed immediately as long as max_active limit is not reached and
413 * resources are available.
415 * system_freezable_wq is equivalent to system_wq except that it's
418 * *_power_efficient_wq are inclined towards saving power and converted
419 * into WQ_UNBOUND variants if 'wq_power_efficient' is enabled; otherwise,
420 * they are same as their non-power-efficient counterparts - e.g.
421 * system_power_efficient_wq is identical to system_wq if
422 * 'wq_power_efficient' is disabled. See WQ_POWER_EFFICIENT for more info.
424 extern struct workqueue_struct *system_wq;
425 extern struct workqueue_struct *system_highpri_wq;
426 extern struct workqueue_struct *system_long_wq;
427 extern struct workqueue_struct *system_unbound_wq;
428 extern struct workqueue_struct *system_freezable_wq;
429 extern struct workqueue_struct *system_power_efficient_wq;
430 extern struct workqueue_struct *system_freezable_power_efficient_wq;
433 * alloc_workqueue - allocate a workqueue
434 * @fmt: printf format for the name of the workqueue
436 * @max_active: max in-flight work items per CPU, 0 for default
437 * remaining args: args for @fmt
439 * Allocate a workqueue with the specified parameters. For detailed
440 * information on WQ_* flags, please refer to
441 * Documentation/core-api/workqueue.rst.
444 * Pointer to the allocated workqueue on success, %NULL on failure.
446 __printf(1, 4) struct workqueue_struct *
447 alloc_workqueue(const char *fmt, unsigned int flags, int max_active, ...);
450 * alloc_ordered_workqueue - allocate an ordered workqueue
451 * @fmt: printf format for the name of the workqueue
452 * @flags: WQ_* flags (only WQ_FREEZABLE and WQ_MEM_RECLAIM are meaningful)
453 * @args: args for @fmt
455 * Allocate an ordered workqueue. An ordered workqueue executes at
456 * most one work item at any given time in the queued order. They are
457 * implemented as unbound workqueues with @max_active of one.
460 * Pointer to the allocated workqueue on success, %NULL on failure.
462 #define alloc_ordered_workqueue(fmt, flags, args...) \
463 alloc_workqueue(fmt, WQ_UNBOUND | __WQ_ORDERED | \
464 __WQ_ORDERED_EXPLICIT | (flags), 1, ##args)
466 #define create_workqueue(name) \
467 alloc_workqueue("%s", __WQ_LEGACY | WQ_MEM_RECLAIM, 1, (name))
468 #define create_freezable_workqueue(name) \
469 alloc_workqueue("%s", __WQ_LEGACY | WQ_FREEZABLE | WQ_UNBOUND | \
470 WQ_MEM_RECLAIM, 1, (name))
471 #define create_singlethread_workqueue(name) \
472 alloc_ordered_workqueue("%s", __WQ_LEGACY | WQ_MEM_RECLAIM, name)
474 extern void destroy_workqueue(struct workqueue_struct *wq);
476 struct workqueue_attrs *alloc_workqueue_attrs(void);
477 void free_workqueue_attrs(struct workqueue_attrs *attrs);
478 int apply_workqueue_attrs(struct workqueue_struct *wq,
479 const struct workqueue_attrs *attrs);
480 extern int workqueue_unbound_exclude_cpumask(cpumask_var_t cpumask);
482 extern bool queue_work_on(int cpu, struct workqueue_struct *wq,
483 struct work_struct *work);
484 extern bool queue_work_node(int node, struct workqueue_struct *wq,
485 struct work_struct *work);
486 extern bool queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
487 struct delayed_work *work, unsigned long delay);
488 extern bool mod_delayed_work_on(int cpu, struct workqueue_struct *wq,
489 struct delayed_work *dwork, unsigned long delay);
490 extern bool queue_rcu_work(struct workqueue_struct *wq, struct rcu_work *rwork);
492 extern void __flush_workqueue(struct workqueue_struct *wq);
493 extern void drain_workqueue(struct workqueue_struct *wq);
495 extern int schedule_on_each_cpu(work_func_t func);
497 int execute_in_process_context(work_func_t fn, struct execute_work *);
499 extern bool flush_work(struct work_struct *work);
500 extern bool cancel_work(struct work_struct *work);
501 extern bool cancel_work_sync(struct work_struct *work);
503 extern bool flush_delayed_work(struct delayed_work *dwork);
504 extern bool cancel_delayed_work(struct delayed_work *dwork);
505 extern bool cancel_delayed_work_sync(struct delayed_work *dwork);
507 extern bool flush_rcu_work(struct rcu_work *rwork);
509 extern void workqueue_set_max_active(struct workqueue_struct *wq,
511 extern struct work_struct *current_work(void);
512 extern bool current_is_workqueue_rescuer(void);
513 extern bool workqueue_congested(int cpu, struct workqueue_struct *wq);
514 extern unsigned int work_busy(struct work_struct *work);
515 extern __printf(1, 2) void set_worker_desc(const char *fmt, ...);
516 extern void print_worker_info(const char *log_lvl, struct task_struct *task);
517 extern void show_all_workqueues(void);
518 extern void show_freezable_workqueues(void);
519 extern void show_one_workqueue(struct workqueue_struct *wq);
520 extern void wq_worker_comm(char *buf, size_t size, struct task_struct *task);
523 * queue_work - queue work on a workqueue
524 * @wq: workqueue to use
525 * @work: work to queue
527 * Returns %false if @work was already on a queue, %true otherwise.
529 * We queue the work to the CPU on which it was submitted, but if the CPU dies
530 * it can be processed by another CPU.
532 * Memory-ordering properties: If it returns %true, guarantees that all stores
533 * preceding the call to queue_work() in the program order will be visible from
534 * the CPU which will execute @work by the time such work executes, e.g.,
536 * { x is initially 0 }
540 * WRITE_ONCE(x, 1); [ @work is being executed ]
541 * r0 = queue_work(wq, work); r1 = READ_ONCE(x);
543 * Forbids: r0 == true && r1 == 0
545 static inline bool queue_work(struct workqueue_struct *wq,
546 struct work_struct *work)
548 return queue_work_on(WORK_CPU_UNBOUND, wq, work);
552 * queue_delayed_work - queue work on a workqueue after delay
553 * @wq: workqueue to use
554 * @dwork: delayable work to queue
555 * @delay: number of jiffies to wait before queueing
557 * Equivalent to queue_delayed_work_on() but tries to use the local CPU.
559 static inline bool queue_delayed_work(struct workqueue_struct *wq,
560 struct delayed_work *dwork,
563 return queue_delayed_work_on(WORK_CPU_UNBOUND, wq, dwork, delay);
567 * mod_delayed_work - modify delay of or queue a delayed work
568 * @wq: workqueue to use
569 * @dwork: work to queue
570 * @delay: number of jiffies to wait before queueing
572 * mod_delayed_work_on() on local CPU.
574 static inline bool mod_delayed_work(struct workqueue_struct *wq,
575 struct delayed_work *dwork,
578 return mod_delayed_work_on(WORK_CPU_UNBOUND, wq, dwork, delay);
582 * schedule_work_on - put work task on a specific cpu
583 * @cpu: cpu to put the work task on
584 * @work: job to be done
586 * This puts a job on a specific cpu
588 static inline bool schedule_work_on(int cpu, struct work_struct *work)
590 return queue_work_on(cpu, system_wq, work);
594 * schedule_work - put work task in global workqueue
595 * @work: job to be done
597 * Returns %false if @work was already on the kernel-global workqueue and
600 * This puts a job in the kernel-global workqueue if it was not already
601 * queued and leaves it in the same position on the kernel-global
602 * workqueue otherwise.
604 * Shares the same memory-ordering properties of queue_work(), cf. the
605 * DocBook header of queue_work().
607 static inline bool schedule_work(struct work_struct *work)
609 return queue_work(system_wq, work);
613 * Detect attempt to flush system-wide workqueues at compile time when possible.
614 * Warn attempt to flush system-wide workqueues at runtime.
617 * for reasons and steps for converting system-wide workqueues into local workqueues.
619 extern void __warn_flushing_systemwide_wq(void)
620 __compiletime_warning("Please avoid flushing system-wide workqueues.");
622 /* Please stop using this function, for this function will be removed in near future. */
623 #define flush_scheduled_work() \
625 __warn_flushing_systemwide_wq(); \
626 __flush_workqueue(system_wq); \
629 #define flush_workqueue(wq) \
631 struct workqueue_struct *_wq = (wq); \
633 if ((__builtin_constant_p(_wq == system_wq) && \
634 _wq == system_wq) || \
635 (__builtin_constant_p(_wq == system_highpri_wq) && \
636 _wq == system_highpri_wq) || \
637 (__builtin_constant_p(_wq == system_long_wq) && \
638 _wq == system_long_wq) || \
639 (__builtin_constant_p(_wq == system_unbound_wq) && \
640 _wq == system_unbound_wq) || \
641 (__builtin_constant_p(_wq == system_freezable_wq) && \
642 _wq == system_freezable_wq) || \
643 (__builtin_constant_p(_wq == system_power_efficient_wq) && \
644 _wq == system_power_efficient_wq) || \
645 (__builtin_constant_p(_wq == system_freezable_power_efficient_wq) && \
646 _wq == system_freezable_power_efficient_wq)) \
647 __warn_flushing_systemwide_wq(); \
648 __flush_workqueue(_wq); \
652 * schedule_delayed_work_on - queue work in global workqueue on CPU after delay
654 * @dwork: job to be done
655 * @delay: number of jiffies to wait
657 * After waiting for a given time this puts a job in the kernel-global
658 * workqueue on the specified CPU.
660 static inline bool schedule_delayed_work_on(int cpu, struct delayed_work *dwork,
663 return queue_delayed_work_on(cpu, system_wq, dwork, delay);
667 * schedule_delayed_work - put work task in global workqueue after delay
668 * @dwork: job to be done
669 * @delay: number of jiffies to wait or 0 for immediate execution
671 * After waiting for a given time this puts a job in the kernel-global
674 static inline bool schedule_delayed_work(struct delayed_work *dwork,
677 return queue_delayed_work(system_wq, dwork, delay);
681 static inline long work_on_cpu(int cpu, long (*fn)(void *), void *arg)
685 static inline long work_on_cpu_safe(int cpu, long (*fn)(void *), void *arg)
690 long work_on_cpu_key(int cpu, long (*fn)(void *),
691 void *arg, struct lock_class_key *key);
693 * A new key is defined for each caller to make sure the work
694 * associated with the function doesn't share its locking class.
696 #define work_on_cpu(_cpu, _fn, _arg) \
698 static struct lock_class_key __key; \
700 work_on_cpu_key(_cpu, _fn, _arg, &__key); \
703 long work_on_cpu_safe_key(int cpu, long (*fn)(void *),
704 void *arg, struct lock_class_key *key);
707 * A new key is defined for each caller to make sure the work
708 * associated with the function doesn't share its locking class.
710 #define work_on_cpu_safe(_cpu, _fn, _arg) \
712 static struct lock_class_key __key; \
714 work_on_cpu_safe_key(_cpu, _fn, _arg, &__key); \
716 #endif /* CONFIG_SMP */
718 #ifdef CONFIG_FREEZER
719 extern void freeze_workqueues_begin(void);
720 extern bool freeze_workqueues_busy(void);
721 extern void thaw_workqueues(void);
722 #endif /* CONFIG_FREEZER */
725 int workqueue_sysfs_register(struct workqueue_struct *wq);
726 #else /* CONFIG_SYSFS */
727 static inline int workqueue_sysfs_register(struct workqueue_struct *wq)
729 #endif /* CONFIG_SYSFS */
731 #ifdef CONFIG_WQ_WATCHDOG
732 void wq_watchdog_touch(int cpu);
733 #else /* CONFIG_WQ_WATCHDOG */
734 static inline void wq_watchdog_touch(int cpu) { }
735 #endif /* CONFIG_WQ_WATCHDOG */
738 int workqueue_prepare_cpu(unsigned int cpu);
739 int workqueue_online_cpu(unsigned int cpu);
740 int workqueue_offline_cpu(unsigned int cpu);
743 void __init workqueue_init_early(void);
744 void __init workqueue_init(void);
745 void __init workqueue_init_topology(void);