Commit eeac7730 authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo

perf pmu-events: Avoid passing pmu_events_map

Preparation for hiding pmu_events_map as an implementation detail. While
the map is passed, the table of events is all that is normally wanted.

While modifying the function's types, rename pmu_events_map__find to
pmu_events_table__find to match later encapsulation. Similarly rename
pmu_add_cpu_aliases_map to pmu_add_cpu_aliases_table.
Signed-off-by: default avatarIan Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.garry@huawei.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: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Will Deacon <will@kernel.org>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Cc: linux-arm-kernel@lists.infradead.org
Link: https://lore.kernel.org/r/20220812230949.683239-7-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 2519db2a
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include "../../../util/cpumap.h" #include "../../../util/cpumap.h"
#include "../../../util/pmu.h" #include "../../../util/pmu.h"
const struct pmu_events_map *pmu_events_map__find(void) const struct pmu_event *pmu_events_table__find(void)
{ {
struct perf_pmu *pmu = NULL; struct perf_pmu *pmu = NULL;
...@@ -18,7 +18,7 @@ const struct pmu_events_map *pmu_events_map__find(void) ...@@ -18,7 +18,7 @@ const struct pmu_events_map *pmu_events_map__find(void)
if (pmu->cpus->nr != cpu__max_cpu().cpu) if (pmu->cpus->nr != cpu__max_cpu().cpu)
return NULL; return NULL;
return perf_pmu__find_map(pmu); return perf_pmu__find_table(pmu);
} }
return NULL; return NULL;
......
...@@ -195,16 +195,12 @@ static int expand_metric_events(void) ...@@ -195,16 +195,12 @@ static int expand_metric_events(void)
.metric_name = NULL, .metric_name = NULL,
}, },
}; };
const struct pmu_events_map ev_map = {
.cpuid = "test",
.table = pme_test,
};
evlist = evlist__new(); evlist = evlist__new();
TEST_ASSERT_VAL("failed to get evlist", evlist); TEST_ASSERT_VAL("failed to get evlist", evlist);
rblist__init(&metric_events); rblist__init(&metric_events);
ret = metricgroup__parse_groups_test(evlist, &ev_map, metric_str, ret = metricgroup__parse_groups_test(evlist, pme_test, metric_str,
false, false, &metric_events); false, false, &metric_events);
if (ret < 0) { if (ret < 0) {
pr_debug("failed to parse '%s' metric\n", metric_str); pr_debug("failed to parse '%s' metric\n", metric_str);
......
...@@ -79,11 +79,6 @@ static struct pmu_event pme_test[] = { ...@@ -79,11 +79,6 @@ static struct pmu_event pme_test[] = {
} }
}; };
static const struct pmu_events_map map = {
.cpuid = "test",
.table = pme_test,
};
struct value { struct value {
const char *event; const char *event;
u64 val; u64 val;
...@@ -166,7 +161,7 @@ static int __compute_metric(const char *name, struct value *vals, ...@@ -166,7 +161,7 @@ static int __compute_metric(const char *name, struct value *vals,
runtime_stat__init(&st); runtime_stat__init(&st);
/* Parse the metric into metric_events list. */ /* Parse the metric into metric_events list. */
err = metricgroup__parse_groups_test(evlist, &map, name, err = metricgroup__parse_groups_test(evlist, pme_test, name,
false, false, false, false,
&metric_events); &metric_events);
if (err) if (err)
......
...@@ -272,13 +272,11 @@ static bool is_same(const char *reference, const char *test) ...@@ -272,13 +272,11 @@ static bool is_same(const char *reference, const char *test)
return !strcmp(reference, test); return !strcmp(reference, test);
} }
static const struct pmu_events_map *__test_pmu_get_events_map(void) static const struct pmu_event *__test_pmu_get_events_table(void)
{ {
const struct pmu_events_map *map; for (const struct pmu_events_map *map = &pmu_events_map[0]; map->cpuid; map++) {
for (map = &pmu_events_map[0]; map->cpuid; map++) {
if (!strcmp(map->cpuid, "testcpu")) if (!strcmp(map->cpuid, "testcpu"))
return map; return map->table;
} }
pr_err("could not find test events map\n"); pr_err("could not find test events map\n");
...@@ -440,8 +438,7 @@ static int test__pmu_event_table(struct test_suite *test __maybe_unused, ...@@ -440,8 +438,7 @@ static int test__pmu_event_table(struct test_suite *test __maybe_unused,
int subtest __maybe_unused) int subtest __maybe_unused)
{ {
const struct pmu_event *sys_event_tables = find_sys_events_table("pme_test_soc_sys"); const struct pmu_event *sys_event_tables = find_sys_events_table("pme_test_soc_sys");
const struct pmu_events_map *map = __test_pmu_get_events_map(); const struct pmu_event *table = __test_pmu_get_events_table();
const struct pmu_event *table;
int map_events = 0, expected_events; int map_events = 0, expected_events;
/* ignore 3x sentinels */ /* ignore 3x sentinels */
...@@ -449,10 +446,10 @@ static int test__pmu_event_table(struct test_suite *test __maybe_unused, ...@@ -449,10 +446,10 @@ static int test__pmu_event_table(struct test_suite *test __maybe_unused,
ARRAY_SIZE(uncore_events) + ARRAY_SIZE(uncore_events) +
ARRAY_SIZE(sys_events) - 3; ARRAY_SIZE(sys_events) - 3;
if (!map || !sys_event_tables) if (!table || !sys_event_tables)
return -1; return -1;
for (table = map->table; table->name; table++) { for (; table->name; table++) {
struct perf_pmu_test_event const **test_event_table; struct perf_pmu_test_event const **test_event_table;
bool found = false; bool found = false;
...@@ -537,10 +534,10 @@ static int __test_core_pmu_event_aliases(char *pmu_name, int *count) ...@@ -537,10 +534,10 @@ static int __test_core_pmu_event_aliases(char *pmu_name, int *count)
struct perf_pmu *pmu; struct perf_pmu *pmu;
LIST_HEAD(aliases); LIST_HEAD(aliases);
int res = 0; int res = 0;
const struct pmu_events_map *map = __test_pmu_get_events_map(); const struct pmu_event *table = __test_pmu_get_events_table();
struct perf_pmu_alias *a, *tmp; struct perf_pmu_alias *a, *tmp;
if (!map) if (!table)
return -1; return -1;
test_event_table = &core_events[0]; test_event_table = &core_events[0];
...@@ -551,7 +548,7 @@ static int __test_core_pmu_event_aliases(char *pmu_name, int *count) ...@@ -551,7 +548,7 @@ static int __test_core_pmu_event_aliases(char *pmu_name, int *count)
pmu->name = pmu_name; pmu->name = pmu_name;
pmu_add_cpu_aliases_map(&aliases, pmu, map); pmu_add_cpu_aliases_table(&aliases, pmu, table);
for (; *test_event_table; test_event_table++) { for (; *test_event_table; test_event_table++) {
struct perf_pmu_test_event const *test_event = *test_event_table; struct perf_pmu_test_event const *test_event = *test_event_table;
...@@ -590,14 +587,14 @@ static int __test_uncore_pmu_event_aliases(struct perf_pmu_test_pmu *test_pmu) ...@@ -590,14 +587,14 @@ static int __test_uncore_pmu_event_aliases(struct perf_pmu_test_pmu *test_pmu)
struct perf_pmu *pmu = &test_pmu->pmu; struct perf_pmu *pmu = &test_pmu->pmu;
const char *pmu_name = pmu->name; const char *pmu_name = pmu->name;
struct perf_pmu_alias *a, *tmp, *alias; struct perf_pmu_alias *a, *tmp, *alias;
const struct pmu_events_map *map; const struct pmu_event *events_table;
LIST_HEAD(aliases); LIST_HEAD(aliases);
int res = 0; int res = 0;
map = __test_pmu_get_events_map(); events_table = __test_pmu_get_events_table();
if (!map) if (!events_table)
return -1; return -1;
pmu_add_cpu_aliases_map(&aliases, pmu, map); pmu_add_cpu_aliases_table(&aliases, pmu, events_table);
pmu_add_sys_aliases(&aliases, pmu); pmu_add_sys_aliases(&aliases, pmu);
/* Count how many aliases we generated */ /* Count how many aliases we generated */
...@@ -848,13 +845,9 @@ static int check_parse_fake(const char *id) ...@@ -848,13 +845,9 @@ static int check_parse_fake(const char *id)
return ret; return ret;
} }
static void expr_failure(const char *msg, static void expr_failure(const char *msg, const struct pmu_event *pe)
const struct pmu_events_map *map,
const struct pmu_event *pe)
{ {
pr_debug("%s for map %s %s\n", msg, map->arch, map->cpuid); pr_debug("%s\nOn metric %s\nOn expression %s\n", msg, pe->metric_name, pe->metric_expr);
pr_debug("On metric %s\n", pe->metric_name);
pr_debug("On expression %s\n", pe->metric_expr);
} }
struct metric { struct metric {
...@@ -864,7 +857,7 @@ struct metric { ...@@ -864,7 +857,7 @@ struct metric {
static int resolve_metric_simple(struct expr_parse_ctx *pctx, static int resolve_metric_simple(struct expr_parse_ctx *pctx,
struct list_head *compound_list, struct list_head *compound_list,
const struct pmu_events_map *map, const struct pmu_event *map,
const char *metric_name) const char *metric_name)
{ {
struct hashmap_entry *cur, *cur_tmp; struct hashmap_entry *cur, *cur_tmp;
...@@ -925,8 +918,7 @@ static int resolve_metric_simple(struct expr_parse_ctx *pctx, ...@@ -925,8 +918,7 @@ static int resolve_metric_simple(struct expr_parse_ctx *pctx,
static int test__parsing(struct test_suite *test __maybe_unused, static int test__parsing(struct test_suite *test __maybe_unused,
int subtest __maybe_unused) int subtest __maybe_unused)
{ {
const struct pmu_events_map *cpus_map = pmu_events_map__find(); const struct pmu_event *cpus_table = pmu_events_table__find();
const struct pmu_events_map *map;
const struct pmu_event *pe; const struct pmu_event *pe;
int i, j, k; int i, j, k;
int ret = 0; int ret = 0;
...@@ -940,7 +932,8 @@ static int test__parsing(struct test_suite *test __maybe_unused, ...@@ -940,7 +932,8 @@ static int test__parsing(struct test_suite *test __maybe_unused,
} }
i = 0; i = 0;
for (;;) { for (;;) {
map = &pmu_events_map[i++]; const struct pmu_events_map *map = &pmu_events_map[i++];
if (!map->table) if (!map->table)
break; break;
j = 0; j = 0;
...@@ -957,14 +950,14 @@ static int test__parsing(struct test_suite *test __maybe_unused, ...@@ -957,14 +950,14 @@ static int test__parsing(struct test_suite *test __maybe_unused,
continue; continue;
expr__ctx_clear(ctx); expr__ctx_clear(ctx);
if (expr__find_ids(pe->metric_expr, NULL, ctx) < 0) { if (expr__find_ids(pe->metric_expr, NULL, ctx) < 0) {
expr_failure("Parse find ids failed", map, pe); expr_failure("Parse find ids failed", pe);
ret++; ret++;
continue; continue;
} }
if (resolve_metric_simple(ctx, &compound_list, map, if (resolve_metric_simple(ctx, &compound_list, map->table,
pe->metric_name)) { pe->metric_name)) {
expr_failure("Could not resolve metrics", map, pe); expr_failure("Could not resolve metrics", pe);
ret++; ret++;
goto exit; /* Don't tolerate errors due to severity */ goto exit; /* Don't tolerate errors due to severity */
} }
...@@ -979,7 +972,7 @@ static int test__parsing(struct test_suite *test __maybe_unused, ...@@ -979,7 +972,7 @@ static int test__parsing(struct test_suite *test __maybe_unused,
expr__add_id_val(ctx, strdup(cur->key), k++); expr__add_id_val(ctx, strdup(cur->key), k++);
hashmap__for_each_entry(ctx->ids, cur, bkt) { hashmap__for_each_entry(ctx->ids, cur, bkt) {
if (check_parse_cpu(cur->key, map == cpus_map, if (check_parse_cpu(cur->key, map->table == cpus_table,
pe)) pe))
ret++; ret++;
} }
...@@ -999,7 +992,7 @@ static int test__parsing(struct test_suite *test __maybe_unused, ...@@ -999,7 +992,7 @@ static int test__parsing(struct test_suite *test __maybe_unused,
hashmap__for_each_entry(ctx->ids, cur, bkt) hashmap__for_each_entry(ctx->ids, cur, bkt)
expr__add_id_val(ctx, strdup(cur->key), k--); expr__add_id_val(ctx, strdup(cur->key), k--);
if (expr__parse(&result, ctx, pe->metric_expr)) { if (expr__parse(&result, ctx, pe->metric_expr)) {
expr_failure("Parse failed", map, pe); expr_failure("Parse failed", pe);
ret++; ret++;
} }
} }
...@@ -1088,8 +1081,6 @@ static int metric_parse_fake(const char *str) ...@@ -1088,8 +1081,6 @@ static int metric_parse_fake(const char *str)
static int test__parsing_fake(struct test_suite *test __maybe_unused, static int test__parsing_fake(struct test_suite *test __maybe_unused,
int subtest __maybe_unused) int subtest __maybe_unused)
{ {
const struct pmu_events_map *map;
const struct pmu_event *pe;
unsigned int i, j; unsigned int i, j;
int err = 0; int err = 0;
...@@ -1101,12 +1092,14 @@ static int test__parsing_fake(struct test_suite *test __maybe_unused, ...@@ -1101,12 +1092,14 @@ static int test__parsing_fake(struct test_suite *test __maybe_unused,
i = 0; i = 0;
for (;;) { for (;;) {
map = &pmu_events_map[i++]; const struct pmu_events_map *map = &pmu_events_map[i++];
if (!map->table) if (!map->table)
break; break;
j = 0; j = 0;
for (;;) { for (;;) {
pe = &map->table[j++]; const struct pmu_event *pe = &map->table[j++];
if (!pe->name && !pe->metric_group && !pe->metric_name) if (!pe->name && !pe->metric_group && !pe->metric_name)
break; break;
if (!pe->metric_expr) if (!pe->metric_expr)
......
This diff is collapsed.
...@@ -71,9 +71,9 @@ int metricgroup__parse_groups(const struct option *opt, ...@@ -71,9 +71,9 @@ int metricgroup__parse_groups(const struct option *opt,
bool metric_no_merge, bool metric_no_merge,
struct rblist *metric_events); struct rblist *metric_events);
const struct pmu_event *metricgroup__find_metric(const char *metric, const struct pmu_event *metricgroup__find_metric(const char *metric,
const struct pmu_events_map *map); const struct pmu_event *table);
int metricgroup__parse_groups_test(struct evlist *evlist, int metricgroup__parse_groups_test(struct evlist *evlist,
const struct pmu_events_map *map, const struct pmu_event *table,
const char *str, const char *str,
bool metric_no_group, bool metric_no_group,
bool metric_no_merge, bool metric_no_merge,
......
...@@ -710,9 +710,9 @@ static char *perf_pmu__getcpuid(struct perf_pmu *pmu) ...@@ -710,9 +710,9 @@ static char *perf_pmu__getcpuid(struct perf_pmu *pmu)
return cpuid; return cpuid;
} }
const struct pmu_events_map *perf_pmu__find_map(struct perf_pmu *pmu) const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu)
{ {
const struct pmu_events_map *map; const struct pmu_event *table = NULL;
char *cpuid = perf_pmu__getcpuid(pmu); char *cpuid = perf_pmu__getcpuid(pmu);
int i; int i;
...@@ -724,22 +724,23 @@ const struct pmu_events_map *perf_pmu__find_map(struct perf_pmu *pmu) ...@@ -724,22 +724,23 @@ const struct pmu_events_map *perf_pmu__find_map(struct perf_pmu *pmu)
i = 0; i = 0;
for (;;) { for (;;) {
map = &pmu_events_map[i++]; const struct pmu_events_map *map = &pmu_events_map[i++];
if (!map->table) {
map = NULL; if (!map->table)
break; break;
}
if (!strcmp_cpuid_str(map->cpuid, cpuid)) if (!strcmp_cpuid_str(map->cpuid, cpuid)) {
table = map->table;
break; break;
}
} }
free(cpuid); free(cpuid);
return map; return table;
} }
const struct pmu_events_map *__weak pmu_events_map__find(void) __weak const struct pmu_event *pmu_events_table__find(void)
{ {
return perf_pmu__find_map(NULL); return perf_pmu__find_table(NULL);
} }
/* /*
...@@ -823,8 +824,8 @@ bool pmu_uncore_alias_match(const char *pmu_name, const char *name) ...@@ -823,8 +824,8 @@ bool pmu_uncore_alias_match(const char *pmu_name, const char *name)
* to the current running CPU. Then, add all PMU events from that table * to the current running CPU. Then, add all PMU events from that table
* as aliases. * as aliases.
*/ */
void pmu_add_cpu_aliases_map(struct list_head *head, struct perf_pmu *pmu, void pmu_add_cpu_aliases_table(struct list_head *head, struct perf_pmu *pmu,
const struct pmu_events_map *map) const struct pmu_event *table)
{ {
int i; int i;
const char *name = pmu->name; const char *name = pmu->name;
...@@ -834,7 +835,7 @@ void pmu_add_cpu_aliases_map(struct list_head *head, struct perf_pmu *pmu, ...@@ -834,7 +835,7 @@ void pmu_add_cpu_aliases_map(struct list_head *head, struct perf_pmu *pmu,
i = 0; i = 0;
while (1) { while (1) {
const char *cpu_name = is_arm_pmu_core(name) ? name : "cpu"; const char *cpu_name = is_arm_pmu_core(name) ? name : "cpu";
const struct pmu_event *pe = &map->table[i++]; const struct pmu_event *pe = &table[i++];
const char *pname = pe->pmu ? pe->pmu : cpu_name; const char *pname = pe->pmu ? pe->pmu : cpu_name;
if (!pe->name) { if (!pe->name) {
...@@ -859,13 +860,13 @@ void pmu_add_cpu_aliases_map(struct list_head *head, struct perf_pmu *pmu, ...@@ -859,13 +860,13 @@ void pmu_add_cpu_aliases_map(struct list_head *head, struct perf_pmu *pmu,
static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu) static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu)
{ {
const struct pmu_events_map *map; const struct pmu_event *table;
map = perf_pmu__find_map(pmu); table = perf_pmu__find_table(pmu);
if (!map) if (!table)
return; return;
pmu_add_cpu_aliases_map(head, pmu, map); pmu_add_cpu_aliases_table(head, pmu, table);
} }
struct pmu_sys_event_iter_data { struct pmu_sys_event_iter_data {
......
...@@ -125,11 +125,11 @@ int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt, ...@@ -125,11 +125,11 @@ int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt,
int perf_pmu__test(void); int perf_pmu__test(void);
struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu); struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu);
void pmu_add_cpu_aliases_map(struct list_head *head, struct perf_pmu *pmu, void pmu_add_cpu_aliases_table(struct list_head *head, struct perf_pmu *pmu,
const struct pmu_events_map *map); const struct pmu_event *table);
const struct pmu_events_map *perf_pmu__find_map(struct perf_pmu *pmu); const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu);
const struct pmu_events_map *pmu_events_map__find(void); const struct pmu_event *pmu_events_table__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);
......
...@@ -135,12 +135,12 @@ static int get_counterset_start(int setnr) ...@@ -135,12 +135,12 @@ static int get_counterset_start(int setnr)
* the name of this counter. * the name of this counter.
* If no match is found a NULL pointer is returned. * If no match is found a NULL pointer is returned.
*/ */
static const char *get_counter_name(int set, int nr, const struct pmu_events_map *map) static const char *get_counter_name(int set, int nr, const struct pmu_event *table)
{ {
int rc, event_nr, wanted = get_counterset_start(set) + nr; int rc, event_nr, wanted = get_counterset_start(set) + nr;
if (map) { if (table) {
const struct pmu_event *evp = map->table; const struct pmu_event *evp = table;
for (; evp->name || evp->event || evp->desc; ++evp) { for (; evp->name || evp->event || evp->desc; ++evp) {
if (evp->name == NULL || evp->event == NULL) if (evp->name == NULL || evp->event == NULL)
...@@ -159,10 +159,10 @@ static void s390_cpumcfdg_dump(struct perf_sample *sample) ...@@ -159,10 +159,10 @@ static void s390_cpumcfdg_dump(struct perf_sample *sample)
unsigned char *buf = sample->raw_data; unsigned char *buf = sample->raw_data;
const char *color = PERF_COLOR_BLUE; const char *color = PERF_COLOR_BLUE;
struct cf_ctrset_entry *cep, ce; struct cf_ctrset_entry *cep, ce;
const struct pmu_events_map *map; const struct pmu_event *table;
u64 *p; u64 *p;
map = pmu_events_map__find(); table = pmu_events_table__find();
while (offset < len) { while (offset < len) {
cep = (struct cf_ctrset_entry *)(buf + offset); cep = (struct cf_ctrset_entry *)(buf + offset);
...@@ -180,7 +180,7 @@ static void s390_cpumcfdg_dump(struct perf_sample *sample) ...@@ -180,7 +180,7 @@ static void s390_cpumcfdg_dump(struct perf_sample *sample)
color_fprintf(stdout, color, " [%#08zx] Counterset:%d" color_fprintf(stdout, color, " [%#08zx] Counterset:%d"
" Counters:%d\n", offset, ce.set, ce.ctr); " Counters:%d\n", offset, ce.set, ce.ctr);
for (i = 0, p = (u64 *)(cep + 1); i < ce.ctr; ++i, ++p) { for (i = 0, p = (u64 *)(cep + 1); i < ce.ctr; ++i, ++p) {
const char *ev_name = get_counter_name(ce.set, i, map); const char *ev_name = get_counter_name(ce.set, i, table);
color_fprintf(stdout, color, color_fprintf(stdout, color,
"\tCounter:%03d %s Value:%#018lx\n", i, "\tCounter:%03d %s Value:%#018lx\n", i,
......
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