11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * workqueue.h --- work queue handling for Linux. 31da177e4SLinus Torvalds */ 41da177e4SLinus Torvalds 51da177e4SLinus Torvalds #ifndef _LINUX_WORKQUEUE_H 61da177e4SLinus Torvalds #define _LINUX_WORKQUEUE_H 71da177e4SLinus Torvalds 81da177e4SLinus Torvalds #include <linux/timer.h> 91da177e4SLinus Torvalds #include <linux/linkage.h> 101da177e4SLinus Torvalds #include <linux/bitops.h> 114e6045f1SJohannes Berg #include <linux/lockdep.h> 127a22ad75STejun Heo #include <linux/threads.h> 13a08727baSLinus Torvalds #include <asm/atomic.h> 141da177e4SLinus Torvalds 151da177e4SLinus Torvalds struct workqueue_struct; 161da177e4SLinus Torvalds 1765f27f38SDavid Howells struct work_struct; 1865f27f38SDavid Howells typedef void (*work_func_t)(struct work_struct *work); 196bb49e59SDavid Howells 20a08727baSLinus Torvalds /* 21a08727baSLinus Torvalds * The first word is the work queue pointer and the flags rolled into 22a08727baSLinus Torvalds * one 23a08727baSLinus Torvalds */ 24a08727baSLinus Torvalds #define work_data_bits(work) ((unsigned long *)(&(work)->data)) 25a08727baSLinus Torvalds 2622df02bbSTejun Heo enum { 2722df02bbSTejun Heo WORK_STRUCT_PENDING_BIT = 0, /* work item is pending execution */ 288a2e8e5dSTejun Heo WORK_STRUCT_DELAYED_BIT = 1, /* work item is delayed */ 298a2e8e5dSTejun Heo WORK_STRUCT_CWQ_BIT = 2, /* data points to cwq */ 308a2e8e5dSTejun Heo WORK_STRUCT_LINKED_BIT = 3, /* next work is linked to this one */ 3122df02bbSTejun Heo #ifdef CONFIG_DEBUG_OBJECTS_WORK 328a2e8e5dSTejun Heo WORK_STRUCT_STATIC_BIT = 4, /* static initializer (debugobjects) */ 338a2e8e5dSTejun Heo WORK_STRUCT_COLOR_SHIFT = 5, /* color for workqueue flushing */ 340f900049STejun Heo #else 358a2e8e5dSTejun Heo WORK_STRUCT_COLOR_SHIFT = 4, /* color for workqueue flushing */ 3622df02bbSTejun Heo #endif 3722df02bbSTejun Heo 3873f53c4aSTejun Heo WORK_STRUCT_COLOR_BITS = 4, 3973f53c4aSTejun Heo 4022df02bbSTejun Heo WORK_STRUCT_PENDING = 1 << WORK_STRUCT_PENDING_BIT, 418a2e8e5dSTejun Heo WORK_STRUCT_DELAYED = 1 << WORK_STRUCT_DELAYED_BIT, 42e120153dSTejun Heo WORK_STRUCT_CWQ = 1 << WORK_STRUCT_CWQ_BIT, 43affee4b2STejun Heo WORK_STRUCT_LINKED = 1 << WORK_STRUCT_LINKED_BIT, 4422df02bbSTejun Heo #ifdef CONFIG_DEBUG_OBJECTS_WORK 4522df02bbSTejun Heo WORK_STRUCT_STATIC = 1 << WORK_STRUCT_STATIC_BIT, 4622df02bbSTejun Heo #else 4722df02bbSTejun Heo WORK_STRUCT_STATIC = 0, 4822df02bbSTejun Heo #endif 4922df02bbSTejun Heo 5073f53c4aSTejun Heo /* 5173f53c4aSTejun Heo * The last color is no color used for works which don't 5273f53c4aSTejun Heo * participate in workqueue flushing. 5373f53c4aSTejun Heo */ 5473f53c4aSTejun Heo WORK_NR_COLORS = (1 << WORK_STRUCT_COLOR_BITS) - 1, 5573f53c4aSTejun Heo WORK_NO_COLOR = WORK_NR_COLORS, 5673f53c4aSTejun Heo 57bdbc5dd7STejun Heo /* special cpu IDs */ 58f3421797STejun Heo WORK_CPU_UNBOUND = NR_CPUS, 59f3421797STejun Heo WORK_CPU_NONE = NR_CPUS + 1, 60bdbc5dd7STejun Heo WORK_CPU_LAST = WORK_CPU_NONE, 61bdbc5dd7STejun Heo 6273f53c4aSTejun Heo /* 63e120153dSTejun Heo * Reserve 7 bits off of cwq pointer w/ debugobjects turned 648a2e8e5dSTejun Heo * off. This makes cwqs aligned to 256 bytes and allows 15 658a2e8e5dSTejun Heo * workqueue flush colors. 6673f53c4aSTejun Heo */ 6773f53c4aSTejun Heo WORK_STRUCT_FLAG_BITS = WORK_STRUCT_COLOR_SHIFT + 6873f53c4aSTejun Heo WORK_STRUCT_COLOR_BITS, 6973f53c4aSTejun Heo 700f900049STejun Heo WORK_STRUCT_FLAG_MASK = (1UL << WORK_STRUCT_FLAG_BITS) - 1, 7122df02bbSTejun Heo WORK_STRUCT_WQ_DATA_MASK = ~WORK_STRUCT_FLAG_MASK, 72bdbc5dd7STejun Heo WORK_STRUCT_NO_CPU = WORK_CPU_NONE << WORK_STRUCT_FLAG_BITS, 73dcd989cbSTejun Heo 74dcd989cbSTejun Heo /* bit mask for work_busy() return values */ 75dcd989cbSTejun Heo WORK_BUSY_PENDING = 1 << 0, 76dcd989cbSTejun Heo WORK_BUSY_RUNNING = 1 << 1, 7722df02bbSTejun Heo }; 7822df02bbSTejun Heo 791da177e4SLinus Torvalds struct work_struct { 80a08727baSLinus Torvalds atomic_long_t data; 811da177e4SLinus Torvalds struct list_head entry; 826bb49e59SDavid Howells work_func_t func; 834e6045f1SJohannes Berg #ifdef CONFIG_LOCKDEP 844e6045f1SJohannes Berg struct lockdep_map lockdep_map; 854e6045f1SJohannes Berg #endif 8652bad64dSDavid Howells }; 8752bad64dSDavid Howells 887a22ad75STejun Heo #define WORK_DATA_INIT() ATOMIC_LONG_INIT(WORK_STRUCT_NO_CPU) 897a22ad75STejun Heo #define WORK_DATA_STATIC_INIT() \ 907a22ad75STejun Heo ATOMIC_LONG_INIT(WORK_STRUCT_NO_CPU | WORK_STRUCT_STATIC) 91a08727baSLinus Torvalds 9252bad64dSDavid Howells struct delayed_work { 9352bad64dSDavid Howells struct work_struct work; 941da177e4SLinus Torvalds struct timer_list timer; 951da177e4SLinus Torvalds }; 961da177e4SLinus Torvalds 97bf6aede7SJean Delvare static inline struct delayed_work *to_delayed_work(struct work_struct *work) 98bf6aede7SJean Delvare { 99bf6aede7SJean Delvare return container_of(work, struct delayed_work, work); 100bf6aede7SJean Delvare } 101bf6aede7SJean Delvare 1021fa44ecaSJames Bottomley struct execute_work { 1031fa44ecaSJames Bottomley struct work_struct work; 1041fa44ecaSJames Bottomley }; 1051fa44ecaSJames Bottomley 1064e6045f1SJohannes Berg #ifdef CONFIG_LOCKDEP 1074e6045f1SJohannes Berg /* 1084e6045f1SJohannes Berg * NB: because we have to copy the lockdep_map, setting _key 1094e6045f1SJohannes Berg * here is required, otherwise it could get initialised to the 1104e6045f1SJohannes Berg * copy of the lockdep_map! 1114e6045f1SJohannes Berg */ 1124e6045f1SJohannes Berg #define __WORK_INIT_LOCKDEP_MAP(n, k) \ 1134e6045f1SJohannes Berg .lockdep_map = STATIC_LOCKDEP_MAP_INIT(n, k), 1144e6045f1SJohannes Berg #else 1154e6045f1SJohannes Berg #define __WORK_INIT_LOCKDEP_MAP(n, k) 1164e6045f1SJohannes Berg #endif 1174e6045f1SJohannes Berg 11865f27f38SDavid Howells #define __WORK_INITIALIZER(n, f) { \ 119dc186ad7SThomas Gleixner .data = WORK_DATA_STATIC_INIT(), \ 12065f27f38SDavid Howells .entry = { &(n).entry, &(n).entry }, \ 12165f27f38SDavid Howells .func = (f), \ 1224e6045f1SJohannes Berg __WORK_INIT_LOCKDEP_MAP(#n, &(n)) \ 12365f27f38SDavid Howells } 12465f27f38SDavid Howells 12565f27f38SDavid Howells #define __DELAYED_WORK_INITIALIZER(n, f) { \ 12665f27f38SDavid Howells .work = __WORK_INITIALIZER((n).work, (f)), \ 1271da177e4SLinus Torvalds .timer = TIMER_INITIALIZER(NULL, 0, 0), \ 1281da177e4SLinus Torvalds } 1291da177e4SLinus Torvalds 13065f27f38SDavid Howells #define DECLARE_WORK(n, f) \ 13165f27f38SDavid Howells struct work_struct n = __WORK_INITIALIZER(n, f) 13265f27f38SDavid Howells 13365f27f38SDavid Howells #define DECLARE_DELAYED_WORK(n, f) \ 13465f27f38SDavid Howells struct delayed_work n = __DELAYED_WORK_INITIALIZER(n, f) 13565f27f38SDavid Howells 1361da177e4SLinus Torvalds /* 13765f27f38SDavid Howells * initialize a work item's function pointer 1381da177e4SLinus Torvalds */ 13965f27f38SDavid Howells #define PREPARE_WORK(_work, _func) \ 1401da177e4SLinus Torvalds do { \ 14152bad64dSDavid Howells (_work)->func = (_func); \ 1421da177e4SLinus Torvalds } while (0) 1431da177e4SLinus Torvalds 14465f27f38SDavid Howells #define PREPARE_DELAYED_WORK(_work, _func) \ 14565f27f38SDavid Howells PREPARE_WORK(&(_work)->work, (_func)) 14652bad64dSDavid Howells 147dc186ad7SThomas Gleixner #ifdef CONFIG_DEBUG_OBJECTS_WORK 148dc186ad7SThomas Gleixner extern void __init_work(struct work_struct *work, int onstack); 149dc186ad7SThomas Gleixner extern void destroy_work_on_stack(struct work_struct *work); 1504690c4abSTejun Heo static inline unsigned int work_static(struct work_struct *work) 1514690c4abSTejun Heo { 15222df02bbSTejun Heo return *work_data_bits(work) & WORK_STRUCT_STATIC; 1534690c4abSTejun Heo } 154dc186ad7SThomas Gleixner #else 155dc186ad7SThomas Gleixner static inline void __init_work(struct work_struct *work, int onstack) { } 156dc186ad7SThomas Gleixner static inline void destroy_work_on_stack(struct work_struct *work) { } 1574690c4abSTejun Heo static inline unsigned int work_static(struct work_struct *work) { return 0; } 158dc186ad7SThomas Gleixner #endif 159dc186ad7SThomas Gleixner 1601da177e4SLinus Torvalds /* 16152bad64dSDavid Howells * initialize all of a work item in one go 162a08727baSLinus Torvalds * 163b9049df5SDmitri Vorobiev * NOTE! No point in using "atomic_long_set()": using a direct 164a08727baSLinus Torvalds * assignment of the work data initializer allows the compiler 165a08727baSLinus Torvalds * to generate better code. 1661da177e4SLinus Torvalds */ 1674e6045f1SJohannes Berg #ifdef CONFIG_LOCKDEP 168dc186ad7SThomas Gleixner #define __INIT_WORK(_work, _func, _onstack) \ 1694e6045f1SJohannes Berg do { \ 1704e6045f1SJohannes Berg static struct lock_class_key __key; \ 1714e6045f1SJohannes Berg \ 172dc186ad7SThomas Gleixner __init_work((_work), _onstack); \ 1734e6045f1SJohannes Berg (_work)->data = (atomic_long_t) WORK_DATA_INIT(); \ 1744e6045f1SJohannes Berg lockdep_init_map(&(_work)->lockdep_map, #_work, &__key, 0);\ 1754e6045f1SJohannes Berg INIT_LIST_HEAD(&(_work)->entry); \ 1764e6045f1SJohannes Berg PREPARE_WORK((_work), (_func)); \ 1774e6045f1SJohannes Berg } while (0) 1784e6045f1SJohannes Berg #else 179dc186ad7SThomas Gleixner #define __INIT_WORK(_work, _func, _onstack) \ 1801da177e4SLinus Torvalds do { \ 181dc186ad7SThomas Gleixner __init_work((_work), _onstack); \ 18223b2e599SOleg Nesterov (_work)->data = (atomic_long_t) WORK_DATA_INIT(); \ 18365f27f38SDavid Howells INIT_LIST_HEAD(&(_work)->entry); \ 18465f27f38SDavid Howells PREPARE_WORK((_work), (_func)); \ 18565f27f38SDavid Howells } while (0) 1864e6045f1SJohannes Berg #endif 18765f27f38SDavid Howells 188dc186ad7SThomas Gleixner #define INIT_WORK(_work, _func) \ 189dc186ad7SThomas Gleixner do { \ 190dc186ad7SThomas Gleixner __INIT_WORK((_work), (_func), 0); \ 191dc186ad7SThomas Gleixner } while (0) 192dc186ad7SThomas Gleixner 193dc186ad7SThomas Gleixner #define INIT_WORK_ON_STACK(_work, _func) \ 194dc186ad7SThomas Gleixner do { \ 195dc186ad7SThomas Gleixner __INIT_WORK((_work), (_func), 1); \ 196dc186ad7SThomas Gleixner } while (0) 197dc186ad7SThomas Gleixner 19865f27f38SDavid Howells #define INIT_DELAYED_WORK(_work, _func) \ 19965f27f38SDavid Howells do { \ 20065f27f38SDavid Howells INIT_WORK(&(_work)->work, (_func)); \ 20165f27f38SDavid Howells init_timer(&(_work)->timer); \ 20265f27f38SDavid Howells } while (0) 20365f27f38SDavid Howells 2046d612b0fSPeter Zijlstra #define INIT_DELAYED_WORK_ON_STACK(_work, _func) \ 2056d612b0fSPeter Zijlstra do { \ 206dc186ad7SThomas Gleixner INIT_WORK_ON_STACK(&(_work)->work, (_func)); \ 2076d612b0fSPeter Zijlstra init_timer_on_stack(&(_work)->timer); \ 2086d612b0fSPeter Zijlstra } while (0) 2096d612b0fSPeter Zijlstra 21028287033SVenki Pallipadi #define INIT_DELAYED_WORK_DEFERRABLE(_work, _func) \ 21128287033SVenki Pallipadi do { \ 21228287033SVenki Pallipadi INIT_WORK(&(_work)->work, (_func)); \ 21328287033SVenki Pallipadi init_timer_deferrable(&(_work)->timer); \ 21428287033SVenki Pallipadi } while (0) 21528287033SVenki Pallipadi 216365970a1SDavid Howells /** 217365970a1SDavid Howells * work_pending - Find out whether a work item is currently pending 218365970a1SDavid Howells * @work: The work item in question 219365970a1SDavid Howells */ 220365970a1SDavid Howells #define work_pending(work) \ 22122df02bbSTejun Heo test_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work)) 222365970a1SDavid Howells 223365970a1SDavid Howells /** 224365970a1SDavid Howells * delayed_work_pending - Find out whether a delayable work item is currently 225365970a1SDavid Howells * pending 226365970a1SDavid Howells * @work: The work item in question 227365970a1SDavid Howells */ 2280221872aSLinus Torvalds #define delayed_work_pending(w) \ 2290221872aSLinus Torvalds work_pending(&(w)->work) 230365970a1SDavid Howells 23165f27f38SDavid Howells /** 23223b2e599SOleg Nesterov * work_clear_pending - for internal use only, mark a work item as not pending 23323b2e599SOleg Nesterov * @work: The work item in question 23465f27f38SDavid Howells */ 23523b2e599SOleg Nesterov #define work_clear_pending(work) \ 23622df02bbSTejun Heo clear_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work)) 23765f27f38SDavid Howells 238c54fce6eSTejun Heo /* 239c54fce6eSTejun Heo * Workqueue flags and constants. For details, please refer to 240c54fce6eSTejun Heo * Documentation/workqueue.txt. 241c54fce6eSTejun Heo */ 24297e37d7bSTejun Heo enum { 243bdbc5dd7STejun Heo WQ_NON_REENTRANT = 1 << 0, /* guarantee non-reentrance */ 244c7fc77f7STejun Heo WQ_UNBOUND = 1 << 1, /* not bound to any cpu */ 245bdbc5dd7STejun Heo WQ_FREEZEABLE = 1 << 2, /* freeze during suspend */ 2466370a6adSTejun Heo WQ_MEM_RECLAIM = 1 << 3, /* may be used for memory reclaim */ 247649027d7STejun Heo WQ_HIGHPRI = 1 << 4, /* high priority */ 248fb0e7bebSTejun Heo WQ_CPU_INTENSIVE = 1 << 5, /* cpu instensive workqueue */ 249b71ab8c2STejun Heo 250e41e704bSTejun Heo WQ_DYING = 1 << 6, /* internal: workqueue is dying */ 2516370a6adSTejun Heo WQ_RESCUER = 1 << 7, /* internal: workqueue has rescuer */ 252e41e704bSTejun Heo 253b71ab8c2STejun Heo WQ_MAX_ACTIVE = 512, /* I like 512, better ideas? */ 254f3421797STejun Heo WQ_MAX_UNBOUND_PER_CPU = 4, /* 4 * #cpus for unbound wq */ 255b71ab8c2STejun Heo WQ_DFL_ACTIVE = WQ_MAX_ACTIVE / 2, 25697e37d7bSTejun Heo }; 25752bad64dSDavid Howells 258f3421797STejun Heo /* unbound wq's aren't per-cpu, scale max_active according to #cpus */ 259f3421797STejun Heo #define WQ_UNBOUND_MAX_ACTIVE \ 260f3421797STejun Heo max_t(int, WQ_MAX_ACTIVE, num_possible_cpus() * WQ_MAX_UNBOUND_PER_CPU) 261f3421797STejun Heo 262d320c038STejun Heo /* 263d320c038STejun Heo * System-wide workqueues which are always present. 264d320c038STejun Heo * 265d320c038STejun Heo * system_wq is the one used by schedule[_delayed]_work[_on](). 266d320c038STejun Heo * Multi-CPU multi-threaded. There are users which expect relatively 267d320c038STejun Heo * short queue flush time. Don't queue works which can run for too 268d320c038STejun Heo * long. 269d320c038STejun Heo * 270d320c038STejun Heo * system_long_wq is similar to system_wq but may host long running 271d320c038STejun Heo * works. Queue flushing might take relatively long. 272d320c038STejun Heo * 273d320c038STejun Heo * system_nrt_wq is non-reentrant and guarantees that any given work 274d320c038STejun Heo * item is never executed in parallel by multiple CPUs. Queue 275d320c038STejun Heo * flushing might take relatively long. 276f3421797STejun Heo * 277f3421797STejun Heo * system_unbound_wq is unbound workqueue. Workers are not bound to 278f3421797STejun Heo * any specific CPU, not concurrency managed, and all queued works are 279f3421797STejun Heo * executed immediately as long as max_active limit is not reached and 280f3421797STejun Heo * resources are available. 281d320c038STejun Heo */ 282d320c038STejun Heo extern struct workqueue_struct *system_wq; 283d320c038STejun Heo extern struct workqueue_struct *system_long_wq; 284d320c038STejun Heo extern struct workqueue_struct *system_nrt_wq; 285f3421797STejun Heo extern struct workqueue_struct *system_unbound_wq; 2861da177e4SLinus Torvalds 2874e6045f1SJohannes Berg extern struct workqueue_struct * 288d320c038STejun Heo __alloc_workqueue_key(const char *name, unsigned int flags, int max_active, 289c790bce0STejun Heo struct lock_class_key *key, const char *lock_name); 2904e6045f1SJohannes Berg 2914e6045f1SJohannes Berg #ifdef CONFIG_LOCKDEP 292d320c038STejun Heo #define alloc_workqueue(name, flags, max_active) \ 2934e6045f1SJohannes Berg ({ \ 2944e6045f1SJohannes Berg static struct lock_class_key __key; \ 295eb13ba87SJohannes Berg const char *__lock_name; \ 296eb13ba87SJohannes Berg \ 297eb13ba87SJohannes Berg if (__builtin_constant_p(name)) \ 298eb13ba87SJohannes Berg __lock_name = (name); \ 299eb13ba87SJohannes Berg else \ 300eb13ba87SJohannes Berg __lock_name = #name; \ 3014e6045f1SJohannes Berg \ 302d320c038STejun Heo __alloc_workqueue_key((name), (flags), (max_active), \ 3031e19ffc6STejun Heo &__key, __lock_name); \ 3044e6045f1SJohannes Berg }) 3054e6045f1SJohannes Berg #else 306d320c038STejun Heo #define alloc_workqueue(name, flags, max_active) \ 307d320c038STejun Heo __alloc_workqueue_key((name), (flags), (max_active), NULL, NULL) 3084e6045f1SJohannes Berg #endif 3094e6045f1SJohannes Berg 31081dcaf65STejun Heo /** 31181dcaf65STejun Heo * alloc_ordered_workqueue - allocate an ordered workqueue 31281dcaf65STejun Heo * @name: name of the workqueue 3136370a6adSTejun Heo * @flags: WQ_* flags (only WQ_FREEZEABLE and WQ_MEM_RECLAIM are meaningful) 31481dcaf65STejun Heo * 31581dcaf65STejun Heo * Allocate an ordered workqueue. An ordered workqueue executes at 31681dcaf65STejun Heo * most one work item at any given time in the queued order. They are 31781dcaf65STejun Heo * implemented as unbound workqueues with @max_active of one. 31881dcaf65STejun Heo * 31981dcaf65STejun Heo * RETURNS: 32081dcaf65STejun Heo * Pointer to the allocated workqueue on success, %NULL on failure. 32181dcaf65STejun Heo */ 32281dcaf65STejun Heo static inline struct workqueue_struct * 32381dcaf65STejun Heo alloc_ordered_workqueue(const char *name, unsigned int flags) 32481dcaf65STejun Heo { 32581dcaf65STejun Heo return alloc_workqueue(name, WQ_UNBOUND | flags, 1); 32681dcaf65STejun Heo } 32781dcaf65STejun Heo 32897e37d7bSTejun Heo #define create_workqueue(name) \ 3296370a6adSTejun Heo alloc_workqueue((name), WQ_MEM_RECLAIM, 1) 33097e37d7bSTejun Heo #define create_freezeable_workqueue(name) \ 3316370a6adSTejun Heo alloc_workqueue((name), WQ_FREEZEABLE | WQ_UNBOUND | WQ_MEM_RECLAIM, 1) 33297e37d7bSTejun Heo #define create_singlethread_workqueue(name) \ 3336370a6adSTejun Heo alloc_workqueue((name), WQ_UNBOUND | WQ_MEM_RECLAIM, 1) 3341da177e4SLinus Torvalds 3351da177e4SLinus Torvalds extern void destroy_workqueue(struct workqueue_struct *wq); 3361da177e4SLinus Torvalds 337b3c97528SHarvey Harrison extern int queue_work(struct workqueue_struct *wq, struct work_struct *work); 338c1a220e7SZhang Rui extern int queue_work_on(int cpu, struct workqueue_struct *wq, 339c1a220e7SZhang Rui struct work_struct *work); 340b3c97528SHarvey Harrison extern int queue_delayed_work(struct workqueue_struct *wq, 341b3c97528SHarvey Harrison struct delayed_work *work, unsigned long delay); 3427a6bc1cdSVenkatesh Pallipadi extern int queue_delayed_work_on(int cpu, struct workqueue_struct *wq, 34352bad64dSDavid Howells struct delayed_work *work, unsigned long delay); 34428e53bddSOleg Nesterov 345b3c97528SHarvey Harrison extern void flush_workqueue(struct workqueue_struct *wq); 34628e53bddSOleg Nesterov extern void flush_scheduled_work(void); 3471da177e4SLinus Torvalds 348b3c97528SHarvey Harrison extern int schedule_work(struct work_struct *work); 349c1a220e7SZhang Rui extern int schedule_work_on(int cpu, struct work_struct *work); 350b3c97528SHarvey Harrison extern int schedule_delayed_work(struct delayed_work *work, unsigned long delay); 35128e53bddSOleg Nesterov extern int schedule_delayed_work_on(int cpu, struct delayed_work *work, 35228e53bddSOleg Nesterov unsigned long delay); 35365f27f38SDavid Howells extern int schedule_on_each_cpu(work_func_t func); 3541da177e4SLinus Torvalds extern int keventd_up(void); 3551da177e4SLinus Torvalds 35665f27f38SDavid Howells int execute_in_process_context(work_func_t fn, struct execute_work *); 3571da177e4SLinus Torvalds 358401a8d04STejun Heo extern bool flush_work(struct work_struct *work); 35909383498STejun Heo extern bool flush_work_sync(struct work_struct *work); 360401a8d04STejun Heo extern bool cancel_work_sync(struct work_struct *work); 361401a8d04STejun Heo 362401a8d04STejun Heo extern bool flush_delayed_work(struct delayed_work *dwork); 36309383498STejun Heo extern bool flush_delayed_work_sync(struct delayed_work *work); 364401a8d04STejun Heo extern bool cancel_delayed_work_sync(struct delayed_work *dwork); 36528e53bddSOleg Nesterov 366dcd989cbSTejun Heo extern void workqueue_set_max_active(struct workqueue_struct *wq, 367dcd989cbSTejun Heo int max_active); 368dcd989cbSTejun Heo extern bool workqueue_congested(unsigned int cpu, struct workqueue_struct *wq); 369dcd989cbSTejun Heo extern unsigned int work_cpu(struct work_struct *work); 370dcd989cbSTejun Heo extern unsigned int work_busy(struct work_struct *work); 371dcd989cbSTejun Heo 3721da177e4SLinus Torvalds /* 3731da177e4SLinus Torvalds * Kill off a pending schedule_delayed_work(). Note that the work callback 374071b6386SOleg Nesterov * function may still be running on return from cancel_delayed_work(), unless 375071b6386SOleg Nesterov * it returns 1 and the work doesn't re-arm itself. Run flush_workqueue() or 37628e53bddSOleg Nesterov * cancel_work_sync() to wait on it. 3771da177e4SLinus Torvalds */ 378401a8d04STejun Heo static inline bool cancel_delayed_work(struct delayed_work *work) 3791da177e4SLinus Torvalds { 380401a8d04STejun Heo bool ret; 3811da177e4SLinus Torvalds 382223a10a9SOleg Nesterov ret = del_timer_sync(&work->timer); 3831da177e4SLinus Torvalds if (ret) 38423b2e599SOleg Nesterov work_clear_pending(&work->work); 3851da177e4SLinus Torvalds return ret; 3861da177e4SLinus Torvalds } 3871da177e4SLinus Torvalds 3884e49627bSOleg Nesterov /* 3894e49627bSOleg Nesterov * Like above, but uses del_timer() instead of del_timer_sync(). This means, 3904e49627bSOleg Nesterov * if it returns 0 the timer function may be running and the queueing is in 3914e49627bSOleg Nesterov * progress. 3924e49627bSOleg Nesterov */ 393401a8d04STejun Heo static inline bool __cancel_delayed_work(struct delayed_work *work) 3944e49627bSOleg Nesterov { 395401a8d04STejun Heo bool ret; 3964e49627bSOleg Nesterov 3974e49627bSOleg Nesterov ret = del_timer(&work->timer); 3984e49627bSOleg Nesterov if (ret) 3994e49627bSOleg Nesterov work_clear_pending(&work->work); 4004e49627bSOleg Nesterov return ret; 4014e49627bSOleg Nesterov } 4024e49627bSOleg Nesterov 403f5a421a4SOleg Nesterov /* Obsolete. use cancel_delayed_work_sync() */ 4041634c48fSOleg Nesterov static inline 4051634c48fSOleg Nesterov void cancel_rearming_delayed_workqueue(struct workqueue_struct *wq, 4061634c48fSOleg Nesterov struct delayed_work *work) 4071634c48fSOleg Nesterov { 408f5a421a4SOleg Nesterov cancel_delayed_work_sync(work); 409f5a421a4SOleg Nesterov } 410f5a421a4SOleg Nesterov 411f5a421a4SOleg Nesterov /* Obsolete. use cancel_delayed_work_sync() */ 412f5a421a4SOleg Nesterov static inline 413f5a421a4SOleg Nesterov void cancel_rearming_delayed_work(struct delayed_work *work) 414f5a421a4SOleg Nesterov { 415f5a421a4SOleg Nesterov cancel_delayed_work_sync(work); 4161634c48fSOleg Nesterov } 4171634c48fSOleg Nesterov 4182d3854a3SRusty Russell #ifndef CONFIG_SMP 4192d3854a3SRusty Russell static inline long work_on_cpu(unsigned int cpu, long (*fn)(void *), void *arg) 4202d3854a3SRusty Russell { 4212d3854a3SRusty Russell return fn(arg); 4222d3854a3SRusty Russell } 4232d3854a3SRusty Russell #else 4242d3854a3SRusty Russell long work_on_cpu(unsigned int cpu, long (*fn)(void *), void *arg); 4252d3854a3SRusty Russell #endif /* CONFIG_SMP */ 426a25909a4SPaul E. McKenney 427a0a1a5fdSTejun Heo #ifdef CONFIG_FREEZER 428a0a1a5fdSTejun Heo extern void freeze_workqueues_begin(void); 429a0a1a5fdSTejun Heo extern bool freeze_workqueues_busy(void); 430a0a1a5fdSTejun Heo extern void thaw_workqueues(void); 431a0a1a5fdSTejun Heo #endif /* CONFIG_FREEZER */ 432a0a1a5fdSTejun Heo 433a25909a4SPaul E. McKenney #ifdef CONFIG_LOCKDEP 434a25909a4SPaul E. McKenney int in_workqueue_context(struct workqueue_struct *wq); 435a25909a4SPaul E. McKenney #endif 4363b7433b8SLinus Torvalds 4371da177e4SLinus Torvalds #endif 438