From 1858a4df3ecbbdf5dce6d4df9edbebed403015ed Mon Sep 17 00:00:00 2001 From: Ian Rogers Date: Thu, 1 Oct 2026 23:54:39 -0700 Subject: perf trace: Only call bpf_get_current_pid_tgid() when filtering tasks In task_traced(), bpf_get_current_pid_tgid() was called before checking has_pids_to_trace. Because BPF helper calls are not marked pure, the compiler cannot sink the call past the has_pids_to_trace check, so the helper was called on every syscall enter and exit even when tracing system-wide. Check has_pids_to_trace before calling bpf_get_current_pid_tgid(). Suggested-by: Arnaldo Carvalho de Melo Assisted-by: Antigravity:gemini-3.1-pro Signed-off-by: Ian Rogers Cc: Howard Chu Cc: Jakub Brnak Cc: Namhyung Kim Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c b/tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c index d16e55706335..0b2ef9541f84 100644 --- a/tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c +++ b/tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c @@ -494,13 +494,15 @@ static bool pid_filter__has(struct pids_filtered *pids, pid_t pid) static bool task_traced(void) { - u64 pid_tgid = bpf_get_current_pid_tgid(); - pid_t pid = uses_tgid ? pid_tgid >> 32 : (pid_t)pid_tgid; + u64 pid_tgid; + pid_t pid; bool *traced; if (!has_pids_to_trace) return true; + pid_tgid = bpf_get_current_pid_tgid(); + pid = uses_tgid ? pid_tgid >> 32 : (pid_t)pid_tgid; traced = bpf_map_lookup_elem(&pids_to_trace, &pid); return traced && *traced; } -- cgit v1.2.3