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_get_timestamp()

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-9-df7d9f87b9b8@linutronix.de

authored by

Thomas Weißschuh and committed by
Thomas Gleixner
562f03ed 381d96cc

+24 -19
+24 -19
lib/vdso/gettimeofday.c
··· 87 87 ts->tv_nsec = ns; 88 88 } 89 89 90 + static __always_inline 91 + bool vdso_get_timestamp(const struct vdso_time_data *vd, const struct vdso_clock *vc, 92 + unsigned int clkidx, u64 *sec, u64 *ns) 93 + { 94 + const struct vdso_timestamp *vdso_ts = &vc->basetime[clkidx]; 95 + u64 cycles; 96 + 97 + if (unlikely(!vdso_clocksource_ok(vc))) 98 + return false; 99 + 100 + cycles = __arch_get_hw_counter(vc->clock_mode, vd); 101 + if (unlikely(!vdso_cycles_ok(cycles))) 102 + return false; 103 + 104 + *ns = vdso_calc_ns(vc, cycles, vdso_ts->nsec); 105 + *sec = vdso_ts->sec; 106 + 107 + return true; 108 + } 109 + 90 110 #ifdef CONFIG_TIME_NS 91 111 92 112 #ifdef CONFIG_GENERIC_VDSO_DATA_STORE ··· 124 104 const struct vdso_time_data *vd = __arch_get_vdso_u_timens_data(vdns); 125 105 const struct timens_offset *offs = &vcns->offset[clk]; 126 106 const struct vdso_clock *vc = vd->clock_data; 127 - const struct vdso_timestamp *vdso_ts; 128 - u64 cycles, ns; 129 107 u32 seq; 130 108 s64 sec; 109 + u64 ns; 131 110 132 111 if (clk != CLOCK_MONOTONIC_RAW) 133 112 vc = &vc[CS_HRES_COARSE]; 134 113 else 135 114 vc = &vc[CS_RAW]; 136 - vdso_ts = &vc->basetime[clk]; 137 115 138 116 do { 139 117 seq = vdso_read_begin(vc); 140 118 141 - if (unlikely(!vdso_clocksource_ok(vc))) 119 + if (!vdso_get_timestamp(vd, vc, clk, &sec, &ns)) 142 120 return false; 143 - 144 - cycles = __arch_get_hw_counter(vc->clock_mode, vd); 145 - if (unlikely(!vdso_cycles_ok(cycles))) 146 - return false; 147 - ns = vdso_calc_ns(vc, cycles, vdso_ts->nsec); 148 - sec = vdso_ts->sec; 149 121 } while (unlikely(vdso_read_retry(vc, seq))); 150 122 151 123 /* Add the namespace offset */ ··· 167 155 bool do_hres(const struct vdso_time_data *vd, const struct vdso_clock *vc, 168 156 clockid_t clk, struct __kernel_timespec *ts) 169 157 { 170 - const struct vdso_timestamp *vdso_ts = &vc->basetime[clk]; 171 - u64 cycles, sec, ns; 158 + u64 sec, ns; 172 159 u32 seq; 173 160 174 161 /* Allows to compile the high resolution parts out */ ··· 194 183 } 195 184 smp_rmb(); 196 185 197 - if (unlikely(!vdso_clocksource_ok(vc))) 186 + if (!vdso_get_timestamp(vd, vc, clk, &sec, &ns)) 198 187 return false; 199 - 200 - cycles = __arch_get_hw_counter(vc->clock_mode, vd); 201 - if (unlikely(!vdso_cycles_ok(cycles))) 202 - return false; 203 - ns = vdso_calc_ns(vc, cycles, vdso_ts->nsec); 204 - sec = vdso_ts->sec; 205 188 } while (unlikely(vdso_read_retry(vc, seq))); 206 189 207 190 vdso_set_timespec(ts, sec, ns);