History

Merge tag 'timers-ptp-2026-06-13' of gitolite.kernel.org:pub/scm/linux/kernel/git/tip/tip

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() ...

Linus Torvalds committed 5 months ago

Commit 2d6d57f2 parents a53fcff bc484a523 files · +348 −194Browse files

Showing the changes to include (4 of 23 files). Show all

Unified · Split

4 files
  1. include/linux/clocksource.h +24 −0
  2. include/linux/pps_kernel.h +6 −4
  3. include/linux/ptp_clock_kernel.h +8 −7
  4. include/linux/timekeeping.h +36 −25
include/linux/clocksource.h+24−0
@@ -31,6 +31,21 @@ struct module; · 30 unmodified lines
3131
3232 #include <vdso/clocksource.h>
3333
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+
3449 /**
3550 * struct clocksource - hardware abstraction for a free running counter
3651 * Provides mostly state-free accessors to the underlying hardware.
@@ -72,6 +87,14 @@ struct module; · 35 unmodified lines
7287 * @flags: Flags describing special properties
7388 * @base: Hardware abstraction for clock on which a clocksource
7489 * 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.
7598 * @enable: Optional function to enable the clocksource
7699 * @disable: Optional function to disable the clocksource
77100 * @suspend: Optional suspend function for the clocksource
@@ -113,6 +136,7 @@ struct clocksource { · 35 unmodified lines
113136 unsigned long flags;
114137 struct clocksource_base *base;
115138
139+ u64 (*read_snapshot)(struct clocksource *cs, struct clocksource_hw_snapshot *chs);
116140 int (*enable)(struct clocksource *cs);
117141 void (*disable)(struct clocksource *cs);
118142 void (*suspend)(struct clocksource *cs);
include/linux/pps_kernel.h+6−4
@@ -99,12 +99,14 @@ static inline void timespec_to_pps_ktime(struct pps_ktime *kt, · 98 unmodified lines
9999
100100 static inline void pps_get_ts(struct pps_event_time *ts)
101101 {
102+#ifdef CONFIG_NTP_PPS
102103 struct system_time_snapshot snap;
103104
104− ktime_get_snapshot(&snap);
105− ts->ts_real = ktime_to_timespec64(snap.real);
106−#ifdef CONFIG_NTP_PPS
107− ts->ts_raw = ktime_to_timespec64(snap.raw);
105+ ktime_get_snapshot_id(CLOCK_REALTIME, &snap);
106+ ts->ts_real = ktime_to_timespec64(snap.systime);
107+ ts->ts_raw = ktime_to_timespec64(snap.monoraw);
108+#else
109+ ktime_get_real_ts64(&ts->ts_real);
108110 #endif
109111 }
110112
include/linux/ptp_clock_kernel.h+8−7
@@ -12,6 +12,7 @@ · 11 unmodified lines
1212 #include <linux/pps_kernel.h>
1313 #include <linux/ptp_clock.h>
1414 #include <linux/timecounter.h>
15+#include <linux/timekeeping.h>
1516 #include <linux/skbuff.h>
1617
1718 #define PTP_CLOCK_NAME_LEN 32
@@ -45,13 +46,13 @@ struct system_device_crosststamp; · 27 unmodified lines
4546
4647 /**
4748 * struct ptp_system_timestamp - system time corresponding to a PHC timestamp
48− * @pre_ts: system timestamp before capturing PHC
49− * @post_ts: system timestamp after capturing PHC
50− * @clockid: clock-base used for capturing the system timestamps
49+ * @pre_sts: system time snapshot before capturing PHC
50+ * @post_sts: system time snapshot after capturing PHC
51+ * @clockid: clock-base used for capturing the system timestamps
5152 */
5253 struct ptp_system_timestamp {
53− struct timespec64 pre_ts;
54− struct timespec64 post_ts;
54+ struct system_time_snapshot pre_sts;
55+ struct system_time_snapshot post_sts;
5556 clockid_t clockid;
5657 };
5758
@@ -510,13 +511,13 @@ static inline ktime_t ptp_convert_timestamp(const ktime_t *hwtstamp, · 452 unmodified lines
510511 static inline void ptp_read_system_prets(struct ptp_system_timestamp *sts)
511512 {
512513 if (sts)
513− ktime_get_clock_ts64(sts->clockid, &sts->pre_ts);
514+ ktime_get_snapshot_id(sts->clockid, &sts->pre_sts);
514515 }
515516
516517 static inline void ptp_read_system_postts(struct ptp_system_timestamp *sts)
517518 {
518519 if (sts)
519− ktime_get_clock_ts64(sts->clockid, &sts->post_ts);
520+ ktime_get_snapshot_id(sts->clockid, &sts->post_sts);
520521 }
521522
522523 #endif
include/linux/timekeeping.h+36−25
@@ -276,37 +276,30 @@ static inline bool ktime_get_aux_ts64(clockid_t id, struct timespec64 *kt) { ret · 275 unmodified lines
276276 #endif
277277
278278 /**
279− * struct system_time_snapshot - simultaneous raw/real time capture with
280− * counter value
281− * @cycles: Clocksource counter value to produce the system times
282− * @real: Realtime system time
283− * @boot: Boot time
284− * @raw: Monotonic raw system time
285− * @cs_id: Clocksource ID
279+ * struct system_time_snapshot - Simultaneous time capture of CLOCK_MONOTONIC_RAW,
280+ * a selected CLOCK_* and the clocksource counter value
281+ * @cycles: Clocksource counter value to produce the system times
282+ * @hw_cycles: For derived clocksources, the hardware counter value from
283+ * which @cycles was derived
284+ * @systime: The system time of the selected CLOCK 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.
286289 * @clock_was_set_seq: The sequence number of clock-was-set events
287290 * @cs_was_changed_seq: The sequence number of clocksource change events
291+ * @valid: True if the snapshot is valid
288292 */
289293 struct system_time_snapshot {
290294 u64 cycles;
291− ktime_t real;
292− ktime_t boot;
293− ktime_t raw;
295+ u64 hw_cycles;
296+ ktime_t systime;
297+ ktime_t monoraw;
294298 enum clocksource_ids cs_id;
299+ enum clocksource_ids hw_csid;
295300 unsigned int clock_was_set_seq;
296301 u8 cs_was_changed_seq;
297−};
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;
302+ u8 valid;
310303 };
311304
312305 /**
@@ -325,6 +318,23 @@ struct system_counterval_t { · 12 unmodified lines
325318 bool use_nsecs;
326319 };
327320
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+
328338 extern bool ktime_real_to_base_clock(ktime_t treal,
329339 enum clocksource_ids base_id, u64 *cycles);
330340 extern bool timekeeping_clocksource_has_base(enum clocksource_ids id);
@@ -341,9 +351,10 @@ extern int get_device_system_crosststamp( · 10 unmodified lines
341351 struct system_device_crosststamp *xtstamp);
342352
343353 /*
344− * Simultaneously snapshot realtime and monotonic raw clocks
354+ * Simultaneously snapshot a given clock with MONOTONIC_RAW and the underlying
355+ * clocksource counter value.
345356 */
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);
347358
348359 /*
349360 * Persistent clock related interfaces

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t