Skip to content

Refactor perf_event sample user program with libbpf bpf_link

Daniel T. Lee bpf netdev 5 versions – Applied

Status from this message: Applied, thanks!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest2 patches 4 repliesApplied
  2. v42 patches 3 repliesSuperseded
  3. v32 patches 3 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v22 patches4 repliesSuperseded
v12 patches3 repliesSuperseded

Changes in v5 from the cover letter

- on error, return error code with exit

Patches in v5 Applied

#Subject and filesSizeRepliesApplied
1/2samples: bpf: move read_trace_pipe to trace_helperssamples/bpf/Makefile samples/bpf/bpf_load.c samples/bpf/bpf_load.h +4 more+28 -231 reply
2/2samples: bpf: refactor perf_event user program with libbpf bpf_linksamples/bpf/Makefile samples/bpf/sampleip_user.c samples/bpf/trace_event_user.c+159 -822 replies

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchAndrii Nakryiko
1/2A-b
2/2A-b

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

Read the v5 thread

Cover letter [PATCH bpf-next v5 0/2] Refactor perf_event sample user program with libbpf bpf_link

Currently, some samples are using ioctl for enabling perf_event and attaching BPF programs to this event. However, the bpf_program__attach of libbpf(using bpf_link) is much more intuitive than the previous method using ioctl.

bpf_program__attach_perf_event manages the enable of perf_event and attach of BPF programs to it, so there's no neeed to do this directly with ioctl.

In addition, bpf_link provides consistency in the use of API because it allows disable (detach, destroy) for multiple events to be treated as one bpf_link__destroy.

To refactor samples with using this libbpf API, the bpf_load in the samples were removed and migrated to libbbpf. Because read_trace_pipe is used in bpf_load, multiple samples cannot be migrated to libbpf, this function was moved to trace_helpers.

Changes in v2:
- check memory allocation is successful
- clean up allocated memory on error

Changes in v3:
- Improve pointer error check (IS_ERR())
- change to calloc for easier destroy of bpf_link
- remove perf_event fd list since bpf_link handles fd
- use newer bpf_object__{open/load} API instead of bpf_prog_load
- perf_event for _SC_NPROCESSORS_ONLN instead of _SC_NPROCESSORS_CONF
- sample specific chagnes...

Changes in v4:
- bpf_link *, bpf_object * set NULL on init & err for easier destroy
- close bpf object with bpf_object__close()

Changes in v5:
- on error, return error code with exit

Daniel T. Lee (2):
samples: bpf: move read_trace_pipe to trace_helpers
samples: bpf: refactor perf_event user program with libbpf bpf_link

 samples/bpf/Makefile                        |   8 +-
 samples/bpf/bpf_load.c                      |  20 ---
 samples/bpf/bpf_load.h                      |   1 -
 samples/bpf/sampleip_user.c                 |  98 +++++++++-----
 samples/bpf/trace_event_user.c              | 139 +++++++++++++-------
 samples/bpf/tracex1_user.c                  |   1 +
 samples/bpf/tracex5_user.c                  |   1 +
 tools/testing/selftests/bpf/trace_helpers.c |  23 ++++
 tools/testing/selftests/bpf/trace_helpers.h |   1 +
 9 files changed, 187 insertions(+), 105 deletions(-)
Signature · 1 line
2.25.1