diff options
| author | Michal Marek <mmarek@suse.cz> | 2010-10-27 18:15:57 -0400 |
|---|---|---|
| committer | Michal Marek <mmarek@suse.cz> | 2010-10-27 18:15:57 -0400 |
| commit | b74b953b998bcc2db91b694446f3a2619ec32de6 (patch) | |
| tree | 6ce24caabd730f6ae9287ed0676ec32e6ff31e9d /include/linux/workqueue.h | |
| parent | abb438526201c6a79949ad45375c051b6681c253 (diff) | |
| parent | f6f94e2ab1b33f0082ac22d71f66385a60d8157f (diff) | |
Merge commit 'v2.6.36' into kbuild/misc
Update to be able to fix a recent change to scripts/basic/docproc.c
(commit eda603f).
Diffstat (limited to 'include/linux/workqueue.h')
| -rw-r--r-- | include/linux/workqueue.h | 166 |
1 files changed, 141 insertions, 25 deletions
diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h index 9466e860d8c2..25e02c941bac 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,61 @@ 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_DELAYED_BIT = 1, /* work item is delayed */ | ||
| 29 | WORK_STRUCT_CWQ_BIT = 2, /* data points to cwq */ | ||
| 30 | WORK_STRUCT_LINKED_BIT = 3, /* next work is linked to this one */ | ||
| 31 | #ifdef CONFIG_DEBUG_OBJECTS_WORK | ||
| 32 | WORK_STRUCT_STATIC_BIT = 4, /* static initializer (debugobjects) */ | ||
| 33 | WORK_STRUCT_COLOR_SHIFT = 5, /* color for workqueue flushing */ | ||
| 34 | #else | ||
| 35 | WORK_STRUCT_COLOR_SHIFT = 4, /* color for workqueue flushing */ | ||
| 36 | #endif | ||
| 37 | |||
| 38 | WORK_STRUCT_COLOR_BITS = 4, | ||
| 39 | |||
| 40 | WORK_STRUCT_PENDING = 1 << WORK_STRUCT_PENDING_BIT, | ||
| 41 | WORK_STRUCT_DELAYED = 1 << WORK_STRUCT_DELAYED_BIT, | ||
| 42 | WORK_STRUCT_CWQ = 1 << WORK_STRUCT_CWQ_BIT, | ||
| 43 | WORK_STRUCT_LINKED = 1 << WORK_STRUCT_LINKED_BIT, | ||
| 44 | #ifdef CONFIG_DEBUG_OBJECTS_WORK | ||
| 45 | WORK_STRUCT_STATIC = 1 << WORK_STRUCT_STATIC_BIT, | ||
| 46 | #else | ||
| 47 | WORK_STRUCT_STATIC = 0, | ||
| 48 | #endif | ||
| 49 | |||
| 50 | /* | ||
| 51 | * The last color is no color used for works which don't | ||
| 52 | * participate in workqueue flushing. | ||
| 53 | */ | ||
| 54 | WORK_NR_COLORS = (1 << WORK_STRUCT_COLOR_BITS) - 1, | ||
| 55 | WORK_NO_COLOR = WORK_NR_COLORS, | ||
| 56 | |||
| 57 | /* special cpu IDs */ | ||
| 58 | WORK_CPU_UNBOUND = NR_CPUS, | ||
| 59 | WORK_CPU_NONE = NR_CPUS + 1, | ||
| 60 | WORK_CPU_LAST = WORK_CPU_NONE, | ||
| 61 | |||
| 62 | /* | ||
| 63 | * Reserve 7 bits off of cwq pointer w/ debugobjects turned | ||
| 64 | * off. This makes cwqs aligned to 256 bytes and allows 15 | ||
| 65 | * workqueue flush colors. | ||
| 66 | */ | ||
| 67 | WORK_STRUCT_FLAG_BITS = WORK_STRUCT_COLOR_SHIFT + | ||
| 68 | WORK_STRUCT_COLOR_BITS, | ||
| 69 | |||
| 70 | WORK_STRUCT_FLAG_MASK = (1UL << WORK_STRUCT_FLAG_BITS) - 1, | ||
| 71 | WORK_STRUCT_WQ_DATA_MASK = ~WORK_STRUCT_FLAG_MASK, | ||
| 72 | WORK_STRUCT_NO_CPU = WORK_CPU_NONE << WORK_STRUCT_FLAG_BITS, | ||
| 73 | |||
| 74 | /* bit mask for work_busy() return values */ | ||
| 75 | WORK_BUSY_PENDING = 1 << 0, | ||
| 76 | WORK_BUSY_RUNNING = 1 << 1, | ||
| 77 | }; | ||
| 78 | |||
| 25 | struct work_struct { | 79 | struct work_struct { |
| 26 | atomic_long_t data; | 80 | 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; | 81 | struct list_head entry; |
| 32 | work_func_t func; | 82 | work_func_t func; |
| 33 | #ifdef CONFIG_LOCKDEP | 83 | #ifdef CONFIG_LOCKDEP |
| @@ -35,8 +85,9 @@ struct work_struct { | |||
| 35 | #endif | 85 | #endif |
| 36 | }; | 86 | }; |
| 37 | 87 | ||
| 38 | #define WORK_DATA_INIT() ATOMIC_LONG_INIT(0) | 88 | #define WORK_DATA_INIT() ATOMIC_LONG_INIT(WORK_STRUCT_NO_CPU) |
| 39 | #define WORK_DATA_STATIC_INIT() ATOMIC_LONG_INIT(2) | 89 | #define WORK_DATA_STATIC_INIT() \ |
| 90 | ATOMIC_LONG_INIT(WORK_STRUCT_NO_CPU | WORK_STRUCT_STATIC) | ||
| 40 | 91 | ||
| 41 | struct delayed_work { | 92 | struct delayed_work { |
| 42 | struct work_struct work; | 93 | struct work_struct work; |
| @@ -96,9 +147,14 @@ struct execute_work { | |||
| 96 | #ifdef CONFIG_DEBUG_OBJECTS_WORK | 147 | #ifdef CONFIG_DEBUG_OBJECTS_WORK |
| 97 | extern void __init_work(struct work_struct *work, int onstack); | 148 | extern void __init_work(struct work_struct *work, int onstack); |
| 98 | extern void destroy_work_on_stack(struct work_struct *work); | 149 | extern void destroy_work_on_stack(struct work_struct *work); |
| 150 | static inline unsigned int work_static(struct work_struct *work) | ||
| 151 | { | ||
| 152 | return *work_data_bits(work) & WORK_STRUCT_STATIC; | ||
| 153 | } | ||
| 99 | #else | 154 | #else |
| 100 | static inline void __init_work(struct work_struct *work, int onstack) { } | 155 | static inline void __init_work(struct work_struct *work, int onstack) { } |
| 101 | static inline void destroy_work_on_stack(struct work_struct *work) { } | 156 | static inline void destroy_work_on_stack(struct work_struct *work) { } |
| 157 | static inline unsigned int work_static(struct work_struct *work) { return 0; } | ||
| 102 | #endif | 158 | #endif |
| 103 | 159 | ||
| 104 | /* | 160 | /* |
| @@ -162,7 +218,7 @@ static inline void destroy_work_on_stack(struct work_struct *work) { } | |||
| 162 | * @work: The work item in question | 218 | * @work: The work item in question |
| 163 | */ | 219 | */ |
| 164 | #define work_pending(work) \ | 220 | #define work_pending(work) \ |
| 165 | test_bit(WORK_STRUCT_PENDING, work_data_bits(work)) | 221 | test_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work)) |
| 166 | 222 | ||
| 167 | /** | 223 | /** |
| 168 | * delayed_work_pending - Find out whether a delayable work item is currently | 224 | * delayed_work_pending - Find out whether a delayable work item is currently |
| @@ -177,16 +233,62 @@ static inline void destroy_work_on_stack(struct work_struct *work) { } | |||
| 177 | * @work: The work item in question | 233 | * @work: The work item in question |
| 178 | */ | 234 | */ |
| 179 | #define work_clear_pending(work) \ | 235 | #define work_clear_pending(work) \ |
| 180 | clear_bit(WORK_STRUCT_PENDING, work_data_bits(work)) | 236 | clear_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work)) |
| 181 | 237 | ||
| 238 | /* | ||
| 239 | * Workqueue flags and constants. For details, please refer to | ||
| 240 | * Documentation/workqueue.txt. | ||
| 241 | */ | ||
| 242 | enum { | ||
| 243 | WQ_NON_REENTRANT = 1 << 0, /* guarantee non-reentrance */ | ||
| 244 | WQ_UNBOUND = 1 << 1, /* not bound to any cpu */ | ||
| 245 | WQ_FREEZEABLE = 1 << 2, /* freeze during suspend */ | ||
| 246 | WQ_RESCUER = 1 << 3, /* has an rescue worker */ | ||
| 247 | WQ_HIGHPRI = 1 << 4, /* high priority */ | ||
| 248 | WQ_CPU_INTENSIVE = 1 << 5, /* cpu instensive workqueue */ | ||
| 249 | |||
| 250 | WQ_DYING = 1 << 6, /* internal: workqueue is dying */ | ||
| 251 | |||
| 252 | WQ_MAX_ACTIVE = 512, /* I like 512, better ideas? */ | ||
| 253 | WQ_MAX_UNBOUND_PER_CPU = 4, /* 4 * #cpus for unbound wq */ | ||
| 254 | WQ_DFL_ACTIVE = WQ_MAX_ACTIVE / 2, | ||
| 255 | }; | ||
| 256 | |||
| 257 | /* unbound wq's aren't per-cpu, scale max_active according to #cpus */ | ||
| 258 | #define WQ_UNBOUND_MAX_ACTIVE \ | ||
| 259 | max_t(int, WQ_MAX_ACTIVE, num_possible_cpus() * WQ_MAX_UNBOUND_PER_CPU) | ||
| 260 | |||
| 261 | /* | ||
| 262 | * System-wide workqueues which are always present. | ||
| 263 | * | ||
| 264 | * system_wq is the one used by schedule[_delayed]_work[_on](). | ||
| 265 | * Multi-CPU multi-threaded. There are users which expect relatively | ||
| 266 | * short queue flush time. Don't queue works which can run for too | ||
| 267 | * long. | ||
| 268 | * | ||
| 269 | * system_long_wq is similar to system_wq but may host long running | ||
| 270 | * works. Queue flushing might take relatively long. | ||
| 271 | * | ||
| 272 | * system_nrt_wq is non-reentrant and guarantees that any given work | ||
| 273 | * item is never executed in parallel by multiple CPUs. Queue | ||
| 274 | * flushing might take relatively long. | ||
| 275 | * | ||
| 276 | * system_unbound_wq is unbound workqueue. Workers are not bound to | ||
| 277 | * any specific CPU, not concurrency managed, and all queued works are | ||
| 278 | * executed immediately as long as max_active limit is not reached and | ||
| 279 | * resources are available. | ||
| 280 | */ | ||
| 281 | extern struct workqueue_struct *system_wq; | ||
| 282 | extern struct workqueue_struct *system_long_wq; | ||
| 283 | extern struct workqueue_struct *system_nrt_wq; | ||
| 284 | extern struct workqueue_struct *system_unbound_wq; | ||
| 182 | 285 | ||
| 183 | extern struct workqueue_struct * | 286 | extern struct workqueue_struct * |
| 184 | __create_workqueue_key(const char *name, int singlethread, | 287 | __alloc_workqueue_key(const char *name, unsigned int flags, int max_active, |
| 185 | int freezeable, int rt, struct lock_class_key *key, | 288 | struct lock_class_key *key, const char *lock_name); |
| 186 | const char *lock_name); | ||
| 187 | 289 | ||
| 188 | #ifdef CONFIG_LOCKDEP | 290 | #ifdef CONFIG_LOCKDEP |
| 189 | #define __create_workqueue(name, singlethread, freezeable, rt) \ | 291 | #define alloc_workqueue(name, flags, max_active) \ |
| 190 | ({ \ | 292 | ({ \ |
| 191 | static struct lock_class_key __key; \ | 293 | static struct lock_class_key __key; \ |
| 192 | const char *__lock_name; \ | 294 | const char *__lock_name; \ |
| @@ -196,20 +298,20 @@ __create_workqueue_key(const char *name, int singlethread, | |||
| 196 | else \ | 298 | else \ |
| 197 | __lock_name = #name; \ | 299 | __lock_name = #name; \ |
| 198 | \ | 300 | \ |
| 199 | __create_workqueue_key((name), (singlethread), \ | 301 | __alloc_workqueue_key((name), (flags), (max_active), \ |
| 200 | (freezeable), (rt), &__key, \ | 302 | &__key, __lock_name); \ |
| 201 | __lock_name); \ | ||
| 202 | }) | 303 | }) |
| 203 | #else | 304 | #else |
| 204 | #define __create_workqueue(name, singlethread, freezeable, rt) \ | 305 | #define alloc_workqueue(name, flags, max_active) \ |
| 205 | __create_workqueue_key((name), (singlethread), (freezeable), (rt), \ | 306 | __alloc_workqueue_key((name), (flags), (max_active), NULL, NULL) |
| 206 | NULL, NULL) | ||
| 207 | #endif | 307 | #endif |
| 208 | 308 | ||
| 209 | #define create_workqueue(name) __create_workqueue((name), 0, 0, 0) | 309 | #define create_workqueue(name) \ |
| 210 | #define create_rt_workqueue(name) __create_workqueue((name), 0, 0, 1) | 310 | alloc_workqueue((name), WQ_RESCUER, 1) |
| 211 | #define create_freezeable_workqueue(name) __create_workqueue((name), 1, 1, 0) | 311 | #define create_freezeable_workqueue(name) \ |
| 212 | #define create_singlethread_workqueue(name) __create_workqueue((name), 1, 0, 0) | 312 | alloc_workqueue((name), WQ_FREEZEABLE | WQ_UNBOUND | WQ_RESCUER, 1) |
| 313 | #define create_singlethread_workqueue(name) \ | ||
| 314 | alloc_workqueue((name), WQ_UNBOUND | WQ_RESCUER, 1) | ||
| 213 | 315 | ||
| 214 | extern void destroy_workqueue(struct workqueue_struct *wq); | 316 | extern void destroy_workqueue(struct workqueue_struct *wq); |
| 215 | 317 | ||
| @@ -231,16 +333,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, | 333 | extern int schedule_delayed_work_on(int cpu, struct delayed_work *work, |
| 232 | unsigned long delay); | 334 | unsigned long delay); |
| 233 | extern int schedule_on_each_cpu(work_func_t func); | 335 | extern int schedule_on_each_cpu(work_func_t func); |
| 234 | extern int current_is_keventd(void); | ||
| 235 | extern int keventd_up(void); | 336 | extern int keventd_up(void); |
| 236 | 337 | ||
| 237 | extern void init_workqueues(void); | ||
| 238 | int execute_in_process_context(work_func_t fn, struct execute_work *); | 338 | int execute_in_process_context(work_func_t fn, struct execute_work *); |
| 239 | 339 | ||
| 240 | extern int flush_work(struct work_struct *work); | 340 | extern int flush_work(struct work_struct *work); |
| 241 | |||
| 242 | extern int cancel_work_sync(struct work_struct *work); | 341 | extern int cancel_work_sync(struct work_struct *work); |
| 243 | 342 | ||
| 343 | extern void workqueue_set_max_active(struct workqueue_struct *wq, | ||
| 344 | int max_active); | ||
| 345 | extern bool workqueue_congested(unsigned int cpu, struct workqueue_struct *wq); | ||
| 346 | extern unsigned int work_cpu(struct work_struct *work); | ||
| 347 | extern unsigned int work_busy(struct work_struct *work); | ||
| 348 | |||
| 244 | /* | 349 | /* |
| 245 | * Kill off a pending schedule_delayed_work(). Note that the work callback | 350 | * 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 | 351 | * function may still be running on return from cancel_delayed_work(), unless |
| @@ -297,4 +402,15 @@ static inline long work_on_cpu(unsigned int cpu, long (*fn)(void *), void *arg) | |||
| 297 | #else | 402 | #else |
| 298 | long work_on_cpu(unsigned int cpu, long (*fn)(void *), void *arg); | 403 | long work_on_cpu(unsigned int cpu, long (*fn)(void *), void *arg); |
| 299 | #endif /* CONFIG_SMP */ | 404 | #endif /* CONFIG_SMP */ |
| 405 | |||
| 406 | #ifdef CONFIG_FREEZER | ||
| 407 | extern void freeze_workqueues_begin(void); | ||
| 408 | extern bool freeze_workqueues_busy(void); | ||
| 409 | extern void thaw_workqueues(void); | ||
| 410 | #endif /* CONFIG_FREEZER */ | ||
| 411 | |||
| 412 | #ifdef CONFIG_LOCKDEP | ||
| 413 | int in_workqueue_context(struct workqueue_struct *wq); | ||
| 414 | #endif | ||
| 415 | |||
| 300 | #endif | 416 | #endif |
