Re: [PATCH 27/49] perf util: Save pmu name to struct perf_pmu_alias

From: Arnaldo Carvalho de Melo
Date: Mon Feb 08 2021 - 15:23:01 EST


Em Mon, Feb 08, 2021 at 07:25:24AM -0800, kan.liang@xxxxxxxxxxxxxxx escreveu:
> From: Jin Yao <yao.jin@xxxxxxxxxxxxxxx>
>
> On hybrid platform, one event is available on one pmu
> (such as, cpu_core or cpu_atom).
>
> This patch saves the pmu name to the pmu field of struct perf_pmu_alias.
> Then next we can know the pmu where the event can be enabled.
>
> Reviewed-by: Andi Kleen <ak@xxxxxxxxxxxxxxx>
> Signed-off-by: Jin Yao <yao.jin@xxxxxxxxxxxxxxx>
> ---
> tools/perf/util/pmu.c | 17 +++++++++++++----
> tools/perf/util/pmu.h | 1 +
> 2 files changed, 14 insertions(+), 4 deletions(-)
>
> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
> index 44ef283..0c25457 100644
> --- a/tools/perf/util/pmu.c
> +++ b/tools/perf/util/pmu.c
> @@ -283,6 +283,7 @@ void perf_pmu_free_alias(struct perf_pmu_alias *newalias)
> zfree(&newalias->str);
> zfree(&newalias->metric_expr);
> zfree(&newalias->metric_name);
> + zfree(&newalias->pmu);
> parse_events_terms__purge(&newalias->terms);
> free(newalias);
> }
> @@ -297,6 +298,10 @@ static bool perf_pmu_merge_alias(struct perf_pmu_alias *newalias,
>
> list_for_each_entry(a, alist, list) {
> if (!strcasecmp(newalias->name, a->name)) {
> + if (newalias->pmu && a->pmu &&
> + !strcasecmp(newalias->pmu, a->pmu)) {
> + continue;
> + }
> perf_pmu_update_alias(a, newalias);
> perf_pmu_free_alias(newalias);
> return true;
> @@ -311,7 +316,8 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name,
> char *unit, char *perpkg,
> char *metric_expr,
> char *metric_name,
> - char *deprecated)
> + char *deprecated,
> + char *pmu)
> {
> struct parse_events_term *term;
> struct perf_pmu_alias *alias;
> @@ -382,6 +388,7 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name,
> }
> alias->per_pkg = perpkg && sscanf(perpkg, "%d", &num) == 1 && num == 1;
> alias->str = strdup(newval);
> + alias->pmu = pmu ? strdup(pmu) : NULL;
>
> if (deprecated)
> alias->deprecated = true;
> @@ -407,7 +414,7 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI
> strim(buf);
>
> return __perf_pmu__new_alias(list, dir, name, NULL, buf, NULL, NULL, NULL,
> - NULL, NULL, NULL, NULL);
> + NULL, NULL, NULL, NULL, NULL);
> }
>
> static inline bool pmu_alias_info_file(char *name)
> @@ -797,7 +804,8 @@ void pmu_add_cpu_aliases_map(struct list_head *head, struct perf_pmu *pmu,
> (char *)pe->unit, (char *)pe->perpkg,
> (char *)pe->metric_expr,
> (char *)pe->metric_name,
> - (char *)pe->deprecated);
> + (char *)pe->deprecated,
> + (char *)pe->pmu);
> }
> }
>
> @@ -870,7 +878,8 @@ static int pmu_add_sys_aliases_iter_fn(struct pmu_event *pe, void *data)
> (char *)pe->perpkg,
> (char *)pe->metric_expr,
> (char *)pe->metric_name,
> - (char *)pe->deprecated);
> + (char *)pe->deprecated,
> + NULL);

At some point I think passing the whole 'struct pme_event' pointer
should be better?

> }
>
> return 0;
> diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
> index 8164388..0e724d5 100644
> --- a/tools/perf/util/pmu.h
> +++ b/tools/perf/util/pmu.h
> @@ -72,6 +72,7 @@ struct perf_pmu_alias {
> bool deprecated;
> char *metric_expr;
> char *metric_name;
> + char *pmu;
> };
>
> struct perf_pmu *perf_pmu__find(const char *name);
> --
> 2.7.4
>

--

- Arnaldo