From: Frederic Weisbecker <frederic@kernel.org>
To: Stian Halseth <stian@itx.no>
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 18:06:57 +0100 [thread overview]
Message-ID: <auDaMdhD2zGBLhDE@localhost.localdomain> (raw)
In-Reply-To: <1e00b909b81c6195b3ad5aeda207d20cbedc3971.camel@itx.no>
Le Mon, Oct 26, 2026 at 06:28:44PM +0100, Stian Halseth a écrit :
> Hi Frederic,
>
>
> On Mon, 2026-10-26 at 17:42 +0100, Frederic Weisbecker wrote:
> >
> > I'm a bit confused by the scenario that happens here. Do you mean
> > that after switching from a clocksource to another, ktime_get() goes
> > backward?
>
> No, not going backward, my description was vague, sorry.
> It's tick_next_period that runs ahead, not ktime going back.
>
> Also, please challenge my assumptions, as I might be analyzing this
> wrong. This codebase is still pretty new to me, and I might
> misinterpret some things.
>
> But from how I see it, on jiffies, ktime only moves at the tick. So
> seen from the tick's point of view, tick_next_period == ktime_get().
>
> After the switch ktime keeps moving between ticks, but the next tick
> still adds a full TICK_NSEC, so tick_next_period ends up ahead of now
> by the part of the period that jiffies never counted.
> In a KVM guest at HZ=250 that was 2.3 ms.
>
> Do you follow my reasoning?
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:
- tick_init_jiffy_update() adjusts tick_next_period to be aligned to TICK_NSEC
- tick_sched_do_timer() -> tick_do_update_jiffies64() sets tick_next_period to
roughly ktime_get() + TICK_NSEC
>
> >
> > Also refine-jiffies is not a suitable clocksource for nohz, so
> > last_tick shouldn't be updated while refine-jiffies is the
> > clocksource.
>
> Yes, right. last_tick gets its first value from the sched timer expiry,
> which is that tick_next_period rounded up to a tick multiple by
> tick_init_jiffy_update().
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.
>
> In the guest that made the first expiry 4.66 ms after now, so for the
> first 0.66 ms a tick stop leaves last_tick - TICK_NSEC in the future.
> Paul's registers show the same, now 235623102 with last_tick
> 240000000.
>
> I can rewrite the commit message along these lines, or fix up
> tick_next_period at the switch instead if you prefer that.
I'm still confused by what is actually happening.
Thanks.
>
> /Stian
--
Frederic Weisbecker
SUSE Labs
next prev parent reply other threads:[~2026-10-27 17:07 UTC|newest]
Thread overview: 11+ 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 [this message]
2026-10-27 19:05 ` Stian Halseth
2026-10-28 14:14 ` Frederic Weisbecker
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=auDaMdhD2zGBLhDE@localhost.localdomain \
--to=frederic@kernel.org \
--cc=anna-maria@linutronix.de \
--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=stian@itx.no \
--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®