aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/pmu-events/empty-pmu-events.c
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/empty-pmu-events.c
parentperf pmu-events: Don't assume pmu_event is an array (diff)
downloadlinux-dev-1ba3752aec30c04bfb7c82b44332ff98294ec0b8.tar.xz
linux-dev-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/empty-pmu-events.c')
-rw-r--r--tools/perf/pmu-events/empty-pmu-events.c44
1 files changed, 24 insertions, 20 deletions
diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-events/empty-pmu-events.c
index bee1967baa2b..5ed8c0aa4817 100644
--- a/tools/perf/pmu-events/empty-pmu-events.c
+++ b/tools/perf/pmu-events/empty-pmu-events.c
@@ -176,6 +176,10 @@ static const struct pmu_event pme_test_soc_cpu[] = {
},
};
+/* 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
@@ -188,7 +192,7 @@ static const struct pmu_event pme_test_soc_cpu[] = {
struct pmu_events_map {
const char *arch;
const char *cpuid;
- const struct pmu_event *table;
+ const struct pmu_events_table table;
};
/*
@@ -199,12 +203,12 @@ static const struct pmu_events_map pmu_events_map[] = {
{
.arch = "testarch",
.cpuid = "testcpu",
- .table = pme_test_soc_cpu,
+ .table = { pme_test_soc_cpu },
},
{
.arch = 0,
.cpuid = 0,
- .table = 0,
+ .table = { 0 },
},
};
@@ -234,23 +238,23 @@ static const struct pmu_event pme_test_soc_sys[] = {
struct pmu_sys_events {
const char *name;
- const struct pmu_event *table;
+ const struct pmu_events_table table;
};
static const struct pmu_sys_events pmu_sys_event_tables[] = {
{
- .table = pme_test_soc_sys,
+ .table = { pme_test_soc_sys },
.name = "pme_test_soc_sys",
},
{
- .table = 0
+ .table = { 0 }
},
};
-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);
@@ -261,9 +265,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;
@@ -277,11 +281,11 @@ const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu)
for (;;) {
const struct pmu_events_map *map = &pmu_events_map[i++];
- if (!map->table)
+ if (!map->cpuid)
break;
if (!strcmp_cpuid_str(map->cpuid, cpuid)) {
- table = map->table;
+ table = &map->table;
break;
}
}
@@ -289,13 +293,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;
}
@@ -303,9 +307,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;
@@ -313,13 +317,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;
}
@@ -329,7 +333,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;