perf evlist: Rename cpus to user_requested_cpus

evlist contains cpus and all_cpus. all_cpus is the union of the cpu maps
of all evsels.

For non-task targets, cpus is set to be cpus requested from the command
line, defaulting to all online cpus if no cpus are specified.

For an uncore event, all_cpus may be just CPU 0 or every online CPU.

This causes all_cpus to have fewer values than the cpus variable which
is confusing given the 'all' in the name.

To try to make the behavior clearer, rename cpus to user_requested_cpus
and add comments on the two struct variables.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: German Gomez <german.gomez@arm.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Fastabend <john.fastabend@gmail.com>
Cc: John Garry <john.garry@huawei.com>
Cc: KP Singh <kpsingh@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Martin KaFai Lau <kafai@fb.com>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Yonghong Song <yhs@fb.com>
Cc: bpf@vger.kernel.org
Cc: coresight@lists.linaro.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: netdev@vger.kernel.org
Link: http://lore.kernel.org/lkml/20220328232648.2127340-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 0df6ade7 d4ff9265

+62 -53
+14 -14
tools/lib/perf/evlist.c
··· 41 41 */ 42 42 if (!evsel->own_cpus || evlist->has_user_cpus) { 43 43 perf_cpu_map__put(evsel->cpus); 44 - evsel->cpus = perf_cpu_map__get(evlist->cpus); 45 - } else if (!evsel->system_wide && perf_cpu_map__empty(evlist->cpus)) { 44 + evsel->cpus = perf_cpu_map__get(evlist->user_requested_cpus); 45 + } else if (!evsel->system_wide && perf_cpu_map__empty(evlist->user_requested_cpus)) { 46 46 perf_cpu_map__put(evsel->cpus); 47 - evsel->cpus = perf_cpu_map__get(evlist->cpus); 47 + evsel->cpus = perf_cpu_map__get(evlist->user_requested_cpus); 48 48 } else if (evsel->cpus != evsel->own_cpus) { 49 49 perf_cpu_map__put(evsel->cpus); 50 50 evsel->cpus = perf_cpu_map__get(evsel->own_cpus); ··· 123 123 124 124 void perf_evlist__exit(struct perf_evlist *evlist) 125 125 { 126 - perf_cpu_map__put(evlist->cpus); 126 + perf_cpu_map__put(evlist->user_requested_cpus); 127 127 perf_cpu_map__put(evlist->all_cpus); 128 128 perf_thread_map__put(evlist->threads); 129 - evlist->cpus = NULL; 129 + evlist->user_requested_cpus = NULL; 130 130 evlist->all_cpus = NULL; 131 131 evlist->threads = NULL; 132 132 fdarray__exit(&evlist->pollfd); ··· 155 155 * original reference count of 1. If that is not the case it is up to 156 156 * the caller to increase the reference count. 157 157 */ 158 - if (cpus != evlist->cpus) { 159 - perf_cpu_map__put(evlist->cpus); 160 - evlist->cpus = perf_cpu_map__get(cpus); 158 + if (cpus != evlist->user_requested_cpus) { 159 + perf_cpu_map__put(evlist->user_requested_cpus); 160 + evlist->user_requested_cpus = perf_cpu_map__get(cpus); 161 161 } 162 162 163 163 if (threads != evlist->threads) { ··· 294 294 295 295 int perf_evlist__alloc_pollfd(struct perf_evlist *evlist) 296 296 { 297 - int nr_cpus = perf_cpu_map__nr(evlist->cpus); 297 + int nr_cpus = perf_cpu_map__nr(evlist->user_requested_cpus); 298 298 int nr_threads = perf_thread_map__nr(evlist->threads); 299 299 int nfds = 0; 300 300 struct perf_evsel *evsel; ··· 426 426 int idx, struct perf_mmap_param *mp, int cpu_idx, 427 427 int thread, int *_output, int *_output_overwrite) 428 428 { 429 - struct perf_cpu evlist_cpu = perf_cpu_map__cpu(evlist->cpus, cpu_idx); 429 + struct perf_cpu evlist_cpu = perf_cpu_map__cpu(evlist->user_requested_cpus, cpu_idx); 430 430 struct perf_evsel *evsel; 431 431 int revent; 432 432 ··· 536 536 struct perf_mmap_param *mp) 537 537 { 538 538 int nr_threads = perf_thread_map__nr(evlist->threads); 539 - int nr_cpus = perf_cpu_map__nr(evlist->cpus); 539 + int nr_cpus = perf_cpu_map__nr(evlist->user_requested_cpus); 540 540 int cpu, thread; 541 541 542 542 for (cpu = 0; cpu < nr_cpus; cpu++) { ··· 564 564 { 565 565 int nr_mmaps; 566 566 567 - nr_mmaps = perf_cpu_map__nr(evlist->cpus); 568 - if (perf_cpu_map__empty(evlist->cpus)) 567 + nr_mmaps = perf_cpu_map__nr(evlist->user_requested_cpus); 568 + if (perf_cpu_map__empty(evlist->user_requested_cpus)) 569 569 nr_mmaps = perf_thread_map__nr(evlist->threads); 570 570 571 571 return nr_mmaps; ··· 576 576 struct perf_mmap_param *mp) 577 577 { 578 578 struct perf_evsel *evsel; 579 - const struct perf_cpu_map *cpus = evlist->cpus; 579 + const struct perf_cpu_map *cpus = evlist->user_requested_cpus; 580 580 const struct perf_thread_map *threads = evlist->threads; 581 581 582 582 if (!ops || !ops->get || !ops->mmap)
+6 -1
tools/lib/perf/include/internal/evlist.h
··· 19 19 int nr_entries; 20 20 int nr_groups; 21 21 bool has_user_cpus; 22 - struct perf_cpu_map *cpus; 22 + /** 23 + * The cpus passed from the command line or all online CPUs by 24 + * default. 25 + */ 26 + struct perf_cpu_map *user_requested_cpus; 27 + /** The union of all evsel cpu maps. */ 23 28 struct perf_cpu_map *all_cpus; 24 29 struct perf_thread_map *threads; 25 30 int nr_mmaps;
+4 -4
tools/perf/arch/arm/util/cs-etm.c
··· 199 199 struct evsel *evsel, u32 option) 200 200 { 201 201 int i, err = -EINVAL; 202 - struct perf_cpu_map *event_cpus = evsel->evlist->core.cpus; 202 + struct perf_cpu_map *event_cpus = evsel->evlist->core.user_requested_cpus; 203 203 struct perf_cpu_map *online_cpus = perf_cpu_map__new(NULL); 204 204 205 205 /* Set option of each CPU we have */ ··· 299 299 container_of(itr, struct cs_etm_recording, itr); 300 300 struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu; 301 301 struct evsel *evsel, *cs_etm_evsel = NULL; 302 - struct perf_cpu_map *cpus = evlist->core.cpus; 302 + struct perf_cpu_map *cpus = evlist->core.user_requested_cpus; 303 303 bool privileged = perf_event_paranoid_check(-1); 304 304 int err = 0; 305 305 ··· 522 522 { 523 523 int i; 524 524 int etmv3 = 0, etmv4 = 0, ete = 0; 525 - struct perf_cpu_map *event_cpus = evlist->core.cpus; 525 + struct perf_cpu_map *event_cpus = evlist->core.user_requested_cpus; 526 526 struct perf_cpu_map *online_cpus = perf_cpu_map__new(NULL); 527 527 528 528 /* cpu map is not empty, we have specific CPUs to work with */ ··· 713 713 u32 offset; 714 714 u64 nr_cpu, type; 715 715 struct perf_cpu_map *cpu_map; 716 - struct perf_cpu_map *event_cpus = session->evlist->core.cpus; 716 + struct perf_cpu_map *event_cpus = session->evlist->core.user_requested_cpus; 717 717 struct perf_cpu_map *online_cpus = perf_cpu_map__new(NULL); 718 718 struct cs_etm_recording *ptr = 719 719 container_of(itr, struct cs_etm_recording, itr);
+1 -1
tools/perf/arch/arm64/util/arm-spe.c
··· 144 144 container_of(itr, struct arm_spe_recording, itr); 145 145 struct perf_pmu *arm_spe_pmu = sper->arm_spe_pmu; 146 146 struct evsel *evsel, *arm_spe_evsel = NULL; 147 - struct perf_cpu_map *cpus = evlist->core.cpus; 147 + struct perf_cpu_map *cpus = evlist->core.user_requested_cpus; 148 148 bool privileged = perf_event_paranoid_check(-1); 149 149 struct evsel *tracking_evsel; 150 150 int err;
+1 -1
tools/perf/arch/x86/util/intel-bts.c
··· 110 110 container_of(itr, struct intel_bts_recording, itr); 111 111 struct perf_pmu *intel_bts_pmu = btsr->intel_bts_pmu; 112 112 struct evsel *evsel, *intel_bts_evsel = NULL; 113 - const struct perf_cpu_map *cpus = evlist->core.cpus; 113 + const struct perf_cpu_map *cpus = evlist->core.user_requested_cpus; 114 114 bool privileged = perf_event_paranoid_check(-1); 115 115 116 116 if (opts->auxtrace_sample_mode) {
+2 -2
tools/perf/arch/x86/util/intel-pt.c
··· 382 382 ui__warning("Intel Processor Trace: TSC not available\n"); 383 383 } 384 384 385 - per_cpu_mmaps = !perf_cpu_map__empty(session->evlist->core.cpus); 385 + per_cpu_mmaps = !perf_cpu_map__empty(session->evlist->core.user_requested_cpus); 386 386 387 387 auxtrace_info->type = PERF_AUXTRACE_INTEL_PT; 388 388 auxtrace_info->priv[INTEL_PT_PMU_TYPE] = intel_pt_pmu->type; ··· 632 632 struct perf_pmu *intel_pt_pmu = ptr->intel_pt_pmu; 633 633 bool have_timing_info, need_immediate = false; 634 634 struct evsel *evsel, *intel_pt_evsel = NULL; 635 - const struct perf_cpu_map *cpus = evlist->core.cpus; 635 + const struct perf_cpu_map *cpus = evlist->core.user_requested_cpus; 636 636 bool privileged = perf_event_paranoid_check(-1); 637 637 u64 tsc_bit; 638 638 int err;
+1 -1
tools/perf/bench/evlist-open-close.c
··· 151 151 152 152 init_stats(&time_stats); 153 153 154 - printf(" Number of cpus:\t%d\n", perf_cpu_map__nr(evlist->core.cpus)); 154 + printf(" Number of cpus:\t%d\n", perf_cpu_map__nr(evlist->core.user_requested_cpus)); 155 155 printf(" Number of threads:\t%d\n", evlist->core.threads->nr); 156 156 printf(" Number of events:\t%d (%d fds)\n", 157 157 evlist->core.nr_entries, evlist__count_evsel_fds(evlist));
+1 -1
tools/perf/builtin-ftrace.c
··· 301 301 302 302 static int set_tracing_cpu(struct perf_ftrace *ftrace) 303 303 { 304 - struct perf_cpu_map *cpumap = ftrace->evlist->core.cpus; 304 + struct perf_cpu_map *cpumap = ftrace->evlist->core.user_requested_cpus; 305 305 306 306 if (!target__has_cpu(&ftrace->target)) 307 307 return 0;
+3 -3
tools/perf/builtin-record.c
··· 987 987 int m, tm, nr_mmaps = evlist->core.nr_mmaps; 988 988 struct mmap *mmap = evlist->mmap; 989 989 struct mmap *overwrite_mmap = evlist->overwrite_mmap; 990 - struct perf_cpu_map *cpus = evlist->core.cpus; 990 + struct perf_cpu_map *cpus = evlist->core.user_requested_cpus; 991 991 992 992 thread_data->nr_mmaps = bitmap_weight(thread_data->mask->maps.bits, 993 993 thread_data->mask->maps.nbits); ··· 1881 1881 return err; 1882 1882 } 1883 1883 1884 - err = perf_event__synthesize_cpu_map(&rec->tool, rec->evlist->core.cpus, 1884 + err = perf_event__synthesize_cpu_map(&rec->tool, rec->evlist->core.user_requested_cpus, 1885 1885 process_synthesized_event, NULL); 1886 1886 if (err < 0) { 1887 1887 pr_err("Couldn't synthesize cpu map.\n"); ··· 3675 3675 static int record__init_thread_masks(struct record *rec) 3676 3676 { 3677 3677 int ret = 0; 3678 - struct perf_cpu_map *cpus = rec->evlist->core.cpus; 3678 + struct perf_cpu_map *cpus = rec->evlist->core.user_requested_cpus; 3679 3679 3680 3680 if (!record__threads_enabled(rec)) 3681 3681 return record__init_thread_default_masks(rec, cpus);
+5 -5
tools/perf/builtin-stat.c
··· 804 804 if (group) 805 805 evlist__set_leader(evsel_list); 806 806 807 - if (!cpu_map__is_dummy(evsel_list->core.cpus)) { 807 + if (!cpu_map__is_dummy(evsel_list->core.user_requested_cpus)) { 808 808 if (affinity__setup(&saved_affinity) < 0) 809 809 return -1; 810 810 affinity = &saved_affinity; ··· 1458 1458 aggr_cpu_id_get_t get_id = aggr_mode__get_aggr(stat_config.aggr_mode); 1459 1459 1460 1460 if (get_id) { 1461 - stat_config.aggr_map = cpu_aggr_map__new(evsel_list->core.cpus, 1461 + stat_config.aggr_map = cpu_aggr_map__new(evsel_list->core.user_requested_cpus, 1462 1462 get_id, /*data=*/NULL); 1463 1463 if (!stat_config.aggr_map) { 1464 1464 pr_err("cannot build %s map", aggr_mode__string[stat_config.aggr_mode]); ··· 1472 1472 * taking the highest cpu number to be the size of 1473 1473 * the aggregation translate cpumap. 1474 1474 */ 1475 - if (evsel_list->core.cpus) 1476 - nr = perf_cpu_map__max(evsel_list->core.cpus).cpu; 1475 + if (evsel_list->core.user_requested_cpus) 1476 + nr = perf_cpu_map__max(evsel_list->core.user_requested_cpus).cpu; 1477 1477 else 1478 1478 nr = 0; 1479 1479 stat_config.cpus_aggr_map = cpu_aggr_map__empty_new(nr + 1); ··· 1630 1630 if (!get_id) 1631 1631 return 0; 1632 1632 1633 - stat_config.aggr_map = cpu_aggr_map__new(evsel_list->core.cpus, get_id, env); 1633 + stat_config.aggr_map = cpu_aggr_map__new(evsel_list->core.user_requested_cpus, get_id, env); 1634 1634 if (!stat_config.aggr_map) { 1635 1635 pr_err("cannot build %s map", aggr_mode__string[stat_config.aggr_mode]); 1636 1636 return -1;
+1 -1
tools/perf/builtin-top.c
··· 1021 1021 1022 1022 evlist__for_each_entry(evlist, counter) { 1023 1023 try_again: 1024 - if (evsel__open(counter, top->evlist->core.cpus, 1024 + if (evsel__open(counter, top->evlist->core.user_requested_cpus, 1025 1025 top->evlist->core.threads) < 0) { 1026 1026 1027 1027 /*
+1 -1
tools/perf/util/auxtrace.c
··· 174 174 mp->idx = idx; 175 175 176 176 if (per_cpu) { 177 - mp->cpu = perf_cpu_map__cpu(evlist->core.cpus, idx); 177 + mp->cpu = perf_cpu_map__cpu(evlist->core.user_requested_cpus, idx); 178 178 if (evlist->core.threads) 179 179 mp->tid = perf_thread_map__pid(evlist->core.threads, 0); 180 180 else
+2 -2
tools/perf/util/bpf_ftrace.c
··· 38 38 39 39 /* don't need to set cpu filter for system-wide mode */ 40 40 if (ftrace->target.cpu_list) { 41 - ncpus = perf_cpu_map__nr(ftrace->evlist->core.cpus); 41 + ncpus = perf_cpu_map__nr(ftrace->evlist->core.user_requested_cpus); 42 42 bpf_map__set_max_entries(skel->maps.cpu_filter, ncpus); 43 43 } 44 44 ··· 63 63 fd = bpf_map__fd(skel->maps.cpu_filter); 64 64 65 65 for (i = 0; i < ncpus; i++) { 66 - cpu = perf_cpu_map__cpu(ftrace->evlist->core.cpus, i).cpu; 66 + cpu = perf_cpu_map__cpu(ftrace->evlist->core.user_requested_cpus, i).cpu; 67 67 bpf_map_update_elem(fd, &cpu, &val, BPF_ANY); 68 68 } 69 69 }
+8 -7
tools/perf/util/evlist.c
··· 440 440 bool has_imm = false; 441 441 442 442 // See explanation in evlist__close() 443 - if (!cpu_map__is_dummy(evlist->core.cpus)) { 443 + if (!cpu_map__is_dummy(evlist->core.user_requested_cpus)) { 444 444 if (affinity__setup(&saved_affinity) < 0) 445 445 return; 446 446 affinity = &saved_affinity; ··· 500 500 struct affinity saved_affinity, *affinity = NULL; 501 501 502 502 // See explanation in evlist__close() 503 - if (!cpu_map__is_dummy(evlist->core.cpus)) { 503 + if (!cpu_map__is_dummy(evlist->core.user_requested_cpus)) { 504 504 if (affinity__setup(&saved_affinity) < 0) 505 505 return; 506 506 affinity = &saved_affinity; ··· 565 565 static int evlist__enable_event_thread(struct evlist *evlist, struct evsel *evsel, int thread) 566 566 { 567 567 int cpu; 568 - int nr_cpus = perf_cpu_map__nr(evlist->core.cpus); 568 + int nr_cpus = perf_cpu_map__nr(evlist->core.user_requested_cpus); 569 569 570 570 if (!evsel->core.fd) 571 571 return -EINVAL; ··· 580 580 581 581 int evlist__enable_event_idx(struct evlist *evlist, struct evsel *evsel, int idx) 582 582 { 583 - bool per_cpu_mmaps = !perf_cpu_map__empty(evlist->core.cpus); 583 + bool per_cpu_mmaps = !perf_cpu_map__empty(evlist->core.user_requested_cpus); 584 584 585 585 if (per_cpu_mmaps) 586 586 return evlist__enable_event_cpu(evlist, evsel, idx); ··· 1301 1301 struct affinity affinity; 1302 1302 1303 1303 /* 1304 - * With perf record core.cpus is usually NULL. 1304 + * With perf record core.user_requested_cpus is usually NULL. 1305 1305 * Use the old method to handle this for now. 1306 1306 */ 1307 - if (!evlist->core.cpus || cpu_map__is_dummy(evlist->core.cpus)) { 1307 + if (!evlist->core.user_requested_cpus || 1308 + cpu_map__is_dummy(evlist->core.user_requested_cpus)) { 1308 1309 evlist__for_each_entry_reverse(evlist, evsel) 1309 1310 evsel__close(evsel); 1310 1311 return; ··· 1368 1367 * Default: one fd per CPU, all threads, aka systemwide 1369 1368 * as sys_perf_event_open(cpu = -1, thread = -1) is EINVAL 1370 1369 */ 1371 - if (evlist->core.threads == NULL && evlist->core.cpus == NULL) { 1370 + if (evlist->core.threads == NULL && evlist->core.user_requested_cpus == NULL) { 1372 1371 err = evlist__create_syswide_maps(evlist); 1373 1372 if (err < 0) 1374 1373 goto out_err;
+3 -3
tools/perf/util/record.c
··· 106 106 if (opts->group) 107 107 evlist__set_leader(evlist); 108 108 109 - if (perf_cpu_map__cpu(evlist->core.cpus, 0).cpu < 0) 109 + if (perf_cpu_map__cpu(evlist->core.user_requested_cpus, 0).cpu < 0) 110 110 opts->no_inherit = true; 111 111 112 112 use_comm_exec = perf_can_comm_exec(); ··· 244 244 245 245 evsel = evlist__last(temp_evlist); 246 246 247 - if (!evlist || perf_cpu_map__empty(evlist->core.cpus)) { 247 + if (!evlist || perf_cpu_map__empty(evlist->core.user_requested_cpus)) { 248 248 struct perf_cpu_map *cpus = perf_cpu_map__new(NULL); 249 249 250 250 if (cpus) ··· 252 252 253 253 perf_cpu_map__put(cpus); 254 254 } else { 255 - cpu = perf_cpu_map__cpu(evlist->core.cpus, 0); 255 + cpu = perf_cpu_map__cpu(evlist->core.user_requested_cpus, 0); 256 256 } 257 257 258 258 while (1) {
+2 -1
tools/perf/util/sideband_evlist.c
··· 114 114 } 115 115 116 116 evlist__for_each_entry(evlist, counter) { 117 - if (evsel__open(counter, evlist->core.cpus, evlist->core.threads) < 0) 117 + if (evsel__open(counter, evlist->core.user_requested_cpus, 118 + evlist->core.threads) < 0) 118 119 goto out_delete_evlist; 119 120 } 120 121
+1 -1
tools/perf/util/stat-display.c
··· 929 929 int all_idx; 930 930 struct perf_cpu cpu; 931 931 932 - perf_cpu_map__for_each_cpu(cpu, all_idx, evlist->core.cpus) { 932 + perf_cpu_map__for_each_cpu(cpu, all_idx, evlist->core.user_requested_cpus) { 933 933 struct evsel *counter; 934 934 bool first = true; 935 935
+1 -1
tools/perf/util/synthetic-events.c
··· 2127 2127 return err; 2128 2128 } 2129 2129 2130 - err = perf_event__synthesize_cpu_map(tool, evlist->core.cpus, process, NULL); 2130 + err = perf_event__synthesize_cpu_map(tool, evlist->core.user_requested_cpus, process, NULL); 2131 2131 if (err < 0) { 2132 2132 pr_err("Couldn't synthesize thread map.\n"); 2133 2133 return err;
+5 -3
tools/perf/util/top.c
··· 95 95 96 96 if (target->cpu_list) 97 97 ret += SNPRINTF(bf + ret, size - ret, ", CPU%s: %s)", 98 - perf_cpu_map__nr(top->evlist->core.cpus) > 1 ? "s" : "", 98 + perf_cpu_map__nr(top->evlist->core.user_requested_cpus) > 1 99 + ? "s" : "", 99 100 target->cpu_list); 100 101 else { 101 102 if (target->tid) 102 103 ret += SNPRINTF(bf + ret, size - ret, ")"); 103 104 else 104 105 ret += SNPRINTF(bf + ret, size - ret, ", %d CPU%s)", 105 - perf_cpu_map__nr(top->evlist->core.cpus), 106 - perf_cpu_map__nr(top->evlist->core.cpus) > 1 ? "s" : ""); 106 + perf_cpu_map__nr(top->evlist->core.user_requested_cpus), 107 + perf_cpu_map__nr(top->evlist->core.user_requested_cpus) > 1 108 + ? "s" : ""); 107 109 } 108 110 109 111 perf_top__reset_sample_counters(top);