mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 09:36:22 +02:00
perf jevents.py: Make generated C code more kernel style
Make jevents.py generate C code that complies with formatting tools: - Add /* clang-format off */ before big_c_string and re-enable it after system mapping tables, bypassing large generated tables while checking functions and early structs. - Make comments more human readable and avoid going over 100 character line length. - Fix spaces indentation to tabs in struct/array initializers. - Fix other checkpatch detected related issues. 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:
parent
bded0398ac
commit
2c43c0c786
File diff suppressed because it is too large
Load Diff
|
|
@ -183,7 +183,7 @@ class BigCString:
|
|||
for s in sorted(self.strings, key=string_cmp_key):
|
||||
if s not in folded_strings:
|
||||
self.offsets[s] = big_string_offset
|
||||
self.big_string.append(f'/* offset={big_string_offset} */ "')
|
||||
self.big_string.append(f'/* offset={big_string_offset} */\n"')
|
||||
self.big_string.append(s)
|
||||
self.big_string.append('"')
|
||||
if s in fold_into_strings:
|
||||
|
|
@ -450,11 +450,12 @@ class JsonEvent:
|
|||
def to_c_string(self, metric: bool) -> str:
|
||||
"""Representation of the event as a C struct initializer."""
|
||||
|
||||
def fix_comment(s: str) -> str:
|
||||
return s.replace('*/', r'\*\/')
|
||||
def make_comment(s: str) -> str:
|
||||
s = s.replace('*/', r'\*\/')
|
||||
return f'\t/* {s} */\n' if len(s) < 80 else f'\t/* {s[0:80]}... */\n'
|
||||
|
||||
s = self.build_c_string(metric)
|
||||
return f'{{ { _bcs.offsets[s] } }}, /* {fix_comment(s)} */\n'
|
||||
return f'{make_comment(s)}\t{{ { _bcs.offsets[s] } }},\n'
|
||||
|
||||
|
||||
@lru_cache(maxsize=None)
|
||||
|
|
@ -558,11 +559,11 @@ static const struct pmu_table_entry {_pending_events_tblname}[] = {{
|
|||
""")
|
||||
for (pmu, tbl_pmu) in sorted(pmus):
|
||||
pmu_name = f"{pmu}\\000"
|
||||
_args.output_file.write(f"""{{
|
||||
.entries = {_pending_events_tblname}_{tbl_pmu},
|
||||
.num_entries = ARRAY_SIZE({_pending_events_tblname}_{tbl_pmu}),
|
||||
.pmu_name = {{ {_bcs.offsets[pmu_name]} /* {pmu_name} */ }},
|
||||
}},
|
||||
_args.output_file.write(f"""\t{{
|
||||
\t\t.entries = {_pending_events_tblname}_{tbl_pmu},
|
||||
\t\t.num_entries = ARRAY_SIZE({_pending_events_tblname}_{tbl_pmu}),
|
||||
\t\t.pmu_name = {{ {_bcs.offsets[pmu_name]} /* {pmu_name} */ }},
|
||||
\t}},
|
||||
""")
|
||||
_args.output_file.write('};\n\n')
|
||||
|
||||
|
|
@ -613,11 +614,11 @@ static const struct pmu_table_entry {_pending_metrics_tblname}[] = {{
|
|||
""")
|
||||
for (pmu, tbl_pmu) in sorted(pmus):
|
||||
pmu_name = f"{pmu}\\000"
|
||||
_args.output_file.write(f"""{{
|
||||
.entries = {_pending_metrics_tblname}_{tbl_pmu},
|
||||
.num_entries = ARRAY_SIZE({_pending_metrics_tblname}_{tbl_pmu}),
|
||||
.pmu_name = {{ {_bcs.offsets[pmu_name]} /* {pmu_name} */ }},
|
||||
}},
|
||||
_args.output_file.write(f"""\t{{
|
||||
\t\t.entries = {_pending_metrics_tblname}_{tbl_pmu},
|
||||
\t\t.num_entries = ARRAY_SIZE({_pending_metrics_tblname}_{tbl_pmu}),
|
||||
\t\t.pmu_name = {{ {_bcs.offsets[pmu_name]} /* {pmu_name} */ }},
|
||||
\t}},
|
||||
""")
|
||||
_args.output_file.write('};\n\n')
|
||||
|
||||
|
|
@ -705,14 +706,14 @@ def print_mapping_table(archs: Sequence[str]) -> None:
|
|||
_args.output_file.write("""
|
||||
/* Struct used to make the PMU event table implementation opaque to callers. */
|
||||
struct pmu_events_table {
|
||||
const struct pmu_table_entry *pmus;
|
||||
uint32_t num_pmus;
|
||||
\tconst struct pmu_table_entry *pmus;
|
||||
\tuint32_t num_pmus;
|
||||
};
|
||||
|
||||
/* Struct used to make the PMU metric table implementation opaque to callers. */
|
||||
struct pmu_metrics_table {
|
||||
const struct pmu_table_entry *pmus;
|
||||
uint32_t num_pmus;
|
||||
\tconst struct pmu_table_entry *pmus;
|
||||
\tuint32_t num_pmus;
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
@ -724,10 +725,10 @@ struct pmu_metrics_table {
|
|||
* The cpuid can contain any character other than the comma.
|
||||
*/
|
||||
struct pmu_events_map {
|
||||
const char *arch;
|
||||
const char *cpuid;
|
||||
struct pmu_events_table event_table;
|
||||
struct pmu_metrics_table metric_table;
|
||||
\tconst char *arch;
|
||||
\tconst char *cpuid;
|
||||
\tstruct pmu_events_table event_table;
|
||||
\tstruct pmu_metrics_table metric_table;
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
@ -896,455 +897,453 @@ static void decompress_metric(int offset, struct pmu_metric *pm)
|
|||
_args.output_file.write("""}
|
||||
|
||||
static int pmu_events_table__for_each_event_pmu(const struct pmu_events_table *table,
|
||||
const struct pmu_table_entry *pmu,
|
||||
pmu_event_iter_fn fn,
|
||||
void *data)
|
||||
\t\t\t\t\t\tconst struct pmu_table_entry *pmu,
|
||||
\t\t\t\t\t\tpmu_event_iter_fn fn,
|
||||
\t\t\t\t\t\tvoid *data)
|
||||
{
|
||||
int ret;
|
||||
struct pmu_event pe = {
|
||||
.pmu = &big_c_string[pmu->pmu_name.offset],
|
||||
};
|
||||
\tint ret;
|
||||
\tstruct pmu_event pe = {
|
||||
\t\t.pmu = &big_c_string[pmu->pmu_name.offset],
|
||||
\t};
|
||||
|
||||
for (uint32_t i = 0; i < pmu->num_entries; i++) {
|
||||
decompress_event(pmu->entries[i].offset, &pe);
|
||||
if (!pe.name)
|
||||
continue;
|
||||
ret = fn(&pe, table, data);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
return 0;
|
||||
\tfor (uint32_t i = 0; i < pmu->num_entries; i++) {
|
||||
\t\tdecompress_event(pmu->entries[i].offset, &pe);
|
||||
\t\tif (!pe.name)
|
||||
\t\t\tcontinue;
|
||||
\t\tret = fn(&pe, table, data);
|
||||
\t\tif (ret)
|
||||
\t\t\treturn ret;
|
||||
\t}
|
||||
\treturn 0;
|
||||
}
|
||||
|
||||
static int pmu_events_table__find_event_pmu(const struct pmu_events_table *table,
|
||||
const struct pmu_table_entry *pmu,
|
||||
const char *name,
|
||||
pmu_event_iter_fn fn,
|
||||
void *data)
|
||||
\t\t\t\t\t const struct pmu_table_entry *pmu,
|
||||
\t\t\t\t\t const char *name,
|
||||
\t\t\t\t\t pmu_event_iter_fn fn,
|
||||
\t\t\t\t\t void *data)
|
||||
{
|
||||
struct pmu_event pe = {
|
||||
.pmu = &big_c_string[pmu->pmu_name.offset],
|
||||
};
|
||||
int low = 0, high = pmu->num_entries - 1;
|
||||
\tstruct pmu_event pe = {
|
||||
\t\t.pmu = &big_c_string[pmu->pmu_name.offset],
|
||||
\t};
|
||||
\tint low = 0, high = pmu->num_entries - 1;
|
||||
|
||||
while (low <= high) {
|
||||
int cmp, mid = (low + high) / 2;
|
||||
\twhile (low <= high) {
|
||||
\t\tint cmp, mid = (low + high) / 2;
|
||||
|
||||
decompress_event(pmu->entries[mid].offset, &pe);
|
||||
\t\tdecompress_event(pmu->entries[mid].offset, &pe);
|
||||
|
||||
if (!pe.name && !name)
|
||||
goto do_call;
|
||||
\t\tif (!pe.name && !name)
|
||||
\t\t\tgoto do_call;
|
||||
|
||||
if (!pe.name && name) {
|
||||
low = mid + 1;
|
||||
continue;
|
||||
}
|
||||
if (pe.name && !name) {
|
||||
high = mid - 1;
|
||||
continue;
|
||||
}
|
||||
\t\tif (!pe.name && name) {
|
||||
\t\t\tlow = mid + 1;
|
||||
\t\t\tcontinue;
|
||||
\t\t}
|
||||
\t\tif (pe.name && !name) {
|
||||
\t\t\thigh = mid - 1;
|
||||
\t\t\tcontinue;
|
||||
\t\t}
|
||||
|
||||
cmp = strcasecmp(pe.name, name);
|
||||
if (cmp < 0) {
|
||||
low = mid + 1;
|
||||
continue;
|
||||
}
|
||||
if (cmp > 0) {
|
||||
high = mid - 1;
|
||||
continue;
|
||||
}
|
||||
\t\tcmp = strcasecmp(pe.name, name);
|
||||
\t\tif (cmp < 0) {
|
||||
\t\t\tlow = mid + 1;
|
||||
\t\t\tcontinue;
|
||||
\t\t}
|
||||
\t\tif (cmp > 0) {
|
||||
\t\t\thigh = mid - 1;
|
||||
\t\t\tcontinue;
|
||||
\t\t}
|
||||
do_call:
|
||||
return fn ? fn(&pe, table, data) : 0;
|
||||
}
|
||||
return PMU_EVENTS__NOT_FOUND;
|
||||
\t\treturn fn ? fn(&pe, table, data) : 0;
|
||||
\t}
|
||||
\treturn PMU_EVENTS__NOT_FOUND;
|
||||
}
|
||||
|
||||
int pmu_events_table__for_each_event(const struct pmu_events_table *table,
|
||||
struct perf_pmu *pmu,
|
||||
pmu_event_iter_fn fn,
|
||||
void *data)
|
||||
\t\t\t\t struct perf_pmu *pmu,
|
||||
\t\t\t\t pmu_event_iter_fn fn,
|
||||
\t\t\t\t void *data)
|
||||
{
|
||||
if (!table)
|
||||
return 0;
|
||||
for (size_t i = 0; i < table->num_pmus; i++) {
|
||||
const struct pmu_table_entry *table_pmu = &table->pmus[i];
|
||||
const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
|
||||
int ret;
|
||||
\tif (!table)
|
||||
\t\treturn 0;
|
||||
\tfor (size_t i = 0; i < table->num_pmus; i++) {
|
||||
\t\tconst struct pmu_table_entry *table_pmu = &table->pmus[i];
|
||||
\t\tconst char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
|
||||
\t\tint ret;
|
||||
|
||||
if (pmu && !perf_pmu__name_wildcard_match(pmu, pmu_name))
|
||||
continue;
|
||||
\t\tif (pmu && !perf_pmu__name_wildcard_match(pmu, pmu_name))
|
||||
\t\t\tcontinue;
|
||||
|
||||
ret = pmu_events_table__for_each_event_pmu(table, table_pmu, fn, data);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
return 0;
|
||||
\t\tret = pmu_events_table__for_each_event_pmu(table, table_pmu, fn, data);
|
||||
\t\tif (ret)
|
||||
\t\t\treturn ret;
|
||||
\t}
|
||||
\treturn 0;
|
||||
}
|
||||
|
||||
int pmu_events_table__find_event(const struct pmu_events_table *table,
|
||||
struct perf_pmu *pmu,
|
||||
const char *name,
|
||||
pmu_event_iter_fn fn,
|
||||
void *data)
|
||||
\t\t\t\t struct perf_pmu *pmu,
|
||||
\t\t\t\t const char *name,
|
||||
\t\t\t\t pmu_event_iter_fn fn,
|
||||
\t\t\t\t void *data)
|
||||
{
|
||||
if (!table)
|
||||
return PMU_EVENTS__NOT_FOUND;
|
||||
for (size_t i = 0; i < table->num_pmus; i++) {
|
||||
const struct pmu_table_entry *table_pmu = &table->pmus[i];
|
||||
const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
|
||||
int ret;
|
||||
\tif (!table)
|
||||
\t\treturn PMU_EVENTS__NOT_FOUND;
|
||||
\tfor (size_t i = 0; i < table->num_pmus; i++) {
|
||||
\t\tconst struct pmu_table_entry *table_pmu = &table->pmus[i];
|
||||
\t\tconst char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
|
||||
\t\tint ret;
|
||||
|
||||
if (pmu && !perf_pmu__name_wildcard_match(pmu, pmu_name))
|
||||
continue;
|
||||
\t\tif (pmu && !perf_pmu__name_wildcard_match(pmu, pmu_name))
|
||||
\t\t\tcontinue;
|
||||
|
||||
ret = pmu_events_table__find_event_pmu(table, table_pmu, name, fn, data);
|
||||
if (ret != PMU_EVENTS__NOT_FOUND)
|
||||
return ret;
|
||||
}
|
||||
return PMU_EVENTS__NOT_FOUND;
|
||||
\t\tret = pmu_events_table__find_event_pmu(table, table_pmu, name, fn, data);
|
||||
\t\tif (ret != PMU_EVENTS__NOT_FOUND)
|
||||
\t\t\treturn ret;
|
||||
\t}
|
||||
\treturn PMU_EVENTS__NOT_FOUND;
|
||||
}
|
||||
|
||||
size_t pmu_events_table__num_events(const struct pmu_events_table *table,
|
||||
struct perf_pmu *pmu)
|
||||
size_t pmu_events_table__num_events(const struct pmu_events_table *table, struct perf_pmu *pmu)
|
||||
{
|
||||
size_t count = 0;
|
||||
\tsize_t count = 0;
|
||||
|
||||
if (!table)
|
||||
return 0;
|
||||
for (size_t i = 0; i < table->num_pmus; i++) {
|
||||
const struct pmu_table_entry *table_pmu = &table->pmus[i];
|
||||
const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
|
||||
\tif (!table)
|
||||
\t\treturn 0;
|
||||
\tfor (size_t i = 0; i < table->num_pmus; i++) {
|
||||
\t\tconst struct pmu_table_entry *table_pmu = &table->pmus[i];
|
||||
\t\tconst char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
|
||||
|
||||
if (perf_pmu__name_wildcard_match(pmu, pmu_name))
|
||||
count += table_pmu->num_entries;
|
||||
}
|
||||
return count;
|
||||
\t\tif (perf_pmu__name_wildcard_match(pmu, pmu_name))
|
||||
\t\t\tcount += table_pmu->num_entries;
|
||||
\t}
|
||||
\treturn count;
|
||||
}
|
||||
|
||||
static int pmu_metrics_table__for_each_metric_pmu(const struct pmu_metrics_table *table,
|
||||
const struct pmu_table_entry *pmu,
|
||||
pmu_metric_iter_fn fn,
|
||||
void *data)
|
||||
\t\t\t\t\t\tconst struct pmu_table_entry *pmu,
|
||||
\t\t\t\t\t\tpmu_metric_iter_fn fn,
|
||||
\t\t\t\t\t\tvoid *data)
|
||||
{
|
||||
int ret;
|
||||
struct pmu_metric pm = {
|
||||
.pmu = &big_c_string[pmu->pmu_name.offset],
|
||||
};
|
||||
\tint ret;
|
||||
\tstruct pmu_metric pm = {
|
||||
\t\t.pmu = &big_c_string[pmu->pmu_name.offset],
|
||||
\t};
|
||||
|
||||
for (uint32_t i = 0; i < pmu->num_entries; i++) {
|
||||
decompress_metric(pmu->entries[i].offset, &pm);
|
||||
if (!pm.metric_expr)
|
||||
continue;
|
||||
ret = fn(&pm, table, data);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
return 0;
|
||||
\tfor (uint32_t i = 0; i < pmu->num_entries; i++) {
|
||||
\t\tdecompress_metric(pmu->entries[i].offset, &pm);
|
||||
\t\tif (!pm.metric_expr)
|
||||
\t\t\tcontinue;
|
||||
\t\tret = fn(&pm, table, data);
|
||||
\t\tif (ret)
|
||||
\t\t\treturn ret;
|
||||
\t}
|
||||
\treturn 0;
|
||||
}
|
||||
|
||||
static int pmu_metrics_table__find_metric_pmu(const struct pmu_metrics_table *table,
|
||||
const struct pmu_table_entry *pmu,
|
||||
const char *metric,
|
||||
pmu_metric_iter_fn fn,
|
||||
void *data)
|
||||
\t\t\t\t\t const struct pmu_table_entry *pmu,
|
||||
\t\t\t\t\t const char *metric,
|
||||
\t\t\t\t\t pmu_metric_iter_fn fn,
|
||||
\t\t\t\t\t void *data)
|
||||
{
|
||||
struct pmu_metric pm = {
|
||||
.pmu = &big_c_string[pmu->pmu_name.offset],
|
||||
};
|
||||
int low = 0, high = pmu->num_entries - 1;
|
||||
\tstruct pmu_metric pm = {
|
||||
\t\t.pmu = &big_c_string[pmu->pmu_name.offset],
|
||||
\t};
|
||||
\tint low = 0, high = pmu->num_entries - 1;
|
||||
|
||||
while (low <= high) {
|
||||
int cmp, mid = (low + high) / 2;
|
||||
\twhile (low <= high) {
|
||||
\t\tint cmp, mid = (low + high) / 2;
|
||||
|
||||
decompress_metric(pmu->entries[mid].offset, &pm);
|
||||
\t\tdecompress_metric(pmu->entries[mid].offset, &pm);
|
||||
|
||||
if (!pm.metric_name && !metric)
|
||||
goto do_call;
|
||||
\t\tif (!pm.metric_name && !metric)
|
||||
\t\t\tgoto do_call;
|
||||
|
||||
if (!pm.metric_name && metric) {
|
||||
low = mid + 1;
|
||||
continue;
|
||||
}
|
||||
if (pm.metric_name && !metric) {
|
||||
high = mid - 1;
|
||||
continue;
|
||||
}
|
||||
\t\tif (!pm.metric_name && metric) {
|
||||
\t\t\tlow = mid + 1;
|
||||
\t\t\tcontinue;
|
||||
\t\t}
|
||||
\t\tif (pm.metric_name && !metric) {
|
||||
\t\t\thigh = mid - 1;
|
||||
\t\t\tcontinue;
|
||||
\t\t}
|
||||
|
||||
cmp = strcmp(pm.metric_name, metric);
|
||||
if (cmp < 0) {
|
||||
low = mid + 1;
|
||||
continue;
|
||||
}
|
||||
if (cmp > 0) {
|
||||
high = mid - 1;
|
||||
continue;
|
||||
}
|
||||
\t\tcmp = strcmp(pm.metric_name, metric);
|
||||
\t\tif (cmp < 0) {
|
||||
\t\t\tlow = mid + 1;
|
||||
\t\t\tcontinue;
|
||||
\t\t}
|
||||
\t\tif (cmp > 0) {
|
||||
\t\t\thigh = mid - 1;
|
||||
\t\t\tcontinue;
|
||||
\t\t}
|
||||
do_call:
|
||||
return fn ? fn(&pm, table, data) : 0;
|
||||
}
|
||||
return PMU_METRICS__NOT_FOUND;
|
||||
\t\treturn fn ? fn(&pm, table, data) : 0;
|
||||
\t}
|
||||
\treturn PMU_METRICS__NOT_FOUND;
|
||||
}
|
||||
|
||||
int pmu_metrics_table__for_each_metric(const struct pmu_metrics_table *table,
|
||||
pmu_metric_iter_fn fn,
|
||||
void *data)
|
||||
\t\t\t\t pmu_metric_iter_fn fn,
|
||||
\t\t\t\t void *data)
|
||||
{
|
||||
if (!table)
|
||||
return 0;
|
||||
for (size_t i = 0; i < table->num_pmus; i++) {
|
||||
int ret = pmu_metrics_table__for_each_metric_pmu(table, &table->pmus[i],
|
||||
fn, data);
|
||||
\tif (!table)
|
||||
\t\treturn 0;
|
||||
\tfor (size_t i = 0; i < table->num_pmus; i++) {
|
||||
\t\tint ret = pmu_metrics_table__for_each_metric_pmu(table, &table->pmus[i], fn, data);
|
||||
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
return 0;
|
||||
\t\tif (ret)
|
||||
\t\t\treturn ret;
|
||||
\t}
|
||||
\treturn 0;
|
||||
}
|
||||
|
||||
int pmu_metrics_table__find_metric(const struct pmu_metrics_table *table,
|
||||
struct perf_pmu *pmu,
|
||||
const char *metric,
|
||||
pmu_metric_iter_fn fn,
|
||||
void *data)
|
||||
\t\t\t\t struct perf_pmu *pmu,
|
||||
\t\t\t\t const char *metric,
|
||||
\t\t\t\t pmu_metric_iter_fn fn,
|
||||
\t\t\t\t void *data)
|
||||
{
|
||||
if (!table)
|
||||
return 0;
|
||||
for (size_t i = 0; i < table->num_pmus; i++) {
|
||||
const struct pmu_table_entry *table_pmu = &table->pmus[i];
|
||||
const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
|
||||
int ret;
|
||||
\tif (!table)
|
||||
\t\treturn 0;
|
||||
\tfor (size_t i = 0; i < table->num_pmus; i++) {
|
||||
\t\tconst struct pmu_table_entry *table_pmu = &table->pmus[i];
|
||||
\t\tconst char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
|
||||
\t\tint ret;
|
||||
|
||||
if (pmu && !perf_pmu__name_wildcard_match(pmu, pmu_name))
|
||||
continue;
|
||||
\t\tif (pmu && !perf_pmu__name_wildcard_match(pmu, pmu_name))
|
||||
\t\t\tcontinue;
|
||||
|
||||
ret = pmu_metrics_table__find_metric_pmu(table, table_pmu, metric, fn, data);
|
||||
if (ret != PMU_METRICS__NOT_FOUND)
|
||||
return ret;
|
||||
}
|
||||
return PMU_METRICS__NOT_FOUND;
|
||||
\t\tret = pmu_metrics_table__find_metric_pmu(table, table_pmu, metric, fn, data);
|
||||
\t\tif (ret != PMU_METRICS__NOT_FOUND)
|
||||
\t\t\treturn ret;
|
||||
\t}
|
||||
\treturn PMU_METRICS__NOT_FOUND;
|
||||
}
|
||||
|
||||
static const struct pmu_events_map *map_for_cpu(struct perf_cpu cpu)
|
||||
{
|
||||
static struct {
|
||||
const struct pmu_events_map *map;
|
||||
struct perf_cpu cpu;
|
||||
} last_result;
|
||||
static struct {
|
||||
const struct pmu_events_map *map;
|
||||
char *cpuid;
|
||||
} last_map_search;
|
||||
static bool has_last_result, has_last_map_search;
|
||||
const struct pmu_events_map *map = NULL;
|
||||
char *cpuid = NULL;
|
||||
size_t i;
|
||||
\tstatic struct {
|
||||
\t\tconst struct pmu_events_map *map;
|
||||
\t\tstruct perf_cpu cpu;
|
||||
\t} last_result;
|
||||
\tstatic struct {
|
||||
\t\tconst struct pmu_events_map *map;
|
||||
\t\tchar *cpuid;
|
||||
\t} last_map_search;
|
||||
\tstatic bool has_last_result, has_last_map_search;
|
||||
\tconst struct pmu_events_map *map = NULL;
|
||||
\tchar *cpuid = NULL;
|
||||
\tsize_t i;
|
||||
|
||||
if (has_last_result && last_result.cpu.cpu == cpu.cpu)
|
||||
return last_result.map;
|
||||
\tif (has_last_result && last_result.cpu.cpu == cpu.cpu)
|
||||
\t\treturn last_result.map;
|
||||
|
||||
cpuid = get_cpuid_allow_env_override(cpu);
|
||||
\tcpuid = get_cpuid_allow_env_override(cpu);
|
||||
|
||||
/*
|
||||
* On some platforms which uses cpus map, cpuid can be NULL for
|
||||
* PMUs other than CORE PMUs.
|
||||
*/
|
||||
if (!cpuid)
|
||||
goto out_update_last_result;
|
||||
\t/*
|
||||
\t * On some platforms which uses cpus map, cpuid can be NULL for
|
||||
\t * PMUs other than CORE PMUs.
|
||||
\t */
|
||||
\tif (!cpuid)
|
||||
\t\tgoto out_update_last_result;
|
||||
|
||||
if (has_last_map_search && !strcmp(last_map_search.cpuid, cpuid)) {
|
||||
map = last_map_search.map;
|
||||
free(cpuid);
|
||||
} else {
|
||||
i = 0;
|
||||
for (;;) {
|
||||
map = &pmu_events_map[i++];
|
||||
\tif (has_last_map_search && !strcmp(last_map_search.cpuid, cpuid)) {
|
||||
\t\tmap = last_map_search.map;
|
||||
\t\tfree(cpuid);
|
||||
\t} else {
|
||||
\t\ti = 0;
|
||||
\t\tfor (;;) {
|
||||
\t\t\tmap = &pmu_events_map[i++];
|
||||
|
||||
if (!map->arch) {
|
||||
map = NULL;
|
||||
break;
|
||||
}
|
||||
\t\t\tif (!map->arch) {
|
||||
\t\t\t\tmap = NULL;
|
||||
\t\t\t\tbreak;
|
||||
\t\t\t}
|
||||
|
||||
if (!strcmp_cpuid_str(map->cpuid, cpuid))
|
||||
break;
|
||||
}
|
||||
free(last_map_search.cpuid);
|
||||
last_map_search.cpuid = cpuid;
|
||||
last_map_search.map = map;
|
||||
has_last_map_search = true;
|
||||
}
|
||||
\t\t\tif (!strcmp_cpuid_str(map->cpuid, cpuid))
|
||||
\t\t\t\tbreak;
|
||||
\t\t}
|
||||
\t\tfree(last_map_search.cpuid);
|
||||
\t\tlast_map_search.cpuid = cpuid;
|
||||
\t\tlast_map_search.map = map;
|
||||
\t\thas_last_map_search = true;
|
||||
\t}
|
||||
out_update_last_result:
|
||||
last_result.cpu = cpu;
|
||||
last_result.map = map;
|
||||
has_last_result = true;
|
||||
return map;
|
||||
\tlast_result.cpu = cpu;
|
||||
\tlast_result.map = map;
|
||||
\thas_last_result = true;
|
||||
\treturn map;
|
||||
}
|
||||
|
||||
static const struct pmu_events_map *map_for_pmu(struct perf_pmu *pmu)
|
||||
{
|
||||
struct perf_cpu cpu = {-1};
|
||||
\tstruct perf_cpu cpu = { -1 };
|
||||
|
||||
if (pmu) {
|
||||
for (size_t i = 0; i < ARRAY_SIZE(pmu_events__common); i++) {
|
||||
const char *pmu_name = &big_c_string[pmu_events__common[i].pmu_name.offset];
|
||||
\tif (pmu) {
|
||||
\t\tfor (size_t i = 0; i < ARRAY_SIZE(pmu_events__common); i++) {
|
||||
\t\t\tconst char *pmu_name = &big_c_string[pmu_events__common[i].pmu_name.offset];
|
||||
|
||||
if (!strcmp(pmu_name, pmu->name)) {
|
||||
const struct pmu_events_map *map = &pmu_events_map[0];
|
||||
\t\t\tif (!strcmp(pmu_name, pmu->name)) {
|
||||
\t\t\t\tconst struct pmu_events_map *map = &pmu_events_map[0];
|
||||
|
||||
while (strcmp("common", map->arch))
|
||||
map++;
|
||||
return map;
|
||||
}
|
||||
}
|
||||
cpu = perf_cpu_map__min(pmu->cpus);
|
||||
}
|
||||
return map_for_cpu(cpu);
|
||||
\t\t\t\twhile (strcmp("common", map->arch))
|
||||
\t\t\t\t\tmap++;
|
||||
\t\t\t\treturn map;
|
||||
\t\t\t}
|
||||
\t\t}
|
||||
\t\tcpu = perf_cpu_map__min(pmu->cpus);
|
||||
\t}
|
||||
\treturn map_for_cpu(cpu);
|
||||
}
|
||||
|
||||
const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu)
|
||||
{
|
||||
const struct pmu_events_map *map = map_for_pmu(pmu);
|
||||
\tconst struct pmu_events_map *map = map_for_pmu(pmu);
|
||||
|
||||
if (!map)
|
||||
return NULL;
|
||||
\tif (!map)
|
||||
\t\treturn NULL;
|
||||
|
||||
if (!pmu)
|
||||
return &map->event_table;
|
||||
\tif (!pmu)
|
||||
\t\treturn &map->event_table;
|
||||
|
||||
for (size_t i = 0; i < map->event_table.num_pmus; i++) {
|
||||
const struct pmu_table_entry *table_pmu = &map->event_table.pmus[i];
|
||||
const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
|
||||
\tfor (size_t i = 0; i < map->event_table.num_pmus; i++) {
|
||||
\t\tconst struct pmu_table_entry *table_pmu = &map->event_table.pmus[i];
|
||||
\t\tconst char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
|
||||
|
||||
if (perf_pmu__name_wildcard_match(pmu, pmu_name))
|
||||
return &map->event_table;
|
||||
}
|
||||
return NULL;
|
||||
\t\tif (perf_pmu__name_wildcard_match(pmu, pmu_name))
|
||||
\t\t\treturn &map->event_table;
|
||||
\t}
|
||||
\treturn NULL;
|
||||
}
|
||||
|
||||
const struct pmu_events_table *perf_pmu__default_core_events_table(void)
|
||||
{
|
||||
int i = 0;
|
||||
\tint i = 0;
|
||||
|
||||
for (;;) {
|
||||
const struct pmu_events_map *map = &pmu_events_map[i++];
|
||||
\tfor (;;) {
|
||||
\t\tconst struct pmu_events_map *map = &pmu_events_map[i++];
|
||||
|
||||
if (!map->arch)
|
||||
break;
|
||||
\t\tif (!map->arch)
|
||||
\t\t\tbreak;
|
||||
|
||||
if (!strcmp(map->cpuid, "common"))
|
||||
return &map->event_table;
|
||||
}
|
||||
return NULL;
|
||||
\t\tif (!strcmp(map->cpuid, "common"))
|
||||
\t\t\treturn &map->event_table;
|
||||
\t}
|
||||
\treturn NULL;
|
||||
}
|
||||
|
||||
const struct pmu_metrics_table *pmu_metrics_table__find(void)
|
||||
{
|
||||
struct perf_cpu cpu = {-1};
|
||||
const struct pmu_events_map *map = map_for_cpu(cpu);
|
||||
\tstruct perf_cpu cpu = { -1 };
|
||||
\tconst struct pmu_events_map *map = map_for_cpu(cpu);
|
||||
|
||||
return map ? &map->metric_table : NULL;
|
||||
\treturn map ? &map->metric_table : NULL;
|
||||
}
|
||||
|
||||
const struct pmu_metrics_table *pmu_metrics_table__default(void)
|
||||
{
|
||||
int i = 0;
|
||||
\tint i = 0;
|
||||
|
||||
for (;;) {
|
||||
const struct pmu_events_map *map = &pmu_events_map[i++];
|
||||
\tfor (;;) {
|
||||
\t\tconst struct pmu_events_map *map = &pmu_events_map[i++];
|
||||
|
||||
if (!map->arch)
|
||||
break;
|
||||
\t\tif (!map->arch)
|
||||
\t\t\tbreak;
|
||||
|
||||
if (!strcmp(map->cpuid, "common"))
|
||||
return &map->metric_table;
|
||||
}
|
||||
return NULL;
|
||||
\t\tif (!strcmp(map->cpuid, "common"))
|
||||
\t\t\treturn &map->metric_table;
|
||||
\t}
|
||||
\treturn NULL;
|
||||
}
|
||||
|
||||
const struct pmu_events_table *find_core_events_table(const char *arch, const char *cpuid)
|
||||
{
|
||||
for (const struct pmu_events_map *tables = &pmu_events_map[0];
|
||||
tables->arch;
|
||||
tables++) {
|
||||
if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid))
|
||||
return &tables->event_table;
|
||||
}
|
||||
return NULL;
|
||||
\tfor (const struct pmu_events_map *tables = &pmu_events_map[0];
|
||||
\t tables->arch;
|
||||
\t tables++) {
|
||||
\t\tif (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid))
|
||||
\t\t\treturn &tables->event_table;
|
||||
\t}
|
||||
\treturn NULL;
|
||||
}
|
||||
|
||||
const struct pmu_metrics_table *find_core_metrics_table(const char *arch, const char *cpuid)
|
||||
{
|
||||
for (const struct pmu_events_map *tables = &pmu_events_map[0];
|
||||
tables->arch;
|
||||
tables++) {
|
||||
if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid))
|
||||
return &tables->metric_table;
|
||||
}
|
||||
return NULL;
|
||||
\tfor (const struct pmu_events_map *tables = &pmu_events_map[0];
|
||||
\t tables->arch;
|
||||
\t tables++) {
|
||||
\t\tif (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid))
|
||||
\t\t\treturn &tables->metric_table;
|
||||
\t}
|
||||
\treturn NULL;
|
||||
}
|
||||
|
||||
int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data)
|
||||
{
|
||||
for (const struct pmu_events_map *tables = &pmu_events_map[0];
|
||||
tables->arch;
|
||||
tables++) {
|
||||
int ret = pmu_events_table__for_each_event(&tables->event_table,
|
||||
/*pmu=*/ NULL, fn, data);
|
||||
\tfor (const struct pmu_events_map *tables = &pmu_events_map[0];
|
||||
\t tables->arch;
|
||||
\t tables++) {
|
||||
\t\tint ret = pmu_events_table__for_each_event(&tables->event_table,
|
||||
\t\t\t\t\t\t\t /*pmu=*/NULL, fn, data);
|
||||
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
return 0;
|
||||
\t\tif (ret)
|
||||
\t\t\treturn ret;
|
||||
\t}
|
||||
\treturn 0;
|
||||
}
|
||||
|
||||
int pmu_for_each_core_metric(pmu_metric_iter_fn fn, void *data)
|
||||
{
|
||||
for (const struct pmu_events_map *tables = &pmu_events_map[0];
|
||||
tables->arch;
|
||||
tables++) {
|
||||
int ret = pmu_metrics_table__for_each_metric(&tables->metric_table, fn, data);
|
||||
\tfor (const struct pmu_events_map *tables = &pmu_events_map[0];
|
||||
\t tables->arch;
|
||||
\t tables++) {
|
||||
\t\tint ret = pmu_metrics_table__for_each_metric(&tables->metric_table, fn, data);
|
||||
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
return 0;
|
||||
\t\tif (ret)
|
||||
\t\t\treturn ret;
|
||||
\t}
|
||||
\treturn 0;
|
||||
}
|
||||
|
||||
const struct pmu_events_table *find_sys_events_table(const char *name)
|
||||
{
|
||||
for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0];
|
||||
tables->name;
|
||||
tables++) {
|
||||
if (!strcmp(tables->name, name))
|
||||
return &tables->event_table;
|
||||
}
|
||||
return NULL;
|
||||
\tfor (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0];
|
||||
\t tables->name;
|
||||
\t tables++) {
|
||||
\t\tif (!strcmp(tables->name, name))
|
||||
\t\t\treturn &tables->event_table;
|
||||
\t}
|
||||
\treturn NULL;
|
||||
}
|
||||
|
||||
int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data)
|
||||
{
|
||||
for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0];
|
||||
tables->name;
|
||||
tables++) {
|
||||
int ret = pmu_events_table__for_each_event(&tables->event_table,
|
||||
/*pmu=*/ NULL, fn, data);
|
||||
\tfor (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0];
|
||||
\t tables->name;
|
||||
\t tables++) {
|
||||
\t\tint ret = pmu_events_table__for_each_event(&tables->event_table,
|
||||
\t\t\t\t\t\t\t /*pmu=*/NULL, fn, data);
|
||||
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
return 0;
|
||||
\t\tif (ret)
|
||||
\t\t\treturn ret;
|
||||
\t}
|
||||
\treturn 0;
|
||||
}
|
||||
|
||||
int pmu_for_each_sys_metric(pmu_metric_iter_fn fn, void *data)
|
||||
{
|
||||
for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0];
|
||||
tables->name;
|
||||
tables++) {
|
||||
int ret = pmu_metrics_table__for_each_metric(&tables->metric_table, fn, data);
|
||||
\tfor (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0];
|
||||
\t tables->name;
|
||||
\t tables++) {
|
||||
\t\tint ret = pmu_metrics_table__for_each_metric(&tables->metric_table, fn, data);
|
||||
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
return 0;
|
||||
\t\tif (ret)
|
||||
\t\t\treturn ret;
|
||||
\t}
|
||||
\treturn 0;
|
||||
}
|
||||
""")
|
||||
|
||||
|
|
@ -1362,22 +1361,21 @@ static const int metricgroups[][2] = {
|
|||
|
||||
const char *describe_metricgroup(const char *group)
|
||||
{
|
||||
int low = 0, high = (int)ARRAY_SIZE(metricgroups) - 1;
|
||||
\tint low = 0, high = (int)ARRAY_SIZE(metricgroups) - 1;
|
||||
|
||||
while (low <= high) {
|
||||
int mid = (low + high) / 2;
|
||||
const char *mgroup = &big_c_string[metricgroups[mid][0]];
|
||||
int cmp = strcmp(mgroup, group);
|
||||
\twhile (low <= high) {
|
||||
\t\tint mid = (low + high) / 2;
|
||||
\t\tconst char *mgroup = &big_c_string[metricgroups[mid][0]];
|
||||
\t\tint cmp = strcmp(mgroup, group);
|
||||
|
||||
if (cmp == 0) {
|
||||
return &big_c_string[metricgroups[mid][1]];
|
||||
} else if (cmp < 0) {
|
||||
low = mid + 1;
|
||||
} else {
|
||||
high = mid - 1;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
\t\tif (cmp == 0)
|
||||
\t\t\treturn &big_c_string[metricgroups[mid][1]];
|
||||
\t\telse if (cmp < 0)
|
||||
\t\t\tlow = mid + 1;
|
||||
\t\telse
|
||||
\t\t\thigh = mid - 1;
|
||||
\t}
|
||||
\treturn NULL;
|
||||
}
|
||||
""")
|
||||
|
||||
|
|
@ -1426,9 +1424,8 @@ such as "arm/cortex-a34".''',
|
|||
'output_string_file', type=argparse.FileType('w', encoding='utf-8'), nargs='?', default=None)
|
||||
_args = ap.parse_args()
|
||||
|
||||
_args.output_file.write(f"""
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/* THIS FILE WAS AUTOGENERATED BY jevents.py arch={_args.arch} model={_args.model} ! */
|
||||
_args.output_file.write(f"""/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/* THIS FILE WAS AUTOGENERATED BY `jevents.py arch={_args.arch} model={_args.model}` ! */
|
||||
""")
|
||||
_args.output_file.write("""
|
||||
#include <pmu-events/pmu-events.h>
|
||||
|
|
@ -1438,13 +1435,13 @@ such as "arm/cortex-a34".''',
|
|||
#include <stddef.h>
|
||||
|
||||
struct compact_pmu_event {
|
||||
int offset;
|
||||
\tint offset;
|
||||
};
|
||||
|
||||
struct pmu_table_entry {
|
||||
const struct compact_pmu_event *entries;
|
||||
uint32_t num_entries;
|
||||
struct compact_pmu_event pmu_name;
|
||||
\tconst struct compact_pmu_event *entries;
|
||||
\tuint32_t num_entries;
|
||||
\tstruct compact_pmu_event pmu_name;
|
||||
};
|
||||
|
||||
""")
|
||||
|
|
@ -1465,6 +1462,7 @@ struct pmu_table_entry {
|
|||
ftw(arch_path, [], preprocess_one_file)
|
||||
|
||||
_bcs.compute()
|
||||
_args.output_file.write('/* clang-format off */\n')
|
||||
if not _args.output_string_file:
|
||||
_args.output_file.write('static const char *const big_c_string =\n')
|
||||
for s in _bcs.big_string:
|
||||
|
|
@ -1487,6 +1485,7 @@ struct pmu_table_entry {
|
|||
|
||||
print_mapping_table(archs)
|
||||
print_system_mapping_table()
|
||||
_args.output_file.write('/* clang-format on */\n')
|
||||
print_metricgroups()
|
||||
_args.output_file.close()
|
||||
if _args.output_string_file:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user