tick-sched: Warn when next tick seems to be in the past
authorAnna-Maria Behnsen <anna-maria@linutronix.de>
Fri, 1 Dec 2023 09:26:25 +0000 (10:26 +0100)
committerThomas Gleixner <tglx@linutronix.de>
Wed, 20 Dec 2023 15:49:38 +0000 (16:49 +0100)
When the next tick is in the past, the delta between basemono and the next
tick gets negativ. But the next tick should never be in the past. The
negative effect of a wrong next tick might be a stop of the tick and timers
might expire late.

To prevent expensive debugging when changing underlying code, add a
WARN_ON_ONCE into this code path. To prevent complete misbehaviour, also
reset next_tick to basemono in this case.

Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Frederic Weisbecker <frederic@kernel.org>
Link: https://lore.kernel.org/r/20231201092654.34614-4-anna-maria@linutronix.de
kernel/time/tick-sched.c

index fce3c6f0e4a672936e495e9dfcfd0ef098a2f3d0..a17d26002831008ae657d2c063f9ff01e2ad709c 100644 (file)
@@ -839,6 +839,10 @@ static ktime_t tick_nohz_next_event(struct tick_sched *ts, int cpu)
                ts->next_timer = next_tick;
        }
 
+       /* Make sure next_tick is never before basemono! */
+       if (WARN_ON_ONCE(basemono > next_tick))
+               next_tick = basemono;
+
        /*
         * If the tick is due in the next period, keep it ticking or
         * force prod the timer.