linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lai Jiangshan <laijs@cn.fujitsu.com>
To: Tejun Heo <tj@kernel.org>, linux-kernel@vger.kernel.org
Cc: Lai Jiangshan <laijs@cn.fujitsu.com>
Subject: [PATCH 10/11 V5] workqueue: unbind/rebind without manager_mutex
Date: Wed, 5 Sep 2012 18:37:47 +0800	[thread overview]
Message-ID: <1346841475-4422-11-git-send-email-laijs@cn.fujitsu.com> (raw)
In-Reply-To: <1346841475-4422-1-git-send-email-laijs@cn.fujitsu.com>

gcwq_unbind_fn() unbind manager by ->manager pointer.

rebinding-manger, unbinding/rebinding newly created worker are done by
other place. so we don't need manager_mutex any more.

Also change the comment of @bind accordingly.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
 kernel/workqueue.c |   52 ++++++++++++++++------------------------------------
 1 files changed, 16 insertions(+), 36 deletions(-)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 819c84e..5fb712a 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -1667,17 +1667,15 @@ static void busy_worker_rebind_fn(struct work_struct *work)
  * add themselves back to idle_list if the gcwq is still associated.
  */
 static void rebind_workers(struct global_cwq *gcwq)
-	__releases(&gcwq->lock) __acquires(&gcwq->lock)
 {
 	struct worker_pool *pool;
 	struct worker *worker, *n;
 	struct hlist_node *pos;
 	int i;
 
-	lockdep_assert_held(&gcwq->lock);
+	spin_lock_irq(&gcwq->lock);
 
-	for_each_worker_pool(pool, gcwq)
-		lockdep_assert_held(&pool->manager_mutex);
+	gcwq->flags &= ~GCWQ_DISASSOCIATED;
 
 	/* exile and kick idle ones */
 	for_each_worker_pool(pool, gcwq) {
@@ -1714,6 +1712,8 @@ static void rebind_workers(struct global_cwq *gcwq)
 			worker->scheduled.next,
 			work_color_to_flags(WORK_NO_COLOR));
 	}
+
+	spin_unlock_irq(&gcwq->lock);
 }
 
 static struct worker *alloc_worker(void)
@@ -1981,11 +1981,14 @@ __acquires(&gcwq->lock)
 	bool bind;
 
 	/*
-	 * Note we have held the manage_mutex, so DISASSOCIATED can't be
-	 * flipped and it is correct that we calculate @bind only once
-	 * and then release the gcwq->lock.
+	 * Snapshot the value of @bind.
+	 * Because the %UNBOUND bit of manager can't be cleared while it
+	 * is creating worker. So we can detect whether the real @bind
+	 * is/was changed and fix the newly created worker's binding in
+	 * manager_start_worker().
 	 */
 	bind = !(gcwq->flags & GCWQ_DISASSOCIATED);
+	BUG_ON(!bind && !(pool->manager->flags & WORKER_UNBOUND));
 
 	if (!need_to_create_worker(pool))
 		return false;
@@ -3441,26 +3444,6 @@ EXPORT_SYMBOL_GPL(work_busy);
  * cpu comes back online.
  */
 
-/* claim manager positions of all pools */
-static void gcwq_claim_management_and_lock(struct global_cwq *gcwq)
-{
-	struct worker_pool *pool;
-
-	for_each_worker_pool(pool, gcwq)
-		mutex_lock_nested(&pool->manager_mutex, pool - gcwq->pools);
-	spin_lock_irq(&gcwq->lock);
-}
-
-/* release manager positions */
-static void gcwq_release_management_and_unlock(struct global_cwq *gcwq)
-{
-	struct worker_pool *pool;
-
-	spin_unlock_irq(&gcwq->lock);
-	for_each_worker_pool(pool, gcwq)
-		mutex_unlock(&pool->manager_mutex);
-}
-
 static void gcwq_unbind_fn(struct work_struct *work)
 {
 	struct global_cwq *gcwq = get_gcwq(smp_processor_id());
@@ -3471,13 +3454,13 @@ static void gcwq_unbind_fn(struct work_struct *work)
 
 	BUG_ON(gcwq->cpu != smp_processor_id());
 
-	gcwq_claim_management_and_lock(gcwq);
+	spin_lock_irq(&gcwq->lock);
 
 	/*
-	 * We've claimed all manager positions.  Make all workers unbound
-	 * and set DISASSOCIATED.  Before this, all workers except for the
-	 * ones which are still executing works from before the last CPU
-	 * down must be on the cpu.  After this, they may become diasporas.
+	 * Make all workers unbound and set DISASSOCIATED.
+	 * Before this, all workers except for the ones which are still
+	 * executing works from before the last CPU down must be on the cpu.
+	 * After this, they may become diasporas.
 	 */
 	for_each_worker_pool(pool, gcwq) {
 		list_for_each_entry(worker, &pool->idle_list, entry)
@@ -3491,7 +3474,7 @@ static void gcwq_unbind_fn(struct work_struct *work)
 
 	gcwq->flags |= GCWQ_DISASSOCIATED;
 
-	gcwq_release_management_and_unlock(gcwq);
+	spin_unlock_irq(&gcwq->lock);
 
 	/*
 	 * Call schedule() so that we cross rq->lock and thus can guarantee
@@ -3547,10 +3530,7 @@ static int __devinit workqueue_cpu_up_callback(struct notifier_block *nfb,
 
 	case CPU_DOWN_FAILED:
 	case CPU_ONLINE:
-		gcwq_claim_management_and_lock(gcwq);
-		gcwq->flags &= ~GCWQ_DISASSOCIATED;
 		rebind_workers(gcwq);
-		gcwq_release_management_and_unlock(gcwq);
 		break;
 	}
 	return NOTIFY_OK;
-- 
1.7.4.4


  parent reply	other threads:[~2012-09-05 10:36 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-05 10:37 [PATCH 00/11 V5] workqueue: reimplement unbind/rebind Lai Jiangshan
2012-09-05 10:37 ` [PATCH 01/11 V5] workqueue: ensure the wq_worker_sleeping() see the right flags Lai Jiangshan
2012-09-05 10:37 ` [PATCH 02/11 V5] workqueue: async idle rebinding Lai Jiangshan
2012-09-05 18:06   ` Tejun Heo
2012-09-06  1:28     ` Lai Jiangshan
2012-09-05 10:37 ` [PATCH 03/11 V5] workqueue: new day don't need WORKER_REBIND for busy rebinding Lai Jiangshan
2012-09-05 18:31   ` Tejun Heo
2012-09-06  2:10     ` Lai Jiangshan
2012-09-05 10:37 ` [PATCH 04/11 V5] workqueue: remove WORKER_REBIND Lai Jiangshan
2012-09-05 10:37 ` [PATCH 05/11 V5] workqueue: Add @bind arguement back without change any thing Lai Jiangshan
2012-09-05 19:49   ` Tejun Heo
2012-09-06  1:04     ` Lai Jiangshan
2012-09-06 16:51       ` Tejun Heo
2012-09-07  2:11         ` Lai Jiangshan
2012-09-07 19:37           ` Tejun Heo
2012-09-05 10:37 ` [PATCH 06/11 V5] workqueue: unbind manager Lai Jiangshan
2012-09-05 10:37 ` [PATCH 07/11 V5] workqueue: rebind manager Lai Jiangshan
2012-09-05 10:37 ` [PATCH 08/11 V5] workqueue: unbind newly created worker Lai Jiangshan
2012-09-05 10:37 ` [PATCH 09/11 V5] workqueue: rebind " Lai Jiangshan
2012-09-05 16:19   ` Lai Jiangshan
2012-09-05 10:37 ` Lai Jiangshan [this message]
2012-09-05 20:04   ` [PATCH 10/11 V5] workqueue: unbind/rebind without manager_mutex Tejun Heo
2012-09-06 10:44     ` Lai Jiangshan
2012-09-06 17:00       ` Tejun Heo
2012-09-05 10:37 ` [PATCH 11/11 V5] workqueue: remove manager_mutex Lai Jiangshan

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=1346841475-4422-11-git-send-email-laijs@cn.fujitsu.com \
    --to=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;
as well as URLs for NNTP newsgroup(s).