From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB39EC4338F for ; Tue, 17 Aug 2021 08:24:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BA91260F41 for ; Tue, 17 Aug 2021 08:24:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239359AbhHQIZI (ORCPT ); Tue, 17 Aug 2021 04:25:08 -0400 Received: from mga14.intel.com ([192.55.52.115]:11571 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239243AbhHQIYm (ORCPT ); Tue, 17 Aug 2021 04:24:42 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10078"; a="215746813" X-IronPort-AV: E=Sophos;i="5.84,328,1620716400"; d="scan'208";a="215746813" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Aug 2021 01:24:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,328,1620716400"; d="scan'208";a="471080322" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by orsmga008.jf.intel.com with ESMTP; 17 Aug 2021 01:24:06 -0700 From: Alexey Bayduraev To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , linux-kernel , Andi Kleen , Adrian Hunter , Alexander Antonov , Alexei Budankov , Riccardo Mancini Subject: [PATCH v11 12/24] perf record: Introduce --threads command line option Date: Tue, 17 Aug 2021 11:23:15 +0300 Message-Id: X-Mailer: git-send-email 2.19.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Provide --threads option in perf record command line interface. The option creates a data streaming thread for each cpu in the system. Document --threads option in Documentation/perf-record.txt. Reviewed-by: Riccardo Mancini Tested-by: Riccardo Mancini Signed-off-by: Alexey Bayduraev --- tools/perf/Documentation/perf-record.txt | 4 +++ tools/perf/builtin-record.c | 44 +++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt index f1079ee7f2ec..0408e677c117 100644 --- a/tools/perf/Documentation/perf-record.txt +++ b/tools/perf/Documentation/perf-record.txt @@ -695,6 +695,10 @@ measurements: wait -n ${perf_pid} exit $? +--threads:: +Write collected trace data into several data files using parallel threads. +The option creates a data streaming thread for each cpu in the system. + include::intel-hybrid.txt[] SEE ALSO diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 06160627f975..246a5746a195 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -122,6 +122,11 @@ static const char *thread_msg_tags[THREAD_MSG__MAX] = { "UNDEFINED", "READY" }; +enum thread_spec { + THREAD_SPEC__UNDEFINED = 0, + THREAD_SPEC__CPU, +}; + struct record { struct perf_tool tool; struct record_opts opts; @@ -2781,6 +2786,16 @@ static void record__thread_mask_free(struct thread_mask *mask) record__mmap_cpu_mask_free(&mask->affinity); } +static int record__parse_threads(const struct option *opt, const char *str, int unset) +{ + struct record_opts *opts = opt->value; + + if (unset || !str || !strlen(str)) + opts->threads_spec = THREAD_SPEC__CPU; + + return 0; +} + static int parse_output_max_size(const struct option *opt, const char *str, int unset) { @@ -3224,6 +3239,9 @@ static struct option __record_options[] = { "\t\t\t Optionally send control command completion ('ack\\n') to ack-fd descriptor.\n" "\t\t\t Alternatively, ctl-fifo / ack-fifo will be opened and used as ctl-fd / ack-fd.", parse_control_option), + OPT_CALLBACK_OPTARG(0, "threads", &record.opts, NULL, "spec", + "write collected trace data into several data files using parallel threads", + record__parse_threads), OPT_END() }; @@ -3273,6 +3291,27 @@ static int record__alloc_thread_masks(struct record *rec, int nr_threads, int nr return ret; } +static int record__init_thread_cpu_masks(struct record *rec, struct perf_cpu_map *cpus) +{ + int t, ret, nr_cpus = perf_cpu_map__nr(cpus); + + ret = record__alloc_thread_masks(rec, nr_cpus, cpu__max_cpu()); + if (ret) + return ret; + + rec->nr_threads = nr_cpus; + pr_debug("threads: nr_threads=%d\n", rec->nr_threads); + + for (t = 0; t < rec->nr_threads; t++) { + set_bit(cpus->map[t], rec->thread_masks[t].maps.bits); + pr_debug("thread_masks[%d]: maps mask [%d]\n", t, cpus->map[t]); + set_bit(cpus->map[t], rec->thread_masks[t].affinity.bits); + pr_debug("thread_masks[%d]: affinity mask [%d]\n", t, cpus->map[t]); + } + + return 0; +} + static int record__init_thread_default_masks(struct record *rec, struct perf_cpu_map *cpus) { int ret; @@ -3292,7 +3331,10 @@ static int record__init_thread_masks(struct record *rec) { struct perf_cpu_map *cpus = rec->evlist->core.cpus; - return record__init_thread_default_masks(rec, cpus); + if (!record__threads_enabled(rec)) + return record__init_thread_default_masks(rec, cpus); + + return record__init_thread_cpu_masks(rec, cpus); } static void record__fini_thread_masks(struct record *rec) -- 2.19.0