[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230823080828.1460376-19-irogers@google.com>
Date: Wed, 23 Aug 2023 01:08:21 -0700
From: Ian Rogers <irogers@...gle.com>
To: Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...nel.org>,
Namhyung Kim <namhyung@...nel.org>,
Ian Rogers <irogers@...gle.com>,
Adrian Hunter <adrian.hunter@...el.com>,
James Clark <james.clark@....com>,
Kan Liang <kan.liang@...ux.intel.com>,
John Garry <john.g.garry@...cle.com>,
Kajol Jain <kjain@...ux.ibm.com>,
Jing Zhang <renyu.zj@...ux.alibaba.com>,
Ravi Bangoria <ravi.bangoria@....com>,
Rob Herring <robh@...nel.org>,
Gaosheng Cui <cuigaosheng1@...wei.com>,
linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH v1 18/25] perf pmu: Prefer passing pmu to aliases list
The aliases list is part of the PMU. Rather than pass the aliases
list, pass the full PMU simplifying some callbacks.
Signed-off-by: Ian Rogers <irogers@...gle.com>
---
tools/perf/util/pmu.c | 44 ++++++++++++++++---------------------------
1 file changed, 16 insertions(+), 28 deletions(-)
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 6db14967ded9..069530b2f79e 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -431,12 +431,12 @@ static void perf_pmu__del_aliases(struct perf_pmu *pmu)
/* Merge an alias, search in alias list. If this name is already
* present merge both of them to combine all information.
*/
-static bool perf_pmu_merge_alias(struct perf_pmu_alias *newalias,
- struct list_head *alist)
+static bool perf_pmu_merge_alias(struct perf_pmu *pmu,
+ struct perf_pmu_alias *newalias)
{
struct perf_pmu_alias *a;
- list_for_each_entry(a, alist, list) {
+ list_for_each_entry(a, &pmu->aliases, list) {
if (!strcasecmp(newalias->name, a->name)) {
if (newalias->pmu_name && a->pmu_name &&
!strcasecmp(newalias->pmu_name, a->pmu_name)) {
@@ -450,7 +450,7 @@ static bool perf_pmu_merge_alias(struct perf_pmu_alias *newalias,
return false;
}
-static int perf_pmu__new_alias(struct list_head *list, int dirfd, const char *name,
+static int perf_pmu__new_alias(struct perf_pmu *pmu, int dirfd, const char *name,
const char *desc, const char *val, FILE *val_fd,
const struct pmu_event *pe)
{
@@ -532,8 +532,8 @@ static int perf_pmu__new_alias(struct list_head *list, int dirfd, const char *na
alias->str = strdup(newval);
alias->pmu_name = pmu_name ? strdup(pmu_name) : NULL;
- if (!perf_pmu_merge_alias(alias, list))
- list_add_tail(&alias->list, list);
+ if (!perf_pmu_merge_alias(pmu, alias))
+ list_add_tail(&alias->list, &pmu->aliases);
return 0;
}
@@ -559,7 +559,7 @@ static inline bool pmu_alias_info_file(char *name)
* Process all the sysfs attributes located under the directory
* specified in 'dir' parameter.
*/
-static int pmu_aliases_parse(int dirfd, struct list_head *head)
+static int pmu_aliases_parse(struct perf_pmu *pmu, int dirfd)
{
struct dirent *evt_ent;
DIR *event_dir;
@@ -593,7 +593,7 @@ static int pmu_aliases_parse(int dirfd, struct list_head *head)
continue;
}
- if (perf_pmu__new_alias(head, dirfd, name, /*desc=*/ NULL,
+ if (perf_pmu__new_alias(pmu, dirfd, name, /*desc=*/ NULL,
/*val=*/ NULL, file, /*pe=*/ NULL) < 0)
pr_debug("Cannot set up %s\n", name);
fclose(file);
@@ -616,7 +616,7 @@ static int pmu_aliases(struct perf_pmu *pmu, int dirfd, const char *name)
return 0;
/* it'll close the fd */
- if (pmu_aliases_parse(fd, &pmu->aliases))
+ if (pmu_aliases_parse(pmu, fd))
return -1;
return 0;
@@ -844,10 +844,9 @@ static int pmu_add_cpu_aliases_map_callback(const struct pmu_event *pe,
const struct pmu_events_table *table __maybe_unused,
void *vdata)
{
- struct list_head *head = vdata;
+ struct perf_pmu *pmu = vdata;
- /* need type casts to override 'const' */
- perf_pmu__new_alias(head, -1, pe->name, pe->desc, pe->event, /*val_fd=*/ NULL, pe);
+ perf_pmu__new_alias(pmu, -1, pe->name, pe->desc, pe->event, /*val_fd=*/ NULL, pe);
return 0;
}
@@ -857,7 +856,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)
{
- pmu_events_table__for_each_event(table, pmu, pmu_add_cpu_aliases_map_callback, &pmu->aliases);
+ pmu_events_table__for_each_event(table, pmu, pmu_add_cpu_aliases_map_callback, pmu);
}
static void pmu_add_cpu_aliases(struct perf_pmu *pmu)
@@ -871,24 +870,18 @@ static void pmu_add_cpu_aliases(struct perf_pmu *pmu)
pmu_add_cpu_aliases_table(pmu, table);
}
-struct pmu_sys_event_iter_data {
- struct list_head *head;
- struct perf_pmu *pmu;
-};
-
static int pmu_add_sys_aliases_iter_fn(const struct pmu_event *pe,
const struct pmu_events_table *table __maybe_unused,
- void *data)
+ void *vdata)
{
- struct pmu_sys_event_iter_data *idata = data;
- struct perf_pmu *pmu = idata->pmu;
+ struct perf_pmu *pmu = vdata;
if (!pe->compat || !pe->pmu)
return 0;
if (!strcmp(pmu->id, pe->compat) &&
pmu_uncore_alias_match(pe->pmu, pmu->name)) {
- perf_pmu__new_alias(idata->head, -1,
+ perf_pmu__new_alias(pmu, -1,
pe->name,
pe->desc,
pe->event,
@@ -901,15 +894,10 @@ static int pmu_add_sys_aliases_iter_fn(const struct pmu_event *pe,
void pmu_add_sys_aliases(struct perf_pmu *pmu)
{
- struct pmu_sys_event_iter_data idata = {
- .head = &pmu->aliases,
- .pmu = pmu,
- };
-
if (!pmu->id)
return;
- pmu_for_each_sys_event(pmu_add_sys_aliases_iter_fn, &idata);
+ pmu_for_each_sys_event(pmu_add_sys_aliases_iter_fn, pmu);
}
struct perf_event_attr * __weak
--
2.42.0.rc1.204.g551eb34607-goog
Powered by blists - more mailing lists