From: Ian Rogers <irogers@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Kan Liang <kan.liang@linux.intel.com>,
James Clark <james.clark@linaro.org>,
Xu Yang <xu.yang_2@nxp.com>,
John Garry <john.g.garry@oracle.com>,
"Masami Hiramatsu (Google)" <mhiramat@kernel.org>,
Howard Chu <howardchu95@gmail.com>,
Weilin Wang <weilin.wang@intel.com>,
Thomas Richter <tmricht@linux.ibm.com>,
Andi Kleen <ak@linux.intel.com>,
Tiezhu Yang <yangtiezhu@loongson.cn>,
Gautam Menghani <gautam@linux.ibm.com>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: [PATCH v2 10/15] perf pmu: Tolerate failure to read the type for wellknown PMUs
Date: Wed, 11 Jun 2025 09:02:01 -0700 [thread overview]
Message-ID: <20250611160206.552030-11-irogers@google.com> (raw)
In-Reply-To: <20250611160206.552030-1-irogers@google.com>
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>
---
tools/perf/util/pmu.c | 34 ++++++++++++++++++++++++++++++++--
1 file changed, 32 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 76b7ded7fbf4..c0c12880146a 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -1180,6 +1180,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)
{
@@ -1199,8 +1225,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;
+ }
}
/*
--
2.50.0.rc0.642.g800a2b2222-goog
next prev parent reply other threads:[~2025-06-11 16:02 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-11 16:01 [PATCH v2 00/15] New perf ilist app Ian Rogers
2025-06-11 16:01 ` [PATCH v2 01/15] perf hwmon_pmu: Avoid shortening hwmon PMU name Ian Rogers
2025-06-11 16:01 ` [PATCH v2 02/15] perf parse-events: Minor tidy up of event_type helper Ian Rogers
2025-06-11 16:01 ` [PATCH v2 03/15] perf python: In str(evsel) use the evsel__pmu_name helper Ian Rogers
2025-06-11 16:01 ` [PATCH v2 04/15] perf python: Fix thread check in pyrf_evsel__read Ian Rogers
2025-06-11 16:01 ` [PATCH v2 05/15] perf python: Correct pyrf_evsel__read for tool PMUs Ian Rogers
2025-06-11 16:01 ` [PATCH v2 06/15] perf python: Add basic PMU abstraction and pmus sequence Ian Rogers
2025-06-11 16:01 ` [PATCH v2 07/15] perf python: Add function returning dictionary of all events on a PMU Ian Rogers
2025-06-11 16:01 ` [PATCH v2 08/15] perf jevents: If the long_desc and desc are identical then drop the long_desc Ian Rogers
2025-06-11 16:02 ` [PATCH v2 09/15] perf jevents: Add common software event json Ian Rogers
2025-06-11 16:02 ` Ian Rogers [this message]
2025-06-11 16:02 ` [PATCH v2 11/15] perf parse-events: Remove non-json software events Ian Rogers
2025-06-11 16:02 ` [PATCH v2 12/15] perf tp_pmu: Factor existing tracepoint logic to new file Ian Rogers
2025-06-11 16:02 ` [PATCH v2 13/15] perf tp_pmu: Add event APIs Ian Rogers
2025-06-11 16:02 ` [PATCH v2 14/15] perf list: Remove tracepoint printing code Ian Rogers
2025-06-11 16:02 ` [PATCH v2 15/15] perf ilist: Add new python ilist command Ian Rogers
2025-06-11 16:34 ` [PATCH v2 00/15] New perf ilist app Ian Rogers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250611160206.552030-11-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=gautam@linux.ibm.com \
--cc=howardchu95@gmail.com \
--cc=james.clark@linaro.org \
--cc=john.g.garry@oracle.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=tmricht@linux.ibm.com \
--cc=weilin.wang@intel.com \
--cc=xu.yang_2@nxp.com \
--cc=yangtiezhu@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).