Thread (14 messages) 14 messages, 6 authors, 2018-08-21

Re: [PATCH] sched: idle: Avoid retaining the tick when it has been stopped

From: "Rafael J. Wysocki" <rafael@kernel.org>
Date: 2018-08-17 10:05:38
Also in: lkml

On Fri, Aug 17, 2018 at 11:34 AM Rafael J. Wysocki [off-list ref] wrote:
On Thursday, August 16, 2018 3:27:24 PM CEST Frederic Weisbecker wrote:
quoted
On Thu, Aug 09, 2018 at 07:08:34PM +0200, Rafael J. Wysocki wrote:
quoted
From: Rafael J. Wysocki <redacted>

If the tick has been stopped already, but the governor has not asked to
stop it (which it can do sometimes), the idle loop should invoke
tick_nohz_idle_stop_tick(), to let tick_nohz_stop_tick() take care
of this case properly.

Fixes: 554c8aa8ecad (sched: idle: Select idle state before stopping the tick)
Signed-off-by: Rafael J. Wysocki <redacted>
---
 kernel/sched/idle.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux-pm/kernel/sched/idle.c
===================================================================
--- linux-pm.orig/kernel/sched/idle.c
+++ linux-pm/kernel/sched/idle.c
@@ -190,7 +190,7 @@ static void cpuidle_idle_call(void)
             */
            next_state = cpuidle_select(drv, dev, &stop_tick);

-           if (stop_tick)
+           if (stop_tick || tick_nohz_tick_stopped())
                    tick_nohz_idle_stop_tick();
            else
                    tick_nohz_idle_retain_tick();
So what if tick_nohz_idle_stop_tick() sees no timer to schedule and
cancels it, we may remain idle in a shallow state for a long while?
Yes, but the governor is expected to avoid using shallow states when the
tick is stopped already.
quoted
Otherwise we can have something like this:
diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
index da9455a..408c985 100644
--- a/kernel/time/tick-sched.c
+++ b/kernel/time/tick-sched.c
@@ -806,6 +806,9 @@ static void tick_nohz_stop_tick(struct tick_sched *ts, int cpu)
 static void tick_nohz_retain_tick(struct tick_sched *ts)
 {
      ts->timer_expires_base = 0;
+
+     if (ts->tick_stopped)
+             tick_nohz_restart(ts, ktime_get());
 }

 #ifdef CONFIG_NO_HZ_FULL
We could do that, but my concern with that approach is that we may end up
stopping and starting the tick back and forth without exiting the loop
in do_idle() just because somebody uses a periodic timer behind our
back and the governor gets confused.

Besides, that would be a change in behavior, while the $subject patch
simply fixes a mistake in the original design.
Anyway, I'm sort of divided here.

We need to do something, this way or another, because the current code
is not strictly correct.

If there are no concerns about the possible extra overhead related to
restarting the tick, I'd just add a tick_nohz_idle_restart_tick() to
the tick_nohz_idle_retain_tick() branch in cpuidle_idle_call() (it
would do what's needed in there without affecting any other places).

Then, of course, governors would not need to worry about leaving the
tick stopped, so menu could be simplified somewhat, which may be a
good thing after all.

Cheers,
Rafael
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help