Skip to contentSkip to conversation

Patchset enabling hardware based cross-timestamps for next gen Intel platforms

PATCH Superseded Christopher S. Hall 4 participants 16 messages Jan 13, 2016 – Jan 15, 2016

Subsystems (8)

v6 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v6 cover Patchset enabling hardware based cross-timestamps for next gen Intel platforms

Modern Intel hardware adds an Always Running Timer (ART) that allows the network and audio device clocks to precisely cross timestamp the device clock with the system clock. This allows a precise correlation of the device time and system time.

This patchset adds interfaces to the timekeeping code allowing drivers to translate ART time to system time.

Changelog:

Changes from v5 to v6:

* Pulled supporting code for snapshotting, correlated
clocksource, and cycles to nanoseconds translation to separate patches. Added patches are marked as NEW below. There is, however, very little *actually* new code, just reorganized code
* Renamed and moved clocksource change sequence to timekeeper
struct (out of tk_read_base)
* Renamed structs for system counter and synced device time
callback to system_counterval_t and sync_device_time_cb, respectively
* Changed PTP cross-timestamp callback name to getcrosststamp
for consistency with the timekeeping code - corresponding function name changes in e1000e driver
* Simplified PTP time calculations making use of ktime_to_* code

Changes from v4 to v5:

* Changes the history mechanism to interpolate system time using
a single historic system time pair (monotonic raw, realtime) rather than implementing a precise history using shadow timekeeper (see v4 changes). The advantage of this approach is that the history can be arbitrarily long. This approach may also be simpler in terms of coding. The major disadvantage is that the realtime clock can be adjusted. When adjusted, the realtime clock time (when interpolating from history) is always approximate. In general, the longer the interpolation period the larger the potential error. There isn't any error interpolating the monotonic raw clock time.
* This patchset also addresses objections to the previous
patchsets overly complex correlated timestamp structure. This patchset splits that structure into several smaller structures. The correlated timestamp interface is renamed cross timestamp to avoid any confusion with the correlated clocksource.
* The correlated clocksource is separated from the cross
timestamp mechanism.
* Add monotonic raw to the PTP user interface
* Add e1000e driver configuration option that wraps Intel PCH
specific code

Changes v3 to v4:

* Adds a history mechanism to accomodate slower devices. In this
case the response time for timestamp reads to the Intel DSP are too slow to be accomodated by the original correlated time mechanism. The history mechanism turns shadow timekeeper into an array where the history is stored.

Christopher S. Hall (9):
Add cycles to nanoseconds translation (NEW)
Add driver cross timestamp interface for higher precision time
synchronization
Add correlated clocksource relating aliased auxiliary and system
clocks (NEW)
Always Running Timer (ART) correlated clocksource
Add timekeeping snapshot code capturing system time and counter (NEW) Add history to cross timestamp interface supporting slower devices Remove duplicated code in ktime_get_raw_and_real()
Add PTP_SYS_OFFSET_PRECISE for driver crosstimestamping Adds hardware supported cross timestamp

 Documentation/ptp/testptp.c                 |   6 +-
 arch/x86/include/asm/cpufeature.h           |   2 +-
 arch/x86/include/asm/tsc.h                  |   2 +
 arch/x86/kernel/tsc.c                       |  46 ++++++
 drivers/net/ethernet/intel/Kconfig          |   9 +
 drivers/net/ethernet/intel/e1000e/defines.h |   5 +
 drivers/net/ethernet/intel/e1000e/ptp.c     |  88 ++++++++++
 drivers/net/ethernet/intel/e1000e/regs.h    |   4 +
 drivers/ptp/ptp_chardev.c                   |  27 +++
 include/linux/clocksource.h                 |  43 +++++
 include/linux/pps_kernel.h                  |  17 +-
 include/linux/ptp_clock_kernel.h            |   8 +
 include/linux/timekeeper_internal.h         |   2 +
 include/linux/timekeeping.h                 |  42 +++++
 include/uapi/linux/ptp_clock.h              |  13 +-
 kernel/time/timekeeping.c                   | 247 +++++++++++++++++++++++++---
 16 files changed, 521 insertions(+), 40 deletions(-)
Signature · 1 line
2.1.4
#1 lore raw

PATCH v6 1/9 Add cycles to nanoseconds translation

The timekeeping code does not currently provide a way to translate externally provided clocksource cycles to system time. The cycle count is always provided by the result clocksource read() method internal to the timekeeping code. The added function timekeeping_cycles_to_ns() calculated a nanosecond value from a cycle count that can be added to tk_read_base.base value yielding the current system time. This allows clocksource cycle values external to the timekeeping code to provide a cycle count that can be transformed to system time.

---
 kernel/time/timekeeping.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)
kernel/time/timekeeping.c +20 -4
index d563c19..3f127dd 100644
@@ -298,13 +298,11 @@ u32 (*arch_gettimeoffset)(void) = default_arch_gettimeoffset;
 static inline u32 arch_gettimeoffset(void) { return 0; }
 #endif
 
-static inline s64 timekeeping_get_ns(struct tk_read_base *tkr)
+static inline s64 timekeeping_delta_to_ns(struct tk_read_base *tkr,
+					  cycle_t delta)
 {
-	cycle_t delta;
 	s64 nsec;
 
-	delta = timekeeping_get_delta(tkr);
-
 	nsec = delta * tkr->mult + tkr->xtime_nsec;
 	nsec >>= tkr->shift;
 
@@ -312,6 +310,24 @@ static inline s64 timekeeping_get_ns(struct tk_read_base *tkr)
 	return nsec + arch_gettimeoffset();
 }
 
+static inline s64 timekeeping_get_ns(struct tk_read_base *tkr)
+{
+	cycle_t delta;
+
+	delta = timekeeping_get_delta(tkr);
+	return timekeeping_delta_to_ns(tkr, delta);
+}
+
+static inline s64 timekeeping_cycles_to_ns(struct tk_read_base *tkr,
+					    cycle_t cycles)
+{
+	cycle_t delta;
+
+	/* calculate the delta since the last update_wall_time */
+	delta = clocksource_delta(cycles, tkr->cycle_last, tkr->mask);
+	return timekeeping_delta_to_ns(tkr, delta);
+}
+
 /**
  * update_fast_timekeeper - Update the fast and NMI safe monotonic timekeeper.
  * @tkr: Timekeeping readout base from which we take the update
Signature · 1 line
2.1.4
#2 lore raw

PATCH v6 2/9 Add driver cross timestamp interface for higher precision time synchronization

In reply to Christopher S. Hall

ACKNOWLEDGMENT: The original correlated clock source and cross timestamp code was developed by Thomas Gleixner <[email protected]>. It has changed considerably and any mistakes are mine.

The precision with which events on multiple networked systems can be synchronized using, as an example, PTP (IEEE 1588, 802.1AS) is limited by the precision of the cross timestamps between the system clock and the device (timestamp) clock. Precision here is the degree of simultaneity when capturing the cross timestamp.

Currently the PTP cross timestamp is captured in software using the PTP device driver ioctl PTP_SYS_OFFSET. Reads of the device clock are interleaved with reads of the realtime clock. At best, the precision of this cross timestamp is on the order of several microseconds due to software latencies. Sub-microsecond precision is required for industrial control and some media applications. To achieve this level of precision hardware supported cross timestamping is needed.

Hardware cross timestamps are derived from simultaneously capturing the device clock and the system clock. Applications use timestamps in nanoseconds rather than clock ticks. The device driver can scale device clock ticks to device time in nanoseconds, but cannot transform system clock ticks. Only the kernel timekeeping code can do this. The function get_device_system_crosstimestamp() allows device drivers to return a cross timestamp with system time properly scaled to nanoseconds.

The cross timestamps contain the realtime and monotonic raw clock times. The realtime value is needed to discipline that clock using PTP and the monotonic raw value is used for applications that don't require a "real" time, but need an unadjusted clock time.

The get_device_system_crosstimestamp() code calls back into the driver to ensure that the system counter is within the current timekeeping update interval. Because of possible NTP/PTP frequency adjustments, extrapolating a realtime clock time outside the current interval with a potentially different scaling factor can result in a small amount of error.

Modern Intel hardware provides an Always Running Timer (ART) which is exactly related to TSC through a known frequency ratio. The ART is routed to devices on the system and is used to precisely and simultaneously capture the device clock with the ART.

---
 include/linux/clocksource.h | 12 ++++++++++
 include/linux/timekeeping.h | 35 ++++++++++++++++++++++++++++
 kernel/time/timekeeping.c   | 56 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 103 insertions(+)
include/linux/clocksource.h +12 -0
index 7784b59..4542293 100644
@@ -255,4 +255,16 @@ static inline void clocksource_probe(void) {}
 #define CLOCKSOURCE_ACPI_DECLARE(name, table_id, fn)		\
 	ACPI_DECLARE_PROBE_ENTRY(clksrc, name, table_id, 0, NULL, 0, fn)
 
+/*
+ * struct system_counterval_t - system counter value with the pointer to the
+ *	corresponding clocksource
+ * @cycles:	System counter value
+ * @cs:		Clocksource corresponding to system counter value. Used by
+ *	timekeeping code to verify comparibility of two cycle values
+ */
+struct system_counterval_t {
+	cycle_t			cycles;
+	struct clocksource	*cs;
+};
+
 #endif /* _LINUX_CLOCKSOURCE_H */
include/linux/timekeeping.h +35 -0
index ec89d84..2651e0a 100644
@@ -266,6 +266,41 @@ extern void timekeeping_inject_sleeptime64(struct timespec64 *delta);
 extern void ktime_get_raw_and_real_ts64(struct timespec64 *ts_raw,
 				        struct timespec64 *ts_real);
 
+
+/*
+ * struct system_device_crosststamp - system/device cross-timestamp
+ *	(syncronized 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;
+/*
+ * struct get_sync_device_time_cb - Provides method to capture device time
+ *	synchronized with raw system counter value
+ * @get_time:	Callback providing synchronized capture of device time
+ *		and system counter. Returns 0 on success, < 0 on failure
+ * @ctx:	Context provided to callback function
+ */
+struct sync_device_time_cb {
+	int	(*get_time)(ktime_t *device_time,
+			    struct system_counterval_t *system_counterval,
+			    void *ctx);
+	void	 *ctx;
+};
+
+/*
+ * Get cross timestamp between system clock and device clock
+ */
+extern int get_device_system_crosststamp(struct sync_device_time_cb *cb,
+					 struct system_device_crosststamp *ts);
+
 /*
  * Persistent clock related interfaces
  */
kernel/time/timekeeping.c +56 -0

62 lines not on this page · raw message

Signature · 1 line
2.1.4
maintainer
#3 lore raw

Re: [PATCH v6 2/9] Add driver cross timestamp interface for higher precision time synchronization

The series is a lot easier to follow now. However, the sync_device_time_cb structure isn't serving any useful purpose:

include/linux/timekeeping.h extern void timekeeping_inject_sleeptime64(struct timespec64 *delta); · line 296

Quoted 13 lines
include/linux/timekeeping.h +13 -0
+/*
+ * struct get_sync_device_time_cb - Provides method to capture device time
+ *	synchronized with raw system counter value
+ * @get_time:	Callback providing synchronized capture of device time
+ *		and system counter. Returns 0 on success, < 0 on failure
+ * @ctx:	Context provided to callback function
+ */
+struct sync_device_time_cb {
+	int	(*get_time)(ktime_t *device_time,
+			    struct system_counterval_t *system_counterval,
+			    void *ctx);
+	void	 *ctx;
+};

Why not simply pass the function and context pointers as separate arguments to get_device_system_crosststamp?

include/linux/timekeeping.h extern void timekeeping_inject_sleeptime64(struct timespec64 *delta); · line 302

Quoted 5 lines
include/linux/timekeeping.h +5 -0
+/*
+ * Get cross timestamp between system clock and device clock
+ */
+extern int get_device_system_crosststamp(struct sync_device_time_cb *cb,
+					 struct system_device_crosststamp *ts);

Here is how it looks at the call site (from the last patch):

Review

Quoted 13 lines
(quoted diff) +13 -0
+static int e1000e_phc_getcrosststamp(struct ptp_clock_info *ptp,
+				     struct system_device_crosststamp *xtstamp)
+{
+	struct e1000_adapter *adapter = container_of(ptp, struct e1000_adapter,
+						     ptp_clock_info);
+	struct sync_device_time_cb sync_devicetime;
+	int ret;
+
+	sync_devicetime.get_time = e1000e_phc_get_syncdevicetime;
+	sync_devicetime.ctx = adapter;
+	ret = get_device_system_crosststamp(&sync_devicetime, NULL, xtstamp);
+	return ret;
+}

It is really just busy work to assign the fields of 'sync_devicetime'. If you don't foresee the need of storing the sync_device_time_cb object, then I would just remove the structure altogether. Then the call site will be cleaner, for example:

static int e1000e_phc_getcrosststamp(struct ptp_clock_info *ptp,
struct system_device_crosststamp *xtstamp)

{
	struct e1000_adapter *adapter = container_of(ptp, struct e1000_adapter,
						     ptp_clock_info);

	return get_device_system_crosststamp(e1000e_phc_get_syncdevicetime,
					     adapter, NULL, xtstamp);
}

Thanks,
Richard

#4 lore raw

PATCH v6 3/9 Add correlated clocksource relating aliased auxiliary and system clocks

In reply to Christopher S. Hall

ACKNOWLEDGMENT: The original correlated clock source and cross timestamp code was developed by Thomas Gleixner <[email protected]>. It has changed considerably and any mistakes are mine.

The timekeeping and clocksource code don't currently comprehend two clocks that are aliases of one another. That is clocks that are *exactly* related. The correlated_cs struct encapsulated this relationship between a clocksource and its alias clock. Modern Intel hardware provides an Always Running Timer (ART) which is exactly related to TSC through a known frequency ratio. The ART is an example of a correlated clocksource.

---
 include/linux/clocksource.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
include/linux/clocksource.h +14 -0
index 4542293..726ca68 100644
@@ -267,4 +267,18 @@ struct system_counterval_t {
 	struct clocksource	*cs;
 };
 
+/*
+ * struct correlated_cs - Descriptor for a clocksource correlated to another
+ *	clocksource
+ * @related_cs:		Pointer to the related timekeeping clocksource
+ * @convert:		Conversion function to convert a timestamp from
+ *			the correlated clocksource to cycles of the related
+ *			timekeeping clocksource
+ */
+struct correlated_cs {
+	struct clocksource	*related_cs;
+	cycle_t			(*convert)(struct correlated_cs *cs,
+					   cycle_t cycles);
+};
+
 #endif /* _LINUX_CLOCKSOURCE_H */
Signature · 1 line
2.1.4
#5 lore raw

Re: [PATCH v6 3/9] Add correlated clocksource relating aliased auxiliary and system clocks

Quoted 30 lines · Christopher S. Hall

ACKNOWLEDGMENT: The original correlated clock source and cross timestamp code was developed by Thomas Gleixner <[email protected]>. It has changed considerably and any mistakes are mine.

The timekeeping and clocksource code don't currently comprehend two clocks that are aliases of one another. That is clocks that are *exactly* related. The correlated_cs struct encapsulated this relationship between a clocksource and its alias clock. Modern Intel hardware provides an Always Running Timer (ART) which is exactly related to TSC through a known frequency ratio. The ART is an example of a correlated clocksource.

---
 include/linux/clocksource.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
include/linux/clocksource.h +4 -0
index 4542293..726ca68 100644
@@ -267,4 +267,18 @@ struct system_counterval_t {
        struct clocksource      *cs;
 };
 
+/*
+ * struct correlated_cs - Descriptor for a clocksource correlated to another
+ *     clocksource
+ * @related_cs:                Pointer to the related timekeeping clocksource

include/linux/clocksource.h struct system_counterval_t { · line 283

Quoted 10 lines
include/linux/clocksource.h +10 -0
+ * @convert:           Conversion function to convert a timestamp from
+ *                     the correlated clocksource to cycles of the related
+ *                     timekeeping clocksource
+ */
+struct correlated_cs {
+       struct clocksource      *related_cs;
+       cycle_t                 (*convert)(struct correlated_cs *cs,
+                                          cycle_t cycles);
+};
+

So.. In reworking your patch set, I've preserved this, but I'm still not totally convinced. Its a generic structure, but not used by any generic code and its only used by hardware specific implementations (ie: the tsc and e1000e_hwts logic). It seems like this could be a tsc.h specific structure w/o a real issue.

And really this doesn't seem to be a generic thing. The e1000e hwts is always the ART based. Its not likely these sorts of cross hardware timestamps are going to be completely abstract and interchangeable, is it?

thanks
-john

#6 lore raw

Re: [PATCH v6 3/9] Add correlated clocksource relating aliased auxiliary and system clocks

Quoted 14 lines · John Stultz
Quoted 12 lines · Christopher S. Hall
include/linux/clocksource.h +12 -0
+/*
+ * struct correlated_cs - Descriptor for a clocksource correlated to another
+ *     clocksource
+ * @related_cs:                Pointer to the related timekeeping clocksource
+ * @convert:           Conversion function to convert a timestamp from
+ *                     the correlated clocksource to cycles of the related
+ *                     timekeeping clocksource
+ */
+struct correlated_cs {
+       struct clocksource      *related_cs;
+       cycle_t                 (*convert)(struct correlated_cs *cs,
+                                          cycle_t cycles);
Quoted 8 lines

include/linux/clocksource.h struct system_counterval_t { · line 283

Quoted 2 lines
include/linux/clocksource.h +2 -0
+};
+

So.. In reworking your patch set, I've preserved this, but I'm still not totally convinced. Its a generic structure, but not used by any generic code and its only used by hardware specific implementations (ie: the tsc and e1000e_hwts logic). It seems like this could be a tsc.h specific structure w/o a real issue.

That correlated_cs is my fault. I invented that when I had that first stab on the cross time stamp thing.

Quoted 4 lines

And really this doesn't seem to be a generic thing. The e1000e hwts is always the ART based. Its not likely these sorts of cross hardware timestamps are going to be completely abstract and interchangeable, is it?

They might be in future. I guess other archs will provide similar means to distribute an always on timer to PCIe for timestamping purposes.

So the question is whether we should expose that timestamp reference via a generic mechanism, e.g. store it somewhere in the pci root complex or wherever the appropriate point for it is.

Though for now, we certainly can make that x86 private and deal with it when others come along.

Thanks,

tglx

#7 lore raw

PATCH v6 4/9 Always Running Timer (ART) correlated clocksource

In reply to Christopher S. Hall

On modern Intel systems TSC is derived from the new Always Running Timer (ART). ART can be captured simultaneous to the capture of audio and network device clocks, allowing a correlation between timebases to be constructed. Upon capture, the driver converts the captured ART value to the appropriate system clock using the correlated clocksource mechanism.

On systems that support ART a new CPUID leaf (0x15) returns parameters ?m? and ?n? such that:

TSC_value = (ART_value * m) / n + k [n >= 2]

[k is an offset that can adjusted by a privileged agent. The IA32_TSC_ADJUST MSR is an example of an interface to adjust k. See 17.14.4 of the Intel SDM for more details]

---
 arch/x86/include/asm/cpufeature.h |  2 +-
 arch/x86/include/asm/tsc.h        |  2 ++
 arch/x86/kernel/tsc.c             | 46 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+), 1 deletion(-)
arch/x86/include/asm/cpufeature.h +1 -1
index f7ba9fb..b940fa1 100644
@@ -85,7 +85,7 @@
 #define X86_FEATURE_P4		( 3*32+ 7) /* "" P4 */
 #define X86_FEATURE_CONSTANT_TSC ( 3*32+ 8) /* TSC ticks at a constant rate */
 #define X86_FEATURE_UP		( 3*32+ 9) /* smp kernel running on up */
-/* free, was #define X86_FEATURE_FXSAVE_LEAK ( 3*32+10) * "" FXSAVE leaks FOP/FIP/FOP */
+#define X86_FEATURE_ART		(3*32+10) /* Platform has always running timer (ART) */
 #define X86_FEATURE_ARCH_PERFMON ( 3*32+11) /* Intel Architectural PerfMon */
 #define X86_FEATURE_PEBS	( 3*32+12) /* Precise-Event Based Sampling */
 #define X86_FEATURE_BTS		( 3*32+13) /* Branch Trace Store */
arch/x86/include/asm/tsc.h +2 -0
index 6d7c547..9474c9c 100644
@@ -29,6 +29,8 @@ static inline cycles_t get_cycles(void)
 	return rdtsc();
 }
 
+extern struct correlated_cs art_timestamper;
+
 extern void tsc_init(void);
 extern void mark_tsc_unstable(char *reason);
 extern int unsynchronized_tsc(void);
arch/x86/kernel/tsc.c +46 -0

68 lines not on this page · raw message

Signature · 1 line
2.1.4
#8 lore raw

Re: [PATCH v6 4/9] Always Running Timer (ART) correlated clocksource

Quoted 5 lines · Christopher S. Hall
arch/x86/kernel/tsc.c +0 -0
index c7c4d9c..26dcf63 100644

arch/x86/kernel/tsc.c static struct notifier_block time_cpufreq_notifier_block = { · line 957

Quoted 9 lines
arch/x86/kernel/tsc.c +6 -0
@@ -949,10 +949,36 @@ static struct notifier_block time_cpufreq_notifier_block = {
        .notifier_call  = time_cpufreq_notifier
 };
 
+#define ART_CPUID_LEAF (0x15)
+/* The denominator will never be less that 2 */
+#define ART_MIN_DENOMINATOR (2)
+
+static u32 art_to_tsc_numerator;
+static u32 art_to_tsc_denominator;

This is declared in a #ifdef CONFIG_CPU_FREQ

Quoted 4 lines
arch/x86/kernel/tsc.c +0 -0
@@ -1071,6 +1097,24 @@ int unsynchronized_tsc(void)
        return 0;
 }
 

arch/x86/kernel/tsc.c int unsynchronized_tsc(void) · line 1109

Quoted 10 lines
arch/x86/kernel/tsc.c +10 -0
+/*
+ * Convert ART to TSC given numerator/denominator found in detect_art()
+ */
+static u64 convert_art_to_tsc(struct correlated_cs *cs, u64 cycles)
+{
+       u64 tmp, res;
+
+       res = (cycles / art_to_tsc_denominator) * art_to_tsc_numerator;
+       tmp = (cycles % art_to_tsc_denominator) * art_to_tsc_numerator;
+       res += tmp / art_to_tsc_denominator;

Then used outside of that block.

So this won't build if CPU_FREQ is disabled.

But don't bother to fix that, as I've already done so and I've got a bunch of tweaks I'm making to the code (I figured I'd done enough nit-picking reviews, and probably should just roll my sleeves up and take a swing at how I'd prefer the code look - including Richard's suggestions as well).

I'll send you my revisions here shortly and hopefully you can let me know if anything goes too far and hopefully do some testing with it.

thanks
-john

#9 lore raw

PATCH v6 5/9 Add timekeeping snapshot code capturing system time and counter

In reply to Christopher S. Hall

In the current timekeeping code there isn't any interface to atomically capture the current relationship between the system counter and system time. ktime_get_snapshot() returns this triple (counter, monotonic raw, realtime) in the system_time_snapshot struct.

---
 include/linux/clocksource.h | 13 +++++++++++++
 include/linux/timekeeping.h |  6 ++++++
 kernel/time/timekeeping.c   | 31 +++++++++++++++++++++++++++++++
 3 files changed, 50 insertions(+)
include/linux/clocksource.h +13 -0
index 726ca68..cccbd1c 100644
@@ -281,4 +281,17 @@ struct correlated_cs {
 					   cycle_t cycles);
 };
 
+/*
+ * 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
+ * @raw:	Monotonic raw system time
+ */
+struct system_time_snapshot {
+	cycles_t	cycles;
+	ktime_t		real;
+	ktime_t		raw;
+};
+
 #endif /* _LINUX_CLOCKSOURCE_H */
include/linux/timekeeping.h +6 -0
index 2651e0a..f5fe657 100644
@@ -301,6 +301,12 @@ struct sync_device_time_cb {
 extern int get_device_system_crosststamp(struct sync_device_time_cb *cb,
 					 struct system_device_crosststamp *ts);
 
+struct system_time_snapshot;
+/*
+ * Simultaneously snapshot realtime and monotonic raw clocks
+ */
+extern void ktime_get_snapshot(struct system_time_snapshot *systime_snapshot);
+
 /*
  * Persistent clock related interfaces
  */
kernel/time/timekeeping.c +31 -0
index 84534f8..26049df 100644
@@ -862,6 +862,37 @@ time64_t ktime_get_real_seconds(void)
 }
 EXPORT_SYMBOL_GPL(ktime_get_real_seconds);
 
+/**
+ * ktime_get_snapshot - snapshots the realtime/monotonic raw clocks with counter
+ * @systime_snapshot:	pointer to struct receiving the system time snapshot
+ */
+void ktime_get_snapshot(struct system_time_snapshot *systime_snapshot)
+{
+	struct timekeeper *tk = &tk_core.timekeeper;
+	unsigned long seq;
+	ktime_t base_raw;
+	ktime_t base_real;
+	s64 nsec_raw;
+	s64 nsec_real;
+	cycle_t now;
+
+	do {
+		seq = read_seqcount_begin(&tk_core.seq);
+
+		now = tk->tkr_mono.read(tk->tkr_mono.clock);
+		base_real = ktime_add(tk->tkr_mono.base,
+				      tk_core.timekeeper.offs_real);
+		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));
+
+	systime_snapshot->cycles = now;
+	systime_snapshot->real = ktime_add_ns(base_real, nsec_real);
+	systime_snapshot->raw = ktime_add_ns(base_raw, nsec_raw);
+}
+EXPORT_SYMBOL_GPL(ktime_get_snapshot);
+
 #ifdef CONFIG_NTP_PPS
 
 /**
Signature · 1 line
2.1.4
#10 lore raw

PATCH v6 6/9 Add history to cross timestamp interface supporting slower devices

In reply to Christopher S. Hall

Another representative use case of time sync and the correlated clocksource (in addition to PTP noted above) is PTP synchronized audio.

In a streaming application, as an example, samples will be sent and/or received by multiple devices with a presentation time that is in terms of the PTP master clock. Synchronizing the audio output on these devices requires correlating the audio clock with the PTP master clock. The more precise this correlation is, the better the audio quality (i.e. out of sync audio sounds bad).

From an application standpoint, to correlate the PTP master clock with the audio device clock, the system clock is used as a intermediate timebase. The transforms such an application would perform are:

    System Clock <-> Audio clock
    System Clock <-> Network Device Clock [<-> PTP Master Clock]

Such audio applications make use of some existing ALSA library calls that provide audio/system cross-timestamps (e.g. snd_pcm_status_get_htstamp()). Previous driver implementations capture these cross timestamps by reading the system clock (raw/mono/real) and the device clock with greatest degree of simultaneity possible in software.

Modern Intel platforms can perform a more accurate cross timestamp in hardware (ART,audio device clock). The audio driver requires ART->system time transforms -- the same as required for the network driver. These platforms offload audio processing (including cross-timestamps) to a DSP which to ensure uninterrupted audio processing, communicates and response to the host only once every millsecond. As a result is takes up to a millisecond for the DSP to receive a request, the request is processed by the DSP, the audio output hardware is polled for completion, the result is copied into shared memory, and the host is notified. All of these operation occur on a millisecond cadence. This transaction requires about 2 ms, but under heavier workloads it may take up to 4 ms.

If update_wall_time() is called while waiting for a response within get_device_system_crosststamp() (from previous patch), a retry is attempted. This will occur if the cycle_interval (determined by CONFIG_HZ and mult/shift values) cycles elapse.

Adding a history allows these slow devices the option of providing an ART value outside of the retry loop. In this case, the callback provided is an accessor function for the previously obtained counter value. If get_system_device_crosststamp() receives a counter value previous to cycle_last, it consults the history provided as an argument in history_ref and interpolates the realtime and monotonic raw system time using the provided counter value. If there are any clock discontinuities, e.g. from calling settimeofday(), the monotonic raw time is interpolated in the usual way, but the realtime clock time is adjusted by scaling the monotonic raw adjustment.

When an accessor function is used a history argument *must* be provided. The history is initialized using ktime_get_snapshot() and must be called before the counter values are read.

When the history is used to interpolate timestamp values, the realtime clock time may be inaccurate to some degree. In general, the longer the length of history the larger the interpolation error. If there are discontinuities (large step changes) to the time, the error can be very large.

---
 include/linux/clocksource.h         |   4 ++
 include/linux/timekeeper_internal.h |   2 +
 include/linux/timekeeping.h         |   3 +-
 kernel/time/timekeeping.c           | 130 ++++++++++++++++++++++++++++++++++++
 4 files changed, 138 insertions(+), 1 deletion(-)
include/linux/clocksource.h +4 -0
index cccbd1c..229aee0 100644
@@ -287,11 +287,15 @@ struct correlated_cs {
  * @cycles:	Clocksource counter value to produce the system times
  * @real:	Realtime system time
  * @raw:	Monotonic raw system time
+ * @clock_was_set_seq:	The sequence number of clock was set events
+ * @cs_was_changed_seq:	The sequence number of clocksource change events
  */
 struct system_time_snapshot {
 	cycles_t	cycles;
 	ktime_t		real;
 	ktime_t		raw;
+	unsigned int	clock_was_set_seq;
+	u8		cs_was_changed_seq;
 };
 
 #endif /* _LINUX_CLOCKSOURCE_H */
include/linux/timekeeper_internal.h +2 -0
index 2524722..e880054 100644
@@ -50,6 +50,7 @@ struct tk_read_base {
  * @offs_tai:		Offset clock monotonic -> clock tai
  * @tai_offset:		The current UTC to TAI offset in seconds
  * @clock_was_set_seq:	The sequence number of clock was set events
+ * @cs_was_changed_seq:	The sequence number of clocksource change events
  * @next_leap_ktime:	CLOCK_MONOTONIC time value of a pending leap-second
  * @raw_time:		Monotonic raw base time in timespec64 format
  * @cycle_interval:	Number of clock cycles in one NTP interval
@@ -91,6 +92,7 @@ struct timekeeper {
 	ktime_t			offs_tai;
 	s32			tai_offset;
 	unsigned int		clock_was_set_seq;
+	u8			cs_was_changed_seq;
 	ktime_t			next_leap_ktime;
 	struct timespec64	raw_time;
 
include/linux/timekeeping.h +2 -1
index f5fe657..dff97c4 100644
@@ -295,13 +295,14 @@ struct sync_device_time_cb {
 	void	 *ctx;
 };
 
+struct system_time_snapshot;
 /*
  * Get cross timestamp between system clock and device clock
  */
 extern int get_device_system_crosststamp(struct sync_device_time_cb *cb,
+					 struct system_time_snapshot *history,
 					 struct system_device_crosststamp *ts);
 
-struct system_time_snapshot;
 /*
  * Simultaneously snapshot realtime and monotonic raw clocks
  */
kernel/time/timekeeping.c +130 -0

174 lines not on this page · raw message

Signature · 1 line
2.1.4
#11 lore raw

PATCH v6 7/9 Remove duplicated code in ktime_get_raw_and_real()

In reply to Christopher S. Hall

The code in ktime_get_snapshot() is a superset of the code in ktime_get_raw_and_real() code. Further, ktime_get_raw_and_real() is called only by the PPS code, pps_get_ts(). Consolidate the pps_get_ts() code into a single function calling ktime_get_snapshot() and eliminate ktime_get_raw_and_real(). A side effect of this is that the raw and real results of pps_get_ts() correspond to exactly the same clock cycle. Previously these values represented separate reads of the system clock.

---
 include/linux/pps_kernel.h | 17 ++++++-----------
 kernel/time/timekeeping.c  | 40 ++--------------------------------------
 2 files changed, 8 insertions(+), 49 deletions(-)
include/linux/pps_kernel.h +6 -11
index 54bf148..35ac903 100644
@@ -111,22 +111,17 @@ static inline void timespec_to_pps_ktime(struct pps_ktime *kt,
 	kt->nsec = ts.tv_nsec;
 }
 
-#ifdef CONFIG_NTP_PPS
-
 static inline void pps_get_ts(struct pps_event_time *ts)
 {
-	ktime_get_raw_and_real_ts64(&ts->ts_raw, &ts->ts_real);
-}
+	struct system_time_snapshot snap;
 
-#else /* CONFIG_NTP_PPS */
-
-static inline void pps_get_ts(struct pps_event_time *ts)
-{
-	ktime_get_real_ts64(&ts->ts_real);
+	ktime_get_snapshot(&snap);
+	ts->ts_real = ktime_to_timespec64(snap.real);
+#ifdef CONFIG_NTP_PPS
+	ts->ts_raw = ktime_to_timespec64(snap.raw);
+#endif
 }
 
-#endif /* CONFIG_NTP_PPS */
-
 /* Subtract known time delay from PPS event time(s) */
 static inline void pps_sub_ts(struct pps_event_time *ts, struct timespec64 delta)
 {
kernel/time/timekeeping.c +2 -38
index 54554ac..9975ca4 100644
@@ -877,6 +877,8 @@ void ktime_get_snapshot(struct system_time_snapshot *systime_snapshot)
 	s64 nsec_real;
 	cycle_t now;
 
+	WARN_ON(timekeeping_suspended);
+
 	do {
 		seq = read_seqcount_begin(&tk_core.seq);
 
@@ -896,44 +898,6 @@ void ktime_get_snapshot(struct system_time_snapshot *systime_snapshot)
 }
 EXPORT_SYMBOL_GPL(ktime_get_snapshot);
 
-#ifdef CONFIG_NTP_PPS
-
-/**
- * ktime_get_raw_and_real_ts64 - get day and raw monotonic time in timespec format
- * @ts_raw:	pointer to the timespec to be set to raw monotonic time
- * @ts_real:	pointer to the timespec to be set to the time of day
- *
- * This function reads both the time of day and raw monotonic time at the
- * same time atomically and stores the resulting timestamps in timespec
- * format.
- */
-void ktime_get_raw_and_real_ts64(struct timespec64 *ts_raw, struct timespec64 *ts_real)
-{
-	struct timekeeper *tk = &tk_core.timekeeper;
-	unsigned long seq;
-	s64 nsecs_raw, nsecs_real;
-
-	WARN_ON_ONCE(timekeeping_suspended);
-
-	do {
-		seq = read_seqcount_begin(&tk_core.seq);
-
-		*ts_raw = tk->raw_time;
-		ts_real->tv_sec = tk->xtime_sec;
-		ts_real->tv_nsec = 0;
-
-		nsecs_raw  = timekeeping_get_ns(&tk->tkr_raw);
-		nsecs_real = timekeeping_get_ns(&tk->tkr_mono);
-
-	} while (read_seqcount_retry(&tk_core.seq, seq));
-
-	timespec64_add_ns(ts_raw, nsecs_raw);
-	timespec64_add_ns(ts_real, nsecs_real);
-}
-EXPORT_SYMBOL(ktime_get_raw_and_real_ts64);
-
-#endif /* CONFIG_NTP_PPS */
-
 /**
  * adjust_historical_crosststamp - adjust crosstimestamp previous to current interval
  * @total_history_cycles:	Total history length in cycles
Signature · 1 line
2.1.4
#12 lore raw

PATCH v6 8/9 Add PTP_SYS_OFFSET_PRECISE for driver crosstimestamping

In reply to Christopher S. Hall

Currently, network /system cross-timestamping is performed in the PTP_SYS_OFFSET ioctl. The PTP clock driver reads gettimeofday() and the gettime64() callback provided by the driver. The cross-timestamp is best effort where the latency between the capture of system time (getnstimeofday()) and the device time (driver callback) may be significant.

The getcrosststamp() callback and corresponding PTP_SYS_OFFSET_PRECISE ioctl allows the driver to perform this device/system correlation when for example cross timestamp hardware is available. Modern Intel systems can do this for onboard Ethernet controllers using the ART counter. There is virtually zero latency between captures of the ART and network device clock.

The capabilities ioctl (PTP_CLOCK_GETCAPS), is augmented allowing applications to query whether or not drivers implement the getcrosststamp callback, providing more precise cross timestamping.

---
 Documentation/ptp/testptp.c      |  6 ++++--
 drivers/ptp/ptp_chardev.c        | 27 +++++++++++++++++++++++++++
 include/linux/ptp_clock_kernel.h |  8 ++++++++
 include/uapi/linux/ptp_clock.h   | 13 ++++++++++++-
 4 files changed, 51 insertions(+), 3 deletions(-)
Documentation/ptp/testptp.c +4 -2
index 6c6247a..d99012f 100644
@@ -277,13 +277,15 @@ int main(int argc, char *argv[])
 			       "  %d external time stamp channels\n"
 			       "  %d programmable periodic signals\n"
 			       "  %d pulse per second\n"
-			       "  %d programmable pins\n",
+			       "  %d programmable pins\n"
+			       "  %d cross timestamping\n",
 			       caps.max_adj,
 			       caps.n_alarm,
 			       caps.n_ext_ts,
 			       caps.n_per_out,
 			       caps.pps,
-			       caps.n_pins);
+			       caps.n_pins,
+			       caps.cross_timestamping);
 		}
 	}
 
drivers/ptp/ptp_chardev.c +27 -0
index da7bae9..579fd65 100644
@@ -22,6 +22,7 @@
 #include <linux/poll.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
+#include <linux/timekeeping.h>
 
 #include "ptp_private.h"
 
@@ -120,11 +121,13 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)
 	struct ptp_clock_caps caps;
 	struct ptp_clock_request req;
 	struct ptp_sys_offset *sysoff = NULL;
+	struct ptp_sys_offset_precise precise_offset;
 	struct ptp_pin_desc pd;
 	struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock);
 	struct ptp_clock_info *ops = ptp->info;
 	struct ptp_clock_time *pct;
 	struct timespec64 ts;
+	struct system_device_crosststamp xtstamp;
 	int enable, err = 0;
 	unsigned int i, pin_index;
 
@@ -138,6 +141,7 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)
 		caps.n_per_out = ptp->info->n_per_out;
 		caps.pps = ptp->info->pps;
 		caps.n_pins = ptp->info->n_pins;
+		caps.cross_timestamping = ptp->info->getcrosststamp != NULL;
 		if (copy_to_user((void __user *)arg, &caps, sizeof(caps)))
 			err = -EFAULT;
 		break;
@@ -180,6 +184,29 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)
 		err = ops->enable(ops, &req, enable);
 		break;
 
+	case PTP_SYS_OFFSET_PRECISE:
+		if (!ptp->info->getcrosststamp) {
+			err = -EOPNOTSUPP;
+			break;
+		}
+		err = ptp->info->getcrosststamp(ptp->info, &xtstamp);
+		if (err)
+			break;
+
+		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);
+		precise_offset.sys_realtime.sec = ts.tv_sec;
+		precise_offset.sys_realtime.nsec = ts.tv_nsec;
+		ts = ktime_to_timespec64(xtstamp.sys_monoraw);
+		precise_offset.sys_monoraw.sec = ts.tv_sec;
+		precise_offset.sys_monoraw.nsec = ts.tv_nsec;
+		if (copy_to_user((void __user *)arg, &precise_offset,
+				 sizeof(precise_offset)))
+			err = -EFAULT;
+		break;
+
 	case PTP_SYS_OFFSET:
 		sysoff = kmalloc(sizeof(*sysoff), GFP_KERNEL);
 		if (!sysoff) {
include/linux/ptp_clock_kernel.h +8 -0
index b8b7306..6b15e16 100644
@@ -38,6 +38,7 @@ struct ptp_clock_request {
 	};
 };
 
+struct system_device_crosststamp;
 /**
  * struct ptp_clock_info - decribes a PTP hardware clock
  *
@@ -67,6 +68,11 @@ struct ptp_clock_request {
  * @gettime64:  Reads the current time from the hardware clock.
  *              parameter ts: Holds the result.
  *
+ * @getcrosststamp:  Reads the current time from the hardware clock and
+ *                   system clock simultaneously.
+ *                   parameter cts: Contains timestamp (device,system) pair,
+ *                   where system time is realtime and monotonic.
+ *
  * @settime64:  Set the current time on the hardware clock.
  *              parameter ts: Time value to set.
  *
@@ -105,6 +111,8 @@ struct ptp_clock_info {
 	int (*adjfreq)(struct ptp_clock_info *ptp, s32 delta);
 	int (*adjtime)(struct ptp_clock_info *ptp, s64 delta);
 	int (*gettime64)(struct ptp_clock_info *ptp, struct timespec64 *ts);
+	int (*getcrosststamp)(struct ptp_clock_info *ptp,
+			      struct system_device_crosststamp *cts);
 	int (*settime64)(struct ptp_clock_info *p, const struct timespec64 *ts);
 	int (*enable)(struct ptp_clock_info *ptp,
 		      struct ptp_clock_request *request, int on);
include/uapi/linux/ptp_clock.h +12 -1
index f0b7bfe..ac6dded 100644
@@ -51,7 +51,9 @@ struct ptp_clock_caps {
 	int n_per_out; /* Number of programmable periodic signals. */
 	int pps;       /* Whether the clock supports a PPS callback. */
 	int n_pins;    /* Number of input/output pins. */
-	int rsv[14];   /* Reserved for future use. */
+	/* Whether the clock supports precise system-device cross timestamps */
+	int cross_timestamping;
+	int rsv[13];   /* Reserved for future use. */
 };
 
 struct ptp_extts_request {
@@ -81,6 +83,13 @@ struct ptp_sys_offset {
 	struct ptp_clock_time ts[2 * PTP_MAX_SAMPLES + 1];
 };
 
+struct ptp_sys_offset_precise {
+	struct ptp_clock_time device;
+	struct ptp_clock_time sys_realtime;
+	struct ptp_clock_time sys_monoraw;
+	unsigned int rsv[4];    /* Reserved for future use. */
+};
+
 enum ptp_pin_function {
 	PTP_PF_NONE,
 	PTP_PF_EXTTS,
@@ -124,6 +133,8 @@ struct ptp_pin_desc {
 #define PTP_SYS_OFFSET     _IOW(PTP_CLK_MAGIC, 5, struct ptp_sys_offset)
 #define PTP_PIN_GETFUNC    _IOWR(PTP_CLK_MAGIC, 6, struct ptp_pin_desc)
 #define PTP_PIN_SETFUNC    _IOW(PTP_CLK_MAGIC, 7, struct ptp_pin_desc)
+#define PTP_SYS_OFFSET_PRECISE \
+	_IOWR(PTP_CLK_MAGIC, 8, struct ptp_sys_offset_precise)
 
 struct ptp_extts_event {
 	struct ptp_clock_time t; /* Time event occured. */
Signature · 1 line
2.1.4
maintainer Acked-by on v6 8/9
#13 lore raw

Re: [PATCH v6 8/9] Add PTP_SYS_OFFSET_PRECISE for driver crosstimestamping

Quoted 6 lines · Christopher S. Hall

Currently, network /system cross-timestamping is performed in the PTP_SYS_OFFSET ioctl. The PTP clock driver reads gettimeofday() and the gettime64() callback provided by the driver. The cross-timestamp is best effort where the latency between the capture of system time (getnstimeofday()) and the device time (driver callback) may be significant.

Looks good to me.

#14 lore raw

PATCH v6 9/9 Adds hardware supported cross timestamp

In reply to Christopher S. Hall

Modern Intel systems supports cross timestamping of the network device clock and Always Running Timer (ART) in hardware. This allows the device time and system time to be precisely correlated. The timestamp pair is returned through e1000e_phc_get_syncdevicetime() used by get_system_device_crosststamp(). The hardware cross-timestamp result is made available to applications through the PTP_SYS_OFFSET_PRECISE ioctl which calls e1000e_phc_getcrosststamp().

---
 drivers/net/ethernet/intel/Kconfig          |  9 +++
 drivers/net/ethernet/intel/e1000e/defines.h |  5 ++
 drivers/net/ethernet/intel/e1000e/ptp.c     | 88 +++++++++++++++++++++++++++++
 drivers/net/ethernet/intel/e1000e/regs.h    |  4 ++
 4 files changed, 106 insertions(+)
drivers/net/ethernet/intel/Kconfig +9 -0
index 4163b16..62bbddc 100644
@@ -83,6 +83,15 @@ config E1000E
 	  To compile this driver as a module, choose M here. The module
 	  will be called e1000e.
 
+config E1000E_HWTS
+	bool "Support HW cross-timestamp on PCH devices"
+	default y
+	depends on E1000E && X86
+	---help---
+	 Say Y to enable hardware supported cross-timestamping on PCH
+	 devices. The cross-timestamp is available through the PTP clock
+	 driver precise cross-timestamp ioctl (PTP_SYS_OFFSET_PRECISE).
+
 config IGB
 	tristate "Intel(R) 82575/82576 PCI-Express Gigabit Ethernet support"
 	depends on PCI
drivers/net/ethernet/intel/e1000e/defines.h +5 -0
index 133d407..13cff75 100644
@@ -527,6 +527,11 @@
 #define E1000_RXCW_C          0x20000000        /* Receive config */
 #define E1000_RXCW_SYNCH      0x40000000        /* Receive config synch */
 
+/* HH Time Sync */
+#define E1000_TSYNCTXCTL_MAX_ALLOWED_DLY_MASK	0x0000F000 /* max delay */
+#define E1000_TSYNCTXCTL_SYNC_COMP		0x40000000 /* sync complete */
+#define E1000_TSYNCTXCTL_START_SYNC		0x80000000 /* initiate sync */
+
 #define E1000_TSYNCTXCTL_VALID		0x00000001 /* Tx timestamp valid */
 #define E1000_TSYNCTXCTL_ENABLED	0x00000010 /* enable Tx timestamping */
 
drivers/net/ethernet/intel/e1000e/ptp.c +88 -0

106 lines not on this page · raw message

drivers/net/ethernet/intel/e1000e/regs.h +4 -0
index 1d5e0b7..0cb4d36 100644
@@ -245,6 +245,10 @@
 #define E1000_SYSTIML	0x0B600	/* System time register Low - RO */
 #define E1000_SYSTIMH	0x0B604	/* System time register High - RO */
 #define E1000_TIMINCA	0x0B608	/* Increment attributes register - RW */
+#define E1000_SYSSTMPL  0x0B648 /* HH Timesync system stamp low register */
+#define E1000_SYSSTMPH  0x0B64C /* HH Timesync system stamp hi register */
+#define E1000_PLTSTMPL  0x0B640 /* HH Timesync platform stamp low register */
+#define E1000_PLTSTMPH  0x0B644 /* HH Timesync platform stamp hi register */
 #define E1000_RXMTRL	0x0B634	/* Time sync Rx EtherType and Msg Type - RW */
 #define E1000_RXUDP	0x0B638	/* Time Sync Rx UDP Port - RW */
 
Signature · 1 line
2.1.4
#15 lore raw
In reply to Christopher S. Hall
Quoted 7 lines · Christopher S. Hall

Modern Intel hardware adds an Always Running Timer (ART) that allows the network and audio device clocks to precisely cross timestamp the device clock with the system clock. This allows a precise correlation of the device time and system time.

This patchset adds interfaces to the timekeeping code allowing drivers to translate ART time to system time.

So thanks again for sending this out. Instead of sending you a bunch of nitpicky changes as I've done in the past, I figured I'd try to more directly help out and try to rework some of the patches to be more to my own liking.

I've pushed them here:
https://git.linaro.org/people/john.stultz/linux.git dev/xtimestamp

My main changes have been:
* Reordered the patches, putting all the timekeeping core changes first, then the usage of those interfaces last.

* Implemented Richard's suggestion to drop one of the helper structures that didn't provide much value

* Moved structures defined in clocksource.h but only used in timekeeping.h to timekeeping.h

* Fixed a few build issues I caught (as well as some of the ones kbuild bot found)

* Reworked the tsc logic to avoid 64bit divisions (which don't build on 32bit systems)

I still have not:
* Done *any* testing at all with this. Please verify I didn't break anything. :)

* Fixed the 64bit div on 32bit systems build issue in get_device_system_crosststamp()/adjust_historical_crosststamp()

* Done another review/edit pass on the commit messages, as they've gotten a bit long (I know, I know.. "be verbose" I said!), but they can probably be tweaked to be better and more contextual to the patches.

Still on the fence:
* Probably should zap the correlated_cs structure or move it to tsc.h, as mentioned in my other email

Anyway, I'll let you take a look at this and feel free to integrate and adapt these ideas as you please into your patchset. Look forward to your next revision!

thanks
-john