[patch 25/26] timekeeping: Provide update for PTP timekeepers

Thomas Gleixner posted 26 patches 7 months ago
[patch 25/26] timekeeping: Provide update for PTP timekeepers
Posted by Thomas Gleixner 7 months ago
Update the PTP timekeepers periodically. For now this is tied to the system
timekeeper update from the tick. This might be revisited.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 kernel/time/timekeeping.c |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
---
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -130,9 +130,11 @@ static struct tk_fast tk_fast_raw  ____c
 
 #ifdef CONFIG_POSIX_PTP_CLOCKS
 static __init void tk_ptp_setup(void);
+static void tk_ptp_advance(void);
 static void tk_ptp_update_clocksource(void);
 #else
 static inline void tk_ptp_setup(void) { }
+static inline void tk_ptp_advance(void) { }
 static inline void tk_ptp_update_clocksource(void) { }
 #endif
 
@@ -2312,11 +2314,13 @@ static bool timekeeping_advance(enum tim
 /**
  * update_wall_time - Uses the current clocksource to increment the wall time
  *
+ * It also updates eventually installed PTP clock timekeepers
  */
 void update_wall_time(void)
 {
 	if (timekeeping_advance(TK_ADV_TICK))
 		clock_was_set_delayed();
+	tk_ptp_advance();
 }
 
 /**
@@ -2762,6 +2766,20 @@ static void tk_ptp_update_clocksource(vo
 	}
 }
 
+static void tk_ptp_advance(void)
+{
+	unsigned long active = READ_ONCE(ptp_timekeepers);
+	unsigned int id;
+
+	for_each_set_bit(id, &active, BITS_PER_LONG) {
+		struct tk_data *tkd = &timekeeper_data[id + TIMEKEEPER_PTP];
+
+		guard(raw_spinlock)(&tkd->lock);
+		if (tkd->shadow_timekeeper.clock_valid)
+			__timekeeping_advance(tkd, TK_ADV_TICK);
+	}
+}
+
 /**
  * ktime_get_ptp - Get TAI time for a PTP clock
  * @id:	ID of the clock to read (CLOCK_PTP...)