Re: [PATCH v6 09/13] alpha/perf: report the ProfileMe window count as the sample weight

From: Magnus Lindholm

Date: Wed Nov 04 2026 - 22:39:02 EST


Hi Matt,

On Wed, Nov 4, 2026 at 7:49 PM Matt Turner <mattst88@xxxxxxxxx> wrote:
>
> What PCTR1 counted during the ProfileMe window, the inum retire delay for
> cycles:p or the window length for instructions:p, is only available in
> the PERF_SAMPLE_RAW data.
>
> Report it in var1_dw of the sample weight, which the weight and
> local_weight sort keys read. It is 20 bits, so it fits. As Alpha is
> little-endian, this is also the right value for plain PERF_SAMPLE_WEIGHT,
> which is what perf record -W asks for. Samples that fall back to the
> interrupted PC get no weight, as it belongs to a different instruction.
>
> 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 | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/arch/alpha/kernel/perf_event.c b/arch/alpha/kernel/perf_event.c
> index b33677cc23ca..c9ab40ff76ad 100644
> --- a/arch/alpha/kernel/perf_event.c
> +++ b/arch/alpha/kernel/perf_event.c
> @@ -1068,7 +1068,7 @@ static void alpha_perf_event_profileme(struct perf_event *event,
> struct perf_raw_record raw;
> struct perf_sample_data data;
> struct pt_regs *pm_regs;
> - bool pc_only = false;
> + bool pc_only = false, exact = true;
> unsigned long pctr_ctl, i_stat, pmpc, ovr, pc, saved_pc, saved_ps;
>
> pctr_ctl = wrperfmon(PERFMON_CMD_READ, 0);
> @@ -1115,6 +1115,7 @@ static void alpha_perf_event_profileme(struct perf_event *event,
> pc = pmpc & EV67_PMPC_PC_MASK;
> if (pmpc & EV67_PMPC_PAL) {
> pc = regs->pc;
> + exact = false;
> } else if (pc < TASK_SIZE && !user_mode(regs)) {
> if (is_user_task(current)) {
> pc_only = true;
> @@ -1124,6 +1125,7 @@ static void alpha_perf_event_profileme(struct perf_event *event,
> pm_regs->ps = 8;
> } else {
> pc = regs->pc;
> + exact = false;
> }
> } else if (pc >= TASK_SIZE && user_mode(regs)) {
> pm_regs = this_cpu_ptr(&alpha_profileme_regs);
> @@ -1157,6 +1159,15 @@ static void alpha_perf_event_profileme(struct perf_event *event,
> };
> perf_sample_save_raw_data(&data, event, &raw);
>
> + /* The count belongs to the profiled instruction, not the interrupted PC. */
> + if (exact && (event->attr.sample_type & PERF_SAMPLE_WEIGHT_TYPE)) {
> + /* perf_sample_data_init() does not clear it. */
> + data.weight.full = 0;
> + data.weight.var1_dw = (pctr_ctl >> EV67_PCTR_1_COUNT_SHIFT) &
> + EV67_PCTR_1_COUNT_MASK;
> + data.sample_flags |= PERF_SAMPLE_WEIGHT_TYPE;
> + }
> +
> if (!alpha_perf_event_set_period(event, hwc, 0))
> return;
>
>
> --
> 2.55.0
>

On my ES40 I compared the sample weight with PCTR1 in the raw record
for all four counting modes. They matched for samples attributed to
PMPC, and samples that fell back to the interrupted PC had weight zero.

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