Skip to content

Commit 23380e4

Browse files
Alexey Bayduraevacmel
authored andcommitted
perf record: Fix per-thread option
Per-thread mode doesn't have specific CPUs for events, add checks for this case. Minor fix to a pr_debug by Ian Rogers <irogers@google.com> to avoid an out of bound array access. Fixes: 7954f71 ("perf record: Introduce thread affinity and mmap masks") Reported-by: Ian Rogers <irogers@google.com> Signed-off-by: Alexey Bayduraev <alexey.bayduraev@gmail.com> Signed-off-by: Ian Rogers <irogers@google.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: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Riccardo Mancini <rickyman7@gmail.com> Cc: Stephane Eranian <eranian@google.com> Link: https://lore.kernel.org/r/20220414014642.3308206-1-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent a668cc0 commit 23380e4

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

tools/perf/builtin-record.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -989,8 +989,11 @@ static int record__thread_data_init_maps(struct record_thread *thread_data, stru
989989
struct mmap *overwrite_mmap = evlist->overwrite_mmap;
990990
struct perf_cpu_map *cpus = evlist->core.user_requested_cpus;
991991

992-
thread_data->nr_mmaps = bitmap_weight(thread_data->mask->maps.bits,
993-
thread_data->mask->maps.nbits);
992+
if (cpu_map__is_dummy(cpus))
993+
thread_data->nr_mmaps = nr_mmaps;
994+
else
995+
thread_data->nr_mmaps = bitmap_weight(thread_data->mask->maps.bits,
996+
thread_data->mask->maps.nbits);
994997
if (mmap) {
995998
thread_data->maps = zalloc(thread_data->nr_mmaps * sizeof(struct mmap *));
996999
if (!thread_data->maps)
@@ -1007,16 +1010,17 @@ static int record__thread_data_init_maps(struct record_thread *thread_data, stru
10071010
thread_data->nr_mmaps, thread_data->maps, thread_data->overwrite_maps);
10081011

10091012
for (m = 0, tm = 0; m < nr_mmaps && tm < thread_data->nr_mmaps; m++) {
1010-
if (test_bit(cpus->map[m].cpu, thread_data->mask->maps.bits)) {
1013+
if (cpu_map__is_dummy(cpus) ||
1014+
test_bit(cpus->map[m].cpu, thread_data->mask->maps.bits)) {
10111015
if (thread_data->maps) {
10121016
thread_data->maps[tm] = &mmap[m];
10131017
pr_debug2("thread_data[%p]: cpu%d: maps[%d] -> mmap[%d]\n",
1014-
thread_data, cpus->map[m].cpu, tm, m);
1018+
thread_data, perf_cpu_map__cpu(cpus, m).cpu, tm, m);
10151019
}
10161020
if (thread_data->overwrite_maps) {
10171021
thread_data->overwrite_maps[tm] = &overwrite_mmap[m];
10181022
pr_debug2("thread_data[%p]: cpu%d: ow_maps[%d] -> ow_mmap[%d]\n",
1019-
thread_data, cpus->map[m].cpu, tm, m);
1023+
thread_data, perf_cpu_map__cpu(cpus, m).cpu, tm, m);
10201024
}
10211025
tm++;
10221026
}
@@ -3329,6 +3333,9 @@ static void record__mmap_cpu_mask_init(struct mmap_cpu_mask *mask, struct perf_c
33293333
{
33303334
int c;
33313335

3336+
if (cpu_map__is_dummy(cpus))
3337+
return;
3338+
33323339
for (c = 0; c < cpus->nr; c++)
33333340
set_bit(cpus->map[c].cpu, mask->bits);
33343341
}
@@ -3680,6 +3687,11 @@ static int record__init_thread_masks(struct record *rec)
36803687
if (!record__threads_enabled(rec))
36813688
return record__init_thread_default_masks(rec, cpus);
36823689

3690+
if (cpu_map__is_dummy(cpus)) {
3691+
pr_err("--per-thread option is mutually exclusive to parallel streaming mode.\n");
3692+
return -EINVAL;
3693+
}
3694+
36833695
switch (rec->opts.threads_spec) {
36843696
case THREAD_SPEC__CPU:
36853697
ret = record__init_thread_cpu_masks(rec, cpus);

0 commit comments

Comments
 (0)