Skip to content

Commit 478ba61

Browse files
jcmvbkbcczankel
authored andcommitted
xtensa: add static function tracer support
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com> Signed-off-by: Chris Zankel <chris@zankel.net>
1 parent 220f535 commit 478ba61

File tree

6 files changed

+78
-2
lines changed

6 files changed

+78
-2
lines changed

arch/xtensa/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ config XTENSA
1919
select CLONE_BACKWARDS
2020
select IRQ_DOMAIN
2121
select HAVE_OPROFILE
22+
select HAVE_FUNCTION_TRACER
2223
help
2324
Xtensa processors are 32-bit RISC machines designed by Tensilica
2425
primarily for embedded systems. These processors are both

arch/xtensa/boot/lib/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ zlib := inffast.c inflate.c inftrees.c
77
lib-y += $(zlib:.c=.o) zmem.o
88

99
ccflags-y := -Ilib/zlib_inflate
10+
ifdef CONFIG_FUNCTION_TRACER
11+
CFLAGS_REMOVE_inflate.o = -pg
12+
CFLAGS_REMOVE_zmem.o = -pg
13+
CFLAGS_REMOVE_inftrees.o = -pg
14+
CFLAGS_REMOVE_inffast.o = -pg
15+
endif
16+
1017

1118
quiet_cmd_copy_zlib = COPY $@
1219
cmd_copy_zlib = cat $< > $@

arch/xtensa/include/asm/ftrace.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <asm/processor.h>
1414

1515
#define HAVE_ARCH_CALLER_ADDR
16+
#ifndef __ASSEMBLY__
1617
#define CALLER_ADDR0 ({ unsigned long a0, a1; \
1718
__asm__ __volatile__ ( \
1819
"mov %0, a0\n" \
@@ -24,10 +25,22 @@ extern unsigned long return_address(unsigned level);
2425
#define CALLER_ADDR1 return_address(1)
2526
#define CALLER_ADDR2 return_address(2)
2627
#define CALLER_ADDR3 return_address(3)
27-
#else
28+
#else /* CONFIG_FRAME_POINTER */
2829
#define CALLER_ADDR1 (0)
2930
#define CALLER_ADDR2 (0)
3031
#define CALLER_ADDR3 (0)
31-
#endif
32+
#endif /* CONFIG_FRAME_POINTER */
33+
#endif /* __ASSEMBLY__ */
34+
35+
#ifdef CONFIG_FUNCTION_TRACER
36+
37+
#define MCOUNT_ADDR ((unsigned long)(_mcount))
38+
#define MCOUNT_INSN_SIZE 3
39+
40+
#ifndef __ASSEMBLY__
41+
extern void _mcount(void);
42+
#define mcount _mcount
43+
#endif /* __ASSEMBLY__ */
44+
#endif /* CONFIG_FUNCTION_TRACER */
3245

3346
#endif /* _XTENSA_FTRACE_H */

arch/xtensa/kernel/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ obj-y := align.o coprocessor.o entry.o irq.o pci-dma.o platform.o process.o \
1111
obj-$(CONFIG_KGDB) += xtensa-stub.o
1212
obj-$(CONFIG_PCI) += pci.o
1313
obj-$(CONFIG_MODULES) += xtensa_ksyms.o module.o
14+
obj-$(CONFIG_FUNCTION_TRACER) += mcount.o
1415

1516
AFLAGS_head.o += -mtext-section-literals
1617

arch/xtensa/kernel/mcount.S

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* arch/xtensa/kernel/mcount.S
3+
*
4+
* Xtensa specific mcount support
5+
*
6+
* This file is subject to the terms and conditions of the GNU General Public
7+
* License. See the file "COPYING" in the main directory of this archive
8+
* for more details.
9+
*
10+
* Copyright (C) 2013 Tensilica Inc.
11+
*/
12+
13+
#include <linux/linkage.h>
14+
#include <asm/ftrace.h>
15+
16+
/*
17+
* Entry condition:
18+
*
19+
* a2: a0 of the caller
20+
*/
21+
22+
ENTRY(_mcount)
23+
24+
entry a1, 16
25+
26+
movi a4, ftrace_trace_function
27+
l32i a4, a4, 0
28+
movi a3, ftrace_stub
29+
bne a3, a4, 1f
30+
retw
31+
32+
1: xor a7, a2, a1
33+
movi a3, 0x3fffffff
34+
and a7, a7, a3
35+
xor a7, a7, a1
36+
37+
xor a6, a0, a1
38+
and a6, a6, a3
39+
xor a6, a6, a1
40+
addi a6, a6, -MCOUNT_INSN_SIZE
41+
callx4 a4
42+
43+
retw
44+
45+
ENDPROC(_mcount)
46+
47+
ENTRY(ftrace_stub)
48+
entry a1, 16
49+
retw
50+
ENDPROC(ftrace_stub)

arch/xtensa/kernel/xtensa_ksyms.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,7 @@ extern long common_exception_return;
124124
extern long _spill_registers;
125125
EXPORT_SYMBOL(common_exception_return);
126126
EXPORT_SYMBOL(_spill_registers);
127+
128+
#ifdef CONFIG_FUNCTION_TRACER
129+
EXPORT_SYMBOL(_mcount);
130+
#endif

0 commit comments

Comments
 (0)