From: Andrii Nakryiko <andriin@fb.com>
To: <bpf@vger.kernel.org>, <netdev@vger.kernel.org>, <ast@fb.com>,
<daniel@iogearbox.net>
Cc: <andrii.nakryiko@gmail.com>, <kernel-team@fb.com>,
Andrii Nakryiko <andriin@fb.com>,
"Paul E . McKenney" <paulmck@kernel.org>,
Jonathan Lemon <jonathan.lemon@gmail.com>
Subject: [PATCH v4 bpf-next 0/5] BPF ring buffer
Date: Fri, 29 May 2020 00:54:19 -0700 [thread overview]
Message-ID: <20200529075424.3139988-1-andriin@fb.com> (raw)
Implement a new BPF ring buffer, as presented at BPF virtual conference ([0]).
It presents an alternative to perf buffer, following its semantics closely,
but allowing sharing same instance of ring buffer across multiple CPUs
efficiently.
Most patches have extensive commentary explaining various aspects, so I'll
keep cover letter short. Overall structure of the patch set:
- patch #1 adds BPF ring buffer implementation to kernel and necessary
verifier support;
- patch #2 adds libbpf consumer implementation for BPF ringbuf;
- patch #3 adds selftest, both for single BPF ring buf use case, as well as
using it with array/hash of maps;
- patch #4 adds extensive benchmarks and provide some analysis in commit
message, it builds upon selftests/bpf's bench runner.
- patch #5 adds most of patch #1 commit message as a doc under
Documentation/bpf/ringbuf.rst.
Litmus tests, validating consumer/producer protocols and memory orderings,
were moved out as discussed in [1] and are going to be posted against -rcu
tree and put under Documentation/litmus-tests/bpf-rb.
[0] https://docs.google.com/presentation/d/18ITdg77Bj6YDOH2LghxrnFxiPWe0fAqcmJY95t_qr0w
[1] https://lkml.org/lkml/2020/5/22/1011
v3->v4:
- fix ringbuf freeing (vunmap, __free_page); verified with a trivial loop
creating and closing ringbuf map endlessly (Daniel);
v2->v3:
- dropped unnecessary smp_wmb() (Paul);
- verifier reference type enhancement patch was dropped (Alexei);
- better verifier message for various memory access checks (Alexei);
- clarified a bit roundup_len() bit shifting (Alexei);
- converted doc to .rst (Alexei);
- fixed warning on 32-bit arches regarding tautological ring area size check.
v1->v2:
- commit()/discard()/output() accept flags (NO_WAKEUP/FORCE_WAKEUP) (Stanislav);
- bpf_ringbuf_query() added, returning available data size, ringbuf size,
consumer/producer positions, needed to implement smarter notification policy
(Stanislav);
- added ringbuf UAPI constants to include/uapi/linux/bpf.h (Jonathan);
- fixed sample size check, added proper ringbuf size check (Jonathan, Alexei);
- wake_up_all() is done through irq_work (Alexei);
- consistent use of smp_load_acquire/smp_store_release, no
READ_ONCE/WRITE_ONCE (Alexei);
- added Documentation/bpf/ringbuf.txt (Stanislav);
- updated litmus test with smp_load_acquire/smp_store_release changes;
- added ring_buffer__consume() API to libbpf for busy-polling;
- ring_buffer__poll() on success returns number of records consumed;
- fixed EPOLL notifications, don't assume available data, done similarly to
perfbuf's implementation;
- both ringbuf and perfbuf now have --rb-sampled mode, instead of
pb-raw/pb-custom mode, updated benchmark results;
- extended ringbuf selftests to validate epoll logic/manual notification
logic, as well as bpf_ringbuf_query().
Cc: Paul E. McKenney <paulmck@kernel.org>
Cc: Jonathan Lemon <jonathan.lemon@gmail.com>
Andrii Nakryiko (5):
bpf: implement BPF ring buffer and verifier support for it
libbpf: add BPF ring buffer support
selftests/bpf: add BPF ringbuf selftests
bpf: add BPF ringbuf and perf buffer benchmarks
docs/bpf: add BPF ring buffer design notes
Documentation/bpf/ringbuf.rst | 209 +++++++
include/linux/bpf.h | 13 +
include/linux/bpf_types.h | 1 +
include/linux/bpf_verifier.h | 4 +
include/uapi/linux/bpf.h | 84 ++-
kernel/bpf/Makefile | 2 +-
kernel/bpf/helpers.c | 10 +
kernel/bpf/ringbuf.c | 501 ++++++++++++++++
kernel/bpf/syscall.c | 12 +
kernel/bpf/verifier.c | 195 ++++--
kernel/trace/bpf_trace.c | 10 +
tools/include/uapi/linux/bpf.h | 84 ++-
tools/lib/bpf/Build | 2 +-
tools/lib/bpf/libbpf.h | 21 +
tools/lib/bpf/libbpf.map | 5 +
tools/lib/bpf/libbpf_probes.c | 5 +
tools/lib/bpf/ringbuf.c | 285 +++++++++
tools/testing/selftests/bpf/Makefile | 5 +-
tools/testing/selftests/bpf/bench.c | 16 +
.../selftests/bpf/benchs/bench_ringbufs.c | 566 ++++++++++++++++++
.../bpf/benchs/run_bench_ringbufs.sh | 75 +++
.../selftests/bpf/prog_tests/ringbuf.c | 211 +++++++
.../selftests/bpf/prog_tests/ringbuf_multi.c | 102 ++++
.../selftests/bpf/progs/perfbuf_bench.c | 33 +
.../selftests/bpf/progs/ringbuf_bench.c | 60 ++
.../selftests/bpf/progs/test_ringbuf.c | 78 +++
.../selftests/bpf/progs/test_ringbuf_multi.c | 77 +++
tools/testing/selftests/bpf/verifier/and.c | 4 +-
.../selftests/bpf/verifier/array_access.c | 4 +-
tools/testing/selftests/bpf/verifier/bounds.c | 6 +-
tools/testing/selftests/bpf/verifier/calls.c | 2 +-
.../bpf/verifier/direct_value_access.c | 4 +-
.../bpf/verifier/helper_access_var_len.c | 2 +-
.../bpf/verifier/helper_value_access.c | 6 +-
.../selftests/bpf/verifier/value_ptr_arith.c | 8 +-
35 files changed, 2630 insertions(+), 72 deletions(-)
create mode 100644 Documentation/bpf/ringbuf.rst
create mode 100644 kernel/bpf/ringbuf.c
create mode 100644 tools/lib/bpf/ringbuf.c
create mode 100644 tools/testing/selftests/bpf/benchs/bench_ringbufs.c
create mode 100755 tools/testing/selftests/bpf/benchs/run_bench_ringbufs.sh
create mode 100644 tools/testing/selftests/bpf/prog_tests/ringbuf.c
create mode 100644 tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c
create mode 100644 tools/testing/selftests/bpf/progs/perfbuf_bench.c
create mode 100644 tools/testing/selftests/bpf/progs/ringbuf_bench.c
create mode 100644 tools/testing/selftests/bpf/progs/test_ringbuf.c
create mode 100644 tools/testing/selftests/bpf/progs/test_ringbuf_multi.c
--
2.24.1
next reply other threads:[~2020-05-29 7:54 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-29 7:54 Andrii Nakryiko [this message]
2020-05-29 7:54 ` [PATCH v4 bpf-next 1/5] bpf: implement BPF ring buffer and verifier support for it Andrii Nakryiko
2020-05-29 7:54 ` [PATCH v4 bpf-next 2/5] libbpf: add BPF ring buffer support Andrii Nakryiko
2020-05-29 7:54 ` [PATCH v4 bpf-next 3/5] selftests/bpf: add BPF ringbuf selftests Andrii Nakryiko
2020-05-29 7:54 ` [PATCH v4 bpf-next 4/5] bpf: add BPF ringbuf and perf buffer benchmarks Andrii Nakryiko
2020-05-29 7:54 ` [PATCH v4 bpf-next 5/5] docs/bpf: add BPF ring buffer design notes Andrii Nakryiko
2020-09-09 13:53 ` Mauro Carvalho Chehab
2020-09-09 14:00 ` Mauro Carvalho Chehab
2020-09-10 22:36 ` Andrii Nakryiko
2020-05-29 15:21 ` [PATCH v4 bpf-next 0/5] BPF ring buffer Daniel Borkmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200529075424.3139988-1-andriin@fb.com \
--to=andriin@fb.com \
--cc=andrii.nakryiko@gmail.com \
--cc=ast@fb.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=jonathan.lemon@gmail.com \
--cc=kernel-team@fb.com \
--cc=netdev@vger.kernel.org \
--cc=paulmck@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).