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 3/7 V6] workqueue: add manager pointer for worker_pool
Date: Sun, 9 Sep 2012 01:12:52 +0800 [thread overview]
Message-ID: <1347124383-18723-4-git-send-email-laijs@cn.fujitsu.com> (raw)
In-Reply-To: <1347124383-18723-1-git-send-email-laijs@cn.fujitsu.com>
We have this plan for manage_workers(): if failed to grab
manager_mutex via mutex_trylock(), we will release gcwq->lock and then
grab manager_mutex again.
This plan will open a hole: hotplug is running after we release gcwq->lock,
and it will not handle the binding of manager. so we add ->manager
on worker_pool and let hotplug code(gcwq_unbind_fn()) handle it.
also fix too_many_workers() to use this pointer.
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
kernel/workqueue.c | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 3dd7ce2..b203806 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -165,6 +165,7 @@ struct worker_pool {
struct timer_list idle_timer; /* L: worker idle timeout */
struct timer_list mayday_timer; /* L: SOS timer for workers */
+ struct worker *manager; /* L: manager worker */
struct mutex manager_mutex; /* mutex manager should hold */
struct ida worker_ida; /* L: for worker IDs */
};
@@ -680,7 +681,7 @@ static bool need_to_manage_workers(struct worker_pool *pool)
/* Do we have too many workers and should some go away? */
static bool too_many_workers(struct worker_pool *pool)
{
- bool managing = mutex_is_locked(&pool->manager_mutex);
+ bool managing = !!pool->manager;
int nr_idle = pool->nr_idle + managing; /* manager is considered idle */
int nr_busy = pool->nr_workers - nr_idle;
@@ -2066,6 +2067,7 @@ static bool manage_workers(struct worker *worker)
if (!mutex_trylock(&pool->manager_mutex))
return ret;
+ pool->manager = worker;
pool->flags &= ~POOL_MANAGE_WORKERS;
/*
@@ -2076,6 +2078,8 @@ static bool manage_workers(struct worker *worker)
ret |= maybe_create_worker(pool);
mutex_unlock(&pool->manager_mutex);
+ pool->manager = NULL;
+
return ret;
}
@@ -3438,9 +3442,12 @@ static void gcwq_unbind_fn(struct work_struct *work)
* 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)
+ for_each_worker_pool(pool, gcwq) {
list_for_each_entry(worker, &pool->idle_list, entry)
worker->flags |= WORKER_UNBOUND;
+ if (pool->manager)
+ pool->manager->flags |= WORKER_UNBOUND;
+ }
for_each_busy_worker(worker, i, pos, gcwq)
worker->flags |= WORKER_UNBOUND;
@@ -3760,6 +3767,7 @@ static int __init init_workqueues(void)
setup_timer(&pool->mayday_timer, gcwq_mayday_timeout,
(unsigned long)pool);
+ pool->manager = NULL;
mutex_init(&pool->manager_mutex);
ida_init(&pool->worker_ida);
}
--
1.7.4.4
next prev parent reply other threads:[~2012-09-08 17:11 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-08 17:12 [PATCH 0/7 V6] workqueue: fix hoplug things Lai Jiangshan
2012-09-08 17:12 ` [PATCH 1/7 V6] workqueue: ensure the wq_worker_sleeping() see the right flags Lai Jiangshan
2012-09-08 17:12 ` [PATCH 2/7 V6] workqueue: async idle rebinding Lai Jiangshan
2012-09-08 17:12 ` Lai Jiangshan [this message]
2012-09-08 17:12 ` [PATCH 4/7 V6] workqueue: fix idle worker depletion Lai Jiangshan
2012-09-08 17:40 ` Tejun Heo
2012-09-08 17:50 ` Lai Jiangshan
2012-09-08 17:53 ` Tejun Heo
2012-09-08 18:07 ` Lai Jiangshan
2012-09-08 18:11 ` Tejun Heo
2012-09-08 18:34 ` Lai Jiangshan
2012-09-08 19:02 ` Tejun Heo
2012-09-09 4:09 ` Lai Jiangshan
2012-09-09 6:30 ` Tejun Heo
2012-09-08 17:12 ` [PATCH 5/7 V6] workqueue: rename manager_mutex to assoc_mutex Lai Jiangshan
2012-09-08 17:12 ` [PATCH 6/7 V6] workqueue: new day don't need WORKER_REBIND for busy rebinding Lai Jiangshan
2012-09-08 17:12 ` [PATCH 7/7 V6] workqueue: remove WORKER_REBIND Lai Jiangshan
2012-09-08 17:27 ` [PATCH 0/7 V6] workqueue: fix hoplug things Lai Jiangshan
2012-09-08 17:34 ` Lai Jiangshan
2012-09-08 17:37 ` Tejun Heo
2012-09-08 17:46 ` Lai Jiangshan
2012-09-08 17:50 ` Tejun Heo
2012-09-08 17:51 ` Tejun Heo
2012-09-08 17:56 ` Lai Jiangshan
2012-09-08 17:59 ` Tejun Heo
2012-09-08 18:21 ` 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=1347124383-18723-4-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®