summaryrefslogtreecommitdiff
path: root/tools/perf/pmu-events/empty-pmu-events.c
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2022-08-13 02:09:45 +0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2022-08-13 21:01:31 +0300
commit660842e468dcefb5d1d4fb40ed3abe4d1388dff7 (patch)
tree1f440d77fef497cee8c1a71bc8cf3d4f1bec69af /tools/perf/pmu-events/empty-pmu-events.c
parent7ae5c03a27934bee9daaeede1b0b1d4bada61ffd (diff)
downloadlinux-660842e468dcefb5d1d4fb40ed3abe4d1388dff7.tar.xz
perf pmu-events: Don't assume pmu_event is an array
The current code assumes that a struct pmu_event can be iterated over forward until a NULL pmu_event is encountered. This makes it difficult to refactor pmu_event. Add a loop function taking a callback function that's passed the struct pmu_event. This way the pmu_event is only needed for one element and not an entire array. Switch existing code iterating over the pmu_event arrays to use the new loop function pmu_events_table_for_each_event. 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-11-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.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-events/empty-pmu-events.c
index 028f44efe48d..bee1967baa2b 100644
--- a/tools/perf/pmu-events/empty-pmu-events.c
+++ b/tools/perf/pmu-events/empty-pmu-events.c
@@ -247,6 +247,20 @@ static const struct pmu_sys_events pmu_sys_event_tables[] = {
},
};
+int pmu_events_table_for_each_event(const struct pmu_event *table, pmu_event_iter_fn fn,
+ void *data)
+{
+ for (const struct pmu_event *pe = &table[0];
+ pe->name || pe->metric_group || pe->metric_name;
+ pe++) {
+ int ret = fn(pe, table, data);
+
+ if (ret)
+ return ret;
+ }
+ return 0;
+}
+
const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu)
{
const struct pmu_event *table = NULL;
@@ -291,14 +305,10 @@ 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++) {
- for (const struct pmu_event *pe = &tables->table[0];
- pe->name || pe->metric_group || pe->metric_name;
- pe++) {
- int ret = fn(pe, &tables->table[0], data);
+ int ret = pmu_events_table_for_each_event(tables->table, fn, data);
- if (ret)
- return ret;
- }
+ if (ret)
+ return ret;
}
return 0;
}
@@ -319,14 +329,10 @@ 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++) {
- for (const struct pmu_event *pe = &tables->table[0];
- pe->name || pe->metric_group || pe->metric_name;
- pe++) {
- int ret = fn(pe, &tables->table[0], data);
+ int ret = pmu_events_table_for_each_event(tables->table, fn, data);
- if (ret)
- return ret;
- }
+ if (ret)
+ return ret;
}
return 0;
}