From: Stian Halseth <stian@itx.no>
To: Frederic Weisbecker <frederic@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
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: Re: [PATCH] sched/cputime: Don't warn when the tick period starts after idle exit
Date: Tue, 27 Oct 2026 20:05:49 +0100 [thread overview]
Message-ID: <bd9b6592bce4b8f2e802518bf2cad561af61e78e.camel@itx.no> (raw)
In-Reply-To: <auDaMdhD2zGBLhDE@localhost.localdomain>
[-- Attachment #1: Type: text/plain, Size: 2517 bytes --]
Hi Frederic,
On Tue, 2026-10-27 at 18:06 +0100, Frederic Weisbecker wrote:
> Ok let me try to picture this:
>
> Initially, jiffies or tsc-early, not sure, is the clocksource:
>
> - tick_setup_device() sets tick_next_period to ktime_get()
> - tick_periodic() adds TICK_NSEC to tick_next_period right before updating
> jiffies. So as you said tick_next_period == ktime_get()
> - Note last_tick is not involved in that mode
>
> Then later on boot comes a oneshot device:
The clocksource is initially jiffies, and I believe there is a step missing
before the oneshot switch: the clocksource switch, while the tick is still
periodic.
Please let me know where I lose you, or if/when you disagree with
my analysis. Not sure if you're more confused about my attempt of an
explanation, or by what's really happening ;)
Here we go...
The oneshot switch can only happen inside a tick, so at the earliest
in the first tick after the clocksource switch. In the guest it came
0.7s later since tsc-early waits for the watchdog in the guest.
So...for a while tick_periodic() runs on tsc-early. ktime now moves
between ticks too, but the next tick still adds a full TICK_NSEC, so
tick_next_period gets ahead of ktime_get() by the part of the period
that had passed at the switch. Still here? :)
In the guest that was measured at 2.3ms. With a periodic lapic it
stays that way, with the TSC deadline timer the following tick is
programmed from ktime again so it is gone, but in Paul's case the
oneshot switch happens in that first tick after the clocksource
switch, so it is still there.
Then finally tick_init_jiffy_update() aligns it upwards. It is not
tick aligned to start with since ktime starts at the sched_clock boot
offset, so that can add most of another tick, and that becomes the
first expiry of the sched timer.
hrtimer_forward_now() doesn't touch it since it is already in the
future. In the guest it ended up 4.66 ms after now at HZ=250, and
tick_do_update_jiffies64() returns early until now gets there.
>
> last_tick actually gets its first value when the tick is stopped for the
> first time in tick_nohz_stop_tick() and is set to the next tick that won't
> happen.
Yes, that expiry. A stop in the first 0.66 ms saves it as last_tick,
and kcpustat_dyntick_stop() then has last_tick - TICK_NSEC still in
the future. I never caught the stop itself in the guest, but Paul's
registers show now 235623102 and tick_start 236000000.
/Stian
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
prev parent reply other threads:[~2026-10-27 19:05 UTC|newest]
Thread overview: 10+ 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 ` [PATCH] sched/cputime: Don't warn when the tick period starts after idle exit Stian Halseth
2026-10-26 16:42 ` Frederic Weisbecker
2026-10-26 17:28 ` Stian Halseth
2026-10-27 17:06 ` Frederic Weisbecker
2026-10-27 19:05 ` Stian Halseth [this message]
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=bd9b6592bce4b8f2e802518bf2cad561af61e78e.camel@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®