From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72FE43DD532 for ; Wed, 20 May 2026 13:52:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779285156; cv=none; b=YoEwSTGzU6J0kKJ3YTXc04CPbctQbvTYGedMfi38jfeTG5tjH21SPZEQd1bTDhdTNrPnlXCjOrELa/F69qh3zNS6EB2Ly64lGwfnY5pXLLRSGOLU1TFEM/V/9S7dvyGo1y0feMdPErvGPu20aMG7XRA/CuLZhtqHKDYSAW2uOa0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779285156; c=relaxed/simple; bh=o2dYoNBW7CYVxvNvKGSxddOtZMLuG/eeDTHwhGdoRUY=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=fVyCLa+QPxi/rCU0fMJ7vG33SXm6po0A7UfLMCFZ1+SJJMdATGek7n9olCYu7UM3+EO9/XJuKC4i79ampJElU96rMaxwqX0nOVWdKvijnuA5h3GvW3VJmzBoTCmjUxTW3rYujILVb2YeVtVgpatN/SDrNOqXPOBcb8AVEy7NPRQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=desiato.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=Aq8AYhYx; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=desiato.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Aq8AYhYx" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Message-ID:Date:Subject:To:From:Reply-To:Cc: Content-ID:Content-Description:In-Reply-To:References; bh=ycgkYI9YEFzszBxd03JBpuSSSHU9AUWlUt8Vk8XeNxg=; b=Aq8AYhYxTcnwiXaFLX1Q6HE21w qIOGYKQGNQtrwK4YfMNnFqQLWLpwTFjeLJNPY10bx2nld1gGNoLwpNwCH+FJKlemBouseFAttX1CG QsleGUU1kyVsrGlvEgEGapYpXRe3DwryV2cF1rbiW9D3ler2OXPeytQkxnQ+rrGTH/KDCn4YoS9PQ kMDzMoOusZdBFGgWWlwm4sSu3fb/fKf+X2/rI4oOZbdrHjuSuEfu2lInrwJewIa9H5VnHrtElsbQR Ux/ajlnok2+0TTdh3SZLW0N4nUQMPPbWNVRe0JbkT+epuk/uJkIAEVFuThlOsBELuAW3PWZEmGTEG swt0kiFA==; Received: from i7.infradead.org ([2001:8b0:10b:1:21e:67ff:fecb:7a92]) by desiato.infradead.org with esmtpsa (Exim 4.99.1 #2 (Red Hat Linux)) id 1wPhLF-0000000Gz9w-3Xip; Wed, 20 May 2026 13:52:10 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.99.2 #2 (Red Hat Linux)) id 1wPhLF-000000009tE-1LxK; Wed, 20 May 2026 14:52:09 +0100 From: David Woodhouse To: Richard Cochran , Wen Gu , David Woodhouse , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , John Stultz , Thomas Gleixner , Stephen Boyd , Anna-Maria Behnsen , Frederic Weisbecker , Shuah Khan , Peter Zijlstra , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Arnd Bergmann , Miroslav Lichvar , Julien Ridoux , Ryan Luu , 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 Message-ID: <20260520135207.37826-1-dwmw2@infradead.org> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: David Woodhouse X-SRS-Rewrite: SMTP reverse-path rewritten from by desiato.infradead.org. See http://www.infradead.org/rpr.html 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(-)