mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stian Halseth <stian@itx.no>
To: Frederic Weisbecker <frederic@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>
Cc: Paul Menzel <pmenzel@molgen.mpg.de>,
	Thomas Gleixner <tglx@kernel.org>,
	Anna-Maria Behnsen <anna-maria@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>,
	Shrikanth Hegde <sshegde@linux.ibm.com>,
	regressions@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH] sched/cputime: Don't warn when the tick period starts after idle exit
Date: Sun, 25 Oct 2026 11:02:02 +0100	[thread overview]
Message-ID: <20261025100202.2584654-1-stian@itx.no> (raw)
In-Reply-To: <bfe9b14a-6e65-41c5-b638-26f6e033788b@molgen.mpg.de>

kcpustat_dyntick_stop() warns if idle ends before the current tick
period has started. It fired once during boot on a Dell XPS 13, in
CPU 0's first idle period, right after the switch from refined-jiffies
to tsc-early.

That can happen. The clocksource switch continues ktime from the last
jiffies update, so ktime falls behind the tick by up to a tick, and the
sched timer that NOHZ arms next on tick_next_period can expire more
than a tick after now. In a KVM guest it was 1.5 ticks ahead after a
switch from jiffies to hpet. An idle period that stops the tick and
exits before it fires then sees ts->last_tick - TICK_NSEC after now.

The tick restart keeps ts->last_tick in that case, so the first tick
covers a period after the idle exit and nothing overlaps, which the
code already handles. Drop the warning.

Fixes: 96a494c9cfd8 ("sched/cputime: Don't account idle time twice after dyntick-idle")
Reported-by: Paul Menzel <pmenzel@molgen.mpg.de>
Closes: https://lore.kernel.org/all/bfe9b14a-6e65-41c5-b638-26f6e033788b@molgen.mpg.de/
Signed-off-by: Stian Halseth <stian@itx.no>
---
I could not hit the window in a KVM guest, but instrumented, the guest
showed the sched timer armed 5.9 ms after now at HZ=250 right after a
jiffies -> hpet switch, and tick stops saving a ts->last_tick more than
a tick ahead. The fix boots without warnings there.

 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 9e0fb8633d823..17f3cbd5d403a 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;
-- 
2.43.0


  parent reply	other threads:[~2026-10-25 10:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-07 14:29 [PATCH v3] sched/cputime: Don't account idle time twice after dyntick-idle Stian Halseth
2026-10-14 12:17 ` Frederic Weisbecker
2026-10-16  8:01 ` [tip: sched/core] " tip-bot2 for Stian Halseth
2026-10-25  7:27 ` WARNING: kernel/sched/cputime.c:481 at kcpustat_dyntick_stop+0x8b/0xa0, CPU#0: swapper/0/0 (was: [PATCH v3] sched/cputime: Don't account idle time twice after dyntick-idle) Paul Menzel
2026-10-25  8:13   ` Stian Halseth
2026-10-25 10:02   ` Stian Halseth [this message]
2026-10-26 16:42     ` [PATCH] sched/cputime: Don't warn when the tick period starts after idle exit Frederic Weisbecker
2026-10-26 17:28       ` Stian Halseth

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=20261025100202.2584654-1-stian@itx.no \
    --to=stian@itx.no \
    --cc=anna-maria@linutronix.de \
    --cc=frederic@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=pmenzel@molgen.mpg.de \
    --cc=regressions@lists.linux.dev \
    --cc=sshegde@linux.ibm.com \
    --cc=tglx@kernel.org \
    /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

all inboxes | Powered by JetHome®