ftrace - add ftrace function_graph support on ARM
Subsystems (2)
PATCH 2/2 ftrace - add ftrace function_graph support on ARM
Sorry - had wrong lists on original message
Add ftrace function-graph tracer support for ARM.
This includes adding code in mcount to check for (and call) a registered function graph trace entry routine, and adding code to support a return trampoline, to catch the function exit.
IRQENTRY_TEXT was added to vmlinux.lds.S (to eliminate a compiler error on kernel/trace/trace_functions_graph.c), although no routines were marked as __irq_entry.
--- arch/arm/Kconfig | 1 arch/arm/kernel/Makefile | 4 +-- arch/arm/kernel/entry-common.S | 36 +++++++++++++++++++++++++++++++- arch/arm/kernel/ftrace_graph.c | 46 +++++++++++++++++++++++++++++++++++++++++ arch/arm/kernel/vmlinux.lds.S | 1 5 files changed, 85 insertions(+), 3 deletions(-)
arch/arm/Kconfig +1 -0
@@ -18,6 +18,7 @@ config ARM select HAVE_KPROBES if (!XIP_KERNEL) select HAVE_KRETPROBES if (HAVE_KPROBES) select HAVE_FUNCTION_TRACER if (!XIP_KERNEL) + select HAVE_FUNCTION_GRAPH_TRACER if (!XIP_KERNEL) select HAVE_GENERIC_DMA_COHERENT select HAVE_KERNEL_GZIP select HAVE_KERNEL_LZO
arch/arm/kernel/Makefile +2 -2
@@ -5,9 +5,8 @@ CPPFLAGS_vmlinux.lds := -DTEXT_OFFSET=$(TEXT_OFFSET) AFLAGS_head.o := -DTEXT_OFFSET=$(TEXT_OFFSET) -ifdef CONFIG_DYNAMIC_FTRACE CFLAGS_REMOVE_ftrace.o = -pg -endif +CFLAGS_REMOVE_ftrace_graph.o = -pg CFLAGS_REMOVE_return_address.o = -pg
@@ -31,6 +30,7 @@ obj-$(CONFIG_SMP) += smp.o obj-$(CONFIG_HAVE_ARM_SCU) += smp_scu.o obj-$(CONFIG_HAVE_ARM_TWD) += smp_twd.o obj-$(CONFIG_DYNAMIC_FTRACE) += ftrace.o +obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace_graph.o obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o obj-$(CONFIG_KPROBES) += kprobes.o kprobes-decode.o obj-$(CONFIG_ATAGS_PROC) += atags.o
arch/arm/kernel/entry-common.S +35 -1
@@ -98,6 +98,11 @@ ENTRY(mcount) mov r0, lr sub r0, r0, #MCOUNT_INSN_SIZE +#ifdef CONFIG_FUNCTION_GRAPH_TRACER + @ FIXTHIS - DYNAMIC_FTRACE does not support function graph tracing + @ when the dynamic work is revived, this should be supported as well +#endif + .globl mcount_call mcount_call: bl ftrace_stub
@@ -144,8 +149,16 @@ ENTRY(mcount) adr r0, ftrace_stub cmp r0, r2 bne trace + +#ifdef CONFIG_FUNCTION_GRAPH_TRACER + ldr r1, =ftrace_graph_return + ldr r2, [r1] + cmp r0, r2 @ if *ftrace_graph_return != ftrace_stub + bne ftrace_graph_caller +#endif /* CONFIG_FUNCTION_GRAPH_TRACER */ + ldr lr, [fp, #-4] @ restore lr - ldmia sp!, {r0-r3, pc} + ldmia sp!, {r0-r3, pc} @ return doing nothing trace: ldr r1, [fp, #-4] @ lr of instrumented routine
@@ -156,6 +169,27 @@ trace: ldr lr, [fp, #-4] @ restore lr ldmia sp!, {r0-r3, pc} +#ifdef CONFIG_FUNCTION_GRAPH_TRACER +ENTRY(ftrace_graph_caller) + sub r0, fp, #4 @ &lr of instrumented routine (&parent) + mov r1, lr @ instrumented routine (func) + sub r1, r1, #MCOUNT_INSN_SIZE + mov r2, fp @ frame pointer + bl prepare_ftrace_return + ldr lr, [fp, #-4] @ restore lr + ldmia sp!, {r0-r3, pc} + + .globl return_to_handler +return_to_handler: + stmdb sp!, {r0-r3} + mov r0, fp @ frame pointer + bl ftrace_return_to_handler + mov lr, r0 @ r0 has real ret addr + ldmia sp!, {r0-r3} + mov pc, lr + +#endif /* CONFIG_FUNCTION_GRAPH_TRACER */ + #endif /* CONFIG_DYNAMIC_FTRACE */ .globl ftrace_stub
arch/arm/kernel/ftrace_graph.c new file +46 -0
46 lines not on this page · raw message
arch/arm/kernel/vmlinux.lds.S +1 -0
@@ -91,6 +91,7 @@ SECTIONS SCHED_TEXT LOCK_TEXT KPROBES_TEXT + IRQENTRY_TEXT #ifdef CONFIG_MMU *(.fixup) #endif
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
PATCH 2/2 ftrace - add ftrace function_graph support on ARM
Quoted 3 lines · Tim Bird
IRQENTRY_TEXTwas added tovmlinux.lds.S(to eliminate a compiler error onkernel/trace/trace_functions_graph.c), although no routines were marked as__irq_entry.
Well, ARM already places the assembly exception text in its own separate section for other reasons. We can't place it in two sections.
What is __irq_entry used for? Just the low level assembly or C functions?
PATCH 2/2 ftrace - add ftrace function_graph support on ARM
Quoted 9 lines · Russell King - ARM Linux
Quoted 3 lines · Tim Bird
IRQENTRY_TEXTwas added tovmlinux.lds.S(to eliminate a compiler error onkernel/trace/trace_functions_graph.c), although no routines were marked as__irq_entry.Well, ARM already places the assembly exception text in its own separate section for other reasons. ?We can't place it in two sections.
What is
__irq_entryused for? ?Just the low level assembly or C functions?
It's used just for the C entry functions for interrupts: asm_do_IRQ() and the IPI and local timer functions.
AFAICS __exception seems to be used only for is_exception_text(). If that's the case, would it be OK to just place those functions in __irq_entry if ftrace is built and have is_exception_text() check that section too?
PATCH 2/2 ftrace - add ftrace function_graph support on ARM
Quoted 12 lines · Rabin Vincent
Quoted 9 lines · Russell King - ARM Linux
Quoted 3 lines · Tim Bird
IRQENTRY_TEXTwas added tovmlinux.lds.S(to eliminate a compiler error onkernel/trace/trace_functions_graph.c), although no routines were marked as__irq_entry.Well, ARM already places the assembly exception text in its own separate section for other reasons. ?We can't place it in two sections.
What is
__irq_entryused for? ?Just the low level assembly or C functions?
Quoted 7 lines
It's used just for the C entry functions for interrupts:
asm_do_IRQ()and the IPI and local timer functions.AFAICS
__exceptionseems to be used only foris_exception_text(). If that's the case, would it be OK to just place those functions in__irq_entryif ftrace is built and haveis_exception_text()check that section too?
No. is_exception_text() is used to detect those functions which have a specific stack layout - which is that there's a pt_regs struct on the stack. Grouping other functions into that violates the expectation.
PATCH 2/2 ftrace - add ftrace function_graph support on ARM
Quoted 4 lines · Russell King - ARM Linux
Quoted 3 lines · Rabin Vincent
It's used just for the C entry functions for interrupts:
asm_do_IRQ()and the IPI and local timer functions.
Quoted 8 lines
Quoted 4 lines
AFAICS
__exceptionseems to be used only foris_exception_text(). If that's the case, would it be OK to just place those functions in__irq_entryif ftrace is built and haveis_exception_text()check that section too?No.
is_exception_text()is used to detect those functions which have a specific stack layout - which is that there's apt_regsstruct on the stack. Grouping other functions into that violates the expectation.
I'm not sure I follow. These functions (asm_do_IRQ(), do_IPI(), and do_local_timer()) will be the only ones in __irq_entry. iow, __irq_entry will contain nothing else except these functions. So we woudn't be grouping other functions; it's just that some of the __exception functions would be moved to the new section so that __exception and __irq_entry combined will contain the functions with the specific stack layout (and only those functions).
PATCH 2/2 ftrace - add ftrace function_graph support on ARM
Quoted 14 lines · Rabin Vincent
Quoted 4 lines · Russell King - ARM Linux
Quoted 3 lines · Rabin Vincent
It's used just for the C entry functions for interrupts:
asm_do_IRQ()and the IPI and local timer functions.Quoted 8 lines
Quoted 4 lines
AFAICS
__exceptionseems to be used only foris_exception_text(). If that's the case, would it be OK to just place those functions in__irq_entryif ftrace is built and haveis_exception_text()check that section too?No.
is_exception_text()is used to detect those functions which have a specific stack layout - which is that there's apt_regsstruct on the stack. Grouping other functions into that violates the expectation.
Quoted 7 lines
I'm not sure I follow. These functions (
asm_do_IRQ(),do_IPI(), anddo_local_timer()) will be the only ones in__irq_entry. iow,__irq_entrywill contain nothing else except these functions. So we woudn't be grouping other functions; it's just that some of the__exceptionfunctions would be moved to the new section so that__exceptionand__irq_entrycombined will contain the functions with the specific stack layout (and only those functions).
And now to go back to the original question I asked: What is __irq_entry used for?
If it's to identify those functions which can't be traced through because of the stack layout, that's true of all __exception marked functions - so we might as well make the linker symbols for irqentry alias the exception text symbols.
I see nothing special of just the three functions you mention that warrant them being handled separately by ftrace.
PATCH 2/2 ftrace - add ftrace function_graph support on ARM
Quoted 2 lines · Russell King - ARM Linux
And now to go back to the original question I asked: What is
__irq_entryused for?
It's used to identify when we're inside the interrupt handling path. Depending upon the tracing options ("funcgraph-irqs"), this can be excluded from the trace output.
Quoted 7 lines
If it's to identify those functions which can't be traced through because of the stack layout, that's true of all
__exceptionmarked functions - so we might as well make the linker symbols for irqentry alias the exception text symbols.I see nothing special of just the three functions you mention that warrant them being handled separately by ftrace.
See above. The funcgraph-irqs option is supposed to only affect the interrupt handling path, not all exception handling.