samples, bpf: Refactor perf_event user program with libbpf bpf_link
authorDaniel T. Lee <danieltimlee@gmail.com>
Sat, 21 Mar 2020 10:04:24 +0000 (19:04 +0900)
committerDaniel Borkmann <daniel@iogearbox.net>
Mon, 23 Mar 2020 21:27:57 +0000 (22:27 +0100)
commitaa5e2af660fc6e35b9518d68dd7e1bb736e9f7e7
treef99d5a219ca3d9f2026770dae2c1a7930eba071e
parent24a6034acc922f1f6292636be4ec4dc3d9b4d2d7
samples, bpf: Refactor perf_event user program with libbpf bpf_link

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. Also, bpf_link__destroy manages the close() of
perf_event fd.

This commit refactors samples that attach the bpf program to perf_event
by using libbbpf instead of ioctl. Also the bpf_load in the samples were
removed and migrated to use libbbpf API.

Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20200321100424.1593964-3-danieltimlee@gmail.com
samples/bpf/Makefile
samples/bpf/sampleip_user.c
samples/bpf/trace_event_user.c