workqueue.h 21 KB

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