Skip to content

Commit

Permalink
tracing/function-return-tracer: change the name into function-graph-t…
Browse files Browse the repository at this point in the history
…racer

Impact: cleanup

This patch changes the name of the "return function tracer" into
function-graph-tracer which is a more suitable name for a tracing
which makes one able to retrieve the ordered call stack during
the code flow.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Frederic Weisbecker authored and Ingo Molnar committed Nov 26, 2008
1 parent 509dcee commit fb52607
Show file tree
Hide file tree
Showing 17 changed files with 173 additions and 72 deletions.
2 changes: 1 addition & 1 deletion arch/x86/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ config X86
select HAVE_FTRACE_MCOUNT_RECORD
select HAVE_DYNAMIC_FTRACE
select HAVE_FUNCTION_TRACER
select HAVE_FUNCTION_RET_TRACER if X86_32
select HAVE_FUNCTION_GRAPH_TRACER if X86_32
select HAVE_FUNCTION_TRACE_MCOUNT_TEST
select HAVE_KVM if ((X86_32 && !X86_VOYAGER && !X86_VISWS && !X86_NUMAQ) || X86_64)
select HAVE_ARCH_KGDB if !X86_VOYAGER
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/include/asm/ftrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct dyn_arch_ftrace {
#endif /* __ASSEMBLY__ */
#endif /* CONFIG_FUNCTION_TRACER */

#ifdef CONFIG_FUNCTION_RET_TRACER
#ifdef CONFIG_FUNCTION_GRAPH_TRACER

#ifndef __ASSEMBLY__

Expand All @@ -51,6 +51,6 @@ struct ftrace_ret_stack {
extern void return_to_handler(void);

#endif /* __ASSEMBLY__ */
#endif /* CONFIG_FUNCTION_RET_TRACER */
#endif /* CONFIG_FUNCTION_GRAPH_TRACER */

#endif /* _ASM_X86_FTRACE_H */
4 changes: 2 additions & 2 deletions arch/x86/kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ CFLAGS_REMOVE_paravirt-spinlocks.o = -pg
CFLAGS_REMOVE_ftrace.o = -pg
endif

ifdef CONFIG_FUNCTION_RET_TRACER
ifdef CONFIG_FUNCTION_GRAPH_TRACER
# Don't trace __switch_to() but let it for function tracer
CFLAGS_REMOVE_process_32.o = -pg
endif
Expand Down Expand Up @@ -70,7 +70,7 @@ obj-$(CONFIG_X86_LOCAL_APIC) += apic.o nmi.o
obj-$(CONFIG_X86_IO_APIC) += io_apic.o
obj-$(CONFIG_X86_REBOOTFIXUPS) += reboot_fixups_32.o
obj-$(CONFIG_DYNAMIC_FTRACE) += ftrace.o
obj-$(CONFIG_FUNCTION_RET_TRACER) += ftrace.o
obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o
obj-$(CONFIG_KEXEC) += machine_kexec_$(BITS).o
obj-$(CONFIG_KEXEC) += relocate_kernel_$(BITS).o crash.o
obj-$(CONFIG_CRASH_DUMP) += crash_dump_$(BITS).o
Expand Down
12 changes: 6 additions & 6 deletions arch/x86/kernel/entry_32.S
Original file line number Diff line number Diff line change
Expand Up @@ -1188,9 +1188,9 @@ ENTRY(mcount)

cmpl $ftrace_stub, ftrace_trace_function
jnz trace
#ifdef CONFIG_FUNCTION_RET_TRACER
cmpl $ftrace_stub, ftrace_function_return
jnz ftrace_return_caller
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
cmpl $ftrace_stub, ftrace_graph_function
jnz ftrace_graph_caller
#endif
.globl ftrace_stub
ftrace_stub:
Expand All @@ -1215,8 +1215,8 @@ END(mcount)
#endif /* CONFIG_DYNAMIC_FTRACE */
#endif /* CONFIG_FUNCTION_TRACER */

#ifdef CONFIG_FUNCTION_RET_TRACER
ENTRY(ftrace_return_caller)
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
ENTRY(ftrace_graph_caller)
cmpl $0, function_trace_stop
jne ftrace_stub

Expand All @@ -1230,7 +1230,7 @@ ENTRY(ftrace_return_caller)
popl %ecx
popl %eax
ret
END(ftrace_return_caller)
END(ftrace_graph_caller)

.globl return_to_handler
return_to_handler:
Expand Down
12 changes: 6 additions & 6 deletions arch/x86/kernel/ftrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ int __init ftrace_dyn_arch_init(void *data)
}
#endif

#ifdef CONFIG_FUNCTION_RET_TRACER
#ifdef CONFIG_FUNCTION_GRAPH_TRACER

#ifndef CONFIG_DYNAMIC_FTRACE

Expand Down Expand Up @@ -389,11 +389,11 @@ static void pop_return_trace(unsigned long *ret, unsigned long long *time,
*/
unsigned long ftrace_return_to_handler(void)
{
struct ftrace_retfunc trace;
struct ftrace_graph_ret trace;
pop_return_trace(&trace.ret, &trace.calltime, &trace.func,
&trace.overrun);
trace.rettime = cpu_clock(raw_smp_processor_id());
ftrace_function_return(&trace);
ftrace_graph_function(&trace);

return trace.ret;
}
Expand Down Expand Up @@ -440,12 +440,12 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr)
);

if (WARN_ON(faulted)) {
unregister_ftrace_return();
unregister_ftrace_graph();
return;
}

if (WARN_ON(!__kernel_text_address(old))) {
unregister_ftrace_return();
unregister_ftrace_graph();
*parent = old;
return;
}
Expand All @@ -456,4 +456,4 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr)
*parent = old;
}

#endif /* CONFIG_FUNCTION_RET_TRACER */
#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
24 changes: 12 additions & 12 deletions include/linux/ftrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ extern int ftrace_update_ftrace_func(ftrace_func_t func);
extern void ftrace_caller(void);
extern void ftrace_call(void);
extern void mcount_call(void);
#ifdef CONFIG_FUNCTION_RET_TRACER
extern void ftrace_return_caller(void);
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
extern void ftrace_graph_caller(void);
#endif

/**
Expand Down Expand Up @@ -315,7 +315,7 @@ ftrace_init_module(struct module *mod,
/*
* Structure that defines a return function trace.
*/
struct ftrace_retfunc {
struct ftrace_graph_ret {
unsigned long ret; /* Return address */
unsigned long func; /* Current function */
unsigned long long calltime;
Expand All @@ -324,22 +324,22 @@ struct ftrace_retfunc {
unsigned long overrun;
};

#ifdef CONFIG_FUNCTION_RET_TRACER
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
#define FTRACE_RETFUNC_DEPTH 50
#define FTRACE_RETSTACK_ALLOC_SIZE 32
/* Type of a callback handler of tracing return function */
typedef void (*trace_function_return_t)(struct ftrace_retfunc *);
typedef void (*trace_function_graph_t)(struct ftrace_graph_ret *);

extern int register_ftrace_return(trace_function_return_t func);
extern int register_ftrace_graph(trace_function_graph_t func);
/* The current handler in use */
extern trace_function_return_t ftrace_function_return;
extern void unregister_ftrace_return(void);
extern trace_function_graph_t ftrace_graph_function;
extern void unregister_ftrace_graph(void);

extern void ftrace_retfunc_init_task(struct task_struct *t);
extern void ftrace_retfunc_exit_task(struct task_struct *t);
extern void ftrace_graph_init_task(struct task_struct *t);
extern void ftrace_graph_exit_task(struct task_struct *t);
#else
static inline void ftrace_retfunc_init_task(struct task_struct *t) { }
static inline void ftrace_retfunc_exit_task(struct task_struct *t) { }
static inline void ftrace_graph_init_task(struct task_struct *t) { }
static inline void ftrace_graph_exit_task(struct task_struct *t) { }
#endif

#endif /* _LINUX_FTRACE_H */
2 changes: 1 addition & 1 deletion include/linux/ftrace_irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define _LINUX_FTRACE_IRQ_H


#if defined(CONFIG_DYNAMIC_FTRACE) || defined(CONFIG_FUNCTION_RET_TRACER)
#if defined(CONFIG_DYNAMIC_FTRACE) || defined(CONFIG_FUNCTION_GRAPH_TRACER)
extern void ftrace_nmi_enter(void);
extern void ftrace_nmi_exit(void);
#else
Expand Down
2 changes: 1 addition & 1 deletion include/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,7 @@ struct task_struct {
unsigned long default_timer_slack_ns;

struct list_head *scm_work_list;
#ifdef CONFIG_FUNCTION_RET_TRACER
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
/* Index of current stored adress in ret_stack */
int curr_ret_stack;
/* Stack of return addresses for return function tracing */
Expand Down
2 changes: 1 addition & 1 deletion kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ CFLAGS_REMOVE_cgroup-debug.o = -pg
CFLAGS_REMOVE_sched_clock.o = -pg
CFLAGS_REMOVE_sched.o = -pg
endif
ifdef CONFIG_FUNCTION_RET_TRACER
ifdef CONFIG_FUNCTION_GRAPH_TRACER
CFLAGS_REMOVE_extable.o = -pg # For __kernel_text_address()
CFLAGS_REMOVE_module.o = -pg # For __module_text_address()
endif
Expand Down
4 changes: 2 additions & 2 deletions kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void free_task(struct task_struct *tsk)
prop_local_destroy_single(&tsk->dirties);
free_thread_info(tsk->stack);
rt_mutex_debug_task_free(tsk);
ftrace_retfunc_exit_task(tsk);
ftrace_graph_exit_task(tsk);
free_task_struct(tsk);
}
EXPORT_SYMBOL(free_task);
Expand Down Expand Up @@ -1271,7 +1271,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
total_forks++;
spin_unlock(&current->sighand->siglock);
write_unlock_irq(&tasklist_lock);
ftrace_retfunc_init_task(p);
ftrace_graph_init_task(p);
proc_fork_connector(p);
cgroup_post_fork(p);
return p;
Expand Down
2 changes: 1 addition & 1 deletion kernel/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -5901,7 +5901,7 @@ void __cpuinit init_idle(struct task_struct *idle, int cpu)
* The idle tasks have their own, simple scheduling class:
*/
idle->sched_class = &idle_sched_class;
ftrace_retfunc_init_task(idle);
ftrace_graph_init_task(idle);
}

/*
Expand Down
19 changes: 11 additions & 8 deletions kernel/trace/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ config NOP_TRACER
config HAVE_FUNCTION_TRACER
bool

config HAVE_FUNCTION_RET_TRACER
config HAVE_FUNCTION_GRAPH_TRACER
bool

config HAVE_FUNCTION_TRACE_MCOUNT_TEST
Expand Down Expand Up @@ -63,15 +63,18 @@ config FUNCTION_TRACER
(the bootup default), then the overhead of the instructions is very
small and not measurable even in micro-benchmarks.

config FUNCTION_RET_TRACER
bool "Kernel Function return Tracer"
depends on HAVE_FUNCTION_RET_TRACER
config FUNCTION_GRAPH_TRACER
bool "Kernel Function Graph Tracer"
depends on HAVE_FUNCTION_GRAPH_TRACER
depends on FUNCTION_TRACER
help
Enable the kernel to trace a function at its return.
It's first purpose is to trace the duration of functions.
This is done by setting the current return address on the thread
info structure of the current task.
Enable the kernel to trace a function at both its return
and its entry.
It's first purpose is to trace the duration of functions and
draw a call graph for each thread with some informations like
the return value.
This is done by setting the current return address on the current
task structure into a stack of calls.

config IRQSOFF_TRACER
bool "Interrupts-off Latency Tracer"
Expand Down
2 changes: 1 addition & 1 deletion kernel/trace/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ obj-$(CONFIG_NOP_TRACER) += trace_nop.o
obj-$(CONFIG_STACK_TRACER) += trace_stack.o
obj-$(CONFIG_MMIOTRACE) += trace_mmiotrace.o
obj-$(CONFIG_BOOT_TRACER) += trace_boot.o
obj-$(CONFIG_FUNCTION_RET_TRACER) += trace_functions_return.o
obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += trace_functions_graph.o
obj-$(CONFIG_TRACE_BRANCH_PROFILING) += trace_branch.o
obj-$(CONFIG_BTS_TRACER) += trace_bts.o

Expand Down
26 changes: 13 additions & 13 deletions kernel/trace/ftrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,11 @@ __ftrace_replace_code(struct dyn_ftrace *rec, int enable)
unsigned long ip, fl;
unsigned long ftrace_addr;

#ifdef CONFIG_FUNCTION_RET_TRACER
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
if (ftrace_tracing_type == FTRACE_TYPE_ENTER)
ftrace_addr = (unsigned long)ftrace_caller;
else
ftrace_addr = (unsigned long)ftrace_return_caller;
ftrace_addr = (unsigned long)ftrace_graph_caller;
#else
ftrace_addr = (unsigned long)ftrace_caller;
#endif
Expand Down Expand Up @@ -1496,13 +1496,13 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
return ret;
}

#ifdef CONFIG_FUNCTION_RET_TRACER
#ifdef CONFIG_FUNCTION_GRAPH_TRACER

static atomic_t ftrace_retfunc_active;

/* The callback that hooks the return of a function */
trace_function_return_t ftrace_function_return =
(trace_function_return_t)ftrace_stub;
trace_function_graph_t ftrace_graph_function =
(trace_function_graph_t)ftrace_stub;


/* Try to assign a return stack array on FTRACE_RETSTACK_ALLOC_SIZE tasks. */
Expand Down Expand Up @@ -1549,7 +1549,7 @@ static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list)
}

/* Allocate a return stack for each task */
static int start_return_tracing(void)
static int start_graph_tracing(void)
{
struct ftrace_ret_stack **ret_stack_list;
int ret;
Expand All @@ -1569,7 +1569,7 @@ static int start_return_tracing(void)
return ret;
}

int register_ftrace_return(trace_function_return_t func)
int register_ftrace_graph(trace_function_graph_t func)
{
int ret = 0;

Expand All @@ -1584,26 +1584,26 @@ int register_ftrace_return(trace_function_return_t func)
goto out;
}
atomic_inc(&ftrace_retfunc_active);
ret = start_return_tracing();
ret = start_graph_tracing();
if (ret) {
atomic_dec(&ftrace_retfunc_active);
goto out;
}
ftrace_tracing_type = FTRACE_TYPE_RETURN;
ftrace_function_return = func;
ftrace_graph_function = func;
ftrace_startup();

out:
mutex_unlock(&ftrace_sysctl_lock);
return ret;
}

void unregister_ftrace_return(void)
void unregister_ftrace_graph(void)
{
mutex_lock(&ftrace_sysctl_lock);

atomic_dec(&ftrace_retfunc_active);
ftrace_function_return = (trace_function_return_t)ftrace_stub;
ftrace_graph_function = (trace_function_graph_t)ftrace_stub;
ftrace_shutdown();
/* Restore normal tracing type */
ftrace_tracing_type = FTRACE_TYPE_ENTER;
Expand All @@ -1612,7 +1612,7 @@ void unregister_ftrace_return(void)
}

/* Allocate a return stack for newly created task */
void ftrace_retfunc_init_task(struct task_struct *t)
void ftrace_graph_init_task(struct task_struct *t)
{
if (atomic_read(&ftrace_retfunc_active)) {
t->ret_stack = kmalloc(FTRACE_RETFUNC_DEPTH
Expand All @@ -1626,7 +1626,7 @@ void ftrace_retfunc_init_task(struct task_struct *t)
t->ret_stack = NULL;
}

void ftrace_retfunc_exit_task(struct task_struct *t)
void ftrace_graph_exit_task(struct task_struct *t)
{
struct ftrace_ret_stack *ret_stack = t->ret_stack;

Expand Down
Loading

0 comments on commit fb52607

Please sign in to comment.