2 * ring buffer based initcalls tracer
4 * Copyright (C) 2008 Frederic Weisbecker <fweisbec@gmail.com>
8 #include <linux/init.h>
9 #include <linux/debugfs.h>
10 #include <linux/ftrace.h>
11 #include <linux/kallsyms.h>
14 #include "trace_output.h"
16 static struct trace_array
*boot_trace
;
17 static bool pre_initcalls_finished
;
19 /* Tells the boot tracer that the pre_smp_initcalls are finished.
21 * It doesn't enable sched events tracing however.
22 * You have to call enable_boot_trace to do so.
24 void start_boot_trace(void)
26 pre_initcalls_finished
= true;
29 void enable_boot_trace(void)
31 if (boot_trace
&& pre_initcalls_finished
)
32 tracing_start_sched_switch_record();
35 void disable_boot_trace(void)
37 if (boot_trace
&& pre_initcalls_finished
)
38 tracing_stop_sched_switch_record();
41 static int boot_trace_init(struct trace_array
*tr
)
49 for_each_cpu(cpu
, cpu_possible_mask
)
50 tracing_reset(tr
, cpu
);
52 tracing_sched_switch_assign_trace(tr
);
56 static enum print_line_t
57 initcall_call_print_line(struct trace_iterator
*iter
)
59 struct trace_entry
*entry
= iter
->ent
;
60 struct trace_seq
*s
= &iter
->seq
;
61 struct trace_boot_call
*field
;
62 struct boot_trace_call
*call
;
64 unsigned long nsec_rem
;
67 trace_assign_type(field
, entry
);
68 call
= &field
->boot_call
;
70 nsec_rem
= do_div(ts
, 1000000000);
72 ret
= trace_seq_printf(s
, "[%5ld.%09ld] calling %s @ %i\n",
73 (unsigned long)ts
, nsec_rem
, call
->func
, call
->caller
);
76 return TRACE_TYPE_PARTIAL_LINE
;
78 return TRACE_TYPE_HANDLED
;
81 static enum print_line_t
82 initcall_ret_print_line(struct trace_iterator
*iter
)
84 struct trace_entry
*entry
= iter
->ent
;
85 struct trace_seq
*s
= &iter
->seq
;
86 struct trace_boot_ret
*field
;
87 struct boot_trace_ret
*init_ret
;
89 unsigned long nsec_rem
;
92 trace_assign_type(field
, entry
);
93 init_ret
= &field
->boot_ret
;
95 nsec_rem
= do_div(ts
, 1000000000);
97 ret
= trace_seq_printf(s
, "[%5ld.%09ld] initcall %s "
98 "returned %d after %llu msecs\n",
101 init_ret
->func
, init_ret
->result
, init_ret
->duration
);
104 return TRACE_TYPE_PARTIAL_LINE
;
106 return TRACE_TYPE_HANDLED
;
109 static enum print_line_t
initcall_print_line(struct trace_iterator
*iter
)
111 struct trace_entry
*entry
= iter
->ent
;
113 switch (entry
->type
) {
114 case TRACE_BOOT_CALL
:
115 return initcall_call_print_line(iter
);
117 return initcall_ret_print_line(iter
);
119 return TRACE_TYPE_UNHANDLED
;
123 struct tracer boot_tracer __read_mostly
=
126 .init
= boot_trace_init
,
127 .reset
= tracing_reset_online_cpus
,
128 .print_line
= initcall_print_line
,
131 void trace_boot_call(struct boot_trace_call
*bt
, initcall_t fn
)
133 struct ring_buffer_event
*event
;
134 struct trace_boot_call
*entry
;
135 struct trace_array
*tr
= boot_trace
;
137 if (!tr
|| !pre_initcalls_finished
)
140 /* Get its name now since this function could
141 * disappear because it is in the .init section.
143 sprint_symbol(bt
->func
, (unsigned long)fn
);
146 event
= trace_buffer_lock_reserve(tr
, TRACE_BOOT_CALL
,
147 sizeof(*entry
), 0, 0);
150 entry
= ring_buffer_event_data(event
);
151 entry
->boot_call
= *bt
;
152 trace_buffer_unlock_commit(tr
, event
, 0, 0);
157 void trace_boot_ret(struct boot_trace_ret
*bt
, initcall_t fn
)
159 struct ring_buffer_event
*event
;
160 struct trace_boot_ret
*entry
;
161 struct trace_array
*tr
= boot_trace
;
163 if (!tr
|| !pre_initcalls_finished
)
166 sprint_symbol(bt
->func
, (unsigned long)fn
);
169 event
= trace_buffer_lock_reserve(tr
, TRACE_BOOT_RET
,
170 sizeof(*entry
), 0, 0);
173 entry
= ring_buffer_event_data(event
);
174 entry
->boot_ret
= *bt
;
175 trace_buffer_unlock_commit(tr
, event
, 0, 0);