Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2557614rwd; Mon, 22 May 2023 00:11:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7n6D8bGkdXUfGtYWHL4GXJxnRmvg5q8FCo2/7qEmO2/sPAXoFdMtNhamqiS4U3Vw5TkMvn X-Received: by 2002:a17:90b:1d85:b0:253:4361:dd with SMTP id pf5-20020a17090b1d8500b00253436100ddmr9732330pjb.32.1684739513160; Mon, 22 May 2023 00:11:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684739513; cv=none; d=google.com; s=arc-20160816; b=Vg38dg6ZS2+uBaMPi5qHt6qUDeqq4QNa4P+MBiR29mPJ8uGyl6JHUYtb0mGRLORUjF Tv80FnZhf0SLcEBf3cBxt1GzUOK12S8JIA7iz711C/dJTBDipdYhgpwhMSkaLlFNPCd9 QFZLCHJtxsog9zyEAF+ssGyNtS2TggQh/4H6JIgtra2QYoQs33bO6nknyQ20+jea7zR5 7Y7MV9659SinjB6jeIprlhOOJXOWoOEHis99ktbvmmvQ0BTRM3tjTWZcNR+od81vI8ms 1UUxH3tEhzSLyqzfE8Ac/psSLcIwqw5otuGS6ajbvNvZ/H4msbn0czLsqO30QoWJhq5D hKzA== 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=/+aFtpu9F2yGljXWeZ17LuoYXO4ZNmuRrdV4BNXebZU=; b=ENLDekGElNSV32XBbVPsCoUsE7FDywGdZYP98ifs6X9VMwNKOI1qX3HxG0vjuQe0FR JYvLNHqbOBnWcyxsWr1U80HQHcAFh4ZqRbaM4ZqwCRR6HSf3LNbSQqcpHZvFuHAZZ5Jl Jl1CQBSCbMpXlJZAh6ly+zu1nnslspwxF8K2M0J8R/797+Jhu1T0M1CZdYJ2GP1iUMbI HvvLgGiIXkQ23dZElX82sirDO1/ROa1YIpHWBPtsYcHJZc7l3l+KC8KfNYR93rYbhZSz 7ChlBGd5cgniC6oHetf+SU+UdUIktRDWjFkKfFuHaSci5I+jAHDYFIucjYLA5SzFqWeE wlgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=WaMOe5OU; 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 gx11-20020a17090b124b00b00247498bcea7si4238425pjb.107.2023.05.22.00.11.38; Mon, 22 May 2023 00:11:53 -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=WaMOe5OU; 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 S231958AbjEVGrN (ORCPT + 99 others); Mon, 22 May 2023 02:47:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232131AbjEVGqA (ORCPT ); Mon, 22 May 2023 02:46:00 -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 356D71730 for ; Sun, 21 May 2023 23:44:53 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba83fed51adso10456746276.0 for ; Sun, 21 May 2023 23:44:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684737868; x=1687329868; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=/+aFtpu9F2yGljXWeZ17LuoYXO4ZNmuRrdV4BNXebZU=; b=WaMOe5OUll0Sz3acYm4uBfP9Z16Iny/8w4BooK0DItssmCmNzxlUurQkN2coR0gNZn VA9XDIt83nTT1n/huWCKal3K6IbRP/7461ldA4ftEms4RfXQKm6GC4TaZwpQGFfcTKqB oIYrXtvyVFtZKxpNNgMT7H8kXvww57QD6IXbvkv3pwYxvv3Xz5UXm4RtaYEssAp4liK9 C4nuzxzYmak9iZYoexyN6LBpeLG85ppM9G08VP2VyuaeDKLi2TYGZxF9s9/ynZ4RtTJn U7hw7jr42r3RXEZu0ZFOeXm+Q48UG/nUdfFzp8U7CchRVHGNj9b29tj0LfL0gIUiaLWu xB8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684737868; x=1687329868; 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=/+aFtpu9F2yGljXWeZ17LuoYXO4ZNmuRrdV4BNXebZU=; b=EMCVvgnEt+fPf4PN8CcE0WC+CNZhmT5tPBs6sonyHmk/q1SIJ5ETDogEb34sri1jHl g/GQlmep3hV5y1IjVIzqdj0BPoDuNipzqql0eWkI3k1wcRIGQFGh9fEcS5xkE+zMQqcA NxrxmR2mxgL7SV9++RCHw/hZzNi57yFuScCYoccS9pQGhkdIMlwGaWYQu1VUj0vGHDGH Q4lD91ae8AelSlbvozt3+9S2yfPR92zfe6ksFRQjpteCtfuR32C1/C3rGz2dC3Ny/JD7 Fzl4RgxmUe+VD6tBAL+hwA+Rk6R8EliJOwypBes4141W9fGiZp6XS/2O5W0pZYH2EIYn qrbg== X-Gm-Message-State: AC+VfDwBzxC7FfwuIxcCvD3Xr98QsfxQXmrGlUPhw+IWbQz6kyBdGwB6 T/PQspe8BOXW24FWuXokyTn5TMghcuMe X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:48d9:8c21:e099:7301]) (user=irogers job=sendgmr) by 2002:a25:bb41:0:b0:b9a:6508:1b5f with SMTP id b1-20020a25bb41000000b00b9a65081b5fmr3592765ybk.11.1684737868018; Sun, 21 May 2023 23:44:28 -0700 (PDT) Date: Sun, 21 May 2023 23:43:29 -0700 In-Reply-To: <20230522064330.189127-1-irogers@google.com> Message-Id: <20230522064330.189127-23-irogers@google.com> Mime-Version: 1.0 References: <20230522064330.189127-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v2 22/23] 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 5736e99facd1..22e9e46ab765 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