Libbpf userspace function ring_buffer__new
Create a new ring buffer manager.
Definition
typedef int (*ring_buffer_sample_fn)(void *ctx, void *data, size_t size);
struct ring_buffer * ring_buffer__new(int map_fd, ring_buffer_sample_fn sample_cb, void *ctx, const struct ring_buffer_opts *opts);
Parameters
map_fd
: file descriptor of theBPF_MAP_TYPE_RINGBUF
map of the first ring buffer that will be part of the ring buffer managersample_cb
: callback function that will be called when a sample is ready for the initial ring bufferctx
: context that will be passed to the callback functionopts
: options for the ring buffer
Returns
A pointer to the newly created ring buffer manager, or NULL
on error. errno
is set to the error code on error.
struct ring_buffer_opts
struct ring_buffer_opts {
size_t sz; /* size of this struct, for forward/backward compatibility */
};
Usage
A ring buffer in this context is a circular buffer where eBPF programs are producers and userspace is the consumer. Even tough the returned value is struct ring_buffer *
, it actually is a "manager" for multiple ring buffers (struct ring
).
All ring buffers that are part of this ring buffer manager can be epoll
-ed together, to get notified of pending data on any of the rings.
A ring buffer manager always contains at least one ring, the map_fd
, sample_cb
, and ctx
parameters are used to create the first ring buffer. It internally calls ring_buffer__add
to add the first ring buffer.
Example
Docs could be improved
This part of the docs is incomplete, contributions are very welcome