From: Francis Laniel <flaniel@linux.microsoft.com>
To: bpf@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
Francis Laniel <flaniel@linux.microsoft.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>, Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>,
Joanne Koong <joannelkoong@gmail.com>,
Dave Marchevsky <davemarchevsky@fb.com>,
Lorenzo Bianconi <lorenzo@kernel.org>,
Geliang Tang <geliang.tang@suse.com>,
Hengqi Chen <hengqi.chen@gmail.com>
Subject: [RFC PATCH v1 0/3] Make BPF ring buffer over writable
Date: Wed, 10 Aug 2022 19:16:51 +0200 [thread overview]
Message-ID: <20220810171702.74932-1-flaniel@linux.microsoft.com> (raw)
Hi.
First, I hope you are fine and the same for your relatives.
Normally, when BPF ring buffer are full, producers cannot write anymore and
need to wait for consumer to get some data.
As a consequence, calling bpf_ringbuf_reserve() from eBPF code returns NULL.
This contribution adds a new flag to make BPF ring buffer over writable.
When the buffer is full, the producer will over write the oldest data.
So, calling bpf_ringbuf_reserve() on an over writable BPF ring buffer never
returns NULL but consumer will loose some data.
This flag can be used to monitor lots of events, like all the syscalls done on
a given machine.
I tested it within a VM with the fourth patch which creates a "toy" eBPF
program:
you@home$ cd /path/to/iovisor/bcc
you@home$ git apply 0001-for-test-purpose-only-Add-toy-to-play-with-BPF-ring-.patch
you@home$ cd /path/to/linux/tools/lib/bpf
you@home$ make -j$(nproc)
you@home$ cp libbpf.a /path/to/iovisor/bcc/libbpf-tools/.output
you@home$ cd /path/to/iovisor/bcc/libbpf-tools/
you@home$ make -j toy
# Start your VM and copy toy executable inside it.
you@vm# ./share/toy
Press any key to begin consuming!
^Z
you@vm# for i in {1..16}; do true; done
you@vm# fg # Please press any key
8
9
10
11
12
13
14
15
16
^Z
you@vm# true && true
you@vm# fg
17
18
As you can see, the first eight events are overwritten.
If you any way to improve this contribution, feel free to share.
Francis Laniel (3):
bpf: Make ring buffer overwritable.
do not merge: Temporary fix for is_power_of_2.
libbpf: Make bpf ring buffer overwritable.
include/uapi/linux/bpf.h | 3 ++
kernel/bpf/ringbuf.c | 51 ++++++++++++++++++++++++++--------
tools/include/uapi/linux/bpf.h | 3 ++
tools/lib/bpf/libbpf.c | 2 +-
tools/lib/bpf/ringbuf.c | 35 ++++++++++++++++++++++-
5 files changed, 81 insertions(+), 13 deletions(-)
Best regards and thank you in advance.
--
2.25.1
next reply other threads:[~2022-08-10 17:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-10 17:16 Francis Laniel [this message]
2022-08-10 17:16 ` [RFC PATCH v1 1/3] bpf: Make ring buffer overwritable Francis Laniel
2022-08-15 21:52 ` Andrii Nakryiko
2022-08-16 10:23 ` Francis Laniel
2022-08-16 12:28 ` Alban Crequy
2022-08-10 17:16 ` [RFC PATCH v1 2/3] do not merge: Temporary fix for is_power_of_2 Francis Laniel
2022-08-10 17:16 ` [RFC PATCH v1 3/3] libbpf: Make bpf ring buffer overwritable Francis Laniel
2022-08-10 17:16 ` [PATCH] for test purpose only: Add toy to play with BPF ring buffer Francis Laniel
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=20220810171702.74932-1-flaniel@linux.microsoft.com \
--to=flaniel@linux.microsoft.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davemarchevsky@fb.com \
--cc=geliang.tang@suse.com \
--cc=haoluo@google.com \
--cc=hengqi.chen@gmail.com \
--cc=joannelkoong@gmail.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lorenzo@kernel.org \
--cc=martin.lau@linux.dev \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=yhs@fb.com \
/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