Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp48017pxb; Tue, 31 Aug 2021 14:50:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOFBFYA0sNp5Djd1J8PiQD4bZhZdnSS4SToIDmpx6wrObAPbDDH/kzJlQ3uoFLlukbqqUr X-Received: by 2002:a17:906:7716:: with SMTP id q22mr33785437ejm.457.1630446617664; Tue, 31 Aug 2021 14:50:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630446617; cv=none; d=google.com; s=arc-20160816; b=Qal2Co4msg5tg5E8xMo2qcgjfSZmeXml8lhG+as3e6Obnr6QR7zbeY8cW6AwGT47yD yQ0jxcN5wG6U7nbbDM9VCUJ/soRAjJ6t790NiwdYqNTK8ABI/f0BfhnymNAMNou+wLD7 xhyXb/+TkiAVIeBWToAVjtlGkABMatbaKOBGaAPy83op8pDaGymnbGnfAGRgZTUjhrbe zBCel+WdU1hRtD0BXgF4iyEWLWQBMnrB8j5KpuxQxeOU0UW18D4PzDPq+PA4EJOn9+7g V412vBcUNKVpV7vkAVwXLCJIwibEB63LRJoFChg6rnxa35LzIJz6dl/EsL/ZS6/VnDpT Jtrw== 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=Z3Lf3uYqA7qT7GLwv1cMni6g+3OKzRqpwCSwKzuWOm0=; b=sTM6ifOS48anHYLSqtfRgb+t9qYw7IuqNMpadbaCBudLqbsPFY9xIDCDQrA/5gyGoj LpHIEXgDYRzd71cyc+e+wXvPBs/403fs5TyBmnbZV0QdZs38awUJ0Xv90yuPwAxpnHin pZVLjj5kE+JmLeXfzO7QlsQ8PVqPAMC30tvk077LoZyK/YI+wHOmm6apCl5DKSTQa/du gYsjDHL7XgWGIA7JDkVndO2XVnqcG6nZcInJj1Ii2Bh9w0swfHBp8LUYfBoJROihOXFS XeunWWj/+zHz7nx+uMiDhu9mnx4J7PYcP0p0fzMYzxGlJJGmWDgSQPKa1aQtGNVHh04S jS3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Gvz1NPpy; 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 s18si14959564eji.59.2021.08.31.14.49.46; Tue, 31 Aug 2021 14:50:17 -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=Gvz1NPpy; 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 S241054AbhHaTxv (ORCPT + 99 others); Tue, 31 Aug 2021 15:53:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:59462 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241009AbhHaTxr (ORCPT ); Tue, 31 Aug 2021 15:53:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 36CFD6108B; Tue, 31 Aug 2021 19:52:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1630439571; bh=xNMN2u+WxIaMkCU2FbZtFtSdUVxdfHTvJJz6sJp62V0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Gvz1NPpyTnZ3uclqKuiMGhsk9g3YiKbrHAaH89MLILtmJMA9+T78PY33gyOWC0Wii b3/Ju0NFxf1LHBbtThBSwmnpcsFoXsGoHvtpBdUpkRxtXnzD7dolMAGckDy9mvPtmt yqqI123QuNFWRnpuV58AAhq/uBgwgLajmUIQ6biEzLLGjd0M9+RqMYUSH9g/2SWdzB WlNAvxahwweui4Lt1JpFA7ALfMQoYXwjpJ0LSly0f2WEW6c7JGLH4i0l8//fksHLd8 OW6aBddmlVPVXNlQBic+eHqcrLagxcOEFl+mroJnVGC1fxNOhB6eY8YAB/qSzWBGYa 57jB3BB3AHn0w== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 083AB4007E; Tue, 31 Aug 2021 16:52:49 -0300 (-03) Date: Tue, 31 Aug 2021 16:52:48 -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 24/37] perf evsel: handle precise_ip fallback in evsel__open_cpu Message-ID: References: <74208c433d2024a6c4af9c0b140b54ed6b5ea810.1629490974.git.rickyman7@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <74208c433d2024a6c4af9c0b140b54ed6b5ea810.1629490974.git.rickyman7@gmail.com> 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:30AM +0200, Riccardo Mancini escreveu: > This is another patch in the effort to separate the fallback mechanisms > from the open itself. > > In case of precise_ip fallback, the original precise_ip will be stored > in the evsel (it was stored in a local variable) and the open will be > retried. Since the precise_ip fallback will be the first in the chain of > fallbacks, there should be no functional change with this patch. Thanks, looks ok, applied. - Arnaldo > Signed-off-by: Riccardo Mancini > --- > tools/perf/util/evsel.c | 59 ++++++++++++++++++----------------------- > tools/perf/util/evsel.h | 2 ++ > 2 files changed, 28 insertions(+), 33 deletions(-) > > diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c > index 3e556afed8dd396c..2e95416b8320c6b9 100644 > --- a/tools/perf/util/evsel.c > +++ b/tools/perf/util/evsel.c > @@ -1709,42 +1709,29 @@ 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) > +bool evsel__precise_ip_fallback(struct evsel *evsel) > { > - 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, evsel->open_flags); > - > - fd = sys_perf_event_open(&evsel->core.attr, pid, cpu, group_fd, evsel->open_flags); > - if (fd >= 0) > - break; > - > - /* Do not try less precise if not requested. */ > - if (!evsel->precise_max) > - break; > - > - /* > - * We tried all the precise_ip values, and it's > - * still failing, so leave it to standard fallback. > - */ > - if (!evsel->core.attr.precise_ip) { > - evsel->core.attr.precise_ip = precise_ip; > - break; > - } > + /* Do not try less precise if not requested. */ > + if (!evsel->precise_max) > + return false; > > - pr_debug2_peo("\nsys_perf_event_open failed, error %d\n", -ENOTSUP); > - evsel->core.attr.precise_ip--; > - pr_debug2_peo("decreasing precise_ip by one (%d)\n", evsel->core.attr.precise_ip); > - display_attr(&evsel->core.attr); > + /* > + * We tried all the precise_ip values, and it's > + * still failing, so leave it to standard fallback. > + */ > + if (!evsel->core.attr.precise_ip) { > + evsel->core.attr.precise_ip = evsel->precise_ip_original; > + return false; > } > > - return fd; > -} > + if (!evsel->precise_ip_original) > + evsel->precise_ip_original = evsel->core.attr.precise_ip; > > + evsel->core.attr.precise_ip--; > + pr_debug2_peo("decreasing precise_ip by one (%d)\n", evsel->core.attr.precise_ip); > + display_attr(&evsel->core.attr); > + return true; > +} > > static struct perf_cpu_map *empty_cpu_map; > static struct perf_thread_map *empty_thread_map; > @@ -2004,8 +1991,11 @@ 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); > + pr_debug2_peo("sys_perf_event_open: pid %d cpu %d group_fd %d flags %#lx", > + pid, cpus->map[cpu], group_fd, evsel->open_flags); > + > + fd = sys_perf_event_open(&evsel->core.attr, pid, cpus->map[cpu], > + group_fd, evsel->open_flags); > > FD(evsel, cpu, thread) = fd; > > @@ -2058,6 +2048,9 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, > return 0; > > try_fallback: > + if (evsel__precise_ip_fallback(evsel)) > + goto retry_open; > + > if (evsel__ignore_missing_thread(evsel, cpus->nr, cpu, threads, thread, err)) { > /* We just removed 1 thread, so lower the upper nthreads limit. */ > nthreads--; > diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h > index 661d2677a19b6248..0a245afab2d87d74 100644 > --- a/tools/perf/util/evsel.h > +++ b/tools/perf/util/evsel.h > @@ -150,6 +150,7 @@ struct evsel { > struct bperf_follower_bpf *follower_skel; > }; > unsigned long open_flags; > + int precise_ip_original; > }; > > struct perf_missing_features { > @@ -297,6 +298,7 @@ bool evsel__ignore_missing_thread(struct evsel *evsel, > int nr_cpus, int cpu, > struct perf_thread_map *threads, > int thread, int err); > +bool evsel__precise_ip_fallback(struct evsel *evsel); > > struct perf_sample; > > -- > 2.31.1 -- - Arnaldo