Skip to content

Commit 002c484

Browse files
captain5050acmel
authored andcommitted
perf pmus: Add function to return count of core PMUs
Add perf_pmus__num_core_pmus that will count core PMUs holding the result in a static. Reuse for perf_pmus__num_mem_pmus. Reviewed-by: Kan Liang <kan.liang@linux.intel.com> Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Ali Saidi <alisaidi@amazon.com> Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com> Cc: Dmitrii Dolgov <9erthalion6@gmail.com> Cc: Huacai Chen <chenhuacai@kernel.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@arm.com> Cc: Jing Zhang <renyu.zj@linux.alibaba.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: John Garry <john.g.garry@oracle.com> Cc: Kajol Jain <kjain@linux.ibm.com> Cc: Kang Minchul <tegongkang@gmail.com> Cc: Leo Yan <leo.yan@linaro.org> Cc: Madhavan Srinivasan <maddy@linux.ibm.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mike Leach <mike.leach@linaro.org> Cc: Ming Wang <wangming01@loongson.cn> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ravi Bangoria <ravi.bangoria@amd.com> Cc: Rob Herring <robh@kernel.org> Cc: Sandipan Das <sandipan.das@amd.com> Cc: Sean Christopherson <seanjc@google.com> Cc: Suzuki Poulouse <suzuki.poulose@arm.com> Cc: Thomas Richter <tmricht@linux.ibm.com> Cc: Will Deacon <will@kernel.org> Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com> Cc: coresight@lists.linaro.org Cc: linux-arm-kernel@lists.infradead.org Link: https://lore.kernel.org/r/20230527072210.2900565-33-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 1dd5f78 commit 002c484

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

tools/perf/util/pmus.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,8 @@ const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str)
229229

230230
int perf_pmus__num_mem_pmus(void)
231231
{
232-
struct perf_pmu *pmu = NULL;
233-
int count = 0;
234-
235232
/* All core PMUs are for mem events. */
236-
while ((pmu = perf_pmus__scan_core(pmu)) != NULL)
237-
count++;
238-
239-
return count;
233+
return perf_pmus__num_core_pmus();
240234
}
241235

242236
/** Struct for ordering events as output in perf list. */
@@ -488,6 +482,19 @@ bool perf_pmus__has_hybrid(void)
488482
return has_hybrid;
489483
}
490484

485+
int perf_pmus__num_core_pmus(void)
486+
{
487+
static int count;
488+
489+
if (!count) {
490+
struct perf_pmu *pmu = NULL;
491+
492+
while ((pmu = perf_pmus__scan_core(pmu)) != NULL)
493+
count++;
494+
}
495+
return count;
496+
}
497+
491498
struct perf_pmu *evsel__find_pmu(const struct evsel *evsel)
492499
{
493500
struct perf_pmu *pmu = evsel->pmu;

tools/perf/util/pmus.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ int perf_pmus__num_mem_pmus(void);
1919
void perf_pmus__print_pmu_events(const struct print_callbacks *print_cb, void *print_state);
2020
bool perf_pmus__have_event(const char *pname, const char *name);
2121
bool perf_pmus__has_hybrid(void);
22+
int perf_pmus__num_core_pmus(void);
2223

2324
#endif /* __PMUS_H */

0 commit comments

Comments
 (0)