public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] tick/sched: Forward timer even in nohz mode
@ 2019-12-16 23:22 Scott Wood
  2019-12-16 23:22 ` [PATCH 2/4] tick/sched: Set last_tick in init paths Scott Wood
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Scott Wood @ 2019-12-16 23:22 UTC (permalink / raw)
  To: Peter Zijlstra, Frederic Weisbecker, Thomas Gleixner, Ingo Molnar
  Cc: linux-kernel, Scott Wood

Currently when exiting nohz, the expiry will be forwarded as if we
had just run the timer.  If we re-enter nohz before this new expiry,
and exit after, this forwarding will happen again.  If this load pattern
recurs the tick can be indefinitely postponed.

To avoid this, use last_tick as-is rather than calling hrtimer_forward().
However, in some cases the tick *will* have just run (despite being
"stopped"), and leading to double timer execution.

To avoid that, forward the timer after every tick (regardless of nohz
status) and keep last_tick up-to-date.  During nohz, last_tick will
reflect what the expiry would have been if not in nohz mode.

Signed-off-by: Scott Wood <swood@redhat.com>
---
 kernel/time/tick-sched.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
index 8b192e67aabc..8936b604dd6c 100644
--- a/kernel/time/tick-sched.c
+++ b/kernel/time/tick-sched.c
@@ -642,9 +642,6 @@ static void tick_nohz_restart(struct tick_sched *ts, ktime_t now)
 	hrtimer_cancel(&ts->sched_timer);
 	hrtimer_set_expires(&ts->sched_timer, ts->last_tick);
 
-	/* Forward the time to expire in the future */
-	hrtimer_forward(&ts->sched_timer, now, tick_period);
-
 	if (ts->nohz_mode == NOHZ_MODE_HIGHRES) {
 		hrtimer_start_expires(&ts->sched_timer,
 				      HRTIMER_MODE_ABS_PINNED_HARD);
@@ -1207,12 +1204,13 @@ static void tick_nohz_handler(struct clock_event_device *dev)
 
 	tick_sched_do_timer(ts, now);
 	tick_sched_handle(ts, regs);
+	hrtimer_forward(&ts->sched_timer, now, tick_period);
+	ts->last_tick = hrtimer_get_expires(&ts->sched_timer);
 
 	/* No need to reprogram if we are running tickless  */
 	if (unlikely(ts->tick_stopped))
 		return;
 
-	hrtimer_forward(&ts->sched_timer, now, tick_period);
 	tick_program_event(hrtimer_get_expires(&ts->sched_timer), 1);
 }
 
@@ -1311,12 +1309,13 @@ static enum hrtimer_restart tick_sched_timer(struct hrtimer *timer)
 	else
 		ts->next_tick = 0;
 
+	hrtimer_forward(timer, now, tick_period);
+	ts->last_tick = hrtimer_get_expires(&ts->sched_timer);
+
 	/* No need to reprogram if we are in idle or full dynticks mode */
 	if (unlikely(ts->tick_stopped))
 		return HRTIMER_NORESTART;
 
-	hrtimer_forward(timer, now, tick_period);
-
 	return HRTIMER_RESTART;
 }
 
-- 
1.8.3.1


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

end of thread, other threads:[~2020-01-08 23:18 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-12-16 23:22 [PATCH 1/4] tick/sched: Forward timer even in nohz mode Scott Wood
2019-12-16 23:22 ` [PATCH 2/4] tick/sched: Set last_tick in init paths Scott Wood
2019-12-16 23:22 ` [PATCH 3/4] sched/core: Don't skip remote tick for idle cpus Scott Wood
2019-12-16 23:22 ` [PATCH 4/4] timers/nohz: Update nohz load in remote tick Scott Wood
2020-01-07  9:26   ` Peter Zijlstra
2020-01-06 20:12 ` [PATCH 1/4] tick/sched: Forward timer even in nohz mode Scott Wood
2020-01-06 22:18 ` Frederic Weisbecker
2020-01-08 23:18   ` Scott Wood

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox