tracing/fastboot: Enable boot tracing only during initcalls
[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 bool pre_initcalls_finished;
17
18 /* Tells the boot tracer that the pre_smp_initcalls are finished.
19  * So we are ready .
20  * It doesn't enable sched events tracing however.
21  * You have to call enable_boot_trace to do so.
22  */
23 void start_boot_trace(void)
24 {
25         pre_initcalls_finished = true;
26 }
27
28 void enable_boot_trace(void)
29 {
30 }
31
32 void disable_boot_trace(void)
33 {
34 }
35
36 void reset_boot_trace(struct trace_array *tr)
37 {
38         disable_boot_trace();
39 }
40
41 static void boot_trace_init(struct trace_array *tr)
42 {
43         int cpu;
44         boot_trace = tr;
45
46         for_each_cpu_mask(cpu, cpu_possible_map)
47                 tracing_reset(tr, cpu);
48 }
49
50 static void boot_trace_ctrl_update(struct trace_array *tr)
51 {
52         if (tr->ctrl)
53                 enable_boot_trace();
54         else
55                 disable_boot_trace();
56 }
57
58 static enum print_line_t initcall_print_line(struct trace_iterator *iter)
59 {
60         int ret;
61         struct trace_entry *entry = iter->ent;
62         struct trace_boot *field = (struct trace_boot *)entry;
63         struct boot_trace *it = &field->initcall;
64         struct trace_seq *s = &iter->seq;
65         struct timespec calltime = ktime_to_timespec(it->calltime);
66         struct timespec rettime = ktime_to_timespec(it->rettime);
67
68         if (entry->type == TRACE_BOOT) {
69                 ret = trace_seq_printf(s, "[%5ld.%09ld] calling  %s @ %i\n",
70                                           calltime.tv_sec,
71                                           calltime.tv_nsec,
72                                           it->func, it->caller);
73                 if (!ret)
74                         return TRACE_TYPE_PARTIAL_LINE;
75
76                 ret = trace_seq_printf(s, "[%5ld.%09ld] initcall %s "
77                                           "returned %d after %lld msecs\n",
78                                           rettime.tv_sec,
79                                           rettime.tv_nsec,
80                                           it->func, it->result, it->duration);
81
82                 if (!ret)
83                         return TRACE_TYPE_PARTIAL_LINE;
84                 return TRACE_TYPE_HANDLED;
85         }
86         return TRACE_TYPE_UNHANDLED;
87 }
88
89 struct tracer boot_tracer __read_mostly =
90 {
91         .name           = "initcall",
92         .init           = boot_trace_init,
93         .reset          = reset_boot_trace,
94         .ctrl_update    = boot_trace_ctrl_update,
95         .print_line     = initcall_print_line,
96 };
97
98 void trace_boot(struct boot_trace *it, initcall_t fn)
99 {
100         struct ring_buffer_event *event;
101         struct trace_boot *entry;
102         struct trace_array_cpu *data;
103         unsigned long irq_flags;
104         struct trace_array *tr = boot_trace;
105
106         if (!pre_initcalls_finished)
107                 return;
108
109         /* Get its name now since this function could
110          * disappear because it is in the .init section.
111          */
112         sprint_symbol(it->func, (unsigned long)fn);
113         preempt_disable();
114         data = tr->data[smp_processor_id()];
115
116         event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
117                                          &irq_flags);
118         if (!event)
119                 goto out;
120         entry   = ring_buffer_event_data(event);
121         tracing_generic_entry_update(&entry->ent, 0, 0);
122         entry->ent.type = TRACE_BOOT;
123         entry->initcall = *it;
124         ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
125
126         trace_wake_up();
127
128  out:
129         preempt_enable();
130 }