Tracing/ftrace: Add the initcall tracer
PATCH 1/4 Tracing/ftrace: Add the initcall tracer
Add the initcall tracer. It will be able to trace the initcalls which follow SMP initialization. It is intended to be used with scripts/bootgraph.pl after some small improvements.
Note that it is not active after its init. To avoid tracing (and so crashing) before the whole tracing engine init, you have to explicitly call start_initcall_trace() after do_pre_smp_initcalls() to enable it.
Signed-off-by Frederic Weisbecker <[email protected]>
---
kernel/trace/trace_initcall.c new file +101 -0
@@ -0,0 +1,101 @@ +/* +* ring buffer based initcalls tracer +* +* Copyright (C) 2008 Frederic Weisbecker <[email protected]> +* +*/ + +#include <linux/init.h> +#include <linux/debugfs.h> +#include <linux/ftrace.h> + +#include "trace.h" + +static struct trace_array *initcall_trace; +static int trace_initcall_enabled; + + +/* Should be started after do_pre_smp_initcalls() in init/main.c */ +void start_initcall_trace (void ) +{ + trace_initcall_enabled =1 ; +} + +void stop_initcall_trace (struct trace_array *tr) +{ + trace_initcall_enabled =0 ; +} + +static void initcall_trace_init (struct trace_array *tr) +{ +int cpu; + initcall_trace = tr; + + trace_initcall_enabled =0 ; + +for_each_cpu_mask (cpu, cpu_possible_map) +tracing_reset (tr->data[cpu]); +} + +static void initcall_trace_ctrl_update (struct trace_array *tr) +{ +if (tr->ctrl) +start_initcall_trace (); +else +stop_initcall_trace (tr); +} + +static int initcall_print_line (struct trace_iterator *iter) +{ +int ret =1 ; +struct trace_entry *entry = iter->ent; +struct initcall_trace *it = &entry->field.initcall; +struct trace_seq *s = &iter->seq; + +if (iter->ent->type ==TRACE_INITCALL ) + ret =trace_seq_printf (s,"%pF called from %i " +"returned %d after %Ld msecs\n" , + it->func, it->caller, it->result, + it->duration); +if (ret) +return 1 ; +return 0 ; +} + +struct tracer initcall_tracer__read_mostly = +{ + .name ="initcall" , + .init = initcall_trace_init, + .reset = stop_initcall_trace, + .ctrl_update = initcall_trace_ctrl_update, + .print_line = initcall_print_line, +}; + + +void trace_initcall (struct initcall_trace *it) +{ +struct trace_entry *entry; +struct trace_array_cpu *data; +unsigned long irq_flags; +struct trace_array *tr = initcall_trace; + +if (!trace_initcall_enabled) +return ; + +preempt_disable (); + data = tr->data[smp_processor_id ()]; + +raw_local_irq_save (irq_flags); +__raw_spin_lock (&data->lock); + + entry =tracing_get_trace_entry (tr, data); +tracing_generic_entry_update (entry,0 ); + entry->type =TRACE_INITCALL ; + entry->field.initcall = *it; + +__raw_spin_unlock (&data->lock); +raw_local_irq_restore (irq_flags); +trace_wake_up (); + +preempt_enable (); +}
kernel/trace/trace.h +4 -0
@@ -6,6 +6,7 @@#include <linux/sched.h> #include <linux/clocksource.h> #include <linux/mmiotrace.h> +#include <linux/ftrace.h> enum trace_type { __TRACE_FIRST_TYPE =0 ,
@@ -19,6 +20,7 @@ enum trace_type {TRACE_SPECIAL ,TRACE_MMIO_RW ,TRACE_MMIO_MAP , +TRACE_INITCALL , __TRACE_LAST_TYPE };
@@ -108,6 +110,7 @@ struct trace_field {struct print_entry print;struct mmiotrace_rw mmiorw;struct mmiotrace_map mmiomap; +struct initcall_trace initcall; }; };
@@ -370,5 +373,6 @@ enum trace_iterator_flags { };extern struct tracer nop_trace; +extern struct tracer initcall_tracer;#endif /* _LINUX_KERNEL_TRACE_H */
include/linux/ftrace.h +19 -0
@@ -5,6 +5,8 @@#include <linux/linkage.h> #include <linux/fs.h> +#include <linux/init.h> +#include <linux/types.h> extern int ftrace_enabled; extern int
@@ -209,4 +211,21 @@ ftrace_init_module(unsigned long *start, unsigned long *end) { }#endif +struct initcall_trace { +pid_t caller; +initcall_t func; +int result; +unsigned long long duration; +}; + +#ifdef CONFIG_INITCALL_TRACER +extern void trace_initcall (struct initcall_trace *it); +extern void start_initcall_trace (void ); +#else +static inline void trace_initcall (struct initcall_trace *it) { } +static inline void start_initcall_trace (void ) { } +#endif + + +#endif /* _LINUX_FTRACE_H */