* [PATCH bpf-next v2 00/14] add libbpf getters for individual ringbuffers
@ 2023-09-25 21:50 Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 01/14] libbpf: refactor cleanup in ring_buffer__add Martin Kelly
` (14 more replies)
0 siblings, 15 replies; 16+ messages in thread
From: Martin Kelly @ 2023-09-25 21:50 UTC (permalink / raw)
To: bpf
Cc: Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann,
Martin KaFai Lau, Martin Kelly
This patch series adds a new ring__ API to libbpf exposing getters for
accessing the individual ringbuffers inside a struct ring_buffer. This is
useful for polling individually, getting available data, or similar use
cases. The API looks like this, and was roughly proposed by Andrii Nakryiko
in another thread:
Getting a ring struct:
struct ring *ring_buffer__ring(struct ring_buffer *rb, unsigned int idx);
Using the ring struct:
unsigned long ring__consumer_pos(const struct ring *r);
unsigned long ring__producer_pos(const struct ring *r);
size_t ring__avail_data_size(const struct ring *r);
size_t ring__size(const struct ring *r);
int ring__map_fd(const struct ring *r);
int ring__consume(struct ring *r);
Changes in v2:
- Addressed all feedback from Andrii Nakryiko
Martin Kelly (14):
libbpf: refactor cleanup in ring_buffer__add
libbpf: switch rings to array of pointers
libbpf: add ring_buffer__ring
selftests/bpf: add tests for ring_buffer__ring
libbpf: add ring__producer_pos, ring__consumer_pos
selftests/bpf: add tests for ring__*_pos
libbpf: add ring__avail_data_size
selftests/bpf: add tests for ring__avail_data_size
libbpf: add ring__size
selftests/bpf: add tests for ring__size
libbpf: add ring__map_fd
selftests/bpf: add tests for ring__map_fd
libbpf: add ring__consume
selftests/bpf: add tests for ring__consume
tools/lib/bpf/libbpf.h | 73 ++++++++++++++++
tools/lib/bpf/libbpf.map | 7 ++
tools/lib/bpf/ringbuf.c | 85 ++++++++++++++++---
.../selftests/bpf/prog_tests/ringbuf.c | 26 ++++++
.../selftests/bpf/prog_tests/ringbuf_multi.c | 15 ++++
5 files changed, 193 insertions(+), 13 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH bpf-next v2 01/14] libbpf: refactor cleanup in ring_buffer__add
2023-09-25 21:50 [PATCH bpf-next v2 00/14] add libbpf getters for individual ringbuffers Martin Kelly
@ 2023-09-25 21:50 ` Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 02/14] libbpf: switch rings to array of pointers Martin Kelly
` (13 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Martin Kelly @ 2023-09-25 21:50 UTC (permalink / raw)
To: bpf
Cc: Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann,
Martin KaFai Lau, Martin Kelly
Refactor the cleanup code in ring_buffer__add to use a unified err_out
label. This reduces code duplication, as well as plugging a potential
leak if mmap_sz != (__u64)(size_t)mmap_sz (currently this would miss
unmapping tmp because ringbuf_unmap_ring isn't called).
Signed-off-by: Martin Kelly <martin.kelly@crowdstrike.com>
---
tools/lib/bpf/ringbuf.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c
index 02199364db13..29b0d19d920f 100644
--- a/tools/lib/bpf/ringbuf.c
+++ b/tools/lib/bpf/ringbuf.c
@@ -121,7 +121,7 @@ int ring_buffer__add(struct ring_buffer *rb, int map_fd,
err = -errno;
pr_warn("ringbuf: failed to mmap consumer page for map fd=%d: %d\n",
map_fd, err);
- return libbpf_err(err);
+ goto err_out;
}
r->consumer_pos = tmp;
@@ -131,16 +131,16 @@ int ring_buffer__add(struct ring_buffer *rb, int map_fd,
*/
mmap_sz = rb->page_size + 2 * (__u64)info.max_entries;
if (mmap_sz != (__u64)(size_t)mmap_sz) {
+ err = -E2BIG;
pr_warn("ringbuf: ring buffer size (%u) is too big\n", info.max_entries);
- return libbpf_err(-E2BIG);
+ goto err_out;
}
tmp = mmap(NULL, (size_t)mmap_sz, PROT_READ, MAP_SHARED, map_fd, rb->page_size);
if (tmp == MAP_FAILED) {
err = -errno;
- ringbuf_unmap_ring(rb, r);
pr_warn("ringbuf: failed to mmap data pages for map fd=%d: %d\n",
map_fd, err);
- return libbpf_err(err);
+ goto err_out;
}
r->producer_pos = tmp;
r->data = tmp + rb->page_size;
@@ -152,14 +152,17 @@ int ring_buffer__add(struct ring_buffer *rb, int map_fd,
e->data.fd = rb->ring_cnt;
if (epoll_ctl(rb->epoll_fd, EPOLL_CTL_ADD, map_fd, e) < 0) {
err = -errno;
- ringbuf_unmap_ring(rb, r);
pr_warn("ringbuf: failed to epoll add map fd=%d: %d\n",
map_fd, err);
- return libbpf_err(err);
+ goto err_out;
}
rb->ring_cnt++;
return 0;
+
+err_out:
+ ringbuf_unmap_ring(rb, r);
+ return libbpf_err(err);
}
void ring_buffer__free(struct ring_buffer *rb)
--
2.34.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH bpf-next v2 02/14] libbpf: switch rings to array of pointers
2023-09-25 21:50 [PATCH bpf-next v2 00/14] add libbpf getters for individual ringbuffers Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 01/14] libbpf: refactor cleanup in ring_buffer__add Martin Kelly
@ 2023-09-25 21:50 ` Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 03/14] libbpf: add ring_buffer__ring Martin Kelly
` (12 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Martin Kelly @ 2023-09-25 21:50 UTC (permalink / raw)
To: bpf
Cc: Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann,
Martin KaFai Lau, Martin Kelly
Switch rb->rings to be an array of pointers instead of a contiguous
block. This allows for each ring pointer to be stable after
ring_buffer__add is called, which allows us to expose struct ring * to
the user without gotchas. Without this change, the realloc in
ring_buffer__add could invalidate a struct ring *, making it unsafe to
give to the user.
Signed-off-by: Martin Kelly <martin.kelly@crowdstrike.com>
---
tools/lib/bpf/ringbuf.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c
index 29b0d19d920f..94d11fb44a49 100644
--- a/tools/lib/bpf/ringbuf.c
+++ b/tools/lib/bpf/ringbuf.c
@@ -34,7 +34,7 @@ struct ring {
struct ring_buffer {
struct epoll_event *events;
- struct ring *rings;
+ struct ring **rings;
size_t page_size;
int epoll_fd;
int ring_cnt;
@@ -57,7 +57,7 @@ struct ringbuf_hdr {
__u32 pad;
};
-static void ringbuf_unmap_ring(struct ring_buffer *rb, struct ring *r)
+static void ringbuf_free_ring(struct ring_buffer *rb, struct ring *r)
{
if (r->consumer_pos) {
munmap(r->consumer_pos, rb->page_size);
@@ -67,6 +67,8 @@ static void ringbuf_unmap_ring(struct ring_buffer *rb, struct ring *r)
munmap(r->producer_pos, rb->page_size + 2 * (r->mask + 1));
r->producer_pos = NULL;
}
+
+ free(r);
}
/* Add extra RINGBUF maps to this ring buffer manager */
@@ -107,8 +109,10 @@ int ring_buffer__add(struct ring_buffer *rb, int map_fd,
return libbpf_err(-ENOMEM);
rb->events = tmp;
- r = &rb->rings[rb->ring_cnt];
- memset(r, 0, sizeof(*r));
+ r = calloc(1, sizeof(*r));
+ if (!r)
+ return libbpf_err(-ENOMEM);
+ rb->rings[rb->ring_cnt] = r;
r->map_fd = map_fd;
r->sample_cb = sample_cb;
@@ -161,7 +165,7 @@ int ring_buffer__add(struct ring_buffer *rb, int map_fd,
return 0;
err_out:
- ringbuf_unmap_ring(rb, r);
+ ringbuf_free_ring(rb, r);
return libbpf_err(err);
}
@@ -173,7 +177,7 @@ void ring_buffer__free(struct ring_buffer *rb)
return;
for (i = 0; i < rb->ring_cnt; ++i)
- ringbuf_unmap_ring(rb, &rb->rings[i]);
+ ringbuf_free_ring(rb, rb->rings[i]);
if (rb->epoll_fd >= 0)
close(rb->epoll_fd);
@@ -281,7 +285,7 @@ int ring_buffer__consume(struct ring_buffer *rb)
int i;
for (i = 0; i < rb->ring_cnt; i++) {
- struct ring *ring = &rb->rings[i];
+ struct ring *ring = rb->rings[i];
err = ringbuf_process_ring(ring);
if (err < 0)
@@ -308,7 +312,7 @@ int ring_buffer__poll(struct ring_buffer *rb, int timeout_ms)
for (i = 0; i < cnt; i++) {
__u32 ring_id = rb->events[i].data.fd;
- struct ring *ring = &rb->rings[ring_id];
+ struct ring *ring = rb->rings[ring_id];
err = ringbuf_process_ring(ring);
if (err < 0)
--
2.34.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH bpf-next v2 03/14] libbpf: add ring_buffer__ring
2023-09-25 21:50 [PATCH bpf-next v2 00/14] add libbpf getters for individual ringbuffers Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 01/14] libbpf: refactor cleanup in ring_buffer__add Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 02/14] libbpf: switch rings to array of pointers Martin Kelly
@ 2023-09-25 21:50 ` Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 04/14] selftests/bpf: add tests for ring_buffer__ring Martin Kelly
` (11 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Martin Kelly @ 2023-09-25 21:50 UTC (permalink / raw)
To: bpf
Cc: Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann,
Martin KaFai Lau, Martin Kelly
Add a new function ring_buffer__ring, which exposes struct ring * to the
user, representing a single ringbuffer.
Signed-off-by: Martin Kelly <martin.kelly@crowdstrike.com>
---
tools/lib/bpf/libbpf.h | 15 +++++++++++++++
tools/lib/bpf/libbpf.map | 1 +
tools/lib/bpf/ringbuf.c | 8 ++++++++
3 files changed, 24 insertions(+)
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 0e52621cba43..de3ef59b9641 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -1229,6 +1229,7 @@ LIBBPF_API int bpf_tc_query(const struct bpf_tc_hook *hook,
/* Ring buffer APIs */
struct ring_buffer;
+struct ring;
struct user_ring_buffer;
typedef int (*ring_buffer_sample_fn)(void *ctx, void *data, size_t size);
@@ -1249,6 +1250,20 @@ LIBBPF_API int ring_buffer__poll(struct ring_buffer *rb, int timeout_ms);
LIBBPF_API int ring_buffer__consume(struct ring_buffer *rb);
LIBBPF_API int ring_buffer__epoll_fd(const struct ring_buffer *rb);
+/**
+ * @brief **ring_buffer__ring()** returns the ringbuffer object inside a given
+ * ringbuffer manager representing a single BPF_MAP_TYPE_RINGBUF map instance.
+ *
+ * @param rb A ringbuffer manager object.
+ * @param idx An index into the ringbuffers contained within the ringbuffer
+ * manager object. The index is 0-based and corresponds to the order in which
+ * ring_buffer__add was called.
+ * @return A ringbuffer object on success; NULL and errno set if the index is
+ * invalid.
+ */
+LIBBPF_API struct ring *ring_buffer__ring(struct ring_buffer *rb,
+ unsigned int idx);
+
struct user_ring_buffer_opts {
size_t sz; /* size of this struct, for forward/backward compatibility */
};
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
index 57712321490f..7a7370c2bc25 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -400,4 +400,5 @@ LIBBPF_1.3.0 {
bpf_program__attach_netfilter;
bpf_program__attach_tcx;
bpf_program__attach_uprobe_multi;
+ ring_buffer__ring;
} LIBBPF_1.2.0;
diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c
index 94d11fb44a49..efde453395b0 100644
--- a/tools/lib/bpf/ringbuf.c
+++ b/tools/lib/bpf/ringbuf.c
@@ -330,6 +330,14 @@ int ring_buffer__epoll_fd(const struct ring_buffer *rb)
return rb->epoll_fd;
}
+struct ring *ring_buffer__ring(struct ring_buffer *rb, unsigned int idx)
+{
+ if (idx >= rb->ring_cnt)
+ return errno = ERANGE, NULL;
+
+ return rb->rings[idx];
+}
+
static void user_ringbuf_unmap_ring(struct user_ring_buffer *rb)
{
if (rb->consumer_pos) {
--
2.34.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH bpf-next v2 04/14] selftests/bpf: add tests for ring_buffer__ring
2023-09-25 21:50 [PATCH bpf-next v2 00/14] add libbpf getters for individual ringbuffers Martin Kelly
` (2 preceding siblings ...)
2023-09-25 21:50 ` [PATCH bpf-next v2 03/14] libbpf: add ring_buffer__ring Martin Kelly
@ 2023-09-25 21:50 ` Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 05/14] libbpf: add ring__producer_pos, ring__consumer_pos Martin Kelly
` (10 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Martin Kelly @ 2023-09-25 21:50 UTC (permalink / raw)
To: bpf
Cc: Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann,
Martin KaFai Lau, Martin Kelly
Add tests for the new API ring_buffer__ring.
Signed-off-by: Martin Kelly <martin.kelly@crowdstrike.com>
---
.../selftests/bpf/prog_tests/ringbuf_multi.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c b/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c
index 1455911d9fcb..58522195081b 100644
--- a/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c
+++ b/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c
@@ -42,6 +42,8 @@ void test_ringbuf_multi(void)
{
struct test_ringbuf_multi *skel;
struct ring_buffer *ringbuf = NULL;
+ struct ring *ring_old;
+ struct ring *ring;
int err;
int page_size = getpagesize();
int proto_fd = -1;
@@ -84,11 +86,24 @@ void test_ringbuf_multi(void)
if (CHECK(!ringbuf, "ringbuf_create", "failed to create ringbuf\n"))
goto cleanup;
+ /* verify ring_buffer__ring returns expected results */
+ ring = ring_buffer__ring(ringbuf, 0);
+ if (!ASSERT_OK_PTR(ring, "ring_buffer__ring_idx_0"))
+ goto cleanup;
+ ring_old = ring;
+ ring = ring_buffer__ring(ringbuf, 1);
+ ASSERT_ERR_PTR(ring, "ring_buffer__ring_idx_1");
+
err = ring_buffer__add(ringbuf, bpf_map__fd(skel->maps.ringbuf2),
process_sample, (void *)(long)2);
if (CHECK(err, "ringbuf_add", "failed to add another ring\n"))
goto cleanup;
+ /* verify adding a new ring didn't invalidate our older pointer */
+ ring = ring_buffer__ring(ringbuf, 0);
+ if (!ASSERT_EQ(ring, ring_old, "ring_buffer__ring_again"))
+ goto cleanup;
+
err = test_ringbuf_multi__attach(skel);
if (CHECK(err, "skel_attach", "skeleton attachment failed: %d\n", err))
goto cleanup;
--
2.34.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH bpf-next v2 05/14] libbpf: add ring__producer_pos, ring__consumer_pos
2023-09-25 21:50 [PATCH bpf-next v2 00/14] add libbpf getters for individual ringbuffers Martin Kelly
` (3 preceding siblings ...)
2023-09-25 21:50 ` [PATCH bpf-next v2 04/14] selftests/bpf: add tests for ring_buffer__ring Martin Kelly
@ 2023-09-25 21:50 ` Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 06/14] selftests/bpf: add tests for ring__*_pos Martin Kelly
` (9 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Martin Kelly @ 2023-09-25 21:50 UTC (permalink / raw)
To: bpf
Cc: Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann,
Martin KaFai Lau, Martin Kelly
Add APIs to get the producer and consumer position for a given
ringbuffer.
Signed-off-by: Martin Kelly <martin.kelly@crowdstrike.com>
---
tools/lib/bpf/libbpf.h | 18 ++++++++++++++++++
tools/lib/bpf/libbpf.map | 2 ++
tools/lib/bpf/ringbuf.c | 14 ++++++++++++++
3 files changed, 34 insertions(+)
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index de3ef59b9641..ab470179b7fe 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -1264,6 +1264,24 @@ LIBBPF_API int ring_buffer__epoll_fd(const struct ring_buffer *rb);
LIBBPF_API struct ring *ring_buffer__ring(struct ring_buffer *rb,
unsigned int idx);
+/**
+ * @brief **ring__consumer_pos()** returns the current consumer position in the
+ * given ringbuffer.
+ *
+ * @param r A ringbuffer object.
+ * @return The current consumer position.
+ */
+LIBBPF_API unsigned long ring__consumer_pos(const struct ring *r);
+
+/**
+ * @brief **ring__producer_pos()** returns the current producer position in the
+ * given ringbuffer.
+ *
+ * @param r A ringbuffer object.
+ * @return The current producer position.
+ */
+LIBBPF_API unsigned long ring__producer_pos(const struct ring *r);
+
struct user_ring_buffer_opts {
size_t sz; /* size of this struct, for forward/backward compatibility */
};
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
index 7a7370c2bc25..3bec002449d5 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -400,5 +400,7 @@ LIBBPF_1.3.0 {
bpf_program__attach_netfilter;
bpf_program__attach_tcx;
bpf_program__attach_uprobe_multi;
+ ring__consumer_pos;
+ ring__producer_pos;
ring_buffer__ring;
} LIBBPF_1.2.0;
diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c
index efde453395b0..d14a607f6b66 100644
--- a/tools/lib/bpf/ringbuf.c
+++ b/tools/lib/bpf/ringbuf.c
@@ -338,6 +338,20 @@ struct ring *ring_buffer__ring(struct ring_buffer *rb, unsigned int idx)
return rb->rings[idx];
}
+unsigned long ring__consumer_pos(const struct ring *r)
+{
+ /* Synchronizes with smp_store_release() in ringbuf_process_ring(). */
+ return smp_load_acquire(r->consumer_pos);
+}
+
+unsigned long ring__producer_pos(const struct ring *r)
+{
+ /* Synchronizes with smp_store_release() in __bpf_ringbuf_reserve() in
+ * the kernel.
+ */
+ return smp_load_acquire(r->producer_pos);
+}
+
static void user_ringbuf_unmap_ring(struct user_ring_buffer *rb)
{
if (rb->consumer_pos) {
--
2.34.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH bpf-next v2 06/14] selftests/bpf: add tests for ring__*_pos
2023-09-25 21:50 [PATCH bpf-next v2 00/14] add libbpf getters for individual ringbuffers Martin Kelly
` (4 preceding siblings ...)
2023-09-25 21:50 ` [PATCH bpf-next v2 05/14] libbpf: add ring__producer_pos, ring__consumer_pos Martin Kelly
@ 2023-09-25 21:50 ` Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 07/14] libbpf: add ring__avail_data_size Martin Kelly
` (8 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Martin Kelly @ 2023-09-25 21:50 UTC (permalink / raw)
To: bpf
Cc: Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann,
Martin KaFai Lau, Martin Kelly
Add tests for the new APIs ring__producer_pos and ring__consumer_pos.
Signed-off-by: Martin Kelly <martin.kelly@crowdstrike.com>
---
tools/testing/selftests/bpf/prog_tests/ringbuf.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf.c b/tools/testing/selftests/bpf/prog_tests/ringbuf.c
index ac104dc652e3..994a36a2b589 100644
--- a/tools/testing/selftests/bpf/prog_tests/ringbuf.c
+++ b/tools/testing/selftests/bpf/prog_tests/ringbuf.c
@@ -91,6 +91,8 @@ static void ringbuf_subtest(void)
int err, cnt, rb_fd;
int page_size = getpagesize();
void *mmap_ptr, *tmp_ptr;
+ struct ring *ring;
+ unsigned long cons_pos, prod_pos;
skel = test_ringbuf_lskel__open();
if (CHECK(!skel, "skel_open", "skeleton open failed\n"))
@@ -162,6 +164,10 @@ static void ringbuf_subtest(void)
trigger_samples();
+ ring = ring_buffer__ring(ringbuf, 0);
+ if (!ASSERT_OK_PTR(ring, "ring_buffer__ring_idx_0"))
+ goto cleanup;
+
/* 2 submitted + 1 discarded records */
CHECK(skel->bss->avail_data != 3 * rec_sz,
"err_avail_size", "exp %ld, got %ld\n",
@@ -176,6 +182,14 @@ static void ringbuf_subtest(void)
"err_prod_pos", "exp %ld, got %ld\n",
3L * rec_sz, skel->bss->prod_pos);
+ /* verify getting this data directly via the ring object yields the same
+ * results
+ */
+ cons_pos = ring__consumer_pos(ring);
+ ASSERT_EQ(cons_pos, 0, "ring_cons_pos");
+ prod_pos = ring__producer_pos(ring);
+ ASSERT_EQ(prod_pos, 3 * rec_sz, "ring_prod_pos");
+
/* poll for samples */
err = ring_buffer__poll(ringbuf, -1);
--
2.34.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH bpf-next v2 07/14] libbpf: add ring__avail_data_size
2023-09-25 21:50 [PATCH bpf-next v2 00/14] add libbpf getters for individual ringbuffers Martin Kelly
` (5 preceding siblings ...)
2023-09-25 21:50 ` [PATCH bpf-next v2 06/14] selftests/bpf: add tests for ring__*_pos Martin Kelly
@ 2023-09-25 21:50 ` Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 08/14] selftests/bpf: add tests for ring__avail_data_size Martin Kelly
` (7 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Martin Kelly @ 2023-09-25 21:50 UTC (permalink / raw)
To: bpf
Cc: Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann,
Martin KaFai Lau, Martin Kelly
Add ring__avail_data_size for querying the currently available data in
the ringbuffer, similar to the BPF_RB_AVAIL_DATA flag in
bpf_ringbuf_query. This is racy during ongoing operations but is still
useful for overall information on how a ringbuffer is behaving.
Signed-off-by: Martin Kelly <martin.kelly@crowdstrike.com>
---
tools/lib/bpf/libbpf.h | 11 +++++++++++
tools/lib/bpf/libbpf.map | 1 +
tools/lib/bpf/ringbuf.c | 9 +++++++++
3 files changed, 21 insertions(+)
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index ab470179b7fe..d60254c5edc6 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -1282,6 +1282,17 @@ LIBBPF_API unsigned long ring__consumer_pos(const struct ring *r);
*/
LIBBPF_API unsigned long ring__producer_pos(const struct ring *r);
+/**
+ * @brief **ring__avail_data_size()** returns the number of bytes in the
+ * ringbuffer not yet consumed. This has no locking associated with it, so it
+ * can be inaccurate if operations are ongoing while this is called. However, it
+ * should still show the correct trend over the long-term.
+ *
+ * @param r A ringbuffer object.
+ * @return The number of bytes not yet consumed.
+ */
+LIBBPF_API size_t ring__avail_data_size(const struct ring *r);
+
struct user_ring_buffer_opts {
size_t sz; /* size of this struct, for forward/backward compatibility */
};
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
index 3bec002449d5..5184c94c0502 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -400,6 +400,7 @@ LIBBPF_1.3.0 {
bpf_program__attach_netfilter;
bpf_program__attach_tcx;
bpf_program__attach_uprobe_multi;
+ ring__avail_data_size;
ring__consumer_pos;
ring__producer_pos;
ring_buffer__ring;
diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c
index d14a607f6b66..07fbc6adcdd9 100644
--- a/tools/lib/bpf/ringbuf.c
+++ b/tools/lib/bpf/ringbuf.c
@@ -352,6 +352,15 @@ unsigned long ring__producer_pos(const struct ring *r)
return smp_load_acquire(r->producer_pos);
}
+size_t ring__avail_data_size(const struct ring *r)
+{
+ unsigned long cons_pos, prod_pos;
+
+ cons_pos = ring__consumer_pos(r);
+ prod_pos = ring__producer_pos(r);
+ return prod_pos - cons_pos;
+}
+
static void user_ringbuf_unmap_ring(struct user_ring_buffer *rb)
{
if (rb->consumer_pos) {
--
2.34.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH bpf-next v2 08/14] selftests/bpf: add tests for ring__avail_data_size
2023-09-25 21:50 [PATCH bpf-next v2 00/14] add libbpf getters for individual ringbuffers Martin Kelly
` (6 preceding siblings ...)
2023-09-25 21:50 ` [PATCH bpf-next v2 07/14] libbpf: add ring__avail_data_size Martin Kelly
@ 2023-09-25 21:50 ` Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 09/14] libbpf: add ring__size Martin Kelly
` (6 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Martin Kelly @ 2023-09-25 21:50 UTC (permalink / raw)
To: bpf
Cc: Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann,
Martin KaFai Lau, Martin Kelly
Add test for the new API ring__avail_data_size.
Signed-off-by: Martin Kelly <martin.kelly@crowdstrike.com>
---
tools/testing/selftests/bpf/prog_tests/ringbuf.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf.c b/tools/testing/selftests/bpf/prog_tests/ringbuf.c
index 994a36a2b589..254b25b8614c 100644
--- a/tools/testing/selftests/bpf/prog_tests/ringbuf.c
+++ b/tools/testing/selftests/bpf/prog_tests/ringbuf.c
@@ -92,7 +92,7 @@ static void ringbuf_subtest(void)
int page_size = getpagesize();
void *mmap_ptr, *tmp_ptr;
struct ring *ring;
- unsigned long cons_pos, prod_pos;
+ unsigned long avail_data, cons_pos, prod_pos;
skel = test_ringbuf_lskel__open();
if (CHECK(!skel, "skel_open", "skeleton open failed\n"))
@@ -185,6 +185,8 @@ static void ringbuf_subtest(void)
/* verify getting this data directly via the ring object yields the same
* results
*/
+ avail_data = ring__avail_data_size(ring);
+ ASSERT_EQ(avail_data, 3 * rec_sz, "ring_avail_size");
cons_pos = ring__consumer_pos(ring);
ASSERT_EQ(cons_pos, 0, "ring_cons_pos");
prod_pos = ring__producer_pos(ring);
--
2.34.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH bpf-next v2 09/14] libbpf: add ring__size
2023-09-25 21:50 [PATCH bpf-next v2 00/14] add libbpf getters for individual ringbuffers Martin Kelly
` (7 preceding siblings ...)
2023-09-25 21:50 ` [PATCH bpf-next v2 08/14] selftests/bpf: add tests for ring__avail_data_size Martin Kelly
@ 2023-09-25 21:50 ` Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 10/14] selftests/bpf: add tests for ring__size Martin Kelly
` (5 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Martin Kelly @ 2023-09-25 21:50 UTC (permalink / raw)
To: bpf
Cc: Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann,
Martin KaFai Lau, Martin Kelly
Add ring__size to get the total size of a given ringbuffer.
Signed-off-by: Martin Kelly <martin.kelly@crowdstrike.com>
---
tools/lib/bpf/libbpf.h | 10 ++++++++++
tools/lib/bpf/libbpf.map | 1 +
tools/lib/bpf/ringbuf.c | 5 +++++
3 files changed, 16 insertions(+)
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index d60254c5edc6..53e2a645c560 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -1293,6 +1293,16 @@ LIBBPF_API unsigned long ring__producer_pos(const struct ring *r);
*/
LIBBPF_API size_t ring__avail_data_size(const struct ring *r);
+/**
+ * @brief **ring__size()** returns the total size of the ringbuffer's map data
+ * area (excluding special producer/consumer pages). Effectively this gives the
+ * amount of usable bytes of data inside the ringbuffer.
+ *
+ * @param r A ringbuffer object.
+ * @return The total size of the ringbuffer map data area.
+ */
+LIBBPF_API size_t ring__size(const struct ring *r);
+
struct user_ring_buffer_opts {
size_t sz; /* size of this struct, for forward/backward compatibility */
};
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
index 5184c94c0502..a116d0bb3c5d 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -403,5 +403,6 @@ LIBBPF_1.3.0 {
ring__avail_data_size;
ring__consumer_pos;
ring__producer_pos;
+ ring__size;
ring_buffer__ring;
} LIBBPF_1.2.0;
diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c
index 07fbc6adcdd9..98d0767dbb50 100644
--- a/tools/lib/bpf/ringbuf.c
+++ b/tools/lib/bpf/ringbuf.c
@@ -361,6 +361,11 @@ size_t ring__avail_data_size(const struct ring *r)
return prod_pos - cons_pos;
}
+size_t ring__size(const struct ring *r)
+{
+ return r->mask + 1;
+}
+
static void user_ringbuf_unmap_ring(struct user_ring_buffer *rb)
{
if (rb->consumer_pos) {
--
2.34.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH bpf-next v2 10/14] selftests/bpf: add tests for ring__size
2023-09-25 21:50 [PATCH bpf-next v2 00/14] add libbpf getters for individual ringbuffers Martin Kelly
` (8 preceding siblings ...)
2023-09-25 21:50 ` [PATCH bpf-next v2 09/14] libbpf: add ring__size Martin Kelly
@ 2023-09-25 21:50 ` Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 11/14] libbpf: add ring__map_fd Martin Kelly
` (4 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Martin Kelly @ 2023-09-25 21:50 UTC (permalink / raw)
To: bpf
Cc: Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann,
Martin KaFai Lau, Martin Kelly
Add tests for the new API ring__size.
Signed-off-by: Martin Kelly <martin.kelly@crowdstrike.com>
---
tools/testing/selftests/bpf/prog_tests/ringbuf.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf.c b/tools/testing/selftests/bpf/prog_tests/ringbuf.c
index 254b25b8614c..c5be480a6ef6 100644
--- a/tools/testing/selftests/bpf/prog_tests/ringbuf.c
+++ b/tools/testing/selftests/bpf/prog_tests/ringbuf.c
@@ -92,7 +92,7 @@ static void ringbuf_subtest(void)
int page_size = getpagesize();
void *mmap_ptr, *tmp_ptr;
struct ring *ring;
- unsigned long avail_data, cons_pos, prod_pos;
+ unsigned long avail_data, ring_size, cons_pos, prod_pos;
skel = test_ringbuf_lskel__open();
if (CHECK(!skel, "skel_open", "skeleton open failed\n"))
@@ -187,6 +187,8 @@ static void ringbuf_subtest(void)
*/
avail_data = ring__avail_data_size(ring);
ASSERT_EQ(avail_data, 3 * rec_sz, "ring_avail_size");
+ ring_size = ring__size(ring);
+ ASSERT_EQ(ring_size, page_size, "ring_ring_size");
cons_pos = ring__consumer_pos(ring);
ASSERT_EQ(cons_pos, 0, "ring_cons_pos");
prod_pos = ring__producer_pos(ring);
--
2.34.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH bpf-next v2 11/14] libbpf: add ring__map_fd
2023-09-25 21:50 [PATCH bpf-next v2 00/14] add libbpf getters for individual ringbuffers Martin Kelly
` (9 preceding siblings ...)
2023-09-25 21:50 ` [PATCH bpf-next v2 10/14] selftests/bpf: add tests for ring__size Martin Kelly
@ 2023-09-25 21:50 ` Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 12/14] selftests/bpf: add tests for ring__map_fd Martin Kelly
` (3 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Martin Kelly @ 2023-09-25 21:50 UTC (permalink / raw)
To: bpf
Cc: Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann,
Martin KaFai Lau, Martin Kelly
Add ring__map_fd to get the file descriptor underlying a given
ringbuffer.
Signed-off-by: Martin Kelly <martin.kelly@crowdstrike.com>
---
tools/lib/bpf/libbpf.h | 9 +++++++++
tools/lib/bpf/libbpf.map | 1 +
tools/lib/bpf/ringbuf.c | 5 +++++
3 files changed, 15 insertions(+)
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 53e2a645c560..114e306c6507 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -1303,6 +1303,15 @@ LIBBPF_API size_t ring__avail_data_size(const struct ring *r);
*/
LIBBPF_API size_t ring__size(const struct ring *r);
+/**
+ * @brief **ring__map_fd()** returns the file descriptor underlying the given
+ * ringbuffer.
+ *
+ * @param r A ringbuffer object.
+ * @return The underlying ringbuffer file descriptor
+ */
+LIBBPF_API int ring__map_fd(const struct ring *r);
+
struct user_ring_buffer_opts {
size_t sz; /* size of this struct, for forward/backward compatibility */
};
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
index a116d0bb3c5d..1b4225327ab6 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -402,6 +402,7 @@ LIBBPF_1.3.0 {
bpf_program__attach_uprobe_multi;
ring__avail_data_size;
ring__consumer_pos;
+ ring__map_fd;
ring__producer_pos;
ring__size;
ring_buffer__ring;
diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c
index 98d0767dbb50..8aec20216b7b 100644
--- a/tools/lib/bpf/ringbuf.c
+++ b/tools/lib/bpf/ringbuf.c
@@ -366,6 +366,11 @@ size_t ring__size(const struct ring *r)
return r->mask + 1;
}
+int ring__map_fd(const struct ring *r)
+{
+ return r->map_fd;
+}
+
static void user_ringbuf_unmap_ring(struct user_ring_buffer *rb)
{
if (rb->consumer_pos) {
--
2.34.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH bpf-next v2 12/14] selftests/bpf: add tests for ring__map_fd
2023-09-25 21:50 [PATCH bpf-next v2 00/14] add libbpf getters for individual ringbuffers Martin Kelly
` (10 preceding siblings ...)
2023-09-25 21:50 ` [PATCH bpf-next v2 11/14] libbpf: add ring__map_fd Martin Kelly
@ 2023-09-25 21:50 ` Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 13/14] libbpf: add ring__consume Martin Kelly
` (2 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Martin Kelly @ 2023-09-25 21:50 UTC (permalink / raw)
To: bpf
Cc: Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann,
Martin KaFai Lau, Martin Kelly
Add tests for the new API ring__map_fd.
Signed-off-by: Martin Kelly <martin.kelly@crowdstrike.com>
---
tools/testing/selftests/bpf/prog_tests/ringbuf.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf.c b/tools/testing/selftests/bpf/prog_tests/ringbuf.c
index c5be480a6ef6..c23f6c54b373 100644
--- a/tools/testing/selftests/bpf/prog_tests/ringbuf.c
+++ b/tools/testing/selftests/bpf/prog_tests/ringbuf.c
@@ -92,6 +92,7 @@ static void ringbuf_subtest(void)
int page_size = getpagesize();
void *mmap_ptr, *tmp_ptr;
struct ring *ring;
+ int map_fd;
unsigned long avail_data, ring_size, cons_pos, prod_pos;
skel = test_ringbuf_lskel__open();
@@ -168,6 +169,9 @@ static void ringbuf_subtest(void)
if (!ASSERT_OK_PTR(ring, "ring_buffer__ring_idx_0"))
goto cleanup;
+ map_fd = ring__map_fd(ring);
+ ASSERT_EQ(map_fd, skel->maps.ringbuf.map_fd, "ring_map_fd");
+
/* 2 submitted + 1 discarded records */
CHECK(skel->bss->avail_data != 3 * rec_sz,
"err_avail_size", "exp %ld, got %ld\n",
--
2.34.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH bpf-next v2 13/14] libbpf: add ring__consume
2023-09-25 21:50 [PATCH bpf-next v2 00/14] add libbpf getters for individual ringbuffers Martin Kelly
` (11 preceding siblings ...)
2023-09-25 21:50 ` [PATCH bpf-next v2 12/14] selftests/bpf: add tests for ring__map_fd Martin Kelly
@ 2023-09-25 21:50 ` Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 14/14] selftests/bpf: add tests for ring__consume Martin Kelly
2023-09-25 23:30 ` [PATCH bpf-next v2 00/14] add libbpf getters for individual ringbuffers patchwork-bot+netdevbpf
14 siblings, 0 replies; 16+ messages in thread
From: Martin Kelly @ 2023-09-25 21:50 UTC (permalink / raw)
To: bpf
Cc: Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann,
Martin KaFai Lau, Martin Kelly
Add ring__consume to consume a single ringbuffer, analogous to
ring_buffer__consume.
Signed-off-by: Martin Kelly <martin.kelly@crowdstrike.com>
---
tools/lib/bpf/libbpf.h | 10 ++++++++++
tools/lib/bpf/libbpf.map | 1 +
tools/lib/bpf/ringbuf.c | 11 +++++++++++
3 files changed, 22 insertions(+)
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 114e306c6507..475378438545 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -1312,6 +1312,16 @@ LIBBPF_API size_t ring__size(const struct ring *r);
*/
LIBBPF_API int ring__map_fd(const struct ring *r);
+/**
+ * @brief **ring__consume()** consumes available ringbuffer data without event
+ * polling.
+ *
+ * @param r A ringbuffer object.
+ * @return The number of records consumed (or INT_MAX, whichever is less), or
+ * a negative number if any of the callbacks return an error.
+ */
+LIBBPF_API int ring__consume(struct ring *r);
+
struct user_ring_buffer_opts {
size_t sz; /* size of this struct, for forward/backward compatibility */
};
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
index 1b4225327ab6..cc973b678a39 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -401,6 +401,7 @@ LIBBPF_1.3.0 {
bpf_program__attach_tcx;
bpf_program__attach_uprobe_multi;
ring__avail_data_size;
+ ring__consume;
ring__consumer_pos;
ring__map_fd;
ring__producer_pos;
diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c
index 8aec20216b7b..aacb64278a01 100644
--- a/tools/lib/bpf/ringbuf.c
+++ b/tools/lib/bpf/ringbuf.c
@@ -371,6 +371,17 @@ int ring__map_fd(const struct ring *r)
return r->map_fd;
}
+int ring__consume(struct ring *r)
+{
+ int64_t res;
+
+ res = ringbuf_process_ring(r);
+ if (res < 0)
+ return libbpf_err(res);
+
+ return res > INT_MAX ? INT_MAX : res;
+}
+
static void user_ringbuf_unmap_ring(struct user_ring_buffer *rb)
{
if (rb->consumer_pos) {
--
2.34.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH bpf-next v2 14/14] selftests/bpf: add tests for ring__consume
2023-09-25 21:50 [PATCH bpf-next v2 00/14] add libbpf getters for individual ringbuffers Martin Kelly
` (12 preceding siblings ...)
2023-09-25 21:50 ` [PATCH bpf-next v2 13/14] libbpf: add ring__consume Martin Kelly
@ 2023-09-25 21:50 ` Martin Kelly
2023-09-25 23:30 ` [PATCH bpf-next v2 00/14] add libbpf getters for individual ringbuffers patchwork-bot+netdevbpf
14 siblings, 0 replies; 16+ messages in thread
From: Martin Kelly @ 2023-09-25 21:50 UTC (permalink / raw)
To: bpf
Cc: Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann,
Martin KaFai Lau, Martin Kelly
Add tests for new API ring__consume.
Signed-off-by: Martin Kelly <martin.kelly@crowdstrike.com>
---
tools/testing/selftests/bpf/prog_tests/ringbuf.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf.c b/tools/testing/selftests/bpf/prog_tests/ringbuf.c
index c23f6c54b373..48c5695b7abf 100644
--- a/tools/testing/selftests/bpf/prog_tests/ringbuf.c
+++ b/tools/testing/selftests/bpf/prog_tests/ringbuf.c
@@ -304,6 +304,10 @@ static void ringbuf_subtest(void)
err = ring_buffer__consume(ringbuf);
CHECK(err < 0, "rb_consume", "failed: %d\b", err);
+ /* also consume using ring__consume to make sure it works the same */
+ err = ring__consume(ring);
+ ASSERT_GE(err, 0, "ring_consume");
+
/* 3 rounds, 2 samples each */
cnt = atomic_xchg(&sample_cnt, 0);
CHECK(cnt != 6, "cnt", "exp %d samples, got %d\n", 6, cnt);
--
2.34.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH bpf-next v2 00/14] add libbpf getters for individual ringbuffers
2023-09-25 21:50 [PATCH bpf-next v2 00/14] add libbpf getters for individual ringbuffers Martin Kelly
` (13 preceding siblings ...)
2023-09-25 21:50 ` [PATCH bpf-next v2 14/14] selftests/bpf: add tests for ring__consume Martin Kelly
@ 2023-09-25 23:30 ` patchwork-bot+netdevbpf
14 siblings, 0 replies; 16+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-09-25 23:30 UTC (permalink / raw)
To: Martin Kelly; +Cc: bpf, andrii, ast, daniel, martin.lau
Hello:
This series was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:
On Mon, 25 Sep 2023 14:50:31 -0700 you wrote:
> This patch series adds a new ring__ API to libbpf exposing getters for
> accessing the individual ringbuffers inside a struct ring_buffer. This is
> useful for polling individually, getting available data, or similar use
> cases. The API looks like this, and was roughly proposed by Andrii Nakryiko
> in another thread:
>
> Getting a ring struct:
> struct ring *ring_buffer__ring(struct ring_buffer *rb, unsigned int idx);
>
> [...]
Here is the summary with links:
- [bpf-next,v2,01/14] libbpf: refactor cleanup in ring_buffer__add
https://git.kernel.org/bpf/bpf-next/c/4448f64c549c
- [bpf-next,v2,02/14] libbpf: switch rings to array of pointers
https://git.kernel.org/bpf/bpf-next/c/ef3b82003e6c
- [bpf-next,v2,03/14] libbpf: add ring_buffer__ring
https://git.kernel.org/bpf/bpf-next/c/1c97f6afd739
- [bpf-next,v2,04/14] selftests/bpf: add tests for ring_buffer__ring
https://git.kernel.org/bpf/bpf-next/c/c1ad2e47f97c
- [bpf-next,v2,05/14] libbpf: add ring__producer_pos, ring__consumer_pos
https://git.kernel.org/bpf/bpf-next/c/059a8c0c5acd
- [bpf-next,v2,06/14] selftests/bpf: add tests for ring__*_pos
https://git.kernel.org/bpf/bpf-next/c/b18db8712ecf
- [bpf-next,v2,07/14] libbpf: add ring__avail_data_size
https://git.kernel.org/bpf/bpf-next/c/3b34d2972612
- [bpf-next,v2,08/14] selftests/bpf: add tests for ring__avail_data_size
https://git.kernel.org/bpf/bpf-next/c/f3a01d385fbb
- [bpf-next,v2,09/14] libbpf: add ring__size
https://git.kernel.org/bpf/bpf-next/c/e79abf717fce
- [bpf-next,v2,10/14] selftests/bpf: add tests for ring__size
https://git.kernel.org/bpf/bpf-next/c/bb32dd2c8fec
- [bpf-next,v2,11/14] libbpf: add ring__map_fd
https://git.kernel.org/bpf/bpf-next/c/ae769390377a
- [bpf-next,v2,12/14] selftests/bpf: add tests for ring__map_fd
https://git.kernel.org/bpf/bpf-next/c/6e38ba5291f9
- [bpf-next,v2,13/14] libbpf: add ring__consume
https://git.kernel.org/bpf/bpf-next/c/16058ff28b7e
- [bpf-next,v2,14/14] selftests/bpf: add tests for ring__consume
https://git.kernel.org/bpf/bpf-next/c/cb3d7dd2d0db
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2023-09-25 23:30 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-25 21:50 [PATCH bpf-next v2 00/14] add libbpf getters for individual ringbuffers Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 01/14] libbpf: refactor cleanup in ring_buffer__add Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 02/14] libbpf: switch rings to array of pointers Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 03/14] libbpf: add ring_buffer__ring Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 04/14] selftests/bpf: add tests for ring_buffer__ring Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 05/14] libbpf: add ring__producer_pos, ring__consumer_pos Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 06/14] selftests/bpf: add tests for ring__*_pos Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 07/14] libbpf: add ring__avail_data_size Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 08/14] selftests/bpf: add tests for ring__avail_data_size Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 09/14] libbpf: add ring__size Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 10/14] selftests/bpf: add tests for ring__size Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 11/14] libbpf: add ring__map_fd Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 12/14] selftests/bpf: add tests for ring__map_fd Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 13/14] libbpf: add ring__consume Martin Kelly
2023-09-25 21:50 ` [PATCH bpf-next v2 14/14] selftests/bpf: add tests for ring__consume Martin Kelly
2023-09-25 23:30 ` [PATCH bpf-next v2 00/14] add libbpf getters for individual ringbuffers patchwork-bot+netdevbpf
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).