Skip to content

Commit d2045f8

Browse files
captain5050acmel
authored andcommitted
perf jevents: Use "default_core" for events with no Unit
The JSON Unit field encodes the name of the PMU to match the events to. When no name is given it has meant the "cpu" core PMU except for tests. On ARM, Intel hybrid and s390 the core PMU is named differently which means that using "cpu" for this case causes the events not to get matched to the PMU. Introduce a new "default_core" string for this case and in the pmu__name_match force all core PMUs to match this name. Fixes: 2e255b4 ("perf jevents: Group events by PMU") Reported-by: Arnaldo Carvalho de Melo <acme@kernel.org> Reported-by: Thomas Richter <tmricht@linux.ibm.com> Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Ian Rogers <irogers@google.com> Cc: James Clark <james.clark@arm.com> Cc: Jing Zhang <renyu.zj@linux.alibaba.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: John Garry <john.g.garry@oracle.com> Cc: Kajol Jain <kjain@linux.ibm.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lore.kernel.org/lkml/20230826062203.1058041-1-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent a84260e commit d2045f8

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

tools/perf/pmu-events/jevents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def real_event(name: str, event: str) -> Optional[str]:
266266
def unit_to_pmu(unit: str) -> Optional[str]:
267267
"""Convert a JSON Unit to Linux PMU name."""
268268
if not unit:
269-
return 'cpu'
269+
return 'default_core'
270270
# Comment brought over from jevents.c:
271271
# it's not realistic to keep adding these, we need something more scalable ...
272272
table = {

tools/perf/tests/pmu-events.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct perf_pmu_test_pmu {
4444

4545
static const struct perf_pmu_test_event bp_l1_btb_correct = {
4646
.event = {
47-
.pmu = "cpu",
47+
.pmu = "default_core",
4848
.name = "bp_l1_btb_correct",
4949
.event = "event=0x8a",
5050
.desc = "L1 BTB Correction",
@@ -56,7 +56,7 @@ static const struct perf_pmu_test_event bp_l1_btb_correct = {
5656

5757
static const struct perf_pmu_test_event bp_l2_btb_correct = {
5858
.event = {
59-
.pmu = "cpu",
59+
.pmu = "default_core",
6060
.name = "bp_l2_btb_correct",
6161
.event = "event=0x8b",
6262
.desc = "L2 BTB Correction",
@@ -68,7 +68,7 @@ static const struct perf_pmu_test_event bp_l2_btb_correct = {
6868

6969
static const struct perf_pmu_test_event segment_reg_loads_any = {
7070
.event = {
71-
.pmu = "cpu",
71+
.pmu = "default_core",
7272
.name = "segment_reg_loads.any",
7373
.event = "event=0x6,period=200000,umask=0x80",
7474
.desc = "Number of segment register loads",
@@ -80,7 +80,7 @@ static const struct perf_pmu_test_event segment_reg_loads_any = {
8080

8181
static const struct perf_pmu_test_event dispatch_blocked_any = {
8282
.event = {
83-
.pmu = "cpu",
83+
.pmu = "default_core",
8484
.name = "dispatch_blocked.any",
8585
.event = "event=0x9,period=200000,umask=0x20",
8686
.desc = "Memory cluster signals to block micro-op dispatch for any reason",
@@ -92,7 +92,7 @@ static const struct perf_pmu_test_event dispatch_blocked_any = {
9292

9393
static const struct perf_pmu_test_event eist_trans = {
9494
.event = {
95-
.pmu = "cpu",
95+
.pmu = "default_core",
9696
.name = "eist_trans",
9797
.event = "event=0x3a,period=200000,umask=0x0",
9898
.desc = "Number of Enhanced Intel SpeedStep(R) Technology (EIST) transitions",
@@ -104,7 +104,7 @@ static const struct perf_pmu_test_event eist_trans = {
104104

105105
static const struct perf_pmu_test_event l3_cache_rd = {
106106
.event = {
107-
.pmu = "cpu",
107+
.pmu = "default_core",
108108
.name = "l3_cache_rd",
109109
.event = "event=0x40",
110110
.desc = "L3 cache access, read",
@@ -391,8 +391,8 @@ static int compare_alias_to_test_event(struct pmu_event_info *alias,
391391
return -1;
392392
}
393393

394-
395-
if (!is_same(alias->pmu_name, test_event->event.pmu)) {
394+
if (!is_same(alias->pmu_name, test_event->event.pmu) &&
395+
!is_same(alias->pmu_name, "default_core")) {
396396
pr_debug("testing aliases PMU %s: mismatched pmu_name, %s vs %s\n",
397397
pmu_name, alias->pmu_name, test_event->event.pmu);
398398
return -1;
@@ -409,7 +409,7 @@ static int test__pmu_event_table_core_callback(const struct pmu_event *pe,
409409
struct perf_pmu_test_event const **test_event_table;
410410
bool found = false;
411411

412-
if (strcmp(pe->pmu, "cpu"))
412+
if (strcmp(pe->pmu, "default_core"))
413413
test_event_table = &uncore_events[0];
414414
else
415415
test_event_table = &core_events[0];
@@ -543,6 +543,7 @@ static int __test_core_pmu_event_aliases(const char *pmu_name, int *count)
543543
INIT_LIST_HEAD(&pmu->caps);
544544
INIT_LIST_HEAD(&pmu->list);
545545
pmu->name = strdup(pmu_name);
546+
pmu->is_core = true;
546547

547548
pmu->events_table = table;
548549
pmu_add_cpu_aliases_table(pmu, table);

tools/perf/util/pmu.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,12 @@ int perf_pmu__for_each_event(struct perf_pmu *pmu, bool skip_duplicate_pmus,
17471747
bool pmu__name_match(const struct perf_pmu *pmu, const char *pmu_name)
17481748
{
17491749
return !strcmp(pmu->name, pmu_name) ||
1750-
(pmu->is_uncore && pmu_uncore_alias_match(pmu_name, pmu->name));
1750+
(pmu->is_uncore && pmu_uncore_alias_match(pmu_name, pmu->name)) ||
1751+
/*
1752+
* jevents and tests use default_core as a marker for any core
1753+
* PMU as the PMU name varies across architectures.
1754+
*/
1755+
(pmu->is_core && !strcmp(pmu_name, "default_core"));
17511756
}
17521757

17531758
bool perf_pmu__is_software(const struct perf_pmu *pmu)

0 commit comments

Comments
 (0)