[tip: timers/vdso] vdso/gettimeofday: Avoid runtime conditional in do_hres_timens()
From: tip-bot2 for Thomas Weißschuh
Date: Thu Oct 15 2026 - 13:28:37 EST
The following commit has been merged into the timers/vdso branch of tip:
Commit-ID: 50628893711fd5dc3fdbe8cb95e685f2fe75b662
Gitweb: https://git.kernel.org/tip/50628893711fd5dc3fdbe8cb95e685f2fe75b662
Author: Thomas Weißschuh <linux@xxxxxxxxxxxxxx>
AuthorDate: Mon, 21 Sep 2026 11:45:58 +02:00
Committer: Thomas Gleixner <tglx@xxxxxxxxxx>
CommitterDate: Thu, 15 Oct 2026 17:33:20 +02:00
vdso/gettimeofday: Avoid runtime conditional in do_hres_timens()
Currently the derivation of the non-namespaced clock from its namespaced
sibling uses a runtime conditional. This conditional mirrors the
VDSO_RAW check in __cvdso_clock_gettime_common(), in a non-obvious way.
Replace the runtime conditional with unconditional pointer arithmetic,
which removes the duplication of logic and also is smaller and faster.
Also get rid of the weird double use of the 'vc' variable, pointing both
to the array of clocks and later to one specific one.
This saves 31 bytes of .text on x86_64.
Signed-off-by: Thomas Weißschuh <linux@xxxxxxxxxxxxxx>
Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxx>
Link: https://patch.msgid.link/20260921-vdso-timens-conditional-v1-1-eac173f8bd92@xxxxxxxxxxxxxx
---
lib/vdso/gettimeofday.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/lib/vdso/gettimeofday.c b/lib/vdso/gettimeofday.c
index 728fed1..c0e8199 100644
--- a/lib/vdso/gettimeofday.c
+++ b/lib/vdso/gettimeofday.c
@@ -140,21 +140,22 @@ const struct vdso_time_data *vdso_timens_data(const struct vdso_time_data *vd)
}
static __always_inline
+const struct vdso_clock *vdso_timens_clock(const struct vdso_clock *vc)
+{
+ return (void *)vc + PAGE_SIZE;
+}
+
+static __always_inline
bool do_hres_timens(const struct vdso_time_data *vdns, const struct vdso_clock *vcns,
clockid_t clk, struct __kernel_timespec *ts)
{
const struct vdso_time_data *vd = vdso_timens_data(vdns);
+ const struct vdso_clock *vc = vdso_timens_clock(vcns);
const struct timens_offset *offs = &vcns->offset[clk];
- const struct vdso_clock *vc = vd->clock_data;
u32 seq;
s64 sec;
u64 ns;
- if (clk != CLOCK_MONOTONIC_RAW)
- vc = &vc[CS_HRES_COARSE];
- else
- vc = &vc[CS_RAW];
-
do {
seq = vdso_read_begin(vc);