tracing: pass around ring buffer instead of tracer
[deliverable/linux.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 43{
d13744cd
FW
44 boot_trace = tr;
45
79fb0768
SR
46 if (!tr)
47 return 0;
48
76f0d073 49 tracing_reset_online_cpus(tr);
d7ad44b6 50
e168e051 51 tracing_sched_switch_assign_trace(tr);
1c80025a 52 return 0;
d13744cd
FW
53}
54
74239072
FW
55static enum print_line_t
56initcall_call_print_line(struct trace_iterator *iter)
d13744cd 57{
74239072
FW
58 struct trace_entry *entry = iter->ent;
59 struct trace_seq *s = &iter->seq;
60 struct trace_boot_call *field;
61 struct boot_trace_call *call;
62 u64 ts;
63 unsigned long nsec_rem;
9e9efffb 64 int ret;
74239072
FW
65
66 trace_assign_type(field, entry);
67 call = &field->boot_call;
68 ts = iter->ts;
a5dec557 69 nsec_rem = do_div(ts, NSEC_PER_SEC);
74239072
FW
70
71 ret = trace_seq_printf(s, "[%5ld.%09ld] calling %s @ %i\n",
72 (unsigned long)ts, nsec_rem, call->func, call->caller);
73
74 if (!ret)
75 return TRACE_TYPE_PARTIAL_LINE;
76 else
77 return TRACE_TYPE_HANDLED;
78}
79
80static enum print_line_t
81initcall_ret_print_line(struct trace_iterator *iter)
82{
d13744cd 83 struct trace_entry *entry = iter->ent;
d13744cd 84 struct trace_seq *s = &iter->seq;
74239072
FW
85 struct trace_boot_ret *field;
86 struct boot_trace_ret *init_ret;
87 u64 ts;
88 unsigned long nsec_rem;
89 int ret;
90
91 trace_assign_type(field, entry);
92 init_ret = &field->boot_ret;
93 ts = iter->ts;
a5dec557 94 nsec_rem = do_div(ts, NSEC_PER_SEC);
74239072
FW
95
96 ret = trace_seq_printf(s, "[%5ld.%09ld] initcall %s "
97 "returned %d after %llu msecs\n",
98 (unsigned long) ts,
99 nsec_rem,
100 init_ret->func, init_ret->result, init_ret->duration);
101
102 if (!ret)
103 return TRACE_TYPE_PARTIAL_LINE;
104 else
cb5ab742 105 return TRACE_TYPE_HANDLED;
74239072
FW
106}
107
108static enum print_line_t initcall_print_line(struct trace_iterator *iter)
109{
110 struct trace_entry *entry = iter->ent;
111
112 switch (entry->type) {
113 case TRACE_BOOT_CALL:
114 return initcall_call_print_line(iter);
115 case TRACE_BOOT_RET:
116 return initcall_ret_print_line(iter);
117 default:
118 return TRACE_TYPE_UNHANDLED;
9e9efffb 119 }
d13744cd
FW
120}
121
122struct tracer boot_tracer __read_mostly =
123{
124 .name = "initcall",
125 .init = boot_trace_init,
213cc060 126 .reset = tracing_reset_online_cpus,
d13744cd
FW
127 .print_line = initcall_print_line,
128};
129
74239072 130void trace_boot_call(struct boot_trace_call *bt, initcall_t fn)
d13744cd 131{
3928a8a2 132 struct ring_buffer_event *event;
e77405ad 133 struct ring_buffer *buffer;
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
e77405ad
SR
146 buffer = tr->buffer;
147 event = trace_buffer_lock_reserve(buffer, TRACE_BOOT_CALL,
51a763dd 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;
e77405ad 153 trace_buffer_unlock_commit(buffer, 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;
e77405ad 161 struct ring_buffer *buffer;
74239072 162 struct trace_boot_ret *entry;
74239072
FW
163 struct trace_array *tr = boot_trace;
164
79fb0768 165 if (!tr || !pre_initcalls_finished)
74239072
FW
166 return;
167
168 sprint_symbol(bt->func, (unsigned long)fn);
d13744cd 169 preempt_disable();
d13744cd 170
e77405ad
SR
171 buffer = tr->buffer;
172 event = trace_buffer_lock_reserve(buffer, TRACE_BOOT_RET,
51a763dd 173 sizeof(*entry), 0, 0);
3928a8a2
SR
174 if (!event)
175 goto out;
176 entry = ring_buffer_event_data(event);
74239072 177 entry->boot_ret = *bt;
e77405ad 178 trace_buffer_unlock_commit(buffer, event, 0, 0);
3928a8a2 179 out:
d13744cd
FW
180 preempt_enable();
181}
This page took 0.118849 seconds and 5 git commands to generate.