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>
15 static struct trace_array *boot_trace;
16 static int trace_boot_enabled;
19 /* Should be started after do_pre_smp_initcalls() in init/main.c */
20 void start_boot_trace(void)
22 trace_boot_enabled = 1;
25 void stop_boot_trace(void)
27 trace_boot_enabled = 0;
30 void reset_boot_trace(struct trace_array *tr)
35 static void boot_trace_init(struct trace_array *tr)
40 trace_boot_enabled = 0;
42 for_each_cpu_mask(cpu, cpu_possible_map)
43 tracing_reset(tr, cpu);
46 static void boot_trace_ctrl_update(struct trace_array *tr)
54 static enum print_line_t initcall_print_line(struct trace_iterator *iter)
57 struct trace_entry *entry = iter->ent;
58 struct trace_boot *field = (struct trace_boot *)entry;
59 struct boot_trace *it = &field->initcall;
60 struct trace_seq *s = &iter->seq;
61 struct timespec calltime = ktime_to_timespec(it->calltime);
62 struct timespec rettime = ktime_to_timespec(it->rettime);
64 if (entry->type == TRACE_BOOT) {
65 ret = trace_seq_printf(s, "[%5ld.%09ld] calling %s @ %i\n",
68 it->func, it->caller);
70 return TRACE_TYPE_PARTIAL_LINE;
72 ret = trace_seq_printf(s, "[%5ld.%09ld] initcall %s "
73 "returned %d after %lld msecs\n",
76 it->func, it->result, it->duration);
79 return TRACE_TYPE_PARTIAL_LINE;
80 return TRACE_TYPE_HANDLED;
82 return TRACE_TYPE_UNHANDLED;
85 struct tracer boot_tracer __read_mostly =
88 .init = boot_trace_init,
89 .reset = reset_boot_trace,
90 .ctrl_update = boot_trace_ctrl_update,
91 .print_line = initcall_print_line,
94 void trace_boot(struct boot_trace *it, initcall_t fn)
96 struct ring_buffer_event *event;
97 struct trace_boot *entry;
98 struct trace_array_cpu *data;
99 unsigned long irq_flags;
100 struct trace_array *tr = boot_trace;
102 if (!trace_boot_enabled)
105 /* Get its name now since this function could
106 * disappear because it is in the .init section.
108 sprint_symbol(it->func, (unsigned long)fn);
110 data = tr->data[smp_processor_id()];
112 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
116 entry = ring_buffer_event_data(event);
117 tracing_generic_entry_update(&entry->ent, 0, 0);
118 entry->ent.type = TRACE_BOOT;
119 entry->initcall = *it;
120 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);