diff options
author | Ian Rogers <irogers@google.com> | 2023-08-23 01:08:11 -0700 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2023-08-23 14:27:58 -0300 |
commit | 838a8c5f40dd272f0b684cde6bf681c5a4d33c0d (patch) | |
tree | 5c8625bd62ad48b6f5c45b0911e7f4319a5cd995 /tools/perf/util/pmu.c | |
parent | da6a5afda54d478980fb82c45390f4a4c4cfa431 (diff) |
perf pmu: Pass PMU rather than aliases and format
Pass the pmu so the aliases and format list can be better abstracted
and later lazily loaded.
Signed-off-by: Ian 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/20230823080828.1460376-9-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/pmu.c')
-rw-r--r-- | tools/perf/util/pmu.c | 69 |
1 files changed, 38 insertions, 31 deletions
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 1839c3668ec5..42f3249994ab 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -58,7 +58,7 @@ struct perf_pmu_format { * Parse & process all the sysfs attributes located under * the directory specified in 'dir' parameter. */ -int perf_pmu__format_parse(int dirfd, struct list_head *head) +int perf_pmu__format_parse(struct perf_pmu *pmu, int dirfd) { struct dirent *evt_ent; DIR *format_dir; @@ -96,7 +96,7 @@ int perf_pmu__format_parse(int dirfd, struct list_head *head) } perf_pmu_set_in(file, scanner); - ret = perf_pmu_parse(head, name, scanner); + ret = perf_pmu_parse(&pmu->format, name, scanner); perf_pmu_lex_destroy(scanner); fclose(file); } @@ -110,7 +110,7 @@ int perf_pmu__format_parse(int dirfd, struct list_head *head) * located at: * /sys/bus/event_source/devices/<dev>/format as sysfs group attributes. */ -static int pmu_format(int dirfd, const char *name, struct list_head *format) +static int pmu_format(struct perf_pmu *pmu, int dirfd, const char *name) { int fd; @@ -119,7 +119,7 @@ static int pmu_format(int dirfd, const char *name, struct list_head *format) return 0; /* it'll close the fd */ - if (perf_pmu__format_parse(fd, format)) + if (perf_pmu__format_parse(pmu, fd)) return -1; return 0; @@ -508,7 +508,7 @@ static int pmu_aliases_parse(int dirfd, struct list_head *head) * Reading the pmu event aliases definition, which should be located at: * /sys/bus/event_source/devices/<dev>/events as sysfs group attributes. */ -static int pmu_aliases(int dirfd, const char *name, struct list_head *head) +static int pmu_aliases(struct perf_pmu *pmu, int dirfd, const char *name) { int fd; @@ -517,7 +517,7 @@ static int pmu_aliases(int dirfd, const char *name, struct list_head *head) return 0; /* it'll close the fd */ - if (pmu_aliases_parse(fd, head)) + if (pmu_aliases_parse(fd, &pmu->aliases)) return -1; return 0; @@ -770,11 +770,10 @@ static int pmu_add_cpu_aliases_map_callback(const struct pmu_event *pe, * From the pmu_events_table, find the events that correspond to the given * PMU and add them to the list 'head'. */ -void pmu_add_cpu_aliases_table(struct list_head *head, struct perf_pmu *pmu, - const struct pmu_events_table *table) +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 = head, + .head = &pmu->aliases, .default_pmu_name = perf_pmus__default_pmu_name(), .pmu = pmu, }; @@ -783,7 +782,7 @@ void pmu_add_cpu_aliases_table(struct list_head *head, struct perf_pmu *pmu, free(data.default_pmu_name); } -static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu) +static void pmu_add_cpu_aliases(struct perf_pmu *pmu) { const struct pmu_events_table *table; @@ -791,7 +790,7 @@ static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu) if (!table) return; - pmu_add_cpu_aliases_table(head, pmu, table); + pmu_add_cpu_aliases_table(pmu, table); } struct pmu_sys_event_iter_data { @@ -821,10 +820,10 @@ static int pmu_add_sys_aliases_iter_fn(const struct pmu_event *pe, return 0; } -void pmu_add_sys_aliases(struct list_head *head, struct perf_pmu *pmu) +void pmu_add_sys_aliases(struct perf_pmu *pmu) { struct pmu_sys_event_iter_data idata = { - .head = head, + .head = &pmu->aliases, .pmu = pmu, }; @@ -863,30 +862,33 @@ static int pmu_max_precise(int dirfd, struct perf_pmu *pmu) struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char *lookup_name) { struct perf_pmu *pmu; - LIST_HEAD(format); - LIST_HEAD(aliases); __u32 type; char *name = pmu_find_real_name(lookup_name); char *alias_name; + pmu = zalloc(sizeof(*pmu)); + if (!pmu) + return NULL; + + INIT_LIST_HEAD(&pmu->format); + INIT_LIST_HEAD(&pmu->aliases); + INIT_LIST_HEAD(&pmu->caps); /* * The pmu data we store & need consists of the pmu * type value and format definitions. Load both right * now. */ - if (pmu_format(dirfd, name, &format)) + if (pmu_format(pmu, dirfd, name)) { + free(pmu); return NULL; - + } /* * Check the aliases first to avoid unnecessary work. */ - if (pmu_aliases(dirfd, name, &aliases)) - return NULL; - - pmu = zalloc(sizeof(*pmu)); - if (!pmu) + if (pmu_aliases(pmu, dirfd, name)) { + free(pmu); return NULL; - + } pmu->is_core = is_pmu_core(name); pmu->cpus = pmu_cpumask(dirfd, name, pmu->is_core); pmu->name = strdup(name); @@ -909,14 +911,8 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char if (pmu->is_uncore) pmu->id = pmu_id(name); pmu->max_precise = pmu_max_precise(dirfd, pmu); - pmu_add_cpu_aliases(&aliases, pmu); - pmu_add_sys_aliases(&aliases, pmu); - - INIT_LIST_HEAD(&pmu->format); - INIT_LIST_HEAD(&pmu->aliases); - INIT_LIST_HEAD(&pmu->caps); - list_splice(&format, &pmu->format); - list_splice(&aliases, &pmu->aliases); + pmu_add_cpu_aliases(pmu); + pmu_add_sys_aliases(pmu); list_add_tail(&pmu->list, pmus); pmu->default_config = perf_pmu__get_default_config(pmu); @@ -1397,6 +1393,17 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, return 0; } +struct perf_pmu_alias *perf_pmu__find_alias(struct perf_pmu *pmu, const char *event) +{ + struct perf_pmu_alias *alias; + + list_for_each_entry(alias, &pmu->aliases, list) + if (!strcmp(event, alias->name)) + return alias; + + return NULL; +} + int perf_pmu__new_format(struct list_head *list, char *name, int config, unsigned long *bits) { |