Merge branches 'tracing/ftrace', 'tracing/function-graph-tracer' and 'tracing/urgent...
[deliverable/linux.git] / 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_sched_switch_record();
32 }
33
34 void disable_boot_trace(void)
35 {
36 if (pre_initcalls_finished)
37 tracing_stop_sched_switch_record();
38 }
39
40 static void reset_boot_trace(struct trace_array *tr)
41 {
42 int cpu;
43
44 tr->time_start = ftrace_now(tr->cpu);
45
46 for_each_online_cpu(cpu)
47 tracing_reset(tr, cpu);
48 }
49
50 static int boot_trace_init(struct trace_array *tr)
51 {
52 int cpu;
53 boot_trace = tr;
54
55 for_each_cpu_mask(cpu, cpu_possible_map)
56 tracing_reset(tr, cpu);
57
58 tracing_sched_switch_assign_trace(tr);
59 return 0;
60 }
61
62 static enum print_line_t
63 initcall_call_print_line(struct trace_iterator *iter)
64 {
65 struct trace_entry *entry = iter->ent;
66 struct trace_seq *s = &iter->seq;
67 struct trace_boot_call *field;
68 struct boot_trace_call *call;
69 u64 ts;
70 unsigned long nsec_rem;
71 int ret;
72
73 trace_assign_type(field, entry);
74 call = &field->boot_call;
75 ts = iter->ts;
76 nsec_rem = do_div(ts, 1000000000);
77
78 ret = trace_seq_printf(s, "[%5ld.%09ld] calling %s @ %i\n",
79 (unsigned long)ts, nsec_rem, call->func, call->caller);
80
81 if (!ret)
82 return TRACE_TYPE_PARTIAL_LINE;
83 else
84 return TRACE_TYPE_HANDLED;
85 }
86
87 static enum print_line_t
88 initcall_ret_print_line(struct trace_iterator *iter)
89 {
90 struct trace_entry *entry = iter->ent;
91 struct trace_seq *s = &iter->seq;
92 struct trace_boot_ret *field;
93 struct boot_trace_ret *init_ret;
94 u64 ts;
95 unsigned long nsec_rem;
96 int ret;
97
98 trace_assign_type(field, entry);
99 init_ret = &field->boot_ret;
100 ts = iter->ts;
101 nsec_rem = do_div(ts, 1000000000);
102
103 ret = trace_seq_printf(s, "[%5ld.%09ld] initcall %s "
104 "returned %d after %llu msecs\n",
105 (unsigned long) ts,
106 nsec_rem,
107 init_ret->func, init_ret->result, init_ret->duration);
108
109 if (!ret)
110 return TRACE_TYPE_PARTIAL_LINE;
111 else
112 return TRACE_TYPE_HANDLED;
113 }
114
115 static enum print_line_t initcall_print_line(struct trace_iterator *iter)
116 {
117 struct trace_entry *entry = iter->ent;
118
119 switch (entry->type) {
120 case TRACE_BOOT_CALL:
121 return initcall_call_print_line(iter);
122 case TRACE_BOOT_RET:
123 return initcall_ret_print_line(iter);
124 default:
125 return TRACE_TYPE_UNHANDLED;
126 }
127 }
128
129 struct tracer boot_tracer __read_mostly =
130 {
131 .name = "initcall",
132 .init = boot_trace_init,
133 .reset = reset_boot_trace,
134 .print_line = initcall_print_line,
135 };
136
137 void trace_boot_call(struct boot_trace_call *bt, initcall_t fn)
138 {
139 struct ring_buffer_event *event;
140 struct trace_boot_call *entry;
141 unsigned long irq_flags;
142 struct trace_array *tr = boot_trace;
143
144 if (!pre_initcalls_finished)
145 return;
146
147 /* Get its name now since this function could
148 * disappear because it is in the .init section.
149 */
150 sprint_symbol(bt->func, (unsigned long)fn);
151 preempt_disable();
152
153 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
154 &irq_flags);
155 if (!event)
156 goto out;
157 entry = ring_buffer_event_data(event);
158 tracing_generic_entry_update(&entry->ent, 0, 0);
159 entry->ent.type = TRACE_BOOT_CALL;
160 entry->boot_call = *bt;
161 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
162
163 trace_wake_up();
164
165 out:
166 preempt_enable();
167 }
168
169 void trace_boot_ret(struct boot_trace_ret *bt, initcall_t fn)
170 {
171 struct ring_buffer_event *event;
172 struct trace_boot_ret *entry;
173 unsigned long irq_flags;
174 struct trace_array *tr = boot_trace;
175
176 if (!pre_initcalls_finished)
177 return;
178
179 sprint_symbol(bt->func, (unsigned long)fn);
180 preempt_disable();
181
182 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
183 &irq_flags);
184 if (!event)
185 goto out;
186 entry = ring_buffer_event_data(event);
187 tracing_generic_entry_update(&entry->ent, 0, 0);
188 entry->ent.type = TRACE_BOOT_RET;
189 entry->boot_ret = *bt;
190 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
191
192 trace_wake_up();
193
194 out:
195 preempt_enable();
196 }
This page took 0.035384 seconds and 6 git commands to generate.