From: Lai Jiangshan <laijs@cn.fujitsu.com>
To: <linux-kernel@vger.kernel.org>
Cc: Tejun Heo <tj@kernel.org>, Lai Jiangshan <laijs@cn.fujitsu.com>,
"Peter Zijlstra" <peterz@infradead.org>,
Viresh Kumar <viresh.kumar@linaro.org>,
"Ingo Molnar" <mingo@kernel.org>
Subject: [PATCH 05/10 V2] workqueue: separate iteration role from worker_idr
Date: Mon, 12 May 2014 14:56:17 +0800 [thread overview]
Message-ID: <1399877792-13046-6-git-send-email-laijs@cn.fujitsu.com> (raw)
In-Reply-To: <1399877792-13046-1-git-send-email-laijs@cn.fujitsu.com>
worker_idr has the iteration(iterating for attached workers) and worker ID
duties. These two duties are not necessary tied together. We can separate
them and use a list for tracking attached workers and iteration
After separation, we can add the rescuer workers to the list for iteration
in future. worker_idr can't add rescuer workers due to rescuer workers
can't allocate id from worker_idr.
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
kernel/workqueue.c | 39 +++++++++++++--------------------------
kernel/workqueue_internal.h | 1 +
2 files changed, 14 insertions(+), 26 deletions(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 95695c3..b6cf4d9 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -161,7 +161,8 @@ struct worker_pool {
/* see manage_workers() for details on the two manager mutexes */
struct mutex manager_arb; /* manager arbitration */
struct mutex manager_mutex; /* manager exclusion */
- struct idr worker_idr; /* M: worker IDs and iteration */
+ struct idr worker_idr; /* M: worker IDs */
+ struct list_head workers; /* M: attached workers */
struct completion *detach_completion; /* all workers detached */
struct workqueue_attrs *attrs; /* I: worker attributes */
@@ -361,22 +362,6 @@ static void copy_workqueue_attrs(struct workqueue_attrs *to,
else
/**
- * for_each_pool_worker - iterate through all workers of a worker_pool
- * @worker: iteration cursor
- * @wi: integer used for iteration
- * @pool: worker_pool to iterate workers of
- *
- * This must be called with @pool->manager_mutex.
- *
- * The if/else clause exists only for the lockdep assertion and can be
- * ignored.
- */
-#define for_each_pool_worker(worker, wi, pool) \
- idr_for_each_entry(&(pool)->worker_idr, (worker), (wi)) \
- if (({ lockdep_assert_held(&pool->manager_mutex); false; })) { } \
- else
-
-/**
* for_each_pwq - iterate through all pool_workqueues of the specified workqueue
* @pwq: iteration cursor
* @wq: the target workqueue
@@ -1674,6 +1659,7 @@ static struct worker *alloc_worker(void)
if (worker) {
INIT_LIST_HEAD(&worker->entry);
INIT_LIST_HEAD(&worker->scheduled);
+ INIT_LIST_HEAD(&worker->node);
/* on creation a worker is in !idle && prep state */
worker->flags = WORKER_PREP;
}
@@ -1696,7 +1682,8 @@ static void worker_detach_from_pool(struct worker *worker,
mutex_lock(&pool->manager_mutex);
idr_remove(&pool->worker_idr, worker->id);
- if (idr_is_empty(&pool->worker_idr))
+ list_del(&worker->node);
+ if (list_empty(&pool->workers))
detach_completion = pool->detach_completion;
mutex_unlock(&pool->manager_mutex);
@@ -1772,6 +1759,8 @@ static struct worker *create_worker(struct worker_pool *pool)
/* successful, commit the pointer to idr */
idr_replace(&pool->worker_idr, worker, worker->id);
+ /* successful, attach the worker to the pool */
+ list_add_tail(&worker->node, &pool->workers);
return worker;
@@ -3481,6 +3470,7 @@ static int init_worker_pool(struct worker_pool *pool)
mutex_init(&pool->manager_arb);
mutex_init(&pool->manager_mutex);
idr_init(&pool->worker_idr);
+ INIT_LIST_HEAD(&pool->workers);
INIT_HLIST_NODE(&pool->hash_node);
pool->refcnt = 1;
@@ -3545,7 +3535,7 @@ static void put_unbound_pool(struct worker_pool *pool)
spin_unlock_irq(&pool->lock);
mutex_lock(&pool->manager_mutex);
- if (!idr_is_empty(&pool->worker_idr))
+ if (!list_empty(&pool->workers))
pool->detach_completion = &detach_completion;
mutex_unlock(&pool->manager_mutex);
@@ -4530,7 +4520,6 @@ static void wq_unbind_fn(struct work_struct *work)
int cpu = smp_processor_id();
struct worker_pool *pool;
struct worker *worker;
- int wi;
for_each_cpu_worker_pool(pool, cpu) {
WARN_ON_ONCE(cpu != smp_processor_id());
@@ -4545,7 +4534,7 @@ static void wq_unbind_fn(struct work_struct *work)
* before the last CPU down must be on the cpu. After
* this, they may become diasporas.
*/
- for_each_pool_worker(worker, wi, pool)
+ list_for_each_entry(worker, &pool->workers, node)
worker->flags |= WORKER_UNBOUND;
pool->flags |= POOL_DISASSOCIATED;
@@ -4591,7 +4580,6 @@ static void wq_unbind_fn(struct work_struct *work)
static void rebind_workers(struct worker_pool *pool)
{
struct worker *worker;
- int wi;
lockdep_assert_held(&pool->manager_mutex);
@@ -4602,13 +4590,13 @@ static void rebind_workers(struct worker_pool *pool)
* of all workers first and then clear UNBOUND. As we're called
* from CPU_ONLINE, the following shouldn't fail.
*/
- for_each_pool_worker(worker, wi, pool)
+ list_for_each_entry(worker, &pool->workers, node)
WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task,
pool->attrs->cpumask) < 0);
spin_lock_irq(&pool->lock);
- for_each_pool_worker(worker, wi, pool) {
+ list_for_each_entry(worker, &pool->workers, node) {
unsigned int worker_flags = worker->flags;
/*
@@ -4660,7 +4648,6 @@ static void restore_unbound_workers_cpumask(struct worker_pool *pool, int cpu)
{
static cpumask_t cpumask;
struct worker *worker;
- int wi;
lockdep_assert_held(&pool->manager_mutex);
@@ -4674,7 +4661,7 @@ static void restore_unbound_workers_cpumask(struct worker_pool *pool, int cpu)
return;
/* as we're called from CPU_ONLINE, the following shouldn't fail */
- for_each_pool_worker(worker, wi, pool)
+ list_for_each_entry(worker, &pool->workers, node)
WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task,
pool->attrs->cpumask) < 0);
}
diff --git a/kernel/workqueue_internal.h b/kernel/workqueue_internal.h
index 7e2204d..c44abc3 100644
--- a/kernel/workqueue_internal.h
+++ b/kernel/workqueue_internal.h
@@ -37,6 +37,7 @@ struct worker {
struct task_struct *task; /* I: worker task */
struct worker_pool *pool; /* I: the associated pool */
/* L: for rescuers */
+ struct list_head node; /* M: attached to the pool */
unsigned long last_active; /* L: last active timestamp */
unsigned int flags; /* X: flags */
--
1.7.4.4
next prev parent reply other threads:[~2014-05-12 6:53 UTC|newest]
Thread overview: 78+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-27 4:08 [PATCH 00/10] workqueue: async worker destruction and pool-binding synchronization Lai Jiangshan
2014-04-27 4:08 ` [PATCH 01/10] workqueue: use manager lock only to protect worker_idr Lai Jiangshan
2014-05-05 13:01 ` Tejun Heo
2014-05-06 15:43 ` Lai Jiangshan
2014-04-27 4:08 ` [PATCH 02/10] workqueue: destroy_worker() should destroy idle workers only Lai Jiangshan
2014-05-05 13:13 ` Tejun Heo
2014-05-06 15:58 ` Lai Jiangshan
2014-04-27 4:08 ` [PATCH 03/10] workqueue: async worker destruction Lai Jiangshan
2014-05-05 14:31 ` Tejun Heo
2014-05-05 15:02 ` Tejun Heo
2014-05-06 16:27 ` Lai Jiangshan
2014-05-06 16:31 ` Tejun Heo
2014-05-07 7:30 ` Lai Jiangshan
2014-05-07 13:15 ` Tejun Heo
2014-04-27 4:08 ` [PATCH 04/10] workqueue: destroy worker directly in the idle timeout handler Lai Jiangshan
2014-05-05 14:36 ` Tejun Heo
2014-05-07 7:10 ` Lai Jiangshan
2014-05-07 13:12 ` Tejun Heo
2014-05-07 13:38 ` Lai Jiangshan
2014-05-07 13:41 ` Tejun Heo
2014-05-07 15:30 ` Lai Jiangshan
2014-05-07 15:37 ` Tejun Heo
2014-04-27 4:09 ` [PATCH 05/10] workqueue: separate iteration role from worker_idr Lai Jiangshan
2014-05-05 14:57 ` Tejun Heo
2014-04-27 4:09 ` [PATCH 06/10] workqueue: convert worker_idr to worker_ida Lai Jiangshan
2014-05-05 14:59 ` Tejun Heo
2014-05-06 16:33 ` Lai Jiangshan
2014-05-06 16:35 ` Tejun Heo
2014-05-06 16:38 ` Tejun Heo
2014-04-27 4:09 ` [PATCH 07/10] workqueue: narrow the protection range of manager_mutex Lai Jiangshan
2014-04-27 4:09 ` [PATCH 08/10] workqueue: rename manager_mutex to bind_mutex Lai Jiangshan
2014-04-27 4:09 ` [PATCH 09/10] workqueue: separate pool-binding code out from create_worker() Lai Jiangshan
2014-04-27 4:09 ` [PATCH 10/10] workqueue: use generic pool-bind/unbind routine for rescuers Lai Jiangshan
2014-05-05 14:54 ` Tejun Heo
2014-05-05 15:05 ` [PATCH 00/10] workqueue: async worker destruction and pool-binding synchronization Tejun Heo
2014-05-12 6:56 ` [PATCH 00/10 V2] workqueue: async worker destruction and worker attaching/detaching Lai Jiangshan
2014-05-12 6:56 ` [PATCH 01/10 V2] workqueue: use manager lock only to protect worker_idr Lai Jiangshan
2014-05-12 6:56 ` [PATCH 02/10 V2] workqueue: destroy_worker() should destroy idle workers only Lai Jiangshan
2014-05-12 21:08 ` Tejun Heo
2014-05-13 6:08 ` Lai Jiangshan
2014-05-12 6:56 ` [PATCH 03/10 V2] workqueue: async worker destruction Lai Jiangshan
2014-05-12 21:20 ` Tejun Heo
2014-05-13 6:32 ` Lai Jiangshan
2014-05-13 14:14 ` Tejun Heo
2014-05-20 9:54 ` Lai Jiangshan
2014-05-12 6:56 ` [PATCH 04/10 V2] workqueue: destroy worker directly in the idle timeout handler Lai Jiangshan
2014-05-12 21:26 ` Tejun Heo
2014-05-12 6:56 ` Lai Jiangshan [this message]
2014-05-12 21:35 ` [PATCH 05/10 V2] workqueue: separate iteration role from worker_idr Tejun Heo
2014-05-12 21:37 ` Tejun Heo
2014-05-12 6:56 ` [PATCH 06/10 V2] workqueue: convert worker_idr to worker_ida Lai Jiangshan
2014-05-12 21:40 ` Tejun Heo
2014-05-13 6:43 ` Lai Jiangshan
2014-05-13 14:17 ` Tejun Heo
2014-05-12 6:56 ` [PATCH 07/10 V2] workqueue: narrow the protection range of manager_mutex Lai Jiangshan
2014-05-12 6:56 ` [PATCH 08/10 V2] workqueue: rename manager_mutex to attach_mutex Lai Jiangshan
2014-05-12 22:01 ` Tejun Heo
2014-05-13 6:45 ` Lai Jiangshan
2014-05-13 14:19 ` Tejun Heo
2014-05-12 6:56 ` [PATCH 09/10 V2] workqueue: separate pool-attaching code out from create_worker() Lai Jiangshan
2014-05-12 6:56 ` [PATCH 10/10 V2] workqueue: use generic attach/detach routine for rescuers Lai Jiangshan
2014-05-12 22:05 ` Tejun Heo
2014-05-13 6:55 ` Lai Jiangshan
2014-05-20 9:46 ` [PATCH V3 00/10] workqueue: async worker destruction and worker attaching/detaching Lai Jiangshan
2014-05-20 9:46 ` [PATCH V3 01/10] workqueue: use manager lock only to protect worker_idr Lai Jiangshan
2014-05-20 9:46 ` [PATCH V3 02/10] workqueue: destroy_worker() should destroy idle workers only Lai Jiangshan
2014-05-20 9:46 ` [PATCH V3 03/10] workqueue: async worker destruction Lai Jiangshan
2014-05-20 14:22 ` Tejun Heo
2014-05-20 14:23 ` Tejun Heo
2014-05-20 14:24 ` Tejun Heo
2014-05-20 9:46 ` [PATCH V3 04/10] workqueue: destroy worker directly in the idle timeout handler Lai Jiangshan
2014-05-20 9:46 ` [PATCH V3 05/10] workqueue: separate iteration role from worker_idr Lai Jiangshan
2014-05-20 9:46 ` [PATCH V3 06/10] workqueue: convert worker_idr to worker_ida Lai Jiangshan
2014-05-20 9:46 ` [PATCH V3 07/10] workqueue: narrow the protection range of manager_mutex Lai Jiangshan
2014-05-20 9:46 ` [PATCH V3 08/10] workqueue: rename manager_mutex to attach_mutex Lai Jiangshan
2014-05-20 9:46 ` [PATCH V3 09/10] workqueue: separate pool-attaching code out from create_worker() Lai Jiangshan
2014-05-20 9:46 ` [PATCH V3 10/10] workqueue: use generic attach/detach routine for rescuers Lai Jiangshan
2014-05-20 15:00 ` [PATCH V3 00/10] workqueue: async worker destruction and worker attaching/detaching 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=1399877792-13046-6-git-send-email-laijs@cn.fujitsu.com \
--to=laijs@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=tj@kernel.org \
--cc=viresh.kumar@linaro.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®