mirror of
https://github.com/netdata/libbpf.git
synced 2026-04-07 09:09:06 +08:00
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
This commit is contained in:
committed by
Andrii Nakryiko
parent
a20576f5f2
commit
2ad16b970a
18
src/libbpf.h
18
src/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,
|
LIBBPF_API struct ring *ring_buffer__ring(struct ring_buffer *rb,
|
||||||
unsigned int idx);
|
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 {
|
struct user_ring_buffer_opts {
|
||||||
size_t sz; /* size of this struct, for forward/backward compatibility */
|
size_t sz; /* size of this struct, for forward/backward compatibility */
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -400,5 +400,7 @@ LIBBPF_1.3.0 {
|
|||||||
bpf_program__attach_netfilter;
|
bpf_program__attach_netfilter;
|
||||||
bpf_program__attach_tcx;
|
bpf_program__attach_tcx;
|
||||||
bpf_program__attach_uprobe_multi;
|
bpf_program__attach_uprobe_multi;
|
||||||
|
ring__consumer_pos;
|
||||||
|
ring__producer_pos;
|
||||||
ring_buffer__ring;
|
ring_buffer__ring;
|
||||||
} LIBBPF_1.2.0;
|
} LIBBPF_1.2.0;
|
||||||
|
|||||||
@@ -338,6 +338,20 @@ struct ring *ring_buffer__ring(struct ring_buffer *rb, unsigned int idx)
|
|||||||
return rb->rings[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)
|
static void user_ringbuf_unmap_ring(struct user_ring_buffer *rb)
|
||||||
{
|
{
|
||||||
if (rb->consumer_pos) {
|
if (rb->consumer_pos) {
|
||||||
|
|||||||
Reference in New Issue
Block a user