mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: laijs@cn.fujitsu.com
Cc: axboe@kernel.dk, jack@suse.cz, fengguang.wu@intel.com,
	jmoyer@redhat.com, zab@redhat.com, linux-kernel@vger.kernel.org,
	herbert@gondor.hengli.com.au, davem@davemloft.net,
	linux-crypto@vger.kernel.org, Tejun Heo <tj@kernel.org>
Subject: [PATCH 08/10] workqueue: break init_and_link_pwq() into two functions and introduce alloc_unbound_pwq()
Date: Tue, 19 Mar 2013 17:00:27 -0700	[thread overview]
Message-ID: <1363737629-16745-9-git-send-email-tj@kernel.org> (raw)
In-Reply-To: <1363737629-16745-1-git-send-email-tj@kernel.org>

Break init_and_link_pwq() into init_pwq() and link_pwq() and move
unbound-workqueue specific handling into apply_workqueue_attrs().
Also, factor out unbound pool and pool_workqueue allocation into
alloc_unbound_pwq().

This reorganization is to prepare for NUMA affinity and doesn't
introduce any functional changes.

Signed-off-by: Tejun Heo <tj@kernel.org>
---
 kernel/workqueue.c | 75 +++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 52 insertions(+), 23 deletions(-)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 3f820a5..bbbfc92 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -3647,13 +3647,10 @@ static void pwq_adjust_max_active(struct pool_workqueue *pwq)
 	spin_unlock(&pwq->pool->lock);
 }
 
-static void init_and_link_pwq(struct pool_workqueue *pwq,
-			      struct workqueue_struct *wq,
-			      struct worker_pool *pool,
-			      struct pool_workqueue **p_last_pwq)
+/* initialize newly zalloced @pwq which is associated with @wq and @pool */
+static void init_pwq(struct pool_workqueue *pwq, struct workqueue_struct *wq,
+		     struct worker_pool *pool)
 {
-	int node;
-
 	BUG_ON((unsigned long)pwq & WORK_STRUCT_FLAG_MASK);
 
 	pwq->pool = pool;
@@ -3663,9 +3660,16 @@ static void init_and_link_pwq(struct pool_workqueue *pwq,
 	INIT_LIST_HEAD(&pwq->delayed_works);
 	INIT_LIST_HEAD(&pwq->mayday_node);
 	INIT_WORK(&pwq->unbound_release_work, pwq_unbound_release_workfn);
+}
 
-	mutex_lock(&wq->flush_mutex);
-	spin_lock_irq(&pwq_lock);
+/* sync @pwq with the current state of its associated wq and link it */
+static void link_pwq(struct pool_workqueue *pwq,
+		     struct pool_workqueue **p_last_pwq)
+{
+	struct workqueue_struct *wq = pwq->wq;
+
+	lockdep_assert_held(&wq->flush_mutex);
+	lockdep_assert_held(&pwq_lock);
 
 	/*
 	 * Set the matching work_color.  This is synchronized with
@@ -3680,15 +3684,27 @@ static void init_and_link_pwq(struct pool_workqueue *pwq,
 
 	/* link in @pwq */
 	list_add_rcu(&pwq->pwqs_node, &wq->pwqs);
+}
 
-	if (wq->flags & WQ_UNBOUND) {
-		copy_workqueue_attrs(wq->unbound_attrs, pool->attrs);
-		for_each_node(node)
-			rcu_assign_pointer(wq->numa_pwq_tbl[node], pwq);
+/* obtain a pool matching @attr and create a pwq associating the pool and @wq */
+static struct pool_workqueue *alloc_unbound_pwq(struct workqueue_struct *wq,
+					const struct workqueue_attrs *attrs)
+{
+	struct worker_pool *pool;
+	struct pool_workqueue *pwq;
+
+	pool = get_unbound_pool(attrs);
+	if (!pool)
+		return NULL;
+
+	pwq = kmem_cache_zalloc(pwq_cache, GFP_KERNEL);
+	if (!pwq) {
+		put_unbound_pool(pool);
+		return NULL;
 	}
 
-	spin_unlock_irq(&pwq_lock);
-	mutex_unlock(&wq->flush_mutex);
+	init_pwq(pwq, wq, pool);
+	return pwq;
 }
 
 /**
@@ -3709,7 +3725,7 @@ int apply_workqueue_attrs(struct workqueue_struct *wq,
 			  const struct workqueue_attrs *attrs)
 {
 	struct pool_workqueue *pwq, *last_pwq;
-	struct worker_pool *pool;
+	int node;
 
 	/* only unbound workqueues can change attributes */
 	if (WARN_ON(!(wq->flags & WQ_UNBOUND)))
@@ -3719,17 +3735,22 @@ int apply_workqueue_attrs(struct workqueue_struct *wq,
 	if (WARN_ON((wq->flags & __WQ_ORDERED) && !list_empty(&wq->pwqs)))
 		return -EINVAL;
 
-	pwq = kmem_cache_zalloc(pwq_cache, GFP_KERNEL);
+	pwq = alloc_unbound_pwq(wq, attrs);
 	if (!pwq)
 		return -ENOMEM;
 
-	pool = get_unbound_pool(attrs);
-	if (!pool) {
-		kmem_cache_free(pwq_cache, pwq);
-		return -ENOMEM;
-	}
+	mutex_lock(&wq->flush_mutex);
+	spin_lock_irq(&pwq_lock);
+
+	link_pwq(pwq, &last_pwq);
+
+	copy_workqueue_attrs(wq->unbound_attrs, pwq->pool->attrs);
+	for_each_node(node)
+		rcu_assign_pointer(wq->numa_pwq_tbl[node], pwq);
+
+	spin_unlock_irq(&pwq_lock);
+	mutex_unlock(&wq->flush_mutex);
 
-	init_and_link_pwq(pwq, wq, pool, &last_pwq);
 	if (last_pwq) {
 		spin_lock_irq(&last_pwq->pool->lock);
 		put_pwq(last_pwq);
@@ -3755,7 +3776,15 @@ static int alloc_and_link_pwqs(struct workqueue_struct *wq)
 			struct worker_pool *cpu_pools =
 				per_cpu(cpu_worker_pools, cpu);
 
-			init_and_link_pwq(pwq, wq, &cpu_pools[highpri], NULL);
+			init_pwq(pwq, wq, &cpu_pools[highpri]);
+
+			mutex_lock(&wq->flush_mutex);
+			spin_lock_irq(&pwq_lock);
+
+			link_pwq(pwq, NULL);
+
+			spin_unlock_irq(&pwq_lock);
+			mutex_unlock(&wq->flush_mutex);
 		}
 		return 0;
 	} else {
-- 
1.8.1.4


  parent reply	other threads:[~2013-03-20  0:01 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-20  0:00 [PATCHSET wq/for-3.10] workqueue: NUMA affinity for unbound workqueues Tejun Heo
2013-03-20  0:00 ` [PATCH 01/10] workqueue: add wq_numa_tbl_len and wq_numa_possible_cpumask[] Tejun Heo
2013-03-20 14:08   ` JoonSoo Kim
2013-03-20 14:48     ` Tejun Heo
2013-03-20 15:43   ` Lai Jiangshan
2013-03-20 15:48     ` Tejun Heo
2013-03-20 16:43       ` Lai Jiangshan
2013-03-20  0:00 ` [PATCH 02/10] workqueue: drop 'H' from kworker names of unbound worker pools Tejun Heo
2013-03-20  0:00 ` [PATCH 03/10] workqueue: determine NUMA node of workers accourding to the allowed cpumask Tejun Heo
2013-03-20  0:00 ` [PATCH 04/10] workqueue: add workqueue->unbound_attrs Tejun Heo
2013-03-20  0:00 ` [PATCH 05/10] workqueue: make workqueue->name[] fixed len Tejun Heo
2013-03-20  0:00 ` [PATCH 06/10] workqueue: move hot fields of workqueue_struct to the end Tejun Heo
2013-03-20  0:00 ` [PATCH 07/10] workqueue: map an unbound workqueues to multiple per-node pool_workqueues Tejun Heo
2013-03-20  0:00 ` Tejun Heo [this message]
2013-03-20 15:52   ` [PATCH 08/10] workqueue: break init_and_link_pwq() into two functions and introduce alloc_unbound_pwq() Lai Jiangshan
2013-03-20 16:04     ` Tejun Heo
2013-03-20  0:00 ` [PATCH 09/10] workqueue: implement NUMA affinity for unbound workqueues Tejun Heo
2013-03-20 15:03   ` Lai Jiangshan
2013-03-20 15:05     ` Tejun Heo
2013-03-20 15:26       ` Lai Jiangshan
2013-03-20 15:32         ` Tejun Heo
2013-03-20 17:08   ` [PATCH v2 " Tejun Heo
2013-03-20 18:54     ` [PATCH v2 UPDATED " Tejun Heo
2013-03-20  0:00 ` [PATCH 10/10] workqueue: update sysfs interface to reflect NUMA awareness and a kernel param to disable NUMA affinity Tejun Heo
2013-03-20 12:14 ` [PATCHSET wq/for-3.10] workqueue: NUMA affinity for unbound workqueues Lai Jiangshan
2013-03-20 17:08 ` [PATCH 11/10] workqueue: use NUMA-aware allocation for pool_workqueues workqueues Tejun Heo
2013-03-20 18:57 ` [PATCHSET wq/for-3.10] workqueue: NUMA affinity for unbound workqueues Tejun Heo
2013-03-24 16:04   ` Lai Jiangshan
2013-03-24 18:55     ` Tejun Heo
2013-03-25 19:15       ` Tejun Heo
2013-03-25 20:48         ` 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=1363737629-16745-9-git-send-email-tj@kernel.org \
    --to=tj@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=davem@davemloft.net \
    --cc=fengguang.wu@intel.com \
    --cc=herbert@gondor.hengli.com.au \
    --cc=jack@suse.cz \
    --cc=jmoyer@redhat.com \
    --cc=laijs@cn.fujitsu.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=zab@redhat.com \
    /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

Powered by JetHome