bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/2] samples: bpf: refactor perf_event user program with libbpf bpf_link
@ 2020-03-10  5:51 Daniel T. Lee
  2020-03-10  5:51 ` [PATCH bpf-next 1/2] samples: bpf: move read_trace_pipe to trace_helpers Daniel T. Lee
  2020-03-10  5:51 ` [PATCH bpf-next 2/2] samples: bpf: refactor perf_event user program with libbpf bpf_link Daniel T. Lee
  0 siblings, 2 replies; 6+ messages in thread
From: Daniel T. Lee @ 2020-03-10  5:51 UTC (permalink / raw)
  To: Daniel Borkmann, Alexei Starovoitov; +Cc: Andrii Nakryiko, netdev, bpf

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.

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                 | 58 +++++++++++++--------
 samples/bpf/trace_event_user.c              | 57 +++++++++++++-------
 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, 106 insertions(+), 64 deletions(-)

-- 
2.25.1


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

end of thread, other threads:[~2020-03-10 22:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-10  5:51 [PATCH bpf-next 0/2] samples: bpf: refactor perf_event user program with libbpf bpf_link Daniel T. Lee
2020-03-10  5:51 ` [PATCH bpf-next 1/2] samples: bpf: move read_trace_pipe to trace_helpers Daniel T. Lee
2020-03-10 21:11   ` John Fastabend
2020-03-10  5:51 ` [PATCH bpf-next 2/2] samples: bpf: refactor perf_event user program with libbpf bpf_link Daniel T. Lee
2020-03-10 21:33   ` John Fastabend
2020-03-10 22:49     ` Daniel T. Lee

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).