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>,
Thomas Falcon <thomas.falcon@intel.com>,
Andi Kleen <ak@linux.intel.com>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
bpf@vger.kernel.org, Atish Patra <atishp@rivosinc.com>,
Beeman Strong <beeman@rivosinc.com>, Leo Yan <leo.yan@arm.com>,
Vince Weaver <vincent.weaver@maine.edu>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Subject: [PATCH v4 02/21] perf perf_api_probe: Avoid scanning all PMUs, try software PMU first
Date: Sun, 14 Sep 2025 11:11:02 -0700 [thread overview]
Message-ID: <20250914181121.1952748-3-irogers@google.com> (raw)
In-Reply-To: <20250914181121.1952748-1-irogers@google.com>
Scan the software PMU first rather than last as it is the least likely
to fail the probe. Specifying the software PMU by name was enabled by
commit 9957d8c801fe ("perf jevents: Add common software event
json"). For hardware events, add core PMU names when getting events to
probe so that not all PMUs are scanned. For example, when legacy
events support wildcards and for the event "cycles:u" on x86, we want
to only scan the "cpu" PMU and not all uncore PMUs for the event too.
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Thomas Richter <tmricht@linux.ibm.com>
---
tools/perf/util/perf_api_probe.c | 27 +++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/tools/perf/util/perf_api_probe.c b/tools/perf/util/perf_api_probe.c
index 1de3b69cdf4a..6ecf38314f01 100644
--- a/tools/perf/util/perf_api_probe.c
+++ b/tools/perf/util/perf_api_probe.c
@@ -59,10 +59,10 @@ static int perf_do_probe_api(setup_probe_fn_t fn, struct perf_cpu cpu, const cha
static bool perf_probe_api(setup_probe_fn_t fn)
{
- const char *try[] = {"cycles:u", "instructions:u", "cpu-clock:u", NULL};
+ struct perf_pmu *pmu;
struct perf_cpu_map *cpus;
struct perf_cpu cpu;
- int ret, i = 0;
+ int ret = 0;
cpus = perf_cpu_map__new_online_cpus();
if (!cpus)
@@ -70,12 +70,23 @@ static bool perf_probe_api(setup_probe_fn_t fn)
cpu = perf_cpu_map__cpu(cpus, 0);
perf_cpu_map__put(cpus);
- do {
- ret = perf_do_probe_api(fn, cpu, try[i++]);
- if (!ret)
- return true;
- } while (ret == -EAGAIN && try[i]);
-
+ ret = perf_do_probe_api(fn, cpu, "software/cpu-clock/u");
+ if (!ret)
+ return true;
+
+ pmu = perf_pmus__scan_core(/*pmu=*/NULL);
+ if (pmu) {
+ const char *try[] = {"cycles", "instructions", NULL};
+ char buf[256];
+ int i = 0;
+
+ while (ret == -EAGAIN && try[i]) {
+ snprintf(buf, sizeof(buf), "%s/%s/u", pmu->name, try[i++]);
+ ret = perf_do_probe_api(fn, cpu, buf);
+ if (!ret)
+ return true;
+ }
+ }
return false;
}
--
2.51.0.384.g4c02a37b29-goog
next prev parent reply other threads:[~2025-09-14 18:11 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-14 18:11 [PATCH v4 00/21] Legacy hardware/cache events as json Ian Rogers
2025-09-14 18:11 ` [PATCH v4 01/21] perf parse-events: Fix legacy cache events if event is duplicated in a PMU Ian Rogers
2025-09-14 18:11 ` Ian Rogers [this message]
2025-09-14 18:11 ` [PATCH v4 03/21] perf record: Skip don't fail for events that don't open Ian Rogers
2025-09-14 18:11 ` [PATCH v4 04/21] perf jevents: Support copying the source json files to OUTPUT Ian Rogers
2025-09-14 18:11 ` [PATCH v4 05/21] perf pmu: Don't eagerly parse event terms Ian Rogers
2025-09-14 18:11 ` [PATCH v4 06/21] perf parse-events: Remove unused FILE input argument to scanner Ian Rogers
2025-09-14 18:11 ` [PATCH v4 07/21] perf pmu: Use fd rather than FILE from new_alias Ian Rogers
2025-09-14 18:11 ` [PATCH v4 08/21] perf pmu: Factor term parsing into a perf_event_attr into a helper Ian Rogers
2025-09-14 18:11 ` [PATCH v4 09/21] perf parse-events: Add terms for legacy hardware and cache config values Ian Rogers
2025-09-14 18:11 ` [PATCH v4 10/21] perf jevents: Add legacy json terms and default_core event table helper Ian Rogers
2025-09-14 18:11 ` [PATCH v4 11/21] perf pmu: Add and use legacy_terms in alias information Ian Rogers
2025-09-14 18:11 ` [PATCH v4 12/21] perf jevents: Add legacy-hardware and legacy-cache json Ian Rogers
2025-09-14 18:11 ` [PATCH v4 13/21] perf print-events: Remove print_hwcache_events Ian Rogers
2025-09-14 18:11 ` [PATCH v4 14/21] perf print-events: Remove print_symbol_events Ian Rogers
2025-09-14 18:11 ` [PATCH v4 15/21] perf parse-events: Remove hard coded legacy hardware and cache parsing Ian Rogers
2025-09-14 18:11 ` [PATCH v4 16/21] perf record: Use evlist__new_default when no events specified Ian Rogers
2025-09-14 18:11 ` [PATCH v4 17/21] perf top: " Ian Rogers
2025-09-14 18:11 ` [PATCH v4 18/21] perf evlist: Avoid scanning all PMUs for evlist__new_default Ian Rogers
2025-09-14 18:11 ` [PATCH v4 19/21] perf evsel: Improvements to __evsel__match Ian Rogers
2025-09-14 18:11 ` [PATCH v4 20/21] perf parse-events: Add HW_CYCLES_STR as default cycles event string Ian Rogers
2025-09-16 13:18 ` Mark Rutland
2025-09-16 15:49 ` Ian Rogers
2025-09-16 17:56 ` Ian Rogers
2025-09-17 6:23 ` Namhyung Kim
2025-09-20 15:16 ` Ian Rogers
2025-09-14 18:11 ` [PATCH v4 21/21] perf test: Make stat grep more robust 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=20250914181121.1952748-3-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=atishp@rivosinc.com \
--cc=beeman@rivosinc.com \
--cc=bpf@vger.kernel.org \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=leo.yan@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=thomas.falcon@intel.com \
--cc=tmricht@linux.ibm.com \
--cc=vincent.weaver@maine.edu \
--cc=xu.yang_2@nxp.com \
/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
all inboxes | Powered by JetHome®