Commit e3edd6cf authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo

perf pmu-events: Reduce processed events by passing PMU

Pass the PMU to pmu_events_table__for_each_event so that entries that
don't match don't need to be processed by callback.

If a NULL PMU is passed then all PMUs are processed.

'perf bench internals pmu-scan's "Average PMU scanning" performance is
reduced by about 5% on an Intel tigerlake.
Signed-off-by: default avatarIan Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Gaosheng Cui <cuigaosheng1@huawei.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Link: https://lore.kernel.org/r/20230824041330.266337-8-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent c4ac7f75
......@@ -266,12 +266,16 @@ static const struct pmu_sys_events pmu_sys_event_tables[] = {
},
};
int pmu_events_table__for_each_event(const struct pmu_events_table *table, pmu_event_iter_fn fn,
void *data)
int pmu_events_table__for_each_event(const struct pmu_events_table *table, struct perf_pmu *pmu,
pmu_event_iter_fn fn, void *data)
{
for (const struct pmu_event *pe = &table->entries[0]; pe->name; pe++) {
int ret = fn(pe, table, data);
int ret;
if (pmu && !pmu__name_match(pmu, pe->pmu))
continue;
ret = fn(pe, table, data);
if (ret)
return ret;
}
......@@ -371,7 +375,8 @@ const struct pmu_metrics_table *find_core_metrics_table(const char *arch, const
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, fn, data);
int ret = pmu_events_table__for_each_event(&tables->event_table,
/*pmu=*/ NULL, fn, data);
if (ret)
return ret;
......@@ -408,7 +413,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, /*pmu=*/ NULL, fn, data);
if (ret)
return ret;
......
......@@ -826,14 +826,20 @@ static int pmu_events_table__for_each_event_pmu(const struct pmu_events_table *t
}
int pmu_events_table__for_each_event(const struct pmu_events_table *table,
struct perf_pmu *pmu,
pmu_event_iter_fn fn,
void *data)
{
for (size_t i = 0; i < table->num_pmus; i++) {
int ret = pmu_events_table__for_each_event_pmu(table, &table->pmus[i],
fn, data);
const struct pmu_table_entry *table_pmu = &table->pmus[i];
const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
int ret;
if (ret)
if (pmu && !pmu__name_match(pmu, pmu_name))
continue;
ret = pmu_events_table__for_each_event_pmu(table, table_pmu, fn, data);
if (pmu || ret)
return ret;
}
return 0;
......@@ -955,7 +961,8 @@ 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, fn, data);
int ret = pmu_events_table__for_each_event(&tables->event_table,
/*pmu=*/ NULL, fn, data);
if (ret)
return ret;
......@@ -992,7 +999,8 @@ 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, fn, data);
int ret = pmu_events_table__for_each_event(&tables->event_table,
/*pmu=*/ NULL, fn, data);
if (ret)
return ret;
......
......@@ -77,7 +77,9 @@ typedef int (*pmu_metric_iter_fn)(const struct pmu_metric *pm,
const struct pmu_metrics_table *table,
void *data);
int pmu_events_table__for_each_event(const struct pmu_events_table *table, pmu_event_iter_fn fn,
int pmu_events_table__for_each_event(const struct pmu_events_table *table,
struct perf_pmu *pmu,
pmu_event_iter_fn fn,
void *data);
int pmu_metrics_table__for_each_metric(const struct pmu_metrics_table *table, pmu_metric_iter_fn fn,
void *data);
......
......@@ -483,12 +483,14 @@ static int test__pmu_event_table(struct test_suite *test __maybe_unused,
if (!table || !sys_event_table)
return -1;
err = pmu_events_table__for_each_event(table, test__pmu_event_table_core_callback,
err = pmu_events_table__for_each_event(table, /*pmu=*/ NULL,
test__pmu_event_table_core_callback,
&map_events);
if (err)
return err;
err = pmu_events_table__for_each_event(sys_event_table, test__pmu_event_table_sys_callback,
err = pmu_events_table__for_each_event(sys_event_table, /*pmu=*/ NULL,
test__pmu_event_table_sys_callback,
&map_events);
if (err)
return err;
......
......@@ -859,28 +859,14 @@ static bool pmu_uncore_alias_match(const char *pmu_name, const char *name)
return res;
}
struct pmu_add_cpu_aliases_map_data {
/* List being added to. */
struct list_head *head;
/* If a pmu_event lacks a given PMU the default used. */
char *default_pmu_name;
/* The PMU that we're searching for events for. */
struct perf_pmu *pmu;
};
static int pmu_add_cpu_aliases_map_callback(const struct pmu_event *pe,
const struct pmu_events_table *table __maybe_unused,
void *vdata)
{
struct pmu_add_cpu_aliases_map_data *data = vdata;
const char *pname = pe->pmu ?: data->default_pmu_name;
struct list_head *head = vdata;
if (!strcmp(pname, data->pmu->name) ||
(data->pmu->is_uncore && pmu_uncore_alias_match(pname, data->pmu->name))) {
/* need type casts to override 'const' */
__perf_pmu__new_alias(data->head, -1, (char *)pe->name, (char *)pe->desc,
(char *)pe->event, pe);
}
__perf_pmu__new_alias(head, -1, (char *)pe->name, (char *)pe->desc, (char *)pe->event, pe);
return 0;
}
......@@ -890,14 +876,7 @@ static int pmu_add_cpu_aliases_map_callback(const struct pmu_event *pe,
*/
void pmu_add_cpu_aliases_table(struct perf_pmu *pmu, const struct pmu_events_table *table)
{
struct pmu_add_cpu_aliases_map_data data = {
.head = &pmu->aliases,
.default_pmu_name = perf_pmus__default_pmu_name(),
.pmu = pmu,
};
pmu_events_table__for_each_event(table, pmu_add_cpu_aliases_map_callback, &data);
free(data.default_pmu_name);
pmu_events_table__for_each_event(table, pmu, pmu_add_cpu_aliases_map_callback, &pmu->aliases);
}
static void pmu_add_cpu_aliases(struct perf_pmu *pmu)
......@@ -1713,6 +1692,12 @@ int perf_pmu__for_each_event(const struct perf_pmu *pmu, void *state, pmu_event_
return ret;
}
bool pmu__name_match(const struct perf_pmu *pmu, const char *pmu_name)
{
return !strcmp(pmu->name, pmu_name) ||
(pmu->is_uncore && pmu_uncore_alias_match(pmu_name, pmu->name));
}
bool perf_pmu__is_software(const struct perf_pmu *pmu)
{
if (pmu->is_core || pmu->is_uncore || pmu->auxtrace)
......
......@@ -198,6 +198,7 @@ bool perf_pmu__auto_merge_stats(const struct perf_pmu *pmu);
bool perf_pmu__have_event(const struct perf_pmu *pmu, const char *name);
size_t perf_pmu__num_events(const struct perf_pmu *pmu);
int perf_pmu__for_each_event(const struct perf_pmu *pmu, void *state, pmu_event_callback cb);
bool pmu__name_match(const struct perf_pmu *pmu, const char *pmu_name);
/**
* perf_pmu_is_software - is the PMU a software PMU as in it uses the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment