Re: [PATCH 1/2] ring-buffer: Introducing ring-buffer mapping functions

From: Steven Rostedt
Date: Tue Mar 21 2023 - 12:52:18 EST


On Tue, 21 Mar 2023 16:20:42 +0000
Vincent Donnefort <vdonnefort@xxxxxxxxxx> wrote:

> > > Do we want a specific field here? That could be deduced from nr_data_pages()
> > > quite easily?
> >
> > I rather not have too much implementation detail knowledge in user space.
> > It only removes a single entry, and it makes user space easier. In fact,
>
> Ack.
>
> > I'm thinking we should not include "__u32 data_pages[]" but instead add a:
> > "__u32 data_start" where user space does:
> >
> > __u32 *data_pages = (_u32 *)meta_page + meta_page->data_start;
> >
> > That way we could extend the data provided by the meta_page in the future.
>
> That'd be nice. Couldn't we keep both to simplify the code for the kernel side?

I would not expose the data_pages[] to user space, because then they'll use
it, and that *will* become an API.

But we could expose it to the kernel side with;

include/uapi/linux/trace_mmap.h:

struct ring_buffer_meta_page {
#if __BITS_PER_LONG == 64
__u64 entries;
__u64 overrun;
#else
__u32 entries;
__u32 overrun;
#endif
__u32 pages_touched;
__u32 reader_page;
__u32 nr_data_pages; /* doesn't take into account the reader_page */
__u32 data_page_head; /* index of data_pages[] */
__u32 meta_page_size; /* size of the meta page */
__u32 data_start; /* offset to where data_pages are */
};

kernel/trace/ring_buffer.c:

struct ring_buffer_meta {
struct ring_buffer_meta_page meta;
u32 data_pages[];
}

Then we can start each function with:

struct ring_buffer_meta_page *meta = &cpu_buffer->meta_page.meta;
u32 *data_pages = cpu_buffer->meta_page.data_pages;

-- Steve