Message ID | 20230914231123.193901-10-martin.kelly@crowdstrike.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | BPF |
Headers | show |
Series | add libbpf getters for individual ringbuffers | expand |
On Thu, Sep 14, 2023 at 4:12 PM Martin Kelly <martin.kelly@crowdstrike.com> wrote: > > 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 | 8 ++++++++ > tools/lib/bpf/libbpf.map | 1 + > tools/lib/bpf/ringbuf.c | 5 +++++ > 3 files changed, 14 insertions(+) > > diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h > index 87e3bad37737..299d98402ad4 100644 > --- a/tools/lib/bpf/libbpf.h > +++ b/tools/lib/bpf/libbpf.h > @@ -1290,6 +1290,14 @@ 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. it's confusing to use "ringbuffer" here, as you refer to ring buffer *manager* and to ring buffer *map* inside it with this. Let's be more precise and also maybe mention that this is the size of ring buffer's map data area (excluding producer/consumer pages) > + * > + * @param r A ring object. > + * @return The total size of the ringbuffer. > + */ > +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 f66d7f0bc224..4ca77e715667 100644 > --- a/tools/lib/bpf/libbpf.map > +++ b/tools/lib/bpf/libbpf.map > @@ -404,4 +404,5 @@ LIBBPF_1.3.0 { > ring__avail_data_size; > ring__consumer_pos; > ring__producer_pos; > + ring__size; > } LIBBPF_1.2.0; > diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c > index f51ad1af6ab8..52c385195f32 100644 > --- a/tools/lib/bpf/ringbuf.c > +++ b/tools/lib/bpf/ringbuf.c > @@ -355,6 +355,11 @@ size_t ring__avail_data_size(const struct ring *r) > return ring__producer_pos(r) - ring__consumer_pos(r); > } > > +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 >
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index 87e3bad37737..299d98402ad4 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -1290,6 +1290,14 @@ 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. + * + * @param r A ring object. + * @return The total size of the ringbuffer. + */ +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 f66d7f0bc224..4ca77e715667 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -404,4 +404,5 @@ LIBBPF_1.3.0 { ring__avail_data_size; ring__consumer_pos; ring__producer_pos; + ring__size; } LIBBPF_1.2.0; diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c index f51ad1af6ab8..52c385195f32 100644 --- a/tools/lib/bpf/ringbuf.c +++ b/tools/lib/bpf/ringbuf.c @@ -355,6 +355,11 @@ size_t ring__avail_data_size(const struct ring *r) return ring__producer_pos(r) - ring__consumer_pos(r); } +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) {
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 | 8 ++++++++ tools/lib/bpf/libbpf.map | 1 + tools/lib/bpf/ringbuf.c | 5 +++++ 3 files changed, 14 insertions(+)