Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ryusuke...
[linux-2.6-block.git] / kernel / trace / trace_boot.c
CommitLineData
d13744cd
FW
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>
5601020f 11#include <linux/kallsyms.h>
a5dec557 12#include <linux/time.h>
d13744cd
FW
13
14#include "trace.h"
f0868d1e 15#include "trace_output.h"
d13744cd
FW
16
17static struct trace_array *boot_trace;
71566a0d 18static bool pre_initcalls_finished;
d13744cd 19
71566a0d
FW
20/* Tells the boot tracer that the pre_smp_initcalls are finished.
21 * So we are ready .
22 * It doesn't enable sched events tracing however.
23 * You have to call enable_boot_trace to do so.
24 */
d13744cd
FW
25void start_boot_trace(void)
26{
71566a0d
FW
27 pre_initcalls_finished = true;
28}
29
30void enable_boot_trace(void)
31{
79fb0768 32 if (boot_trace && pre_initcalls_finished)
e168e051 33 tracing_start_sched_switch_record();
d13744cd
FW
34}
35
71566a0d 36void disable_boot_trace(void)
d13744cd 37{
79fb0768 38 if (boot_trace && pre_initcalls_finished)
e168e051 39 tracing_stop_sched_switch_record();
d13744cd
FW
40}
41
1c80025a 42static int boot_trace_init(struct trace_array *tr)
d13744cd
FW
43{
44 int cpu;
45 boot_trace = tr;
46
79fb0768
SR
47 if (!tr)
48 return 0;
49
4462344e 50 for_each_cpu(cpu, cpu_possible_mask)
3928a8a2 51 tracing_reset(tr, cpu);
d7ad44b6 52
e168e051 53 tracing_sched_switch_assign_trace(tr);
1c80025a 54 return 0;
d13744cd
FW
55}
56
74239072
FW
57static enum print_line_t
58initcall_call_print_line(struct trace_iterator *iter)
d13744cd 59{
74239072
FW
60 struct trace_entry *entry = iter->ent;
61 struct trace_seq *s = &iter->seq;
62 struct trace_boot_call *field;
63 struct boot_trace_call *call;
64 u64 ts;
65 unsigned long nsec_rem;
9e9efffb 66 int ret;
74239072
FW
67
68 trace_assign_type(field, entry);
69 call = &field->boot_call;
70 ts = iter->ts;
a5dec557 71 nsec_rem = do_div(ts, NSEC_PER_SEC);
74239072
FW
72
73 ret = trace_seq_printf(s, "[%5ld.%09ld] calling %s @ %i\n",
74 (unsigned long)ts, nsec_rem, call->func, call->caller);
75
76 if (!ret)
77 return TRACE_TYPE_PARTIAL_LINE;
78 else
79 return TRACE_TYPE_HANDLED;
80}
81
82static enum print_line_t
83initcall_ret_print_line(struct trace_iterator *iter)
84{
d13744cd 85 struct trace_entry *entry = iter->ent;
d13744cd 86 struct trace_seq *s = &iter->seq;
74239072
FW
87 struct trace_boot_ret *field;
88 struct boot_trace_ret *init_ret;
89 u64 ts;
90 unsigned long nsec_rem;
91 int ret;
92
93 trace_assign_type(field, entry);
94 init_ret = &field->boot_ret;
95 ts = iter->ts;
a5dec557 96 nsec_rem = do_div(ts, NSEC_PER_SEC);
74239072
FW
97
98 ret = trace_seq_printf(s, "[%5ld.%09ld] initcall %s "
99 "returned %d after %llu msecs\n",
100 (unsigned long) ts,
101 nsec_rem,
102 init_ret->func, init_ret->result, init_ret->duration);
103
104 if (!ret)
105 return TRACE_TYPE_PARTIAL_LINE;
106 else
cb5ab742 107 return TRACE_TYPE_HANDLED;
74239072
FW
108}
109
110static enum print_line_t initcall_print_line(struct trace_iterator *iter)
111{
112 struct trace_entry *entry = iter->ent;
113
114 switch (entry->type) {
115 case TRACE_BOOT_CALL:
116 return initcall_call_print_line(iter);
117 case TRACE_BOOT_RET:
118 return initcall_ret_print_line(iter);
119 default:
120 return TRACE_TYPE_UNHANDLED;
9e9efffb 121 }
d13744cd
FW
122}
123
124struct tracer boot_tracer __read_mostly =
125{
126 .name = "initcall",
127 .init = boot_trace_init,
213cc060 128 .reset = tracing_reset_online_cpus,
d13744cd
FW
129 .print_line = initcall_print_line,
130};
131
74239072 132void trace_boot_call(struct boot_trace_call *bt, initcall_t fn)
d13744cd 133{
3928a8a2 134 struct ring_buffer_event *event;
74239072 135 struct trace_boot_call *entry;
d13744cd
FW
136 struct trace_array *tr = boot_trace;
137
79fb0768 138 if (!tr || !pre_initcalls_finished)
d13744cd
FW
139 return;
140
5601020f
FW
141 /* Get its name now since this function could
142 * disappear because it is in the .init section.
143 */
74239072
FW
144 sprint_symbol(bt->func, (unsigned long)fn);
145 preempt_disable();
146
51a763dd
ACM
147 event = trace_buffer_lock_reserve(tr, TRACE_BOOT_CALL,
148 sizeof(*entry), 0, 0);
74239072
FW
149 if (!event)
150 goto out;
151 entry = ring_buffer_event_data(event);
74239072 152 entry->boot_call = *bt;
51a763dd 153 trace_buffer_unlock_commit(tr, event, 0, 0);
74239072
FW
154 out:
155 preempt_enable();
156}
157
158void trace_boot_ret(struct boot_trace_ret *bt, initcall_t fn)
159{
160 struct ring_buffer_event *event;
161 struct trace_boot_ret *entry;
74239072
FW
162 struct trace_array *tr = boot_trace;
163
79fb0768 164 if (!tr || !pre_initcalls_finished)
74239072
FW
165 return;
166
167 sprint_symbol(bt->func, (unsigned long)fn);
d13744cd 168 preempt_disable();
d13744cd 169
51a763dd
ACM
170 event = trace_buffer_lock_reserve(tr, TRACE_BOOT_RET,
171 sizeof(*entry), 0, 0);
3928a8a2
SR
172 if (!event)
173 goto out;
174 entry = ring_buffer_event_data(event);
74239072 175 entry->boot_ret = *bt;
51a763dd 176 trace_buffer_unlock_commit(tr, event, 0, 0);
3928a8a2 177 out:
d13744cd
FW
178 preempt_enable();
179}