diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2010-08-07 15:42:58 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-08-07 15:42:58 -0400 |
commit | 3b7433b8a8a83c87972065b1852b7dcae691e464 (patch) | |
tree | 93fa2c003f8baef5ab0733b53bac77961ed5240c /include/linux/workqueue.h | |
parent | 4a386c3e177ca2fbc70c9283d0b46537844763a0 (diff) | |
parent | 6ee0578b4daaea01c96b172c6aacca43fd9807a6 (diff) |
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq: (55 commits)
workqueue: mark init_workqueues() as early_initcall()
workqueue: explain for_each_*cwq_cpu() iterators
fscache: fix build on !CONFIG_SYSCTL
slow-work: kill it
gfs2: use workqueue instead of slow-work
drm: use workqueue instead of slow-work
cifs: use workqueue instead of slow-work
fscache: drop references to slow-work
fscache: convert operation to use workqueue instead of slow-work
fscache: convert object to use workqueue instead of slow-work
workqueue: fix how cpu number is stored in work->data
workqueue: fix mayday_mask handling on UP
workqueue: fix build problem on !CONFIG_SMP
workqueue: fix locking in retry path of maybe_create_worker()
async: use workqueue for worker pool
workqueue: remove WQ_SINGLE_CPU and use WQ_UNBOUND instead
workqueue: implement unbound workqueue
workqueue: prepare for WQ_UNBOUND implementation
libata: take advantage of cmwq and remove concurrency limitations
workqueue: fix worker management invocation without pending works
...
Fixed up conflicts in fs/cifs/* as per Tejun. Other trivial conflicts in
include/linux/workqueue.h, kernel/trace/Kconfig and kernel/workqueue.c
Diffstat (limited to 'include/linux/workqueue.h')
-rw-r--r-- | include/linux/workqueue.h | 154 |
1 files changed, 129 insertions, 25 deletions
diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h index d0f7c8178498..4f9d277bcd9a 100644 --- a/include/linux/workqueue.h +++ b/include/linux/workqueue.h | |||
@@ -9,6 +9,7 @@ | |||
9 | #include <linux/linkage.h> | 9 | #include <linux/linkage.h> |
10 | #include <linux/bitops.h> | 10 | #include <linux/bitops.h> |
11 | #include <linux/lockdep.h> | 11 | #include <linux/lockdep.h> |
12 | #include <linux/threads.h> | ||
12 | #include <asm/atomic.h> | 13 | #include <asm/atomic.h> |
13 | 14 | ||
14 | struct workqueue_struct; | 15 | struct workqueue_struct; |
@@ -22,12 +23,59 @@ typedef void (*work_func_t)(struct work_struct *work); | |||
22 | */ | 23 | */ |
23 | #define work_data_bits(work) ((unsigned long *)(&(work)->data)) | 24 | #define work_data_bits(work) ((unsigned long *)(&(work)->data)) |
24 | 25 | ||
26 | enum { | ||
27 | WORK_STRUCT_PENDING_BIT = 0, /* work item is pending execution */ | ||
28 | WORK_STRUCT_CWQ_BIT = 1, /* data points to cwq */ | ||
29 | WORK_STRUCT_LINKED_BIT = 2, /* next work is linked to this one */ | ||
30 | #ifdef CONFIG_DEBUG_OBJECTS_WORK | ||
31 | WORK_STRUCT_STATIC_BIT = 3, /* static initializer (debugobjects) */ | ||
32 | WORK_STRUCT_COLOR_SHIFT = 4, /* color for workqueue flushing */ | ||
33 | #else | ||
34 | WORK_STRUCT_COLOR_SHIFT = 3, /* color for workqueue flushing */ | ||
35 | #endif | ||
36 | |||
37 | WORK_STRUCT_COLOR_BITS = 4, | ||
38 | |||
39 | WORK_STRUCT_PENDING = 1 << WORK_STRUCT_PENDING_BIT, | ||
40 | WORK_STRUCT_CWQ = 1 << WORK_STRUCT_CWQ_BIT, | ||
41 | WORK_STRUCT_LINKED = 1 << WORK_STRUCT_LINKED_BIT, | ||
42 | #ifdef CONFIG_DEBUG_OBJECTS_WORK | ||
43 | WORK_STRUCT_STATIC = 1 << WORK_STRUCT_STATIC_BIT, | ||
44 | #else | ||
45 | WORK_STRUCT_STATIC = 0, | ||
46 | #endif | ||
47 | |||
48 | /* | ||
49 | * The last color is no color used for works which don't | ||
50 | * participate in workqueue flushing. | ||
51 | */ | ||
52 | WORK_NR_COLORS = (1 << WORK_STRUCT_COLOR_BITS) - 1, | ||
53 | WORK_NO_COLOR = WORK_NR_COLORS, | ||
54 | |||
55 | /* special cpu IDs */ | ||
56 | WORK_CPU_UNBOUND = NR_CPUS, | ||
57 | WORK_CPU_NONE = NR_CPUS + 1, | ||
58 | WORK_CPU_LAST = WORK_CPU_NONE, | ||
59 | |||
60 | /* | ||
61 | * Reserve 7 bits off of cwq pointer w/ debugobjects turned | ||
62 | * off. This makes cwqs aligned to 128 bytes which isn't too | ||
63 | * excessive while allowing 15 workqueue flush colors. | ||
64 | */ | ||
65 | WORK_STRUCT_FLAG_BITS = WORK_STRUCT_COLOR_SHIFT + | ||
66 | WORK_STRUCT_COLOR_BITS, | ||
67 | |||
68 | WORK_STRUCT_FLAG_MASK = (1UL << WORK_STRUCT_FLAG_BITS) - 1, | ||
69 | WORK_STRUCT_WQ_DATA_MASK = ~WORK_STRUCT_FLAG_MASK, | ||
70 | WORK_STRUCT_NO_CPU = WORK_CPU_NONE << WORK_STRUCT_FLAG_BITS, | ||
71 | |||
72 | /* bit mask for work_busy() return values */ | ||
73 | WORK_BUSY_PENDING = 1 << 0, | ||
74 | WORK_BUSY_RUNNING = 1 << 1, | ||
75 | }; | ||
76 | |||
25 | struct work_struct { | 77 | struct work_struct { |
26 | atomic_long_t data; | 78 | atomic_long_t data; |
27 | #define WORK_STRUCT_PENDING 0 /* T if work item pending execution */ | ||
28 | #define WORK_STRUCT_STATIC 1 /* static initializer (debugobjects) */ | ||
29 | #define WORK_STRUCT_FLAG_MASK (3UL) | ||
30 | #define WORK_STRUCT_WQ_DATA_MASK (~WORK_STRUCT_FLAG_MASK) | ||
31 | struct list_head entry; | 79 | struct list_head entry; |
32 | work_func_t func; | 80 | work_func_t func; |
33 | #ifdef CONFIG_LOCKDEP | 81 | #ifdef CONFIG_LOCKDEP |
@@ -35,8 +83,9 @@ struct work_struct { | |||
35 | #endif | 83 | #endif |
36 | }; | 84 | }; |
37 | 85 | ||
38 | #define WORK_DATA_INIT() ATOMIC_LONG_INIT(0) | 86 | #define WORK_DATA_INIT() ATOMIC_LONG_INIT(WORK_STRUCT_NO_CPU) |
39 | #define WORK_DATA_STATIC_INIT() ATOMIC_LONG_INIT(2) | 87 | #define WORK_DATA_STATIC_INIT() \ |
88 | ATOMIC_LONG_INIT(WORK_STRUCT_NO_CPU | WORK_STRUCT_STATIC) | ||
40 | 89 | ||
41 | struct delayed_work { | 90 | struct delayed_work { |
42 | struct work_struct work; | 91 | struct work_struct work; |
@@ -96,9 +145,14 @@ struct execute_work { | |||
96 | #ifdef CONFIG_DEBUG_OBJECTS_WORK | 145 | #ifdef CONFIG_DEBUG_OBJECTS_WORK |
97 | extern void __init_work(struct work_struct *work, int onstack); | 146 | extern void __init_work(struct work_struct *work, int onstack); |
98 | extern void destroy_work_on_stack(struct work_struct *work); | 147 | extern void destroy_work_on_stack(struct work_struct *work); |
148 | static inline unsigned int work_static(struct work_struct *work) | ||
149 | { | ||
150 | return *work_data_bits(work) & WORK_STRUCT_STATIC; | ||
151 | } | ||
99 | #else | 152 | #else |
100 | static inline void __init_work(struct work_struct *work, int onstack) { } | 153 | static inline void __init_work(struct work_struct *work, int onstack) { } |
101 | static inline void destroy_work_on_stack(struct work_struct *work) { } | 154 | static inline void destroy_work_on_stack(struct work_struct *work) { } |
155 | static inline unsigned int work_static(struct work_struct *work) { return 0; } | ||
102 | #endif | 156 | #endif |
103 | 157 | ||
104 | /* | 158 | /* |
@@ -162,7 +216,7 @@ static inline void destroy_work_on_stack(struct work_struct *work) { } | |||
162 | * @work: The work item in question | 216 | * @work: The work item in question |
163 | */ | 217 | */ |
164 | #define work_pending(work) \ | 218 | #define work_pending(work) \ |
165 | test_bit(WORK_STRUCT_PENDING, work_data_bits(work)) | 219 | test_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work)) |
166 | 220 | ||
167 | /** | 221 | /** |
168 | * delayed_work_pending - Find out whether a delayable work item is currently | 222 | * delayed_work_pending - Find out whether a delayable work item is currently |
@@ -177,16 +231,56 @@ static inline void destroy_work_on_stack(struct work_struct *work) { } | |||
177 | * @work: The work item in question | 231 | * @work: The work item in question |
178 | */ | 232 | */ |
179 | #define work_clear_pending(work) \ | 233 | #define work_clear_pending(work) \ |
180 | clear_bit(WORK_STRUCT_PENDING, work_data_bits(work)) | 234 | clear_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work)) |
235 | |||
236 | enum { | ||
237 | WQ_NON_REENTRANT = 1 << 0, /* guarantee non-reentrance */ | ||
238 | WQ_UNBOUND = 1 << 1, /* not bound to any cpu */ | ||
239 | WQ_FREEZEABLE = 1 << 2, /* freeze during suspend */ | ||
240 | WQ_RESCUER = 1 << 3, /* has an rescue worker */ | ||
241 | WQ_HIGHPRI = 1 << 4, /* high priority */ | ||
242 | WQ_CPU_INTENSIVE = 1 << 5, /* cpu instensive workqueue */ | ||
243 | |||
244 | WQ_MAX_ACTIVE = 512, /* I like 512, better ideas? */ | ||
245 | WQ_MAX_UNBOUND_PER_CPU = 4, /* 4 * #cpus for unbound wq */ | ||
246 | WQ_DFL_ACTIVE = WQ_MAX_ACTIVE / 2, | ||
247 | }; | ||
248 | |||
249 | /* unbound wq's aren't per-cpu, scale max_active according to #cpus */ | ||
250 | #define WQ_UNBOUND_MAX_ACTIVE \ | ||
251 | max_t(int, WQ_MAX_ACTIVE, num_possible_cpus() * WQ_MAX_UNBOUND_PER_CPU) | ||
181 | 252 | ||
253 | /* | ||
254 | * System-wide workqueues which are always present. | ||
255 | * | ||
256 | * system_wq is the one used by schedule[_delayed]_work[_on](). | ||
257 | * Multi-CPU multi-threaded. There are users which expect relatively | ||
258 | * short queue flush time. Don't queue works which can run for too | ||
259 | * long. | ||
260 | * | ||
261 | * system_long_wq is similar to system_wq but may host long running | ||
262 | * works. Queue flushing might take relatively long. | ||
263 | * | ||
264 | * system_nrt_wq is non-reentrant and guarantees that any given work | ||
265 | * item is never executed in parallel by multiple CPUs. Queue | ||
266 | * flushing might take relatively long. | ||
267 | * | ||
268 | * system_unbound_wq is unbound workqueue. Workers are not bound to | ||
269 | * any specific CPU, not concurrency managed, and all queued works are | ||
270 | * executed immediately as long as max_active limit is not reached and | ||
271 | * resources are available. | ||
272 | */ | ||
273 | extern struct workqueue_struct *system_wq; | ||
274 | extern struct workqueue_struct *system_long_wq; | ||
275 | extern struct workqueue_struct *system_nrt_wq; | ||
276 | extern struct workqueue_struct *system_unbound_wq; | ||
182 | 277 | ||
183 | extern struct workqueue_struct * | 278 | extern struct workqueue_struct * |
184 | __create_workqueue_key(const char *name, int singlethread, | 279 | __alloc_workqueue_key(const char *name, unsigned int flags, int max_active, |
185 | int freezeable, int rt, struct lock_class_key *key, | 280 | struct lock_class_key *key, const char *lock_name); |
186 | const char *lock_name); | ||
187 | 281 | ||
188 | #ifdef CONFIG_LOCKDEP | 282 | #ifdef CONFIG_LOCKDEP |
189 | #define __create_workqueue(name, singlethread, freezeable, rt) \ | 283 | #define alloc_workqueue(name, flags, max_active) \ |
190 | ({ \ | 284 | ({ \ |
191 | static struct lock_class_key __key; \ | 285 | static struct lock_class_key __key; \ |
192 | const char *__lock_name; \ | 286 | const char *__lock_name; \ |
@@ -196,20 +290,20 @@ __create_workqueue_key(const char *name, int singlethread, | |||
196 | else \ | 290 | else \ |
197 | __lock_name = #name; \ | 291 | __lock_name = #name; \ |
198 | \ | 292 | \ |
199 | __create_workqueue_key((name), (singlethread), \ | 293 | __alloc_workqueue_key((name), (flags), (max_active), \ |
200 | (freezeable), (rt), &__key, \ | 294 | &__key, __lock_name); \ |
201 | __lock_name); \ | ||
202 | }) | 295 | }) |
203 | #else | 296 | #else |
204 | #define __create_workqueue(name, singlethread, freezeable, rt) \ | 297 | #define alloc_workqueue(name, flags, max_active) \ |
205 | __create_workqueue_key((name), (singlethread), (freezeable), (rt), \ | 298 | __alloc_workqueue_key((name), (flags), (max_active), NULL, NULL) |
206 | NULL, NULL) | ||
207 | #endif | 299 | #endif |
208 | 300 | ||
209 | #define create_workqueue(name) __create_workqueue((name), 0, 0, 0) | 301 | #define create_workqueue(name) \ |
210 | #define create_rt_workqueue(name) __create_workqueue((name), 0, 0, 1) | 302 | alloc_workqueue((name), WQ_RESCUER, 1) |
211 | #define create_freezeable_workqueue(name) __create_workqueue((name), 1, 1, 0) | 303 | #define create_freezeable_workqueue(name) \ |
212 | #define create_singlethread_workqueue(name) __create_workqueue((name), 1, 0, 0) | 304 | alloc_workqueue((name), WQ_FREEZEABLE | WQ_UNBOUND | WQ_RESCUER, 1) |
305 | #define create_singlethread_workqueue(name) \ | ||
306 | alloc_workqueue((name), WQ_UNBOUND | WQ_RESCUER, 1) | ||
213 | 307 | ||
214 | extern void destroy_workqueue(struct workqueue_struct *wq); | 308 | extern void destroy_workqueue(struct workqueue_struct *wq); |
215 | 309 | ||
@@ -231,16 +325,19 @@ extern int schedule_delayed_work(struct delayed_work *work, unsigned long delay) | |||
231 | extern int schedule_delayed_work_on(int cpu, struct delayed_work *work, | 325 | extern int schedule_delayed_work_on(int cpu, struct delayed_work *work, |
232 | unsigned long delay); | 326 | unsigned long delay); |
233 | extern int schedule_on_each_cpu(work_func_t func); | 327 | extern int schedule_on_each_cpu(work_func_t func); |
234 | extern int current_is_keventd(void); | ||
235 | extern int keventd_up(void); | 328 | extern int keventd_up(void); |
236 | 329 | ||
237 | extern void init_workqueues(void); | ||
238 | int execute_in_process_context(work_func_t fn, struct execute_work *); | 330 | int execute_in_process_context(work_func_t fn, struct execute_work *); |
239 | 331 | ||
240 | extern int flush_work(struct work_struct *work); | 332 | extern int flush_work(struct work_struct *work); |
241 | |||
242 | extern int cancel_work_sync(struct work_struct *work); | 333 | extern int cancel_work_sync(struct work_struct *work); |
243 | 334 | ||
335 | extern void workqueue_set_max_active(struct workqueue_struct *wq, | ||
336 | int max_active); | ||
337 | extern bool workqueue_congested(unsigned int cpu, struct workqueue_struct *wq); | ||
338 | extern unsigned int work_cpu(struct work_struct *work); | ||
339 | extern unsigned int work_busy(struct work_struct *work); | ||
340 | |||
244 | /* | 341 | /* |
245 | * Kill off a pending schedule_delayed_work(). Note that the work callback | 342 | * Kill off a pending schedule_delayed_work(). Note that the work callback |
246 | * function may still be running on return from cancel_delayed_work(), unless | 343 | * function may still be running on return from cancel_delayed_work(), unless |
@@ -298,7 +395,14 @@ static inline long work_on_cpu(unsigned int cpu, long (*fn)(void *), void *arg) | |||
298 | long work_on_cpu(unsigned int cpu, long (*fn)(void *), void *arg); | 395 | long work_on_cpu(unsigned int cpu, long (*fn)(void *), void *arg); |
299 | #endif /* CONFIG_SMP */ | 396 | #endif /* CONFIG_SMP */ |
300 | 397 | ||
398 | #ifdef CONFIG_FREEZER | ||
399 | extern void freeze_workqueues_begin(void); | ||
400 | extern bool freeze_workqueues_busy(void); | ||
401 | extern void thaw_workqueues(void); | ||
402 | #endif /* CONFIG_FREEZER */ | ||
403 | |||
301 | #ifdef CONFIG_LOCKDEP | 404 | #ifdef CONFIG_LOCKDEP |
302 | int in_workqueue_context(struct workqueue_struct *wq); | 405 | int in_workqueue_context(struct workqueue_struct *wq); |
303 | #endif | 406 | #endif |
407 | |||
304 | #endif | 408 | #endif |