csky: Add support for perf registers sampling
authorMao Han <han_mao@c-sky.com>
Mon, 15 Apr 2019 09:17:29 +0000 (17:17 +0800)
committerGuo Ren <ren_guo@c-sky.com>
Mon, 22 Apr 2019 05:44:57 +0000 (13:44 +0800)
This patch implements the perf registers sampling and validation API
for csky arch. The valid registers and their register ID are defined in
perf_regs.h. Perf tool can backtrace in userspace with unwind library
and the registers/user stack dump support.

Signed-off-by: Mao Han <han_mao@c-sky.com>
Signed-off-by: Guo Ren <ren_guo@c-sky.com>
arch/csky/Kconfig
arch/csky/include/uapi/asm/perf_regs.h [new file with mode: 0644]
arch/csky/kernel/Makefile
arch/csky/kernel/perf_regs.c [new file with mode: 0644]

index c4974cf6a222a6f4c2d466c1c0f190b5acfdc99b..8e45c7ac8e2492788dc514bb65ad70418001d89d 100644 (file)
@@ -38,6 +38,8 @@ config CSKY
        select HAVE_KERNEL_LZO
        select HAVE_KERNEL_LZMA
        select HAVE_PERF_EVENTS
+       select HAVE_PERF_REGS
+       select HAVE_PERF_USER_STACK_DUMP
        select HAVE_DMA_API_DEBUG
        select HAVE_DMA_CONTIGUOUS
        select HAVE_SYSCALL_TRACEPOINTS
diff --git a/arch/csky/include/uapi/asm/perf_regs.h b/arch/csky/include/uapi/asm/perf_regs.h
new file mode 100644 (file)
index 0000000..ee323d8
--- /dev/null
@@ -0,0 +1,51 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef _ASM_CSKY_PERF_REGS_H
+#define _ASM_CSKY_PERF_REGS_H
+
+/* Index of struct pt_regs */
+enum perf_event_csky_regs {
+       PERF_REG_CSKY_TLS,
+       PERF_REG_CSKY_LR,
+       PERF_REG_CSKY_PC,
+       PERF_REG_CSKY_SR,
+       PERF_REG_CSKY_SP,
+       PERF_REG_CSKY_ORIG_A0,
+       PERF_REG_CSKY_A0,
+       PERF_REG_CSKY_A1,
+       PERF_REG_CSKY_A2,
+       PERF_REG_CSKY_A3,
+       PERF_REG_CSKY_REGS0,
+       PERF_REG_CSKY_REGS1,
+       PERF_REG_CSKY_REGS2,
+       PERF_REG_CSKY_REGS3,
+       PERF_REG_CSKY_REGS4,
+       PERF_REG_CSKY_REGS5,
+       PERF_REG_CSKY_REGS6,
+       PERF_REG_CSKY_REGS7,
+       PERF_REG_CSKY_REGS8,
+       PERF_REG_CSKY_REGS9,
+#if defined(__CSKYABIV2__)
+       PERF_REG_CSKY_EXREGS0,
+       PERF_REG_CSKY_EXREGS1,
+       PERF_REG_CSKY_EXREGS2,
+       PERF_REG_CSKY_EXREGS3,
+       PERF_REG_CSKY_EXREGS4,
+       PERF_REG_CSKY_EXREGS5,
+       PERF_REG_CSKY_EXREGS6,
+       PERF_REG_CSKY_EXREGS7,
+       PERF_REG_CSKY_EXREGS8,
+       PERF_REG_CSKY_EXREGS9,
+       PERF_REG_CSKY_EXREGS10,
+       PERF_REG_CSKY_EXREGS11,
+       PERF_REG_CSKY_EXREGS12,
+       PERF_REG_CSKY_EXREGS13,
+       PERF_REG_CSKY_EXREGS14,
+       PERF_REG_CSKY_HI,
+       PERF_REG_CSKY_LO,
+       PERF_REG_CSKY_DCSR,
+#endif
+       PERF_REG_CSKY_MAX,
+};
+#endif /* _ASM_CSKY_PERF_REGS_H */
index 4c462f584dd1a904a006083f75e73bcb6282cd8b..1624b04bffb52946a1fa88f13977dc587f1ff376 100644 (file)
@@ -10,6 +10,7 @@ obj-$(CONFIG_FUNCTION_TRACER)         += ftrace.o
 obj-$(CONFIG_STACKTRACE)               += stacktrace.o
 obj-$(CONFIG_CSKY_PMU_V1)              += perf_event.o
 obj-$(CONFIG_PERF_EVENTS)              += perf_callchain.o
+obj-$(CONFIG_HAVE_PERF_REGS)            += perf_regs.o
 
 ifdef CONFIG_FUNCTION_TRACER
 CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE)
diff --git a/arch/csky/kernel/perf_regs.c b/arch/csky/kernel/perf_regs.c
new file mode 100644 (file)
index 0000000..eb32838
--- /dev/null
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd.
+
+#include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/perf_event.h>
+#include <linux/bug.h>
+#include <asm/perf_regs.h>
+#include <asm/ptrace.h>
+
+u64 perf_reg_value(struct pt_regs *regs, int idx)
+{
+       if (WARN_ON_ONCE((u32)idx >= PERF_REG_CSKY_MAX))
+               return 0;
+
+       return (u64)*((u32 *)regs + idx);
+}
+
+#define REG_RESERVED (~((1ULL << PERF_REG_CSKY_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_32;
+}
+
+void perf_get_regs_user(struct perf_regs *regs_user,
+                       struct pt_regs *regs,
+                       struct pt_regs *regs_user_copy)
+{
+       regs_user->regs = task_pt_regs(current);
+       regs_user->abi = perf_reg_abi(current);
+}