Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
002c4845 1dd5f78d

+15 -7
+14 -7
tools/perf/util/pmus.c
··· 229 229 230 230 int perf_pmus__num_mem_pmus(void) 231 231 { 232 - struct perf_pmu *pmu = NULL; 233 - int count = 0; 234 - 235 232 /* 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(); 240 234 } 241 235 242 236 /** Struct for ordering events as output in perf list. */ ··· 480 486 hybrid_scanned = true; 481 487 } 482 488 return has_hybrid; 489 + } 490 + 491 + int perf_pmus__num_core_pmus(void) 492 + { 493 + static int count; 494 + 495 + if (!count) { 496 + struct perf_pmu *pmu = NULL; 497 + 498 + while ((pmu = perf_pmus__scan_core(pmu)) != NULL) 499 + count++; 500 + } 501 + return count; 483 502 } 484 503 485 504 struct perf_pmu *evsel__find_pmu(const struct evsel *evsel)
+1
tools/perf/util/pmus.h
··· 19 19 void perf_pmus__print_pmu_events(const struct print_callbacks *print_cb, void *print_state); 20 20 bool perf_pmus__have_event(const char *pname, const char *name); 21 21 bool perf_pmus__has_hybrid(void); 22 + int perf_pmus__num_core_pmus(void); 22 23 23 24 #endif /* __PMUS_H */