Skip to contentSkip to conversation

ptp: split non-host-disciplined PHC drivers into a dedicated subdirectory

PATCH In review Wen Gu 2 participants 5 messages Jun 30 – Jul 1

Subsystems (7)
lore
Share & tools
lore

Wen Gu

author
#0 lore raw

v3 cover ptp: split non-host-disciplined PHC drivers into a dedicated subdirectory

Hi all,

This series follows the discussion in RFC [1-2], v1 [3] and v2 [4].

# Background

The PTP Hardware Clock (PHC) interface (/dev/ptpX and the standard PTP_* ioctls) is used by two distinct classes of drivers in drivers/ptp/:
host-disciplined PHC drivers whose frequency and phase are adjusted by the host's time synchronization stack, and non-host-disciplined PHC drivers that expose an external precision time reference and are read-only. Several non-host-disciplined PHC drivers already exist in the kernel [5-9], and more are expected to appear [10-11].

During review of incoming non-host-disciplined PHC drivers, concerns were raised that they may not be a good fit for the netdev maintainership model [12], where all PTP/PHC drivers are currently maintained. This leaves an unclear upstream home and maintainership model for this class of drivers.

# Proposal

This series makes the separation explicit by reorganizing the drivers/ptp/ layout into the following groups:

- drivers/ptp/ : PTP core infrastructure and host-disciplined
PHC drivers.

- drivers/ptp/emulated/ : non-host-disciplined PHC drivers that expose precision time from hypervisors, platforms, or firmware. These clocks are read-only and not adjusted by the host.

Patch 1 performs the directory reorganization: move drivers and split Kconfig/Makefiles accordingly, without intended functional changes.

Patch 2 updates MAINTAINERS to match the new layout and adds a dedicated entry for drivers/ptp/emulated/.

No userspace ABI changes are intended; this is a refactor and maintenance metadata update only.

# Changes since v2:

- List David Woodhouse as the sole maintainer (M:) of emulated PTP drivers as suggested by Jakub. Wen Gu and Xuan Zhuo are listed as reviewers (R:).

- Updated the T: field to use David's tree:
git://git.infradead.org/linux-ptp.git

- Reworded commit messages to clarify the distinction between the two groups as host-disciplined vs. read-only (devices that purport to know real time better than the host).

# Changes since v1:

- List David Woodhouse as the maintainer of emulated PTP drivers.

- Adjust the directory layout: instead of creating both ieee1588/ and emulated/ subdirectories, keep the network-oriented drivers in the main drivers/ptp/ directory and only split out the emulated drivers.

# Changes since RFC v2:

- Keep ptp_ocp under the network-oriented PTP drivers as suggested by Jakub.

Thanks for any input.

Regards.

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
[4] https://lore.kernel.org/all/[email protected]/
[5] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a0e136d436ded817c0aade72efdefa56a00b4e5e
[6] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7d10001e20e46ad6ad95622164686bc2cbfc9802
[7] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=2d7de7a3010d713fb89b7ba99e6fdc14475ad106
[8] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=3716a49a81ba19dda7202633a68b28564ba95eb5
[9] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=9a17125a18f9ae1e1233a8e2d919059445b9d6fd
[10] https://lore.kernel.org/netdev/[email protected]/
[11] https://lore.kernel.org/mhi/[email protected]/
[12] https://lore.kernel.org/netdev/[email protected]/

Wen Gu (2):
ptp: move non-host-disciplined clock drivers into a dedicated
subdirectory
MAINTAINERS: update PTP maintainer entries after directory split

 MAINTAINERS                                 | 21 +++++--
 drivers/ptp/Kconfig                         | 55 +------------------
 drivers/ptp/Makefile                        | 11 ++--
 drivers/ptp/emulated/Kconfig                | 61 +++++++++++++++++++++
 drivers/ptp/emulated/Makefile               | 11 ++++
 drivers/ptp/{ => emulated}/ptp_kvm_arm.c    |  0
 drivers/ptp/{ => emulated}/ptp_kvm_common.c |  0
 drivers/ptp/{ => emulated}/ptp_kvm_x86.c    |  0
 drivers/ptp/{ => emulated}/ptp_s390.c       |  0
 drivers/ptp/{ => emulated}/ptp_vmclock.c    |  0
 drivers/ptp/{ => emulated}/ptp_vmw.c        |  0
 11 files changed, 94 insertions(+), 65 deletions(-)
 create mode 100644 drivers/ptp/emulated/Kconfig
 create mode 100644 drivers/ptp/emulated/Makefile
 rename drivers/ptp/{ => emulated}/ptp_kvm_arm.c (100%)
 rename drivers/ptp/{ => emulated}/ptp_kvm_common.c (100%)
 rename drivers/ptp/{ => emulated}/ptp_kvm_x86.c (100%)
 rename drivers/ptp/{ => emulated}/ptp_s390.c (100%)
 rename drivers/ptp/{ => emulated}/ptp_vmclock.c (100%)
 rename drivers/ptp/{ => emulated}/ptp_vmw.c (100%)
Signature · 1 line
2.43.5
author
#1 lore raw

PATCH v3 1/2 ptp: move non-host-disciplined clock drivers into a dedicated subdirectory

The PTP subsystem today contains both host-disciplined PHC drivers and various clock implementations that expose external precision time sources via the PTP interface but are not disciplined by the host.

Move the latter into a dedicated subdirectory to prepare for clearer ownership and maintenance boundaries:

- drivers/ptp/ : PTP core infrastructure and host-disciplined
PHC drivers.

- drivers/ptp/emulated/ : PHC drivers that expose precision time from hypervisors, platforms, or firmware. These clocks are read-only and not host-disciplined.

No functional changes are intended; this is a directory reorganization only.

---
 drivers/ptp/Kconfig                         | 55 +------------------
 drivers/ptp/Makefile                        | 11 ++--
 drivers/ptp/emulated/Kconfig                | 61 +++++++++++++++++++++
 drivers/ptp/emulated/Makefile               | 11 ++++
 drivers/ptp/{ => emulated}/ptp_kvm_arm.c    |  0
 drivers/ptp/{ => emulated}/ptp_kvm_common.c |  0
 drivers/ptp/{ => emulated}/ptp_kvm_x86.c    |  0
 drivers/ptp/{ => emulated}/ptp_s390.c       |  0
 drivers/ptp/{ => emulated}/ptp_vmclock.c    |  0
 drivers/ptp/{ => emulated}/ptp_vmw.c        |  0
 10 files changed, 78 insertions(+), 60 deletions(-)
 create mode 100644 drivers/ptp/emulated/Kconfig
 create mode 100644 drivers/ptp/emulated/Makefile
 rename drivers/ptp/{ => emulated}/ptp_kvm_arm.c (100%)
 rename drivers/ptp/{ => emulated}/ptp_kvm_common.c (100%)
 rename drivers/ptp/{ => emulated}/ptp_kvm_x86.c (100%)
 rename drivers/ptp/{ => emulated}/ptp_s390.c (100%)
 rename drivers/ptp/{ => emulated}/ptp_vmclock.c (100%)
 rename drivers/ptp/{ => emulated}/ptp_vmw.c (100%)
drivers/ptp/Kconfig +2 -53
index b93640ca08b7..19ec509cb365 100644
@@ -119,35 +119,6 @@ config PTP_1588_CLOCK_PCH
 	  To compile this driver as a module, choose M here: the module
 	  will be called ptp_pch.
 
-config PTP_1588_CLOCK_KVM
-	tristate "KVM virtual PTP clock"
-	depends on PTP_1588_CLOCK
-	depends on (KVM_GUEST && X86) || (HAVE_ARM_SMCCC_DISCOVERY && ARM_ARCH_TIMER)
-	default y
-	help
-	  This driver adds support for using kvm infrastructure as a PTP
-	  clock. This clock is only useful if you are using KVM guests.
-
-	  To compile this driver as a module, choose M here: the module
-	  will be called ptp_kvm.
-
-config PTP_1588_CLOCK_VMCLOCK
-	tristate "Virtual machine PTP clock"
-	depends on X86_TSC || ARM_ARCH_TIMER
-	depends on PTP_1588_CLOCK && ARCH_SUPPORTS_INT128
-	default PTP_1588_CLOCK_KVM
-	help
-	  This driver adds support for using a virtual precision clock
-	  advertised by the hypervisor. This clock is only useful in virtual
-	  machines where such a device is present.
-
-	  Unlike the KVM virtual PTP clock, the VMCLOCK device offers support
-	  for reliable timekeeping even across live migration. So this driver
-	  is enabled by default whenever the KVM PTP clock is.
-
-	  To compile this driver as a module, choose M here: the module
-	  will be called ptp_vmclock.
-
 config PTP_1588_CLOCK_IDT82P33
 	tristate "IDT 82P33xxx PTP clock"
 	depends on PTP_1588_CLOCK && I2C
@@ -195,18 +166,6 @@ config PTP_1588_CLOCK_MOCK
 	  To compile this driver as a module, choose M here: the module
 	  will be called ptp_mock.
 
-config PTP_1588_CLOCK_VMW
-	tristate "VMware virtual PTP clock"
-	depends on ACPI && HYPERVISOR_GUEST && X86
-	depends on PTP_1588_CLOCK
-	help
-	  This driver adds support for using VMware virtual precision
-	  clock device as a PTP clock. This is only useful in virtual
-	  machines running on VMware virtual infrastructure.
-
-	  To compile this driver as a module, choose M here: the module
-	  will be called ptp_vmw.
-
 config PTP_1588_CLOCK_OCP
 	tristate "OpenCompute TimeCard as PTP clock"
 	depends on PTP_1588_CLOCK
@@ -241,18 +200,6 @@ config PTP_DFL_TOD
 	  To compile this driver as a module, choose M here: the module
 	  will be called ptp_dfl_tod.
 
-config PTP_S390
-	tristate "S390 PTP driver"
-	depends on PTP_1588_CLOCK
-	depends on S390
-	help
-	  This driver adds support for S390 time steering via the PtP
-	  interface. This works by adding a in-kernel clock delta value,
-	  which is always added to time values used in the kernel. The PtP
-	  driver provides the raw clock value without the delta to
-	  userspace. That way userspace programs like chrony could steer
-	  the kernel clock.
-
 config PTP_NETC_V4_TIMER
 	tristate "NXP NETC V4 Timer PTP Driver"
 	depends on PTP_1588_CLOCK
@@ -263,4 +210,6 @@ config PTP_NETC_V4_TIMER
 	  synchronization. It also supports periodic output signal (e.g. PPS)
 	  and external trigger timestamping.
 
+source "drivers/ptp/emulated/Kconfig"
+
 endmenu
drivers/ptp/Makefile +4 -7
index bdc47e284f14..bcea2d3d4efd 100644
@@ -1,24 +1,21 @@
 # SPDX-License-Identifier: GPL-2.0
 #
-# Makefile for PTP 1588 clock support.
+# Makefile for PTP clock support.
 #
 
+subdir-ccflags-y += -I$(srctree)/drivers/ptp
+
 ptp-y					:= ptp_clock.o ptp_chardev.o ptp_sysfs.o ptp_vclock.o
-ptp_kvm-$(CONFIG_X86)			:= ptp_kvm_x86.o ptp_kvm_common.o
-ptp_kvm-$(CONFIG_HAVE_ARM_SMCCC)	:= ptp_kvm_arm.o ptp_kvm_common.o
 obj-$(CONFIG_PTP_1588_CLOCK)		+= ptp.o
 obj-$(CONFIG_PTP_1588_CLOCK_DTE)	+= ptp_dte.o
 obj-$(CONFIG_PTP_1588_CLOCK_INES)	+= ptp_ines.o
 obj-$(CONFIG_PTP_1588_CLOCK_PCH)	+= ptp_pch.o
-obj-$(CONFIG_PTP_1588_CLOCK_KVM)	+= ptp_kvm.o
-obj-$(CONFIG_PTP_1588_CLOCK_VMCLOCK)	+= ptp_vmclock.o
 obj-$(CONFIG_PTP_1588_CLOCK_QORIQ)	+= ptp_qoriq.o
 obj-$(CONFIG_PTP_1588_CLOCK_IDTCM)	+= ptp_clockmatrix.o
 obj-$(CONFIG_PTP_1588_CLOCK_FC3W)	+= ptp_fc3.o
 obj-$(CONFIG_PTP_1588_CLOCK_IDT82P33)	+= ptp_idt82p33.o
 obj-$(CONFIG_PTP_1588_CLOCK_MOCK)	+= ptp_mock.o
-obj-$(CONFIG_PTP_1588_CLOCK_VMW)	+= ptp_vmw.o
 obj-$(CONFIG_PTP_1588_CLOCK_OCP)	+= ptp_ocp.o
 obj-$(CONFIG_PTP_DFL_TOD)		+= ptp_dfl_tod.o
-obj-$(CONFIG_PTP_S390)			+= ptp_s390.o
 obj-$(CONFIG_PTP_NETC_V4_TIMER)		+= ptp_netc.o
+obj-$(CONFIG_PTP_1588_CLOCK)		+= emulated/
drivers/ptp/emulated/Kconfig new file +61 -0

61 lines not on this page · raw message

drivers/ptp/emulated/Makefile new file +11 -0
new file mode 100644
index 000000000000..577917df3dc9
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for emulated PTP clocks.
+#
+
+ptp_kvm-$(CONFIG_X86)			:= ptp_kvm_x86.o ptp_kvm_common.o
+ptp_kvm-$(CONFIG_HAVE_ARM_SMCCC)	:= ptp_kvm_arm.o ptp_kvm_common.o
+obj-$(CONFIG_PTP_1588_CLOCK_KVM)	+= ptp_kvm.o
+obj-$(CONFIG_PTP_1588_CLOCK_VMCLOCK)	+= ptp_vmclock.o
+obj-$(CONFIG_PTP_1588_CLOCK_VMW)	+= ptp_vmw.o
+obj-$(CONFIG_PTP_S390)			+= ptp_s390.o
drivers/ptp/emulated/ptp_kvm_arm.c renamed from drivers/ptp/ptp_kvm_arm.c +0 -0
similarity index 100%
rename from drivers/ptp/ptp_kvm_arm.c
rename to drivers/ptp/emulated/ptp_kvm_arm.c
drivers/ptp/emulated/ptp_kvm_common.c renamed from drivers/ptp/ptp_kvm_common.c +0 -0
similarity index 100%
rename from drivers/ptp/ptp_kvm_common.c
rename to drivers/ptp/emulated/ptp_kvm_common.c
drivers/ptp/emulated/ptp_kvm_x86.c renamed from drivers/ptp/ptp_kvm_x86.c +0 -0
similarity index 100%
rename from drivers/ptp/ptp_kvm_x86.c
rename to drivers/ptp/emulated/ptp_kvm_x86.c
drivers/ptp/emulated/ptp_s390.c renamed from drivers/ptp/ptp_s390.c +0 -0
similarity index 100%
rename from drivers/ptp/ptp_s390.c
rename to drivers/ptp/emulated/ptp_s390.c
drivers/ptp/emulated/ptp_vmclock.c renamed from drivers/ptp/ptp_vmclock.c +0 -0
similarity index 100%
rename from drivers/ptp/ptp_vmclock.c
rename to drivers/ptp/emulated/ptp_vmclock.c
drivers/ptp/emulated/ptp_vmw.c renamed from drivers/ptp/ptp_vmw.c +0 -0
similarity index 100%
rename from drivers/ptp/ptp_vmw.c
rename to drivers/ptp/emulated/ptp_vmw.c
Signature · 1 line
2.43.5
author
#2 lore raw

PATCH v3 2/2 MAINTAINERS: update PTP maintainer entries after directory split

In reply to Wen Gu

Update MAINTAINERS to match the new drivers/ptp/ directory layout after moving emulated PTP clock drivers into a new subdirectory.

Adjust file patterns and per-driver entries to point to their new locations, and add a dedicated MAINTAINERS entry for the emulated PTP clock drivers.

---
 MAINTAINERS | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
MAINTAINERS +16 -5
index 15011f5752a9..909bc2bd4f6c 100644
@@ -18716,6 +18716,7 @@ X:	Documentation/devicetree/bindings/net/can/
 X:	Documentation/devicetree/bindings/net/wireless/
 X:	drivers/net/can/
 X:	drivers/net/wireless/
+X:	drivers/ptp/emulated/
 
 NETWORKING DRIVERS (WIRELESS)
 M:	Johannes Berg <[email protected]>
@@ -21737,8 +21738,18 @@ F:	Documentation/driver-api/ptp.rst
 F:	drivers/net/phy/dp83640*
 F:	drivers/ptp/*
 F:	include/linux/ptp_cl*
+X:	drivers/ptp/emulated/
 K:	(?:\b|_)ptp(?:\b|_)
 
+PTP EMULATED CLOCK SUPPORT
+M:	David Woodhouse <[email protected]>
+R:	Wen Gu <[email protected]>
+R:	Xuan Zhuo <[email protected]>
+L:	[email protected]
+S:	Maintained
+T:	git git://git.infradead.org/linux-ptp.git
+F:	drivers/ptp/emulated/
+
 PTP MOCKUP CLOCK SUPPORT
 M:	Vladimir Oltean <[email protected]>
 L:	[email protected]
@@ -21755,10 +21766,10 @@ F:	net/ethtool/phc_vclocks.c
 
 PTP VMCLOCK SUPPORT
 M:	David Woodhouse <[email protected]>
-L:	[email protected]
+L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/ptp/amazon,vmclock.yaml
-F:	drivers/ptp/ptp_vmclock.c
+F:	drivers/ptp/emulated/ptp_vmclock.c
 F:	include/uapi/linux/vmclock-abi.h
 
 PTRACE SUPPORT
@@ -23875,7 +23886,7 @@ S390 PTP DRIVER
 M:	Sven Schnelle <[email protected]>
 L:	[email protected]
 S:	Supported
-F:	drivers/ptp/ptp_s390.c
+F:	drivers/ptp/emulated/ptp_s390.c
 
 S390 SCM DRIVER
 M:	Vineeth Vijayan <[email protected]>
@@ -28858,9 +28869,9 @@ M:	Nick Shi <[email protected]>
 R:	Ajay Kaher <[email protected]>
 R:	Alexey Makhalov <[email protected]>
 R:	Broadcom internal kernel review list <[email protected]>
-L:	[email protected]
+L:	[email protected]
 S:	Supported
-F:	drivers/ptp/ptp_vmw.c
+F:	drivers/ptp/emulated/ptp_vmw.c
 
 VMWARE VMCI DRIVER
 M:	Bryan Tan <[email protected]>
Signature · 1 line
2.43.5
maintainer
#3 lore raw
In reply to Wen Gu
Quoted 5 lines · Wen Gu

# Proposal

This series makes the separation explicit by reorganizing the drivers/ptp/ layout into the following groups:

Quoted 7 lines

  - drivers/ptp/          : PTP core infrastructure and host-disciplined PHC drivers.

  - drivers/ptp/emulated/ : non-host-disciplined PHC drivers that expose precision time from hypervisors, platforms, or firmware. These clocks are read-only and not adjusted by the host.

I was thinking we'd move them to drivers/phc, and simplify them as we do.

Most of them are just a lot of PTP driver boilerplate, wrapping around one central function like

static int vmclock_get_crosststamp(struct vmclock_state *st,
struct ptp_system_timestamp *sts, struct system_counterval_t *system_counter, struct timespec64 *tspec)

...which is called with different permutations of arguments depending on the actual PTP call.

I was thinking of reducing the duplication and having the PHC drivers provide *only* that central function. Let the common PHC code provide the interface to PTP (as well as to core timekeeping, for setting the clock at boot, for timekeeping_set_reference() in the vmclock case, and perhaps even for a PPS-like discipline from other clocks).

Here's a *very* hastily thrown together proof of concept; utterly untested and AI-produced, and I've only given it the bare minimum of oversight thus far (I have been meaning to do this for weeks but other things have taken precedence so far)...

https://git.infradead.org/?p=linux-phc.git;a=shortlog;h=refs/heads/next

author
#4 lore raw
Quoted 21 lines · David Woodhouse

On Tue, 2026-06-30 at 11:15 +0800, Wen Gu wrote:

I was thinking we'd move them to drivers/phc, and simplify them as we do.

Most of them are just a lot of PTP driver boilerplate, wrapping around one central function like

static int vmclock_get_crosststamp(struct vmclock_state *st,
struct ptp_system_timestamp *sts, struct system_counterval_t *system_counter, struct timespec64 *tspec)

...which is called with different permutations of arguments depending on the actual PTP call.

I was thinking of reducing the duplication and having the PHC drivers provide *only* that central function. Let the common PHC code provide the interface to PTP (as well as to core timekeeping, for setting the clock at boot, for timekeeping_set_reference() in the vmclock case, and perhaps even for a PPS-like discipline from other clocks).

Quoted 6 lines

Here's a *very* hastily thrown together proof of concept; utterly untested and AI-produced, and I've only given it the bare minimum of oversight thus far (I have been meaning to do this for weeks but other things have taken precedence so far)...

https://git.infradead.org/?p=linux-phc.git;a=shortlog;h=refs/heads/next

Thanks for the POC. I've looked over it and agree this is a cleaner approach overall. The v3 was meant as an interim step, but given the POC it makes more sense to go straight to drivers/phc.

I'm happy to adapt the Alibaba CIPU PHC driver to the new framework once it's in place, and glad to help along the way if needed.