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