Skip to content

Commit 5d1ab65

Browse files
captain5050acmel
authored andcommitted
perf stat: Add no-affinity flag
Add flag that disables affinity behavior. Using sched_setaffinity() to place a perf thread on a CPU can avoid certain interprocessor interrupts but may introduce a delay due to the scheduling, particularly on loaded machines. Add a command line option to disable the behavior. This behavior is less present in other tools like `perf record`, as it uses a ring buffer and doesn't make repeated system calls. Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Andres Freund <andres@anarazel.de> Cc: Dapeng Mi <dapeng1.mi@linux.intel.com> Cc: Dr. David Alan Gilbert <linux@treblig.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@linaro.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Falcon <thomas.falcon@intel.com> Cc: Thomas Richter <tmricht@linux.ibm.com> Cc: Yang Li <yang.lee@linux.alibaba.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent d484361 commit 5d1ab65

4 files changed

Lines changed: 13 additions & 5 deletions

File tree

tools/perf/Documentation/perf-stat.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,11 @@ color the metric's computed value.
382382
Don't print output, warnings or messages. This is useful with perf stat
383383
record below to only write data to the perf.data file.
384384

385+
--no-affinity::
386+
Don't change scheduler CPU affinities when iterating over
387+
CPUs. Disables an optimization aimed at minimizing interprocessor
388+
interrupts.
389+
385390
STAT RECORD
386391
-----------
387392
Stores stat data into perf data file.

tools/perf/builtin-stat.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,6 +2426,7 @@ static int parse_tpebs_mode(const struct option *opt, const char *str,
24262426
int cmd_stat(int argc, const char **argv)
24272427
{
24282428
struct opt_aggr_mode opt_mode = {};
2429+
bool affinity = true, affinity_set = false;
24292430
struct option stat_options[] = {
24302431
OPT_BOOLEAN('T', "transaction", &transaction_run,
24312432
"hardware transaction statistics"),
@@ -2554,6 +2555,8 @@ int cmd_stat(int argc, const char **argv)
25542555
"don't print 'summary' for CSV summary output"),
25552556
OPT_BOOLEAN(0, "quiet", &quiet,
25562557
"don't print any output, messages or warnings (useful with record)"),
2558+
OPT_BOOLEAN_SET(0, "affinity", &affinity, &affinity_set,
2559+
"enable (default) or disable affinity optimizations to reduce IPIs"),
25572560
OPT_CALLBACK(0, "cputype", &evsel_list, "hybrid cpu type",
25582561
"Only enable events on applying cpu with this type "
25592562
"for hybrid platform (e.g. core or atom)",
@@ -2611,6 +2614,9 @@ int cmd_stat(int argc, const char **argv)
26112614
} else
26122615
stat_config.csv_sep = DEFAULT_SEPARATOR;
26132616

2617+
if (affinity_set)
2618+
evsel_list->no_affinity = !affinity;
2619+
26142620
if (argc && strlen(argv[0]) > 2 && strstarts("record", argv[0])) {
26152621
argc = __cmd_record(stat_options, &opt_mode, argc, argv);
26162622
if (argc < 0)

tools/perf/util/evlist.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,7 @@ static bool evlist__use_affinity(struct evlist *evlist)
369369
struct perf_cpu_map *used_cpus = NULL;
370370
bool ret = false;
371371

372-
/*
373-
* With perf record core.user_requested_cpus is usually NULL.
374-
* Use the old method to handle this for now.
375-
*/
376-
if (!evlist->core.user_requested_cpus ||
372+
if (evlist->no_affinity || !evlist->core.user_requested_cpus ||
377373
cpu_map__is_dummy(evlist->core.user_requested_cpus))
378374
return false;
379375

tools/perf/util/evlist.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ struct event_enable_timer;
5959
struct evlist {
6060
struct perf_evlist core;
6161
bool enabled;
62+
bool no_affinity;
6263
int id_pos;
6364
int is_pos;
6465
int nr_br_cntr;

0 commit comments

Comments
 (0)