Skip to content

Commit 49de179

Browse files
committed
perf stat: No need to setup affinities when starting a workload
I.e. the simple: $ perf stat sleep 1 Uses a dummy CPU map and thus there is no need to setup/cleanup affinities to avoid IPIs, etc. With this we're down to a sched_getaffinity() call, in the libnuma initialization, that probably can be removed in a followup patch. 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 1855b79 commit 49de179

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

tools/perf/builtin-stat.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
788788
const bool forks = (argc > 0);
789789
bool is_pipe = STAT_RECORD ? perf_stat.data.is_pipe : false;
790790
struct evlist_cpu_iterator evlist_cpu_itr;
791-
struct affinity affinity;
791+
struct affinity saved_affinity, *affinity = NULL;
792792
int err;
793793
bool second_pass = false;
794794

@@ -803,8 +803,11 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
803803
if (group)
804804
evlist__set_leader(evsel_list);
805805

806-
if (affinity__setup(&affinity) < 0)
807-
return -1;
806+
if (!cpu_map__is_dummy(evsel_list->core.cpus)) {
807+
if (affinity__setup(&saved_affinity) < 0)
808+
return -1;
809+
affinity = &saved_affinity;
810+
}
808811

809812
evlist__for_each_entry(evsel_list, counter) {
810813
if (bpf_counter__load(counter, &target))
@@ -813,7 +816,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
813816
all_counters_use_bpf = false;
814817
}
815818

816-
evlist__for_each_cpu(evlist_cpu_itr, evsel_list, &affinity) {
819+
evlist__for_each_cpu(evlist_cpu_itr, evsel_list, affinity) {
817820
counter = evlist_cpu_itr.evsel;
818821

819822
/*
@@ -869,7 +872,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
869872
*/
870873

871874
/* First close errored or weak retry */
872-
evlist__for_each_cpu(evlist_cpu_itr, evsel_list, &affinity) {
875+
evlist__for_each_cpu(evlist_cpu_itr, evsel_list, affinity) {
873876
counter = evlist_cpu_itr.evsel;
874877

875878
if (!counter->reset_group && !counter->errored)
@@ -878,7 +881,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
878881
perf_evsel__close_cpu(&counter->core, evlist_cpu_itr.cpu_map_idx);
879882
}
880883
/* Now reopen weak */
881-
evlist__for_each_cpu(evlist_cpu_itr, evsel_list, &affinity) {
884+
evlist__for_each_cpu(evlist_cpu_itr, evsel_list, affinity) {
882885
counter = evlist_cpu_itr.evsel;
883886

884887
if (!counter->reset_group && !counter->errored)
@@ -904,7 +907,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
904907
counter->supported = true;
905908
}
906909
}
907-
affinity__cleanup(&affinity);
910+
affinity__cleanup(affinity);
908911

909912
evlist__for_each_entry(evsel_list, counter) {
910913
if (!counter->supported) {

0 commit comments

Comments
 (0)