From nobody Sun Feb 8 17:36:45 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5CB9FC77B73 for ; Fri, 26 May 2023 21:57:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244417AbjEZV5a (ORCPT ); Fri, 26 May 2023 17:57:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244276AbjEZV4y (ORCPT ); Fri, 26 May 2023 17:56:54 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96829170F for ; Fri, 26 May 2023 14:56:12 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-babb5e91ab4so2702560276.0 for ; Fri, 26 May 2023 14:56:12 -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=BsEROEH2vuxyGuIRa80dQGSK0uDyEwAFCaOtnFxNceTJbyl1iFteiORWtD98Th+lqP outBlr8s83htcoB26HBzns+fPkjIaprMu9bEvDF8nG99IWL4UvVUts6PzlkvlxtquPTR zSdZqqwRWMF6qcJ5gIBDDsz0LYDBsFZWimhErhj3S622MQKCrMMDcBpRyvDW6MWYMuNW ab7dF6fu6Uk+GZmcYfUiExXruPTsqacScn64rldyXcJyAnr2R0w4RPowrsAi712uYmf/ INyaYaUioDSvZ62aTQ6I3C0pZrAwdRqEdIv9Wf7or/RcC+HGE666n8PtWLBiRiLkN/Qr LlMQ== X-Gm-Message-State: AC+VfDxW9Y7HBF3Emgo7fArY9oZLofloZnqV2avDL7fxTb14JL3DxcU1 op2PdQM3lkGBfUH4/QQwfMtyl+jYk0Le 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 @@ =20 static LIST_HEAD(core_pmus); static LIST_HEAD(other_pmus); +static bool read_sysfs_core_pmus; +static bool read_sysfs_all_pmus; =20 void perf_pmus__destroy(void) { @@ -29,6 +31,8 @@ void perf_pmus__destroy(void) =20 perf_pmu__delete(pmu); } + read_sysfs_core_pmus =3D false; + read_sysfs_all_pmus =3D false; } =20 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; =20 /* * 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; =20 + if (read_sysfs_all_pmus) + return NULL; + + core_pmu =3D is_pmu_core(name); + if (core_pmu && read_sysfs_core_pmus) + return NULL; + dirfd =3D perf_pmu__event_source_devices_fd(); - pmu =3D perf_pmu__lookup(is_pmu_core(name) ? &core_pmus : &other_pmus, di= rfd, name); + pmu =3D perf_pmu__lookup(core_pmu ? &core_pmus : &other_pmus, dirfd, name= ); close(dirfd); =20 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; =20 /* * 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; =20 - return perf_pmu__lookup(is_pmu_core(name) ? &core_pmus : &other_pmus, dir= fd, name); + if (read_sysfs_all_pmus) + return NULL; + + core_pmu =3D 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); } =20 /* 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; =20 + if (read_sysfs_all_pmus || (core_only && read_sysfs_core_pmus)) + return; + fd =3D perf_pmu__event_source_devices_fd(); if (fd < 0) return; @@ -111,6 +134,12 @@ static void pmu_read_sysfs(bool core_only) } =20 closedir(dir); + if (core_only) { + read_sysfs_core_pmus =3D true; + } else { + read_sysfs_core_pmus =3D true; + read_sysfs_all_pmus =3D true; + } } =20 struct perf_pmu *perf_pmus__find_by_type(unsigned int type) --=20 2.41.0.rc0.172.g3f132b7071-goog