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>
This commit is contained in:
Ian Rogers
2022-08-12 16:09:45 -07:00
committed by Arnaldo Carvalho de Melo
parent 7ae5c03a27
commit 660842e468
7 changed files with 315 additions and 184 deletions

View File

@@ -129,6 +129,28 @@ static int get_counterset_start(int setnr)
}
}
struct get_counter_name_data {
int wanted;
const char *result;
};
static int get_counter_name_callback(const struct pmu_event *evp,
const struct pmu_event *table __maybe_unused,
void *vdata)
{
struct get_counter_name_data *data = vdata;
int rc, event_nr;
if (evp->name == NULL || evp->event == NULL)
return 0;
rc = sscanf(evp->event, "event=%x", &event_nr);
if (rc == 1 && event_nr == data->wanted) {
data->result = evp->name;
return 1; /* Terminate the search. */
}
return 0;
}
/* Scan the PMU table and extract the logical name of a counter from the
* PMU events table. Input is the counter set and counter number with in the
* set. Construct the event number and use this as key. If they match return
@@ -137,20 +159,16 @@ static int get_counterset_start(int setnr)
*/
static const char *get_counter_name(int set, int nr, const struct pmu_event *table)
{
int rc, event_nr, wanted = get_counterset_start(set) + nr;
struct get_counter_name_data data = {
.wanted = get_counterset_start(set) + nr,
.result = NULL,
};
if (table) {
const struct pmu_event *evp = table;
if (!table)
return NULL;
for (; evp->name || evp->event || evp->desc; ++evp) {
if (evp->name == NULL || evp->event == NULL)
continue;
rc = sscanf(evp->event, "event=%x", &event_nr);
if (rc == 1 && event_nr == wanted)
return evp->name;
}
}
return NULL;
pmu_events_table_for_each_event(table, get_counter_name_callback, &data);
return data.result;
}
static void s390_cpumcfdg_dump(struct perf_sample *sample)