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 (pre_initcalls_finished)
32 tracing_start_sched_switch_record();
35 void disable_boot_trace(void)
37 if (pre_initcalls_finished)
38 tracing_stop_sched_switch_record();
41 static int boot_trace_init(struct trace_array *tr)
46 for_each_cpu(cpu, cpu_possible_mask)
47 tracing_reset(tr, cpu);
49 tracing_sched_switch_assign_trace(tr);
53 static enum print_line_t
54 initcall_call_print_line(struct trace_iterator *iter)
56 struct trace_entry *entry = iter->ent;
57 struct trace_seq *s = &iter->seq;
58 struct trace_boot_call *field;
59 struct boot_trace_call *call;
61 unsigned long nsec_rem;
64 trace_assign_type(field, entry);
65 call = &field->boot_call;
67 nsec_rem = do_div(ts, 1000000000);
69 ret = trace_seq_printf(s, "[%5ld.%09ld] calling %s @ %i\n",
70 (unsigned long)ts, nsec_rem, call->func, call->caller);
73 return TRACE_TYPE_PARTIAL_LINE;
75 return TRACE_TYPE_HANDLED;
78 static enum print_line_t
79 initcall_ret_print_line(struct trace_iterator *iter)
81 struct trace_entry *entry = iter->ent;
82 struct trace_seq *s = &iter->seq;
83 struct trace_boot_ret *field;
84 struct boot_trace_ret *init_ret;
86 unsigned long nsec_rem;
89 trace_assign_type(field, entry);
90 init_ret = &field->boot_ret;
92 nsec_rem = do_div(ts, 1000000000);
94 ret = trace_seq_printf(s, "[%5ld.%09ld] initcall %s "
95 "returned %d after %llu msecs\n",
98 init_ret->func, init_ret->result, init_ret->duration);
101 return TRACE_TYPE_PARTIAL_LINE;
103 return TRACE_TYPE_HANDLED;
106 static enum print_line_t initcall_print_line(struct trace_iterator *iter)
108 struct trace_entry *entry = iter->ent;
110 switch (entry->type) {
111 case TRACE_BOOT_CALL:
112 return initcall_call_print_line(iter);
114 return initcall_ret_print_line(iter);
116 return TRACE_TYPE_UNHANDLED;
120 struct tracer boot_tracer __read_mostly =
123 .init = boot_trace_init,
124 .reset = tracing_reset_online_cpus,
125 .print_line = initcall_print_line,
128 void trace_boot_call(struct boot_trace_call *bt, initcall_t fn)
130 struct ring_buffer_event *event;
131 struct trace_boot_call *entry;
132 unsigned long irq_flags;
133 struct trace_array *tr = boot_trace;
135 if (!pre_initcalls_finished)
138 /* Get its name now since this function could
139 * disappear because it is in the .init section.
141 sprint_symbol(bt->func, (unsigned long)fn);
144 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
148 entry = ring_buffer_event_data(event);
149 tracing_generic_entry_update(&entry->ent, 0, 0);
150 entry->ent.type = TRACE_BOOT_CALL;
151 entry->boot_call = *bt;
152 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
160 void trace_boot_ret(struct boot_trace_ret *bt, initcall_t fn)
162 struct ring_buffer_event *event;
163 struct trace_boot_ret *entry;
164 unsigned long irq_flags;
165 struct trace_array *tr = boot_trace;
167 if (!pre_initcalls_finished)
170 sprint_symbol(bt->func, (unsigned long)fn);
173 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
177 entry = ring_buffer_event_data(event);
178 tracing_generic_entry_update(&entry->ent, 0, 0);
179 entry->ent.type = TRACE_BOOT_RET;
180 entry->boot_ret = *bt;
181 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);