Pull timekeeping updates from Thomas Gleixner: "Updates for NTP/timekeeping and PTP: - Expand timekeeping snapshot mechanisms The various snapshot functions are mostly used for PTP to collect "atomic" snapshots of various involved clocks. They lack support for the recently introduced AUX clocks and do not provide the underlying counter value (e.g. TSC) to user space. Exposing the counter value snapshot allows for better control and steering. Convert the hard wired ktime_get_snapshot() to take a clock ID, which allows the caller to select the clock ID to be captured along with CLOCK_MONONOTONIC_RAW. Additionally capture the underlying hardware counter value and the clock source ID of the counter. Expand the hardware based snapshot capture where devices provide a mechanism to snapshot the hardware PTP clock and the system counter (usually via PCI/PTM) to support AUX clocks and also provide the captured counter value back to the caller and not only the clock timestamps derived from it. - Add a new optional read_snapshot() callback to clocksources That is required to capture atomic snapshots from clocksources which are derived from TSC with a scaling mechanism (e.g. Hyper-V, KVMclock). The value pair is handed back in the snapshot structure to the callers, so they can do the necessary correlations in a more precise way. This touches usage sites of the affected functions and data structure all over the tree, but stays fully backwards compatible for the existing user space exposed interfaces. New PTP IOCTLs will provide access to the extended functionality in later kernel versions" * tag 'timers-ptp-2026-06-13' of gitolite.kernel.org:pub/scm/linux/kernel/git/tip/tip: (28 commits) ptp: vmclock: Use hw_cycles from snapshot for precise TSC pairing x86/kvmclock: Implement read_snapshot() for kvmclock clocksource clocksource/hyperv: Implement read_snapshot() for TSC page clocksource timekeeping: Add clocksource read_snapshot() method and hw_cycles to snapshot ptp: Switch to ktime_get_snapshot_id() for pre/post timestamps timekeeping: Add support for AUX clock cross timestamping timekeeping: Remove system_device_crosststamp::sys_realtime ALSA: hda/common: Use system_device_crosststamp::sys_systime wifi: iwlwifi: Use system_device_crosststamp::sys_systime ptp: Use system_device_crosststamp::sys_systime timekeeping: Prepare for cross timestamps on arbitrary clock IDs timekeeping: Remove ktime_get_snapshot() virtio_rtc: Use provided clock ID for history snapshot net/mlx5: Use provided clock ID for history snapshot igc: Use provided clock ID for history snapshot ice/ptp: Use provided clock ID for history snapshot wifi: iwlwifi: Adopt PTP cross timestamps to core changes timekeeping: Add CLOCK ID to system_device_crosststamp timekeeping: Add system_counterval_t to struct system_device_crosststamp timekeeping: Add CLOCK_AUX support for ktime_get_snapshot_id() ...
Showing the changes to include (4 of 23 files). Show all
Unified · Split
| @@ -31,6 +31,21 @@ struct module; · 30 unmodified lines | |||
| 31 | 31 | ||
| 32 | #include <vdso/clocksource.h> | 32 | #include <vdso/clocksource.h> |
| 33 | 33 | ||
| 34 | /** | ||
| 35 | * struct clocksource_hw_snapshot - Snapshot for the underlying hardware counter of derived | ||
| 36 | * clocksources like kvmclock or Hyper-V scaled TSC | ||
| 37 | * @hw_cycles: The hardware counter value | ||
| 38 | * @hw_csid: Clocksource ID of the hardware counter | ||
| 39 | * | ||
| 40 | * Such clocksources must implement the read_snapshot() callback and fill in the | ||
| 41 | * hardware counter value, the clocksource ID of the hardware counter and derive | ||
| 42 | * the actual clocksource cycles from @hw_cycles to provide an atomic snapshot | ||
| 43 | */ | ||
| 44 | struct clocksource_hw_snapshot { | ||
| 45 | u64 hw_cycles; | ||
| 46 | enum clocksource_ids hw_csid; | ||
| 47 | }; | ||
| 48 | |||
| 34 | /** | 49 | /** |
| 35 | * struct clocksource - hardware abstraction for a free running counter | 50 | * struct clocksource - hardware abstraction for a free running counter |
| 36 | * Provides mostly state-free accessors to the underlying hardware. | 51 | * Provides mostly state-free accessors to the underlying hardware. |
| @@ -72,6 +87,14 @@ struct module; · 35 unmodified lines | |||
| 72 | * @flags: Flags describing special properties | 87 | * @flags: Flags describing special properties |
| 73 | * @base: Hardware abstraction for clock on which a clocksource | 88 | * @base: Hardware abstraction for clock on which a clocksource |
| 74 | * is based | 89 | * is based |
| 90 | * @read_snapshot: Extended @read() function for clocksources such as | ||
| 91 | * kvmclock or the Hyper-V scaled TSC where the actual | ||
| 92 | * clocksource value for timekeeping is calculated from an | ||
| 93 | * underlying hardware counter. Returns the timekeeping | ||
| 94 | * relevant cycle value and stores the raw value of the | ||
| 95 | * underlying counter from which it was calculated | ||
| 96 | * including the clocksource ID of that counter in the | ||
| 97 | * clocksource hardware snapshot. | ||
| 75 | * @enable: Optional function to enable the clocksource | 98 | * @enable: Optional function to enable the clocksource |
| 76 | * @disable: Optional function to disable the clocksource | 99 | * @disable: Optional function to disable the clocksource |
| 77 | * @suspend: Optional suspend function for the clocksource | 100 | * @suspend: Optional suspend function for the clocksource |
| @@ -113,6 +136,7 @@ struct clocksource { · 35 unmodified lines | |||
| 113 | unsigned long flags; | 136 | unsigned long flags; |
| 114 | struct clocksource_base *base; | 137 | struct clocksource_base *base; |
| 115 | 138 | ||
| 139 | u64 (*read_snapshot)(struct clocksource *cs, struct clocksource_hw_snapshot *chs); | ||
| 116 | int (*enable)(struct clocksource *cs); | 140 | int (*enable)(struct clocksource *cs); |
| 117 | void (*disable)(struct clocksource *cs); | 141 | void (*disable)(struct clocksource *cs); |
| 118 | void (*suspend)(struct clocksource *cs); | 142 | void (*suspend)(struct clocksource *cs); |
| @@ -99,12 +99,14 @@ static inline void timespec_to_pps_ktime(struct pps_ktime *kt, · 98 unmodified lines | |||
| 99 | 99 | ||
| 100 | static inline void pps_get_ts(struct pps_event_time *ts) | 100 | static inline void pps_get_ts(struct pps_event_time *ts) |
| 101 | { | 101 | { |
| 102 | #ifdef CONFIG_NTP_PPS | ||
| 102 | struct system_time_snapshot snap; | 103 | struct system_time_snapshot snap; |
| 103 | 104 | ||
| 104 | ktime_get_snapshot(&snap); | 105 | ktime_get_snapshot_id(CLOCK_REALTIME, &snap); |
| 105 | ts->ts_real = ktime_to_timespec64(snap.real); | 106 | ts->ts_real = ktime_to_timespec64(snap.systime); |
| 106 | #ifdef CONFIG_NTP_PPS | 107 | ts->ts_raw = ktime_to_timespec64(snap.monoraw); |
| 107 | ts->ts_raw = ktime_to_timespec64(snap.raw); | 108 | #else |
| 109 | ktime_get_real_ts64(&ts->ts_real); | ||
| 108 | #endif | 110 | #endif |
| 109 | } | 111 | } |
| 110 | 112 | ||
| @@ -12,6 +12,7 @@ · 11 unmodified lines | |||
| 12 | #include <linux/pps_kernel.h> | 12 | #include <linux/pps_kernel.h> |
| 13 | #include <linux/ptp_clock.h> | 13 | #include <linux/ptp_clock.h> |
| 14 | #include <linux/timecounter.h> | 14 | #include <linux/timecounter.h> |
| 15 | #include <linux/timekeeping.h> | ||
| 15 | #include <linux/skbuff.h> | 16 | #include <linux/skbuff.h> |
| 16 | 17 | ||
| 17 | #define PTP_CLOCK_NAME_LEN 32 | 18 | #define PTP_CLOCK_NAME_LEN 32 |
| @@ -45,13 +46,13 @@ struct system_device_crosststamp; · 27 unmodified lines | |||
| 45 | 46 | ||
| 46 | /** | 47 | /** |
| 47 | * struct ptp_system_timestamp - system time corresponding to a PHC timestamp | 48 | * struct ptp_system_timestamp - system time corresponding to a PHC timestamp |
| 48 | * @pre_ts: system timestamp before capturing PHC | 49 | * @pre_sts: system time snapshot before capturing PHC |
| 49 | * @post_ts: system timestamp after capturing PHC | 50 | * @post_sts: system time snapshot after capturing PHC |
| 50 | * @clockid: clock-base used for capturing the system timestamps | 51 | * @clockid: clock-base used for capturing the system timestamps |
| 51 | */ | 52 | */ |
| 52 | struct ptp_system_timestamp { | 53 | struct ptp_system_timestamp { |
| 53 | struct timespec64 pre_ts; | 54 | struct system_time_snapshot pre_sts; |
| 54 | struct timespec64 post_ts; | 55 | struct system_time_snapshot post_sts; |
| 55 | clockid_t clockid; | 56 | clockid_t clockid; |
| 56 | }; | 57 | }; |
| 57 | 58 | ||
| @@ -510,13 +511,13 @@ static inline ktime_t ptp_convert_timestamp(const ktime_t *hwtstamp, · 452 unmodified lines | |||
| 510 | static inline void ptp_read_system_prets(struct ptp_system_timestamp *sts) | 511 | static inline void ptp_read_system_prets(struct ptp_system_timestamp *sts) |
| 511 | { | 512 | { |
| 512 | if (sts) | 513 | if (sts) |
| 513 | ktime_get_clock_ts64(sts->clockid, &sts->pre_ts); | 514 | ktime_get_snapshot_id(sts->clockid, &sts->pre_sts); |
| 514 | } | 515 | } |
| 515 | 516 | ||
| 516 | static inline void ptp_read_system_postts(struct ptp_system_timestamp *sts) | 517 | static inline void ptp_read_system_postts(struct ptp_system_timestamp *sts) |
| 517 | { | 518 | { |
| 518 | if (sts) | 519 | if (sts) |
| 519 | ktime_get_clock_ts64(sts->clockid, &sts->post_ts); | 520 | ktime_get_snapshot_id(sts->clockid, &sts->post_sts); |
| 520 | } | 521 | } |
| 521 | 522 | ||
| 522 | #endif | 523 | #endif |
| @@ -276,37 +276,30 @@ static inline bool ktime_get_aux_ts64(clockid_t id, struct timespec64 *kt) { ret · 275 unmodified lines | |||
| 276 | #endif | 276 | #endif |
| 277 | 277 | ||
| 278 | /** | 278 | /** |
| 279 | * struct system_time_snapshot - simultaneous raw/real time capture with | 279 | * struct system_time_snapshot - Simultaneous time capture of CLOCK_MONOTONIC_RAW, |
| 280 | * counter value | 280 | * a selected CLOCK_* and the clocksource counter value |
| 281 | * @cycles: Clocksource counter value to produce the system times | 281 | * @cycles: Clocksource counter value to produce the system times |
| 282 | * @real: Realtime system time | 282 | * @hw_cycles: For derived clocksources, the hardware counter value from |
| 283 | * @boot: Boot time | 283 | * which @cycles was derived |
| 284 | * @raw: Monotonic raw system time | 284 | * @systime: The system time of the selected CLOCK ID |
| 285 | * @cs_id: Clocksource ID | 285 | * @monoraw: Monotonic raw system time |
| 286 | * @cs_id: Clocksource ID | ||
| 287 | * @hw_csid: Clocksource ID of the underlying hardware counter for derived | ||
| 288 | * clocksources which implement the read_snapshot() callback. | ||
| 286 | * @clock_was_set_seq: The sequence number of clock-was-set events | 289 | * @clock_was_set_seq: The sequence number of clock-was-set events |
| 287 | * @cs_was_changed_seq: The sequence number of clocksource change events | 290 | * @cs_was_changed_seq: The sequence number of clocksource change events |
| 291 | * @valid: True if the snapshot is valid | ||
| 288 | */ | 292 | */ |
| 289 | struct system_time_snapshot { | 293 | struct system_time_snapshot { |
| 290 | u64 cycles; | 294 | u64 cycles; |
| 291 | ktime_t real; | 295 | u64 hw_cycles; |
| 292 | ktime_t boot; | 296 | ktime_t systime; |
| 293 | ktime_t raw; | 297 | ktime_t monoraw; |
| 294 | enum clocksource_ids cs_id; | 298 | enum clocksource_ids cs_id; |
| 299 | enum clocksource_ids hw_csid; | ||
| 295 | unsigned int clock_was_set_seq; | 300 | unsigned int clock_was_set_seq; |
| 296 | u8 cs_was_changed_seq; | 301 | u8 cs_was_changed_seq; |
| 297 | }; | 302 | u8 valid; |
| 298 | |||
| 299 | /** | ||
| 300 | * struct system_device_crosststamp - system/device cross-timestamp | ||
| 301 | * (synchronized capture) | ||
| 302 | * @device: Device time | ||
| 303 | * @sys_realtime: Realtime simultaneous with device time | ||
| 304 | * @sys_monoraw: Monotonic raw simultaneous with device time | ||
| 305 | */ | ||
| 306 | struct system_device_crosststamp { | ||
| 307 | ktime_t device; | ||
| 308 | ktime_t sys_realtime; | ||
| 309 | ktime_t sys_monoraw; | ||
| 310 | }; | 303 | }; |
| 311 | 304 | ||
| 312 | /** | 305 | /** |
| @@ -325,6 +318,23 @@ struct system_counterval_t { · 12 unmodified lines | |||
| 325 | bool use_nsecs; | 318 | bool use_nsecs; |
| 326 | }; | 319 | }; |
| 327 | 320 | ||
| 321 | /** | ||
| 322 | * struct system_device_crosststamp - system/device cross-timestamp | ||
| 323 | * (synchronized capture) | ||
| 324 | * @clock_id: System time Clock ID to capture | ||
| 325 | * @device: Device time | ||
| 326 | * @sys_counter: Clocksource counter value simultaneous with device time | ||
| 327 | * @sys_systime: System time for @clock_id | ||
| 328 | * @sys_monoraw: Monotonic raw simultaneous with device time | ||
| 329 | */ | ||
| 330 | struct system_device_crosststamp { | ||
| 331 | clockid_t clock_id; | ||
| 332 | ktime_t device; | ||
| 333 | struct system_counterval_t sys_counter; | ||
| 334 | ktime_t sys_systime; | ||
| 335 | ktime_t sys_monoraw; | ||
| 336 | }; | ||
| 337 | |||
| 328 | extern bool ktime_real_to_base_clock(ktime_t treal, | 338 | extern bool ktime_real_to_base_clock(ktime_t treal, |
| 329 | enum clocksource_ids base_id, u64 *cycles); | 339 | enum clocksource_ids base_id, u64 *cycles); |
| 330 | extern bool timekeeping_clocksource_has_base(enum clocksource_ids id); | 340 | extern bool timekeeping_clocksource_has_base(enum clocksource_ids id); |
| @@ -341,9 +351,10 @@ extern int get_device_system_crosststamp( · 10 unmodified lines | |||
| 341 | struct system_device_crosststamp *xtstamp); | 351 | struct system_device_crosststamp *xtstamp); |
| 342 | 352 | ||
| 343 | /* | 353 | /* |
| 344 | * Simultaneously snapshot realtime and monotonic raw clocks | 354 | * Simultaneously snapshot a given clock with MONOTONIC_RAW and the underlying |
| 355 | * clocksource counter value. | ||
| 345 | */ | 356 | */ |
| 346 | extern void ktime_get_snapshot(struct system_time_snapshot *systime_snapshot); | 357 | extern void ktime_get_snapshot_id(clockid_t clock_id, struct system_time_snapshot *systime_snapshot); |
| 347 | 358 | ||
| 348 | /* | 359 | /* |
| 349 | * Persistent clock related interfaces | 360 | * Persistent clock related interfaces |