From: Frederic Weisbecker <fweisbec@gmail.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
Christoph Lameter <cl@linux.com>,
Kevin Hilman <khilman@linaro.org>,
Lai Jiangshan <laijs@cn.fujitsu.com>,
Mike Galbraith <bitbucket@online.de>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
Tejun Heo <tj@kernel.org>, Viresh Kumar <viresh.kumar@linaro.org>
Subject: [PATCH 4/4] workqueue: Handle ordered workqueues on cpumask_unbounds change
Date: Thu, 24 Apr 2014 16:37:36 +0200 [thread overview]
Message-ID: <1398350256-7834-5-git-send-email-fweisbec@gmail.com> (raw)
In-Reply-To: <1398350256-7834-1-git-send-email-fweisbec@gmail.com>
Ordered unbound workqueues need some special care if we want to
modify their CPU affinity. These can't be simply handled through
apply_workqueue_attrs() since it works by hot plugging worker pools
which has parallelism side effects and this would break ordering.
The way we solve this is to change the affinity of the (presumaly
unique) worker backing the ordered workqueues.
NOTE: Now like Lai said, there may be bad side effects on this because
ordered wq may share their worker pool with non-ordered workqueues.
So changing the affinity of the worker itself is not a nice solution.
This patch is very likely to be replaced by Lai's patch
"workqueue: allow changing attributions of ordered workqueue"
https://lkml.org/lkml/2014/4/15/181
Cc: Christoph Lameter <cl@linux.com>
Cc: Kevin Hilman <khilman@linaro.org>
Cc: Lai Jiangshan <laijs@cn.fujitsu.com>
Cc: Mike Galbraith <bitbucket@online.de>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
kernel/workqueue.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 67 insertions(+), 9 deletions(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 387ce38..564e034 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -3328,26 +3328,84 @@ static struct bus_type wq_subsys = {
static int apply_workqueue_attrs_locked(struct workqueue_struct *wq,
const struct workqueue_attrs *attrs);
+static int unbounds_cpumask_apply_ordered(struct workqueue_struct *wq,
+ cpumask_var_t cpumask)
+{
+ struct pool_workqueue *pwq;
+ struct worker_pool *pool;
+ struct worker *worker;
+ int ret = 0;
+ int wi;
+
+ /* Ordered wq have a single pool */
+ pwq = list_first_entry(&wq->pwqs, typeof(*pwq), pwqs_node);
+ pool = pwq->pool;
+
+ mutex_lock(&pool->manager_mutex);
+ /* There is a single worker on that pool, but the iterator is convenient */
+ for_each_pool_worker(worker, wi, pool) {
+ ret = set_cpus_allowed_ptr(worker->task, cpumask);
+ if (ret)
+ goto fail;
+ }
+
+ cpumask_copy(pool->attrs->cpumask, cpumask);
+ mutex_unlock(&pool->manager_mutex);
+
+ mutex_lock(&wq->mutex);
+ cpumask_copy(wq->unbound_attrs->cpumask, cpumask);
+ mutex_unlock(&wq->mutex);
+
+ return 0;
+
+fail:
+ mutex_unlock(&pool->manager_mutex);
+ return ret;
+}
+
+static int unbounds_cpumask_apply(struct workqueue_struct *wq,
+ cpumask_var_t cpumask)
+{
+ struct workqueue_attrs *attrs;
+ int ret;
+
+ attrs = wq_sysfs_prep_attrs(wq);
+ if (!attrs)
+ return -ENOMEM;
+
+ /*
+ * TODO: this works well when the cpumask is schrinked
+ * but more plumbing is needed to handle cpumask value
+ * expansion
+ */
+ ret = apply_workqueue_attrs_locked(wq, attrs);
+ free_workqueue_attrs(attrs);
+
+ return ret;
+}
+
/* Must be called with wq_unbound_mutex held */
static int unbounds_cpumask_apply_all(cpumask_var_t cpumask)
{
struct workqueue_struct *wq;
list_for_each_entry(wq, &workqueues, list) {
- struct workqueue_attrs *attrs;
+ int ret;
if (!(wq->flags & WQ_UNBOUND))
continue;
/* Ordered workqueues need specific treatment */
if (wq->flags & __WQ_ORDERED)
- continue;
-
- attrs = wq_sysfs_prep_attrs(wq);
- if (!attrs)
- return -ENOMEM;
-
- WARN_ON_ONCE(apply_workqueue_attrs_locked(wq, attrs));
- free_workqueue_attrs(attrs);
+ /*
+ * Calling unbounds_cpumask_apply_ordered() once on
+ * the first ordered wq we meet should be enough because
+ * all ordered workqueues all share the same single worker pool.
+ * But this detail might change in the future
+ */
+ ret = unbounds_cpumask_apply_ordered(wq, cpumask);
+ else
+ ret = unbounds_cpumask_apply(wq, cpumask);
+ WARN_ON_ONCE(ret);
}
return 0;
--
1.8.3.1
next prev parent reply other threads:[~2014-04-24 14:37 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-24 14:37 [RFC PATCH 0/4] workqueue: Introduce low-level unbound wq sysfs cpumask Frederic Weisbecker
2014-04-24 14:37 ` [PATCH 1/4] workqueue: Create low-level unbound workqueues cpumask Frederic Weisbecker
2014-04-24 15:37 ` Tejun Heo
2014-05-01 15:01 ` Frederic Weisbecker
2014-05-01 15:02 ` Tejun Heo
2014-05-01 15:09 ` Frederic Weisbecker
2014-05-01 15:13 ` Tejun Heo
2014-04-24 22:42 ` Kevin Hilman
2014-04-24 14:37 ` [PATCH 2/4] workqueue: Split apply attrs code from its locking Frederic Weisbecker
2014-04-24 14:48 ` Tejun Heo
2014-05-01 14:40 ` Frederic Weisbecker
2014-05-01 14:41 ` Tejun Heo
2014-04-24 14:37 ` [PATCH 3/4] workqueue: Allow modifying low level unbound workqueue cpumask Frederic Weisbecker
2014-04-24 15:30 ` Tejun Heo
2014-05-01 14:49 ` Frederic Weisbecker
2014-04-24 14:37 ` Frederic Weisbecker [this message]
2014-04-24 15:33 ` [PATCH 4/4] workqueue: Handle ordered workqueues on cpumask_unbounds change Tejun Heo
2014-05-01 14:51 ` Frederic Weisbecker
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=1398350256-7834-5-git-send-email-fweisbec@gmail.com \
--to=fweisbec@gmail.com \
--cc=bitbucket@online.de \
--cc=cl@linux.com \
--cc=khilman@linaro.org \
--cc=laijs@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--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®