tracing: ftrace features and clean ups
Steven Rostedt
maintainerIngo,
This series is based off of your tip/perf/core and does not contain the changes in the previous git pull request (does not include my repo's tip/perf/core). This is a separate pull.
Please pull the latest tip/perf/core-2 tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
tip/perf/core-2
Jiri Olsa (1):
tracing: Add funcgraph-irq option for function graph tracer.
Steven Rostedt (2):
tracing: Do not trace in irq when funcgraph-irq option is zero
tracing: Remove leftover FTRACE_ENABLE/DISABLE_MCOUNT enums
----
kernel/trace/ftrace.c | 18 +---- kernel/trace/trace_functions_graph.c | 124 +++++++++++++++++++++++++++++++++- 2 files changed, 126 insertions(+), 16 deletions(-)
Steven Rostedt
maintainerPATCH 1/3 tracing: Add funcgraph-irq option for function graph tracer.
From: Jiri Olsa <[email protected]>
It's handy to be able to disable the irq related output and not to have to jump over each irq related code, when you have no interrest in it.
The option is by default enabled, so there's no change to current behaviour. It affects only the final output, so all the irq related data stay in the ring buffer.
LKML-Reference: <[email protected]>
--- kernel/trace/trace_functions_graph.c | 101 +++++++++++++++++++++++++++++++++- 1 files changed, 100 insertions(+), 1 deletions(-)
kernel/trace/trace_functions_graph.c +100 -1
@@ -18,6 +18,7 @@struct fgraph_cpu_data {pid_t last_pid;int depth; +int depth_irq;int ignore;unsigned long enter_funcs[FTRACE_RETFUNC_DEPTH ]; };
@@ -41,6 +42,7 @@ struct fgraph_data {#define TRACE_GRAPH_PRINT_PROC 0x8#define TRACE_GRAPH_PRINT_DURATION 0x10#define TRACE_GRAPH_PRINT_ABS_TIME 0x20 +#define TRACE_GRAPH_PRINT_IRQS 0x40static struct tracer_opt trace_opts[] = {/* Display overruns? (for self-debug purpose) */
@@ -55,13 +57,15 @@ static struct tracer_opt trace_opts[] = { { TRACER_OPT(funcgraph-duration, TRACE_GRAPH_PRINT_DURATION) },/* Display absolute time of an entry */ { TRACER_OPT(funcgraph-abstime, TRACE_GRAPH_PRINT_ABS_TIME) }, +/* Display interrupts */ + { TRACER_OPT(funcgraph-irqs, TRACE_GRAPH_PRINT_IRQS) }, { } /* Empty entry */ };static struct tracer_flags tracer_flags = {/* Don't display overruns and proc by default */ .val =TRACE_GRAPH_PRINT_CPU |TRACE_GRAPH_PRINT_OVERHEAD | -TRACE_GRAPH_PRINT_DURATION , +TRACE_GRAPH_PRINT_DURATION |TRACE_GRAPH_PRINT_IRQS , .opts = trace_opts };
@@ -855,6 +859,92 @@ print_graph_prologue(struct trace_iterator *iter, struct trace_seq *s,return 0 ; } +/* +* Entry check for irq code +* +* returns 1 if +* - we are inside irq code +* - we just extered irq code +* +* retunns 0 if +* - funcgraph-interrupts option is set +* - we are not inside irq code +*/ +static int +check_irq_entry (struct trace_iterator *iter,u32 flags, +unsigned long addr,int depth) +{ +int cpu = iter->cpu; +struct fgraph_data *data = iter->private; +int *depth_irq = &(per_cpu_ptr (data->cpu_data, cpu)->depth_irq); + +if (flags &TRACE_GRAPH_PRINT_IRQS ) +return 0 ; + +/* +* We are inside the irq code +*/ +if (*depth_irq >=0 ) +return 1 ; + +if ((addr < (unsigned long )__irqentry_text_start) || + (addr >= (unsigned long )__irqentry_text_end)) +return 0 ; + +/* +* We are entering irq code. +*/ + *depth_irq = depth; +return 1 ; +} + +/* +* Return check for irq code +* +* returns 1 if +* - we are inside irq code +* - we just left irq code +* +* returns 0 if +* - funcgraph-interrupts option is set +* - we are not inside irq code +*/ +static int +check_irq_return (struct trace_iterator *iter,u32 flags,int depth) +{ +int cpu = iter->cpu; +struct fgraph_data *data = iter->private; +int *depth_irq = &(per_cpu_ptr (data->cpu_data, cpu)->depth_irq); + +if (flags &TRACE_GRAPH_PRINT_IRQS ) +return 0 ; + +/* +* We are not inside the irq code. +*/ +if (*depth_irq ==-1 ) +return 0 ; + +/* +* We are inside the irq code, and this is returning entry. +* Let's not trace it and clear the entry depth, since +* we are out of irq code. +* +* This condition ensures that we 'leave the irq code' once +* we are out of the entry depth. Thus protecting us from +* the RETURN entry loss. +*/ +if (*depth_irq >= depth) { + *depth_irq =-1 ; +return 1 ; + } + +/* +* We are inside the irq code, and this is not the entry. +*/ +return 1 ; +} +static enum print_line_t print_graph_entry (struct ftrace_graph_ent_entry *field,struct trace_seq *s,struct trace_iterator *iter,u32 flags)
@@ -865,6 +955,9 @@ print_graph_entry(struct ftrace_graph_ent_entry *field, struct trace_seq *s,static enum print_line_t ret;int cpu = iter->cpu; +if (check_irq_entry (iter, flags, call->func, call->depth)) +return TRACE_TYPE_HANDLED ; +if (print_graph_prologue (iter, s,TRACE_GRAPH_ENT , call->func, flags))return TRACE_TYPE_PARTIAL_LINE ;
@@ -902,6 +995,9 @@ print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s,int ret;int i; +if (check_irq_return (iter, flags, trace->depth)) +return TRACE_TYPE_HANDLED ; +if (data) {struct fgraph_cpu_data *cpu_data;int cpu = iter->cpu;
@@ -1210,9 +1306,12 @@ void graph_trace_open(struct trace_iterator *iter)pid_t *pid = &(per_cpu_ptr (data->cpu_data, cpu)->last_pid);int *depth = &(per_cpu_ptr (data->cpu_data, cpu)->depth);int *ignore = &(per_cpu_ptr (data->cpu_data, cpu)->ignore); +int *depth_irq = &(per_cpu_ptr (data->cpu_data, cpu)->depth_irq); + *pid =-1 ; *depth =0 ; *ignore =0 ; + *depth_irq =-1 ; } iter->private = data;
Signature · 1 line
1.7.1
Steven Rostedt
maintainerPATCH 2/3 tracing: Do not trace in irq when funcgraph-irq option is zero
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
When the function graph tracer funcgraph-irq option is zero, disable tracing in IRQs. This makes the option have two effects.
1) When reading the trace file, do not display the functions that happen in interrupt context (when detected)
2) [*new*] When recording a trace, skip those that are detected to be in interrupt by the 'in_irq()' function
Note, in_irq() is updated at irq_enter() and irq_exit(). There are still functions that are recorded by the function graph tracer that is in interrupt context but outside the irq_enter/exit() routines.
--- kernel/trace/trace_functions_graph.c | 23 ++++++++++++++++++++++- 1 files changed, 22 insertions(+), 1 deletions(-)
kernel/trace/trace_functions_graph.c +22 -1
@@ -15,6 +15,9 @@#include "trace.h" #include "trace_output.h" +/* When set, irq functions will be ignored */ +static int ftrace_graph_skip_irqs; +struct fgraph_cpu_data {pid_t last_pid;int depth;
@@ -208,6 +211,14 @@ int __trace_graph_entry(struct trace_array *tr,return 1 ; } +static inline int ftrace_graph_ignore_irqs (void ) +{ +if (!ftrace_graph_skip_irqs) +return 0 ; + +return in_irq (); +} +int trace_graph_entry (struct ftrace_graph_ent *trace) {struct trace_array *tr = graph_array;
@@ -222,7 +233,8 @@ int trace_graph_entry(struct ftrace_graph_ent *trace)return 0 ;/* trace it when it is-nested-in or is a function enabled. */ -if (!(trace->depth ||ftrace_graph_addr (trace->func))) +if (!(trace->depth ||ftrace_graph_addr (trace->func)) || +ftrace_graph_ignore_irqs ())return 0 ;local_irq_save (flags);
@@ -1334,6 +1346,14 @@ void graph_trace_close(struct trace_iterator *iter) } } +static int func_graph_set_flag (u32 old_flags,u32 bit,int set) +{ +if (bit ==TRACE_GRAPH_PRINT_IRQS ) + ftrace_graph_skip_irqs = !set; + +return 0 ; +} +static struct trace_event_functions graph_functions = { .trace = print_graph_function_event, };
@@ -1360,6 +1380,7 @@ static struct tracer graph_trace __read_mostly = { .print_line = print_graph_function, .print_header = print_graph_headers, .flags = &tracer_flags, + .set_flag = func_graph_set_flag,#ifdef CONFIG_FTRACE_SELFTEST .selftest = trace_selftest_startup_function_graph,#endif
Signature · 1 line
1.7.1
Steven Rostedt
maintainerPATCH 3/3 tracing: Remove leftover FTRACE_ENABLE/DISABLE_MCOUNT enums
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
The enums for FTRACE_ENABLE_MCOUNT and FTRACE_DISABLE_MCOUNT were used as commands to ftrace_run_update_code(). But these commands were used by the old nasty ftrace daemon that has long been slain.
This is a clean up patch to remove the references to these enums and simplify the code a little.
--- kernel/trace/ftrace.c | 18 ++++-------------- 1 files changed, 4 insertions(+), 14 deletions(-)
kernel/trace/ftrace.c +4 -14
@@ -884,10 +884,8 @@ enum {FTRACE_ENABLE_CALLS = (1 <<0 ),FTRACE_DISABLE_CALLS = (1 <<1 ),FTRACE_UPDATE_TRACE_FUNC = (1 <<2 ), -FTRACE_ENABLE_MCOUNT = (1 <<3 ), -FTRACE_DISABLE_MCOUNT = (1 <<4 ), -FTRACE_START_FUNC_RET = (1 <<5 ), - FTRACE_STOP_FUNC_RET = (1 << 6), +FTRACE_START_FUNC_RET = (1 <<3 ), + FTRACE_STOP_FUNC_RET = (1 << 4), };static int ftrace_filtered;
@@ -1226,8 +1224,6 @@ static void ftrace_shutdown(int command)static void ftrace_startup_sysctl (void ) { -int command =FTRACE_ENABLE_MCOUNT ; -if (unlikely (ftrace_disabled))return ;
@@ -1235,23 +1231,17 @@ static void ftrace_startup_sysctl(void) saved_ftrace_func =NULL ;/* ftrace_start_up is true if we want ftrace running */ if (ftrace_start_up) - command |=FTRACE_ENABLE_CALLS ; - -ftrace_run_update_code (command); +ftrace_run_update_code (FTRACE_ENABLE_CALLS ); }static void ftrace_shutdown_sysctl (void ) { -int command =FTRACE_DISABLE_MCOUNT ; -if (unlikely (ftrace_disabled))return ;/* ftrace_start_up is true if ftrace is running */ if (ftrace_start_up) - command |=FTRACE_DISABLE_CALLS ; - -ftrace_run_update_code (command); +ftrace_run_update_code (FTRACE_DISABLE_CALLS ); }static cycle_t ftrace_update_time;
Signature · 1 line
1.7.1
Re: [PATCH 3/3] tracing: Remove leftover FTRACE_ENABLE/DISABLE_MCOUNT enums
kernel/trace/ftrace.c enum { · line 888
Quoted 10 lines · Steven Rostedt
From: Steven Rostedt <[email protected]>
The enums for
FTRACE_ENABLE_MCOUNTandFTRACE_DISABLE_MCOUNTwere used as commands toftrace_run_update_code(). But these commands were used by the old nasty ftrace daemon that has long been slain.kernel/trace/ftrace.c +2
-2-FTRACE_START_FUNC_RET = (1 <<5 ), - FTRACE_STOP_FUNC_RET = (1 << 6), +FTRACE_START_FUNC_RET = (1 <<3 ), + FTRACE_STOP_FUNC_RET = (1 << 4),
This renumber isn't visible to user space, correct? (Asking because the enable/ disable apparently *were* visible to the since-slain userspace daemon)
Steven Rostedt
maintainerRe: [PATCH 3/3] tracing: Remove leftover FTRACE_ENABLE/DISABLE_MCOUNT enums
Quoted 7 lines · On Wed, 2010-09-15 at 12:10 -0400, [email protected] wrote:
Quoted 5 lines · Steven Rostedt
From: Steven Rostedt <[email protected]>
The enums for
FTRACE_ENABLE_MCOUNTandFTRACE_DISABLE_MCOUNTwere used as commands toftrace_run_update_code(). But these commands were used by the old nasty ftrace daemon that has long been slain.
Quoted 7 lines
kernel/trace/ftrace.c enum { · line 888
Quoted 4 lines
kernel/trace/ftrace.c +2
-2-FTRACE_START_FUNC_RET = (1 <<5 ), - FTRACE_STOP_FUNC_RET = (1 << 6), +FTRACE_START_FUNC_RET = (1 <<3 ), + FTRACE_STOP_FUNC_RET = (1 << 4),This renumber isn't visible to user space, correct? (Asking because the enable/ disable apparently *were* visible to the since-slain userspace daemon)
Nope, it's not visible to userspace, and the slain-daemon was a kernel thread, not userspace.
-- Steve
Quoted 15 lines · Steven Rostedt
Ingo,
This series is based off of your tip/perf/core and does not contain the changes in the previous git pull request (does not include my repo's tip/perf/core). This is a separate pull.
Please pull the latest tip/perf/core-2 tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
tip/perf/core-2Jiri Olsa (1):
tracing: Add funcgraph-irq option for function graph tracer.
Quoted 8 lines
Steven Rostedt (2):
tracing: Do not trace in irq when funcgraph-irq option is zero
tracing: Remove leftover FTRACE_ENABLE/DISABLE_MCOUNT enums----
kernel/trace/ftrace.c | 18 +---- kernel/trace/trace_functions_graph.c | 124 +++++++++++++++++++++++++++++++++- 2 files changed, 126 insertions(+), 16 deletions(-)
Pulled, thanks a lot Steve!
Ingo