aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/workqueue.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/workqueue.c')
-rw-r--r--kernel/workqueue.c49
1 files changed, 35 insertions, 14 deletions
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 11869faa6819..5ca7ce9ce754 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -79,7 +79,9 @@ enum {
79 MAX_IDLE_WORKERS_RATIO = 4, /* 1/4 of busy can be idle */ 79 MAX_IDLE_WORKERS_RATIO = 4, /* 1/4 of busy can be idle */
80 IDLE_WORKER_TIMEOUT = 300 * HZ, /* keep idle ones for 5 mins */ 80 IDLE_WORKER_TIMEOUT = 300 * HZ, /* keep idle ones for 5 mins */
81 81
82 MAYDAY_INITIAL_TIMEOUT = HZ / 100, /* call for help after 10ms */ 82 MAYDAY_INITIAL_TIMEOUT = HZ / 100 >= 2 ? HZ / 100 : 2,
83 /* call for help after 10ms
84 (min two ticks) */
83 MAYDAY_INTERVAL = HZ / 10, /* and then every 100ms */ 85 MAYDAY_INTERVAL = HZ / 10, /* and then every 100ms */
84 CREATE_COOLDOWN = HZ, /* time to breath after fail */ 86 CREATE_COOLDOWN = HZ, /* time to breath after fail */
85 TRUSTEE_COOLDOWN = HZ / 10, /* for trustee draining */ 87 TRUSTEE_COOLDOWN = HZ / 10, /* for trustee draining */
@@ -249,10 +251,12 @@ struct workqueue_struct *system_wq __read_mostly;
249struct workqueue_struct *system_long_wq __read_mostly; 251struct workqueue_struct *system_long_wq __read_mostly;
250struct workqueue_struct *system_nrt_wq __read_mostly; 252struct workqueue_struct *system_nrt_wq __read_mostly;
251struct workqueue_struct *system_unbound_wq __read_mostly; 253struct workqueue_struct *system_unbound_wq __read_mostly;
254struct workqueue_struct *system_freezable_wq __read_mostly;
252EXPORT_SYMBOL_GPL(system_wq); 255EXPORT_SYMBOL_GPL(system_wq);
253EXPORT_SYMBOL_GPL(system_long_wq); 256EXPORT_SYMBOL_GPL(system_long_wq);
254EXPORT_SYMBOL_GPL(system_nrt_wq); 257EXPORT_SYMBOL_GPL(system_nrt_wq);
255EXPORT_SYMBOL_GPL(system_unbound_wq); 258EXPORT_SYMBOL_GPL(system_unbound_wq);
259EXPORT_SYMBOL_GPL(system_freezable_wq);
256 260
257#define CREATE_TRACE_POINTS 261#define CREATE_TRACE_POINTS
258#include <trace/events/workqueue.h> 262#include <trace/events/workqueue.h>
@@ -314,6 +318,11 @@ static inline int __next_wq_cpu(int cpu, const struct cpumask *mask,
314 318
315static struct debug_obj_descr work_debug_descr; 319static struct debug_obj_descr work_debug_descr;
316 320
321static void *work_debug_hint(void *addr)
322{
323 return ((struct work_struct *) addr)->func;
324}
325
317/* 326/*
318 * fixup_init is called when: 327 * fixup_init is called when:
319 * - an active object is initialized 328 * - an active object is initialized
@@ -385,6 +394,7 @@ static int work_fixup_free(void *addr, enum debug_obj_state state)
385 394
386static struct debug_obj_descr work_debug_descr = { 395static struct debug_obj_descr work_debug_descr = {
387 .name = "work_struct", 396 .name = "work_struct",
397 .debug_hint = work_debug_hint,
388 .fixup_init = work_fixup_init, 398 .fixup_init = work_fixup_init,
389 .fixup_activate = work_fixup_activate, 399 .fixup_activate = work_fixup_activate,
390 .fixup_free = work_fixup_free, 400 .fixup_free = work_fixup_free,
@@ -2047,6 +2057,15 @@ repeat:
2047 move_linked_works(work, scheduled, &n); 2057 move_linked_works(work, scheduled, &n);
2048 2058
2049 process_scheduled_works(rescuer); 2059 process_scheduled_works(rescuer);
2060
2061 /*
2062 * Leave this gcwq. If keep_working() is %true, notify a
2063 * regular worker; otherwise, we end up with 0 concurrency
2064 * and stalling the execution.
2065 */
2066 if (keep_working(gcwq))
2067 wake_up_worker(gcwq);
2068
2050 spin_unlock_irq(&gcwq->lock); 2069 spin_unlock_irq(&gcwq->lock);
2051 } 2070 }
2052 2071
@@ -2956,7 +2975,7 @@ struct workqueue_struct *__alloc_workqueue_key(const char *name,
2956 */ 2975 */
2957 spin_lock(&workqueue_lock); 2976 spin_lock(&workqueue_lock);
2958 2977
2959 if (workqueue_freezing && wq->flags & WQ_FREEZEABLE) 2978 if (workqueue_freezing && wq->flags & WQ_FREEZABLE)
2960 for_each_cwq_cpu(cpu, wq) 2979 for_each_cwq_cpu(cpu, wq)
2961 get_cwq(cpu, wq)->max_active = 0; 2980 get_cwq(cpu, wq)->max_active = 0;
2962 2981
@@ -3068,7 +3087,7 @@ void workqueue_set_max_active(struct workqueue_struct *wq, int max_active)
3068 3087
3069 spin_lock_irq(&gcwq->lock); 3088 spin_lock_irq(&gcwq->lock);
3070 3089
3071 if (!(wq->flags & WQ_FREEZEABLE) || 3090 if (!(wq->flags & WQ_FREEZABLE) ||
3072 !(gcwq->flags & GCWQ_FREEZING)) 3091 !(gcwq->flags & GCWQ_FREEZING))
3073 get_cwq(gcwq->cpu, wq)->max_active = max_active; 3092 get_cwq(gcwq->cpu, wq)->max_active = max_active;
3074 3093
@@ -3318,7 +3337,7 @@ static int __cpuinit trustee_thread(void *__gcwq)
3318 * want to get it over with ASAP - spam rescuers, wake up as 3337 * want to get it over with ASAP - spam rescuers, wake up as
3319 * many idlers as necessary and create new ones till the 3338 * many idlers as necessary and create new ones till the
3320 * worklist is empty. Note that if the gcwq is frozen, there 3339 * worklist is empty. Note that if the gcwq is frozen, there
3321 * may be frozen works in freezeable cwqs. Don't declare 3340 * may be frozen works in freezable cwqs. Don't declare
3322 * completion while frozen. 3341 * completion while frozen.
3323 */ 3342 */
3324 while (gcwq->nr_workers != gcwq->nr_idle || 3343 while (gcwq->nr_workers != gcwq->nr_idle ||
@@ -3576,9 +3595,9 @@ EXPORT_SYMBOL_GPL(work_on_cpu);
3576/** 3595/**
3577 * freeze_workqueues_begin - begin freezing workqueues 3596 * freeze_workqueues_begin - begin freezing workqueues
3578 * 3597 *
3579 * Start freezing workqueues. After this function returns, all 3598 * Start freezing workqueues. After this function returns, all freezable
3580 * freezeable workqueues will queue new works to their frozen_works 3599 * workqueues will queue new works to their frozen_works list instead of
3581 * list instead of gcwq->worklist. 3600 * gcwq->worklist.
3582 * 3601 *
3583 * CONTEXT: 3602 * CONTEXT:
3584 * Grabs and releases workqueue_lock and gcwq->lock's. 3603 * Grabs and releases workqueue_lock and gcwq->lock's.
@@ -3604,7 +3623,7 @@ void freeze_workqueues_begin(void)
3604 list_for_each_entry(wq, &workqueues, list) { 3623 list_for_each_entry(wq, &workqueues, list) {
3605 struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq); 3624 struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq);
3606 3625
3607 if (cwq && wq->flags & WQ_FREEZEABLE) 3626 if (cwq && wq->flags & WQ_FREEZABLE)
3608 cwq->max_active = 0; 3627 cwq->max_active = 0;
3609 } 3628 }
3610 3629
@@ -3615,7 +3634,7 @@ void freeze_workqueues_begin(void)
3615} 3634}
3616 3635
3617/** 3636/**
3618 * freeze_workqueues_busy - are freezeable workqueues still busy? 3637 * freeze_workqueues_busy - are freezable workqueues still busy?
3619 * 3638 *
3620 * Check whether freezing is complete. This function must be called 3639 * Check whether freezing is complete. This function must be called
3621 * between freeze_workqueues_begin() and thaw_workqueues(). 3640 * between freeze_workqueues_begin() and thaw_workqueues().
@@ -3624,8 +3643,8 @@ void freeze_workqueues_begin(void)
3624 * Grabs and releases workqueue_lock. 3643 * Grabs and releases workqueue_lock.
3625 * 3644 *
3626 * RETURNS: 3645 * RETURNS:
3627 * %true if some freezeable workqueues are still busy. %false if 3646 * %true if some freezable workqueues are still busy. %false if freezing
3628 * freezing is complete. 3647 * is complete.
3629 */ 3648 */
3630bool freeze_workqueues_busy(void) 3649bool freeze_workqueues_busy(void)
3631{ 3650{
@@ -3645,7 +3664,7 @@ bool freeze_workqueues_busy(void)
3645 list_for_each_entry(wq, &workqueues, list) { 3664 list_for_each_entry(wq, &workqueues, list) {
3646 struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq); 3665 struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq);
3647 3666
3648 if (!cwq || !(wq->flags & WQ_FREEZEABLE)) 3667 if (!cwq || !(wq->flags & WQ_FREEZABLE))
3649 continue; 3668 continue;
3650 3669
3651 BUG_ON(cwq->nr_active < 0); 3670 BUG_ON(cwq->nr_active < 0);
@@ -3690,7 +3709,7 @@ void thaw_workqueues(void)
3690 list_for_each_entry(wq, &workqueues, list) { 3709 list_for_each_entry(wq, &workqueues, list) {
3691 struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq); 3710 struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq);
3692 3711
3693 if (!cwq || !(wq->flags & WQ_FREEZEABLE)) 3712 if (!cwq || !(wq->flags & WQ_FREEZABLE))
3694 continue; 3713 continue;
3695 3714
3696 /* restore max_active and repopulate worklist */ 3715 /* restore max_active and repopulate worklist */
@@ -3764,8 +3783,10 @@ static int __init init_workqueues(void)
3764 system_nrt_wq = alloc_workqueue("events_nrt", WQ_NON_REENTRANT, 0); 3783 system_nrt_wq = alloc_workqueue("events_nrt", WQ_NON_REENTRANT, 0);
3765 system_unbound_wq = alloc_workqueue("events_unbound", WQ_UNBOUND, 3784 system_unbound_wq = alloc_workqueue("events_unbound", WQ_UNBOUND,
3766 WQ_UNBOUND_MAX_ACTIVE); 3785 WQ_UNBOUND_MAX_ACTIVE);
3786 system_freezable_wq = alloc_workqueue("events_freezable",
3787 WQ_FREEZABLE, 0);
3767 BUG_ON(!system_wq || !system_long_wq || !system_nrt_wq || 3788 BUG_ON(!system_wq || !system_long_wq || !system_nrt_wq ||
3768 !system_unbound_wq); 3789 !system_unbound_wq || !system_freezable_wq);
3769 return 0; 3790 return 0;
3770} 3791}
3771early_initcall(init_workqueues); 3792early_initcall(init_workqueues);