linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: "liwei (GF)" <liwei391@huawei.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Kan Liang <kan.liang@linux.intel.com>,
	Sean Christopherson <seanjc@google.com>,
	K Prateek Nayak <kprateek.nayak@amd.com>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1] perf header: Fix missing PMU caps
Date: Fri, 25 Aug 2023 10:20:54 -0300	[thread overview]
Message-ID: <ZOiqtn0D8DuWHMKS@kernel.org> (raw)
In-Reply-To: <CAP-5=fUW9VmBoxfeTHL3upqg-gZRuE6Gd3e0LhY_N5UP6Am5ew@mail.gmail.com>

Em Thu, Aug 24, 2023 at 03:54:00PM -0700, Ian Rogers escreveu:
> On Mon, Aug 21, 2023 at 6:16 AM Arnaldo Carvalho de Melo
> <acme@kernel.org> wrote:
> >
> > Em Sat, Aug 19, 2023 at 12:16:09PM +0800, liwei (GF) escreveu:
> > > Hi Ian:
> > >
> > > On 2023/8/19 1:19, Ian Rogers wrote:
> > > > PMU caps are written as HEADER_PMU_CAPS or for the special case of the
> > > > PMU "cpu" as HEADER_CPU_PMU_CAPS. As the PMU "cpu" is special, and not
> > > > any "core" PMU, the logic had become broken and core PMUs not called
> > > > "cpu" were not having their caps written. This affects ARM and s390
> > > > non-hybrid PMUs.
> > > >
> > > > Simplify the PMU caps writing logic to scan one fewer time and to be
> > > > more explicit in its behavior.
> > > >
> > > > Reported-by: Wei Li <liwei391@huawei.com>
> > > > Fixes: 178ddf3bad98 ("perf header: Avoid hybrid PMU list in write_pmu_caps")
> > > > Signed-off-by: Ian Rogers <irogers@google.com>
> > > > ---
> > > >  tools/perf/util/header.c | 31 ++++++++++++++++---------------
> > > >  1 file changed, 16 insertions(+), 15 deletions(-)
> > > >
> > > > diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> > > > index 52fbf526fe74..13c71d28e0eb 100644
> > > > --- a/tools/perf/util/header.c
> > > > +++ b/tools/perf/util/header.c
> > > > @@ -1605,8 +1605,15 @@ static int write_pmu_caps(struct feat_fd *ff,
> > > >     int ret;
> > > >
> > > >     while ((pmu = perf_pmus__scan(pmu))) {
> > > > -           if (!pmu->name || !strcmp(pmu->name, "cpu") ||
> > > > -               perf_pmu__caps_parse(pmu) <= 0)
> > > > +           if (!strcmp(pmu->name, "cpu")) {
> > >
> > > So you removed the check of 'pmu->name', does this check really redundant? since
> > > we can find such checks in many places in the perf code. If not, i think it is
> > > necessary for strcmp().
> >
> > Indeed, when sorting in tools/perf/util/pmus.c in cmp_sevent() we have:
> >
> >         /* Order by PMU name. */
> >         if (as->pmu != bs->pmu) {
> >                 a_pmu_name = a_pmu_name ?: (as->pmu->name ?: "");
> >                 b_pmu_name = b_pmu_name ?: (bs->pmu->name ?: "");
> >                 ret = strcmp(a_pmu_name, b_pmu_name);
> >                 if (ret)
> >                         return ret;
> >         }
> >
> >
> > And even if in this specific case, for some reason, we could guarantee
> > that pmu->name isn't NULL, then removing that check should be best left
> > for a separate patch with an explanation as to why that is safe.
> >
> > Having it as:
> >
> >         while ((pmu = perf_pmus__scan(pmu))) {
> > -               if (!pmu->name || !strcmp(pmu->name, "cpu") ||
> > -                   perf_pmu__caps_parse(pmu) <= 0)
> > +               if (!pmu->name || !strcmp(pmu->name, "cpu")) {
> >
> > even eases a bit reviewing, as we see we're just removing that
> > perf_pmu__caps_parse(pmu) line.
> >
> > Ian?
> 
> The pmu name is initialized with:
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/pmu.c?h=perf-tools-next#n1001
> pmu->name = strdup(name);
> if (!pmu->name)
> goto err;
> 
> so name can't be NULL, strdup of NULL is segv, as if it were pmu would
> be NULL. I'll clean this up in an additional patch on top of this one.

Ok, perhaps at some point we can introduce a perf_pmu__name_is(pmu,
"cpu") and then have an assert for it not being NULL, as for some time
those tests were performed.

But thanks for checking, I'll apply the patches.

- Arnaldo

 
> Thanks,
> Ian
> 
> > - Arnaldo
> >
> >
> > > > +                   /*
> > > > +                    * The "cpu" PMU is special and covered by
> > > > +                    * HEADER_CPU_PMU_CAPS. Note, core PMUs are
> > > > +                    * counted/written here for ARM, s390 and Intel hybrid.
> > > > +                    */
> > > > +                   continue;
> > > > +           }
> > > > +           if (perf_pmu__caps_parse(pmu) <= 0)
> > > >                     continue;
> > > >             nr_pmu++;
> > > >     }
> > > > @@ -1619,23 +1626,17 @@ static int write_pmu_caps(struct feat_fd *ff,
> > > >             return 0;
> > > >
> > > >     /*
> > > > -    * Write hybrid pmu caps first to maintain compatibility with
> > > > -    * older perf tool.
> > > > +    * Note older perf tools assume core PMUs come first, this is a property
> > > > +    * of perf_pmus__scan.
> > > >      */
> > > > -   if (perf_pmus__num_core_pmus() > 1) {
> > > > -           pmu = NULL;
> > > > -           while ((pmu = perf_pmus__scan_core(pmu))) {
> > > > -                   ret = __write_pmu_caps(ff, pmu, true);
> > > > -                   if (ret < 0)
> > > > -                           return ret;
> > > > -           }
> > > > -   }
> > > > -
> > > >     pmu = NULL;
> > > >     while ((pmu = perf_pmus__scan(pmu))) {
> > > > -           if (pmu->is_core || !pmu->nr_caps)
> > > > +           if (!strcmp(pmu->name, "cpu")) {
> > >
> > > same here
> > >
> > > Thanks,
> > > Wei
> > >
> > > > +                   /* Skip as above. */
> > > > +                   continue;
> > > > +           }
> > > > +           if (perf_pmu__caps_parse(pmu) <= 0)
> > > >                     continue;
> > > > -
> > > >             ret = __write_pmu_caps(ff, pmu, true);
> > > >             if (ret < 0)
> > > >                     return ret;
> >
> > --
> >
> > - Arnaldo

-- 

- Arnaldo

      reply	other threads:[~2023-08-25 13:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-18 17:19 [PATCH v1] perf header: Fix missing PMU caps Ian Rogers
2023-08-19  4:16 ` liwei (GF)
2023-08-21 13:16   ` Arnaldo Carvalho de Melo
2023-08-24 22:54     ` Ian Rogers
2023-08-25 13:20       ` Arnaldo Carvalho de Melo [this message]

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=ZOiqtn0D8DuWHMKS@kernel.org \
    --to=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=liwei391@huawei.com \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=seanjc@google.com \
    /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;
as well as URLs for NNTP newsgroup(s).