Commit e126bef5 authored by John Garry's avatar John Garry Committed by Arnaldo Carvalho de Melo

perf pmu: Add pmu_events_map__find() function to find the common PMU map for the system

Add a function to find the common PMU map for the system.

For arm64, a special variant is added. This is because arm64 supports
heterogeneous CPU systems. As such, it cannot be guaranteed that the
cpumap is same for all CPUs. So in case of heterogeneous systems, don't
return a cpumap.
Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
Signed-off-by: default avatarJohn Garry <john.garry@huawei.com>
Tested-by: default avatarPaul A. Clarke <pc@us.ibm.com>
Acked-by: default avatarJiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Shaokun Zhang <zhangshaokun@hisilicon.com>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linuxarm@huawei.com
Link: https://lore.kernel.org/r/1617791570-165223-4-git-send-email-john.garry@huawei.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent a48a995e
...@@ -2,6 +2,7 @@ perf-y += header.o ...@@ -2,6 +2,7 @@ perf-y += header.o
perf-y += machine.o perf-y += machine.o
perf-y += perf_regs.o perf-y += perf_regs.o
perf-y += tsc.o perf-y += tsc.o
perf-y += pmu.o
perf-y += kvm-stat.o perf-y += kvm-stat.o
perf-$(CONFIG_DWARF) += dwarf-regs.o perf-$(CONFIG_DWARF) += dwarf-regs.o
perf-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind.o perf-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind.o
......
// SPDX-License-Identifier: GPL-2.0
#include "../../util/cpumap.h"
#include "../../util/pmu.h"
struct pmu_events_map *pmu_events_map__find(void)
{
struct perf_pmu *pmu = NULL;
while ((pmu = perf_pmu__scan(pmu))) {
if (!is_pmu_core(pmu->name))
continue;
/*
* The cpumap should cover all CPUs. Otherwise, some CPUs may
* not support some events or have different event IDs.
*/
if (pmu->cpus->nr != cpu__max_cpu())
return NULL;
return perf_pmu__find_map(pmu);
}
return NULL;
}
...@@ -539,7 +539,7 @@ static int resolve_metric_simple(struct expr_parse_ctx *pctx, ...@@ -539,7 +539,7 @@ static int resolve_metric_simple(struct expr_parse_ctx *pctx,
static int test_parsing(void) static int test_parsing(void)
{ {
struct pmu_events_map *cpus_map = perf_pmu__find_map(NULL); struct pmu_events_map *cpus_map = pmu_events_map__find();
struct pmu_events_map *map; struct pmu_events_map *map;
struct pmu_event *pe; struct pmu_event *pe;
int i, j, k; int i, j, k;
......
...@@ -618,7 +618,7 @@ static int metricgroup__print_sys_event_iter(struct pmu_event *pe, void *data) ...@@ -618,7 +618,7 @@ static int metricgroup__print_sys_event_iter(struct pmu_event *pe, void *data)
void metricgroup__print(bool metrics, bool metricgroups, char *filter, void metricgroup__print(bool metrics, bool metricgroups, char *filter,
bool raw, bool details) bool raw, bool details)
{ {
struct pmu_events_map *map = perf_pmu__find_map(NULL); struct pmu_events_map *map = pmu_events_map__find();
struct pmu_event *pe; struct pmu_event *pe;
int i; int i;
struct rblist groups; struct rblist groups;
...@@ -1254,8 +1254,7 @@ int metricgroup__parse_groups(const struct option *opt, ...@@ -1254,8 +1254,7 @@ int metricgroup__parse_groups(const struct option *opt,
struct rblist *metric_events) struct rblist *metric_events)
{ {
struct evlist *perf_evlist = *(struct evlist **)opt->value; struct evlist *perf_evlist = *(struct evlist **)opt->value;
struct pmu_events_map *map = perf_pmu__find_map(NULL); struct pmu_events_map *map = pmu_events_map__find();
return parse_groups(perf_evlist, str, metric_no_group, return parse_groups(perf_evlist, str, metric_no_group,
metric_no_merge, NULL, metric_events, map); metric_no_merge, NULL, metric_events, map);
...@@ -1274,7 +1273,7 @@ int metricgroup__parse_groups_test(struct evlist *evlist, ...@@ -1274,7 +1273,7 @@ int metricgroup__parse_groups_test(struct evlist *evlist,
bool metricgroup__has_metric(const char *metric) bool metricgroup__has_metric(const char *metric)
{ {
struct pmu_events_map *map = perf_pmu__find_map(NULL); struct pmu_events_map *map = pmu_events_map__find();
struct pmu_event *pe; struct pmu_event *pe;
int i; int i;
......
...@@ -717,6 +717,11 @@ struct pmu_events_map *perf_pmu__find_map(struct perf_pmu *pmu) ...@@ -717,6 +717,11 @@ struct pmu_events_map *perf_pmu__find_map(struct perf_pmu *pmu)
return map; return map;
} }
struct pmu_events_map *__weak pmu_events_map__find(void)
{
return perf_pmu__find_map(NULL);
}
bool pmu_uncore_alias_match(const char *pmu_name, const char *name) bool pmu_uncore_alias_match(const char *pmu_name, const char *name)
{ {
char *tmp = NULL, *tok, *str; char *tmp = NULL, *tok, *str;
......
...@@ -114,6 +114,7 @@ void pmu_add_cpu_aliases_map(struct list_head *head, struct perf_pmu *pmu, ...@@ -114,6 +114,7 @@ void pmu_add_cpu_aliases_map(struct list_head *head, struct perf_pmu *pmu,
struct pmu_events_map *map); struct pmu_events_map *map);
struct pmu_events_map *perf_pmu__find_map(struct perf_pmu *pmu); struct pmu_events_map *perf_pmu__find_map(struct perf_pmu *pmu);
struct pmu_events_map *pmu_events_map__find(void);
bool pmu_uncore_alias_match(const char *pmu_name, const char *name); bool pmu_uncore_alias_match(const char *pmu_name, const char *name);
void perf_pmu_free_alias(struct perf_pmu_alias *alias); void perf_pmu_free_alias(struct perf_pmu_alias *alias);
......
...@@ -160,11 +160,9 @@ static void s390_cpumcfdg_dump(struct perf_sample *sample) ...@@ -160,11 +160,9 @@ static void s390_cpumcfdg_dump(struct perf_sample *sample)
const char *color = PERF_COLOR_BLUE; const char *color = PERF_COLOR_BLUE;
struct cf_ctrset_entry *cep, ce; struct cf_ctrset_entry *cep, ce;
struct pmu_events_map *map; struct pmu_events_map *map;
struct perf_pmu pmu;
u64 *p; u64 *p;
memset(&pmu, 0, sizeof(pmu)); map = pmu_events_map__find();
map = perf_pmu__find_map(&pmu);
while (offset < len) { while (offset < len) {
cep = (struct cf_ctrset_entry *)(buf + offset); cep = (struct cf_ctrset_entry *)(buf + offset);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment