perf bench futex: Define SYS_futex on 32-bit arches with 64-bit time_t
Subsystems (3)
PATCH 1/1 perf bench futex: Define SYS_futex on 32-bit arches with 64-bit time_t
The kernel does not provide sys_futex() on 32-bit architectures that lack a 32-bit time representation, such as riscv32. Consequently glibc does not define SYS_futex there, only SYS_futex_time64, and perf bench's futex benchmarks fail to build:
bench/futex.h: In function 'futex_syscall':
bench/futex.h:77:18: error: 'SYS_futex' undeclared (first use in this function)
Define SYS_futex as SYS_futex_time64 when only the latter is available. The guard and its comment are taken verbatim from tools/testing/selftests/futex/include/futextest.h, where they were added by commit 04850819c65c ("selftests/futex: Define SYS_futex on 32-bit architectures with 64-bit time_t"), keeping the two futex userspace headers in sync.
No timespec conversion helper is needed on top of this. glibc lays out struct timespec on 32-bit architectures with 64-bit time_t as { int64 tv_sec; int32 tv_nsec; 32-bit pad }, which is compatible with struct __kernel_timespec, and every futex_wait()/futex_lock_pi()/ futex_wait_requeue_pi() call site in perf bench passes a NULL timeout anyway, so no timespec ever crosses the syscall boundary here.
Note that an earlier and more ambitious attempt at this was commit c1ff12dac465 ("perf bench futex: Add support for 32-bit systems with 64-bit time_t"), reverted by
commit ba4026b09d83 ("Revert "perf bench futex: Add support for 32-bit systems with 64-bit time_t"") because it included linux/time_types.h, which is unavailable on older distributions. This change deliberately avoids that dependency and adds only the one guard needed to fix compilation.
--- tools/perf/bench/futex.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
tools/perf/bench/futex.h +11 -0
@@ -14,6 +14,17 @@#include <sys/types.h> #include <linux/futex.h> +/* +* SYS_futex is expected from system C library, in glibc some 32-bit +* architectures (e.g. RV32) are using 64-bit time_t, therefore it doesn't have +* SYS_futex defined but just SYS_futex_time64. Define SYS_futex as +* SYS_futex_time64 in this situation to ensure the compilation and the +* compatibility. +*/ +#if !defined(SYS_futex) && defined(SYS_futex_time64) +#define SYS_futex SYS_futex_time64 +#endif +struct bench_futex_parameters {bool silent;bool fshared;
base-commit: 66498c75b4f8017f62d720d9b59675bdf3abce91
Signature · 1 line
2.43.7
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 15 lines
The kernel does not provide
sys_futex()on 32-bit architectures that lack a 32-bit time representation, such as riscv32. Consequently glibc does not defineSYS_futexthere, onlySYS_futex_time64, and perf bench's futex benchmarks fail to build:
bench/futex.h: In function 'futex_syscall':
bench/futex.h:77:18: error: 'SYS_futex' undeclared (first use in this function)Define
SYS_futexasSYS_futex_time64when only the latter is available. The guard and its comment are taken verbatim fromtools/testing/selftests/futex/include/futextest.h, where they were added by commit04850819c65c("selftests/futex: DefineSYS_futexon 32-bit architectures with 64-bittime_t"), keeping the two futex userspace headers in sync.
Quoted 6 lines
[ ... ]
which is unavailable on older distributions. This change deliberately avoids that dependency and adds only the one guard needed to fix compilation.Signed-off-by Nylon Chen <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 32 lines · Nylon Chen
The kernel does not provide
sys_futex()on 32-bit architectures that lack a 32-bit time representation, such as riscv32. Consequently glibc does not defineSYS_futexthere, onlySYS_futex_time64, and perf bench's futex benchmarks fail to build:
bench/futex.h: In function 'futex_syscall':
bench/futex.h:77:18: error: 'SYS_futex' undeclared (first use in this function)Define
SYS_futexasSYS_futex_time64when only the latter is available. The guard and its comment are taken verbatim fromtools/testing/selftests/futex/include/futextest.h, where they were added by commit04850819c65c("selftests/futex: DefineSYS_futexon 32-bit architectures with 64-bittime_t"), keeping the two futex userspace headers in sync.No timespec conversion helper is needed on top of this. glibc lays out struct timespec on 32-bit architectures with 64-bit
time_tas { int64tv_sec; int32tv_nsec; 32-bit pad }, which is compatible with struct__kernel_timespec, and every futex_wait()/futex_lock_pi()/futex_wait_requeue_pi()call site in perf bench passes a NULL timeout anyway, so no timespec ever crosses the syscall boundary here.Note that an earlier and more ambitious attempt at this was commit
c1ff12dac465("perf bench futex: Add support for 32-bit systems with 64-bittime_t"), reverted by
commitba4026b09d83("Revert "perf bench futex: Add support for 32-bit systems with 64-bittime_t"") because it includedlinux/time_types.h, which is unavailable on older distributions. This change deliberately avoids that dependency and adds only the one guard needed to fix compilation.
Quoted 1 line
Signed-off-by Nylon Chen <[email protected]>
Thanks,
Ian
Quoted 31 lines
--- tools/perf/bench/futex.h | 11 +++++++++++ 1 file changed, 11 insertions(+)tools/perf/bench/futex.h +11
-0@@ -14,6 +14,17 @@#include <sys/types.h> #include <linux/futex.h> +/* +* SYS_futex is expected from system C library, in glibc some 32-bit +* architectures (e.g. RV32) are using 64-bit time_t, therefore it doesn't have +* SYS_futex defined but just SYS_futex_time64. Define SYS_futex as +* SYS_futex_time64 in this situation to ensure the compilation and the +* compatibility. +*/ +#if !defined(SYS_futex) && defined(SYS_futex_time64) +#define SYS_futex SYS_futex_time64 +#endif +struct bench_futex_parameters {bool silent;bool fshared;base-commit:
66498c75b4f8017f62d720d9b59675bdf3abce91--
2.43.7
Quoted 33 lines · Ian Rogers
Quoted 32 lines · Nylon Chen
The kernel does not provide
sys_futex()on 32-bit architectures that lack a 32-bit time representation, such as riscv32. Consequently glibc does not defineSYS_futexthere, onlySYS_futex_time64, and perf bench's futex benchmarks fail to build:
bench/futex.h: In function 'futex_syscall':
bench/futex.h:77:18: error: 'SYS_futex' undeclared (first use in this function)Define
SYS_futexasSYS_futex_time64when only the latter is available. The guard and its comment are taken verbatim fromtools/testing/selftests/futex/include/futextest.h, where they were added by commit04850819c65c("selftests/futex: DefineSYS_futexon 32-bit architectures with 64-bittime_t"), keeping the two futex userspace headers in sync.No timespec conversion helper is needed on top of this. glibc lays out struct timespec on 32-bit architectures with 64-bit
time_tas { int64tv_sec; int32tv_nsec; 32-bit pad }, which is compatible with struct__kernel_timespec, and every futex_wait()/futex_lock_pi()/futex_wait_requeue_pi()call site in perf bench passes a NULL timeout anyway, so no timespec ever crosses the syscall boundary here.Note that an earlier and more ambitious attempt at this was commit
c1ff12dac465("perf bench futex: Add support for 32-bit systems with 64-bittime_t"), reverted by
commitba4026b09d83("Revert "perf bench futex: Add support for 32-bit systems with 64-bittime_t"") because it includedlinux/time_types.h, which is unavailable on older distributions. This change deliberately avoids that dependency and adds only the one guard needed to fix compilation.
Quoted 3 lines
Quoted 1 line
Signed-off-by Nylon Chen <[email protected]>Reviewed-by Ian Rogers <[email protected]>
Thanks, applied to perf-tools-next, for v7.4.
- Arnaldo