Commit 16058ff2 authored by Martin Kelly's avatar Martin Kelly Committed by Andrii Nakryiko

libbpf: Add ring__consume

Add ring__consume to consume a single ringbuffer, analogous to
ring_buffer__consume.
Signed-off-by: default avatarMartin Kelly <martin.kelly@crowdstrike.com>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20230925215045.2375758-14-martin.kelly@crowdstrike.com
parent 6e38ba52
...@@ -1312,6 +1312,16 @@ LIBBPF_API size_t ring__size(const struct ring *r); ...@@ -1312,6 +1312,16 @@ LIBBPF_API size_t ring__size(const struct ring *r);
*/ */
LIBBPF_API int ring__map_fd(const struct ring *r); LIBBPF_API int ring__map_fd(const struct ring *r);
/**
* @brief **ring__consume()** consumes available ringbuffer data without event
* polling.
*
* @param r A ringbuffer object.
* @return The number of records consumed (or INT_MAX, whichever is less), or
* a negative number if any of the callbacks return an error.
*/
LIBBPF_API int ring__consume(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 */
}; };
......
...@@ -401,6 +401,7 @@ LIBBPF_1.3.0 { ...@@ -401,6 +401,7 @@ LIBBPF_1.3.0 {
bpf_program__attach_tcx; bpf_program__attach_tcx;
bpf_program__attach_uprobe_multi; bpf_program__attach_uprobe_multi;
ring__avail_data_size; ring__avail_data_size;
ring__consume;
ring__consumer_pos; ring__consumer_pos;
ring__map_fd; ring__map_fd;
ring__producer_pos; ring__producer_pos;
......
...@@ -371,6 +371,17 @@ int ring__map_fd(const struct ring *r) ...@@ -371,6 +371,17 @@ int ring__map_fd(const struct ring *r)
return r->map_fd; return r->map_fd;
} }
int ring__consume(struct ring *r)
{
int64_t res;
res = ringbuf_process_ring(r);
if (res < 0)
return libbpf_err(res);
return res > INT_MAX ? INT_MAX : res;
}
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) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment