Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp279402pxb; Sat, 21 Aug 2021 02:23:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcxgWfA2UkMfsSOuIBAVgV+72/EqLSmcLntFx6eD5pZ/JndQ2SWL9Azh81qRKuGA/AbwxF X-Received: by 2002:a17:907:9851:: with SMTP id jj17mr25845045ejc.489.1629537833414; Sat, 21 Aug 2021 02:23:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629537833; cv=none; d=google.com; s=arc-20160816; b=FzyaTqoAvwEplnylMt6dkWUzBL9bZkndTY7qwrcB34uYdm3v8+lqiLpgo1Ehzri8GZ aUFWAIv64cGlDErn6HX9M4CKOB10cMhnybY9uVniaDn+4VjkQ+2ZhpYH5C8NfFcsbFqk dKzFmYKx6DvTBvxdH9cWpj9D+QPTn8i5Iam4cRN/f/Hr8AZWYu+rdc0CPiPuPu0f8ccO l817nYfFGGZtghg915Tyjdi/NNE8h9nEwlxZkSgX8+r4qrw2vQSZI9MTDcfW4O/Gaj73 Uhg7eT3zNMecHBY9jdK1oxfaF0Obb9zcbzjn10OIUcojPyCi55+f43i1bdDSVB1loint L6Ng== 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=bgPEK1IAfRbcf64sxtgFjOq9WczpOQefLSQknOJFNgw=; b=nA7Ks6dy5/9wuLmoavlyPwV8A4B/usPT3uwM02kPvCPRYcnKhJxpa+tguLGZWtwt+H 5lkNyv4ViieTqi8+ACqbhNejH9w1UMiZmrnu2fvyqpy1yjWxm7zWATQkiP3XxZJcby5Z ufrB+y300nslbMJ9vja/JVftr/SqX7VGlLc7QNErvcydlwMdXXdhSdC6Gj7InSWLxO8q qpp1Z/8aj4HmAde1qxA334Ypi382Y5xROfd6aivkqnbHvm9SLzvxJCY8G5AwhHbXJmWU GrL3ibVE9BZHVgl7jf/95Za6wn4wUbgL6mO/i3qEJRE6cw9nFJcHy2LWFysJMvDGTnBv cCZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="I+ilja/9"; 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 g4si8475998edb.578.2021.08.21.02.23.31; Sat, 21 Aug 2021 02:23:53 -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="I+ilja/9"; 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 S234755AbhHUJWe (ORCPT + 99 others); Sat, 21 Aug 2021 05:22:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235147AbhHUJV5 (ORCPT ); Sat, 21 Aug 2021 05:21:57 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40AF6C0611BD; Sat, 21 Aug 2021 02:20:20 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id d6so17650276edt.7; Sat, 21 Aug 2021 02:20:20 -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=bgPEK1IAfRbcf64sxtgFjOq9WczpOQefLSQknOJFNgw=; b=I+ilja/9mBtJaapuFwCjDpRGyqV9LZ0j1YOE1XhsqQh+VJfL1czIZpyz6YnvMGhy8F K2RKdt7PsrTVsWUe3QcRxSDN813QunrEfkmhL81CliwD3ub0Le2mCxTekPM3eiy56o7I 3Mj6+5sO5anoZW4e0/swEnKy/ijORJ6nxj5S7zTNUFuD8ZNb0OwR1tqwLCKVftVPzPvf PK7/LD+Uwbok9vxdLX6/oAdwHiYruiywNUGrrGrjQvOPRpgvN2UGprYp3xrEqgpA2/St xBQqmgVmYIjkuFijUuQoMwDEYCKLkGWUvBTDM08RxDrrjU5NgZ13l5AAW093Ee6aSL6o aAfQ== 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=bgPEK1IAfRbcf64sxtgFjOq9WczpOQefLSQknOJFNgw=; b=WP8dgJ7h38Zui2iSGMtgjjo8PKmBRUM08z1sz2fu0feH7/3ujD5nkToXAYDg1/kkgN 4HI/G6y5ZQmKGhUtrJiwuiGcPAHUW/1pNhfj/xj2WKPdRbCv5m1KncD+/z2XlW9G5FEy LGuD2HsJXOQI2X6vFUXSPwS+Eaa07csh+tXmvOH5I8y+k6FkxpAHiO4LU9tS7VpjSRWo RdtzWkqDgof8/ApxYRUsro8eNuDjvAOgwbRKvAxruF6GFX6HVZ4KYP8iPR0YwaqmNw5H 4BI8OnRVJCCwBDvVSQubfCWuRjWBdbmjpv+cjsgD1EyyM63z2bdkFRSZvIX0z4wM1A7X w6Qw== X-Gm-Message-State: AOAM5300X6a8cLUttNGOwmy72x+vu+bnPa/Ti+NA4p4smB2wwtTOJi8b DafHAdWioZJf+R04Qb68XGY= X-Received: by 2002:a05:6402:1cb9:: with SMTP id cz25mr190285edb.11.1629537618772; Sat, 21 Aug 2021 02:20:18 -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.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Aug 2021 02:20:18 -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 24/37] perf evsel: handle precise_ip fallback in evsel__open_cpu Date: Sat, 21 Aug 2021 11:19:30 +0200 Message-Id: <74208c433d2024a6c4af9c0b140b54ed6b5ea810.1629490974.git.rickyman7@gmail.com> 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 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. 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