[01/19] perf tools: Save evsel->pmu in parse_events()

Message ID 20221014061550.463644-2-namhyung@kernel.org
State New
Headers
Series perf stat: Cleanup counter aggregation (v2) |

Commit Message

Namhyung Kim Oct. 14, 2022, 6:15 a.m. UTC
  Now evsel has a pmu pointer, let's save the info and use it like in
evsel__find_pmu().

Acked-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/evsel.c        | 1 +
 tools/perf/util/parse-events.c | 1 +
 tools/perf/util/pmu.c          | 4 ++++
 3 files changed, 6 insertions(+)
  

Comments

Arnaldo Carvalho de Melo Oct. 15, 2022, 12:55 p.m. UTC | #1
Em Thu, Oct 13, 2022 at 11:15:32PM -0700, Namhyung Kim escreveu:
> Now evsel has a pmu pointer, let's save the info and use it like in
> evsel__find_pmu().

This one made 'perf test metricgroups' to fail, I removed it and that
test passes. Can you please double check?

I have all the other patches in my local perf/core branch and I'm
prepping up a pull req with those included to Linus, holler if you
disagree.

- Arnaldo
 
> Acked-by: Ian Rogers <irogers@google.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
>  tools/perf/util/evsel.c        | 1 +
>  tools/perf/util/parse-events.c | 1 +
>  tools/perf/util/pmu.c          | 4 ++++
>  3 files changed, 6 insertions(+)
> 
> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> index 76605fde3507..196f8e4859d7 100644
> --- a/tools/perf/util/evsel.c
> +++ b/tools/perf/util/evsel.c
> @@ -467,6 +467,7 @@ struct evsel *evsel__clone(struct evsel *orig)
>  	evsel->collect_stat = orig->collect_stat;
>  	evsel->weak_group = orig->weak_group;
>  	evsel->use_config_name = orig->use_config_name;
> +	evsel->pmu = orig->pmu;
>  
>  	if (evsel__copy_config_terms(evsel, orig) < 0)
>  		goto out_err;
> diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
> index 437389dacf48..9e704841273d 100644
> --- a/tools/perf/util/parse-events.c
> +++ b/tools/perf/util/parse-events.c
> @@ -263,6 +263,7 @@ __add_event(struct list_head *list, int *idx,
>  	evsel->core.own_cpus = perf_cpu_map__get(cpus);
>  	evsel->core.requires_cpu = pmu ? pmu->is_uncore : false;
>  	evsel->auto_merge_stats = auto_merge_stats;
> +	evsel->pmu = pmu;
>  
>  	if (name)
>  		evsel->name = strdup(name);
> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
> index 74a2cafb4e8d..15bf5943083a 100644
> --- a/tools/perf/util/pmu.c
> +++ b/tools/perf/util/pmu.c
> @@ -1048,11 +1048,15 @@ struct perf_pmu *evsel__find_pmu(struct evsel *evsel)
>  {
>  	struct perf_pmu *pmu = NULL;
>  
> +	if (evsel->pmu)
> +		return evsel->pmu;
> +
>  	while ((pmu = perf_pmu__scan(pmu)) != NULL) {
>  		if (pmu->type == evsel->core.attr.type)
>  			break;
>  	}
>  
> +	evsel->pmu = pmu;
>  	return pmu;
>  }
>  
> -- 
> 2.38.0.413.g74048e4d9e-goog
  

Patch

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 76605fde3507..196f8e4859d7 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -467,6 +467,7 @@  struct evsel *evsel__clone(struct evsel *orig)
 	evsel->collect_stat = orig->collect_stat;
 	evsel->weak_group = orig->weak_group;
 	evsel->use_config_name = orig->use_config_name;
+	evsel->pmu = orig->pmu;
 
 	if (evsel__copy_config_terms(evsel, orig) < 0)
 		goto out_err;
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 437389dacf48..9e704841273d 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -263,6 +263,7 @@  __add_event(struct list_head *list, int *idx,
 	evsel->core.own_cpus = perf_cpu_map__get(cpus);
 	evsel->core.requires_cpu = pmu ? pmu->is_uncore : false;
 	evsel->auto_merge_stats = auto_merge_stats;
+	evsel->pmu = pmu;
 
 	if (name)
 		evsel->name = strdup(name);
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 74a2cafb4e8d..15bf5943083a 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -1048,11 +1048,15 @@  struct perf_pmu *evsel__find_pmu(struct evsel *evsel)
 {
 	struct perf_pmu *pmu = NULL;
 
+	if (evsel->pmu)
+		return evsel->pmu;
+
 	while ((pmu = perf_pmu__scan(pmu)) != NULL) {
 		if (pmu->type == evsel->core.attr.type)
 			break;
 	}
 
+	evsel->pmu = pmu;
 	return pmu;
 }