timekeeping: Move shadow_timekeeper into tk_core
authorThomas Gleixner <tglx@linutronix.de>
Wed, 9 Oct 2024 08:29:00 +0000 (10:29 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Fri, 25 Oct 2024 17:49:13 +0000 (19:49 +0200)
tk_core requires shadow_timekeeper to allow timekeeping_advance() updating
without holding the timekeeper sequence count write locked. This allows the
readers to make progress up to the actual update where the shadow
timekeeper is copied over to the real timekeeper.

As long as there is only a single timekeeper, having them separate is
fine. But when the timekeeper infrastructure will be reused for per ptp
clock timekeepers, shadow_timekeeper needs to be part of tk_core.

No functional change.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: John Stultz <jstultz@google.com>
Link: https://lore.kernel.org/all/20241009-devel-anna-maria-b4-timers-ptp-timekeeping-v2-7-554456a44a15@linutronix.de
kernel/time/timekeeping.c

index cfb718dec737dd75a65f4307565831edd84b289f..848d2b18f8002a667c7ed39c3f9ce0e44b1bdb7a 100644 (file)
@@ -50,11 +50,11 @@ DEFINE_RAW_SPINLOCK(timekeeper_lock);
 static struct {
        seqcount_raw_spinlock_t seq;
        struct timekeeper       timekeeper;
+       struct timekeeper       shadow_timekeeper;
 } tk_core ____cacheline_aligned = {
        .seq = SEQCNT_RAW_SPINLOCK_ZERO(tk_core.seq, &timekeeper_lock),
 };
 
-static struct timekeeper shadow_timekeeper;
 
 /* flag for if timekeeping is suspended */
 int __read_mostly timekeeping_suspended;
@@ -795,8 +795,7 @@ static void timekeeping_update(struct timekeeper *tk, unsigned int action)
         * timekeeper structure on the next update with stale data
         */
        if (action & TK_MIRROR)
-               memcpy(&shadow_timekeeper, &tk_core.timekeeper,
-                      sizeof(tk_core.timekeeper));
+               memcpy(&tk_core.shadow_timekeeper, &tk_core.timekeeper, sizeof(tk_core.timekeeper));
 }
 
 /**
@@ -2305,8 +2304,8 @@ static u64 logarithmic_accumulation(struct timekeeper *tk, u64 offset,
  */
 static bool timekeeping_advance(enum timekeeping_adv_mode mode)
 {
+       struct timekeeper *tk = &tk_core.shadow_timekeeper;
        struct timekeeper *real_tk = &tk_core.timekeeper;
-       struct timekeeper *tk = &shadow_timekeeper;
        unsigned int clock_set = 0;
        int shift = 0, maxshift;
        u64 offset;