mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	"linaro-kernel@lists.linaro.org" <linaro-kernel@lists.linaro.org>,
	Ingo Molnar <mingo@kernel.org>
Subject: Re: [PATCH] sched: fix clear NOHZ_BALANCE_KICK
Date: Tue, 4 Jun 2013 11:36:11 +0200	[thread overview]
Message-ID: <20130604093611.GJ8923@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <CAKfTPtCB_ftNWjgAM9s79dX_tuS4yevjdD0YxvKfKS4dxz=LLQ@mail.gmail.com>


The best I can seem to come up with is something like the below; but I think
its ghastly. Surely we can do something saner with that bit.

Having to clear it at 3 different places is just wrong.

---
 kernel/sched/core.c | 35 +++++++++++++++++++++++++----------
 kernel/sched/fair.c |  6 ++++--
 2 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 142c682..4846223 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -630,15 +630,23 @@ void wake_up_nohz_cpu(int cpu)
 		wake_up_idle_cpu(cpu);
 }
 
-static inline bool got_nohz_idle_kick(void)
+static inline bool got_nohz_idle_kick(int cpu)
 {
-	int cpu = smp_processor_id();
-	return idle_cpu(cpu) && test_bit(NOHZ_BALANCE_KICK, nohz_flags(cpu));
+	bool nohz_kick = test_bit(NOHZ_BALANCE_KICK, nohz_flags(cpu));
+	
+	if (!nohz_kick)
+		return false;
+
+	if (idle_cpu(cpu))
+		return true;
+
+	clear_bit(NOHZ_BALANCE_KICK, nohz_flags(cpu));
+	return false;
 }
 
 #else /* CONFIG_NO_HZ_COMMON */
 
-static inline bool got_nohz_idle_kick(void)
+static inline bool got_nohz_idle_kick(int cpu)
 {
 	return false;
 }
@@ -1395,8 +1403,11 @@ static void sched_ttwu_pending(void)
 
 void scheduler_ipi(void)
 {
-	if (llist_empty(&this_rq()->wake_list) && !got_nohz_idle_kick()
-	    && !tick_nohz_full_cpu(smp_processor_id()))
+	int this_cpu = smp_processor_id();
+	bool nohz_kick = got_nohz_idle_kick(this_cpu);
+
+	if (llist_empty(&this_rq()->wake_list) && !nohz_kick &&
+	    !tick_nohz_full_cpu(this_cpu))
 		return;
 
 	/*
@@ -1413,15 +1424,19 @@ void scheduler_ipi(void)
 	 * somewhat pessimize the simple resched case.
 	 */
 	irq_enter();
-	tick_nohz_full_check();
+	tick_nohz_full_check(); /* restart tick if required */
 	sched_ttwu_pending();
 
 	/*
 	 * Check if someone kicked us for doing the nohz idle load balance.
 	 */
-	if (unlikely(got_nohz_idle_kick() && !need_resched())) {
-		this_rq()->idle_balance = 1;
-		raise_softirq_irqoff(SCHED_SOFTIRQ);
+	if (unlikely(nohz_kick)) {
+		if (!need_resched()) {
+			this_rq()->idle_balance = 1;
+			raise_softirq_irqoff(SCHED_SOFTIRQ);
+		} else {
+			clear_bit(NOHZ_BALANCE_KICK, nohz_flags(this_cpu));
+		}
 	}
 	irq_exit();
 }
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 143dcdb..4e6cff4 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -5600,8 +5600,10 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle)
 	struct rq *rq;
 	int balance_cpu;
 
-	if (idle != CPU_IDLE ||
-	    !test_bit(NOHZ_BALANCE_KICK, nohz_flags(this_cpu)))
+	if (!test_bit(NOHZ_BALANCE_KICK, nohz_flags(this_cpu)))
+		return;
+
+	if (idle != CPU_IDLE)
 		goto end;
 
 	for_each_cpu(balance_cpu, nohz.idle_cpus_mask) {


  reply	other threads:[~2013-06-04  9:36 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-30 15:23 Vincent Guittot
2013-06-03 22:48 ` Frederic Weisbecker
2013-06-04  8:21   ` Vincent Guittot
2013-06-04  9:36     ` Peter Zijlstra [this message]
2013-06-04 10:26       ` Frederic Weisbecker
2013-06-04 11:11         ` Vincent Guittot
2013-06-04 11:19           ` Frederic Weisbecker
2013-06-04 11:48             ` Vincent Guittot
2013-06-04 14:44               ` Frederic Weisbecker
2013-06-04 15:29                 ` Vincent Guittot
2013-06-05 13:31                   ` Frederic Weisbecker
2013-06-04 11:15         ` Peter Zijlstra
2013-06-04 11:53           ` Frederic Weisbecker
2013-06-04  9:56     ` 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=20130604093611.GJ8923@twins.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=fweisbec@gmail.com \
    --cc=linaro-kernel@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=vincent.guittot@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®