summaryrefslogtreecommitdiffstats
path: root/tools/perf/util/pmus.c
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2023-06-22 21:38:42 -0700
committerNamhyung Kim <namhyung@kernel.org>2023-06-22 22:14:35 -0700
commitd685819b40affd39d2fbc937e93b2eee7fc63dd5 (patch)
treec70c383d890332d5f3be929091f87452b3e117fb /tools/perf/util/pmus.c
parent33941dbd14da4eac40a26ac5fd5f84e1842ffc3a (diff)
downloadlinux-stable-d685819b40affd39d2fbc937e93b2eee7fc63dd5.tar.gz
linux-stable-d685819b40affd39d2fbc937e93b2eee7fc63dd5.tar.bz2
linux-stable-d685819b40affd39d2fbc937e93b2eee7fc63dd5.zip
perf pmus: Add notion of default PMU for JSON events
JSON events created in pmu-events.c by jevents.py may not specify a PMU they are associated with, in which case it is implied that it is the first core PMU. Care is needed to select this for regular 'cpu', s390 'cpum_cf' and ARMs many names as at the point the name is first needed the core PMUs list hasn't been initialized. Add a helper in perf_pmus to create this value, in the worst case by scanning sysfs. v2. Add missing close if fdopendir fails. Signed-off-by: Ian Rogers <irogers@google.com> Tested-by: Thomas Richter <tmricht@linux.ibm.com> Cc: Ravi Bangoria <ravi.bangoria@amd.com> Cc: James Clark <james.clark@arm.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Thomas Richter <tmricht@linux.ibm.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Link: https://lore.kernel.org/r/20230623043843.4080180-1-irogers@google.com Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Diffstat (limited to 'tools/perf/util/pmus.c')
-rw-r--r--tools/perf/util/pmus.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c
index d891d72c824e..0866dee3fc62 100644
--- a/tools/perf/util/pmus.c
+++ b/tools/perf/util/pmus.c
@@ -137,8 +137,10 @@ static void pmu_read_sysfs(bool core_only)
return;
dir = fdopendir(fd);
- if (!dir)
+ if (!dir) {
+ close(fd);
return;
+ }
while ((dent = readdir(dir))) {
if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
@@ -524,6 +526,39 @@ bool perf_pmus__supports_extended_type(void)
return perf_pmus__do_support_extended_type;
}
+char *perf_pmus__default_pmu_name(void)
+{
+ int fd;
+ DIR *dir;
+ struct dirent *dent;
+ char *result = NULL;
+
+ if (!list_empty(&core_pmus))
+ return strdup(list_first_entry(&core_pmus, struct perf_pmu, list)->name);
+
+ fd = perf_pmu__event_source_devices_fd();
+ if (fd < 0)
+ return strdup("cpu");
+
+ dir = fdopendir(fd);
+ if (!dir) {
+ close(fd);
+ return strdup("cpu");
+ }
+
+ while ((dent = readdir(dir))) {
+ if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
+ continue;
+ if (is_pmu_core(dent->d_name)) {
+ result = strdup(dent->d_name);
+ break;
+ }
+ }
+
+ closedir(dir);
+ return result ?: strdup("cpu");
+}
+
struct perf_pmu *evsel__find_pmu(const struct evsel *evsel)
{
struct perf_pmu *pmu = evsel->pmu;