Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf pmu: Tolerate failure to read the type for wellknown PMUs

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>

authored by

Ian Rogers and committed by
Namhyung Kim
8c75dc74 bcc7693a

+32 -2
+32 -2
tools/perf/util/pmu.c
··· 1182 1182 return 0; 1183 1183 } 1184 1184 1185 + static __u32 wellknown_pmu_type(const char *pmu_name) 1186 + { 1187 + struct { 1188 + const char *pmu_name; 1189 + __u32 type; 1190 + } wellknown_pmus[] = { 1191 + { 1192 + "software", 1193 + PERF_TYPE_SOFTWARE 1194 + }, 1195 + { 1196 + "tracepoint", 1197 + PERF_TYPE_TRACEPOINT 1198 + }, 1199 + { 1200 + "breakpoint", 1201 + PERF_TYPE_BREAKPOINT 1202 + }, 1203 + }; 1204 + for (size_t i = 0; i < ARRAY_SIZE(wellknown_pmus); i++) { 1205 + if (!strcmp(wellknown_pmus[i].pmu_name, pmu_name)) 1206 + return wellknown_pmus[i].type; 1207 + } 1208 + return PERF_TYPE_MAX; 1209 + } 1210 + 1185 1211 struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char *name, 1186 1212 bool eager_load) 1187 1213 { ··· 1227 1201 * that type value is successfully assigned (return 1). 1228 1202 */ 1229 1203 if (perf_pmu__scan_file_at(pmu, dirfd, "type", "%u", &pmu->type) != 1) { 1230 - perf_pmu__delete(pmu); 1231 - return NULL; 1204 + /* Double check the PMU's name isn't wellknown. */ 1205 + pmu->type = wellknown_pmu_type(name); 1206 + if (pmu->type == PERF_TYPE_MAX) { 1207 + perf_pmu__delete(pmu); 1208 + return NULL; 1209 + } 1232 1210 } 1233 1211 1234 1212 /*