summaryrefslogtreecommitdiffstats
path: root/tools/perf/pmu-events/jevents.py
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2022-08-12 16:09:46 -0700
committerArnaldo Carvalho de Melo <acme@redhat.com>2022-08-13 15:02:08 -0300
commit1ba3752aec30c04bfb7c82b44332ff98294ec0b8 (patch)
tree94ceb76274a753ada79c823731335a58ec5c83da /tools/perf/pmu-events/jevents.py
parent660842e468dcefb5d1d4fb40ed3abe4d1388dff7 (diff)
downloadlinux-1ba3752aec30c04bfb7c82b44332ff98294ec0b8.tar.gz
linux-1ba3752aec30c04bfb7c82b44332ff98294ec0b8.tar.bz2
linux-1ba3752aec30c04bfb7c82b44332ff98294ec0b8.zip
perf pmu-events: Hide the pmu_events
Hide that the pmu_event structs are an array with a new wrapper struct. Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@arm.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: John Garry <john.garry@huawei.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Leo Yan <leo.yan@linaro.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mike Leach <mike.leach@linaro.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ravi Bangoria <ravi.bangoria@amd.com> Cc: Stephane Eranian <eranian@google.com> Cc: Will Deacon <will@kernel.org> Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com> Cc: linux-arm-kernel@lists.infradead.org Link: https://lore.kernel.org/r/20220812230949.683239-12-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/pmu-events/jevents.py')
-rwxr-xr-xtools/perf/pmu-events/jevents.py47
1 files changed, 26 insertions, 21 deletions
diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py
index 977f2061a990..4b7948ba57d6 100755
--- a/tools/perf/pmu-events/jevents.py
+++ b/tools/perf/pmu-events/jevents.py
@@ -335,6 +335,11 @@ def process_one_file(parents: Sequence[str], item: os.DirEntry) -> None:
def print_mapping_table(archs: Sequence[str]) -> None:
"""Read the mapfile and generate the struct from cpuid string to event table."""
_args.output_file.write("""
+/* Struct used to make the PMU event table implementation opaque to callers. */
+struct pmu_events_table {
+ const struct pmu_event *entries;
+};
+
/*
* Map a CPU to its table of PMU events. The CPU is identified by the
* cpuid field, which is an arch-specific identifier for the CPU.
@@ -346,7 +351,7 @@ def print_mapping_table(archs: Sequence[str]) -> None:
struct pmu_events_map {
const char *arch;
const char *cpuid;
- const struct pmu_event *table;
+ struct pmu_events_table table;
};
/*
@@ -360,7 +365,7 @@ const struct pmu_events_map pmu_events_map[] = {
_args.output_file.write("""{
\t.arch = "testarch",
\t.cpuid = "testcpu",
-\t.table = pme_test_soc_cpu,
+\t.table = { pme_test_soc_cpu },
},
""")
else:
@@ -375,7 +380,7 @@ const struct pmu_events_map pmu_events_map[] = {
_args.output_file.write(f"""{{
\t.arch = "{arch}",
\t.cpuid = "{cpuid}",
-\t.table = {tblname}
+\t.table = {{ {tblname} }}
}},
""")
first = False
@@ -383,7 +388,7 @@ const struct pmu_events_map pmu_events_map[] = {
_args.output_file.write("""{
\t.arch = 0,
\t.cpuid = 0,
-\t.table = 0,
+\t.table = { 0 },
}
};
""")
@@ -394,26 +399,26 @@ def print_system_mapping_table() -> None:
_args.output_file.write("""
struct pmu_sys_events {
\tconst char *name;
-\tconst struct pmu_event *table;
+\tstruct pmu_events_table table;
};
static const struct pmu_sys_events pmu_sys_event_tables[] = {
""")
for tblname in _sys_event_tables:
_args.output_file.write(f"""\t{{
-\t\t.table = {tblname},
+\t\t.table = {{ {tblname} }},
\t\t.name = \"{tblname}\",
\t}},
""")
_args.output_file.write("""\t{
-\t\t.table = 0
+\t\t.table = { 0 }
\t},
};
-int pmu_events_table_for_each_event(const struct pmu_event *table, pmu_event_iter_fn fn,
+int pmu_events_table_for_each_event(const struct pmu_events_table *table, pmu_event_iter_fn fn,
void *data)
{
- for (const struct pmu_event *pe = &table[0];
+ for (const struct pmu_event *pe = &table->entries[0];
pe->name || pe->metric_group || pe->metric_name;
pe++) {
int ret = fn(pe, table, data);
@@ -424,9 +429,9 @@ int pmu_events_table_for_each_event(const struct pmu_event *table, pmu_event_ite
return 0;
}
-const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu)
+const struct pmu_events_table *perf_pmu__find_table(struct perf_pmu *pmu)
{
- const struct pmu_event *table = NULL;
+ const struct pmu_events_table *table = NULL;
char *cpuid = perf_pmu__getcpuid(pmu);
int i;
@@ -439,11 +444,11 @@ const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu)
i = 0;
for (;;) {
const struct pmu_events_map *map = &pmu_events_map[i++];
- if (!map->table)
+ if (!map->arch)
break;
if (!strcmp_cpuid_str(map->cpuid, cpuid)) {
- table = map->table;
+ table = &map->table;
break;
}
}
@@ -451,13 +456,13 @@ const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu)
return table;
}
-const struct pmu_event *find_core_events_table(const char *arch, const char *cpuid)
+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->table;
+ tables->arch;
tables++) {
if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid))
- return tables->table;
+ return &tables->table;
}
return NULL;
}
@@ -465,9 +470,9 @@ const struct pmu_event *find_core_events_table(const char *arch, const char *cpu
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->table;
+ tables->arch;
tables++) {
- int ret = pmu_events_table_for_each_event(tables->table, fn, data);
+ int ret = pmu_events_table_for_each_event(&tables->table, fn, data);
if (ret)
return ret;
@@ -475,13 +480,13 @@ int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data)
return 0;
}
-const struct pmu_event *find_sys_events_table(const char *name)
+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->table;
+ return &tables->table;
}
return NULL;
}
@@ -491,7 +496,7 @@ 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->table, fn, data);
+ int ret = pmu_events_table_for_each_event(&tables->table, fn, data);
if (ret)
return ret;