aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/workqueue.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/workqueue.c')
-rw-r--r--kernel/workqueue.c75
1 files changed, 56 insertions, 19 deletions
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 8ee6ec82f88a..04ef830690ec 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,
@@ -768,7 +778,11 @@ static inline void worker_clr_flags(struct worker *worker, unsigned int flags)
768 778
769 worker->flags &= ~flags; 779 worker->flags &= ~flags;
770 780
771 /* if transitioning out of NOT_RUNNING, increment nr_running */ 781 /*
782 * If transitioning out of NOT_RUNNING, increment nr_running. Note
783 * that the nested NOT_RUNNING is not a noop. NOT_RUNNING is mask
784 * of multiple flags, not a single flag.
785 */
772 if ((flags & WORKER_NOT_RUNNING) && (oflags & WORKER_NOT_RUNNING)) 786 if ((flags & WORKER_NOT_RUNNING) && (oflags & WORKER_NOT_RUNNING))
773 if (!(worker->flags & WORKER_NOT_RUNNING)) 787 if (!(worker->flags & WORKER_NOT_RUNNING))
774 atomic_inc(get_gcwq_nr_running(gcwq->cpu)); 788 atomic_inc(get_gcwq_nr_running(gcwq->cpu));
@@ -1352,8 +1366,10 @@ static struct worker *create_worker(struct global_cwq *gcwq, bool bind)
1352 worker->id = id; 1366 worker->id = id;
1353 1367
1354 if (!on_unbound_cpu) 1368 if (!on_unbound_cpu)
1355 worker->task = kthread_create(worker_thread, worker, 1369 worker->task = kthread_create_on_node(worker_thread,
1356 "kworker/%u:%d", gcwq->cpu, id); 1370 worker,
1371 cpu_to_node(gcwq->cpu),
1372 "kworker/%u:%d", gcwq->cpu, id);
1357 else 1373 else
1358 worker->task = kthread_create(worker_thread, worker, 1374 worker->task = kthread_create(worker_thread, worker,
1359 "kworker/u:%d", id); 1375 "kworker/u:%d", id);
@@ -1840,7 +1856,7 @@ __acquires(&gcwq->lock)
1840 spin_unlock_irq(&gcwq->lock); 1856 spin_unlock_irq(&gcwq->lock);
1841 1857
1842 work_clear_pending(work); 1858 work_clear_pending(work);
1843 lock_map_acquire(&cwq->wq->lockdep_map); 1859 lock_map_acquire_read(&cwq->wq->lockdep_map);
1844 lock_map_acquire(&lockdep_map); 1860 lock_map_acquire(&lockdep_map);
1845 trace_workqueue_execute_start(work); 1861 trace_workqueue_execute_start(work);
1846 f(work); 1862 f(work);
@@ -2043,6 +2059,15 @@ repeat:
2043 move_linked_works(work, scheduled, &n); 2059 move_linked_works(work, scheduled, &n);
2044 2060
2045 process_scheduled_works(rescuer); 2061 process_scheduled_works(rescuer);
2062
2063 /*
2064 * Leave this gcwq. If keep_working() is %true, notify a
2065 * regular worker; otherwise, we end up with 0 concurrency
2066 * and stalling the execution.
2067 */
2068 if (keep_working(gcwq))
2069 wake_up_worker(gcwq);
2070
2046 spin_unlock_irq(&gcwq->lock); 2071 spin_unlock_irq(&gcwq->lock);
2047 } 2072 }
2048 2073
@@ -2384,8 +2409,18 @@ static bool start_flush_work(struct work_struct *work, struct wq_barrier *barr,
2384 insert_wq_barrier(cwq, barr, work, worker); 2409 insert_wq_barrier(cwq, barr, work, worker);
2385 spin_unlock_irq(&gcwq->lock); 2410 spin_unlock_irq(&gcwq->lock);
2386 2411
2387 lock_map_acquire(&cwq->wq->lockdep_map); 2412 /*
2413 * If @max_active is 1 or rescuer is in use, flushing another work
2414 * item on the same workqueue may lead to deadlock. Make sure the
2415 * flusher is not running on the same workqueue by verifying write
2416 * access.
2417 */
2418 if (cwq->wq->saved_max_active == 1 || cwq->wq->flags & WQ_RESCUER)
2419 lock_map_acquire(&cwq->wq->lockdep_map);
2420 else
2421 lock_map_acquire_read(&cwq->wq->lockdep_map);
2388 lock_map_release(&cwq->wq->lockdep_map); 2422 lock_map_release(&cwq->wq->lockdep_map);
2423
2389 return true; 2424 return true;
2390already_gone: 2425already_gone:
2391 spin_unlock_irq(&gcwq->lock); 2426 spin_unlock_irq(&gcwq->lock);
@@ -2942,7 +2977,7 @@ struct workqueue_struct *__alloc_workqueue_key(const char *name,
2942 */ 2977 */
2943 spin_lock(&workqueue_lock); 2978 spin_lock(&workqueue_lock);
2944 2979
2945 if (workqueue_freezing && wq->flags & WQ_FREEZEABLE) 2980 if (workqueue_freezing && wq->flags & WQ_FREEZABLE)
2946 for_each_cwq_cpu(cpu, wq) 2981 for_each_cwq_cpu(cpu, wq)
2947 get_cwq(cpu, wq)->max_active = 0; 2982 get_cwq(cpu, wq)->max_active = 0;
2948 2983
@@ -3054,7 +3089,7 @@ void workqueue_set_max_active(struct workqueue_struct *wq, int max_active)
3054 3089
3055 spin_lock_irq(&gcwq->lock); 3090 spin_lock_irq(&gcwq->lock);
3056 3091
3057 if (!(wq->flags & WQ_FREEZEABLE) || 3092 if (!(wq->flags & WQ_FREEZABLE) ||
3058 !(gcwq->flags & GCWQ_FREEZING)) 3093 !(gcwq->flags & GCWQ_FREEZING))
3059 get_cwq(gcwq->cpu, wq)->max_active = max_active; 3094 get_cwq(gcwq->cpu, wq)->max_active = max_active;
3060 3095
@@ -3304,7 +3339,7 @@ static int __cpuinit trustee_thread(void *__gcwq)
3304 * want to get it over with ASAP - spam rescuers, wake up as 3339 * want to get it over with ASAP - spam rescuers, wake up as
3305 * many idlers as necessary and create new ones till the 3340 * many idlers as necessary and create new ones till the
3306 * worklist is empty. Note that if the gcwq is frozen, there 3341 * worklist is empty. Note that if the gcwq is frozen, there
3307 * may be frozen works in freezeable cwqs. Don't declare 3342 * may be frozen works in freezable cwqs. Don't declare
3308 * completion while frozen. 3343 * completion while frozen.
3309 */ 3344 */
3310 while (gcwq->nr_workers != gcwq->nr_idle || 3345 while (gcwq->nr_workers != gcwq->nr_idle ||
@@ -3562,9 +3597,9 @@ EXPORT_SYMBOL_GPL(work_on_cpu);
3562/** 3597/**
3563 * freeze_workqueues_begin - begin freezing workqueues 3598 * freeze_workqueues_begin - begin freezing workqueues
3564 * 3599 *
3565 * Start freezing workqueues. After this function returns, all 3600 * Start freezing workqueues. After this function returns, all freezable
3566 * freezeable workqueues will queue new works to their frozen_works 3601 * workqueues will queue new works to their frozen_works list instead of
3567 * list instead of gcwq->worklist. 3602 * gcwq->worklist.
3568 * 3603 *
3569 * CONTEXT: 3604 * CONTEXT:
3570 * Grabs and releases workqueue_lock and gcwq->lock's. 3605 * Grabs and releases workqueue_lock and gcwq->lock's.
@@ -3590,7 +3625,7 @@ void freeze_workqueues_begin(void)
3590 list_for_each_entry(wq, &workqueues, list) { 3625 list_for_each_entry(wq, &workqueues, list) {
3591 struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq); 3626 struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq);
3592 3627
3593 if (cwq && wq->flags & WQ_FREEZEABLE) 3628 if (cwq && wq->flags & WQ_FREEZABLE)
3594 cwq->max_active = 0; 3629 cwq->max_active = 0;
3595 } 3630 }
3596 3631
@@ -3601,7 +3636,7 @@ void freeze_workqueues_begin(void)
3601} 3636}
3602 3637
3603/** 3638/**
3604 * freeze_workqueues_busy - are freezeable workqueues still busy? 3639 * freeze_workqueues_busy - are freezable workqueues still busy?
3605 * 3640 *
3606 * Check whether freezing is complete. This function must be called 3641 * Check whether freezing is complete. This function must be called
3607 * between freeze_workqueues_begin() and thaw_workqueues(). 3642 * between freeze_workqueues_begin() and thaw_workqueues().
@@ -3610,8 +3645,8 @@ void freeze_workqueues_begin(void)
3610 * Grabs and releases workqueue_lock. 3645 * Grabs and releases workqueue_lock.
3611 * 3646 *
3612 * RETURNS: 3647 * RETURNS:
3613 * %true if some freezeable workqueues are still busy. %false if 3648 * %true if some freezable workqueues are still busy. %false if freezing
3614 * freezing is complete. 3649 * is complete.
3615 */ 3650 */
3616bool freeze_workqueues_busy(void) 3651bool freeze_workqueues_busy(void)
3617{ 3652{
@@ -3631,7 +3666,7 @@ bool freeze_workqueues_busy(void)
3631 list_for_each_entry(wq, &workqueues, list) { 3666 list_for_each_entry(wq, &workqueues, list) {
3632 struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq); 3667 struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq);
3633 3668
3634 if (!cwq || !(wq->flags & WQ_FREEZEABLE)) 3669 if (!cwq || !(wq->flags & WQ_FREEZABLE))
3635 continue; 3670 continue;
3636 3671
3637 BUG_ON(cwq->nr_active < 0); 3672 BUG_ON(cwq->nr_active < 0);
@@ -3676,7 +3711,7 @@ void thaw_workqueues(void)
3676 list_for_each_entry(wq, &workqueues, list) { 3711 list_for_each_entry(wq, &workqueues, list) {
3677 struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq); 3712 struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq);
3678 3713
3679 if (!cwq || !(wq->flags & WQ_FREEZEABLE)) 3714 if (!cwq || !(wq->flags & WQ_FREEZABLE))
3680 continue; 3715 continue;
3681 3716
3682 /* restore max_active and repopulate worklist */ 3717 /* restore max_active and repopulate worklist */
@@ -3750,8 +3785,10 @@ static int __init init_workqueues(void)
3750 system_nrt_wq = alloc_workqueue("events_nrt", WQ_NON_REENTRANT, 0); 3785 system_nrt_wq = alloc_workqueue("events_nrt", WQ_NON_REENTRANT, 0);
3751 system_unbound_wq = alloc_workqueue("events_unbound", WQ_UNBOUND, 3786 system_unbound_wq = alloc_workqueue("events_unbound", WQ_UNBOUND,
3752 WQ_UNBOUND_MAX_ACTIVE); 3787 WQ_UNBOUND_MAX_ACTIVE);
3788 system_freezable_wq = alloc_workqueue("events_freezable",
3789 WQ_FREEZABLE, 0);
3753 BUG_ON(!system_wq || !system_long_wq || !system_nrt_wq || 3790 BUG_ON(!system_wq || !system_long_wq || !system_nrt_wq ||
3754 !system_unbound_wq); 3791 !system_unbound_wq || !system_freezable_wq);
3755 return 0; 3792 return 0;
3756} 3793}
3757early_initcall(init_workqueues); 3794early_initcall(init_workqueues);