[PATCH v5 08/11] alpha/perf: report the ProfileMe window count as the sample weight
From: Matt Turner
Date: Tue Nov 03 2026 - 15:39:28 EST
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 6c74f67ad341..c2c367b51617 100644
--- a/arch/alpha/kernel/perf_event.c
+++ b/arch/alpha/kernel/perf_event.c
@@ -1030,7 +1030,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);
@@ -1077,6 +1077,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;
@@ -1086,6 +1087,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);
@@ -1119,6 +1121,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