Skip to content

Commit 099b157

Browse files
captain5050acmel
authored andcommitted
perf jevent: Add an 'all' architecture argument
When 'all' is passed as the architecture generate a mapping table for all architectures. This simplifies testing. To identify the table for an architecture add an arch variable to the pmu_events_map. 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 8d33834 commit 099b157

File tree

4 files changed

+47
-29
lines changed

4 files changed

+47
-29
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,14 @@ static const struct pmu_event pme_test_soc_cpu[] = {
110110

111111
const struct pmu_events_map pmu_events_map[] = {
112112
{
113+
.arch = "testarch",
113114
.cpuid = "testcpu",
114115
.version = "v1",
115116
.type = "core",
116117
.table = pme_test_soc_cpu,
117118
},
118119
{
120+
.arch = 0,
119121
.cpuid = 0,
120122
.version = 0,
121123
.type = 0,

tools/perf/pmu-events/jevents.py

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -305,38 +305,45 @@ def is_leaf_dir(path: str) -> bool:
305305
print_events_table_entries(item, get_topic(item.name))
306306

307307

308-
def print_mapping_table() -> None:
308+
def print_mapping_table(archs: Sequence[str]) -> None:
309309
"""Read the mapfile and generate the struct from cpuid string to event table."""
310-
with open(f'{_args.starting_dir}/{_args.arch}/mapfile.csv') as csvfile:
311-
table = csv.reader(csvfile)
312-
_args.output_file.write(
313-
'const struct pmu_events_map pmu_events_map[] = {\n')
314-
first = True
315-
for row in table:
316-
# Skip the first row or any row beginning with #.
317-
if not first and len(row) > 0 and not row[0].startswith('#'):
318-
tblname = file_name_to_table_name([], row[2].replace('/', '_'))
319-
_args.output_file.write("""{
320-
\t.cpuid = \"%s\",
321-
\t.version = \"%s\",
322-
\t.type = \"%s\",
323-
\t.table = %s
324-
},
325-
""" % (row[0].replace('\\', '\\\\'), row[1], row[3], tblname))
326-
first = False
327-
328-
_args.output_file.write("""{
310+
_args.output_file.write('const struct pmu_events_map pmu_events_map[] = {\n')
311+
for arch in archs:
312+
if arch == 'test':
313+
_args.output_file.write("""{
314+
\t.arch = "testarch",
329315
\t.cpuid = "testcpu",
330316
\t.version = "v1",
331317
\t.type = "core",
332318
\t.table = pme_test_soc_cpu,
333319
},
334-
{
320+
""")
321+
else:
322+
with open(f'{_args.starting_dir}/{arch}/mapfile.csv') as csvfile:
323+
table = csv.reader(csvfile)
324+
first = True
325+
for row in table:
326+
# Skip the first row or any row beginning with #.
327+
if not first and len(row) > 0 and not row[0].startswith('#'):
328+
tblname = file_name_to_table_name([], row[2].replace('/', '_'))
329+
cpuid = row[0].replace('\\', '\\\\')
330+
_args.output_file.write(f"""{{
331+
\t.arch = "{arch}",
332+
\t.cpuid = "{cpuid}",
333+
\t.version = "{row[1]}",
334+
\t.type = "{row[3]}",
335+
\t.table = {tblname}
336+
}},
337+
""")
338+
first = False
339+
340+
_args.output_file.write("""{
341+
\t.arch = 0,
335342
\t.cpuid = 0,
336343
\t.version = 0,
337344
\t.type = 0,
338345
\t.table = 0,
339-
},
346+
}
340347
};
341348
""")
342349

@@ -387,15 +394,24 @@ def ftw(path: str, parents: Sequence[str],
387394
_args = ap.parse_args()
388395

389396
_args.output_file.write("#include \"pmu-events/pmu-events.h\"\n")
390-
for path in [_args.arch, 'test']:
391-
arch_path = f'{_args.starting_dir}/{path}'
392-
if not os.path.isdir(arch_path):
393-
raise IOError(f'Missing architecture directory in \'{arch_path}\'')
397+
archs = []
398+
for item in os.scandir(_args.starting_dir):
399+
if not item.is_dir():
400+
continue
401+
if item.name == _args.arch or _args.arch == 'all' or item.name == 'test':
402+
archs.append(item.name)
403+
404+
if len(archs) < 2:
405+
raise IOError(f'Missing architecture directory \'{_args.arch}\'')
406+
407+
archs.sort()
408+
for arch in archs:
409+
arch_path = f'{_args.starting_dir}/{arch}'
394410
preprocess_arch_std_files(arch_path)
395411
ftw(arch_path, [], process_one_file)
396412
print_events_table_suffix()
397413

398-
print_mapping_table()
414+
print_mapping_table(archs)
399415
print_system_mapping_table()
400416

401417

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct pmu_event {
3838
* The cpuid can contain any character other than the comma.
3939
*/
4040
struct pmu_events_map {
41+
const char *arch;
4142
const char *cpuid;
4243
const char *version;
4344
const char *type; /* core, uncore etc */

tools/perf/tests/pmu-events.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -864,8 +864,7 @@ static void expr_failure(const char *msg,
864864
const struct pmu_events_map *map,
865865
const struct pmu_event *pe)
866866
{
867-
pr_debug("%s for map %s %s %s\n",
868-
msg, map->cpuid, map->version, map->type);
867+
pr_debug("%s for map %s %s\n", msg, map->arch, map->cpuid);
869868
pr_debug("On metric %s\n", pe->metric_name);
870869
pr_debug("On expression %s\n", pe->metric_expr);
871870
}

0 commit comments

Comments
 (0)