perf pmus: Allow just core PMU scanning
Scanning all PMUs is expensive as all PMUs sysfs entries are loaded, benchmarking shows more than 4x the cost: ``` $ perf bench internals pmu-scan -i 1000 Computing performance of sysfs PMU event scan for 1000 times Average core PMU scanning took: 989.231 usec (+- 1.535 usec) Average PMU scanning took: 4309.425 usec (+- 74.322 usec) ``` Add new perf_pmus__scan_core routine that scans just core PMUs. Replace perf_pmus__scan calls with perf_pmus__scan_core when non-core PMUs are being ignored. 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-30-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
committed by
Arnaldo Carvalho de Melo
parent
15c57a8037
commit
9d6a1df9b2
@ -87,7 +87,7 @@ static struct perf_pmu *perf_pmu__find2(int dirfd, const char *name)
|
||||
}
|
||||
|
||||
/* Add all pmus in sysfs to pmu list: */
|
||||
static void pmu_read_sysfs(void)
|
||||
static void pmu_read_sysfs(bool core_only)
|
||||
{
|
||||
int fd;
|
||||
DIR *dir;
|
||||
@ -104,6 +104,8 @@ static void pmu_read_sysfs(void)
|
||||
while ((dent = readdir(dir))) {
|
||||
if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
|
||||
continue;
|
||||
if (core_only && !is_pmu_core(dent->d_name))
|
||||
continue;
|
||||
/* add to static LIST_HEAD(core_pmus) or LIST_HEAD(other_pmus): */
|
||||
perf_pmu__find2(fd, dent->d_name);
|
||||
}
|
||||
@ -135,7 +137,7 @@ struct perf_pmu *perf_pmus__scan(struct perf_pmu *pmu)
|
||||
bool use_core_pmus = !pmu || pmu->is_core;
|
||||
|
||||
if (!pmu) {
|
||||
pmu_read_sysfs();
|
||||
pmu_read_sysfs(/*core_only=*/false);
|
||||
pmu = list_prepare_entry(pmu, &core_pmus, list);
|
||||
}
|
||||
if (use_core_pmus) {
|
||||
@ -150,6 +152,18 @@ struct perf_pmu *perf_pmus__scan(struct perf_pmu *pmu)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct perf_pmu *perf_pmus__scan_core(struct perf_pmu *pmu)
|
||||
{
|
||||
if (!pmu) {
|
||||
pmu_read_sysfs(/*core_only=*/true);
|
||||
pmu = list_prepare_entry(pmu, &core_pmus, list);
|
||||
}
|
||||
list_for_each_entry_continue(pmu, &core_pmus, list)
|
||||
return pmu;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str)
|
||||
{
|
||||
struct perf_pmu *pmu = NULL;
|
||||
@ -176,10 +190,10 @@ int perf_pmus__num_mem_pmus(void)
|
||||
struct perf_pmu *pmu = NULL;
|
||||
int count = 0;
|
||||
|
||||
while ((pmu = perf_pmus__scan(pmu)) != NULL) {
|
||||
if (perf_pmu__is_mem_pmu(pmu))
|
||||
count++;
|
||||
}
|
||||
/* All core PMUs are for mem events. */
|
||||
while ((pmu = perf_pmus__scan_core(pmu)) != NULL)
|
||||
count++;
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
@ -421,8 +435,8 @@ bool perf_pmus__has_hybrid(void)
|
||||
if (!hybrid_scanned) {
|
||||
struct perf_pmu *pmu = NULL;
|
||||
|
||||
while ((pmu = perf_pmus__scan(pmu)) != NULL) {
|
||||
if (pmu->is_core && is_pmu_hybrid(pmu->name)) {
|
||||
while ((pmu = perf_pmus__scan_core(pmu)) != NULL) {
|
||||
if (is_pmu_hybrid(pmu->name)) {
|
||||
has_hybrid = true;
|
||||
break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user