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

libperf cpumap: Replace usage of perf_cpu_map__new(NULL) with perf_cpu_map__new_online_cpus()

Passing NULL to perf_cpu_map__new() performs
perf_cpu_map__new_online_cpus(), just directly call
perf_cpu_map__new_online_cpus() to be more intention revealing.

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-5-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
effe957c 923ca62a

+32 -32
+1 -1
tools/lib/perf/Documentation/examples/sampling.c
··· 39 39 40 40 libperf_init(libperf_print); 41 41 42 - cpus = perf_cpu_map__new(NULL); 42 + cpus = perf_cpu_map__new_online_cpus(); 43 43 if (!cpus) { 44 44 fprintf(stderr, "failed to create cpus\n"); 45 45 return -1;
+1 -1
tools/lib/perf/Documentation/libperf-sampling.txt
··· 97 97 98 98 [source,c] 99 99 -- 100 - 42 cpus = perf_cpu_map__new(NULL); 100 + 42 cpus = perf_cpu_map__new_online_cpus(); 101 101 43 if (!cpus) { 102 102 44 fprintf(stderr, "failed to create cpus\n"); 103 103 45 return -1;
+1 -1
tools/lib/perf/evlist.c
··· 39 39 if (evsel->system_wide) { 40 40 /* System wide: set the cpu map of the evsel to all online CPUs. */ 41 41 perf_cpu_map__put(evsel->cpus); 42 - evsel->cpus = perf_cpu_map__new(NULL); 42 + evsel->cpus = perf_cpu_map__new_online_cpus(); 43 43 } else if (evlist->has_user_cpus && evsel->is_pmu_core) { 44 44 /* 45 45 * User requested CPUs on a core PMU, ensure the requested CPUs
+2 -2
tools/lib/perf/tests/test-evlist.c
··· 46 46 }; 47 47 int err, idx; 48 48 49 - cpus = perf_cpu_map__new(NULL); 49 + cpus = perf_cpu_map__new_online_cpus(); 50 50 __T("failed to create cpus", cpus); 51 51 52 52 evlist = perf_evlist__new(); ··· 350 350 351 351 attr.config = id; 352 352 353 - cpus = perf_cpu_map__new(NULL); 353 + cpus = perf_cpu_map__new_online_cpus(); 354 354 __T("failed to create cpus", cpus); 355 355 356 356 evlist = perf_evlist__new();
+1 -1
tools/lib/perf/tests/test-evsel.c
··· 27 27 }; 28 28 int err, idx; 29 29 30 - cpus = perf_cpu_map__new(NULL); 30 + cpus = perf_cpu_map__new_online_cpus(); 31 31 __T("failed to create cpus", cpus); 32 32 33 33 evsel = perf_evsel__new(&attr);
+3 -3
tools/perf/arch/arm/util/cs-etm.c
··· 199 199 { 200 200 int i, err = -EINVAL; 201 201 struct perf_cpu_map *event_cpus = evsel->evlist->core.user_requested_cpus; 202 - struct perf_cpu_map *online_cpus = perf_cpu_map__new(NULL); 202 + struct perf_cpu_map *online_cpus = perf_cpu_map__new_online_cpus(); 203 203 204 204 /* Set option of each CPU we have */ 205 205 for (i = 0; i < cpu__max_cpu().cpu; i++) { ··· 536 536 int i; 537 537 int etmv3 = 0, etmv4 = 0, ete = 0; 538 538 struct perf_cpu_map *event_cpus = evlist->core.user_requested_cpus; 539 - struct perf_cpu_map *online_cpus = perf_cpu_map__new(NULL); 539 + struct perf_cpu_map *online_cpus = perf_cpu_map__new_online_cpus(); 540 540 541 541 /* cpu map is not empty, we have specific CPUs to work with */ 542 542 if (!perf_cpu_map__has_any_cpu_or_is_empty(event_cpus)) { ··· 802 802 u64 nr_cpu, type; 803 803 struct perf_cpu_map *cpu_map; 804 804 struct perf_cpu_map *event_cpus = session->evlist->core.user_requested_cpus; 805 - struct perf_cpu_map *online_cpus = perf_cpu_map__new(NULL); 805 + struct perf_cpu_map *online_cpus = perf_cpu_map__new_online_cpus(); 806 806 struct cs_etm_recording *ptr = 807 807 container_of(itr, struct cs_etm_recording, itr); 808 808 struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu;
+1 -1
tools/perf/arch/arm64/util/header.c
··· 57 57 58 58 int get_cpuid(char *buf, size_t sz) 59 59 { 60 - struct perf_cpu_map *cpus = perf_cpu_map__new(NULL); 60 + struct perf_cpu_map *cpus = perf_cpu_map__new_online_cpus(); 61 61 int ret; 62 62 63 63 if (!cpus)
+1 -1
tools/perf/bench/epoll-ctl.c
··· 330 330 act.sa_sigaction = toggle_done; 331 331 sigaction(SIGINT, &act, NULL); 332 332 333 - cpu = perf_cpu_map__new(NULL); 333 + cpu = perf_cpu_map__new_online_cpus(); 334 334 if (!cpu) 335 335 goto errmem; 336 336
+1 -1
tools/perf/bench/epoll-wait.c
··· 444 444 act.sa_sigaction = toggle_done; 445 445 sigaction(SIGINT, &act, NULL); 446 446 447 - cpu = perf_cpu_map__new(NULL); 447 + cpu = perf_cpu_map__new_online_cpus(); 448 448 if (!cpu) 449 449 goto errmem; 450 450
+1 -1
tools/perf/bench/futex-hash.c
··· 138 138 exit(EXIT_FAILURE); 139 139 } 140 140 141 - cpu = perf_cpu_map__new(NULL); 141 + cpu = perf_cpu_map__new_online_cpus(); 142 142 if (!cpu) 143 143 goto errmem; 144 144
+1 -1
tools/perf/bench/futex-lock-pi.c
··· 172 172 if (argc) 173 173 goto err; 174 174 175 - cpu = perf_cpu_map__new(NULL); 175 + cpu = perf_cpu_map__new_online_cpus(); 176 176 if (!cpu) 177 177 err(EXIT_FAILURE, "calloc"); 178 178
+1 -1
tools/perf/bench/futex-requeue.c
··· 174 174 if (argc) 175 175 goto err; 176 176 177 - cpu = perf_cpu_map__new(NULL); 177 + cpu = perf_cpu_map__new_online_cpus(); 178 178 if (!cpu) 179 179 err(EXIT_FAILURE, "cpu_map__new"); 180 180
+1 -1
tools/perf/bench/futex-wake-parallel.c
··· 264 264 err(EXIT_FAILURE, "mlockall"); 265 265 } 266 266 267 - cpu = perf_cpu_map__new(NULL); 267 + cpu = perf_cpu_map__new_online_cpus(); 268 268 if (!cpu) 269 269 err(EXIT_FAILURE, "calloc"); 270 270
+1 -1
tools/perf/bench/futex-wake.c
··· 149 149 exit(EXIT_FAILURE); 150 150 } 151 151 152 - cpu = perf_cpu_map__new(NULL); 152 + cpu = perf_cpu_map__new_online_cpus(); 153 153 if (!cpu) 154 154 err(EXIT_FAILURE, "calloc"); 155 155
+1 -1
tools/perf/builtin-ftrace.c
··· 333 333 334 334 static int reset_tracing_cpu(void) 335 335 { 336 - struct perf_cpu_map *cpumap = perf_cpu_map__new(NULL); 336 + struct perf_cpu_map *cpumap = perf_cpu_map__new_online_cpus(); 337 337 int ret; 338 338 339 339 ret = set_tracing_cpumask(cpumap);
+1 -1
tools/perf/tests/code-reading.c
··· 610 610 goto out_put; 611 611 } 612 612 613 - cpus = perf_cpu_map__new(NULL); 613 + cpus = perf_cpu_map__new_online_cpus(); 614 614 if (!cpus) { 615 615 pr_debug("perf_cpu_map__new failed\n"); 616 616 goto out_put;
+1 -1
tools/perf/tests/keep-tracking.c
··· 81 81 threads = thread_map__new(-1, getpid(), UINT_MAX); 82 82 CHECK_NOT_NULL__(threads); 83 83 84 - cpus = perf_cpu_map__new(NULL); 84 + cpus = perf_cpu_map__new_online_cpus(); 85 85 CHECK_NOT_NULL__(cpus); 86 86 87 87 evlist = evlist__new();
+1 -1
tools/perf/tests/mmap-basic.c
··· 52 52 return -1; 53 53 } 54 54 55 - cpus = perf_cpu_map__new(NULL); 55 + cpus = perf_cpu_map__new_online_cpus(); 56 56 if (cpus == NULL) { 57 57 pr_debug("perf_cpu_map__new\n"); 58 58 goto out_free_threads;
+1 -1
tools/perf/tests/openat-syscall-all-cpus.c
··· 37 37 return -1; 38 38 } 39 39 40 - cpus = perf_cpu_map__new(NULL); 40 + cpus = perf_cpu_map__new_online_cpus(); 41 41 if (cpus == NULL) { 42 42 pr_debug("perf_cpu_map__new\n"); 43 43 goto out_thread_map_delete;
+1 -1
tools/perf/tests/perf-time-to-tsc.c
··· 93 93 threads = thread_map__new(-1, getpid(), UINT_MAX); 94 94 CHECK_NOT_NULL__(threads); 95 95 96 - cpus = perf_cpu_map__new(NULL); 96 + cpus = perf_cpu_map__new_online_cpus(); 97 97 CHECK_NOT_NULL__(cpus); 98 98 99 99 evlist = evlist__new();
+1 -1
tools/perf/tests/switch-tracking.c
··· 351 351 goto out_err; 352 352 } 353 353 354 - cpus = perf_cpu_map__new(NULL); 354 + cpus = perf_cpu_map__new_online_cpus(); 355 355 if (!cpus) { 356 356 pr_debug("perf_cpu_map__new failed!\n"); 357 357 goto out_err;
+1 -1
tools/perf/tests/topology.c
··· 215 215 if (session_write_header(path)) 216 216 goto free_path; 217 217 218 - map = perf_cpu_map__new(NULL); 218 + map = perf_cpu_map__new_online_cpus(); 219 219 if (map == NULL) { 220 220 pr_debug("failed to get system cpumap\n"); 221 221 goto free_path;
+1 -1
tools/perf/util/bpf_counter.c
··· 455 455 return -1; 456 456 457 457 if (!all_cpu_map) { 458 - all_cpu_map = perf_cpu_map__new(NULL); 458 + all_cpu_map = perf_cpu_map__new_online_cpus(); 459 459 if (!all_cpu_map) 460 460 return -1; 461 461 }
+1 -1
tools/perf/util/cpumap.c
··· 672 672 static struct perf_cpu_map *online; 673 673 674 674 if (!online) 675 - online = perf_cpu_map__new(NULL); /* from /sys/devices/system/cpu/online */ 675 + online = perf_cpu_map__new_online_cpus(); /* from /sys/devices/system/cpu/online */ 676 676 677 677 return online; 678 678 }
+1 -1
tools/perf/util/cputopo.c
··· 267 267 ncpus = cpu__max_present_cpu().cpu; 268 268 269 269 /* build online CPU map */ 270 - map = perf_cpu_map__new(NULL); 270 + map = perf_cpu_map__new_online_cpus(); 271 271 if (map == NULL) { 272 272 pr_debug("failed to get system cpumap\n"); 273 273 return NULL;
+1 -1
tools/perf/util/evlist.c
··· 1352 1352 * error, and we may not want to do that fallback to a 1353 1353 * default cpu identity map :-\ 1354 1354 */ 1355 - cpus = perf_cpu_map__new(NULL); 1355 + cpus = perf_cpu_map__new_online_cpus(); 1356 1356 if (!cpus) 1357 1357 goto out; 1358 1358
+2 -2
tools/perf/util/perf_api_probe.c
··· 64 64 struct perf_cpu cpu; 65 65 int ret, i = 0; 66 66 67 - cpus = perf_cpu_map__new(NULL); 67 + cpus = perf_cpu_map__new_online_cpus(); 68 68 if (!cpus) 69 69 return false; 70 70 cpu = perf_cpu_map__cpu(cpus, 0); ··· 140 140 struct perf_cpu cpu; 141 141 int fd; 142 142 143 - cpus = perf_cpu_map__new(NULL); 143 + cpus = perf_cpu_map__new_online_cpus(); 144 144 if (!cpus) 145 145 return false; 146 146
+1 -1
tools/perf/util/record.c
··· 238 238 evsel = evlist__last(temp_evlist); 239 239 240 240 if (!evlist || perf_cpu_map__has_any_cpu_or_is_empty(evlist->core.user_requested_cpus)) { 241 - struct perf_cpu_map *cpus = perf_cpu_map__new(NULL); 241 + struct perf_cpu_map *cpus = perf_cpu_map__new_online_cpus(); 242 242 243 243 if (cpus) 244 244 cpu = perf_cpu_map__cpu(cpus, 0);