Skip to content

Commit 6ab41fc

Browse files
committed
Merge tag 'timers-urgent-2025-09-07' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull timer fix from Ingo Molnar: "Fix a severe slowdown regression in the timer vDSO code related to the while() loop in __iter_div_u64_rem(), when the AUX-clock is enabled" * tag 'timers-urgent-2025-09-07' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: vdso/vsyscall: Avoid slow division loop in auxiliary clock update
2 parents b7369eb + 762af5a commit 6ab41fc

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

include/linux/timekeeper_internal.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ struct tk_read_base {
7676
* @cs_was_changed_seq: The sequence number of clocksource change events
7777
* @clock_valid: Indicator for valid clock
7878
* @monotonic_to_boot: CLOCK_MONOTONIC to CLOCK_BOOTTIME offset
79+
* @monotonic_to_aux: CLOCK_MONOTONIC to CLOCK_AUX offset
7980
* @cycle_interval: Number of clock cycles in one NTP interval
8081
* @xtime_interval: Number of clock shifted nano seconds in one NTP
8182
* interval.
@@ -117,6 +118,9 @@ struct tk_read_base {
117118
* @offs_aux is used by the auxiliary timekeepers which do not utilize any
118119
* of the regular timekeeper offset fields.
119120
*
121+
* @monotonic_to_aux is a timespec64 representation of @offs_aux to
122+
* accelerate the VDSO update for CLOCK_AUX.
123+
*
120124
* The cacheline ordering of the structure is optimized for in kernel usage of
121125
* the ktime_get() and ktime_get_ts64() family of time accessors. Struct
122126
* timekeeper is prepended in the core timekeeping code with a sequence count,
@@ -159,7 +163,10 @@ struct timekeeper {
159163
u8 cs_was_changed_seq;
160164
u8 clock_valid;
161165

162-
struct timespec64 monotonic_to_boot;
166+
union {
167+
struct timespec64 monotonic_to_boot;
168+
struct timespec64 monotonic_to_aux;
169+
};
163170

164171
u64 cycle_interval;
165172
u64 xtime_interval;

kernel/time/timekeeping.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ static inline bool tk_is_aux(const struct timekeeper *tk)
8383
}
8484
#endif
8585

86+
static inline void tk_update_aux_offs(struct timekeeper *tk, ktime_t offs)
87+
{
88+
tk->offs_aux = offs;
89+
tk->monotonic_to_aux = ktime_to_timespec64(offs);
90+
}
91+
8692
/* flag for if timekeeping is suspended */
8793
int __read_mostly timekeeping_suspended;
8894

@@ -1506,7 +1512,7 @@ static int __timekeeping_inject_offset(struct tk_data *tkd, const struct timespe
15061512
timekeeping_restore_shadow(tkd);
15071513
return -EINVAL;
15081514
}
1509-
tks->offs_aux = offs;
1515+
tk_update_aux_offs(tks, offs);
15101516
}
15111517

15121518
timekeeping_update_from_shadow(tkd, TK_UPDATE_ALL);
@@ -2937,7 +2943,7 @@ static int aux_clock_set(const clockid_t id, const struct timespec64 *tnew)
29372943
* xtime ("realtime") is not applicable for auxiliary clocks and
29382944
* kept in sync with "monotonic".
29392945
*/
2940-
aux_tks->offs_aux = ktime_sub(timespec64_to_ktime(*tnew), tnow);
2946+
tk_update_aux_offs(aux_tks, ktime_sub(timespec64_to_ktime(*tnew), tnow));
29412947

29422948
timekeeping_update_from_shadow(aux_tkd, TK_UPDATE_ALL);
29432949
return 0;

kernel/time/vsyscall.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,10 @@ void vdso_time_update_aux(struct timekeeper *tk)
159159
if (clock_mode != VDSO_CLOCKMODE_NONE) {
160160
fill_clock_configuration(vc, &tk->tkr_mono);
161161

162-
vdso_ts->sec = tk->xtime_sec;
162+
vdso_ts->sec = tk->xtime_sec + tk->monotonic_to_aux.tv_sec;
163163

164164
nsec = tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift;
165-
nsec += tk->offs_aux;
165+
nsec += tk->monotonic_to_aux.tv_nsec;
166166
vdso_ts->sec += __iter_div_u64_rem(nsec, NSEC_PER_SEC, &nsec);
167167
nsec = nsec << tk->tkr_mono.shift;
168168
vdso_ts->nsec = nsec;

0 commit comments

Comments
 (0)