Alpha arch development list
 help / color / mirror / Atom feed
From: Matt Turner <mattst88@gmail.com>
To: linux-alpha@vger.kernel.org, richard.henderson@linaro.org
Cc: linmag7@gmail.com, linux-kernel@vger.kernel.org
Subject: [PATCH 22/24] alpha: add HAVE_PERF_REGS and HAVE_PERF_USER_STACK_DUMP support
Date: Tue,  1 Sep 2026 11:50:35 -0400	[thread overview]
Message-ID: <6e7a5e56a201a74c00d1615a7ac1d58d385194eb.1788277742.git.mattst88@gmail.com> (raw)
In-Reply-To: <cover.1788277742.git.mattst88@gmail.com>

Implement the perf register sampling interface for Alpha. This enables
perf to capture register state and user stack dumps with samples,
supporting --call-graph dwarf.

The perf_regs enum exposes the registers available in pt_regs: r0-r8,
r16-r28, gp, pc, and ps. Registers r9-r15 are callee-saved and live
in switch_stack, not pt_regs, so they are not included.

A switch statement maps perf register indices to pt_regs fields since
Alpha's pt_regs layout is non-contiguous (unlike architectures where
direct array indexing works).

Assisted-by: Claude:claude-opus-4-6
Signed-off-by: Matt Turner <mattst88@gmail.com>
---
 arch/alpha/Kconfig                      |  2 +
 arch/alpha/include/asm/perf_regs.h      |  7 ++
 arch/alpha/include/uapi/asm/perf_regs.h | 34 ++++++++++
 arch/alpha/kernel/Makefile              |  1 +
 arch/alpha/kernel/perf_regs.c           | 86 +++++++++++++++++++++++++
 5 files changed, 130 insertions(+)
 create mode 100644 arch/alpha/include/asm/perf_regs.h
 create mode 100644 arch/alpha/include/uapi/asm/perf_regs.h
 create mode 100644 arch/alpha/kernel/perf_regs.c

diff --git ./arch/alpha/Kconfig ./arch/alpha/Kconfig
index bda8443a7323..74d13a29b8a9 100644
--- ./arch/alpha/Kconfig
+++ ./arch/alpha/Kconfig
@@ -31,6 +31,8 @@ config ALPHA
 	select HAVE_PAGE_SIZE_8KB
 	select HAVE_PCSPKR_PLATFORM
 	select HAVE_PERF_EVENTS
+	select HAVE_PERF_REGS
+	select HAVE_PERF_USER_STACK_DUMP
 	select NEED_DMA_MAP_STATE
 	select NEED_SG_DMA_LENGTH
 	select GENERIC_IRQ_PROBE
diff --git ./arch/alpha/include/asm/perf_regs.h ./arch/alpha/include/asm/perf_regs.h
new file mode 100644
index 000000000000..6045da1a2a4f
--- /dev/null
+++ ./arch/alpha/include/asm/perf_regs.h
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_ALPHA_PERF_REGS_H
+#define _ASM_ALPHA_PERF_REGS_H
+
+#include <uapi/asm/perf_regs.h>
+
+#endif /* _ASM_ALPHA_PERF_REGS_H */
diff --git ./arch/alpha/include/uapi/asm/perf_regs.h ./arch/alpha/include/uapi/asm/perf_regs.h
new file mode 100644
index 000000000000..afeb6a1584cd
--- /dev/null
+++ ./arch/alpha/include/uapi/asm/perf_regs.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef _UAPI_ASM_ALPHA_PERF_REGS_H
+#define _UAPI_ASM_ALPHA_PERF_REGS_H
+
+enum perf_event_alpha_regs {
+	PERF_REG_ALPHA_R0,
+	PERF_REG_ALPHA_R1,
+	PERF_REG_ALPHA_R2,
+	PERF_REG_ALPHA_R3,
+	PERF_REG_ALPHA_R4,
+	PERF_REG_ALPHA_R5,
+	PERF_REG_ALPHA_R6,
+	PERF_REG_ALPHA_R7,
+	PERF_REG_ALPHA_R8,
+	PERF_REG_ALPHA_R16,
+	PERF_REG_ALPHA_R17,
+	PERF_REG_ALPHA_R18,
+	PERF_REG_ALPHA_R19,
+	PERF_REG_ALPHA_R20,
+	PERF_REG_ALPHA_R21,
+	PERF_REG_ALPHA_R22,
+	PERF_REG_ALPHA_R23,
+	PERF_REG_ALPHA_R24,
+	PERF_REG_ALPHA_R25,
+	PERF_REG_ALPHA_R26,
+	PERF_REG_ALPHA_R27,
+	PERF_REG_ALPHA_R28,
+	PERF_REG_ALPHA_GP,
+	PERF_REG_ALPHA_PC,
+	PERF_REG_ALPHA_PS,
+	PERF_REG_ALPHA_MAX,
+};
+
+#endif /* _UAPI_ASM_ALPHA_PERF_REGS_H */
diff --git ./arch/alpha/kernel/Makefile ./arch/alpha/kernel/Makefile
index 4ea5c189e60e..0c04b89676ed 100644
--- ./arch/alpha/kernel/Makefile
+++ ./arch/alpha/kernel/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_PCI)	+= pci.o pci_iommu.o pci-sysfs.o
 obj-$(CONFIG_SRM_ENV)	+= srm_env.o
 obj-$(CONFIG_MODULES)	+= module.o
 obj-$(CONFIG_PERF_EVENTS) += perf_event.o
+obj-$(CONFIG_HAVE_PERF_REGS) += perf_regs.o
 obj-$(CONFIG_RTC_DRV_ALPHA) += rtc.o
 obj-$(CONFIG_AUDIT)	+= audit.o
 
diff --git ./arch/alpha/kernel/perf_regs.c ./arch/alpha/kernel/perf_regs.c
new file mode 100644
index 000000000000..e15081ac95e0
--- /dev/null
+++ ./arch/alpha/kernel/perf_regs.c
@@ -0,0 +1,86 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/perf_event.h>
+#include <asm/perf_regs.h>
+#include <asm/ptrace.h>
+
+u64 perf_reg_value(struct pt_regs *regs, int idx)
+{
+	switch (idx) {
+	case PERF_REG_ALPHA_R0:
+		return regs->r0;
+	case PERF_REG_ALPHA_R1:
+		return regs->r1;
+	case PERF_REG_ALPHA_R2:
+		return regs->r2;
+	case PERF_REG_ALPHA_R3:
+		return regs->r3;
+	case PERF_REG_ALPHA_R4:
+		return regs->r4;
+	case PERF_REG_ALPHA_R5:
+		return regs->r5;
+	case PERF_REG_ALPHA_R6:
+		return regs->r6;
+	case PERF_REG_ALPHA_R7:
+		return regs->r7;
+	case PERF_REG_ALPHA_R8:
+		return regs->r8;
+	case PERF_REG_ALPHA_R16:
+		return regs->r16;
+	case PERF_REG_ALPHA_R17:
+		return regs->r17;
+	case PERF_REG_ALPHA_R18:
+		return regs->r18;
+	case PERF_REG_ALPHA_R19:
+		return regs->r19;
+	case PERF_REG_ALPHA_R20:
+		return regs->r20;
+	case PERF_REG_ALPHA_R21:
+		return regs->r21;
+	case PERF_REG_ALPHA_R22:
+		return regs->r22;
+	case PERF_REG_ALPHA_R23:
+		return regs->r23;
+	case PERF_REG_ALPHA_R24:
+		return regs->r24;
+	case PERF_REG_ALPHA_R25:
+		return regs->r25;
+	case PERF_REG_ALPHA_R26:
+		return regs->r26;
+	case PERF_REG_ALPHA_R27:
+		return regs->r27;
+	case PERF_REG_ALPHA_R28:
+		return regs->r28;
+	case PERF_REG_ALPHA_GP:
+		return regs->gp;
+	case PERF_REG_ALPHA_PC:
+		return regs->pc;
+	case PERF_REG_ALPHA_PS:
+		return regs->ps;
+	default:
+		WARN_ON_ONCE(1);
+		return 0;
+	}
+}
+
+#define REG_RESERVED (~((1ULL << PERF_REG_ALPHA_MAX) - 1))
+
+int perf_reg_validate(u64 mask)
+{
+	if (!mask || mask & REG_RESERVED)
+		return -EINVAL;
+
+	return 0;
+}
+
+u64 perf_reg_abi(struct task_struct *task)
+{
+	return PERF_SAMPLE_REGS_ABI_64;
+}
+
+void perf_get_regs_user(struct perf_regs *regs_user,
+			struct pt_regs *regs)
+{
+	regs_user->regs = task_pt_regs(current);
+	regs_user->abi = perf_reg_abi(current);
+}
-- 
2.54.0


  parent reply	other threads:[~2026-09-01 15:51 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-01 15:50 [PATCH 00/24] alpha: catch up on architecture Kconfig options Matt Turner
2026-09-01 15:50 ` [PATCH 01/24] alpha: fix arch_irqs_disabled_flags() to treat any raised IPL as disabled Matt Turner
2026-09-01 23:20   ` Magnus Lindholm
2026-09-01 15:50 ` [PATCH 02/24] alpha: enter hardirq context before looking up the irq descriptor Matt Turner
2026-09-03 22:07   ` Magnus Lindholm
2026-09-01 15:50 ` [PATCH 03/24] alpha: select ARCH_HAS_UBSAN Matt Turner
2026-09-01 22:34   ` Magnus Lindholm
2026-09-01 15:50 ` [PATCH 04/24] alpha: select ARCH_HAS_GCOV_PROFILE_ALL Matt Turner
2026-09-03 22:35   ` Magnus Lindholm
2026-09-01 15:50 ` [PATCH 05/24] alpha: select HAVE_DEBUG_KMEMLEAK Matt Turner
2026-09-02  6:01   ` Magnus Lindholm
2026-09-01 15:50 ` [PATCH 06/24] alpha: select EDAC_SUPPORT Matt Turner
2026-09-01 23:17   ` Magnus Lindholm
2026-09-01 15:50 ` [PATCH 07/24] alpha: select ARCH_SUPPORTS_ATOMIC_RMW Matt Turner
2026-09-02  6:17   ` Magnus Lindholm
2026-09-01 15:50 ` [PATCH 08/24] alpha: select ARCH_HAS_FAST_MULTIPLIER Matt Turner
2026-09-02  7:49   ` Magnus Lindholm
2026-09-01 15:50 ` [PATCH 09/24] alpha: select ARCH_SUPPORTS_INT128 Matt Turner
2026-09-02  8:50   ` Magnus Lindholm
2026-09-01 15:50 ` [PATCH 10/24] alpha: select HAVE_ARCH_COMPILER_H Matt Turner
2026-09-02  9:11   ` Magnus Lindholm
2026-09-01 15:50 ` [PATCH 11/24] alpha: select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE Matt Turner
2026-09-02  9:25   ` Magnus Lindholm
2026-09-01 15:50 ` [PATCH 12/24] alpha: add HAVE_ARCH_THREAD_STRUCT_WHITELIST support Matt Turner
2026-09-02  9:35   ` Magnus Lindholm
2026-09-01 15:50 ` [PATCH 13/24] alpha: add ARCH_HAS_PTE_SPECIAL support Matt Turner
2026-09-02  9:42   ` Magnus Lindholm
2026-09-01 15:50 ` [PATCH 14/24] alpha: add ARCH_SUPPORTS_PAGE_TABLE_CHECK support Matt Turner
2026-09-01 22:45   ` Magnus Lindholm
2026-09-01 15:50 ` [PATCH 15/24] alpha: select ARCH_HAS_DEBUG_VM_PGTABLE Matt Turner
2026-09-03 22:52   ` Magnus Lindholm
2026-09-01 15:50 ` [PATCH 16/24] alpha: select HAVE_GUP_FAST Matt Turner
2026-09-02 21:09   ` Magnus Lindholm
2026-09-01 15:50 ` [PATCH 17/24] alpha: select ARCH_USE_MEMTEST Matt Turner
2026-09-02 21:56   ` Magnus Lindholm
2026-09-01 15:50 ` [PATCH 18/24] alpha: select SYSCTL_EXCEPTION_TRACE Matt Turner
2026-09-02 22:02   ` Magnus Lindholm
2026-09-01 15:50 ` [PATCH 19/24] alpha: discard .eh_frame and the relocation sections Matt Turner
2026-09-03  5:18   ` Magnus Lindholm
2026-09-01 15:50 ` [PATCH 20/24] alpha: select ARCH_WANT_LD_ORPHAN_WARN Matt Turner
2026-09-03  5:34   ` Magnus Lindholm
2026-09-01 15:50 ` [PATCH 21/24] alpha: select ARCH_WANT_IRQS_OFF_ACTIVATE_MM Matt Turner
2026-09-03  5:42   ` Magnus Lindholm
2026-09-01 15:50 ` Matt Turner [this message]
2026-09-03 21:01   ` [PATCH 22/24] alpha: add HAVE_PERF_REGS and HAVE_PERF_USER_STACK_DUMP support Magnus Lindholm
2026-09-01 15:50 ` [PATCH 23/24] alpha: select SPARSE_IRQ Matt Turner
2026-09-03 21:26   ` Magnus Lindholm
2026-09-01 15:50 ` [PATCH 24/24] alpha: add TRACE_IRQFLAGS_SUPPORT Matt Turner
2026-09-03 22:58   ` Magnus Lindholm
2026-09-02 18:53 ` [PATCH 00/24] alpha: catch up on architecture Kconfig options Magnus Lindholm
2026-09-02 18:57   ` Matt Turner

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=6e7a5e56a201a74c00d1615a7ac1d58d385194eb.1788277742.git.mattst88@gmail.com \
    --to=mattst88@gmail.com \
    --cc=linmag7@gmail.com \
    --cc=linux-alpha@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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