Message ID | 1695037955-107983-2-git-send-email-renyu.zj@linux.alibaba.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2596363vqi; Mon, 18 Sep 2023 04:56:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHdKcXqOIBzs/Awm0NmXRfUwmj34O+PkIKl1XDtNDqe3EmjCI72NwMApi09qeRKkZHbnmeS X-Received: by 2002:a9d:798d:0:b0:6b9:67e4:eba7 with SMTP id h13-20020a9d798d000000b006b967e4eba7mr9418227otm.23.1695038200545; Mon, 18 Sep 2023 04:56:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695038200; cv=none; d=google.com; s=arc-20160816; b=RQwD8jlSvqfGheclKXZHsv75zj6+SRdLXLalSl9H7w0Ka/CysKv5qrRzHLI34/oQWc GUd7eOw1Y8fCVzyT4LRIE3TroQXOVo3GQjwoF4kHB+f2/3DD1Izve0vv9q04lgRYLfGK MoqsUe7oGqEamNbDnKnVg/6wKW04U7xW8t8QI8sIOaxM9ua5wffUT4IbytIQjb2ONjP1 gzGJ1OY5C5UD8BpUzA4lJD7q12dvaH++w4dEVE4KUjyZAQmf+HhpY9QCHVkITLuY8UPS eMtlNupI0Gwj+bKAsEgPQNIkMwGmMqhCho39I6FDTLv8cSIE/pDZGdTkjgIHX/34KBfr b6dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=OwV5c0sYhgDiSmZo+sCuGD9fDD/j99ylCgz72MdTbfg=; fh=9KkEy5BETl+n6HvtEwBLK4NkRgCt0Iv6FwLxABl1azE=; b=KQXZVL1GWQ9QQHi3ldCF406DaHNWf5WZD2OH1fTHdwrYTvVuVZ6sEnhF1T8tX+wlsI R4RxF7V+Cbm+T36cuQUmnKo7W/tCse7u+87Vrk5mQjxzfp7zsaXpgzO0upgwPud+Hrze W0DpSOw7woRW350u7OKrF0jb/ql7dzVMltr+M3rbkDLtXBGT4vuCjJdYv8V/DsYfCgO0 COnLHrkeWWVQe3WCKgbxbEirLOnQcoexQBYqkfHlwManHaDXTJ+pRauEa+8RzTz1gPPV 53OC0spDLXfBxdTxFVTb87GhQwfD0oJg5B3v5sgRUeYK+abMiDNK5nwdIWfbibfET770 97sg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id b13-20020a63d80d000000b0057828b85ae3si5268759pgh.439.2023.09.18.04.56.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 04:56:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 8F7C480A49A2; Mon, 18 Sep 2023 04:53:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241346AbjIRLxK (ORCPT <rfc822;kernel.ruili@gmail.com> + 27 others); Mon, 18 Sep 2023 07:53:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241749AbjIRLwz (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 18 Sep 2023 07:52:55 -0400 Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55379E6; Mon, 18 Sep 2023 04:52:49 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046056;MF=renyu.zj@linux.alibaba.com;NM=1;PH=DS;RN=21;SR=0;TI=SMTPD_---0VsMQsjd_1695037964; Received: from srmbuffer011165236051.sqa.net(mailfrom:renyu.zj@linux.alibaba.com fp:SMTPD_---0VsMQsjd_1695037964) by smtp.aliyun-inc.com; Mon, 18 Sep 2023 19:52:45 +0800 From: Jing Zhang <renyu.zj@linux.alibaba.com> To: John Garry <john.g.garry@oracle.com>, Ian Rogers <irogers@google.com> Cc: Will Deacon <will@kernel.org>, James Clark <james.clark@arm.com>, Arnaldo Carvalho de Melo <acme@kernel.org>, Mark Rutland <mark.rutland@arm.com>, Mike Leach <mike.leach@linaro.org>, Leo Yan <leo.yan@linaro.org>, Namhyung Kim <namhyung@kernel.org>, Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@redhat.com>, Alexander Shishkin <alexander.shishkin@linux.intel.com>, Jiri Olsa <jolsa@kernel.org>, Adrian Hunter <adrian.hunter@intel.com>, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-doc@vger.kernel.org, Zhuo Song <zhuo.song@linux.alibaba.com>, Jing Zhang <renyu.zj@linux.alibaba.com>, Shuai Xue <xueshuai@linux.alibaba.com> Subject: [PATCH v9 1/7] perf pmu: "Compat" supports regular expression matching identifiers Date: Mon, 18 Sep 2023 19:52:29 +0800 Message-Id: <1695037955-107983-2-git-send-email-renyu.zj@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1695037955-107983-1-git-send-email-renyu.zj@linux.alibaba.com> References: <1695037955-107983-1-git-send-email-renyu.zj@linux.alibaba.com> X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 18 Sep 2023 04:53:56 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777376376127436099 X-GMAIL-MSGID: 1777376376127436099 |
Series |
Add metrics for Arm CMN
|
|
Commit Message
Jing Zhang
Sept. 18, 2023, 11:52 a.m. UTC
The jevent "Compat" is used for uncore PMU alias or metric definitions.
The same PMU driver has different PMU identifiers due to different
hardware versions and types, but they may have some common PMU event.
Since a Compat value can only match one identifier, when adding the
same event alias to PMUs with different identifiers, each identifier
needs to be defined once, which is not streamlined enough.
So let "Compat" support using regular expression to match identifiers
for uncore PMU alias. For example, if the "Compat" value is set to
"43401|43c01", it would be able to match PMU identifiers such as "43401"
or "43c01", which correspond to CMN600_r0p0 or CMN700_r0p0.
Signed-off-by: Jing Zhang <renyu.zj@linux.alibaba.com>
---
tools/perf/util/pmu.c | 23 +++++++++++++++++++++--
tools/perf/util/pmu.h | 1 +
2 files changed, 22 insertions(+), 2 deletions(-)
Comments
On Mon, Sep 18, 2023 at 4:52 AM Jing Zhang <renyu.zj@linux.alibaba.com> wrote: > > The jevent "Compat" is used for uncore PMU alias or metric definitions. > > The same PMU driver has different PMU identifiers due to different > hardware versions and types, but they may have some common PMU event. > Since a Compat value can only match one identifier, when adding the > same event alias to PMUs with different identifiers, each identifier > needs to be defined once, which is not streamlined enough. > > So let "Compat" support using regular expression to match identifiers > for uncore PMU alias. For example, if the "Compat" value is set to > "43401|43c01", it would be able to match PMU identifiers such as "43401" > or "43c01", which correspond to CMN600_r0p0 or CMN700_r0p0. > > Signed-off-by: Jing Zhang <renyu.zj@linux.alibaba.com> > --- > tools/perf/util/pmu.c | 23 +++++++++++++++++++++-- > tools/perf/util/pmu.h | 1 + > 2 files changed, 22 insertions(+), 2 deletions(-) > > diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c > index e215985..7e2242f 100644 > --- a/tools/perf/util/pmu.c > +++ b/tools/perf/util/pmu.c > @@ -28,6 +28,7 @@ > #include "strbuf.h" > #include "fncache.h" > #include "util/evsel_config.h" > +#include <regex.h> > > struct perf_pmu perf_pmu__fake = { > .name = "fake", > @@ -875,6 +876,24 @@ static bool pmu_uncore_alias_match(const char *pmu_name, const char *name) > return res; > } > > +bool pmu_uncore_identifier_match(const char *compat, const char *id) > +{ > + regex_t re; > + regmatch_t pmatch[1]; > + int match; > + > + if (regcomp(&re, compat, REG_EXTENDED) != 0) { > + /* Warn unable to generate match particular string. */ > + pr_info("Invalid regular expression %s\n", compat); > + return false; > + } > + > + match = !regexec(&re, id, 1, pmatch, 0); I wonder if we can make the regular expressions like "^(434|436|43c|43a)" more like "(434|436|43c|43a).*", so that we fully match the id string, by here doing: if (match) { /* Ensure a full match. */ match = pmatch[0].rm_so == 0 && pmatch[0].rm_eo == strlen(id); } I think longer term we can use jevents.py to generate a pmu-events.l, which would have a contents something like: (434|436|43c|43a).* { return PMU_....;} That should make the matching faster but may add some restrictions onto the regular expression. Thanks, Ian > + regfree(&re); > + > + return match; > +} > + > static int pmu_add_cpu_aliases_map_callback(const struct pmu_event *pe, > const struct pmu_events_table *table __maybe_unused, > void *vdata) > @@ -915,8 +934,8 @@ static int pmu_add_sys_aliases_iter_fn(const struct pmu_event *pe, > if (!pe->compat || !pe->pmu) > return 0; > > - if (!strcmp(pmu->id, pe->compat) && > - pmu_uncore_alias_match(pe->pmu, pmu->name)) { > + if (pmu_uncore_alias_match(pe->pmu, pmu->name) && > + pmu_uncore_identifier_match(pe->compat, pmu->id)) { > perf_pmu__new_alias(pmu, > pe->name, > pe->desc, > diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h > index bd5d804..fc155ce 100644 > --- a/tools/perf/util/pmu.h > +++ b/tools/perf/util/pmu.h > @@ -240,6 +240,7 @@ void pmu_add_cpu_aliases_table(struct perf_pmu *pmu, > char *perf_pmu__getcpuid(struct perf_pmu *pmu); > const struct pmu_events_table *pmu_events_table__find(void); > const struct pmu_metrics_table *pmu_metrics_table__find(void); > +bool pmu_uncore_identifier_match(const char *compat, const char *id); > > int perf_pmu__convert_scale(const char *scale, char **end, double *sval); > > -- > 1.8.3.1 >
在 2023/9/21 上午2:36, Ian Rogers 写道: > On Mon, Sep 18, 2023 at 4:52 AM Jing Zhang <renyu.zj@linux.alibaba.com> wrote: >> >> The jevent "Compat" is used for uncore PMU alias or metric definitions. >> >> The same PMU driver has different PMU identifiers due to different >> hardware versions and types, but they may have some common PMU event. >> Since a Compat value can only match one identifier, when adding the >> same event alias to PMUs with different identifiers, each identifier >> needs to be defined once, which is not streamlined enough. >> >> So let "Compat" support using regular expression to match identifiers >> for uncore PMU alias. For example, if the "Compat" value is set to >> "43401|43c01", it would be able to match PMU identifiers such as "43401" >> or "43c01", which correspond to CMN600_r0p0 or CMN700_r0p0. >> >> Signed-off-by: Jing Zhang <renyu.zj@linux.alibaba.com> >> --- >> tools/perf/util/pmu.c | 23 +++++++++++++++++++++-- >> tools/perf/util/pmu.h | 1 + >> 2 files changed, 22 insertions(+), 2 deletions(-) >> >> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c >> index e215985..7e2242f 100644 >> --- a/tools/perf/util/pmu.c >> +++ b/tools/perf/util/pmu.c >> @@ -28,6 +28,7 @@ >> #include "strbuf.h" >> #include "fncache.h" >> #include "util/evsel_config.h" >> +#include <regex.h> >> >> struct perf_pmu perf_pmu__fake = { >> .name = "fake", >> @@ -875,6 +876,24 @@ static bool pmu_uncore_alias_match(const char *pmu_name, const char *name) >> return res; >> } >> >> +bool pmu_uncore_identifier_match(const char *compat, const char *id) >> +{ >> + regex_t re; >> + regmatch_t pmatch[1]; >> + int match; >> + >> + if (regcomp(&re, compat, REG_EXTENDED) != 0) { >> + /* Warn unable to generate match particular string. */ >> + pr_info("Invalid regular expression %s\n", compat); >> + return false; >> + } >> + >> + match = !regexec(&re, id, 1, pmatch, 0); > > I wonder if we can make the regular expressions like > "^(434|436|43c|43a)" more like "(434|436|43c|43a).*", so that we fully > match the id string, by here doing: > > if (match) { > /* Ensure a full match. */ > match = pmatch[0].rm_so == 0 && pmatch[0].rm_eo == strlen(id); > } > Ok, will do. > I think longer term we can use jevents.py to generate a pmu-events.l, > which would have a contents something like: > > (434|436|43c|43a).* { return PMU_....;} > > That should make the matching faster but may add some restrictions > onto the regular expression. Could you please describe the function of pmu-event.l in more detail? I may not fully understand it. Thanks, Jing > > Thanks, > Ian > >> + regfree(&re); >> + >> + return match; >> +} >> + >> static int pmu_add_cpu_aliases_map_callback(const struct pmu_event *pe, >> const struct pmu_events_table *table __maybe_unused, >> void *vdata) >> @@ -915,8 +934,8 @@ static int pmu_add_sys_aliases_iter_fn(const struct pmu_event *pe, >> if (!pe->compat || !pe->pmu) >> return 0; >> >> - if (!strcmp(pmu->id, pe->compat) && >> - pmu_uncore_alias_match(pe->pmu, pmu->name)) { >> + if (pmu_uncore_alias_match(pe->pmu, pmu->name) && >> + pmu_uncore_identifier_match(pe->compat, pmu->id)) { >> perf_pmu__new_alias(pmu, >> pe->name, >> pe->desc, >> diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h >> index bd5d804..fc155ce 100644 >> --- a/tools/perf/util/pmu.h >> +++ b/tools/perf/util/pmu.h >> @@ -240,6 +240,7 @@ void pmu_add_cpu_aliases_table(struct perf_pmu *pmu, >> char *perf_pmu__getcpuid(struct perf_pmu *pmu); >> const struct pmu_events_table *pmu_events_table__find(void); >> const struct pmu_metrics_table *pmu_metrics_table__find(void); >> +bool pmu_uncore_identifier_match(const char *compat, const char *id); >> >> int perf_pmu__convert_scale(const char *scale, char **end, double *sval); >> >> -- >> 1.8.3.1 >>
On Fri, Sep 22, 2023 at 1:19 AM Jing Zhang <renyu.zj@linux.alibaba.com> wrote: > > > > 在 2023/9/21 上午2:36, Ian Rogers 写道: > > On Mon, Sep 18, 2023 at 4:52 AM Jing Zhang <renyu.zj@linux.alibaba.com> wrote: > >> > >> The jevent "Compat" is used for uncore PMU alias or metric definitions. > >> > >> The same PMU driver has different PMU identifiers due to different > >> hardware versions and types, but they may have some common PMU event. > >> Since a Compat value can only match one identifier, when adding the > >> same event alias to PMUs with different identifiers, each identifier > >> needs to be defined once, which is not streamlined enough. > >> > >> So let "Compat" support using regular expression to match identifiers > >> for uncore PMU alias. For example, if the "Compat" value is set to > >> "43401|43c01", it would be able to match PMU identifiers such as "43401" > >> or "43c01", which correspond to CMN600_r0p0 or CMN700_r0p0. > >> > >> Signed-off-by: Jing Zhang <renyu.zj@linux.alibaba.com> > >> --- > >> tools/perf/util/pmu.c | 23 +++++++++++++++++++++-- > >> tools/perf/util/pmu.h | 1 + > >> 2 files changed, 22 insertions(+), 2 deletions(-) > >> > >> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c > >> index e215985..7e2242f 100644 > >> --- a/tools/perf/util/pmu.c > >> +++ b/tools/perf/util/pmu.c > >> @@ -28,6 +28,7 @@ > >> #include "strbuf.h" > >> #include "fncache.h" > >> #include "util/evsel_config.h" > >> +#include <regex.h> > >> > >> struct perf_pmu perf_pmu__fake = { > >> .name = "fake", > >> @@ -875,6 +876,24 @@ static bool pmu_uncore_alias_match(const char *pmu_name, const char *name) > >> return res; > >> } > >> > >> +bool pmu_uncore_identifier_match(const char *compat, const char *id) > >> +{ > >> + regex_t re; > >> + regmatch_t pmatch[1]; > >> + int match; > >> + > >> + if (regcomp(&re, compat, REG_EXTENDED) != 0) { > >> + /* Warn unable to generate match particular string. */ > >> + pr_info("Invalid regular expression %s\n", compat); > >> + return false; > >> + } > >> + > >> + match = !regexec(&re, id, 1, pmatch, 0); > > > > I wonder if we can make the regular expressions like > > "^(434|436|43c|43a)" more like "(434|436|43c|43a).*", so that we fully > > match the id string, by here doing: > > > > if (match) { > > /* Ensure a full match. */ > > match = pmatch[0].rm_so == 0 && pmatch[0].rm_eo == strlen(id); > > } > > > > Ok, will do. > > > > I think longer term we can use jevents.py to generate a pmu-events.l, > > which would have a contents something like: > > > > (434|436|43c|43a).* { return PMU_....;} > > > > That should make the matching faster but may add some restrictions > > onto the regular expression. > > Could you please describe the function of pmu-event.l in more detail? I may not fully understand it. So for now there's no need for a pmu-event.l, I'm fine with the code as-is. The issue for using regular expressions is that we need to compile (regcomp) then use them (regexec), and in this new code the result of the parsing is discarded - perhaps we can save on some compiling with a 1 element cache, let's wait to see performance data saying it is an issue. If we were to compile the regular expressions at build time with flex then the runtime cost, any caching, etc. is unnecessary. Hope this makes sense. Thanks, Ian > Thanks, > Jing > > > > > Thanks, > > Ian > > > >> + regfree(&re); > >> + > >> + return match; > >> +} > >> + > >> static int pmu_add_cpu_aliases_map_callback(const struct pmu_event *pe, > >> const struct pmu_events_table *table __maybe_unused, > >> void *vdata) > >> @@ -915,8 +934,8 @@ static int pmu_add_sys_aliases_iter_fn(const struct pmu_event *pe, > >> if (!pe->compat || !pe->pmu) > >> return 0; > >> > >> - if (!strcmp(pmu->id, pe->compat) && > >> - pmu_uncore_alias_match(pe->pmu, pmu->name)) { > >> + if (pmu_uncore_alias_match(pe->pmu, pmu->name) && > >> + pmu_uncore_identifier_match(pe->compat, pmu->id)) { > >> perf_pmu__new_alias(pmu, > >> pe->name, > >> pe->desc, > >> diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h > >> index bd5d804..fc155ce 100644 > >> --- a/tools/perf/util/pmu.h > >> +++ b/tools/perf/util/pmu.h > >> @@ -240,6 +240,7 @@ void pmu_add_cpu_aliases_table(struct perf_pmu *pmu, > >> char *perf_pmu__getcpuid(struct perf_pmu *pmu); > >> const struct pmu_events_table *pmu_events_table__find(void); > >> const struct pmu_metrics_table *pmu_metrics_table__find(void); > >> +bool pmu_uncore_identifier_match(const char *compat, const char *id); > >> > >> int perf_pmu__convert_scale(const char *scale, char **end, double *sval); > >> > >> -- > >> 1.8.3.1 > >>
在 2023/9/22 下午10:58, Ian Rogers 写道: > On Fri, Sep 22, 2023 at 1:19 AM Jing Zhang <renyu.zj@linux.alibaba.com> wrote: >> >> >> >> 在 2023/9/21 上午2:36, Ian Rogers 写道: >>> On Mon, Sep 18, 2023 at 4:52 AM Jing Zhang <renyu.zj@linux.alibaba.com> wrote: >>>> >>>> The jevent "Compat" is used for uncore PMU alias or metric definitions. >>>> >>>> The same PMU driver has different PMU identifiers due to different >>>> hardware versions and types, but they may have some common PMU event. >>>> Since a Compat value can only match one identifier, when adding the >>>> same event alias to PMUs with different identifiers, each identifier >>>> needs to be defined once, which is not streamlined enough. >>>> >>>> So let "Compat" support using regular expression to match identifiers >>>> for uncore PMU alias. For example, if the "Compat" value is set to >>>> "43401|43c01", it would be able to match PMU identifiers such as "43401" >>>> or "43c01", which correspond to CMN600_r0p0 or CMN700_r0p0. >>>> >>>> Signed-off-by: Jing Zhang <renyu.zj@linux.alibaba.com> >>>> --- >>>> tools/perf/util/pmu.c | 23 +++++++++++++++++++++-- >>>> tools/perf/util/pmu.h | 1 + >>>> 2 files changed, 22 insertions(+), 2 deletions(-) >>>> >>>> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c >>>> index e215985..7e2242f 100644 >>>> --- a/tools/perf/util/pmu.c >>>> +++ b/tools/perf/util/pmu.c >>>> @@ -28,6 +28,7 @@ >>>> #include "strbuf.h" >>>> #include "fncache.h" >>>> #include "util/evsel_config.h" >>>> +#include <regex.h> >>>> >>>> struct perf_pmu perf_pmu__fake = { >>>> .name = "fake", >>>> @@ -875,6 +876,24 @@ static bool pmu_uncore_alias_match(const char *pmu_name, const char *name) >>>> return res; >>>> } >>>> >>>> +bool pmu_uncore_identifier_match(const char *compat, const char *id) >>>> +{ >>>> + regex_t re; >>>> + regmatch_t pmatch[1]; >>>> + int match; >>>> + >>>> + if (regcomp(&re, compat, REG_EXTENDED) != 0) { >>>> + /* Warn unable to generate match particular string. */ >>>> + pr_info("Invalid regular expression %s\n", compat); >>>> + return false; >>>> + } >>>> + >>>> + match = !regexec(&re, id, 1, pmatch, 0); >>> >>> I wonder if we can make the regular expressions like >>> "^(434|436|43c|43a)" more like "(434|436|43c|43a).*", so that we fully >>> match the id string, by here doing: >>> >>> if (match) { >>> /* Ensure a full match. */ >>> match = pmatch[0].rm_so == 0 && pmatch[0].rm_eo == strlen(id); >>> } >>> >> >> Ok, will do. >> >> >>> I think longer term we can use jevents.py to generate a pmu-events.l, >>> which would have a contents something like: >>> >>> (434|436|43c|43a).* { return PMU_....;} >>> >>> That should make the matching faster but may add some restrictions >>> onto the regular expression. >> >> Could you please describe the function of pmu-event.l in more detail? I may not fully understand it. > > So for now there's no need for a pmu-event.l, I'm fine with the code > as-is. The issue for using regular expressions is that we need to > compile (regcomp) then use them (regexec), and in this new code the > result of the parsing is discarded - perhaps we can save on some > compiling with a 1 element cache, let's wait to see performance data > saying it is an issue. If we were to compile the regular expressions > at build time with flex then the runtime cost, any caching, etc. is > unnecessary. > I see, thanks for the explanation. Thanks, Jing > Hope this makes sense. Thanks, > Ian > >> Thanks, >> Jing >> >>> >>> Thanks, >>> Ian >>> >>>> + regfree(&re); >>>> + >>>> + return match; >>>> +} >>>> + >>>> static int pmu_add_cpu_aliases_map_callback(const struct pmu_event *pe, >>>> const struct pmu_events_table *table __maybe_unused, >>>> void *vdata) >>>> @@ -915,8 +934,8 @@ static int pmu_add_sys_aliases_iter_fn(const struct pmu_event *pe, >>>> if (!pe->compat || !pe->pmu) >>>> return 0; >>>> >>>> - if (!strcmp(pmu->id, pe->compat) && >>>> - pmu_uncore_alias_match(pe->pmu, pmu->name)) { >>>> + if (pmu_uncore_alias_match(pe->pmu, pmu->name) && >>>> + pmu_uncore_identifier_match(pe->compat, pmu->id)) { >>>> perf_pmu__new_alias(pmu, >>>> pe->name, >>>> pe->desc, >>>> diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h >>>> index bd5d804..fc155ce 100644 >>>> --- a/tools/perf/util/pmu.h >>>> +++ b/tools/perf/util/pmu.h >>>> @@ -240,6 +240,7 @@ void pmu_add_cpu_aliases_table(struct perf_pmu *pmu, >>>> char *perf_pmu__getcpuid(struct perf_pmu *pmu); >>>> const struct pmu_events_table *pmu_events_table__find(void); >>>> const struct pmu_metrics_table *pmu_metrics_table__find(void); >>>> +bool pmu_uncore_identifier_match(const char *compat, const char *id); >>>> >>>> int perf_pmu__convert_scale(const char *scale, char **end, double *sval); >>>> >>>> -- >>>> 1.8.3.1 >>>>
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index e215985..7e2242f 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -28,6 +28,7 @@ #include "strbuf.h" #include "fncache.h" #include "util/evsel_config.h" +#include <regex.h> struct perf_pmu perf_pmu__fake = { .name = "fake", @@ -875,6 +876,24 @@ static bool pmu_uncore_alias_match(const char *pmu_name, const char *name) return res; } +bool pmu_uncore_identifier_match(const char *compat, const char *id) +{ + regex_t re; + regmatch_t pmatch[1]; + int match; + + if (regcomp(&re, compat, REG_EXTENDED) != 0) { + /* Warn unable to generate match particular string. */ + pr_info("Invalid regular expression %s\n", compat); + return false; + } + + match = !regexec(&re, id, 1, pmatch, 0); + regfree(&re); + + return match; +} + static int pmu_add_cpu_aliases_map_callback(const struct pmu_event *pe, const struct pmu_events_table *table __maybe_unused, void *vdata) @@ -915,8 +934,8 @@ static int pmu_add_sys_aliases_iter_fn(const struct pmu_event *pe, if (!pe->compat || !pe->pmu) return 0; - if (!strcmp(pmu->id, pe->compat) && - pmu_uncore_alias_match(pe->pmu, pmu->name)) { + if (pmu_uncore_alias_match(pe->pmu, pmu->name) && + pmu_uncore_identifier_match(pe->compat, pmu->id)) { perf_pmu__new_alias(pmu, pe->name, pe->desc, diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index bd5d804..fc155ce 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -240,6 +240,7 @@ void pmu_add_cpu_aliases_table(struct perf_pmu *pmu, char *perf_pmu__getcpuid(struct perf_pmu *pmu); const struct pmu_events_table *pmu_events_table__find(void); const struct pmu_metrics_table *pmu_metrics_table__find(void); +bool pmu_uncore_identifier_match(const char *compat, const char *id); int perf_pmu__convert_scale(const char *scale, char **end, double *sval);