Skip to content

Commit e6d4c00

Browse files
committed
timekeeping: Provide update for auxiliary timekeepers
Update the auxiliary timekeepers periodically. For now this is tied to the system timekeeper update from the tick. This might be revisited and moved out of the tick. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: John Stultz <jstultz@google.com> Link: https://lore.kernel.org/all/20250625183758.382451331@linutronix.de
1 parent ecf3e70 commit e6d4c00

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

kernel/time/timekeeping.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,11 @@ static struct tk_fast tk_fast_raw ____cacheline_aligned = {
131131
#ifdef CONFIG_POSIX_AUX_CLOCKS
132132
static __init void tk_aux_setup(void);
133133
static void tk_aux_update_clocksource(void);
134+
static void tk_aux_advance(void);
134135
#else
135136
static inline void tk_aux_setup(void) { }
136137
static inline void tk_aux_update_clocksource(void) { }
138+
static inline void tk_aux_advance(void) { }
137139
#endif
138140

139141
unsigned long timekeeper_lock_irqsave(void)
@@ -2317,11 +2319,13 @@ static bool timekeeping_advance(enum timekeeping_adv_mode mode)
23172319
/**
23182320
* update_wall_time - Uses the current clocksource to increment the wall time
23192321
*
2322+
* It also updates the enabled auxiliary clock timekeepers
23202323
*/
23212324
void update_wall_time(void)
23222325
{
23232326
if (timekeeping_advance(TK_ADV_TICK))
23242327
clock_was_set_delayed();
2328+
tk_aux_advance();
23252329
}
23262330

23272331
/**
@@ -2764,6 +2768,21 @@ static void tk_aux_update_clocksource(void)
27642768
}
27652769
}
27662770

2771+
static void tk_aux_advance(void)
2772+
{
2773+
unsigned long active = READ_ONCE(aux_timekeepers);
2774+
unsigned int id;
2775+
2776+
/* Lockless quick check to avoid extra cache lines */
2777+
for_each_set_bit(id, &active, BITS_PER_LONG) {
2778+
struct tk_data *aux_tkd = &timekeeper_data[id + TIMEKEEPER_AUX_FIRST];
2779+
2780+
guard(raw_spinlock)(&aux_tkd->lock);
2781+
if (aux_tkd->shadow_timekeeper.clock_valid)
2782+
__timekeeping_advance(aux_tkd, TK_ADV_TICK);
2783+
}
2784+
}
2785+
27672786
/**
27682787
* ktime_get_aux - Get time for a AUX clock
27692788
* @id: ID of the clock to read (CLOCK_AUX...)

0 commit comments

Comments
 (0)