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>,
Richard Cochran <richardcochran@gmail.com>,
Jie Wang <jie.wang@intel.com>, Yuan Wang <yuan1.wang@intel.com>,
Ryan Luu <rluu@amazon.com>, Julien Ridoux <ridouxj@amazon.com>,
linux-kernel@vger.kernel.org, nh-open-source@amazon.com
Subject: Re: [PATCH v2 1/6] timekeeping: Allow tick_length changes to apply mid-tick
Date: Thu, 19 Nov 2026 17:11:00 +0000 [thread overview]
Message-ID: <e280fa68d0ba8e167402b53363a554b2e7c83cee.camel@infradead.org> (raw)
In-Reply-To: <20261106030856.2538039-2-dwmw2@infradead.org>
[-- Attachment #1: Type: text/plain, Size: 3515 bytes --]
On Thu, 2026-11-05 at 19:08 -0800, David Woodhouse wrote:
> From: David Woodhouse <dwmw@amazon.co.uk>
>
> When the NTP tick length changes, timekeeping_apply_adjustment() applies
> the accounting for the new rate to ntp_error retrospectively for the
> partial tick which is currently in progress. So the ideal line of the
> clock conceptually changes from the moment of cycle_last (which can be
> almost a full tick ago), and ntp_error grows to show the difference
> between that and what userspace actually saw already.
>
> Commit c2cda2a5bda9 ("timekeeping/ntp: Don't align NTP frequency
> adjustments to ticks") removed the equivalent alignment term from the
> old accounting in 2018, precisely so that a new frequency took effect
> at the time of the update. Commit b7befd6d9120 ("timekeeping: Account
> for monotonicity adjustment in ntp_error") effectively reinstated the
> alignment, because *some* accounting is needed at that point — the
> same retrospective mult change also carries the dither and skew
> components, whose divergence genuinely does belong in ntp_error.
>
> This can lead to a significant value (10s of microseconds) landing in
> ntp_error which can take *days* to drain through the natural mult ±1
> dithering.
>
> The slow-draining ntp_error then applies a consistent bias to that ±1
> dithering, meaning that the precision of the effective frequency
> requested by userspace is limited to integer 'mult' values, since the
> dithering is no longer effective to achieve the fractional parts.
>
> Jie Wang reports that this makes phc2sys take minutes instead of
> seconds to settle CLOCK_REALTIME after a step of the PHC it follows:
> the servo slews at up to 10% and then backs off by several percent per
> second, charging tens of microseconds to ntp_error on every update. On
> a gPTP setup (ptp4l + phc2sys on back-to-back i226 NICs, PREEMPT_RT),
> the time for the phc2sys offset to settle below 100ns after a 1s step
> of the grandmaster's PHC rose from ~32s to 200-400s or more. Yuan Wang
> measured this patch alone restoring it to 32s across three consecutive
> steps, with the steady-state lock (~8ns rms) unchanged.
>
> Fix this by allowing the rate change to be conceptually applied at
> 'offset' into the partial tick, rather than the start of the tick.
> This means that the amount of delta which gets accumulated into
> ntp_error remains low.
>
> Rather than factoring this into timekeeping_apply_adjustment() which
> already makes my eyes bleed, pre-correct it when the rate changes, to
> adjust the 'intended' clock position according to the delta between
> old and new tick lengths (but leaving skew as it should be).
>
> Fixes: b7befd6d9120 ("timekeeping: Account for monotonicity adjustment in ntp_error")
> Reported-by: Jie Wang <jie.wang@intel.com>
> Closes: https://lore.kernel.org/all/20261105032150.1763572-1-yuan1.wang@intel.com/
> Cc: stable@vger.kernel.org
> Acked-by: John Stultz <jstultz@google.com>
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
> v2: Pull the dividend/mult restructure up from patch 6 so the old and
> new calculations match visually, and rewrite the comment explaining
> the mid-tick compensation (John). Add the commit archaeology, the
> gPTP symptom and measurements from Jie Wang's report, with
> Fixes/Cc: stable.
Ping? Patches 1-5 of this series are mergeable for 7.5 but this one
wants to go into 7.4 and 7.3-stable.
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6179 bytes --]
next prev parent reply other threads:[~2026-11-19 17:11 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 3:08 [PATCH v2 0/6] timekeeping: Reduce magnitude of ntp_error David Woodhouse
2026-11-06 3:08 ` [PATCH v2 1/6] timekeeping: Allow tick_length changes to apply mid-tick David Woodhouse
2026-11-19 17:11 ` David Woodhouse [this message]
2026-11-06 3:08 ` [PATCH v2 2/6] ntp: Recalculate skew_delta when the phase offset changes David Woodhouse
2026-11-06 3:08 ` [PATCH v2 3/6] timekeeping: Bound idle sleep while a phase slew is in flight David Woodhouse
2026-11-06 3:08 ` [PATCH v2 4/6] timekeeping: Reinstate proportional correction of ntp_error David Woodhouse
2026-11-06 3:08 ` [PATCH v2 5/6] pps: Always use ktime_get_snapshot_id() for pps_get_ts() David Woodhouse
2026-11-06 8:44 ` Rodolfo Giometti
2026-11-06 3:08 ` [PATCH v2 6/6] timekeeping: Apply extrapolated ntp_error to clock snapshots David Woodhouse
2026-11-06 8:44 ` Rodolfo Giometti
2026-11-06 21:35 ` David Woodhouse
2026-11-06 3:24 ` [PATCH v2 0/6] timekeeping: Reduce magnitude of ntp_error David Woodhouse
2026-11-06 8:44 ` Rodolfo Giometti
2026-11-06 18:05 ` David Woodhouse
2026-11-09 7:57 ` Rodolfo Giometti
2026-11-09 5:50 ` Wang, Yuan1
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=e280fa68d0ba8e167402b53363a554b2e7c83cee.camel@infradead.org \
--to=dwmw2@infradead.org \
--cc=giometti@enneenne.com \
--cc=jie.wang@intel.com \
--cc=jstultz@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mlichvar@redhat.com \
--cc=nh-open-source@amazon.com \
--cc=richardcochran@gmail.com \
--cc=ridouxj@amazon.com \
--cc=rluu@amazon.com \
--cc=sboyd@kernel.org \
--cc=tglx@kernel.org \
--cc=yuan1.wang@intel.com \
/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®