[PATCH v5 09/11] alpha/perf: report the data source of ProfileMe DTB misses

From: Matt Turner

Date: Tue Nov 03 2026 - 15:40:03 EST


A ProfileMe sample whose instruction trapped on a DTB miss identifies a
memory access that missed the DTB, but only in the PERF_SAMPLE_RAW data.

Set PERF_SAMPLE_DATA_SRC for those samples, so that the memory sort keys
see them: mem_dtlb is an L1 miss, and mem_op comes from the opcode, as
I_STAT does not say whether the access was a load or a store. Samples
that fall back to the interrupted PC get none.

I_STAT[TRP] is ignored for an instruction killed before it was mapped. On
an EV7, TRP and MIS were seen set for killed instructions that are not
even branches.

Suggested-by: Ian Rogers <irogers@xxxxxxxxxx>
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Matt Turner <mattst88@xxxxxxxxx>
---
arch/alpha/include/asm/wrperfmon.h | 11 ++++++++
arch/alpha/kernel/perf_event.c | 51 ++++++++++++++++++++++++++++++++++++++
2 files changed, 62 insertions(+)

diff --git a/arch/alpha/include/asm/wrperfmon.h b/arch/alpha/include/asm/wrperfmon.h
index 7fbbfd74926a..489b3e073a32 100644
--- a/arch/alpha/include/asm/wrperfmon.h
+++ b/arch/alpha/include/asm/wrperfmon.h
@@ -100,6 +100,17 @@
/* ProfileMe status, from the EV67/EV68 Hardware Reference Manuals. */
#define EV67_I_STAT_OVR_SHIFT 30
#define EV67_I_STAT_OVR_MASK 0x7UL
+#define EV67_I_STAT_TRAP_TYPE_SHIFT 34
+#define EV67_I_STAT_TRAP_TYPE_MASK 0xfUL
+#define EV67_I_STAT_TRP (1UL<<39)
+#define EV67_I_STAT_MIS (1UL<<40)
+
+/* I_STAT[TRAP_TYPE] values */
+#define EV67_TRAP_DTB_DOUBLE_3 2
+#define EV67_TRAP_DTB_DOUBLE_4 3
+#define EV67_TRAP_DTB_SINGLE 6
+
+#define EV67_PCTR_PM_KILLED_BM (1UL<<26)

/* PMPC bits 63:2 hold the profiled PC. Bit 0 set means a PALmode address. */
#define EV67_PMPC_PAL (1UL<<0)
diff --git a/arch/alpha/kernel/perf_event.c b/arch/alpha/kernel/perf_event.c
index c2c367b51617..7f53aea261b0 100644
--- a/arch/alpha/kernel/perf_event.c
+++ b/arch/alpha/kernel/perf_event.c
@@ -20,6 +20,7 @@
#include <linux/overflow.h>
#include <linux/prandom.h>
#include <linux/sched/task_stack.h>
+#include <linux/uaccess.h>

#include <asm/hwrpb.h>
#include <linux/atomic.h>
@@ -1015,6 +1016,39 @@ static void alpha_profileme_set_regs_user(struct perf_event *event,
sizeof(u64);
}

+/* TRP, and MIS with it, are stale for an insn killed before it was mapped. */
+static bool alpha_profileme_trp(unsigned long i_stat, unsigned long pctr_ctl)
+{
+ return !(pctr_ctl & EV67_PCTR_PM_KILLED_BM) && (i_stat & EV67_I_STAT_TRP);
+}
+
+static u64 alpha_profileme_mem_op(unsigned long pc)
+{
+ u32 insn;
+
+ if (pc < TASK_SIZE) {
+ if (copy_from_user_nofault(&insn, (const void __user *)pc,
+ sizeof(insn)))
+ return PERF_MEM_OP_NA;
+ } else if (copy_from_kernel_nofault(&insn, (const void *)pc,
+ sizeof(insn))) {
+ return PERF_MEM_OP_NA;
+ }
+
+ switch (insn >> 26) {
+ case 0x0a: case 0x0b: case 0x0c: /* ldbu, ldq_u, ldwu */
+ case 0x20: case 0x21: case 0x22: case 0x23: /* ldf, ldg, lds, ldt */
+ case 0x28: case 0x29: case 0x2a: case 0x2b: /* ldl, ldq, ldl_l, ldq_l */
+ return PERF_MEM_OP_LOAD;
+ case 0x0d: case 0x0e: case 0x0f: /* stw, stb, stq_u */
+ case 0x24: case 0x25: case 0x26: case 0x27: /* stf, stg, sts, stt */
+ case 0x2c: case 0x2d: case 0x2e: case 0x2f: /* stl, stq, stl_c, stq_c */
+ return PERF_MEM_OP_STORE;
+ default:
+ return PERF_MEM_OP_NA;
+ }
+}
+
/*
* Handle the close of a ProfileMe window on PCTR0.
*
@@ -1130,6 +1164,23 @@ static void alpha_perf_event_profileme(struct perf_event *event,
data.sample_flags |= PERF_SAMPLE_WEIGHT_TYPE;
}

+ if (exact && (event->attr.sample_type & PERF_SAMPLE_DATA_SRC) &&
+ alpha_profileme_trp(i_stat, pctr_ctl) &&
+ !(i_stat & EV67_I_STAT_MIS)) {
+ switch ((i_stat >> EV67_I_STAT_TRAP_TYPE_SHIFT) &
+ EV67_I_STAT_TRAP_TYPE_MASK) {
+ case EV67_TRAP_DTB_SINGLE:
+ case EV67_TRAP_DTB_DOUBLE_3:
+ case EV67_TRAP_DTB_DOUBLE_4:
+ data.data_src.val = PERF_MEM_NA;
+ data.data_src.mem_op = alpha_profileme_mem_op(pc);
+ data.data_src.mem_dtlb = PERF_MEM_TLB_L1 |
+ PERF_MEM_TLB_MISS;
+ data.sample_flags |= PERF_SAMPLE_DATA_SRC;
+ break;
+ }
+ }
+
if (!alpha_perf_event_set_period(event, hwc, 0))
return;


--
2.55.0