All of lore.kernel.org
 help / color / mirror / Atom feed
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: Sat, 31 Oct 2026 22:54:52 +0100	[thread overview]
Message-ID: <auZjrNbfXPv_L6J7@pavilion.home> (raw)
In-Reply-To: <a4ba7e5be50ed4de4cad3d3e53355eb533587694.camel@itx.no>

Le Sat, Oct 31, 2026 at 03:11:46PM +0100, Stian Halseth a écrit :
> Hi Frederic,
> 
> 
> On Sat, 2026-10-31 at 14:54 +0100, Frederic Weisbecker wrote:
> > > 
> > > Here is where it goes wrong. One tick has passed in real time, but not
> > > in ktime. The switch happened d after the last tick, jiffies never
> > > counted that d, and the tsc only counts from the switch on, so here
> > > ktime_get() == jiffies + TICK_NSEC - d.
> > 
> > So that assume that during the clocksource switch, the new clock synchronize
> > with the old one so that ktime_get() from the new clock should start from
> > the last value of the old clock. I'm having troubles to verify if
> > tk_setup_internals() does exactly that. 
> 
> Not that one, the timekeeping_forward_now() just before it. It folds
> the old clock into xtime_nsec, and tk_setup_internals() keeps that and
> only resets cycle_last from the new clock. On jiffies that value is the
> last tick.

Ah yes! You got it!

> 
> > 
> > [    1.549194] old= 1352575566
> > [    1.549930] new= 1352578748
> > [    1.550636] clocksource: Switched to clocksource tsc-early
> > 
> > That's 3 us, it could be the simple difference between the 2 printk.
> 
> Look at the timestamps: 736 us passed between the two printks, but
> ktime moved 3 us. The 3 us is tsc-early, from the read in
> tk_setup_internals() to your second ktime_get(). The time from the
> last tick to the first printk, plus the 733 us from there to
> tk_setup_internals(), is never counted. That is the d. If you print
> ktime_get() in tick_periodic() as well, old= will match the previous
> tick exactly.

Makes sense.

> 
> > 
> > But the switch from tsc-early to tsc is much more:
> > 
> > [    2.639818] old= 2445754540
> > [    2.640172] new= 2446107950
> > [    2.640927] clocksource: Switched to clocksource tsc
> > 
> > That's 353 us.
> 
> Here the printks are 354 us apart and ktime moved 353 us. Both clocks
> run, so nothing is lost: tsc-early counts up to the switch and tsc
> continues from there.

Now that's clear!

Thanks.

-- 
Frederic Weisbecker
SUSE Labs

  reply	other threads:[~2026-10-31 21:54 UTC|newest]

Thread overview: 17+ 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-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
2026-10-28 14:14             ` Frederic Weisbecker
2026-10-28 17:37               ` Stian Halseth
2026-10-31 13:54                 ` Frederic Weisbecker
2026-10-31 14:11                   ` Stian Halseth
2026-10-31 21:54                     ` Frederic Weisbecker [this message]
2026-10-31 22:05                 ` Frederic Weisbecker
2026-10-30 16:14     ` Breno Leitao
2026-10-30 20:48       ` 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=auZjrNbfXPv_L6J7@pavilion.home \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.