From: David Woodhouse <dwmw2@infradead.org>
To: "Richard Cochran" <richardcochran@gmail.com>,
"Wen Gu" <guwen@linux.alibaba.com>,
"David Woodhouse" <dwmw2@infradead.org>,
"Andrew Lunn" <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"John Stultz" <jstultz@google.com>,
"Thomas Gleixner" <tglx@kernel.org>,
"Stephen Boyd" <sboyd@kernel.org>,
"Anna-Maria Behnsen" <anna-maria@linutronix.de>,
"Frederic Weisbecker" <frederic@kernel.org>,
"Shuah Khan" <shuah@kernel.org>,
"Peter Zijlstra" <peterz@infradead.org>,
"Thomas Weißschuh" <thomas.weissschuh@linutronix.de>,
"Arnd Bergmann" <arnd@arndb.de>,
"Miroslav Lichvar" <mlichvar@redhat.com>,
"Julien Ridoux" <ridouxj@amazon.com>,
"Ryan Luu" <rluu@amazon.com>,
linux-kernel@vger.kernel.org
Subject: [RFC PATCH v3 00/10] timekeeping: Fix drift tracking precision and add feed-forward discipline via vmclock
Date: Wed, 20 May 2026 14:33:39 +0100 [thread overview]
Message-ID: <20260520135207.37826-1-dwmw2@infradead.org> (raw)
This is v3 of the series to allow feed-forward clock discipline, allowing
a guest kernel to lock its system clock directly to a hypervisor-provided
vmclock reference with nanosecond precision and no drift.
With all the drift-inducing bugs in the core timekeeping resolved in the
first patches of the series, the RFC timekeeping_set_reference()
function basically just sets the tick length and time_offset according
to the reference, and lets the now-fixed core timekeeping get on with
its job.
The vmclock device (https://uapi-group.org/specifications/specs/vmclock/)
provides a shared memory page containing a linear time function:
time = base + (counter - counter_value) × period. The guest can read
this at any time to determine the hypervisor's view of the current time,
without a VM exit. Unlike guest-driven NTP, it allows for accurate time
to be preserved across live migration.
The existing ptp_vmclock driver already exposes this as a PTP clock for
userspace consumers (phc2sys, chrony). This series adds kernel-internal
consumption: the tick mechanism can clamp directly to the vmclock
reference, eliminating the need for NTP to discipline the guest clock.
Now testing *without* nohz in the guest, I no longer see single-digit
nanoseconds of jitter; I wouldn't describe it as being that high. It
goes to ±1ns and stays there, although it does take a while to converge
since dropping the exponential tail clamping.
Changes since v2:
• Renamed "clawback" to "monotonicity adjustment" throughout (patch 2).
• Drop the exponential tail clamping (v2 patch 3).
• Convert adjtime() to use time_offset to deliver skew too, and remove
the separate 'tick_length_base' as adjusting tick_length directly is
no longer used to skew the clock. The skew_delta basically does the
same thing, but is easier to get the accounting right.
• The timekeeping_set_reference() API (patch 8) now takes tk_core.lock
and computes the phase offset internally, eliminating the race window
that existed in v2 between setting the reference and the tick code
consuming it.
• vmclock_host (patch 10) is no longer marked WIP — it has a selftest
and proper locking (but is still RFC).
• Added MAINTAINERS entry for Miroslav Lichvar as timekeeping reviewer
(patch 1).
The series:
Patch 1: MAINTAINERS update
1. Add Miroslav Lichvar as timekeeping reviewer.
Patches 2-3: Timekeeping bugfixes (suitable for stable/independent review)
2. Remove stale xtime_remainder from ntp_error accumulation.
3. Account for monotonicity adjustment in ntp_error.
Patch 4: Independent bugfix
4. Guard against divide-by-zero during clocksource recalibration.
Patches 5-7: NTP rework — eliminate tick_length_base
5. Drive time_offset skew via per-tick ntp_error transfer instead of
tick_length inflation, with mult adjustment for dithering bandwidth.
6. Convert adjtime() to use time_offset directly instead of inflating
tick_length, removing the rounding loss that prevented convergence.
7. Remove tick_length_base entirely — tick_length is now always the
NTP-disciplined value with no per-tick inflation.
Patches 8-9: Feed-forward reference clock infrastructure
8. Add timekeeping_set_reference() API for external clock references.
9. Wire ptp_vmclock to call timekeeping_set_reference() on probe.
Patch 10: Host-side vmclock page export
10. Add /dev/vmclock_host miscdev for VMM consumption, with selftest.
Tested with QEMU passing through a vmclock device to a guest. The guest
clock converges to the reference within seconds and remains within
single-digit nanoseconds indefinitely, with no further external
correction.
https://git.infradead.org/?p=users/dwmw2/qemu.git;a=shortlog;h=refs/heads/vmclock-passthrough
David Woodhouse (10):
MAINTAINERS: Add Miroslav as timekeeping reviewer
timekeeping: Remove xtime_remainder from ntp_error accumulation
timekeeping: Account for monotonicity adjustment in ntp_error
timekeeping: Guard against divide-by-zero in timekeeping_adjust
timekeeping: Drive time_offset skew via per-tick ntp_error transfer
ntp: Convert adjtime() to use time_offset instead of tick_length inflation
ntp: Remove tick_length_base, use tick_length directly
timekeeping: Add absolute reference for feed-forward clock discipline
ptp_vmclock: Feed reference to timekeeping for feed-forward discipline
kernel/time: Add /dev/vmclock_host miscdev
MAINTAINERS | 1 +
drivers/ptp/ptp_vmclock.c | 95 +++++
include/linux/timekeeper_internal.h | 6 +-
include/linux/timekeeping_reference.h | 19 +
kernel/time/Kconfig | 7 +
kernel/time/Makefile | 1 +
kernel/time/ntp.c | 132 +++++--
kernel/time/ntp_internal.h | 9 +
kernel/time/timekeeping.c | 76 +++-
kernel/time/vmclock_host.c | 391 +++++++++++++++++++++
tools/testing/selftests/timers/vmclock_host_test.c | 171 +++++++++
11 files changed, 867 insertions(+), 41 deletions(-)
next reply other threads:[~2026-05-20 13:52 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-20 13:33 David Woodhouse [this message]
2026-05-20 13:33 ` [RFC PATCH v3 01/10] MAINTAINERS: Add Miroslav as timekeeping reviewer David Woodhouse
2026-05-20 23:28 ` John Stultz
2026-05-20 13:33 ` [RFC PATCH v3 02/10] timekeeping: Remove xtime_remainder from ntp_error accumulation David Woodhouse
2026-05-22 11:41 ` David Woodhouse
2026-05-29 23:21 ` John Stultz
2026-05-30 10:51 ` David Woodhouse
2026-05-20 13:33 ` [RFC PATCH v3 03/10] timekeeping: Account for monotonicity adjustment in ntp_error David Woodhouse
2026-05-20 23:27 ` John Stultz
2026-05-20 23:36 ` David Woodhouse
2026-05-20 13:33 ` [RFC PATCH v3 04/10] timekeeping: Guard against divide-by-zero in timekeeping_adjust David Woodhouse
2026-05-20 23:29 ` John Stultz
2026-05-20 13:33 ` [RFC PATCH v3 05/10] timekeeping: Drive time_offset skew via per-tick ntp_error transfer David Woodhouse
2026-05-20 13:33 ` [RFC PATCH v3 06/10] ntp: Convert adjtime() to use time_offset instead of tick_length inflation David Woodhouse
2026-05-20 13:33 ` [RFC PATCH v3 07/10] ntp: Remove tick_length_base, use tick_length directly David Woodhouse
2026-05-20 13:33 ` [RFC PATCH v3 08/10] timekeeping: Add absolute reference for feed-forward clock discipline David Woodhouse
2026-05-20 13:33 ` [RFC PATCH v3 09/10] ptp_vmclock: Feed reference to timekeeping for feed-forward discipline David Woodhouse
2026-05-20 13:33 ` [RFC PATCH v3 10/10] kernel/time: Add /dev/vmclock_host miscdev David Woodhouse
2026-05-21 6:29 ` Wen Gu
2026-05-28 16:18 ` David Woodhouse
2026-05-23 11:49 ` [RFC PATCH v3 00/10] timekeeping: Fix drift tracking precision and add feed-forward discipline via vmclock David Woodhouse
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=20260520135207.37826-1-dwmw2@infradead.org \
--to=dwmw2@infradead.org \
--cc=andrew+netdev@lunn.ch \
--cc=anna-maria@linutronix.de \
--cc=arnd@arndb.de \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=frederic@kernel.org \
--cc=guwen@linux.alibaba.com \
--cc=jstultz@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mlichvar@redhat.com \
--cc=pabeni@redhat.com \
--cc=peterz@infradead.org \
--cc=richardcochran@gmail.com \
--cc=ridouxj@amazon.com \
--cc=rluu@amazon.com \
--cc=sboyd@kernel.org \
--cc=shuah@kernel.org \
--cc=tglx@kernel.org \
--cc=thomas.weissschuh@linutronix.de \
/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®