linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC 0/6] perf record: Use pinned BPF program for filter (v1)
@ 2024-05-22 21:56 Namhyung Kim
  2024-05-22 21:56 ` [PATCH 1/6] perf bpf-filter: Make filters map a single entry hashmap Namhyung Kim
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Namhyung Kim @ 2024-05-22 21:56 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ian Rogers, Kan Liang
  Cc: Jiri Olsa, Adrian Hunter, Peter Zijlstra, Ingo Molnar, LKML,
	linux-perf-users, KP Singh, Stephane Eranian, Song Liu, bpf

Hello,

This is to support the unprivileged BPF filter for profiling per-task events.
Until now only root (or any user with CAP_BPF) can use the filter and we
cannot add a new unprivileged BPF program types.  After talking with the BPF
folks at LSF/MM/BPF 2024, I was told that this is the way to go.  Finally I
managed to make it working with pinned BPF objects. :)

But it requires the one-time setup (by root) before using it like below.

  # perf record --setup-filter pin

This will load the BPF program and maps and pin them in the BPF-fs.  Then
normal users can use the filter.

  $ perf record -o- -e cycles:u --filter 'period < 10000' perf test -w noploop | perf script -i-
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.011 MB - ]
        perf  759982 448227.214189:          1 cycles:u:      7f153719f4d0 _start+0x0 (/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2)
        perf  759982 448227.214195:          1 cycles:u:      7f153719f4d0 _start+0x0 (/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2)
        perf  759982 448227.214196:          7 cycles:u:      7f153719f4d0 _start+0x0 (/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2)
        perf  759982 448227.214196:        223 cycles:u:      7f153719f4d0 _start+0x0 (/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2)
        perf  759982 448227.214198:       9475 cycles:u:  ffffffff8ee012a0 [unknown] ([unknown])
        perf  759982 448227.548608:          1 cycles:u:      559a9f03c81c noploop+0x5c (/home/namhyung/linux/tools/perf/perf)
        perf  759982 448227.548611:          1 cycles:u:      559a9f03c81c noploop+0x5c (/home/namhyung/linux/tools/perf/perf)
        perf  759982 448227.548612:         12 cycles:u:      559a9f03c81c noploop+0x5c (/home/namhyung/linux/tools/perf/perf)
        perf  759982 448227.548613:        466 cycles:u:      559a9f03c81c noploop+0x5c (/home/namhyung/linux/tools/perf/perf)

It's also possible to unload (and unpin, of course) using this command:

  # perf record --setup-filter unpin

The code is avaiable in 'perf/pinned-filter-v1' branch at

  git://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git

Thanks,
Namhyung


Namhyung Kim (6):
  perf bpf-filter: Make filters map a single entry hashmap
  perf bpf-filter: Pass 'target' to perf_bpf_filter__prepare()
  perf bpf-filter: Split per-task filter use case
  perf bpf-filter: Support pin/unpin BPF object
  perf record: Fix a potential error handling issue
  perf record: Add --setup-filter option

 tools/perf/Documentation/perf-record.txt     |   5 +
 tools/perf/builtin-record.c                  |  23 +-
 tools/perf/builtin-stat.c                    |   2 +-
 tools/perf/builtin-trace.c                   |   2 +-
 tools/perf/util/bpf-filter.c                 | 369 +++++++++++++++++--
 tools/perf/util/bpf-filter.h                 |  19 +-
 tools/perf/util/bpf_skel/sample-filter.h     |   4 +-
 tools/perf/util/bpf_skel/sample_filter.bpf.c |  58 ++-
 tools/perf/util/evlist.c                     |   5 +-
 tools/perf/util/evlist.h                     |   4 +-
 tools/perf/util/python.c                     |   3 +-
 11 files changed, 428 insertions(+), 66 deletions(-)


base-commit: ea558c86248b4955e5c5f3c0c921df450880605e
-- 
2.45.1.288.g0e0cd299f1-goog


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-05-22 21:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-22 21:56 [RFC 0/6] perf record: Use pinned BPF program for filter (v1) Namhyung Kim
2024-05-22 21:56 ` [PATCH 1/6] perf bpf-filter: Make filters map a single entry hashmap Namhyung Kim
2024-05-22 21:56 ` [PATCH 2/6] perf bpf-filter: Pass 'target' to perf_bpf_filter__prepare() Namhyung Kim
2024-05-22 21:56 ` [PATCH 3/6] perf bpf-filter: Split per-task filter use case Namhyung Kim
2024-05-22 21:56 ` [PATCH 4/6] perf bpf-filter: Support pin/unpin BPF object Namhyung Kim
2024-05-22 21:56 ` [PATCH 5/6] perf record: Fix a potential error handling issue Namhyung Kim
2024-05-22 21:56 ` [PATCH 6/6] perf record: Add --setup-filter option Namhyung Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).