[RFC PATCH v1 33/37] perf record: pin threads to monitored cpus if enough threads available

From: Riccardo Mancini
Date: Sat Aug 21 2021 - 05:22:33 EST


This patch sets the affinity of the workqueue threads to pin them to
each monitored CPU in case the --threads option is set with enough
threads and evlist multithreading is enabled.

This yields a better performance for the evlist operations, since
affinity need not be sent by each thread everytime.

Signed-off-by: Riccardo Mancini <rickyman7@xxxxxxxxx>
---
tools/perf/builtin-record.c | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 7802a0e25f631fac..e2d2445e05d7c07a 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -2945,6 +2945,16 @@ int cmd_record(int argc, const char **argv)
pr_err("setup_global_workqueue: %s\n", errbuf);
goto out;
}
+
+ if ((int)rec->opts.nr_threads >= rec->evlist->core.all_cpus->nr
+ && rec->opts.multithreaded_evlist) {
+ err = workqueue_set_affinities_cpu(global_wq, rec->evlist->core.all_cpus);
+ if (err) {
+ workqueue_strerror(global_wq, err, errbuf, sizeof(errbuf));
+ pr_err("workqueue_set_affinities_cpu: %s\n", errbuf);
+ goto out;
+ }
+ }
}

err = __cmd_record(&record, argc, argv);
--
2.31.1