Skip to content

Commit 0df6ade

Browse files
captain5050acmel
authored andcommitted
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>
1 parent d4ff926 commit 0df6ade

File tree

19 files changed

+62
-53
lines changed

19 files changed

+62
-53
lines changed

tools/lib/perf/evlist.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ static void __perf_evlist__propagate_maps(struct perf_evlist *evlist,
4141
*/
4242
if (!evsel->own_cpus || evlist->has_user_cpus) {
4343
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)) {
4646
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);
4848
} else if (evsel->cpus != evsel->own_cpus) {
4949
perf_cpu_map__put(evsel->cpus);
5050
evsel->cpus = perf_cpu_map__get(evsel->own_cpus);
@@ -123,10 +123,10 @@ static void perf_evlist__purge(struct perf_evlist *evlist)
123123

124124
void perf_evlist__exit(struct perf_evlist *evlist)
125125
{
126-
perf_cpu_map__put(evlist->cpus);
126+
perf_cpu_map__put(evlist->user_requested_cpus);
127127
perf_cpu_map__put(evlist->all_cpus);
128128
perf_thread_map__put(evlist->threads);
129-
evlist->cpus = NULL;
129+
evlist->user_requested_cpus = NULL;
130130
evlist->all_cpus = NULL;
131131
evlist->threads = NULL;
132132
fdarray__exit(&evlist->pollfd);
@@ -155,9 +155,9 @@ void perf_evlist__set_maps(struct perf_evlist *evlist,
155155
* original reference count of 1. If that is not the case it is up to
156156
* the caller to increase the reference count.
157157
*/
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);
161161
}
162162

163163
if (threads != evlist->threads) {
@@ -294,7 +294,7 @@ int perf_evlist__id_add_fd(struct perf_evlist *evlist,
294294

295295
int perf_evlist__alloc_pollfd(struct perf_evlist *evlist)
296296
{
297-
int nr_cpus = perf_cpu_map__nr(evlist->cpus);
297+
int nr_cpus = perf_cpu_map__nr(evlist->user_requested_cpus);
298298
int nr_threads = perf_thread_map__nr(evlist->threads);
299299
int nfds = 0;
300300
struct perf_evsel *evsel;
@@ -426,7 +426,7 @@ mmap_per_evsel(struct perf_evlist *evlist, struct perf_evlist_mmap_ops *ops,
426426
int idx, struct perf_mmap_param *mp, int cpu_idx,
427427
int thread, int *_output, int *_output_overwrite)
428428
{
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);
430430
struct perf_evsel *evsel;
431431
int revent;
432432

@@ -536,7 +536,7 @@ mmap_per_cpu(struct perf_evlist *evlist, struct perf_evlist_mmap_ops *ops,
536536
struct perf_mmap_param *mp)
537537
{
538538
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);
540540
int cpu, thread;
541541

542542
for (cpu = 0; cpu < nr_cpus; cpu++) {
@@ -564,8 +564,8 @@ static int perf_evlist__nr_mmaps(struct perf_evlist *evlist)
564564
{
565565
int nr_mmaps;
566566

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))
569569
nr_mmaps = perf_thread_map__nr(evlist->threads);
570570

571571
return nr_mmaps;
@@ -576,7 +576,7 @@ int perf_evlist__mmap_ops(struct perf_evlist *evlist,
576576
struct perf_mmap_param *mp)
577577
{
578578
struct perf_evsel *evsel;
579-
const struct perf_cpu_map *cpus = evlist->cpus;
579+
const struct perf_cpu_map *cpus = evlist->user_requested_cpus;
580580
const struct perf_thread_map *threads = evlist->threads;
581581

582582
if (!ops || !ops->get || !ops->mmap)

tools/lib/perf/include/internal/evlist.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ struct perf_evlist {
1919
int nr_entries;
2020
int nr_groups;
2121
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. */
2328
struct perf_cpu_map *all_cpus;
2429
struct perf_thread_map *threads;
2530
int nr_mmaps;

tools/perf/arch/arm/util/cs-etm.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static int cs_etm_set_option(struct auxtrace_record *itr,
199199
struct evsel *evsel, u32 option)
200200
{
201201
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;
203203
struct perf_cpu_map *online_cpus = perf_cpu_map__new(NULL);
204204

205205
/* Set option of each CPU we have */
@@ -299,7 +299,7 @@ static int cs_etm_recording_options(struct auxtrace_record *itr,
299299
container_of(itr, struct cs_etm_recording, itr);
300300
struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu;
301301
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;
303303
bool privileged = perf_event_paranoid_check(-1);
304304
int err = 0;
305305

@@ -522,7 +522,7 @@ cs_etm_info_priv_size(struct auxtrace_record *itr __maybe_unused,
522522
{
523523
int i;
524524
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;
526526
struct perf_cpu_map *online_cpus = perf_cpu_map__new(NULL);
527527

528528
/* cpu map is not empty, we have specific CPUs to work with */
@@ -713,7 +713,7 @@ static int cs_etm_info_fill(struct auxtrace_record *itr,
713713
u32 offset;
714714
u64 nr_cpu, type;
715715
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;
717717
struct perf_cpu_map *online_cpus = perf_cpu_map__new(NULL);
718718
struct cs_etm_recording *ptr =
719719
container_of(itr, struct cs_etm_recording, itr);

tools/perf/arch/arm64/util/arm-spe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ static int arm_spe_recording_options(struct auxtrace_record *itr,
144144
container_of(itr, struct arm_spe_recording, itr);
145145
struct perf_pmu *arm_spe_pmu = sper->arm_spe_pmu;
146146
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;
148148
bool privileged = perf_event_paranoid_check(-1);
149149
struct evsel *tracking_evsel;
150150
int err;

tools/perf/arch/x86/util/intel-bts.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static int intel_bts_recording_options(struct auxtrace_record *itr,
110110
container_of(itr, struct intel_bts_recording, itr);
111111
struct perf_pmu *intel_bts_pmu = btsr->intel_bts_pmu;
112112
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;
114114
bool privileged = perf_event_paranoid_check(-1);
115115

116116
if (opts->auxtrace_sample_mode) {

tools/perf/arch/x86/util/intel-pt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ static int intel_pt_info_fill(struct auxtrace_record *itr,
382382
ui__warning("Intel Processor Trace: TSC not available\n");
383383
}
384384

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);
386386

387387
auxtrace_info->type = PERF_AUXTRACE_INTEL_PT;
388388
auxtrace_info->priv[INTEL_PT_PMU_TYPE] = intel_pt_pmu->type;
@@ -632,7 +632,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
632632
struct perf_pmu *intel_pt_pmu = ptr->intel_pt_pmu;
633633
bool have_timing_info, need_immediate = false;
634634
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;
636636
bool privileged = perf_event_paranoid_check(-1);
637637
u64 tsc_bit;
638638
int err;

tools/perf/bench/evlist-open-close.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static int bench_evlist_open_close__run(char *evstr)
151151

152152
init_stats(&time_stats);
153153

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));
155155
printf(" Number of threads:\t%d\n", evlist->core.threads->nr);
156156
printf(" Number of events:\t%d (%d fds)\n",
157157
evlist->core.nr_entries, evlist__count_evsel_fds(evlist));

tools/perf/builtin-ftrace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ static int set_tracing_cpumask(struct perf_cpu_map *cpumap)
301301

302302
static int set_tracing_cpu(struct perf_ftrace *ftrace)
303303
{
304-
struct perf_cpu_map *cpumap = ftrace->evlist->core.cpus;
304+
struct perf_cpu_map *cpumap = ftrace->evlist->core.user_requested_cpus;
305305

306306
if (!target__has_cpu(&ftrace->target))
307307
return 0;

tools/perf/builtin-record.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ static int record__thread_data_init_maps(struct record_thread *thread_data, stru
987987
int m, tm, nr_mmaps = evlist->core.nr_mmaps;
988988
struct mmap *mmap = evlist->mmap;
989989
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;
991991

992992
thread_data->nr_mmaps = bitmap_weight(thread_data->mask->maps.bits,
993993
thread_data->mask->maps.nbits);
@@ -1881,7 +1881,7 @@ static int record__synthesize(struct record *rec, bool tail)
18811881
return err;
18821882
}
18831883

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,
18851885
process_synthesized_event, NULL);
18861886
if (err < 0) {
18871887
pr_err("Couldn't synthesize cpu map.\n");
@@ -3675,7 +3675,7 @@ static int record__init_thread_default_masks(struct record *rec, struct perf_cpu
36753675
static int record__init_thread_masks(struct record *rec)
36763676
{
36773677
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;
36793679

36803680
if (!record__threads_enabled(rec))
36813681
return record__init_thread_default_masks(rec, cpus);

tools/perf/builtin-stat.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
804804
if (group)
805805
evlist__set_leader(evsel_list);
806806

807-
if (!cpu_map__is_dummy(evsel_list->core.cpus)) {
807+
if (!cpu_map__is_dummy(evsel_list->core.user_requested_cpus)) {
808808
if (affinity__setup(&saved_affinity) < 0)
809809
return -1;
810810
affinity = &saved_affinity;
@@ -1458,7 +1458,7 @@ static int perf_stat_init_aggr_mode(void)
14581458
aggr_cpu_id_get_t get_id = aggr_mode__get_aggr(stat_config.aggr_mode);
14591459

14601460
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,
14621462
get_id, /*data=*/NULL);
14631463
if (!stat_config.aggr_map) {
14641464
pr_err("cannot build %s map", aggr_mode__string[stat_config.aggr_mode]);
@@ -1472,8 +1472,8 @@ static int perf_stat_init_aggr_mode(void)
14721472
* taking the highest cpu number to be the size of
14731473
* the aggregation translate cpumap.
14741474
*/
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;
14771477
else
14781478
nr = 0;
14791479
stat_config.cpus_aggr_map = cpu_aggr_map__empty_new(nr + 1);
@@ -1630,7 +1630,7 @@ static int perf_stat_init_aggr_mode_file(struct perf_stat *st)
16301630
if (!get_id)
16311631
return 0;
16321632

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);
16341634
if (!stat_config.aggr_map) {
16351635
pr_err("cannot build %s map", aggr_mode__string[stat_config.aggr_mode]);
16361636
return -1;

0 commit comments

Comments
 (0)