linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: <cmetcalf@ezchip.com>
To: Tejun Heo <tj@kernel.org>,
	"Peter Zijlstra (Intel)" <peterz@infradead.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	Martin Schwidefsky <schwidefsky@de.ibm.com>,
	<linux-kernel@vger.kernel.org>
Cc: Chris Metcalf <cmetcalf@ezchip.com>
Subject: [PATCH] workqueue: avoid nohz_full cores
Date: Tue, 31 Mar 2015 15:25:59 -0400	[thread overview]
Message-ID: <1427829959-3023-1-git-send-email-cmetcalf@ezchip.com> (raw)

From: Chris Metcalf <cmetcalf@ezchip.com>

When queuing work, we should avoid queuing it on the local cpu if
we are using WORK_CPU_UNBOUND and the local cpu is nohz_full, since
the workqueue will mean a later interrupt of the nohz_full process
that presumably would prefer continuing to have 100% of the core
without interrupts.

Likewise, remove the nohz_full cores from unbound workqueues.  If
all the cores are nohz_full, we leave them in.

Signed-off-by: Chris Metcalf <cmetcalf@ezchip.com>
---
Note that this patch depends on my earlier commit, not yet pulled
into Linus' tree, that added the tick_nohz_full_clear_cpus() API:
https://lkml.org/lkml/2015/3/24/956

 include/linux/tick.h |  9 +++++++++
 kernel/workqueue.c   | 10 +++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/include/linux/tick.h b/include/linux/tick.h
index 29456c443970..119ed00c96d5 100644
--- a/include/linux/tick.h
+++ b/include/linux/tick.h
@@ -224,6 +224,15 @@ static inline bool is_housekeeping_cpu(int cpu)
 	return true;
 }
 
+static inline int prefer_housekeeping_cpu(int cpu)
+{
+#ifdef CONFIG_NO_HZ_FULL
+	if (tick_nohz_full_cpu(cpu))
+		return cpumask_next(-1, housekeeping_mask);
+#endif
+	return cpu;
+}
+
 static inline void housekeeping_affine(struct task_struct *t)
 {
 #ifdef CONFIG_NO_HZ_FULL
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index f28849394791..ebe5ce3ae42d 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -48,6 +48,7 @@
 #include <linux/nodemask.h>
 #include <linux/moduleparam.h>
 #include <linux/uaccess.h>
+#include <linux/tick.h>
 
 #include "workqueue_internal.h"
 
@@ -1303,7 +1304,7 @@ static void __queue_work(int cpu, struct workqueue_struct *wq,
 		return;
 retry:
 	if (req_cpu == WORK_CPU_UNBOUND)
-		cpu = raw_smp_processor_id();
+		cpu = prefer_housekeeping_cpu(raw_smp_processor_id());
 
 	/* pwq which will be used unless @work is executing elsewhere */
 	if (!(wq->flags & WQ_UNBOUND))
@@ -3782,6 +3783,7 @@ int apply_workqueue_attrs(struct workqueue_struct *wq,
 	/* make a copy of @attrs and sanitize it */
 	copy_workqueue_attrs(new_attrs, attrs);
 	cpumask_and(new_attrs->cpumask, new_attrs->cpumask, cpu_possible_mask);
+	tick_nohz_full_clear_cpus(new_attrs->cpumask);
 
 	/*
 	 * We may create multiple pwqs with differing cpumasks.  Make a
@@ -3810,6 +3812,12 @@ int apply_workqueue_attrs(struct workqueue_struct *wq,
 
 	for_each_node(node) {
 		if (wq_calc_node_cpumask(attrs, node, -1, tmp_attrs->cpumask)) {
+#ifdef CONFIG_NO_HZ_FULL
+			tick_nohz_full_clear_cpus(tmp_attrs->cpumask);
+			if (cpumask_empty(tmp_attrs->cpumask))
+				cpumask_copy(tmp_attrs->cpumask,
+					     new_attrs->cpumask);
+#endif
 			pwq_tbl[node] = alloc_unbound_pwq(wq, tmp_attrs);
 			if (!pwq_tbl[node])
 				goto enomem_pwq;
-- 
2.1.2


             reply	other threads:[~2015-03-31 19:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-31 19:25 cmetcalf [this message]
2015-03-31 19:37 ` [PATCH] workqueue: avoid nohz_full cores Tejun Heo
2015-04-01  7:56   ` Peter Zijlstra
2015-04-01 15:46     ` Tejun Heo
2015-03-31 20:58 ` Frederic Weisbecker
2015-03-31 21:06   ` 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=1427829959-3023-1-git-send-email-cmetcalf@ezchip.com \
    --to=cmetcalf@ezchip.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=schwidefsky@de.ibm.com \
    --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;
as well as URLs for NNTP newsgroup(s).