* [PATCH v9 0/7] Add metrics for Arm CMN
@ 2023-09-18 11:52 Jing Zhang
2023-09-18 11:52 ` [PATCH v9 1/7] perf pmu: "Compat" supports regular expression matching identifiers Jing Zhang
` (6 more replies)
0 siblings, 7 replies; 12+ messages in thread
From: Jing Zhang @ 2023-09-18 11:52 UTC (permalink / raw)
To: John Garry, Ian Rogers
Cc: Will Deacon, James Clark, Arnaldo Carvalho de Melo, Mark Rutland,
Mike Leach, Leo Yan, Namhyung Kim, Peter Zijlstra, Ingo Molnar,
Alexander Shishkin, Jiri Olsa, Adrian Hunter, linux-kernel,
linux-arm-kernel, linux-perf-users, linux-doc, Zhuo Song,
Jing Zhang, Shuai Xue
Changes since v8:
- Compat uses regular expression matching identifier as suggested by Ian.
- Remove [PATCH v8 3/8] and workaround CMN event description issues
through jevent.py as suggested by Ian.
- Link: https://lore.kernel.org/all/1694087913-46144-1-git-send-email-renyu.zj@linux.alibaba.com/
Jing Zhang (7):
perf pmu: "Compat" supports regular expression matching identifiers
perf metric: "Compat" supports regular expression matching identifiers
perf jevents: Support EventidCode and NodeType
perf test: Make matching_pmu effective
perf test: Add pmu-event test for "Compat" and new event_field.
perf jevents: Add support for Arm CMN PMU aliasing
perf vendor events: Add JSON metrics for Arm CMN
.../pmu-events/arch/arm64/arm/cmn/sys/cmn.json | 266 +++++++++++++++++++++
.../pmu-events/arch/arm64/arm/cmn/sys/metric.json | 74 ++++++
.../pmu-events/arch/test/test_soc/sys/uncore.json | 8 +
tools/perf/pmu-events/empty-pmu-events.c | 8 +
tools/perf/pmu-events/jevents.py | 11 +-
tools/perf/tests/pmu-events.c | 65 ++++-
tools/perf/util/metricgroup.c | 2 +-
tools/perf/util/pmu.c | 23 +-
tools/perf/util/pmu.h | 1 +
9 files changed, 452 insertions(+), 6 deletions(-)
create mode 100644 tools/perf/pmu-events/arch/arm64/arm/cmn/sys/cmn.json
create mode 100644 tools/perf/pmu-events/arch/arm64/arm/cmn/sys/metric.json
--
1.8.3.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v9 1/7] perf pmu: "Compat" supports regular expression matching identifiers
2023-09-18 11:52 [PATCH v9 0/7] Add metrics for Arm CMN Jing Zhang
@ 2023-09-18 11:52 ` Jing Zhang
2023-09-20 18:36 ` Ian Rogers
2023-09-18 11:52 ` [PATCH v9 2/7] perf metric: " Jing Zhang
` (5 subsequent siblings)
6 siblings, 1 reply; 12+ messages in thread
From: Jing Zhang @ 2023-09-18 11:52 UTC (permalink / raw)
To: John Garry, Ian Rogers
Cc: Will Deacon, James Clark, Arnaldo Carvalho de Melo, Mark Rutland,
Mike Leach, Leo Yan, Namhyung Kim, Peter Zijlstra, Ingo Molnar,
Alexander Shishkin, Jiri Olsa, Adrian Hunter, linux-kernel,
linux-arm-kernel, linux-perf-users, linux-doc, Zhuo Song,
Jing Zhang, Shuai Xue
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);
+ 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
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v9 2/7] perf metric: "Compat" supports regular expression matching identifiers
2023-09-18 11:52 [PATCH v9 0/7] Add metrics for Arm CMN Jing Zhang
2023-09-18 11:52 ` [PATCH v9 1/7] perf pmu: "Compat" supports regular expression matching identifiers Jing Zhang
@ 2023-09-18 11:52 ` Jing Zhang
2023-09-18 11:52 ` [PATCH v9 3/7] perf jevents: Support EventidCode and NodeType Jing Zhang
` (4 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: Jing Zhang @ 2023-09-18 11:52 UTC (permalink / raw)
To: John Garry, Ian Rogers
Cc: Will Deacon, James Clark, Arnaldo Carvalho de Melo, Mark Rutland,
Mike Leach, Leo Yan, Namhyung Kim, Peter Zijlstra, Ingo Molnar,
Alexander Shishkin, Jiri Olsa, Adrian Hunter, linux-kernel,
linux-arm-kernel, linux-perf-users, linux-doc, Zhuo Song,
Jing Zhang, Shuai Xue
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 metric.
Since a Compat value can only match one identifier, when adding the
same metric 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 multiple
identifiers for uncore PMU metric.
Signed-off-by: Jing Zhang <renyu.zj@linux.alibaba.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/metricgroup.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
index 6231044..0484736 100644
--- a/tools/perf/util/metricgroup.c
+++ b/tools/perf/util/metricgroup.c
@@ -498,7 +498,7 @@ static int metricgroup__sys_event_iter(const struct pmu_metric *pm,
while ((pmu = perf_pmus__scan(pmu))) {
- if (!pmu->id || strcmp(pmu->id, pm->compat))
+ if (!pmu->id || !pmu_uncore_identifier_match(pm->compat, pmu->id))
continue;
return d->fn(pm, table, d->data);
--
1.8.3.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v9 3/7] perf jevents: Support EventidCode and NodeType
2023-09-18 11:52 [PATCH v9 0/7] Add metrics for Arm CMN Jing Zhang
2023-09-18 11:52 ` [PATCH v9 1/7] perf pmu: "Compat" supports regular expression matching identifiers Jing Zhang
2023-09-18 11:52 ` [PATCH v9 2/7] perf metric: " Jing Zhang
@ 2023-09-18 11:52 ` Jing Zhang
2023-09-18 11:52 ` [PATCH v9 4/7] perf test: Make matching_pmu effective Jing Zhang
` (3 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: Jing Zhang @ 2023-09-18 11:52 UTC (permalink / raw)
To: John Garry, Ian Rogers
Cc: Will Deacon, James Clark, Arnaldo Carvalho de Melo, Mark Rutland,
Mike Leach, Leo Yan, Namhyung Kim, Peter Zijlstra, Ingo Molnar,
Alexander Shishkin, Jiri Olsa, Adrian Hunter, linux-kernel,
linux-arm-kernel, linux-perf-users, linux-doc, Zhuo Song,
Jing Zhang, Shuai Xue
The previous code assumes an event has either an "event=" or "config"
field at the beginning. For CMN neither of these may be present, as an
event is typically "type=xx,eventid=xxx".
So add EventidCode and NodeType to support CMN event description.
I compared pmu_event.c before and after compiling with JEVENT_ARCH=all,
they are consistent.
Signed-off-by: Jing Zhang <renyu.zj@linux.alibaba.com>
---
tools/perf/pmu-events/jevents.py | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py
index a7e8833..057d51aa 100755
--- a/tools/perf/pmu-events/jevents.py
+++ b/tools/perf/pmu-events/jevents.py
@@ -298,6 +298,7 @@ class JsonEvent:
if 'ExtSel' in jd:
eventcode |= int(jd['ExtSel']) << 8
configcode = int(jd['ConfigCode'], 0) if 'ConfigCode' in jd else None
+ eventidcode = int(jd['EventidCode'], 0) if 'EventidCode' in jd else None
self.name = jd['EventName'].lower() if 'EventName' in jd else None
self.topic = ''
self.compat = jd.get('Compat')
@@ -335,7 +336,13 @@ class JsonEvent:
if precise and self.desc and '(Precise Event)' not in self.desc:
extra_desc += ' (Must be precise)' if precise == '2' else (' (Precise '
'event)')
- event = f'config={llx(configcode)}' if configcode is not None else f'event={llx(eventcode)}'
+ event = None
+ if configcode is not None:
+ event = f'config={llx(configcode)}'
+ elif eventidcode is not None:
+ event = f'eventid={llx(eventidcode)}'
+ else:
+ event = f'event={llx(eventcode)}'
event_fields = [
('AnyThread', 'any='),
('PortMask', 'ch_mask='),
@@ -345,6 +352,7 @@ class JsonEvent:
('Invert', 'inv='),
('SampleAfterValue', 'period='),
('UMask', 'umask='),
+ ('NodeType', 'type='),
]
for key, value in event_fields:
if key in jd and jd[key] != '0':
--
1.8.3.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v9 4/7] perf test: Make matching_pmu effective
2023-09-18 11:52 [PATCH v9 0/7] Add metrics for Arm CMN Jing Zhang
` (2 preceding siblings ...)
2023-09-18 11:52 ` [PATCH v9 3/7] perf jevents: Support EventidCode and NodeType Jing Zhang
@ 2023-09-18 11:52 ` Jing Zhang
2023-09-18 11:52 ` [PATCH v9 5/7] perf test: Add pmu-event test for "Compat" and new event_field Jing Zhang
` (2 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: Jing Zhang @ 2023-09-18 11:52 UTC (permalink / raw)
To: John Garry, Ian Rogers
Cc: Will Deacon, James Clark, Arnaldo Carvalho de Melo, Mark Rutland,
Mike Leach, Leo Yan, Namhyung Kim, Peter Zijlstra, Ingo Molnar,
Alexander Shishkin, Jiri Olsa, Adrian Hunter, linux-kernel,
linux-arm-kernel, linux-perf-users, linux-doc, Zhuo Song,
Jing Zhang, Shuai Xue
The perf_pmu_test_event.matching_pmu didn't work. No matter what its
value is, it does not affect the test results. So let matching_pmu be
used for matching perf_pmu_test_pmu.pmu.name.
Signed-off-by: Jing Zhang <renyu.zj@linux.alibaba.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
---
tools/perf/tests/pmu-events.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c
index f5321fb..0cf572f 100644
--- a/tools/perf/tests/pmu-events.c
+++ b/tools/perf/tests/pmu-events.c
@@ -245,7 +245,7 @@ struct perf_pmu_test_pmu {
},
.alias_str = "event=0x2b",
.alias_long_desc = "ddr write-cycles event",
- .matching_pmu = "uncore_sys_ddr_pmu",
+ .matching_pmu = "uncore_sys_ddr_pmu0",
};
static const struct perf_pmu_test_event sys_ccn_pmu_read_cycles = {
@@ -259,7 +259,7 @@ struct perf_pmu_test_pmu {
},
.alias_str = "config=0x2c",
.alias_long_desc = "ccn read-cycles event",
- .matching_pmu = "uncore_sys_ccn_pmu",
+ .matching_pmu = "uncore_sys_ccn_pmu4",
};
static const struct perf_pmu_test_event *sys_events[] = {
@@ -615,6 +615,12 @@ static int __test_uncore_pmu_event_aliases(struct perf_pmu_test_pmu *test_pmu)
.count = &matched_count,
};
+ if (strcmp(pmu_name, test_event.matching_pmu)) {
+ pr_debug("testing aliases uncore PMU %s: mismatched matching_pmu, %s vs %s\n",
+ pmu_name, test_event.matching_pmu, pmu_name);
+ return -1;
+ }
+
err = perf_pmu__find_event(pmu, event->name, &args,
test_core_pmu_event_aliases_cb);
if (err) {
--
1.8.3.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v9 5/7] perf test: Add pmu-event test for "Compat" and new event_field.
2023-09-18 11:52 [PATCH v9 0/7] Add metrics for Arm CMN Jing Zhang
` (3 preceding siblings ...)
2023-09-18 11:52 ` [PATCH v9 4/7] perf test: Make matching_pmu effective Jing Zhang
@ 2023-09-18 11:52 ` Jing Zhang
2023-09-18 11:52 ` [PATCH v9 6/7] perf jevents: Add support for Arm CMN PMU aliasing Jing Zhang
2023-09-18 11:52 ` [PATCH v9 7/7] perf vendor events: Add JSON metrics for Arm CMN Jing Zhang
6 siblings, 0 replies; 12+ messages in thread
From: Jing Zhang @ 2023-09-18 11:52 UTC (permalink / raw)
To: John Garry, Ian Rogers
Cc: Will Deacon, James Clark, Arnaldo Carvalho de Melo, Mark Rutland,
Mike Leach, Leo Yan, Namhyung Kim, Peter Zijlstra, Ingo Molnar,
Alexander Shishkin, Jiri Olsa, Adrian Hunter, linux-kernel,
linux-arm-kernel, linux-perf-users, linux-doc, Zhuo Song,
Jing Zhang, Shuai Xue
Add new event test for uncore system event which is used to verify the
functionality of "Compat" matching multiple identifiers and the new event
fields "EventidCode" and "NodeType".
Signed-off-by: Jing Zhang <renyu.zj@linux.alibaba.com>
---
.../pmu-events/arch/test/test_soc/sys/uncore.json | 8 ++++
tools/perf/pmu-events/empty-pmu-events.c | 8 ++++
tools/perf/tests/pmu-events.c | 55 ++++++++++++++++++++++
3 files changed, 71 insertions(+)
diff --git a/tools/perf/pmu-events/arch/test/test_soc/sys/uncore.json b/tools/perf/pmu-events/arch/test/test_soc/sys/uncore.json
index c7e7528..701df3b 100644
--- a/tools/perf/pmu-events/arch/test/test_soc/sys/uncore.json
+++ b/tools/perf/pmu-events/arch/test/test_soc/sys/uncore.json
@@ -12,5 +12,13 @@
"EventName": "sys_ccn_pmu.read_cycles",
"Unit": "sys_ccn_pmu",
"Compat": "0x01"
+ },
+ {
+ "BriefDescription": "Counts total cache misses in first lookup result (high priority)",
+ "EventidCode": "0x1",
+ "NodeType": "0x5",
+ "EventName": "sys_cmn_pmu.hnf_cache_miss",
+ "Unit": "sys_cmn_pmu",
+ "Compat": "^(434|436|43c|43a)"
}
]
diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-events/empty-pmu-events.c
index 12bd043..b380836 100644
--- a/tools/perf/pmu-events/empty-pmu-events.c
+++ b/tools/perf/pmu-events/empty-pmu-events.c
@@ -245,6 +245,14 @@ struct pmu_events_map {
.pmu = "uncore_sys_ccn_pmu",
},
{
+ .name = "sys_cmn_pmu.hnf_cache_miss",
+ .event = "eventid=0x1,type=0x5",
+ .desc = "Counts total cache misses in first lookup result (high priority). Unit: uncore_sys_cmn_pmu ",
+ .compat = "^(434|436|43c|43a)",
+ .topic = "uncore",
+ .pmu = "uncore_sys_cmn_pmu",
+ },
+ {
.name = 0,
.event = 0,
.desc = 0,
diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c
index 0cf572f..9e52d5e 100644
--- a/tools/perf/tests/pmu-events.c
+++ b/tools/perf/tests/pmu-events.c
@@ -262,9 +262,24 @@ struct perf_pmu_test_pmu {
.matching_pmu = "uncore_sys_ccn_pmu4",
};
+static const struct perf_pmu_test_event sys_cmn_pmu_hnf_cache_miss = {
+ .event = {
+ .name = "sys_cmn_pmu.hnf_cache_miss",
+ .event = "eventid=0x1,type=0x5",
+ .desc = "Counts total cache misses in first lookup result (high priority)",
+ .topic = "uncore",
+ .pmu = "uncore_sys_cmn_pmu",
+ .compat = "^(434|436|43c|43a)",
+ },
+ .alias_str = "eventid=0x1,type=0x5",
+ .alias_long_desc = "Counts total cache misses in first lookup result (high priority)",
+ .matching_pmu = "uncore_sys_cmn_pmu0",
+};
+
static const struct perf_pmu_test_event *sys_events[] = {
&sys_ddr_pmu_write_cycles,
&sys_ccn_pmu_read_cycles,
+ &sys_cmn_pmu_hnf_cache_miss,
NULL
};
@@ -707,6 +722,46 @@ static int __test_uncore_pmu_event_aliases(struct perf_pmu_test_pmu *test_pmu)
&sys_ccn_pmu_read_cycles,
},
},
+ {
+ .pmu = {
+ .name = (char *)"uncore_sys_cmn_pmu0",
+ .is_uncore = 1,
+ .id = (char *)"43401",
+ },
+ .aliases = {
+ &sys_cmn_pmu_hnf_cache_miss,
+ },
+ },
+ {
+ .pmu = {
+ .name = (char *)"uncore_sys_cmn_pmu0",
+ .is_uncore = 1,
+ .id = (char *)"43602",
+ },
+ .aliases = {
+ &sys_cmn_pmu_hnf_cache_miss,
+ },
+ },
+ {
+ .pmu = {
+ .name = (char *)"uncore_sys_cmn_pmu0",
+ .is_uncore = 1,
+ .id = (char *)"43c03",
+ },
+ .aliases = {
+ &sys_cmn_pmu_hnf_cache_miss,
+ },
+ },
+ {
+ .pmu = {
+ .name = (char *)"uncore_sys_cmn_pmu0",
+ .is_uncore = 1,
+ .id = (char *)"43a01",
+ },
+ .aliases = {
+ &sys_cmn_pmu_hnf_cache_miss,
+ },
+ }
};
/* Test that aliases generated are as expected */
--
1.8.3.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v9 6/7] perf jevents: Add support for Arm CMN PMU aliasing
2023-09-18 11:52 [PATCH v9 0/7] Add metrics for Arm CMN Jing Zhang
` (4 preceding siblings ...)
2023-09-18 11:52 ` [PATCH v9 5/7] perf test: Add pmu-event test for "Compat" and new event_field Jing Zhang
@ 2023-09-18 11:52 ` Jing Zhang
2023-09-18 11:52 ` [PATCH v9 7/7] perf vendor events: Add JSON metrics for Arm CMN Jing Zhang
6 siblings, 0 replies; 12+ messages in thread
From: Jing Zhang @ 2023-09-18 11:52 UTC (permalink / raw)
To: John Garry, Ian Rogers
Cc: Will Deacon, James Clark, Arnaldo Carvalho de Melo, Mark Rutland,
Mike Leach, Leo Yan, Namhyung Kim, Peter Zijlstra, Ingo Molnar,
Alexander Shishkin, Jiri Olsa, Adrian Hunter, linux-kernel,
linux-arm-kernel, linux-perf-users, linux-doc, Zhuo Song,
Jing Zhang, Shuai Xue
Currently just add aliases for part of Arm CMN PMU events which
are general and compatible for any SoC and CMN-ANY.
"Compat" value "^(434|436|43c|43a)" means it is compatible with
all CMN600/CMN650/CMN700/Ci700, which can be obtained from
commit 7819e05a0dce ("perf/arm-cmn: Revamp model detection").
The arm-cmn PMU events got from:
[0] https://developer.arm.com/documentation/100180/0302/?lang=en
[1] https://developer.arm.com/documentation/101408/0100/?lang=en
[2] https://developer.arm.com/documentation/102308/0302/?lang=en
[3] https://developer.arm.com/documentation/101569/0300/?lang=en
Signed-off-by: Jing Zhang <renyu.zj@linux.alibaba.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
---
.../pmu-events/arch/arm64/arm/cmn/sys/cmn.json | 266 +++++++++++++++++++++
tools/perf/pmu-events/jevents.py | 1 +
2 files changed, 267 insertions(+)
create mode 100644 tools/perf/pmu-events/arch/arm64/arm/cmn/sys/cmn.json
diff --git a/tools/perf/pmu-events/arch/arm64/arm/cmn/sys/cmn.json b/tools/perf/pmu-events/arch/arm64/arm/cmn/sys/cmn.json
new file mode 100644
index 0000000..dd5d4ec
--- /dev/null
+++ b/tools/perf/pmu-events/arch/arm64/arm/cmn/sys/cmn.json
@@ -0,0 +1,266 @@
+[
+ {
+ "EventName": "hnf_cache_miss",
+ "EventidCode": "0x1",
+ "NodeType": "0x5",
+ "BriefDescription": "Counts total cache misses in first lookup result (high priority).",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "hnf_slc_sf_cache_access",
+ "EventidCode": "0x2",
+ "NodeType": "0x5",
+ "BriefDescription": "Counts number of cache accesses in first access (high priority).",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "hnf_cache_fill",
+ "EventidCode": "0x3",
+ "NodeType": "0x5",
+ "BriefDescription": "Counts total allocations in HN SLC (all cache line allocations to SLC).",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "hnf_pocq_retry",
+ "EventidCode": "0x4",
+ "NodeType": "0x5",
+ "BriefDescription": "Counts number of retried requests.",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "hnf_pocq_reqs_recvd",
+ "EventidCode": "0x5",
+ "NodeType": "0x5",
+ "BriefDescription": "Counts number of requests that HN receives.",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "hnf_sf_hit",
+ "EventidCode": "0x6",
+ "NodeType": "0x5",
+ "BriefDescription": "Counts number of SF hits.",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "hnf_sf_evictions",
+ "EventidCode": "0x7",
+ "NodeType": "0x5",
+ "BriefDescription": "Counts number of SF eviction cache invalidations initiated.",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "hnf_dir_snoops_sent",
+ "EventidCode": "0x8",
+ "NodeType": "0x5",
+ "BriefDescription": "Counts number of directed snoops sent (not including SF back invalidation).",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "hnf_brd_snoops_sent",
+ "EventidCode": "0x9",
+ "NodeType": "0x5",
+ "BriefDescription": "Counts number of multicast snoops sent (not including SF back invalidation).",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "hnf_slc_eviction",
+ "EventidCode": "0xa",
+ "NodeType": "0x5",
+ "BriefDescription": "Counts number of SLC evictions (dirty only).",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "hnf_slc_fill_invalid_way",
+ "EventidCode": "0xb",
+ "NodeType": "0x5",
+ "BriefDescription": "Counts number of SLC fills to an invalid way.",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "hnf_mc_retries",
+ "EventidCode": "0xc",
+ "NodeType": "0x5",
+ "BriefDescription": "Counts number of retried transactions by the MC.",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "hnf_mc_reqs",
+ "EventidCode": "0xd",
+ "NodeType": "0x5",
+ "BriefDescription": "Counts number of requests that are sent to MC.",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "hnf_qos_hh_retry",
+ "EventidCode": "0xe",
+ "NodeType": "0x5",
+ "BriefDescription": "Counts number of times a HighHigh priority request is protocolretried at the HN‑F.",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "rnid_s0_rdata_beats",
+ "EventidCode": "0x1",
+ "NodeType": "0xa",
+ "BriefDescription": "Number of RData beats (RVALID and RREADY) dispatched on port 0. This event measures the read bandwidth, including CMO responses.",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "rnid_s1_rdata_beats",
+ "EventidCode": "0x2",
+ "NodeType": "0xa",
+ "BriefDescription": "Number of RData beats (RVALID and RREADY) dispatched on port 1. This event measures the read bandwidth, including CMO responses.",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "rnid_s2_rdata_beats",
+ "EventidCode": "0x3",
+ "NodeType": "0xa",
+ "BriefDescription": "Number of RData beats (RVALID and RREADY) dispatched on port 2. This event measures the read bandwidth, including CMO responses.",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "rnid_rxdat_flits",
+ "EventidCode": "0x4",
+ "NodeType": "0xa",
+ "BriefDescription": "Number of RXDAT flits received. This event measures the true read data bandwidth, excluding CMOs.",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "rnid_txdat_flits",
+ "EventidCode": "0x5",
+ "NodeType": "0xa",
+ "BriefDescription": "Number of TXDAT flits dispatched. This event measures the write bandwidth.",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "rnid_txreq_flits_total",
+ "EventidCode": "0x6",
+ "NodeType": "0xa",
+ "BriefDescription": "Number of TXREQ flits dispatched. This event measures the total request bandwidth.",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "rnid_txreq_flits_retried",
+ "EventidCode": "0x7",
+ "NodeType": "0xa",
+ "BriefDescription": "Number of retried TXREQ flits dispatched. This event measures the retry rate.",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "sbsx_txrsp_retryack",
+ "EventidCode": "0x4",
+ "NodeType": "0x7",
+ "BriefDescription": "Number of RXREQ flits dispatched. This event is a measure of the retry rate.",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "sbsx_txdat_flitv",
+ "EventidCode": "0x5",
+ "NodeType": "0x7",
+ "BriefDescription": "Number of TXDAT flits dispatched from XP to SBSX. This event is a measure of the write bandwidth.",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "sbsx_arvalid_no_arready",
+ "EventidCode": "0x21",
+ "NodeType": "0x7",
+ "BriefDescription": "Number of cycles the SBSX bridge is stalled because of backpressure on AR channel.",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "sbsx_awvalid_no_awready",
+ "EventidCode": "0x22",
+ "NodeType": "0x7",
+ "BriefDescription": "Number of cycles the SBSX bridge is stalled because of backpressure on AW channel.",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "sbsx_wvalid_no_wready",
+ "EventidCode": "0x23",
+ "NodeType": "0x7",
+ "BriefDescription": "Number of cycles the SBSX bridge is stalled because of backpressure on W channel.",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "hni_txrsp_retryack",
+ "EventidCode": "0x2a",
+ "NodeType": "0x4",
+ "BriefDescription": "Number of RXREQ flits dispatched. This event is a measure of the retry rate.",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "hni_arvalid_no_arready",
+ "EventidCode": "0x2b",
+ "NodeType": "0x4",
+ "BriefDescription": "Number of cycles the HN-I bridge is stalled because of backpressure on AR channel.",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "hni_arready_no_arvalid",
+ "EventidCode": "0x2c",
+ "NodeType": "0x4",
+ "BriefDescription": "Number of cycles the AR channel is waiting for new requests from HN-I bridge.",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "hni_awvalid_no_awready",
+ "EventidCode": "0x2d",
+ "NodeType": "0x4",
+ "BriefDescription": "Number of cycles the HN-I bridge is stalled because of backpressure on AW channel.",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "hni_awready_no_awvalid",
+ "EventidCode": "0x2e",
+ "NodeType": "0x4",
+ "BriefDescription": "Number of cycles the AW channel is waiting for new requests from HN-I bridge.",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "hni_wvalid_no_wready",
+ "EventidCode": "0x2f",
+ "NodeType": "0x4",
+ "BriefDescription": "Number of cycles the HN-I bridge is stalled because of backpressure on W channel.",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "EventName": "hni_txdat_stall",
+ "EventidCode": "0x30",
+ "NodeType": "0x4",
+ "BriefDescription": "TXDAT valid but no link credit available.",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ }
+]
diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py
index 057d51aa..b1ab412 100755
--- a/tools/perf/pmu-events/jevents.py
+++ b/tools/perf/pmu-events/jevents.py
@@ -289,6 +289,7 @@ class JsonEvent:
'cpu_core': 'cpu_core',
'cpu_atom': 'cpu_atom',
'ali_drw': 'ali_drw',
+ 'arm_cmn': 'arm_cmn',
}
return table[unit] if unit in table else f'uncore_{unit.lower()}'
--
1.8.3.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v9 7/7] perf vendor events: Add JSON metrics for Arm CMN
2023-09-18 11:52 [PATCH v9 0/7] Add metrics for Arm CMN Jing Zhang
` (5 preceding siblings ...)
2023-09-18 11:52 ` [PATCH v9 6/7] perf jevents: Add support for Arm CMN PMU aliasing Jing Zhang
@ 2023-09-18 11:52 ` Jing Zhang
6 siblings, 0 replies; 12+ messages in thread
From: Jing Zhang @ 2023-09-18 11:52 UTC (permalink / raw)
To: John Garry, Ian Rogers
Cc: Will Deacon, James Clark, Arnaldo Carvalho de Melo, Mark Rutland,
Mike Leach, Leo Yan, Namhyung Kim, Peter Zijlstra, Ingo Molnar,
Alexander Shishkin, Jiri Olsa, Adrian Hunter, linux-kernel,
linux-arm-kernel, linux-perf-users, linux-doc, Zhuo Song,
Jing Zhang, Shuai Xue
Add JSON metrics for Arm CMN. Currently just add part of CMN PMU
metrics which are general and compatible for any SoC with CMN-ANY.
Signed-off-by: Jing Zhang <renyu.zj@linux.alibaba.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
---
.../pmu-events/arch/arm64/arm/cmn/sys/metric.json | 74 ++++++++++++++++++++++
1 file changed, 74 insertions(+)
create mode 100644 tools/perf/pmu-events/arch/arm64/arm/cmn/sys/metric.json
diff --git a/tools/perf/pmu-events/arch/arm64/arm/cmn/sys/metric.json b/tools/perf/pmu-events/arch/arm64/arm/cmn/sys/metric.json
new file mode 100644
index 0000000..0e30026
--- /dev/null
+++ b/tools/perf/pmu-events/arch/arm64/arm/cmn/sys/metric.json
@@ -0,0 +1,74 @@
+[
+ {
+ "MetricName": "slc_miss_rate",
+ "BriefDescription": "The system level cache miss rate.",
+ "MetricGroup": "cmn",
+ "MetricExpr": "hnf_cache_miss / hnf_slc_sf_cache_access",
+ "ScaleUnit": "100%",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "MetricName": "hnf_message_retry_rate",
+ "BriefDescription": "HN-F message retry rate indicates whether a lack of credits is causing the bottlenecks.",
+ "MetricGroup": "cmn",
+ "MetricExpr": "hnf_pocq_retry / hnf_pocq_reqs_recvd",
+ "ScaleUnit": "100%",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "MetricName": "sf_hit_rate",
+ "BriefDescription": "Snoop filter hit rate can be used to measure the snoop filter efficiency.",
+ "MetricGroup": "cmn",
+ "MetricExpr": "hnf_sf_hit / hnf_slc_sf_cache_access",
+ "ScaleUnit": "100%",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "MetricName": "mc_message_retry_rate",
+ "BriefDescription": "The memory controller request retries rate indicates whether the memory controller is the bottleneck.",
+ "MetricGroup": "cmn",
+ "MetricExpr": "hnf_mc_retries / hnf_mc_reqs",
+ "ScaleUnit": "100%",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "MetricName": "rni_actual_read_bandwidth.all",
+ "BriefDescription": "This event measure the actual bandwidth that RN-I bridge sends to the interconnect.",
+ "MetricGroup": "cmn",
+ "MetricExpr": "rnid_rxdat_flits * 32 / 1e6 / duration_time",
+ "ScaleUnit": "1MB/s",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "MetricName": "rni_actual_write_bandwidth.all",
+ "BriefDescription": "This event measures the actual write bandwidth at RN-I bridges.",
+ "MetricGroup": "cmn",
+ "MetricExpr": "rnid_txdat_flits * 32 / 1e6 / duration_time",
+ "ScaleUnit": "1MB/s",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "MetricName": "rni_retry_rate",
+ "BriefDescription": "RN-I bridge retry rate indicates whether the memory controller is the bottleneck.",
+ "MetricGroup": "cmn",
+ "MetricExpr": "rnid_txreq_flits_retried / rnid_txreq_flits_total",
+ "ScaleUnit": "100%",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ },
+ {
+ "MetricName": "sbsx_actual_write_bandwidth.all",
+ "BriefDescription": "sbsx actual write bandwidth.",
+ "MetricGroup": "cmn",
+ "MetricExpr": "sbsx_txdat_flitv * 32 / 1e6 / duration_time",
+ "ScaleUnit": "1MB/s",
+ "Unit": "arm_cmn",
+ "Compat": "^(434|436|43c|43a)"
+ }
+]
--
1.8.3.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v9 1/7] perf pmu: "Compat" supports regular expression matching identifiers
2023-09-18 11:52 ` [PATCH v9 1/7] perf pmu: "Compat" supports regular expression matching identifiers Jing Zhang
@ 2023-09-20 18:36 ` Ian Rogers
2023-09-22 8:19 ` Jing Zhang
0 siblings, 1 reply; 12+ messages in thread
From: Ian Rogers @ 2023-09-20 18:36 UTC (permalink / raw)
To: Jing Zhang
Cc: John Garry, Will Deacon, James Clark, Arnaldo Carvalho de Melo,
Mark Rutland, Mike Leach, Leo Yan, Namhyung Kim, Peter Zijlstra,
Ingo Molnar, Alexander Shishkin, Jiri Olsa, Adrian Hunter,
linux-kernel, linux-arm-kernel, linux-perf-users, linux-doc,
Zhuo Song, Shuai Xue
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
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v9 1/7] perf pmu: "Compat" supports regular expression matching identifiers
2023-09-20 18:36 ` Ian Rogers
@ 2023-09-22 8:19 ` Jing Zhang
2023-09-22 14:58 ` Ian Rogers
0 siblings, 1 reply; 12+ messages in thread
From: Jing Zhang @ 2023-09-22 8:19 UTC (permalink / raw)
To: Ian Rogers
Cc: John Garry, Will Deacon, James Clark, Arnaldo Carvalho de Melo,
Mark Rutland, Mike Leach, Leo Yan, Namhyung Kim, Peter Zijlstra,
Ingo Molnar, Alexander Shishkin, Jiri Olsa, Adrian Hunter,
linux-kernel, linux-arm-kernel, linux-perf-users, linux-doc,
Zhuo Song, Shuai Xue
在 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
>>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v9 1/7] perf pmu: "Compat" supports regular expression matching identifiers
2023-09-22 8:19 ` Jing Zhang
@ 2023-09-22 14:58 ` Ian Rogers
2023-09-25 2:19 ` Jing Zhang
0 siblings, 1 reply; 12+ messages in thread
From: Ian Rogers @ 2023-09-22 14:58 UTC (permalink / raw)
To: Jing Zhang
Cc: John Garry, Will Deacon, James Clark, Arnaldo Carvalho de Melo,
Mark Rutland, Mike Leach, Leo Yan, Namhyung Kim, Peter Zijlstra,
Ingo Molnar, Alexander Shishkin, Jiri Olsa, Adrian Hunter,
linux-kernel, linux-arm-kernel, linux-perf-users, linux-doc,
Zhuo Song, Shuai Xue
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
> >>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v9 1/7] perf pmu: "Compat" supports regular expression matching identifiers
2023-09-22 14:58 ` Ian Rogers
@ 2023-09-25 2:19 ` Jing Zhang
0 siblings, 0 replies; 12+ messages in thread
From: Jing Zhang @ 2023-09-25 2:19 UTC (permalink / raw)
To: Ian Rogers
Cc: John Garry, Will Deacon, James Clark, Arnaldo Carvalho de Melo,
Mark Rutland, Mike Leach, Leo Yan, Namhyung Kim, Peter Zijlstra,
Ingo Molnar, Alexander Shishkin, Jiri Olsa, Adrian Hunter,
linux-kernel, linux-arm-kernel, linux-perf-users, linux-doc,
Zhuo Song, Shuai Xue
在 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
>>>>
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2023-09-25 2:20 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-18 11:52 [PATCH v9 0/7] Add metrics for Arm CMN Jing Zhang
2023-09-18 11:52 ` [PATCH v9 1/7] perf pmu: "Compat" supports regular expression matching identifiers Jing Zhang
2023-09-20 18:36 ` Ian Rogers
2023-09-22 8:19 ` Jing Zhang
2023-09-22 14:58 ` Ian Rogers
2023-09-25 2:19 ` Jing Zhang
2023-09-18 11:52 ` [PATCH v9 2/7] perf metric: " Jing Zhang
2023-09-18 11:52 ` [PATCH v9 3/7] perf jevents: Support EventidCode and NodeType Jing Zhang
2023-09-18 11:52 ` [PATCH v9 4/7] perf test: Make matching_pmu effective Jing Zhang
2023-09-18 11:52 ` [PATCH v9 5/7] perf test: Add pmu-event test for "Compat" and new event_field Jing Zhang
2023-09-18 11:52 ` [PATCH v9 6/7] perf jevents: Add support for Arm CMN PMU aliasing Jing Zhang
2023-09-18 11:52 ` [PATCH v9 7/7] perf vendor events: Add JSON metrics for Arm CMN Jing Zhang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®