]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
perf pmu: Tolerate failure to read the type for wellknown PMUs
authorIan Rogers <irogers@google.com>
Thu, 10 Jul 2025 23:51:17 +0000 (16:51 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Fri, 11 Jul 2025 19:36:40 +0000 (12:36 -0700)
If sysfs isn't mounted then we may fail to read a PMU's type. In this
situation resort to lookup of wellknown types. Only applies to
software, tracepoint and breakpoint PMUs.

Signed-off-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20250710235126.1086011-5-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/pmu.c

index f795883c233fb0a0534d597a667e3bd7cb0dcfed..23666883049d3951d15b60adb8b4636716ce1b64 100644 (file)
@@ -1182,6 +1182,32 @@ int perf_pmu__init(struct perf_pmu *pmu, __u32 type, const char *name)
        return 0;
 }
 
+static __u32 wellknown_pmu_type(const char *pmu_name)
+{
+       struct {
+               const char *pmu_name;
+               __u32 type;
+       } wellknown_pmus[] = {
+               {
+                       "software",
+                       PERF_TYPE_SOFTWARE
+               },
+               {
+                       "tracepoint",
+                       PERF_TYPE_TRACEPOINT
+               },
+               {
+                       "breakpoint",
+                       PERF_TYPE_BREAKPOINT
+               },
+       };
+       for (size_t i = 0; i < ARRAY_SIZE(wellknown_pmus); i++) {
+               if (!strcmp(wellknown_pmus[i].pmu_name, pmu_name))
+                       return wellknown_pmus[i].type;
+       }
+       return PERF_TYPE_MAX;
+}
+
 struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char *name,
                                  bool eager_load)
 {
@@ -1201,8 +1227,12 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char
         * that type value is successfully assigned (return 1).
         */
        if (perf_pmu__scan_file_at(pmu, dirfd, "type", "%u", &pmu->type) != 1) {
-               perf_pmu__delete(pmu);
-               return NULL;
+               /* Double check the PMU's name isn't wellknown. */
+               pmu->type = wellknown_pmu_type(name);
+               if (pmu->type == PERF_TYPE_MAX) {
+                       perf_pmu__delete(pmu);
+                       return NULL;
+               }
        }
 
        /*