public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
	Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Andi Kleen <ak@linux.intel.com>, Ian Rogers <irogers@google.com>,
	Stephane Eranian <eranian@google.com>
Subject: Re: [PATCH v3] perf evsel: Fix missing exclude_{host,guest} setting
Date: Wed, 3 Nov 2021 08:24:03 +0100	[thread overview]
Message-ID: <YYI5EwCjBojR+1QW@krava> (raw)
In-Reply-To: <CAM9d7cjPq7=HoPAi3Cd3crcNJO8hWu0cU8j4qOTqSMxd7M6BqQ@mail.gmail.com>

On Tue, Nov 02, 2021 at 04:21:21PM -0700, Namhyung Kim wrote:
> Hi Jiri,
> 
> On Tue, Nov 2, 2021 at 7:10 AM Jiri Olsa <jolsa@redhat.com> 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@google.com>
> > > Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> > > ---
> > > 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?

evsel->pmu is not there yet (only evsel->pmu_name) so that
would need to be added.. we have evsel__find_pmu available

then the idea is to use evsel->pmu instead of the hasmap,
like add:

  struct pmu {
    ...
    bool missing_exclude_guest;
  };

set it when the guest filtering fails and and check it
instead of the hashmap__find call

> 
> >
> > 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.

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

jitka

> 
> Thanks,
> Namhyung
> 


  reply	other threads:[~2021-11-03  7:24 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-29 22:49 [PATCH v3] perf evsel: Fix missing exclude_{host,guest} setting Namhyung Kim
2021-10-31 11:13 ` Jiri Olsa
2021-11-01 21:09 ` Arnaldo Carvalho de Melo
2021-11-02 23:08   ` Namhyung Kim
2021-11-02 14:10 ` Jiri Olsa
2021-11-02 23:21   ` Namhyung Kim
2021-11-03  7:24     ` Jiri Olsa [this message]
2021-11-03  7:44       ` Stephane Eranian
2021-11-03 11:32         ` Arnaldo Carvalho de Melo
2021-11-03 17:35           ` Stephane Eranian
2021-11-03 21:03             ` Arnaldo Carvalho de Melo
2021-11-03 22:29               ` Stephane Eranian
2021-11-04 17:40                 ` Arnaldo Carvalho de Melo
2021-11-04 21:38                   ` Namhyung Kim
2021-11-03  7:21 ` Ravi Bangoria
2021-11-05 18:00   ` Namhyung Kim
2021-11-06 19:24     ` Arnaldo Carvalho de Melo
2021-11-07 10:25       ` Ravi Bangoria
2021-11-07 10:57         ` Arnaldo Carvalho de Melo
2021-11-08 18:50         ` Namhyung Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YYI5EwCjBojR+1QW@krava \
    --to=jolsa@redhat.com \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=eranian@google.com \
    --cc=irogers@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox