Skip to content

Commit 2519db2

Browse files
captain5050acmel
authored andcommitted
perf pmu-events: Hide pmu_sys_event_tables
Move usage of the table to pmu-events.c so it may be hidden. By abstracting the table the implementation can later be changed. 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 7b2f844 commit 2519db2

File tree

6 files changed

+84
-52
lines changed

6 files changed

+84
-52
lines changed

tools/perf/pmu-events/empty-pmu-events.c

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* The test cpu/soc is provided for testing.
77
*/
88
#include "pmu-events/pmu-events.h"
9+
#include <string.h>
10+
#include <stddef.h>
911

1012
static const struct pmu_event pme_test_soc_cpu[] = {
1113
{
@@ -145,7 +147,12 @@ static const struct pmu_event pme_test_soc_sys[] = {
145147
},
146148
};
147149

148-
const struct pmu_sys_events pmu_sys_event_tables[] = {
150+
struct pmu_sys_events {
151+
const char *name;
152+
const struct pmu_event *table;
153+
};
154+
155+
static const struct pmu_sys_events pmu_sys_event_tables[] = {
149156
{
150157
.table = pme_test_soc_sys,
151158
.name = "pme_test_soc_sys",
@@ -154,3 +161,31 @@ const struct pmu_sys_events pmu_sys_event_tables[] = {
154161
.table = 0
155162
},
156163
};
164+
165+
const struct pmu_event *find_sys_events_table(const char *name)
166+
{
167+
for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0];
168+
tables->name;
169+
tables++) {
170+
if (!strcmp(tables->name, name))
171+
return tables->table;
172+
}
173+
return NULL;
174+
}
175+
176+
int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data)
177+
{
178+
for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0];
179+
tables->name;
180+
tables++) {
181+
for (const struct pmu_event *pe = &tables->table[0];
182+
pe->name || pe->metric_group || pe->metric_name;
183+
pe++) {
184+
int ret = fn(pe, data);
185+
186+
if (ret)
187+
return ret;
188+
}
189+
}
190+
return 0;
191+
}

tools/perf/pmu-events/jevents.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,14 @@ def print_mapping_table(archs: Sequence[str]) -> None:
371371

372372
def print_system_mapping_table() -> None:
373373
"""C struct mapping table array for tables from /sys directories."""
374-
_args.output_file.write(
375-
'\nconst struct pmu_sys_events pmu_sys_event_tables[] = {\n')
374+
_args.output_file.write("""
375+
struct pmu_sys_events {
376+
\tconst char *name;
377+
\tconst struct pmu_event *table;
378+
};
379+
380+
static const struct pmu_sys_events pmu_sys_event_tables[] = {
381+
""")
376382
for tblname in _sys_event_tables:
377383
_args.output_file.write(f"""\t{{
378384
\t\t.table = {tblname},
@@ -383,6 +389,34 @@ def print_system_mapping_table() -> None:
383389
\t\t.table = 0
384390
\t},
385391
};
392+
393+
const struct pmu_event *find_sys_events_table(const char *name)
394+
{
395+
for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0];
396+
tables->name;
397+
tables++) {
398+
if (!strcmp(tables->name, name))
399+
return tables->table;
400+
}
401+
return NULL;
402+
}
403+
404+
int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data)
405+
{
406+
for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0];
407+
tables->name;
408+
tables++) {
409+
for (const struct pmu_event *pe = &tables->table[0];
410+
pe->name || pe->metric_group || pe->metric_name;
411+
pe++) {
412+
int ret = fn(pe, data);
413+
414+
if (ret)
415+
return ret;
416+
}
417+
}
418+
return 0;
419+
}
386420
""")
387421

388422

@@ -414,7 +448,12 @@ def ftw(path: str, parents: Sequence[str],
414448
'output_file', type=argparse.FileType('w'), nargs='?', default=sys.stdout)
415449
_args = ap.parse_args()
416450

417-
_args.output_file.write("#include \"pmu-events/pmu-events.h\"\n")
451+
_args.output_file.write("""
452+
#include "pmu-events/pmu-events.h"
453+
#include <string.h>
454+
#include <stddef.h>
455+
456+
""")
418457
archs = []
419458
for item in os.scandir(_args.starting_dir):
420459
if not item.is_dir():

tools/perf/pmu-events/pmu-events.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,15 @@ struct pmu_events_map {
4343
const struct pmu_event *table;
4444
};
4545

46-
struct pmu_sys_events {
47-
const char *name;
48-
const struct pmu_event *table;
49-
};
50-
5146
/*
5247
* Global table mapping each known CPU for the architecture to its
5348
* table of PMU events.
5449
*/
5550
extern const struct pmu_events_map pmu_events_map[];
56-
extern const struct pmu_sys_events pmu_sys_event_tables[];
51+
52+
const struct pmu_event *find_sys_events_table(const char *name);
53+
54+
typedef int (*pmu_event_iter_fn)(const struct pmu_event *pe, void *data);
55+
int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data);
5756

5857
#endif

tools/perf/tests/pmu-events.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -286,18 +286,6 @@ static const struct pmu_events_map *__test_pmu_get_events_map(void)
286286
return NULL;
287287
}
288288

289-
static const struct pmu_event *__test_pmu_get_sys_events_table(void)
290-
{
291-
const struct pmu_sys_events *tables = &pmu_sys_event_tables[0];
292-
293-
for ( ; tables->name; tables++) {
294-
if (!strcmp("pme_test_soc_sys", tables->name))
295-
return tables->table;
296-
}
297-
298-
return NULL;
299-
}
300-
301289
static int compare_pmu_events(const struct pmu_event *e1, const struct pmu_event *e2)
302290
{
303291
if (!is_same(e1->name, e2->name)) {
@@ -451,7 +439,7 @@ static int compare_alias_to_test_event(struct perf_pmu_alias *alias,
451439
static int test__pmu_event_table(struct test_suite *test __maybe_unused,
452440
int subtest __maybe_unused)
453441
{
454-
const struct pmu_event *sys_event_tables = __test_pmu_get_sys_events_table();
442+
const struct pmu_event *sys_event_tables = find_sys_events_table("pme_test_soc_sys");
455443
const struct pmu_events_map *map = __test_pmu_get_events_map();
456444
const struct pmu_event *table;
457445
int map_events = 0, expected_events;

tools/perf/util/pmu.c

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -868,33 +868,6 @@ static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu)
868868
pmu_add_cpu_aliases_map(head, pmu, map);
869869
}
870870

871-
void pmu_for_each_sys_event(pmu_sys_event_iter_fn fn, void *data)
872-
{
873-
int i = 0;
874-
875-
while (1) {
876-
const struct pmu_sys_events *event_table;
877-
int j = 0;
878-
879-
event_table = &pmu_sys_event_tables[i++];
880-
881-
if (!event_table->table)
882-
break;
883-
884-
while (1) {
885-
const struct pmu_event *pe = &event_table->table[j++];
886-
int ret;
887-
888-
if (!pe->name && !pe->metric_group && !pe->metric_name)
889-
break;
890-
891-
ret = fn(pe, data);
892-
if (ret)
893-
break;
894-
}
895-
}
896-
}
897-
898871
struct pmu_sys_event_iter_data {
899872
struct list_head *head;
900873
struct perf_pmu *pmu;

tools/perf/util/pmu.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ const struct pmu_events_map *pmu_events_map__find(void);
133133
bool pmu_uncore_alias_match(const char *pmu_name, const char *name);
134134
void perf_pmu_free_alias(struct perf_pmu_alias *alias);
135135

136-
typedef int (*pmu_sys_event_iter_fn)(const struct pmu_event *pe, void *data);
137-
void pmu_for_each_sys_event(pmu_sys_event_iter_fn fn, void *data);
138136
int perf_pmu__convert_scale(const char *scale, char **end, double *sval);
139137

140138
int perf_pmu__caps_parse(struct perf_pmu *pmu);

0 commit comments

Comments
 (0)