summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2026-10-01 23:54:39 -0700
committerArnaldo Carvalho de Melo <acme@redhat.com>2026-10-02 18:04:37 +0200
commit1858a4df3ecbbdf5dce6d4df9edbebed403015ed (patch)
treeb6ee3f233efaeb8aab67a1ecccba50d5db7c26c9
parent148cd3adf2df9e53fd9b3070ae1178d4876f8c67 (diff)
downloadlinux-next-1858a4df3ecbbdf5dce6d4df9edbebed403015ed.tar.gz
linux-next-1858a4df3ecbbdf5dce6d4df9edbebed403015ed.zip
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 <acme@redhat.com> Assisted-by: Antigravity:gemini-3.1-pro Signed-off-by: Ian Rogers <irogers@google.com> Cc: Howard Chu <howardchu95@gmail.com> Cc: Jakub Brnak <jbrnak@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c6
1 files 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;
}