Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf offcpu: Check process id for the given workload

Current task filter checks task->pid which is different for each
thread. But we want to profile all the threads in the process. So
let's compare process id (or thread-group id: tgid) instead.

Before:
$ sudo perf record --off-cpu -- perf bench sched messaging -t
$ sudo perf report --stat | grep -A1 offcpu
offcpu-time stats:
SAMPLE events: 2

After:
$ sudo perf record --off-cpu -- perf bench sched messaging -t
$ sudo perf report --stat | grep -A1 offcpu
offcpu-time stats:
SAMPLE events: 850

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Blake Jones <blakejones@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Milian Wolff <milian.wolff@kdab.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <songliubraving@fb.com>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20220811185456.194721-2-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
07fc958b 806731a9

+8 -1
+1
tools/perf/util/bpf_off_cpu.c
··· 78 78 u8 val = 1; 79 79 80 80 skel->bss->has_task = 1; 81 + skel->bss->uses_tgid = 1; 81 82 fd = bpf_map__fd(skel->maps.task_filter); 82 83 pid = perf_thread_map__pid(evlist->core.threads, 0); 83 84 bpf_map_update_elem(fd, &pid, &val, BPF_ANY);
+7 -1
tools/perf/util/bpf_skel/off_cpu.bpf.c
··· 85 85 int has_cpu = 0; 86 86 int has_task = 0; 87 87 int has_cgroup = 0; 88 + int uses_tgid = 0; 88 89 89 90 const volatile bool has_prev_state = false; 90 91 const volatile bool needs_cgroup = false; ··· 145 144 146 145 if (has_task) { 147 146 __u8 *ok; 148 - __u32 pid = t->pid; 147 + __u32 pid; 148 + 149 + if (uses_tgid) 150 + pid = t->tgid; 151 + else 152 + pid = t->pid; 149 153 150 154 ok = bpf_map_lookup_elem(&task_filter, &pid); 151 155 if (!ok)