[RFC PATCH 1/4] nptl: use futex_time64 for lll_futex_syscall() if possible

Arnd Bergmann arnd@kernel.org
Tue Nov 10 14:51:43 GMT 2026


From: Arnd Bergmann <arnd@arndb.de>

When __ASSUME_TIME64_SYSCALLS is set, __NR_futex_time64 is always
available, so use that in place of __NR_futex for 32-bit architectures
regardless of __TIMESIZE.

Remove the slightly ambiguous lll_futex_timed_wait() macro that
could take either a timespec or __timespec64 argument depending
on the architecture. This was harmless since the only caller
always passes a NULL timeout. All users that do care about the
timeout were already calling helpers from futex-internal.c
which handles this correctly.

This is required for running on __TIMESIZE==32 architectures on
kernels built with CONFIG_COMPAT_32BIT_TIME.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 sysdeps/nptl/futex-internal.h     |  6 +-----
 sysdeps/nptl/lowlevellock-futex.h | 15 +++++++++++----
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/sysdeps/nptl/futex-internal.h b/sysdeps/nptl/futex-internal.h
index 502f89476a24..8934a5ee7932 100644
--- a/sysdeps/nptl/futex-internal.h
+++ b/sysdeps/nptl/futex-internal.h
@@ -123,7 +119,7 @@ futex_fatal_error (void)
 static __always_inline int
 futex_wait (unsigned int *futex_word, unsigned int expected, int private)
 {
-  int err = lll_futex_timed_wait (futex_word, expected, NULL, private);
+  int err = lll_futex_wait (futex_word, expected, private);
   switch (err)
     {
     case 0:
diff --git a/sysdeps/nptl/lowlevellock-futex.h b/sysdeps/nptl/lowlevellock-futex.h
index 640861350101..711723b0b0ad 100644
--- a/sysdeps/nptl/lowlevellock-futex.h
+++ b/sysdeps/nptl/lowlevellock-futex.h
@@ -53,6 +53,15 @@
 # define __lll_private_flag(fl, private) \
   (((fl) | FUTEX_PRIVATE_FLAG) ^ (private))
 
+#if defined(__ASSUME_TIME64_SYSCALLS) && defined(__NR_futex_time64)
+# define lll_futex_syscall(nargs, futexp, op, ...)                      \
+  ({                                                                    \
+    long int __ret = INTERNAL_SYSCALL (futex_time64, nargs, futexp, op,	\
+				       __VA_ARGS__);                    \
+    (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (__ret))         	\
+     ? -INTERNAL_SYSCALL_ERRNO (__ret) : 0);                     	\
+  })
+#else
 # define lll_futex_syscall(nargs, futexp, op, ...)                      \
   ({                                                                    \
     long int __ret = INTERNAL_SYSCALL (futex, nargs, futexp, op, 	\
@@ -60,6 +69,7 @@
     (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (__ret))         	\
      ? -INTERNAL_SYSCALL_ERRNO (__ret) : 0);                     	\
   })
+#endif
 
 /* For most of these macros, the return value is never really used.
    Nevertheless, the protocol is that each one returns a negated errno
@@ -70,12 +80,9 @@
 
 /* Wait while *FUTEXP == VAL for an lll_futex_wake call on FUTEXP.  */
 # define lll_futex_wait(futexp, val, private) \
-  lll_futex_timed_wait (futexp, val, NULL, private)
-
-# define lll_futex_timed_wait(futexp, val, timeout, private)     \
   lll_futex_syscall (4, futexp,                                 \
 		     __lll_private_flag (FUTEX_WAIT, private),  \
-		     val, timeout)
+		     val, NULL)
 
 /* Verify whether the supplied clockid is supported by
    lll_futex_clock_wait_bitset.  */
-- 
2.53.0



More information about the Libc-alpha mailing list