From: Joonsoo Kim <iamjoonsoo.kim@lge.com>
To: Tejun Heo <tj@kernel.org>
Cc: linux-kernel@vger.kernel.org, Lai Jiangshan <laijs@cn.fujitsu.com>
Subject: Re: [PATCH 15/17] workqueue: remove global_cwq
Date: Tue, 22 Jan 2013 15:50:39 +0900 [thread overview]
Message-ID: <20130122065039.GA4417@lge.com> (raw)
In-Reply-To: <1358386969-945-16-git-send-email-tj@kernel.org>
On Wed, Jan 16, 2013 at 05:42:47PM -0800, Tejun Heo wrote:
> global_cwq is now nothing but a container for per-pcu standard
s/per-pcu/per-cpu/
> worker_pools. Declare the worker pools directly as
> cpu/unbound_std_worker_pools[] and remove global_cwq.
>
> * 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.
>
> Signed-off-by: Tejun Heo <tj@kernel.org>
> ---
> kernel/workqueue.c | 47 +++++++++++++++++------------------------------
> 1 file changed, 17 insertions(+), 30 deletions(-)
>
> diff --git a/kernel/workqueue.c b/kernel/workqueue.c
> index d37db53..4bddf52 100644
> --- a/kernel/workqueue.c
> +++ b/kernel/workqueue.c
> @@ -120,7 +120,6 @@ enum {
> * W: workqueue_lock protected.
> */
>
> -struct global_cwq;
> struct worker_pool;
>
> /*
> @@ -174,16 +173,6 @@ struct worker_pool {
> };
>
> /*
> - * Global per-cpu workqueue. There's one and only one for each cpu
> - * and all works are queued and processed here regardless of their
> - * target workqueues.
> - */
> -struct global_cwq {
> - struct worker_pool pools[NR_STD_WORKER_POOLS];
> - /* normal and highpri pools */
> -} ____cacheline_aligned_in_smp;
> -
> -/*
> * The per-CPU workqueue. The lower WORK_STRUCT_FLAG_BITS of
> * work_struct->data are used for flags and thus cwqs need to be
> * aligned at two's power of the number of flag bits.
> @@ -277,8 +266,8 @@ EXPORT_SYMBOL_GPL(system_freezable_wq);
> #include <trace/events/workqueue.h>
>
> #define for_each_std_worker_pool(pool, cpu) \
> - for ((pool) = &get_gcwq((cpu))->pools[0]; \
> - (pool) < &get_gcwq((cpu))->pools[NR_STD_WORKER_POOLS]; (pool)++)
> + for ((pool) = &std_worker_pools(cpu)[0]; \
> + (pool) < &std_worker_pools(cpu)[NR_STD_WORKER_POOLS]; (pool)++)
>
> #define for_each_busy_worker(worker, i, pos, pool) \
> hash_for_each(pool->busy_hash, i, pos, worker, hentry)
> @@ -454,19 +443,19 @@ static LIST_HEAD(workqueues);
> static bool workqueue_freezing; /* W: have wqs started freezing? */
>
> /*
> - * The almighty global cpu workqueues. nr_running is the only field
> - * which is expected to be used frequently by other cpus via
> - * try_to_wake_up(). Put it in a separate cacheline.
> + * The CPU standard worker pools. nr_running is the only field which is
> + * expected to be used frequently by other cpus via try_to_wake_up(). Put
> + * it in a separate cacheline.
> */
> -static DEFINE_PER_CPU(struct global_cwq, global_cwq);
> +static DEFINE_PER_CPU_ALIGNED(struct worker_pool [NR_STD_WORKER_POOLS],
> + cpu_std_worker_pools);
> static DEFINE_PER_CPU_SHARED_ALIGNED(atomic_t, pool_nr_running[NR_STD_WORKER_POOLS]);
Why worker_pool is defined as DEFINE_PER_CPU_ALIGNED?
And this makes only worker_pool[0] aligned with cacheline.
worker_pool[1] is not aligned with cacheline.
Now, we have a spin_lock for each instance of worker_pool and
each one is independent instance.
So, IMHO, it is better to align worker_pool[1] with cacheline.
Thanks.
> /*
> - * Global cpu workqueue and nr_running counter for unbound gcwq. The pools
> - * for online CPUs have POOL_DISASSOCIATED set, and all their workers have
> - * WORKER_UNBOUND set.
> + * Standard worker pools and nr_running counter for unbound CPU. The pools
> + * have POOL_DISASSOCIATED set, and all workers have WORKER_UNBOUND set.
> */
> -static struct global_cwq unbound_global_cwq;
> +static struct worker_pool unbound_std_worker_pools[NR_STD_WORKER_POOLS];
> static atomic_t unbound_pool_nr_running[NR_STD_WORKER_POOLS] = {
> [0 ... NR_STD_WORKER_POOLS - 1] = ATOMIC_INIT(0), /* always 0 */
> };
> @@ -477,17 +466,17 @@ static DEFINE_IDR(worker_pool_idr);
>
> static int worker_thread(void *__worker);
>
> -static struct global_cwq *get_gcwq(unsigned int cpu)
> +static struct worker_pool *std_worker_pools(int cpu)
> {
> if (cpu != WORK_CPU_UNBOUND)
> - return &per_cpu(global_cwq, cpu);
> + return per_cpu(cpu_std_worker_pools, cpu);
> else
> - return &unbound_global_cwq;
> + return unbound_std_worker_pools;
> }
>
> static int std_worker_pool_pri(struct worker_pool *pool)
> {
> - return pool - get_gcwq(pool->cpu)->pools;
> + return pool - std_worker_pools(pool->cpu);
> }
>
> /* allocate ID and assign it to @pool */
> @@ -514,9 +503,9 @@ static struct worker_pool *worker_pool_by_id(int pool_id)
>
> static struct worker_pool *get_std_worker_pool(int cpu, bool highpri)
> {
> - struct global_cwq *gcwq = get_gcwq(cpu);
> + struct worker_pool *pools = std_worker_pools(cpu);
>
> - return &gcwq->pools[highpri];
> + return &pools[highpri];
> }
>
> static atomic_t *get_pool_nr_running(struct worker_pool *pool)
> @@ -3279,11 +3268,9 @@ struct workqueue_struct *__alloc_workqueue_key(const char *fmt,
>
> for_each_cwq_cpu(cpu, wq) {
> struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq);
> - struct global_cwq *gcwq = get_gcwq(cpu);
> - int pool_idx = (bool)(flags & WQ_HIGHPRI);
>
> BUG_ON((unsigned long)cwq & WORK_STRUCT_FLAG_MASK);
> - cwq->pool = &gcwq->pools[pool_idx];
> + cwq->pool = get_std_worker_pool(cpu, flags & WQ_HIGHPRI);
> cwq->wq = wq;
> cwq->flush_color = -1;
> cwq->max_active = max_active;
> --
> 1.8.0.2
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
next prev parent reply other threads:[~2013-01-22 6:50 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-17 1:42 [PATCHSET] workqueue: remove gcwq and make worker_pool the only backend abstraction Tejun Heo
2013-01-17 1:42 ` [PATCH 01/17] workqueue: unexport work_cpu() Tejun Heo
2013-01-17 1:42 ` [PATCH 02/17] workqueue: use std_ prefix for the standard per-cpu pools Tejun Heo
2013-01-17 1:42 ` [PATCH 03/17] workqueue: make GCWQ_DISASSOCIATED a pool flag Tejun Heo
2013-01-17 1:42 ` [PATCH 04/17] workqueue: make GCWQ_FREEZING " Tejun Heo
2013-01-17 1:42 ` [PATCH 05/17] workqueue: introduce WORK_OFFQ_CPU_NONE Tejun Heo
2013-01-17 1:42 ` [PATCH 06/17] workqueue: add worker_pool->id Tejun Heo
2013-01-17 1:42 ` [PATCH 07/17] workqueue: record pool ID instead of CPU in work->data when off-queue Tejun Heo
2013-01-17 1:42 ` [PATCH 08/17] workqueue: move busy_hash from global_cwq to worker_pool Tejun Heo
2013-01-17 1:42 ` [PATCH 09/17] workqueue: move global_cwq->cpu " Tejun Heo
2013-01-17 1:42 ` [PATCH 10/17] workqueue: move global_cwq->lock " Tejun Heo
2013-01-17 1:42 ` [PATCH 11/17] workqueue: make hotplug processing per-pool Tejun Heo
2013-01-17 1:42 ` [PATCH 12/17] workqueue: make freezing/thawing per-pool Tejun Heo
2013-01-17 1:42 ` [PATCH 13/17] workqueue: replace for_each_worker_pool() with for_each_std_worker_pool() Tejun Heo
2013-01-17 1:42 ` [PATCH 14/17] workqueue: remove worker_pool->gcwq Tejun Heo
2013-01-17 1:42 ` [PATCH 15/17] workqueue: remove global_cwq Tejun Heo
2013-01-22 6:50 ` Joonsoo Kim [this message]
2013-01-23 1:09 ` Tejun Heo
2013-01-23 18:09 ` [PATCH v2 " Tejun Heo
2013-01-24 9:29 ` Joonsoo Kim
2013-01-24 18:44 ` Tejun Heo
2013-01-17 1:42 ` [PATCH 16/17] workqueue: rename nr_running variables Tejun Heo
2013-01-17 1:42 ` [PATCH 17/17] workqueue: post global_cwq removal cleanups Tejun Heo
2013-01-17 1:48 ` [PATCHSET] workqueue: remove gcwq and make worker_pool the only backend abstraction Tejun Heo
2013-01-17 3:25 ` Wanlong Gao
2013-01-17 19:11 ` Tejun Heo
2013-01-22 5:37 ` Joonsoo Kim
2013-01-23 1:07 ` Tejun Heo
2013-01-24 13:36 ` Lai Jiangshan
2013-01-24 18:51 ` Tejun Heo
2013-01-24 19:03 ` Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130122065039.GA4417@lge.com \
--to=iamjoonsoo.kim@lge.com \
--cc=laijs@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox