Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp278690pxb; Sat, 21 Aug 2021 02:22:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKEcm5wTn+s9px6xGcQLY6W6cCs1UkpJAaQ9OVLY8XeqoE2GsZ3/CoSyWL6AgH9H75biFr X-Received: by 2002:a92:6a05:: with SMTP id f5mr9806794ilc.140.1629537752219; Sat, 21 Aug 2021 02:22:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629537752; cv=none; d=google.com; s=arc-20160816; b=VxmIrSfennHwNSG+EKSfv2qKpByMOFQybVdyFD/kw9fzvu6FJWgByDo44YFhd8vnFc ioQ5lqXARnOIM5T8e00/zq+lOA1UKHsd9sExAJ3llg6dK0vAiz+MsbTKQVMZQxAsggLF salPM5k0Zm7QD2W/actz5V6iMv9Rj/oLpiG3FZ+QqVU/cCav1m/mYpD33mB3350JW4rw QOQeUM7tgKYhxxSs4IVcZC5g3RRRp62kBWrPAiZiAsuRJ7C8aNAuVc6ogfpIvreLtY4M w3VcKec0VJJJ87kLGlZOC4VwMiXFQK6HAKD/eW3MO7JIVwmhCbUnoVroOY7cQMJSEzlY tV/A== 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=K06lN51zooeraOtXEnuTstuj3NqHpgaRejWVBk4KyOk=; b=t9snkVKaw4NdtAe+OyMiyIn1eq1bInu8BdbO3dXXIOkR766XRbhtrj3baPdxzNtMlr vvQ3nQhm217yOO0KkfIUKT9DU02WradCb9O3S4pSQiryunrf5DULcTYmWUYyuZg7qPgi +Wdo4Ibz1SRgImq/frofTcZDmx/GIR0MXJhh31KWxhMqAyRjl+pjh69IsxZWyjxw7NxA 2ptXYHZdkrZI/esFRcl8yVsFItR8Yn6nhN0W3p23S9Y/Hgk/Cf51Y4mFMf728f5iuCC6 /Y+YVwkt0ANWj8qMLAr0p1ymQIDFvEKZ/ngQbyM5v3HgH43n0cHCs7em6puNcIiymMPH cqlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PGI+h7CA; 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 t4si10375903iof.69.2021.08.21.02.22.20; Sat, 21 Aug 2021 02:22:32 -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=PGI+h7CA; 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 S233776AbhHUJVt (ORCPT + 99 others); Sat, 21 Aug 2021 05:21:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234073AbhHUJVQ (ORCPT ); Sat, 21 Aug 2021 05:21:16 -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 BDD6BC061226; Sat, 21 Aug 2021 02:20:09 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id bt14so25229171ejb.3; Sat, 21 Aug 2021 02:20:09 -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=K06lN51zooeraOtXEnuTstuj3NqHpgaRejWVBk4KyOk=; b=PGI+h7CA1GqZcp4I1rAnRgvjggxCainerJwwcK2u4W8y/JqKLtiE4yBNPAF1aLnLI2 mzYHhOBesppnvlNDBLvrlBtZ3HtN5yViQa1qAhxvbIYbTExwoHbvwS+TzGTObAXknsuY I3dEfvBhLmiHg8Du7CugiOSdi0Nl7CXb1lka+gP37UJ/9muyKhKZtzg3E0saCHlLm0Pv bB+ljE9Ctzqllh1W08dZLQRS04IihAx7K1P0gHrJLAQFoQobCe/lr6Ku1ihCabX/KJq/ QMe01khZWUY1Krhr75Redrn73SPJ9k7bQZplB/CkG7HPHEWStw+4Ttl990zuXQBLAjD1 UG2g== 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=K06lN51zooeraOtXEnuTstuj3NqHpgaRejWVBk4KyOk=; b=odLnZPLCIletJhoICxpxwB8qKKwKLve8HwzLShih8XjbbqhGnZjl/vZOXMeS5elk6i K5LRfaxhYE3AAUDIaEIqiozvsc5AVQJg4kNcksDzQ3NXzc3Qwiab8OUbymeuCs3hcVZD ZTt6n2jTMtvWdGPBpkT4lepwRdRNQ/lhQS35/uwBKqrffnqzE9cug05RjumTrYjDTym9 wuFSFOZzxdE/tY0tjwJXqwcXS9Oqq31XGb+1pjycwnExbIKqyrU7JTCVTYXEFKeH+0TW LYdmM7qbV44w0Y394ubyyCeppOiXZBS9HwjPB5kBUAmpjytyceME9d9prFT9InReVbxP sbSg== X-Gm-Message-State: AOAM5316VM9VVWzLMs+xh0j3YKqOUGSLtc83j4iclYafIGhEDGasXffc UdZalCPI80+qyM6UQ7vDFWU= X-Received: by 2002:a17:906:e57:: with SMTP id q23mr25767665eji.483.1629537608295; Sat, 21 Aug 2021 02:20:08 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Aug 2021 02:20:08 -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 16/37] perf evsel: save open flags in evsel Date: Sat, 21 Aug 2021 11:19:22 +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 caches the flags used in perf_event_open inside evsel, so that they can be set in __evsel__prepare_open (this will be useful in following patches, when the fallback mechanisms will be handled outside the open itself). This also optimizes the code, by not having to recompute them everytime. Since flags are now saved in evsel, the flags argument in perf_event_open is removed. Signed-off-by: Riccardo Mancini --- tools/perf/util/evsel.c | 24 ++++++++++++------------ tools/perf/util/evsel.h | 1 + 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index ddf324e2e17a0951..509a2970a94b3142 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1710,17 +1710,16 @@ static void display_attr(struct perf_event_attr *attr) } static int perf_event_open(struct evsel *evsel, - pid_t pid, int cpu, int group_fd, - unsigned long flags) + pid_t pid, int cpu, int group_fd) { int precise_ip = evsel->core.attr.precise_ip; int fd; while (1) { pr_debug2_peo("sys_perf_event_open: pid %d cpu %d group_fd %d flags %#lx", - pid, cpu, group_fd, flags); + pid, cpu, group_fd, evsel->open_flags); - fd = sys_perf_event_open(&evsel->core.attr, pid, cpu, group_fd, flags); + fd = sys_perf_event_open(&evsel->core.attr, pid, cpu, group_fd, evsel->open_flags); if (fd >= 0) break; @@ -1788,6 +1787,10 @@ static int __evsel__prepare_open(struct evsel *evsel, struct perf_cpu_map *cpus, perf_evsel__alloc_fd(&evsel->core, cpus->nr, nthreads) < 0) return -ENOMEM; + evsel->open_flags = PERF_FLAG_FD_CLOEXEC; + if (evsel->cgrp) + evsel->open_flags |= PERF_FLAG_PID_CGROUP; + return 0; } @@ -1796,7 +1799,6 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, 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; @@ -1815,10 +1817,8 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, else nthreads = threads->nr; - if (evsel->cgrp) { - flags |= PERF_FLAG_PID_CGROUP; + if (evsel->cgrp) pid = evsel->cgrp->fd; - } fallback_missing_features: if (perf_missing_features.weight_struct) { @@ -1832,7 +1832,7 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, evsel->core.attr.clockid = 0; } if (perf_missing_features.cloexec) - flags &= ~(unsigned long)PERF_FLAG_FD_CLOEXEC; + evsel->open_flags &= ~(unsigned long)PERF_FLAG_FD_CLOEXEC; if (perf_missing_features.mmap2) evsel->core.attr.mmap2 = 0; if (perf_missing_features.exclude_guest) @@ -1866,7 +1866,7 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, test_attr__ready(); fd = perf_event_open(evsel, pid, cpus->map[cpu], - group_fd, flags); + group_fd); FD(evsel, cpu, thread) = fd; @@ -1874,7 +1874,7 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, if (unlikely(test_attr__enabled)) { test_attr__open(&evsel->core.attr, pid, cpus->map[cpu], - fd, group_fd, flags); + fd, group_fd, evsel->open_flags); } if (fd < 0) { @@ -2012,7 +2012,7 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, perf_missing_features.clockid = true; pr_debug2_peo("switching off use_clockid\n"); goto fallback_missing_features; - } else if (!perf_missing_features.cloexec && (flags & PERF_FLAG_FD_CLOEXEC)) { + } else if (!perf_missing_features.cloexec && (evsel->open_flags & PERF_FLAG_FD_CLOEXEC)) { perf_missing_features.cloexec = true; pr_debug2_peo("switching off cloexec flag\n"); goto fallback_missing_features; diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index eabccce406886320..1c0057e80d080f2f 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -149,6 +149,7 @@ struct evsel { struct bperf_leader_bpf *leader_skel; struct bperf_follower_bpf *follower_skel; }; + unsigned long open_flags; }; struct perf_missing_features { -- 2.31.1