The --num-thread is to control number of thread to process events when
--multi-thread option is enabled.  Default value is the number of cpu
on the system that runs perf report.  The config variable
'report.num-thread' is also added to set a different default value.

Signed-off-by: Namhyung Kim <namhy...@kernel.org>
---
Also update the perf/threaded-v4 branch.

 tools/perf/Documentation/perf-report.txt |  5 +++++
 tools/perf/builtin-report.c              | 29 +++++++++++++++++++++++++----
 tools/perf/util/session.c                |  4 ++--
 tools/perf/util/session.h                |  3 ++-
 4 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/tools/perf/Documentation/perf-report.txt 
b/tools/perf/Documentation/perf-report.txt
index 3917710e2620..c6050496d720 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -356,6 +356,11 @@ OPTIONS
 --multi-thread::
        Speed up report by parallelizing sample processing using multi-thread.
 
+--num-thread::
+       Number of thread to process sample events.  Should be greater than or
+       equals to 2.  Default is number of cpus on the system unless
+       report.num-thread config variable is set.
+
 include::callchain-overhead-calculation.txt[]
 
 SEE ALSO
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 4d08e5f0a7bb..71ab710f2a1e 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -54,6 +54,7 @@ struct report {
        bool                    header;
        bool                    header_only;
        bool                    multi_thread;
+       int                     nr_thread;
        int                     max_stack;
        struct perf_read_values show_threads_values;
        const char              *pretty_printing_style;
@@ -89,6 +90,10 @@ static int report__config(const char *var, const char 
*value, void *cb)
                rep->multi_thread = perf_config_bool(var, value);
                return 0;
        }
+       if (!strcmp(var, "report.num-thread")) {
+               rep->nr_thread = perf_config_int(var, value);
+               return 0;
+       }
 
        return perf_default_config(var, value, cb);
 }
@@ -522,7 +527,8 @@ static int __cmd_report(struct report *rep)
 
        if (rep->multi_thread) {
                rep->tool.sample = process_sample_event_mt;
-               ret = perf_session__process_events_mt(session, rep);
+               ret = perf_session__process_events_mt(session, rep->nr_thread,
+                                                     rep);
        } else {
                ret = perf_session__process_events(session);
        }
@@ -664,6 +670,7 @@ int cmd_report(int argc, const char **argv, const char 
*prefix __maybe_unused)
                },
                .max_stack               = PERF_MAX_STACK_DEPTH,
                .pretty_printing_style   = "normal",
+               .nr_thread               = -1,
        };
        const struct option options[] = {
        OPT_STRING('i', "input", &input_name, "file",
@@ -774,6 +781,8 @@ int cmd_report(int argc, const char **argv, const char 
*prefix __maybe_unused)
                            itrace_parse_synth_opts),
        OPT_BOOLEAN(0, "multi-thread", &report.multi_thread,
                    "Speed up sample processing using multi-thead"),
+       OPT_INTEGER(0, "num-thread", &report.nr_thread,
+                   "Number of thread to process samples (>= 2)"),
        OPT_END()
        };
        struct perf_data_file file = {
@@ -820,9 +829,21 @@ int cmd_report(int argc, const char **argv, const char 
*prefix __maybe_unused)
 
        session->itrace_synth_opts = &itrace_synth_opts;
 
-       if (report.multi_thread && !perf_has_index) {
-               pr_debug("fallback to single thread for normal data file.\n");
-               report.multi_thread = false;
+       if (report.multi_thread) {
+               if (!perf_has_index) {
+                       pr_debug("fallback to single thread for normal data 
file.\n");
+                       report.multi_thread = false;
+               } else {
+                       if (report.nr_thread == -1)
+                               report.nr_thread = 
sysconf(_SC_NPROCESSORS_ONLN);
+                       else if (report.nr_thread < 2) {
+                               pr_err("invalid number of thread: %d\n",
+                                      report.nr_thread);
+                               parse_options_usage(report_usage, options,
+                                                   "num-thread", 0);
+                               goto error;
+                       }
+               }
        }
 
        report.session = session;
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 5f6c319bd236..747d63843bab 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1726,7 +1726,8 @@ static void *processing_thread_idx(void *arg)
        return arg;
 }
 
-int perf_session__process_events_mt(struct perf_session *session, void *arg)
+int perf_session__process_events_mt(struct perf_session *session,
+                                   int nr_thread, void *arg)
 {
        struct perf_data_file *file = session->file;
        struct perf_evlist *evlist = session->evlist;
@@ -1742,7 +1743,6 @@ int perf_session__process_events_mt(struct perf_session 
*session, void *arg)
        int err, i, k;
        int nr_index = session->header.nr_index;
        u64 size = perf_data_file__size(file);
-       int nr_thread = sysconf(_SC_NPROCESSORS_ONLN);
 
        if (perf_data_file__is_pipe(file) || !session->header.index) {
                pr_err("data file doesn't contain the index table\n");
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index fde658d5d081..a033e104f124 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -56,7 +56,8 @@ int perf_session__peek_event(struct perf_session *session, 
off_t file_offset,
                             struct perf_sample *sample);
 
 int perf_session__process_events(struct perf_session *session);
-int perf_session__process_events_mt(struct perf_session *session, void *arg);
+int perf_session__process_events_mt(struct perf_session *session,
+                                   int nr_thread, void *arg);
 
 int perf_session__queue_event(struct perf_session *s, union perf_event *event,
                              struct perf_sample *sample, u64 file_offset);
-- 
2.4.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to