diff options
author | Martin Kelly <martin.kelly@crowdstrike.com> | 2023-09-25 14:50:36 -0700 |
---|---|---|
committer | Andrii Nakryiko <andrii@kernel.org> | 2023-09-25 16:22:42 -0700 |
commit | 059a8c0c5acd37ecfa64f1832e8765d30f253ce8 (patch) | |
tree | 121e16ee53c4f30fdcac2e5452510c153c6ce7aa /tools/lib/bpf/ringbuf.c | |
parent | c1ad2e47f97c6d95e52be0c2a68b23fc99214734 (diff) | |
download | linux-059a8c0c5acd37ecfa64f1832e8765d30f253ce8.tar.gz linux-059a8c0c5acd37ecfa64f1832e8765d30f253ce8.tar.bz2 linux-059a8c0c5acd37ecfa64f1832e8765d30f253ce8.zip |
libbpf: Add ring__producer_pos, ring__consumer_pos
Add APIs to get the producer and consumer position for 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-6-martin.kelly@crowdstrike.com
Diffstat (limited to 'tools/lib/bpf/ringbuf.c')
-rw-r--r-- | tools/lib/bpf/ringbuf.c | 14 |
1 files changed, 14 insertions, 0 deletions
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) { |