[RFC PATCH v2 3/4] riscv: Add perf_arch_misc_flags callback
From: Mayuresh Chitale
Date: Thu Oct 29 2026 - 09:12:31 EST
Similar to X86, add perf_arch_misc_flags callback so that
PERF_RECORD_MISC flags may be set based on the regs provided by the
SBI PMU perf driver.
Signed-off-by: Mayuresh Chitale <mayuresh.chitale@xxxxxxxxxxxxxxxx>
diff --git a/arch/riscv/include/asm/perf_event.h b/arch/riscv/include/asm/perf_event.h
index bcc928fd3785..cf13702b185f 100644
--- a/arch/riscv/include/asm/perf_event.h
+++ b/arch/riscv/include/asm/perf_event.h
@@ -9,6 +9,14 @@
#define _ASM_RISCV_PERF_EVENT_H
#ifdef CONFIG_PERF_EVENTS
+/* Use sstatus bit 2 to convey whether an epc in the sample is precise or not */
+#define PERF_SR_PRECISE _AC(0x00000004, UL)
+
+struct pt_regs;
+extern unsigned long perf_arch_misc_flags(struct pt_regs *regs);
+#define perf_arch_misc_flags(regs) perf_arch_misc_flags(regs)
+#define perf_arch_instruction_pointer(regs) instruction_pointer(regs)
+
#include <linux/perf_event.h>
#define perf_arch_bpf_user_pt_regs(regs) (struct user_regs_struct *)regs
diff --git a/arch/riscv/kernel/perf_callchain.c b/arch/riscv/kernel/perf_callchain.c
index b465bc9eb870..9b68d21b3a51 100644
--- a/arch/riscv/kernel/perf_callchain.c
+++ b/arch/riscv/kernel/perf_callchain.c
@@ -6,6 +6,21 @@
#include <asm/stacktrace.h>
+unsigned long perf_arch_misc_flags(struct pt_regs *regs)
+{
+ unsigned long misc;
+
+ if (user_mode(regs))
+ misc = PERF_RECORD_MISC_USER;
+ else
+ misc = PERF_RECORD_MISC_KERNEL;
+
+ if (regs->status & PERF_SR_PRECISE)
+ misc |= PERF_RECORD_MISC_EXACT_IP;
+
+ return misc;
+}
+
static bool fill_callchain(void *entry, unsigned long pc)
{
return perf_callchain_store(entry, pc) == 0;