Skip to content

Commit eeac773

Browse files
captain5050acmel
authored andcommitted
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: Ian Rogers <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: James Clark <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: John Garry <[email protected]> Cc: Kan Liang <[email protected]> Cc: Leo Yan <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mike Leach <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Ravi Bangoria <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: Will Deacon <[email protected]> Cc: Xing Zhengjun <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 2519db2 commit eeac773

File tree

9 files changed

+101
-120
lines changed

9 files changed

+101
-120
lines changed

tools/perf/arch/arm64/util/pmu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "../../../util/cpumap.h"
44
#include "../../../util/pmu.h"
55

6-
const struct pmu_events_map *pmu_events_map__find(void)
6+
const struct pmu_event *pmu_events_table__find(void)
77
{
88
struct perf_pmu *pmu = NULL;
99

@@ -18,7 +18,7 @@ const struct pmu_events_map *pmu_events_map__find(void)
1818
if (pmu->cpus->nr != cpu__max_cpu().cpu)
1919
return NULL;
2020

21-
return perf_pmu__find_map(pmu);
21+
return perf_pmu__find_table(pmu);
2222
}
2323

2424
return NULL;

tools/perf/tests/expand-cgroup.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,12 @@ static int expand_metric_events(void)
195195
.metric_name = NULL,
196196
},
197197
};
198-
const struct pmu_events_map ev_map = {
199-
.cpuid = "test",
200-
.table = pme_test,
201-
};
202198

203199
evlist = evlist__new();
204200
TEST_ASSERT_VAL("failed to get evlist", evlist);
205201

206202
rblist__init(&metric_events);
207-
ret = metricgroup__parse_groups_test(evlist, &ev_map, metric_str,
203+
ret = metricgroup__parse_groups_test(evlist, pme_test, metric_str,
208204
false, false, &metric_events);
209205
if (ret < 0) {
210206
pr_debug("failed to parse '%s' metric\n", metric_str);

tools/perf/tests/parse-metric.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,6 @@ static struct pmu_event pme_test[] = {
7979
}
8080
};
8181

82-
static const struct pmu_events_map map = {
83-
.cpuid = "test",
84-
.table = pme_test,
85-
};
86-
8782
struct value {
8883
const char *event;
8984
u64 val;
@@ -166,7 +161,7 @@ static int __compute_metric(const char *name, struct value *vals,
166161
runtime_stat__init(&st);
167162

168163
/* Parse the metric into metric_events list. */
169-
err = metricgroup__parse_groups_test(evlist, &map, name,
164+
err = metricgroup__parse_groups_test(evlist, pme_test, name,
170165
false, false,
171166
&metric_events);
172167
if (err)

tools/perf/tests/pmu-events.c

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,11 @@ static bool is_same(const char *reference, const char *test)
272272
return !strcmp(reference, test);
273273
}
274274

275-
static const struct pmu_events_map *__test_pmu_get_events_map(void)
275+
static const struct pmu_event *__test_pmu_get_events_table(void)
276276
{
277-
const struct pmu_events_map *map;
278-
279-
for (map = &pmu_events_map[0]; map->cpuid; map++) {
277+
for (const struct pmu_events_map *map = &pmu_events_map[0]; map->cpuid; map++) {
280278
if (!strcmp(map->cpuid, "testcpu"))
281-
return map;
279+
return map->table;
282280
}
283281

284282
pr_err("could not find test events map\n");
@@ -440,19 +438,18 @@ static int test__pmu_event_table(struct test_suite *test __maybe_unused,
440438
int subtest __maybe_unused)
441439
{
442440
const struct pmu_event *sys_event_tables = find_sys_events_table("pme_test_soc_sys");
443-
const struct pmu_events_map *map = __test_pmu_get_events_map();
444-
const struct pmu_event *table;
441+
const struct pmu_event *table = __test_pmu_get_events_table();
445442
int map_events = 0, expected_events;
446443

447444
/* ignore 3x sentinels */
448445
expected_events = ARRAY_SIZE(core_events) +
449446
ARRAY_SIZE(uncore_events) +
450447
ARRAY_SIZE(sys_events) - 3;
451448

452-
if (!map || !sys_event_tables)
449+
if (!table || !sys_event_tables)
453450
return -1;
454451

455-
for (table = map->table; table->name; table++) {
452+
for (; table->name; table++) {
456453
struct perf_pmu_test_event const **test_event_table;
457454
bool found = false;
458455

@@ -537,10 +534,10 @@ static int __test_core_pmu_event_aliases(char *pmu_name, int *count)
537534
struct perf_pmu *pmu;
538535
LIST_HEAD(aliases);
539536
int res = 0;
540-
const struct pmu_events_map *map = __test_pmu_get_events_map();
537+
const struct pmu_event *table = __test_pmu_get_events_table();
541538
struct perf_pmu_alias *a, *tmp;
542539

543-
if (!map)
540+
if (!table)
544541
return -1;
545542

546543
test_event_table = &core_events[0];
@@ -551,7 +548,7 @@ static int __test_core_pmu_event_aliases(char *pmu_name, int *count)
551548

552549
pmu->name = pmu_name;
553550

554-
pmu_add_cpu_aliases_map(&aliases, pmu, map);
551+
pmu_add_cpu_aliases_table(&aliases, pmu, table);
555552

556553
for (; *test_event_table; test_event_table++) {
557554
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)
590587
struct perf_pmu *pmu = &test_pmu->pmu;
591588
const char *pmu_name = pmu->name;
592589
struct perf_pmu_alias *a, *tmp, *alias;
593-
const struct pmu_events_map *map;
590+
const struct pmu_event *events_table;
594591
LIST_HEAD(aliases);
595592
int res = 0;
596593

597-
map = __test_pmu_get_events_map();
598-
if (!map)
594+
events_table = __test_pmu_get_events_table();
595+
if (!events_table)
599596
return -1;
600-
pmu_add_cpu_aliases_map(&aliases, pmu, map);
597+
pmu_add_cpu_aliases_table(&aliases, pmu, events_table);
601598
pmu_add_sys_aliases(&aliases, pmu);
602599

603600
/* Count how many aliases we generated */
@@ -848,13 +845,9 @@ static int check_parse_fake(const char *id)
848845
return ret;
849846
}
850847

851-
static void expr_failure(const char *msg,
852-
const struct pmu_events_map *map,
853-
const struct pmu_event *pe)
848+
static void expr_failure(const char *msg, const struct pmu_event *pe)
854849
{
855-
pr_debug("%s for map %s %s\n", msg, map->arch, map->cpuid);
856-
pr_debug("On metric %s\n", pe->metric_name);
857-
pr_debug("On expression %s\n", pe->metric_expr);
850+
pr_debug("%s\nOn metric %s\nOn expression %s\n", msg, pe->metric_name, pe->metric_expr);
858851
}
859852

860853
struct metric {
@@ -864,7 +857,7 @@ struct metric {
864857

865858
static int resolve_metric_simple(struct expr_parse_ctx *pctx,
866859
struct list_head *compound_list,
867-
const struct pmu_events_map *map,
860+
const struct pmu_event *map,
868861
const char *metric_name)
869862
{
870863
struct hashmap_entry *cur, *cur_tmp;
@@ -925,8 +918,7 @@ static int resolve_metric_simple(struct expr_parse_ctx *pctx,
925918
static int test__parsing(struct test_suite *test __maybe_unused,
926919
int subtest __maybe_unused)
927920
{
928-
const struct pmu_events_map *cpus_map = pmu_events_map__find();
929-
const struct pmu_events_map *map;
921+
const struct pmu_event *cpus_table = pmu_events_table__find();
930922
const struct pmu_event *pe;
931923
int i, j, k;
932924
int ret = 0;
@@ -940,7 +932,8 @@ static int test__parsing(struct test_suite *test __maybe_unused,
940932
}
941933
i = 0;
942934
for (;;) {
943-
map = &pmu_events_map[i++];
935+
const struct pmu_events_map *map = &pmu_events_map[i++];
936+
944937
if (!map->table)
945938
break;
946939
j = 0;
@@ -957,14 +950,14 @@ static int test__parsing(struct test_suite *test __maybe_unused,
957950
continue;
958951
expr__ctx_clear(ctx);
959952
if (expr__find_ids(pe->metric_expr, NULL, ctx) < 0) {
960-
expr_failure("Parse find ids failed", map, pe);
953+
expr_failure("Parse find ids failed", pe);
961954
ret++;
962955
continue;
963956
}
964957

965-
if (resolve_metric_simple(ctx, &compound_list, map,
958+
if (resolve_metric_simple(ctx, &compound_list, map->table,
966959
pe->metric_name)) {
967-
expr_failure("Could not resolve metrics", map, pe);
960+
expr_failure("Could not resolve metrics", pe);
968961
ret++;
969962
goto exit; /* Don't tolerate errors due to severity */
970963
}
@@ -979,7 +972,7 @@ static int test__parsing(struct test_suite *test __maybe_unused,
979972
expr__add_id_val(ctx, strdup(cur->key), k++);
980973

981974
hashmap__for_each_entry(ctx->ids, cur, bkt) {
982-
if (check_parse_cpu(cur->key, map == cpus_map,
975+
if (check_parse_cpu(cur->key, map->table == cpus_table,
983976
pe))
984977
ret++;
985978
}
@@ -999,7 +992,7 @@ static int test__parsing(struct test_suite *test __maybe_unused,
999992
hashmap__for_each_entry(ctx->ids, cur, bkt)
1000993
expr__add_id_val(ctx, strdup(cur->key), k--);
1001994
if (expr__parse(&result, ctx, pe->metric_expr)) {
1002-
expr_failure("Parse failed", map, pe);
995+
expr_failure("Parse failed", pe);
1003996
ret++;
1004997
}
1005998
}
@@ -1088,8 +1081,6 @@ static int metric_parse_fake(const char *str)
10881081
static int test__parsing_fake(struct test_suite *test __maybe_unused,
10891082
int subtest __maybe_unused)
10901083
{
1091-
const struct pmu_events_map *map;
1092-
const struct pmu_event *pe;
10931084
unsigned int i, j;
10941085
int err = 0;
10951086

@@ -1101,12 +1092,14 @@ static int test__parsing_fake(struct test_suite *test __maybe_unused,
11011092

11021093
i = 0;
11031094
for (;;) {
1104-
map = &pmu_events_map[i++];
1095+
const struct pmu_events_map *map = &pmu_events_map[i++];
1096+
11051097
if (!map->table)
11061098
break;
11071099
j = 0;
11081100
for (;;) {
1109-
pe = &map->table[j++];
1101+
const struct pmu_event *pe = &map->table[j++];
1102+
11101103
if (!pe->name && !pe->metric_group && !pe->metric_name)
11111104
break;
11121105
if (!pe->metric_expr)

0 commit comments

Comments
 (0)