mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: Thomas Gleixner <tglx@kernel.org>, John Stultz <jstultz@google.com>
Cc: Stephen Boyd <sboyd@kernel.org>,
	Miroslav Lichvar <mlichvar@redhat.com>,
	Rodolfo Giometti <giometti@enneenne.com>,
	Ryan Luu <rluu@amazon.com>, Julien Ridoux <ridouxj@amazon.com>,
		linux-kernel@vger.kernel.org
Subject: Re: [PATCH 0/5] timekeeping: Reduce magnitude of ntp_error
Date: Wed, 21 Oct 2026 15:37:04 +0100	[thread overview]
Message-ID: <8431ae22ee7c7a786c93d8c0bbc85366f39291bd.camel@infradead.org> (raw)
In-Reply-To: <20261001202134.33929-1-dwmw2@infradead.org>

[-- Attachment #1: Type: text/plain, Size: 3729 bytes --]

On Thu, 2026-10-01 at 21:21 +0100, David Woodhouse wrote:
> The timekeeper's ntp_error variable tracks the delta between the ideal
> time that the kernel *should* be reporting as CLOCK_REALTIME, and the
> time that is *actually* being reported.
> 
> A previous patch series in v7.3, up to commit 794ddd6e15cf ("ntp:
> Remove tick_length_base, use tick_length directly"), fixed *errors* in
> the accounting of ntp_error — cases where the reported time would
> diverge from the ideal time *without* the divergence being correctly
> tracked in ntp_error for subsequent compensation.
> 
> This series is the next step: it reduces the magnitude of the
> excursions which are (now) *correctly* tracked in ntp_error.
> 
> The ntp_error mechanism works fine when it remains close to zero. The
> actual clock is steered back towards the ideal by a single ±1
> dithering of the per-cycle 'mult' period, changing between high and
> low each time ntp_error crosses zero.
> 
> This doesn't work as well when the value of ntp_error gets higher. In
> some cases, 83µs of ntp_error was seen. Draining that through the mult
> ±1 dithering, at typically less than 1ns/s, could take days. And while
> it does, the precision of the frequency that can be effected by the
> kernel's timekeeping is limited by the integer quantisation, because
> it's permanently biased to either mult or mult+1 according to the
> direction of the persistent ntp_error, and frequencies between the two
> values cannot be achieved by the normal dithering. On top of which,
> chrony was attempting to discipline the *reported* clock, even as
> the kernel was attempting to steer it as hard as it could (albeit
> not very hard) back to the kernel's ideal.
> 
> There are two cases where during frequency/phase adjustment, the
> change was effectively applied to the 'ideal' vs 'actual' rate at
> different moments in time. This accounting for this in ntp_error was
> self-consistent, but the better answer is for them to be conceptually
> applied at the same moment, without contributing anything to ntp_error
> at all.
> 
> While the timekeeping code is applying a phase correction, that
> applies an additional bias to the per-cycle 'mult' values. If a
> tickless kernel goes idle while this skew is being applied, it can
> continue to apply that bias *long* after it was intended to finish,
> overshooting the intended phase correction (by 500µs/s in the case of
> adjtime). Fix this in timekeeping_max_deferment() by requesting a
> wakeup at the top of the next second while phase skew is being
> applied. (NB: Only for the core timekeeper, not aux clocks which
> remain as they were).
> 
> Finally, if ntp_error ever does get excessive, we can deliberately
> apply a phase skew to return it to zero faster than the normal
> dithering would permit. An equivalent mechanism was removed in commit
> dc491596f639 ("timekeeping: Rework frequency adjustments to work
> better w/ nohz") but especially with the timekeeping_max_deferment()
> change mentioned above, this now works effectively even with (and
> in fact especially with) tickless idle. But again only for the core
> timekeeper... unless we want to wake for aux clocks too?
> 
> Tests running at https://david.woodhou.se/ntptest-virt/ on baseline
> vs. patched kernels, both tickless and periodic. The effect is seen
> most clearly on the tickless kernel, where the baseline experiences
> much higher jitter around corrections that should be smooth.

Ping? Patches 1-4 of this should be ready to merge now.

So is number 5 as far as I'm concerned, but I'm happy to entertain
further discussion if anyone has an opinion they want to share.

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6179 bytes --]

  parent reply	other threads:[~2026-10-21 14:37 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-01 20:21 David Woodhouse
2026-10-01 20:21 ` [PATCH 1/5] timekeeping: Allow tick_length changes to apply mid-tick David Woodhouse
2026-10-21 19:01   ` John Stultz
2026-10-22 13:39     ` David Woodhouse
2026-10-01 20:21 ` [PATCH 2/5] ntp: Recalculate skew_delta when the phase offset changes David Woodhouse
2026-10-21 19:05   ` John Stultz
2026-10-01 20:21 ` [PATCH 3/5] timekeeping: Bound idle sleep while a phase slew is in flight David Woodhouse
2026-10-01 20:21 ` [PATCH 4/5] timekeeping: Reinstate proportional correction of ntp_error David Woodhouse
2026-10-05 10:04   ` Miroslav Lichvar
2026-10-05 13:17     ` David Woodhouse
2026-10-01 20:21 ` [PATCH 5/5] [DO NOT MERGE] timekeeping: Apply extrapolated ntp_error to clock snapshots David Woodhouse
2026-10-02  8:30   ` Rodolfo Giometti
2026-10-02  9:14     ` David Woodhouse
2026-10-02 10:26       ` Rodolfo Giometti
2026-10-02 22:47         ` David Woodhouse
2026-10-05  8:15           ` Rodolfo Giometti
2026-10-05  8:49             ` David Woodhouse
2026-10-05 10:15               ` Rodolfo Giometti
2026-10-05 10:49                 ` David Woodhouse
2026-10-21 14:37 ` David Woodhouse [this message]
2026-10-22  9:05   ` [PATCH 0/5] timekeeping: Reduce magnitude of ntp_error Rodolfo Giometti

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=8431ae22ee7c7a786c93d8c0bbc85366f39291bd.camel@infradead.org \
    --to=dwmw2@infradead.org \
    --cc=giometti@enneenne.com \
    --cc=jstultz@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mlichvar@redhat.com \
    --cc=ridouxj@amazon.com \
    --cc=rluu@amazon.com \
    --cc=sboyd@kernel.org \
    --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®