Skip to content

Commit 292c34c

Browse files
Kan Liangacmel
authored andcommitted
perf pmu: Fix core PMU alias list for X86 platform
When counting uncore event with alias, core event is mistakenly involved, for example: perf stat --no-merge -e "unc_m_cas_count.all" -C0 sleep 1 Performance counter stats for 'CPU(s) 0': 0 unc_m_cas_count.all [uncore_imc_4] 0 unc_m_cas_count.all [uncore_imc_2] 0 unc_m_cas_count.all [uncore_imc_0] 153,640 unc_m_cas_count.all [cpu] 0 unc_m_cas_count.all [uncore_imc_5] 25,026 unc_m_cas_count.all [uncore_imc_3] 0 unc_m_cas_count.all [uncore_imc_1] 1.001447890 seconds time elapsed The reason is that current implementation doesn't check PMU name of a event when adding its alias into the alias list for core PMU. The uncore event aliases are mistakenly added. This bug was introduced in: commit 14b22ae ("perf pmu: Add helper function is_pmu_core to detect PMU CORE devices") Checking the PMU name for all PMUs on X86 and other architectures except ARM. There is no behavior change for ARM. Signed-off-by: Kan Liang <kan.liang@linux.intel.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Agustin Vega-Frias <agustinv@codeaurora.org> Cc: Andi Kleen <ak@linux.intel.com> Cc: Ganapatrao Kulkarni <ganapatrao.kulkarni@cavium.com> Cc: Jin Yao <yao.jin@linux.intel.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Shaokun Zhang <zhangshaokun@hisilicon.com> Cc: Will Deacon <will.deacon@arm.com> Fixes: 14b22ae ("perf pmu: Add helper function is_pmu_core to detect PMU CORE devices") Link: http://lkml.kernel.org/r/1524594014-79243-1-git-send-email-kan.liang@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 5d9946c commit 292c34c

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

tools/perf/util/pmu.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,10 @@ static bool pmu_is_uncore(const char *name)
539539

540540
/*
541541
* PMU CORE devices have different name other than cpu in sysfs on some
542-
* platforms. looking for possible sysfs files to identify as core device.
542+
* platforms.
543+
* Looking for possible sysfs files to identify the arm core device.
543544
*/
544-
static int is_pmu_core(const char *name)
545+
static int is_arm_pmu_core(const char *name)
545546
{
546547
struct stat st;
547548
char path[PATH_MAX];
@@ -550,12 +551,6 @@ static int is_pmu_core(const char *name)
550551
if (!sysfs)
551552
return 0;
552553

553-
/* Look for cpu sysfs (x86 and others) */
554-
scnprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu", sysfs);
555-
if ((stat(path, &st) == 0) &&
556-
(strncmp(name, "cpu", strlen("cpu")) == 0))
557-
return 1;
558-
559554
/* Look for cpu sysfs (specific to arm) */
560555
scnprintf(path, PATH_MAX, "%s/bus/event_source/devices/%s/cpus",
561556
sysfs, name);
@@ -668,6 +663,7 @@ static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu)
668663
struct pmu_events_map *map;
669664
struct pmu_event *pe;
670665
const char *name = pmu->name;
666+
const char *pname;
671667

672668
map = perf_pmu__find_map(pmu);
673669
if (!map)
@@ -686,11 +682,9 @@ static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu)
686682
break;
687683
}
688684

689-
if (!is_pmu_core(name)) {
690-
/* check for uncore devices */
691-
if (pe->pmu == NULL)
692-
continue;
693-
if (strncmp(pe->pmu, name, strlen(pe->pmu)))
685+
if (!is_arm_pmu_core(name)) {
686+
pname = pe->pmu ? pe->pmu : "cpu";
687+
if (strncmp(pname, name, strlen(pname)))
694688
continue;
695689
}
696690

0 commit comments

Comments
 (0)