Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf cpumap: Use for each loop

Improve readability in perf_pmu__cpus_match() by using
perf_cpu_map__for_each_cpu().

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: André Almeida <andrealmeid@collabora.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: German Gomez <german.gomez@arm.com>
Cc: Hao Luo <haoluo@google.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Miaoqian Lin <linmq006@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Shunsuke Nakamura <nakamura.shun@fujitsu.com>
Cc: Song Liu <song@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Stephen Brennan <stephen.s.brennan@oracle.com>
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Yury Norov <yury.norov@gmail.com>
Link: http://lore.kernel.org/lkml/20220211103415.2737789-3-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
6a12a63e c56c3927

+6 -8
+6 -8
tools/perf/util/pmu.c
··· 1998 1998 { 1999 1999 struct perf_cpu_map *pmu_cpus = pmu->cpus; 2000 2000 struct perf_cpu_map *matched_cpus, *unmatched_cpus; 2001 - int matched_nr = 0, unmatched_nr = 0; 2001 + struct perf_cpu cpu; 2002 + int i, matched_nr = 0, unmatched_nr = 0; 2002 2003 2003 2004 matched_cpus = perf_cpu_map__default_new(); 2004 2005 if (!matched_cpus) ··· 2011 2010 return -1; 2012 2011 } 2013 2012 2014 - for (int i = 0; i < cpus->nr; i++) { 2015 - int cpu; 2016 - 2017 - cpu = perf_cpu_map__idx(pmu_cpus, cpus->map[i]); 2018 - if (cpu == -1) 2019 - unmatched_cpus->map[unmatched_nr++] = cpus->map[i]; 2013 + perf_cpu_map__for_each_cpu(cpu, i, cpus) { 2014 + if (!perf_cpu_map__has(pmu_cpus, cpu)) 2015 + unmatched_cpus->map[unmatched_nr++] = cpu; 2020 2016 else 2021 - matched_cpus->map[matched_nr++] = cpus->map[i]; 2017 + matched_cpus->map[matched_nr++] = cpu; 2022 2018 } 2023 2019 2024 2020 unmatched_cpus->nr = unmatched_nr;