xref: /openbmc/linux/include/linux/workqueue.h (revision e41e704b)
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 */
28e120153dSTejun Heo 	WORK_STRUCT_CWQ_BIT	= 1,	/* data points to cwq */
29e120153dSTejun Heo 	WORK_STRUCT_LINKED_BIT	= 2,	/* next work is linked to this one */
3022df02bbSTejun Heo #ifdef CONFIG_DEBUG_OBJECTS_WORK
31e120153dSTejun Heo 	WORK_STRUCT_STATIC_BIT	= 3,	/* static initializer (debugobjects) */
32e120153dSTejun Heo 	WORK_STRUCT_COLOR_SHIFT	= 4,	/* color for workqueue flushing */
330f900049STejun Heo #else
34e120153dSTejun Heo 	WORK_STRUCT_COLOR_SHIFT	= 3,	/* color for workqueue flushing */
3522df02bbSTejun Heo #endif
3622df02bbSTejun Heo 
3773f53c4aSTejun Heo 	WORK_STRUCT_COLOR_BITS	= 4,
3873f53c4aSTejun Heo 
3922df02bbSTejun Heo 	WORK_STRUCT_PENDING	= 1 << WORK_STRUCT_PENDING_BIT,
40e120153dSTejun Heo 	WORK_STRUCT_CWQ		= 1 << WORK_STRUCT_CWQ_BIT,
41affee4b2STejun Heo 	WORK_STRUCT_LINKED	= 1 << WORK_STRUCT_LINKED_BIT,
4222df02bbSTejun Heo #ifdef CONFIG_DEBUG_OBJECTS_WORK
4322df02bbSTejun Heo 	WORK_STRUCT_STATIC	= 1 << WORK_STRUCT_STATIC_BIT,
4422df02bbSTejun Heo #else
4522df02bbSTejun Heo 	WORK_STRUCT_STATIC	= 0,
4622df02bbSTejun Heo #endif
4722df02bbSTejun Heo 
4873f53c4aSTejun Heo 	/*
4973f53c4aSTejun Heo 	 * The last color is no color used for works which don't
5073f53c4aSTejun Heo 	 * participate in workqueue flushing.
5173f53c4aSTejun Heo 	 */
5273f53c4aSTejun Heo 	WORK_NR_COLORS		= (1 << WORK_STRUCT_COLOR_BITS) - 1,
5373f53c4aSTejun Heo 	WORK_NO_COLOR		= WORK_NR_COLORS,
5473f53c4aSTejun Heo 
55bdbc5dd7STejun Heo 	/* special cpu IDs */
56f3421797STejun Heo 	WORK_CPU_UNBOUND	= NR_CPUS,
57f3421797STejun Heo 	WORK_CPU_NONE		= NR_CPUS + 1,
58bdbc5dd7STejun Heo 	WORK_CPU_LAST		= WORK_CPU_NONE,
59bdbc5dd7STejun Heo 
6073f53c4aSTejun Heo 	/*
61e120153dSTejun Heo 	 * Reserve 7 bits off of cwq pointer w/ debugobjects turned
62e120153dSTejun Heo 	 * off.  This makes cwqs aligned to 128 bytes which isn't too
6373f53c4aSTejun Heo 	 * excessive while allowing 15 workqueue flush colors.
6473f53c4aSTejun Heo 	 */
6573f53c4aSTejun Heo 	WORK_STRUCT_FLAG_BITS	= WORK_STRUCT_COLOR_SHIFT +
6673f53c4aSTejun Heo 				  WORK_STRUCT_COLOR_BITS,
6773f53c4aSTejun Heo 
680f900049STejun Heo 	WORK_STRUCT_FLAG_MASK	= (1UL << WORK_STRUCT_FLAG_BITS) - 1,
6922df02bbSTejun Heo 	WORK_STRUCT_WQ_DATA_MASK = ~WORK_STRUCT_FLAG_MASK,
70bdbc5dd7STejun Heo 	WORK_STRUCT_NO_CPU	= WORK_CPU_NONE << WORK_STRUCT_FLAG_BITS,
71dcd989cbSTejun Heo 
72dcd989cbSTejun Heo 	/* bit mask for work_busy() return values */
73dcd989cbSTejun Heo 	WORK_BUSY_PENDING	= 1 << 0,
74dcd989cbSTejun Heo 	WORK_BUSY_RUNNING	= 1 << 1,
7522df02bbSTejun Heo };
7622df02bbSTejun Heo 
771da177e4SLinus Torvalds struct work_struct {
78a08727baSLinus Torvalds 	atomic_long_t data;
791da177e4SLinus Torvalds 	struct list_head entry;
806bb49e59SDavid Howells 	work_func_t func;
814e6045f1SJohannes Berg #ifdef CONFIG_LOCKDEP
824e6045f1SJohannes Berg 	struct lockdep_map lockdep_map;
834e6045f1SJohannes Berg #endif
8452bad64dSDavid Howells };
8552bad64dSDavid Howells 
867a22ad75STejun Heo #define WORK_DATA_INIT()	ATOMIC_LONG_INIT(WORK_STRUCT_NO_CPU)
877a22ad75STejun Heo #define WORK_DATA_STATIC_INIT()	\
887a22ad75STejun Heo 	ATOMIC_LONG_INIT(WORK_STRUCT_NO_CPU | WORK_STRUCT_STATIC)
89a08727baSLinus Torvalds 
9052bad64dSDavid Howells struct delayed_work {
9152bad64dSDavid Howells 	struct work_struct work;
921da177e4SLinus Torvalds 	struct timer_list timer;
931da177e4SLinus Torvalds };
941da177e4SLinus Torvalds 
95bf6aede7SJean Delvare static inline struct delayed_work *to_delayed_work(struct work_struct *work)
96bf6aede7SJean Delvare {
97bf6aede7SJean Delvare 	return container_of(work, struct delayed_work, work);
98bf6aede7SJean Delvare }
99bf6aede7SJean Delvare 
1001fa44ecaSJames Bottomley struct execute_work {
1011fa44ecaSJames Bottomley 	struct work_struct work;
1021fa44ecaSJames Bottomley };
1031fa44ecaSJames Bottomley 
1044e6045f1SJohannes Berg #ifdef CONFIG_LOCKDEP
1054e6045f1SJohannes Berg /*
1064e6045f1SJohannes Berg  * NB: because we have to copy the lockdep_map, setting _key
1074e6045f1SJohannes Berg  * here is required, otherwise it could get initialised to the
1084e6045f1SJohannes Berg  * copy of the lockdep_map!
1094e6045f1SJohannes Berg  */
1104e6045f1SJohannes Berg #define __WORK_INIT_LOCKDEP_MAP(n, k) \
1114e6045f1SJohannes Berg 	.lockdep_map = STATIC_LOCKDEP_MAP_INIT(n, k),
1124e6045f1SJohannes Berg #else
1134e6045f1SJohannes Berg #define __WORK_INIT_LOCKDEP_MAP(n, k)
1144e6045f1SJohannes Berg #endif
1154e6045f1SJohannes Berg 
11665f27f38SDavid Howells #define __WORK_INITIALIZER(n, f) {				\
117dc186ad7SThomas Gleixner 	.data = WORK_DATA_STATIC_INIT(),			\
11865f27f38SDavid Howells 	.entry	= { &(n).entry, &(n).entry },			\
11965f27f38SDavid Howells 	.func = (f),						\
1204e6045f1SJohannes Berg 	__WORK_INIT_LOCKDEP_MAP(#n, &(n))			\
12165f27f38SDavid Howells 	}
12265f27f38SDavid Howells 
12365f27f38SDavid Howells #define __DELAYED_WORK_INITIALIZER(n, f) {			\
12465f27f38SDavid Howells 	.work = __WORK_INITIALIZER((n).work, (f)),		\
1251da177e4SLinus Torvalds 	.timer = TIMER_INITIALIZER(NULL, 0, 0),			\
1261da177e4SLinus Torvalds 	}
1271da177e4SLinus Torvalds 
12865f27f38SDavid Howells #define DECLARE_WORK(n, f)					\
12965f27f38SDavid Howells 	struct work_struct n = __WORK_INITIALIZER(n, f)
13065f27f38SDavid Howells 
13165f27f38SDavid Howells #define DECLARE_DELAYED_WORK(n, f)				\
13265f27f38SDavid Howells 	struct delayed_work n = __DELAYED_WORK_INITIALIZER(n, f)
13365f27f38SDavid Howells 
1341da177e4SLinus Torvalds /*
13565f27f38SDavid Howells  * initialize a work item's function pointer
1361da177e4SLinus Torvalds  */
13765f27f38SDavid Howells #define PREPARE_WORK(_work, _func)				\
1381da177e4SLinus Torvalds 	do {							\
13952bad64dSDavid Howells 		(_work)->func = (_func);			\
1401da177e4SLinus Torvalds 	} while (0)
1411da177e4SLinus Torvalds 
14265f27f38SDavid Howells #define PREPARE_DELAYED_WORK(_work, _func)			\
14365f27f38SDavid Howells 	PREPARE_WORK(&(_work)->work, (_func))
14452bad64dSDavid Howells 
145dc186ad7SThomas Gleixner #ifdef CONFIG_DEBUG_OBJECTS_WORK
146dc186ad7SThomas Gleixner extern void __init_work(struct work_struct *work, int onstack);
147dc186ad7SThomas Gleixner extern void destroy_work_on_stack(struct work_struct *work);
1484690c4abSTejun Heo static inline unsigned int work_static(struct work_struct *work)
1494690c4abSTejun Heo {
15022df02bbSTejun Heo 	return *work_data_bits(work) & WORK_STRUCT_STATIC;
1514690c4abSTejun Heo }
152dc186ad7SThomas Gleixner #else
153dc186ad7SThomas Gleixner static inline void __init_work(struct work_struct *work, int onstack) { }
154dc186ad7SThomas Gleixner static inline void destroy_work_on_stack(struct work_struct *work) { }
1554690c4abSTejun Heo static inline unsigned int work_static(struct work_struct *work) { return 0; }
156dc186ad7SThomas Gleixner #endif
157dc186ad7SThomas Gleixner 
1581da177e4SLinus Torvalds /*
15952bad64dSDavid Howells  * initialize all of a work item in one go
160a08727baSLinus Torvalds  *
161b9049df5SDmitri Vorobiev  * NOTE! No point in using "atomic_long_set()": using a direct
162a08727baSLinus Torvalds  * assignment of the work data initializer allows the compiler
163a08727baSLinus Torvalds  * to generate better code.
1641da177e4SLinus Torvalds  */
1654e6045f1SJohannes Berg #ifdef CONFIG_LOCKDEP
166dc186ad7SThomas Gleixner #define __INIT_WORK(_work, _func, _onstack)				\
1674e6045f1SJohannes Berg 	do {								\
1684e6045f1SJohannes Berg 		static struct lock_class_key __key;			\
1694e6045f1SJohannes Berg 									\
170dc186ad7SThomas Gleixner 		__init_work((_work), _onstack);				\
1714e6045f1SJohannes Berg 		(_work)->data = (atomic_long_t) WORK_DATA_INIT();	\
1724e6045f1SJohannes Berg 		lockdep_init_map(&(_work)->lockdep_map, #_work, &__key, 0);\
1734e6045f1SJohannes Berg 		INIT_LIST_HEAD(&(_work)->entry);			\
1744e6045f1SJohannes Berg 		PREPARE_WORK((_work), (_func));				\
1754e6045f1SJohannes Berg 	} while (0)
1764e6045f1SJohannes Berg #else
177dc186ad7SThomas Gleixner #define __INIT_WORK(_work, _func, _onstack)				\
1781da177e4SLinus Torvalds 	do {								\
179dc186ad7SThomas Gleixner 		__init_work((_work), _onstack);				\
18023b2e599SOleg Nesterov 		(_work)->data = (atomic_long_t) WORK_DATA_INIT();	\
18165f27f38SDavid Howells 		INIT_LIST_HEAD(&(_work)->entry);			\
18265f27f38SDavid Howells 		PREPARE_WORK((_work), (_func));				\
18365f27f38SDavid Howells 	} while (0)
1844e6045f1SJohannes Berg #endif
18565f27f38SDavid Howells 
186dc186ad7SThomas Gleixner #define INIT_WORK(_work, _func)					\
187dc186ad7SThomas Gleixner 	do {							\
188dc186ad7SThomas Gleixner 		__INIT_WORK((_work), (_func), 0);		\
189dc186ad7SThomas Gleixner 	} while (0)
190dc186ad7SThomas Gleixner 
191dc186ad7SThomas Gleixner #define INIT_WORK_ON_STACK(_work, _func)			\
192dc186ad7SThomas Gleixner 	do {							\
193dc186ad7SThomas Gleixner 		__INIT_WORK((_work), (_func), 1);		\
194dc186ad7SThomas Gleixner 	} while (0)
195dc186ad7SThomas Gleixner 
19665f27f38SDavid Howells #define INIT_DELAYED_WORK(_work, _func)				\
19765f27f38SDavid Howells 	do {							\
19865f27f38SDavid Howells 		INIT_WORK(&(_work)->work, (_func));		\
19965f27f38SDavid Howells 		init_timer(&(_work)->timer);			\
20065f27f38SDavid Howells 	} while (0)
20165f27f38SDavid Howells 
2026d612b0fSPeter Zijlstra #define INIT_DELAYED_WORK_ON_STACK(_work, _func)		\
2036d612b0fSPeter Zijlstra 	do {							\
204dc186ad7SThomas Gleixner 		INIT_WORK_ON_STACK(&(_work)->work, (_func));	\
2056d612b0fSPeter Zijlstra 		init_timer_on_stack(&(_work)->timer);		\
2066d612b0fSPeter Zijlstra 	} while (0)
2076d612b0fSPeter Zijlstra 
20828287033SVenki Pallipadi #define INIT_DELAYED_WORK_DEFERRABLE(_work, _func)		\
20928287033SVenki Pallipadi 	do {							\
21028287033SVenki Pallipadi 		INIT_WORK(&(_work)->work, (_func));		\
21128287033SVenki Pallipadi 		init_timer_deferrable(&(_work)->timer);		\
21228287033SVenki Pallipadi 	} while (0)
21328287033SVenki Pallipadi 
214365970a1SDavid Howells /**
215365970a1SDavid Howells  * work_pending - Find out whether a work item is currently pending
216365970a1SDavid Howells  * @work: The work item in question
217365970a1SDavid Howells  */
218365970a1SDavid Howells #define work_pending(work) \
21922df02bbSTejun Heo 	test_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))
220365970a1SDavid Howells 
221365970a1SDavid Howells /**
222365970a1SDavid Howells  * delayed_work_pending - Find out whether a delayable work item is currently
223365970a1SDavid Howells  * pending
224365970a1SDavid Howells  * @work: The work item in question
225365970a1SDavid Howells  */
2260221872aSLinus Torvalds #define delayed_work_pending(w) \
2270221872aSLinus Torvalds 	work_pending(&(w)->work)
228365970a1SDavid Howells 
22965f27f38SDavid Howells /**
23023b2e599SOleg Nesterov  * work_clear_pending - for internal use only, mark a work item as not pending
23123b2e599SOleg Nesterov  * @work: The work item in question
23265f27f38SDavid Howells  */
23323b2e599SOleg Nesterov #define work_clear_pending(work) \
23422df02bbSTejun Heo 	clear_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))
23565f27f38SDavid Howells 
23697e37d7bSTejun Heo enum {
237bdbc5dd7STejun Heo 	WQ_NON_REENTRANT	= 1 << 0, /* guarantee non-reentrance */
238c7fc77f7STejun Heo 	WQ_UNBOUND		= 1 << 1, /* not bound to any cpu */
239bdbc5dd7STejun Heo 	WQ_FREEZEABLE		= 1 << 2, /* freeze during suspend */
240e22bee78STejun Heo 	WQ_RESCUER		= 1 << 3, /* has an rescue worker */
241649027d7STejun Heo 	WQ_HIGHPRI		= 1 << 4, /* high priority */
242fb0e7bebSTejun Heo 	WQ_CPU_INTENSIVE	= 1 << 5, /* cpu instensive workqueue */
243b71ab8c2STejun Heo 
244e41e704bSTejun Heo 	WQ_DYING		= 1 << 6, /* internal: workqueue is dying */
245e41e704bSTejun Heo 
246b71ab8c2STejun Heo 	WQ_MAX_ACTIVE		= 512,	  /* I like 512, better ideas? */
247f3421797STejun Heo 	WQ_MAX_UNBOUND_PER_CPU	= 4,	  /* 4 * #cpus for unbound wq */
248b71ab8c2STejun Heo 	WQ_DFL_ACTIVE		= WQ_MAX_ACTIVE / 2,
24997e37d7bSTejun Heo };
25052bad64dSDavid Howells 
251f3421797STejun Heo /* unbound wq's aren't per-cpu, scale max_active according to #cpus */
252f3421797STejun Heo #define WQ_UNBOUND_MAX_ACTIVE	\
253f3421797STejun Heo 	max_t(int, WQ_MAX_ACTIVE, num_possible_cpus() * WQ_MAX_UNBOUND_PER_CPU)
254f3421797STejun Heo 
255d320c038STejun Heo /*
256d320c038STejun Heo  * System-wide workqueues which are always present.
257d320c038STejun Heo  *
258d320c038STejun Heo  * system_wq is the one used by schedule[_delayed]_work[_on]().
259d320c038STejun Heo  * Multi-CPU multi-threaded.  There are users which expect relatively
260d320c038STejun Heo  * short queue flush time.  Don't queue works which can run for too
261d320c038STejun Heo  * long.
262d320c038STejun Heo  *
263d320c038STejun Heo  * system_long_wq is similar to system_wq but may host long running
264d320c038STejun Heo  * works.  Queue flushing might take relatively long.
265d320c038STejun Heo  *
266d320c038STejun Heo  * system_nrt_wq is non-reentrant and guarantees that any given work
267d320c038STejun Heo  * item is never executed in parallel by multiple CPUs.  Queue
268d320c038STejun Heo  * flushing might take relatively long.
269f3421797STejun Heo  *
270f3421797STejun Heo  * system_unbound_wq is unbound workqueue.  Workers are not bound to
271f3421797STejun Heo  * any specific CPU, not concurrency managed, and all queued works are
272f3421797STejun Heo  * executed immediately as long as max_active limit is not reached and
273f3421797STejun Heo  * resources are available.
274d320c038STejun Heo  */
275d320c038STejun Heo extern struct workqueue_struct *system_wq;
276d320c038STejun Heo extern struct workqueue_struct *system_long_wq;
277d320c038STejun Heo extern struct workqueue_struct *system_nrt_wq;
278f3421797STejun Heo extern struct workqueue_struct *system_unbound_wq;
2791da177e4SLinus Torvalds 
2804e6045f1SJohannes Berg extern struct workqueue_struct *
281d320c038STejun Heo __alloc_workqueue_key(const char *name, unsigned int flags, int max_active,
282c790bce0STejun Heo 		      struct lock_class_key *key, const char *lock_name);
2834e6045f1SJohannes Berg 
2844e6045f1SJohannes Berg #ifdef CONFIG_LOCKDEP
285d320c038STejun Heo #define alloc_workqueue(name, flags, max_active)		\
2864e6045f1SJohannes Berg ({								\
2874e6045f1SJohannes Berg 	static struct lock_class_key __key;			\
288eb13ba87SJohannes Berg 	const char *__lock_name;				\
289eb13ba87SJohannes Berg 								\
290eb13ba87SJohannes Berg 	if (__builtin_constant_p(name))				\
291eb13ba87SJohannes Berg 		__lock_name = (name);				\
292eb13ba87SJohannes Berg 	else							\
293eb13ba87SJohannes Berg 		__lock_name = #name;				\
2944e6045f1SJohannes Berg 								\
295d320c038STejun Heo 	__alloc_workqueue_key((name), (flags), (max_active),	\
2961e19ffc6STejun Heo 			      &__key, __lock_name);		\
2974e6045f1SJohannes Berg })
2984e6045f1SJohannes Berg #else
299d320c038STejun Heo #define alloc_workqueue(name, flags, max_active)		\
300d320c038STejun Heo 	__alloc_workqueue_key((name), (flags), (max_active), NULL, NULL)
3014e6045f1SJohannes Berg #endif
3024e6045f1SJohannes Berg 
30397e37d7bSTejun Heo #define create_workqueue(name)					\
304d320c038STejun Heo 	alloc_workqueue((name), WQ_RESCUER, 1)
30597e37d7bSTejun Heo #define create_freezeable_workqueue(name)			\
306c7fc77f7STejun Heo 	alloc_workqueue((name), WQ_FREEZEABLE | WQ_UNBOUND | WQ_RESCUER, 1)
30797e37d7bSTejun Heo #define create_singlethread_workqueue(name)			\
308c7fc77f7STejun Heo 	alloc_workqueue((name), WQ_UNBOUND | WQ_RESCUER, 1)
3091da177e4SLinus Torvalds 
3101da177e4SLinus Torvalds extern void destroy_workqueue(struct workqueue_struct *wq);
3111da177e4SLinus Torvalds 
312b3c97528SHarvey Harrison extern int queue_work(struct workqueue_struct *wq, struct work_struct *work);
313c1a220e7SZhang Rui extern int queue_work_on(int cpu, struct workqueue_struct *wq,
314c1a220e7SZhang Rui 			struct work_struct *work);
315b3c97528SHarvey Harrison extern int queue_delayed_work(struct workqueue_struct *wq,
316b3c97528SHarvey Harrison 			struct delayed_work *work, unsigned long delay);
3177a6bc1cdSVenkatesh Pallipadi extern int queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
31852bad64dSDavid Howells 			struct delayed_work *work, unsigned long delay);
31928e53bddSOleg Nesterov 
320b3c97528SHarvey Harrison extern void flush_workqueue(struct workqueue_struct *wq);
32128e53bddSOleg Nesterov extern void flush_scheduled_work(void);
32243046b60SLinus Torvalds extern void flush_delayed_work(struct delayed_work *work);
3231da177e4SLinus Torvalds 
324b3c97528SHarvey Harrison extern int schedule_work(struct work_struct *work);
325c1a220e7SZhang Rui extern int schedule_work_on(int cpu, struct work_struct *work);
326b3c97528SHarvey Harrison extern int schedule_delayed_work(struct delayed_work *work, unsigned long delay);
32728e53bddSOleg Nesterov extern int schedule_delayed_work_on(int cpu, struct delayed_work *work,
32828e53bddSOleg Nesterov 					unsigned long delay);
32965f27f38SDavid Howells extern int schedule_on_each_cpu(work_func_t func);
3301da177e4SLinus Torvalds extern int keventd_up(void);
3311da177e4SLinus Torvalds 
33265f27f38SDavid Howells int execute_in_process_context(work_func_t fn, struct execute_work *);
3331da177e4SLinus Torvalds 
334db700897SOleg Nesterov extern int flush_work(struct work_struct *work);
3351f1f642eSOleg Nesterov extern int cancel_work_sync(struct work_struct *work);
33628e53bddSOleg Nesterov 
337dcd989cbSTejun Heo extern void workqueue_set_max_active(struct workqueue_struct *wq,
338dcd989cbSTejun Heo 				     int max_active);
339dcd989cbSTejun Heo extern bool workqueue_congested(unsigned int cpu, struct workqueue_struct *wq);
340dcd989cbSTejun Heo extern unsigned int work_cpu(struct work_struct *work);
341dcd989cbSTejun Heo extern unsigned int work_busy(struct work_struct *work);
342dcd989cbSTejun Heo 
3431da177e4SLinus Torvalds /*
3441da177e4SLinus Torvalds  * Kill off a pending schedule_delayed_work().  Note that the work callback
345071b6386SOleg Nesterov  * function may still be running on return from cancel_delayed_work(), unless
346071b6386SOleg Nesterov  * it returns 1 and the work doesn't re-arm itself. Run flush_workqueue() or
34728e53bddSOleg Nesterov  * cancel_work_sync() to wait on it.
3481da177e4SLinus Torvalds  */
34952bad64dSDavid Howells static inline int cancel_delayed_work(struct delayed_work *work)
3501da177e4SLinus Torvalds {
3511da177e4SLinus Torvalds 	int ret;
3521da177e4SLinus Torvalds 
353223a10a9SOleg Nesterov 	ret = del_timer_sync(&work->timer);
3541da177e4SLinus Torvalds 	if (ret)
35523b2e599SOleg Nesterov 		work_clear_pending(&work->work);
3561da177e4SLinus Torvalds 	return ret;
3571da177e4SLinus Torvalds }
3581da177e4SLinus Torvalds 
3594e49627bSOleg Nesterov /*
3604e49627bSOleg Nesterov  * Like above, but uses del_timer() instead of del_timer_sync(). This means,
3614e49627bSOleg Nesterov  * if it returns 0 the timer function may be running and the queueing is in
3624e49627bSOleg Nesterov  * progress.
3634e49627bSOleg Nesterov  */
3644e49627bSOleg Nesterov static inline int __cancel_delayed_work(struct delayed_work *work)
3654e49627bSOleg Nesterov {
3664e49627bSOleg Nesterov 	int ret;
3674e49627bSOleg Nesterov 
3684e49627bSOleg Nesterov 	ret = del_timer(&work->timer);
3694e49627bSOleg Nesterov 	if (ret)
3704e49627bSOleg Nesterov 		work_clear_pending(&work->work);
3714e49627bSOleg Nesterov 	return ret;
3724e49627bSOleg Nesterov }
3734e49627bSOleg Nesterov 
3741f1f642eSOleg Nesterov extern int cancel_delayed_work_sync(struct delayed_work *work);
3751634c48fSOleg Nesterov 
376f5a421a4SOleg Nesterov /* Obsolete. use cancel_delayed_work_sync() */
3771634c48fSOleg Nesterov static inline
3781634c48fSOleg Nesterov void cancel_rearming_delayed_workqueue(struct workqueue_struct *wq,
3791634c48fSOleg Nesterov 					struct delayed_work *work)
3801634c48fSOleg Nesterov {
381f5a421a4SOleg Nesterov 	cancel_delayed_work_sync(work);
382f5a421a4SOleg Nesterov }
383f5a421a4SOleg Nesterov 
384f5a421a4SOleg Nesterov /* Obsolete. use cancel_delayed_work_sync() */
385f5a421a4SOleg Nesterov static inline
386f5a421a4SOleg Nesterov void cancel_rearming_delayed_work(struct delayed_work *work)
387f5a421a4SOleg Nesterov {
388f5a421a4SOleg Nesterov 	cancel_delayed_work_sync(work);
3891634c48fSOleg Nesterov }
3901634c48fSOleg Nesterov 
3912d3854a3SRusty Russell #ifndef CONFIG_SMP
3922d3854a3SRusty Russell static inline long work_on_cpu(unsigned int cpu, long (*fn)(void *), void *arg)
3932d3854a3SRusty Russell {
3942d3854a3SRusty Russell 	return fn(arg);
3952d3854a3SRusty Russell }
3962d3854a3SRusty Russell #else
3972d3854a3SRusty Russell long work_on_cpu(unsigned int cpu, long (*fn)(void *), void *arg);
3982d3854a3SRusty Russell #endif /* CONFIG_SMP */
399a25909a4SPaul E. McKenney 
400a0a1a5fdSTejun Heo #ifdef CONFIG_FREEZER
401a0a1a5fdSTejun Heo extern void freeze_workqueues_begin(void);
402a0a1a5fdSTejun Heo extern bool freeze_workqueues_busy(void);
403a0a1a5fdSTejun Heo extern void thaw_workqueues(void);
404a0a1a5fdSTejun Heo #endif /* CONFIG_FREEZER */
405a0a1a5fdSTejun Heo 
406a25909a4SPaul E. McKenney #ifdef CONFIG_LOCKDEP
407a25909a4SPaul E. McKenney int in_workqueue_context(struct workqueue_struct *wq);
408a25909a4SPaul E. McKenney #endif
4093b7433b8SLinus Torvalds 
4101da177e4SLinus Torvalds #endif
411