Skip to content

Commit 0d3d237

Browse files
committed
perf evlist: No need to setup affinities when disabling events for pid targets
When the target is a pid, not started by 'perf stat' we need to disable the events, and in that case there is no need to setup affinities as we use a dummy CPU map, with just one entry set to -1. So stop doing it to avoid this needless call to sched_getaffinity(): # strace -ke sched_getaffinity perf stat -e cycles -p 241957 sleep 1 <SNIP> sched_getaffinity(0, 512, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]) = 8 > /usr/lib64/libc-2.33.so(sched_getaffinity@@GLIBC_2.3.4+0x1a) [0xe6eea] > /var/home/acme/bin/perf(affinity__setup+0x6a) [0x532a2a] > /var/home/acme/bin/perf(__evlist__disable.constprop.0+0x27) [0x4b9827] > /var/home/acme/bin/perf(cmd_stat+0x29b5) [0x431725] > /var/home/acme/bin/perf(run_builtin+0x6a) [0x4a2cfa] > /var/home/acme/bin/perf(main+0x612) [0x40f8c2] > /usr/lib64/libc-2.33.so(__libc_start_main+0xd4) [0x27b74] > /var/home/acme/bin/perf(_start+0x2d) [0x40fadd] <SNIP> Acked-by: Ian Rogers <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent f350ee9 commit 0d3d237

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

tools/perf/util/evlist.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -430,15 +430,19 @@ static void __evlist__disable(struct evlist *evlist, char *evsel_name)
430430
{
431431
struct evsel *pos;
432432
struct evlist_cpu_iterator evlist_cpu_itr;
433-
struct affinity affinity;
433+
struct affinity saved_affinity, *affinity = NULL;
434434
bool has_imm = false;
435435

436-
if (affinity__setup(&affinity) < 0)
437-
return;
436+
// See explanation in evlist__close()
437+
if (!cpu_map__is_dummy(evlist->core.cpus)) {
438+
if (affinity__setup(&saved_affinity) < 0)
439+
return;
440+
affinity = &saved_affinity;
441+
}
438442

439443
/* Disable 'immediate' events last */
440444
for (int imm = 0; imm <= 1; imm++) {
441-
evlist__for_each_cpu(evlist_cpu_itr, evlist, &affinity) {
445+
evlist__for_each_cpu(evlist_cpu_itr, evlist, affinity) {
442446
pos = evlist_cpu_itr.evsel;
443447
if (evsel__strcmp(pos, evsel_name))
444448
continue;
@@ -454,7 +458,7 @@ static void __evlist__disable(struct evlist *evlist, char *evsel_name)
454458
break;
455459
}
456460

457-
affinity__cleanup(&affinity);
461+
affinity__cleanup(affinity);
458462
evlist__for_each_entry(evlist, pos) {
459463
if (evsel__strcmp(pos, evsel_name))
460464
continue;

0 commit comments

Comments
 (0)