Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

vdso/gettimeofday: Introduce vdso_set_timespec()

This code is duplicated and with the introduction of auxiliary clocks will
be duplicated even more.

Introduce a helper.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/20250701-vdso-auxclock-v1-8-df7d9f87b9b8@linutronix.de

authored by

Thomas Weißschuh and committed by
Thomas Gleixner
381d96cc 1a1cd5fe

+14 -18
+14 -18
lib/vdso/gettimeofday.c
··· 77 77 return likely((u32) clock < MAX_CLOCKS); 78 78 } 79 79 80 + /* 81 + * Must not be invoked within the sequence read section as a race inside 82 + * that loop could result in __iter_div_u64_rem() being extremely slow. 83 + */ 84 + static __always_inline void vdso_set_timespec(struct __kernel_timespec *ts, u64 sec, u64 ns) 85 + { 86 + ts->tv_sec = sec + __iter_div_u64_rem(ns, NSEC_PER_SEC, &ns); 87 + ts->tv_nsec = ns; 88 + } 89 + 80 90 #ifdef CONFIG_TIME_NS 81 91 82 92 #ifdef CONFIG_GENERIC_VDSO_DATA_STORE ··· 132 122 sec += offs->sec; 133 123 ns += offs->nsec; 134 124 135 - /* 136 - * Do this outside the loop: a race inside the loop could result 137 - * in __iter_div_u64_rem() being extremely slow. 138 - */ 139 - ts->tv_sec = sec + __iter_div_u64_rem(ns, NSEC_PER_SEC, &ns); 140 - ts->tv_nsec = ns; 125 + vdso_set_timespec(ts, sec, ns); 141 126 142 127 return true; 143 128 } ··· 193 188 sec = vdso_ts->sec; 194 189 } while (unlikely(vdso_read_retry(vc, seq))); 195 190 196 - /* 197 - * Do this outside the loop: a race inside the loop could result 198 - * in __iter_div_u64_rem() being extremely slow. 199 - */ 200 - ts->tv_sec = sec + __iter_div_u64_rem(ns, NSEC_PER_SEC, &ns); 201 - ts->tv_nsec = ns; 191 + vdso_set_timespec(ts, sec, ns); 202 192 203 193 return true; 204 194 } ··· 223 223 sec += offs->sec; 224 224 nsec += offs->nsec; 225 225 226 - /* 227 - * Do this outside the loop: a race inside the loop could result 228 - * in __iter_div_u64_rem() being extremely slow. 229 - */ 230 - ts->tv_sec = sec + __iter_div_u64_rem(nsec, NSEC_PER_SEC, &nsec); 231 - ts->tv_nsec = nsec; 226 + vdso_set_timespec(ts, sec, nsec); 227 + 232 228 return true; 233 229 } 234 230 #else