ptp: add Alibaba CIPU PTP clock driver
Subsystems (3)
PATCH v4 1/1 ptp: add Alibaba CIPU PTP clock driver
This adds a driver for Alibaba CIPU PTP clock. The CIPU, an underlying infrastructure of Alibaba Cloud, synchronizes time with reference clocks continuously and provides PTP clocks for VMs and bare metals in cloud.
User space e.g. chrony, in VMs or bare metals can get the value of CIPU clock time through the ptp device exposed by this driver.
---v4->v3:
- use disable_* variant helpers as suggested by Paolo.
- minor nit: make PTP_CIPU_REG macro one line. v3->v2:
https://lore.kernel.org/netdev/[email protected]/
- follow the sysfs convention of one value per file;
- rename enum constants for brevity;
- improve macros for printing;
- add more comments;v2->v1:
https://lore.kernel.org/netdev/[email protected]/
- add Kconfig dependency on CONFIG_PCI to fix kernel test robot's complaint.
v1:
https://lore.kernel.org/netdev/[email protected]/
--- MAINTAINERS | 7 + drivers/ptp/Kconfig | 13 + drivers/ptp/Makefile | 1 + drivers/ptp/ptp_cipu.c | 946 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 967 insertions(+) create mode 100644 drivers/ptp/ptp_cipu.c
MAINTAINERS +7 -0
@@ -786,6 +786,13 @@ S: Maintained F: Documentation/i2c/busses/i2c-ali1563.rst F: drivers/i2c/busses/i2c-ali1563.c +ALIBABA CIPU PTP DRIVER +M: Wen Gu <[email protected]> +M: Xuan Zhuo <[email protected]> +L: [email protected] +S: Supported +F: drivers/ptp/ptp_cipu.c + ALIBABA ELASTIC RDMA DRIVER M: Cheng Xu <[email protected]> M: Kai Shen <[email protected]>
drivers/ptp/Kconfig +13 -0
@@ -252,4 +252,17 @@ config PTP_S390 driver provides the raw clock value without the delta to userspace. That way userspace programs like chrony could steer the kernel clock. + +config PTP_1588_CLOCK_CIPU + tristate "Alibaba CIPU PTP clock" + depends on PTP_1588_CLOCK + depends on 64BIT + depends on PCI + help + This driver adds support for using Alibaba CIPU clock device + as a PTP clock. This is only useful in Alibaba Cloud CIPU + infrastructure. + + To compile this driver as a module, choose M here: the module + will be called ptp_cipu. endmenu
drivers/ptp/Makefile +1 -0
@@ -23,3 +23,4 @@ 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_1588_CLOCK_CIPU) += ptp_cipu.o
drivers/ptp/ptp_cipu.c new file +946 -0
946 lines not on this page · raw message
Signature · 1 line
2.43.5
Jakub Kicinski
maintainerQuoted 22 lines · On Tue, 12 Aug 2025 19:53:21 +0800 Wen Gu wrote:
This adds a driver for Alibaba CIPU PTP clock. The CIPU, an underlying infrastructure of Alibaba Cloud, synchronizes time with reference clocks continuously and provides PTP clocks for VMs and bare metals in cloud.
drivers/ptp/ptp_cipu.c new file +18
-0+static struct attribute *ptp_cipu_attrs[] = { + &dev_attr_reg_dev_feat.attr, + &dev_attr_reg_gst_feat.attr, + &dev_attr_reg_drv_ver.attr, + &dev_attr_reg_env_ver.attr, + &dev_attr_reg_dev_stat.attr, + &dev_attr_reg_sync_stat.attr, + &dev_attr_reg_tm_prec_ns.attr, + &dev_attr_reg_epo_base_yr.attr, + &dev_attr_reg_leap_sec.attr, + &dev_attr_reg_max_lat_ns.attr, + &dev_attr_reg_mt_tout_us.attr, + &dev_attr_reg_thresh_us.attr, + + &dev_attr_ptp_gettm.attr, + &dev_attr_ptp_gettm_inval_err.attr, + &dev_attr_ptp_gettm_tout_err.attr, + &dev_attr_ptp_gettm_excd_thresh.attr,
drivers/ptp/ptp_cipu.c line 731
Quoted 10 lines
drivers/ptp/ptp_cipu.c new file +10
-0+ + &dev_attr_dev_clk_abn.attr, + &dev_attr_dev_clk_abn_rec.attr, + &dev_attr_dev_maint.attr, + &dev_attr_dev_maint_rec.attr, + &dev_attr_dev_maint_tout.attr, + &dev_attr_dev_busy.attr, + &dev_attr_dev_busy_rec.attr, + &dev_attr_dev_err.attr, + &dev_attr_dev_err_rec.attr,
This driver is lacking documentation. You need to describe how the user is expected to interact with the device and document all these sysfs attributes.
Maybe it's just me, but in general I really wish someone stepped up and created a separate subsystem for all these cloud / vm clocks. They have nothing to do with PTP. In my mind PTP clocks are simple HW tickers on which we build all the time related stuff. While this driver reports the base year for the epoch and leap second status via sysfs.
Quoted 38 lines · Jakub Kicinski
Quoted 22 lines · On Tue, 12 Aug 2025 19:53:21 +0800 Wen Gu wrote:
This adds a driver for Alibaba CIPU PTP clock. The CIPU, an underlying infrastructure of Alibaba Cloud, synchronizes time with reference clocks continuously and provides PTP clocks for VMs and bare metals in cloud.
drivers/ptp/ptp_cipu.c new file +18
-0+static struct attribute *ptp_cipu_attrs[] = { + &dev_attr_reg_dev_feat.attr, + &dev_attr_reg_gst_feat.attr, + &dev_attr_reg_drv_ver.attr, + &dev_attr_reg_env_ver.attr, + &dev_attr_reg_dev_stat.attr, + &dev_attr_reg_sync_stat.attr, + &dev_attr_reg_tm_prec_ns.attr, + &dev_attr_reg_epo_base_yr.attr, + &dev_attr_reg_leap_sec.attr, + &dev_attr_reg_max_lat_ns.attr, + &dev_attr_reg_mt_tout_us.attr, + &dev_attr_reg_thresh_us.attr, + + &dev_attr_ptp_gettm.attr, + &dev_attr_ptp_gettm_inval_err.attr, + &dev_attr_ptp_gettm_tout_err.attr, + &dev_attr_ptp_gettm_excd_thresh.attr,drivers/ptp/ptp_cipu.c line 731
Quoted 10 lines
drivers/ptp/ptp_cipu.c new file +10
-0+ + &dev_attr_dev_clk_abn.attr, + &dev_attr_dev_clk_abn_rec.attr, + &dev_attr_dev_maint.attr, + &dev_attr_dev_maint_rec.attr, + &dev_attr_dev_maint_tout.attr, + &dev_attr_dev_busy.attr, + &dev_attr_dev_busy_rec.attr, + &dev_attr_dev_err.attr, + &dev_attr_dev_err_rec.attr,This driver is lacking documentation. You need to describe how the user is expected to interact with the device and document all these sysfs attributes.
Quoted 5 lines
Maybe it's just me, but in general I really wish someone stepped up and created a separate subsystem for all these cloud / vm clocks. They have nothing to do with PTP. In my mind PTP clocks are simple HW tickers on which we build all the time related stuff. While this driver reports the base year for the epoch and leap second status via sysfs.
None of it should exist in the cloud anyway. The *only* thing that makes sense for a VM is for the hypervisor to just *tell* the guest what the relationship is between the CPU's hardware counter (e.g. TSC) and real time. Which is what VMclock was invented for. Use that, instead of making *every* guest on the system duplicate the same work of synchronising the *same* underlying oscillator. Badly, with steal time in the mix.
Given PCIe PTM to synchronize counters, you could even implement vmclock over PCI for bare metal.
Quoted 45 lines · David Woodhouse
Quoted 38 lines · Jakub Kicinski
Quoted 22 lines · On Tue, 12 Aug 2025 19:53:21 +0800 Wen Gu wrote:
This adds a driver for Alibaba CIPU PTP clock. The CIPU, an underlying infrastructure of Alibaba Cloud, synchronizes time with reference clocks continuously and provides PTP clocks for VMs and bare metals in cloud.
drivers/ptp/ptp_cipu.c new file +18
-0+static struct attribute *ptp_cipu_attrs[] = { + &dev_attr_reg_dev_feat.attr, + &dev_attr_reg_gst_feat.attr, + &dev_attr_reg_drv_ver.attr, + &dev_attr_reg_env_ver.attr, + &dev_attr_reg_dev_stat.attr, + &dev_attr_reg_sync_stat.attr, + &dev_attr_reg_tm_prec_ns.attr, + &dev_attr_reg_epo_base_yr.attr, + &dev_attr_reg_leap_sec.attr, + &dev_attr_reg_max_lat_ns.attr, + &dev_attr_reg_mt_tout_us.attr, + &dev_attr_reg_thresh_us.attr, + + &dev_attr_ptp_gettm.attr, + &dev_attr_ptp_gettm_inval_err.attr, + &dev_attr_ptp_gettm_tout_err.attr, + &dev_attr_ptp_gettm_excd_thresh.attr,drivers/ptp/ptp_cipu.c line 731
Quoted 10 lines
drivers/ptp/ptp_cipu.c new file +10
-0+ + &dev_attr_dev_clk_abn.attr, + &dev_attr_dev_clk_abn_rec.attr, + &dev_attr_dev_maint.attr, + &dev_attr_dev_maint_rec.attr, + &dev_attr_dev_maint_tout.attr, + &dev_attr_dev_busy.attr, + &dev_attr_dev_busy_rec.attr, + &dev_attr_dev_err.attr, + &dev_attr_dev_err_rec.attr,This driver is lacking documentation. You need to describe how the user is expected to interact with the device and document all these sysfs attributes.
Quoted 5 lines
Maybe it's just me, but in general I really wish someone stepped up and created a separate subsystem for all these cloud / vm clocks. They have nothing to do with PTP. In my mind PTP clocks are simple HW tickers on which we build all the time related stuff. While this driver reports the base year for the epoch and leap second status via sysfs.
Quoted 8 lines
None of it should exist in the cloud anyway. The *only* thing that makes sense for a VM is for the hypervisor to just *tell* the guest what the relationship is between the CPU's hardware counter (e.g. TSC) and real time. Which is what VMclock was invented for. Use that, instead of making *every* guest on the system duplicate the same work of synchronising the *same* underlying oscillator. Badly, with steal time in the mix.
Our design is similar, but based on Alibaba CIPU[1].
The CIPU in cloud synchronizes time with the atomic clock and get high-precision time value. It then virtualizes PCI devices and passes them to VMs or bare metals. So VMs and bare metals can use these PCI devices's timestamp registers to obtain the high-precision time. The driver here exposes these devices as PTP clocks for use by VMs and bare metals (e.g. chrony).
[1] https://www.alibabacloud.com/blog/a-detailed-explanation-about-alibaba-cloud-cipu_599183
Quoted 3 lines
Given PCIe PTM to synchronize counters, you could even implement vmclock over PCI for bare metal.
PCIe PTM is not supported by CIPU, so vmclock can't work for bare metals, that's also one of the reasons why we choose current design.
Thanks.
Quoted 29 lines · Jakub Kicinski
Quoted 28 lines · On Tue, 12 Aug 2025 19:53:21 +0800 Wen Gu wrote:
This adds a driver for Alibaba CIPU PTP clock. The CIPU, an underlying infrastructure of Alibaba Cloud, synchronizes time with reference clocks continuously and provides PTP clocks for VMs and bare metals in cloud.
drivers/ptp/ptp_cipu.c new file +24
-0+static struct attribute *ptp_cipu_attrs[] = { + &dev_attr_reg_dev_feat.attr, + &dev_attr_reg_gst_feat.attr, + &dev_attr_reg_drv_ver.attr, + &dev_attr_reg_env_ver.attr, + &dev_attr_reg_dev_stat.attr, + &dev_attr_reg_sync_stat.attr, + &dev_attr_reg_tm_prec_ns.attr, + &dev_attr_reg_epo_base_yr.attr, + &dev_attr_reg_leap_sec.attr, + &dev_attr_reg_max_lat_ns.attr, + &dev_attr_reg_mt_tout_us.attr, + &dev_attr_reg_thresh_us.attr, + + &dev_attr_ptp_gettm.attr, + &dev_attr_ptp_gettm_inval_err.attr, + &dev_attr_ptp_gettm_tout_err.attr, + &dev_attr_ptp_gettm_excd_thresh.attr, + + &dev_attr_dev_clk_abn.attr, + &dev_attr_dev_clk_abn_rec.attr, + &dev_attr_dev_maint.attr, + &dev_attr_dev_maint_rec.attr, + &dev_attr_dev_maint_tout.attr,
Quoted 9 lines
drivers/ptp/ptp_cipu.c line 731
Quoted 4 lines
drivers/ptp/ptp_cipu.c new file +4
-0+ &dev_attr_dev_busy.attr, + &dev_attr_dev_busy_rec.attr, + &dev_attr_dev_err.attr, + &dev_attr_dev_err_rec.attr,This driver is lacking documentation. You need to describe how the user is expected to interact with the device and document all these sysfs attributes.
OK. I will add the description.
Would you prefer me to create a related .rst file under Documentation/ (perhaps in a new Documentation/clock/ptp/ directory?), or add the description comments directly in this driver source?
Quoted 5 lines
Maybe it's just me, but in general I really wish someone stepped up and created a separate subsystem for all these cloud / vm clocks. They have nothing to do with PTP. In my mind PTP clocks are simple HW tickers on which we build all the time related stuff. While this driver reports the base year for the epoch and leap second status via sysfs.
These sysfs are intended to provide diagnostics and informations. For users, interacting with this PTP clock works the same way as with other PTP clock, through the exposed chardev. The 1588 protocol related work has been done by the cloud infra so the driver only reads some registers.
Thanks.
Quoted 1 line
These sysfs are intended to provide diagnostics and informations.
Maybe they should be in debugfs if they are just diagnostics? You then don't need to document them, because they are not ABI.
Andrew
Quoted 6 lines · Andrew Lunn
Quoted 1 line
These sysfs are intended to provide diagnostics and informations.
Maybe they should be in debugfs if they are just diagnostics? You then don't need to document them, because they are not ABI.
Andrew
Hi Andrew,
Thank you for the suggestion.
But these sysfs aren't only for developer debugging, some cloud components rely on the statistics to assess the health of PTP clocks or to perform corresponding actions based on the reg values. So I prefer to use the stable sysfs.
Thanks!
Quoted 10 lines · Wen Gu
Quoted 6 lines · Andrew Lunn
Quoted 1 line
These sysfs are intended to provide diagnostics and informations.
Maybe they should be in debugfs if they are just diagnostics? You then don't need to document them, because they are not ABI.
Andrew
Quoted 8 lines
Hi Andrew,
Thank you for the suggestion.
But these sysfs aren't only for developer debugging, some cloud components rely on the statistics to assess the health of PTP clocks or to perform corresponding actions based on the reg values. So I prefer to use the stable sysfs.
Doesn't this somewhat contradict what you said earlier:
These sysfs are intended to provide diagnostics and informations. For users, interacting with this PTP clock works the same way as with other PTP clock, through the exposed chardev.
So users don't use just the standard chardev, they additionally need sysfs.
Maybe take a step back. Do what Jakub suggested:
Maybe it's just me, but in general I really wish someone stepped up and created a separate subsystem for all these cloud / vm clocks. They have nothing to do with PTP. In my mind PTP clocks are simple HW tickers on which we build all the time related stuff. While this driver reports the base year for the epoch and leap second status via sysfs.
Talk with the other cloud vendors and define a common set of properties, rather than each vendor having their own incompatible set.
OS 101: the OS is supposed to abstract over the hardware to make different hardware all look the same.
Andrew
Quoted 20 lines · Andrew Lunn
Quoted 10 lines · Wen Gu
Quoted 6 lines · Andrew Lunn
Quoted 1 line
These sysfs are intended to provide diagnostics and informations.
Maybe they should be in debugfs if they are just diagnostics? You then don't need to document them, because they are not ABI.
Andrew
Quoted 8 lines
Hi Andrew,
Thank you for the suggestion.
But these sysfs aren't only for developer debugging, some cloud components rely on the statistics to assess the health of PTP clocks or to perform corresponding actions based on the reg values. So I prefer to use the stable sysfs.
Quoted 8 lines
Doesn't this somewhat contradict what you said earlier:
These sysfs are intended to provide diagnostics and informations. For users, interacting with this PTP clock works the same way as with other PTP clock, through the exposed chardev.
So users don't use just the standard chardev, they additionally need sysfs.
No, they are not contradictory.
For cloud users, they only need to use standard ptp chardev exposed to do time operations. This is no different from using any other PTP clock.
The sysfs are used by Alibaba cloud's components that monitor the health and behavior of the underlay device to ensure SLAs.
Quoted 10 lines
Maybe take a step back. Do what Jakub suggested:
Maybe it's just me, but in general I really wish someone stepped up and created a separate subsystem for all these cloud / vm clocks. They have nothing to do with PTP. In my mind PTP clocks are simple HW tickers on which we build all the time related stuff. While this driver reports the base year for the epoch and leap second status via sysfs.
Quoted 5 lines
Talk with the other cloud vendors and define a common set of properties, rather than each vendor having their own incompatible set.
OS 101: the OS is supposed to abstract over the hardware to make different hardware all look the same.
IMHO, the abstraction has been done by PTP layer, e.g. struct ptp_clock_info, struct ptp_clock and ptp_clock_{un}register(). For users, the PTP clock provide by any vendors should be same in terms of usage, Alibaba Cloud is no exception.
But the specific implementation of underlay varies from ventor to ventor. Some depends on ptp4l and NIC with IEEE 1588, some offload 1588 work to underlay infra and get timestamps directly. I think it is difficult to require all vendors to provide the same underlying attributes. Besides, Even the underlying implementation and properties are different, it does not affect the user's use of them and the abstraction as PTP clocks.
Thanks!
Quoted 2 lines
Andrew
Jakub Kicinski
maintainerQuoted 10 lines · On Sat, 16 Aug 2025 11:52:18 +0800 Wen Gu wrote:
Quoted 4 lines
This driver is lacking documentation. You need to describe how the user is expected to interact with the device and document all these sysfs attributes.
OK. I will add the description.
Would you prefer me to create a related .rst file under
Documentation/(perhaps in a newDocumentation/clock/ptp/directory?), or add the description comments directly in this driver source?
It's supposed to be user-facing documentation, so Documentation.
But you ignored David Woodhouse's response, and also skirted around Andrew's comment on OS kernel being an abstraction layer. So if you plan to post a v5 -- the documentation better clearly explain why this is a PTP device, and not a real time clock.
Richard Cochran
maintainerQuoted 5 lines · Jakub Kicinski
Maybe it's just me, but in general I really wish someone stepped up and created a separate subsystem for all these cloud / vm clocks. They have nothing to do with PTP. In my mind PTP clocks are simple HW tickers on which we build all the time related stuff. While this driver reports the base year for the epoch and leap second status via sysfs.
Yeah, that is my feeling as well.
Thanks,
Richard
Quoted 9 lines · Richard Cochran
Quoted 5 lines · Jakub Kicinski
Maybe it's just me, but in general I really wish someone stepped up and created a separate subsystem for all these cloud / vm clocks. They have nothing to do with PTP. In my mind PTP clocks are simple HW tickers on which we build all the time related stuff. While this driver reports the base year for the epoch and leap second status via sysfs.
Yeah, that is my feeling as well.
Agreed. While vmclock is presented as a PTP clock for compatibility, it's more than that because it can do better than simply giving a single precise point in time. It actually tells the guest the precise relationship between the hardware counter and real time, much like the private data structure exposed from the kernel to vDSO gettimeofday.
We should work on having the kernel consume that *directly* and feed its CLOCK_REALTIME with it. Having hundreds of guests on the same host all recalculate the same thing based on a set of points in time, obtained through /dev/ptpX or otherwise, is just daft.
Quoted 17 lines · David Woodhouse
Quoted 9 lines · Richard Cochran
Quoted 5 lines · Jakub Kicinski
Maybe it's just me, but in general I really wish someone stepped up and created a separate subsystem for all these cloud / vm clocks. They have nothing to do with PTP. In my mind PTP clocks are simple HW tickers on which we build all the time related stuff. While this driver reports the base year for the epoch and leap second status via sysfs.
Yeah, that is my feeling as well.
Agreed. While vmclock is presented as a PTP clock for compatibility, it's more than that because it can do better than simply giving a single precise point in time. It actually tells the guest the precise relationship between the hardware counter and real time, much like the private data structure exposed from the kernel to vDSO gettimeofday.
Quoted 4 lines
We should work on having the kernel consume that *directly* and feed its
CLOCK_REALTIMEwith it. Having hundreds of guests on the same host all recalculate the same thing based on a set of points in time, obtained through/dev/ptpXor otherwise, is just daft.
Hi David,
How does vmclock work in a bare‑metal scenario, given that there is no guest–hypervisor architecture?
You mentioned "vmclock over PCI", do you mean passing a PCI device to the bare‑metal? What is this PCI device, and which driver does it use?
Thanks.
Quoted 8 lines · Wen Gu
Hi David,
How does vmclock work in a bare‑metal scenario, given that there is no guest–hypervisor architecture?
You mentioned "vmclock over PCI", do you mean passing a PCI device to the bare‑metal? What is this PCI device, and which driver does it use?
It would need PCIe PTM to synchronize against the host's arch timer or TSC, which you said you don't have on the CIPU. We don't have PTM either, so there is no existing defined PCI device.
I'm in the process of writing up a specification for the vmclock device. It doesn't really contain much information that isn't already in the QEMU and Linux code; it'll just be an easier way to find it rather than reading GPL'd code, which is problematic for some.
I *could* add a PCI transport, but I figured it was easy enough to do that later if anyone implements one.
Quoted 10 lines · David Woodhouse
Quoted 8 lines · Wen Gu
Hi David,
How does vmclock work in a bare‑metal scenario, given that there is no guest–hypervisor architecture?
You mentioned "vmclock over PCI", do you mean passing a PCI device to the bare‑metal? What is this PCI device, and which driver does it use?
Hi David, sorry for the late reply, my mailbox misclassified this mail.
Quoted 4 lines
It would need PCIe PTM to synchronize against the host's arch timer or TSC, which you said you don't have on the CIPU. We don't have PTM either, so there is no existing defined PCI device.
I see. that's what I thought, in our scenario VM and bare metal can not use a unified way based on vmclock to achieve PTP clock currently.
Quoted 7 lines
I'm in the process of writing up a specification for the vmclock device. It doesn't really contain much information that isn't already in the QEMU and Linux code; it'll just be an easier way to find it rather than reading GPL'd code, which is problematic for some.
I *could* add a PCI transport, but I figured it was easy enough to do that later if anyone implements one.
Understood, thanks for the update.