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