diff options
author | Martin Kelly <martin.kelly@crowdstrike.com> | 2023-09-26 00:50:38 +0300 |
---|---|---|
committer | Andrii Nakryiko <andrii@kernel.org> | 2023-09-26 02:22:42 +0300 |
commit | 3b34d2972612299fb38ad7f3c2bc62c2d03237f3 (patch) | |
tree | e5045f2680621f6877dbad69369640cd65c0c4e5 /tools/lib/bpf/ringbuf.c | |
parent | b18db8712ecf5c880da222f6e0d7be53f0af4c4d (diff) | |
download | linux-3b34d2972612299fb38ad7f3c2bc62c2d03237f3.tar.xz |
libbpf: Add ring__avail_data_size
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>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20230925215045.2375758-8-martin.kelly@crowdstrike.com
Diffstat (limited to 'tools/lib/bpf/ringbuf.c')
-rw-r--r-- | tools/lib/bpf/ringbuf.c | 9 |
1 files changed, 9 insertions, 0 deletions
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) { |