Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1506573pxv; Fri, 2 Jul 2021 05:36:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxO+bFXP1IT06I1lL5yeMjFdwBbBP93G69v7VTTScgtNoaDuH9fHVfWhvDb6NqEOv/rtaps X-Received: by 2002:a05:6402:312d:: with SMTP id dd13mr6620094edb.140.1625229389604; Fri, 02 Jul 2021 05:36:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625229389; cv=none; d=google.com; s=arc-20160816; b=nlBQ9zJxKhRXyb6SsMYRACp503iJTH12CzakNkjvrdKviBPKWVv001+PG490srK3Up dpuNRrTAzdNWkx8kbVQaydzCRE+zDrmharq5diHmhcGCfJaL+pFyQ1xLXHQ0Aay0yNvx aqsCRr1Fvck8xKu3lu7bFUbkhrIMTgWvRd53wNXAmJ5DZld0kdo+HG1gr5/iBIaTeiCA Btneme4HaGNAI8h/VlDgy/ql12hzToHxfKtCU9mNAEzjhF0ixI+XrM2CZQiv3fyMB8x8 kbK8Ud85uqNIk/0aULatbpAdgSZRXnS7x497r8IpX3LLv8ZV6R8KnHBWhsklBiPAjr6W f4ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=jbcpngiAtU+LN8mLhT4XkSInhL5CJfxfj2vHRUogyvI=; b=LIoTwBigNeYMiTNaK1oIUORYlgoOraQIS/6M1N4L2ArlJqeIPV8U9+juPihHwG+0pn aJrX+PrMVyFuF9J4jEhsgE8MlRhPX/NG6HzHz0G6j30dHn+vzFz0QArbhNChYoaG9o4N 43mN8Iv0oj2Jw36+EGV+nRDv6eLWTHGlnOtZqPzBwV/r7V4M7Q9HDaPQ5VqOCOEAKAmn a4/hRInADofmUmwP3LJQo9k6p5AGNGJMzmkWW1kohleUNDrEsJ6NmW2z0B5CrkKBGmWr Nu2n6K62o6zj2plRL11abUmP/vo5d/eSxB7l/6ZvuPOJPzsH7HO4DVHLLZRMvAA5sZGd gUdg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g21si2875134edb.437.2021.07.02.05.36.05; Fri, 02 Jul 2021 05:36:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232331AbhGBMfq (ORCPT + 99 others); Fri, 2 Jul 2021 08:35:46 -0400 Received: from mga17.intel.com ([192.55.52.151]:32637 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232377AbhGBMfp (ORCPT ); Fri, 2 Jul 2021 08:35:45 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10032"; a="189107273" X-IronPort-AV: E=Sophos;i="5.83,317,1616482800"; d="scan'208";a="189107273" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 05:33:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,317,1616482800"; d="scan'208";a="642660281" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by fmsmga006.fm.intel.com with ESMTP; 02 Jul 2021 05:33:10 -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 v9 12/24] perf record: Introduce --threads command line option Date: Fri, 2 Jul 2021 15:32:20 +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. 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 d71bac847936..ca2771b80fd5 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 ba3f60f7882a..9a34ec45ce2c 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; @@ -2809,6 +2814,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) { @@ -3252,6 +3267,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() }; @@ -3301,6 +3319,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; @@ -3320,7 +3359,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