[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250416045117.876775-5-irogers@google.com>
Date: Tue, 15 Apr 2025 21:51:17 -0700
From: Ian Rogers <irogers@...gle.com>
To: Peter Zijlstra <peterz@...radead.org>, Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>, Namhyung Kim <namhyung@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>, Jiri Olsa <jolsa@...nel.org>,
Ian Rogers <irogers@...gle.com>, Adrian Hunter <adrian.hunter@...el.com>,
Kan Liang <kan.liang@...ux.intel.com>, James Clark <james.clark@...aro.org>,
Ze Gao <zegao2021@...il.com>, Weilin Wang <weilin.wang@...el.com>,
Dominique Martinet <asmadeus@...ewreck.org>,
Jean-Philippe Romain <jean-philippe.romain@...s.st.com>, Junhao He <hejunhao3@...wei.com>,
linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org,
Aditya Bodkhe <Aditya.Bodkhe1@....com>, Leo Yan <leo.yan@....com>,
Thomas Falcon <thomas.falcon@...el.com>, Atish Patra <atishp@...osinc.com>
Subject: [PATCH v8 4/4] perf perf_api_probe: Avoid scanning all PMUs, try
software PMU first
Add PMU names when geting events to probe. The first is only ever used
but by not specifying a PMU name perf_api_probe will load all the
PMUs.
Signed-off-by: Ian Rogers <irogers@...gle.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..a910cde4d78b 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.49.0.777.g153de2bbd5-goog
Powered by blists - more mailing lists