libperf cpumap: Add for_each_cpu() that skips the "any CPU" case
authorIan Rogers <irogers@google.com>
Wed, 29 Nov 2023 06:02:02 +0000 (22:02 -0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 12 Dec 2023 17:55:13 +0000 (14:55 -0300)
When iterating CPUs in a CPU map it is often desirable to skip the "any
CPU" (aka dummy) case. Add a helper for this and use in builtin-record.

Reviewed-by: James Clark <james.clark@arm.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexandre Ghiti <alexghiti@rivosinc.com>
Cc: Andrew Jones <ajones@ventanamicro.com>
Cc: André Almeida <andrealmeid@igalia.com>
Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Cc: Atish Patra <atishp@rivosinc.com>
Cc: Changbin Du <changbin.du@huawei.com>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Paran Lee <p4ranlee@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Steinar H. Gunderson <sesse@google.com>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: Yang Jihong <yangjihong1@huawei.com>
Cc: Yang Li <yang.lee@linux.alibaba.com>
Cc: Yanteng Si <siyanteng@loongson.cn>
Cc: bpf@vger.kernel.org
Cc: coresight@lists.linaro.org
Cc: linux-arm-kernel@lists.infradead.org
Link: https://lore.kernel.org/r/20231129060211.1890454-6-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/lib/perf/include/perf/cpumap.h
tools/perf/builtin-record.c

index 9cf361fc5edcb4a8c3648efefd4eaa2ec1395d34..dbe0a7352b6487fa62b4d8523f300f98a5158af7 100644 (file)
@@ -64,6 +64,12 @@ LIBPERF_API bool perf_cpu_map__has_any_cpu(const struct perf_cpu_map *map);
             (idx) < perf_cpu_map__nr(cpus);                    \
             (idx)++, (cpu) = perf_cpu_map__cpu(cpus, idx))
 
+#define perf_cpu_map__for_each_cpu_skip_any(_cpu, idx, cpus)   \
+       for ((idx) = 0, (_cpu) = perf_cpu_map__cpu(cpus, idx);  \
+            (idx) < perf_cpu_map__nr(cpus);                    \
+            (idx)++, (_cpu) = perf_cpu_map__cpu(cpus, idx))    \
+               if ((_cpu).cpu != -1)
+
 #define perf_cpu_map__for_each_idx(idx, cpus)                          \
        for ((idx) = 0; (idx) < perf_cpu_map__nr(cpus); (idx)++)
 
index eb5a398ddb1d8da504420e5193e89928b34279bb..8a1002683fda27d3a59be9bdd9bb994d5256a02a 100644 (file)
@@ -3601,9 +3601,7 @@ static int record__mmap_cpu_mask_init(struct mmap_cpu_mask *mask, struct perf_cp
        if (cpu_map__is_dummy(cpus))
                return 0;
 
-       perf_cpu_map__for_each_cpu(cpu, idx, cpus) {
-               if (cpu.cpu == -1)
-                       continue;
+       perf_cpu_map__for_each_cpu_skip_any(cpu, idx, cpus) {
                /* Return ENODEV is input cpu is greater than max cpu */
                if ((unsigned long)cpu.cpu > mask->nbits)
                        return -ENODEV;