History

workqueue: move global_cwq->cpu to worker_pool

Move gcwq->cpu to pool->cpu. This introduces a couple places where gcwq->pools[0].cpu is used. These will soon go away as gcwq is further reduced. This is part of an effort to remove global_cwq and make worker_pool the top level abstraction, which in turn will help implementing worker pools with user-specified attributes.

Tejun Heo committed 13 years ago

Commit ec22ca51 parent c9e7cf22 files · +22 −22Browse files

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

Unified · Split

kernel/workqueue.c+21−21
@@ -124,6 +124,7 @@ enum { · 123 unmodified lines
124124
125125 struct worker_pool {
126126 struct global_cwq *gcwq; /* I: the owning gcwq */
127+ unsigned int cpu; /* I: the associated cpu */
127128 int id; /* I: pool ID */
128129 unsigned int flags; /* X: flags */
129130
@@ -152,7 +153,6 @@ struct worker_pool { · 22 unmodified lines
152153 */
153154 struct global_cwq {
154155 spinlock_t lock; /* the gcwq lock */
155− unsigned int cpu; /* I: the associated cpu */
156156
157157 struct worker_pool pools[NR_STD_WORKER_POOLS];
158158 /* normal and highpri pools */
@@ -489,7 +489,7 @@ static struct worker_pool *worker_pool_by_id(int pool_id) · 330 unmodified lines
489489
490490 static atomic_t *get_pool_nr_running(struct worker_pool *pool)
491491 {
492− int cpu = pool->gcwq->cpu;
492+ int cpu = pool->cpu;
493493 int idx = std_worker_pool_pri(pool);
494494
495495 if (cpu != WORK_CPU_UNBOUND)
@@ -764,7 +764,7 @@ void wq_worker_waking_up(struct task_struct *task, unsigned int cpu) · 268 unmodified lines
764764 struct worker *worker = kthread_data(task);
765765
766766 if (!(worker->flags & WORKER_NOT_RUNNING)) {
767− WARN_ON_ONCE(worker->pool->gcwq->cpu != cpu);
767+ WARN_ON_ONCE(worker->pool->cpu != cpu);
768768 atomic_inc(get_pool_nr_running(worker->pool));
769769 }
770770 }
@@ -1278,7 +1278,7 @@ static void __queue_work(unsigned int cpu, struct workqueue_struct *wq, · 507 unmodified lines
12781278 }
12791279
12801280 /* gcwq determined, get cwq and queue */
1281− cwq = get_cwq(gcwq->cpu, wq);
1281+ cwq = get_cwq(gcwq->pools[0].cpu, wq);
12821282 trace_workqueue_queue_work(req_cpu, cwq, work);
12831283
12841284 if (WARN_ON(!list_empty(&work->entry))) {
@@ -1385,20 +1385,20 @@ static void __queue_delayed_work(int cpu, struct workqueue_struct *wq, · 100 unmodified lines
13851385
13861386 /*
13871387 * This stores cwq for the moment, for the timer_fn. Note that the
1388− * work's gcwq is preserved to allow reentrance detection for
1388+ * work's pool is preserved to allow reentrance detection for
13891389 * delayed works.
13901390 */
13911391 if (!(wq->flags & WQ_UNBOUND)) {
1392− struct global_cwq *gcwq = get_work_gcwq(work);
1392+ struct worker_pool *pool = get_work_pool(work);
13931393
13941394 /*
1395− * If we cannot get the last gcwq from @work directly,
1395+ * If we cannot get the last pool from @work directly,
13961396 * select the last CPU such that it avoids unnecessarily
13971397 * triggering non-reentrancy check in __queue_work().
13981398 */
13991399 lcpu = cpu;
1400− if (gcwq)
1401− lcpu = gcwq->cpu;
1400+ if (pool)
1401+ lcpu = pool->cpu;
14021402 if (lcpu == WORK_CPU_UNBOUND)
14031403 lcpu = raw_smp_processor_id();
14041404 } else {
@@ -1619,14 +1619,14 @@ __acquires(&gcwq->lock) · 214 unmodified lines
16191619 * against POOL_DISASSOCIATED.
16201620 */
16211621 if (!(pool->flags & POOL_DISASSOCIATED))
1622− set_cpus_allowed_ptr(task, get_cpu_mask(gcwq->cpu));
1622+ set_cpus_allowed_ptr(task, get_cpu_mask(pool->cpu));
16231623
16241624 spin_lock_irq(&gcwq->lock);
16251625 if (pool->flags & POOL_DISASSOCIATED)
16261626 return false;
1627− if (task_cpu(task) == gcwq->cpu &&
1627+ if (task_cpu(task) == pool->cpu &&
16281628 cpumask_equal(&current->cpus_allowed,
1629− get_cpu_mask(gcwq->cpu)))
1629+ get_cpu_mask(pool->cpu)))
16301630 return true;
16311631 spin_unlock_irq(&gcwq->lock);
16321632
@@ -1747,7 +1747,7 @@ static void rebind_workers(struct global_cwq *gcwq) · 114 unmodified lines
17471747 else
17481748 wq = system_wq;
17491749
1750− insert_work(get_cwq(gcwq->cpu, wq), rebind_work,
1750+ insert_work(get_cwq(pool->cpu, wq), rebind_work,
17511751 worker->scheduled.next,
17521752 work_color_to_flags(WORK_NO_COLOR));
17531753 }
@@ -1806,10 +1806,10 @@ static struct worker *create_worker(struct worker_pool *pool) · 52 unmodified lines
18061806 worker->pool = pool;
18071807 worker->id = id;
18081808
1809− if (gcwq->cpu != WORK_CPU_UNBOUND)
1809+ if (pool->cpu != WORK_CPU_UNBOUND)
18101810 worker->task = kthread_create_on_node(worker_thread,
1811− worker, cpu_to_node(gcwq->cpu),
1812− "kworker/%u:%d%s", gcwq->cpu, id, pri);
1811+ worker, cpu_to_node(pool->cpu),
1812+ "kworker/%u:%d%s", pool->cpu, id, pri);
18131813 else
18141814 worker->task = kthread_create(worker_thread, worker,
18151815 "kworker/u:%d%s", id, pri);
@@ -1829,7 +1829,7 @@ static struct worker *create_worker(struct worker_pool *pool) · 13 unmodified lines
18291829 * online, make sure every worker has %PF_THREAD_BOUND set.
18301830 */
18311831 if (!(pool->flags & POOL_DISASSOCIATED)) {
1832− kthread_bind(worker->task, gcwq->cpu);
1832+ kthread_bind(worker->task, pool->cpu);
18331833 } else {
18341834 worker->task->flags |= PF_THREAD_BOUND;
18351835 worker->flags |= WORKER_UNBOUND;
@@ -1936,7 +1936,7 @@ static bool send_mayday(struct work_struct *work) · 100 unmodified lines
19361936 return false;
19371937
19381938 /* mayday mayday mayday */
1939− cpu = cwq->pool->gcwq->cpu;
1939+ cpu = cwq->pool->cpu;
19401940 /* WORK_CPU_UNBOUND can't be set in cpumask, use cpu 0 instead */
19411941 if (cpu == WORK_CPU_UNBOUND)
19421942 cpu = 0;
@@ -2193,7 +2193,7 @@ __acquires(&gcwq->lock) · 250 unmodified lines
21932193 */
21942194 WARN_ON_ONCE(!(worker->flags & WORKER_UNBOUND) &&
21952195 !(pool->flags & POOL_DISASSOCIATED) &&
2196− raw_smp_processor_id() != gcwq->cpu);
2196+ raw_smp_processor_id() != pool->cpu);
21972197
21982198 /*
21992199 * A single work shouldn't be executed concurrently by
@@ -3553,7 +3553,7 @@ static void gcwq_unbind_fn(struct work_struct *work) · 1353 unmodified lines
35533553 struct hlist_node *pos;
35543554 int i;
35553555
3556− BUG_ON(gcwq->cpu != smp_processor_id());
3556+ BUG_ON(gcwq->pools[0].cpu != smp_processor_id());
35573557
35583558 gcwq_claim_assoc_and_lock(gcwq);
35593559
@@ -3860,10 +3860,10 @@ static int __init init_workqueues(void) · 300 unmodified lines
38603860 struct worker_pool *pool;
38613861
38623862 spin_lock_init(&gcwq->lock);
3863− gcwq->cpu = cpu;
38643863
38653864 for_each_worker_pool(pool, gcwq) {
38663865 pool->gcwq = gcwq;
3866+ pool->cpu = cpu;
38673867 pool->flags |= POOL_DISASSOCIATED;
38683868 INIT_LIST_HEAD(&pool->worklist);
38693869 INIT_LIST_HEAD(&pool->idle_list);