[patch 05/26] time: Introduce PTP clocks

Thomas Gleixner posted 26 patches 7 months ago
[patch 05/26] time: Introduce PTP clocks
Posted by Thomas Gleixner 7 months ago
From: Anna-Maria Behnsen <anna-maria@linutronix.de>

To support per PTP clock timekeeping and the related user space interfaces,
it's required to define a clock ID range for them.

Reserve 8 PTP clock IDs after the regular timekeeping clock ID space.

This is the maximum number of PTP clocks the kernel can support. The actual
number of supported clocks depends obviously on the presence of PTP devices
and might be constraint by the available VDSO space.

Add the corresponding timekeeper IDs as well.

Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

---
 include/linux/timekeeper_internal.h |    6 ++++++
 include/uapi/linux/time.h           |   10 ++++++++++
 kernel/time/Kconfig                 |    3 +++
 3 files changed, 19 insertions(+)
---
--- a/include/linux/timekeeper_internal.h
+++ b/include/linux/timekeeper_internal.h
@@ -14,10 +14,16 @@
 /**
  * timekeeper_ids - IDs for various time keepers in the kernel
  * @TIMEKEEPER_CORE:	The central core timekeeper managing system time
+ * @TIMEKEEPER_PTP:	The first PTP timekeeper
+ * @TIMEKEEPER_PTP_LAST:The last PTP timekeeper
  * @TIMEKEEPERS_MAX:	The maximum number of timekeepers managed
  */
 enum timekeeper_ids {
 	TIMEKEEPER_CORE,
+#ifdef CONFIG_POSIX_PTP_CLOCKS
+	TIMEKEEPER_PTP,
+	TIMEKEEPER_PTP_LAST = TIMEKEEPER_PTP + MAX_PTP_CLOCKS - 1,
+#endif
 	TIMEKEEPERS_MAX,
 };
 
--- a/include/uapi/linux/time.h
+++ b/include/uapi/linux/time.h
@@ -64,6 +64,16 @@ struct timezone {
 #define CLOCK_TAI			11
 
 #define MAX_CLOCKS			16
+
+/*
+ * PTP clock support. PTP clocks are dynamically configured by associating
+ * a clock ID to a PTP device. The kernel can support up to 16 PTP clocks,
+ * but the actual limit depends on architecture constraints vs. VDSO.
+ */
+#define	CLOCK_PTP			MAX_CLOCKS
+#define	MAX_PTP_CLOCKS			8
+#define CLOCK_PTP_LAST			(CLOCK_PTP + MAX_PTP_CLOCKS - 1)
+
 #define CLOCKS_MASK			(CLOCK_REALTIME | CLOCK_MONOTONIC)
 #define CLOCKS_MONO			CLOCK_MONOTONIC
 
--- a/kernel/time/Kconfig
+++ b/kernel/time/Kconfig
@@ -57,6 +57,9 @@ config POSIX_CPU_TIMERS_TASK_WORK
 	bool
 	default y if POSIX_TIMERS && HAVE_POSIX_CPU_TIMERS_TASK_WORK
 
+config POSIX_PTP_CLOCKS
+	def_bool POSIX_TIMERS && PTP_1588_CLOCK
+
 config LEGACY_TIMER_TICK
 	bool
 	help