Re: [PATCH v3] perf evsel: Fix missing exclude_{host,guest} setting

From: Namhyung Kim
Date: Thu Nov 04 2021 - 17:38:54 EST


On Thu, Nov 4, 2021 at 10:40 AM Arnaldo Carvalho de Melo
<acme@xxxxxxxxxx> wrote:
>
> Em Wed, Nov 03, 2021 at 03:29:50PM -0700, Stephane Eranian escreveu:
> > On Wed, Nov 3, 2021 at 2:03 PM Arnaldo Carvalho de Melo <acme@xxxxxxxxxx> wrote:
> > > Em Wed, Nov 03, 2021 at 10:35:04AM -0700, Stephane Eranian escreveu:
> > > > On Wed, Nov 3, 2021 at 4:32 AM Arnaldo Carvalho de Melo <acme@xxxxxxxxxx> wrote:
> > > > > Em Wed, Nov 03, 2021 at 12:44:12AM -0700, Stephane Eranian escreveu:
> > > > > > On Wed, Nov 3, 2021 at 12:24 AM Jiri Olsa <jolsa@xxxxxxxxxx> wrote:
> > > > > > > > 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.
>
> > > > > > > hm, I think if pmu doesn't support host/guest filtering then
> > > > > > > I think 'pmu/bla1/G' should error, no? better no number than
> > > > > > > bad number
>
> > > > > > Yes, it should in my opinion.
>
> > > > > Yeah, I thought about this yesterday (holiday here).
>
> > > > Otherwise you create the illusion that you are monitoring in guest
> > > > mode when you are not.
>
> > > > The question is: how can the tool know which modifiers are supported
> > > > per pmu model?
>
> > > As things stand kernel-wise, we should just do capability querying, i.e.
> > > if the user asks for a feature not available for a specific PMU, we
> > > should refuse and provide a helpful error message to the user.
>
> > > If the PMUs in the kernel had some kind of mask that stated what of the
> > > 'struct perf_event_attr' selectable features are supported, then we
> > > would just be able to avoid bothering the kernel asking for unsupported
> > > stuff.
>
> > I think we could add something like that in the sysfs entry for each
> > PMU instance.
> > that would avoid all these perf_event_open() calls and trying to
> > decipher the error
> > code.
>
> That would speed up these checks with newer kernels, yeah, with older
> kernels we'd fall back to what we have now + bailing out in the current
> case (PMUs not supporting exclude_guest).

Agreed.

>
> > > Just for exclude_guest we don't even need to have
> > > evsel->pmu->missing_features.exclude_guest, as this is a hard error, no
> > > point in caching previous capability queries.

But we set attr.exclude_guest by default so we should check
if the user set the modifier explicitly or not.

With the explicit G modifier, it should fail immediately.
If it's implicit, then we should remove it from the attr
and proceed. So it's worth it to cache the result.

I think we don't need to fill evsel->pmu link unnecessarily.
I mean we can set it only if needed (for exclude_guest)
and keep a NULL pointer when it has no problem.

Thanks,
Namhyung