[tip: sched/urgent] sched/cputime: Don't warn when the tick period starts after idle exit

From: tip-bot2 for Stian Halseth

Date: Sun Nov 01 2026 - 01:50:31 EST


The following commit has been merged into the sched/urgent branch of tip:

Commit-ID: b327e63683a2b894b500027375342c25222b58ef
Gitweb: https://git.kernel.org/tip/b327e63683a2b894b500027375342c25222b58ef
Author: Stian Halseth <stian@xxxxxx>
AuthorDate: Sat, 31 Oct 2026 09:14:07 +01:00
Committer: Ingo Molnar <mingo@xxxxxxxxxx>
CommitterDate: Sun, 01 Nov 2026 07:32:38 +01:00

sched/cputime: Don't warn when the tick period starts after idle exit

kcpustat_dyntick_stop() warns if idle ends before the tick period
that the next tick will account has started. That happens on x86 in
a CPU's first idle period with the tick stopped, right after the
switch from the jiffies clocksource to tsc-early.

On the jiffies clocksource ktime only moves at the tick. When the
clocksource switches some time d after a tick, that d is lost: ktime
continues from the value of the last tick. The next tick comes
TICK_NSEC after the last one, but ktime has only moved TICK_NSEC - d,
while tick_periodic() still adds a full TICK_NSEC to tick_next_period,
which is now d ahead of ktime. When NOHZ starts,
tick_init_jiffy_update() rounds it up to a multiple of TICK_NSEC and
the sched timer is armed there, up to nearly two ticks after now. A
tick stop saves that as ts->last_tick, and an idle exit before now
reaches ts->last_tick - TICK_NSEC sees the tick period in the future.

Nothing is accounted twice then. The first tick covers a period that
starts after the idle exit, and the code already handles it. Drop the
warning.

Fixes: 96a494c9cfd8 ("sched/cputime: Don't account idle time twice after dyntick-idle")
Reported-by: Paul Menzel <pmenzel@xxxxxxxxxxxxx>
Reported-by: Breno Leitao <leitao@xxxxxxxxxx>
Reported-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Reviewed-by: Kayra Cizmeci <kayracizmeci@xxxxxxxxx>
Reviewed-by: Frederic Weisbecker <frederic@xxxxxxxxxx>
Signed-off-by: Stian Halseth <stian@xxxxxx>
Signed-off-by: Ingo Molnar <mingo@xxxxxxxxxx>
Link: https://lore.kernel.org/all/auTCQauaU733PY5z@xxxxxxxxx/
Link: https://lore.kernel.org/all/CAHk-=winC2u2D1FAX5grfq9F=bxmARxhuiQ4MvHAiJFu3iF6gw@xxxxxxxxxxxxxx/
Link: https://patch.msgid.link/20261031081408.3378884-1-stian@xxxxxx
Closes: https://lore.kernel.org/all/bfe9b14a-6e65-41c5-b638-26f6e033788b@xxxxxxxxxxxxx/
--
kernel/sched/cputime.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
---
kernel/sched/cputime.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 9e0fb86..17f3cbd 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -478,7 +478,12 @@ void kcpustat_dyntick_stop(u64 now, u64 tick_start)
kc->idle_tick_overlap = 0;
}
tick_start = max(tick_start, kc->idle_dyntick_entry);
- if (!WARN_ON_ONCE(now < tick_start))
+ /*
+ * After a switch from the jiffies clocksource the tick can be
+ * armed more than a tick ahead, so the period may not have
+ * started yet.
+ */
+ if (now > tick_start)
kc->idle_tick_overlap += now - tick_start;
kcpustat_idle_stop(kc, now);
kc->idle_dyntick = false;