linux/include/linux/workqueue.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0 */
   2/*
   3 * workqueue.h --- work queue handling for Linux.
   4 */
   5
   6#ifndef _LINUX_WORKQUEUE_H
   7#define _LINUX_WORKQUEUE_H
   8
   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/rh_kabi.h>
  18
  19struct workqueue_struct;
  20
  21struct work_struct;
  22typedef void (*work_func_t)(struct work_struct *work);
  23void delayed_work_timer_fn(struct timer_list *t);
  24
  25/*
  26 * The first word is the work queue pointer and the flags rolled into
  27 * one
  28 */
  29#define work_data_bits(work) ((unsigned long *)(&(work)->data))
  30
  31enum {
  32        WORK_STRUCT_PENDING_BIT = 0,    /* work item is pending execution */
  33        WORK_STRUCT_DELAYED_BIT = 1,    /* work item is delayed */
  34        WORK_STRUCT_PWQ_BIT     = 2,    /* data points to pwq */
  35        WORK_STRUCT_LINKED_BIT  = 3,    /* next work is linked to this one */
  36#ifdef CONFIG_DEBUG_OBJECTS_WORK
  37        WORK_STRUCT_STATIC_BIT  = 4,    /* static initializer (debugobjects) */
  38        WORK_STRUCT_COLOR_SHIFT = 5,    /* color for workqueue flushing */
  39#else
  40        WORK_STRUCT_COLOR_SHIFT = 4,    /* color for workqueue flushing */
  41#endif
  42
  43        WORK_STRUCT_COLOR_BITS  = 4,
  44
  45        WORK_STRUCT_PENDING     = 1 << WORK_STRUCT_PENDING_BIT,
  46        WORK_STRUCT_DELAYED     = 1 << WORK_STRUCT_DELAYED_BIT,
  47        WORK_STRUCT_PWQ         = 1 << WORK_STRUCT_PWQ_BIT,
  48        WORK_STRUCT_LINKED      = 1 << WORK_STRUCT_LINKED_BIT,
  49#ifdef CONFIG_DEBUG_OBJECTS_WORK
  50        WORK_STRUCT_STATIC      = 1 << WORK_STRUCT_STATIC_BIT,
  51#else
  52        WORK_STRUCT_STATIC      = 0,
  53#endif
  54
  55        /*
  56         * The last color is no color used for works which don't
  57         * participate in workqueue flushing.
  58         */
  59        WORK_NR_COLORS          = (1 << WORK_STRUCT_COLOR_BITS) - 1,
  60        WORK_NO_COLOR           = WORK_NR_COLORS,
  61
  62        /* not bound to any CPU, prefer the local CPU */
  63        WORK_CPU_UNBOUND        = NR_CPUS,
  64
  65        /*
  66         * Reserve 7 bits off of pwq pointer w/ debugobjects turned off.
  67         * This makes pwqs aligned to 256 bytes and allows 15 workqueue
  68         * flush colors.
  69         */
  70        WORK_STRUCT_FLAG_BITS   = WORK_STRUCT_COLOR_SHIFT +
  71                                  WORK_STRUCT_COLOR_BITS,
  72
  73        /* data contains off-queue information when !WORK_STRUCT_PWQ */
  74        WORK_OFFQ_FLAG_BASE     = WORK_STRUCT_COLOR_SHIFT,
  75
  76        __WORK_OFFQ_CANCELING   = WORK_OFFQ_FLAG_BASE,
  77        WORK_OFFQ_CANCELING     = (1 << __WORK_OFFQ_CANCELING),
  78
  79        /*
  80         * When a work item is off queue, its high bits point to the last
  81         * pool it was on.  Cap at 31 bits and use the highest number to
  82         * indicate that no pool is associated.
  83         */
  84        WORK_OFFQ_FLAG_BITS     = 1,
  85        WORK_OFFQ_POOL_SHIFT    = WORK_OFFQ_FLAG_BASE + WORK_OFFQ_FLAG_BITS,
  86        WORK_OFFQ_LEFT          = BITS_PER_LONG - WORK_OFFQ_POOL_SHIFT,
  87        WORK_OFFQ_POOL_BITS     = WORK_OFFQ_LEFT <= 31 ? WORK_OFFQ_LEFT : 31,
  88        WORK_OFFQ_POOL_NONE     = (1LU << WORK_OFFQ_POOL_BITS) - 1,
  89
  90        /* convenience constants */
  91        WORK_STRUCT_FLAG_MASK   = (1UL << WORK_STRUCT_FLAG_BITS) - 1,
  92        WORK_STRUCT_WQ_DATA_MASK = ~WORK_STRUCT_FLAG_MASK,
  93        WORK_STRUCT_NO_POOL     = (unsigned long)WORK_OFFQ_POOL_NONE << WORK_OFFQ_POOL_SHIFT,
  94
  95        /* bit mask for work_busy() return values */
  96        WORK_BUSY_PENDING       = 1 << 0,
  97        WORK_BUSY_RUNNING       = 1 << 1,
  98
  99        /* maximum string length for set_worker_desc() */
 100        WORKER_DESC_LEN         = 24,
 101};
 102
 103struct work_struct {
 104        atomic_long_t data;
 105        struct list_head entry;
 106        work_func_t func;
 107#ifdef CONFIG_LOCKDEP
 108        struct lockdep_map lockdep_map;
 109#endif
 110        /* RHEL-Only for use by wb_update_bandwidth_workfn */
 111        RH_KABI_USE(1, void *bdi_wb_backptr)
 112        RH_KABI_RESERVE(2)
 113        RH_KABI_RESERVE(3)
 114        RH_KABI_RESERVE(4)
 115};
 116
 117#define WORK_DATA_INIT()        ATOMIC_LONG_INIT((unsigned long)WORK_STRUCT_NO_POOL)
 118#define WORK_DATA_STATIC_INIT() \
 119        ATOMIC_LONG_INIT((unsigned long)(WORK_STRUCT_NO_POOL | WORK_STRUCT_STATIC))
 120
 121struct delayed_work {
 122        struct work_struct work;
 123        struct timer_list timer;
 124
 125        /* target workqueue and CPU ->timer uses to queue ->work */
 126        struct workqueue_struct *wq;
 127        int cpu;
 128        RH_KABI_RESERVE(1)
 129        RH_KABI_RESERVE(2)
 130        RH_KABI_RESERVE(3)
 131        RH_KABI_RESERVE(4)
 132};
 133
 134struct rcu_work {
 135        struct work_struct work;
 136        struct rcu_head rcu;
 137
 138        /* target workqueue ->rcu uses to queue ->work */
 139        struct workqueue_struct *wq;
 140};
 141
 142/**
 143 * struct workqueue_attrs - A struct for workqueue attributes.
 144 *
 145 * This can be used to change attributes of an unbound workqueue.
 146 */
 147struct workqueue_attrs {
 148        /**
 149         * @nice: nice level
 150         */
 151        int nice;
 152
 153        /**
 154         * @cpumask: allowed CPUs
 155         */
 156        cpumask_var_t cpumask;
 157
 158        /**
 159         * @no_numa: disable NUMA affinity
 160         *
 161         * Unlike other fields, ``no_numa`` isn't a property of a worker_pool. It
 162         * only modifies how :c:func:`apply_workqueue_attrs` select pools and thus
 163         * doesn't participate in pool hash calculations or equality comparisons.
 164         */
 165        bool no_numa;
 166};
 167
 168static inline struct delayed_work *to_delayed_work(struct work_struct *work)
 169{
 170        return container_of(work, struct delayed_work, work);
 171}
 172
 173static inline struct rcu_work *to_rcu_work(struct work_struct *work)
 174{
 175        return container_of(work, struct rcu_work, work);
 176}
 177
 178struct execute_work {
 179        struct work_struct work;
 180};
 181
 182#ifdef CONFIG_LOCKDEP
 183/*
 184 * NB: because we have to copy the lockdep_map, setting _key
 185 * here is required, otherwise it could get initialised to the
 186 * copy of the lockdep_map!
 187 */
 188#define __WORK_INIT_LOCKDEP_MAP(n, k) \
 189        .lockdep_map = STATIC_LOCKDEP_MAP_INIT(n, k),
 190#else
 191#define __WORK_INIT_LOCKDEP_MAP(n, k)
 192#endif
 193
 194#define __WORK_INITIALIZER(n, f) {                                      \
 195        .data = WORK_DATA_STATIC_INIT(),                                \
 196        .entry  = { &(n).entry, &(n).entry },                           \
 197        .func = (f),                                                    \
 198        __WORK_INIT_LOCKDEP_MAP(#n, &(n))                               \
 199        }
 200
 201#define __DELAYED_WORK_INITIALIZER(n, f, tflags) {                      \
 202        .work = __WORK_INITIALIZER((n).work, (f)),                      \
 203        .timer = __TIMER_INITIALIZER(delayed_work_timer_fn,\
 204                                     (tflags) | TIMER_IRQSAFE),         \
 205        }
 206
 207#define DECLARE_WORK(n, f)                                              \
 208        struct work_struct n = __WORK_INITIALIZER(n, f)
 209
 210#define DECLARE_DELAYED_WORK(n, f)                                      \
 211        struct delayed_work n = __DELAYED_WORK_INITIALIZER(n, f, 0)
 212
 213#define DECLARE_DEFERRABLE_WORK(n, f)                                   \
 214        struct delayed_work n = __DELAYED_WORK_INITIALIZER(n, f, TIMER_DEFERRABLE)
 215
 216#ifdef CONFIG_DEBUG_OBJECTS_WORK
 217extern void __init_work(struct work_struct *work, int onstack);
 218extern void destroy_work_on_stack(struct work_struct *work);
 219extern void destroy_delayed_work_on_stack(struct delayed_work *work);
 220static inline unsigned int work_static(struct work_struct *work)
 221{
 222        return *work_data_bits(work) & WORK_STRUCT_STATIC;
 223}
 224#else
 225static inline void __init_work(struct work_struct *work, int onstack) { }
 226static inline void destroy_work_on_stack(struct work_struct *work) { }
 227static inline void destroy_delayed_work_on_stack(struct delayed_work *work) { }
 228static inline unsigned int work_static(struct work_struct *work) { return 0; }
 229#endif
 230
 231/*
 232 * initialize all of a work item in one go
 233 *
 234 * NOTE! No point in using "atomic_long_set()": using a direct
 235 * assignment of the work data initializer allows the compiler
 236 * to generate better code.
 237 */
 238#ifdef CONFIG_LOCKDEP
 239#define __INIT_WORK(_work, _func, _onstack)                             \
 240        do {                                                            \
 241                static struct lock_class_key __key;                     \
 242                                                                        \
 243                __init_work((_work), _onstack);                         \
 244                (_work)->data = (atomic_long_t) WORK_DATA_INIT();       \
 245                lockdep_init_map(&(_work)->lockdep_map, "(work_completion)"#_work, &__key, 0); \
 246                INIT_LIST_HEAD(&(_work)->entry);                        \
 247                (_work)->func = (_func);                                \
 248        } while (0)
 249#else
 250#define __INIT_WORK(_work, _func, _onstack)                             \
 251        do {                                                            \
 252                __init_work((_work), _onstack);                         \
 253                (_work)->data = (atomic_long_t) WORK_DATA_INIT();       \
 254                INIT_LIST_HEAD(&(_work)->entry);                        \
 255                (_work)->func = (_func);                                \
 256        } while (0)
 257#endif
 258
 259#define INIT_WORK(_work, _func)                                         \
 260        __INIT_WORK((_work), (_func), 0)
 261
 262#define INIT_WORK_ONSTACK(_work, _func)                                 \
 263        __INIT_WORK((_work), (_func), 1)
 264
 265#define __INIT_DELAYED_WORK(_work, _func, _tflags)                      \
 266        do {                                                            \
 267                INIT_WORK(&(_work)->work, (_func));                     \
 268                __init_timer(&(_work)->timer,                           \
 269                             delayed_work_timer_fn,                     \
 270                             (_tflags) | TIMER_IRQSAFE);                \
 271        } while (0)
 272
 273#define __INIT_DELAYED_WORK_ONSTACK(_work, _func, _tflags)              \
 274        do {                                                            \
 275                INIT_WORK_ONSTACK(&(_work)->work, (_func));             \
 276                __init_timer_on_stack(&(_work)->timer,                  \
 277                                      delayed_work_timer_fn,            \
 278                                      (_tflags) | TIMER_IRQSAFE);       \
 279        } while (0)
 280
 281#define INIT_DELAYED_WORK(_work, _func)                                 \
 282        __INIT_DELAYED_WORK(_work, _func, 0)
 283
 284#define INIT_DELAYED_WORK_ONSTACK(_work, _func)                         \
 285        __INIT_DELAYED_WORK_ONSTACK(_work, _func, 0)
 286
 287#define INIT_DEFERRABLE_WORK(_work, _func)                              \
 288        __INIT_DELAYED_WORK(_work, _func, TIMER_DEFERRABLE)
 289
 290#define INIT_DEFERRABLE_WORK_ONSTACK(_work, _func)                      \
 291        __INIT_DELAYED_WORK_ONSTACK(_work, _func, TIMER_DEFERRABLE)
 292
 293#define INIT_RCU_WORK(_work, _func)                                     \
 294        INIT_WORK(&(_work)->work, (_func))
 295
 296#define INIT_RCU_WORK_ONSTACK(_work, _func)                             \
 297        INIT_WORK_ONSTACK(&(_work)->work, (_func))
 298
 299/**
 300 * work_pending - Find out whether a work item is currently pending
 301 * @work: The work item in question
 302 */
 303#define work_pending(work) \
 304        test_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))
 305
 306/**
 307 * delayed_work_pending - Find out whether a delayable work item is currently
 308 * pending
 309 * @w: The work item in question
 310 */
 311#define delayed_work_pending(w) \
 312        work_pending(&(w)->work)
 313
 314/*
 315 * Workqueue flags and constants.  For details, please refer to
 316 * Documentation/core-api/workqueue.rst.
 317 */
 318enum {
 319        WQ_UNBOUND              = 1 << 1, /* not bound to any cpu */
 320        WQ_FREEZABLE            = 1 << 2, /* freeze during suspend */
 321        WQ_MEM_RECLAIM          = 1 << 3, /* may be used for memory reclaim */
 322        WQ_HIGHPRI              = 1 << 4, /* high priority */
 323        WQ_CPU_INTENSIVE        = 1 << 5, /* cpu intensive workqueue */
 324        WQ_SYSFS                = 1 << 6, /* visible in sysfs, see wq_sysfs_register() */
 325
 326        /*
 327         * Per-cpu workqueues are generally preferred because they tend to
 328         * show better performance thanks to cache locality.  Per-cpu
 329         * workqueues exclude the scheduler from choosing the CPU to
 330         * execute the worker threads, which has an unfortunate side effect
 331         * of increasing power consumption.
 332         *
 333         * The scheduler considers a CPU idle if it doesn't have any task
 334         * to execute and tries to keep idle cores idle to conserve power;
 335         * however, for example, a per-cpu work item scheduled from an
 336         * interrupt handler on an idle CPU will force the scheduler to
 337         * excute the work item on that CPU breaking the idleness, which in
 338         * turn may lead to more scheduling choices which are sub-optimal
 339         * in terms of power consumption.
 340         *
 341         * Workqueues marked with WQ_POWER_EFFICIENT are per-cpu by default
 342         * but become unbound if workqueue.power_efficient kernel param is
 343         * specified.  Per-cpu workqueues which are identified to
 344         * contribute significantly to power-consumption are identified and
 345         * marked with this flag and enabling the power_efficient mode
 346         * leads to noticeable power saving at the cost of small
 347         * performance disadvantage.
 348         *
 349         * http://thread.gmane.org/gmane.linux.kernel/1480396
 350         */
 351        WQ_POWER_EFFICIENT      = 1 << 7,
 352
 353        __WQ_DRAINING           = 1 << 16, /* internal: workqueue is draining */
 354        __WQ_ORDERED            = 1 << 17, /* internal: workqueue is ordered */
 355        __WQ_LEGACY             = 1 << 18, /* internal: create*_workqueue() */
 356        __WQ_ORDERED_EXPLICIT   = 1 << 19, /* internal: alloc_ordered_workqueue() */
 357
 358        WQ_MAX_ACTIVE           = 512,    /* I like 512, better ideas? */
 359        WQ_MAX_UNBOUND_PER_CPU  = 4,      /* 4 * #cpus for unbound wq */
 360        WQ_DFL_ACTIVE           = WQ_MAX_ACTIVE / 2,
 361};
 362
 363/* unbound wq's aren't per-cpu, scale max_active according to #cpus */
 364#define WQ_UNBOUND_MAX_ACTIVE   \
 365        max_t(int, WQ_MAX_ACTIVE, num_possible_cpus() * WQ_MAX_UNBOUND_PER_CPU)
 366
 367/*
 368 * System-wide workqueues which are always present.
 369 *
 370 * system_wq is the one used by schedule[_delayed]_work[_on]().
 371 * Multi-CPU multi-threaded.  There are users which expect relatively
 372 * short queue flush time.  Don't queue works which can run for too
 373 * long.
 374 *
 375 * system_highpri_wq is similar to system_wq but for work items which
 376 * require WQ_HIGHPRI.
 377 *
 378 * system_long_wq is similar to system_wq but may host long running
 379 * works.  Queue flushing might take relatively long.
 380 *
 381 * system_unbound_wq is unbound workqueue.  Workers are not bound to
 382 * any specific CPU, not concurrency managed, and all queued works are
 383 * executed immediately as long as max_active limit is not reached and
 384 * resources are available.
 385 *
 386 * system_freezable_wq is equivalent to system_wq except that it's
 387 * freezable.
 388 *
 389 * *_power_efficient_wq are inclined towards saving power and converted
 390 * into WQ_UNBOUND variants if 'wq_power_efficient' is enabled; otherwise,
 391 * they are same as their non-power-efficient counterparts - e.g.
 392 * system_power_efficient_wq is identical to system_wq if
 393 * 'wq_power_efficient' is disabled.  See WQ_POWER_EFFICIENT for more info.
 394 */
 395extern struct workqueue_struct *system_wq;
 396extern struct workqueue_struct *system_highpri_wq;
 397extern struct workqueue_struct *system_long_wq;
 398extern struct workqueue_struct *system_unbound_wq;
 399extern struct workqueue_struct *system_freezable_wq;
 400extern struct workqueue_struct *system_power_efficient_wq;
 401extern struct workqueue_struct *system_freezable_power_efficient_wq;
 402
 403/**
 404 * alloc_workqueue - allocate a workqueue
 405 * @fmt: printf format for the name of the workqueue
 406 * @flags: WQ_* flags
 407 * @max_active: max in-flight work items, 0 for default
 408 * remaining args: args for @fmt
 409 *
 410 * Allocate a workqueue with the specified parameters.  For detailed
 411 * information on WQ_* flags, please refer to
 412 * Documentation/core-api/workqueue.rst.
 413 *
 414 * RETURNS:
 415 * Pointer to the allocated workqueue on success, %NULL on failure.
 416 */
 417struct workqueue_struct *alloc_workqueue(const char *fmt,
 418                                         unsigned int flags,
 419                                         int max_active, ...);
 420
 421/**
 422 * alloc_ordered_workqueue - allocate an ordered workqueue
 423 * @fmt: printf format for the name of the workqueue
 424 * @flags: WQ_* flags (only WQ_FREEZABLE and WQ_MEM_RECLAIM are meaningful)
 425 * @args...: args for @fmt
 426 *
 427 * Allocate an ordered workqueue.  An ordered workqueue executes at
 428 * most one work item at any given time in the queued order.  They are
 429 * implemented as unbound workqueues with @max_active of one.
 430 *
 431 * RETURNS:
 432 * Pointer to the allocated workqueue on success, %NULL on failure.
 433 */
 434#define alloc_ordered_workqueue(fmt, flags, args...)                    \
 435        alloc_workqueue(fmt, WQ_UNBOUND | __WQ_ORDERED |                \
 436                        __WQ_ORDERED_EXPLICIT | (flags), 1, ##args)
 437
 438#define create_workqueue(name)                                          \
 439        alloc_workqueue("%s", __WQ_LEGACY | WQ_MEM_RECLAIM, 1, (name))
 440#define create_freezable_workqueue(name)                                \
 441        alloc_workqueue("%s", __WQ_LEGACY | WQ_FREEZABLE | WQ_UNBOUND | \
 442                        WQ_MEM_RECLAIM, 1, (name))
 443#define create_singlethread_workqueue(name)                             \
 444        alloc_ordered_workqueue("%s", __WQ_LEGACY | WQ_MEM_RECLAIM, name)
 445
 446extern void destroy_workqueue(struct workqueue_struct *wq);
 447
 448struct workqueue_attrs *alloc_workqueue_attrs(void);
 449void free_workqueue_attrs(struct workqueue_attrs *attrs);
 450int apply_workqueue_attrs(struct workqueue_struct *wq,
 451                          const struct workqueue_attrs *attrs);
 452int workqueue_set_unbound_cpumask(cpumask_var_t cpumask);
 453
 454extern bool queue_work_on(int cpu, struct workqueue_struct *wq,
 455                        struct work_struct *work);
 456extern bool queue_work_node(int node, struct workqueue_struct *wq,
 457                            struct work_struct *work);
 458extern bool queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
 459                        struct delayed_work *work, unsigned long delay);
 460extern bool mod_delayed_work_on(int cpu, struct workqueue_struct *wq,
 461                        struct delayed_work *dwork, unsigned long delay);
 462extern bool queue_rcu_work(struct workqueue_struct *wq, struct rcu_work *rwork);
 463
 464extern void flush_workqueue(struct workqueue_struct *wq);
 465extern void drain_workqueue(struct workqueue_struct *wq);
 466
 467extern int schedule_on_each_cpu(work_func_t func);
 468
 469int execute_in_process_context(work_func_t fn, struct execute_work *);
 470
 471extern bool flush_work(struct work_struct *work);
 472extern bool cancel_work_sync(struct work_struct *work);
 473
 474extern bool flush_delayed_work(struct delayed_work *dwork);
 475extern bool cancel_delayed_work(struct delayed_work *dwork);
 476extern bool cancel_delayed_work_sync(struct delayed_work *dwork);
 477
 478extern bool flush_rcu_work(struct rcu_work *rwork);
 479
 480extern void workqueue_set_max_active(struct workqueue_struct *wq,
 481                                     int max_active);
 482extern struct work_struct *current_work(void);
 483extern bool current_is_workqueue_rescuer(void);
 484extern bool workqueue_congested(int cpu, struct workqueue_struct *wq);
 485extern unsigned int work_busy(struct work_struct *work);
 486extern __printf(1, 2) void set_worker_desc(const char *fmt, ...);
 487extern void print_worker_info(const char *log_lvl, struct task_struct *task);
 488extern void show_workqueue_state(void);
 489extern void wq_worker_comm(char *buf, size_t size, struct task_struct *task);
 490
 491/**
 492 * queue_work - queue work on a workqueue
 493 * @wq: workqueue to use
 494 * @work: work to queue
 495 *
 496 * Returns %false if @work was already on a queue, %true otherwise.
 497 *
 498 * We queue the work to the CPU on which it was submitted, but if the CPU dies
 499 * it can be processed by another CPU.
 500 */
 501static inline bool queue_work(struct workqueue_struct *wq,
 502                              struct work_struct *work)
 503{
 504        return queue_work_on(WORK_CPU_UNBOUND, wq, work);
 505}
 506
 507/**
 508 * queue_delayed_work - queue work on a workqueue after delay
 509 * @wq: workqueue to use
 510 * @dwork: delayable work to queue
 511 * @delay: number of jiffies to wait before queueing
 512 *
 513 * Equivalent to queue_delayed_work_on() but tries to use the local CPU.
 514 */
 515static inline bool queue_delayed_work(struct workqueue_struct *wq,
 516                                      struct delayed_work *dwork,
 517                                      unsigned long delay)
 518{
 519        return queue_delayed_work_on(WORK_CPU_UNBOUND, wq, dwork, delay);
 520}
 521
 522/**
 523 * mod_delayed_work - modify delay of or queue a delayed work
 524 * @wq: workqueue to use
 525 * @dwork: work to queue
 526 * @delay: number of jiffies to wait before queueing
 527 *
 528 * mod_delayed_work_on() on local CPU.
 529 */
 530static inline bool mod_delayed_work(struct workqueue_struct *wq,
 531                                    struct delayed_work *dwork,
 532                                    unsigned long delay)
 533{
 534        return mod_delayed_work_on(WORK_CPU_UNBOUND, wq, dwork, delay);
 535}
 536
 537/**
 538 * schedule_work_on - put work task on a specific cpu
 539 * @cpu: cpu to put the work task on
 540 * @work: job to be done
 541 *
 542 * This puts a job on a specific cpu
 543 */
 544static inline bool schedule_work_on(int cpu, struct work_struct *work)
 545{
 546        return queue_work_on(cpu, system_wq, work);
 547}
 548
 549/**
 550 * schedule_work - put work task in global workqueue
 551 * @work: job to be done
 552 *
 553 * Returns %false if @work was already on the kernel-global workqueue and
 554 * %true otherwise.
 555 *
 556 * This puts a job in the kernel-global workqueue if it was not already
 557 * queued and leaves it in the same position on the kernel-global
 558 * workqueue otherwise.
 559 */
 560static inline bool schedule_work(struct work_struct *work)
 561{
 562        return queue_work(system_wq, work);
 563}
 564
 565/**
 566 * flush_scheduled_work - ensure that any scheduled work has run to completion.
 567 *
 568 * Forces execution of the kernel-global workqueue and blocks until its
 569 * completion.
 570 *
 571 * Think twice before calling this function!  It's very easy to get into
 572 * trouble if you don't take great care.  Either of the following situations
 573 * will lead to deadlock:
 574 *
 575 *      One of the work items currently on the workqueue needs to acquire
 576 *      a lock held by your code or its caller.
 577 *
 578 *      Your code is running in the context of a work routine.
 579 *
 580 * They will be detected by lockdep when they occur, but the first might not
 581 * occur very often.  It depends on what work items are on the workqueue and
 582 * what locks they need, which you have no control over.
 583 *
 584 * In most situations flushing the entire workqueue is overkill; you merely
 585 * need to know that a particular work item isn't queued and isn't running.
 586 * In such cases you should use cancel_delayed_work_sync() or
 587 * cancel_work_sync() instead.
 588 */
 589static inline void flush_scheduled_work(void)
 590{
 591        flush_workqueue(system_wq);
 592}
 593
 594/**
 595 * schedule_delayed_work_on - queue work in global workqueue on CPU after delay
 596 * @cpu: cpu to use
 597 * @dwork: job to be done
 598 * @delay: number of jiffies to wait
 599 *
 600 * After waiting for a given time this puts a job in the kernel-global
 601 * workqueue on the specified CPU.
 602 */
 603static inline bool schedule_delayed_work_on(int cpu, struct delayed_work *dwork,
 604                                            unsigned long delay)
 605{
 606        return queue_delayed_work_on(cpu, system_wq, dwork, delay);
 607}
 608
 609/**
 610 * schedule_delayed_work - put work task in global workqueue after delay
 611 * @dwork: job to be done
 612 * @delay: number of jiffies to wait or 0 for immediate execution
 613 *
 614 * After waiting for a given time this puts a job in the kernel-global
 615 * workqueue.
 616 */
 617static inline bool schedule_delayed_work(struct delayed_work *dwork,
 618                                         unsigned long delay)
 619{
 620        return queue_delayed_work(system_wq, dwork, delay);
 621}
 622
 623#ifndef CONFIG_SMP
 624static inline long work_on_cpu(int cpu, long (*fn)(void *), void *arg)
 625{
 626        return fn(arg);
 627}
 628static inline long work_on_cpu_safe(int cpu, long (*fn)(void *), void *arg)
 629{
 630        return fn(arg);
 631}
 632#else
 633long work_on_cpu(int cpu, long (*fn)(void *), void *arg);
 634long work_on_cpu_safe(int cpu, long (*fn)(void *), void *arg);
 635#endif /* CONFIG_SMP */
 636
 637#ifdef CONFIG_FREEZER
 638extern void freeze_workqueues_begin(void);
 639extern bool freeze_workqueues_busy(void);
 640extern void thaw_workqueues(void);
 641#endif /* CONFIG_FREEZER */
 642
 643#ifdef CONFIG_SYSFS
 644int workqueue_sysfs_register(struct workqueue_struct *wq);
 645#else   /* CONFIG_SYSFS */
 646static inline int workqueue_sysfs_register(struct workqueue_struct *wq)
 647{ return 0; }
 648#endif  /* CONFIG_SYSFS */
 649
 650#ifdef CONFIG_WQ_WATCHDOG
 651void wq_watchdog_touch(int cpu);
 652#else   /* CONFIG_WQ_WATCHDOG */
 653static inline void wq_watchdog_touch(int cpu) { }
 654#endif  /* CONFIG_WQ_WATCHDOG */
 655
 656#ifdef CONFIG_SMP
 657int workqueue_prepare_cpu(unsigned int cpu);
 658int workqueue_online_cpu(unsigned int cpu);
 659int workqueue_offline_cpu(unsigned int cpu);
 660#endif
 661
 662int __init workqueue_init_early(void);
 663int __init workqueue_init(void);
 664
 665#endif
 666