Skip to contentSkip to conversation

timekeeping/ptp: Expand snapshot functionality

PATCH Superseded Thomas Gleixner 10 participants 87 messages May 26 – Jul 6

Subsystems (17)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Thomas Gleixner

author maintainer
#0 lore raw

cover timekeeping/ptp: Expand snapshot functionality

Sorry for the large CC list, but changing the inner workings touches unfortunately a lot of places in one go.

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

It's 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-v1

Thanks to David for rebasing his PTP/timekeeping work on top and providing feedback, fixes and testing.

Thanks,

tglx

---
 arch/arm64/kvm/hyp_trace.c                          |    8 
 arch/arm64/kvm/hypercalls.c                         |    6 
 drivers/net/dsa/sja1105/sja1105_main.c              |    8 
 drivers/net/ethernet/intel/ice/ice_ptp.c            |    5 
 drivers/net/ethernet/intel/igc/igc.h                |    1 
 drivers/net/ethernet/intel/igc/igc_ptp.c            |    4 
 drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c |    4 
 drivers/net/wireless/intel/iwlwifi/mld/ptp.c        |    5 
 drivers/net/wireless/intel/iwlwifi/mvm/ptp.c        |    7 
 drivers/pps/generators/pps_gen-dummy.c              |    6 
 drivers/pps/generators/pps_gen_tio.c                |    6 
 drivers/ptp/ptp_chardev.c                           |   18 +
 drivers/ptp/ptp_ocp.c                               |   11 -
 drivers/ptp/ptp_vmclock.c                           |   25 --
 drivers/virtio/virtio_rtc_ptp.c                     |    2 
 include/linux/pps_kernel.h                          |    8 
 include/linux/ptp_clock_kernel.h                    |   15 -
 include/linux/timekeeping.h                         |   54 ++---
 kernel/time/timekeeping.c                           |  211 ++++++++++++--------
 sound/hda/common/controller.c                       |    4 
 20 files changed, 236 insertions(+), 172 deletions(-)
author maintainer
#1 lore raw

PATCH 1/24 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::sys, 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.

No functional change vs. current users of ktime_get_snapshot()

---
 include/linux/timekeeping.h |   29 ++++++++++-----
 kernel/time/timekeeping.c   |   84 +++++++++++++++++++++++++++++++++-----------
 2 files changed, 84 insertions(+), 29 deletions(-)
include/linux/timekeeping.h +20 -9
@@ -276,24 +276,28 @@ 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
+ * @sys:		The system time of the selected CLOCK ID
+ * @real:		Realtime system time
+ * @boot:		Boot time
+ * @raw:		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			sys;
 	ktime_t			real;
 	ktime_t			boot;
 	ktime_t			raw;
 	enum clocksource_ids	cs_id;
 	unsigned int		clock_was_set_seq;
 	u8			cs_was_changed_seq;
+	u8			valid;
 };
 
 /**
@@ -341,9 +345,16 @@ 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 bool ktime_get_snapshot_id(struct system_time_snapshot *systime_snapshot,
+				  clockid_t clock_id);
+
+static inline void ktime_get_snapshot(struct system_time_snapshot *systime_snapshot)
+{
+	WARN_ON_ONCE(!ktime_get_snapshot_id(systime_snapshot, CLOCK_REALTIME));
+}
 
 /*
  * Persistent clock related interfaces
kernel/time/timekeeping.c +64 -20

107 lines not on this page · raw message

#2 lore raw

Re: [patch 01/24] timekeeping: Provide ktime_get_snapshot_id()

kernel/time/timekeeping.c noinstr time64_t __ktime_get_real_second · line 1193

Quoted 12 lines · Thomas Gleixner

/**
- * ktime_get_snapshot - snapshots the realtime/monotonic raw clocks with counter
- * @systime_snapshot: pointer to struct receiving the system time snapshot
+ * 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
*/

kernel/time/timekeeping.c +1 -1
-void ktime_get_snapshot(struct system_time_snapshot *systime_snapshot)
+bool ktime_get_snapshot_id(struct system_time_snapshot *systime_snapshot, clockid_t clock_id)
 {

Since this function now returns a bool would it make sense to add a "Return:" comment to the kdoc to help explain what the return value means?

I saw that you have a WARN_ON with the ktime_get_snapshot wrapper. I guess it returns false if timekeeping_suspended.

Quoted 10 lines
kernel/time/timekeeping.c +4 -3
-	struct timekeeper *tk = &tk_core.timekeeper;
+	ktime_t base_raw, base_sys, offs_sys, *offs, offs_zero = 0;
+	u64 nsec_raw, nsec_sys, now;
+	struct timekeeper *tk;
+	struct tk_data *tkd;
 	unsigned int seq;
-	ktime_t base_raw;
 	ktime_t base_real;
 	ktime_t base_boot;
-	u64 nsec_raw;

kernel/time/timekeeping.c noinstr time64_t __ktime_get_real_second · line 1207

Quoted 10 lines
kernel/time/timekeeping.c +6 -3
-	u64 nsec_real;
-	u64 now;
 
-	WARN_ON_ONCE(timekeeping_suspended);
+	/* Invalidate the snapshot for all failure cases */
+	systime_snapshot->valid = false;
+
+	if (WARN_ON_ONCE(timekeeping_suspended))
+		return false;
+

This warns here, and the wrapper ktime_get_snapshot also warns. Does that make sense? I guess eventually the ktime_get_snapshot will be removed?

author maintainer
#3 lore raw

Re: [patch 01/24] timekeeping: Provide ktime_get_snapshot_id()

Quoted 10 lines · Jacob Keller

kernel/time/timekeeping.c noinstr time64_t __ktime_get_real_second · line 1193

Quoted 3 lines · Thomas Gleixner
kernel/time/timekeeping.c +1 -1
-void ktime_get_snapshot(struct system_time_snapshot *systime_snapshot)
+bool ktime_get_snapshot_id(struct system_time_snapshot *systime_snapshot, clockid_t clock_id)
 {

Since this function now returns a bool would it make sense to add a "Return:" comment to the kdoc to help explain what the return value means?

I saw that you have a WARN_ON with the ktime_get_snapshot wrapper. I guess it returns false if timekeeping_suspended.

...

Quoted 2 lines

This warns here, and the wrapper ktime_get_snapshot also warns. Does that make sense? I guess eventually the ktime_get_snapshot will be removed?

No it does not and it's a leftover from an early version. I later switched to have a valid bit in the struct because otherwise I'd need to modify a gazillion call sites to propagate the return value through.

Let me remove it.

Thanks,

tglx

maintainer Reviewed-by Tested-by on v1 1/24
#4 lore raw

Re: [patch 01/24] timekeeping: Provide ktime_get_snapshot_id()

In reply to Thomas Gleixner
Quoted 18 lines · Thomas Gleixner

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::sys, which will replace the system_time_snapshot::real/boot members once all usage sites have been converted.

Quoted 7 lines

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.

No functional change vs. current users of ktime_get_snapshot()

Reviewed-by on v1 1/24
#5 lore raw

Re: [patch 01/24] timekeeping: Provide ktime_get_snapshot_id()

In reply to Thomas Gleixner
Quoted 18 lines · Thomas Gleixner

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::sys, which will replace the system_time_snapshot::real/boot members once all usage sites have been converted.

Quoted 7 lines

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.

No functional change vs. current users of ktime_get_snapshot()

Plus some subjective nitpicks below.

Quoted 44 lines
---
 include/linux/timekeeping.h |   29 ++++++++++-----
 kernel/time/timekeeping.c   |   84 +++++++++++++++++++++++++++++++++-----------
 2 files changed, 84 insertions(+), 29 deletions(-)
include/linux/timekeeping.h +11 -7
@@ -276,24 +276,28 @@ 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
+ * @sys:		The system time of the selected CLOCK ID
+ * @real:		Realtime system time
+ * @boot:		Boot time
+ * @raw:		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			sys;
 	ktime_t			real;
 	ktime_t			boot;
 	ktime_t			raw;
 	enum clocksource_ids	cs_id;
 	unsigned int		clock_was_set_seq;
 	u8			cs_was_changed_seq;
+	u8			valid;
 };
 
 /**

include/linux/timekeeping.h extern int get_device_system_crosststamp · line 352

Quoted 10 lines
include/linux/timekeeping.h +4 -2
@@ -341,9 +345,16 @@ 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 bool ktime_get_snapshot_id(struct system_time_snapshot *systime_snapshot,
+				  clockid_t clock_id);

None of the callers (except the wrapper below, which gets removed later) is checking the return value. Having both the return value and the valid member looks a bit weird, too.

Clockid parameter first for consistency?

Quoted 20 lines
include/linux/timekeeping.h +5 -0
+
+static inline void ktime_get_snapshot(struct system_time_snapshot *systime_snapshot)
+{
+	WARN_ON_ONCE(!ktime_get_snapshot_id(systime_snapshot, CLOCK_REALTIME));
+}
 
 /*
  * Persistent clock related interfaces
kernel/time/timekeeping.c +4 -2
@@ -1183,43 +1183,87 @@ noinstr time64_t __ktime_get_real_second
 }
 
 /**
- * ktime_get_snapshot - snapshots the realtime/monotonic raw clocks with counter
- * @systime_snapshot:	pointer to struct receiving the system time snapshot
+ * 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

kernel/time/timekeeping.c noinstr time64_t __ktime_get_real_second · line 1197

Quoted 10 lines
kernel/time/timekeeping.c +6 -2
+ * @clock_id:		The clock ID to snapshot
  */
-void ktime_get_snapshot(struct system_time_snapshot *systime_snapshot)
+bool ktime_get_snapshot_id(struct system_time_snapshot *systime_snapshot, clockid_t clock_id)
 {
-	struct timekeeper *tk = &tk_core.timekeeper;
+	ktime_t base_raw, base_sys, offs_sys, *offs, offs_zero = 0;
+	u64 nsec_raw, nsec_sys, now;
+	struct timekeeper *tk;
+	struct tk_data *tkd;

This indirection only makes sense with the support for AUX clocks added later.

kernel/time/timekeeping.c noinstr time64_t __ktime_get_real_second · line 1200

Quoted 4 lines
kernel/time/timekeeping.c +0 -1
 	unsigned int seq;
-	ktime_t base_raw;
 	ktime_t base_real;
 	ktime_t base_boot;

The ktime_t variable declarations are weird now.

Quoted 55 lines
kernel/time/timekeeping.c +35 -12
-	u64 nsec_raw;
-	u64 nsec_real;
-	u64 now;
 
-	WARN_ON_ONCE(timekeeping_suspended);
+	/* Invalidate the snapshot for all failure cases */
+	systime_snapshot->valid = false;
+
+	if (WARN_ON_ONCE(timekeeping_suspended))
+		return false;
+
+	switch (clock_id) {
+	case CLOCK_REALTIME:
+		tkd = &tk_core;
+		offs = &tk_core.timekeeper.offs_real;
+		break;
+	/* Map RAW to MONOTONIC so the loop below is trivial */
+	case CLOCK_MONOTONIC_RAW:
+	case CLOCK_MONOTONIC:
+		tkd = &tk_core;
+		offs = &offs_zero;
+		break;
+	case CLOCK_BOOTTIME:
+		tkd = &tk_core;
+		offs = &tk_core.timekeeper.offs_boot;
+		break;
+	default:
+		WARN_ON_ONCE(1);
+		return false;
+	}
+
+	tk = &tkd->timekeeper;
 
 	do {
-		seq = read_seqcount_begin(&tk_core.seq);
+		seq = read_seqcount_begin(&tkd->seq);
+
 		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;
 		systime_snapshot->clock_was_set_seq = tk->clock_was_set_seq;
-		base_real = ktime_add(tk->tkr_mono.base,
-				      tk_core.timekeeper.offs_real);
-		base_boot = ktime_add(tk->tkr_mono.base,
-				      tk_core.timekeeper.offs_boot);
+
+		base_sys = tk->tkr_mono.base;
+		offs_sys = *offs;
 		base_raw = tk->tkr_raw.base;
-		nsec_real = timekeeping_cycles_to_ns(&tk->tkr_mono, now);
-		nsec_raw  = timekeeping_cycles_to_ns(&tk->tkr_raw, now);
-	} while (read_seqcount_retry(&tk_core.seq, seq));
+
+		/* Kept around until the callers are fixed up */
+		base_real = ktime_add(base_sys, tk_core.timekeeper.offs_real);

kernel/time/timekeeping.c noinstr time64_t __ktime_get_real_second · line 1251

Quoted 10 lines
kernel/time/timekeeping.c +6 -2
+		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->real = ktime_add_ns(base_real, nsec_real);
-	systime_snapshot->boot = ktime_add_ns(base_boot, nsec_real);
+	systime_snapshot->sys = ktime_add_ns(base_sys, offs_sys + nsec_sys);

Technically offs_sys is ktime_t and not u64, so would need ktime_add(). (Not that it makes a difference)

Quoted 20 lines
kernel/time/timekeeping.c +13 -1
+	systime_snapshot->real = ktime_add_ns(base_real, nsec_sys);
+	systime_snapshot->boot = ktime_add_ns(base_boot, nsec_sys);
 	systime_snapshot->raw = 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.
+	 */
+	if (clock_id == CLOCK_MONOTONIC_RAW)
+		systime_snapshot->sys = systime_snapshot->raw;
+	/* Tell the consumer that this snapshot is valid */
+	systime_snapshot->valid = true;
+	return true;
 }
-EXPORT_SYMBOL_GPL(ktime_get_snapshot);
+EXPORT_SYMBOL_GPL(ktime_get_snapshot_id);
 
 /* Scale base by mult/div checking for overflow */
 static int scale64_check_overflow(u64 mult, u64 div, u64 *base)
author maintainer
#6 lore raw

PATCH 2/24 timekeeping: Use system_time_snapshot::sys instead of ::real

In reply to Thomas Gleixner

system_time_snapshot::sys 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 'sys' as 'real' is 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 |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/time/timekeeping.c +2 -2
@@ -1342,7 +1342,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->sys));
 		ret = scale64_check_overflow(partial_history_cycles,
 					     total_history_cycles, &corr_real);
 		if (ret)
@@ -1352,7 +1352,7 @@ 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_realtime = ktime_add_ns(history->sys, 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);
maintainer Reviewed-by Tested-by on v1 2/24
#7 lore raw

Re: [PATCH 2/24] timekeeping: Use system_time_snapshot::sys instead of ::real

Quoted 11 lines · Thomas Gleixner

system_time_snapshot::sys 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 'sys' as 'real' is 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.

Reviewed-by on v1 2/24
#8 lore raw

Re: [patch 02/24] timekeeping: Use system_time_snapshot::sys instead of ::real

In reply to Thomas Gleixner
Quoted 11 lines · Thomas Gleixner

system_time_snapshot::sys 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 'sys' as 'real' is 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.

author maintainer
#9 lore raw

PATCH 3/24 pps: generators: Use ktime_get_real_ts64() instead of ktime_get_snapshot()

In reply to Thomas Gleixner

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.

Cc Rodolfo Giometti <[email protected]>
---
 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
 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
 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;
 }
 
maintainer Reviewed-by on v1 3/24
#10 lore raw

Re: [PATCH 3/24] pps: generators: Use ktime_get_real_ts64() instead of ktime_get_snapshot()

Quoted 9 lines · Thomas Gleixner

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.

Reviewed-by on v1 3/24
#11 lore raw

Re: [patch 03/24] pps: generators: Use ktime_get_real_ts64() instead of ktime_get_snapshot()

In reply to Thomas Gleixner
Quoted 10 lines · Thomas Gleixner

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.

Cc Rodolfo Giometti <[email protected]>

These preparation commits could also go to the front of the series.

author maintainer
#12 lore raw

PATCH 4/24 pps: Convert to ktime_get_snapshot_id()

In reply to Thomas Gleixner

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::sys field instead of snapshot::real, which is going away.

Similar to the PPS generators, avoid the more expensive snapshot when CONFIG_NTP_PPS is disabled.

No functional change intended.

Cc Rodolfo Giometti <[email protected]>
---
 include/linux/pps_kernel.h |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
include/linux/pps_kernel.h +5 -3
@@ -99,12 +99,14 @@ static inline void timespec_to_pps_ktime
 
 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
+	ktime_get_snapshot_id(&snap, CLOCK_REALTIME);
+	ts->ts_real = ktime_to_timespec64(snap.sys);
 	ts->ts_raw = ktime_to_timespec64(snap.raw);
+#else
+	ktime_get_real_ts64(&ts->ts_real);
 #endif
 }
 
maintainer Reviewed-by on v1 4/24
#13 lore raw

Re: [PATCH 4/24] pps: Convert to ktime_get_snapshot_id()

Quoted 11 lines · Thomas Gleixner

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::sys field instead of snapshot::real, which is going away.

Similar to the PPS generators, avoid the more expensive snapshot when CONFIG_NTP_PPS is disabled.

No functional change intended.

Reviewed-by on v1 4/24
#14 lore raw

Re: [patch 04/24] pps: Convert to ktime_get_snapshot_id()

In reply to Thomas Gleixner
Quoted 5 lines · Thomas Gleixner

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::sys field instead of snapshot::real, which is going away.

Quoted 7 lines

Similar to the PPS generators, avoid the more expensive snapshot when CONFIG_NTP_PPS is disabled.

No functional change intended.

Cc Rodolfo Giometti <[email protected]>

include/linux/pps_kernel.h static inline void timespec_to_pps_ktime · line 102

Quoted 11 lines
---
 include/linux/pps_kernel.h |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
include/linux/pps_kernel.h +1 -0
@@ -99,12 +99,14 @@ static inline void timespec_to_pps_ktime
 
 static inline void pps_get_ts(struct pps_event_time *ts)
 {
+#ifdef CONFIG_NTP_PPS

IS_ENABLED()?

Quoted 14 lines
include/linux/pps_kernel.h +4 -3
 	struct system_time_snapshot snap;
 
-	ktime_get_snapshot(&snap);
-	ts->ts_real = ktime_to_timespec64(snap.real);
-#ifdef CONFIG_NTP_PPS
+	ktime_get_snapshot_id(&snap, CLOCK_REALTIME);
+	ts->ts_real = ktime_to_timespec64(snap.sys);
 	ts->ts_raw = ktime_to_timespec64(snap.raw);
+#else
+	ktime_get_real_ts64(&ts->ts_real);
 #endif
 }
 
author maintainer
#15 lore raw

Re: [patch 04/24] pps: Convert to ktime_get_snapshot_id()

Quoted 6 lines · Thomas Weißschuh
Quoted 3 lines · Thomas Gleixner

static inline void pps_get_ts(struct pps_event_time *ts) {
+#ifdef CONFIG_NTP_PPS

IS_ENABLED()?

ts->ts_raw is #ifdeffed out then, which would make the build fail :(

author maintainer
#16 lore raw

PATCH 5/24 KVM: arm64: Use ktime_get_snapshot_id() to retrieve CLOCK_BOOTTIME

In reply to Thomas Gleixner

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::sys field, which holds the system timestamp selected by the CLOCK ID argument.

No functional change intended.

Cc Vincent Donnefort <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Oliver Upton <[email protected]>
---
 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(&snap, CLOCK_BOOTTIME);
+	boot = ktime_to_ns(snap.sys);
 
 	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.sys);
 	hyp_clock->cycles = snap.cycles;
 	hyp_clock->mult = 0;
 
maintainer Reviewed-by on v1 5/24
#17 lore raw

Re: [PATCH 5/24] KVM: arm64: Use ktime_get_snapshot_id() to retrieve CLOCK_BOOTTIME

Quoted 11 lines · Thomas Gleixner

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::sys field, which holds the system timestamp selected by the CLOCK ID argument.

No functional change intended.

Reviewed-by on v1 5/24
#18 lore raw

Re: [patch 05/24] KVM: arm64: Use ktime_get_snapshot_id() to retrieve CLOCK_BOOTTIME

In reply to Thomas Gleixner
Quoted 8 lines · Thomas Gleixner

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::sys field, which holds the system timestamp selected by the CLOCK ID argument.

Quoted 7 lines

No functional change intended.

Cc Vincent Donnefort <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Oliver Upton <[email protected]>
maintainer Acked-by on v1 5/24
#19 lore raw

Re: [patch 05/24] KVM: arm64: Use ktime_get_snapshot_id() to retrieve CLOCK_BOOTTIME

In reply to Thomas Gleixner
Quoted 11 lines · Thomas Gleixner

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::sys field, which holds the system timestamp selected by the CLOCK ID argument.

No functional change intended.

Quoted 8 lines
Cc Vincent Donnefort <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Oliver Upton <[email protected]>
---
 arch/arm64/kvm/hyp_trace.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Acked-by on v1 5/24
#20 lore raw

Re: [patch 05/24] KVM: arm64: Use ktime_get_snapshot_id() to retrieve CLOCK_BOOTTIME

In reply to Thomas Gleixner
Quoted 8 lines · Thomas Gleixner

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::sys field, which holds the system timestamp selected by the CLOCK ID argument.

Quoted 7 lines

No functional change intended.

Cc Vincent Donnefort <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Oliver Upton <[email protected]>
Quoted 30 lines
---
 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(&snap, CLOCK_BOOTTIME);
+	boot = ktime_to_ns(snap.sys);
 
 	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.sys);
 	hyp_clock->cycles = snap.cycles;
 	hyp_clock->mult = 0;
 
author maintainer
#21 lore raw

PATCH 6/24 KVM: arm64: Use ktime_get_snapshot_id() to snapshot CLOCK_REALTIME

In reply to Thomas Gleixner

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::sys 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(&systime_snapshot, CLOCK_REALTIME);
 
 	/*
 	 * 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.sys);
+	val[1] = lower_32_bits(systime_snapshot.sys);
 	val[2] = upper_32_bits(cycles);
 	val[3] = lower_32_bits(cycles);
 }
maintainer Reviewed-by on v1 6/24
#22 lore raw

Re: [PATCH 6/24] KVM: arm64: Use ktime_get_snapshot_id() to snapshot CLOCK_REALTIME

Quoted 11 lines · Thomas Gleixner

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::sys field, which holds the system timestamp selected by the CLOCK ID argument.

No functional change intended.

Reviewed-by on v1 6/24
#23 lore raw

Re: [patch 06/24] KVM: arm64: Use ktime_get_snapshot_id() to snapshot CLOCK_REALTIME

In reply to Thomas Gleixner
Quoted 8 lines · Thomas Gleixner

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::sys field, which holds the system timestamp selected by the CLOCK ID argument.

Quoted 6 lines

No functional change intended.

maintainer Acked-by on v1 6/24
#24 lore raw

Re: [patch 06/24] KVM: arm64: Use ktime_get_snapshot_id() to snapshot CLOCK_REALTIME

In reply to Thomas Gleixner
Quoted 11 lines · Thomas Gleixner

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::sys field, which holds the system timestamp selected by the CLOCK ID argument.

No functional change intended.

Quoted 7 lines
---
 arch/arm64/kvm/hypercalls.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
author maintainer
#25 lore raw

PATCH 7/24 ptp: ptp_vmclock: Convert to ktime_get_snapshot_id()

In reply to Thomas Gleixner

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::sys 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(&systime_snapshot, CLOCK_REALTIME);
 			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.sys);
 		if (systime_snapshot.cs_id == st->cs_id)
 			sts->post_ts = sts->pre_ts;
 	}
@@ -272,7 +272,7 @@ static int ptp_vmclock_getcrosststamp(st
 	if (ret == -ENODEV) {
 		struct system_time_snapshot systime_snapshot;
 
-		ktime_get_snapshot(&systime_snapshot);
+		ktime_get_snapshot_id(&systime_snapshot, CLOCK_REALTIME);
 
 		if (systime_snapshot.cs_id == CSID_X86_TSC ||
 		    systime_snapshot.cs_id == CSID_X86_KVM_CLK) {
maintainer Reviewed-by Tested-by on v1 7/24
#26 lore raw

Re: [PATCH 7/24] ptp: ptp_vmclock: Convert to ktime_get_snapshot_id()

Quoted 10 lines · Thomas Gleixner

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::sys field, which holds the system timestamp selected by the CLOCK ID argument.

No functional change intended.

Reviewed-by on v1 7/24
#27 lore raw

Re: [patch 07/24] ptp: ptp_vmclock: Convert to ktime_get_snapshot_id()

In reply to Thomas Gleixner
Quoted 4 lines · Thomas Gleixner

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.

Quoted 8 lines

Convert vmclock over and use the new system_time_snapshot::sys field, which holds the system timestamp selected by the CLOCK ID argument.

No functional change intended.

author maintainer
#28 lore raw

PATCH 8/24 timekeeping: Remove system_time_snapshot::real/boot

In reply to Thomas Gleixner

All users are converted over to ktime_get_snapshot_id() and system_time_snapshot::sys.

Remove the leftovers.

---
 include/linux/timekeeping.h |    4 ----
 kernel/time/timekeeping.c   |    8 --------
 2 files changed, 12 deletions(-)
include/linux/timekeeping.h +0 -4
@@ -280,8 +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
  * @sys:		The system time of the selected CLOCK ID
- * @real:		Realtime system time
- * @boot:		Boot time
  * @raw:		Monotonic raw system time
  * @cs_id:		Clocksource ID
  * @clock_was_set_seq:	The sequence number of clock-was-set events
@@ -291,8 +289,6 @@ static inline bool ktime_get_aux_ts64(cl
 struct system_time_snapshot {
 	u64			cycles;
 	ktime_t			sys;
-	ktime_t			real;
-	ktime_t			boot;
 	ktime_t			raw;
 	enum clocksource_ids	cs_id;
 	unsigned int		clock_was_set_seq;
kernel/time/timekeeping.c +0 -8
@@ -1196,8 +1196,6 @@ bool ktime_get_snapshot_id(struct system
 	struct 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 @@ bool ktime_get_snapshot_id(struct system
 		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->sys = 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->raw = ktime_add_ns(base_raw, nsec_raw);
 
 	/*
#29 lore raw

Re: [patch 08/24] timekeeping: Remove system_time_snapshot::real/boot

Quoted 3 lines · Thomas Gleixner

All users are converted over to ktime_get_snapshot_id() and system_time_snapshot::sys.

I would have expected this to also remove ktime_get_snapshot() since the description claims all users are converted to ktime_get_snapshot_id().

Quoted 59 lines

Remove the leftovers.

---
 include/linux/timekeeping.h |    4 ----
 kernel/time/timekeeping.c   |    8 --------
 2 files changed, 12 deletions(-)
include/linux/timekeeping.h +0 -4
@@ -280,8 +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
  * @sys:		The system time of the selected CLOCK ID
- * @real:		Realtime system time
- * @boot:		Boot time
  * @raw:		Monotonic raw system time
  * @cs_id:		Clocksource ID
  * @clock_was_set_seq:	The sequence number of clock-was-set events
@@ -291,8 +289,6 @@ static inline bool ktime_get_aux_ts64(cl
 struct system_time_snapshot {
 	u64			cycles;
 	ktime_t			sys;
-	ktime_t			real;
-	ktime_t			boot;
 	ktime_t			raw;
 	enum clocksource_ids	cs_id;
 	unsigned int		clock_was_set_seq;
kernel/time/timekeeping.c +0 -8
@@ -1196,8 +1196,6 @@ bool ktime_get_snapshot_id(struct system
 	struct 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 @@ bool ktime_get_snapshot_id(struct system
 		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->sys = 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->raw = ktime_add_ns(base_raw, nsec_raw);
 
 	/*
#30 lore raw

Re: [patch 08/24] timekeeping: Remove system_time_snapshot::real/boot

Quoted 8 lines · Jacob Keller
Quoted 3 lines · Thomas Gleixner

All users are converted over to ktime_get_snapshot_id() and system_time_snapshot::sys.

I would have expected this to also remove ktime_get_snapshot() since the description claims all users are converted to ktime_get_snapshot_id().

Ah. All the users of the real/boot paramaters have been updated, but drivers still use ktime_get_snapshot() until later in the series. Ok, that makes sense.

Reviewed-by on v1 8/24
#32 lore raw

Re: [patch 08/24] timekeeping: Remove system_time_snapshot::real/boot

In reply to Thomas Gleixner
Quoted 6 lines · Thomas Gleixner

All users are converted over to ktime_get_snapshot_id() and system_time_snapshot::sys.

Remove the leftovers.

Quoted 37 lines
---
 include/linux/timekeeping.h |    4 ----
 kernel/time/timekeeping.c   |    8 --------
 2 files changed, 12 deletions(-)
include/linux/timekeeping.h +0 -4
@@ -280,8 +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
  * @sys:		The system time of the selected CLOCK ID
- * @real:		Realtime system time
- * @boot:		Boot time
  * @raw:		Monotonic raw system time
  * @cs_id:		Clocksource ID
  * @clock_was_set_seq:	The sequence number of clock-was-set events
@@ -291,8 +289,6 @@ static inline bool ktime_get_aux_ts64(cl
 struct system_time_snapshot {
 	u64			cycles;
 	ktime_t			sys;
-	ktime_t			real;
-	ktime_t			boot;
 	ktime_t			raw;
 	enum clocksource_ids	cs_id;
 	unsigned int		clock_was_set_seq;
kernel/time/timekeeping.c +0 -2
@@ -1196,8 +1196,6 @@ bool ktime_get_snapshot_id(struct system
 	struct 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;

kernel/time/timekeeping.c bool ktime_get_snapshot_id(struct system · line 1245

Quoted 7 lines
kernel/time/timekeeping.c +0 -4
@@ -1239,18 +1237,12 @@ bool ktime_get_snapshot_id(struct system
 		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);
-

In patch 1 I was confused slightly why only these two lines use tk_core, while everything else uses tk->, even base_sys.
Functionally it doesn't make a difference, but for clarity this could be more consistent.

Quoted 12 lines
kernel/time/timekeeping.c +0 -2
 		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->sys = 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->raw = ktime_add_ns(base_raw, nsec_raw);
 
 	/*
author maintainer
#33 lore raw

PATCH 9/24 timekeeping: Add CLOCK_AUX support for ktime_get_snapshot_id()

In reply to Thomas Gleixner

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 @@ bool ktime_get_snapshot_id(struct system
 		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 false;
+		offs = &tkd->timekeeper.offs_aux;
+		break;
 	default:
 		WARN_ON_ONCE(1);
 		return false;
@@ -1228,6 +1239,10 @@ bool ktime_get_snapshot_id(struct system
 	do {
 		seq = read_seqcount_begin(&tkd->seq);
 
+		/* Aux clocks can be invalid */
+		if (!tk->clock_valid)
+			return false;
+
 		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;
#36 lore raw

Re: [patch 09/24] timekeeping: Add CLOCK_AUX support for ktime_get_snapshot_id()

In reply to Thomas Gleixner

On Tue, May 26, 2026 at 07:14:13PM +0200, Thomas Gleixner wrote:
(...)

kernel/time/timekeeping.c bool ktime_get_snapshot_id(struct system · line 1231

Quoted 11 lines

static inline void tk_update_aux_offs(struct timekeeper *tk, ktime_t offs)

kernel/time/timekeeping.c +6 -0
@@ -1218,6 +1223,12 @@ bool ktime_get_snapshot_id(struct system
 		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 false;
+		offs = &tkd->timekeeper.offs_aux;
+		break;

'tkd' is also used to compute 'monoraw'. However 'tkr_raw' and 'tkr_mono' are the same for auxilary clocks, so this will compute a wrong 'monoraw'. Instead 'monoraw' should be computed based on 'tk_core'. Which then also requires the sequence locking of 'tk_core'.

As you know I have a series which unifies the locking between the different timekeepers. Maybe we revert this patch for 7.2 and I send a fixed variant including the prerequisites for 7.3.

(The same goes for get_device_system_crosststamp())

Quoted 15 lines
kernel/time/timekeeping.c +4 -0
 	default:
 		WARN_ON_ONCE(1);
 		return false;
@@ -1228,6 +1239,10 @@ bool ktime_get_snapshot_id(struct system
 	do {
 		seq = read_seqcount_begin(&tkd->seq);
 
+		/* Aux clocks can be invalid */
+		if (!tk->clock_valid)
+			return false;
+
 		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;
author maintainer
#37 lore raw

Re: [patch 09/24] timekeeping: Add CLOCK_AUX support for ktime_get_snapshot_id()

Quoted 17 lines · Thomas Weißschuh

On Tue, May 26, 2026 at 07:14:13PM +0200, Thomas Gleixner wrote:
(...)

kernel/time/timekeeping.c bool ktime_get_snapshot_id(struct system · line 1231

Quoted 11 lines

static inline void tk_update_aux_offs(struct timekeeper *tk, ktime_t offs)

kernel/time/timekeeping.c +6 -0
@@ -1218,6 +1223,12 @@ bool ktime_get_snapshot_id(struct system
 		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 false;
+		offs = &tkd->timekeeper.offs_aux;
+		break;

'tkd' is also used to compute 'monoraw'. However 'tkr_raw' and 'tkr_mono' are the same for auxilary clocks, so this will compute a wrong 'monoraw'.

AUX clocks are independent in the first place and the MONORAW part is the "MONORAW" related to the AUX clock itself.

Quoted 2 lines

Instead 'monoraw' should be computed based on 'tk_core'. Which then also requires the sequence locking of 'tk_core'.

No. From a PTP and steering point of view you want the "raw" value which is related to the AUX clock itself and not the global one.

The global MONORAW and the AUX clock MONORAW are related obviously as they share the same conversion factors.

MONORAW(AUX$N) = MONORAW(GLOBAL) + OFFSET(AUX$N)

We don't have that information anywhere right now and we might want to expose it to allow user space a proper correlation, but that's an orthogonal problem.

From a PTP/steering point of view the code is correct as is.

Thanks,

tglx

#38 lore raw

Re: [patch 09/24] timekeeping: Add CLOCK_AUX support for ktime_get_snapshot_id()

Quoted 19 lines · Thomas Gleixner
Quoted 17 lines · Thomas Weißschuh

On Tue, May 26, 2026 at 07:14:13PM +0200, Thomas Gleixner wrote:
(...)

kernel/time/timekeeping.c bool ktime_get_snapshot_id(struct system · line 1231

Quoted 11 lines

static inline void tk_update_aux_offs(struct timekeeper *tk, ktime_t offs)

kernel/time/timekeeping.c +6 -0
@@ -1218,6 +1223,12 @@ bool ktime_get_snapshot_id(struct system
 		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 false;
+		offs = &tkd->timekeeper.offs_aux;
+		break;

'tkd' is also used to compute 'monoraw'. However 'tkr_raw' and 'tkr_mono' are the same for auxilary clocks, so this will compute a wrong 'monoraw'.

Quoted 8 lines

AUX clocks are independent in the first place and the MONORAW part is the "MONORAW" related to the AUX clock itself.

Quoted 2 lines

Instead 'monoraw' should be computed based on 'tk_core'. Which then also requires the sequence locking of 'tk_core'.

No. From a PTP and steering point of view you want the "raw" value which is related to the AUX clock itself and not the global one.

Ack.

However the kdocs call it 'CLOCK_MONOTONIC_RAW'. Can we clean this up?

Quoted 10 lines

The global MONORAW and the AUX clock MONORAW are related obviously as they share the same conversion factors.

MONORAW(AUX$N) = MONORAW(GLOBAL) + OFFSET(AUX$N)

We don't have that information anywhere right now and we might want to expose it to allow user space a proper correlation, but that's an orthogonal problem.

From a PTP/steering point of view the code is correct as is.

Thanks for the clarifications.

Thomas

author maintainer
#39 lore raw

Re: [patch 09/24] timekeeping: Add CLOCK_AUX support for ktime_get_snapshot_id()

Quoted 26 lines · Thomas Weißschuh
Quoted 25 lines · Thomas Gleixner
Quoted 17 lines · Thomas Weißschuh

On Tue, May 26, 2026 at 07:14:13PM +0200, Thomas Gleixner wrote:
(...)

Review bool ktime_get_snapshot_id(struct system · line 1231

Quoted 11 lines

static inline void tk_update_aux_offs(struct timekeeper *tk, ktime_t offs)

(quoted diff) +6 -0
@@ -1218,6 +1223,12 @@ bool ktime_get_snapshot_id(struct system
 		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 false;
+		offs = &tkd->timekeeper.offs_aux;
+		break;

'tkd' is also used to compute 'monoraw'. However 'tkr_raw' and 'tkr_mono' are the same for auxilary clocks, so this will compute a wrong 'monoraw'.

AUX clocks are independent in the first place and the MONORAW part is the "MONORAW" related to the AUX clock itself.

Quoted 2 lines

Instead 'monoraw' should be computed based on 'tk_core'. Which then also requires the sequence locking of 'tk_core'.

Quoted 6 lines
Quoted 2 lines

No. From a PTP and steering point of view you want the "raw" value which is related to the AUX clock itself and not the global one.

Ack.

However the kdocs call it 'CLOCK_MONOTONIC_RAW'. Can we clean this up?

Yes. Something like the below?

Thanks,

tglx
---

kernel/time/timekeeping.c +15 -1
@@ -1202,10 +1202,21 @@ static inline u64 tk_clock_read_snapshot
 
 /**
  * ktime_get_snapshot_id -  Simultaneously snapshot a given clock ID with
- *			    CLOCK_MONOTONIC_RAW and the underlying
+ *			    the corresponding monotonic raw the underlying
  *			    clocksource counter value.
  * @clock_id:		The clock ID to snapshot
  * @systime_snapshot:	Pointer to struct receiving the system time snapshot
+ *
+ * For the system time keeping clocks (REALTIME, MONOTONIC and BOOTTIME) the
+ * monotonic raw clock is CLOCK_MONOTONIC_RAW. For AUX clocks this is the
+ * monotonic raw clock related to the AUX clock. These AUX clock related
+ * monotonic raw clocks have a strict linear offset to the system time
+ * CLOCK_MONOTONIC_RAW:
+ *
+ *	MONOTONIC_RAW(AUX$N) = CLOCK_MONOTONIC_RAW(system) + offset(AUX$N)
+ *
+ * The offset is established when a AUX clock is initialized, but it is
+ * currently not accessible.
  */
 void ktime_get_snapshot_id(clockid_t clock_id, struct system_time_snapshot *systime_snapshot)
 {
@@ -1512,6 +1523,9 @@ EXPORT_SYMBOL_GPL(ktime_real_to_base_clo
  * @xtstamp:		Receives simultaneously captured system and device time
  *
  * Reads a timestamp from a device and correlates it to system time
+ *
+ * See documentation for ktime_get_snapshot_id() for information about the raw
+ * monotonic time stamp which is used here.
  */
 int get_device_system_crosststamp(int (*get_time_fn)
 				  (ktime_t *device_time,
#40 lore raw

Re: [patch 09/24] timekeeping: Add CLOCK_AUX support for ktime_get_snapshot_id()

Quoted 27 lines · Thomas Gleixner
Quoted 26 lines · Thomas Weißschuh
Quoted 25 lines · Thomas Gleixner
Quoted 17 lines · Thomas Weißschuh

On Tue, May 26, 2026 at 07:14:13PM +0200, Thomas Gleixner wrote:
(...)

Review bool ktime_get_snapshot_id(struct system · line 1231

Quoted 11 lines

static inline void tk_update_aux_offs(struct timekeeper *tk, ktime_t offs)

(quoted diff) +6 -0
@@ -1218,6 +1223,12 @@ bool ktime_get_snapshot_id(struct system
 		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 false;
+		offs = &tkd->timekeeper.offs_aux;
+		break;

'tkd' is also used to compute 'monoraw'. However 'tkr_raw' and 'tkr_mono' are the same for auxilary clocks, so this will compute a wrong 'monoraw'.

AUX clocks are independent in the first place and the MONORAW part is the "MONORAW" related to the AUX clock itself.

Quoted 2 lines

Instead 'monoraw' should be computed based on 'tk_core'. Which then also requires the sequence locking of 'tk_core'.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

No. From a PTP and steering point of view you want the "raw" value which is related to the AUX clock itself and not the global one.

Ack.

However the kdocs call it 'CLOCK_MONOTONIC_RAW'. Can we clean this up?

Yes. Something like the below?

Looks good, thanks.
The corresponding structure definitions are a also affected, though.

Quoted 40 lines

Thanks,

tglx
---

kernel/time/timekeeping.c +15 -1
@@ -1202,10 +1202,21 @@ static inline u64 tk_clock_read_snapshot
 
 /**
  * ktime_get_snapshot_id -  Simultaneously snapshot a given clock ID with
- *			    CLOCK_MONOTONIC_RAW and the underlying
+ *			    the corresponding monotonic raw the underlying
  *			    clocksource counter value.
  * @clock_id:		The clock ID to snapshot
  * @systime_snapshot:	Pointer to struct receiving the system time snapshot
+ *
+ * For the system time keeping clocks (REALTIME, MONOTONIC and BOOTTIME) the
+ * monotonic raw clock is CLOCK_MONOTONIC_RAW. For AUX clocks this is the
+ * monotonic raw clock related to the AUX clock. These AUX clock related
+ * monotonic raw clocks have a strict linear offset to the system time
+ * CLOCK_MONOTONIC_RAW:
+ *
+ *	MONOTONIC_RAW(AUX$N) = CLOCK_MONOTONIC_RAW(system) + offset(AUX$N)
+ *
+ * The offset is established when a AUX clock is initialized, but it is
+ * currently not accessible.
  */
 void ktime_get_snapshot_id(clockid_t clock_id, struct system_time_snapshot *systime_snapshot)
 {
@@ -1512,6 +1523,9 @@ EXPORT_SYMBOL_GPL(ktime_real_to_base_clo
  * @xtstamp:		Receives simultaneously captured system and device time
  *
  * Reads a timestamp from a device and correlates it to system time
+ *
+ * See documentation for ktime_get_snapshot_id() for information about the raw
+ * monotonic time stamp which is used here.
  */
 int get_device_system_crosststamp(int (*get_time_fn)
 				  (ktime_t *device_time,
author maintainer
#41 lore raw

Re: [patch 09/24] timekeeping: Add CLOCK_AUX support for ktime_get_snapshot_id()

Quoted 31 lines · Thomas Weißschuh
Quoted 30 lines · Thomas Gleixner
Quoted 29 lines · Thomas Weißschuh
Quoted 27 lines · Thomas Gleixner
Quoted 17 lines · Thomas Weißschuh

On Tue, May 26, 2026 at 07:14:13PM +0200, Thomas Gleixner wrote:
(...)

Review bool ktime_get_snapshot_id(struct system · line 1231

Quoted 11 lines

static inline void tk_update_aux_offs(struct timekeeper *tk, ktime_t offs)

(quoted diff) +6 -0
@@ -1218,6 +1223,12 @@ bool ktime_get_snapshot_id(struct system
 		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 false;
+		offs = &tkd->timekeeper.offs_aux;
+		break;

'tkd' is also used to compute 'monoraw'. However 'tkr_raw' and 'tkr_mono' are the same for auxilary clocks, so this will compute a wrong 'monoraw'.

AUX clocks are independent in the first place and the MONORAW part is the "MONORAW" related to the AUX clock itself.

Quoted 2 lines

Instead 'monoraw' should be computed based on 'tk_core'. Which then also requires the sequence locking of 'tk_core'.

No. From a PTP and steering point of view you want the "raw" value which is related to the AUX clock itself and not the global one.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Ack.

However the kdocs call it 'CLOCK_MONOTONIC_RAW'. Can we clean this up?

Yes. Something like the below?

Looks good, thanks.
The corresponding structure definitions are a also affected, though.

True.

author maintainer
#42 lore raw

PATCH 1/1 timekeeping: Document monotonic raw timestamps in snapshots correctly

The comments related to raw monotonic timestamps for the various snapshot mechanisms in code and struct documentation are ambiguous. They reference them as CLOCK_MONOTONIC_RAW timestamps, but with the arrival of AUX clocks that's not longer correct.

The raw monotonic timestamps only represent CLOCK_MONOTONIC_RAW for the system time clock IDs, i.e. REALTIME, MONOTONIC, BOOTTIME, TAI.

For AUX clocks they refer to the monotonic raw clock which is related to the individual AUX clocks. These monotonic raw timestamps have the same conversion factor as CLOCK_MONOTONIC_RAW, but differ from that by an offset:

MONORAW(AUX$N) = MONORAW(SYSTEM) + OFFSET(AUX$N)

The offset is established when a AUX clock is enabled and stays constant for the lifetime of the AUX clock.

Update the comments so they reflect reality.

---
 include/linux/timekeeping.h |   10 +++++++++-
 kernel/time/timekeeping.c   |   16 +++++++++++++++-
 2 files changed, 24 insertions(+), 2 deletions(-)
include/linux/timekeeping.h +9 -1
@@ -276,7 +276,7 @@ static inline bool ktime_get_aux_ts64(cl
 #endif
 
 /**
- * struct system_time_snapshot - Simultaneous time capture of CLOCK_MONOTONIC_RAW,
+ * struct system_time_snapshot - Simultaneous time capture of monotonic raw time,
  *				 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
@@ -289,6 +289,10 @@ static inline bool ktime_get_aux_ts64(cl
  * @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
+ *
+ * @monoraw is CLOCK_MONOTONIC_RAW for system time CLOCK ids. For CLOCK_AUX$N
+ * clock ids it's the monotonic raw time related to the AUX clock, which is
+ * CLOCK_MONOTONIC_RAW plus a AUX clock specific offset.
  */
 struct system_time_snapshot {
 	u64			cycles;
@@ -326,6 +330,10 @@ struct system_counterval_t {
  * @sys_counter:	Clocksource counter value simultaneous with device time
  * @sys_systime:	System time for @clock_id
  * @sys_monoraw:	Monotonic raw simultaneous with device time
+ *
+ * @sys_monoraw is CLOCK_MONOTONIC_RAW for system time CLOCK ids. For
+ * CLOCK_AUX$N clock ids it's the monotonic raw time related to the AUX clock,
+ * which is CLOCK_MONOTONIC_RAW plus a AUX clock specific offset.
  */
 struct system_device_crosststamp {
 	clockid_t			clock_id;
kernel/time/timekeeping.c +15 -1
@@ -1202,10 +1202,21 @@ static inline u64 tk_clock_read_snapshot
 
 /**
  * ktime_get_snapshot_id -  Simultaneously snapshot a given clock ID with
- *			    CLOCK_MONOTONIC_RAW and the underlying
+ *			    the corresponding monotonic raw and the underlying
  *			    clocksource counter value.
  * @clock_id:		The clock ID to snapshot
  * @systime_snapshot:	Pointer to struct receiving the system time snapshot
+ *
+ * For the system time keeping clocks (REALTIME, MONOTONIC and BOOTTIME) the
+ * monotonic raw clock is CLOCK_MONOTONIC_RAW. For AUX clocks this is the
+ * monotonic raw clock related to the AUX clock. These AUX clock related
+ * monotonic raw clocks have a strict linear offset to the system time
+ * CLOCK_MONOTONIC_RAW:
+ *
+ *	MONOTONIC_RAW(AUX$N) = CLOCK_MONOTONIC_RAW(system) + offset(AUX$N)
+ *
+ * The offset is established when a AUX clock is initialized, but it is
+ * currently not accessible.
  */
 void ktime_get_snapshot_id(clockid_t clock_id, struct system_time_snapshot *systime_snapshot)
 {
@@ -1512,6 +1523,9 @@ EXPORT_SYMBOL_GPL(ktime_real_to_base_clo
  * @xtstamp:		Receives simultaneously captured system and device time
  *
  * Reads a timestamp from a device and correlates it to system time
+ *
+ * See documentation for ktime_get_snapshot_id() for information about the raw
+ * monotonic time stamp which is used here.
  */
 int get_device_system_crosststamp(int (*get_time_fn)
 				  (ktime_t *device_time,
Reviewed-by on v1 1/1
#43 lore raw

Re: [PATCH] timekeeping: Document monotonic raw timestamps in snapshots correctly

Quoted 15 lines · Thomas Gleixner

The comments related to raw monotonic timestamps for the various snapshot mechanisms in code and struct documentation are ambiguous. They reference them as CLOCK_MONOTONIC_RAW timestamps, but with the arrival of AUX clocks that's not longer correct.

The raw monotonic timestamps only represent CLOCK_MONOTONIC_RAW for the system time clock IDs, i.e. REALTIME, MONOTONIC, BOOTTIME, TAI.

For AUX clocks they refer to the monotonic raw clock which is related to the individual AUX clocks. These monotonic raw timestamps have the same conversion factor as CLOCK_MONOTONIC_RAW, but differ from that by an offset:

MONORAW(AUX$N) = MONORAW(SYSTEM) + OFFSET(AUX$N)

Quoted 7 lines

The offset is established when a AUX clock is enabled and stays constant for the lifetime of the AUX clock.

Update the comments so they reflect reality.

Thanks!

(...)

#44 lore raw

[tip: timers/core] timekeeping: Document monotonic raw timestamps in snapshots correctly

In reply to Thomas Gleixner
The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     e2904ddb14a4198ad31eb12a072a6923f0c8ca09
Gitweb:        https://git.kernel.org/tip/e2904ddb14a4198ad31eb12a072a6923f0c8ca09
Author:        Thomas Gleixner <[email protected]>
AuthorDate:    Sun, 05 Jul 2026 14:38:04 +02:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Mon, 06 Jul 2026 17:47:44 +02:00

timekeeping: Document monotonic raw timestamps in snapshots correctly

The comments related to raw monotonic timestamps for the various snapshot mechanisms in code and struct documentation are ambiguous. They reference them as CLOCK_MONOTONIC_RAW timestamps, but with the arrival of AUX clocks that's not longer correct.

The raw monotonic timestamps only represent CLOCK_MONOTONIC_RAW for the system time clock IDs, i.e. REALTIME, MONOTONIC, BOOTTIME, TAI.

For AUX clocks they refer to the monotonic raw clock which is related to the individual AUX clocks. These monotonic raw timestamps have the same conversion factor as CLOCK_MONOTONIC_RAW, but differ from that by an offset:

MONORAW(AUX$N) = MONORAW(SYSTEM) + OFFSET(AUX$N)

The offset is established when a AUX clock is enabled and stays constant for the lifetime of the AUX clock.

Update the comments so they reflect reality.

---
 include/linux/timekeeping.h | 10 +++++++++-
 kernel/time/timekeeping.c   | 16 +++++++++++++++-
 2 files changed, 24 insertions(+), 2 deletions(-)
include/linux/timekeeping.h +9 -1
index 984a866..b4191a8 100644
@@ -276,7 +276,7 @@ static inline bool ktime_get_aux_ts64(clockid_t id, struct timespec64 *kt) { ret
 #endif
 
 /**
- * struct system_time_snapshot - Simultaneous time capture of CLOCK_MONOTONIC_RAW,
+ * struct system_time_snapshot - Simultaneous time capture of monotonic raw time,
  *				 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
@@ -289,6 +289,10 @@ static inline bool ktime_get_aux_ts64(clockid_t id, struct timespec64 *kt) { ret
  * @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
+ *
+ * @monoraw is CLOCK_MONOTONIC_RAW for system time CLOCK ids. For CLOCK_AUX$N
+ * clock ids it's the monotonic raw time related to the AUX clock, which is
+ * CLOCK_MONOTONIC_RAW plus a AUX clock specific offset.
  */
 struct system_time_snapshot {
 	u64			cycles;
@@ -326,6 +330,10 @@ struct system_counterval_t {
  * @sys_counter:	Clocksource counter value simultaneous with device time
  * @sys_systime:	System time for @clock_id
  * @sys_monoraw:	Monotonic raw simultaneous with device time
+ *
+ * @sys_monoraw is CLOCK_MONOTONIC_RAW for system time CLOCK ids. For
+ * CLOCK_AUX$N clock ids it's the monotonic raw time related to the AUX clock,
+ * which is CLOCK_MONOTONIC_RAW plus a AUX clock specific offset.
  */
 struct system_device_crosststamp {
 	clockid_t			clock_id;
kernel/time/timekeeping.c +15 -1
index b1b5ec4..5985d66 100644
@@ -1202,10 +1202,21 @@ static inline u64 tk_clock_read_snapshot(const struct tk_read_base *tkr,
 
 /**
  * ktime_get_snapshot_id -  Simultaneously snapshot a given clock ID with
- *			    CLOCK_MONOTONIC_RAW and the underlying
+ *			    the corresponding monotonic raw and the underlying
  *			    clocksource counter value.
  * @clock_id:		The clock ID to snapshot
  * @systime_snapshot:	Pointer to struct receiving the system time snapshot
+ *
+ * For the system time keeping clocks (REALTIME, MONOTONIC and BOOTTIME) the
+ * monotonic raw clock is CLOCK_MONOTONIC_RAW. For AUX clocks this is the
+ * monotonic raw clock related to the AUX clock. These AUX clock related
+ * monotonic raw clocks have a strict linear offset to the system time
+ * CLOCK_MONOTONIC_RAW:
+ *
+ *	MONOTONIC_RAW(AUX$N) = CLOCK_MONOTONIC_RAW(system) + offset(AUX$N)
+ *
+ * The offset is established when a AUX clock is initialized, but it is
+ * currently not accessible.
  */
 void ktime_get_snapshot_id(clockid_t clock_id, struct system_time_snapshot *systime_snapshot)
 {
@@ -1512,6 +1523,9 @@ EXPORT_SYMBOL_GPL(ktime_real_to_base_clock);
  * @xtstamp:		Receives simultaneously captured system and device time
  *
  * Reads a timestamp from a device and correlates it to system time
+ *
+ * See documentation for ktime_get_snapshot_id() for information about the raw
+ * monotonic time stamp which is used here.
  */
 int get_device_system_crosststamp(int (*get_time_fn)
 				  (ktime_t *device_time,
maintainer
#45 lore raw

Re: [patch 09/24] timekeeping: Add CLOCK_AUX support for ktime_get_snapshot_id()

In reply to Thomas Weißschuh
Quoted 10 lines · Thomas Weißschuh

'tkd' is also used to compute 'monoraw'. However 'tkr_raw' and 'tkr_mono' are the same for auxilary clocks, so this will compute a wrong 'monoraw'. Instead 'monoraw' should be computed based on 'tk_core'. Which then also requires the sequence locking of 'tk_core'.

As you know I have a series which unifies the locking between the different timekeepers. Maybe we revert this patch for 7.2 and I send a fixed variant including the prerequisites for 7.3.

(The same goes for get_device_system_crosststamp())

No fundamental objection from me... but does it matter in practice? Is it even reachable?

I think the only way these functions can end up being invoked for aux clocks is via PTP_SYS_OFFSET_EXTENDED, which since commit a6d799608e6 ("ptp: Switch to ktime_get_snapshot_id() for pre/post timestamps") and some other driver-specific changes in this series, can now invoke them with the user-requested clockid.

But those callers *only* care about ::systime, don't they? So the problem never arises because there's no code path in which anything actually cares about ::monoraw for AUX clocks.

If we back out the handling of AUX clocks in ktime_get_snapshot_id() we'd have to roll back much of that other plumbing too. If we *just* remove the 'case CLOCK_AUX ... CLOCK_AUX_LAST' hunk, we'd end up with users being able to trigger the 'default: WARN_ON_ONCE(1)' which follows.

So while you're right, I *think* it's harmless in practice and reverting it safely is slightly more complex than it seems at first glance?

author maintainer
#46 lore raw

PATCH 10/24 timekeeping: Add system_counterval_t to struct system_device_crosststamp

In reply to Thomas Gleixner

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

maintainer Reviewed-by Tested-by on v1 10/24
#47 lore raw

Re: [PATCH 10/24] timekeeping: Add system_counterval_t to struct system_device_crosststamp

Quoted 8 lines · Thomas Gleixner

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.

author maintainer
#48 lore raw

PATCH 11/24 timekeeping: Add CLOCK ID to system_device_crosststamp

In reply to Thomas Gleixner

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
 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_
 			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;
 
maintainer Reviewed-by Tested-by on v1 11/24
#49 lore raw

Re: [PATCH 11/24] timekeeping: Add CLOCK ID to system_device_crosststamp

Quoted 7 lines · Thomas Gleixner

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.

Quoted 7 lines

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.

author maintainer
#50 lore raw

PATCH 12/24 wifi: iwlwifi: Adopt PTP cross timestamps to core changes

In reply to Thomas Gleixner

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.

Cc Miri Korenblit <[email protected]>
Cc Johannes Berg <[email protected]>
---
 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);
maintainer Reviewed-by on v1 12/24
#51 lore raw

Re: [PATCH 12/24] wifi: iwlwifi: Adopt PTP cross timestamps to core changes

Quoted 9 lines · Thomas Gleixner

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.

author maintainer
#52 lore raw

PATCH 13/24 ice/ptp: Use provided clock ID for history snapshot

In reply to Thomas Gleixner

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, ctx->snapshot_clock_id);
 
 	/* 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,
 	};
 
Acked-by on v1 13/24
#53 lore raw

Re: [patch 13/24] ice/ptp: Use provided clock ID for history snapshot

Quoted 11 lines · Thomas Gleixner

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.

maintainer Reviewed-by on v1 13/24
#54 lore raw

Re: [PATCH 13/24] ice/ptp: Use provided clock ID for history snapshot

In reply to Thomas Gleixner
Quoted 10 lines · Thomas Gleixner

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.

author maintainer
#55 lore raw

PATCH 14/24 igc: Use provided clock ID for history snapshot

In reply to Thomas Gleixner

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, adapter->snapshot_clock_id);
 
 		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);
Acked-by on v1 14/24
#56 lore raw

Re: [patch 14/24] igc: Use provided clock ID for history snapshot

Quoted 4 lines · Thomas Gleixner

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.

Quoted 8 lines

Save the provided clock ID and use it in igc_phc_get_syncdevicetime() for taking the history snapshot.

No functional change.

---

maintainer Reviewed-by on v1 14/24
#57 lore raw

Re: [PATCH 14/24] igc: Use provided clock ID for history snapshot

In reply to Thomas Gleixner
Quoted 10 lines · Thomas Gleixner

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.

author maintainer
#58 lore raw

PATCH 15/24 net/mlx5: Use provided clock ID for history snapshot

In reply to Thomas Gleixner

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(&history_begin, cts->clock_id);
 
 	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(&history_begin, cts->clock_id);
 
 	err = get_device_system_crosststamp(mlx5_mtctr_syncdevicecyclestime,
 					    mdev, &history_begin, cts);
maintainer Reviewed-by on v1 15/24
#59 lore raw

Re: [PATCH 15/24] net/mlx5: Use provided clock ID for history snapshot

Quoted 9 lines · Thomas Gleixner

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.

author maintainer
#60 lore raw

PATCH 16/24 virtio_rtc: Use provided clock ID for history snapshot

In reply to Thomas Gleixner

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.

Cc Peter Hilber <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
---
 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(str
 	if (ret)
 		return ret;
 
-	ktime_get_snapshot(&history_begin);
+	ktime_get_snapshot_id(&history_begin, xtstamp->clock_id);
 	if (history_begin.cs_id != cs_id)
 		return -EOPNOTSUPP;
 
maintainer Reviewed-by on v1 16/24
#61 lore raw

Re: [PATCH 16/24] virtio_rtc: Use provided clock ID for history snapshot

Quoted 9 lines · Thomas Gleixner

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.

author maintainer
#62 lore raw

PATCH 17/24 timekeeping: Remove ktime_get_snapshot()

In reply to Thomas Gleixner

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
@@ -351,11 +351,6 @@ extern int get_device_system_crosststamp
 extern bool ktime_get_snapshot_id(struct system_time_snapshot *systime_snapshot,
 				  clockid_t clock_id);
 
-static inline void ktime_get_snapshot(struct system_time_snapshot *systime_snapshot)
-{
-	WARN_ON_ONCE(!ktime_get_snapshot_id(systime_snapshot, CLOCK_REALTIME));
-}
-
 /*
  * Persistent clock related interfaces
  */
author maintainer
#65 lore raw

PATCH 18/24 timekeeping: Prepare for cross timestamps on arbitrary clock IDs

In reply to Thomas Gleixner

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

maintainer Reviewed-by Tested-by on v1 18/24
#66 lore raw

Re: [PATCH 18/24] timekeeping: Prepare for cross timestamps on arbitrary clock IDs

Quoted 8 lines · Thomas Gleixner

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.

Quoted 7 lines

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

I suspect I'll be back to frown at adjust_historical_crosststamp() at some point, but that's a separate issue. For this change:

Reviewed-by on v1 18/24
#67 lore raw

Re: [patch 18/24] timekeeping: Prepare for cross timestamps on arbitrary clock IDs

In reply to Thomas Gleixner
Quoted 8 lines · Thomas Gleixner

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.

Quoted 7 lines

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

author maintainer
#68 lore raw

PATCH 19/24 ptp: Use system_device_crosststamp::sys_systime

In reply to Thomas Gleixner

.. 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);
author maintainer
#70 lore raw

PATCH 20/24 wifi: iwlwifi: Use system_device_crosststamp::sys_systime

In reply to Thomas Gleixner

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);
author maintainer
#72 lore raw

PATCH 21/24 ALSA: hda/common: Use system_device_crosststamp::sys_systime

In reply to Thomas Gleixner

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;
 
 		}
author maintainer
#74 lore raw

PATCH 22/24 timekeeping: Remove system_device_crosststamp::sys_realtime

In reply to Thomas Gleixner

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;
 };
 
author maintainer
#77 lore raw

PATCH 23/24 timekeeping: Add support for AUX clock cross timestamping

In reply to Thomas Gleixner

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
@@ -1518,6 +1518,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 false;
+		offs = &tkd->timekeeper.offs_aux;
+		break;
 	default:
 		WARN_ON_ONCE(1);
 		return false;
maintainer Reviewed-by on v1 23/24
#78 lore raw

Re: [PATCH 23/24] timekeeping: Add support for AUX clock cross timestamping

Quoted 5 lines · Thomas Gleixner

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.

Reviewed-by on v1 23/24
#79 lore raw

Re: [patch 23/24] timekeeping: Add support for AUX clock cross timestamping

In reply to Thomas Gleixner
Quoted 5 lines · Thomas Gleixner

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.

author maintainer
#80 lore raw

PATCH 24/24 ptp: Switch to ktime_get_snapshot_id() for pre/post timestamps

In reply to Thomas Gleixner

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.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);
 	/* 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(stru
 			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.sys);
+		extoff->ts[i][0].sec = ts.tv_sec;
+		extoff->ts[i][0].nsec = ts.tv_nsec;
+
+		ts = ktime_to_timespec64(sts.post_sts.sys);
+		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_ts.sys -= 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.sys);
+		post_ns = ktime_to_ns(sts.post_sts.sys);
 		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(&systime_snapshot, CLOCK_REALTIME);
-			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.sys);
-		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_timest
 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->pre_sts, sts->clockid);
 }
 
 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->post_sts, sts->clockid);
 }
 
 #endif
maintainer Reviewed-by Tested-by on v1 24/24
#81 lore raw

Re: [PATCH 24/24] ptp: Switch to ktime_get_snapshot_id() for pre/post timestamps

Quoted 9 lines · Thomas Gleixner

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.

maintainer Acked-by on v1 24/24
#82 lore raw

Re: [patch 24/24] ptp: Switch to ktime_get_snapshot_id() for pre/post timestamps

In reply to Thomas Gleixner
Quoted 9 lines · Thomas Gleixner

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.

for ptp_ocp:

maintainer
#83 lore raw

Re: [patch 24/24] ptp: Switch to ktime_get_snapshot_id() for pre/post timestamps

In reply to Thomas Gleixner

drivers/ptp/ptp_ocp.c static int · line 1495

Quoted 7 lines · On Tue, 26 May 2026 19:15:27 +0200 Thomas Gleixner wrote:
drivers/ptp/ptp_ocp.c +2 -5
-	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_ts.sys -= bp->ts_window_adjust;

FWIW build says:

drivers/ptp/ptp_ocp.c:1495:8: error: no member named 'post_ts' in 'struct ptp_system_timestamp'

 1495 |                 sts->post_ts.sys -= bp->ts_window_adjust;
      |                 ~~~  ^
author maintainer
#84 lore raw

Re: [patch 24/24] ptp: Switch to ktime_get_snapshot_id() for pre/post timestamps

Quoted 11 lines · Jakub Kicinski

drivers/ptp/ptp_ocp.c static int · line 1495

Quoted 7 lines · On Tue, 26 May 2026 19:15:27 +0200 Thomas Gleixner wrote:
drivers/ptp/ptp_ocp.c +2 -5
-	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_ts.sys -= bp->ts_window_adjust;

FWIW build says:

Quoted 3 lines

drivers/ptp/ptp_ocp.c:1495:8: error: no member named 'post_ts' in 'struct ptp_system_timestamp'

 1495 |                 sts->post_ts.sys -= bp->ts_window_adjust;
      |                 ~~~  ^

Noticed too and fixed locally already.

Reviewed-by on the v1 series
#85 lore raw
In reply to Thomas Gleixner
Quoted 17 lines · Thomas Gleixner

Sorry for the large CC list, but changing the inner workings touches unfortunately a lot of places in one go.

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:

Quoted 9 lines

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

Overall the series looks good to me. I made some comments while reviewing but nothing major and I think mostly it was on interim code that is removed by the end of the series.

Quoted 32 lines

It's 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-v1

Thanks to David for rebasing his PTP/timekeeping work on top and providing feedback, fixes and testing.

Thanks,

tglx

---
 arch/arm64/kvm/hyp_trace.c                          |    8 
 arch/arm64/kvm/hypercalls.c                         |    6 
 drivers/net/dsa/sja1105/sja1105_main.c              |    8 
 drivers/net/ethernet/intel/ice/ice_ptp.c            |    5 
 drivers/net/ethernet/intel/igc/igc.h                |    1 
 drivers/net/ethernet/intel/igc/igc_ptp.c            |    4 
 drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c |    4 
 drivers/net/wireless/intel/iwlwifi/mld/ptp.c        |    5 
 drivers/net/wireless/intel/iwlwifi/mvm/ptp.c        |    7 
 drivers/pps/generators/pps_gen-dummy.c              |    6 
 drivers/pps/generators/pps_gen_tio.c                |    6 
 drivers/ptp/ptp_chardev.c                           |   18 +
 drivers/ptp/ptp_ocp.c                               |   11 -
 drivers/ptp/ptp_vmclock.c                           |   25 --
 drivers/virtio/virtio_rtc_ptp.c                     |    2 
 include/linux/pps_kernel.h                          |    8 
 include/linux/ptp_clock_kernel.h                    |   15 -
 include/linux/timekeeping.h                         |   54 ++---
 kernel/time/timekeeping.c                           |  211 ++++++++++++--------
 sound/hda/common/controller.c                       |    4 
 20 files changed, 236 insertions(+), 172 deletions(-)