Commit e79abf71 authored by Martin Kelly's avatar Martin Kelly Committed by Andrii Nakryiko
Browse files

libbpf: Add ring__size



Add ring__size to get the total size of a given ringbuffer.

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-10-martin.kelly@crowdstrike.com
parent f3a01d38
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -1293,6 +1293,16 @@ LIBBPF_API unsigned long ring__producer_pos(const struct ring *r);
 */
LIBBPF_API size_t ring__avail_data_size(const struct ring *r);

/**
 * @brief **ring__size()** returns the total size of the ringbuffer's map data
 * area (excluding special producer/consumer pages). Effectively this gives the
 * amount of usable bytes of data inside the ringbuffer.
 *
 * @param r A ringbuffer object.
 * @return The total size of the ringbuffer map data area.
 */
LIBBPF_API size_t ring__size(const struct ring *r);

struct user_ring_buffer_opts {
	size_t sz; /* size of this struct, for forward/backward compatibility */
};
+1 −0
Original line number Diff line number Diff line
@@ -403,5 +403,6 @@ LIBBPF_1.3.0 {
		ring__avail_data_size;
		ring__consumer_pos;
		ring__producer_pos;
		ring__size;
		ring_buffer__ring;
} LIBBPF_1.2.0;
+5 −0
Original line number Diff line number Diff line
@@ -361,6 +361,11 @@ size_t ring__avail_data_size(const struct ring *r)
	return prod_pos - cons_pos;
}

size_t ring__size(const struct ring *r)
{
	return r->mask + 1;
}

static void user_ringbuf_unmap_ring(struct user_ring_buffer *rb)
{
	if (rb->consumer_pos) {