mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-07-22 02:17:36 -04:00
perf pmu-events: Add API to get metric table name and iterate tables
Add name field to struct pmu_metrics_table and populate it in generated tables. Add pmu_metrics_table__name() to retrieve the name. Add pmu_metrics_table__for_each_table() to iterate over all known metric tables. This will be used to break apart slow metric tests per table. Assisted-by: Gemini-CLI:Google Gemini 3 Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@linaro.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
committed by
Arnaldo Carvalho de Melo
parent
2c43c0c786
commit
53247b207b
@@ -5403,6 +5403,7 @@ struct pmu_events_table {
|
||||
|
||||
/* Struct used to make the PMU metric table implementation opaque to callers. */
|
||||
struct pmu_metrics_table {
|
||||
const char *name;
|
||||
const struct pmu_table_entry *pmus;
|
||||
uint32_t num_pmus;
|
||||
};
|
||||
@@ -5435,6 +5436,7 @@ static const struct pmu_events_map pmu_events_map[] = {
|
||||
.num_pmus = ARRAY_SIZE(pmu_events__common),
|
||||
},
|
||||
.metric_table = {
|
||||
.name = "common",
|
||||
.pmus = pmu_metrics__common,
|
||||
.num_pmus = ARRAY_SIZE(pmu_metrics__common),
|
||||
},
|
||||
@@ -5447,6 +5449,7 @@ static const struct pmu_events_map pmu_events_map[] = {
|
||||
.num_pmus = ARRAY_SIZE(pmu_events__test_soc_cpu),
|
||||
},
|
||||
.metric_table = {
|
||||
.name = "test_soc_cpu",
|
||||
.pmus = pmu_metrics__test_soc_cpu,
|
||||
.num_pmus = ARRAY_SIZE(pmu_metrics__test_soc_cpu),
|
||||
}
|
||||
@@ -5455,7 +5458,7 @@ static const struct pmu_events_map pmu_events_map[] = {
|
||||
.arch = 0,
|
||||
.cpuid = 0,
|
||||
.event_table = { 0, 0 },
|
||||
.metric_table = { 0, 0 },
|
||||
.metric_table = { 0 },
|
||||
}
|
||||
};
|
||||
|
||||
@@ -5475,7 +5478,7 @@ static const struct pmu_sys_events pmu_sys_event_tables[] = {
|
||||
},
|
||||
{
|
||||
.event_table = { 0, 0 },
|
||||
.metric_table = { 0, 0 },
|
||||
.metric_table = { 0 },
|
||||
},
|
||||
};
|
||||
|
||||
@@ -5990,6 +5993,45 @@ int pmu_for_each_sys_metric(pmu_metric_iter_fn fn, void *data)
|
||||
}
|
||||
/* clang-format on */
|
||||
|
||||
const char *pmu_metrics_table__name(const struct pmu_metrics_table *table)
|
||||
{
|
||||
return table ? table->name : NULL;
|
||||
}
|
||||
|
||||
int pmu_metrics_table__iterate_tables(pmu_metrics_table_iter_t fn, void *data)
|
||||
{
|
||||
size_t i;
|
||||
int ret;
|
||||
|
||||
for (i = 0; pmu_events_map[i].cpuid; i++) {
|
||||
size_t j;
|
||||
bool found = false;
|
||||
|
||||
if (!pmu_events_map[i].metric_table.pmus)
|
||||
continue;
|
||||
for (j = 0; j < i; j++) {
|
||||
if (pmu_events_map[j].metric_table.pmus ==
|
||||
pmu_events_map[i].metric_table.pmus) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found)
|
||||
continue;
|
||||
ret = fn(&pmu_events_map[i].metric_table, data);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
for (i = 0; pmu_sys_event_tables[i].name; i++) {
|
||||
if (!pmu_sys_event_tables[i].metric_table.pmus)
|
||||
continue;
|
||||
ret = fn(&pmu_sys_event_tables[i].metric_table, data);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const int metricgroups[][2] = {
|
||||
|
||||
};
|
||||
|
||||
@@ -712,6 +712,7 @@ struct pmu_events_table {
|
||||
|
||||
/* Struct used to make the PMU metric table implementation opaque to callers. */
|
||||
struct pmu_metrics_table {
|
||||
\tconst char *name;
|
||||
\tconst struct pmu_table_entry *pmus;
|
||||
\tuint32_t num_pmus;
|
||||
};
|
||||
@@ -747,6 +748,7 @@ static const struct pmu_events_map pmu_events_map[] = {
|
||||
\t\t.num_pmus = ARRAY_SIZE(pmu_events__test_soc_cpu),
|
||||
\t},
|
||||
\t.metric_table = {
|
||||
\t\t.name = "test_soc_cpu",
|
||||
\t\t.pmus = pmu_metrics__test_soc_cpu,
|
||||
\t\t.num_pmus = ARRAY_SIZE(pmu_metrics__test_soc_cpu),
|
||||
\t}
|
||||
@@ -761,6 +763,7 @@ static const struct pmu_events_map pmu_events_map[] = {
|
||||
\t\t.num_pmus = ARRAY_SIZE(pmu_events__common),
|
||||
\t},
|
||||
\t.metric_table = {
|
||||
\t\t.name = "common",
|
||||
\t\t.pmus = pmu_metrics__common,
|
||||
\t\t.num_pmus = ARRAY_SIZE(pmu_metrics__common),
|
||||
\t},
|
||||
@@ -781,8 +784,10 @@ static const struct pmu_events_map pmu_events_map[] = {
|
||||
event_size = '0'
|
||||
metric_tblname = file_name_to_table_name('pmu_metrics_', [], row[2].replace('/', '_'))
|
||||
if metric_tblname in _metric_tables:
|
||||
metric_name = f'"{metric_tblname.replace("pmu_metrics__", "")}"'
|
||||
metric_size = f'ARRAY_SIZE({metric_tblname})'
|
||||
else:
|
||||
metric_name = 'NULL'
|
||||
metric_tblname = 'NULL'
|
||||
metric_size = '0'
|
||||
if event_size == '0' and metric_size == '0':
|
||||
@@ -796,6 +801,7 @@ static const struct pmu_events_map pmu_events_map[] = {
|
||||
\t\t.num_pmus = {event_size}
|
||||
\t}},
|
||||
\t.metric_table = {{
|
||||
\t\t.name = {metric_name},
|
||||
\t\t.pmus = {metric_tblname},
|
||||
\t\t.num_pmus = {metric_size}
|
||||
\t}}
|
||||
@@ -807,12 +813,55 @@ static const struct pmu_events_map pmu_events_map[] = {
|
||||
\t.arch = 0,
|
||||
\t.cpuid = 0,
|
||||
\t.event_table = { 0, 0 },
|
||||
\t.metric_table = { 0, 0 },
|
||||
\t.metric_table = { 0 },
|
||||
}
|
||||
};
|
||||
""")
|
||||
|
||||
|
||||
def print_metric_table_functions() -> None:
|
||||
_args.output_file.write("""
|
||||
const char *pmu_metrics_table__name(const struct pmu_metrics_table *table)
|
||||
{
|
||||
\treturn table ? table->name : NULL;
|
||||
}
|
||||
|
||||
int pmu_metrics_table__iterate_tables(pmu_metrics_table_iter_t fn, void *data)
|
||||
{
|
||||
\tsize_t i;
|
||||
\tint ret;
|
||||
|
||||
\tfor (i = 0; pmu_events_map[i].cpuid; i++) {
|
||||
\t\tsize_t j;
|
||||
\t\tbool found = false;
|
||||
|
||||
\t\tif (!pmu_events_map[i].metric_table.pmus)
|
||||
\t\t\tcontinue;
|
||||
\t\tfor (j = 0; j < i; j++) {
|
||||
\t\t\tif (pmu_events_map[j].metric_table.pmus ==
|
||||
\t\t\t pmu_events_map[i].metric_table.pmus) {
|
||||
\t\t\t\tfound = true;
|
||||
\t\t\t\tbreak;
|
||||
\t\t\t}
|
||||
\t\t}
|
||||
\t\tif (found)
|
||||
\t\t\tcontinue;
|
||||
\t\tret = fn(&pmu_events_map[i].metric_table, data);
|
||||
\t\tif (ret)
|
||||
\t\t\treturn ret;
|
||||
\t}
|
||||
\tfor (i = 0; pmu_sys_event_tables[i].name; i++) {
|
||||
\t\tif (!pmu_sys_event_tables[i].metric_table.pmus)
|
||||
\t\t\tcontinue;
|
||||
\t\tret = fn(&pmu_sys_event_tables[i].metric_table, data);
|
||||
\t\tif (ret)
|
||||
\t\t\treturn ret;
|
||||
\t}
|
||||
\treturn 0;
|
||||
}
|
||||
""")
|
||||
|
||||
|
||||
def print_system_mapping_table() -> None:
|
||||
"""C struct mapping table array for tables from /sys directories."""
|
||||
_args.output_file.write("""
|
||||
@@ -835,6 +884,7 @@ static const struct pmu_sys_events pmu_sys_event_tables[] = {
|
||||
if metric_tblname in _sys_metric_tables:
|
||||
_args.output_file.write(f"""
|
||||
\t\t.metric_table = {{
|
||||
\t\t\t.name = "{metric_tblname.replace('pmu_metrics__', '')}",
|
||||
\t\t\t.pmus = {metric_tblname},
|
||||
\t\t\t.num_pmus = ARRAY_SIZE({metric_tblname})
|
||||
\t\t}},""")
|
||||
@@ -848,6 +898,7 @@ static const struct pmu_sys_events pmu_sys_event_tables[] = {
|
||||
continue
|
||||
_args.output_file.write(f"""\t{{
|
||||
\t\t.metric_table = {{
|
||||
\t\t\t.name = "{tblname.replace('pmu_metrics__', '')}",
|
||||
\t\t\t.pmus = {tblname},
|
||||
\t\t\t.num_pmus = ARRAY_SIZE({tblname})
|
||||
\t\t}},
|
||||
@@ -856,7 +907,7 @@ static const struct pmu_sys_events pmu_sys_event_tables[] = {
|
||||
""")
|
||||
_args.output_file.write("""\t{
|
||||
\t\t.event_table = { 0, 0 },
|
||||
\t\t.metric_table = { 0, 0 },
|
||||
\t\t.metric_table = { 0 },
|
||||
\t},
|
||||
};
|
||||
|
||||
@@ -1486,6 +1537,7 @@ struct pmu_table_entry {
|
||||
print_mapping_table(archs)
|
||||
print_system_mapping_table()
|
||||
_args.output_file.write('/* clang-format on */\n')
|
||||
print_metric_table_functions()
|
||||
print_metricgroups()
|
||||
_args.output_file.close()
|
||||
if _args.output_string_file:
|
||||
|
||||
@@ -91,6 +91,9 @@ typedef int (*pmu_metric_iter_fn)(const struct pmu_metric *pm,
|
||||
const struct pmu_metrics_table *table,
|
||||
void *data);
|
||||
|
||||
typedef int (*pmu_metrics_table_iter_t)(const struct pmu_metrics_table *table,
|
||||
void *data);
|
||||
|
||||
int pmu_events_table__for_each_event(const struct pmu_events_table *table,
|
||||
struct perf_pmu *pmu,
|
||||
pmu_event_iter_fn fn,
|
||||
@@ -112,6 +115,8 @@ size_t pmu_events_table__num_events(const struct pmu_events_table *table,
|
||||
|
||||
int pmu_metrics_table__for_each_metric(const struct pmu_metrics_table *table, pmu_metric_iter_fn fn,
|
||||
void *data);
|
||||
const char *pmu_metrics_table__name(const struct pmu_metrics_table *table);
|
||||
int pmu_metrics_table__iterate_tables(pmu_metrics_table_iter_t fn, void *data);
|
||||
/*
|
||||
* Search for a table and entry matching with pmu__name_wildcard_match or any
|
||||
* tables if pmu is NULL. Each matching metric has fn called on it. 0 implies to
|
||||
|
||||
Reference in New Issue
Block a user