mirror of https://lore.kernel.org/lkml/
 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 23:05:36 +0100	[thread overview]
Message-ID: <auZmMBmheFxH5Dlz@pavilion.home> (raw)
In-Reply-To: <68f0450d47577dc4f83d32e5b0211c97ee8d24bd.camel@itx.no>

Le Wed, Oct 28, 2026 at 06:37:22PM +0100, Stian Halseth a écrit :
> Hi Frederic,
> 
> On Wed, 2026-10-28 at 15:14 +0100, Frederic Weisbecker wrote:
> > 
> > So let me depict that:
> > 
> > // clocksource = jiffies ?
> > // clockevent = lapic ?
> > tick_setup_device()
> >    tick_next_period = ktime_get() // jiffies_to_nsecs(jiffies)
> > 
> > tick_periodic()
> >    tick_next_period += TICK_NSECS
> >    jiffies++ // ktime_get() == tick_next_period
> > 
> > // jiffies > tsc_early
> > clocksource_select()
> > 
> > tick_periodic()
> >    //one tick has passed, so ktime_get() == jiffies + 1
> 
> 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.

Ok now that makes sense.

> 
> >    tick_next_period += TICK_NSECS
> >    jiffies++ // ktime_get() == tick_next_period == jiffies
> 
> So after this, tick_next_period == ktime_get() + d.
> 
> The same thing as a diagram:
> 
> // jiffies -> tsc-early, d after the last tick
> clocksource_select()
>    ktime_get() == last tick          // the d is not in there
> 
> tick_periodic()                      // TICK_NSEC after the last tick
>    ktime_get() == last tick + TICK_NSEC - d
>    tick_next_period += TICK_NSEC     // == last tick + TICK_NSEC
>    // tick_next_period == ktime_get() + d
> 
> From a measurement I did with a QEMU guest: at the switch both were
> 329532326. At the next tick ktime_get() was 331212239, 1.68 ms later,
> so d was 2.32 ms, and tick_next_period became 333532326, 2.32 ms
> ahead.

I see now.

Thanks

-- 
Frederic Weisbecker
SUSE Labs

  parent reply	other threads:[~2026-10-31 22:05 UTC|newest]

Thread overview: 18+ 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
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
2026-10-31 22:05                 ` Frederic Weisbecker [this message]
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=auZmMBmheFxH5Dlz@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 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®