From: Zhan Xusheng <zhanxusheng1024@gmail.com>
To: tglx@kernel.org, thomas.weissschuh@linutronix.de
Cc: luto@kernel.org, vincenzo.frascino@arm.com,
david.laight.linux@gmail.com, linux-kernel@vger.kernel.org,
zhanxusheng@xiaomi.com
Subject: [PATCH v5 1/4] vdso/math64: Use OPTIMIZER_HIDE_VAR() in __iter_div_u64_rem()
Date: Wed, 16 Sep 2026 10:32:49 +0800 [thread overview]
Message-ID: <20260916023252.418473-2-zhanxusheng@xiaomi.com> (raw)
In-Reply-To: <20260916023252.418473-1-zhanxusheng@xiaomi.com>
__iter_div_u64_rem() divides by repeated subtraction, because its callers
only ever produce a small quotient. A barrier inside the subtraction loop
keeps the compiler from replacing the loop with a division:
asm("" : "+rm"(dividend));
The "rm" constraint permits a memory operand. clang picks it and spills
the dividend inside the loop, at 32-bit and 64-bit alike. The helper sits
on the clock_gettime() fast path through vdso_set_timespec(), so the spill
is not free: with clang 18 the x86 vDSO is 64 bytes larger in vdso64 text
and 112 bytes larger in vdso32 text than with a register-only barrier.
Use OPTIMIZER_HIDE_VAR(), which is the register-only form of the same
barrier and the form the rest of the kernel uses. gcc 13 generates
identical code either way, and neither compiler turns the loop into a
division at either width.
Put the function signature on one line while touching it, and reformat the
comment, which described the asm() that is now gone.
Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
---
include/vdso/math64.h | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/include/vdso/math64.h b/include/vdso/math64.h
index 22ae212f8b28..c628d6cf447c 100644
--- a/include/vdso/math64.h
+++ b/include/vdso/math64.h
@@ -2,15 +2,16 @@
#ifndef __VDSO_MATH64_H
#define __VDSO_MATH64_H
-static __always_inline u32
-__iter_div_u64_rem(u64 dividend, u32 divisor, u64 *remainder)
+static __always_inline u32 __iter_div_u64_rem(u64 dividend, u32 divisor, u64 *remainder)
{
u32 ret = 0;
while (dividend >= divisor) {
- /* The following asm() prevents the compiler from
- optimising this loop into a modulo operation. */
- asm("" : "+rm"(dividend));
+ /*
+ * Prevent the compiler from optimising this loop into a
+ * modulo operation.
+ */
+ OPTIMIZER_HIDE_VAR(dividend);
dividend -= divisor;
ret++;
--
2.43.0
next prev parent reply other threads:[~2026-09-16 2:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-16 2:32 [PATCH v5 0/4] vdso: Keep the CLOCK_AUX base at full precision Zhan Xusheng
2026-09-16 2:32 ` Zhan Xusheng [this message]
2026-09-25 7:44 ` [PATCH v5 1/4] vdso/math64: Use OPTIMIZER_HIDE_VAR() in __iter_div_u64_rem() Thomas Weißschuh
2026-09-29 19:27 ` [tip: timers/vdso] " tip-bot2 for Zhan Xusheng
2026-09-16 2:32 ` [PATCH v5 2/4] vdso/math64: Add and use __iter_div64_u64_rem() Zhan Xusheng
2026-09-29 19:27 ` [tip: timers/vdso] " tip-bot2 for Zhan Xusheng
2026-09-16 2:32 ` [PATCH v5 3/4] vdso/vsyscall: Keep the CLOCK_AUX base scaled Zhan Xusheng
2026-09-29 19:27 ` [tip: timers/vdso] " tip-bot2 for Zhan Xusheng
2026-09-16 2:32 ` [PATCH v5 4/4] vdso/gettimeofday: Assert that the clockid fits into the u32 bitmask Zhan Xusheng
2026-09-29 19:27 ` [tip: timers/vdso] " tip-bot2 for Zhan Xusheng
2026-09-30 12:41 ` [PATCH v5 0/4] vdso: Keep the CLOCK_AUX base at full precision Thomas Gleixner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260916023252.418473-2-zhanxusheng@xiaomi.com \
--to=zhanxusheng1024@gmail.com \
--cc=david.laight.linux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=tglx@kernel.org \
--cc=thomas.weissschuh@linutronix.de \
--cc=vincenzo.frascino@arm.com \
--cc=zhanxusheng@xiaomi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®