[PATCH v6 12/13] alpha/perf: sample only retired instructions for precise events
From: Matt Turner
Date: Wed Nov 04 2026 - 14:47:30 EST
ProfileMe samples include instructions killed on a wrong path, which
show up as hot spots in perf report although they did no work. On an
EV7 loop with a randomly mispredicted branch, 19% of the samples were
killed before being mapped and another 48% later.
PEBS and AMD IBS op samples are of retired instructions only, so make
precise_ip imply the retired filter, unless filters are given. The
profileme bit still selects every sample. With cycles:p, both kinds of
killed sample went to 0%.
DTB miss samples, whose instruction is aborted, are then dropped too:
cycles:p reports DTB hits only, and the misses need cpu/cycles,trapped/p.
The kept samples carry the full period, as do those AMD IBS keeps when
its swfilt discards others. So in frequency mode the sample rate, and
the event count perf report estimates from the periods, fall by the
share of killed instructions: to about a third on that loop.
Suggested-by: Ian Rogers <irogers@xxxxxxxxxx>
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Matt Turner <mattst88@xxxxxxxxx>
---
arch/alpha/kernel/perf_event.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/alpha/kernel/perf_event.c b/arch/alpha/kernel/perf_event.c
index 32a8b5c98381..7e34eac0ea47 100644
--- a/arch/alpha/kernel/perf_event.c
+++ b/arch/alpha/kernel/perf_event.c
@@ -837,6 +837,11 @@ static int __hw_perf_event_init(struct perf_event *event)
if (attr->config1 && !profileme)
return -EINVAL;
hwc->config = attr->config1;
+ /* As with PEBS, precise samples are of retired instructions. */
+ if (attr->precise_ip && !attr->config1 &&
+ !(attr->type == PERF_TYPE_RAW &&
+ (attr->config & ALPHA_PERF_CONFIG_PROFILEME)))
+ hwc->config = ALPHA_PERF_CONFIG1_RETIRED;
if (attr->type == PERF_TYPE_RAW &&
(attr->config & ALPHA_PERF_CONFIG_RANDOMIZE)) {
--
2.55.0