ftrace: more updates to tip
Steven Rostedt
maintainercover ftrace: more updates to tip
Ingo,
The following patches are in:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
branch: tip/devel
Steven Rostedt (6):
ftrace: move function tracer functions out of trace.c
trace: add gcc printf check to trace_seq_printf
trace: clean up format errors in calls to trace_seq_printf
ftrace: combine stack trace in function call
ftrace: remove static from function tracer functions
trace: set max latency variable to zero on default
----
kernel/trace/kmemtrace.c | 4 +- kernel/trace/trace.c | 89 +---------------------------- kernel/trace/trace.h | 10 --- kernel/trace/trace_functions.c | 115 ++++++++++++++++++++++++++++++++++--- kernel/trace/trace_irqsoff.c | 1 + kernel/trace/trace_mmiotrace.c | 13 ++-- kernel/trace/trace_output.c | 2 +- kernel/trace/trace_output.h | 3 +- kernel/trace/trace_sched_wakeup.c | 1 + 9 files changed, 122 insertions(+), 116 deletions(-)
Steven Rostedt
maintainerPATCH 1/6 ftrace: move function tracer functions out of trace.c
From: Steven Rostedt <[email protected]>
Impact: clean up of trace.c
The function tracer functions were put in trace.c because it needed to share static variables that were in trace.c. Since then, those variables have become global for various reasons. This patch moves the function tracer functions into trace_function.c where they belong.
--- kernel/trace/trace.c | 84 ---------------------------------------- kernel/trace/trace_functions.c | 84 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 83 insertions(+), 85 deletions(-)
kernel/trace/trace.c +0 -84
@@ -1046,65 +1046,6 @@ ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3)local_irq_restore (flags); } -#ifdef CONFIG_FUNCTION_TRACER -static void -function_trace_call_preempt_only(unsigned long ip, unsigned long parent_ip) -{ - struct trace_array *tr = &global_trace; - struct trace_array_cpu *data; - unsigned long flags; - long disabled; - int cpu, resched; - int pc; - - if (unlikely(!ftrace_function_enabled)) - return; - - pc = preempt_count(); - resched = ftrace_preempt_disable(); - local_save_flags(flags); - cpu = raw_smp_processor_id(); - data = tr->data[cpu]; - disabled = atomic_inc_return(&data->disabled); - - if (likely(disabled == 1)) - trace_function(tr, data, ip, parent_ip, flags, pc); - - atomic_dec(&data->disabled); - ftrace_preempt_enable(resched); -} - -static void -function_trace_call(unsigned long ip, unsigned long parent_ip) -{ - struct trace_array *tr = &global_trace; - struct trace_array_cpu *data; - unsigned long flags; - long disabled; - int cpu; - int pc; - - if (unlikely(!ftrace_function_enabled)) - return; - - /* - * Need to use raw, since this must be called before the - * recursive protection is performed. - */ - local_irq_save(flags); - cpu = raw_smp_processor_id(); - data = tr->data[cpu]; - disabled = atomic_inc_return(&data->disabled); - - if (likely(disabled == 1)) { - pc = preempt_count(); - trace_function(tr, data, ip, parent_ip, flags, pc); - } - - atomic_dec(&data->disabled); - local_irq_restore(flags); -} -#ifdef CONFIG_FUNCTION_GRAPH_TRACER int trace_graph_entry (struct ftrace_graph_ent *trace) {
@@ -1162,31 +1103,6 @@ void trace_graph_return(struct ftrace_graph_ret *trace) }#endif /* CONFIG_FUNCTION_GRAPH_TRACER */ -static struct ftrace_ops trace_ops__read_mostly = -{ - .func = function_trace_call, -}; - -void tracing_start_function_trace (void ) -{ - ftrace_function_enabled =0 ; - -if (trace_flags &TRACE_ITER_PREEMPTONLY ) - trace_ops.func = function_trace_call_preempt_only; -else - trace_ops.func = function_trace_call; - -register_ftrace_function (&trace_ops); - ftrace_function_enabled =1 ; -} - -void tracing_stop_function_trace (void ) -{ - ftrace_function_enabled =0 ; -unregister_ftrace_function (&trace_ops); -} -#endif -enum trace_file_type {TRACE_FILE_LAT_FMT =1 ,TRACE_FILE_ANNOTATE =2 ,
kernel/trace/trace_functions.c +83 -1
108 lines not on this page · raw message
Signature · 3 lines
1.5.6.5 --
Re: [PATCH 1/6] ftrace: move function tracer functions out of trace.c
kernel/trace/trace_functions.c static void function_trace_start(struct trace_array *tr) · line 65
Quoted 12 lines · On Thu, 15 Jan 2009 23:53:43 -0500 Steven Rostedt <[email protected]> wrote:
static void
kernel/trace/trace_functions.c +11
-0+function_trace_call_preempt_only(unsigned long ip, unsigned long parent_ip) +{ +struct trace_array *tr = func_trace; +struct trace_array_cpu *data; +unsigned long flags; +long disabled; +int cpu, resched; +int pc; + +if (unlikely (!ftrace_function_enabled)) +return ;
We're optimizing for the tracing-is-enabled case. What's the thinking here?
Re: [PATCH 1/6] ftrace: move function tracer functions out of trace.c
Quoted 17 lines · Andrew Morton
kernel/trace/trace_functions.c static void function_trace_start(struct trace_array *tr) · line 65
Quoted 12 lines · On Thu, 15 Jan 2009 23:53:43 -0500 Steven Rostedt <[email protected]> wrote:
static void
kernel/trace/trace_functions.c +11
-0+function_trace_call_preempt_only(unsigned long ip, unsigned long parent_ip) +{ +struct trace_array *tr = func_trace; +struct trace_array_cpu *data; +unsigned long flags; +long disabled; +int cpu, resched; +int pc; + +if (unlikely (!ftrace_function_enabled)) +return ;We're optimizing for the tracing-is-enabled case. What's the thinking here?
There's two levels here: first the patched in callsites. Those are NOPs in the usual case - there's no overhead for the default 'function tracing is built in but not enabled' case.
There's a second level: a /debug/tracing/tracing_enabled lightweight dynamic flag to flip tracing on/off while the tracer is enabled. _That_ one, if it ever matters to a codepath, is default-enabled.
I.e. the above code sequence is correct.
Thanks,
Ingo
Steven Rostedt
maintainerRe: [PATCH 1/6] ftrace: move function tracer functions out of trace.c
In reply to Andrew MortonQuoted 17 lines · Andrew Morton
kernel/trace/trace_functions.c static void function_trace_start(struct trace_array *tr) · line 65
Quoted 12 lines · On Thu, 15 Jan 2009 23:53:43 -0500 Steven Rostedt <[email protected]> wrote:
static void
kernel/trace/trace_functions.c +11
-0+function_trace_call_preempt_only(unsigned long ip, unsigned long parent_ip) +{ +struct trace_array *tr = func_trace; +struct trace_array_cpu *data; +unsigned long flags; +long disabled; +int cpu, resched; +int pc; + +if (unlikely (!ftrace_function_enabled)) +return ;We're optimizing for the tracing-is-enabled case. What's the thinking here?
This is called only when tracing _is_ enabled :-) Either it was enabled by the dynamic ftrace system, or there's another variable tested before jumping to the functions. This function must be register, and when it is, tracing is expected to run.
The reason for the "ftrace_function_enabled" variable is to prevent tracing to start before the stop_machine finishes. It is local to this one tracer. Without it, you get a lot of garbage on the start up of the tracer.
-- Steve
Steven Rostedt
maintainerPATCH 2/6 trace: add gcc printf check to trace_seq_printf
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
Andrew Morton suggested adding a printf checker to trace_seq_printf since there are a number of users that have improper format arguments.
--- kernel/trace/trace_output.h | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
kernel/trace/trace_output.h +2 -1
@@ -16,7 +16,8 @@ struct trace_event {trace_print_func binary; }; -extern int trace_seq_printf (struct trace_seq *s,const char *fmt, ...); +extern int trace_seq_printf (struct trace_seq *s,const char *fmt, ...) + __attribute__ ((format (printf,2 ,3 )));extern int seq_print_ip_sym (struct trace_seq *s,unsigned long ip,unsigned long sym_flags);
Signature · 3 lines
1.5.6.5 --
Steven Rostedt
maintainerPATCH 3/6 trace: clean up format errors in calls to trace_seq_printf
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
After adding the printf format checking for trace_seq_printf, several warnings now show up. This patch cleans them up.
--- kernel/trace/kmemtrace.c | 4 ++-- kernel/trace/trace_mmiotrace.c | 13 +++++++------ kernel/trace/trace_output.c | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-)
kernel/trace/kmemtrace.c +2 -2
@@ -139,12 +139,12 @@ kmemtrace_print_alloc_compress(struct trace_iterator *iter,return TRACE_TYPE_PARTIAL_LINE ;/* Requested */ - ret =trace_seq_printf (s,"%4d " , entry->bytes_req); + ret =trace_seq_printf (s,"%4ld " , entry->bytes_req);if (!ret)return TRACE_TYPE_PARTIAL_LINE ;/* Allocated */ - ret =trace_seq_printf (s,"%4d " , entry->bytes_alloc); + ret =trace_seq_printf (s,"%4ld " , entry->bytes_alloc);if (!ret)return TRACE_TYPE_PARTIAL_LINE ;
kernel/trace/trace_mmiotrace.c +7 -6
@@ -184,21 +184,22 @@ static enum print_line_t mmio_print_rw(struct trace_iterator *iter)switch (rw->opcode) {case MMIO_READ : ret =trace_seq_printf (s, -"R %d %lu.%06lu %d 0x%llx 0x%lx 0x%lx %d\n" , +"R %d %u.%06lu %d 0x%llx 0x%lx 0x%lx %d\n" , rw->width, secs, usec_rem, rw->map_id, (unsigned long long )rw->phys, rw->value, rw->pc,0 );break ;case MMIO_WRITE : ret =trace_seq_printf (s, -"W %d %lu.%06lu %d 0x%llx 0x%lx 0x%lx %d\n" , +"W %d %u.%06lu %d 0x%llx 0x%lx 0x%lx %d\n" , rw->width, secs, usec_rem, rw->map_id, (unsigned long long )rw->phys, rw->value, rw->pc,0 );break ;case MMIO_UNKNOWN_OP : ret = trace_seq_printf(s, - "UNKNOWN %lu.%06lu %d 0x%llx %02x,%02x,%02x 0x%lx %d\n", + "UNKNOWN %u.%06lu %d 0x%llx %02lx,%02lx," + "%02lx 0x%lx %d\n", secs, usec_rem, rw->map_id, (unsigned long long)rw->phys, (rw->value >> 16) & 0xff, (rw->value >> 8) & 0xff,
@@ -230,14 +231,14 @@ static enum print_line_t mmio_print_map(struct trace_iterator *iter)switch (m->opcode) {case MMIO_PROBE : ret =trace_seq_printf (s, -"MAP %lu.%06lu %d 0x%llx 0x%lx 0x%lx 0x%lx %d\n" , +"MAP %u.%06lu %d 0x%llx 0x%lx 0x%lx 0x%lx %d\n" , secs, usec_rem, m->map_id, (unsigned long long )m->phys, m->virt, m->len,0UL ,0 );break ;case MMIO_UNPROBE : ret =trace_seq_printf (s, -"UNMAP %lu.%06lu %d 0x%lx %d\n" , +"UNMAP %u.%06lu %d 0x%lx %d\n" , secs, usec_rem, m->map_id,0UL ,0 );break ;default :
@@ -261,7 +262,7 @@ static enum print_line_t mmio_print_mark(struct trace_iterator *iter)int ret;/* The trailing newline must be in the message. */ - ret =trace_seq_printf (s,"MARK %lu.%06lu %s" , secs, usec_rem, msg); + ret =trace_seq_printf (s,"MARK %u.%06lu %s" , secs, usec_rem, msg);if (!ret)return TRACE_TYPE_PARTIAL_LINE ;
kernel/trace/trace_output.c +1 -1
@@ -440,7 +440,7 @@ trace_fn_raw(struct trace_seq *s, struct trace_entry *entry, int flags)trace_assign_type (field, entry); -if (!trace_seq_printf (s,"%x %x\n" , +if (!trace_seq_printf (s,"%lx %lx\n" , field->ip, field->parent_ip))return TRACE_TYPE_PARTIAL_LINE ;
Signature · 3 lines
1.5.6.5 --
Steven Rostedt
maintainerPATCH 4/6 ftrace: combine stack trace in function call
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
Impact: less likely to interleave function and stack traces
This patch does replaces the separate stack trace on function with a record function and stack trace together. This will switch between the function only recording to a function and stack recording.
Also some whitespace fix ups as well.
--- kernel/trace/trace_functions.c | 61 +++++++++++++++++++++++---------------- 1 files changed, 36 insertions(+), 25 deletions(-)
kernel/trace/trace_functions.c +36 -25
@@ -133,6 +133,7 @@ function_stack_trace_call(unsigned long ip, unsigned long parent_ip)if (likely (disabled ==1 )) { pc =preempt_count (); +trace_function (tr, data, ip, parent_ip, flags, pc);/* * skip over 5 funcs: * __ftrace_trace_stack,
@@ -154,24 +155,6 @@ static struct ftrace_ops trace_ops __read_mostly = .func = function_trace_call, }; -void tracing_start_function_trace (void ) -{ - ftrace_function_enabled =0 ; - -if (trace_flags &TRACE_ITER_PREEMPTONLY ) - trace_ops.func = function_trace_call_preempt_only; -else - trace_ops.func = function_trace_call; - -register_ftrace_function (&trace_ops); - ftrace_function_enabled =1 ; -} - -void tracing_stop_function_trace (void ) -{ - ftrace_function_enabled =0 ; -unregister_ftrace_function (&trace_ops); -}static struct ftrace_ops trace_stack_ops__read_mostly = { .func = function_stack_trace_call,
@@ -194,6 +177,31 @@ static struct tracer_flags func_flags = { .opts = func_opts }; +void tracing_start_function_trace (void ) +{ + ftrace_function_enabled =0 ; + +if (trace_flags &TRACE_ITER_PREEMPTONLY ) + trace_ops.func = function_trace_call_preempt_only; +else + trace_ops.func = function_trace_call; + +if (func_flags.val &TRACE_FUNC_OPT_STACK ) +register_ftrace_function (&trace_stack_ops); +else +register_ftrace_function (&trace_ops); + + ftrace_function_enabled =1 ; +} + +void tracing_stop_function_trace (void ) +{ + ftrace_function_enabled =0 ; +/* OK if they are not registered */ +unregister_ftrace_function (&trace_stack_ops); +unregister_ftrace_function (&trace_ops); +} +static int func_set_flag (u32 old_flags,u32 bit,int set) {if (bit ==TRACE_FUNC_OPT_STACK ) {
@@ -201,10 +209,13 @@ static int func_set_flag(u32 old_flags, u32 bit, int set)if (!!set == !!(func_flags.val &TRACE_FUNC_OPT_STACK ))return 0 ; -if (set) +if (set) { +unregister_ftrace_function (&trace_ops);register_ftrace_function (&trace_stack_ops); -else + }else {unregister_ftrace_function (&trace_stack_ops); +register_ftrace_function (&trace_ops); + }return 0 ; }
@@ -214,14 +225,14 @@ static int func_set_flag(u32 old_flags, u32 bit, int set)static struct tracer function_trace__read_mostly = { - .name ="function" , - .init = function_trace_init, - .reset = function_trace_reset, - .start = function_trace_start, + .name ="function" , + .init = function_trace_init, + .reset = function_trace_reset, + .start = function_trace_start, .flags = &func_flags, .set_flag = func_set_flag, #ifdef CONFIG_FTRACE_SELFTEST - .selftest = trace_selftest_startup_function, + .selftest = trace_selftest_startup_function, #endif };
Signature · 3 lines
1.5.6.5 --
Steven Rostedt
maintainerPATCH 5/6 ftrace: remove static from function tracer functions
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
Impact: clean up
After reorganizing the functions in trace.c and trace_function.c, they no longer need to be in global context. This patch makes the functions and one variable into static.
--- kernel/trace/trace.c | 3 --- kernel/trace/trace.h | 10 ---------- kernel/trace/trace_functions.c | 10 ++++++++-- 3 files changed, 8 insertions(+), 15 deletions(-)
kernel/trace/trace.c +0 -3
@@ -187,9 +187,6 @@ int tracing_is_enabled(void)return tracer_enabled; } -/* function tracing enabled */ -int ftrace_function_enabled; -/* * trace_buf_size is the size in bytes that is allocated * for a buffer. Note, the number of bytes is always rounded
kernel/trace/trace.h +0 -10
@@ -464,16 +464,6 @@ void __trace_stack(struct trace_array *tr,extern cycle_t ftrace_now (int cpu); -#ifdef CONFIG_FUNCTION_TRACER -void tracing_start_function_trace (void ); -void tracing_stop_function_trace (void ); -#else -# define tracing_start_function_trace () do { } while (0) -# define tracing_stop_function_trace () do { } while (0) -#endif - -extern int ftrace_function_enabled; -#ifdef CONFIG_CONTEXT_SWITCH_TRACER typedef void (*tracer_switch_func_t)(void *private,
kernel/trace/trace_functions.c +8 -2
@@ -16,8 +16,14 @@#include "trace.h" +/* function tracing enabled */ +static int ftrace_function_enabled; +static struct trace_array *func_trace; +static void tracing_start_function_trace (void ); +static void tracing_stop_function_trace (void ); +static void start_function_trace (struct trace_array *tr) { func_trace = tr;
@@ -177,7 +183,7 @@ static struct tracer_flags func_flags = { .opts = func_opts }; -void tracing_start_function_trace (void ) +static void tracing_start_function_trace (void ) { ftrace_function_enabled =0 ;
@@ -194,7 +200,7 @@ void tracing_start_function_trace(void) ftrace_function_enabled =1 ; } -void tracing_stop_function_trace (void ) +static void tracing_stop_function_trace (void ) { ftrace_function_enabled =0 ;/* OK if they are not registered */
Signature · 3 lines
1.5.6.5 --
Steven Rostedt
maintainerPATCH 6/6 trace: set max latency variable to zero on default
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
Impact: trace max latencies on start of latency tracing
This patch sets the max latency to zero whenever one of the irq variant tracers or the wakeup tracer is set to current tracer.
Most developers expect to see output when starting up a latency tracer. But since the max_latency is already set to max, and it takes a latency greater than max_latency to be recorded, there is no trace. This is not the expected behavior and has even confused myself.
--- kernel/trace/trace.c | 2 +- kernel/trace/trace_irqsoff.c | 1 + kernel/trace/trace_sched_wakeup.c | 1 + 3 files changed, 3 insertions(+), 1 deletions(-)
kernel/trace/trace.c +1 -1
@@ -41,7 +41,7 @@#define TRACE_BUFFER_FLAGS (RB_FL_OVERWRITE) -unsigned long __read_mostly tracing_max_latency = (cycle_t )ULONG_MAX ; +unsigned long __read_mostly tracing_max_latency;unsigned long __read_mostly tracing_thresh;/*
kernel/trace/trace_irqsoff.c +1 -0
@@ -380,6 +380,7 @@ static void stop_irqsoff_tracer(struct trace_array *tr)static void __irqsoff_tracer_init (struct trace_array *tr) { + tracing_max_latency =0 ; irqsoff_trace = tr;/* make sure that the tracer is visible */ smp_wmb ();
kernel/trace/trace_sched_wakeup.c +1 -0
@@ -333,6 +333,7 @@ static void stop_wakeup_tracer(struct trace_array *tr)static int wakeup_tracer_init (struct trace_array *tr) { + tracing_max_latency =0 ; wakeup_trace = tr;start_wakeup_tracer (tr);return 0 ;
Signature · 3 lines
1.5.6.5 --
Quoted 18 lines · Steven Rostedt
Ingo,
The following patches are in:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.gitbranch: tip/devel
Steven Rostedt (6):
ftrace: move function tracer functions out oftrace.c
trace: add gcc printf check totrace_seq_printf
trace: clean up format errors in calls totrace_seq_printf
ftrace: combine stack trace in function call
ftrace: remove static from function tracer functions
trace: set max latency variable to zero on default----
Quoted 10 lines
kernel/trace/kmemtrace.c | 4 +- kernel/trace/trace.c | 89 +---------------------------- kernel/trace/trace.h | 10 --- kernel/trace/trace_functions.c | 115 ++++++++++++++++++++++++++++++++++--- kernel/trace/trace_irqsoff.c | 1 + kernel/trace/trace_mmiotrace.c | 13 ++-- kernel/trace/trace_output.c | 2 +- kernel/trace/trace_output.h | 3 +- kernel/trace/trace_sched_wakeup.c | 1 + 9 files changed, 122 insertions(+), 116 deletions(-)
Pulled into tip/tracing/ftrace, thanks Steve!
Ingo