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 3/4] workqueue: Allow modifying low level unbound workqueue cpumask
Date: Thu, 24 Apr 2014 16:37:35 +0200 [thread overview]
Message-ID: <1398350256-7834-4-git-send-email-fweisbec@gmail.com> (raw)
In-Reply-To: <1398350256-7834-1-git-send-email-fweisbec@gmail.com>
Allow to modify the low-level unbound workqueues cpumask through
sysfs. This is performed by traversing the entire workqueue list
and calling apply_workqueue_attrs() on the unbound workqueues.
Ordered workqueues need some specific treatment and will be dealt with
in a subsequent patch.
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 | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 61 insertions(+), 2 deletions(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 2c38e32..387ce38 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -293,7 +293,7 @@ static DEFINE_SPINLOCK(wq_mayday_lock); /* protects wq->maydays list */
static LIST_HEAD(workqueues); /* PL: list of all workqueues */
static bool workqueue_freezing; /* PL: have wqs started freezing? */
-static cpumask_var_t wq_unbound_cpumask;
+static cpumask_var_t wq_unbound_cpumask; /* PL: low level cpumask for all unbound wqs */
/* the per-cpu worker pools */
static DEFINE_PER_CPU_SHARED_ALIGNED(struct worker_pool [NR_STD_WORKER_POOLS],
@@ -3325,19 +3325,78 @@ static struct bus_type wq_subsys = {
.dev_groups = wq_sysfs_groups,
};
+static int apply_workqueue_attrs_locked(struct workqueue_struct *wq,
+ const struct workqueue_attrs *attrs);
+
+/* 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;
+
+ 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);
+ }
+
+ return 0;
+}
+
+static ssize_t unbounds_cpumask_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ cpumask_var_t cpumask;
+ int ret = -EINVAL;
+
+ if (!zalloc_cpumask_var(&cpumask, GFP_KERNEL))
+ return -ENOMEM;
+
+ ret = cpumask_parse(buf, cpumask);
+ if (ret)
+ goto out;
+
+ get_online_cpus();
+ if (cpumask_intersects(cpumask, cpu_online_mask)) {
+ mutex_lock(&wq_pool_mutex);
+ cpumask_copy(wq_unbound_cpumask, cpumask);
+ ret = unbounds_cpumask_apply_all(cpumask);
+ mutex_unlock(&wq_pool_mutex);
+ }
+ put_online_cpus();
+out:
+ free_cpumask_var(cpumask);
+ return ret ? ret : count;
+}
+
static ssize_t unbounds_cpumask_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
int written;
+ mutex_lock(&wq_pool_mutex);
written = cpumask_scnprintf(buf, PAGE_SIZE, wq_unbound_cpumask);
+ mutex_unlock(&wq_pool_mutex);
+
written += scnprintf(buf + written, PAGE_SIZE - written, "\n");
return written;
}
static struct device_attribute wq_sysfs_cpumask_attr =
- __ATTR(cpumask_unbounds, 0444, unbounds_cpumask_show, NULL);
+ __ATTR(cpumask_unbounds, 0644, unbounds_cpumask_show,
+ unbounds_cpumask_store);
static int __init wq_sysfs_init(void)
{
--
1.8.3.1
next prev parent reply other threads:[~2014-04-24 14:38 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 ` Frederic Weisbecker [this message]
2014-04-24 15:30 ` [PATCH 3/4] workqueue: Allow modifying low level unbound workqueue cpumask Tejun Heo
2014-05-01 14:49 ` Frederic Weisbecker
2014-04-24 14:37 ` [PATCH 4/4] workqueue: Handle ordered workqueues on cpumask_unbounds change Frederic Weisbecker
2014-04-24 15:33 ` 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-4-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
Powered by JetHome