Re: [PATCH v6 12/13] alpha/perf: sample only retired instructions for precise events

From: Magnus Lindholm

Date: Thu Nov 05 2026 - 14:16:21 EST


Hi Matt,

On Wed, Nov 4, 2026 at 7:49 PM Matt Turner <mattst88@xxxxxxxxx> wrote:
>
> 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
>

All 77717 instructions:p samples I checked on my ES40 matched the
retired predicate. Using cpu/event=2,profileme=1/ gave me the
unfiltered view, including the DTB miss samples.

Reviewed-by: Magnus Lindholm <linmag7@xxxxxxxxx>
Tested-by: Magnus Lindholm <linmag7@xxxxxxxxx>