All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] perf evlist: Avoid iteration for empty evlist.
@ 2022-03-17 23:16 Ian Rogers
  2022-03-18 14:26 ` Arnaldo Carvalho de Melo
  2022-03-18 20:40 ` Jiri Olsa
  0 siblings, 2 replies; 3+ messages in thread
From: Ian Rogers @ 2022-03-17 23:16 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Adrian Hunter,
	Linux Kernel Mailing List
  Cc: Ian Rogers

As seen with 'perf stat --null ..' and reported in:
https://lore.kernel.org/lkml/YjCLcpcX2peeQVCH@kernel.org/

v2. Avoids setting evsel in the empty list case as suggested by Jiri
    Olsa <jolsa@kernel.org>.
Fixes: 472832d2c000 ("perf evlist: Refactor evlist__for_each_cpu()")
Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/evlist.c | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 8134d45e2164..9bb79e049957 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -346,7 +346,7 @@ struct evlist_cpu_iterator evlist__cpu_begin(struct evlist *evlist, struct affin
 {
 	struct evlist_cpu_iterator itr = {
 		.container = evlist,
-		.evsel = evlist__first(evlist),
+		.evsel = NULL,
 		.cpu_map_idx = 0,
 		.evlist_cpu_map_idx = 0,
 		.evlist_cpu_map_nr = perf_cpu_map__nr(evlist->core.all_cpus),
@@ -354,16 +354,22 @@ struct evlist_cpu_iterator evlist__cpu_begin(struct evlist *evlist, struct affin
 		.affinity = affinity,
 	};
 
-	if (itr.affinity) {
-		itr.cpu = perf_cpu_map__cpu(evlist->core.all_cpus, 0);
-		affinity__set(itr.affinity, itr.cpu.cpu);
-		itr.cpu_map_idx = perf_cpu_map__idx(itr.evsel->core.cpus, itr.cpu);
-		/*
-		 * If this CPU isn't in the evsel's cpu map then advance through
-		 * the list.
-		 */
-		if (itr.cpu_map_idx == -1)
-			evlist_cpu_iterator__next(&itr);
+	if (evlist__empty(evlist)) {
+		/* Ensure the empty list doesn't iterate. */
+		itr.evlist_cpu_map_idx = itr.evlist_cpu_map_nr;
+	} else {
+		itr.evsel = evlist__first(evlist);
+		if (itr.affinity) {
+			itr.cpu = perf_cpu_map__cpu(evlist->core.all_cpus, 0);
+			affinity__set(itr.affinity, itr.cpu.cpu);
+			itr.cpu_map_idx = perf_cpu_map__idx(itr.evsel->core.cpus, itr.cpu);
+			/*
+			 * If this CPU isn't in the evsel's cpu map then advance
+			 * through the list.
+			 */
+			if (itr.cpu_map_idx == -1)
+				evlist_cpu_iterator__next(&itr);
+		}
 	}
 	return itr;
 }
-- 
2.35.1.894.gb6a874cedc-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] perf evlist: Avoid iteration for empty evlist.
  2022-03-17 23:16 [PATCH v2] perf evlist: Avoid iteration for empty evlist Ian Rogers
@ 2022-03-18 14:26 ` Arnaldo Carvalho de Melo
  2022-03-18 20:40 ` Jiri Olsa
  1 sibling, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2022-03-18 14:26 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Namhyung Kim, Jiri Olsa, Adrian Hunter, Linux Kernel Mailing List

Em Thu, Mar 17, 2022 at 04:16:43PM -0700, Ian Rogers escreveu:
> As seen with 'perf stat --null ..' and reported in:
> https://lore.kernel.org/lkml/YjCLcpcX2peeQVCH@kernel.org/
> 
> v2. Avoids setting evsel in the empty list case as suggested by Jiri
>     Olsa <jolsa@kernel.org>.
> Fixes: 472832d2c000 ("perf evlist: Refactor evlist__for_each_cpu()")
> Signed-off-by: Ian Rogers <irogers@google.com>

Thanks, replaced v1 with this new one.

- Arnaldo

> ---
>  tools/perf/util/evlist.c | 28 +++++++++++++++++-----------
>  1 file changed, 17 insertions(+), 11 deletions(-)
> 
> diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
> index 8134d45e2164..9bb79e049957 100644
> --- a/tools/perf/util/evlist.c
> +++ b/tools/perf/util/evlist.c
> @@ -346,7 +346,7 @@ struct evlist_cpu_iterator evlist__cpu_begin(struct evlist *evlist, struct affin
>  {
>  	struct evlist_cpu_iterator itr = {
>  		.container = evlist,
> -		.evsel = evlist__first(evlist),
> +		.evsel = NULL,
>  		.cpu_map_idx = 0,
>  		.evlist_cpu_map_idx = 0,
>  		.evlist_cpu_map_nr = perf_cpu_map__nr(evlist->core.all_cpus),
> @@ -354,16 +354,22 @@ struct evlist_cpu_iterator evlist__cpu_begin(struct evlist *evlist, struct affin
>  		.affinity = affinity,
>  	};
>  
> -	if (itr.affinity) {
> -		itr.cpu = perf_cpu_map__cpu(evlist->core.all_cpus, 0);
> -		affinity__set(itr.affinity, itr.cpu.cpu);
> -		itr.cpu_map_idx = perf_cpu_map__idx(itr.evsel->core.cpus, itr.cpu);
> -		/*
> -		 * If this CPU isn't in the evsel's cpu map then advance through
> -		 * the list.
> -		 */
> -		if (itr.cpu_map_idx == -1)
> -			evlist_cpu_iterator__next(&itr);
> +	if (evlist__empty(evlist)) {
> +		/* Ensure the empty list doesn't iterate. */
> +		itr.evlist_cpu_map_idx = itr.evlist_cpu_map_nr;
> +	} else {
> +		itr.evsel = evlist__first(evlist);
> +		if (itr.affinity) {
> +			itr.cpu = perf_cpu_map__cpu(evlist->core.all_cpus, 0);
> +			affinity__set(itr.affinity, itr.cpu.cpu);
> +			itr.cpu_map_idx = perf_cpu_map__idx(itr.evsel->core.cpus, itr.cpu);
> +			/*
> +			 * If this CPU isn't in the evsel's cpu map then advance
> +			 * through the list.
> +			 */
> +			if (itr.cpu_map_idx == -1)
> +				evlist_cpu_iterator__next(&itr);
> +		}
>  	}
>  	return itr;
>  }
> -- 
> 2.35.1.894.gb6a874cedc-goog

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] perf evlist: Avoid iteration for empty evlist.
  2022-03-17 23:16 [PATCH v2] perf evlist: Avoid iteration for empty evlist Ian Rogers
  2022-03-18 14:26 ` Arnaldo Carvalho de Melo
@ 2022-03-18 20:40 ` Jiri Olsa
  1 sibling, 0 replies; 3+ messages in thread
From: Jiri Olsa @ 2022-03-18 20:40 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Adrian Hunter,
	Linux Kernel Mailing List

On Thu, Mar 17, 2022 at 04:16:43PM -0700, Ian Rogers wrote:
> As seen with 'perf stat --null ..' and reported in:
> https://lore.kernel.org/lkml/YjCLcpcX2peeQVCH@kernel.org/
> 
> v2. Avoids setting evsel in the empty list case as suggested by Jiri
>     Olsa <jolsa@kernel.org>.
> Fixes: 472832d2c000 ("perf evlist: Refactor evlist__for_each_cpu()")
> Signed-off-by: Ian Rogers <irogers@google.com>

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

> ---
>  tools/perf/util/evlist.c | 28 +++++++++++++++++-----------
>  1 file changed, 17 insertions(+), 11 deletions(-)
> 
> diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
> index 8134d45e2164..9bb79e049957 100644
> --- a/tools/perf/util/evlist.c
> +++ b/tools/perf/util/evlist.c
> @@ -346,7 +346,7 @@ struct evlist_cpu_iterator evlist__cpu_begin(struct evlist *evlist, struct affin
>  {
>  	struct evlist_cpu_iterator itr = {
>  		.container = evlist,
> -		.evsel = evlist__first(evlist),
> +		.evsel = NULL,
>  		.cpu_map_idx = 0,
>  		.evlist_cpu_map_idx = 0,
>  		.evlist_cpu_map_nr = perf_cpu_map__nr(evlist->core.all_cpus),
> @@ -354,16 +354,22 @@ struct evlist_cpu_iterator evlist__cpu_begin(struct evlist *evlist, struct affin
>  		.affinity = affinity,
>  	};
>  
> -	if (itr.affinity) {
> -		itr.cpu = perf_cpu_map__cpu(evlist->core.all_cpus, 0);
> -		affinity__set(itr.affinity, itr.cpu.cpu);
> -		itr.cpu_map_idx = perf_cpu_map__idx(itr.evsel->core.cpus, itr.cpu);
> -		/*
> -		 * If this CPU isn't in the evsel's cpu map then advance through
> -		 * the list.
> -		 */
> -		if (itr.cpu_map_idx == -1)
> -			evlist_cpu_iterator__next(&itr);
> +	if (evlist__empty(evlist)) {
> +		/* Ensure the empty list doesn't iterate. */
> +		itr.evlist_cpu_map_idx = itr.evlist_cpu_map_nr;
> +	} else {
> +		itr.evsel = evlist__first(evlist);
> +		if (itr.affinity) {
> +			itr.cpu = perf_cpu_map__cpu(evlist->core.all_cpus, 0);
> +			affinity__set(itr.affinity, itr.cpu.cpu);
> +			itr.cpu_map_idx = perf_cpu_map__idx(itr.evsel->core.cpus, itr.cpu);
> +			/*
> +			 * If this CPU isn't in the evsel's cpu map then advance
> +			 * through the list.
> +			 */
> +			if (itr.cpu_map_idx == -1)
> +				evlist_cpu_iterator__next(&itr);
> +		}
>  	}
>  	return itr;
>  }
> -- 
> 2.35.1.894.gb6a874cedc-goog
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-03-18 20:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-17 23:16 [PATCH v2] perf evlist: Avoid iteration for empty evlist Ian Rogers
2022-03-18 14:26 ` Arnaldo Carvalho de Melo
2022-03-18 20:40 ` Jiri Olsa

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.