Skip to contentSkip to conversation

selftests/bench: use syscall(SYS_gettid) as libc support for gettid() is sometimes absent

PATCH Applied Alan Maguire 2 participants 2 messages Mar 22, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/bench: use syscall(SYS_gettid) as libc support for gettid() is sometimes absent

With glibc 2.28, selftests compilation fails for benchs/bench_trigger.c:

benchs/bench_trigger.c: In function ‘inc_counter’:
benchs/bench_trigger.c:25:23: error: implicit declaration of function ‘gettid’; did you mean ‘getgid’? [-Werror=implicit-function-declaration]

   25 |                 tid = gettid();
      |                       ^~~~~~
      |                       getgid

cc1: all warnings being treated as errors

It appears support for the gettid() wrapper is variable across glibc versions, so may be safer to use syscall(SYS_gettid) instead.

Fixes 520fad2e3206 ("selftests/bpf: scale benchmark counting by using per-CPU counters")
---
 tools/testing/selftests/bpf/benchs/bench_trigger.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/benchs/bench_trigger.c +1 -1
index b7aea79495ba..9c50412f72e9 100644
@@ -22,7 +22,7 @@ static __always_inline void inc_counter(struct counter *counters)
 	unsigned slot;
 
 	if (unlikely(tid == 0))
-		tid = gettid();
+		tid = syscall(SYS_gettid);
 
 	/* multiplicative hashing, it's fast */
 	slot = 2654435769U * tid;
Signature · 1 line
2.31.1
#1 lore raw
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Quoted 10 lines · On Fri, 22 Mar 2024 09:57:28 +0000 you wrote:

With glibc 2.28, selftests compilation fails for benchs/bench_trigger.c:

benchs/bench_trigger.c: In function ‘inc_counter’:
benchs/bench_trigger.c:25:23: error: implicit declaration of function ‘gettid’; did you mean ‘getgid’? [-Werror=implicit-function-declaration]

   25 |                 tid = gettid();
      |                       ^~~~~~
      |                       getgid

cc1: all warnings being treated as errors

[...]

Here is the summary with links:
- [bpf-next] selftests/bench: use syscall(SYS_gettid) as libc support for gettid() is sometimes absent

    https://git.kernel.org/bpf/bpf-next/c/1684d6eb99e4

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html