Skip to content

perf/core: Prepare sample data for BPF

Namhyung Kim bpf linux-s390 linuxppc-dev lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest8 patches 14 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/8perf/core: Save the dynamic parts of sample data sizeinclude/linux/perf_event.h kernel/events/core.c+12 -71 reply
2/8perf/core: Add perf_sample_save_callchain() helperarch/x86/events/amd/ibs.c arch/x86/events/intel/ds.c include/linux/perf_event.h +1 more+23 -231 reply
3/8perf/core: Add perf_sample_save_raw_data() helperarch/s390/kernel/perf_cpum_cf.c arch/s390/kernel/perf_pai_crypto.c arch/s390/kernel/perf_pai_ext.c +4 more+39 -464 replies
4/8perf/core: Add perf_sample_save_brstack() helperarch/powerpc/perf/core-book3s.c arch/x86/events/amd/core.c arch/x86/events/intel/core.c +3 more+53 -530 replies
5/8perf/core: Set data->sample_flags in perf_prepare_sample()kernel/events/core.c+65 -202 replies
6/8perf/core: Do not pass header for sample id initkernel/events/core.c+7 -71 reply
7/8perf/core: Introduce perf_prepare_header()arch/s390/kernel/perf_cpum_sf.c arch/x86/events/intel/ds.c include/linux/perf_event.h +1 more+43 -171 reply
8/8perf/core: Call perf_prepare_sample() before running BPFkernel/events/core.c+1 -71 reply

Reviews trailers per patch

5 of 8 patches have a Reviewed-by or Acked-by.

PatchSong Liu
1/8A-b
2/8A-b
3/8
4/8
5/8
6/8A-b
7/8A-b
8/8A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCHSET 0/8] perf/core: Prepare sample data for BPF

Hello,

The perf_prepare_sample() is to fill the perf sample data and update the header info before sending it to the ring buffer. But we want to use it for BPF overflow handler so that it can access the sample data to filter relevant ones.

Changes in v2)
* the layout change is merged
* reduce branches using __cond_set (PeterZ)
* add helpers to set dynamic sample data (PeterZ)
* introduce perf_prepare_header() (PeterZ)
* call perf_prepare_sample() before bpf_overflow_handler unconditionally

This means the perf_prepare_handler() can be called more than once. To avoid duplicate work, use the data->sample_flags and save the data size.

I also added a few of helpers to set those information accordingly. But it looks some fields like REGS_USER, STACK_USER and AUX are saved in the perf_prepare_sample() so I didn't add the helpers for them.

After than we can just check the filtered_sample_type flags begin zero to determine if it has more work. In that case, it needs to update the data->type since it's possible to miss when PMU driver sets all required sample flags before calling perf_prepare_sample().

The code is also available at 'perf/prepare-sample-v2' branch in

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

Thanks,
Namhyung

Namhyung Kim (8):
perf/core: Save the dynamic parts of sample data size perf/core: Add perf_sample_save_callchain() helper perf/core: Add perf_sample_save_raw_data() helper perf/core: Add perf_sample_save_brstack() helper perf/core: Set data->sample_flags in perf_prepare_sample() perf/core: Do not pass header for sample id init perf/core: Introduce perf_prepare_header() perf/core: Call perf_prepare_sample() before running BPF

 arch/powerpc/perf/core-book3s.c    |   3 +-
 arch/s390/kernel/perf_cpum_cf.c    |   4 +-
 arch/s390/kernel/perf_cpum_sf.c    |   3 +-
 arch/s390/kernel/perf_pai_crypto.c |   4 +-
 arch/s390/kernel/perf_pai_ext.c    |   4 +-
 arch/x86/events/amd/core.c         |   6 +-
 arch/x86/events/amd/ibs.c          |   9 +-
 arch/x86/events/intel/core.c       |   6 +-
 arch/x86/events/intel/ds.c         |  24 ++--
 include/linux/perf_event.h         | 133 +++++++++++++-----
 kernel/events/core.c               | 207 ++++++++++++++++-------------
 kernel/trace/bpf_trace.c           |   6 +-
 12 files changed, 236 insertions(+), 173 deletions(-)

base-commit: 9fcad995c6c52cc9791f7ee9f1386a5684055f9c

Signature · 1 line
2.39.0.314.g84b9a713c41-goog