Skip to content

Commit 3f59446

Browse files
committed
perf pmu: Tolerate failure to read the type for wellknown PMUs
JIRA: https://issues.redhat.com/browse/RHEL-78198 upstream ======== commit 8c75dc7 Author: Ian Rogers <irogers@google.com> Date: Thu Jul 10 16:51:17 2025 -0700 description =========== 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> Signed-off-by: Michael Petlan <mpetlan@redhat.com>
1 parent c3e6b74 commit 3f59446

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

tools/perf/util/pmu.c

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,32 @@ int perf_pmu__init(struct perf_pmu *pmu, __u32 type, const char *name)
11811181
return 0;
11821182
}
11831183

1184+
static __u32 wellknown_pmu_type(const char *pmu_name)
1185+
{
1186+
struct {
1187+
const char *pmu_name;
1188+
__u32 type;
1189+
} wellknown_pmus[] = {
1190+
{
1191+
"software",
1192+
PERF_TYPE_SOFTWARE
1193+
},
1194+
{
1195+
"tracepoint",
1196+
PERF_TYPE_TRACEPOINT
1197+
},
1198+
{
1199+
"breakpoint",
1200+
PERF_TYPE_BREAKPOINT
1201+
},
1202+
};
1203+
for (size_t i = 0; i < ARRAY_SIZE(wellknown_pmus); i++) {
1204+
if (!strcmp(wellknown_pmus[i].pmu_name, pmu_name))
1205+
return wellknown_pmus[i].type;
1206+
}
1207+
return PERF_TYPE_MAX;
1208+
}
1209+
11841210
struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char *name,
11851211
bool eager_load)
11861212
{
@@ -1200,8 +1226,12 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char
12001226
* that type value is successfully assigned (return 1).
12011227
*/
12021228
if (perf_pmu__scan_file_at(pmu, dirfd, "type", "%u", &pmu->type) != 1) {
1203-
perf_pmu__delete(pmu);
1204-
return NULL;
1229+
/* Double check the PMU's name isn't wellknown. */
1230+
pmu->type = wellknown_pmu_type(name);
1231+
if (pmu->type == PERF_TYPE_MAX) {
1232+
perf_pmu__delete(pmu);
1233+
return NULL;
1234+
}
12051235
}
12061236

12071237
/*

0 commit comments

Comments
 (0)