History

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq: workqueue: use zalloc_cpumask_var() for gcwq->mayday_mask workqueue: fix GCWQ_DISASSOCIATED initialization workqueue: Add a workqueue chapter to the tracepoint docbook workqueue: fix cwq->nr_active underflow workqueue: improve destroy_workqueue() debuggability workqueue: mark lock acquisition on worker_maybe_bind_and_lock() workqueue: annotate lock context change workqueue: free rescuer on destroy_workqueue

Linus Torvalds committed 16 years ago

Commit cd4d4fc2 parents 608307e 9c375473 files · +54 −22Browse files

Showing the changes to kernel/workqueue.c (1 of 3 files). Show all

Unified · Split

kernel/workqueue.c+38−15
@@ -90,7 +90,8 @@ enum { · 89 unmodified lines
9090 /*
9191 * Structure fields follow one of the following exclusion rules.
9292 *
93− * I: Set during initialization and read-only afterwards.
93+ * I: Modifiable by initialization/destruction paths and read-only for
94+ * everyone else.
9495 *
9596 * P: Preemption protected. Disabling preemption is enough and should
9697 * only be modified and accessed from the local cpu.
@@ -198,7 +199,7 @@ typedef cpumask_var_t mayday_mask_t; · 101 unmodified lines
198199 cpumask_test_and_set_cpu((cpu), (mask))
199200 #define mayday_clear_cpu(cpu, mask) cpumask_clear_cpu((cpu), (mask))
200201 #define for_each_mayday_cpu(cpu, mask) for_each_cpu((cpu), (mask))
201−#define alloc_mayday_mask(maskp, gfp) alloc_cpumask_var((maskp), (gfp))
202+#define alloc_mayday_mask(maskp, gfp) zalloc_cpumask_var((maskp), (gfp))
202203 #define free_mayday_mask(mask) free_cpumask_var((mask))
203204 #else
204205 typedef unsigned long mayday_mask_t;
@@ -943,10 +944,14 @@ static void __queue_work(unsigned int cpu, struct workqueue_struct *wq, · 738 unmodified lines
943944 struct global_cwq *gcwq;
944945 struct cpu_workqueue_struct *cwq;
945946 struct list_head *worklist;
947+ unsigned int work_flags;
946948 unsigned long flags;
947949
948950 debug_work_activate(work);
949951
952+ if (WARN_ON_ONCE(wq->flags & WQ_DYING))
953+ return;
954+
950955 /* determine gcwq to use */
951956 if (!(wq->flags & WQ_UNBOUND)) {
952957 struct global_cwq *last_gcwq;
@@ -989,14 +994,17 @@ static void __queue_work(unsigned int cpu, struct workqueue_struct *wq, · 36 unmodified lines
989994 BUG_ON(!list_empty(&work->entry));
990995
991996 cwq->nr_in_flight[cwq->work_color]++;
997+ work_flags = work_color_to_flags(cwq->work_color);
992998
993999 if (likely(cwq->nr_active < cwq->max_active)) {
9941000 cwq->nr_active++;
9951001 worklist = gcwq_determine_ins_pos(gcwq, cwq);
996− } else
1002+ } else {
1003+ work_flags |= WORK_STRUCT_DELAYED;
9971004 worklist = &cwq->delayed_works;
1005+ }
9981006
999− insert_work(cwq, work, worklist, work_color_to_flags(cwq->work_color));
1007+ insert_work(cwq, work, worklist, work_flags);
10001008
10011009 spin_unlock_irqrestore(&gcwq->lock, flags);
10021010 }
@@ -1215,6 +1223,7 @@ static void worker_leave_idle(struct worker *worker) · 212 unmodified lines
12151223 * bound), %false if offline.
12161224 */
12171225 static bool worker_maybe_bind_and_lock(struct worker *worker)
1226+__acquires(&gcwq->lock)
12181227 {
12191228 struct global_cwq *gcwq = worker->gcwq;
12201229 struct task_struct *task = worker->task;
@@ -1488,6 +1497,8 @@ static void gcwq_mayday_timeout(unsigned long __gcwq) · 267 unmodified lines
14881497 * otherwise.
14891498 */
14901499 static bool maybe_create_worker(struct global_cwq *gcwq)
1500+__releases(&gcwq->lock)
1501+__acquires(&gcwq->lock)
14911502 {
14921503 if (!need_to_create_worker(gcwq))
14931504 return false;
@@ -1662,6 +1673,7 @@ static void cwq_activate_first_delayed(struct cpu_workqueue_struct *cwq) · 168 unmodified lines
16621673 struct list_head *pos = gcwq_determine_ins_pos(cwq->gcwq, cwq);
16631674
16641675 move_linked_works(work, pos, NULL);
1676+ __clear_bit(WORK_STRUCT_DELAYED_BIT, work_data_bits(work));
16651677 cwq->nr_active++;
16661678 }
16671679
@@ -1669,6 +1681,7 @@ static void cwq_activate_first_delayed(struct cpu_workqueue_struct *cwq) · 1 unmodified line
16691681 * cwq_dec_nr_in_flight - decrement cwq's nr_in_flight
16701682 * @cwq: cwq of interest
16711683 * @color: color of work which left the queue
1684+ * @delayed: for a delayed work
16721685 *
16731686 * A work either has completed or is removed from pending queue,
16741687 * decrement nr_in_flight of its cwq and handle workqueue flushing.
@@ -1676,19 +1689,22 @@ static void cwq_activate_first_delayed(struct cpu_workqueue_struct *cwq) · 1 unmodified line
16761689 * CONTEXT:
16771690 * spin_lock_irq(gcwq->lock).
16781691 */
1679−static void cwq_dec_nr_in_flight(struct cpu_workqueue_struct *cwq, int color)
1692+static void cwq_dec_nr_in_flight(struct cpu_workqueue_struct *cwq, int color,
1693+ bool delayed)
16801694 {
16811695 /* ignore uncolored works */
16821696 if (color == WORK_NO_COLOR)
16831697 return;
16841698
16851699 cwq->nr_in_flight[color]--;
1686− cwq->nr_active--;
16871700
1688− if (!list_empty(&cwq->delayed_works)) {
1689− /* one down, submit a delayed one */
1690− if (cwq->nr_active < cwq->max_active)
1691− cwq_activate_first_delayed(cwq);
1701+ if (!delayed) {
1702+ cwq->nr_active--;
1703+ if (!list_empty(&cwq->delayed_works)) {
1704+ /* one down, submit a delayed one */
1705+ if (cwq->nr_active < cwq->max_active)
1706+ cwq_activate_first_delayed(cwq);
1707+ }
16921708 }
16931709
16941710 /* is flush in progress and are we at the flushing tip? */
@@ -1725,6 +1741,8 @@ static void cwq_dec_nr_in_flight(struct cpu_workqueue_struct *cwq, int color) · 30 unmodified lines
17251741 * spin_lock_irq(gcwq->lock) which is released and regrabbed.
17261742 */
17271743 static void process_one_work(struct worker *worker, struct work_struct *work)
1744+__releases(&gcwq->lock)
1745+__acquires(&gcwq->lock)
17281746 {
17291747 struct cpu_workqueue_struct *cwq = get_work_cwq(work);
17301748 struct global_cwq *gcwq = cwq->gcwq;
@@ -1823,7 +1841,7 @@ static void process_one_work(struct worker *worker, struct work_struct *work) · 92 unmodified lines
18231841 hlist_del_init(&worker->hentry);
18241842 worker->current_work = NULL;
18251843 worker->current_cwq = NULL;
1826− cwq_dec_nr_in_flight(cwq, work_color);
1844+ cwq_dec_nr_in_flight(cwq, work_color, false);
18271845 }
18281846
18291847 /**
@@ -2388,7 +2406,8 @@ static int try_to_grab_pending(struct work_struct *work) · 558 unmodified lines
23882406 debug_work_deactivate(work);
23892407 list_del_init(&work->entry);
23902408 cwq_dec_nr_in_flight(get_work_cwq(work),
2391− get_work_color(work));
2409+ get_work_color(work),
2410+ *work_data_bits(work) & WORK_STRUCT_DELAYED);
23922411 ret = 1;
23932412 }
23942413 }
@@ -2791,7 +2810,6 @@ struct workqueue_struct *__alloc_workqueue_key(const char *name, · 396 unmodified lines
27912810 if (IS_ERR(rescuer->task))
27922811 goto err;
27932812
2794− wq->rescuer = rescuer;
27952813 rescuer->task->flags |= PF_THREAD_BOUND;
27962814 wake_up_process(rescuer->task);
27972815 }
@@ -2833,6 +2851,7 @@ void destroy_workqueue(struct workqueue_struct *wq) · 35 unmodified lines
28332851 {
28342852 unsigned int cpu;
28352853
2854+ wq->flags |= WQ_DYING;
28362855 flush_workqueue(wq);
28372856
28382857 /*
@@ -2857,6 +2876,7 @@ void destroy_workqueue(struct workqueue_struct *wq) · 18 unmodified lines
28572876 if (wq->flags & WQ_RESCUER) {
28582877 kthread_stop(wq->rescuer->task);
28592878 free_mayday_mask(wq->mayday_mask);
2879+ kfree(wq->rescuer);
28602880 }
28612881
28622882 free_cwqs(wq);
@@ -3239,6 +3259,8 @@ static int __cpuinit trustee_thread(void *__gcwq) · 376 unmodified lines
32393259 * multiple times. To be used by cpu_callback.
32403260 */
32413261 static void __cpuinit wait_trustee_state(struct global_cwq *gcwq, int state)
3262+__releases(&gcwq->lock)
3263+__acquires(&gcwq->lock)
32423264 {
32433265 if (!(gcwq->trustee_state == state ||
32443266 gcwq->trustee_state == TRUSTEE_DONE)) {
@@ -3545,8 +3567,7 @@ static int __init init_workqueues(void) · 300 unmodified lines
35453567 spin_lock_init(&gcwq->lock);
35463568 INIT_LIST_HEAD(&gcwq->worklist);
35473569 gcwq->cpu = cpu;
3548− if (cpu == WORK_CPU_UNBOUND)
3549− gcwq->flags |= GCWQ_DISASSOCIATED;
3570+ gcwq->flags |= GCWQ_DISASSOCIATED;
35503571
35513572 INIT_LIST_HEAD(&gcwq->idle_list);
35523573 for (i = 0; i < BUSY_WORKER_HASH_SIZE; i++)
@@ -3570,6 +3591,8 @@ static int __init init_workqueues(void) · 17 unmodified lines
35703591 struct global_cwq *gcwq = get_gcwq(cpu);
35713592 struct worker *worker;
35723593
3594+ if (cpu != WORK_CPU_UNBOUND)
3595+ gcwq->flags &= ~GCWQ_DISASSOCIATED;
35733596 worker = create_worker(gcwq, true);
35743597 BUG_ON(!worker);
35753598 spin_lock_irq(&gcwq->lock);