From patchwork Fri May 26 21:54:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13257407 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6F9F9C77B73 for ; Fri, 26 May 2023 22:41:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=BTmXuSRgnT0EfaIduNL7vKCv4ErjlUMDsjGi/UaXXXY=; b=WFv8HTjt+CQm8D f94M3MmwPYFPA5KV769k7Sx8gqX8WeJbEZ62dpwUPi1EyJN07JDY1zKKtE6y3iSIKkfqdvdsyIZCu i3U6Q7UaYiwrRtkqzSLeQGSEQNBzSWr6A1Q+7kJlopq2XrW72wq6TI5s0L5IXjCeGfDOFmeKKTYI/ f//EdE82O0N05lV/tnX4VqFl36SPHZ2Jhr/eUGc3lpb4MngXQJXZmIxn5FsBbupKrRcnk9VWQzzHM Sk5wpnycaM94logOudW/VjB0hfJ5gFaJuyMAf8VRYcl9iygsRNSPOuE7cf0O/k+BiZRZrz1q772aa 7t6p+3tkJy0mu1oWFPAg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q2g7B-004A6U-05; Fri, 26 May 2023 22:40:53 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q2g6f-0049qh-1l for linux-arm-kernel@bombadil.infradead.org; Fri, 26 May 2023 22:40:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description; bh=rh9VPjugtBPm6X+hrybIGNZEfoE06aG1Vq+cBf1Euw8=; b=g4/xT3r9LKEPJ8ZhVRia9h8M6J Y0nKOy/3UdM43m/yKqBhJPNogES+k9DW5voFFV6SArTkA+4Qm5ZEtMo0UqDdUfwpADfEmW04INbrn 6Ca4Upabl98hlhWHbljIt+xDomklINHbZCCyIOW9z53hCye2SNk68Zv6yzrJzRV7AvRqFioQMKh+d SS+wrF3k9qd2zyHv/6VWPfzLpT8IlVjHRZhIXtH3VsUUw2rmTA3RNZi8RNCe3ZmY1YLoCXv6lfuB0 DXUeqo35nCWivWe3ht42Qr3I9/MvY0QVt3wdjq60ETntx99cub+8onujnF+BGLFnTxL6MYoi7m2cA Yek4hd8g==; Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q2fPB-007ixD-15 for linux-arm-kernel@lists.infradead.org; Fri, 26 May 2023 21:55:28 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba69d93a6b5so2683235276.1 for ; Fri, 26 May 2023 14:55:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138123; x=1687730123; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=rh9VPjugtBPm6X+hrybIGNZEfoE06aG1Vq+cBf1Euw8=; b=NT47HnCq13e2wZRzBEQWWbHa/45uvSJ/XVEwTiDIWl1gDOzU7WvOS2G/IJ5doVx4AG HDJ+am3vb+kV/p1Z7SsxVG2Xpvdd5jMwtiWLTdgSOWbczhyR+kDdn3YesUdkW6qJvfeT rYAq1RljWhu/+pnAP2BF6TRkkP3YaZatsjHazMIyTwIglHKhqD2l33MfmWciS6kTcqgF b6B9h4GNjQwp6TxdvDgQCv5pLmko9M+nBiGytDeb9QNrigkOPNFadhoiw4Eq4zwqUtix qVYZ79buD0oir3DABZBTE8DO/WSaGe4DoB4bVCoQXYB4tdLNUCQMsBHc+MEEu6MXtOiG BBpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138123; x=1687730123; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rh9VPjugtBPm6X+hrybIGNZEfoE06aG1Vq+cBf1Euw8=; b=HmgKcFlKazFLTfH2xbHNXR9Z5OPkjA5PL7Ay8wFIzY8tX+a8CbDVCUHFIYOBAM2rpk CWXaYW3suyLU0XxnOb7q1zNUNduDCwlPFNTs5vmAecv5BhHRnRXfEQzKIymRCKC9v+tp gPW2XHq+e5bHcQzUluSaf9EiG7hIf5MolNnVOz/iZei8TgC5qZdHg+XkEWuoUS5GEA0v djVgi3C2v1PDGt3GfjIWhQqVY/zPbiLZqUZ91C4MGfufD48bch1nOJrQqXy96DiomnTY 90F19EIO/ZcC4GJ5rnXvNRN3VzL/MTCv0s1wNrI05+I6t3JhrEU0N2xeIpo1h1Xa/Uk/ Wp1g== X-Gm-Message-State: AC+VfDyqyt3EQmJOC6AzAmzaB8VepzhLm3u884/e2hPKJfqa2eu5Id8v U1TeaSSC6AEGRgsQLtHA1j8dm2FwW/R+ X-Google-Smtp-Source: ACHHUZ6Iu1fmtHJGUmPzxev78Fx3TvKNcbnqx6CoeWzqHZJpPNCQBBZPeyu1JlueZVJRFDGqvNyf/oaRflmQ X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a25:2646:0:b0:bad:41b:f343 with SMTP id m67-20020a252646000000b00bad041bf343mr1730959ybm.1.1685138123360; Fri, 26 May 2023 14:55:23 -0700 (PDT) Date: Fri, 26 May 2023 14:54:06 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-32-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 31/35] perf pmus: Avoid repeated sysfs scanning From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230526_225526_359327_81366107 X-CRM114-Status: GOOD ( 18.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org perf_pmus__scan will process every directory in sysfs to see if it is a PMU, attempting to add it if not already in the pmus list. Add two booleans to record whether this scanning has been done for core or all PMUs. Skip scanning in the event that scanning has already occurred. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/util/pmus.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index de7fc36519c9..2c512345191d 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -14,6 +14,8 @@ static LIST_HEAD(core_pmus); static LIST_HEAD(other_pmus); +static bool read_sysfs_core_pmus; +static bool read_sysfs_all_pmus; void perf_pmus__destroy(void) { @@ -29,6 +31,8 @@ void perf_pmus__destroy(void) perf_pmu__delete(pmu); } + read_sysfs_core_pmus = false; + read_sysfs_all_pmus = false; } static struct perf_pmu *pmu_find(const char *name) @@ -53,6 +57,7 @@ struct perf_pmu *perf_pmus__find(const char *name) { struct perf_pmu *pmu; int dirfd; + bool core_pmu; /* * Once PMU is loaded it stays in the list, @@ -63,8 +68,15 @@ struct perf_pmu *perf_pmus__find(const char *name) if (pmu) return pmu; + if (read_sysfs_all_pmus) + return NULL; + + core_pmu = is_pmu_core(name); + if (core_pmu && read_sysfs_core_pmus) + return NULL; + dirfd = perf_pmu__event_source_devices_fd(); - pmu = perf_pmu__lookup(is_pmu_core(name) ? &core_pmus : &other_pmus, dirfd, name); + pmu = perf_pmu__lookup(core_pmu ? &core_pmus : &other_pmus, dirfd, name); close(dirfd); return pmu; @@ -73,6 +85,7 @@ struct perf_pmu *perf_pmus__find(const char *name) static struct perf_pmu *perf_pmu__find2(int dirfd, const char *name) { struct perf_pmu *pmu; + bool core_pmu; /* * Once PMU is loaded it stays in the list, @@ -83,7 +96,14 @@ static struct perf_pmu *perf_pmu__find2(int dirfd, const char *name) if (pmu) return pmu; - return perf_pmu__lookup(is_pmu_core(name) ? &core_pmus : &other_pmus, dirfd, name); + if (read_sysfs_all_pmus) + return NULL; + + core_pmu = is_pmu_core(name); + if (core_pmu && read_sysfs_core_pmus) + return NULL; + + return perf_pmu__lookup(core_pmu ? &core_pmus : &other_pmus, dirfd, name); } /* Add all pmus in sysfs to pmu list: */ @@ -93,6 +113,9 @@ static void pmu_read_sysfs(bool core_only) DIR *dir; struct dirent *dent; + if (read_sysfs_all_pmus || (core_only && read_sysfs_core_pmus)) + return; + fd = perf_pmu__event_source_devices_fd(); if (fd < 0) return; @@ -111,6 +134,12 @@ static void pmu_read_sysfs(bool core_only) } closedir(dir); + if (core_only) { + read_sysfs_core_pmus = true; + } else { + read_sysfs_core_pmus = true; + read_sysfs_all_pmus = true; + } } struct perf_pmu *perf_pmus__find_by_type(unsigned int type)