Commit 8e7d8a2e authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo

perf pmus: Avoid repeated sysfs scanning

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.
Reviewed-by: default avatarKan Liang <kan.liang@linux.intel.com>
Signed-off-by: default avatarIan 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-31-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 9d6a1df9
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
static LIST_HEAD(core_pmus); static LIST_HEAD(core_pmus);
static LIST_HEAD(other_pmus); static LIST_HEAD(other_pmus);
static bool read_sysfs_core_pmus;
static bool read_sysfs_all_pmus;
void perf_pmus__destroy(void) void perf_pmus__destroy(void)
{ {
...@@ -29,6 +31,8 @@ void perf_pmus__destroy(void) ...@@ -29,6 +31,8 @@ void perf_pmus__destroy(void)
perf_pmu__delete(pmu); perf_pmu__delete(pmu);
} }
read_sysfs_core_pmus = false;
read_sysfs_all_pmus = false;
} }
static struct perf_pmu *pmu_find(const char *name) static struct perf_pmu *pmu_find(const char *name)
...@@ -53,6 +57,7 @@ struct perf_pmu *perf_pmus__find(const char *name) ...@@ -53,6 +57,7 @@ struct perf_pmu *perf_pmus__find(const char *name)
{ {
struct perf_pmu *pmu; struct perf_pmu *pmu;
int dirfd; int dirfd;
bool core_pmu;
/* /*
* Once PMU is loaded it stays in the list, * Once PMU is loaded it stays in the list,
...@@ -63,8 +68,15 @@ struct perf_pmu *perf_pmus__find(const char *name) ...@@ -63,8 +68,15 @@ struct perf_pmu *perf_pmus__find(const char *name)
if (pmu) if (pmu)
return 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(); 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); close(dirfd);
return pmu; return pmu;
...@@ -73,6 +85,7 @@ struct perf_pmu *perf_pmus__find(const char *name) ...@@ -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) static struct perf_pmu *perf_pmu__find2(int dirfd, const char *name)
{ {
struct perf_pmu *pmu; struct perf_pmu *pmu;
bool core_pmu;
/* /*
* Once PMU is loaded it stays in the list, * 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) ...@@ -83,7 +96,14 @@ static struct perf_pmu *perf_pmu__find2(int dirfd, const char *name)
if (pmu) if (pmu)
return 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: */ /* Add all pmus in sysfs to pmu list: */
...@@ -93,6 +113,9 @@ static void pmu_read_sysfs(bool core_only) ...@@ -93,6 +113,9 @@ static void pmu_read_sysfs(bool core_only)
DIR *dir; DIR *dir;
struct dirent *dent; struct dirent *dent;
if (read_sysfs_all_pmus || (core_only && read_sysfs_core_pmus))
return;
fd = perf_pmu__event_source_devices_fd(); fd = perf_pmu__event_source_devices_fd();
if (fd < 0) if (fd < 0)
return; return;
...@@ -111,6 +134,12 @@ static void pmu_read_sysfs(bool core_only) ...@@ -111,6 +134,12 @@ static void pmu_read_sysfs(bool core_only)
} }
closedir(dir); 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) struct perf_pmu *perf_pmus__find_by_type(unsigned int type)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment