Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp4757879pxb; Tue, 31 Aug 2021 12:33:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPWaNiwSKR4XhV/q/LFb1h2l3499xmuSxXjbCcyjcNjXhW47GTeXg/iVZUwvbpJ2bkApFg X-Received: by 2002:aa7:c1d0:: with SMTP id d16mr31909149edp.110.1630438414636; Tue, 31 Aug 2021 12:33:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630438414; cv=none; d=google.com; s=arc-20160816; b=W2AS8h0LPy4p0ivR7W1PkF59XbAsYwkM+UjdUdeov6gNDKamuDV684tW5LO1ForU4/ L9wH6EJIp7iUswO2Z8jscYSB3AaOOtlyhIxDR+9LsWh/scG0UCqZxzoXXsVnjbqZKeqL jBX3jDcuV1szV8GL2zKnNTSFF2f6tXvDnC5ikHDvbSwNf+Hnt/8Ac5R6VA2pnosASmBW 0lVZt63qkoC3dbk+mbSetMCcSicvq97MYBN8NK+Mk2GX7yXgmCgz9N0Fv2FkNBKHcefB 2Myx/tDEjqx1rt8mp4BmnVkOCnPsVamNvf/pwQcgKKkaUoshDE4tTwiNcQYcFM27gisB /k2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=FS964hk49rPLz/fzolg3ie3mKTQt1D1OgtQKGKkI3S0=; b=GClkKij14SY98B6jWlx0E1lxV3pLrfIWtFG7F4cL0Gskq4CQ8v2A61OyaVNM8zbo3R +RXTbTZC4wnZuFqqxPBlXca2/gdz7dA0TfxG5qYOO1b3IAmtBRc4m5iYWJYEAV9tXdIH 1Eoft4R77DrP+IOMuywnHEoVghkwbvjWf9Pa+gT9UpVEhEahTREidPUin4jpM0POovQY wKyVtT9onk8k+VMhgId9xYm3evKbej7YYRYUUQSFxspr+2draAwVwB3T0vWLwtF0POBp Kl5SP44zKlKtdQoz0KyZfUDJ6f84JcP01RFT17cDmXV8aaXYMZaYCEobAWtc738X5n/A WYqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZmEuKQQC; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v20si17354351eji.303.2021.08.31.12.33.07; Tue, 31 Aug 2021 12:33:34 -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=@kernel.org header.s=k20201202 header.b=ZmEuKQQC; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240620AbhHaTcD (ORCPT + 99 others); Tue, 31 Aug 2021 15:32:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:43392 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234139AbhHaTcB (ORCPT ); Tue, 31 Aug 2021 15:32:01 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D0F6260F91; Tue, 31 Aug 2021 19:31:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1630438266; bh=NFwDSnpklMxKC8EPBXBrgV0olmRU2p/XdOiop04+OXY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ZmEuKQQCj4tfmsYyd5IsPjxYsRUf3ApRsmYdwQ6q3/qUi76aR0LmiwGmXuyVQPjdB CNGvHoIM5ZEqHo8f9lc31czbFDwjIY01Chxsghw6C9Q1LfFs/BUofJrztjHzJVun+j 0Niqp6lNuaGceUIjD66H5UXzQ+OdNFltfUTCO+EmkcjcwyDFpeRYsN6lQTu1z3SfYw P3inIZDD0vBMtQSlToI4yXOvx228cHUkBtjLXLoa09050UQb3QIj9wOvAqkefAVeKu dokUAuH8DUqskf5u0K3XtWkXRxiKK0pRRVEiK4Kh1VFJqnTHwSwKjdLz1J4gRT0YPm tFM5+VinuW+BQ== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 720894007E; Tue, 31 Aug 2021 16:31:03 -0300 (-03) Date: Tue, 31 Aug 2021 16:31:03 -0300 From: Arnaldo Carvalho de Melo To: Riccardo Mancini Cc: Ian Rogers , Namhyung Kim , Peter Zijlstra , Ingo Molnar , Mark Rutland , Jiri Olsa , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: Re: [RFC PATCH v1 16/37] perf evsel: save open flags in evsel Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Sat, Aug 21, 2021 at 11:19:22AM +0200, Riccardo Mancini escreveu: > 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. Nice, thanks, applied, I'll make available what I have in tmp.perf/core so that you can take a look before I push it all to Linus, this week. - Arnaldo > 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 -- - Arnaldo