Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp278593pxb; Sat, 21 Aug 2021 02:22:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBLkEVafjZ9ircwaOBgxzsdtoUBHNFHs0heiJR9468ApZL3ZKc0FD5FQps79TH1zwbM03r X-Received: by 2002:a92:c145:: with SMTP id b5mr7003005ilh.150.1629537738808; Sat, 21 Aug 2021 02:22:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629537738; cv=none; d=google.com; s=arc-20160816; b=COfeBin2+W9v84NXeJoxIYTqQFlEIuLjKr0Q7KxrlYLbAwTOqaqm1yPrnAmC04h0Ep fgsvv3NS1+NTw8qjnM6zGv+hy876Upjn89K+vkzIpLQ7m2wlgzQgDXDOI95zEo0zo2eD TOVr3rjJQev8G+Xf38trnT0ZoRIPS2ovwbVyWvVTm21TKfZh4Jf0X95MRYckQ0YunHoR JrDpmQ2VZvCjhS6q9LOfxa2J7RtI4qtfKlD8cBMdqNEBYbo4/OCmqmWXewhyc0AI82wG JTv3q3L+MHn6o/FMd7zBNUCbQuWPgMIGpNmnyL9Kn57hB+yVboL3bSFIF3PMqkV8yehY SRZA== 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=BJSUm8Y9WnxzFwDFjQxHNxBZXFxJQPdQmlVoLoTFeKI=; b=tw+m3QrfY3Iey4kTWDqPGpVuRqaRh+g5KBDx2LcS/5cVlqVCaLg9aGOBib9lcCbH6n HKD27f1EfwSCp0MoOwDfDd0pVpxkaF+wKL1c2PdXD7S8yxO8/iUZCYPsBOK3yXJR9dxp fj8llxvFajM8LhRO3g5sgP4sSn53brEkRlwhdMQZ46k7ikOKecaK69EmAznZn+bx1xQx nBrPvFjMQF8hrsgOf2QAR+7ey4DS+SNTEqgd4jUjy/w0YOgILDOJRfx4otyOc8lxqbfc nehMOvf0lRGdKJfUg9URKwKxeepbXEeCPsLUzOmbZAXmG1J2EEUz4sCh6B7KCoOXMSzq ZEnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=F3uSEing; 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 w4si8738992ioa.95.2021.08.21.02.22.07; Sat, 21 Aug 2021 02:22:18 -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=F3uSEing; 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 S234381AbhHUJVk (ORCPT + 99 others); Sat, 21 Aug 2021 05:21:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233806AbhHUJVP (ORCPT ); Sat, 21 Aug 2021 05:21:15 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A42CC06124C; Sat, 21 Aug 2021 02:20:08 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id ia27so2990907ejc.10; Sat, 21 Aug 2021 02:20:08 -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=BJSUm8Y9WnxzFwDFjQxHNxBZXFxJQPdQmlVoLoTFeKI=; b=F3uSEingtZ8e2chaZYz9uYo2cTkvJWXNwlgxioO9kGhbAhoJKJhNipWw0o9rWStTzV RpZZJE1XvmbaVlHEWfapDpAg24tCNWhNNQJnBhDaBtgndh8XFnTvIwCTM2EWyMewMkPo /igCQT7wVgYn0BE1aJWEzqNOEHjQEYtxkz52VbnjiMx5At0Nlf9doLbgFzFmvrbEjoo+ c+WZtAKgwiM+PUkfu0YwmUgf4zbqmgN7Zrg8xjvUTd1NypFWJsfWVw6k8ZqowqeT11u+ BidrcuPhZ74fpLlBRtAz2D2jRnABTuckS12vIdwQaoy0T76sy3H//rE3ci3fbGNKNZdd Q3Sg== 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=BJSUm8Y9WnxzFwDFjQxHNxBZXFxJQPdQmlVoLoTFeKI=; b=WhOntWXsy9wEBSoib79oc/2Uyg+9HlTrFzVaXMEEuD35g4SnaAdZ/+CT+hsMmaG+wu WgY3ngy6DaBIBmum1tbr6PywvzHwyENYsplg4ccYGonkbxk1W5oh0P6jLDkVaPKpCJJP qWBDE46RgteHe2YnuFFsiCw7n+CX2jfEZPm0/sYglJhYl2gcErGRJNIXCrW0Xrz1FDVG TI3brDmUVfOZCsbSS/3w4JPqDi9E1756OHwWelUMWyvwB8JA6ix+E8qYOP7U83Aix8T4 JQburLmPlqFwYVvDV7DdJBYaUn6zSBPdXysqfB8WqOXI310eO/amcCyNXC9btyGG8Xk+ oN6A== X-Gm-Message-State: AOAM533iI6IVhrwVqLiD/opclEb/yLJQFjzYrsz9eSgf2hrpPK75SwaH Q5zG5G0+Uf+dBCt7+KcCCow= X-Received: by 2002:a17:906:405:: with SMTP id d5mr25680829eja.189.1629537606974; Sat, 21 Aug 2021 02:20:06 -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.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Aug 2021 02:20:06 -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 15/37] perf evsel: separate open preparation from open itself Date: Sat, 21 Aug 2021 11:19:21 +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 is a preparatory patch for the following patches with the goal to separate in evlist__open_cpu the actual perf_event_open, which could be performed in parallel, from the existing fallback mechanisms, which should be handled sequentially. This patch separates the first lines of evsel__open_cpu into a new __evsel__prepare_open function. Signed-off-by: Riccardo Mancini --- tools/perf/util/evsel.c | 45 +++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 7b4bb3229a16524e..ddf324e2e17a0951 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1746,22 +1746,20 @@ static int perf_event_open(struct evsel *evsel, return fd; } -static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, - struct perf_thread_map *threads, - int start_cpu, int end_cpu) + +static struct perf_cpu_map *empty_cpu_map; +static struct perf_thread_map *empty_thread_map; + +static int __evsel__prepare_open(struct evsel *evsel, struct perf_cpu_map *cpus, + struct perf_thread_map *threads) { - int cpu, thread, nthreads; - unsigned long flags = PERF_FLAG_FD_CLOEXEC; - int pid = -1, err, old_errno; - enum { NO_CHANGE, SET_TO_MAX, INCREASED_MAX } set_rlimit = NO_CHANGE; + int nthreads; if ((perf_missing_features.write_backward && evsel->core.attr.write_backward) || (perf_missing_features.aux_output && evsel->core.attr.aux_output)) return -EINVAL; if (cpus == NULL) { - static struct perf_cpu_map *empty_cpu_map; - if (empty_cpu_map == NULL) { empty_cpu_map = perf_cpu_map__dummy_new(); if (empty_cpu_map == NULL) @@ -1772,8 +1770,6 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, } if (threads == NULL) { - static struct perf_thread_map *empty_thread_map; - if (empty_thread_map == NULL) { empty_thread_map = thread_map__new_by_tid(-1); if (empty_thread_map == NULL) @@ -1792,6 +1788,33 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, perf_evsel__alloc_fd(&evsel->core, cpus->nr, nthreads) < 0) return -ENOMEM; + return 0; +} + +static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, + struct perf_thread_map *threads, + int start_cpu, int end_cpu) +{ + int cpu, thread, nthreads; + unsigned long flags = PERF_FLAG_FD_CLOEXEC; + int pid = -1, err, old_errno; + enum { NO_CHANGE, SET_TO_MAX, INCREASED_MAX } set_rlimit = NO_CHANGE; + + err = __evsel__prepare_open(evsel, cpus, threads); + if (err) + return err; + + if (cpus == NULL) + cpus = empty_cpu_map; + + if (threads == NULL) + threads = empty_thread_map; + + if (evsel->core.system_wide) + nthreads = 1; + else + nthreads = threads->nr; + if (evsel->cgrp) { flags |= PERF_FLAG_PID_CGROUP; pid = evsel->cgrp->fd; -- 2.31.1