Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp149225rwd; Wed, 24 May 2023 15:46:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4py9dlKt7kOMB4aep6TwpsDF6HK2FFfqWZ5HoCB8qa4Ev9gh95IDMbn3ETskErqP+bODKb X-Received: by 2002:a05:6a00:124f:b0:64a:fa71:a98f with SMTP id u15-20020a056a00124f00b0064afa71a98fmr5416148pfi.13.1684968388112; Wed, 24 May 2023 15:46:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684968388; cv=none; d=google.com; s=arc-20160816; b=SvfRg98M3FEqetwh5yrSOidj8XW3DgzdmNt6Orse1oPn+bB17IYgwWxTQGzjfymusB TRNnhVDCXH4z2yUeq5DdE8BY/W3sjpJSBPjEZ3xvk+/NJjkWfoL3btlkXDPP8bkxU0cR jxtqwXuIj9/EC2Rt2VqvJDZqvWTxbz8t+x7bSaU+b8/ooAE3RM+7+9F4Jb1eSkWNiy/y E5HBpcl8EX+WYHKoCVyvpP1wA7PymojhggHwdIq9iyi2mbYsFSPtO7lPNuRRiwslNXBM ziyKUA6Fti01lN3g00Y3ZJlWnJVrLMmKEbu5Zmt4th9RK2syw8klYcFlsxFX4lNcDB86 L0aQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=Oxcc/fbHqqjPzgaZ7RoCmF9ePDnlZuETNbTW2zw+MN8=; b=J1uplg3AfwaJV+ZPhtOckWBIcXvS8LO7Tf8ONI+A97HEaskh3NOHFbrBf+qEFfdxM2 WKOLWyL819W0aZYUOx1Kf+3sMDHS0OsJt/hov/+scIH8yOICx2wF/RfWqqmVnIvvB84P 9xxTFD1UAe4IxsDO1UoHkilLQwLFZtQABNuQBt9wBVd3PKTM6upzYBxD+UlXzxjBt4Rg rwKKj+63ZGfXNejIJFyJy8nvouxkSoePe/EBwyZPkaVsCzKdSQCO4I2fLUuIWMSYFPsE pLc0X6eIhG1akrkckvF+4oG2xSr6btt+cgvazXAlbvzESTYWNyhGR81YcZtKHmt5hN1a qBAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=4r0YNvfU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v127-20020a626185000000b0064d419dd566si9248537pfb.205.2023.05.24.15.46.14; Wed, 24 May 2023 15:46:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=4r0YNvfU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237784AbjEXWWP (ORCPT + 99 others); Wed, 24 May 2023 18:22:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237776AbjEXWVk (ORCPT ); Wed, 24 May 2023 18:21:40 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D33D210FB for ; Wed, 24 May 2023 15:20:55 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-564f6099813so29602187b3.2 for ; Wed, 24 May 2023 15:20:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966787; x=1687558787; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Oxcc/fbHqqjPzgaZ7RoCmF9ePDnlZuETNbTW2zw+MN8=; b=4r0YNvfUcwIDoJ2EzMpnJcIyMz4UPDfw4aLOoOLXEvSFAABfi/cJgQVwjJTD5eTYZr 1feUPiAb6nqK3LtcPFGwHKEz0eSrVWniMGNsr027dyp1mV/8NUmZdyMHe11WziC822SE mDKwrtajc1w+upC/UnBE92BB+egOUCfeqLUSLc8sg7KcnTIp+WJLMARWI2AxWqj6LieQ +WxqqvJXfPNkdV1mrh1OyY3z8AT12zn97m5dloj6c0uefZ54+BaNWrAXP4KCd6M7SUGA 6mRPDf3Lr4MVRAX51s8H8yIoVdm36qnVZ6H6Hb82EbxDLFBlNVgtaqIFodgQz0iIkZYJ z6tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966787; x=1687558787; 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=Oxcc/fbHqqjPzgaZ7RoCmF9ePDnlZuETNbTW2zw+MN8=; b=Xomh7opxjlRLGA1LcUzkJ2xeTefyzXBuEmfWuFfn5fSb8hAaVJl3GodmTsYQri6Rfn no/AmZ2gLd7gcZKabFw3Pps+ULB7G6v6m2tolyY85dtsSrxubH5PmKp7zt12+09/Sl1u k+6G2gRBiYTZFM2CJl24zL9bxn4CrbilI6RGyMmJIAxFptLqrgQWokMQo7uA8dP2xeZa CaLGgi+pR6afz8U2iSIXqv1GH1vtAvhMzUuEYK2V2sT0k6XaPWxuiJ7zMXYl/6IYx0tp smXcVPOimxJLT88kZIURpx7+WpaR/VSGDdkb68nGqyxNJW3r2hRyYaBLnG38GM7vaCH+ u14w== X-Gm-Message-State: AC+VfDxKSyfYAHqYrVhPArHTro6xkDVlAi9EAA2PbxRymk9fXuikSMwO 3XdfvKwF7Z4InL7VfkKUt8pVElg+u1Li X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a81:ae68:0:b0:561:94a8:29c5 with SMTP id g40-20020a81ae68000000b0056194a829c5mr11391391ywk.4.1684966787215; Wed, 24 May 2023 15:19:47 -0700 (PDT) Date: Wed, 24 May 2023 15:18:27 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-32-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 --- 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) -- 2.40.1.698.g37aff9b760-goog