From patchwork Fri May 26 21:54:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13257409 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 1C018C7EE31 for ; Fri, 26 May 2023 22:41:29 +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=IW4KrEMJfgUMiWOhO1aNh0RoxjNpfypuFPjlXcVohwI=; b=yGICraxWl/Tpdz fEoT2cjMfRtXqOYt+v35SU+1RwccPdrZ31D+2+qP38uLw0esTiiMhKu1GimlBX0jwfIEp+i/LL8EE /M0IRPb0E6iD1rc8Io9XmnT2Fh0dT9KMnhqbYCG2dFHcjrgQJrcehqWoWsISP8n21pP5ihFxDNsXC cyP9i1cTJmst34ilrqZqlgbKtqLVjSGdvaJVYVSK2D0sIg93MLzZ9khX5Xsr4mVSub+KwvqEpL50D /kGSSlcTBNaoOF1rteRv+ECM2SIM0sCsyeoqgJ5gXJcLiCmZKNO95O4Cp3JyByz7NIUpdgUhlUIli 6aMc/AaShy94IdK+eqTQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q2g7D-004A8W-2h; Fri, 26 May 2023 22:40:55 +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 1q2g6s-0049wC-0W for linux-arm-kernel@bombadil.infradead.org; Fri, 26 May 2023 22:40:34 +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=vW2lbdpPJdg/r6QP2GPnX5xgemELHxkJ0mClCQxJlXE=; b=UVyuP+fk1kgUS6UIsnmZQlcPrS HEpx5IczVU5qW5gHQ3NmppLpMrmFBHhk1nH3u1cNGwZkP85LdqpsUuPe5vRwaBetp1mIUqtvINsb6 haQRUJvBdVC1MknmQoJzigBwuckBCWi6VNAtga52wD61TAn05FRVm2aKOAFsmTySrziCOL2ufsbr3 SqAEYYjNxQ91buOPqwdJoAhJ7pnwj4USxz7obu1SBjegatcjSegYkTw1YN+OEXfBkZahaUT2znFtU djVwzYWVjd0QATkMK8s2IXegGmJLTl4NlXdRSw11qxOfvUlfE+310BQbBkoiVpPRaLe3gRNYOe6IC hhAoxibw==; Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q2fPF-007ixw-13 for linux-arm-kernel@lists.infradead.org; Fri, 26 May 2023 21:55:31 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-559c416b024so16777947b3.1 for ; Fri, 26 May 2023 14:55:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138127; x=1687730127; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=vW2lbdpPJdg/r6QP2GPnX5xgemELHxkJ0mClCQxJlXE=; b=XgJYAm41O7NNFLVHPpeeRZju9bD5zUvsAC0wt/UXOVLw3GOfF0JaoBMe6TBnPqkDUE jYdH81MvGVvclARKFyJ+Jgl7dihH7i1nYuM33T1qAdu9hQxuma0ZNocFspbqG5fg53kf 4CrE581+2bLeQ/wzdCJdRvTbLVN5+U11VRZTFLjVH5/IOwxEBng7w3jNTu1ciOoSniUD DFKPeorSfxpLWSMYHLy6dm+O2HDNl5TYai1K5TOZvxeVRCUhuNBy43xF9GawgVp2vtYq dC5SFDsDu1an8pxHIAPY58ESVMsOOWY6NjEK8t3G7kD/zcEjKDJ/j8pZhZcvZTis1nwh rpdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138127; x=1687730127; 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=vW2lbdpPJdg/r6QP2GPnX5xgemELHxkJ0mClCQxJlXE=; b=DsFGIzkAszeFqUE6sqXKkaNkxHCCtA1DagrE8FMXZZHEkS2hcTlFQ47Feh9qxKGreq QPYC9kH+66fDV+Kl4KUaoJJbDJQuDw+UyhzKZach8dBkjp6KCu5Xq1IfK2GXISTxqTha EXuKTMWJh7wzCcyr1KF82ZxqfF7VcuQAxK+rzO5v9dvoVOxs5yziRfMJqP7A3unofXkJ /d7FYpjS+ur0aRK/HA3B3Ug767c9bGx/IChE6VgwKyrDHLOJ1oHjDvBmSIVVUBONTCZU D6TbBunjmMI8L5GhBmKUGcliMXwwV7touG1XBZ+cO70ePL1n/JQV3lkSC6AaMhslgvlY UIxA== X-Gm-Message-State: AC+VfDwKHABbPAAxSudZ16EAd70Zacq0hIBDsWEqEJof+z206N6Fuavh WF+qWPP8KYMPiZjVxhQVLyGUBLnaaT2m X-Google-Smtp-Source: ACHHUZ4NRRDlyH/flCqp3jYK/1HAot9LkkCV9xPcWa5EvIdoqnj1c7Po8JDOungTNQVgPDVDILQcujc4hqvO X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a81:b710:0:b0:565:cfdf:7a70 with SMTP id v16-20020a81b710000000b00565cfdf7a70mr64876ywh.2.1685138127743; Fri, 26 May 2023 14:55:27 -0700 (PDT) Date: Fri, 26 May 2023 14:54:08 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-34-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 33/35] perf pmus: Add function to return count of core PMUs 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_225529_458864_0B617079 X-CRM114-Status: GOOD ( 15.24 ) 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 Add perf_pmus__num_core_pmus that will count core PMUs holding the result in a static. Reuse for perf_pmus__num_mem_pmus. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/util/pmus.c | 21 ++++++++++++++------- tools/perf/util/pmus.h | 1 + 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 6ecccb5ad03e..bf927aed162e 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -229,14 +229,8 @@ const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str) int perf_pmus__num_mem_pmus(void) { - struct perf_pmu *pmu = NULL; - int count = 0; - /* All core PMUs are for mem events. */ - while ((pmu = perf_pmus__scan_core(pmu)) != NULL) - count++; - - return count; + return perf_pmus__num_core_pmus(); } /** Struct for ordering events as output in perf list. */ @@ -488,6 +482,19 @@ bool perf_pmus__has_hybrid(void) return has_hybrid; } +int perf_pmus__num_core_pmus(void) +{ + static int count; + + if (!count) { + struct perf_pmu *pmu = NULL; + + while ((pmu = perf_pmus__scan_core(pmu)) != NULL) + count++; + } + return count; +} + struct perf_pmu *evsel__find_pmu(const struct evsel *evsel) { struct perf_pmu *pmu = evsel->pmu; diff --git a/tools/perf/util/pmus.h b/tools/perf/util/pmus.h index 9de0222ed52b..27400a027d41 100644 --- a/tools/perf/util/pmus.h +++ b/tools/perf/util/pmus.h @@ -19,5 +19,6 @@ int perf_pmus__num_mem_pmus(void); void perf_pmus__print_pmu_events(const struct print_callbacks *print_cb, void *print_state); bool perf_pmus__have_event(const char *pname, const char *name); bool perf_pmus__has_hybrid(void); +int perf_pmus__num_core_pmus(void); #endif /* __PMUS_H */