diff options
author | Tejun Heo <tj@kernel.org> | 2013-01-24 14:01:33 -0500 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2013-01-24 14:01:33 -0500 |
commit | 9daf9e678d18585433a4ad90ec51a448e5fd054c (patch) | |
tree | e21d85aa3280cabe420c8c8c992f59e11b4aab82 /kernel/workqueue.c | |
parent | 715b06b864c99a18cb8368dfb187da4f569788cd (diff) |
workqueue: add worker_pool->id
Add worker_pool->id which is allocated from worker_pool_idr. This
will be used to record the last associated worker_pool in work->data.
Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Diffstat (limited to 'kernel/workqueue.c')
-rw-r--r-- | kernel/workqueue.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 405282d30046..9c6ad974bb9e 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c | |||
@@ -124,6 +124,7 @@ enum { | |||
124 | 124 | ||
125 | struct worker_pool { | 125 | struct worker_pool { |
126 | struct global_cwq *gcwq; /* I: the owning gcwq */ | 126 | struct global_cwq *gcwq; /* I: the owning gcwq */ |
127 | int id; /* I: pool ID */ | ||
127 | unsigned int flags; /* X: flags */ | 128 | unsigned int flags; /* X: flags */ |
128 | 129 | ||
129 | struct list_head worklist; /* L: list of pending works */ | 130 | struct list_head worklist; /* L: list of pending works */ |
@@ -445,6 +446,10 @@ static atomic_t unbound_pool_nr_running[NR_STD_WORKER_POOLS] = { | |||
445 | [0 ... NR_STD_WORKER_POOLS - 1] = ATOMIC_INIT(0), /* always 0 */ | 446 | [0 ... NR_STD_WORKER_POOLS - 1] = ATOMIC_INIT(0), /* always 0 */ |
446 | }; | 447 | }; |
447 | 448 | ||
449 | /* idr of all pools */ | ||
450 | static DEFINE_MUTEX(worker_pool_idr_mutex); | ||
451 | static DEFINE_IDR(worker_pool_idr); | ||
452 | |||
448 | static int worker_thread(void *__worker); | 453 | static int worker_thread(void *__worker); |
449 | static unsigned int work_cpu(struct work_struct *work); | 454 | static unsigned int work_cpu(struct work_struct *work); |
450 | 455 | ||
@@ -461,6 +466,19 @@ static struct global_cwq *get_gcwq(unsigned int cpu) | |||
461 | return &unbound_global_cwq; | 466 | return &unbound_global_cwq; |
462 | } | 467 | } |
463 | 468 | ||
469 | /* allocate ID and assign it to @pool */ | ||
470 | static int worker_pool_assign_id(struct worker_pool *pool) | ||
471 | { | ||
472 | int ret; | ||
473 | |||
474 | mutex_lock(&worker_pool_idr_mutex); | ||
475 | idr_pre_get(&worker_pool_idr, GFP_KERNEL); | ||
476 | ret = idr_get_new(&worker_pool_idr, pool, &pool->id); | ||
477 | mutex_unlock(&worker_pool_idr_mutex); | ||
478 | |||
479 | return ret; | ||
480 | } | ||
481 | |||
464 | static atomic_t *get_pool_nr_running(struct worker_pool *pool) | 482 | static atomic_t *get_pool_nr_running(struct worker_pool *pool) |
465 | { | 483 | { |
466 | int cpu = pool->gcwq->cpu; | 484 | int cpu = pool->gcwq->cpu; |
@@ -3830,6 +3848,9 @@ static int __init init_workqueues(void) | |||
3830 | 3848 | ||
3831 | mutex_init(&pool->assoc_mutex); | 3849 | mutex_init(&pool->assoc_mutex); |
3832 | ida_init(&pool->worker_ida); | 3850 | ida_init(&pool->worker_ida); |
3851 | |||
3852 | /* alloc pool ID */ | ||
3853 | BUG_ON(worker_pool_assign_id(pool)); | ||
3833 | } | 3854 | } |
3834 | } | 3855 | } |
3835 | 3856 | ||