aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/workqueue.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-01-24 14:01:34 -0500
committerTejun Heo <tj@kernel.org>2013-01-24 14:01:34 -0500
commita60dc39c016a65bfdbd05c43b3707962d5ed04c7 (patch)
treec16982dba52f5f83dc09817c37e86ec201f84c03 /kernel/workqueue.c
parent4e8f0a609677a25f504527e50981df146c5b3d08 (diff)
workqueue: remove global_cwq
global_cwq is now nothing but a container for per-cpu standard worker_pools. Declare the worker pools directly as cpu/unbound_std_worker_pools[] and remove global_cwq. * ____cacheline_aligned_in_smp moved from global_cwq to worker_pool. This probably would have made sense even before this change as we want each pool to be aligned. * get_gcwq() is replaced with std_worker_pools() which returns the pointer to the standard pool array for a given CPU. * __alloc_workqueue_key() updated to use get_std_worker_pool() instead of open-coding pool determination. 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. v2: Joonsoo pointed out that it'd better to align struct worker_pool rather than the array so that every pool is aligned. Signed-off-by: Tejun Heo <tj@kernel.org> Reviewed-by: Lai Jiangshan <laijs@cn.fujitsu.com> Cc: Joonsoo Kim <js1304@gmail.com>
Diffstat (limited to 'kernel/workqueue.c')
-rw-r--r--kernel/workqueue.c46
1 files changed, 17 insertions, 29 deletions
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 475a447aa6d8..224580f7459c 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -144,16 +144,6 @@ struct worker_pool {
144 144
145 struct mutex assoc_mutex; /* protect POOL_DISASSOCIATED */ 145 struct mutex assoc_mutex; /* protect POOL_DISASSOCIATED */
146 struct ida worker_ida; /* L: for worker IDs */ 146 struct ida worker_ida; /* L: for worker IDs */
147};
148
149/*
150 * Global per-cpu workqueue. There's one and only one for each cpu
151 * and all works are queued and processed here regardless of their
152 * target workqueues.
153 */
154struct global_cwq {
155 struct worker_pool pools[NR_STD_WORKER_POOLS];
156 /* normal and highpri pools */
157} ____cacheline_aligned_in_smp; 147} ____cacheline_aligned_in_smp;
158 148
159/* 149/*
@@ -250,8 +240,8 @@ EXPORT_SYMBOL_GPL(system_freezable_wq);
250#include <trace/events/workqueue.h> 240#include <trace/events/workqueue.h>
251 241
252#define for_each_std_worker_pool(pool, cpu) \ 242#define for_each_std_worker_pool(pool, cpu) \
253 for ((pool) = &get_gcwq((cpu))->pools[0]; \ 243 for ((pool) = &std_worker_pools(cpu)[0]; \
254 (pool) < &get_gcwq((cpu))->pools[NR_STD_WORKER_POOLS]; (pool)++) 244 (pool) < &std_worker_pools(cpu)[NR_STD_WORKER_POOLS]; (pool)++)
255 245
256#define for_each_busy_worker(worker, i, pos, pool) \ 246#define for_each_busy_worker(worker, i, pos, pool) \
257 hash_for_each(pool->busy_hash, i, pos, worker, hentry) 247 hash_for_each(pool->busy_hash, i, pos, worker, hentry)
@@ -427,19 +417,19 @@ static LIST_HEAD(workqueues);
427static bool workqueue_freezing; /* W: have wqs started freezing? */ 417static bool workqueue_freezing; /* W: have wqs started freezing? */
428 418
429/* 419/*
430 * The almighty global cpu workqueues. nr_running is the only field 420 * The CPU standard worker pools. nr_running is the only field which is
431 * which is expected to be used frequently by other cpus via 421 * expected to be used frequently by other cpus via try_to_wake_up(). Put
432 * try_to_wake_up(). Put it in a separate cacheline. 422 * it in a separate cacheline.
433 */ 423 */
434static DEFINE_PER_CPU(struct global_cwq, global_cwq); 424static DEFINE_PER_CPU(struct worker_pool [NR_STD_WORKER_POOLS],
425 cpu_std_worker_pools);
435static DEFINE_PER_CPU_SHARED_ALIGNED(atomic_t, pool_nr_running[NR_STD_WORKER_POOLS]); 426static DEFINE_PER_CPU_SHARED_ALIGNED(atomic_t, pool_nr_running[NR_STD_WORKER_POOLS]);
436 427
437/* 428/*
438 * Global cpu workqueue and nr_running counter for unbound gcwq. The pools 429 * Standard worker pools and nr_running counter for unbound CPU. The pools
439 * for online CPUs have POOL_DISASSOCIATED set, and all their workers have 430 * have POOL_DISASSOCIATED set, and all workers have WORKER_UNBOUND set.
440 * WORKER_UNBOUND set.
441 */ 431 */
442static struct global_cwq unbound_global_cwq; 432static struct worker_pool unbound_std_worker_pools[NR_STD_WORKER_POOLS];
443static atomic_t unbound_pool_nr_running[NR_STD_WORKER_POOLS] = { 433static atomic_t unbound_pool_nr_running[NR_STD_WORKER_POOLS] = {
444 [0 ... NR_STD_WORKER_POOLS - 1] = ATOMIC_INIT(0), /* always 0 */ 434 [0 ... NR_STD_WORKER_POOLS - 1] = ATOMIC_INIT(0), /* always 0 */
445}; 435};
@@ -450,17 +440,17 @@ static DEFINE_IDR(worker_pool_idr);
450 440
451static int worker_thread(void *__worker); 441static int worker_thread(void *__worker);
452 442
453static struct global_cwq *get_gcwq(unsigned int cpu) 443static struct worker_pool *std_worker_pools(int cpu)
454{ 444{
455 if (cpu != WORK_CPU_UNBOUND) 445 if (cpu != WORK_CPU_UNBOUND)
456 return &per_cpu(global_cwq, cpu); 446 return per_cpu(cpu_std_worker_pools, cpu);
457 else 447 else
458 return &unbound_global_cwq; 448 return unbound_std_worker_pools;
459} 449}
460 450
461static int std_worker_pool_pri(struct worker_pool *pool) 451static int std_worker_pool_pri(struct worker_pool *pool)
462{ 452{
463 return pool - get_gcwq(pool->cpu)->pools; 453 return pool - std_worker_pools(pool->cpu);
464} 454}
465 455
466/* allocate ID and assign it to @pool */ 456/* allocate ID and assign it to @pool */
@@ -487,9 +477,9 @@ static struct worker_pool *worker_pool_by_id(int pool_id)
487 477
488static struct worker_pool *get_std_worker_pool(int cpu, bool highpri) 478static struct worker_pool *get_std_worker_pool(int cpu, bool highpri)
489{ 479{
490 struct global_cwq *gcwq = get_gcwq(cpu); 480 struct worker_pool *pools = std_worker_pools(cpu);
491 481
492 return &gcwq->pools[highpri]; 482 return &pools[highpri];
493} 483}
494 484
495static atomic_t *get_pool_nr_running(struct worker_pool *pool) 485static atomic_t *get_pool_nr_running(struct worker_pool *pool)
@@ -3269,11 +3259,9 @@ struct workqueue_struct *__alloc_workqueue_key(const char *fmt,
3269 3259
3270 for_each_cwq_cpu(cpu, wq) { 3260 for_each_cwq_cpu(cpu, wq) {
3271 struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq); 3261 struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq);
3272 struct global_cwq *gcwq = get_gcwq(cpu);
3273 int pool_idx = (bool)(flags & WQ_HIGHPRI);
3274 3262
3275 BUG_ON((unsigned long)cwq & WORK_STRUCT_FLAG_MASK); 3263 BUG_ON((unsigned long)cwq & WORK_STRUCT_FLAG_MASK);
3276 cwq->pool = &gcwq->pools[pool_idx]; 3264 cwq->pool = get_std_worker_pool(cpu, flags & WQ_HIGHPRI);
3277 cwq->wq = wq; 3265 cwq->wq = wq;
3278 cwq->flush_color = -1; 3266 cwq->flush_color = -1;
3279 cwq->max_active = max_active; 3267 cwq->max_active = max_active;