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