Skip to content

Commit 9897009

Browse files
captain5050acmel
authored andcommitted
perf header: Fix missing PMU caps
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. Fixes: 178ddf3 ("perf header: Avoid hybrid PMU list in write_pmu_caps") Reported-by: Wei Li <liwei391@huawei.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: Athira Rajeev <atrajeev@linux.vnet.ibm.com> Cc: Huacai Chen <chenhuacai@kernel.org> Cc: Ian Rogers <irogers@google.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@arm.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: John Garry <john.g.garry@oracle.com> Cc: K Prateek Nayak <kprateek.nayak@amd.com> Cc: Kajol Jain <kjain@linux.ibm.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Leo Yan <leo.yan@linaro.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mike Leach <mike.leach@linaro.org> Cc: Ming Wang <wangming01@loongson.cn> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ravi Bangoria <ravi.bangoria@amd.com> Cc: Sean Christopherson <seanjc@google.com> Cc: Suzuki Poulouse <suzuki.poulose@arm.com> Cc: Will Deacon <will@kernel.org> Cc: linux-arm-kernel@lists.infradead.org Link: https://lore.kernel.org/r/20230825024002.801955-2-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent eeb6b12 commit 9897009

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

tools/perf/util/header.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,8 +1605,15 @@ static int write_pmu_caps(struct feat_fd *ff,
16051605
int ret;
16061606

16071607
while ((pmu = perf_pmus__scan(pmu))) {
1608-
if (!pmu->name || !strcmp(pmu->name, "cpu") ||
1609-
perf_pmu__caps_parse(pmu) <= 0)
1608+
if (!strcmp(pmu->name, "cpu")) {
1609+
/*
1610+
* The "cpu" PMU is special and covered by
1611+
* HEADER_CPU_PMU_CAPS. Note, core PMUs are
1612+
* counted/written here for ARM, s390 and Intel hybrid.
1613+
*/
1614+
continue;
1615+
}
1616+
if (perf_pmu__caps_parse(pmu) <= 0)
16101617
continue;
16111618
nr_pmu++;
16121619
}
@@ -1619,23 +1626,17 @@ static int write_pmu_caps(struct feat_fd *ff,
16191626
return 0;
16201627

16211628
/*
1622-
* Write hybrid pmu caps first to maintain compatibility with
1623-
* older perf tool.
1629+
* Note older perf tools assume core PMUs come first, this is a property
1630+
* of perf_pmus__scan.
16241631
*/
1625-
if (perf_pmus__num_core_pmus() > 1) {
1626-
pmu = NULL;
1627-
while ((pmu = perf_pmus__scan_core(pmu))) {
1628-
ret = __write_pmu_caps(ff, pmu, true);
1629-
if (ret < 0)
1630-
return ret;
1631-
}
1632-
}
1633-
16341632
pmu = NULL;
16351633
while ((pmu = perf_pmus__scan(pmu))) {
1636-
if (pmu->is_core || !pmu->nr_caps)
1634+
if (!strcmp(pmu->name, "cpu")) {
1635+
/* Skip as above. */
1636+
continue;
1637+
}
1638+
if (perf_pmu__caps_parse(pmu) <= 0)
16371639
continue;
1638-
16391640
ret = __write_pmu_caps(ff, pmu, true);
16401641
if (ret < 0)
16411642
return ret;

0 commit comments

Comments
 (0)