Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp279875pxb; Sat, 21 Aug 2021 02:24:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZ4qgYlgQMT57+jg6fEeJLjt7KJKLj+/fdMCqffgjixu36BZMgeYV6FFuMkNfI4/7+YGmM X-Received: by 2002:a05:6e02:1a0e:: with SMTP id s14mr16404294ild.48.1629537878821; Sat, 21 Aug 2021 02:24:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629537878; cv=none; d=google.com; s=arc-20160816; b=WwEQn+x5rhPGJYOvHEkgOb5wZ4NFdUb8hw+7huJEShhs3uO2JfSmDcwvtTNMBwKIed 22SS+stDIfRO4qp/FAPt8USQCpEI+RYrq8w+oM3KOirIFp+rGTKDVgdGMr0/PrC9PYXe MT0AcyJAsK7BcfTscK7pJoF8dJ4IAkqBUyIZIv8FCfe4nPW6NhXoC0PXtJ48IVi6bO7/ S5MiTIB4tod2yMqn5Rat1GlO3Y+pmMxg08szfedds327KWbLVGU06RHBmeA57iMySBu3 jydkgYL87/T1M3nZ3jVjimufptNP3y0ZtqGvlHu3E1l1p3q9sUOH5fqt7i9HglR+VOkX CsVQ== 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 :dkim-signature; bh=3Nz5cuYI+OBcCvgsxocGu8/AZ30FKdwuuYGkZjJe3RI=; b=b8giSkXx3jA4dXIGZ1gmxyj8xVjAM/CeBqYAPhsmTXmo5mpgZtwHr54aqqrQ4bjM2V za0PBhgC9bbggzyL/V5szvlRzr2ItLqXeKPq5KKePbPo2niS5KrQE3N1el0mdJV8r3mu ag3XUfSs5XsRynzF0QgLWr1NqhBKlzsY/vMbdzwbs1JOa0KFSLEqIBHnQX4Uur41FJjz yUeEcWXFcc5/mmKAfzjdWs5HfKG5rX+1o4m/hxaR8nFFkZ+B2V9vTcfyjT4RCHFDqTOC kCyizBFcbEsp+i+jAaw0RJloE9H7A2C9Nq9cUrN34A++1V+J9pOODSAajtbDy+TRK79e FE7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=XlfGwAjv; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u4si7788673jak.106.2021.08.21.02.24.27; Sat, 21 Aug 2021 02:24:38 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=XlfGwAjv; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241098AbhHUJXL (ORCPT + 99 others); Sat, 21 Aug 2021 05:23:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234073AbhHUJWc (ORCPT ); Sat, 21 Aug 2021 05:22:32 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5DAAC061152; Sat, 21 Aug 2021 02:20:32 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id z20so25183200ejf.5; Sat, 21 Aug 2021 02:20:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3Nz5cuYI+OBcCvgsxocGu8/AZ30FKdwuuYGkZjJe3RI=; b=XlfGwAjvHqfY+y4udXph83bMIIMSpq+LH04Tv1UnmEAhu+SI9fZUUDs8BQlQmhWdPn Y7cfA0zb+kADyU9y1OZPZ9t2mjEJQBD1OwjPxi8/76ohjBipKsx778JAaxcqaoVmQxLM maTYh5GJETMpfc91FdgA8MSnIw+7IyOEkLiehoCzgC7iQnRoQEC1wXDZ3zADk1mBfOgP dIGgtMI1P6+bhVPv0zCmRpO5ayN+CrHb8/nNFODRBnG+6uZy6aCkNli3/YJysAoJ5c2o 3bgrIeA8j/3btQV+VNS4CJ/77cTlPqsbQWmq/WUfDMr2fR90HRF6MT1jI/KimY2zRw+M 1YhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3Nz5cuYI+OBcCvgsxocGu8/AZ30FKdwuuYGkZjJe3RI=; b=JoI+5hcJi7GLEixgDoCqCkjM78MJUs7ZcPtpJLgyweEh2DuBx6fwdvzSw0S9gvvY0f 1Wq3r+oB/6L2FF9iJqnyCrWzqYdvPTa2NNdA/MvGgRaWBI3EUGtrGO5Vo2RAqGubWCLG 4/UQ9oOL4+wscAIcufWKNikSXB6XeAs7+yB5AduYGtSP+B/01bboDB+pvj1gyyQk+O5i cL/ty0sstoCzrhYwhbyAYGPkWXBocGQzFPik1W0/9WZ6jQHdvHNuYgkVIIdnTdrNYk6c OUfv2HRgKTSPU4x0XDysVh+j/dyg+9z9sN/CYONtfSE6T7PHT/ht0ScMECFEqNiD4mhR yjPQ== X-Gm-Message-State: AOAM530jboCXGa/6u0KRQJxONLv8q4jfCGNtUjYC+5ipBrkGL8hcqwux Lmn6ci1AskNOn5LzAmwzCis= X-Received: by 2002:a17:906:ac1:: with SMTP id z1mr25592170ejf.261.1629537631322; Sat, 21 Aug 2021 02:20:31 -0700 (PDT) Received: from honeypot.. (mob-176-243-254-204.net.vodafone.it. [176.243.254.204]) by smtp.googlemail.com with ESMTPSA id a25sm4003878ejv.91.2021.08.21.02.20.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Aug 2021 02:20:30 -0700 (PDT) From: Riccardo Mancini To: Arnaldo Carvalho de Melo Cc: Ian Rogers , Namhyung Kim , Peter Zijlstra , Ingo Molnar , Mark Rutland , Jiri Olsa , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Riccardo Mancini Subject: [RFC PATCH v1 34/37] perf record: apply multithreading in init and fini phases Date: Sat, 21 Aug 2021 11:19:40 +0200 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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