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 */ 246e22bee78STejun Heo WQ_RESCUER = 1 << 3, /* has an rescue worker */ 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 */ 251e41e704bSTejun Heo 252b71ab8c2STejun Heo WQ_MAX_ACTIVE = 512, /* I like 512, better ideas? */ 253f3421797STejun Heo WQ_MAX_UNBOUND_PER_CPU = 4, /* 4 * #cpus for unbound wq */ 254b71ab8c2STejun Heo WQ_DFL_ACTIVE = WQ_MAX_ACTIVE / 2, 25597e37d7bSTejun Heo }; 25652bad64dSDavid Howells 257f3421797STejun Heo /* unbound wq's aren't per-cpu, scale max_active according to #cpus */ 258f3421797STejun Heo #define WQ_UNBOUND_MAX_ACTIVE \ 259f3421797STejun Heo max_t(int, WQ_MAX_ACTIVE, num_possible_cpus() * WQ_MAX_UNBOUND_PER_CPU) 260f3421797STejun Heo 261d320c038STejun Heo /* 262d320c038STejun Heo * System-wide workqueues which are always present. 263d320c038STejun Heo * 264d320c038STejun Heo * system_wq is the one used by schedule[_delayed]_work[_on](). 265d320c038STejun Heo * Multi-CPU multi-threaded. There are users which expect relatively 266d320c038STejun Heo * short queue flush time. Don't queue works which can run for too 267d320c038STejun Heo * long. 268d320c038STejun Heo * 269d320c038STejun Heo * system_long_wq is similar to system_wq but may host long running 270d320c038STejun Heo * works. Queue flushing might take relatively long. 271d320c038STejun Heo * 272d320c038STejun Heo * system_nrt_wq is non-reentrant and guarantees that any given work 273d320c038STejun Heo * item is never executed in parallel by multiple CPUs. Queue 274d320c038STejun Heo * flushing might take relatively long. 275f3421797STejun Heo * 276f3421797STejun Heo * system_unbound_wq is unbound workqueue. Workers are not bound to 277f3421797STejun Heo * any specific CPU, not concurrency managed, and all queued works are 278f3421797STejun Heo * executed immediately as long as max_active limit is not reached and 279f3421797STejun Heo * resources are available. 280d320c038STejun Heo */ 281d320c038STejun Heo extern struct workqueue_struct *system_wq; 282d320c038STejun Heo extern struct workqueue_struct *system_long_wq; 283d320c038STejun Heo extern struct workqueue_struct *system_nrt_wq; 284f3421797STejun Heo extern struct workqueue_struct *system_unbound_wq; 2851da177e4SLinus Torvalds 2864e6045f1SJohannes Berg extern struct workqueue_struct * 287d320c038STejun Heo __alloc_workqueue_key(const char *name, unsigned int flags, int max_active, 288c790bce0STejun Heo struct lock_class_key *key, const char *lock_name); 2894e6045f1SJohannes Berg 2904e6045f1SJohannes Berg #ifdef CONFIG_LOCKDEP 291d320c038STejun Heo #define alloc_workqueue(name, flags, max_active) \ 2924e6045f1SJohannes Berg ({ \ 2934e6045f1SJohannes Berg static struct lock_class_key __key; \ 294eb13ba87SJohannes Berg const char *__lock_name; \ 295eb13ba87SJohannes Berg \ 296eb13ba87SJohannes Berg if (__builtin_constant_p(name)) \ 297eb13ba87SJohannes Berg __lock_name = (name); \ 298eb13ba87SJohannes Berg else \ 299eb13ba87SJohannes Berg __lock_name = #name; \ 3004e6045f1SJohannes Berg \ 301d320c038STejun Heo __alloc_workqueue_key((name), (flags), (max_active), \ 3021e19ffc6STejun Heo &__key, __lock_name); \ 3034e6045f1SJohannes Berg }) 3044e6045f1SJohannes Berg #else 305d320c038STejun Heo #define alloc_workqueue(name, flags, max_active) \ 306d320c038STejun Heo __alloc_workqueue_key((name), (flags), (max_active), NULL, NULL) 3074e6045f1SJohannes Berg #endif 3084e6045f1SJohannes Berg 30981dcaf65STejun Heo /** 31081dcaf65STejun Heo * alloc_ordered_workqueue - allocate an ordered workqueue 31181dcaf65STejun Heo * @name: name of the workqueue 31281dcaf65STejun Heo * @flags: WQ_* flags (only WQ_FREEZEABLE and WQ_RESCUER are meaningful) 31381dcaf65STejun Heo * 31481dcaf65STejun Heo * Allocate an ordered workqueue. An ordered workqueue executes at 31581dcaf65STejun Heo * most one work item at any given time in the queued order. They are 31681dcaf65STejun Heo * implemented as unbound workqueues with @max_active of one. 31781dcaf65STejun Heo * 31881dcaf65STejun Heo * RETURNS: 31981dcaf65STejun Heo * Pointer to the allocated workqueue on success, %NULL on failure. 32081dcaf65STejun Heo */ 32181dcaf65STejun Heo static inline struct workqueue_struct * 32281dcaf65STejun Heo alloc_ordered_workqueue(const char *name, unsigned int flags) 32381dcaf65STejun Heo { 32481dcaf65STejun Heo return alloc_workqueue(name, WQ_UNBOUND | flags, 1); 32581dcaf65STejun Heo } 32681dcaf65STejun Heo 32797e37d7bSTejun Heo #define create_workqueue(name) \ 328d320c038STejun Heo alloc_workqueue((name), WQ_RESCUER, 1) 32997e37d7bSTejun Heo #define create_freezeable_workqueue(name) \ 330c7fc77f7STejun Heo alloc_workqueue((name), WQ_FREEZEABLE | WQ_UNBOUND | WQ_RESCUER, 1) 33197e37d7bSTejun Heo #define create_singlethread_workqueue(name) \ 332c7fc77f7STejun Heo alloc_workqueue((name), WQ_UNBOUND | WQ_RESCUER, 1) 3331da177e4SLinus Torvalds 3341da177e4SLinus Torvalds extern void destroy_workqueue(struct workqueue_struct *wq); 3351da177e4SLinus Torvalds 336b3c97528SHarvey Harrison extern int queue_work(struct workqueue_struct *wq, struct work_struct *work); 337c1a220e7SZhang Rui extern int queue_work_on(int cpu, struct workqueue_struct *wq, 338c1a220e7SZhang Rui struct work_struct *work); 339b3c97528SHarvey Harrison extern int queue_delayed_work(struct workqueue_struct *wq, 340b3c97528SHarvey Harrison struct delayed_work *work, unsigned long delay); 3417a6bc1cdSVenkatesh Pallipadi extern int queue_delayed_work_on(int cpu, struct workqueue_struct *wq, 34252bad64dSDavid Howells struct delayed_work *work, unsigned long delay); 34328e53bddSOleg Nesterov 344b3c97528SHarvey Harrison extern void flush_workqueue(struct workqueue_struct *wq); 34528e53bddSOleg Nesterov extern void flush_scheduled_work(void); 34643046b60SLinus Torvalds extern void flush_delayed_work(struct delayed_work *work); 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 358db700897SOleg Nesterov extern int flush_work(struct work_struct *work); 3591f1f642eSOleg Nesterov extern int cancel_work_sync(struct work_struct *work); 36028e53bddSOleg Nesterov 361dcd989cbSTejun Heo extern void workqueue_set_max_active(struct workqueue_struct *wq, 362dcd989cbSTejun Heo int max_active); 363dcd989cbSTejun Heo extern bool workqueue_congested(unsigned int cpu, struct workqueue_struct *wq); 364dcd989cbSTejun Heo extern unsigned int work_cpu(struct work_struct *work); 365dcd989cbSTejun Heo extern unsigned int work_busy(struct work_struct *work); 366dcd989cbSTejun Heo 3671da177e4SLinus Torvalds /* 3681da177e4SLinus Torvalds * Kill off a pending schedule_delayed_work(). Note that the work callback 369071b6386SOleg Nesterov * function may still be running on return from cancel_delayed_work(), unless 370071b6386SOleg Nesterov * it returns 1 and the work doesn't re-arm itself. Run flush_workqueue() or 37128e53bddSOleg Nesterov * cancel_work_sync() to wait on it. 3721da177e4SLinus Torvalds */ 37352bad64dSDavid Howells static inline int cancel_delayed_work(struct delayed_work *work) 3741da177e4SLinus Torvalds { 3751da177e4SLinus Torvalds int ret; 3761da177e4SLinus Torvalds 377223a10a9SOleg Nesterov ret = del_timer_sync(&work->timer); 3781da177e4SLinus Torvalds if (ret) 37923b2e599SOleg Nesterov work_clear_pending(&work->work); 3801da177e4SLinus Torvalds return ret; 3811da177e4SLinus Torvalds } 3821da177e4SLinus Torvalds 3834e49627bSOleg Nesterov /* 3844e49627bSOleg Nesterov * Like above, but uses del_timer() instead of del_timer_sync(). This means, 3854e49627bSOleg Nesterov * if it returns 0 the timer function may be running and the queueing is in 3864e49627bSOleg Nesterov * progress. 3874e49627bSOleg Nesterov */ 3884e49627bSOleg Nesterov static inline int __cancel_delayed_work(struct delayed_work *work) 3894e49627bSOleg Nesterov { 3904e49627bSOleg Nesterov int ret; 3914e49627bSOleg Nesterov 3924e49627bSOleg Nesterov ret = del_timer(&work->timer); 3934e49627bSOleg Nesterov if (ret) 3944e49627bSOleg Nesterov work_clear_pending(&work->work); 3954e49627bSOleg Nesterov return ret; 3964e49627bSOleg Nesterov } 3974e49627bSOleg Nesterov 3981f1f642eSOleg Nesterov extern int cancel_delayed_work_sync(struct delayed_work *work); 3991634c48fSOleg Nesterov 400f5a421a4SOleg Nesterov /* Obsolete. use cancel_delayed_work_sync() */ 4011634c48fSOleg Nesterov static inline 4021634c48fSOleg Nesterov void cancel_rearming_delayed_workqueue(struct workqueue_struct *wq, 4031634c48fSOleg Nesterov struct delayed_work *work) 4041634c48fSOleg Nesterov { 405f5a421a4SOleg Nesterov cancel_delayed_work_sync(work); 406f5a421a4SOleg Nesterov } 407f5a421a4SOleg Nesterov 408f5a421a4SOleg Nesterov /* Obsolete. use cancel_delayed_work_sync() */ 409f5a421a4SOleg Nesterov static inline 410f5a421a4SOleg Nesterov void cancel_rearming_delayed_work(struct delayed_work *work) 411f5a421a4SOleg Nesterov { 412f5a421a4SOleg Nesterov cancel_delayed_work_sync(work); 4131634c48fSOleg Nesterov } 4141634c48fSOleg Nesterov 4152d3854a3SRusty Russell #ifndef CONFIG_SMP 4162d3854a3SRusty Russell static inline long work_on_cpu(unsigned int cpu, long (*fn)(void *), void *arg) 4172d3854a3SRusty Russell { 4182d3854a3SRusty Russell return fn(arg); 4192d3854a3SRusty Russell } 4202d3854a3SRusty Russell #else 4212d3854a3SRusty Russell long work_on_cpu(unsigned int cpu, long (*fn)(void *), void *arg); 4222d3854a3SRusty Russell #endif /* CONFIG_SMP */ 423a25909a4SPaul E. McKenney 424a0a1a5fdSTejun Heo #ifdef CONFIG_FREEZER 425a0a1a5fdSTejun Heo extern void freeze_workqueues_begin(void); 426a0a1a5fdSTejun Heo extern bool freeze_workqueues_busy(void); 427a0a1a5fdSTejun Heo extern void thaw_workqueues(void); 428a0a1a5fdSTejun Heo #endif /* CONFIG_FREEZER */ 429a0a1a5fdSTejun Heo 430a25909a4SPaul E. McKenney #ifdef CONFIG_LOCKDEP 431a25909a4SPaul E. McKenney int in_workqueue_context(struct workqueue_struct *wq); 432a25909a4SPaul E. McKenney #endif 4333b7433b8SLinus Torvalds 4341da177e4SLinus Torvalds #endif 435