Re: [RESEND PATCH V3 1/6] perf: Add branch stack extra

From: Andi Kleen
Date: Tue Oct 03 2023 - 12:56:04 EST


On Tue, Oct 03, 2023 at 06:33:00PM +0200, Peter Zijlstra wrote:
> On Tue, Oct 03, 2023 at 08:06:59AM -0700, Andi Kleen wrote:
> > > I'm thinking we should do something like expose branch_counter_nr and
> > > branch_counter_width in the sysfs node, and then rename this extra field
> > > to counters.
> > >
> > > Then userspace can do something like:
> > >
> > > for (i = 0; i < branch_counter_nr; i++) {
> > > counter[i] = counters & ((1 << branch_counter_width) - 1);
> > > counters >>= branch_counter_width;
> > > }
> > >
> > > to extract the actual counter values.
> >
> > perf script/report won't necessarily have access to the sysfs
> > values if they run on a different system
> >
> > It would need extra PT style metadata written by perf record to
> > perf.data and read by the user tools.
> >
> > Seems complicated. It would be better if it just parsed on its own.
>
> Well, you really don't want to repeat the 4,2 thing in every event, that
> seems daft (and a waste of space, because how large do we want those
> fields to be etc..).

It's just a few bits? It could be an extra 16bit field or so per event.

There are probably other self describing encodings for the numbers
(e.g. some variant of LEB128 on a sub byte level), but that might be more
expensive to store it.

What would worry me is that various users would just hard code and then
fail later. There are lots of non perf tools perf.data parsers around
these days.

-Andi