linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/3] bpf: Add bpf_perf_event_read_sample() helper (v1)
@ 2022-11-01  5:23 Namhyung Kim
  2022-11-01  5:23 ` [PATCH bpf-next 1/3] perf/core: Prepare sample data before calling BPF Namhyung Kim
                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Namhyung Kim @ 2022-11-01  5:23 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Song Liu,
	Peter Zijlstra
  Cc: Martin KaFai Lau, Yonghong Song, John Fastabend, KP Singh,
	Hao Luo, Stanislav Fomichev, LKML, bpf, Jiri Olsa,
	Steven Rostedt, Ingo Molnar, Arnaldo Carvalho de Melo

Hello,

I'd like to add bpf_perf_event_read_sample() helper to get the sample data
of an perf_event from BPF programs.  This enables more sophistigated filtering
for the perf samples.  Initially I'm thinking of code and data address based
filtering.

The original discussion can be seen here:
  https://lore.kernel.org/r/20220823210354.1407473-1-namhyung@kernel.org

The bpf_perf_event_read_sample() will take a buffer and size to save the data
as well as a flag to specify perf sample type.  The flag argument should have
a single value in the enum perf_event_sample_format like PERF_SAMPLE_IP.  If
the buffer is NULL, it will return the size of data instead.  This is to
support variable length data in the future.

The first patch adds bpf_prepare_sample() to setup necessary perf sample data
before calling the bpf overflow handler for the perf event.  The existing
logic for callchain moved to the function and it sets IP and ADDR data if
they are not set already.

The second patch actually adds the bpf_perf_event_read_sample() helper and
supports IP and ADDR data.  The last patch adds a test code for this.

The code is available at 'bpf/perf-sample-v1' branch in

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

Thanks,
Namhyung

Namhyung Kim (3):
  perf/core: Prepare sample data before calling BPF
  bpf: Add bpf_perf_event_read_sample() helper
  bpf: Add perf_event_read_sample test cases

 include/uapi/linux/bpf.h                      |  23 +++
 kernel/events/core.c                          |  40 +++-
 kernel/trace/bpf_trace.c                      |  49 +++++
 tools/include/uapi/linux/bpf.h                |  23 +++
 .../selftests/bpf/prog_tests/perf_sample.c    | 172 ++++++++++++++++++
 .../selftests/bpf/progs/test_perf_sample.c    |  28 +++
 6 files changed, 326 insertions(+), 9 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/perf_sample.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_perf_sample.c


base-commit: e39e739ab57399f46167d453bbdb8ef8d57c6488
-- 
2.38.1.273.g43a17bfeac-goog


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

end of thread, other threads:[~2022-11-04  6:18 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-01  5:23 [PATCH bpf-next 0/3] bpf: Add bpf_perf_event_read_sample() helper (v1) Namhyung Kim
2022-11-01  5:23 ` [PATCH bpf-next 1/3] perf/core: Prepare sample data before calling BPF Namhyung Kim
2022-11-01 10:03   ` Jiri Olsa
2022-11-04  6:03     ` Namhyung Kim
2022-11-01  5:23 ` [PATCH bpf-next 2/3] bpf: Add bpf_perf_event_read_sample() helper Namhyung Kim
2022-11-01 10:02   ` Jiri Olsa
2022-11-01 18:26     ` Alexei Starovoitov
2022-11-01 18:46       ` Song Liu
2022-11-01 18:52         ` Alexei Starovoitov
2022-11-01 20:04           ` Song Liu
2022-11-01 22:16             ` Namhyung Kim
2022-11-02  0:13               ` Song Liu
2022-11-02 22:18                 ` Namhyung Kim
2022-11-03 18:41                   ` Song Liu
2022-11-03 19:45     ` Yonghong Song
2022-11-03 20:55       ` Song Liu
2022-11-03 21:21         ` Yonghong Song
2022-11-04  6:18           ` Namhyung Kim
2022-11-01  5:23 ` [PATCH bpf-next 3/3] bpf: Add perf_event_read_sample test cases 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).