timekeeping/ptp: Expand snapshot functionality
Subsystems (17)
Thomas Gleixner
maintainerv2 cover timekeeping/ptp: Expand snapshot functionality
This is an update to V1 which can be found here:
https://lore.kernel.org/lkml/[email protected]
PTP wants to grow new snapshot functionality, which provides not only the captured CLOCK* values, but also the underlying clocksource counter value.
https://lore.kernel.org/[email protected]
There was quite some discussion in seemingly related threads how to capture these values and how to provide core infrastructure so that driver writers have something to work with
https://lore.kernel.org/[email protected]
https://lore.kernel.org/[email protected]
This series implements the timekeeping related mechanisms to:
1) Capture CLOCK values along with the clocksource counter value for non-hardware based sampling
2) Expanding the hardware cross time stamp mechanism to hand back the clocksource counter value, which was captured by the device, along with the related CLOCK values
3) Adding AUX clock support to the hardware cross timestamping core
4) Add support for derived clocksources to the snapshot mechanism (New in V2)
Changes vs. V1:
- Fixed the ptp_ocp typo - 0-day, Jakub
- Renamed the system_time_snapshot members sys and raw so systime and monoraw to make them less ambigous.
- Fixed the error case return values of get_device_system_crosststamp()
- Made ktime_snapshot_id() void as there is no point for the return value, which is nowhere checked and cannot be propagated. system_time_snapshot::valid has to be evaluated at the call sites anyway. - Jacob
- Picked up the first patch from Davids follow up series, which extends the snapshot mechanism so that derived clocksources (like kvmclock and Hyper-V scaled TSC) can return the actual underlying hardware counter value (TSC for the two examples).
- Collected Reviewed/Acked/Tested-by tags
Delta patch against v1 below.
The series is based on v7.1-rc2 and also available from git:
git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git timekeeping-ptp-extend-v2
Thanks,
tglx
---
arch/arm64/kvm/hyp_trace.c +3 -3
@@ -51,8 +51,8 @@ static void __hyp_clock_work(struct work_struct *work) hyp_clock = container_of(dwork, struct hyp_trace_clock, work); -ktime_get_snapshot_id (&snap,CLOCK_BOOTTIME ); - boot =ktime_to_ns (snap.sys); +ktime_get_snapshot_id (CLOCK_BOOTTIME , &snap); + boot =ktime_to_ns (snap.systime); delta_boot = boot - hyp_clock->boot; delta_cycles = snap.cycles - hyp_clock->cycles;
@@ -120,7 +120,7 @@ static void hyp_trace_clock_enable(struct hyp_trace_clock *hyp_clock, bool enablktime_get_snapshot_id (&snap,CLOCK_BOOTTIME ); - hyp_clock->boot =ktime_to_ns (snap.sys); + hyp_clock->boot =ktime_to_ns (snap.systime); hyp_clock->cycles = snap.cycles; hyp_clock->mult =0 ;
arch/arm64/kvm/hypercalls.c +3 -3
@@ -28,7 +28,7 @@ static void kvm_ptp_get_time(struct kvm_vcpu *vcpu, u64 *val)* system time and counter value must captured at the same * time to keep consistency and precision. */ -ktime_get_snapshot_id (&systime_snapshot,CLOCK_REALTIME ); +ktime_get_snapshot_id (CLOCK_REALTIME , &systime_snapshot);/* * This is only valid if the current clocksource is the
@@ -61,8 +61,8 @@ static void kvm_ptp_get_time(struct kvm_vcpu *vcpu, u64 *val)* in the future (about 292 years from 1970, and at that stage * nobody will give a damn about it). */ - val[0 ] =upper_32_bits (systime_snapshot.sys); - val[1 ] =lower_32_bits (systime_snapshot.sys); + val[0 ] =upper_32_bits (systime_snapshot.systime); + val[1 ] =lower_32_bits (systime_snapshot.systime); val[2 ] =upper_32_bits (cycles); val[3 ] =lower_32_bits (cycles); }
drivers/net/dsa/sja1105/sja1105_main.c +4 -4
@@ -2310,10 +2310,10 @@ int sja1105_static_config_reload(struct sja1105_private *priv, goto out; } - t1 =ktime_to_ns (ptp_sts_before.pre_sts.sys); - t2 =ktime_to_ns (ptp_sts_before.post_sts.sys); - t3 =ktime_to_ns (ptp_sts_after.pre_sts.sys); - t4 =ktime_to_ns (ptp_sts_after.post_sts.sys); + t1 =ktime_to_ns (ptp_sts_before.pre_sts.systime); + t2 =ktime_to_ns (ptp_sts_before.post_sts.systime); + t3 =ktime_to_ns (ptp_sts_after.pre_sts.systime); + t4 =ktime_to_ns (ptp_sts_after.post_sts.systime);/* Mid point, corresponds to pre-reset PTPCLKVAL */ t12 = t1 + (t2 - t1) /2 ;/* Mid point, corresponds to post-reset PTPCLKVAL, aka 0 */
drivers/net/ethernet/intel/ice/ice_ptp.c +1 -1
@@ -2117,7 +2117,7 @@ static int ice_capture_crosststamp(ktime_t *device, }/* Snapshot system time for historic interpolation */ -ktime_get_snapshot_id (&ctx->snapshot, ctx->snapshot_clock_id); +ktime_get_snapshot_id (ctx->snapshot_clock_id, &ctx->snapshot);/* Program cmd to master timer */ ice_ptp_src_cmd (hw,ICE_PTP_READ_TIME );
drivers/net/ethernet/intel/igc/igc_ptp.c +1 -1
@@ -1049,7 +1049,7 @@ static int igc_phc_get_syncdevicetime(ktime_t *device,*/ do { /* Get a snapshot of system clocks to use as historic value. */ - ktime_get_snapshot_id(&adapter->snapshot, adapter->snapshot_clock_id); + ktime_get_snapshot_id(adapter->snapshot_clock_id, &adapter->snapshot); igc_ptm_trigger(hw);
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +2 -2
@@ -340,7 +340,7 @@ static int mlx5_ptp_getcrosststamp(struct ptp_clock_info *ptp, goto unlock; } -ktime_get_snapshot_id (&history_begin, cts->clock_id); +ktime_get_snapshot_id (cts->clock_id, &history_begin); err =get_device_system_crosststamp (mlx5_mtctr_syncdevicetime, mdev, &history_begin, cts);
@@ -366,7 +366,7 @@ static int mlx5_ptp_getcrosscycles(struct ptp_clock_info *ptp, goto unlock; } -ktime_get_snapshot_id (&history_begin, cts->clock_id); +ktime_get_snapshot_id (cts->clock_id, &history_begin); err =get_device_system_crosststamp (mlx5_mtctr_syncdevicecyclestime, mdev, &history_begin, cts);
drivers/ptp/ptp_chardev.c +2 -2
@@ -392,11 +392,11 @@ static long ptp_sys_offset_extended(struct ptp_clock *ptp, void __user *arg, extoff->ts[i][1 ].sec = ts.tv_sec; extoff->ts[i][1 ].nsec = ts.tv_nsec; - ts =ktime_to_timespec64 (sts.pre_sts.sys); + ts =ktime_to_timespec64 (sts.pre_sts.systime); extoff->ts[i][0 ].sec = ts.tv_sec; extoff->ts[i][0 ].nsec = ts.tv_nsec; - ts =ktime_to_timespec64 (sts.post_sts.sys); + ts =ktime_to_timespec64 (sts.post_sts.systime); extoff->ts[i][2 ].sec = ts.tv_sec; extoff->ts[i][2 ].nsec = ts.tv_nsec; }
drivers/ptp/ptp_ocp.c +3 -3
@@ -1492,7 +1492,7 @@ __ptp_ocp_gettime_locked(struct ptp_ocp *bp, struct timespec64 *ts,ptp_read_system_postts (sts);if (sts && bp->ts_window_adjust) - sts->post_ts.sys -= bp->ts_window_adjust; + sts->post_sts.systime -= bp->ts_window_adjust; time_ns =ioread32 (&bp->reg->time_ns); time_sec =ioread32 (&bp->reg->time_sec);
@@ -4592,8 +4592,8 @@ ptp_ocp_summary_show(struct seq_file *s, void *data)struct timespec64 sys_ts;s64 pre_ns, post_ns, ns; - pre_ns =ktime_to_ns (sts.pre_sts.sys); - post_ns =ktime_to_ns (sts.post_sts.sys); + pre_ns =ktime_to_ns (sts.pre_sts.systime); + post_ns =ktime_to_ns (sts.post_sts.systime); ns = (pre_ns + post_ns) /2 ; ns += (s64 )bp->utc_tai_offset *NSEC_PER_SEC ; sys_ts =ns_to_timespec64 (ns);
drivers/ptp/ptp_vmclock.c +1 -1
@@ -263,7 +263,7 @@ static int ptp_vmclock_getcrosststamp(struct ptp_clock_info *ptp,if (ret == -ENODEV ) {struct system_time_snapshot systime_snapshot; -ktime_get_snapshot_id (&systime_snapshot,CLOCK_REALTIME ); +ktime_get_snapshot_id (CLOCK_REALTIME , &systime_snapshot);if (systime_snapshot.cs_id ==CSID_X86_TSC || systime_snapshot.cs_id ==CSID_X86_KVM_CLK ) {
drivers/virtio/virtio_rtc_ptp.c +1 -1
@@ -139,7 +139,7 @@ static int viortc_ptp_getcrosststamp(struct ptp_clock_info *ptp,if (ret)return ret; -ktime_get_snapshot_id (&history_begin, xtstamp->clock_id); +ktime_get_snapshot_id (xtstamp->clock_id, &history_begin);if (history_begin.cs_id != cs_id)return -EOPNOTSUPP ;
include/linux/clocksource.h +24 -0
@@ -31,6 +31,21 @@ struct module;#include <vdso/clocksource.h> +/** +* struct clocksource_hw_snapshot - Snapshot for the underlying hardware counter of derived +* clocksources like kvmclock or Hyper-V scaled TSC +* @hw_cycles: The hardware counter value +* @hw_csid: Clocksource ID of the hardware counter +* +* Such clocksources must implement the read_snapshot() callback and fill in the +* hardware counter value, the clocksource ID of the hardware counter and derive +* the actual clocksource cycles from @hw_cycles to provide an atomic snapshot +*/ +struct clocksource_hw_snapshot { +u64 hw_cycles; +enum clocksource_ids hw_csid; +}; +/** * struct clocksource - hardware abstraction for a free running counter * Provides mostly state-free accessors to the underlying hardware.
@@ -72,6 +87,14 @@ struct module;* @flags: Flags describing special properties * @base: Hardware abstraction for clock on which a clocksource * is based +* @read_snapshot: Extended @read() function for clocksources such as +* kvmclock or the Hyper-V scaled TSC where the actual +* clocksource value for timekeeping is calculated from an +* underlying hardware counter. Returns the timekeeping +* relevant cycle value and stores the raw value of the +* underlying counter from which it was calculated +* including the clocksource ID of that counter in the +* clocksource hardware snapshot. * @enable: Optional function to enable the clocksource * @disable: Optional function to disable the clocksource * @suspend: Optional suspend function for the clocksource
@@ -113,6 +136,7 @@ struct clocksource {unsigned long flags;struct clocksource_base *base; +u64 (*read_snapshot)(struct clocksource *cs,struct clocksource_hw_snapshot *chs);int (*enable)(struct clocksource *cs);void (*disable)(struct clocksource *cs);void (*suspend)(struct clocksource *cs);
include/linux/pps_kernel.h +3 -3
@@ -102,9 +102,9 @@ static inline void pps_get_ts(struct pps_event_time *ts)#ifdef CONFIG_NTP_PPS struct system_time_snapshot snap; -ktime_get_snapshot_id (&snap,CLOCK_REALTIME ); - ts->ts_real =ktime_to_timespec64 (snap.sys); - ts->ts_raw =ktime_to_timespec64 (snap.raw); +ktime_get_snapshot_id (CLOCK_REALTIME , &snap); + ts->ts_real =ktime_to_timespec64 (snap.systime); + ts->ts_raw =ktime_to_timespec64 (snap.monoraw);#else ktime_get_real_ts64 (&ts->ts_real);#endif
include/linux/ptp_clock_kernel.h +2 -2
@@ -511,13 +511,13 @@ static inline ktime_t ptp_convert_timestamp(const ktime_t *hwtstamp,static inline void ptp_read_system_prets (struct ptp_system_timestamp *sts) {if (sts) -ktime_get_snapshot_id (&sts->pre_sts, sts->clockid); +ktime_get_snapshot_id (sts->clockid, &sts->pre_sts); }static inline void ptp_read_system_postts (struct ptp_system_timestamp *sts) {if (sts) -ktime_get_snapshot_id (&sts->post_sts, sts->clockid); +ktime_get_snapshot_id (sts->clockid, &sts->post_sts); }#endif
include/linux/timekeeping.h +11 -6
@@ -279,18 +279,24 @@ static inline bool ktime_get_aux_ts64(clockid_t id, struct timespec64 *kt) { ret* struct system_time_snapshot - Simultaneous time capture of CLOCK_MONOTONIC_RAW, * a selected CLOCK_* and the clocksource counter value * @cycles: Clocksource counter value to produce the system times -* @sys: The system time of the selected CLOCK ID -* @raw: Monotonic raw system time +* @hw_cycles: For derived clocksources, the hardware counter value from +* which @cycles was derived +* @systime: The system time of the selected CLOCK ID +* @monoraw: Monotonic raw system time * @cs_id: Clocksource ID +* @hw_csid: Clocksource ID of the underlying hardware counter for derived +* clocksources which implement the read_snapshot() callback. * @clock_was_set_seq: The sequence number of clock-was-set events * @cs_was_changed_seq: The sequence number of clocksource change events * @valid: True if the snapshot is valid */ struct system_time_snapshot {u64 cycles; -ktime_t sys; -ktime_t raw; +u64 hw_cycles; +ktime_t systime; +ktime_t monoraw;enum clocksource_ids cs_id; +enum clocksource_ids hw_csid;unsigned int clock_was_set_seq;u8 cs_was_changed_seq;u8 valid;
@@ -348,8 +354,7 @@ extern int get_device_system_crosststamp(* Simultaneously snapshot a given clock with MONOTONIC_RAW and the underlying * clocksource counter value. */ -extern bool ktime_get_snapshot_id (struct system_time_snapshot *systime_snapshot, -clockid_t clock_id); +extern void ktime_get_snapshot_id (clockid_t clock_id,struct system_time_snapshot *systime_snapshot);/* * Persistent clock related interfaces
kernel/time/timekeeping.c +36 -18
140 lines not on this page · raw message
Thomas Gleixner
maintainerPATCH v2 1/25 timekeeping: Provide ktime_get_snapshot_id()
From: Thomas Gleixner <[email protected]>
ktime_get_snapshot() provides a snapshot of the underlying clocksource counter value and the corresponding CLOCK_MONOTONIC_RAW, CLOCK_REALTIME and CLOCK_BOOTTIME timestamps.
There is no usage of CLOCK_REALTIME and CLOCK_BOOTTIME at the same time and CLOCK_BOOTTIME support was just added for the ARM64 KVM tracing mechanism, which needs CLOCK_BOOTTIME and the underlying clocksource counter value.
ktime_get_snapshot() is also not suitable for usage with CLOCK_AUX, but that's a prerequisite to support PTP hardware timestamping for CLOCK_AUX steering.
As a first step, rename ktime_get_snapshot() to ktime_get_snapshot_id(), which now takes a clockid argument to select the clock which needs to be captured. The result is stored in system_time_snapshot::systime, which will replace the system_time_snapshot::real/boot members once all usage sites have been converted.
ktime_get_snapshot() is a simple wrapper which hands in CLOCK_REALTIME as clockid argument for the conversion period. That means CLOCK_REALTIME is now captured twice, but that redunancy is only temporary.
As all usage sites of struct system_time_snapshot has to be updated anyway, rename the 'raw' member to 'monoraw' for clarity.
No functional change vs. current users of ktime_get_snapshot()
--- include/linux/timekeeping.h | 34 ++++++++++++----- kernel/time/timekeeping.c | 85 +++++++++++++++++++++++++++++++++----------- 2 files changed, 88 insertions(+), 31 deletions(-)
include/linux/timekeeping.h +24 -10
@@ -276,24 +276,32 @@ static inline bool ktime_get_aux_ts64(cl#endif /** -* struct system_time_snapshot - simultaneous raw/real time capture with -* counter value -* @cycles: Clocksource counter value to produce the system times -* @real: Realtime system time -* @boot: Boot time -* @raw: Monotonic raw system time -* @cs_id: Clocksource ID +* struct system_time_snapshot - Simultaneous time capture of CLOCK_MONOTONIC_RAW, +* a selected CLOCK_* and the clocksource counter value +* @cycles: Clocksource counter value to produce the system times +* @systime: The system time of the selected CLOCK ID +* @real: Realtime system time +* @boot: Boot time +* @raw: Monotonic raw system time +* @monoraw: Monotonic raw system time +* @cs_id: Clocksource ID * @clock_was_set_seq: The sequence number of clock-was-set events * @cs_was_changed_seq: The sequence number of clocksource change events +* @valid: True if the snapshot is valid */ struct system_time_snapshot {u64 cycles; +ktime_t systime;ktime_t real;ktime_t boot; -ktime_t raw; +union { +ktime_t raw; +ktime_t monoraw; + };enum clocksource_ids cs_id;unsigned int clock_was_set_seq;u8 cs_was_changed_seq; +u8 valid; };/**
@@ -341,9 +349,15 @@ extern int get_device_system_crosststamp struct system_device_crosststamp *xtstamp);/* -* Simultaneously snapshot realtime and monotonic raw clocks +* Simultaneously snapshot a given clock with MONOTONIC_RAW and the underlying +* clocksource counter value. */ -extern void ktime_get_snapshot (struct system_time_snapshot *systime_snapshot); +extern void ktime_get_snapshot_id (clockid_t clock_id,struct system_time_snapshot *systime_snapshot); + +static inline void ktime_get_snapshot (struct system_time_snapshot *systime_snapshot) +{ +ktime_get_snapshot_id (CLOCK_REALTIME , systime_snapshot); +}/* * Persistent clock related interfaces
kernel/time/timekeeping.c +64 -21
107 lines not on this page · raw message
[tip: timers/ptp] timekeeping: Provide ktime_get_snapshot_id()
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: eba302268a019275fd6ff452d4ff0b94fef11c76 Gitweb: https://git.kernel.org/tip/eba302268a019275fd6ff452d4ff0b94fef11c76 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 21:59:51 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 02 Jun 2026 11:39:57 +02:00
timekeeping: Provide ktime_get_snapshot_id()
ktime_get_snapshot() provides a snapshot of the underlying clocksource counter value and the corresponding CLOCK_MONOTONIC_RAW, CLOCK_REALTIME and CLOCK_BOOTTIME timestamps.
There is no usage of CLOCK_REALTIME and CLOCK_BOOTTIME at the same time and CLOCK_BOOTTIME support was just added for the ARM64 KVM tracing mechanism, which needs CLOCK_BOOTTIME and the underlying clocksource counter value.
ktime_get_snapshot() is also not suitable for usage with CLOCK_AUX, but that's a prerequisite to support PTP hardware timestamping for CLOCK_AUX steering.
As a first step, rename ktime_get_snapshot() to ktime_get_snapshot_id(), which now takes a clockid argument to select the clock which needs to be captured. The result is stored in system_time_snapshot::systime, which will replace the system_time_snapshot::real/boot members once all usage sites have been converted.
ktime_get_snapshot() is a simple wrapper which hands in CLOCK_REALTIME as clockid argument for the conversion period. That means CLOCK_REALTIME is now captured twice, but that redunancy is only temporary.
As all usage sites of struct system_time_snapshot has to be updated anyway, rename the 'raw' member to 'monoraw' for clarity.
No functional change vs. current users of ktime_get_snapshot()
--- include/linux/timekeeping.h | 34 +++++++++----- kernel/time/timekeeping.c | 89 ++++++++++++++++++++++++++---------- 2 files changed, 90 insertions(+), 33 deletions(-)
include/linux/timekeeping.h +24 -10
@@ -276,24 +276,32 @@ static inline bool ktime_get_aux_ts64(clockid_t id, struct timespec64 *kt) { ret#endif /** -* struct system_time_snapshot - simultaneous raw/real time capture with -* counter value -* @cycles: Clocksource counter value to produce the system times -* @real: Realtime system time -* @boot: Boot time -* @raw: Monotonic raw system time -* @cs_id: Clocksource ID +* struct system_time_snapshot - Simultaneous time capture of CLOCK_MONOTONIC_RAW, +* a selected CLOCK_* and the clocksource counter value +* @cycles: Clocksource counter value to produce the system times +* @systime: The system time of the selected CLOCK ID +* @real: Realtime system time +* @boot: Boot time +* @raw: Monotonic raw system time +* @monoraw: Monotonic raw system time +* @cs_id: Clocksource ID * @clock_was_set_seq: The sequence number of clock-was-set events * @cs_was_changed_seq: The sequence number of clocksource change events +* @valid: True if the snapshot is valid */ struct system_time_snapshot {u64 cycles; +ktime_t systime;ktime_t real;ktime_t boot; -ktime_t raw; +union { +ktime_t raw; +ktime_t monoraw; + };enum clocksource_ids cs_id;unsigned int clock_was_set_seq;u8 cs_was_changed_seq; +u8 valid; };/**
@@ -341,9 +349,15 @@ extern int get_device_system_crosststamp( struct system_device_crosststamp *xtstamp);/* -* Simultaneously snapshot realtime and monotonic raw clocks +* Simultaneously snapshot a given clock with MONOTONIC_RAW and the underlying +* clocksource counter value. */ -extern void ktime_get_snapshot (struct system_time_snapshot *systime_snapshot); +extern void ktime_get_snapshot_id (clockid_t clock_id,struct system_time_snapshot *systime_snapshot); + +static inline void ktime_get_snapshot (struct system_time_snapshot *systime_snapshot) +{ +ktime_get_snapshot_id (CLOCK_REALTIME , systime_snapshot); +}/* * Persistent clock related interfaces
kernel/time/timekeeping.c +66 -23
109 lines not on this page · raw message
Thomas Gleixner
maintainerPATCH v2 2/25 timekeeping: Use system_time_snapshot::systime/monoraw instead of ::real/raw
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
system_time_snapshot::systime provides the same information as system_time_snapshot::real when the snapshot was taken with ktime_get_snapshot_id(CLOCK_REALTIME).
Convert the history interpolation over to use 'systime' and 'monoraw' as 'real/raw' are going away once all users are converted.
As a side effect this is the first step to support CLOCK_AUX with get_device_crosstime_stamp() and the history interpolation.
--- kernel/time/timekeeping.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/time/timekeeping.c +4 -4
@@ -1323,7 +1323,7 @@ static int adjust_historical_crosststamp* partial_history_cycles / total_history_cycles */ corr_raw = (u64 )ktime_to_ns ( -ktime_sub (ts->sys_monoraw, history->raw)); +ktime_sub (ts->sys_monoraw, history->monoraw)); ret =scale64_check_overflow (partial_history_cycles, total_history_cycles, &corr_raw);if (ret)
@@ -1341,7 +1341,7 @@ static int adjust_historical_crosststamp (corr_raw, tk->tkr_mono.mult, tk->tkr_raw.mult); }else { corr_real = (u64 )ktime_to_ns ( -ktime_sub (ts->sys_realtime, history->real)); +ktime_sub (ts->sys_realtime, history->systime)); ret =scale64_check_overflow (partial_history_cycles, total_history_cycles, &corr_real);if (ret)
@@ -1350,8 +1350,8 @@ static int adjust_historical_crosststamp/* Fixup monotonic raw and real time time values */ if (interp_forward) { - ts->sys_monoraw =ktime_add_ns (history->raw, corr_raw); - ts->sys_realtime =ktime_add_ns (history->real, corr_real); + ts->sys_monoraw =ktime_add_ns (history->monoraw, corr_raw); + ts->sys_realtime =ktime_add_ns (history->systime, corr_real); }else { ts->sys_monoraw =ktime_sub_ns (ts->sys_monoraw, corr_raw); ts->sys_realtime =ktime_sub_ns (ts->sys_realtime, corr_real);
[tip: timers/ptp] timekeeping: Use system_time_snapshot::systime/monoraw instead of ::real/raw
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: ef22786707e3967b539c3b1e6b5c7ea8b408430f Gitweb: https://git.kernel.org/tip/ef22786707e3967b539c3b1e6b5c7ea8b408430f Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 21:59:55 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 02 Jun 2026 11:39:57 +02:00
timekeeping: Use system_time_snapshot::systime/monoraw instead of ::real/raw
system_time_snapshot::systime provides the same information as system_time_snapshot::real when the snapshot was taken with ktime_get_snapshot_id(CLOCK_REALTIME).
Convert the history interpolation over to use 'systime' and 'monoraw' as 'real/raw' are going away once all users are converted.
As a side effect this is the first step to support CLOCK_AUX with get_device_crosstime_stamp() and the history interpolation.
--- kernel/time/timekeeping.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/time/timekeeping.c +4 -4
@@ -1323,7 +1323,7 @@ static int adjust_historical_crosststamp(struct system_time_snapshot *history,* partial_history_cycles / total_history_cycles */ corr_raw = (u64 )ktime_to_ns ( -ktime_sub (ts->sys_monoraw, history->raw)); +ktime_sub (ts->sys_monoraw, history->monoraw)); ret =scale64_check_overflow (partial_history_cycles, total_history_cycles, &corr_raw);if (ret)
@@ -1341,7 +1341,7 @@ static int adjust_historical_crosststamp(struct system_time_snapshot *history, (corr_raw, tk->tkr_mono.mult, tk->tkr_raw.mult); }else { corr_real = (u64 )ktime_to_ns ( -ktime_sub (ts->sys_realtime, history->real)); +ktime_sub (ts->sys_realtime, history->systime)); ret =scale64_check_overflow (partial_history_cycles, total_history_cycles, &corr_real);if (ret)
@@ -1350,8 +1350,8 @@ static int adjust_historical_crosststamp(struct system_time_snapshot *history,/* Fixup monotonic raw and real time time values */ if (interp_forward) { - ts->sys_monoraw =ktime_add_ns (history->raw, corr_raw); - ts->sys_realtime =ktime_add_ns (history->real, corr_real); + ts->sys_monoraw =ktime_add_ns (history->monoraw, corr_raw); + ts->sys_realtime =ktime_add_ns (history->systime, corr_real); }else { ts->sys_monoraw =ktime_sub_ns (ts->sys_monoraw, corr_raw); ts->sys_realtime =ktime_sub_ns (ts->sys_realtime, corr_real);
Thomas Gleixner
maintainerPATCH v2 3/25 pps: generators: Use ktime_get_real_ts64() instead of ktime_get_snapshot()
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
There is no reason to use the more complex ktime_get_snapshot() for retrieving CLOCK_REALTIME.
Just use ktime_get_real_ts64(), which avoids the extra timespec64 conversion as a bonus.
No functional change intended.
--- drivers/pps/generators/pps_gen-dummy.c | 6 +----- drivers/pps/generators/pps_gen_tio.c | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-)
drivers/pps/generators/pps_gen-dummy.c +1 -5
@@ -39,11 +39,7 @@ static void pps_gen_ktimer_event(structstatic int pps_gen_dummy_get_time (struct pps_gen_device *pps_gen,struct timespec64 *time) { -struct system_time_snapshot snap; - -ktime_get_snapshot (&snap); - *time =ktime_to_timespec64 (snap.real); - +ktime_get_real_ts64 (time);return 0 ; }
drivers/pps/generators/pps_gen_tio.c +1 -5
@@ -189,11 +189,7 @@ static int pps_tio_gen_enable(struct ppsstatic int pps_tio_get_time (struct pps_gen_device *pps_gen,struct timespec64 *time) { -struct system_time_snapshot snap; - -ktime_get_snapshot (&snap); - *time =ktime_to_timespec64 (snap.real); - +ktime_get_real_ts64 (time);return 0 ; }
Rodolfo Giometti
maintainer Acked-by Tested-by Arthur Kiyanovski Reviewed-by David Woodhouse Reviewed-by Thomas Weißschuh Reviewed-by Jacob Keller on v2 3/25Re: [patch V2 03/25] pps: generators: Use ktime_get_real_ts64() instead of ktime_get_snapshot()
Quoted 8 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
There is no reason to use the more complex
ktime_get_snapshot()for retrievingCLOCK_REALTIME.Just use
ktime_get_real_ts64(), which avoids the extra timespec64 conversion as a bonus.
Quoted 7 lines
No functional change intended.
Signed-off-by Thomas Gleixner <[email protected]>Tested-by Arthur Kiyanovski <[email protected]>Reviewed-by David Woodhouse <[email protected]>Reviewed-by Thomas Weißschuh <[email protected]>Reviewed-by Jacob Keller <[email protected]>
Quoted 10 lines
--- drivers/pps/generators/pps_gen-dummy.c | 6 +----- drivers/pps/generators/pps_gen_tio.c | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-)drivers/pps/generators/pps_gen-dummy.c +0
-0@@ -39,11 +39,7 @@ static void pps_gen_ktimer_event(structstatic int pps_gen_dummy_get_time (struct pps_gen_device *pps_gen,struct timespec64 *time) {
drivers/pps/generators/pps_gen-dummy.c static void pps_gen_ktimer_event(struct
Quoted 10 lines
drivers/pps/generators/pps_gen-dummy.c +1
-6-struct system_time_snapshot snap; - -ktime_get_snapshot (&snap); - *time =ktime_to_timespec64 (snap.real); - +ktime_get_real_ts64 (time);return 0 ; } --- a/drivers/pps/generators/pps_gen_
From: Thomas Gleixner <[email protected]>
There is no reason to use the more complex ktime_get_snapshot() for retrieving CLOCK_REALTIME.
Just use ktime_get_real_ts64(), which avoids the extra timespec64 conversion as a bonus.
No functional change intended.
--- drivers/pps/generators/pps_gen-dummy.c | 6 +----- drivers/pps/generators/pps_gen_tio.c | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-)
drivers/pps/generators/pps_gen-dummy.c +1 -5
@@ -39,11 +39,7 @@ static void pps_gen_ktimer_event(structstatic int pps_gen_dummy_get_time (struct pps_gen_device *pps_gen,struct timespec64 *time) { -struct system_time_snapshot snap; - -ktime_get_snapshot (&snap); - *time =ktime_to_timespec64 (snap.real); - +ktime_get_real_ts64 (time);return 0 ; }
drivers/pps/generators/pps_gen_tio.c +1 -5
@@ -189,11 +189,7 @@ static int pps_tio_gen_enable(struct ppsstatic int pps_tio_get_time (struct pps_gen_device *pps_gen,struct timespec64 *time) { -struct system_time_snapshot snap; - -ktime_get_snapshot (&snap); - *time =ktime_to_timespec64 (snap.real); - +ktime_get_real_ts64 (time);return 0 ; }
tio.c
Quoted 15 lines
+++
b/drivers/pps/generators/pps_gen_tio.cdrivers/pps/generators/pps_gen-dummy.c +1
-5@@ -189,11 +189,7 @@ static int pps_tio_gen_enable(struct ppsstatic int pps_tio_get_time (struct pps_gen_device *pps_gen,struct timespec64 *time) { -struct system_time_snapshot snap; - -ktime_get_snapshot (&snap); - *time =ktime_to_timespec64 (snap.real); - +ktime_get_real_ts64 (time);return 0 ; }
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems phone: +39 349 2432127 UNIX programming
[tip: timers/ptp] pps: generators: Use ktime_get_real_ts64() instead of ktime_get_snapshot()
In reply to Thomas GleixnerThe following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: fe1159fe49b40f73de88d2c29200c813952e061f Gitweb: https://git.kernel.org/tip/fe1159fe49b40f73de88d2c29200c813952e061f Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 21:59:59 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 02 Jun 2026 11:39:58 +02:00
pps: generators: Use ktime_get_real_ts64() instead of ktime_get_snapshot()
There is no reason to use the more complex ktime_get_snapshot() for retrieving CLOCK_REALTIME.
Just use ktime_get_real_ts64(), which avoids the extra timespec64 conversion as a bonus.
No functional change intended.
--- drivers/pps/generators/pps_gen-dummy.c | 6 +----- drivers/pps/generators/pps_gen_tio.c | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-)
drivers/pps/generators/pps_gen-dummy.c +1 -5
@@ -39,11 +39,7 @@ static void pps_gen_ktimer_event(struct timer_list *unused)static int pps_gen_dummy_get_time (struct pps_gen_device *pps_gen,struct timespec64 *time) { -struct system_time_snapshot snap; - -ktime_get_snapshot (&snap); - *time =ktime_to_timespec64 (snap.real); - +ktime_get_real_ts64 (time);return 0 ; }
drivers/pps/generators/pps_gen_tio.c +1 -5
@@ -189,11 +189,7 @@ static int pps_tio_gen_enable(struct pps_gen_device *pps_gen, bool enable)static int pps_tio_get_time (struct pps_gen_device *pps_gen,struct timespec64 *time) { -struct system_time_snapshot snap; - -ktime_get_snapshot (&snap); - *time =ktime_to_timespec64 (snap.real); - +ktime_get_real_ts64 (time);return 0 ; }
Thomas Gleixner
maintainerPATCH v2 4/25 pps: Convert to ktime_get_snapshot_id()
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
ktime_get_snapshot() resolves to ktime_get_snapshot_id(CLOCK_REALTIME).
Make it obvious in the code and convert the readout to use the snapshot::systime and monoraw fields instead of snapshot::real and raw, which aregoing away.
Similar to the PPS generators, avoid the more expensive snapshot when CONFIG_NTP_PPS is disabled.
No functional change intended.
--- include/linux/pps_kernel.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
include/linux/pps_kernel.h +6 -4
@@ -99,12 +99,14 @@ static inline void timespec_to_pps_ktimestatic inline void pps_get_ts (struct pps_event_time *ts) { +#ifdef CONFIG_NTP_PPS struct system_time_snapshot snap; -ktime_get_snapshot (&snap); - ts->ts_real =ktime_to_timespec64 (snap.real); -#ifdef CONFIG_NTP_PPS - ts->ts_raw =ktime_to_timespec64 (snap.raw); +ktime_get_snapshot_id (CLOCK_REALTIME , &snap); + ts->ts_real =ktime_to_timespec64 (snap.systime); + ts->ts_raw =ktime_to_timespec64 (snap.monoraw); +#else +ktime_get_real_ts64 (&ts->ts_real);#endif }
Rodolfo Giometti
maintainerRe: [patch V2 04/25] pps: Convert to ktime_get_snapshot_id()
Quoted 29 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
ktime_get_snapshot()resolves toktime_get_snapshot_id(CLOCK_REALTIME).Make it obvious in the code and convert the readout to use the
snapshot::systimeand monoraw fields instead ofsnapshot::realand raw, which aregoing away.Similar to the PPS generators, avoid the more expensive snapshot when
CONFIG_NTP_PPSis disabled.No functional change intended.
Signed-off-by Thomas Gleixner <[email protected]>Tested-by Arthur Kiyanovski <[email protected]>Reviewed-by David Woodhouse <[email protected]>Reviewed-by Thomas Weißschuh <[email protected]>Reviewed-by Jacob Keller <[email protected]>--- include/linux/pps_kernel.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)include/linux/pps_kernel.h +1
-0@@ -99,12 +99,14 @@ static inline void timespec_to_pps_ktimestatic inline void pps_get_ts (struct pps_event_time *ts) { +#ifdef CONFIG_NTP_PPS struct system_time_snapshot snap;
include/linux/pps_kernel.h static inline void timespec_to_pps_ktime · line 109
Quoted 10 lines
include/linux/pps_kernel.h +5
-4-ktime_get_snapshot (&snap); - ts->ts_real =ktime_to_timespec64 (snap.real); -#ifdef CONFIG_NTP_PPS - ts->ts_raw =ktime_to_timespec64 (snap.raw); +ktime_get_snapshot_id (CLOCK_REALTIME , &snap); + ts->ts_real =ktime_to_timespec64 (snap.systime); + ts->ts_raw =ktime_to_timespec64 (snap.monoraw); +#else +ktime_get_real_ts64 (&ts->ts_real);
/*
* Prevent kernel stack information disclosure if the
* structure is later copied to userspace.
*/
ts->ts_raw = (struct timespec64){0, 0};include/linux/pps_kernel.h static inline void timespec_to_pps_ktime · line 112
Quoted 4 lines
include/linux/pps_kernel.h +0
-0#endif }
Ciao,
Rodolfo
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems phone: +39 349 2432127 UNIX programming
Thomas Gleixner
maintainerRe: [patch V2 04/25] pps: Convert to ktime_get_snapshot_id()
Quoted 6 lines · Rodolfo Giometti
Quoted 5 lines · Thomas Gleixner
static inline void
pps_get_ts(struct pps_event_time *ts){
+#ifdefCONFIG_NTP_PPS
structsystem_time_snapshotsnap;
Quoted 15 lines
include/linux/pps_kernel.h static inline void timespec_to_pps_ktime · line 109
Quoted 9 lines
include/linux/pps_kernel.h +5
-4-ktime_get_snapshot (&snap); - ts->ts_real =ktime_to_timespec64 (snap.real); -#ifdef CONFIG_NTP_PPS - ts->ts_raw =ktime_to_timespec64 (snap.raw); +ktime_get_snapshot_id (CLOCK_REALTIME , &snap); + ts->ts_real =ktime_to_timespec64 (snap.systime); + ts->ts_raw =ktime_to_timespec64 (snap.monoraw); +#else +ktime_get_real_ts64 (&ts->ts_real);/* * Prevent kernel stack information disclosure if the * structure is later copied to userspace. */ ts->ts_raw = (struct timespec64){0, 0};
Which will fail to build because of:
struct pps_event_time {
#ifdef CONFIG_NTP_PPS
struct timespec64 ts_raw;
#endif /* CONFIG_NTP_PPS */
struct timespec64 ts_real;
};No?
David Woodhouse
maintainerRe: [patch V2 04/25] pps: Convert to ktime_get_snapshot_id()
Quoted 25 lines · Thomas Gleixner
Quoted 13 lines · Rodolfo Giometti
Quoted 12 lines · Thomas Gleixner
static inline void
pps_get_ts(struct pps_event_time *ts){
+#ifdefCONFIG_NTP_PPS
structsystem_time_snapshotsnap;include/linux/pps_kernel.h +3
-4-ktime_get_snapshot (&snap); - ts->ts_real =ktime_to_timespec64 (snap.real); -#ifdef CONFIG_NTP_PPS - ts->ts_raw =ktime_to_timespec64 (snap.raw); +ktime_get_snapshot_id (CLOCK_REALTIME , &snap); + ts->ts_real =ktime_to_timespec64 (snap.systime); + ts->ts_raw =ktime_to_timespec64 (snap.monoraw);Quoted 8 lines
include/linux/pps_kernel.h static inline void timespec_to_pps_ktime · line 109
Quoted 2 lines
include/linux/pps_kernel.h +2
-0+#else +ktime_get_real_ts64 (&ts->ts_real);/*
* Prevent kernel stack information disclosure if the
* structure is later copied to userspace. */
ts->ts_raw= (struct timespec64){0, 0};Which will fail to build because of:
Quoted 8 lines
struct
pps_event_time{
#ifdefCONFIG_NTP_PPS
struct timespec64ts_raw;
#endif /*CONFIG_NTP_PPS*/
struct timespec64ts_real;
};No?
I think we should kill struct pps_event_time and just use a system_time_snapshot anyway.
And I think we can make CONFIG_NTP_PPS work for NOHZ too. If I understand correctly, the main problem with NOHZ is that without a tick, the reported CLOCK_REALTIME sawtooths much more around the time that the core timekeeping *wants* to report. That is, tk->ntp_error goes much higher and much lower, than when the precise 'mult' rate can be re-adjusted every tick to keep it on course.
If we add an ntp_error field to the system_time_snapshot, the PPS code could use that to correct the CLOCK_REALTIME value and the jitter that NOHZ introduces wouldn't matter.
[tip: timers/ptp] pps: Convert to ktime_get_snapshot_id()
In reply to Thomas GleixnerThe following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: d5becddf8a0f18bcc18129efa086530b5263c6b4 Gitweb: https://git.kernel.org/tip/d5becddf8a0f18bcc18129efa086530b5263c6b4 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:04 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 02 Jun 2026 11:39:58 +02:00
pps: Convert to ktime_get_snapshot_id()
ktime_get_snapshot() resolves to ktime_get_snapshot_id(CLOCK_REALTIME).
Make it obvious in the code and convert the readout to use the snapshot::systime and monoraw fields instead of snapshot::real and raw, which aregoing away.
Similar to the PPS generators, avoid the more expensive snapshot when CONFIG_NTP_PPS is disabled.
No functional change intended.
--- include/linux/pps_kernel.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
include/linux/pps_kernel.h +6 -4
@@ -99,12 +99,14 @@ static inline void timespec_to_pps_ktime(struct pps_ktime *kt,static inline void pps_get_ts (struct pps_event_time *ts) { +#ifdef CONFIG_NTP_PPS struct system_time_snapshot snap; -ktime_get_snapshot (&snap); - ts->ts_real =ktime_to_timespec64 (snap.real); -#ifdef CONFIG_NTP_PPS - ts->ts_raw =ktime_to_timespec64 (snap.raw); +ktime_get_snapshot_id (CLOCK_REALTIME , &snap); + ts->ts_real =ktime_to_timespec64 (snap.systime); + ts->ts_raw =ktime_to_timespec64 (snap.monoraw); +#else +ktime_get_real_ts64 (&ts->ts_real);#endif }
Thomas Gleixner
maintainerPATCH v2 5/25 KVM: arm64: Use ktime_get_snapshot_id() to retrieve CLOCK_BOOTTIME
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
ktime_get_snapshot() is replaced by ktime_get_snapshot_id() which allows to request a particular CLOCK ID to be captured along with the clocksource counter.
Convert the tracing mechanism over and use the new system_time_snapshot::systime field, which holds the system timestamp selected by the CLOCK ID argument.
No functional change intended.
--- arch/arm64/kvm/hyp_trace.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm64/kvm/hyp_trace.c +4 -4
@@ -51,8 +51,8 @@ static void __hyp_clock_work(struct work hyp_clock = container_of(dwork, struct hyp_trace_clock, work); -ktime_get_snapshot (&snap); - boot =ktime_to_ns (snap.boot); +ktime_get_snapshot_id (CLOCK_BOOTTIME , &snap); + boot =ktime_to_ns (snap.systime); delta_boot = boot - hyp_clock->boot; delta_cycles = snap.cycles - hyp_clock->cycles;
@@ -118,9 +118,9 @@ static void hyp_trace_clock_enable(struc hyp_clock->running = false; } -ktime_get_snapshot (&snap); +ktime_get_snapshot_id (&snap,CLOCK_BOOTTIME ); - hyp_clock->boot =ktime_to_ns (snap.boot); + hyp_clock->boot =ktime_to_ns (snap.systime); hyp_clock->cycles = snap.cycles; hyp_clock->mult =0 ;
[tip: timers/ptp] KVM: arm64: Use ktime_get_snapshot_id() to retrieve CLOCK_BOOTTIME
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: d09439210441efbadd8b0aa32c1ddb1eab2f3abd Gitweb: https://git.kernel.org/tip/d09439210441efbadd8b0aa32c1ddb1eab2f3abd Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:08 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 02 Jun 2026 11:39:58 +02:00
KVM: arm64: Use ktime_get_snapshot_id() to retrieve CLOCK_BOOTTIME
ktime_get_snapshot() is replaced by ktime_get_snapshot_id() which allows to request a particular CLOCK ID to be captured along with the clocksource counter.
Convert the tracing mechanism over and use the new system_time_snapshot::systime field, which holds the system timestamp selected by the CLOCK ID argument.
No functional change intended.
--- arch/arm64/kvm/hyp_trace.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm64/kvm/hyp_trace.c +4 -4
@@ -51,8 +51,8 @@ static void __hyp_clock_work(struct work_struct *work) hyp_clock = container_of(dwork, struct hyp_trace_clock, work); -ktime_get_snapshot (&snap); - boot =ktime_to_ns (snap.boot); +ktime_get_snapshot_id (CLOCK_BOOTTIME , &snap); + boot =ktime_to_ns (snap.systime); delta_boot = boot - hyp_clock->boot; delta_cycles = snap.cycles - hyp_clock->cycles;
@@ -118,9 +118,9 @@ static void hyp_trace_clock_enable(struct hyp_trace_clock *hyp_clock, bool enabl hyp_clock->running = false; } -ktime_get_snapshot (&snap); +ktime_get_snapshot_id (&snap,CLOCK_BOOTTIME ); - hyp_clock->boot =ktime_to_ns (snap.boot); + hyp_clock->boot =ktime_to_ns (snap.systime); hyp_clock->cycles = snap.cycles; hyp_clock->mult =0 ;
Re: [tip: timers/ptp] KVM: arm64: Use ktime_get_snapshot_id() to retrieve CLOCK_BOOTTIME
Hi Thomas,
Quoted 10 lines · On Tue, Jun 02, 2026 at 09:46:13AM -0000, tip-bot2 for Thomas Gleixner wrote:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: d09439210441efbadd8b0aa32c1ddb1eab2f3abd Gitweb: https://git.kernel.org/tip/d09439210441efbadd8b0aa32c1ddb1eab2f3abd Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:08 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 02 Jun 2026 11:39:58 +02:00KVM: arm64: Use
ktime_get_snapshot_id()to retrieveCLOCK_BOOTTIME
...
Quoted 19 lines
arch/arm64/kvm/hyp_trace.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)arch/arm64/kvm/hyp_trace.c +2
-2@@ -51,8 +51,8 @@ static void __hyp_clock_work(struct work_struct *work) hyp_clock = container_of(dwork, struct hyp_trace_clock, work); -ktime_get_snapshot (&snap); - boot =ktime_to_ns (snap.boot); +ktime_get_snapshot_id (CLOCK_BOOTTIME , &snap); + boot =ktime_to_ns (snap.systime); delta_boot = boot - hyp_clock->boot; delta_cycles = snap.cycles - hyp_clock->cycles;
arch/arm64/kvm/hyp_trace.c static void hyp_trace_clock_enable(struct hyp_trace_clock *hyp_clock, bool enabl · line 121
Quoted 5 lines
arch/arm64/kvm/hyp_trace.c +1
-1@@ -118,9 +118,9 @@ static void hyp_trace_clock_enable(struct hyp_trace_clock *hyp_clock, bool enabl hyp_clock->running = false; } -ktime_get_snapshot (&snap); +ktime_get_snapshot_id (&snap,CLOCK_BOOTTIME );
It looks like this instance of ktime_get_snapshot_id() did not get its arguments swapped when applied, which breaks the build in -next:
arch/arm64/kvm/hyp_trace.c:121:24: error: incompatible pointer to integer conversion passing 'struct system_time_snapshot *' to parameter of type 'clockid_t' (aka 'int') [-Wint-conversion]
121 | ktime_get_snapshot_id(&snap, CLOCK_BOOTTIME);
| ^~~~~
include/linux/timekeeping.h:357:45: note: passing argument to parameter 'clock_id' here
357 | extern void ktime_get_snapshot_id(clockid_t clock_id, struct system_time_snapshot *systime_snapshot);
| ^
arch/arm64/kvm/hyp_trace.c:121:31: error: incompatible integer to pointer conversion passing 'int' to parameter of type 'struct system_time_snapshot *' [-Wint-conversion]
121 | ktime_get_snapshot_id(&snap, CLOCK_BOOTTIME);
| ^~~~~~~~~~~~~~
include/uapi/linux/time.h:56:26: note: expanded from macro 'CLOCK_BOOTTIME'
56 | #define CLOCK_BOOTTIME 7
| ^
include/linux/timekeeping.h:357:84: note: passing argument to parameter 'systime_snapshot' here
357 | extern void ktime_get_snapshot_id(clockid_t clock_id, struct system_time_snapshot *systime_snapshot);
| ^2 errors generated.
Do you want a fix up patch or do you want to just squash in the fix?
Quoted 5 lines
arch/arm64/kvm/hyp_trace.c +1
-1- hyp_clock->boot =ktime_to_ns (snap.boot); + hyp_clock->boot =ktime_to_ns (snap.systime); hyp_clock->cycles = snap.cycles; hyp_clock->mult =0 ;
Signature · 2 lines
Cheers, Nathan
Thomas Gleixner
maintainerRe: [tip: timers/ptp] KVM: arm64: Use ktime_get_snapshot_id() to retrieve CLOCK_BOOTTIME
Quoted 6 lines · Nathan Chancellor
arch/arm64/kvm/hyp_trace.c static void hyp_trace_clock_enable(struct hyp_trace_clock *hyp_clock, bool enabl · line 121
Quoted 3 lines
arch/arm64/kvm/hyp_trace.c +1
-1-ktime_get_snapshot (&snap); +ktime_get_snapshot_id (&snap,CLOCK_BOOTTIME );It looks like this instance of
ktime_get_snapshot_id()did not get its arguments swapped when applied, which breaks the build in -next:
Yes. I'm an idiot. I had it on my checklist for merging and then ....
Quoted 1 line
Do you want a fix up patch or do you want to just squash in the fix?
I squashed it.
[tip: timers/ptp] KVM: arm64: Use ktime_get_snapshot_id() to retrieve CLOCK_BOOTTIME
In reply to Thomas GleixnerThe following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: ed645be2ab1bcbc0e27242c7316fc15475962333 Gitweb: https://git.kernel.org/tip/ed645be2ab1bcbc0e27242c7316fc15475962333 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:08 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 04 Jun 2026 11:04:16 +02:00
KVM: arm64: Use ktime_get_snapshot_id() to retrieve CLOCK_BOOTTIME
ktime_get_snapshot() is replaced by ktime_get_snapshot_id() which allows to request a particular CLOCK ID to be captured along with the clocksource counter.
Convert the tracing mechanism over and use the new system_time_snapshot::systime field, which holds the system timestamp selected by the CLOCK ID argument.
No functional change intended.
--- arch/arm64/kvm/hyp_trace.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm64/kvm/hyp_trace.c +4 -4
@@ -51,8 +51,8 @@ static void __hyp_clock_work(struct work_struct *work) hyp_clock = container_of(dwork, struct hyp_trace_clock, work); -ktime_get_snapshot (&snap); - boot =ktime_to_ns (snap.boot); +ktime_get_snapshot_id (CLOCK_BOOTTIME , &snap); + boot =ktime_to_ns (snap.systime); delta_boot = boot - hyp_clock->boot; delta_cycles = snap.cycles - hyp_clock->cycles;
@@ -118,9 +118,9 @@ static void hyp_trace_clock_enable(struct hyp_trace_clock *hyp_clock, bool enabl hyp_clock->running = false; } -ktime_get_snapshot (&snap); +ktime_get_snapshot_id (CLOCK_BOOTTIME , &snap); - hyp_clock->boot =ktime_to_ns (snap.boot); + hyp_clock->boot =ktime_to_ns (snap.systime); hyp_clock->cycles = snap.cycles; hyp_clock->mult =0 ;
Thomas Gleixner
maintainerPATCH v2 6/25 KVM: arm64: Use ktime_get_snapshot_id() to snapshot CLOCK_REALTIME
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
ktime_get_snapshot() is replaced by ktime_get_snapshot_id() which allows to request a particular CLOCK ID to be captured along with the clocksource counter.
Convert the usage in kvm_get_ptp_time() over and use the new system_time_snapshot::systime field, which holds the system timestamp selected by the CLOCK ID argument.
No functional change intended.
--- arch/arm64/kvm/hypercalls.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/arm64/kvm/hypercalls.c +3 -3
@@ -28,7 +28,7 @@ static void kvm_ptp_get_time(struct kvm_* system time and counter value must captured at the same * time to keep consistency and precision. */ -ktime_get_snapshot (&systime_snapshot); +ktime_get_snapshot_id (CLOCK_REALTIME , &systime_snapshot);/* * This is only valid if the current clocksource is the
@@ -61,8 +61,8 @@ static void kvm_ptp_get_time(struct kvm_* in the future (about 292 years from 1970, and at that stage * nobody will give a damn about it). */ - val[0 ] =upper_32_bits (systime_snapshot.real); - val[1 ] =lower_32_bits (systime_snapshot.real); + val[0 ] =upper_32_bits (systime_snapshot.systime); + val[1 ] =lower_32_bits (systime_snapshot.systime); val[2 ] =upper_32_bits (cycles); val[3 ] =lower_32_bits (cycles); }
[tip: timers/ptp] KVM: arm64: Use ktime_get_snapshot_id() to snapshot CLOCK_REALTIME
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 48efaad67a8d18b75512aa3ab5bbfe661866020f Gitweb: https://git.kernel.org/tip/48efaad67a8d18b75512aa3ab5bbfe661866020f Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:12 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 02 Jun 2026 11:39:58 +02:00
KVM: arm64: Use ktime_get_snapshot_id() to snapshot CLOCK_REALTIME
ktime_get_snapshot() is replaced by ktime_get_snapshot_id() which allows to request a particular CLOCK ID to be captured along with the clocksource counter.
Convert the usage in kvm_get_ptp_time() over and use the new system_time_snapshot::systime field, which holds the system timestamp selected by the CLOCK ID argument.
No functional change intended.
--- arch/arm64/kvm/hypercalls.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/arm64/kvm/hypercalls.c +3 -3
@@ -28,7 +28,7 @@ static void kvm_ptp_get_time(struct kvm_vcpu *vcpu, u64 *val)* system time and counter value must captured at the same * time to keep consistency and precision. */ -ktime_get_snapshot (&systime_snapshot); +ktime_get_snapshot_id (CLOCK_REALTIME , &systime_snapshot);/* * This is only valid if the current clocksource is the
@@ -61,8 +61,8 @@ static void kvm_ptp_get_time(struct kvm_vcpu *vcpu, u64 *val)* in the future (about 292 years from 1970, and at that stage * nobody will give a damn about it). */ - val[0 ] =upper_32_bits (systime_snapshot.real); - val[1 ] =lower_32_bits (systime_snapshot.real); + val[0 ] =upper_32_bits (systime_snapshot.systime); + val[1 ] =lower_32_bits (systime_snapshot.systime); val[2 ] =upper_32_bits (cycles); val[3 ] =lower_32_bits (cycles); }
[tip: timers/ptp] KVM: arm64: Use ktime_get_snapshot_id() to snapshot CLOCK_REALTIME
In reply to Thomas GleixnerThe following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 744f8406a3d197b8e466d1ab09c4c3b8de8d65ea Gitweb: https://git.kernel.org/tip/744f8406a3d197b8e466d1ab09c4c3b8de8d65ea Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:12 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 04 Jun 2026 11:04:16 +02:00
KVM: arm64: Use ktime_get_snapshot_id() to snapshot CLOCK_REALTIME
ktime_get_snapshot() is replaced by ktime_get_snapshot_id() which allows to request a particular CLOCK ID to be captured along with the clocksource counter.
Convert the usage in kvm_get_ptp_time() over and use the new system_time_snapshot::systime field, which holds the system timestamp selected by the CLOCK ID argument.
No functional change intended.
--- arch/arm64/kvm/hypercalls.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/arm64/kvm/hypercalls.c +3 -3
@@ -28,7 +28,7 @@ static void kvm_ptp_get_time(struct kvm_vcpu *vcpu, u64 *val)* system time and counter value must captured at the same * time to keep consistency and precision. */ -ktime_get_snapshot (&systime_snapshot); +ktime_get_snapshot_id (CLOCK_REALTIME , &systime_snapshot);/* * This is only valid if the current clocksource is the
@@ -61,8 +61,8 @@ static void kvm_ptp_get_time(struct kvm_vcpu *vcpu, u64 *val)* in the future (about 292 years from 1970, and at that stage * nobody will give a damn about it). */ - val[0 ] =upper_32_bits (systime_snapshot.real); - val[1 ] =lower_32_bits (systime_snapshot.real); + val[0 ] =upper_32_bits (systime_snapshot.systime); + val[1 ] =lower_32_bits (systime_snapshot.systime); val[2 ] =upper_32_bits (cycles); val[3 ] =lower_32_bits (cycles); }
Thomas Gleixner
maintainerPATCH v2 7/25 ptp: ptp_vmclock: Convert to ktime_get_snapshot_id()
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
ktime_get_snapshot() is replaced by ktime_get_snapshot_id() which allows to request a particular CLOCK ID to be captured along with the clocksource counter.
Convert vmclock over and use the new system_time_snapshot::systime field, which holds the system timestamp selected by the CLOCK ID argument.
No functional change intended.
--- drivers/ptp/ptp_vmclock.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/ptp/ptp_vmclock.c +4 -4
@@ -132,7 +132,7 @@ static int vmclock_get_crosststamp(struc* will be derived from the *same* counter value. * * If the system isn't using the same counter, then the value -* from ktime_get_snapshot() will still be used as pre_ts, and +* from ktime_get_snapshot_id() will still be used as pre_ts, and * ptp_read_system_postts() is called to populate postts after * calling get_cycles(). *
@@ -140,7 +140,7 @@ static int vmclock_get_crosststamp(struc* the seq_count loop. */ if (sts) { -ktime_get_snapshot (&systime_snapshot); +ktime_get_snapshot_id (CLOCK_REALTIME , &systime_snapshot);if (systime_snapshot.cs_id == st->cs_id) { cycle = systime_snapshot.cycles; }else {
@@ -181,7 +181,7 @@ static int vmclock_get_crosststamp(struc }if (sts) { - sts->pre_ts =ktime_to_timespec64 (systime_snapshot.real); + sts->pre_ts =ktime_to_timespec64 (systime_snapshot.systime);if (systime_snapshot.cs_id == st->cs_id) sts->post_ts = sts->pre_ts; }
@@ -272,7 +272,7 @@ static int ptp_vmclock_getcrosststamp(stif (ret == -ENODEV ) {struct system_time_snapshot systime_snapshot; -ktime_get_snapshot (&systime_snapshot); +ktime_get_snapshot_id (CLOCK_REALTIME , &systime_snapshot);if (systime_snapshot.cs_id ==CSID_X86_TSC || systime_snapshot.cs_id ==CSID_X86_KVM_CLK ) {
[tip: timers/ptp] ptp: ptp_vmclock: Convert to ktime_get_snapshot_id()
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: d3dae55436460830abb99e0519a093469ad08416 Gitweb: https://git.kernel.org/tip/d3dae55436460830abb99e0519a093469ad08416 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:16 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 02 Jun 2026 11:39:58 +02:00
ptp: ptp_vmclock: Convert to ktime_get_snapshot_id()
ktime_get_snapshot() is replaced by ktime_get_snapshot_id() which allows to request a particular CLOCK ID to be captured along with the clocksource counter.
Convert vmclock over and use the new system_time_snapshot::systime field, which holds the system timestamp selected by the CLOCK ID argument.
No functional change intended.
--- drivers/ptp/ptp_vmclock.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/ptp/ptp_vmclock.c +4 -4
@@ -132,7 +132,7 @@ static int vmclock_get_crosststamp(struct vmclock_state *st,* will be derived from the *same* counter value. * * If the system isn't using the same counter, then the value -* from ktime_get_snapshot() will still be used as pre_ts, and +* from ktime_get_snapshot_id() will still be used as pre_ts, and * ptp_read_system_postts() is called to populate postts after * calling get_cycles(). *
@@ -140,7 +140,7 @@ static int vmclock_get_crosststamp(struct vmclock_state *st,* the seq_count loop. */ if (sts) { -ktime_get_snapshot (&systime_snapshot); +ktime_get_snapshot_id (CLOCK_REALTIME , &systime_snapshot);if (systime_snapshot.cs_id == st->cs_id) { cycle = systime_snapshot.cycles; }else {
@@ -181,7 +181,7 @@ static int vmclock_get_crosststamp(struct vmclock_state *st, }if (sts) { - sts->pre_ts =ktime_to_timespec64 (systime_snapshot.real); + sts->pre_ts =ktime_to_timespec64 (systime_snapshot.systime);if (systime_snapshot.cs_id == st->cs_id) sts->post_ts = sts->pre_ts; }
@@ -272,7 +272,7 @@ static int ptp_vmclock_getcrosststamp(struct ptp_clock_info *ptp,if (ret == -ENODEV ) {struct system_time_snapshot systime_snapshot; -ktime_get_snapshot (&systime_snapshot); +ktime_get_snapshot_id (CLOCK_REALTIME , &systime_snapshot);if (systime_snapshot.cs_id ==CSID_X86_TSC || systime_snapshot.cs_id ==CSID_X86_KVM_CLK ) {
[tip: timers/ptp] ptp: ptp_vmclock: Convert to ktime_get_snapshot_id()
In reply to Thomas GleixnerThe following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 50de63d924deb0357d510818c7443b3446a837be Gitweb: https://git.kernel.org/tip/50de63d924deb0357d510818c7443b3446a837be Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:16 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 04 Jun 2026 11:04:16 +02:00
ptp: ptp_vmclock: Convert to ktime_get_snapshot_id()
ktime_get_snapshot() is replaced by ktime_get_snapshot_id() which allows to request a particular CLOCK ID to be captured along with the clocksource counter.
Convert vmclock over and use the new system_time_snapshot::systime field, which holds the system timestamp selected by the CLOCK ID argument.
No functional change intended.
--- drivers/ptp/ptp_vmclock.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/ptp/ptp_vmclock.c +4 -4
@@ -132,7 +132,7 @@ static int vmclock_get_crosststamp(struct vmclock_state *st,* will be derived from the *same* counter value. * * If the system isn't using the same counter, then the value -* from ktime_get_snapshot() will still be used as pre_ts, and +* from ktime_get_snapshot_id() will still be used as pre_ts, and * ptp_read_system_postts() is called to populate postts after * calling get_cycles(). *
@@ -140,7 +140,7 @@ static int vmclock_get_crosststamp(struct vmclock_state *st,* the seq_count loop. */ if (sts) { -ktime_get_snapshot (&systime_snapshot); +ktime_get_snapshot_id (CLOCK_REALTIME , &systime_snapshot);if (systime_snapshot.cs_id == st->cs_id) { cycle = systime_snapshot.cycles; }else {
@@ -181,7 +181,7 @@ static int vmclock_get_crosststamp(struct vmclock_state *st, }if (sts) { - sts->pre_ts =ktime_to_timespec64 (systime_snapshot.real); + sts->pre_ts =ktime_to_timespec64 (systime_snapshot.systime);if (systime_snapshot.cs_id == st->cs_id) sts->post_ts = sts->pre_ts; }
@@ -272,7 +272,7 @@ static int ptp_vmclock_getcrosststamp(struct ptp_clock_info *ptp,if (ret == -ENODEV ) {struct system_time_snapshot systime_snapshot; -ktime_get_snapshot (&systime_snapshot); +ktime_get_snapshot_id (CLOCK_REALTIME , &systime_snapshot);if (systime_snapshot.cs_id ==CSID_X86_TSC || systime_snapshot.cs_id ==CSID_X86_KVM_CLK ) {
Thomas Gleixner
maintainerPATCH v2 8/25 timekeeping: Remove system_time_snapshot::real/boot/raw
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
All users are converted over to ktime_get_snapshot_id() and system_time_snapshot::systime and ::monoraw.
Remove the leftovers.
--- include/linux/timekeeping.h | 10 +--------- kernel/time/timekeeping.c | 8 -------- 2 files changed, 1 insertion(+), 17 deletions(-)
include/linux/timekeeping.h +1 -9
@@ -280,9 +280,6 @@ static inline bool ktime_get_aux_ts64(cl* a selected CLOCK_* and the clocksource counter value * @cycles: Clocksource counter value to produce the system times * @systime: The system time of the selected CLOCK ID -* @real: Realtime system time -* @boot: Boot time -* @raw: Monotonic raw system time * @monoraw: Monotonic raw system time * @cs_id: Clocksource ID * @clock_was_set_seq: The sequence number of clock-was-set events
@@ -292,12 +289,7 @@ static inline bool ktime_get_aux_ts64(clstruct system_time_snapshot {u64 cycles;ktime_t systime; -ktime_t real; -ktime_t boot; -union { -ktime_t raw; -ktime_t monoraw; - }; +ktime_t monoraw;enum clocksource_ids cs_id;unsigned int clock_was_set_seq;u8 cs_was_changed_seq;
kernel/time/timekeeping.c +0 -8
@@ -1196,8 +1196,6 @@ void ktime_get_snapshot_id(clockid_t clostruct timekeeper *tk;struct tk_data *tkd;unsigned int seq; -ktime_t base_real; -ktime_t base_boot;/* Invalidate the snapshot for all failure cases */ systime_snapshot->valid = false;
@@ -1239,18 +1237,12 @@ void ktime_get_snapshot_id(clockid_t clo offs_sys = *offs; base_raw = tk->tkr_raw.base; -/* Kept around until the callers are fixed up */ - base_real =ktime_add (base_sys, tk_core.timekeeper.offs_real); - base_boot =ktime_add (base_sys, tk_core.timekeeper.offs_boot); - nsec_sys =timekeeping_cycles_to_ns (&tk->tkr_mono, now); nsec_raw =timekeeping_cycles_to_ns (&tk->tkr_raw, now); }while (read_seqcount_retry (&tkd->seq, seq)); systime_snapshot->cycles = now; systime_snapshot->systime =ktime_add_ns (base_sys, offs_sys + nsec_sys); - systime_snapshot->real =ktime_add_ns (base_real, nsec_sys); - systime_snapshot->boot =ktime_add_ns (base_boot, nsec_sys); systime_snapshot->monoraw =ktime_add_ns (base_raw, nsec_raw);/*
[tip: timers/ptp] timekeeping: Remove system_time_snapshot::real/boot/raw
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 0a87dc71524f30e0c2df1171044201d78d6b0c55 Gitweb: https://git.kernel.org/tip/0a87dc71524f30e0c2df1171044201d78d6b0c55 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:20 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 02 Jun 2026 11:39:58 +02:00
timekeeping: Remove system_time_snapshot::real/boot/raw
All users are converted over to ktime_get_snapshot_id() and system_time_snapshot::systime and ::monoraw.
Remove the leftovers.
--- include/linux/timekeeping.h | 10 +--------- kernel/time/timekeeping.c | 8 -------- 2 files changed, 1 insertion(+), 17 deletions(-)
include/linux/timekeeping.h +1 -9
@@ -280,9 +280,6 @@ static inline bool ktime_get_aux_ts64(clockid_t id, struct timespec64 *kt) { ret* a selected CLOCK_* and the clocksource counter value * @cycles: Clocksource counter value to produce the system times * @systime: The system time of the selected CLOCK ID -* @real: Realtime system time -* @boot: Boot time -* @raw: Monotonic raw system time * @monoraw: Monotonic raw system time * @cs_id: Clocksource ID * @clock_was_set_seq: The sequence number of clock-was-set events
@@ -292,12 +289,7 @@ static inline bool ktime_get_aux_ts64(clockid_t id, struct timespec64 *kt) { retstruct system_time_snapshot {u64 cycles;ktime_t systime; -ktime_t real; -ktime_t boot; -union { -ktime_t raw; -ktime_t monoraw; - }; +ktime_t monoraw;enum clocksource_ids cs_id;unsigned int clock_was_set_seq;u8 cs_was_changed_seq;
kernel/time/timekeeping.c +0 -8
@@ -1196,8 +1196,6 @@ void ktime_get_snapshot_id(clockid_t clock_id, struct system_time_snapshot *syststruct timekeeper *tk;struct tk_data *tkd;unsigned int seq; -ktime_t base_real; -ktime_t base_boot;/* Invalidate the snapshot for all failure cases */ systime_snapshot->valid = false;
@@ -1239,18 +1237,12 @@ void ktime_get_snapshot_id(clockid_t clock_id, struct system_time_snapshot *syst offs_sys = *offs; base_raw = tk->tkr_raw.base; -/* Kept around until the callers are fixed up */ - base_real =ktime_add (base_sys, tk_core.timekeeper.offs_real); - base_boot =ktime_add (base_sys, tk_core.timekeeper.offs_boot); - nsec_sys =timekeeping_cycles_to_ns (&tk->tkr_mono, now); nsec_raw =timekeeping_cycles_to_ns (&tk->tkr_raw, now); }while (read_seqcount_retry (&tkd->seq, seq)); systime_snapshot->cycles = now; systime_snapshot->systime =ktime_add_ns (base_sys, offs_sys + nsec_sys); - systime_snapshot->real =ktime_add_ns (base_real, nsec_sys); - systime_snapshot->boot =ktime_add_ns (base_boot, nsec_sys); systime_snapshot->monoraw =ktime_add_ns (base_raw, nsec_raw);/*
[tip: timers/ptp] timekeeping: Remove system_time_snapshot::real/boot/raw
In reply to Thomas GleixnerThe following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 705e1068071f82b6c66b9e28124fbb7123b04c1d Gitweb: https://git.kernel.org/tip/705e1068071f82b6c66b9e28124fbb7123b04c1d Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:20 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 04 Jun 2026 11:04:16 +02:00
timekeeping: Remove system_time_snapshot::real/boot/raw
All users are converted over to ktime_get_snapshot_id() and system_time_snapshot::systime and ::monoraw.
Remove the leftovers.
--- include/linux/timekeeping.h | 10 +--------- kernel/time/timekeeping.c | 8 -------- 2 files changed, 1 insertion(+), 17 deletions(-)
include/linux/timekeeping.h +1 -9
@@ -280,9 +280,6 @@ static inline bool ktime_get_aux_ts64(clockid_t id, struct timespec64 *kt) { ret* a selected CLOCK_* and the clocksource counter value * @cycles: Clocksource counter value to produce the system times * @systime: The system time of the selected CLOCK ID -* @real: Realtime system time -* @boot: Boot time -* @raw: Monotonic raw system time * @monoraw: Monotonic raw system time * @cs_id: Clocksource ID * @clock_was_set_seq: The sequence number of clock-was-set events
@@ -292,12 +289,7 @@ static inline bool ktime_get_aux_ts64(clockid_t id, struct timespec64 *kt) { retstruct system_time_snapshot {u64 cycles;ktime_t systime; -ktime_t real; -ktime_t boot; -union { -ktime_t raw; -ktime_t monoraw; - }; +ktime_t monoraw;enum clocksource_ids cs_id;unsigned int clock_was_set_seq;u8 cs_was_changed_seq;
kernel/time/timekeeping.c +0 -8
@@ -1196,8 +1196,6 @@ void ktime_get_snapshot_id(clockid_t clock_id, struct system_time_snapshot *syststruct timekeeper *tk;struct tk_data *tkd;unsigned int seq; -ktime_t base_real; -ktime_t base_boot;/* Invalidate the snapshot for all failure cases */ systime_snapshot->valid = false;
@@ -1239,18 +1237,12 @@ void ktime_get_snapshot_id(clockid_t clock_id, struct system_time_snapshot *syst offs_sys = *offs; base_raw = tk->tkr_raw.base; -/* Kept around until the callers are fixed up */ - base_real =ktime_add (base_sys, tk_core.timekeeper.offs_real); - base_boot =ktime_add (base_sys, tk_core.timekeeper.offs_boot); - nsec_sys =timekeeping_cycles_to_ns (&tk->tkr_mono, now); nsec_raw =timekeeping_cycles_to_ns (&tk->tkr_raw, now); }while (read_seqcount_retry (&tkd->seq, seq)); systime_snapshot->cycles = now; systime_snapshot->systime =ktime_add_ns (base_sys, offs_sys + nsec_sys); - systime_snapshot->real =ktime_add_ns (base_real, nsec_sys); - systime_snapshot->boot =ktime_add_ns (base_boot, nsec_sys); systime_snapshot->monoraw =ktime_add_ns (base_raw, nsec_raw);/*
Thomas Gleixner
maintainerPATCH v2 9/25 timekeeping: Add CLOCK_AUX support for ktime_get_snapshot_id()
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
Now that all users are converted it's possible to enable snapshotting of CLOCK_AUX time. The underlying clocksource is the same as for all other CLOCK variants.
--- kernel/time/timekeeping.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
kernel/time/timekeeping.c +15 -0
@@ -67,6 +67,7 @@ static inline bool tk_is_aux(const struc {return tk->id >=TIMEKEEPER_AUX_FIRST && tk->id <=TIMEKEEPER_AUX_LAST ; } +static inline struct tk_data *aux_get_tk_data (clockid_t id);#else static inline bool tk_get_aux_ts64 (unsigned int tkid,struct timespec64 *ts) {
@@ -77,6 +78,10 @@ static inline bool tk_is_aux(const struc {return false; } +static inline struct tk_data *aux_get_tk_data (clockid_t id) +{ +return NULL ; +}#endif static inline void tk_update_aux_offs (struct timekeeper *tk,ktime_t offs)
@@ -1218,6 +1223,12 @@ void ktime_get_snapshot_id(clockid_t clo tkd = &tk_core; offs = &tk_core.timekeeper.offs_boot;break ; + case CLOCK_AUX ... CLOCK_AUX_LAST: + tkd =aux_get_tk_data (clock_id); +if (!tkd) +return ; + offs = &tkd->timekeeper.offs_aux; +break ;default :WARN_ON_ONCE (1 );return ;
@@ -1228,6 +1239,10 @@ void ktime_get_snapshot_id(clockid_t clo do { seq = read_seqcount_begin(&tkd->seq); + /* Aux clocks can be invalid */ + if (!tk->clock_valid) + return; + now = tk_clock_read(&tk->tkr_mono); systime_snapshot->cs_id = tk->tkr_mono.clock->id; systime_snapshot->cs_was_changed_seq = tk->cs_was_changed_seq;
[tip: timers/ptp] timekeeping: Add CLOCK_AUX support for ktime_get_snapshot_id()
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: a19658b83784d305ceed5bee3fdf5fdb955a5d1a Gitweb: https://git.kernel.org/tip/a19658b83784d305ceed5bee3fdf5fdb955a5d1a Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:24 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 02 Jun 2026 11:39:58 +02:00
timekeeping: Add CLOCK_AUX support for ktime_get_snapshot_id()
Now that all users are converted it's possible to enable snapshotting of CLOCK_AUX time. The underlying clocksource is the same as for all other CLOCK variants.
--- kernel/time/timekeeping.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
kernel/time/timekeeping.c +15 -0
@@ -67,6 +67,7 @@ static inline bool tk_is_aux(const struct timekeeper *tk) {return tk->id >=TIMEKEEPER_AUX_FIRST && tk->id <=TIMEKEEPER_AUX_LAST ; } +static inline struct tk_data *aux_get_tk_data (clockid_t id);#else static inline bool tk_get_aux_ts64 (unsigned int tkid,struct timespec64 *ts) {
@@ -77,6 +78,10 @@ static inline bool tk_is_aux(const struct timekeeper *tk) {return false; } +static inline struct tk_data *aux_get_tk_data (clockid_t id) +{ +return NULL ; +}#endif static inline void tk_update_aux_offs (struct timekeeper *tk,ktime_t offs)
@@ -1218,6 +1223,12 @@ void ktime_get_snapshot_id(clockid_t clock_id, struct system_time_snapshot *syst tkd = &tk_core; offs = &tk_core.timekeeper.offs_boot;break ; + case CLOCK_AUX ... CLOCK_AUX_LAST: + tkd =aux_get_tk_data (clock_id); +if (!tkd) +return ; + offs = &tkd->timekeeper.offs_aux; +break ;default :WARN_ON_ONCE (1 );return ;
@@ -1228,6 +1239,10 @@ void ktime_get_snapshot_id(clockid_t clock_id, struct system_time_snapshot *syst do { seq = read_seqcount_begin(&tkd->seq); + /* Aux clocks can be invalid */ + if (!tk->clock_valid) + return; + now = tk_clock_read(&tk->tkr_mono); systime_snapshot->cs_id = tk->tkr_mono.clock->id; systime_snapshot->cs_was_changed_seq = tk->cs_was_changed_seq;
[tip: timers/ptp] timekeeping: Add CLOCK_AUX support for ktime_get_snapshot_id()
In reply to Thomas GleixnerThe following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 23c1bfa9f8dbefe0be1fa32aaf235c08cb24bd78 Gitweb: https://git.kernel.org/tip/23c1bfa9f8dbefe0be1fa32aaf235c08cb24bd78 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:24 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 04 Jun 2026 11:04:16 +02:00
timekeeping: Add CLOCK_AUX support for ktime_get_snapshot_id()
Now that all users are converted it's possible to enable snapshotting of CLOCK_AUX time. The underlying clocksource is the same as for all other CLOCK variants.
--- kernel/time/timekeeping.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
kernel/time/timekeeping.c +15 -0
@@ -67,6 +67,7 @@ static inline bool tk_is_aux(const struct timekeeper *tk) {return tk->id >=TIMEKEEPER_AUX_FIRST && tk->id <=TIMEKEEPER_AUX_LAST ; } +static inline struct tk_data *aux_get_tk_data (clockid_t id);#else static inline bool tk_get_aux_ts64 (unsigned int tkid,struct timespec64 *ts) {
@@ -77,6 +78,10 @@ static inline bool tk_is_aux(const struct timekeeper *tk) {return false; } +static inline struct tk_data *aux_get_tk_data (clockid_t id) +{ +return NULL ; +}#endif static inline void tk_update_aux_offs (struct timekeeper *tk,ktime_t offs)
@@ -1218,6 +1223,12 @@ void ktime_get_snapshot_id(clockid_t clock_id, struct system_time_snapshot *syst tkd = &tk_core; offs = &tk_core.timekeeper.offs_boot;break ; + case CLOCK_AUX ... CLOCK_AUX_LAST: + tkd =aux_get_tk_data (clock_id); +if (!tkd) +return ; + offs = &tkd->timekeeper.offs_aux; +break ;default :WARN_ON_ONCE (1 );return ;
@@ -1228,6 +1239,10 @@ void ktime_get_snapshot_id(clockid_t clock_id, struct system_time_snapshot *syst do { seq = read_seqcount_begin(&tkd->seq); + /* Aux clocks can be invalid */ + if (!tk->clock_valid) + return; + now = tk_clock_read(&tk->tkr_mono); systime_snapshot->cs_id = tk->tkr_mono.clock->id; systime_snapshot->cs_was_changed_seq = tk->cs_was_changed_seq;
Thomas Gleixner
maintainerPATCH v2 10/25 timekeeping: Add system_counterval_t to struct system_device_crosststamp
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
An upcoming extension to the PTP IOCTL requires to return the system counter value and the clocksource ID to user space. get_device_system_crosststamp() has this information already.
Extend struct system_device_crosststamp with a system_counterval_t member and fill in the data.
--- include/linux/timekeeping.h | 28 ++++++++++++++------------ kernel/time/timekeeping.c | 46 ++++++++++++++++++++------------------------ 2 files changed, 36 insertions(+), 38 deletions(-)
include/linux/timekeeping.h +15 -13
@@ -297,19 +297,6 @@ struct system_time_snapshot { };/** -* struct system_device_crosststamp - system/device cross-timestamp -* (synchronized capture) -* @device: Device time -* @sys_realtime: Realtime simultaneous with device time -* @sys_monoraw: Monotonic raw simultaneous with device time -*/ -struct system_device_crosststamp { -ktime_t device; -ktime_t sys_realtime; -ktime_t sys_monoraw; -}; - -/** * struct system_counterval_t - system counter value with the ID of the * corresponding clocksource * @cycles: System counter value
@@ -325,6 +312,21 @@ struct system_counterval_t {bool use_nsecs; }; +/** +* struct system_device_crosststamp - system/device cross-timestamp +* (synchronized capture) +* @device: Device time +* @sys_counter: Clocksource counter value simultaneous with device time +* @sys_realtime: Realtime simultaneous with device time +* @sys_monoraw: Monotonic raw simultaneous with device time +*/ +struct system_device_crosststamp { +ktime_t device; +struct system_counterval_t sys_counter; +ktime_t sys_realtime; +ktime_t sys_monoraw; +}; +extern bool ktime_real_to_base_clock (ktime_t treal,enum clocksource_ids base_id,u64 *cycles);extern bool timekeeping_clocksource_has_base (enum clocksource_ids id);
kernel/time/timekeeping.c +21 -25
95 lines not on this page · raw message
[tip: timers/ptp] timekeeping: Add system_counterval_t to struct system_device_crosststamp
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 44e3ae4396f982f84a24d8c7d2b8f613a78ef34a Gitweb: https://git.kernel.org/tip/44e3ae4396f982f84a24d8c7d2b8f613a78ef34a Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:28 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 02 Jun 2026 11:39:58 +02:00
timekeeping: Add system_counterval_t to struct system_device_crosststamp
An upcoming extension to the PTP IOCTL requires to return the system counter value and the clocksource ID to user space. get_device_system_crosststamp() has this information already.
Extend struct system_device_crosststamp with a system_counterval_t member and fill in the data.
--- include/linux/timekeeping.h | 28 +++++++++++----------- kernel/time/timekeeping.c | 46 ++++++++++++++++-------------------- 2 files changed, 36 insertions(+), 38 deletions(-)
include/linux/timekeeping.h +15 -13
@@ -297,19 +297,6 @@ struct system_time_snapshot { };/** -* struct system_device_crosststamp - system/device cross-timestamp -* (synchronized capture) -* @device: Device time -* @sys_realtime: Realtime simultaneous with device time -* @sys_monoraw: Monotonic raw simultaneous with device time -*/ -struct system_device_crosststamp { -ktime_t device; -ktime_t sys_realtime; -ktime_t sys_monoraw; -}; - -/** * struct system_counterval_t - system counter value with the ID of the * corresponding clocksource * @cycles: System counter value
@@ -325,6 +312,21 @@ struct system_counterval_t {bool use_nsecs; }; +/** +* struct system_device_crosststamp - system/device cross-timestamp +* (synchronized capture) +* @device: Device time +* @sys_counter: Clocksource counter value simultaneous with device time +* @sys_realtime: Realtime simultaneous with device time +* @sys_monoraw: Monotonic raw simultaneous with device time +*/ +struct system_device_crosststamp { +ktime_t device; +struct system_counterval_t sys_counter; +ktime_t sys_realtime; +ktime_t sys_monoraw; +}; +extern bool ktime_real_to_base_clock (ktime_t treal,enum clocksource_ids base_id,u64 *cycles);extern bool timekeeping_clocksource_has_base (enum clocksource_ids id);
kernel/time/timekeeping.c +21 -25
95 lines not on this page · raw message
[tip: timers/ptp] timekeeping: Add system_counterval_t to struct system_device_crosststamp
In reply to Thomas GleixnerThe following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 6c14771816435a7ecf52d981a341e2de21463268 Gitweb: https://git.kernel.org/tip/6c14771816435a7ecf52d981a341e2de21463268 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:28 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 04 Jun 2026 11:04:16 +02:00
timekeeping: Add system_counterval_t to struct system_device_crosststamp
An upcoming extension to the PTP IOCTL requires to return the system counter value and the clocksource ID to user space. get_device_system_crosststamp() has this information already.
Extend struct system_device_crosststamp with a system_counterval_t member and fill in the data.
--- include/linux/timekeeping.h | 28 +++++++++++----------- kernel/time/timekeeping.c | 46 ++++++++++++++++-------------------- 2 files changed, 36 insertions(+), 38 deletions(-)
include/linux/timekeeping.h +15 -13
@@ -297,19 +297,6 @@ struct system_time_snapshot { };/** -* struct system_device_crosststamp - system/device cross-timestamp -* (synchronized capture) -* @device: Device time -* @sys_realtime: Realtime simultaneous with device time -* @sys_monoraw: Monotonic raw simultaneous with device time -*/ -struct system_device_crosststamp { -ktime_t device; -ktime_t sys_realtime; -ktime_t sys_monoraw; -}; - -/** * struct system_counterval_t - system counter value with the ID of the * corresponding clocksource * @cycles: System counter value
@@ -325,6 +312,21 @@ struct system_counterval_t {bool use_nsecs; }; +/** +* struct system_device_crosststamp - system/device cross-timestamp +* (synchronized capture) +* @device: Device time +* @sys_counter: Clocksource counter value simultaneous with device time +* @sys_realtime: Realtime simultaneous with device time +* @sys_monoraw: Monotonic raw simultaneous with device time +*/ +struct system_device_crosststamp { +ktime_t device; +struct system_counterval_t sys_counter; +ktime_t sys_realtime; +ktime_t sys_monoraw; +}; +extern bool ktime_real_to_base_clock (ktime_t treal,enum clocksource_ids base_id,u64 *cycles);extern bool timekeeping_clocksource_has_base (enum clocksource_ids id);
kernel/time/timekeeping.c +21 -25
95 lines not on this page · raw message
Thomas Gleixner
maintainerPATCH v2 11/25 timekeeping: Add CLOCK ID to system_device_crosststamp
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
The normal capture for system/device cross timestamps is CLOCK_REALTIME, but that's meaningless for AUX clocks.
Add a clock_id field to struct system_device_crosststamp and initialize it with CLOCK_REALTIME at the two places which prepare for cross timestamps.
After the related code has been cleaned up, the core code will honor the clock_id field when calculating the system time from the system counter snapshot.
No functional change.
--- drivers/ptp/ptp_chardev.c | 2 +- include/linux/timekeeping.h | 2 ++ sound/hda/common/controller.c | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-)
drivers/ptp/ptp_chardev.c +1 -1
@@ -317,8 +317,8 @@ typedef int (*ptp_crosststamp_fn)(structstatic long ptp_sys_offset_precise (struct ptp_clock *ptp,void __user *arg,ptp_crosststamp_fn crosststamp_fn) { +struct system_device_crosststamp xtstamp = { .clock_id =CLOCK_REALTIME };struct ptp_sys_offset_precise precise_offset; -struct system_device_crosststamp xtstamp;struct timespec64 ts;int err;
include/linux/timekeeping.h +2 -0
@@ -315,12 +315,14 @@ struct system_counterval_t {/** * struct system_device_crosststamp - system/device cross-timestamp * (synchronized capture) +* @clock_id: System time Clock ID to capture * @device: Device time * @sys_counter: Clocksource counter value simultaneous with device time * @sys_realtime: Realtime simultaneous with device time * @sys_monoraw: Monotonic raw simultaneous with device time */ struct system_device_crosststamp { +clockid_t clock_id;ktime_t device;struct system_counterval_t sys_counter;ktime_t sys_realtime;
sound/hda/common/controller.c +1 -1
@@ -489,9 +489,9 @@ static int azx_get_time_info(struct snd_struct snd_pcm_audio_tstamp_config *audio_tstamp_config, struct snd_pcm_audio_tstamp_report *audio_tstamp_report) { + struct system_device_crosststamp xtstamp = { .clock_id = CLOCK_REALTIME };struct azx_dev *azx_dev =get_azx_dev (substream);struct snd_pcm_runtime *runtime = substream->runtime; -struct system_device_crosststamp xtstamp;int ret;u64 nsec;
[tip: timers/ptp] timekeeping: Add CLOCK ID to system_device_crosststamp
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 98a8a67b497263441c0b6562d95fe01e80527fd1 Gitweb: https://git.kernel.org/tip/98a8a67b497263441c0b6562d95fe01e80527fd1 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:32 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 02 Jun 2026 11:39:58 +02:00
timekeeping: Add CLOCK ID to system_device_crosststamp
The normal capture for system/device cross timestamps is CLOCK_REALTIME, but that's meaningless for AUX clocks.
Add a clock_id field to struct system_device_crosststamp and initialize it with CLOCK_REALTIME at the two places which prepare for cross timestamps.
After the related code has been cleaned up, the core code will honor the clock_id field when calculating the system time from the system counter snapshot.
No functional change.
--- drivers/ptp/ptp_chardev.c | 2 +- include/linux/timekeeping.h | 2 ++ sound/hda/common/controller.c | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-)
drivers/ptp/ptp_chardev.c +1 -1
@@ -317,8 +317,8 @@ typedef int (*ptp_crosststamp_fn)(struct ptp_clock_info *,static long ptp_sys_offset_precise (struct ptp_clock *ptp,void __user *arg,ptp_crosststamp_fn crosststamp_fn) { +struct system_device_crosststamp xtstamp = { .clock_id =CLOCK_REALTIME };struct ptp_sys_offset_precise precise_offset; -struct system_device_crosststamp xtstamp;struct timespec64 ts;int err;
include/linux/timekeeping.h +2 -0
@@ -315,12 +315,14 @@ struct system_counterval_t {/** * struct system_device_crosststamp - system/device cross-timestamp * (synchronized capture) +* @clock_id: System time Clock ID to capture * @device: Device time * @sys_counter: Clocksource counter value simultaneous with device time * @sys_realtime: Realtime simultaneous with device time * @sys_monoraw: Monotonic raw simultaneous with device time */ struct system_device_crosststamp { +clockid_t clock_id;ktime_t device;struct system_counterval_t sys_counter;ktime_t sys_realtime;
sound/hda/common/controller.c +1 -1
@@ -489,9 +489,9 @@ static int azx_get_time_info(struct snd_pcm_substream *substream,struct snd_pcm_audio_tstamp_config *audio_tstamp_config, struct snd_pcm_audio_tstamp_report *audio_tstamp_report) { + struct system_device_crosststamp xtstamp = { .clock_id = CLOCK_REALTIME };struct azx_dev *azx_dev =get_azx_dev (substream);struct snd_pcm_runtime *runtime = substream->runtime; -struct system_device_crosststamp xtstamp;int ret;u64 nsec;
[tip: timers/ptp] timekeeping: Add CLOCK ID to system_device_crosststamp
In reply to Thomas GleixnerThe following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: e3b8d03faa4d266d19ff7a7534e7bf810ff681cf Gitweb: https://git.kernel.org/tip/e3b8d03faa4d266d19ff7a7534e7bf810ff681cf Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:32 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 04 Jun 2026 11:04:16 +02:00
timekeeping: Add CLOCK ID to system_device_crosststamp
The normal capture for system/device cross timestamps is CLOCK_REALTIME, but that's meaningless for AUX clocks.
Add a clock_id field to struct system_device_crosststamp and initialize it with CLOCK_REALTIME at the two places which prepare for cross timestamps.
After the related code has been cleaned up, the core code will honor the clock_id field when calculating the system time from the system counter snapshot.
No functional change.
--- drivers/ptp/ptp_chardev.c | 2 +- include/linux/timekeeping.h | 2 ++ sound/hda/common/controller.c | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-)
drivers/ptp/ptp_chardev.c +1 -1
@@ -317,8 +317,8 @@ typedef int (*ptp_crosststamp_fn)(struct ptp_clock_info *,static long ptp_sys_offset_precise (struct ptp_clock *ptp,void __user *arg,ptp_crosststamp_fn crosststamp_fn) { +struct system_device_crosststamp xtstamp = { .clock_id =CLOCK_REALTIME };struct ptp_sys_offset_precise precise_offset; -struct system_device_crosststamp xtstamp;struct timespec64 ts;int err;
include/linux/timekeeping.h +2 -0
@@ -315,12 +315,14 @@ struct system_counterval_t {/** * struct system_device_crosststamp - system/device cross-timestamp * (synchronized capture) +* @clock_id: System time Clock ID to capture * @device: Device time * @sys_counter: Clocksource counter value simultaneous with device time * @sys_realtime: Realtime simultaneous with device time * @sys_monoraw: Monotonic raw simultaneous with device time */ struct system_device_crosststamp { +clockid_t clock_id;ktime_t device;struct system_counterval_t sys_counter;ktime_t sys_realtime;
sound/hda/common/controller.c +1 -1
@@ -489,9 +489,9 @@ static int azx_get_time_info(struct snd_pcm_substream *substream,struct snd_pcm_audio_tstamp_config *audio_tstamp_config, struct snd_pcm_audio_tstamp_report *audio_tstamp_report) { + struct system_device_crosststamp xtstamp = { .clock_id = CLOCK_REALTIME };struct azx_dev *azx_dev =get_azx_dev (substream);struct snd_pcm_runtime *runtime = substream->runtime; -struct system_device_crosststamp xtstamp;int ret;u64 nsec;
Thomas Gleixner
maintainerPATCH v2 12/25 wifi: iwlwifi: Adopt PTP cross timestamps to core changes
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
iwlwifi only supports CLOCK_REALTIME timestamps and provides an incomplete result without system counter values etc.
It also zeros struct system_device_crosststamp, which is already zeroed in the core and initialized with the clock ID.
Remove the zeroing and reject any request for a clock ID other than REALTIME.
--- drivers/net/wireless/intel/iwlwifi/mld/ptp.c | 3 ++- drivers/net/wireless/intel/iwlwifi/mvm/ptp.c | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-)
drivers/net/wireless/intel/iwlwifi/mld/ptp.c +2 -1
@@ -250,7 +250,8 @@ iwl_mld_phc_get_crosstimestamp(struct pt/* System (wall) time */ ktime_t sys_time; -memset (xtstamp,0 ,sizeof (struct system_device_crosststamp )); +if (xtstamp->clock_id !=CLOCK_REALTIME ) +return -ENOTSUPP ; ret =iwl_mld_get_crosstimestamp_fw (mld, &gp2, &sys_time);if (ret) {
drivers/net/wireless/intel/iwlwifi/mvm/ptp.c +3 -2
@@ -160,13 +160,14 @@ iwl_mvm_phc_get_crosstimestamp(struct pt/* System (wall) time */ ktime_t sys_time; -memset (xtstamp,0 ,sizeof (struct system_device_crosststamp )); -if (!mvm->ptp_data.ptp_clock) {IWL_ERR (mvm,"No PHC clock registered\n" );return -ENODEV ; } +if (xtstamp->clock_id !=CLOCK_REALTIME ) +return -ENOTSUPP ; +mutex_lock (&mvm->mutex);if (fw_has_capa (&mvm->fw->ucode_capa,IWL_UCODE_TLV_CAPA_SYNCED_TIME )) { ret =iwl_mvm_get_crosstimestamp_fw (mvm, &gp2, &sys_time);
[tip: timers/ptp] wifi: iwlwifi: Adopt PTP cross timestamps to core changes
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 6a5d1d6b447f4ead15133730b92141707c61832b Gitweb: https://git.kernel.org/tip/6a5d1d6b447f4ead15133730b92141707c61832b Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:36 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 02 Jun 2026 11:39:58 +02:00
wifi: iwlwifi: Adopt PTP cross timestamps to core changes
iwlwifi only supports CLOCK_REALTIME timestamps and provides an incomplete result without system counter values etc.
It also zeros struct system_device_crosststamp, which is already zeroed in the core and initialized with the clock ID.
Remove the zeroing and reject any request for a clock ID other than REALTIME.
--- drivers/net/wireless/intel/iwlwifi/mld/ptp.c | 3 ++- drivers/net/wireless/intel/iwlwifi/mvm/ptp.c | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-)
drivers/net/wireless/intel/iwlwifi/mld/ptp.c +2 -1
@@ -250,7 +250,8 @@ iwl_mld_phc_get_crosstimestamp(struct ptp_clock_info *ptp,/* System (wall) time */ ktime_t sys_time; -memset (xtstamp,0 ,sizeof (struct system_device_crosststamp )); +if (xtstamp->clock_id !=CLOCK_REALTIME ) +return -ENOTSUPP ; ret =iwl_mld_get_crosstimestamp_fw (mld, &gp2, &sys_time);if (ret) {
drivers/net/wireless/intel/iwlwifi/mvm/ptp.c +3 -2
@@ -160,13 +160,14 @@ iwl_mvm_phc_get_crosstimestamp(struct ptp_clock_info *ptp,/* System (wall) time */ ktime_t sys_time; -memset (xtstamp,0 ,sizeof (struct system_device_crosststamp )); -if (!mvm->ptp_data.ptp_clock) {IWL_ERR (mvm,"No PHC clock registered\n" );return -ENODEV ; } +if (xtstamp->clock_id !=CLOCK_REALTIME ) +return -ENOTSUPP ; +mutex_lock (&mvm->mutex);if (fw_has_capa (&mvm->fw->ucode_capa,IWL_UCODE_TLV_CAPA_SYNCED_TIME )) { ret =iwl_mvm_get_crosstimestamp_fw (mvm, &gp2, &sys_time);
[tip: timers/ptp] wifi: iwlwifi: Adopt PTP cross timestamps to core changes
In reply to Thomas GleixnerThe following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 570cf418bfc9d7d0ab662794dd2e2f4eeb79dfe5 Gitweb: https://git.kernel.org/tip/570cf418bfc9d7d0ab662794dd2e2f4eeb79dfe5 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:36 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 04 Jun 2026 11:04:16 +02:00
wifi: iwlwifi: Adopt PTP cross timestamps to core changes
iwlwifi only supports CLOCK_REALTIME timestamps and provides an incomplete result without system counter values etc.
It also zeros struct system_device_crosststamp, which is already zeroed in the core and initialized with the clock ID.
Remove the zeroing and reject any request for a clock ID other than REALTIME.
--- drivers/net/wireless/intel/iwlwifi/mld/ptp.c | 3 ++- drivers/net/wireless/intel/iwlwifi/mvm/ptp.c | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-)
drivers/net/wireless/intel/iwlwifi/mld/ptp.c +2 -1
@@ -250,7 +250,8 @@ iwl_mld_phc_get_crosstimestamp(struct ptp_clock_info *ptp,/* System (wall) time */ ktime_t sys_time; -memset (xtstamp,0 ,sizeof (struct system_device_crosststamp )); +if (xtstamp->clock_id !=CLOCK_REALTIME ) +return -ENOTSUPP ; ret =iwl_mld_get_crosstimestamp_fw (mld, &gp2, &sys_time);if (ret) {
drivers/net/wireless/intel/iwlwifi/mvm/ptp.c +3 -2
@@ -160,13 +160,14 @@ iwl_mvm_phc_get_crosstimestamp(struct ptp_clock_info *ptp,/* System (wall) time */ ktime_t sys_time; -memset (xtstamp,0 ,sizeof (struct system_device_crosststamp )); -if (!mvm->ptp_data.ptp_clock) {IWL_ERR (mvm,"No PHC clock registered\n" );return -ENODEV ; } +if (xtstamp->clock_id !=CLOCK_REALTIME ) +return -ENOTSUPP ; +mutex_lock (&mvm->mutex);if (fw_has_capa (&mvm->fw->ucode_capa,IWL_UCODE_TLV_CAPA_SYNCED_TIME )) { ret =iwl_mvm_get_crosstimestamp_fw (mvm, &gp2, &sys_time);
Thomas Gleixner
maintainerPATCH v2 13/25 ice/ptp: Use provided clock ID for history snapshot
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
The PTP core indicates in system_device_crosststamp::clock_id the clock ID for which then system time stamp should be taken. That allows to utilize hardware timestamps with e.g. AUX clocks.
Save the provided clock ID and use it in ice_capture_crosststamp() for taking the history snapshot.
No functional change.
--- drivers/net/ethernet/intel/ice/ice_ptp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_ptp.c +4 -1
@@ -2065,11 +2065,13 @@ static const struct ice_crosststamp_cfg/** * struct ice_crosststamp_ctx - Device cross timestamp context * @snapshot: snapshot of system clocks for historic interpolation +* @snapshot_clock_id: System clock ID for @snapshot * @pf: pointer to the PF private structure * @cfg: pointer to hardware configuration for cross timestamp */ struct ice_crosststamp_ctx {struct system_time_snapshot snapshot; +clockid_t snapshot_clock_id;struct ice_pf *pf;const struct ice_crosststamp_cfg *cfg; };
@@ -2115,7 +2117,7 @@ static int ice_capture_crosststamp(ktime }/* Snapshot system time for historic interpolation */ -ktime_get_snapshot (&ctx->snapshot); +ktime_get_snapshot_id (ctx->snapshot_clock_id, &ctx->snapshot);/* Program cmd to master timer */ ice_ptp_src_cmd (hw,ICE_PTP_READ_TIME );
@@ -2176,6 +2178,7 @@ static int ice_ptp_getcrosststamp(struct {struct ice_pf *pf =ptp_info_to_pf (info);struct ice_crosststamp_ctx ctx = { + .snapshot_clock_id = cts->clock_id, .pf = pf, };
[tip: timers/ptp] ice/ptp: Use provided clock ID for history snapshot
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: db9e2147563fc7a19b2f187a95ddd890d374f40e Gitweb: https://git.kernel.org/tip/db9e2147563fc7a19b2f187a95ddd890d374f40e Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:40 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 02 Jun 2026 11:39:59 +02:00
ice/ptp: Use provided clock ID for history snapshot
The PTP core indicates in system_device_crosststamp::clock_id the clock ID for which then system time stamp should be taken. That allows to utilize hardware timestamps with e.g. AUX clocks.
Save the provided clock ID and use it in ice_capture_crosststamp() for taking the history snapshot.
No functional change.
--- drivers/net/ethernet/intel/ice/ice_ptp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_ptp.c +4 -1
@@ -2065,11 +2065,13 @@ static const struct ice_crosststamp_cfg ice_crosststamp_cfg_e830 = {/** * struct ice_crosststamp_ctx - Device cross timestamp context * @snapshot: snapshot of system clocks for historic interpolation +* @snapshot_clock_id: System clock ID for @snapshot * @pf: pointer to the PF private structure * @cfg: pointer to hardware configuration for cross timestamp */ struct ice_crosststamp_ctx {struct system_time_snapshot snapshot; +clockid_t snapshot_clock_id;struct ice_pf *pf;const struct ice_crosststamp_cfg *cfg; };
@@ -2115,7 +2117,7 @@ static int ice_capture_crosststamp(ktime_t *device, }/* Snapshot system time for historic interpolation */ -ktime_get_snapshot (&ctx->snapshot); +ktime_get_snapshot_id (ctx->snapshot_clock_id, &ctx->snapshot);/* Program cmd to master timer */ ice_ptp_src_cmd (hw,ICE_PTP_READ_TIME );
@@ -2176,6 +2178,7 @@ static int ice_ptp_getcrosststamp(struct ptp_clock_info *info, {struct ice_pf *pf =ptp_info_to_pf (info);struct ice_crosststamp_ctx ctx = { + .snapshot_clock_id = cts->clock_id, .pf = pf, };
[tip: timers/ptp] ice/ptp: Use provided clock ID for history snapshot
In reply to Thomas GleixnerThe following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 23bc637750e4142ef9e86a06872fdf32e74a9050 Gitweb: https://git.kernel.org/tip/23bc637750e4142ef9e86a06872fdf32e74a9050 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:40 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 04 Jun 2026 11:04:16 +02:00
ice/ptp: Use provided clock ID for history snapshot
The PTP core indicates in system_device_crosststamp::clock_id the clock ID for which then system time stamp should be taken. That allows to utilize hardware timestamps with e.g. AUX clocks.
Save the provided clock ID and use it in ice_capture_crosststamp() for taking the history snapshot.
No functional change.
--- drivers/net/ethernet/intel/ice/ice_ptp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_ptp.c +4 -1
@@ -2065,11 +2065,13 @@ static const struct ice_crosststamp_cfg ice_crosststamp_cfg_e830 = {/** * struct ice_crosststamp_ctx - Device cross timestamp context * @snapshot: snapshot of system clocks for historic interpolation +* @snapshot_clock_id: System clock ID for @snapshot * @pf: pointer to the PF private structure * @cfg: pointer to hardware configuration for cross timestamp */ struct ice_crosststamp_ctx {struct system_time_snapshot snapshot; +clockid_t snapshot_clock_id;struct ice_pf *pf;const struct ice_crosststamp_cfg *cfg; };
@@ -2115,7 +2117,7 @@ static int ice_capture_crosststamp(ktime_t *device, }/* Snapshot system time for historic interpolation */ -ktime_get_snapshot (&ctx->snapshot); +ktime_get_snapshot_id (ctx->snapshot_clock_id, &ctx->snapshot);/* Program cmd to master timer */ ice_ptp_src_cmd (hw,ICE_PTP_READ_TIME );
@@ -2176,6 +2178,7 @@ static int ice_ptp_getcrosststamp(struct ptp_clock_info *info, {struct ice_pf *pf =ptp_info_to_pf (info);struct ice_crosststamp_ctx ctx = { + .snapshot_clock_id = cts->clock_id, .pf = pf, };
Thomas Gleixner
maintainerPATCH v2 14/25 igc: Use provided clock ID for history snapshot
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
The PTP core indicates in system_device_crosststamp::clock_id the clock ID for which the system time stamp should be taken. That allows to utilize hardware timestamps with e.g. AUX clocks.
Save the provided clock ID and use it in igc_phc_get_syncdevicetime() for taking the history snapshot.
No functional change.
--- drivers/net/ethernet/intel/igc/igc.h | 1 + drivers/net/ethernet/intel/igc/igc_ptp.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/igc/igc.h +1 -0
@@ -326,6 +326,7 @@ struct igc_adapter {struct timespec64 prev_ptp_time;/* Pre-reset PTP clock */ ktime_t ptp_reset_start;/* Reset time in clock mono */ struct system_time_snapshot snapshot; +clockid_t snapshot_clock_id;struct mutex ptm_lock;/* Only allow one PTM transaction at a time */ char fw_version[32 ];
drivers/net/ethernet/intel/igc/igc_ptp.c +3 -1
@@ -1049,7 +1049,7 @@ static int igc_phc_get_syncdevicetime(kt*/ do { /* Get a snapshot of system clocks to use as historic value. */ - ktime_get_snapshot(&adapter->snapshot); + ktime_get_snapshot_id(adapter->snapshot_clock_id, &adapter->snapshot); igc_ptm_trigger(hw);
@@ -1103,6 +1103,8 @@ static int igc_ptp_getcrosststamp(struct/* This blocks until any in progress PTM transactions complete */ mutex_lock (&adapter->ptm_lock); + adapter->snapshot_clock_id = cts->clock_id; + ret =get_device_system_crosststamp (igc_phc_get_syncdevicetime, adapter, &adapter->snapshot, cts);mutex_unlock (&adapter->ptm_lock);
[tip: timers/ptp] igc: Use provided clock ID for history snapshot
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 7beb75ca0c231c2f129f5e8e4a7b45980ec4d8c5 Gitweb: https://git.kernel.org/tip/7beb75ca0c231c2f129f5e8e4a7b45980ec4d8c5 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:44 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 02 Jun 2026 11:39:59 +02:00
igc: Use provided clock ID for history snapshot
The PTP core indicates in system_device_crosststamp::clock_id the clock ID for which the system time stamp should be taken. That allows to utilize hardware timestamps with e.g. AUX clocks.
Save the provided clock ID and use it in igc_phc_get_syncdevicetime() for taking the history snapshot.
No functional change.
--- drivers/net/ethernet/intel/igc/igc.h | 1 + drivers/net/ethernet/intel/igc/igc_ptp.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/igc/igc.h +1 -0
@@ -326,6 +326,7 @@ struct igc_adapter {struct timespec64 prev_ptp_time;/* Pre-reset PTP clock */ ktime_t ptp_reset_start;/* Reset time in clock mono */ struct system_time_snapshot snapshot; +clockid_t snapshot_clock_id;struct mutex ptm_lock;/* Only allow one PTM transaction at a time */ char fw_version[32 ];
drivers/net/ethernet/intel/igc/igc_ptp.c +3 -1
@@ -1049,7 +1049,7 @@ static int igc_phc_get_syncdevicetime(ktime_t *device,*/ do { /* Get a snapshot of system clocks to use as historic value. */ - ktime_get_snapshot(&adapter->snapshot); + ktime_get_snapshot_id(adapter->snapshot_clock_id, &adapter->snapshot); igc_ptm_trigger(hw);
@@ -1103,6 +1103,8 @@ static int igc_ptp_getcrosststamp(struct ptp_clock_info *ptp,/* This blocks until any in progress PTM transactions complete */ mutex_lock (&adapter->ptm_lock); + adapter->snapshot_clock_id = cts->clock_id; + ret =get_device_system_crosststamp (igc_phc_get_syncdevicetime, adapter, &adapter->snapshot, cts);mutex_unlock (&adapter->ptm_lock);
[tip: timers/ptp] igc: Use provided clock ID for history snapshot
In reply to Thomas GleixnerThe following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: af1816babcd9eff5c40eaf0de149b469debdfdb4 Gitweb: https://git.kernel.org/tip/af1816babcd9eff5c40eaf0de149b469debdfdb4 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:44 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 04 Jun 2026 11:04:17 +02:00
igc: Use provided clock ID for history snapshot
The PTP core indicates in system_device_crosststamp::clock_id the clock ID for which the system time stamp should be taken. That allows to utilize hardware timestamps with e.g. AUX clocks.
Save the provided clock ID and use it in igc_phc_get_syncdevicetime() for taking the history snapshot.
No functional change.
--- drivers/net/ethernet/intel/igc/igc.h | 1 + drivers/net/ethernet/intel/igc/igc_ptp.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/igc/igc.h +1 -0
@@ -326,6 +326,7 @@ struct igc_adapter {struct timespec64 prev_ptp_time;/* Pre-reset PTP clock */ ktime_t ptp_reset_start;/* Reset time in clock mono */ struct system_time_snapshot snapshot; +clockid_t snapshot_clock_id;struct mutex ptm_lock;/* Only allow one PTM transaction at a time */ char fw_version[32 ];
drivers/net/ethernet/intel/igc/igc_ptp.c +3 -1
@@ -1049,7 +1049,7 @@ static int igc_phc_get_syncdevicetime(ktime_t *device,*/ do { /* Get a snapshot of system clocks to use as historic value. */ - ktime_get_snapshot(&adapter->snapshot); + ktime_get_snapshot_id(adapter->snapshot_clock_id, &adapter->snapshot); igc_ptm_trigger(hw);
@@ -1103,6 +1103,8 @@ static int igc_ptp_getcrosststamp(struct ptp_clock_info *ptp,/* This blocks until any in progress PTM transactions complete */ mutex_lock (&adapter->ptm_lock); + adapter->snapshot_clock_id = cts->clock_id; + ret =get_device_system_crosststamp (igc_phc_get_syncdevicetime, adapter, &adapter->snapshot, cts);mutex_unlock (&adapter->ptm_lock);
Thomas Gleixner
maintainerPATCH v2 15/25 net/mlx5: Use provided clock ID for history snapshot
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
The PTP core indicates in system_device_crosststamp::clock_id the clock ID for which the system time stamp should be taken. That allows to utilize hardware timestamps with e.g. AUX clocks.
Use ktime_get_snapshot_id() and hand the provided clock ID in.
No functional change.
--- drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +2 -2
@@ -340,7 +340,7 @@ static int mlx5_ptp_getcrosststamp(struc goto unlock; } -ktime_get_snapshot (&history_begin); +ktime_get_snapshot_id (cts->clock_id, &history_begin); err =get_device_system_crosststamp (mlx5_mtctr_syncdevicetime, mdev, &history_begin, cts);
@@ -366,7 +366,7 @@ static int mlx5_ptp_getcrosscycles(struc goto unlock; } -ktime_get_snapshot (&history_begin); +ktime_get_snapshot_id (cts->clock_id, &history_begin); err =get_device_system_crosststamp (mlx5_mtctr_syncdevicecyclestime, mdev, &history_begin, cts);
[tip: timers/ptp] net/mlx5: Use provided clock ID for history snapshot
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 001b4d0c82580e56fd7b39317fb07c0a463db3da Gitweb: https://git.kernel.org/tip/001b4d0c82580e56fd7b39317fb07c0a463db3da Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:48 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 02 Jun 2026 11:39:59 +02:00
net/mlx5: Use provided clock ID for history snapshot
The PTP core indicates in system_device_crosststamp::clock_id the clock ID for which the system time stamp should be taken. That allows to utilize hardware timestamps with e.g. AUX clocks.
Use ktime_get_snapshot_id() and hand the provided clock ID in.
No functional change.
--- drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +2 -2
@@ -340,7 +340,7 @@ static int mlx5_ptp_getcrosststamp(struct ptp_clock_info *ptp, goto unlock; } -ktime_get_snapshot (&history_begin); +ktime_get_snapshot_id (cts->clock_id, &history_begin); err =get_device_system_crosststamp (mlx5_mtctr_syncdevicetime, mdev, &history_begin, cts);
@@ -366,7 +366,7 @@ static int mlx5_ptp_getcrosscycles(struct ptp_clock_info *ptp, goto unlock; } -ktime_get_snapshot (&history_begin); +ktime_get_snapshot_id (cts->clock_id, &history_begin); err =get_device_system_crosststamp (mlx5_mtctr_syncdevicecyclestime, mdev, &history_begin, cts);
[tip: timers/ptp] net/mlx5: Use provided clock ID for history snapshot
In reply to Thomas GleixnerThe following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 8216433ebe7e1b904c9e0f3176d7f99cbdb78bcd Gitweb: https://git.kernel.org/tip/8216433ebe7e1b904c9e0f3176d7f99cbdb78bcd Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:48 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 04 Jun 2026 11:04:17 +02:00
net/mlx5: Use provided clock ID for history snapshot
The PTP core indicates in system_device_crosststamp::clock_id the clock ID for which the system time stamp should be taken. That allows to utilize hardware timestamps with e.g. AUX clocks.
Use ktime_get_snapshot_id() and hand the provided clock ID in.
No functional change.
--- drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +2 -2
@@ -340,7 +340,7 @@ static int mlx5_ptp_getcrosststamp(struct ptp_clock_info *ptp, goto unlock; } -ktime_get_snapshot (&history_begin); +ktime_get_snapshot_id (cts->clock_id, &history_begin); err =get_device_system_crosststamp (mlx5_mtctr_syncdevicetime, mdev, &history_begin, cts);
@@ -366,7 +366,7 @@ static int mlx5_ptp_getcrosscycles(struct ptp_clock_info *ptp, goto unlock; } -ktime_get_snapshot (&history_begin); +ktime_get_snapshot_id (cts->clock_id, &history_begin); err =get_device_system_crosststamp (mlx5_mtctr_syncdevicecyclestime, mdev, &history_begin, cts);
Thomas Gleixner
maintainerPATCH v2 16/25 virtio_rtc: Use provided clock ID for history snapshot
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
The PTP core indicates in system_device_crosststamp::clock_id the clock ID for which the system time stamp should be taken. That allows to utilize hardware timestamps with e.g. AUX clocks.
Use ktime_get_snapshot_id() and hand the provided clock ID in.
No functional change.
--- drivers/virtio/virtio_rtc_ptp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/virtio/virtio_rtc_ptp.c +1 -1
@@ -139,7 +139,7 @@ static int viortc_ptp_getcrosststamp(strif (ret)return ret; -ktime_get_snapshot (&history_begin); +ktime_get_snapshot_id (xtstamp->clock_id, &history_begin);if (history_begin.cs_id != cs_id)return -EOPNOTSUPP ;
[tip: timers/ptp] virtio_rtc: Use provided clock ID for history snapshot
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: babe4b6d03be8fe7787490d7b93f593134abc51e Gitweb: https://git.kernel.org/tip/babe4b6d03be8fe7787490d7b93f593134abc51e Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:52 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 02 Jun 2026 11:39:59 +02:00
virtio_rtc: Use provided clock ID for history snapshot
The PTP core indicates in system_device_crosststamp::clock_id the clock ID for which the system time stamp should be taken. That allows to utilize hardware timestamps with e.g. AUX clocks.
Use ktime_get_snapshot_id() and hand the provided clock ID in.
No functional change.
--- drivers/virtio/virtio_rtc_ptp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/virtio/virtio_rtc_ptp.c +1 -1
@@ -139,7 +139,7 @@ static int viortc_ptp_getcrosststamp(struct ptp_clock_info *ptp,if (ret)return ret; -ktime_get_snapshot (&history_begin); +ktime_get_snapshot_id (xtstamp->clock_id, &history_begin);if (history_begin.cs_id != cs_id)return -EOPNOTSUPP ;
Re: [patch V2 16/25] virtio_rtc: Use provided clock ID for history snapshot
In reply to Thomas GleixnerQuoted 6 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
The PTP core indicates in
system_device_crosststamp::clock_idthe clock ID for which the system time stamp should be taken. That allows to utilize hardware timestamps with e.g. AUX clocks.
Quoted 8 lines
Use
ktime_get_snapshot_id()and hand the provided clock ID in.No functional change.
Signed-off-by Thomas Gleixner <[email protected]>Tested-by Arthur Kiyanovski <[email protected]>Reviewed-by David Woodhouse <[email protected]>Reviewed-by Jacob Keller <[email protected]>
Quoted 15 lines
--- drivers/virtio/virtio_rtc_ptp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/virtio/virtio_rtc_ptp.c +1
-1@@ -139,7 +139,7 @@ static int viortc_ptp_getcrosststamp(strif (ret)return ret; -ktime_get_snapshot (&history_begin); +ktime_get_snapshot_id (xtstamp->clock_id, &history_begin);if (history_begin.cs_id != cs_id)return -EOPNOTSUPP ;
[tip: timers/ptp] virtio_rtc: Use provided clock ID for history snapshot
In reply to Thomas GleixnerThe following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 786493096848006020d7b8e57a53742a64fe5d4d Gitweb: https://git.kernel.org/tip/786493096848006020d7b8e57a53742a64fe5d4d Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:52 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 04 Jun 2026 11:04:17 +02:00
virtio_rtc: Use provided clock ID for history snapshot
The PTP core indicates in system_device_crosststamp::clock_id the clock ID for which the system time stamp should be taken. That allows to utilize hardware timestamps with e.g. AUX clocks.
Use ktime_get_snapshot_id() and hand the provided clock ID in.
No functional change.
--- drivers/virtio/virtio_rtc_ptp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/virtio/virtio_rtc_ptp.c +1 -1
@@ -139,7 +139,7 @@ static int viortc_ptp_getcrosststamp(struct ptp_clock_info *ptp,if (ret)return ret; -ktime_get_snapshot (&history_begin); +ktime_get_snapshot_id (xtstamp->clock_id, &history_begin);if (history_begin.cs_id != cs_id)return -EOPNOTSUPP ;
Thomas Gleixner
maintainerPATCH v2 17/25 timekeeping: Remove ktime_get_snapshot()
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
All users have been converted to ktime_get_snapshot_id().
--- include/linux/timekeeping.h | 5 ----- 1 file changed, 5 deletions(-)
include/linux/timekeeping.h +0 -5
@@ -350,11 +350,6 @@ extern int get_device_system_crosststamp*/ extern void ktime_get_snapshot_id (clockid_t clock_id,struct system_time_snapshot *systime_snapshot); -static inline void ktime_get_snapshot (struct system_time_snapshot *systime_snapshot) -{ -ktime_get_snapshot_id (CLOCK_REALTIME , systime_snapshot); -} -/* * Persistent clock related interfaces */
[tip: timers/ptp] timekeeping: Remove ktime_get_snapshot()
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: bfa570d832ea4bec2cb715339c34154f493887fd Gitweb: https://git.kernel.org/tip/bfa570d832ea4bec2cb715339c34154f493887fd Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:56 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 02 Jun 2026 11:39:59 +02:00
timekeeping: Remove ktime_get_snapshot()
All users have been converted to ktime_get_snapshot_id().
--- include/linux/timekeeping.h | 5 ----- 1 file changed, 5 deletions(-)
include/linux/timekeeping.h +0 -5
@@ -350,11 +350,6 @@ extern int get_device_system_crosststamp(*/ extern void ktime_get_snapshot_id (clockid_t clock_id,struct system_time_snapshot *systime_snapshot); -static inline void ktime_get_snapshot (struct system_time_snapshot *systime_snapshot) -{ -ktime_get_snapshot_id (CLOCK_REALTIME , systime_snapshot); -} -/* * Persistent clock related interfaces */
[tip: timers/ptp] timekeeping: Remove ktime_get_snapshot()
In reply to Thomas GleixnerThe following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: b21d442c9aebe5ed95303883d3365e430e134cf1 Gitweb: https://git.kernel.org/tip/b21d442c9aebe5ed95303883d3365e430e134cf1 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:00:56 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 04 Jun 2026 11:04:17 +02:00
timekeeping: Remove ktime_get_snapshot()
All users have been converted to ktime_get_snapshot_id().
--- include/linux/timekeeping.h | 5 ----- 1 file changed, 5 deletions(-)
include/linux/timekeeping.h +0 -5
@@ -350,11 +350,6 @@ extern int get_device_system_crosststamp(*/ extern void ktime_get_snapshot_id (clockid_t clock_id,struct system_time_snapshot *systime_snapshot); -static inline void ktime_get_snapshot (struct system_time_snapshot *systime_snapshot) -{ -ktime_get_snapshot_id (CLOCK_REALTIME , systime_snapshot); -} -/* * Persistent clock related interfaces */
Thomas Gleixner
maintainerPATCH v2 18/25 timekeeping: Prepare for cross timestamps on arbitrary clock IDs
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
PTP device system crosstime stamps support only CLOCK_REALTIME, which is meaningless for AUX clocks. The PTP core hands in the clock ID already, so prepare the core code to honor it.
- Add a new sys_systime field to struct system_device_crosststamp which aliases the sys_realtime field. Once all users are converted sys_realtime can be removed.
- Prepare get_device_system_crosststamp() and the related code for it by switching to sys_systime and providing the initial changes to utilize different time keepers.
No functional change intended.
--- include/linux/timekeeping.h | 7 ++++- kernel/time/timekeeping.c | 60 +++++++++++++++++++++++++------------------- 2 files changed, 41 insertions(+), 26 deletions(-)
include/linux/timekeeping.h +6 -1
@@ -319,13 +319,18 @@ struct system_counterval_t {* @device: Device time * @sys_counter: Clocksource counter value simultaneous with device time * @sys_realtime: Realtime simultaneous with device time +* @sys_systime: System time for @clock_id * @sys_monoraw: Monotonic raw simultaneous with device time */ struct system_device_crosststamp {clockid_t clock_id;ktime_t device;struct system_counterval_t sys_counter; -ktime_t sys_realtime; +union { +/* realtime goes away once all users are converted */ +ktime_t sys_realtime; +ktime_t sys_systime; + };ktime_t sys_monoraw; };
kernel/time/timekeeping.c +35 -25
111 lines not on this page · raw message
[tip: timers/ptp] timekeeping: Prepare for cross timestamps on arbitrary clock IDs
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 9ff027f820c3a86368572b5123b13f61bf1a8108 Gitweb: https://git.kernel.org/tip/9ff027f820c3a86368572b5123b13f61bf1a8108 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:01:00 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 02 Jun 2026 11:39:59 +02:00
timekeeping: Prepare for cross timestamps on arbitrary clock IDs
PTP device system crosstime stamps support only CLOCK_REALTIME, which is meaningless for AUX clocks. The PTP core hands in the clock ID already, so prepare the core code to honor it.
- Add a new sys_systime field to struct system_device_crosststamp which aliases the sys_realtime field. Once all users are converted sys_realtime can be removed.
- Prepare get_device_system_crosststamp() and the related code for it by switching to sys_systime and providing the initial changes to utilize different time keepers.
No functional change intended.
--- include/linux/timekeeping.h | 7 +++- kernel/time/timekeeping.c | 60 +++++++++++++++++++++--------------- 2 files changed, 41 insertions(+), 26 deletions(-)
include/linux/timekeeping.h +6 -1
@@ -319,13 +319,18 @@ struct system_counterval_t {* @device: Device time * @sys_counter: Clocksource counter value simultaneous with device time * @sys_realtime: Realtime simultaneous with device time +* @sys_systime: System time for @clock_id * @sys_monoraw: Monotonic raw simultaneous with device time */ struct system_device_crosststamp {clockid_t clock_id;ktime_t device;struct system_counterval_t sys_counter; -ktime_t sys_realtime; +union { +/* realtime goes away once all users are converted */ +ktime_t sys_realtime; +ktime_t sys_systime; + };ktime_t sys_monoraw; };
kernel/time/timekeeping.c +35 -25
111 lines not on this page · raw message
[tip: timers/ptp] timekeeping: Prepare for cross timestamps on arbitrary clock IDs
In reply to Thomas GleixnerThe following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 09fb74f77e02489d1d8c555d44bab99d4905127c Gitweb: https://git.kernel.org/tip/09fb74f77e02489d1d8c555d44bab99d4905127c Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:01:00 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 04 Jun 2026 11:04:17 +02:00
timekeeping: Prepare for cross timestamps on arbitrary clock IDs
PTP device system crosstime stamps support only CLOCK_REALTIME, which is meaningless for AUX clocks. The PTP core hands in the clock ID already, so prepare the core code to honor it.
- Add a new sys_systime field to struct system_device_crosststamp which aliases the sys_realtime field. Once all users are converted sys_realtime can be removed.
- Prepare get_device_system_crosststamp() and the related code for it by switching to sys_systime and providing the initial changes to utilize different time keepers.
No functional change intended.
--- include/linux/timekeeping.h | 7 +++- kernel/time/timekeeping.c | 60 +++++++++++++++++++++--------------- 2 files changed, 41 insertions(+), 26 deletions(-)
include/linux/timekeeping.h +6 -1
@@ -319,13 +319,18 @@ struct system_counterval_t {* @device: Device time * @sys_counter: Clocksource counter value simultaneous with device time * @sys_realtime: Realtime simultaneous with device time +* @sys_systime: System time for @clock_id * @sys_monoraw: Monotonic raw simultaneous with device time */ struct system_device_crosststamp {clockid_t clock_id;ktime_t device;struct system_counterval_t sys_counter; -ktime_t sys_realtime; +union { +/* realtime goes away once all users are converted */ +ktime_t sys_realtime; +ktime_t sys_systime; + };ktime_t sys_monoraw; };
kernel/time/timekeeping.c +35 -25
111 lines not on this page · raw message
David Woodhouse
maintainerRe: [patch V2 18/25] timekeeping: Prepare for cross timestamps on arbitrary clock IDs
In reply to Thomas GleixnerQuoted 10 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
PTP device system crosstime stamps support only
CLOCK_REALTIME, which is meaningless for AUX clocks. The PTP core hands in the clock ID already, so prepare the core code to honor it.- Add a new
sys_systimefield to structsystem_device_crosststampwhich aliases thesys_realtimefield. Once all users are convertedsys_realtimecan be removed.
Quoted 5 lines
- Prepare
get_device_system_crosststamp()and the related code for it by switching tosys_systimeand providing the initial changes to utilize different time keepers.No functional change intended.
We ended up with ktime_get_snapshot_id() also supporting CLOCK_BOOTTIME and CLOCK_MONOTONIC_RAW, but not get_device_system_crosststamp(). Should we make that consistent?
Thomas Gleixner
maintainerRe: [patch V2 18/25] timekeeping: Prepare for cross timestamps on arbitrary clock IDs
Quoted 15 lines · David Woodhouse
Quoted 14 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
PTP device system crosstime stamps support only
CLOCK_REALTIME, which is meaningless for AUX clocks. The PTP core hands in the clock ID already, so prepare the core code to honor it.- Add a new
sys_systimefield to structsystem_device_crosststampwhich aliases thesys_realtimefield. Once all users are convertedsys_realtimecan be removed.- Prepare
get_device_system_crosststamp()and the related code for it by switching tosys_systimeand providing the initial changes to utilize different time keepers.
Quoted 5 lines
Quoted 1 line
No functional change intended.
We ended up with
ktime_get_snapshot_id()also supportingCLOCK_BOOTTIMEandCLOCK_MONOTONIC_RAW, but notget_device_system_crosststamp(). Should we make that consistent?
Maybe. The BOOTTIME support is only there for that ARM64 hyper trace muck, but has no other relevance.
MONORAW is there for the PTP EXTENDED IOCTL, but with PRECISE the snapshot already contains the raw value and you'd have to prevent the historical adjustment part for RAW. So I don't see the actual value, but I don't have a strong opinion either.
Thanks,
tglx
David Woodhouse
maintainerRe: [patch V2 18/25] timekeeping: Prepare for cross timestamps on arbitrary clock IDs
Quoted 5 lines · Thomas Gleixner
Quoted 3 lines · David Woodhouse
We ended up with
ktime_get_snapshot_id()also supportingCLOCK_BOOTTIMEandCLOCK_MONOTONIC_RAW, but notget_device_system_crosststamp(). Should we make that consistent?
Quoted 7 lines
Maybe. The BOOTTIME support is only there for that ARM64 hyper trace muck, but has no other relevance.
MONORAW is there for the PTP EXTENDED IOCTL, but with PRECISE the snapshot already contains the raw value and you'd have to prevent the historical adjustment part for RAW. So I don't see the actual value, but I don't have a strong opinion either.
Yeah, I'm not sure I see the need for it; it's just the consistency thing that slightly bothered me once I had them both in my sights doing the snapshot_ntp_error() thing in both.
Thomas Gleixner
maintainerPATCH v2 19/25 ptp: Use system_device_crosststamp::sys_systime
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
.. to prepare for cross timestamps with variable clock IDs.
No functional change.
--- drivers/ptp/ptp_chardev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ptp/ptp_chardev.c +1 -1
@@ -333,7 +333,7 @@ static long ptp_sys_offset_precise(struc ts =ktime_to_timespec64 (xtstamp.device); precise_offset.device.sec = ts.tv_sec; precise_offset.device.nsec = ts.tv_nsec; - ts =ktime_to_timespec64 (xtstamp.sys_realtime); + ts =ktime_to_timespec64 (xtstamp.sys_systime); precise_offset.sys_realtime.sec = ts.tv_sec; precise_offset.sys_realtime.nsec = ts.tv_nsec; ts =ktime_to_timespec64 (xtstamp.sys_monoraw);
[tip: timers/ptp] ptp: Use system_device_crosststamp::sys_systime
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 4204722943d357a7c7b71e96e3d501ac011e1d00 Gitweb: https://git.kernel.org/tip/4204722943d357a7c7b71e96e3d501ac011e1d00 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:01:05 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 02 Jun 2026 11:39:59 +02:00
ptp: Use system_device_crosststamp::sys_systime
.. to prepare for cross timestamps with variable clock IDs.
No functional change.
--- drivers/ptp/ptp_chardev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ptp/ptp_chardev.c +1 -1
@@ -333,7 +333,7 @@ static long ptp_sys_offset_precise(struct ptp_clock *ptp, void __user *arg, ts =ktime_to_timespec64 (xtstamp.device); precise_offset.device.sec = ts.tv_sec; precise_offset.device.nsec = ts.tv_nsec; - ts =ktime_to_timespec64 (xtstamp.sys_realtime); + ts =ktime_to_timespec64 (xtstamp.sys_systime); precise_offset.sys_realtime.sec = ts.tv_sec; precise_offset.sys_realtime.nsec = ts.tv_nsec; ts =ktime_to_timespec64 (xtstamp.sys_monoraw);
[tip: timers/ptp] ptp: Use system_device_crosststamp::sys_systime
In reply to Thomas GleixnerThe following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 12b497db7cbd2f07b7f182452bce6bb0e48e71dc Gitweb: https://git.kernel.org/tip/12b497db7cbd2f07b7f182452bce6bb0e48e71dc Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:01:05 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 04 Jun 2026 11:04:17 +02:00
ptp: Use system_device_crosststamp::sys_systime
.. to prepare for cross timestamps with variable clock IDs.
No functional change.
--- drivers/ptp/ptp_chardev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ptp/ptp_chardev.c +1 -1
@@ -333,7 +333,7 @@ static long ptp_sys_offset_precise(struct ptp_clock *ptp, void __user *arg, ts =ktime_to_timespec64 (xtstamp.device); precise_offset.device.sec = ts.tv_sec; precise_offset.device.nsec = ts.tv_nsec; - ts =ktime_to_timespec64 (xtstamp.sys_realtime); + ts =ktime_to_timespec64 (xtstamp.sys_systime); precise_offset.sys_realtime.sec = ts.tv_sec; precise_offset.sys_realtime.nsec = ts.tv_nsec; ts =ktime_to_timespec64 (xtstamp.sys_monoraw);
Thomas Gleixner
maintainerPATCH v2 20/25 wifi: iwlwifi: Use system_device_crosststamp::sys_systime
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
sys_systime is an alias for sys_realtime. The latter will be removed so switch the code over to the new naming scheme.
No functional change.
--- drivers/net/wireless/intel/iwlwifi/mld/ptp.c | 2 +- drivers/net/wireless/intel/iwlwifi/mvm/ptp.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/intel/iwlwifi/mld/ptp.c +1 -1
@@ -271,7 +271,7 @@ iwl_mld_phc_get_crosstimestamp(struct pt/* System monotonic raw time is not used */ xtstamp->device =ns_to_ktime (gp2_ns); - xtstamp->sys_realtime = sys_time; + xtstamp->sys_systime = sys_time;return ret; }
drivers/net/wireless/intel/iwlwifi/mvm/ptp.c +1 -1
@@ -185,7 +185,7 @@ iwl_mvm_phc_get_crosstimestamp(struct pt/* System monotonic raw time is not used */ xtstamp->device = (ktime_t )gp2_ns; - xtstamp->sys_realtime = sys_time; + xtstamp->sys_systime = sys_time; out:mutex_unlock (&mvm->mutex);
[tip: timers/ptp] wifi: iwlwifi: Use system_device_crosststamp::sys_systime
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: c5566c29ad23e1d5b17c64ac2b605f6d3821bab0 Gitweb: https://git.kernel.org/tip/c5566c29ad23e1d5b17c64ac2b605f6d3821bab0 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:01:09 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 02 Jun 2026 11:39:59 +02:00
wifi: iwlwifi: Use system_device_crosststamp::sys_systime
sys_systime is an alias for sys_realtime. The latter will be removed so switch the code over to the new naming scheme.
No functional change.
--- drivers/net/wireless/intel/iwlwifi/mld/ptp.c | 2 +- drivers/net/wireless/intel/iwlwifi/mvm/ptp.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/intel/iwlwifi/mld/ptp.c +1 -1
@@ -271,7 +271,7 @@ iwl_mld_phc_get_crosstimestamp(struct ptp_clock_info *ptp,/* System monotonic raw time is not used */ xtstamp->device =ns_to_ktime (gp2_ns); - xtstamp->sys_realtime = sys_time; + xtstamp->sys_systime = sys_time;return ret; }
drivers/net/wireless/intel/iwlwifi/mvm/ptp.c +1 -1
@@ -185,7 +185,7 @@ iwl_mvm_phc_get_crosstimestamp(struct ptp_clock_info *ptp,/* System monotonic raw time is not used */ xtstamp->device = (ktime_t )gp2_ns; - xtstamp->sys_realtime = sys_time; + xtstamp->sys_systime = sys_time; out:mutex_unlock (&mvm->mutex);
[tip: timers/ptp] wifi: iwlwifi: Use system_device_crosststamp::sys_systime
In reply to Thomas GleixnerThe following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 25af33c5c532b4429ffa803320aa626af7888f6c Gitweb: https://git.kernel.org/tip/25af33c5c532b4429ffa803320aa626af7888f6c Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:01:09 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 04 Jun 2026 11:04:17 +02:00
wifi: iwlwifi: Use system_device_crosststamp::sys_systime
sys_systime is an alias for sys_realtime. The latter will be removed so switch the code over to the new naming scheme.
No functional change.
--- drivers/net/wireless/intel/iwlwifi/mld/ptp.c | 2 +- drivers/net/wireless/intel/iwlwifi/mvm/ptp.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/intel/iwlwifi/mld/ptp.c +1 -1
@@ -271,7 +271,7 @@ iwl_mld_phc_get_crosstimestamp(struct ptp_clock_info *ptp,/* System monotonic raw time is not used */ xtstamp->device =ns_to_ktime (gp2_ns); - xtstamp->sys_realtime = sys_time; + xtstamp->sys_systime = sys_time;return ret; }
drivers/net/wireless/intel/iwlwifi/mvm/ptp.c +1 -1
@@ -185,7 +185,7 @@ iwl_mvm_phc_get_crosstimestamp(struct ptp_clock_info *ptp,/* System monotonic raw time is not used */ xtstamp->device = (ktime_t )gp2_ns; - xtstamp->sys_realtime = sys_time; + xtstamp->sys_systime = sys_time; out:mutex_unlock (&mvm->mutex);
Thomas Gleixner
maintainerPATCH v2 21/25 ALSA: hda/common: Use system_device_crosststamp::sys_systime
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
sys_systime is an alias for sys_realtime. The latter will be removed so switch the code over to the new naming scheme.
No functional change.
--- sound/hda/common/controller.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/hda/common/controller.c +1 -1
@@ -525,7 +525,7 @@ static int azx_get_time_info(struct snd_break ;default : - *system_ts =ktime_to_timespec64 (xtstamp.sys_realtime); + *system_ts =ktime_to_timespec64 (xtstamp.sys_systime);break ; }
[tip: timers/ptp] ALSA: hda/common: Use system_device_crosststamp::sys_systime
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 2ee8af24ff1daaf630a69046cfaf3a6e97254915 Gitweb: https://git.kernel.org/tip/2ee8af24ff1daaf630a69046cfaf3a6e97254915 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:01:13 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 02 Jun 2026 11:39:59 +02:00
ALSA: hda/common: Use system_device_crosststamp::sys_systime
sys_systime is an alias for sys_realtime. The latter will be removed so switch the code over to the new naming scheme.
No functional change.
--- sound/hda/common/controller.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/hda/common/controller.c +1 -1
@@ -525,7 +525,7 @@ static int azx_get_time_info(struct snd_pcm_substream *substream,break ;default : - *system_ts =ktime_to_timespec64 (xtstamp.sys_realtime); + *system_ts =ktime_to_timespec64 (xtstamp.sys_systime);break ; }
Re: [patch V2 21/25] ALSA: hda/common: Use system_device_crosststamp::sys_systime
In reply to Thomas GleixnerQuoted 6 lines · Thomas Gleixner
From: Thomas Gleixner <[email protected]>
sys_systimeis an alias forsys_realtime. The latter will be removed so switch the code over to the new naming scheme.
Quoted 6 lines
No functional change.
Signed-off-by Thomas Gleixner <[email protected]>Tested-by Arthur Kiyanovski <[email protected]>Reviewed-by David Woodhouse <[email protected]>Reviewed-by Jacob Keller <[email protected]>
thanks,
Takashi
Quoted 17 lines
--- sound/hda/common/controller.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)sound/hda/common/controller.c +1
-1@@ -525,7 +525,7 @@ static int azx_get_time_info(struct snd_break ;default : - *system_ts =ktime_to_timespec64 (xtstamp.sys_realtime); + *system_ts =ktime_to_timespec64 (xtstamp.sys_systime);break ; }
[tip: timers/ptp] ALSA: hda/common: Use system_device_crosststamp::sys_systime
In reply to Thomas GleixnerThe following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 13029a25eaa92457d8363a94c48592991770cc67 Gitweb: https://git.kernel.org/tip/13029a25eaa92457d8363a94c48592991770cc67 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:01:13 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 04 Jun 2026 11:04:17 +02:00
ALSA: hda/common: Use system_device_crosststamp::sys_systime
sys_systime is an alias for sys_realtime. The latter will be removed so switch the code over to the new naming scheme.
No functional change.
--- sound/hda/common/controller.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/hda/common/controller.c +1 -1
@@ -525,7 +525,7 @@ static int azx_get_time_info(struct snd_pcm_substream *substream,break ;default : - *system_ts =ktime_to_timespec64 (xtstamp.sys_realtime); + *system_ts =ktime_to_timespec64 (xtstamp.sys_systime);break ; }
Thomas Gleixner
maintainerPATCH v2 22/25 timekeeping: Remove system_device_crosststamp::sys_realtime
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
All users are converted to sys_systime.
--- include/linux/timekeeping.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
include/linux/timekeeping.h +1 -6
@@ -318,7 +318,6 @@ struct system_counterval_t {* @clock_id: System time Clock ID to capture * @device: Device time * @sys_counter: Clocksource counter value simultaneous with device time -* @sys_realtime: Realtime simultaneous with device time * @sys_systime: System time for @clock_id * @sys_monoraw: Monotonic raw simultaneous with device time */
@@ -326,11 +325,7 @@ struct system_device_crosststamp {clockid_t clock_id;ktime_t device;struct system_counterval_t sys_counter; -union { -/* realtime goes away once all users are converted */ -ktime_t sys_realtime; -ktime_t sys_systime; - }; +ktime_t sys_systime;ktime_t sys_monoraw; };
[tip: timers/ptp] timekeeping: Remove system_device_crosststamp::sys_realtime
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: acc25f921f405350a3b30787a7660922b24649ba Gitweb: https://git.kernel.org/tip/acc25f921f405350a3b30787a7660922b24649ba Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:01:17 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 02 Jun 2026 11:39:59 +02:00
timekeeping: Remove system_device_crosststamp::sys_realtime
All users are converted to sys_systime.
--- include/linux/timekeeping.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
include/linux/timekeeping.h +1 -6
@@ -318,7 +318,6 @@ struct system_counterval_t {* @clock_id: System time Clock ID to capture * @device: Device time * @sys_counter: Clocksource counter value simultaneous with device time -* @sys_realtime: Realtime simultaneous with device time * @sys_systime: System time for @clock_id * @sys_monoraw: Monotonic raw simultaneous with device time */
@@ -326,11 +325,7 @@ struct system_device_crosststamp {clockid_t clock_id;ktime_t device;struct system_counterval_t sys_counter; -union { -/* realtime goes away once all users are converted */ -ktime_t sys_realtime; -ktime_t sys_systime; - }; +ktime_t sys_systime;ktime_t sys_monoraw; };
[tip: timers/ptp] timekeeping: Remove system_device_crosststamp::sys_realtime
In reply to Thomas GleixnerThe following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 5ccaf1e569f04d8fd5f0167be728fdb48f448f81 Gitweb: https://git.kernel.org/tip/5ccaf1e569f04d8fd5f0167be728fdb48f448f81 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:01:17 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 04 Jun 2026 11:04:17 +02:00
timekeeping: Remove system_device_crosststamp::sys_realtime
All users are converted to sys_systime.
--- include/linux/timekeeping.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
include/linux/timekeeping.h +1 -6
@@ -318,7 +318,6 @@ struct system_counterval_t {* @clock_id: System time Clock ID to capture * @device: Device time * @sys_counter: Clocksource counter value simultaneous with device time -* @sys_realtime: Realtime simultaneous with device time * @sys_systime: System time for @clock_id * @sys_monoraw: Monotonic raw simultaneous with device time */
@@ -326,11 +325,7 @@ struct system_device_crosststamp {clockid_t clock_id;ktime_t device;struct system_counterval_t sys_counter; -union { -/* realtime goes away once all users are converted */ -ktime_t sys_realtime; -ktime_t sys_systime; - }; +ktime_t sys_systime;ktime_t sys_monoraw; };
Thomas Gleixner
maintainerPATCH v2 23/25 timekeeping: Add support for AUX clock cross timestamping
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
Now that all prerequisites are in place add the final support for AUX clocks in get_device_system_crosststamp(), which enables the PTP layer to support hardware cross timestamps with a new IOTCL.
--- kernel/time/timekeeping.c | 6 ++++++ 1 file changed, 6 insertions(+)
kernel/time/timekeeping.c +6 -0
@@ -1517,6 +1517,12 @@ int get_device_system_crosststamp(int (* tkd = &tk_core; offs = &tk_core.timekeeper.offs_real;break ; + case CLOCK_AUX ... CLOCK_AUX_LAST: + tkd =aux_get_tk_data (xtstamp->clock_id); +if (!tkd) +return -ENODEV ; + offs = &tkd->timekeeper.offs_aux; +break ;default :WARN_ON_ONCE (1 );return -ENODEV ;
[tip: timers/ptp] timekeeping: Add support for AUX clock cross timestamping
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 7a58ec6a456cad02345cfbd949d8da6d5eaedd1d Gitweb: https://git.kernel.org/tip/7a58ec6a456cad02345cfbd949d8da6d5eaedd1d Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:01:21 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 02 Jun 2026 11:40:00 +02:00
timekeeping: Add support for AUX clock cross timestamping
Now that all prerequisites are in place add the final support for AUX clocks in get_device_system_crosststamp(), which enables the PTP layer to support hardware cross timestamps with a new IOTCL.
--- kernel/time/timekeeping.c | 6 ++++++ 1 file changed, 6 insertions(+)
kernel/time/timekeeping.c +6 -0
@@ -1517,6 +1517,12 @@ int get_device_system_crosststamp(int (*get_time_fn) tkd = &tk_core; offs = &tk_core.timekeeper.offs_real;break ; + case CLOCK_AUX ... CLOCK_AUX_LAST: + tkd =aux_get_tk_data (xtstamp->clock_id); +if (!tkd) +return -ENODEV ; + offs = &tkd->timekeeper.offs_aux; +break ;default :WARN_ON_ONCE (1 );return -ENODEV ;
[tip: timers/ptp] timekeeping: Add support for AUX clock cross timestamping
In reply to Thomas GleixnerThe following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 9aebde8af6fe247d92816c197badf7e236c8f037 Gitweb: https://git.kernel.org/tip/9aebde8af6fe247d92816c197badf7e236c8f037 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:01:21 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 04 Jun 2026 11:04:18 +02:00
timekeeping: Add support for AUX clock cross timestamping
Now that all prerequisites are in place add the final support for AUX clocks in get_device_system_crosststamp(), which enables the PTP layer to support hardware cross timestamps with a new IOTCL.
--- kernel/time/timekeeping.c | 6 ++++++ 1 file changed, 6 insertions(+)
kernel/time/timekeeping.c +6 -0
@@ -1517,6 +1517,12 @@ int get_device_system_crosststamp(int (*get_time_fn) tkd = &tk_core; offs = &tk_core.timekeeper.offs_real;break ; + case CLOCK_AUX ... CLOCK_AUX_LAST: + tkd =aux_get_tk_data (xtstamp->clock_id); +if (!tkd) +return -ENODEV ; + offs = &tkd->timekeeper.offs_aux; +break ;default :WARN_ON_ONCE (1 );return -ENODEV ;
Thomas Gleixner
maintainerPATCH v2 24/25 ptp: Switch to ktime_get_snapshot_id() for pre/post timestamps
In reply to Thomas GleixnerFrom: Thomas Gleixner <[email protected]>
To prepare for a new PTP IOCTL, which exposes the raw counter value along with the requested system time snapshot, switch the pre/post time stamp sampling over to use ktime_get_snapshot_id() and fix up all usage sites.
No functional change intended.
The ptp_vmclock conversion was simplified by David Woodhouse.
--- drivers/net/dsa/sja1105/sja1105_main.c | 8 ++++---- drivers/ptp/ptp_chardev.c | 14 +++++++++----- drivers/ptp/ptp_ocp.c | 11 ++++------- drivers/ptp/ptp_vmclock.c | 23 +++++++---------------- include/linux/ptp_clock_kernel.h | 15 ++++++++------- 5 files changed, 32 insertions(+), 39 deletions(-)
drivers/net/dsa/sja1105/sja1105_main.c +4 -4
@@ -2310,10 +2310,10 @@ int sja1105_static_config_reload(struct goto out; } - t1 =timespec64_to_ns (&ptp_sts_before.pre_ts); - t2 =timespec64_to_ns (&ptp_sts_before.post_ts); - t3 =timespec64_to_ns (&ptp_sts_after.pre_ts); - t4 =timespec64_to_ns (&ptp_sts_after.post_ts); + t1 =ktime_to_ns (ptp_sts_before.pre_sts.systime); + t2 =ktime_to_ns (ptp_sts_before.post_sts.systime); + t3 =ktime_to_ns (ptp_sts_after.pre_sts.systime); + t4 =ktime_to_ns (ptp_sts_after.post_sts.systime);/* Mid point, corresponds to pre-reset PTPCLKVAL */ t12 = t1 + (t2 - t1) /2 ;/* Mid point, corresponds to post-reset PTPCLKVAL, aka 0 */
drivers/ptp/ptp_chardev.c +9 -5
@@ -386,15 +386,19 @@ static long ptp_sys_offset_extended(strureturn err;/* Filter out disabled or unavailable clocks */ -if (sts.pre_ts.tv_sec <0 || sts.post_ts.tv_sec <0 ) +if (!sts.pre_sts.valid || !sts.post_sts.valid)return -EINVAL ; - extoff->ts[i][0 ].sec = sts.pre_ts.tv_sec; - extoff->ts[i][0 ].nsec = sts.pre_ts.tv_nsec; extoff->ts[i][1 ].sec = ts.tv_sec; extoff->ts[i][1 ].nsec = ts.tv_nsec; - extoff->ts[i][2 ].sec = sts.post_ts.tv_sec; - extoff->ts[i][2 ].nsec = sts.post_ts.tv_nsec; + + ts =ktime_to_timespec64 (sts.pre_sts.systime); + extoff->ts[i][0 ].sec = ts.tv_sec; + extoff->ts[i][0 ].nsec = ts.tv_nsec; + + ts =ktime_to_timespec64 (sts.post_sts.systime); + extoff->ts[i][2 ].sec = ts.tv_sec; + extoff->ts[i][2 ].nsec = ts.tv_nsec; }return copy_to_user (arg, extoff,sizeof (*extoff)) ? -EFAULT :0 ;
drivers/ptp/ptp_ocp.c +4 -7
@@ -1491,11 +1491,8 @@ static int }ptp_read_system_postts (sts); -if (sts && bp->ts_window_adjust) { -s64 ns =timespec64_to_ns (&sts->post_ts); - - sts->post_ts =ns_to_timespec64 (ns - bp->ts_window_adjust); - } +if (sts && bp->ts_window_adjust) + sts->post_sts.systime -= bp->ts_window_adjust; time_ns =ioread32 (&bp->reg->time_ns); time_sec =ioread32 (&bp->reg->time_sec);
@@ -4595,8 +4592,8 @@ ptp_ocp_summary_show(struct seq_file *s,struct timespec64 sys_ts;s64 pre_ns, post_ns, ns; - pre_ns =timespec64_to_ns (&sts.pre_ts); - post_ns =timespec64_to_ns (&sts.post_ts); + pre_ns =ktime_to_ns (sts.pre_sts.systime); + post_ns =ktime_to_ns (sts.post_sts.systime); ns = (pre_ns + post_ns) /2 ; ns += (s64 )bp->utc_tai_offset *NSEC_PER_SEC ; sys_ts =ns_to_timespec64 (ns);
drivers/ptp/ptp_vmclock.c +7 -16
@@ -101,7 +101,6 @@ static int vmclock_get_crosststamp(struc struct timespec64 *tspec) {ktime_t deadline =ktime_add (ktime_get (),VMCLOCK_MAX_WAIT ); -struct system_time_snapshot systime_snapshot;uint64_t cycle, delta, seq, frac_sec;#ifdef CONFIG_X86
@@ -132,17 +131,15 @@ static int vmclock_get_crosststamp(struc* will be derived from the *same* counter value. * * If the system isn't using the same counter, then the value -* from ktime_get_snapshot_id() will still be used as pre_ts, and -* ptp_read_system_postts() is called to populate postts after -* calling get_cycles(). -* -* The conversion to timespec64 happens further down, outside -* the seq_count loop. +* from ptp_read_system_prets() will still be used as pre_ts, +* and ptp_read_system_postts() is called to populate postts +* after calling get_cycles(). */ if (sts) { -ktime_get_snapshot_id (CLOCK_REALTIME , &systime_snapshot); -if (systime_snapshot.cs_id == st->cs_id) { - cycle = systime_snapshot.cycles; +ptp_read_system_prets (sts); +if (sts->pre_sts.cs_id == st->cs_id) { + cycle = sts->pre_sts.cycles; + sts->post_sts = sts->pre_sts; }else { cycle =get_cycles ();ptp_read_system_postts (sts);
@@ -180,12 +177,6 @@ static int vmclock_get_crosststamp(struc system_counter->cs_id = st->cs_id; } -if (sts) { - sts->pre_ts =ktime_to_timespec64 (systime_snapshot.systime); -if (systime_snapshot.cs_id == st->cs_id) - sts->post_ts = sts->pre_ts; - } -return 0 ; }
include/linux/ptp_clock_kernel.h +8 -7
@@ -12,6 +12,7 @@#include <linux/pps_kernel.h> #include <linux/ptp_clock.h> #include <linux/timecounter.h> +#include <linux/timekeeping.h> #include <linux/skbuff.h> #define PTP_CLOCK_NAME_LEN 32
@@ -45,13 +46,13 @@ struct system_device_crosststamp;/** * struct ptp_system_timestamp - system time corresponding to a PHC timestamp -* @pre_ts: system timestamp before capturing PHC -* @post_ts: system timestamp after capturing PHC -* @clockid: clock-base used for capturing the system timestamps +* @pre_sts: system time snapshot before capturing PHC +* @post_sts: system time snapshot after capturing PHC +* @clockid: clock-base used for capturing the system timestamps */ struct ptp_system_timestamp { -struct timespec64 pre_ts; -struct timespec64 post_ts; +struct system_time_snapshot pre_sts; +struct system_time_snapshot post_sts;clockid_t clockid; };
@@ -510,13 +511,13 @@ static inline ktime_t ptp_convert_timeststatic inline void ptp_read_system_prets (struct ptp_system_timestamp *sts) {if (sts) -ktime_get_clock_ts64 (sts->clockid, &sts->pre_ts); +ktime_get_snapshot_id (sts->clockid, &sts->pre_sts); }static inline void ptp_read_system_postts (struct ptp_system_timestamp *sts) {if (sts) -ktime_get_clock_ts64 (sts->clockid, &sts->post_ts); +ktime_get_snapshot_id (sts->clockid, &sts->post_sts); }#endif
[tip: timers/ptp] ptp: Switch to ktime_get_snapshot_id() for pre/post timestamps
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 1ed6bf4c4ea99a0b1cdc16621cd15fb2b559f9d4 Gitweb: https://git.kernel.org/tip/1ed6bf4c4ea99a0b1cdc16621cd15fb2b559f9d4 Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:01:25 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 02 Jun 2026 11:40:00 +02:00
ptp: Switch to ktime_get_snapshot_id() for pre/post timestamps
To prepare for a new PTP IOCTL, which exposes the raw counter value along with the requested system time snapshot, switch the pre/post time stamp sampling over to use ktime_get_snapshot_id() and fix up all usage sites.
No functional change intended.
The ptp_vmclock conversion was simplified by David Woodhouse.
--- drivers/net/dsa/sja1105/sja1105_main.c | 8 ++++---- drivers/ptp/ptp_chardev.c | 14 +++++++++----- drivers/ptp/ptp_ocp.c | 11 ++++------- drivers/ptp/ptp_vmclock.c | 23 +++++++---------------- include/linux/ptp_clock_kernel.h | 15 ++++++++------- 5 files changed, 32 insertions(+), 39 deletions(-)
drivers/net/dsa/sja1105/sja1105_main.c +4 -4
@@ -2310,10 +2310,10 @@ int sja1105_static_config_reload(struct sja1105_private *priv, goto out; } - t1 =timespec64_to_ns (&ptp_sts_before.pre_ts); - t2 =timespec64_to_ns (&ptp_sts_before.post_ts); - t3 =timespec64_to_ns (&ptp_sts_after.pre_ts); - t4 =timespec64_to_ns (&ptp_sts_after.post_ts); + t1 =ktime_to_ns (ptp_sts_before.pre_sts.systime); + t2 =ktime_to_ns (ptp_sts_before.post_sts.systime); + t3 =ktime_to_ns (ptp_sts_after.pre_sts.systime); + t4 =ktime_to_ns (ptp_sts_after.post_sts.systime);/* Mid point, corresponds to pre-reset PTPCLKVAL */ t12 = t1 + (t2 - t1) /2 ;/* Mid point, corresponds to post-reset PTPCLKVAL, aka 0 */
drivers/ptp/ptp_chardev.c +9 -5
@@ -386,15 +386,19 @@ static long ptp_sys_offset_extended(struct ptp_clock *ptp, void __user *arg,return err;/* Filter out disabled or unavailable clocks */ -if (sts.pre_ts.tv_sec <0 || sts.post_ts.tv_sec <0 ) +if (!sts.pre_sts.valid || !sts.post_sts.valid)return -EINVAL ; - extoff->ts[i][0 ].sec = sts.pre_ts.tv_sec; - extoff->ts[i][0 ].nsec = sts.pre_ts.tv_nsec; extoff->ts[i][1 ].sec = ts.tv_sec; extoff->ts[i][1 ].nsec = ts.tv_nsec; - extoff->ts[i][2 ].sec = sts.post_ts.tv_sec; - extoff->ts[i][2 ].nsec = sts.post_ts.tv_nsec; + + ts =ktime_to_timespec64 (sts.pre_sts.systime); + extoff->ts[i][0 ].sec = ts.tv_sec; + extoff->ts[i][0 ].nsec = ts.tv_nsec; + + ts =ktime_to_timespec64 (sts.post_sts.systime); + extoff->ts[i][2 ].sec = ts.tv_sec; + extoff->ts[i][2 ].nsec = ts.tv_nsec; }return copy_to_user (arg, extoff,sizeof (*extoff)) ? -EFAULT :0 ;
drivers/ptp/ptp_ocp.c +4 -7
@@ -1491,11 +1491,8 @@ __ptp_ocp_gettime_locked(struct ptp_ocp *bp, struct timespec64 *ts, }ptp_read_system_postts (sts); -if (sts && bp->ts_window_adjust) { -s64 ns =timespec64_to_ns (&sts->post_ts); - - sts->post_ts =ns_to_timespec64 (ns - bp->ts_window_adjust); - } +if (sts && bp->ts_window_adjust) + sts->post_sts.systime -= bp->ts_window_adjust; time_ns =ioread32 (&bp->reg->time_ns); time_sec =ioread32 (&bp->reg->time_sec);
@@ -4595,8 +4592,8 @@ ptp_ocp_summary_show(struct seq_file *s, void *data)struct timespec64 sys_ts;s64 pre_ns, post_ns, ns; - pre_ns =timespec64_to_ns (&sts.pre_ts); - post_ns =timespec64_to_ns (&sts.post_ts); + pre_ns =ktime_to_ns (sts.pre_sts.systime); + post_ns =ktime_to_ns (sts.post_sts.systime); ns = (pre_ns + post_ns) /2 ; ns += (s64 )bp->utc_tai_offset *NSEC_PER_SEC ; sys_ts =ns_to_timespec64 (ns);
drivers/ptp/ptp_vmclock.c +7 -16
@@ -101,7 +101,6 @@ static int vmclock_get_crosststamp(struct vmclock_state *st, struct timespec64 *tspec) {ktime_t deadline =ktime_add (ktime_get (),VMCLOCK_MAX_WAIT ); -struct system_time_snapshot systime_snapshot;uint64_t cycle, delta, seq, frac_sec;#ifdef CONFIG_X86
@@ -132,17 +131,15 @@ static int vmclock_get_crosststamp(struct vmclock_state *st,* will be derived from the *same* counter value. * * If the system isn't using the same counter, then the value -* from ktime_get_snapshot_id() will still be used as pre_ts, and -* ptp_read_system_postts() is called to populate postts after -* calling get_cycles(). -* -* The conversion to timespec64 happens further down, outside -* the seq_count loop. +* from ptp_read_system_prets() will still be used as pre_ts, +* and ptp_read_system_postts() is called to populate postts +* after calling get_cycles(). */ if (sts) { -ktime_get_snapshot_id (CLOCK_REALTIME , &systime_snapshot); -if (systime_snapshot.cs_id == st->cs_id) { - cycle = systime_snapshot.cycles; +ptp_read_system_prets (sts); +if (sts->pre_sts.cs_id == st->cs_id) { + cycle = sts->pre_sts.cycles; + sts->post_sts = sts->pre_sts; }else { cycle =get_cycles ();ptp_read_system_postts (sts);
@@ -180,12 +177,6 @@ static int vmclock_get_crosststamp(struct vmclock_state *st, system_counter->cs_id = st->cs_id; } -if (sts) { - sts->pre_ts =ktime_to_timespec64 (systime_snapshot.systime); -if (systime_snapshot.cs_id == st->cs_id) - sts->post_ts = sts->pre_ts; - } -return 0 ; }
include/linux/ptp_clock_kernel.h +8 -7
@@ -12,6 +12,7 @@#include <linux/pps_kernel.h> #include <linux/ptp_clock.h> #include <linux/timecounter.h> +#include <linux/timekeeping.h> #include <linux/skbuff.h> #define PTP_CLOCK_NAME_LEN 32
@@ -45,13 +46,13 @@ struct system_device_crosststamp;/** * struct ptp_system_timestamp - system time corresponding to a PHC timestamp -* @pre_ts: system timestamp before capturing PHC -* @post_ts: system timestamp after capturing PHC -* @clockid: clock-base used for capturing the system timestamps +* @pre_sts: system time snapshot before capturing PHC +* @post_sts: system time snapshot after capturing PHC +* @clockid: clock-base used for capturing the system timestamps */ struct ptp_system_timestamp { -struct timespec64 pre_ts; -struct timespec64 post_ts; +struct system_time_snapshot pre_sts; +struct system_time_snapshot post_sts;clockid_t clockid; };
@@ -510,13 +511,13 @@ static inline ktime_t ptp_convert_timestamp(const ktime_t *hwtstamp,static inline void ptp_read_system_prets (struct ptp_system_timestamp *sts) {if (sts) -ktime_get_clock_ts64 (sts->clockid, &sts->pre_ts); +ktime_get_snapshot_id (sts->clockid, &sts->pre_sts); }static inline void ptp_read_system_postts (struct ptp_system_timestamp *sts) {if (sts) -ktime_get_clock_ts64 (sts->clockid, &sts->post_ts); +ktime_get_snapshot_id (sts->clockid, &sts->post_sts); }#endif
[tip: timers/ptp] ptp: Switch to ktime_get_snapshot_id() for pre/post timestamps
In reply to Thomas GleixnerThe following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: a6d799608e6a61b48908bff955200d03c34c90ca Gitweb: https://git.kernel.org/tip/a6d799608e6a61b48908bff955200d03c34c90ca Author: Thomas Gleixner <[email protected]> AuthorDate: Fri, 29 May 2026 22:01:25 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 04 Jun 2026 11:04:18 +02:00
ptp: Switch to ktime_get_snapshot_id() for pre/post timestamps
To prepare for a new PTP IOCTL, which exposes the raw counter value along with the requested system time snapshot, switch the pre/post time stamp sampling over to use ktime_get_snapshot_id() and fix up all usage sites.
No functional change intended.
The ptp_vmclock conversion was simplified by David Woodhouse.
--- drivers/net/dsa/sja1105/sja1105_main.c | 8 ++++---- drivers/ptp/ptp_chardev.c | 14 +++++++++----- drivers/ptp/ptp_ocp.c | 11 ++++------- drivers/ptp/ptp_vmclock.c | 23 +++++++---------------- include/linux/ptp_clock_kernel.h | 15 ++++++++------- 5 files changed, 32 insertions(+), 39 deletions(-)
drivers/net/dsa/sja1105/sja1105_main.c +4 -4
@@ -2310,10 +2310,10 @@ int sja1105_static_config_reload(struct sja1105_private *priv, goto out; } - t1 =timespec64_to_ns (&ptp_sts_before.pre_ts); - t2 =timespec64_to_ns (&ptp_sts_before.post_ts); - t3 =timespec64_to_ns (&ptp_sts_after.pre_ts); - t4 =timespec64_to_ns (&ptp_sts_after.post_ts); + t1 =ktime_to_ns (ptp_sts_before.pre_sts.systime); + t2 =ktime_to_ns (ptp_sts_before.post_sts.systime); + t3 =ktime_to_ns (ptp_sts_after.pre_sts.systime); + t4 =ktime_to_ns (ptp_sts_after.post_sts.systime);/* Mid point, corresponds to pre-reset PTPCLKVAL */ t12 = t1 + (t2 - t1) /2 ;/* Mid point, corresponds to post-reset PTPCLKVAL, aka 0 */
drivers/ptp/ptp_chardev.c +9 -5
@@ -386,15 +386,19 @@ static long ptp_sys_offset_extended(struct ptp_clock *ptp, void __user *arg,return err;/* Filter out disabled or unavailable clocks */ -if (sts.pre_ts.tv_sec <0 || sts.post_ts.tv_sec <0 ) +if (!sts.pre_sts.valid || !sts.post_sts.valid)return -EINVAL ; - extoff->ts[i][0 ].sec = sts.pre_ts.tv_sec; - extoff->ts[i][0 ].nsec = sts.pre_ts.tv_nsec; extoff->ts[i][1 ].sec = ts.tv_sec; extoff->ts[i][1 ].nsec = ts.tv_nsec; - extoff->ts[i][2 ].sec = sts.post_ts.tv_sec; - extoff->ts[i][2 ].nsec = sts.post_ts.tv_nsec; + + ts =ktime_to_timespec64 (sts.pre_sts.systime); + extoff->ts[i][0 ].sec = ts.tv_sec; + extoff->ts[i][0 ].nsec = ts.tv_nsec; + + ts =ktime_to_timespec64 (sts.post_sts.systime); + extoff->ts[i][2 ].sec = ts.tv_sec; + extoff->ts[i][2 ].nsec = ts.tv_nsec; }return copy_to_user (arg, extoff,sizeof (*extoff)) ? -EFAULT :0 ;
drivers/ptp/ptp_ocp.c +4 -7
@@ -1491,11 +1491,8 @@ __ptp_ocp_gettime_locked(struct ptp_ocp *bp, struct timespec64 *ts, }ptp_read_system_postts (sts); -if (sts && bp->ts_window_adjust) { -s64 ns =timespec64_to_ns (&sts->post_ts); - - sts->post_ts =ns_to_timespec64 (ns - bp->ts_window_adjust); - } +if (sts && bp->ts_window_adjust) + sts->post_sts.systime -= bp->ts_window_adjust; time_ns =ioread32 (&bp->reg->time_ns); time_sec =ioread32 (&bp->reg->time_sec);
@@ -4595,8 +4592,8 @@ ptp_ocp_summary_show(struct seq_file *s, void *data)struct timespec64 sys_ts;s64 pre_ns, post_ns, ns; - pre_ns =timespec64_to_ns (&sts.pre_ts); - post_ns =timespec64_to_ns (&sts.post_ts); + pre_ns =ktime_to_ns (sts.pre_sts.systime); + post_ns =ktime_to_ns (sts.post_sts.systime); ns = (pre_ns + post_ns) /2 ; ns += (s64 )bp->utc_tai_offset *NSEC_PER_SEC ; sys_ts =ns_to_timespec64 (ns);
drivers/ptp/ptp_vmclock.c +7 -16
@@ -101,7 +101,6 @@ static int vmclock_get_crosststamp(struct vmclock_state *st, struct timespec64 *tspec) {ktime_t deadline =ktime_add (ktime_get (),VMCLOCK_MAX_WAIT ); -struct system_time_snapshot systime_snapshot;uint64_t cycle, delta, seq, frac_sec;#ifdef CONFIG_X86
@@ -132,17 +131,15 @@ static int vmclock_get_crosststamp(struct vmclock_state *st,* will be derived from the *same* counter value. * * If the system isn't using the same counter, then the value -* from ktime_get_snapshot_id() will still be used as pre_ts, and -* ptp_read_system_postts() is called to populate postts after -* calling get_cycles(). -* -* The conversion to timespec64 happens further down, outside -* the seq_count loop. +* from ptp_read_system_prets() will still be used as pre_ts, +* and ptp_read_system_postts() is called to populate postts +* after calling get_cycles(). */ if (sts) { -ktime_get_snapshot_id (CLOCK_REALTIME , &systime_snapshot); -if (systime_snapshot.cs_id == st->cs_id) { - cycle = systime_snapshot.cycles; +ptp_read_system_prets (sts); +if (sts->pre_sts.cs_id == st->cs_id) { + cycle = sts->pre_sts.cycles; + sts->post_sts = sts->pre_sts; }else { cycle =get_cycles ();ptp_read_system_postts (sts);
@@ -180,12 +177,6 @@ static int vmclock_get_crosststamp(struct vmclock_state *st, system_counter->cs_id = st->cs_id; } -if (sts) { - sts->pre_ts =ktime_to_timespec64 (systime_snapshot.systime); -if (systime_snapshot.cs_id == st->cs_id) - sts->post_ts = sts->pre_ts; - } -return 0 ; }
include/linux/ptp_clock_kernel.h +8 -7
@@ -12,6 +12,7 @@#include <linux/pps_kernel.h> #include <linux/ptp_clock.h> #include <linux/timecounter.h> +#include <linux/timekeeping.h> #include <linux/skbuff.h> #define PTP_CLOCK_NAME_LEN 32
@@ -45,13 +46,13 @@ struct system_device_crosststamp;/** * struct ptp_system_timestamp - system time corresponding to a PHC timestamp -* @pre_ts: system timestamp before capturing PHC -* @post_ts: system timestamp after capturing PHC -* @clockid: clock-base used for capturing the system timestamps +* @pre_sts: system time snapshot before capturing PHC +* @post_sts: system time snapshot after capturing PHC +* @clockid: clock-base used for capturing the system timestamps */ struct ptp_system_timestamp { -struct timespec64 pre_ts; -struct timespec64 post_ts; +struct system_time_snapshot pre_sts; +struct system_time_snapshot post_sts;clockid_t clockid; };
@@ -510,13 +511,13 @@ static inline ktime_t ptp_convert_timestamp(const ktime_t *hwtstamp,static inline void ptp_read_system_prets (struct ptp_system_timestamp *sts) {if (sts) -ktime_get_clock_ts64 (sts->clockid, &sts->pre_ts); +ktime_get_snapshot_id (sts->clockid, &sts->pre_sts); }static inline void ptp_read_system_postts (struct ptp_system_timestamp *sts) {if (sts) -ktime_get_clock_ts64 (sts->clockid, &sts->post_ts); +ktime_get_snapshot_id (sts->clockid, &sts->post_sts); }#endif
Thomas Gleixner
maintainerPATCH v2 25/25 timekeeping: Add clocksource read_snapshot() method and hw_cycles to snapshot
In reply to Thomas GleixnerFrom: David Woodhouse <[email protected]>
Add a read_snapshot() callback to struct clocksource which returns the derived clocksource value while also providing the underlying hardware counter reading and the related clocksource ID.
This allows ktime_get_snapshot_id() to populate new hw_cycles and hw_csid fields in struct system_time_snapshot.
For clocksources that are derived from an underlying counter (e.g., Hyper-V TSC page scales TSC to 10MHz, kvmclock scales TSC to 1GHz), this provides atomic access to both the derived value needed for timekeeping calculations, and the raw hardware counter needed by consumers like KVM's master clock and the vmclock PTP driver.
[ tglx: Reworked it slightly ]
--- include/linux/clocksource.h | 24 ++++++++++++++++++++++++ include/linux/timekeeping.h | 6 ++++++ kernel/time/timekeeping.c | 21 ++++++++++++++++++++- 3 files changed, 50 insertions(+), 1 deletion(-)
include/linux/clocksource.h +24 -0
@@ -32,6 +32,21 @@ struct module;#include <vdso/clocksource.h> /** +* struct clocksource_hw_snapshot - Snapshot for the underlying hardware counter of derived +* clocksources like kvmclock or Hyper-V scaled TSC +* @hw_cycles: The hardware counter value +* @hw_csid: Clocksource ID of the hardware counter +* +* Such clocksources must implement the read_snapshot() callback and fill in the +* hardware counter value, the clocksource ID of the hardware counter and derive +* the actual clocksource cycles from @hw_cycles to provide an atomic snapshot +*/ +struct clocksource_hw_snapshot { +u64 hw_cycles; +enum clocksource_ids hw_csid; +}; + +/** * struct clocksource - hardware abstraction for a free running counter * Provides mostly state-free accessors to the underlying hardware. * This is the structure used for system time.
@@ -72,6 +87,14 @@ struct module;* @flags: Flags describing special properties * @base: Hardware abstraction for clock on which a clocksource * is based +* @read_snapshot: Extended @read() function for clocksources such as +* kvmclock or the Hyper-V scaled TSC where the actual +* clocksource value for timekeeping is calculated from an +* underlying hardware counter. Returns the timekeeping +* relevant cycle value and stores the raw value of the +* underlying counter from which it was calculated +* including the clocksource ID of that counter in the +* clocksource hardware snapshot. * @enable: Optional function to enable the clocksource * @disable: Optional function to disable the clocksource * @suspend: Optional suspend function for the clocksource
@@ -113,6 +136,7 @@ struct clocksource {unsigned long flags;struct clocksource_base *base; +u64 (*read_snapshot)(struct clocksource *cs,struct clocksource_hw_snapshot *chs);int (*enable)(struct clocksource *cs);void (*disable)(struct clocksource *cs);void (*suspend)(struct clocksource *cs);
include/linux/timekeeping.h +6 -0
@@ -279,18 +279,24 @@ static inline bool ktime_get_aux_ts64(cl* struct system_time_snapshot - Simultaneous time capture of CLOCK_MONOTONIC_RAW, * a selected CLOCK_* and the clocksource counter value * @cycles: Clocksource counter value to produce the system times +* @hw_cycles: For derived clocksources, the hardware counter value from +* which @cycles was derived * @systime: The system time of the selected CLOCK ID * @monoraw: Monotonic raw system time * @cs_id: Clocksource ID +* @hw_csid: Clocksource ID of the underlying hardware counter for derived +* clocksources which implement the read_snapshot() callback. * @clock_was_set_seq: The sequence number of clock-was-set events * @cs_was_changed_seq: The sequence number of clocksource change events * @valid: True if the snapshot is valid */ struct system_time_snapshot {u64 cycles; +u64 hw_cycles;ktime_t systime;ktime_t monoraw;enum clocksource_ids cs_id; +enum clocksource_ids hw_csid;unsigned int clock_was_set_seq;u8 cs_was_changed_seq;u8 valid;
kernel/time/timekeeping.c +20 -1
@@ -320,6 +320,7 @@ static __always_inline u64 tk_clock_read return clock->read(clock); } +static inline void clocksource_disable_inline_read (void ) { }static inline void clocksource_enable_inline_read (void ) { }#endif
@@ -1187,6 +1188,18 @@ noinstr time64_t __ktime_get_real_secondreturn tk->xtime_sec; } +static inline u64 tk_clock_read_snapshot (const struct tk_read_base *tkr, +struct clocksource_hw_snapshot *chs) +{ +struct clocksource *clock =READ_ONCE (tkr->clock); + +if (unlikely (clock->read_snapshot)) +return clock->read_snapshot (clock, chs); + +return clock->read (clock); +} + +/** * ktime_get_snapshot_id - Simultaneously snapshot a given clock ID with * CLOCK_MONOTONIC_RAW and the underlying
@@ -1237,14 +1250,20 @@ void ktime_get_snapshot_id(clockid_t clo tk = &tkd->timekeeper; do { + struct clocksource_hw_snapshot chs = { }; + seq = read_seqcount_begin(&tkd->seq); /* Aux clocks can be invalid */ if (!tk->clock_valid) return; - now = tk_clock_read(&tk->tkr_mono); + now = tk_clock_read_snapshot(&tk->tkr_mono, &chs); systime_snapshot->cs_id = tk->tkr_mono.clock->id; + + systime_snapshot->hw_cycles = chs.hw_cycles; + systime_snapshot->hw_csid = chs.hw_csid; + systime_snapshot->cs_was_changed_seq = tk->cs_was_changed_seq; systime_snapshot->clock_was_set_seq = tk->clock_was_set_seq;
[tip: timers/ptp] timekeeping: Add clocksource read_snapshot() method and hw_cycles to snapshot
The following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: 571287cd351fcda7df3050009786f110cfd30bd9 Gitweb: https://git.kernel.org/tip/571287cd351fcda7df3050009786f110cfd30bd9 Author: David Woodhouse <[email protected]> AuthorDate: Fri, 29 May 2026 22:01:29 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 02 Jun 2026 11:40:00 +02:00
timekeeping: Add clocksource read_snapshot() method and hw_cycles to snapshot
Add a read_snapshot() callback to struct clocksource which returns the derived clocksource value while also providing the underlying hardware counter reading and the related clocksource ID.
This allows ktime_get_snapshot_id() to populate new hw_cycles and hw_csid fields in struct system_time_snapshot.
For clocksources that are derived from an underlying counter (e.g., Hyper-V TSC page scales TSC to 10MHz, kvmclock scales TSC to 1GHz), this provides atomic access to both the derived value needed for timekeeping calculations, and the raw hardware counter needed by consumers like KVM's master clock and the vmclock PTP driver.
[ tglx: Reworked it slightly ]
--- include/linux/clocksource.h | 24 ++++++++++++++++++++++++ include/linux/timekeeping.h | 6 ++++++ kernel/time/timekeeping.c | 21 ++++++++++++++++++++- 3 files changed, 50 insertions(+), 1 deletion(-)
include/linux/clocksource.h +24 -0
@@ -32,6 +32,21 @@ struct module;#include <vdso/clocksource.h> /** +* struct clocksource_hw_snapshot - Snapshot for the underlying hardware counter of derived +* clocksources like kvmclock or Hyper-V scaled TSC +* @hw_cycles: The hardware counter value +* @hw_csid: Clocksource ID of the hardware counter +* +* Such clocksources must implement the read_snapshot() callback and fill in the +* hardware counter value, the clocksource ID of the hardware counter and derive +* the actual clocksource cycles from @hw_cycles to provide an atomic snapshot +*/ +struct clocksource_hw_snapshot { +u64 hw_cycles; +enum clocksource_ids hw_csid; +}; + +/** * struct clocksource - hardware abstraction for a free running counter * Provides mostly state-free accessors to the underlying hardware. * This is the structure used for system time.
@@ -72,6 +87,14 @@ struct module;* @flags: Flags describing special properties * @base: Hardware abstraction for clock on which a clocksource * is based +* @read_snapshot: Extended @read() function for clocksources such as +* kvmclock or the Hyper-V scaled TSC where the actual +* clocksource value for timekeeping is calculated from an +* underlying hardware counter. Returns the timekeeping +* relevant cycle value and stores the raw value of the +* underlying counter from which it was calculated +* including the clocksource ID of that counter in the +* clocksource hardware snapshot. * @enable: Optional function to enable the clocksource * @disable: Optional function to disable the clocksource * @suspend: Optional suspend function for the clocksource
@@ -113,6 +136,7 @@ struct clocksource {unsigned long flags;struct clocksource_base *base; +u64 (*read_snapshot)(struct clocksource *cs,struct clocksource_hw_snapshot *chs);int (*enable)(struct clocksource *cs);void (*disable)(struct clocksource *cs);void (*suspend)(struct clocksource *cs);
include/linux/timekeeping.h +6 -0
@@ -279,18 +279,24 @@ static inline bool ktime_get_aux_ts64(clockid_t id, struct timespec64 *kt) { ret* struct system_time_snapshot - Simultaneous time capture of CLOCK_MONOTONIC_RAW, * a selected CLOCK_* and the clocksource counter value * @cycles: Clocksource counter value to produce the system times +* @hw_cycles: For derived clocksources, the hardware counter value from +* which @cycles was derived * @systime: The system time of the selected CLOCK ID * @monoraw: Monotonic raw system time * @cs_id: Clocksource ID +* @hw_csid: Clocksource ID of the underlying hardware counter for derived +* clocksources which implement the read_snapshot() callback. * @clock_was_set_seq: The sequence number of clock-was-set events * @cs_was_changed_seq: The sequence number of clocksource change events * @valid: True if the snapshot is valid */ struct system_time_snapshot {u64 cycles; +u64 hw_cycles;ktime_t systime;ktime_t monoraw;enum clocksource_ids cs_id; +enum clocksource_ids hw_csid;unsigned int clock_was_set_seq;u8 cs_was_changed_seq;u8 valid;
kernel/time/timekeeping.c +20 -1
@@ -320,6 +320,7 @@ static __always_inline u64 tk_clock_read(const struct tk_read_base *tkr) return clock->read(clock); } +static inline void clocksource_disable_inline_read (void ) { }static inline void clocksource_enable_inline_read (void ) { }#endif
@@ -1187,6 +1188,18 @@ noinstr time64_t __ktime_get_real_seconds(void)return tk->xtime_sec; } +static inline u64 tk_clock_read_snapshot (const struct tk_read_base *tkr, +struct clocksource_hw_snapshot *chs) +{ +struct clocksource *clock =READ_ONCE (tkr->clock); + +if (unlikely (clock->read_snapshot)) +return clock->read_snapshot (clock, chs); + +return clock->read (clock); +} + +/** * ktime_get_snapshot_id - Simultaneously snapshot a given clock ID with * CLOCK_MONOTONIC_RAW and the underlying
@@ -1237,14 +1250,20 @@ void ktime_get_snapshot_id(clockid_t clock_id, struct system_time_snapshot *syst tk = &tkd->timekeeper; do { + struct clocksource_hw_snapshot chs = { }; + seq = read_seqcount_begin(&tkd->seq); /* Aux clocks can be invalid */ if (!tk->clock_valid) return; - now = tk_clock_read(&tk->tkr_mono); + now = tk_clock_read_snapshot(&tk->tkr_mono, &chs); systime_snapshot->cs_id = tk->tkr_mono.clock->id; + + systime_snapshot->hw_cycles = chs.hw_cycles; + systime_snapshot->hw_csid = chs.hw_csid; + systime_snapshot->cs_was_changed_seq = tk->cs_was_changed_seq; systime_snapshot->clock_was_set_seq = tk->clock_was_set_seq;
[tip: timers/ptp] timekeeping: Add clocksource read_snapshot() method and hw_cycles to snapshot
In reply to Thomas GleixnerThe following commit has been merged into the timers/ptp branch of tip:
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: ca1ec8bfac8c95d0fed9e3611ea21400d1f37262 Gitweb: https://git.kernel.org/tip/ca1ec8bfac8c95d0fed9e3611ea21400d1f37262 Author: David Woodhouse <[email protected]> AuthorDate: Fri, 29 May 2026 22:01:29 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 04 Jun 2026 11:04:18 +02:00
timekeeping: Add clocksource read_snapshot() method and hw_cycles to snapshot
Add a read_snapshot() callback to struct clocksource which returns the derived clocksource value while also providing the underlying hardware counter reading and the related clocksource ID.
This allows ktime_get_snapshot_id() to populate new hw_cycles and hw_csid fields in struct system_time_snapshot.
For clocksources that are derived from an underlying counter (e.g., Hyper-V TSC page scales TSC to 10MHz, kvmclock scales TSC to 1GHz), this provides atomic access to both the derived value needed for timekeeping calculations, and the raw hardware counter needed by consumers like KVM's master clock and the vmclock PTP driver.
[ tglx: Reworked it slightly ]
--- include/linux/clocksource.h | 24 ++++++++++++++++++++++++ include/linux/timekeeping.h | 6 ++++++ kernel/time/timekeeping.c | 21 ++++++++++++++++++++- 3 files changed, 50 insertions(+), 1 deletion(-)
include/linux/clocksource.h +24 -0
@@ -32,6 +32,21 @@ struct module;#include <vdso/clocksource.h> /** +* struct clocksource_hw_snapshot - Snapshot for the underlying hardware counter of derived +* clocksources like kvmclock or Hyper-V scaled TSC +* @hw_cycles: The hardware counter value +* @hw_csid: Clocksource ID of the hardware counter +* +* Such clocksources must implement the read_snapshot() callback and fill in the +* hardware counter value, the clocksource ID of the hardware counter and derive +* the actual clocksource cycles from @hw_cycles to provide an atomic snapshot +*/ +struct clocksource_hw_snapshot { +u64 hw_cycles; +enum clocksource_ids hw_csid; +}; + +/** * struct clocksource - hardware abstraction for a free running counter * Provides mostly state-free accessors to the underlying hardware. * This is the structure used for system time.
@@ -72,6 +87,14 @@ struct module;* @flags: Flags describing special properties * @base: Hardware abstraction for clock on which a clocksource * is based +* @read_snapshot: Extended @read() function for clocksources such as +* kvmclock or the Hyper-V scaled TSC where the actual +* clocksource value for timekeeping is calculated from an +* underlying hardware counter. Returns the timekeeping +* relevant cycle value and stores the raw value of the +* underlying counter from which it was calculated +* including the clocksource ID of that counter in the +* clocksource hardware snapshot. * @enable: Optional function to enable the clocksource * @disable: Optional function to disable the clocksource * @suspend: Optional suspend function for the clocksource
@@ -113,6 +136,7 @@ struct clocksource {unsigned long flags;struct clocksource_base *base; +u64 (*read_snapshot)(struct clocksource *cs,struct clocksource_hw_snapshot *chs);int (*enable)(struct clocksource *cs);void (*disable)(struct clocksource *cs);void (*suspend)(struct clocksource *cs);
include/linux/timekeeping.h +6 -0
@@ -279,18 +279,24 @@ static inline bool ktime_get_aux_ts64(clockid_t id, struct timespec64 *kt) { ret* struct system_time_snapshot - Simultaneous time capture of CLOCK_MONOTONIC_RAW, * a selected CLOCK_* and the clocksource counter value * @cycles: Clocksource counter value to produce the system times +* @hw_cycles: For derived clocksources, the hardware counter value from +* which @cycles was derived * @systime: The system time of the selected CLOCK ID * @monoraw: Monotonic raw system time * @cs_id: Clocksource ID +* @hw_csid: Clocksource ID of the underlying hardware counter for derived +* clocksources which implement the read_snapshot() callback. * @clock_was_set_seq: The sequence number of clock-was-set events * @cs_was_changed_seq: The sequence number of clocksource change events * @valid: True if the snapshot is valid */ struct system_time_snapshot {u64 cycles; +u64 hw_cycles;ktime_t systime;ktime_t monoraw;enum clocksource_ids cs_id; +enum clocksource_ids hw_csid;unsigned int clock_was_set_seq;u8 cs_was_changed_seq;u8 valid;
kernel/time/timekeeping.c +20 -1
@@ -320,6 +320,7 @@ static __always_inline u64 tk_clock_read(const struct tk_read_base *tkr) return clock->read(clock); } +static inline void clocksource_disable_inline_read (void ) { }static inline void clocksource_enable_inline_read (void ) { }#endif
@@ -1187,6 +1188,18 @@ noinstr time64_t __ktime_get_real_seconds(void)return tk->xtime_sec; } +static inline u64 tk_clock_read_snapshot (const struct tk_read_base *tkr, +struct clocksource_hw_snapshot *chs) +{ +struct clocksource *clock =READ_ONCE (tkr->clock); + +if (unlikely (clock->read_snapshot)) +return clock->read_snapshot (clock, chs); + +return clock->read (clock); +} + +/** * ktime_get_snapshot_id - Simultaneously snapshot a given clock ID with * CLOCK_MONOTONIC_RAW and the underlying
@@ -1237,14 +1250,20 @@ void ktime_get_snapshot_id(clockid_t clock_id, struct system_time_snapshot *syst tk = &tkd->timekeeper; do { + struct clocksource_hw_snapshot chs = { }; + seq = read_seqcount_begin(&tkd->seq); /* Aux clocks can be invalid */ if (!tk->clock_valid) return; - now = tk_clock_read(&tk->tkr_mono); + now = tk_clock_read_snapshot(&tk->tkr_mono, &chs); systime_snapshot->cs_id = tk->tkr_mono.clock->id; + + systime_snapshot->hw_cycles = chs.hw_cycles; + systime_snapshot->hw_csid = chs.hw_csid; + systime_snapshot->cs_was_changed_seq = tk->cs_was_changed_seq; systime_snapshot->clock_was_set_seq = tk->clock_was_set_seq;
Quoted 51 lines · Thomas Gleixner
This is an update to V1 which can be found here:
https://lore.kernel.org/lkml/[email protected]PTP wants to grow new snapshot functionality, which provides not only the captured CLOCK* values, but also the underlying clocksource counter value.
https://lore.kernel.org/[email protected]There was quite some discussion in seemingly related threads how to capture these values and how to provide core infrastructure so that driver writers have something to work with
https://lore.kernel.org/[email protected] https://lore.kernel.org/[email protected]This series implements the timekeeping related mechanisms to:
1) Capture CLOCK values along with the clocksource counter value for non-hardware based sampling
2) Expanding the hardware cross time stamp mechanism to hand back the clocksource counter value, which was captured by the device, along with the related CLOCK values
3) Adding AUX clock support to the hardware cross timestamping core
4) Add support for derived clocksources to the snapshot mechanism (New in V2)
Changes vs. V1:
- Fixed the
ptp_ocptypo - 0-day, Jakub- Renamed the
system_time_snapshotmembers sys and raw so systime and monoraw to make them less ambigous.- Fixed the error case return values of
get_device_system_crosststamp()- Made
ktime_snapshot_id()void as there is no point for the return value, which is nowhere checked and cannot be propagated.system_time_snapshot::validhas to be evaluated at the call sites anyway. - Jacob- Picked up the first patch from Davids follow up series, which extends the snapshot mechanism so that derived clocksources (like kvmclock and Hyper-V scaled TSC) can return the actual underlying hardware counter value (TSC for the two examples).
- Collected Reviewed/Acked/Tested-by tags
Quoted 7 lines
Delta patch against v1 below.
The series is based on v7.1-rc2 and also available from git:
git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.gittimekeeping-ptp-extend-v2Thanks,
The changes in v2 are great! Appreciate it.
Quoted 7 lines · Thomas Gleixner
This is an update to V1 which can be found here:
https://lore.kernel.org/lkml/[email protected]PTP wants to grow new snapshot functionality, which provides not only the captured CLOCK* values, but also the underlying clocksource counter value.
Quoted 8 lines
https://lore.kernel.org/[email protected]There was quite some discussion in seemingly related threads how to capture these values and how to provide core infrastructure so that driver writers have something to work with
https://lore.kernel.org/[email protected] https://lore.kernel.org/[email protected]
virtio bits:
Quoted 510 lines
This series implements the timekeeping related mechanisms to:
1) Capture CLOCK values along with the clocksource counter value for non-hardware based sampling
2) Expanding the hardware cross time stamp mechanism to hand back the clocksource counter value, which was captured by the device, along with the related CLOCK values
3) Adding AUX clock support to the hardware cross timestamping core
4) Add support for derived clocksources to the snapshot mechanism (New in V2)
Changes vs. V1:
- Fixed the
ptp_ocptypo - 0-day, Jakub- Renamed the
system_time_snapshotmembers sys and raw so systime and monoraw to make them less ambigous.- Fixed the error case return values of
get_device_system_crosststamp()- Made
ktime_snapshot_id()void as there is no point for the return value, which is nowhere checked and cannot be propagated.system_time_snapshot::validhas to be evaluated at the call sites anyway. - Jacob- Picked up the first patch from Davids follow up series, which extends the snapshot mechanism so that derived clocksources (like kvmclock and Hyper-V scaled TSC) can return the actual underlying hardware counter value (TSC for the two examples).
- Collected Reviewed/Acked/Tested-by tags
Delta patch against v1 below.
The series is based on v7.1-rc2 and also available from git:
git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.gittimekeeping-ptp-extend-v2Thanks,
tglx
---arch/arm64/kvm/hyp_trace.c +3
-3@@ -51,8 +51,8 @@ static void __hyp_clock_work(struct work_struct *work) hyp_clock = container_of(dwork, struct hyp_trace_clock, work); -ktime_get_snapshot_id (&snap,CLOCK_BOOTTIME ); - boot =ktime_to_ns (snap.sys); +ktime_get_snapshot_id (CLOCK_BOOTTIME , &snap); + boot =ktime_to_ns (snap.systime); delta_boot = boot - hyp_clock->boot; delta_cycles = snap.cycles - hyp_clock->cycles;@@ -120,7 +120,7 @@ static void hyp_trace_clock_enable(struct hyp_trace_clock *hyp_clock, bool enablktime_get_snapshot_id (&snap,CLOCK_BOOTTIME ); - hyp_clock->boot =ktime_to_ns (snap.sys); + hyp_clock->boot =ktime_to_ns (snap.systime); hyp_clock->cycles = snap.cycles; hyp_clock->mult =0 ;arch/arm64/kvm/hypercalls.c +3
-3@@ -28,7 +28,7 @@ static void kvm_ptp_get_time(struct kvm_vcpu *vcpu, u64 *val)* system time and counter value must captured at the same * time to keep consistency and precision. */ -ktime_get_snapshot_id (&systime_snapshot,CLOCK_REALTIME ); +ktime_get_snapshot_id (CLOCK_REALTIME , &systime_snapshot);/* * This is only valid if the current clocksource is the @@ -61,8 +61,8 @@ static void kvm_ptp_get_time(struct kvm_vcpu *vcpu, u64 *val)* in the future (about 292 years from 1970, and at that stage * nobody will give a damn about it). */ - val[0 ] =upper_32_bits (systime_snapshot.sys); - val[1 ] =lower_32_bits (systime_snapshot.sys); + val[0 ] =upper_32_bits (systime_snapshot.systime); + val[1 ] =lower_32_bits (systime_snapshot.systime); val[2 ] =upper_32_bits (cycles); val[3 ] =lower_32_bits (cycles); }drivers/net/dsa/sja1105/sja1105_main.c +4
-4@@ -2310,10 +2310,10 @@ int sja1105_static_config_reload(struct sja1105_private *priv, goto out; } - t1 =ktime_to_ns (ptp_sts_before.pre_sts.sys); - t2 =ktime_to_ns (ptp_sts_before.post_sts.sys); - t3 =ktime_to_ns (ptp_sts_after.pre_sts.sys); - t4 =ktime_to_ns (ptp_sts_after.post_sts.sys); + t1 =ktime_to_ns (ptp_sts_before.pre_sts.systime); + t2 =ktime_to_ns (ptp_sts_before.post_sts.systime); + t3 =ktime_to_ns (ptp_sts_after.pre_sts.systime); + t4 =ktime_to_ns (ptp_sts_after.post_sts.systime);/* Mid point, corresponds to pre-reset PTPCLKVAL */ t12 = t1 + (t2 - t1) /2 ;/* Mid point, corresponds to post-reset PTPCLKVAL, aka 0 */ drivers/net/ethernet/intel/ice/ice_ptp.c +1
-1@@ -2117,7 +2117,7 @@ static int ice_capture_crosststamp(ktime_t *device, }/* Snapshot system time for historic interpolation */ -ktime_get_snapshot_id (&ctx->snapshot, ctx->snapshot_clock_id); +ktime_get_snapshot_id (ctx->snapshot_clock_id, &ctx->snapshot);/* Program cmd to master timer */ ice_ptp_src_cmd (hw,ICE_PTP_READ_TIME );drivers/net/ethernet/intel/igc/igc_ptp.c +1
-1@@ -1049,7 +1049,7 @@ static int igc_phc_get_syncdevicetime(ktime_t *device,*/ do { /* Get a snapshot of system clocks to use as historic value. */ - ktime_get_snapshot_id(&adapter->snapshot, adapter->snapshot_clock_id); + ktime_get_snapshot_id(adapter->snapshot_clock_id, &adapter->snapshot); igc_ptm_trigger(hw);drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +2
-2@@ -340,7 +340,7 @@ static int mlx5_ptp_getcrosststamp(struct ptp_clock_info *ptp, goto unlock; } -ktime_get_snapshot_id (&history_begin, cts->clock_id); +ktime_get_snapshot_id (cts->clock_id, &history_begin); err =get_device_system_crosststamp (mlx5_mtctr_syncdevicetime, mdev, &history_begin, cts);@@ -366,7 +366,7 @@ static int mlx5_ptp_getcrosscycles(struct ptp_clock_info *ptp, goto unlock; } -ktime_get_snapshot_id (&history_begin, cts->clock_id); +ktime_get_snapshot_id (cts->clock_id, &history_begin); err =get_device_system_crosststamp (mlx5_mtctr_syncdevicecyclestime, mdev, &history_begin, cts);drivers/ptp/ptp_chardev.c +2
-2@@ -392,11 +392,11 @@ static long ptp_sys_offset_extended(struct ptp_clock *ptp, void __user *arg, extoff->ts[i][1 ].sec = ts.tv_sec; extoff->ts[i][1 ].nsec = ts.tv_nsec; - ts =ktime_to_timespec64 (sts.pre_sts.sys); + ts =ktime_to_timespec64 (sts.pre_sts.systime); extoff->ts[i][0 ].sec = ts.tv_sec; extoff->ts[i][0 ].nsec = ts.tv_nsec; - ts =ktime_to_timespec64 (sts.post_sts.sys); + ts =ktime_to_timespec64 (sts.post_sts.systime); extoff->ts[i][2 ].sec = ts.tv_sec; extoff->ts[i][2 ].nsec = ts.tv_nsec; }drivers/ptp/ptp_ocp.c +3
-3@@ -1492,7 +1492,7 @@ __ptp_ocp_gettime_locked(struct ptp_ocp *bp, struct timespec64 *ts,ptp_read_system_postts (sts);if (sts && bp->ts_window_adjust) - sts->post_ts.sys -= bp->ts_window_adjust; + sts->post_sts.systime -= bp->ts_window_adjust; time_ns =ioread32 (&bp->reg->time_ns); time_sec =ioread32 (&bp->reg->time_sec);@@ -4592,8 +4592,8 @@ ptp_ocp_summary_show(struct seq_file *s, void *data)struct timespec64 sys_ts;s64 pre_ns, post_ns, ns; - pre_ns =ktime_to_ns (sts.pre_sts.sys); - post_ns =ktime_to_ns (sts.post_sts.sys); + pre_ns =ktime_to_ns (sts.pre_sts.systime); + post_ns =ktime_to_ns (sts.post_sts.systime); ns = (pre_ns + post_ns) /2 ; ns += (s64 )bp->utc_tai_offset *NSEC_PER_SEC ; sys_ts =ns_to_timespec64 (ns);drivers/ptp/ptp_vmclock.c +1
-1@@ -263,7 +263,7 @@ static int ptp_vmclock_getcrosststamp(struct ptp_clock_info *ptp,if (ret == -ENODEV ) {struct system_time_snapshot systime_snapshot; -ktime_get_snapshot_id (&systime_snapshot,CLOCK_REALTIME ); +ktime_get_snapshot_id (CLOCK_REALTIME , &systime_snapshot);if (systime_snapshot.cs_id ==CSID_X86_TSC || systime_snapshot.cs_id ==CSID_X86_KVM_CLK ) {drivers/virtio/virtio_rtc_ptp.c +1
-1@@ -139,7 +139,7 @@ static int viortc_ptp_getcrosststamp(struct ptp_clock_info *ptp,if (ret)return ret; -ktime_get_snapshot_id (&history_begin, xtstamp->clock_id); +ktime_get_snapshot_id (xtstamp->clock_id, &history_begin);if (history_begin.cs_id != cs_id)return -EOPNOTSUPP ;include/linux/clocksource.h +24
-0@@ -31,6 +31,21 @@ struct module;#include <vdso/clocksource.h> +/** +* struct clocksource_hw_snapshot - Snapshot for the underlying hardware counter of derived +* clocksources like kvmclock or Hyper-V scaled TSC +* @hw_cycles: The hardware counter value +* @hw_csid: Clocksource ID of the hardware counter +* +* Such clocksources must implement the read_snapshot() callback and fill in the +* hardware counter value, the clocksource ID of the hardware counter and derive +* the actual clocksource cycles from @hw_cycles to provide an atomic snapshot +*/ +struct clocksource_hw_snapshot { +u64 hw_cycles; +enum clocksource_ids hw_csid; +}; +/** * struct clocksource - hardware abstraction for a free running counter * Provides mostly state-free accessors to the underlying hardware. @@ -72,6 +87,14 @@ struct module;* @flags: Flags describing special properties * @base: Hardware abstraction for clock on which a clocksource * is based +* @read_snapshot: Extended @read() function for clocksources such as +* kvmclock or the Hyper-V scaled TSC where the actual +* clocksource value for timekeeping is calculated from an +* underlying hardware counter. Returns the timekeeping +* relevant cycle value and stores the raw value of the +* underlying counter from which it was calculated +* including the clocksource ID of that counter in the +* clocksource hardware snapshot. * @enable: Optional function to enable the clocksource * @disable: Optional function to disable the clocksource * @suspend: Optional suspend function for the clocksource @@ -113,6 +136,7 @@ struct clocksource {unsigned long flags;struct clocksource_base *base; +u64 (*read_snapshot)(struct clocksource *cs,struct clocksource_hw_snapshot *chs);int (*enable)(struct clocksource *cs);void (*disable)(struct clocksource *cs);void (*suspend)(struct clocksource *cs);include/linux/pps_kernel.h +3
-3@@ -102,9 +102,9 @@ static inline void pps_get_ts(struct pps_event_time *ts)#ifdef CONFIG_NTP_PPS struct system_time_snapshot snap; -ktime_get_snapshot_id (&snap,CLOCK_REALTIME ); - ts->ts_real =ktime_to_timespec64 (snap.sys); - ts->ts_raw =ktime_to_timespec64 (snap.raw); +ktime_get_snapshot_id (CLOCK_REALTIME , &snap); + ts->ts_real =ktime_to_timespec64 (snap.systime); + ts->ts_raw =ktime_to_timespec64 (snap.monoraw);#else ktime_get_real_ts64 (&ts->ts_real);#endif include/linux/ptp_clock_kernel.h +2
-2@@ -511,13 +511,13 @@ static inline ktime_t ptp_convert_timestamp(const ktime_t *hwtstamp,static inline void ptp_read_system_prets (struct ptp_system_timestamp *sts) {if (sts) -ktime_get_snapshot_id (&sts->pre_sts, sts->clockid); +ktime_get_snapshot_id (sts->clockid, &sts->pre_sts); }static inline void ptp_read_system_postts (struct ptp_system_timestamp *sts) {if (sts) -ktime_get_snapshot_id (&sts->post_sts, sts->clockid); +ktime_get_snapshot_id (sts->clockid, &sts->post_sts); }#endif include/linux/timekeeping.h +11
-6@@ -279,18 +279,24 @@ static inline bool ktime_get_aux_ts64(clockid_t id, struct timespec64 *kt) { ret* struct system_time_snapshot - Simultaneous time capture of CLOCK_MONOTONIC_RAW, * a selected CLOCK_* and the clocksource counter value * @cycles: Clocksource counter value to produce the system times -* @sys: The system time of the selected CLOCK ID -* @raw: Monotonic raw system time +* @hw_cycles: For derived clocksources, the hardware counter value from +* which @cycles was derived +* @systime: The system time of the selected CLOCK ID +* @monoraw: Monotonic raw system time * @cs_id: Clocksource ID +* @hw_csid: Clocksource ID of the underlying hardware counter for derived +* clocksources which implement the read_snapshot() callback. * @clock_was_set_seq: The sequence number of clock-was-set events * @cs_was_changed_seq: The sequence number of clocksource change events * @valid: True if the snapshot is valid */ struct system_time_snapshot {u64 cycles; -ktime_t sys; -ktime_t raw; +u64 hw_cycles; +ktime_t systime; +ktime_t monoraw;enum clocksource_ids cs_id; +enum clocksource_ids hw_csid;unsigned int clock_was_set_seq;u8 cs_was_changed_seq;u8 valid;@@ -348,8 +354,7 @@ extern int get_device_system_crosststamp(* Simultaneously snapshot a given clock with MONOTONIC_RAW and the underlying * clocksource counter value. */ -extern bool ktime_get_snapshot_id (struct system_time_snapshot *systime_snapshot, -clockid_t clock_id); +extern void ktime_get_snapshot_id (clockid_t clock_id,struct system_time_snapshot *systime_snapshot);/* * Persistent clock related interfaces kernel/time/timekeeping.c +36
-18@@ -320,6 +320,7 @@ static __always_inline u64 tk_clock_read(const struct tk_read_base *tkr) return clock->read(clock); } +static inline void clocksource_disable_inline_read (void ) { }static inline void clocksource_enable_inline_read (void ) { }#endif @@ -1187,14 +1188,26 @@ noinstr time64_t __ktime_get_real_seconds(void)return tk->xtime_sec; } +static inline u64 tk_clock_read_snapshot (const struct tk_read_base *tkr, +struct clocksource_hw_snapshot *chs) +{ +struct clocksource *clock =READ_ONCE (tkr->clock); + +if (unlikely (clock->read_snapshot)) +return clock->read_snapshot (clock, chs); + +return clock->read (clock); +} + +/** * ktime_get_snapshot_id - Simultaneously snapshot a given clock ID with * CLOCK_MONOTONIC_RAW and the underlying * clocksource counter value. -* @systime_snapshot: Pointer to struct receiving the system time snapshot * @clock_id: The clock ID to snapshot +* @systime_snapshot: Pointer to struct receiving the system time snapshot */ -bool ktime_get_snapshot_id (struct system_time_snapshot *systime_snapshot,clockid_t clock_id) +void ktime_get_snapshot_id (clockid_t clock_id,struct system_time_snapshot *systime_snapshot) {ktime_t base_raw, base_sys, offs_sys, *offs, offs_zero =0 ;u64 nsec_raw, nsec_sys, now;@@ -1206,7 +1219,7 @@ bool ktime_get_snapshot_id(struct system_time_snapshot *systime_snapshot, clocki systime_snapshot->valid = false;if (WARN_ON_ONCE (timekeeping_suspended)) -return false; +return ;switch (clock_id) {case CLOCK_REALTIME :@@ -1226,25 +1239,31 @@ bool ktime_get_snapshot_id(struct system_time_snapshot *systime_snapshot, clocki case CLOCK_AUX ... CLOCK_AUX_LAST: tkd =aux_get_tk_data (clock_id);if (!tkd) -return false; +return ; offs = &tkd->timekeeper.offs_aux;break ;default :WARN_ON_ONCE (1 ); -return false; +return ; } tk = &tkd->timekeeper; do { + struct clocksource_hw_snapshot chs = { }; + seq = read_seqcount_begin(&tkd->seq); /* Aux clocks can be invalid */ if (!tk->clock_valid) - return false; + return; - now = tk_clock_read(&tk->tkr_mono); + now = tk_clock_read_snapshot(&tk->tkr_mono, &chs); systime_snapshot->cs_id = tk->tkr_mono.clock->id; + + systime_snapshot->hw_cycles = chs.hw_cycles; + systime_snapshot->hw_csid = chs.hw_csid; + systime_snapshot->cs_was_changed_seq = tk->cs_was_changed_seq; systime_snapshot->clock_was_set_seq = tk->clock_was_set_seq;@@ -1257,18 +1276,17 @@ bool ktime_get_snapshot_id(struct system_time_snapshot *systime_snapshot, clocki }while (read_seqcount_retry (&tkd->seq, seq)); systime_snapshot->cycles = now; - systime_snapshot->sys =ktime_add_ns (base_sys, offs_sys + nsec_sys); - systime_snapshot->raw =ktime_add_ns (base_raw, nsec_raw); + systime_snapshot->systime =ktime_add_ns (base_sys, offs_sys + nsec_sys); + systime_snapshot->monoraw =ktime_add_ns (base_raw, nsec_raw);/* * Special case for PTP. Just transfer the raw time into sys, -* so the call sites can consistently use snap::sys. +* so the call sites can consistently use snap::systime. */ if (clock_id ==CLOCK_MONOTONIC_RAW ) - systime_snapshot->sys = systime_snapshot->raw; + systime_snapshot->systime = systime_snapshot->monoraw;/* Tell the consumer that this snapshot is valid */ systime_snapshot->valid = true; -return true; }EXPORT_SYMBOL_GPL (ktime_get_snapshot_id);@@ -1330,7 +1348,7 @@ static int adjust_historical_crosststamp(struct system_time_snapshot *history,* Scale the monotonic raw time delta by: * partial_history_cycles / total_history_cycles */ - corr_raw = (u64 )ktime_to_ns (ktime_sub (ts->sys_monoraw, history->raw)); + corr_raw = (u64 )ktime_to_ns (ktime_sub (ts->sys_monoraw, history->monoraw)); ret =scale64_check_overflow (partial_history_cycles, total_history_cycles, &corr_raw);if (ret)@@ -1347,7 +1365,7 @@ static int adjust_historical_crosststamp(struct system_time_snapshot *history,if (discontinuity) { corr_sys =mul_u64_u32_div (corr_raw, tk->tkr_mono.mult, tk->tkr_raw.mult); }else { - corr_sys = (u64 )ktime_to_ns (ktime_sub (ts->sys_systime, history->sys)); + corr_sys = (u64 )ktime_to_ns (ktime_sub (ts->sys_systime, history->systime)); ret =scale64_check_overflow (partial_history_cycles, total_history_cycles, &corr_sys);if (ret)@@ -1356,8 +1374,8 @@ static int adjust_historical_crosststamp(struct system_time_snapshot *history,/* Fixup monotonic raw and system time time values */ if (interp_forward) { - ts->sys_monoraw =ktime_add_ns (history->raw, corr_raw); - ts->sys_systime =ktime_add_ns (history->sys, corr_sys); + ts->sys_monoraw =ktime_add_ns (history->monoraw, corr_raw); + ts->sys_systime =ktime_add_ns (history->systime, corr_sys); }else { ts->sys_monoraw =ktime_sub_ns (ts->sys_monoraw, corr_raw); ts->sys_systime =ktime_sub_ns (ts->sys_systime, corr_sys);@@ -1521,12 +1539,12 @@ int get_device_system_crosststamp(int (*get_time_fn) case CLOCK_AUX ... CLOCK_AUX_LAST: tkd =aux_get_tk_data (xtstamp->clock_id);if (!tkd) -return false; +return -ENODEV ; offs = &tkd->timekeeper.offs_aux;break ;default :WARN_ON_ONCE (1 ); -return false; +return -ENODEV ; } tk = &tkd->timekeeper;