diff options
Diffstat (limited to 'kernel/workqueue.c')
| -rw-r--r-- | kernel/workqueue.c | 222 |
1 files changed, 169 insertions, 53 deletions
diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 17c2f03d2c27..a3da07c5af28 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c | |||
| @@ -29,6 +29,9 @@ | |||
| 29 | #include <linux/kthread.h> | 29 | #include <linux/kthread.h> |
| 30 | #include <linux/hardirq.h> | 30 | #include <linux/hardirq.h> |
| 31 | #include <linux/mempolicy.h> | 31 | #include <linux/mempolicy.h> |
| 32 | #include <linux/freezer.h> | ||
| 33 | #include <linux/kallsyms.h> | ||
| 34 | #include <linux/debug_locks.h> | ||
| 32 | 35 | ||
| 33 | /* | 36 | /* |
| 34 | * The per-CPU workqueue (if single thread, we always use the first | 37 | * The per-CPU workqueue (if single thread, we always use the first |
| @@ -55,6 +58,8 @@ struct cpu_workqueue_struct { | |||
| 55 | struct task_struct *thread; | 58 | struct task_struct *thread; |
| 56 | 59 | ||
| 57 | int run_depth; /* Detect run_workqueue() recursion depth */ | 60 | int run_depth; /* Detect run_workqueue() recursion depth */ |
| 61 | |||
| 62 | int freezeable; /* Freeze the thread during suspend */ | ||
| 58 | } ____cacheline_aligned; | 63 | } ____cacheline_aligned; |
| 59 | 64 | ||
| 60 | /* | 65 | /* |
| @@ -80,6 +85,99 @@ static inline int is_single_threaded(struct workqueue_struct *wq) | |||
| 80 | return list_empty(&wq->list); | 85 | return list_empty(&wq->list); |
| 81 | } | 86 | } |
| 82 | 87 | ||
| 88 | /* | ||
| 89 | * Set the workqueue on which a work item is to be run | ||
| 90 | * - Must *only* be called if the pending flag is set | ||
| 91 | */ | ||
| 92 | static inline void set_wq_data(struct work_struct *work, void *wq) | ||
| 93 | { | ||
| 94 | unsigned long new; | ||
| 95 | |||
| 96 | BUG_ON(!work_pending(work)); | ||
| 97 | |||
| 98 | new = (unsigned long) wq | (1UL << WORK_STRUCT_PENDING); | ||
| 99 | new |= WORK_STRUCT_FLAG_MASK & *work_data_bits(work); | ||
| 100 | atomic_long_set(&work->data, new); | ||
| 101 | } | ||
| 102 | |||
| 103 | static inline void *get_wq_data(struct work_struct *work) | ||
| 104 | { | ||
| 105 | return (void *) (atomic_long_read(&work->data) & WORK_STRUCT_WQ_DATA_MASK); | ||
| 106 | } | ||
| 107 | |||
| 108 | static int __run_work(struct cpu_workqueue_struct *cwq, struct work_struct *work) | ||
| 109 | { | ||
| 110 | int ret = 0; | ||
| 111 | unsigned long flags; | ||
| 112 | |||
| 113 | spin_lock_irqsave(&cwq->lock, flags); | ||
| 114 | /* | ||
| 115 | * We need to re-validate the work info after we've gotten | ||
| 116 | * the cpu_workqueue lock. We can run the work now iff: | ||
| 117 | * | ||
| 118 | * - the wq_data still matches the cpu_workqueue_struct | ||
| 119 | * - AND the work is still marked pending | ||
| 120 | * - AND the work is still on a list (which will be this | ||
| 121 | * workqueue_struct list) | ||
| 122 | * | ||
| 123 | * All these conditions are important, because we | ||
| 124 | * need to protect against the work being run right | ||
| 125 | * now on another CPU (all but the last one might be | ||
| 126 | * true if it's currently running and has not been | ||
| 127 | * released yet, for example). | ||
| 128 | */ | ||
| 129 | if (get_wq_data(work) == cwq | ||
| 130 | && work_pending(work) | ||
| 131 | && !list_empty(&work->entry)) { | ||
| 132 | work_func_t f = work->func; | ||
| 133 | list_del_init(&work->entry); | ||
| 134 | spin_unlock_irqrestore(&cwq->lock, flags); | ||
| 135 | |||
| 136 | if (!test_bit(WORK_STRUCT_NOAUTOREL, work_data_bits(work))) | ||
| 137 | work_release(work); | ||
| 138 | f(work); | ||
| 139 | |||
| 140 | spin_lock_irqsave(&cwq->lock, flags); | ||
| 141 | cwq->remove_sequence++; | ||
| 142 | wake_up(&cwq->work_done); | ||
| 143 | ret = 1; | ||
| 144 | } | ||
| 145 | spin_unlock_irqrestore(&cwq->lock, flags); | ||
| 146 | return ret; | ||
| 147 | } | ||
| 148 | |||
| 149 | /** | ||
| 150 | * run_scheduled_work - run scheduled work synchronously | ||
| 151 | * @work: work to run | ||
| 152 | * | ||
| 153 | * This checks if the work was pending, and runs it | ||
| 154 | * synchronously if so. It returns a boolean to indicate | ||
| 155 | * whether it had any scheduled work to run or not. | ||
| 156 | * | ||
| 157 | * NOTE! This _only_ works for normal work_structs. You | ||
| 158 | * CANNOT use this for delayed work, because the wq data | ||
| 159 | * for delayed work will not point properly to the per- | ||
| 160 | * CPU workqueue struct, but will change! | ||
| 161 | */ | ||
| 162 | int fastcall run_scheduled_work(struct work_struct *work) | ||
| 163 | { | ||
| 164 | for (;;) { | ||
| 165 | struct cpu_workqueue_struct *cwq; | ||
| 166 | |||
| 167 | if (!work_pending(work)) | ||
| 168 | return 0; | ||
| 169 | if (list_empty(&work->entry)) | ||
| 170 | return 0; | ||
| 171 | /* NOTE! This depends intimately on __queue_work! */ | ||
| 172 | cwq = get_wq_data(work); | ||
| 173 | if (!cwq) | ||
| 174 | return 0; | ||
| 175 | if (__run_work(cwq, work)) | ||
| 176 | return 1; | ||
| 177 | } | ||
| 178 | } | ||
| 179 | EXPORT_SYMBOL(run_scheduled_work); | ||
| 180 | |||
| 83 | /* Preempt must be disabled. */ | 181 | /* Preempt must be disabled. */ |
| 84 | static void __queue_work(struct cpu_workqueue_struct *cwq, | 182 | static void __queue_work(struct cpu_workqueue_struct *cwq, |
| 85 | struct work_struct *work) | 183 | struct work_struct *work) |
| @@ -87,7 +185,7 @@ static void __queue_work(struct cpu_workqueue_struct *cwq, | |||
| 87 | unsigned long flags; | 185 | unsigned long flags; |
| 88 | 186 | ||
| 89 | spin_lock_irqsave(&cwq->lock, flags); | 187 | spin_lock_irqsave(&cwq->lock, flags); |
| 90 | work->wq_data = cwq; | 188 | set_wq_data(work, cwq); |
| 91 | list_add_tail(&work->entry, &cwq->worklist); | 189 | list_add_tail(&work->entry, &cwq->worklist); |
| 92 | cwq->insert_sequence++; | 190 | cwq->insert_sequence++; |
| 93 | wake_up(&cwq->more_work); | 191 | wake_up(&cwq->more_work); |
| @@ -108,7 +206,7 @@ int fastcall queue_work(struct workqueue_struct *wq, struct work_struct *work) | |||
| 108 | { | 206 | { |
| 109 | int ret = 0, cpu = get_cpu(); | 207 | int ret = 0, cpu = get_cpu(); |
| 110 | 208 | ||
| 111 | if (!test_and_set_bit(0, &work->pending)) { | 209 | if (!test_and_set_bit(WORK_STRUCT_PENDING, work_data_bits(work))) { |
| 112 | if (unlikely(is_single_threaded(wq))) | 210 | if (unlikely(is_single_threaded(wq))) |
| 113 | cpu = singlethread_cpu; | 211 | cpu = singlethread_cpu; |
| 114 | BUG_ON(!list_empty(&work->entry)); | 212 | BUG_ON(!list_empty(&work->entry)); |
| @@ -122,38 +220,42 @@ EXPORT_SYMBOL_GPL(queue_work); | |||
| 122 | 220 | ||
| 123 | static void delayed_work_timer_fn(unsigned long __data) | 221 | static void delayed_work_timer_fn(unsigned long __data) |
| 124 | { | 222 | { |
| 125 | struct work_struct *work = (struct work_struct *)__data; | 223 | struct delayed_work *dwork = (struct delayed_work *)__data; |
| 126 | struct workqueue_struct *wq = work->wq_data; | 224 | struct workqueue_struct *wq = get_wq_data(&dwork->work); |
| 127 | int cpu = smp_processor_id(); | 225 | int cpu = smp_processor_id(); |
| 128 | 226 | ||
| 129 | if (unlikely(is_single_threaded(wq))) | 227 | if (unlikely(is_single_threaded(wq))) |
| 130 | cpu = singlethread_cpu; | 228 | cpu = singlethread_cpu; |
| 131 | 229 | ||
| 132 | __queue_work(per_cpu_ptr(wq->cpu_wq, cpu), work); | 230 | __queue_work(per_cpu_ptr(wq->cpu_wq, cpu), &dwork->work); |
| 133 | } | 231 | } |
| 134 | 232 | ||
| 135 | /** | 233 | /** |
| 136 | * queue_delayed_work - queue work on a workqueue after delay | 234 | * queue_delayed_work - queue work on a workqueue after delay |
| 137 | * @wq: workqueue to use | 235 | * @wq: workqueue to use |
| 138 | * @work: work to queue | 236 | * @dwork: delayable work to queue |
| 139 | * @delay: number of jiffies to wait before queueing | 237 | * @delay: number of jiffies to wait before queueing |
| 140 | * | 238 | * |
| 141 | * Returns 0 if @work was already on a queue, non-zero otherwise. | 239 | * Returns 0 if @work was already on a queue, non-zero otherwise. |
| 142 | */ | 240 | */ |
| 143 | int fastcall queue_delayed_work(struct workqueue_struct *wq, | 241 | int fastcall queue_delayed_work(struct workqueue_struct *wq, |
| 144 | struct work_struct *work, unsigned long delay) | 242 | struct delayed_work *dwork, unsigned long delay) |
| 145 | { | 243 | { |
| 146 | int ret = 0; | 244 | int ret = 0; |
| 147 | struct timer_list *timer = &work->timer; | 245 | struct timer_list *timer = &dwork->timer; |
| 246 | struct work_struct *work = &dwork->work; | ||
| 148 | 247 | ||
| 149 | if (!test_and_set_bit(0, &work->pending)) { | 248 | if (delay == 0) |
| 249 | return queue_work(wq, work); | ||
| 250 | |||
| 251 | if (!test_and_set_bit(WORK_STRUCT_PENDING, work_data_bits(work))) { | ||
| 150 | BUG_ON(timer_pending(timer)); | 252 | BUG_ON(timer_pending(timer)); |
| 151 | BUG_ON(!list_empty(&work->entry)); | 253 | BUG_ON(!list_empty(&work->entry)); |
| 152 | 254 | ||
| 153 | /* This stores wq for the moment, for the timer_fn */ | 255 | /* This stores wq for the moment, for the timer_fn */ |
| 154 | work->wq_data = wq; | 256 | set_wq_data(work, wq); |
| 155 | timer->expires = jiffies + delay; | 257 | timer->expires = jiffies + delay; |
| 156 | timer->data = (unsigned long)work; | 258 | timer->data = (unsigned long)dwork; |
| 157 | timer->function = delayed_work_timer_fn; | 259 | timer->function = delayed_work_timer_fn; |
| 158 | add_timer(timer); | 260 | add_timer(timer); |
| 159 | ret = 1; | 261 | ret = 1; |
| @@ -166,25 +268,26 @@ EXPORT_SYMBOL_GPL(queue_delayed_work); | |||
| 166 | * queue_delayed_work_on - queue work on specific CPU after delay | 268 | * queue_delayed_work_on - queue work on specific CPU after delay |
| 167 | * @cpu: CPU number to execute work on | 269 | * @cpu: CPU number to execute work on |
| 168 | * @wq: workqueue to use | 270 | * @wq: workqueue to use |
| 169 | * @work: work to queue | 271 | * @dwork: work to queue |
| 170 | * @delay: number of jiffies to wait before queueing | 272 | * @delay: number of jiffies to wait before queueing |
| 171 | * | 273 | * |
| 172 | * Returns 0 if @work was already on a queue, non-zero otherwise. | 274 | * Returns 0 if @work was already on a queue, non-zero otherwise. |
| 173 | */ | 275 | */ |
| 174 | int queue_delayed_work_on(int cpu, struct workqueue_struct *wq, | 276 | int queue_delayed_work_on(int cpu, struct workqueue_struct *wq, |
| 175 | struct work_struct *work, unsigned long delay) | 277 | struct delayed_work *dwork, unsigned long delay) |
| 176 | { | 278 | { |
| 177 | int ret = 0; | 279 | int ret = 0; |
| 178 | struct timer_list *timer = &work->timer; | 280 | struct timer_list *timer = &dwork->timer; |
| 281 | struct work_struct *work = &dwork->work; | ||
| 179 | 282 | ||
| 180 | if (!test_and_set_bit(0, &work->pending)) { | 283 | if (!test_and_set_bit(WORK_STRUCT_PENDING, work_data_bits(work))) { |
| 181 | BUG_ON(timer_pending(timer)); | 284 | BUG_ON(timer_pending(timer)); |
| 182 | BUG_ON(!list_empty(&work->entry)); | 285 | BUG_ON(!list_empty(&work->entry)); |
| 183 | 286 | ||
| 184 | /* This stores wq for the moment, for the timer_fn */ | 287 | /* This stores wq for the moment, for the timer_fn */ |
| 185 | work->wq_data = wq; | 288 | set_wq_data(work, wq); |
| 186 | timer->expires = jiffies + delay; | 289 | timer->expires = jiffies + delay; |
| 187 | timer->data = (unsigned long)work; | 290 | timer->data = (unsigned long)dwork; |
| 188 | timer->function = delayed_work_timer_fn; | 291 | timer->function = delayed_work_timer_fn; |
| 189 | add_timer_on(timer, cpu); | 292 | add_timer_on(timer, cpu); |
| 190 | ret = 1; | 293 | ret = 1; |
| @@ -212,15 +315,26 @@ static void run_workqueue(struct cpu_workqueue_struct *cwq) | |||
| 212 | while (!list_empty(&cwq->worklist)) { | 315 | while (!list_empty(&cwq->worklist)) { |
| 213 | struct work_struct *work = list_entry(cwq->worklist.next, | 316 | struct work_struct *work = list_entry(cwq->worklist.next, |
| 214 | struct work_struct, entry); | 317 | struct work_struct, entry); |
| 215 | void (*f) (void *) = work->func; | 318 | work_func_t f = work->func; |
| 216 | void *data = work->data; | ||
| 217 | 319 | ||
| 218 | list_del_init(cwq->worklist.next); | 320 | list_del_init(cwq->worklist.next); |
| 219 | spin_unlock_irqrestore(&cwq->lock, flags); | 321 | spin_unlock_irqrestore(&cwq->lock, flags); |
| 220 | 322 | ||
| 221 | BUG_ON(work->wq_data != cwq); | 323 | BUG_ON(get_wq_data(work) != cwq); |
| 222 | clear_bit(0, &work->pending); | 324 | if (!test_bit(WORK_STRUCT_NOAUTOREL, work_data_bits(work))) |
| 223 | f(data); | 325 | work_release(work); |
| 326 | f(work); | ||
| 327 | |||
| 328 | if (unlikely(in_atomic() || lockdep_depth(current) > 0)) { | ||
| 329 | printk(KERN_ERR "BUG: workqueue leaked lock or atomic: " | ||
| 330 | "%s/0x%08x/%d\n", | ||
| 331 | current->comm, preempt_count(), | ||
| 332 | current->pid); | ||
| 333 | printk(KERN_ERR " last function: "); | ||
| 334 | print_symbol("%s\n", (unsigned long)f); | ||
| 335 | debug_show_held_locks(current); | ||
| 336 | dump_stack(); | ||
| 337 | } | ||
| 224 | 338 | ||
| 225 | spin_lock_irqsave(&cwq->lock, flags); | 339 | spin_lock_irqsave(&cwq->lock, flags); |
| 226 | cwq->remove_sequence++; | 340 | cwq->remove_sequence++; |
| @@ -237,7 +351,8 @@ static int worker_thread(void *__cwq) | |||
| 237 | struct k_sigaction sa; | 351 | struct k_sigaction sa; |
| 238 | sigset_t blocked; | 352 | sigset_t blocked; |
| 239 | 353 | ||
| 240 | current->flags |= PF_NOFREEZE; | 354 | if (!cwq->freezeable) |
| 355 | current->flags |= PF_NOFREEZE; | ||
| 241 | 356 | ||
| 242 | set_user_nice(current, -5); | 357 | set_user_nice(current, -5); |
| 243 | 358 | ||
| @@ -260,6 +375,9 @@ static int worker_thread(void *__cwq) | |||
| 260 | 375 | ||
| 261 | set_current_state(TASK_INTERRUPTIBLE); | 376 | set_current_state(TASK_INTERRUPTIBLE); |
| 262 | while (!kthread_should_stop()) { | 377 | while (!kthread_should_stop()) { |
| 378 | if (cwq->freezeable) | ||
| 379 | try_to_freeze(); | ||
| 380 | |||
| 263 | add_wait_queue(&cwq->more_work, &wait); | 381 | add_wait_queue(&cwq->more_work, &wait); |
| 264 | if (list_empty(&cwq->worklist)) | 382 | if (list_empty(&cwq->worklist)) |
| 265 | schedule(); | 383 | schedule(); |
| @@ -336,7 +454,7 @@ void fastcall flush_workqueue(struct workqueue_struct *wq) | |||
| 336 | EXPORT_SYMBOL_GPL(flush_workqueue); | 454 | EXPORT_SYMBOL_GPL(flush_workqueue); |
| 337 | 455 | ||
| 338 | static struct task_struct *create_workqueue_thread(struct workqueue_struct *wq, | 456 | static struct task_struct *create_workqueue_thread(struct workqueue_struct *wq, |
| 339 | int cpu) | 457 | int cpu, int freezeable) |
| 340 | { | 458 | { |
| 341 | struct cpu_workqueue_struct *cwq = per_cpu_ptr(wq->cpu_wq, cpu); | 459 | struct cpu_workqueue_struct *cwq = per_cpu_ptr(wq->cpu_wq, cpu); |
| 342 | struct task_struct *p; | 460 | struct task_struct *p; |
| @@ -346,6 +464,7 @@ static struct task_struct *create_workqueue_thread(struct workqueue_struct *wq, | |||
| 346 | cwq->thread = NULL; | 464 | cwq->thread = NULL; |
| 347 | cwq->insert_sequence = 0; | 465 | cwq->insert_sequence = 0; |
| 348 | cwq->remove_sequence = 0; | 466 | cwq->remove_sequence = 0; |
| 467 | cwq->freezeable = freezeable; | ||
| 349 | INIT_LIST_HEAD(&cwq->worklist); | 468 | INIT_LIST_HEAD(&cwq->worklist); |
| 350 | init_waitqueue_head(&cwq->more_work); | 469 | init_waitqueue_head(&cwq->more_work); |
| 351 | init_waitqueue_head(&cwq->work_done); | 470 | init_waitqueue_head(&cwq->work_done); |
| @@ -361,7 +480,7 @@ static struct task_struct *create_workqueue_thread(struct workqueue_struct *wq, | |||
| 361 | } | 480 | } |
| 362 | 481 | ||
| 363 | struct workqueue_struct *__create_workqueue(const char *name, | 482 | struct workqueue_struct *__create_workqueue(const char *name, |
| 364 | int singlethread) | 483 | int singlethread, int freezeable) |
| 365 | { | 484 | { |
| 366 | int cpu, destroy = 0; | 485 | int cpu, destroy = 0; |
| 367 | struct workqueue_struct *wq; | 486 | struct workqueue_struct *wq; |
| @@ -381,7 +500,7 @@ struct workqueue_struct *__create_workqueue(const char *name, | |||
| 381 | mutex_lock(&workqueue_mutex); | 500 | mutex_lock(&workqueue_mutex); |
| 382 | if (singlethread) { | 501 | if (singlethread) { |
| 383 | INIT_LIST_HEAD(&wq->list); | 502 | INIT_LIST_HEAD(&wq->list); |
| 384 | p = create_workqueue_thread(wq, singlethread_cpu); | 503 | p = create_workqueue_thread(wq, singlethread_cpu, freezeable); |
| 385 | if (!p) | 504 | if (!p) |
| 386 | destroy = 1; | 505 | destroy = 1; |
| 387 | else | 506 | else |
| @@ -389,7 +508,7 @@ struct workqueue_struct *__create_workqueue(const char *name, | |||
| 389 | } else { | 508 | } else { |
| 390 | list_add(&wq->list, &workqueues); | 509 | list_add(&wq->list, &workqueues); |
| 391 | for_each_online_cpu(cpu) { | 510 | for_each_online_cpu(cpu) { |
| 392 | p = create_workqueue_thread(wq, cpu); | 511 | p = create_workqueue_thread(wq, cpu, freezeable); |
| 393 | if (p) { | 512 | if (p) { |
| 394 | kthread_bind(p, cpu); | 513 | kthread_bind(p, cpu); |
| 395 | wake_up_process(p); | 514 | wake_up_process(p); |
| @@ -468,38 +587,37 @@ EXPORT_SYMBOL(schedule_work); | |||
| 468 | 587 | ||
| 469 | /** | 588 | /** |
| 470 | * schedule_delayed_work - put work task in global workqueue after delay | 589 | * schedule_delayed_work - put work task in global workqueue after delay |
| 471 | * @work: job to be done | 590 | * @dwork: job to be done |
| 472 | * @delay: number of jiffies to wait | 591 | * @delay: number of jiffies to wait or 0 for immediate execution |
| 473 | * | 592 | * |
| 474 | * After waiting for a given time this puts a job in the kernel-global | 593 | * After waiting for a given time this puts a job in the kernel-global |
| 475 | * workqueue. | 594 | * workqueue. |
| 476 | */ | 595 | */ |
| 477 | int fastcall schedule_delayed_work(struct work_struct *work, unsigned long delay) | 596 | int fastcall schedule_delayed_work(struct delayed_work *dwork, unsigned long delay) |
| 478 | { | 597 | { |
| 479 | return queue_delayed_work(keventd_wq, work, delay); | 598 | return queue_delayed_work(keventd_wq, dwork, delay); |
| 480 | } | 599 | } |
| 481 | EXPORT_SYMBOL(schedule_delayed_work); | 600 | EXPORT_SYMBOL(schedule_delayed_work); |
| 482 | 601 | ||
| 483 | /** | 602 | /** |
| 484 | * schedule_delayed_work_on - queue work in global workqueue on CPU after delay | 603 | * schedule_delayed_work_on - queue work in global workqueue on CPU after delay |
| 485 | * @cpu: cpu to use | 604 | * @cpu: cpu to use |
| 486 | * @work: job to be done | 605 | * @dwork: job to be done |
| 487 | * @delay: number of jiffies to wait | 606 | * @delay: number of jiffies to wait |
| 488 | * | 607 | * |
| 489 | * After waiting for a given time this puts a job in the kernel-global | 608 | * After waiting for a given time this puts a job in the kernel-global |
| 490 | * workqueue on the specified CPU. | 609 | * workqueue on the specified CPU. |
| 491 | */ | 610 | */ |
| 492 | int schedule_delayed_work_on(int cpu, | 611 | int schedule_delayed_work_on(int cpu, |
| 493 | struct work_struct *work, unsigned long delay) | 612 | struct delayed_work *dwork, unsigned long delay) |
| 494 | { | 613 | { |
| 495 | return queue_delayed_work_on(cpu, keventd_wq, work, delay); | 614 | return queue_delayed_work_on(cpu, keventd_wq, dwork, delay); |
| 496 | } | 615 | } |
| 497 | EXPORT_SYMBOL(schedule_delayed_work_on); | 616 | EXPORT_SYMBOL(schedule_delayed_work_on); |
| 498 | 617 | ||
| 499 | /** | 618 | /** |
| 500 | * schedule_on_each_cpu - call a function on each online CPU from keventd | 619 | * schedule_on_each_cpu - call a function on each online CPU from keventd |
| 501 | * @func: the function to call | 620 | * @func: the function to call |
| 502 | * @info: a pointer to pass to func() | ||
| 503 | * | 621 | * |
| 504 | * Returns zero on success. | 622 | * Returns zero on success. |
| 505 | * Returns -ve errno on failure. | 623 | * Returns -ve errno on failure. |
| @@ -508,7 +626,7 @@ EXPORT_SYMBOL(schedule_delayed_work_on); | |||
| 508 | * | 626 | * |
| 509 | * schedule_on_each_cpu() is very slow. | 627 | * schedule_on_each_cpu() is very slow. |
| 510 | */ | 628 | */ |
| 511 | int schedule_on_each_cpu(void (*func)(void *info), void *info) | 629 | int schedule_on_each_cpu(work_func_t func) |
| 512 | { | 630 | { |
| 513 | int cpu; | 631 | int cpu; |
| 514 | struct work_struct *works; | 632 | struct work_struct *works; |
| @@ -519,9 +637,11 @@ int schedule_on_each_cpu(void (*func)(void *info), void *info) | |||
| 519 | 637 | ||
| 520 | mutex_lock(&workqueue_mutex); | 638 | mutex_lock(&workqueue_mutex); |
| 521 | for_each_online_cpu(cpu) { | 639 | for_each_online_cpu(cpu) { |
| 522 | INIT_WORK(per_cpu_ptr(works, cpu), func, info); | 640 | struct work_struct *work = per_cpu_ptr(works, cpu); |
| 523 | __queue_work(per_cpu_ptr(keventd_wq->cpu_wq, cpu), | 641 | |
| 524 | per_cpu_ptr(works, cpu)); | 642 | INIT_WORK(work, func); |
| 643 | set_bit(WORK_STRUCT_PENDING, work_data_bits(work)); | ||
| 644 | __queue_work(per_cpu_ptr(keventd_wq->cpu_wq, cpu), work); | ||
| 525 | } | 645 | } |
| 526 | mutex_unlock(&workqueue_mutex); | 646 | mutex_unlock(&workqueue_mutex); |
| 527 | flush_workqueue(keventd_wq); | 647 | flush_workqueue(keventd_wq); |
| @@ -539,12 +659,12 @@ EXPORT_SYMBOL(flush_scheduled_work); | |||
| 539 | * cancel_rearming_delayed_workqueue - reliably kill off a delayed | 659 | * cancel_rearming_delayed_workqueue - reliably kill off a delayed |
| 540 | * work whose handler rearms the delayed work. | 660 | * work whose handler rearms the delayed work. |
| 541 | * @wq: the controlling workqueue structure | 661 | * @wq: the controlling workqueue structure |
| 542 | * @work: the delayed work struct | 662 | * @dwork: the delayed work struct |
| 543 | */ | 663 | */ |
| 544 | void cancel_rearming_delayed_workqueue(struct workqueue_struct *wq, | 664 | void cancel_rearming_delayed_workqueue(struct workqueue_struct *wq, |
| 545 | struct work_struct *work) | 665 | struct delayed_work *dwork) |
| 546 | { | 666 | { |
| 547 | while (!cancel_delayed_work(work)) | 667 | while (!cancel_delayed_work(dwork)) |
| 548 | flush_workqueue(wq); | 668 | flush_workqueue(wq); |
| 549 | } | 669 | } |
| 550 | EXPORT_SYMBOL(cancel_rearming_delayed_workqueue); | 670 | EXPORT_SYMBOL(cancel_rearming_delayed_workqueue); |
| @@ -552,18 +672,17 @@ EXPORT_SYMBOL(cancel_rearming_delayed_workqueue); | |||
| 552 | /** | 672 | /** |
| 553 | * cancel_rearming_delayed_work - reliably kill off a delayed keventd | 673 | * cancel_rearming_delayed_work - reliably kill off a delayed keventd |
| 554 | * work whose handler rearms the delayed work. | 674 | * work whose handler rearms the delayed work. |
| 555 | * @work: the delayed work struct | 675 | * @dwork: the delayed work struct |
| 556 | */ | 676 | */ |
| 557 | void cancel_rearming_delayed_work(struct work_struct *work) | 677 | void cancel_rearming_delayed_work(struct delayed_work *dwork) |
| 558 | { | 678 | { |
| 559 | cancel_rearming_delayed_workqueue(keventd_wq, work); | 679 | cancel_rearming_delayed_workqueue(keventd_wq, dwork); |
| 560 | } | 680 | } |
| 561 | EXPORT_SYMBOL(cancel_rearming_delayed_work); | 681 | EXPORT_SYMBOL(cancel_rearming_delayed_work); |
| 562 | 682 | ||
| 563 | /** | 683 | /** |
| 564 | * execute_in_process_context - reliably execute the routine with user context | 684 | * execute_in_process_context - reliably execute the routine with user context |
| 565 | * @fn: the function to execute | 685 | * @fn: the function to execute |
| 566 | * @data: data to pass to the function | ||
| 567 | * @ew: guaranteed storage for the execute work structure (must | 686 | * @ew: guaranteed storage for the execute work structure (must |
| 568 | * be available when the work executes) | 687 | * be available when the work executes) |
| 569 | * | 688 | * |
| @@ -573,15 +692,14 @@ EXPORT_SYMBOL(cancel_rearming_delayed_work); | |||
| 573 | * Returns: 0 - function was executed | 692 | * Returns: 0 - function was executed |
| 574 | * 1 - function was scheduled for execution | 693 | * 1 - function was scheduled for execution |
| 575 | */ | 694 | */ |
| 576 | int execute_in_process_context(void (*fn)(void *data), void *data, | 695 | int execute_in_process_context(work_func_t fn, struct execute_work *ew) |
| 577 | struct execute_work *ew) | ||
| 578 | { | 696 | { |
| 579 | if (!in_interrupt()) { | 697 | if (!in_interrupt()) { |
| 580 | fn(data); | 698 | fn(&ew->work); |
| 581 | return 0; | 699 | return 0; |
| 582 | } | 700 | } |
| 583 | 701 | ||
| 584 | INIT_WORK(&ew->work, fn, data); | 702 | INIT_WORK(&ew->work, fn); |
| 585 | schedule_work(&ew->work); | 703 | schedule_work(&ew->work); |
| 586 | 704 | ||
| 587 | return 1; | 705 | return 1; |
| @@ -609,7 +727,6 @@ int current_is_keventd(void) | |||
| 609 | 727 | ||
| 610 | } | 728 | } |
| 611 | 729 | ||
| 612 | #ifdef CONFIG_HOTPLUG_CPU | ||
| 613 | /* Take the work from this (downed) CPU. */ | 730 | /* Take the work from this (downed) CPU. */ |
| 614 | static void take_over_work(struct workqueue_struct *wq, unsigned int cpu) | 731 | static void take_over_work(struct workqueue_struct *wq, unsigned int cpu) |
| 615 | { | 732 | { |
| @@ -642,7 +759,7 @@ static int __devinit workqueue_cpu_callback(struct notifier_block *nfb, | |||
| 642 | mutex_lock(&workqueue_mutex); | 759 | mutex_lock(&workqueue_mutex); |
| 643 | /* Create a new workqueue thread for it. */ | 760 | /* Create a new workqueue thread for it. */ |
| 644 | list_for_each_entry(wq, &workqueues, list) { | 761 | list_for_each_entry(wq, &workqueues, list) { |
| 645 | if (!create_workqueue_thread(wq, hotcpu)) { | 762 | if (!create_workqueue_thread(wq, hotcpu, 0)) { |
| 646 | printk("workqueue for %i failed\n", hotcpu); | 763 | printk("workqueue for %i failed\n", hotcpu); |
| 647 | return NOTIFY_BAD; | 764 | return NOTIFY_BAD; |
| 648 | } | 765 | } |
| @@ -692,7 +809,6 @@ static int __devinit workqueue_cpu_callback(struct notifier_block *nfb, | |||
| 692 | 809 | ||
| 693 | return NOTIFY_OK; | 810 | return NOTIFY_OK; |
| 694 | } | 811 | } |
| 695 | #endif | ||
| 696 | 812 | ||
| 697 | void init_workqueues(void) | 813 | void init_workqueues(void) |
| 698 | { | 814 | { |
