Skip to content

Commit 7736627

Browse files
Andi Kleenacmel
authored andcommitted
perf stat: Use affinity for closing file descriptors
Closing a perf fd can also trigger an IPI to the target CPU. Use the same affinity technique as we use for reading/enabling events to closing to optimize the CPU transitions. Before on a large test case with 94 CPUs: % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 32.56 3.085463 50 61483 close After: 10.54 0.735704 11 61485 close Signed-off-by: Andi Kleen <[email protected]> Acked-by: Jiri Olsa <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 99d6141 commit 7736627

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

tools/perf/util/evlist.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "debug.h"
1919
#include "units.h"
2020
#include <internal/lib.h> // page_size
21+
#include "affinity.h"
2122
#include "../perf.h"
2223
#include "asm/bug.h"
2324
#include "bpf-event.h"
@@ -1169,9 +1170,35 @@ void perf_evlist__set_selected(struct evlist *evlist,
11691170
void evlist__close(struct evlist *evlist)
11701171
{
11711172
struct evsel *evsel;
1173+
struct affinity affinity;
1174+
int cpu, i;
11721175

1173-
evlist__for_each_entry_reverse(evlist, evsel)
1174-
evsel__close(evsel);
1176+
/*
1177+
* With perf record core.cpus is usually NULL.
1178+
* Use the old method to handle this for now.
1179+
*/
1180+
if (!evlist->core.cpus) {
1181+
evlist__for_each_entry_reverse(evlist, evsel)
1182+
evsel__close(evsel);
1183+
return;
1184+
}
1185+
1186+
if (affinity__setup(&affinity) < 0)
1187+
return;
1188+
evlist__for_each_cpu(evlist, i, cpu) {
1189+
affinity__set(&affinity, cpu);
1190+
1191+
evlist__for_each_entry_reverse(evlist, evsel) {
1192+
if (evsel__cpu_iter_skip(evsel, cpu))
1193+
continue;
1194+
perf_evsel__close_cpu(&evsel->core, evsel->cpu_iter - 1);
1195+
}
1196+
}
1197+
affinity__cleanup(&affinity);
1198+
evlist__for_each_entry_reverse(evlist, evsel) {
1199+
perf_evsel__free_fd(&evsel->core);
1200+
perf_evsel__free_id(&evsel->core);
1201+
}
11751202
}
11761203

11771204
static int perf_evlist__create_syswide_maps(struct evlist *evlist)

0 commit comments

Comments
 (0)