mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Matt Turner <mattst88@gmail.com>
To: Richard Henderson <richard.henderson@linaro.org>,
	 Magnus Lindholm <linmag7@gmail.com>,
	Peter Zijlstra <peterz@infradead.org>,
	 Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	 Namhyung Kim <namhyung@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	 Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	 Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
	 Adrian Hunter <adrian.hunter@intel.com>,
	 James Clark <james.clark@linaro.org>
Cc: linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-perf-users@vger.kernel.org,
	Matt Turner <mattst88@gmail.com>
Subject: [PATCH v5 09/11] alpha/perf: report the data source of ProfileMe DTB misses
Date: Tue, 03 Nov 2026 15:37:42 -0500	[thread overview]
Message-ID: <20261103-alpha-profileme-v5-9-bbe3937fbf3a@gmail.com> (raw)
In-Reply-To: <20261103-alpha-profileme-v5-0-bbe3937fbf3a@gmail.com>

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@google.com>
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Matt Turner <mattst88@gmail.com>
---
 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


  parent reply	other threads:[~2026-11-03 20:37 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 20:37 [PATCH v5 00/11] alpha/perf: add ProfileMe sampling Matt Turner
2026-11-03 20:37 ` [PATCH v5 01/11] alpha/perf: pass PERFMON_CMD_LOGGING_ALL to the logging options call Matt Turner
2026-11-03 20:37 ` [PATCH v5 02/11] alpha/perf: add sysfs format and event attributes Matt Turner
2026-11-03 20:37 ` [PATCH v5 03/11] alpha/perf: clear PERF_HES_UPTODATE when an event starts counting Matt Turner
2026-11-03 20:37 ` [PATCH v5 04/11] alpha/perf: do not report user registers from the entry code Matt Turner
2026-11-03 20:37 ` [PATCH v5 05/11] alpha/perf: implement ProfileMe sampling Matt Turner
2026-11-03 20:37 ` [PATCH v5 06/11] alpha/perf: attach ProfileMe status as PERF_SAMPLE_RAW data Matt Turner
2026-11-03 20:37 ` [PATCH v5 07/11] alpha/perf: optionally randomize the ProfileMe sampling interval Matt Turner
2026-11-03 20:37 ` [PATCH v5 08/11] alpha/perf: report the ProfileMe window count as the sample weight Matt Turner
2026-11-03 20:37 ` Matt Turner [this message]
2026-11-03 20:37 ` [PATCH v5 10/11] alpha/perf: add ProfileMe sample filters Matt Turner
2026-11-03 20:37 ` [PATCH v5 11/11] alpha/perf: sample only retired instructions for precise events Matt Turner
2026-11-03 23:42 ` [PATCH v5 00/11] alpha/perf: add ProfileMe sampling Ian Rogers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261103-alpha-profileme-v5-9-bbe3937fbf3a@gmail.com \
    --to=mattst88@gmail.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linmag7@gmail.com \
    --cc=linux-alpha@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®