workqueue.c (0a9d59a2461477bd9ed143c01af9df3f8f00fa81) workqueue.c (58a69cb47ec6991bf006a3e5d202e8571b0327a4)
1/*
2 * kernel/workqueue.c - generic async execution with shared worker pool
3 *
4 * Copyright (C) 2002 Ingo Molnar
5 *
6 * Derived from the taskqueue/keventd code by:
7 * David Woodhouse <dwmw2@infradead.org>
8 * Andrew Morton

--- 2033 unchanged lines hidden (view full) ---

2042 * process'em.
2043 */
2044 BUG_ON(!list_empty(&rescuer->scheduled));
2045 list_for_each_entry_safe(work, n, &gcwq->worklist, entry)
2046 if (get_work_cwq(work) == cwq)
2047 move_linked_works(work, scheduled, &n);
2048
2049 process_scheduled_works(rescuer);
1/*
2 * kernel/workqueue.c - generic async execution with shared worker pool
3 *
4 * Copyright (C) 2002 Ingo Molnar
5 *
6 * Derived from the taskqueue/keventd code by:
7 * David Woodhouse <dwmw2@infradead.org>
8 * Andrew Morton

--- 2033 unchanged lines hidden (view full) ---

2042 * process'em.
2043 */
2044 BUG_ON(!list_empty(&rescuer->scheduled));
2045 list_for_each_entry_safe(work, n, &gcwq->worklist, entry)
2046 if (get_work_cwq(work) == cwq)
2047 move_linked_works(work, scheduled, &n);
2048
2049 process_scheduled_works(rescuer);
2050
2051 /*
2052 * Leave this gcwq. If keep_working() is %true, notify a
2053 * regular worker; otherwise, we end up with 0 concurrency
2054 * and stalling the execution.
2055 */
2056 if (keep_working(gcwq))
2057 wake_up_worker(gcwq);
2058
2050 spin_unlock_irq(&gcwq->lock);
2051 }
2052
2053 schedule();
2054 goto repeat;
2055}
2056
2057struct wq_barrier {

--- 893 unchanged lines hidden (view full) ---

2951
2952 /*
2953 * workqueue_lock protects global freeze state and workqueues
2954 * list. Grab it, set max_active accordingly and add the new
2955 * workqueue to workqueues list.
2956 */
2957 spin_lock(&workqueue_lock);
2958
2059 spin_unlock_irq(&gcwq->lock);
2060 }
2061
2062 schedule();
2063 goto repeat;
2064}
2065
2066struct wq_barrier {

--- 893 unchanged lines hidden (view full) ---

2960
2961 /*
2962 * workqueue_lock protects global freeze state and workqueues
2963 * list. Grab it, set max_active accordingly and add the new
2964 * workqueue to workqueues list.
2965 */
2966 spin_lock(&workqueue_lock);
2967
2959 if (workqueue_freezing && wq->flags & WQ_FREEZEABLE)
2968 if (workqueue_freezing && wq->flags & WQ_FREEZABLE)
2960 for_each_cwq_cpu(cpu, wq)
2961 get_cwq(cpu, wq)->max_active = 0;
2962
2963 list_add(&wq->list, &workqueues);
2964
2965 spin_unlock(&workqueue_lock);
2966
2967 return wq;

--- 95 unchanged lines hidden (view full) ---

3063
3064 wq->saved_max_active = max_active;
3065
3066 for_each_cwq_cpu(cpu, wq) {
3067 struct global_cwq *gcwq = get_gcwq(cpu);
3068
3069 spin_lock_irq(&gcwq->lock);
3070
2969 for_each_cwq_cpu(cpu, wq)
2970 get_cwq(cpu, wq)->max_active = 0;
2971
2972 list_add(&wq->list, &workqueues);
2973
2974 spin_unlock(&workqueue_lock);
2975
2976 return wq;

--- 95 unchanged lines hidden (view full) ---

3072
3073 wq->saved_max_active = max_active;
3074
3075 for_each_cwq_cpu(cpu, wq) {
3076 struct global_cwq *gcwq = get_gcwq(cpu);
3077
3078 spin_lock_irq(&gcwq->lock);
3079
3071 if (!(wq->flags & WQ_FREEZEABLE) ||
3080 if (!(wq->flags & WQ_FREEZABLE) ||
3072 !(gcwq->flags & GCWQ_FREEZING))
3073 get_cwq(gcwq->cpu, wq)->max_active = max_active;
3074
3075 spin_unlock_irq(&gcwq->lock);
3076 }
3077
3078 spin_unlock(&workqueue_lock);
3079}

--- 233 unchanged lines hidden (view full) ---

3313
3314 /*
3315 * The original cpu is in the process of dying and may go away
3316 * anytime now. When that happens, we and all workers would
3317 * be migrated to other cpus. Try draining any left work. We
3318 * want to get it over with ASAP - spam rescuers, wake up as
3319 * many idlers as necessary and create new ones till the
3320 * worklist is empty. Note that if the gcwq is frozen, there
3081 !(gcwq->flags & GCWQ_FREEZING))
3082 get_cwq(gcwq->cpu, wq)->max_active = max_active;
3083
3084 spin_unlock_irq(&gcwq->lock);
3085 }
3086
3087 spin_unlock(&workqueue_lock);
3088}

--- 233 unchanged lines hidden (view full) ---

3322
3323 /*
3324 * The original cpu is in the process of dying and may go away
3325 * anytime now. When that happens, we and all workers would
3326 * be migrated to other cpus. Try draining any left work. We
3327 * want to get it over with ASAP - spam rescuers, wake up as
3328 * many idlers as necessary and create new ones till the
3329 * worklist is empty. Note that if the gcwq is frozen, there
3321 * may be frozen works in freezeable cwqs. Don't declare
3330 * may be frozen works in freezable cwqs. Don't declare
3322 * completion while frozen.
3323 */
3324 while (gcwq->nr_workers != gcwq->nr_idle ||
3325 gcwq->flags & GCWQ_FREEZING ||
3326 gcwq->trustee_state == TRUSTEE_IN_CHARGE) {
3327 int nr_works = 0;
3328
3329 list_for_each_entry(work, &gcwq->worklist, entry) {

--- 241 unchanged lines hidden (view full) ---

3571EXPORT_SYMBOL_GPL(work_on_cpu);
3572#endif /* CONFIG_SMP */
3573
3574#ifdef CONFIG_FREEZER
3575
3576/**
3577 * freeze_workqueues_begin - begin freezing workqueues
3578 *
3331 * completion while frozen.
3332 */
3333 while (gcwq->nr_workers != gcwq->nr_idle ||
3334 gcwq->flags & GCWQ_FREEZING ||
3335 gcwq->trustee_state == TRUSTEE_IN_CHARGE) {
3336 int nr_works = 0;
3337
3338 list_for_each_entry(work, &gcwq->worklist, entry) {

--- 241 unchanged lines hidden (view full) ---

3580EXPORT_SYMBOL_GPL(work_on_cpu);
3581#endif /* CONFIG_SMP */
3582
3583#ifdef CONFIG_FREEZER
3584
3585/**
3586 * freeze_workqueues_begin - begin freezing workqueues
3587 *
3579 * Start freezing workqueues. After this function returns, all
3580 * freezeable workqueues will queue new works to their frozen_works
3581 * list instead of gcwq->worklist.
3588 * Start freezing workqueues. After this function returns, all freezable
3589 * workqueues will queue new works to their frozen_works list instead of
3590 * gcwq->worklist.
3582 *
3583 * CONTEXT:
3584 * Grabs and releases workqueue_lock and gcwq->lock's.
3585 */
3586void freeze_workqueues_begin(void)
3587{
3588 unsigned int cpu;
3589

--- 9 unchanged lines hidden (view full) ---

3599 spin_lock_irq(&gcwq->lock);
3600
3601 BUG_ON(gcwq->flags & GCWQ_FREEZING);
3602 gcwq->flags |= GCWQ_FREEZING;
3603
3604 list_for_each_entry(wq, &workqueues, list) {
3605 struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq);
3606
3591 *
3592 * CONTEXT:
3593 * Grabs and releases workqueue_lock and gcwq->lock's.
3594 */
3595void freeze_workqueues_begin(void)
3596{
3597 unsigned int cpu;
3598

--- 9 unchanged lines hidden (view full) ---

3608 spin_lock_irq(&gcwq->lock);
3609
3610 BUG_ON(gcwq->flags & GCWQ_FREEZING);
3611 gcwq->flags |= GCWQ_FREEZING;
3612
3613 list_for_each_entry(wq, &workqueues, list) {
3614 struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq);
3615
3607 if (cwq && wq->flags & WQ_FREEZEABLE)
3616 if (cwq && wq->flags & WQ_FREEZABLE)
3608 cwq->max_active = 0;
3609 }
3610
3611 spin_unlock_irq(&gcwq->lock);
3612 }
3613
3614 spin_unlock(&workqueue_lock);
3615}
3616
3617/**
3617 cwq->max_active = 0;
3618 }
3619
3620 spin_unlock_irq(&gcwq->lock);
3621 }
3622
3623 spin_unlock(&workqueue_lock);
3624}
3625
3626/**
3618 * freeze_workqueues_busy - are freezeable workqueues still busy?
3627 * freeze_workqueues_busy - are freezable workqueues still busy?
3619 *
3620 * Check whether freezing is complete. This function must be called
3621 * between freeze_workqueues_begin() and thaw_workqueues().
3622 *
3623 * CONTEXT:
3624 * Grabs and releases workqueue_lock.
3625 *
3626 * RETURNS:
3628 *
3629 * Check whether freezing is complete. This function must be called
3630 * between freeze_workqueues_begin() and thaw_workqueues().
3631 *
3632 * CONTEXT:
3633 * Grabs and releases workqueue_lock.
3634 *
3635 * RETURNS:
3627 * %true if some freezeable workqueues are still busy. %false if
3628 * freezing is complete.
3636 * %true if some freezable workqueues are still busy. %false if freezing
3637 * is complete.
3629 */
3630bool freeze_workqueues_busy(void)
3631{
3632 unsigned int cpu;
3633 bool busy = false;
3634
3635 spin_lock(&workqueue_lock);
3636
3637 BUG_ON(!workqueue_freezing);
3638
3639 for_each_gcwq_cpu(cpu) {
3640 struct workqueue_struct *wq;
3641 /*
3642 * nr_active is monotonically decreasing. It's safe
3643 * to peek without lock.
3644 */
3645 list_for_each_entry(wq, &workqueues, list) {
3646 struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq);
3647
3638 */
3639bool freeze_workqueues_busy(void)
3640{
3641 unsigned int cpu;
3642 bool busy = false;
3643
3644 spin_lock(&workqueue_lock);
3645
3646 BUG_ON(!workqueue_freezing);
3647
3648 for_each_gcwq_cpu(cpu) {
3649 struct workqueue_struct *wq;
3650 /*
3651 * nr_active is monotonically decreasing. It's safe
3652 * to peek without lock.
3653 */
3654 list_for_each_entry(wq, &workqueues, list) {
3655 struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq);
3656
3648 if (!cwq || !(wq->flags & WQ_FREEZEABLE))
3657 if (!cwq || !(wq->flags & WQ_FREEZABLE))
3649 continue;
3650
3651 BUG_ON(cwq->nr_active < 0);
3652 if (cwq->nr_active) {
3653 busy = true;
3654 goto out_unlock;
3655 }
3656 }

--- 28 unchanged lines hidden (view full) ---

3685 spin_lock_irq(&gcwq->lock);
3686
3687 BUG_ON(!(gcwq->flags & GCWQ_FREEZING));
3688 gcwq->flags &= ~GCWQ_FREEZING;
3689
3690 list_for_each_entry(wq, &workqueues, list) {
3691 struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq);
3692
3658 continue;
3659
3660 BUG_ON(cwq->nr_active < 0);
3661 if (cwq->nr_active) {
3662 busy = true;
3663 goto out_unlock;
3664 }
3665 }

--- 28 unchanged lines hidden (view full) ---

3694 spin_lock_irq(&gcwq->lock);
3695
3696 BUG_ON(!(gcwq->flags & GCWQ_FREEZING));
3697 gcwq->flags &= ~GCWQ_FREEZING;
3698
3699 list_for_each_entry(wq, &workqueues, list) {
3700 struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq);
3701
3693 if (!cwq || !(wq->flags & WQ_FREEZEABLE))
3702 if (!cwq || !(wq->flags & WQ_FREEZABLE))
3694 continue;
3695
3696 /* restore max_active and repopulate worklist */
3697 cwq->max_active = wq->saved_max_active;
3698
3699 while (!list_empty(&cwq->delayed_works) &&
3700 cwq->nr_active < cwq->max_active)
3701 cwq_activate_first_delayed(cwq);

--- 70 unchanged lines hidden ---
3703 continue;
3704
3705 /* restore max_active and repopulate worklist */
3706 cwq->max_active = wq->saved_max_active;
3707
3708 while (!list_empty(&cwq->delayed_works) &&
3709 cwq->nr_active < cwq->max_active)
3710 cwq_activate_first_delayed(cwq);

--- 70 unchanged lines hidden ---