tracing/fastboot: get the initcall name before it disappears
[safe/jmp/linux-2.6] / kernel / trace / trace_boot.c
1 /*
2  * ring buffer based initcalls tracer
3  *
4  * Copyright (C) 2008 Frederic Weisbecker <fweisbec@gmail.com>
5  *
6  */
7
8 #include <linux/init.h>
9 #include <linux/debugfs.h>
10 #include <linux/ftrace.h>
11 #include <linux/kallsyms.h>
12
13 #include "trace.h"
14
15 static struct trace_array *boot_trace;
16 static int trace_boot_enabled;
17
18
19 /* Should be started after do_pre_smp_initcalls() in init/main.c */
20 void start_boot_trace(void)
21 {
22         trace_boot_enabled = 1;
23 }
24
25 void stop_boot_trace(struct trace_array *tr)
26 {
27         trace_boot_enabled = 0;
28 }
29
30 static void boot_trace_init(struct trace_array *tr)
31 {
32         int cpu;
33         boot_trace = tr;
34
35         trace_boot_enabled = 0;
36
37         for_each_cpu_mask(cpu, cpu_possible_map)
38                 tracing_reset(tr, cpu);
39 }
40
41 static void boot_trace_ctrl_update(struct trace_array *tr)
42 {
43         if (tr->ctrl)
44                 start_boot_trace();
45         else
46                 stop_boot_trace(tr);
47 }
48
49 static enum print_line_t initcall_print_line(struct trace_iterator *iter)
50 {
51         int ret;
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);
58
59         if (entry->type == TRACE_BOOT) {
60                 ret = trace_seq_printf(s, "[%5ld.%06ld] calling  %s @ %i\n",
61                                           calltime.tv_sec,
62                                           calltime.tv_nsec,
63                                           it->func, it->caller);
64                 if (!ret)
65                         return TRACE_TYPE_PARTIAL_LINE;
66
67                 ret = trace_seq_printf(s, "[%5ld.%06ld] initcall %s "
68                                           "returned %d after %lld msecs\n",
69                                           rettime.tv_sec,
70                                           rettime.tv_nsec,
71                                           it->func, it->result, it->duration);
72
73                 if (!ret)
74                         return TRACE_TYPE_PARTIAL_LINE;
75                 return TRACE_TYPE_HANDLED;
76         }
77         return TRACE_TYPE_UNHANDLED;
78 }
79
80 struct tracer boot_tracer __read_mostly =
81 {
82         .name           = "initcall",
83         .init           = boot_trace_init,
84         .reset          = stop_boot_trace,
85         .ctrl_update    = boot_trace_ctrl_update,
86         .print_line     = initcall_print_line,
87 };
88
89 void trace_boot(struct boot_trace *it, initcall_t fn)
90 {
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;
96
97         if (!trace_boot_enabled)
98                 return;
99
100         /* Get its name now since this function could
101          * disappear because it is in the .init section.
102          */
103         sprint_symbol(it->func, (unsigned long)fn);
104         preempt_disable();
105         data = tr->data[smp_processor_id()];
106
107         event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
108                                          &irq_flags);
109         if (!event)
110                 goto out;
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);
116
117         trace_wake_up();
118
119  out:
120         preempt_enable();
121 }