2023-09-05 16:23:23

by Leo Yan

[permalink] [raw]
Subject: Re: [PATCH v6] Documentation: userspace-api: Document perf ring buffer mechanism

Hi Namhyung,

On Sat, Aug 26, 2023 at 07:45:15AM -0700, Namhyung Kim wrote:

[...]

> > > > The combination is supported in perf tool:
> > > >
> > > > ---+------------+-----------
> > > > | Forward | Backward
> > > > ---+------------+-----------
> > > > rw | Yes | No
> > > > ---+------------+-----------
> > > > ro | X | Yes
> > > > ---+------------+-----------
> > > >
> > > > Yes: is supported
> > > > No: is not supported
> > > > X: is not feasible
> > >
> > > I think they are all supported. You can use rw mode with backward
> > > direction but it's just not intuitive. Also ro mode with forward direction
> > > is working but there's a chance to miss the start position of the
> > > previous event.
> >
> > I am a bit confused for the all four modes are supported.
> >
> > From the code [1], we can see there have only two combinations:
> >
> > - overwrite + read-only mode (PROT_READ);
> > - no-overwrite + read-write mode (PROT_READ | PROT_WRITE);
> >
> > And I think perf tool must use the backward writing for "overwrite",
> > and use the forward writing for "non-overwrite" mode. I think the
> > code [2] can help us to conclude this.
>
> I mean the kernel supports all the combinations but perf tool uses
> the selected two. IIUC you are describing the kernel behavior, right?

You are right. I read the kernel code again and get the same conclusion
with you.

The kernel code is general enough, which supports forward and backward
writing directions and doesn't assume the direction is bound to any
specific ring buffer mode. On the other hand, the perf tool selects
the combinations of the direction and mapping property for two modes:
one is the non-overwrite mode and another is the overwritable mode.

In the next spin, I'd like to add a subsection "Ring buffer modes" to
describe the implementation in the kernel and userspace respectively,
hope this can avoid confusion.

Thanks a lot for suggestion!


Leo