diff options
| author | Ingo Molnar <mingo@elte.hu> | 2008-10-28 11:26:12 -0400 |
|---|---|---|
| committer | Ingo Molnar <mingo@elte.hu> | 2008-10-28 11:26:12 -0400 |
| commit | 7a9787e1eba95a166265e6a260cf30af04ef0a99 (patch) | |
| tree | e730a4565e0318140d2fbd2f0415d18a339d7336 /kernel/workqueue.c | |
| parent | 41b9eb264c8407655db57b60b4457fe1b2ec9977 (diff) | |
| parent | 0173a3265b228da319ceb9c1ec6a5682fd1b2d92 (diff) | |
Merge commit 'v2.6.28-rc2' into x86/pci-ioapic-boot-irq-quirks
Diffstat (limited to 'kernel/workqueue.c')
| -rw-r--r-- | kernel/workqueue.c | 191 |
1 files changed, 146 insertions, 45 deletions
diff --git a/kernel/workqueue.c b/kernel/workqueue.c index ce7799540c9..f928f2a87b9 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c | |||
| @@ -9,7 +9,7 @@ | |||
| 9 | * Derived from the taskqueue/keventd code by: | 9 | * Derived from the taskqueue/keventd code by: |
| 10 | * | 10 | * |
| 11 | * David Woodhouse <dwmw2@infradead.org> | 11 | * David Woodhouse <dwmw2@infradead.org> |
| 12 | * Andrew Morton <andrewm@uow.edu.au> | 12 | * Andrew Morton |
| 13 | * Kai Petzke <wpp@marie.physik.tu-berlin.de> | 13 | * Kai Petzke <wpp@marie.physik.tu-berlin.de> |
| 14 | * Theodore Ts'o <tytso@mit.edu> | 14 | * Theodore Ts'o <tytso@mit.edu> |
| 15 | * | 15 | * |
| @@ -62,6 +62,7 @@ struct workqueue_struct { | |||
| 62 | const char *name; | 62 | const char *name; |
| 63 | int singlethread; | 63 | int singlethread; |
| 64 | int freezeable; /* Freeze threads during suspend */ | 64 | int freezeable; /* Freeze threads during suspend */ |
| 65 | int rt; | ||
| 65 | #ifdef CONFIG_LOCKDEP | 66 | #ifdef CONFIG_LOCKDEP |
| 66 | struct lockdep_map lockdep_map; | 67 | struct lockdep_map lockdep_map; |
| 67 | #endif | 68 | #endif |
| @@ -125,7 +126,7 @@ struct cpu_workqueue_struct *get_wq_data(struct work_struct *work) | |||
| 125 | } | 126 | } |
| 126 | 127 | ||
| 127 | static void insert_work(struct cpu_workqueue_struct *cwq, | 128 | static void insert_work(struct cpu_workqueue_struct *cwq, |
| 128 | struct work_struct *work, int tail) | 129 | struct work_struct *work, struct list_head *head) |
| 129 | { | 130 | { |
| 130 | set_wq_data(work, cwq); | 131 | set_wq_data(work, cwq); |
| 131 | /* | 132 | /* |
| @@ -133,21 +134,17 @@ static void insert_work(struct cpu_workqueue_struct *cwq, | |||
| 133 | * result of list_add() below, see try_to_grab_pending(). | 134 | * result of list_add() below, see try_to_grab_pending(). |
| 134 | */ | 135 | */ |
| 135 | smp_wmb(); | 136 | smp_wmb(); |
| 136 | if (tail) | 137 | list_add_tail(&work->entry, head); |
| 137 | list_add_tail(&work->entry, &cwq->worklist); | ||
| 138 | else | ||
| 139 | list_add(&work->entry, &cwq->worklist); | ||
| 140 | wake_up(&cwq->more_work); | 138 | wake_up(&cwq->more_work); |
| 141 | } | 139 | } |
| 142 | 140 | ||
| 143 | /* Preempt must be disabled. */ | ||
| 144 | static void __queue_work(struct cpu_workqueue_struct *cwq, | 141 | static void __queue_work(struct cpu_workqueue_struct *cwq, |
| 145 | struct work_struct *work) | 142 | struct work_struct *work) |
| 146 | { | 143 | { |
| 147 | unsigned long flags; | 144 | unsigned long flags; |
| 148 | 145 | ||
| 149 | spin_lock_irqsave(&cwq->lock, flags); | 146 | spin_lock_irqsave(&cwq->lock, flags); |
| 150 | insert_work(cwq, work, 1); | 147 | insert_work(cwq, work, &cwq->worklist); |
| 151 | spin_unlock_irqrestore(&cwq->lock, flags); | 148 | spin_unlock_irqrestore(&cwq->lock, flags); |
| 152 | } | 149 | } |
| 153 | 150 | ||
| @@ -163,17 +160,39 @@ static void __queue_work(struct cpu_workqueue_struct *cwq, | |||
| 163 | */ | 160 | */ |
| 164 | int queue_work(struct workqueue_struct *wq, struct work_struct *work) | 161 | int queue_work(struct workqueue_struct *wq, struct work_struct *work) |
| 165 | { | 162 | { |
| 163 | int ret; | ||
| 164 | |||
| 165 | ret = queue_work_on(get_cpu(), wq, work); | ||
| 166 | put_cpu(); | ||
| 167 | |||
| 168 | return ret; | ||
| 169 | } | ||
| 170 | EXPORT_SYMBOL_GPL(queue_work); | ||
| 171 | |||
| 172 | /** | ||
| 173 | * queue_work_on - queue work on specific cpu | ||
| 174 | * @cpu: CPU number to execute work on | ||
| 175 | * @wq: workqueue to use | ||
| 176 | * @work: work to queue | ||
| 177 | * | ||
| 178 | * Returns 0 if @work was already on a queue, non-zero otherwise. | ||
| 179 | * | ||
| 180 | * We queue the work to a specific CPU, the caller must ensure it | ||
| 181 | * can't go away. | ||
| 182 | */ | ||
| 183 | int | ||
| 184 | queue_work_on(int cpu, struct workqueue_struct *wq, struct work_struct *work) | ||
| 185 | { | ||
| 166 | int ret = 0; | 186 | int ret = 0; |
| 167 | 187 | ||
| 168 | if (!test_and_set_bit(WORK_STRUCT_PENDING, work_data_bits(work))) { | 188 | if (!test_and_set_bit(WORK_STRUCT_PENDING, work_data_bits(work))) { |
| 169 | BUG_ON(!list_empty(&work->entry)); | 189 | BUG_ON(!list_empty(&work->entry)); |
| 170 | __queue_work(wq_per_cpu(wq, get_cpu()), work); | 190 | __queue_work(wq_per_cpu(wq, cpu), work); |
| 171 | put_cpu(); | ||
| 172 | ret = 1; | 191 | ret = 1; |
| 173 | } | 192 | } |
| 174 | return ret; | 193 | return ret; |
| 175 | } | 194 | } |
| 176 | EXPORT_SYMBOL_GPL(queue_work); | 195 | EXPORT_SYMBOL_GPL(queue_work_on); |
| 177 | 196 | ||
| 178 | static void delayed_work_timer_fn(unsigned long __data) | 197 | static void delayed_work_timer_fn(unsigned long __data) |
| 179 | { | 198 | { |
| @@ -272,11 +291,11 @@ static void run_workqueue(struct cpu_workqueue_struct *cwq) | |||
| 272 | 291 | ||
| 273 | BUG_ON(get_wq_data(work) != cwq); | 292 | BUG_ON(get_wq_data(work) != cwq); |
| 274 | work_clear_pending(work); | 293 | work_clear_pending(work); |
| 275 | lock_acquire(&cwq->wq->lockdep_map, 0, 0, 0, 2, _THIS_IP_); | 294 | lock_map_acquire(&cwq->wq->lockdep_map); |
| 276 | lock_acquire(&lockdep_map, 0, 0, 0, 2, _THIS_IP_); | 295 | lock_map_acquire(&lockdep_map); |
| 277 | f(work); | 296 | f(work); |
| 278 | lock_release(&lockdep_map, 1, _THIS_IP_); | 297 | lock_map_release(&lockdep_map); |
| 279 | lock_release(&cwq->wq->lockdep_map, 1, _THIS_IP_); | 298 | lock_map_release(&cwq->wq->lockdep_map); |
| 280 | 299 | ||
| 281 | if (unlikely(in_atomic() || lockdep_depth(current) > 0)) { | 300 | if (unlikely(in_atomic() || lockdep_depth(current) > 0)) { |
| 282 | printk(KERN_ERR "BUG: workqueue leaked lock or atomic: " | 301 | printk(KERN_ERR "BUG: workqueue leaked lock or atomic: " |
| @@ -337,14 +356,14 @@ static void wq_barrier_func(struct work_struct *work) | |||
| 337 | } | 356 | } |
| 338 | 357 | ||
| 339 | static void insert_wq_barrier(struct cpu_workqueue_struct *cwq, | 358 | static void insert_wq_barrier(struct cpu_workqueue_struct *cwq, |
| 340 | struct wq_barrier *barr, int tail) | 359 | struct wq_barrier *barr, struct list_head *head) |
| 341 | { | 360 | { |
| 342 | INIT_WORK(&barr->work, wq_barrier_func); | 361 | INIT_WORK(&barr->work, wq_barrier_func); |
| 343 | __set_bit(WORK_STRUCT_PENDING, work_data_bits(&barr->work)); | 362 | __set_bit(WORK_STRUCT_PENDING, work_data_bits(&barr->work)); |
| 344 | 363 | ||
| 345 | init_completion(&barr->done); | 364 | init_completion(&barr->done); |
| 346 | 365 | ||
| 347 | insert_work(cwq, &barr->work, tail); | 366 | insert_work(cwq, &barr->work, head); |
| 348 | } | 367 | } |
| 349 | 368 | ||
| 350 | static int flush_cpu_workqueue(struct cpu_workqueue_struct *cwq) | 369 | static int flush_cpu_workqueue(struct cpu_workqueue_struct *cwq) |
| @@ -364,7 +383,7 @@ static int flush_cpu_workqueue(struct cpu_workqueue_struct *cwq) | |||
| 364 | active = 0; | 383 | active = 0; |
| 365 | spin_lock_irq(&cwq->lock); | 384 | spin_lock_irq(&cwq->lock); |
| 366 | if (!list_empty(&cwq->worklist) || cwq->current_work != NULL) { | 385 | if (!list_empty(&cwq->worklist) || cwq->current_work != NULL) { |
| 367 | insert_wq_barrier(cwq, &barr, 1); | 386 | insert_wq_barrier(cwq, &barr, &cwq->worklist); |
| 368 | active = 1; | 387 | active = 1; |
| 369 | } | 388 | } |
| 370 | spin_unlock_irq(&cwq->lock); | 389 | spin_unlock_irq(&cwq->lock); |
| @@ -395,13 +414,64 @@ void flush_workqueue(struct workqueue_struct *wq) | |||
| 395 | int cpu; | 414 | int cpu; |
| 396 | 415 | ||
| 397 | might_sleep(); | 416 | might_sleep(); |
| 398 | lock_acquire(&wq->lockdep_map, 0, 0, 0, 2, _THIS_IP_); | 417 | lock_map_acquire(&wq->lockdep_map); |
| 399 | lock_release(&wq->lockdep_map, 1, _THIS_IP_); | 418 | lock_map_release(&wq->lockdep_map); |
| 400 | for_each_cpu_mask(cpu, *cpu_map) | 419 | for_each_cpu_mask_nr(cpu, *cpu_map) |
| 401 | flush_cpu_workqueue(per_cpu_ptr(wq->cpu_wq, cpu)); | 420 | flush_cpu_workqueue(per_cpu_ptr(wq->cpu_wq, cpu)); |
| 402 | } | 421 | } |
| 403 | EXPORT_SYMBOL_GPL(flush_workqueue); | 422 | EXPORT_SYMBOL_GPL(flush_workqueue); |
| 404 | 423 | ||
| 424 | /** | ||
| 425 | * flush_work - block until a work_struct's callback has terminated | ||
| 426 | * @work: the work which is to be flushed | ||
| 427 | * | ||
| 428 | * Returns false if @work has already terminated. | ||
| 429 | * | ||
| 430 | * It is expected that, prior to calling flush_work(), the caller has | ||
| 431 | * arranged for the work to not be requeued, otherwise it doesn't make | ||
| 432 | * sense to use this function. | ||
| 433 | */ | ||
| 434 | int flush_work(struct work_struct *work) | ||
| 435 | { | ||
| 436 | struct cpu_workqueue_struct *cwq; | ||
| 437 | struct list_head *prev; | ||
| 438 | struct wq_barrier barr; | ||
| 439 | |||
| 440 | might_sleep(); | ||
| 441 | cwq = get_wq_data(work); | ||
| 442 | if (!cwq) | ||
| 443 | return 0; | ||
| 444 | |||
| 445 | lock_map_acquire(&cwq->wq->lockdep_map); | ||
| 446 | lock_map_release(&cwq->wq->lockdep_map); | ||
| 447 | |||
| 448 | prev = NULL; | ||
| 449 | spin_lock_irq(&cwq->lock); | ||
| 450 | if (!list_empty(&work->entry)) { | ||
| 451 | /* | ||
| 452 | * See the comment near try_to_grab_pending()->smp_rmb(). | ||
| 453 | * If it was re-queued under us we are not going to wait. | ||
| 454 | */ | ||
| 455 | smp_rmb(); | ||
| 456 | if (unlikely(cwq != get_wq_data(work))) | ||
| 457 | goto out; | ||
| 458 | prev = &work->entry; | ||
| 459 | } else { | ||
| 460 | if (cwq->current_work != work) | ||
| 461 | goto out; | ||
| 462 | prev = &cwq->worklist; | ||
| 463 | } | ||
| 464 | insert_wq_barrier(cwq, &barr, prev->next); | ||
| 465 | out: | ||
| 466 | spin_unlock_irq(&cwq->lock); | ||
| 467 | if (!prev) | ||
| 468 | return 0; | ||
| 469 | |||
| 470 | wait_for_completion(&barr.done); | ||
| 471 | return 1; | ||
| 472 | } | ||
| 473 | EXPORT_SYMBOL_GPL(flush_work); | ||
| 474 | |||
| 405 | /* | 475 | /* |
| 406 | * Upon a successful return (>= 0), the caller "owns" WORK_STRUCT_PENDING bit, | 476 | * Upon a successful return (>= 0), the caller "owns" WORK_STRUCT_PENDING bit, |
| 407 | * so this work can't be re-armed in any way. | 477 | * so this work can't be re-armed in any way. |
| @@ -449,7 +519,7 @@ static void wait_on_cpu_work(struct cpu_workqueue_struct *cwq, | |||
| 449 | 519 | ||
| 450 | spin_lock_irq(&cwq->lock); | 520 | spin_lock_irq(&cwq->lock); |
| 451 | if (unlikely(cwq->current_work == work)) { | 521 | if (unlikely(cwq->current_work == work)) { |
| 452 | insert_wq_barrier(cwq, &barr, 0); | 522 | insert_wq_barrier(cwq, &barr, cwq->worklist.next); |
| 453 | running = 1; | 523 | running = 1; |
| 454 | } | 524 | } |
| 455 | spin_unlock_irq(&cwq->lock); | 525 | spin_unlock_irq(&cwq->lock); |
| @@ -467,8 +537,8 @@ static void wait_on_work(struct work_struct *work) | |||
| 467 | 537 | ||
| 468 | might_sleep(); | 538 | might_sleep(); |
| 469 | 539 | ||
| 470 | lock_acquire(&work->lockdep_map, 0, 0, 0, 2, _THIS_IP_); | 540 | lock_map_acquire(&work->lockdep_map); |
| 471 | lock_release(&work->lockdep_map, 1, _THIS_IP_); | 541 | lock_map_release(&work->lockdep_map); |
| 472 | 542 | ||
| 473 | cwq = get_wq_data(work); | 543 | cwq = get_wq_data(work); |
| 474 | if (!cwq) | 544 | if (!cwq) |
| @@ -477,7 +547,7 @@ static void wait_on_work(struct work_struct *work) | |||
| 477 | wq = cwq->wq; | 547 | wq = cwq->wq; |
| 478 | cpu_map = wq_cpu_map(wq); | 548 | cpu_map = wq_cpu_map(wq); |
| 479 | 549 | ||
| 480 | for_each_cpu_mask(cpu, *cpu_map) | 550 | for_each_cpu_mask_nr(cpu, *cpu_map) |
| 481 | wait_on_cpu_work(per_cpu_ptr(wq->cpu_wq, cpu), work); | 551 | wait_on_cpu_work(per_cpu_ptr(wq->cpu_wq, cpu), work); |
| 482 | } | 552 | } |
| 483 | 553 | ||
| @@ -553,6 +623,19 @@ int schedule_work(struct work_struct *work) | |||
| 553 | } | 623 | } |
| 554 | EXPORT_SYMBOL(schedule_work); | 624 | EXPORT_SYMBOL(schedule_work); |
| 555 | 625 | ||
| 626 | /* | ||
| 627 | * schedule_work_on - put work task on a specific cpu | ||
| 628 | * @cpu: cpu to put the work task on | ||
| 629 | * @work: job to be done | ||
| 630 | * | ||
| 631 | * This puts a job on a specific cpu | ||
| 632 | */ | ||
| 633 | int schedule_work_on(int cpu, struct work_struct *work) | ||
| 634 | { | ||
| 635 | return queue_work_on(cpu, keventd_wq, work); | ||
| 636 | } | ||
| 637 | EXPORT_SYMBOL(schedule_work_on); | ||
| 638 | |||
| 556 | /** | 639 | /** |
| 557 | * schedule_delayed_work - put work task in global workqueue after delay | 640 | * schedule_delayed_work - put work task in global workqueue after delay |
| 558 | * @dwork: job to be done | 641 | * @dwork: job to be done |
| @@ -607,10 +690,10 @@ int schedule_on_each_cpu(work_func_t func) | |||
| 607 | struct work_struct *work = per_cpu_ptr(works, cpu); | 690 | struct work_struct *work = per_cpu_ptr(works, cpu); |
| 608 | 691 | ||
| 609 | INIT_WORK(work, func); | 692 | INIT_WORK(work, func); |
| 610 | set_bit(WORK_STRUCT_PENDING, work_data_bits(work)); | 693 | schedule_work_on(cpu, work); |
| 611 | __queue_work(per_cpu_ptr(keventd_wq->cpu_wq, cpu), work); | ||
| 612 | } | 694 | } |
| 613 | flush_workqueue(keventd_wq); | 695 | for_each_online_cpu(cpu) |
| 696 | flush_work(per_cpu_ptr(works, cpu)); | ||
| 614 | put_online_cpus(); | 697 | put_online_cpus(); |
| 615 | free_percpu(works); | 698 | free_percpu(works); |
| 616 | return 0; | 699 | return 0; |
| @@ -684,6 +767,7 @@ init_cpu_workqueue(struct workqueue_struct *wq, int cpu) | |||
| 684 | 767 | ||
| 685 | static int create_workqueue_thread(struct cpu_workqueue_struct *cwq, int cpu) | 768 | static int create_workqueue_thread(struct cpu_workqueue_struct *cwq, int cpu) |
| 686 | { | 769 | { |
| 770 | struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 }; | ||
| 687 | struct workqueue_struct *wq = cwq->wq; | 771 | struct workqueue_struct *wq = cwq->wq; |
| 688 | const char *fmt = is_single_threaded(wq) ? "%s" : "%s/%d"; | 772 | const char *fmt = is_single_threaded(wq) ? "%s" : "%s/%d"; |
| 689 | struct task_struct *p; | 773 | struct task_struct *p; |
| @@ -699,7 +783,8 @@ static int create_workqueue_thread(struct cpu_workqueue_struct *cwq, int cpu) | |||
| 699 | */ | 783 | */ |
| 700 | if (IS_ERR(p)) | 784 | if (IS_ERR(p)) |
| 701 | return PTR_ERR(p); | 785 | return PTR_ERR(p); |
| 702 | 786 | if (cwq->wq->rt) | |
| 787 | sched_setscheduler_nocheck(p, SCHED_FIFO, ¶m); | ||
| 703 | cwq->thread = p; | 788 | cwq->thread = p; |
| 704 | 789 | ||
| 705 | return 0; | 790 | return 0; |
| @@ -719,6 +804,7 @@ static void start_workqueue_thread(struct cpu_workqueue_struct *cwq, int cpu) | |||
| 719 | struct workqueue_struct *__create_workqueue_key(const char *name, | 804 | struct workqueue_struct *__create_workqueue_key(const char *name, |
| 720 | int singlethread, | 805 | int singlethread, |
| 721 | int freezeable, | 806 | int freezeable, |
| 807 | int rt, | ||
| 722 | struct lock_class_key *key, | 808 | struct lock_class_key *key, |
| 723 | const char *lock_name) | 809 | const char *lock_name) |
| 724 | { | 810 | { |
| @@ -740,6 +826,7 @@ struct workqueue_struct *__create_workqueue_key(const char *name, | |||
| 740 | lockdep_init_map(&wq->lockdep_map, lock_name, key, 0); | 826 | lockdep_init_map(&wq->lockdep_map, lock_name, key, 0); |
| 741 | wq->singlethread = singlethread; | 827 | wq->singlethread = singlethread; |
| 742 | wq->freezeable = freezeable; | 828 | wq->freezeable = freezeable; |
| 829 | wq->rt = rt; | ||
| 743 | INIT_LIST_HEAD(&wq->list); | 830 | INIT_LIST_HEAD(&wq->list); |
| 744 | 831 | ||
| 745 | if (singlethread) { | 832 | if (singlethread) { |
| @@ -747,11 +834,22 @@ struct workqueue_struct *__create_workqueue_key(const char *name, | |||
| 747 | err = create_workqueue_thread(cwq, singlethread_cpu); | 834 | err = create_workqueue_thread(cwq, singlethread_cpu); |
| 748 | start_workqueue_thread(cwq, -1); | 835 | start_workqueue_thread(cwq, -1); |
| 749 | } else { | 836 | } else { |
| 750 | get_online_cpus(); | 837 | cpu_maps_update_begin(); |
| 838 | /* | ||
| 839 | * We must place this wq on list even if the code below fails. | ||
| 840 | * cpu_down(cpu) can remove cpu from cpu_populated_map before | ||
| 841 | * destroy_workqueue() takes the lock, in that case we leak | ||
| 842 | * cwq[cpu]->thread. | ||
| 843 | */ | ||
| 751 | spin_lock(&workqueue_lock); | 844 | spin_lock(&workqueue_lock); |
| 752 | list_add(&wq->list, &workqueues); | 845 | list_add(&wq->list, &workqueues); |
| 753 | spin_unlock(&workqueue_lock); | 846 | spin_unlock(&workqueue_lock); |
| 754 | 847 | /* | |
| 848 | * We must initialize cwqs for each possible cpu even if we | ||
| 849 | * are going to call destroy_workqueue() finally. Otherwise | ||
| 850 | * cpu_up() can hit the uninitialized cwq once we drop the | ||
| 851 | * lock. | ||
| 852 | */ | ||
| 755 | for_each_possible_cpu(cpu) { | 853 | for_each_possible_cpu(cpu) { |
| 756 | cwq = init_cpu_workqueue(wq, cpu); | 854 | cwq = init_cpu_workqueue(wq, cpu); |
| 757 | if (err || !cpu_online(cpu)) | 855 | if (err || !cpu_online(cpu)) |
| @@ -759,7 +857,7 @@ struct workqueue_struct *__create_workqueue_key(const char *name, | |||
| 759 | err = create_workqueue_thread(cwq, cpu); | 857 | err = create_workqueue_thread(cwq, cpu); |
| 760 | start_workqueue_thread(cwq, cpu); | 858 | start_workqueue_thread(cwq, cpu); |
| 761 | } | 859 | } |
| 762 | put_online_cpus(); | 860 | cpu_maps_update_done(); |
| 763 | } | 861 | } |
| 764 | 862 | ||
| 765 | if (err) { | 863 | if (err) { |
| @@ -773,18 +871,18 @@ EXPORT_SYMBOL_GPL(__create_workqueue_key); | |||
| 773 | static void cleanup_workqueue_thread(struct cpu_workqueue_struct *cwq) | 871 | static void cleanup_workqueue_thread(struct cpu_workqueue_struct *cwq) |
| 774 | { | 872 | { |
| 775 | /* | 873 | /* |
| 776 | * Our caller is either destroy_workqueue() or CPU_DEAD, | 874 | * Our caller is either destroy_workqueue() or CPU_POST_DEAD, |
| 777 | * get_online_cpus() protects cwq->thread. | 875 | * cpu_add_remove_lock protects cwq->thread. |
| 778 | */ | 876 | */ |
| 779 | if (cwq->thread == NULL) | 877 | if (cwq->thread == NULL) |
| 780 | return; | 878 | return; |
| 781 | 879 | ||
| 782 | lock_acquire(&cwq->wq->lockdep_map, 0, 0, 0, 2, _THIS_IP_); | 880 | lock_map_acquire(&cwq->wq->lockdep_map); |
| 783 | lock_release(&cwq->wq->lockdep_map, 1, _THIS_IP_); | 881 | lock_map_release(&cwq->wq->lockdep_map); |
| 784 | 882 | ||
| 785 | flush_cpu_workqueue(cwq); | 883 | flush_cpu_workqueue(cwq); |
| 786 | /* | 884 | /* |
| 787 | * If the caller is CPU_DEAD and cwq->worklist was not empty, | 885 | * If the caller is CPU_POST_DEAD and cwq->worklist was not empty, |
| 788 | * a concurrent flush_workqueue() can insert a barrier after us. | 886 | * a concurrent flush_workqueue() can insert a barrier after us. |
| 789 | * However, in that case run_workqueue() won't return and check | 887 | * However, in that case run_workqueue() won't return and check |
| 790 | * kthread_should_stop() until it flushes all work_struct's. | 888 | * kthread_should_stop() until it flushes all work_struct's. |
| @@ -808,14 +906,14 @@ void destroy_workqueue(struct workqueue_struct *wq) | |||
| 808 | const cpumask_t *cpu_map = wq_cpu_map(wq); | 906 | const cpumask_t *cpu_map = wq_cpu_map(wq); |
| 809 | int cpu; | 907 | int cpu; |
| 810 | 908 | ||
| 811 | get_online_cpus(); | 909 | cpu_maps_update_begin(); |
| 812 | spin_lock(&workqueue_lock); | 910 | spin_lock(&workqueue_lock); |
| 813 | list_del(&wq->list); | 911 | list_del(&wq->list); |
| 814 | spin_unlock(&workqueue_lock); | 912 | spin_unlock(&workqueue_lock); |
| 815 | 913 | ||
| 816 | for_each_cpu_mask(cpu, *cpu_map) | 914 | for_each_cpu_mask_nr(cpu, *cpu_map) |
| 817 | cleanup_workqueue_thread(per_cpu_ptr(wq->cpu_wq, cpu)); | 915 | cleanup_workqueue_thread(per_cpu_ptr(wq->cpu_wq, cpu)); |
| 818 | put_online_cpus(); | 916 | cpu_maps_update_done(); |
| 819 | 917 | ||
| 820 | free_percpu(wq->cpu_wq); | 918 | free_percpu(wq->cpu_wq); |
| 821 | kfree(wq); | 919 | kfree(wq); |
| @@ -829,6 +927,7 @@ static int __devinit workqueue_cpu_callback(struct notifier_block *nfb, | |||
| 829 | unsigned int cpu = (unsigned long)hcpu; | 927 | unsigned int cpu = (unsigned long)hcpu; |
| 830 | struct cpu_workqueue_struct *cwq; | 928 | struct cpu_workqueue_struct *cwq; |
| 831 | struct workqueue_struct *wq; | 929 | struct workqueue_struct *wq; |
| 930 | int ret = NOTIFY_OK; | ||
| 832 | 931 | ||
| 833 | action &= ~CPU_TASKS_FROZEN; | 932 | action &= ~CPU_TASKS_FROZEN; |
| 834 | 933 | ||
| @@ -836,7 +935,7 @@ static int __devinit workqueue_cpu_callback(struct notifier_block *nfb, | |||
| 836 | case CPU_UP_PREPARE: | 935 | case CPU_UP_PREPARE: |
| 837 | cpu_set(cpu, cpu_populated_map); | 936 | cpu_set(cpu, cpu_populated_map); |
| 838 | } | 937 | } |
| 839 | 938 | undo: | |
| 840 | list_for_each_entry(wq, &workqueues, list) { | 939 | list_for_each_entry(wq, &workqueues, list) { |
| 841 | cwq = per_cpu_ptr(wq->cpu_wq, cpu); | 940 | cwq = per_cpu_ptr(wq->cpu_wq, cpu); |
| 842 | 941 | ||
| @@ -846,7 +945,9 @@ static int __devinit workqueue_cpu_callback(struct notifier_block *nfb, | |||
| 846 | break; | 945 | break; |
| 847 | printk(KERN_ERR "workqueue [%s] for %i failed\n", | 946 | printk(KERN_ERR "workqueue [%s] for %i failed\n", |
| 848 | wq->name, cpu); | 947 | wq->name, cpu); |
| 849 | return NOTIFY_BAD; | 948 | action = CPU_UP_CANCELED; |
| 949 | ret = NOTIFY_BAD; | ||
| 950 | goto undo; | ||
| 850 | 951 | ||
| 851 | case CPU_ONLINE: | 952 | case CPU_ONLINE: |
| 852 | start_workqueue_thread(cwq, cpu); | 953 | start_workqueue_thread(cwq, cpu); |
| @@ -854,7 +955,7 @@ static int __devinit workqueue_cpu_callback(struct notifier_block *nfb, | |||
| 854 | 955 | ||
| 855 | case CPU_UP_CANCELED: | 956 | case CPU_UP_CANCELED: |
| 856 | start_workqueue_thread(cwq, -1); | 957 | start_workqueue_thread(cwq, -1); |
| 857 | case CPU_DEAD: | 958 | case CPU_POST_DEAD: |
| 858 | cleanup_workqueue_thread(cwq); | 959 | cleanup_workqueue_thread(cwq); |
| 859 | break; | 960 | break; |
| 860 | } | 961 | } |
| @@ -862,11 +963,11 @@ static int __devinit workqueue_cpu_callback(struct notifier_block *nfb, | |||
| 862 | 963 | ||
| 863 | switch (action) { | 964 | switch (action) { |
| 864 | case CPU_UP_CANCELED: | 965 | case CPU_UP_CANCELED: |
| 865 | case CPU_DEAD: | 966 | case CPU_POST_DEAD: |
| 866 | cpu_clear(cpu, cpu_populated_map); | 967 | cpu_clear(cpu, cpu_populated_map); |
| 867 | } | 968 | } |
| 868 | 969 | ||
| 869 | return NOTIFY_OK; | 970 | return ret; |
| 870 | } | 971 | } |
| 871 | 972 | ||
| 872 | void __init init_workqueues(void) | 973 | void __init init_workqueues(void) |
