diff options
author | Martin Kelly <martin.kelly@crowdstrike.com> | 2023-09-25 14:50:40 -0700 |
---|---|---|
committer | Andrii Nakryiko <andrii.nakryiko@gmail.com> | 2023-10-02 11:17:48 -0700 |
commit | cd3fe56c75a188dabe3b7a3474f1b0bedb8343c8 (patch) | |
tree | a875399b92527e9ae98dd34ddfa483a523b8ba05 | |
parent | 3e675ed6aba10468577783eb792e9a981d6b639a (diff) | |
download | libbpf-cd3fe56c75a188dabe3b7a3474f1b0bedb8343c8.tar.gz |
libbpf: Add ring__size
Add ring__size to get the total size of a given ringbuffer.
Signed-off-by: Martin Kelly <martin.kelly@crowdstrike.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20230925215045.2375758-10-martin.kelly@crowdstrike.com
-rw-r--r-- | src/libbpf.h | 10 | ||||
-rw-r--r-- | src/libbpf.map | 1 | ||||
-rw-r--r-- | src/ringbuf.c | 5 |
3 files changed, 16 insertions, 0 deletions
diff --git a/src/libbpf.h b/src/libbpf.h index d60254c..53e2a64 100644 --- a/src/libbpf.h +++ b/src/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/src/libbpf.map b/src/libbpf.map index 5184c94..a116d0b 100644 --- a/src/libbpf.map +++ b/src/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/src/ringbuf.c b/src/ringbuf.c index 07fbc6a..98d0767 100644 --- a/src/ringbuf.c +++ b/src/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) { |