From: Frederic Weisbecker <frederic@kernel.org>
To: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Peter Zijlstra <peterz@infradead.org>,
Linux PM <linux-pm@vger.kernel.org>,
Frederic Weisbecker <fweisbec@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Paul McKenney <paulmck@linux.vnet.ibm.com>,
Thomas Ilsche <thomas.ilsche@tu-dresden.de>,
Doug Smythies <dsmythies@telus.net>,
Rik van Riel <riel@surriel.com>,
Aubrey Li <aubrey.li@linux.intel.com>,
Mike Galbraith <mgalbraith@suse.de>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [RFT][PATCH v4 2/7] sched: idle: Do not stop the tick upfront in the idle loop
Date: Thu, 15 Mar 2018 17:10:36 +0100 [thread overview]
Message-ID: <20180315161031.GA12313@lerouge> (raw)
In-Reply-To: <2177770.i4UbKDJpnI@aspire.rjw.lan>
On Mon, Mar 12, 2018 at 10:51:11AM +0100, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> Push the decision whether or not to stop the tick somewhat deeper
> into the idle loop.
>
> Stopping the tick upfront leads to unpleasant outcomes in case the
> idle governor doesn't agree with the timekeeping code on the duration
> of the upcoming idle period.
Looks like you meant "nohz" instead of "timekeeping"?
> Specifically, if the tick has been
> stopped and the idle governor predicts short idle, the situation is
> bad regardless of whether or not the prediction is accurate. If it
> is accurate, the tick has been stopped unnecessarily which means
> excessive overhead. If it is not accurate, the CPU is likely to
> spend too much time in the (shallow, because short idle has been
> predicted) idle state selected by the governor [1].
>
> As the first step towards addressing this problem, change the code
> to make the tick stopping decision inside of the loop in do_idle().
> In particular, do not stop the tick in the cpu_idle_poll() code path.
> Also don't do that in tick_nohz_irq_exit() which doesn't really have
> enough information on whether or not to stop the tick.
>
> Link: https://marc.info/?l=linux-pm&m=150116085925208&w=2 # [1]
> Link: https://tu-dresden.de/zih/forschung/ressourcen/dateien/projekte/haec/powernightmares.pdf
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
> kernel/sched/idle.c | 8 +++++---
> kernel/time/tick-sched.c | 6 ++----
> 2 files changed, 7 insertions(+), 7 deletions(-)
>
> Index: linux-pm/kernel/sched/idle.c
> ===================================================================
> --- linux-pm.orig/kernel/sched/idle.c
> +++ linux-pm/kernel/sched/idle.c
> @@ -241,10 +241,12 @@ static void do_idle(void)
> * broadcast device expired for us, we don't want to go deep
> * idle as we know that the IPI is going to arrive right away.
> */
> - if (cpu_idle_force_poll || tick_check_broadcast_expired())
> + if (cpu_idle_force_poll || tick_check_broadcast_expired()) {
> cpu_idle_poll();
> - else
> + } else {
> + tick_nohz_idle_stop_tick();
> cpuidle_idle_call();
> + }
I'm worried about one thing here. Say we enter cpuidle_idle_call() and the tick is stopped.
Later on, we get a tick, so we exit cpuidle_idle_call(), then we find cpu_idle_force_poll
or tick_check_broadcast_expired() to be true. So we poll but the tick hasn't been updated
to fire again.
I don't know if it can happen but cpu_idle_poll_ctrl() seem to be callable anytime.
It looks like it's only used on __init code or on power suspend/resume, not sure about
the implications on the latter, still there could be further misuse in the future.
Concerning tick_check_broadcast_expired(), it's hard to tell if it can be enabled
concurrently from another CPU or from interrupts.
Anyway perhaps we should have, out of paranoia:
+ if (cpu_idle_force_poll || tick_check_broadcast_expired()) {
+ tick_nohz_idle_restart_tick();
cpu_idle_poll();
- else
...where tick_nohz_idle_restart_tick() would be:
diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
index 29a5733..9ae1ef5 100644
--- a/kernel/time/tick-sched.c
+++ b/kernel/time/tick-sched.c
@@ -1046,6 +1046,18 @@ static void tick_nohz_account_idle_ticks(struct tick_sched *ts)
#endif
}
+static void __tick_nohz_idle_restart_tick(struct tick_sched *ts, ktime_t now)
+{
+ tick_nohz_restart_sched_tick(ts, now);
+ tick_nohz_account_idle_ticks(ts);
+}
+
+void tick_nohz_idle_restart_tick(void)
+{
+ if (ts->tick_stopped)
+ __tick_nohz_idle_restart_tick(this_cpu_ptr(&tick_cpu_sched), ktime_get());
+}
+
/**
* tick_nohz_idle_exit - restart the idle tick from the idle task
*
@@ -1070,10 +1082,8 @@ void tick_nohz_idle_exit(void)
if (ts->idle_active)
tick_nohz_stop_idle(ts, now);
- if (ts->tick_stopped) {
- tick_nohz_restart_sched_tick(ts, now);
- tick_nohz_account_idle_ticks(ts);
- }
+ if (ts->tick_stopped())
+ __tick_nohz_idle_restart_tick(ts, now)
local_irq_enable();
}
Thanks.
next prev parent reply other threads:[~2018-03-15 16:10 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-12 9:46 [RFT][PATCH v4 0/7] sched/cpuidle: Idle loop rework Rafael J. Wysocki
2018-03-12 9:47 ` [RFT][PATCH v4 1/7] time: tick-sched: Reorganize idle tick management code Rafael J. Wysocki
2018-03-14 15:49 ` Frederic Weisbecker
2018-03-14 17:20 ` Peter Zijlstra
2018-03-15 17:26 ` Frederic Weisbecker
2018-03-15 12:33 ` Rafael J. Wysocki
2018-03-12 9:51 ` [RFT][PATCH v4 2/7] sched: idle: Do not stop the tick upfront in the idle loop Rafael J. Wysocki
2018-03-15 16:10 ` Frederic Weisbecker [this message]
2018-03-15 16:50 ` Rafael J. Wysocki
2018-03-12 9:53 ` [RFT][PATCH v4 3/7] sched: idle: Do not stop the tick before cpuidle_idle_call() Rafael J. Wysocki
2018-03-15 18:19 ` Frederic Weisbecker
2018-03-15 20:41 ` Rafael J. Wysocki
2018-03-15 21:12 ` Rafael J. Wysocki
2018-03-16 14:17 ` Frederic Weisbecker
2018-03-16 14:16 ` Frederic Weisbecker
2018-03-12 9:54 ` [RFT][PATCH v4 4/7] cpuidle: Return nohz hint from cpuidle_select() Rafael J. Wysocki
2018-03-14 12:59 ` Peter Zijlstra
2018-03-15 12:54 ` Rafael J. Wysocki
2018-03-12 10:04 ` [RFT][PATCH v4 5/7] sched: idle: Select idle state before stopping the tick Rafael J. Wysocki
2018-03-12 10:05 ` [RFT][PATCH v4 6/7] cpuidle: menu: Refine idle state selection for running tick Rafael J. Wysocki
2018-03-12 10:07 ` [RFT][PATCH v4 7/7] cpuidle: menu: Avoid selecting shallow states with stopped tick Rafael J. Wysocki
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=20180315161031.GA12313@lerouge \
--to=frederic@kernel.org \
--cc=aubrey.li@linux.intel.com \
--cc=dsmythies@telus.net \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mgalbraith@suse.de \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=riel@surriel.com \
--cc=rjw@rjwysocki.net \
--cc=tglx@linutronix.de \
--cc=thomas.ilsche@tu-dresden.de \
/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