[PATCH v5 4/6] lib/vdso: Allow fixed clock mode

From: Christophe Leroy
Date: Thu Jan 30 2020 - 11:08:53 EST


Some architectures have a fixed clocksource which is known at compile
time and cannot be replaced or disabled at runtime, e.g. timebase on
PowerPC. For such cases the clock mode check in the VDSO code is
pointless.

Therefore, give architectures the opportunity to redefine the way
clock_mode is checked by moving the check into an
__arch_vdso_capable() macro.

Signed-off-by: Christophe Leroy <christophe.leroy@xxxxxx>
---
lib/vdso/gettimeofday.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/lib/vdso/gettimeofday.c b/lib/vdso/gettimeofday.c
index 72d65dd50cb4..0b4b71880f22 100644
--- a/lib/vdso/gettimeofday.c
+++ b/lib/vdso/gettimeofday.c
@@ -120,12 +120,18 @@ static __always_inline int do_hres(const struct vdso_data *vd, clockid_t clk,
cpu_relax();
}
smp_rmb();
+#ifdef __arch_vdso_capable
+ if (unlikely(!__arch_vdso_capable(vd->clock_mode)))
+ return -1;
+#endif

cycles = __arch_get_hw_counter(vd->clock_mode);
ns = vdso_ts->nsec;
last = vd->cycle_last;
+#ifndef __arch_vdso_capable
if (unlikely((s64)cycles < 0))
return -1;
+#endif

ns += vdso_calc_delta(cycles, last, vd->mask, vd->mult);
ns >>= vd->shift;
--
2.25.0