mirror of
https://github.com/netdata/libbpf.git
synced 2026-04-05 08:09:07 +08:00
libbpf: Add ring_buffer__ring
Add a new function ring_buffer__ring, which exposes struct ring * to the user, representing a single 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-4-martin.kelly@crowdstrike.com
This commit is contained in:
committed by
Andrii Nakryiko
parent
bfa471bc85
commit
a20576f5f2
15
src/libbpf.h
15
src/libbpf.h
@@ -1229,6 +1229,7 @@ LIBBPF_API int bpf_tc_query(const struct bpf_tc_hook *hook,
|
|||||||
|
|
||||||
/* Ring buffer APIs */
|
/* Ring buffer APIs */
|
||||||
struct ring_buffer;
|
struct ring_buffer;
|
||||||
|
struct ring;
|
||||||
struct user_ring_buffer;
|
struct user_ring_buffer;
|
||||||
|
|
||||||
typedef int (*ring_buffer_sample_fn)(void *ctx, void *data, size_t size);
|
typedef int (*ring_buffer_sample_fn)(void *ctx, void *data, size_t size);
|
||||||
@@ -1249,6 +1250,20 @@ LIBBPF_API int ring_buffer__poll(struct ring_buffer *rb, int timeout_ms);
|
|||||||
LIBBPF_API int ring_buffer__consume(struct ring_buffer *rb);
|
LIBBPF_API int ring_buffer__consume(struct ring_buffer *rb);
|
||||||
LIBBPF_API int ring_buffer__epoll_fd(const struct ring_buffer *rb);
|
LIBBPF_API int ring_buffer__epoll_fd(const struct ring_buffer *rb);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief **ring_buffer__ring()** returns the ringbuffer object inside a given
|
||||||
|
* ringbuffer manager representing a single BPF_MAP_TYPE_RINGBUF map instance.
|
||||||
|
*
|
||||||
|
* @param rb A ringbuffer manager object.
|
||||||
|
* @param idx An index into the ringbuffers contained within the ringbuffer
|
||||||
|
* manager object. The index is 0-based and corresponds to the order in which
|
||||||
|
* ring_buffer__add was called.
|
||||||
|
* @return A ringbuffer object on success; NULL and errno set if the index is
|
||||||
|
* invalid.
|
||||||
|
*/
|
||||||
|
LIBBPF_API struct ring *ring_buffer__ring(struct ring_buffer *rb,
|
||||||
|
unsigned int idx);
|
||||||
|
|
||||||
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,4 +400,5 @@ 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_buffer__ring;
|
||||||
} LIBBPF_1.2.0;
|
} LIBBPF_1.2.0;
|
||||||
|
|||||||
@@ -330,6 +330,14 @@ int ring_buffer__epoll_fd(const struct ring_buffer *rb)
|
|||||||
return rb->epoll_fd;
|
return rb->epoll_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ring *ring_buffer__ring(struct ring_buffer *rb, unsigned int idx)
|
||||||
|
{
|
||||||
|
if (idx >= rb->ring_cnt)
|
||||||
|
return errno = ERANGE, NULL;
|
||||||
|
|
||||||
|
return rb->rings[idx];
|
||||||
|
}
|
||||||
|
|
||||||
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