aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuo Ren <ren_guo@c-sky.com>2018-12-09 01:29:59 -0500
committerGuo Ren <ren_guo@c-sky.com>2018-12-31 10:16:46 -0500
commit230c77a5e92a29bf21e98ee35e22b0537f61c55b (patch)
tree78aa6ee2843c765edd87b1a9a824f50558c0888a
parent17a68777bc883c8044c8b2d40aa112ff4e8a4fb1 (diff)
csky: basic ftrace supported
When gcc with -pg, it'll add _mcount stub in every function. We need implement the _mcount in kernel and ftrace depends on stackstrace. To do: call-graph, dynamic ftrace Signed-off-by: Guo Ren <ren_guo@c-sky.com>
-rw-r--r--arch/csky/Kconfig1
-rw-r--r--arch/csky/abiv2/Makefile1
-rw-r--r--arch/csky/abiv2/mcount.S24
-rw-r--r--arch/csky/include/asm/ftrace.h9
-rw-r--r--arch/csky/kernel/Makefile5
-rw-r--r--arch/csky/kernel/ftrace.c24
6 files changed, 64 insertions, 0 deletions
diff --git a/arch/csky/Kconfig b/arch/csky/Kconfig
index 65804d1628a8..0b9a290c0157 100644
--- a/arch/csky/Kconfig
+++ b/arch/csky/Kconfig
@@ -29,6 +29,7 @@ config CSKY
29 select GENERIC_SCHED_CLOCK 29 select GENERIC_SCHED_CLOCK
30 select GENERIC_SMP_IDLE_THREAD 30 select GENERIC_SMP_IDLE_THREAD
31 select HAVE_ARCH_TRACEHOOK 31 select HAVE_ARCH_TRACEHOOK
32 select HAVE_FUNCTION_TRACER
32 select HAVE_GENERIC_DMA_COHERENT 33 select HAVE_GENERIC_DMA_COHERENT
33 select HAVE_KERNEL_GZIP 34 select HAVE_KERNEL_GZIP
34 select HAVE_KERNEL_LZO 35 select HAVE_KERNEL_LZO
diff --git a/arch/csky/abiv2/Makefile b/arch/csky/abiv2/Makefile
index 069ca7276b99..b1d44f6fbcbd 100644
--- a/arch/csky/abiv2/Makefile
+++ b/arch/csky/abiv2/Makefile
@@ -8,3 +8,4 @@ obj-y += strcmp.o
8obj-y += strcpy.o 8obj-y += strcpy.o
9obj-y += strlen.o 9obj-y += strlen.o
10obj-y += strksyms.o 10obj-y += strksyms.o
11obj-$(CONFIG_FUNCTION_TRACER) += mcount.o
diff --git a/arch/csky/abiv2/mcount.S b/arch/csky/abiv2/mcount.S
new file mode 100644
index 000000000000..73377d5ddd18
--- /dev/null
+++ b/arch/csky/abiv2/mcount.S
@@ -0,0 +1,24 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
3
4#include <linux/linkage.h>
5
6ENTRY (_mcount)
7 subi sp, 20
8 stw a0, (sp, 0)
9 stw a1, (sp, 4)
10 stw a2, (sp, 8)
11 stw a3, (sp, 12)
12 stw lr, (sp, 16)
13 mov a1, lr
14 ldw a0, (sp, 20)
15 jsri csky_mcount
16 ldw a0, (sp, 0)
17 ldw a1, (sp, 4)
18 ldw a2, (sp, 8)
19 ldw a3, (sp, 12)
20 ldw t1, (sp, 16)
21 ldw lr, (sp, 20)
22 addi sp, 24
23 jmp t1
24END (_mcount)
diff --git a/arch/csky/include/asm/ftrace.h b/arch/csky/include/asm/ftrace.h
new file mode 100644
index 000000000000..1d22a1787b8b
--- /dev/null
+++ b/arch/csky/include/asm/ftrace.h
@@ -0,0 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
3
4#ifndef __ASM_CSKY_FTRACE_H
5#define __ASM_CSKY_FTRACE_H
6
7extern void _mcount(unsigned long from_pc);
8
9#endif /* __ASM_CSKY_FTRACE_H */
diff --git a/arch/csky/kernel/Makefile b/arch/csky/kernel/Makefile
index ba5ca486f0f6..3c0e2d15d4e0 100644
--- a/arch/csky/kernel/Makefile
+++ b/arch/csky/kernel/Makefile
@@ -6,4 +6,9 @@ obj-y += process.o cpu-probe.o ptrace.o dumpstack.o
6 6
7obj-$(CONFIG_MODULES) += module.o 7obj-$(CONFIG_MODULES) += module.o
8obj-$(CONFIG_SMP) += smp.o 8obj-$(CONFIG_SMP) += smp.o
9obj-$(CONFIG_FUNCTION_TRACER) += ftrace.o
9obj-$(CONFIG_STACKTRACE) += stacktrace.o 10obj-$(CONFIG_STACKTRACE) += stacktrace.o
11
12ifdef CONFIG_FUNCTION_TRACER
13CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE)
14endif
diff --git a/arch/csky/kernel/ftrace.c b/arch/csky/kernel/ftrace.c
new file mode 100644
index 000000000000..ad054f7190f9
--- /dev/null
+++ b/arch/csky/kernel/ftrace.c
@@ -0,0 +1,24 @@
1// SPDX-License-Identifier: GPL-2.0
2// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
3
4#include <linux/ftrace.h>
5#include <linux/uaccess.h>
6
7extern void (*ftrace_trace_function)(unsigned long, unsigned long,
8 struct ftrace_ops*, struct pt_regs*);
9
10
11noinline void __naked ftrace_stub(unsigned long ip, unsigned long parent_ip,
12 struct ftrace_ops *op, struct pt_regs *regs)
13{
14 asm volatile ("\n");
15}
16
17noinline void csky_mcount(unsigned long from_pc, unsigned long self_pc)
18{
19 if (ftrace_trace_function != ftrace_stub)
20 ftrace_trace_function(self_pc, from_pc, NULL, NULL);
21}
22
23/* _mcount is defined in abi's mcount.S */
24EXPORT_SYMBOL(_mcount);