[RFC PATCH 09/25] perf stat: Add helper functions for hardware-grouping method

weilin.wang@intel.com posted 25 patches 2 years, 4 months ago
There is a newer version of this series
[RFC PATCH 09/25] perf stat: Add helper functions for hardware-grouping method
Posted by weilin.wang@intel.com 2 years, 4 months ago
From: Weilin Wang <weilin.wang@intel.com>

Add functions to free pmu_info_list and event_info_list before exit
grouping

Signed-off-by: Weilin Wang <weilin.wang@intel.com>
---
 tools/perf/util/metricgroup.c | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
index feb5dab26..0ca885a42 100644
--- a/tools/perf/util/metricgroup.c
+++ b/tools/perf/util/metricgroup.c
@@ -1507,6 +1507,27 @@ static int parse_counter(const char *counter,
 	return 0;
 }
 
+static void metricgroup__free_event_info(struct list_head
+					*event_info_list)
+{
+	struct metricgroup__event_info *e, *tmp;
+
+	list_for_each_entry_safe(e, tmp, event_info_list, nd) {
+		list_del_init(&e->nd);
+		free(e);
+	}
+}
+
+static void metricgroup__free_pmu_info(struct list_head *pmu_info_list)
+{
+	struct metricgroup__pmu_counters *p, *tmp;
+
+	list_for_each_entry_safe(p, tmp, pmu_info_list, nd) {
+		list_del_init(&p->nd);
+		free(p);
+	}
+}
+
 static struct metricgroup__event_info *event_info__new(const char *name,
 						      const char *pmu_name,
 						      const char *counter,
@@ -1524,7 +1545,8 @@ static struct metricgroup__event_info *event_info__new(const char *name,
 	}
 	e->name = name;
 	e->free_counter = free_counter;
-	e->pmu_name = strdup(pmu_name);
+	//e->pmu_name = strdup(pmu_name);
+	e->pmu_name = pmu_name;
 	if (free_counter) {
 		ret = set_counter_bitmap(0, e->counters);
 		if (ret)
@@ -1687,13 +1709,15 @@ static int hw_aware_build_grouping(struct expr_parse_ctx *ctx __maybe_unused,
 
 		ret = get_metricgroup_events(id, etable, &event_info_list);
 		if (ret)
-			return ret;
+			goto err_out;
 	}
 	ret = get_pmu_counter_layouts(&pmu_info_list, ltable);
 	if (ret)
-		return ret;
-
+		goto err_out;
 
+err_out:
+	metricgroup__free_event_info(&event_info_list);
+	metricgroup__free_pmu_info(&pmu_info_list);
 	return ret;
 #undef RETURN_IF_NON_ZERO
 }
-- 
2.39.3
Re: [RFC PATCH 09/25] perf stat: Add helper functions for hardware-grouping method
Posted by Yang Jihong 2 years, 4 months ago
Hello,

On 2023/9/25 14:18, weilin.wang@intel.com wrote:
> From: Weilin Wang <weilin.wang@intel.com>
> 
> Add functions to free pmu_info_list and event_info_list before exit
> grouping
> 
> Signed-off-by: Weilin Wang <weilin.wang@intel.com>
> ---
>   tools/perf/util/metricgroup.c | 32 ++++++++++++++++++++++++++++----
>   1 file changed, 28 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
> index feb5dab26..0ca885a42 100644
> --- a/tools/perf/util/metricgroup.c
> +++ b/tools/perf/util/metricgroup.c
> @@ -1507,6 +1507,27 @@ static int parse_counter(const char *counter,
>   	return 0;
>   }
>   
> +static void metricgroup__free_event_info(struct list_head
> +					*event_info_list)
> +{
> +	struct metricgroup__event_info *e, *tmp;
> +
> +	list_for_each_entry_safe(e, tmp, event_info_list, nd) {
> +		list_del_init(&e->nd);
> +		free(e);
> +	}
> +}
> +
> +static void metricgroup__free_pmu_info(struct list_head *pmu_info_list)
> +{
> +	struct metricgroup__pmu_counters *p, *tmp;
> +
> +	list_for_each_entry_safe(p, tmp, pmu_info_list, nd) {
> +		list_del_init(&p->nd);
> +		free(p);
> +	}
> +}
> +
>   static struct metricgroup__event_info *event_info__new(const char *name,
>   						      const char *pmu_name,
>   						      const char *counter,
> @@ -1524,7 +1545,8 @@ static struct metricgroup__event_info *event_info__new(const char *name,
>   	}
>   	e->name = name;
>   	e->free_counter = free_counter;
> -	e->pmu_name = strdup(pmu_name);
> +	//e->pmu_name = strdup(pmu_name);
Can the commented-out code be deleted?

> +	e->pmu_name = pmu_name;
>   	if (free_counter) {
>   		ret = set_counter_bitmap(0, e->counters);
>   		if (ret)
> @@ -1687,13 +1709,15 @@ static int hw_aware_build_grouping(struct expr_parse_ctx *ctx __maybe_unused,
>   
>   		ret = get_metricgroup_events(id, etable, &event_info_list);
>   		if (ret)
> -			return ret;
> +			goto err_out;
>   	}
>   	ret = get_pmu_counter_layouts(&pmu_info_list, ltable);
>   	if (ret)
> -		return ret;
> -
> +		goto err_out;
There seems to be no need for "goto err_out" here.

>   
> +err_out:
> +	metricgroup__free_event_info(&event_info_list);
> +	metricgroup__free_pmu_info(&pmu_info_list);
>   	return ret;
>   #undef RETURN_IF_NON_ZERO
>   }
> 


Thanks,
Yang
RE: [RFC PATCH 09/25] perf stat: Add helper functions for hardware-grouping method
Posted by Wang, Weilin 2 years, 4 months ago

> -----Original Message-----
> From: Yang Jihong <yangjihong1@huawei.com>
> Sent: Monday, September 25, 2023 8:37 PM
> To: Wang, Weilin <weilin.wang@intel.com>; Ian Rogers
> <irogers@google.com>; Peter Zijlstra <peterz@infradead.org>; Ingo Molnar
> <mingo@redhat.com>; Arnaldo Carvalho de Melo <acme@kernel.org>;
> Alexander Shishkin <alexander.shishkin@linux.intel.com>; Jiri Olsa
> <jolsa@kernel.org>; Namhyung Kim <namhyung@kernel.org>; Hunter, Adrian
> <adrian.hunter@intel.com>; Kan Liang <kan.liang@linux.intel.com>
> Cc: linux-perf-users@vger.kernel.org; linux-kernel@vger.kernel.org; Taylor,
> Perry <perry.taylor@intel.com>; Alt, Samantha <samantha.alt@intel.com>;
> Biggers, Caleb <caleb.biggers@intel.com>; Mark Rutland
> <mark.rutland@arm.com>
> Subject: Re: [RFC PATCH 09/25] perf stat: Add helper functions for hardware-
> grouping method
> 
> Hello,
> 
> On 2023/9/25 14:18, weilin.wang@intel.com wrote:
> > From: Weilin Wang <weilin.wang@intel.com>
> >
> > Add functions to free pmu_info_list and event_info_list before exit
> > grouping
> >
> > Signed-off-by: Weilin Wang <weilin.wang@intel.com>
> > ---
> >   tools/perf/util/metricgroup.c | 32 ++++++++++++++++++++++++++++----
> >   1 file changed, 28 insertions(+), 4 deletions(-)
> >
> > diff --git a/tools/perf/util/metricgroup.c
> > b/tools/perf/util/metricgroup.c index feb5dab26..0ca885a42 100644
> > --- a/tools/perf/util/metricgroup.c
> > +++ b/tools/perf/util/metricgroup.c
> > @@ -1507,6 +1507,27 @@ static int parse_counter(const char *counter,
> >   	return 0;
> >   }
> >
> > +static void metricgroup__free_event_info(struct list_head
> > +					*event_info_list)
> > +{
> > +	struct metricgroup__event_info *e, *tmp;
> > +
> > +	list_for_each_entry_safe(e, tmp, event_info_list, nd) {
> > +		list_del_init(&e->nd);
> > +		free(e);
> > +	}
> > +}
> > +
> > +static void metricgroup__free_pmu_info(struct list_head
> > +*pmu_info_list) {
> > +	struct metricgroup__pmu_counters *p, *tmp;
> > +
> > +	list_for_each_entry_safe(p, tmp, pmu_info_list, nd) {
> > +		list_del_init(&p->nd);
> > +		free(p);
> > +	}
> > +}
> > +
> >   static struct metricgroup__event_info *event_info__new(const char *name,
> >   						      const char *pmu_name,
> >   						      const char *counter,
> > @@ -1524,7 +1545,8 @@ static struct metricgroup__event_info
> *event_info__new(const char *name,
> >   	}
> >   	e->name = name;
> >   	e->free_counter = free_counter;
> > -	e->pmu_name = strdup(pmu_name);
> > +	//e->pmu_name = strdup(pmu_name);
> Can the commented-out code be deleted?
> 
> > +	e->pmu_name = pmu_name;
> >   	if (free_counter) {
> >   		ret = set_counter_bitmap(0, e->counters);
> >   		if (ret)
> > @@ -1687,13 +1709,15 @@ static int hw_aware_build_grouping(struct
> > expr_parse_ctx *ctx __maybe_unused,
> >
> >   		ret = get_metricgroup_events(id, etable, &event_info_list);
> >   		if (ret)
> > -			return ret;
> > +			goto err_out;
> >   	}
> >   	ret = get_pmu_counter_layouts(&pmu_info_list, ltable);
> >   	if (ret)
> > -		return ret;
> > -
> > +		goto err_out;
> There seems to be no need for "goto err_out" here.

Hi, Yang. Thanks for being interested! I will update the code based on all the comments I received so far. 
Please also let me know if you have any suggestions or comments on the grouping method. 

Thanks,
Weilin

> 
> >
> > +err_out:
> > +	metricgroup__free_event_info(&event_info_list);
> > +	metricgroup__free_pmu_info(&pmu_info_list);
> >   	return ret;
> >   #undef RETURN_IF_NON_ZERO
> >   }
> >
> 
> 
> Thanks,
> Yang