Commit 3339ec44 authored by Ravi Bangoria's avatar Ravi Bangoria Committed by Arnaldo Carvalho de Melo

perf pmu: Parse pmu caps sysfs only once

In addition to returning nr_caps, cache it locally in struct perf_pmu.

Similarly, cache status of whether caps sysfs has already been parsed
or not. These will help to avoid parsing sysfs every time the function
gets called.
Reviewed-by: default avatarKan Liang <kan.liang@linux.intel.com>
Signed-off-by: default avatarRavi Bangoria <ravi.bangoria@amd.com>
Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
Cc: Ananth Narayan <ananth.narayan@amd.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kim Phillips <kim.phillips@amd.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Robert Richter <rrichter@amd.com>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Santosh Shukla <santosh.shukla@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: like.xu.linux@gmail.com
Cc: x86@kernel.org
Link: https://lore.kernel.org/r/20220604044519.594-3-ravi.bangoria@amd.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 9ab95b0b
...@@ -1890,7 +1890,11 @@ int perf_pmu__caps_parse(struct perf_pmu *pmu) ...@@ -1890,7 +1890,11 @@ int perf_pmu__caps_parse(struct perf_pmu *pmu)
const char *sysfs = sysfs__mountpoint(); const char *sysfs = sysfs__mountpoint();
DIR *caps_dir; DIR *caps_dir;
struct dirent *evt_ent; struct dirent *evt_ent;
int nr_caps = 0;
if (pmu->caps_initialized)
return pmu->nr_caps;
pmu->nr_caps = 0;
if (!sysfs) if (!sysfs)
return -1; return -1;
...@@ -1898,8 +1902,10 @@ int perf_pmu__caps_parse(struct perf_pmu *pmu) ...@@ -1898,8 +1902,10 @@ int perf_pmu__caps_parse(struct perf_pmu *pmu)
snprintf(caps_path, PATH_MAX, snprintf(caps_path, PATH_MAX,
"%s" EVENT_SOURCE_DEVICE_PATH "%s/caps", sysfs, pmu->name); "%s" EVENT_SOURCE_DEVICE_PATH "%s/caps", sysfs, pmu->name);
if (stat(caps_path, &st) < 0) if (stat(caps_path, &st) < 0) {
pmu->caps_initialized = true;
return 0; /* no error if caps does not exist */ return 0; /* no error if caps does not exist */
}
caps_dir = opendir(caps_path); caps_dir = opendir(caps_path);
if (!caps_dir) if (!caps_dir)
...@@ -1926,13 +1932,14 @@ int perf_pmu__caps_parse(struct perf_pmu *pmu) ...@@ -1926,13 +1932,14 @@ int perf_pmu__caps_parse(struct perf_pmu *pmu)
continue; continue;
} }
nr_caps++; pmu->nr_caps++;
fclose(file); fclose(file);
} }
closedir(caps_dir); closedir(caps_dir);
return nr_caps; pmu->caps_initialized = true;
return pmu->nr_caps;
} }
void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config, void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config,
......
...@@ -46,6 +46,8 @@ struct perf_pmu { ...@@ -46,6 +46,8 @@ struct perf_pmu {
struct perf_cpu_map *cpus; struct perf_cpu_map *cpus;
struct list_head format; /* HEAD struct perf_pmu_format -> list */ struct list_head format; /* HEAD struct perf_pmu_format -> list */
struct list_head aliases; /* HEAD struct perf_pmu_alias -> list */ struct list_head aliases; /* HEAD struct perf_pmu_alias -> list */
bool caps_initialized;
u32 nr_caps;
struct list_head caps; /* HEAD struct perf_pmu_caps -> list */ struct list_head caps; /* HEAD struct perf_pmu_caps -> list */
struct list_head list; /* ELEM */ struct list_head list; /* ELEM */
struct list_head hybrid_list; struct list_head hybrid_list;
......
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