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>, Jiri Olsa <jolsa@kernel.org>,
Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>
Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 05/16] perf pmu: Probe precise_ip levels
Date: Fri, 13 Nov 2026 11:55:50 -0800 [thread overview]
Message-ID: <20261113195601.2872738-6-irogers@google.com> (raw)
In-Reply-To: <20261113195601.2872738-1-irogers@google.com>
Extend perf_pmu__probe() to probe supported precise_ip levels (1..3) and
populate probed.precise_mask and probed.max_precise.
Some PMUs that do not implement hardware precise sampling (such as
software, breakpoint, or AUX trace PMUs) silently ignore attr.precise_ip
even on non-sampling events (sample_period == 0), whereas PMUs that
genuinely validate precise_ip either reject precise_ip > 0 on counting
events or are sampling-only PMUs. Check for this before probing levels
1..3 so non-precise PMUs are not misreported as supporting precise_ip,
while still detecting higher precision levels when core events are
forwarded to hardware sampling units (such as AMD IBS).
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/pmu.c | 60 +++++++++++++++++++++++++++++++++++++++++++
tools/perf/util/pmu.h | 4 +++
2 files changed, 64 insertions(+)
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index d8bcf0e91f6f..322d90695c4b 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -3475,6 +3475,66 @@ static void __perf_pmu__probe(struct perf_pmu *pmu, int pmu_cpu)
if (pmu->probed.can_sample)
probe_sample_types(pmu, &base_attr, pid, cpu, flags);
+ /*
+ * 3. Precise sampling support (:p, :pp, :ppp).
+ * PMUs that do not validate attr.precise_ip (such as software,
+ * breakpoint, or intel_pt) silently accept precise_ip > 0 even when
+ * sample_period == 0. A PMU that genuinely implements precise_ip
+ * either rejects precise_ip > 0 on non-sampling events or is a
+ * sampling-only PMU (such as AMD ibs_op).
+ * Note: On AMD, core events like cycles:P are forwarded to IBS and
+ * support higher precision than advertised in sysfs caps/max_precise.
+ */
+ if (pmu->probed.can_sample && !pmu->auxtrace) {
+ bool ignores_precise_ip = false;
+
+ if (pmu->probed.can_count) {
+ struct perf_event_attr c_attr = base_attr;
+ int fd;
+
+ c_attr.sample_period = 0;
+ c_attr.freq = 0;
+ c_attr.sample_type = 0;
+ c_attr.precise_ip = 1;
+ fd = sys_perf_event_open(&c_attr, pid, cpu, -1, flags);
+ if (fd >= 0) {
+ close(fd);
+ ignores_precise_ip = true;
+ }
+ }
+
+ if (!ignores_precise_ip) {
+ for (int level = 1; level <= 3; level++) {
+ struct perf_event_attr p_attr = base_attr;
+ int fd;
+
+ p_attr.sample_period = 10000;
+ p_attr.sample_type = PERF_SAMPLE_IP;
+ p_attr.precise_ip = level;
+ fd = sys_perf_event_open(&p_attr, pid, cpu, -1, flags);
+ if (fd < 0 && p_attr.exclude_kernel && p_attr.config2 == 0) {
+ p_attr.config2 = 1;
+ fd = sys_perf_event_open(&p_attr, pid, cpu, -1, flags);
+ }
+ if (fd >= 0) {
+ close(fd);
+ pmu->probed.precise_mask |= (1u << level);
+ pmu->probed.max_precise = level;
+ }
+ }
+ /*
+ * Sampling-only PMUs, like AMD ibs_op, can't be checked
+ * with a counting event. If every level, including 3
+ * that few PMUs support, opened then assume precise_ip
+ * is ignored.
+ */
+ if (!pmu->probed.can_count && pmu->probed.precise_mask == 0xe) {
+ pmu->probed.precise_mask = 0;
+ pmu->probed.max_precise = 0;
+ }
+ }
+ }
+
if (keepalive_fd >= 0)
close(keepalive_fd);
pmu->probed.checked = true;
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
index 658485faa05d..fea65e314547 100644
--- a/tools/perf/util/pmu.h
+++ b/tools/perf/util/pmu.h
@@ -238,6 +238,10 @@ struct perf_pmu {
char *probe_event;
/** @probed.open_err: errno if open_supported is false. */
int open_err;
+ /** @probed.max_precise: Maximum precise_ip level (0..3) supported. */
+ int max_precise;
+ /** @probed.precise_mask: Bitmask of supported precise_ip levels (1..3). */
+ unsigned int precise_mask;
/**
* @probed.sample_types: Bitmask of supported
* enum perf_event_sample_format flags.
--
2.56.1.703.gf848ed807c-goog
next prev parent reply other threads:[~2026-11-13 19:56 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 19:55 [PATCH v2 00/16] perf sysinfo: Add subcommand to probe and summarize PMU capabilities Ian Rogers
2026-11-13 19:55 ` [PATCH v2 01/16] perf pmus: Expose duplicate uncore PMU scanning helpers Ian Rogers
2026-11-13 19:55 ` [PATCH v2 02/16] perf mem-events: Expose PMU init and name formatting helpers Ian Rogers
2026-11-13 19:55 ` [PATCH v2 03/16] perf pmu: Add perf_pmu__probe() for basic open, counting, and sampling Ian Rogers
2026-11-13 19:55 ` [PATCH v2 04/16] perf pmu: Probe supported sample_type flags Ian Rogers
2026-11-13 19:55 ` Ian Rogers [this message]
2026-11-13 19:55 ` [PATCH v2 06/16] perf pmu: Probe privilege exclusion modifiers Ian Rogers
2026-11-13 19:55 ` [PATCH v2 07/16] perf pmu: Probe execution and AUX area features Ian Rogers
2026-11-13 19:55 ` [PATCH v2 08/16] perf pmu: Probe event group size limits Ian Rogers
2026-11-13 19:55 ` [PATCH v2 09/16] perf pmu: Probe user and interrupt sample register masks Ian Rogers
2026-11-13 19:55 ` [PATCH v2 10/16] perf pmu: Probe interrupt registers that require precise sampling Ian Rogers
2026-11-13 19:55 ` [PATCH v2 11/16] perf pmu: Probe memory profiling events and sample formats Ian Rogers
2026-11-13 19:55 ` [PATCH v2 12/16] perf pmu: Probe user-space mmap capabilities Ian Rogers
2026-11-13 19:55 ` [PATCH v2 13/16] perf pmu: Probe branch instruction skid Ian Rogers
2026-11-13 19:55 ` [PATCH v2 14/16] perf sysinfo: Add sysinfo subcommand Ian Rogers
2026-11-13 19:56 ` [PATCH v2 15/16] perf docs: Add perf-sysinfo man page Ian Rogers
2026-11-13 19:56 ` [PATCH v2 16/16] perf test: Add perf sysinfo shell test 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=20261113195601.2872738-6-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/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®