[RFC PATCH v3 13/15] perf top: setup global workqueue

From: Riccardo Mancini
Date: Fri Aug 20 2021 - 06:55:12 EST


This patch initializes the global workqueue in perf-top if
nr_threads_synthesize is set.

This patch is a preparation for using the global_workqueue in
synthesize.

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

diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index a3ae9176a83e2453..9b4f220920780a95 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -49,6 +49,7 @@
#include "util/term.h"
#include "util/intlist.h"
#include "util/parse-branch-options.h"
+#include "util/workqueue/workqueue.h"
#include "arch/common.h"
#include "ui/ui.h"

@@ -1767,8 +1768,23 @@ int cmd_top(int argc, const char **argv)
opts->no_bpf_event = true;
}

+ if (top.nr_threads_synthesize == UINT_MAX)
+ top.nr_threads_synthesize = sysconf(_SC_NPROCESSORS_ONLN);
+ if (top.nr_threads_synthesize > 1) {
+ status = setup_global_workqueue(top.nr_threads_synthesize);
+ if (status) {
+ create_workqueue_strerror(global_wq, errbuf, sizeof(errbuf));
+ pr_err("setup_global_workqueue: %s\n", errbuf);
+ goto out_stop_sb_th;
+ }
+ }
+
status = __cmd_top(&top);

+ if (top.nr_threads_synthesize > 1)
+ teardown_global_workqueue();
+
+out_stop_sb_th:
if (!opts->no_bpf_event)
evlist__stop_sb_thread(top.sb_evlist);

--
2.31.1