Skip to content

Commit eed542d

Browse files
AKASHI Takahirorostedt
authored andcommitted
ftrace: Make CALLER_ADDRx macros more generic
Most archs with HAVE_ARCH_CALLER_ADDR have pretty much the same definitions of CALLER_ADDRx(n). Instead of duplicating the code for all the archs, define a ftrace_return_address0() and ftrace_return_address(n) that can be overwritten by the archs if they need to do something different. Instead of 7 macros in every arch, we now only have at most 2 (and actually only 1 as ftrace_return_address0() should be the same for all archs). The CALLER_ADDRx(n) will now be defined in linux/ftrace.h and use the ftrace_return_address*(n?) macros. This removes a lot of the duplicate code. Link: http://lkml.kernel.org/p/1400585464-30333-1-git-send-email-takahiro.akashi@linaro.org Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent d6d211d commit eed542d

File tree

6 files changed

+26
-63
lines changed

6 files changed

+26
-63
lines changed

arch/arm/include/asm/ftrace.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,7 @@ extern inline void *return_address(unsigned int level)
5252

5353
#endif
5454

55-
#define HAVE_ARCH_CALLER_ADDR
56-
57-
#define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
58-
#define CALLER_ADDR1 ((unsigned long)return_address(1))
59-
#define CALLER_ADDR2 ((unsigned long)return_address(2))
60-
#define CALLER_ADDR3 ((unsigned long)return_address(3))
61-
#define CALLER_ADDR4 ((unsigned long)return_address(4))
62-
#define CALLER_ADDR5 ((unsigned long)return_address(5))
63-
#define CALLER_ADDR6 ((unsigned long)return_address(6))
55+
#define ftrace_return_addr(n) return_address(n)
6456

6557
#endif /* ifndef __ASSEMBLY__ */
6658

arch/blackfin/include/asm/ftrace.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,7 @@ extern inline void *return_address(unsigned int level)
6666

6767
#endif /* CONFIG_FRAME_POINTER */
6868

69-
#define HAVE_ARCH_CALLER_ADDR
70-
71-
/* inline function or macro may lead to unexpected result */
72-
#define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
73-
#define CALLER_ADDR1 ((unsigned long)return_address(1))
74-
#define CALLER_ADDR2 ((unsigned long)return_address(2))
75-
#define CALLER_ADDR3 ((unsigned long)return_address(3))
76-
#define CALLER_ADDR4 ((unsigned long)return_address(4))
77-
#define CALLER_ADDR5 ((unsigned long)return_address(5))
78-
#define CALLER_ADDR6 ((unsigned long)return_address(6))
69+
#define ftrace_return_address(n) return_address(n)
7970

8071
#endif /* __ASSEMBLY__ */
8172

arch/parisc/include/asm/ftrace.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,7 @@ extern void return_to_handler(void);
2424

2525
extern unsigned long return_address(unsigned int);
2626

27-
#define HAVE_ARCH_CALLER_ADDR
28-
29-
#define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
30-
#define CALLER_ADDR1 return_address(1)
31-
#define CALLER_ADDR2 return_address(2)
32-
#define CALLER_ADDR3 return_address(3)
33-
#define CALLER_ADDR4 return_address(4)
34-
#define CALLER_ADDR5 return_address(5)
35-
#define CALLER_ADDR6 return_address(6)
27+
#define ftrace_return_address(n) return_address(n)
3628

3729
#endif /* __ASSEMBLY__ */
3830

arch/sh/include/asm/ftrace.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,7 @@ static inline unsigned long ftrace_call_adjust(unsigned long addr)
4040
/* arch/sh/kernel/return_address.c */
4141
extern void *return_address(unsigned int);
4242

43-
#define HAVE_ARCH_CALLER_ADDR
44-
45-
#define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
46-
#define CALLER_ADDR1 ((unsigned long)return_address(1))
47-
#define CALLER_ADDR2 ((unsigned long)return_address(2))
48-
#define CALLER_ADDR3 ((unsigned long)return_address(3))
49-
#define CALLER_ADDR4 ((unsigned long)return_address(4))
50-
#define CALLER_ADDR5 ((unsigned long)return_address(5))
51-
#define CALLER_ADDR6 ((unsigned long)return_address(6))
43+
#define ftrace_return_address(n) return_address(n)
5244

5345
#endif /* __ASSEMBLY__ */
5446

arch/xtensa/include/asm/ftrace.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,18 @@
1212

1313
#include <asm/processor.h>
1414

15-
#define HAVE_ARCH_CALLER_ADDR
1615
#ifndef __ASSEMBLY__
17-
#define CALLER_ADDR0 ({ unsigned long a0, a1; \
16+
#define ftrace_return_address0 ({ unsigned long a0, a1; \
1817
__asm__ __volatile__ ( \
1918
"mov %0, a0\n" \
2019
"mov %1, a1\n" \
2120
: "=r"(a0), "=r"(a1)); \
2221
MAKE_PC_FROM_RA(a0, a1); })
22+
2323
#ifdef CONFIG_FRAME_POINTER
2424
extern unsigned long return_address(unsigned level);
25-
#define CALLER_ADDR1 return_address(1)
26-
#define CALLER_ADDR2 return_address(2)
27-
#define CALLER_ADDR3 return_address(3)
28-
#else /* CONFIG_FRAME_POINTER */
29-
#define CALLER_ADDR1 (0)
30-
#define CALLER_ADDR2 (0)
31-
#define CALLER_ADDR3 (0)
32-
#endif /* CONFIG_FRAME_POINTER */
25+
#define ftrace_return_address(n) return_address(n)
26+
#endif
3327
#endif /* __ASSEMBLY__ */
3428

3529
#ifdef CONFIG_FUNCTION_TRACER

include/linux/ftrace.h

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -616,25 +616,27 @@ static inline void __ftrace_enabled_restore(int enabled)
616616
#endif
617617
}
618618

619-
#ifndef HAVE_ARCH_CALLER_ADDR
619+
/* All archs should have this, but we define it for consistency */
620+
#ifndef ftrace_return_address0
621+
# define ftrace_return_address0 __builtin_return_address(0)
622+
#endif
623+
624+
/* Archs may use other ways for ADDR1 and beyond */
625+
#ifndef ftrace_return_address
620626
# ifdef CONFIG_FRAME_POINTER
621-
# define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
622-
# define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1))
623-
# define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2))
624-
# define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3))
625-
# define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4))
626-
# define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5))
627-
# define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6))
627+
# define ftrace_return_address(n) __builtin_return_address(n)
628628
# else
629-
# define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
630-
# define CALLER_ADDR1 0UL
631-
# define CALLER_ADDR2 0UL
632-
# define CALLER_ADDR3 0UL
633-
# define CALLER_ADDR4 0UL
634-
# define CALLER_ADDR5 0UL
635-
# define CALLER_ADDR6 0UL
629+
# define ftrace_return_address(n) 0UL
636630
# endif
637-
#endif /* ifndef HAVE_ARCH_CALLER_ADDR */
631+
#endif
632+
633+
#define CALLER_ADDR0 ((unsigned long)ftrace_return_address0)
634+
#define CALLER_ADDR1 ((unsigned long)ftrace_return_address(1))
635+
#define CALLER_ADDR2 ((unsigned long)ftrace_return_address(2))
636+
#define CALLER_ADDR3 ((unsigned long)ftrace_return_address(3))
637+
#define CALLER_ADDR4 ((unsigned long)ftrace_return_address(4))
638+
#define CALLER_ADDR5 ((unsigned long)ftrace_return_address(5))
639+
#define CALLER_ADDR6 ((unsigned long)ftrace_return_address(6))
638640

639641
#ifdef CONFIG_IRQSOFF_TRACER
640642
extern void time_hardirqs_on(unsigned long a0, unsigned long a1);

0 commit comments

Comments
 (0)