[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YgaXEo6pOolljvo5@kernel.org>
Date: Fri, 11 Feb 2022 14:04:18 -0300
From: Arnaldo Carvalho de Melo <acme@...nel.org>
To: Ian Rogers <irogers@...gle.com>
Cc: Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...nel.org>,
Namhyung Kim <namhyung@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>,
Darren Hart <dvhart@...radead.org>,
Davidlohr Bueso <dave@...olabs.net>,
André Almeida <andrealmeid@...labora.com>,
James Clark <james.clark@....com>,
John Garry <john.garry@...wei.com>,
Riccardo Mancini <rickyman7@...il.com>,
Yury Norov <yury.norov@...il.com>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Jin Yao <yao.jin@...ux.intel.com>,
Adrian Hunter <adrian.hunter@...el.com>,
Leo Yan <leo.yan@...aro.org>, Andi Kleen <ak@...ux.intel.com>,
Thomas Richter <tmricht@...ux.ibm.com>,
Kan Liang <kan.liang@...ux.intel.com>,
Madhavan Srinivasan <maddy@...ux.ibm.com>,
Shunsuke Nakamura <nakamura.shun@...itsu.com>,
Song Liu <song@...nel.org>,
Masami Hiramatsu <mhiramat@...nel.org>,
Steven Rostedt <rostedt@...dmis.org>,
Miaoqian Lin <linmq006@...il.com>,
Stephen Brennan <stephen.s.brennan@...cle.com>,
Kajol Jain <kjain@...ux.ibm.com>,
Alexey Bayduraev <alexey.v.bayduraev@...ux.intel.com>,
German Gomez <german.gomez@....com>,
linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org,
Eric Dumazet <edumazet@...gle.com>,
Dmitry Vyukov <dvyukov@...gle.com>,
Hao Luo <haoluo@...gle.com>, eranian@...gle.com
Subject: Re: [PATCH v3 02/22] perf cpumap: Use for each loop
Em Fri, Feb 11, 2022 at 02:33:55AM -0800, Ian Rogers escreveu:
> Improve readability in perf_pmu__cpus_match by using
> perf_cpu_map__for_each_cpu.
>
> Signed-off-by: Ian Rogers <irogers@...gle.com>
> ---
> tools/perf/util/pmu.c | 14 ++++++--------
> 1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
> index 8dfbba15aeb8..9a1c7e63e663 100644
> --- a/tools/perf/util/pmu.c
> +++ b/tools/perf/util/pmu.c
> @@ -1998,7 +1998,8 @@ int perf_pmu__cpus_match(struct perf_pmu *pmu, struct perf_cpu_map *cpus,
> {
> struct perf_cpu_map *pmu_cpus = pmu->cpus;
> struct perf_cpu_map *matched_cpus, *unmatched_cpus;
> - int matched_nr = 0, unmatched_nr = 0;
> + struct perf_cpu cpu;
> + int i, matched_nr = 0, unmatched_nr = 0;
>
> matched_cpus = perf_cpu_map__default_new();
> if (!matched_cpus)
> @@ -2010,14 +2011,11 @@ int perf_pmu__cpus_match(struct perf_pmu *pmu, struct perf_cpu_map *cpus,
> return -1;
> }
>
> - for (int i = 0; i < cpus->nr; i++) {
> - int cpu;
> -
> - cpu = perf_cpu_map__idx(pmu_cpus, cpus->map[i]);
> - if (cpu == -1)
> - unmatched_cpus->map[unmatched_nr++] = cpus->map[i];
> + perf_cpu_map__for_each_cpu(cpu, i, cpus) {
I'm applying this patch, but I wonder if we couldn't remove the need for
pre-declaring the integer iterator, so that the previous patch hunk
wouldn't be needed.
> + if (!perf_cpu_map__has(pmu_cpus, cpu))
> + unmatched_cpus->map[unmatched_nr++] = cpu;
> else
> - matched_cpus->map[matched_nr++] = cpus->map[i];
> + matched_cpus->map[matched_nr++] = cpu;
> }
>
> unmatched_cpus->nr = unmatched_nr;
> --
> 2.35.1.265.g69c8d7142f-goog
--
- Arnaldo
Powered by blists - more mailing lists