Re: [PATCH v3] perf evsel: Fix missing exclude_{host,guest} setting
From: Namhyung Kim
Date: Tue Nov 02 2021 - 19:21:39 EST
Hi Jiri,
On Tue, Nov 2, 2021 at 7:10 AM Jiri Olsa <jolsa@xxxxxxxxxx> wrote:
>
> On Fri, Oct 29, 2021 at 03:49:29PM -0700, Namhyung Kim wrote:
> > The current logic for the perf missing feature has a bug that it can
> > wrongly clear some modifiers like G or H. Actually some PMUs don't
> > support any filtering or exclusion while others do. But we check it
> > as a global feature.
> >
> > For example, the cycles event can have 'G' modifier to enable it only
> > in the guest mode on x86. When you don't run any VMs it'll return 0.
> >
> > # perf stat -a -e cycles:G sleep 1
> >
> > Performance counter stats for 'system wide':
> >
> > 0 cycles:G
> >
> > 1.000721670 seconds time elapsed
> >
> > But when it's used with other pmu events that don't support G modifier,
> > it'll be reset and return non-zero values.
> >
> > # perf stat -a -e cycles:G,msr/tsc/ sleep 1
> >
> > Performance counter stats for 'system wide':
> >
> > 538,029,960 cycles:G
> > 16,924,010,738 msr/tsc/
> >
> > 1.001815327 seconds time elapsed
> >
> > This is because of the missing feature detection logic being global.
> > Add a hashmap to set pmu-specific exclude_host/guest features.
> >
> > Reported-by: Stephane Eranian <eranian@xxxxxxxxxx>
> > Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
> > ---
> > v3 changes)
> > * check memory allocation failure
> > * add more NULL check
>
> we were discussing this with Arnaldo yesterday and he had an idea to use
> evsel->pmu link to store this info instead of hash.. I first thought we
> needed 'evsel' related data, but after I gave it some thought I think that
> might actually work
I don't get it.. do we have evsel->pmu already? Or do you want to add it?
Yeah, the filtering facility (attr.exclude_*) should be kept in a PMU data
not in the evsel. So I added a hashmap to find the pmu data from attr.type.
How do I use evsel->pmu to store the info then?
>
> my argument was following usecase:
>
> cycles:G,instructions:G,pmu/bla1/:G,pmu/bla2/
>
> that we would falsely clear pmu/bla1/:G if we used the 'evsel->pmu' data..
> but then I realized it's detection if pmu support :G and so if the :G is
> not there, none of the events should have it
>
> thoughts?
I don't think I'm following well... ;-p
If the pmu doesn't support host/guest filtering, pmu/bla1/G
may count something. Not sure if it's better to error out.
But the cycles:G and instructions:G should result in 0
in case there's no VM running.
Thanks,
Namhyung