mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] sched: fix clear NOHZ_BALANCE_KICK
@ 2013-06-05  8:13 Vincent Guittot
  2013-06-05 10:44 ` Peter Zijlstra
  2013-06-19 18:39 ` [tip:sched/core] sched: Fix " tip-bot for Vincent Guittot
  0 siblings, 2 replies; 3+ messages in thread
From: Vincent Guittot @ 2013-06-05  8:13 UTC (permalink / raw)
  To: linux-kernel, linaro-kernel, peterz, mingo, fweisbec; +Cc: Vincent Guittot

I have faced a sequence where the Idle Load Balance was sometime not
triggered for a while on my platform.

CPU 0 and CPU 1 are running tasks and CPU 2 is idle

CPU 1 kicks the Idle Load Balance
CPU 1 selects CPU 2 as the new Idle Load Balancer
CPU 2 sets NOHZ_BALANCE_KICK for CPU 2
CPU 2 sends a reschedule IPI to CPU 2
While CPU 3 wakes up, CPU 0 or CPU 1 migrates a waking up task A on CPU 2
CPU 2 finally wakes up, runs task A and discards the Idle Load Balance
task A quickly goes back to sleep (before a tick occurs on CPU 2)
CPU 2 goes back to idle with NOHZ_BALANCE_KICK set

Whenever CPU 2 will be selected as the ILB, no reschedule IPI will be sent
because NOHZ_BALANCE_KICK is already set and no Idle Load Balance will be
performed.

We must wait for the sched softirq to be raised on CPU 2 thanks to another
part the kernel to come back to clear NOHZ_BALANCE_KICK.

The proposed solution clears NOHZ_BALANCE_KICK in schedule_ipi if
we can't raise the sched_softirq for the Idle Load Balance.

Change since V1:
- move the clear of NOHZ_BALANCE_KICK in got_nohz_idle_kick if the ILB
can't run on this CPU (as suggested by Peter)

Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
---
 kernel/sched/core.c |   21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 58453b8..919bee6 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -633,7 +633,19 @@ void wake_up_nohz_cpu(int cpu)
 static inline bool got_nohz_idle_kick(void)
 {
 	int cpu = smp_processor_id();
-	return idle_cpu(cpu) && test_bit(NOHZ_BALANCE_KICK, nohz_flags(cpu));
+
+	if (!test_bit(NOHZ_BALANCE_KICK, nohz_flags(cpu)))
+		return false;
+
+	if (idle_cpu(cpu) && !need_resched())
+		return true;
+
+	/*
+	 * We can't run Idle Load Balance on this CPU for this time so we
+	 * cancel it and clear NOHZ_BALANCE_KICK
+	 */
+	clear_bit(NOHZ_BALANCE_KICK, nohz_flags(cpu));
+	return false;
 }
 
 #else /* CONFIG_NO_HZ_COMMON */
@@ -1393,8 +1405,9 @@ 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()))
+	if (llist_empty(&this_rq()->wake_list)
+			&& !tick_nohz_full_cpu(smp_processor_id())
+			&& !got_nohz_idle_kick())
 		return;
 
 	/*
@@ -1417,7 +1430,7 @@ void scheduler_ipi(void)
 	/*
 	 * Check if someone kicked us for doing the nohz idle load balance.
 	 */
-	if (unlikely(got_nohz_idle_kick() && !need_resched())) {
+	if (unlikely(got_nohz_idle_kick())) {
 		this_rq()->idle_balance = 1;
 		raise_softirq_irqoff(SCHED_SOFTIRQ);
 	}
-- 
1.7.9.5


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] sched: fix clear NOHZ_BALANCE_KICK
  2013-06-05  8:13 [PATCH v2] sched: fix clear NOHZ_BALANCE_KICK Vincent Guittot
@ 2013-06-05 10:44 ` Peter Zijlstra
  2013-06-19 18:39 ` [tip:sched/core] sched: Fix " tip-bot for Vincent Guittot
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2013-06-05 10:44 UTC (permalink / raw)
  To: Vincent Guittot; +Cc: linux-kernel, linaro-kernel, mingo, fweisbec

On Wed, Jun 05, 2013 at 10:13:11AM +0200, Vincent Guittot wrote:
> I have faced a sequence where the Idle Load Balance was sometime not
> triggered for a while on my platform.
> 
> CPU 0 and CPU 1 are running tasks and CPU 2 is idle
> 
> CPU 1 kicks the Idle Load Balance
> CPU 1 selects CPU 2 as the new Idle Load Balancer
> CPU 2 sets NOHZ_BALANCE_KICK for CPU 2
> CPU 2 sends a reschedule IPI to CPU 2
> While CPU 3 wakes up, CPU 0 or CPU 1 migrates a waking up task A on CPU 2
> CPU 2 finally wakes up, runs task A and discards the Idle Load Balance
> task A quickly goes back to sleep (before a tick occurs on CPU 2)
> CPU 2 goes back to idle with NOHZ_BALANCE_KICK set
> 
> Whenever CPU 2 will be selected as the ILB, no reschedule IPI will be sent
> because NOHZ_BALANCE_KICK is already set and no Idle Load Balance will be
> performed.
> 
> We must wait for the sched softirq to be raised on CPU 2 thanks to another
> part the kernel to come back to clear NOHZ_BALANCE_KICK.
> 
> The proposed solution clears NOHZ_BALANCE_KICK in schedule_ipi if
> we can't raise the sched_softirq for the Idle Load Balance.
> 
> Change since V1:
> - move the clear of NOHZ_BALANCE_KICK in got_nohz_idle_kick if the ILB
> can't run on this CPU (as suggested by Peter)
> 
> Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>

Thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip:sched/core] sched: Fix clear NOHZ_BALANCE_KICK
  2013-06-05  8:13 [PATCH v2] sched: fix clear NOHZ_BALANCE_KICK Vincent Guittot
  2013-06-05 10:44 ` Peter Zijlstra
@ 2013-06-19 18:39 ` tip-bot for Vincent Guittot
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Vincent Guittot @ 2013-06-19 18:39 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, peterz, vincent.guittot, tglx

Commit-ID:  873b4c65b519fd769940eb281f77848227d4e5c1
Gitweb:     http://git.kernel.org/tip/873b4c65b519fd769940eb281f77848227d4e5c1
Author:     Vincent Guittot <vincent.guittot@linaro.org>
AuthorDate: Wed, 5 Jun 2013 10:13:11 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 19 Jun 2013 12:55:09 +0200

sched: Fix clear NOHZ_BALANCE_KICK

I have faced a sequence where the Idle Load Balance was sometime not
triggered for a while on my platform, in the following scenario:

 CPU 0 and CPU 1 are running tasks and CPU 2 is idle

 CPU 1 kicks the Idle Load Balance
 CPU 1 selects CPU 2 as the new Idle Load Balancer
 CPU 2 sets NOHZ_BALANCE_KICK for CPU 2
 CPU 2 sends a reschedule IPI to CPU 2

 While CPU 3 wakes up, CPU 0 or CPU 1 migrates a waking up task A on CPU 2

 CPU 2 finally wakes up, runs task A and discards the Idle Load Balance
       task A quickly goes back to sleep (before a tick occurs on CPU 2)
 CPU 2 goes back to idle with NOHZ_BALANCE_KICK set

Whenever CPU 2 will be selected as the ILB, no reschedule IPI will be sent
because NOHZ_BALANCE_KICK is already set and no Idle Load Balance will be
performed.

We must wait for the sched softirq to be raised on CPU 2 thanks to another
part the kernel to come back to clear NOHZ_BALANCE_KICK.

The proposed solution clears NOHZ_BALANCE_KICK in schedule_ipi if
we can't raise the sched_softirq for the Idle Load Balance.

Change since V1:

- move the clear of NOHZ_BALANCE_KICK in got_nohz_idle_kick if the ILB
  can't run on this CPU (as suggested by Peter)

Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1370419991-13870-1-git-send-email-vincent.guittot@linaro.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/sched/core.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 58453b8..919bee6 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -633,7 +633,19 @@ void wake_up_nohz_cpu(int cpu)
 static inline bool got_nohz_idle_kick(void)
 {
 	int cpu = smp_processor_id();
-	return idle_cpu(cpu) && test_bit(NOHZ_BALANCE_KICK, nohz_flags(cpu));
+
+	if (!test_bit(NOHZ_BALANCE_KICK, nohz_flags(cpu)))
+		return false;
+
+	if (idle_cpu(cpu) && !need_resched())
+		return true;
+
+	/*
+	 * We can't run Idle Load Balance on this CPU for this time so we
+	 * cancel it and clear NOHZ_BALANCE_KICK
+	 */
+	clear_bit(NOHZ_BALANCE_KICK, nohz_flags(cpu));
+	return false;
 }
 
 #else /* CONFIG_NO_HZ_COMMON */
@@ -1393,8 +1405,9 @@ 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()))
+	if (llist_empty(&this_rq()->wake_list)
+			&& !tick_nohz_full_cpu(smp_processor_id())
+			&& !got_nohz_idle_kick())
 		return;
 
 	/*
@@ -1417,7 +1430,7 @@ void scheduler_ipi(void)
 	/*
 	 * Check if someone kicked us for doing the nohz idle load balance.
 	 */
-	if (unlikely(got_nohz_idle_kick() && !need_resched())) {
+	if (unlikely(got_nohz_idle_kick())) {
 		this_rq()->idle_balance = 1;
 		raise_softirq_irqoff(SCHED_SOFTIRQ);
 	}

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-06-19 18:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-05  8:13 [PATCH v2] sched: fix clear NOHZ_BALANCE_KICK Vincent Guittot
2013-06-05 10:44 ` Peter Zijlstra
2013-06-19 18:39 ` [tip:sched/core] sched: Fix " tip-bot for Vincent Guittot

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