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(struct trace_array *tr)
27 trace_boot_enabled = 0;
30 static void boot_trace_init(struct trace_array *tr)
35 trace_boot_enabled = 0;
37 for_each_cpu_mask(cpu, cpu_possible_map)
38 tracing_reset(tr, cpu);
41 static void boot_trace_ctrl_update(struct trace_array *tr)
49 static enum print_line_t initcall_print_line(struct trace_iterator *iter)
52 struct trace_entry *entry = iter->ent;
53 struct trace_boot *field = (struct trace_boot *)entry;
54 struct boot_trace *it = &field->initcall;
55 struct trace_seq *s = &iter->seq;
56 struct timespec calltime = ktime_to_timespec(it->calltime);
57 struct timespec rettime = ktime_to_timespec(it->rettime);
59 if (entry->type == TRACE_BOOT) {
60 ret = trace_seq_printf(s, "[%5ld.%06ld] calling %s @ %i\n",
63 it->func, it->caller);
65 return TRACE_TYPE_PARTIAL_LINE;
67 ret = trace_seq_printf(s, "[%5ld.%06ld] initcall %s "
68 "returned %d after %lld msecs\n",
71 it->func, it->result, it->duration);
74 return TRACE_TYPE_PARTIAL_LINE;
75 return TRACE_TYPE_HANDLED;
77 return TRACE_TYPE_UNHANDLED;
80 struct tracer boot_tracer __read_mostly =
83 .init = boot_trace_init,
84 .reset = stop_boot_trace,
85 .ctrl_update = boot_trace_ctrl_update,
86 .print_line = initcall_print_line,
89 void trace_boot(struct boot_trace *it, initcall_t fn)
91 struct ring_buffer_event *event;
92 struct trace_boot *entry;
93 struct trace_array_cpu *data;
94 unsigned long irq_flags;
95 struct trace_array *tr = boot_trace;
97 if (!trace_boot_enabled)
100 /* Get its name now since this function could
101 * disappear because it is in the .init section.
103 sprint_symbol(it->func, (unsigned long)fn);
105 data = tr->data[smp_processor_id()];
107 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
111 entry = ring_buffer_event_data(event);
112 tracing_generic_entry_update(&entry->ent, 0, 0);
113 entry->ent.type = TRACE_BOOT;
114 entry->initcall = *it;
115 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);