lkml.org 
[lkml]   [2021]   [Aug]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC PATCH v1 34/37] perf record: apply multithreading in init and fini phases
Date
This patch grows the multithreaded portion of perf-record, marked by the
perf_set_multithreaded and perf_set_singlethreaded functions to the whole
init and fini part of __cmd_record.
By doing so, perf-record can take advantage of the parallelized evlist
operations (open, enable, disable, close).

This patch also needs to handle the case in which evlist and synthesis
multithreading are not enabled at the same time. Therefore, in
record__synthesize multithreading is enabled/disabled and then
disabled/renabled if needed.

Signed-off-by: Riccardo Mancini <rickyman7@gmail.com>
---
tools/perf/builtin-record.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index e2d2445e05d7c07a..db9ec08db672f994 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1411,6 +1411,7 @@ static int record__synthesize(struct record *rec, bool tail)
struct perf_tool *tool = &rec->tool;
int err = 0;
event_op f = process_synthesized_event;
+ bool perf_was_singlethreaded = perf_singlethreaded;

if (rec->opts.tail_synthesize != tail)
return 0;
@@ -1499,12 +1500,16 @@ static int record__synthesize(struct record *rec, bool tail)
if (rec->opts.multithreaded_synthesis) {
perf_set_multithreaded();
f = process_locked_synthesized_event;
+ } else {
+ perf_set_singlethreaded();
}

err = __machine__synthesize_threads(machine, tool, &opts->target, rec->evlist->core.threads,
f, opts->sample_address);

- if (rec->opts.multithreaded_synthesis)
+ if (!perf_was_singlethreaded && perf_singlethreaded)
+ perf_set_multithreaded();
+ if (perf_was_singlethreaded && !perf_singlethreaded)
perf_set_singlethreaded();

out:
@@ -1735,6 +1740,9 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)

record__uniquify_name(rec);

+ if (rec->opts.multithreaded_evlist)
+ perf_set_multithreaded();
+
if (record__open(rec) != 0) {
err = -1;
goto out_child;
@@ -1877,6 +1885,10 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
}
}

+ // disable locks in the main thread since there is no multithreading
+ if (rec->opts.multithreaded_evlist)
+ perf_set_singlethreaded();
+
trigger_ready(&auxtrace_snapshot_trigger);
trigger_ready(&switch_output_trigger);
perf_hooks__invoke_record_start();
@@ -1998,6 +2010,10 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
}
}

+ // reenable multithreading for evlist
+ if (rec->opts.multithreaded_evlist)
+ perf_set_multithreaded();
+
trigger_off(&auxtrace_snapshot_trigger);
trigger_off(&switch_output_trigger);

@@ -2099,6 +2115,10 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)

if (!opts->no_bpf_event)
evlist__stop_sb_thread(rec->sb_evlist);
+
+ // disable multithreaded mode on exit
+ if (rec->opts.multithreaded_evlist)
+ perf_set_singlethreaded();
return status;
}

--
2.31.1
\
 
 \ /
  Last update: 2021-08-21 11:23    [W:0.266 / U:0.160 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site