From: Lai Jiangshan <laijs@cn.fujitsu.com>
To: Tejun Heo <tj@kernel.org>
Cc: Lai Jiangshan <laijs@cn.fujitsu.com>, <linux-kernel@vger.kernel.org>
Subject: [PATCH 4/6] workqueue: commit worker to pool's concurrency setting atomically.
Date: Sat, 12 Apr 2014 18:45:33 +0800 [thread overview]
Message-ID: <1397299543-12012-5-git-send-email-laijs@cn.fujitsu.com> (raw)
In-Reply-To: <1397299543-12012-1-git-send-email-laijs@cn.fujitsu.com>
workers' concurrency setting need to be coordinate with pool's
concurrency setting when create_worker()/destroy_worker()/cpu_inline()
cpu_offline().
But create_worker() handles it non-atomically(not in a single pool->lock).
This patch makes the behavior atomically.
Now bind_list is used for coordinating workers' cpumask with the pool.
worker_idr is used for coordinating workers' concurrency with the pool.
cpumask is coordinated at first and then concurrency.
We don't want to remove worker_idr and re-use bind_list.
if we do so:
1) the locking will become much complex.
2) after removing worker_idr, we need to add a ida back
we do not save any thing.
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
kernel/workqueue.c | 15 +++------------
1 files changed, 3 insertions(+), 12 deletions(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 6c38aed..3a6be02 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -63,10 +63,6 @@ enum {
* While DISASSOCIATED, the cpu may be offline and all workers have
* %WORKER_UNBOUND set and concurrency management disabled, and may
* be executing on any CPU. The pool behaves as an unbound one.
- *
- * Note that DISASSOCIATED should be flipped only while holding
- * manager_mutex to avoid changing binding state while
- * create_worker() is in progress.
*/
POOL_MANAGE_WORKERS = 1 << 0, /* need to manage workers */
POOL_DISASSOCIATED = 1 << 2, /* cpu can't serve workers */
@@ -1745,16 +1741,10 @@ static struct worker *create_worker(struct worker_pool *pool)
bind_worker(worker, pool);
- /*
- * The caller is responsible for ensuring %POOL_DISASSOCIATED
- * remains stable across this function. See the comments above the
- * flag definition for details.
- */
+ /* successful, commit the worker to the pool's concurrency setting */
+ spin_lock_irq(&pool->lock);
if (pool->flags & POOL_DISASSOCIATED)
worker->flags |= WORKER_UNBOUND;
-
- /* successful, commit the pointer to idr */
- spin_lock_irq(&pool->lock);
idr_replace(&pool->worker_idr, worker, worker->id);
spin_unlock_irq(&pool->lock);
@@ -1841,6 +1831,7 @@ static void destroy_worker(struct worker *worker)
list_del_init(&worker->entry);
worker->flags |= WORKER_DIE;
+ /* release @id and leave pool's concurrency setting */
idr_remove(&pool->worker_idr, worker->id);
wake_up_process(worker->task);
}
--
1.7.4.4
next prev parent reply other threads:[~2014-04-12 10:43 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1397299543-12012-1-git-send-email-laijs@cn.fujitsu.com>
2014-04-12 10:45 ` [PATCH 1/6] workqueue: generic routine to restore percpu/unbound pools' workers' cpumask Lai Jiangshan
2014-04-12 10:45 ` [PATCH 2/6] workqueue: generic framework to manage normal&rescuer " Lai Jiangshan
2014-04-12 10:45 ` [PATCH 3/6] workqueue: make destroy_worker() atomically Lai Jiangshan
2014-04-12 10:45 ` Lai Jiangshan [this message]
2014-04-12 10:45 ` [PATCH 5/6] workqueue: remove manager_mutex Lai Jiangshan
2014-04-12 10:45 ` [PATCH 6/6] workqueue: destroy worker directly in idle timeout handler Lai Jiangshan
2014-04-12 10:50 ` [PATCH 0/6] workqueue: simpler&better workers management synchronization Lai Jiangshan
2014-04-21 1:33 ` Lai Jiangshan
2014-04-21 22:34 ` 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=1397299543-12012-5-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
all inboxes | Powered by JetHome®