Commit | Line | Data |
---|---|---|
bc0c38d1 SR |
1 | /* |
2 | * ring buffer based function tracer | |
3 | * | |
4 | * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com> | |
5 | * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com> | |
6 | * | |
7 | * Originally taken from the RT patch by: | |
8 | * Arnaldo Carvalho de Melo <acme@redhat.com> | |
9 | * | |
10 | * Based on code from the latency_tracer, that is: | |
11 | * Copyright (C) 2004-2006 Ingo Molnar | |
12 | * Copyright (C) 2004 William Lee Irwin III | |
13 | */ | |
2cadf913 | 14 | #include <linux/ring_buffer.h> |
bc0c38d1 | 15 | #include <linux/utsrelease.h> |
2cadf913 SR |
16 | #include <linux/stacktrace.h> |
17 | #include <linux/writeback.h> | |
bc0c38d1 SR |
18 | #include <linux/kallsyms.h> |
19 | #include <linux/seq_file.h> | |
3f5a54e3 | 20 | #include <linux/notifier.h> |
2cadf913 | 21 | #include <linux/irqflags.h> |
bc0c38d1 | 22 | #include <linux/debugfs.h> |
4c11d7ae | 23 | #include <linux/pagemap.h> |
bc0c38d1 SR |
24 | #include <linux/hardirq.h> |
25 | #include <linux/linkage.h> | |
26 | #include <linux/uaccess.h> | |
2cadf913 | 27 | #include <linux/kprobes.h> |
bc0c38d1 SR |
28 | #include <linux/ftrace.h> |
29 | #include <linux/module.h> | |
30 | #include <linux/percpu.h> | |
2cadf913 | 31 | #include <linux/splice.h> |
3f5a54e3 | 32 | #include <linux/kdebug.h> |
5f0c6c03 | 33 | #include <linux/string.h> |
bc0c38d1 SR |
34 | #include <linux/ctype.h> |
35 | #include <linux/init.h> | |
2a2cc8f7 | 36 | #include <linux/poll.h> |
bc0c38d1 SR |
37 | #include <linux/gfp.h> |
38 | #include <linux/fs.h> | |
86387f7e | 39 | |
bc0c38d1 | 40 | #include "trace.h" |
f0868d1e | 41 | #include "trace_output.h" |
bc0c38d1 | 42 | |
3928a8a2 SR |
43 | #define TRACE_BUFFER_FLAGS (RB_FL_OVERWRITE) |
44 | ||
745b1626 | 45 | unsigned long __read_mostly tracing_max_latency; |
bc0c38d1 SR |
46 | unsigned long __read_mostly tracing_thresh; |
47 | ||
73c5162a SR |
48 | /* |
49 | * On boot up, the ring buffer is set to the minimum size, so that | |
50 | * we do not waste memory on systems that are not using tracing. | |
51 | */ | |
52 | static int ring_buffer_expanded; | |
53 | ||
8e1b82e0 FW |
54 | /* |
55 | * We need to change this state when a selftest is running. | |
ff32504f FW |
56 | * A selftest will lurk into the ring-buffer to count the |
57 | * entries inserted during the selftest although some concurrent | |
5e1607a0 | 58 | * insertions into the ring-buffer such as trace_printk could occurred |
ff32504f FW |
59 | * at the same time, giving false positive or negative results. |
60 | */ | |
8e1b82e0 | 61 | static bool __read_mostly tracing_selftest_running; |
ff32504f | 62 | |
b2821ae6 SR |
63 | /* |
64 | * If a tracer is running, we do not want to run SELFTEST. | |
65 | */ | |
66 | static bool __read_mostly tracing_selftest_disabled; | |
67 | ||
adf9f195 FW |
68 | /* For tracers that don't implement custom flags */ |
69 | static struct tracer_opt dummy_tracer_opt[] = { | |
70 | { } | |
71 | }; | |
72 | ||
73 | static struct tracer_flags dummy_tracer_flags = { | |
74 | .val = 0, | |
75 | .opts = dummy_tracer_opt | |
76 | }; | |
77 | ||
78 | static int dummy_set_flag(u32 old_flags, u32 bit, int set) | |
79 | { | |
80 | return 0; | |
81 | } | |
0f048701 SR |
82 | |
83 | /* | |
84 | * Kill all tracing for good (never come back). | |
85 | * It is initialized to 1 but will turn to zero if the initialization | |
86 | * of the tracer is successful. But that is the only place that sets | |
87 | * this back to zero. | |
88 | */ | |
4fd27358 | 89 | static int tracing_disabled = 1; |
0f048701 | 90 | |
d769041f SR |
91 | static DEFINE_PER_CPU(local_t, ftrace_cpu_disabled); |
92 | ||
93 | static inline void ftrace_disable_cpu(void) | |
94 | { | |
95 | preempt_disable(); | |
96 | local_inc(&__get_cpu_var(ftrace_cpu_disabled)); | |
97 | } | |
98 | ||
99 | static inline void ftrace_enable_cpu(void) | |
100 | { | |
101 | local_dec(&__get_cpu_var(ftrace_cpu_disabled)); | |
102 | preempt_enable(); | |
103 | } | |
104 | ||
9e01c1b7 | 105 | static cpumask_var_t __read_mostly tracing_buffer_mask; |
ab46428c | 106 | |
b04cc6b1 FW |
107 | /* Define which cpu buffers are currently read in trace_pipe */ |
108 | static cpumask_var_t tracing_reader_cpumask; | |
109 | ||
ab46428c | 110 | #define for_each_tracing_cpu(cpu) \ |
9e01c1b7 | 111 | for_each_cpu(cpu, tracing_buffer_mask) |
ab46428c | 112 | |
944ac425 SR |
113 | /* |
114 | * ftrace_dump_on_oops - variable to dump ftrace buffer on oops | |
115 | * | |
116 | * If there is an oops (or kernel panic) and the ftrace_dump_on_oops | |
117 | * is set, then ftrace_dump is called. This will output the contents | |
118 | * of the ftrace buffers to the console. This is very useful for | |
119 | * capturing traces that lead to crashes and outputing it to a | |
120 | * serial console. | |
121 | * | |
122 | * It is default off, but you can enable it with either specifying | |
123 | * "ftrace_dump_on_oops" in the kernel command line, or setting | |
124 | * /proc/sys/kernel/ftrace_dump_on_oops to true. | |
125 | */ | |
126 | int ftrace_dump_on_oops; | |
127 | ||
b2821ae6 SR |
128 | static int tracing_set_tracer(const char *buf); |
129 | ||
130 | #define BOOTUP_TRACER_SIZE 100 | |
131 | static char bootup_tracer_buf[BOOTUP_TRACER_SIZE] __initdata; | |
132 | static char *default_bootup_tracer; | |
d9e54076 PZ |
133 | |
134 | static int __init set_ftrace(char *str) | |
135 | { | |
b2821ae6 SR |
136 | strncpy(bootup_tracer_buf, str, BOOTUP_TRACER_SIZE); |
137 | default_bootup_tracer = bootup_tracer_buf; | |
73c5162a SR |
138 | /* We are using ftrace early, expand it */ |
139 | ring_buffer_expanded = 1; | |
d9e54076 PZ |
140 | return 1; |
141 | } | |
b2821ae6 | 142 | __setup("ftrace=", set_ftrace); |
d9e54076 | 143 | |
944ac425 SR |
144 | static int __init set_ftrace_dump_on_oops(char *str) |
145 | { | |
146 | ftrace_dump_on_oops = 1; | |
147 | return 1; | |
148 | } | |
149 | __setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops); | |
60a11774 | 150 | |
cf8e3474 | 151 | unsigned long long ns2usecs(cycle_t nsec) |
bc0c38d1 SR |
152 | { |
153 | nsec += 500; | |
154 | do_div(nsec, 1000); | |
155 | return nsec; | |
156 | } | |
157 | ||
4fcdae83 SR |
158 | /* |
159 | * The global_trace is the descriptor that holds the tracing | |
160 | * buffers for the live tracing. For each CPU, it contains | |
161 | * a link list of pages that will store trace entries. The | |
162 | * page descriptor of the pages in the memory is used to hold | |
163 | * the link list by linking the lru item in the page descriptor | |
164 | * to each of the pages in the buffer per CPU. | |
165 | * | |
166 | * For each active CPU there is a data field that holds the | |
167 | * pages for the buffer for that CPU. Each CPU has the same number | |
168 | * of pages allocated for its buffer. | |
169 | */ | |
bc0c38d1 SR |
170 | static struct trace_array global_trace; |
171 | ||
172 | static DEFINE_PER_CPU(struct trace_array_cpu, global_trace_cpu); | |
173 | ||
37886f6a SR |
174 | cycle_t ftrace_now(int cpu) |
175 | { | |
176 | u64 ts; | |
177 | ||
178 | /* Early boot up does not have a buffer yet */ | |
179 | if (!global_trace.buffer) | |
180 | return trace_clock_local(); | |
181 | ||
182 | ts = ring_buffer_time_stamp(global_trace.buffer, cpu); | |
183 | ring_buffer_normalize_time_stamp(global_trace.buffer, cpu, &ts); | |
184 | ||
185 | return ts; | |
186 | } | |
bc0c38d1 | 187 | |
4fcdae83 SR |
188 | /* |
189 | * The max_tr is used to snapshot the global_trace when a maximum | |
190 | * latency is reached. Some tracers will use this to store a maximum | |
191 | * trace while it continues examining live traces. | |
192 | * | |
193 | * The buffers for the max_tr are set up the same as the global_trace. | |
194 | * When a snapshot is taken, the link list of the max_tr is swapped | |
195 | * with the link list of the global_trace and the buffers are reset for | |
196 | * the global_trace so the tracing can continue. | |
197 | */ | |
bc0c38d1 SR |
198 | static struct trace_array max_tr; |
199 | ||
200 | static DEFINE_PER_CPU(struct trace_array_cpu, max_data); | |
201 | ||
4fcdae83 | 202 | /* tracer_enabled is used to toggle activation of a tracer */ |
26994ead | 203 | static int tracer_enabled = 1; |
4fcdae83 | 204 | |
9036990d SR |
205 | /** |
206 | * tracing_is_enabled - return tracer_enabled status | |
207 | * | |
208 | * This function is used by other tracers to know the status | |
209 | * of the tracer_enabled flag. Tracers may use this function | |
210 | * to know if it should enable their features when starting | |
211 | * up. See irqsoff tracer for an example (start_irqsoff_tracer). | |
212 | */ | |
213 | int tracing_is_enabled(void) | |
214 | { | |
215 | return tracer_enabled; | |
216 | } | |
217 | ||
4fcdae83 | 218 | /* |
3928a8a2 SR |
219 | * trace_buf_size is the size in bytes that is allocated |
220 | * for a buffer. Note, the number of bytes is always rounded | |
221 | * to page size. | |
3f5a54e3 SR |
222 | * |
223 | * This number is purposely set to a low number of 16384. | |
224 | * If the dump on oops happens, it will be much appreciated | |
225 | * to not have to wait for all that output. Anyway this can be | |
226 | * boot time and run time configurable. | |
4fcdae83 | 227 | */ |
3928a8a2 | 228 | #define TRACE_BUF_SIZE_DEFAULT 1441792UL /* 16384 * 88 (sizeof(entry)) */ |
3f5a54e3 | 229 | |
3928a8a2 | 230 | static unsigned long trace_buf_size = TRACE_BUF_SIZE_DEFAULT; |
bc0c38d1 | 231 | |
4fcdae83 | 232 | /* trace_types holds a link list of available tracers. */ |
bc0c38d1 | 233 | static struct tracer *trace_types __read_mostly; |
4fcdae83 SR |
234 | |
235 | /* current_trace points to the tracer that is currently active */ | |
bc0c38d1 | 236 | static struct tracer *current_trace __read_mostly; |
4fcdae83 SR |
237 | |
238 | /* | |
239 | * max_tracer_type_len is used to simplify the allocating of | |
240 | * buffers to read userspace tracer names. We keep track of | |
241 | * the longest tracer name registered. | |
242 | */ | |
bc0c38d1 SR |
243 | static int max_tracer_type_len; |
244 | ||
4fcdae83 SR |
245 | /* |
246 | * trace_types_lock is used to protect the trace_types list. | |
247 | * This lock is also used to keep user access serialized. | |
248 | * Accesses from userspace will grab this lock while userspace | |
249 | * activities happen inside the kernel. | |
250 | */ | |
bc0c38d1 | 251 | static DEFINE_MUTEX(trace_types_lock); |
4fcdae83 SR |
252 | |
253 | /* trace_wait is a waitqueue for tasks blocked on trace_poll */ | |
4e655519 IM |
254 | static DECLARE_WAIT_QUEUE_HEAD(trace_wait); |
255 | ||
ee6bce52 | 256 | /* trace_flags holds trace_options default values */ |
12ef7d44 | 257 | unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK | |
a2a16d6a SR |
258 | TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | TRACE_ITER_SLEEP_TIME | |
259 | TRACE_ITER_GRAPH_TIME; | |
4e655519 | 260 | |
4fcdae83 SR |
261 | /** |
262 | * trace_wake_up - wake up tasks waiting for trace input | |
263 | * | |
264 | * Simply wakes up any task that is blocked on the trace_wait | |
265 | * queue. These is used with trace_poll for tasks polling the trace. | |
266 | */ | |
4e655519 IM |
267 | void trace_wake_up(void) |
268 | { | |
017730c1 IM |
269 | /* |
270 | * The runqueue_is_locked() can fail, but this is the best we | |
271 | * have for now: | |
272 | */ | |
273 | if (!(trace_flags & TRACE_ITER_BLOCK) && !runqueue_is_locked()) | |
4e655519 IM |
274 | wake_up(&trace_wait); |
275 | } | |
bc0c38d1 | 276 | |
3928a8a2 | 277 | static int __init set_buf_size(char *str) |
bc0c38d1 | 278 | { |
3928a8a2 | 279 | unsigned long buf_size; |
c6caeeb1 SR |
280 | int ret; |
281 | ||
bc0c38d1 SR |
282 | if (!str) |
283 | return 0; | |
3928a8a2 | 284 | ret = strict_strtoul(str, 0, &buf_size); |
c6caeeb1 | 285 | /* nr_entries can not be zero */ |
3928a8a2 | 286 | if (ret < 0 || buf_size == 0) |
c6caeeb1 | 287 | return 0; |
3928a8a2 | 288 | trace_buf_size = buf_size; |
bc0c38d1 SR |
289 | return 1; |
290 | } | |
3928a8a2 | 291 | __setup("trace_buf_size=", set_buf_size); |
bc0c38d1 | 292 | |
57f50be1 SR |
293 | unsigned long nsecs_to_usecs(unsigned long nsecs) |
294 | { | |
295 | return nsecs / 1000; | |
296 | } | |
297 | ||
4fcdae83 | 298 | /* These must match the bit postions in trace_iterator_flags */ |
bc0c38d1 SR |
299 | static const char *trace_options[] = { |
300 | "print-parent", | |
301 | "sym-offset", | |
302 | "sym-addr", | |
303 | "verbose", | |
f9896bf3 | 304 | "raw", |
5e3ca0ec | 305 | "hex", |
cb0f12aa | 306 | "bin", |
2a2cc8f7 | 307 | "block", |
86387f7e | 308 | "stacktrace", |
4ac3ba41 | 309 | "sched-tree", |
5e1607a0 | 310 | "trace_printk", |
b2a866f9 | 311 | "ftrace_preempt", |
9f029e83 | 312 | "branch", |
12ef7d44 | 313 | "annotate", |
02b67518 | 314 | "userstacktrace", |
b54d3de9 | 315 | "sym-userobj", |
66896a85 | 316 | "printk-msg-only", |
c4a8e8be | 317 | "context-info", |
c032ef64 | 318 | "latency-format", |
af4617bd | 319 | "global-clock", |
be6f164a | 320 | "sleep-time", |
a2a16d6a | 321 | "graph-time", |
bc0c38d1 SR |
322 | NULL |
323 | }; | |
324 | ||
4fcdae83 SR |
325 | /* |
326 | * ftrace_max_lock is used to protect the swapping of buffers | |
327 | * when taking a max snapshot. The buffers themselves are | |
328 | * protected by per_cpu spinlocks. But the action of the swap | |
329 | * needs its own lock. | |
330 | * | |
331 | * This is defined as a raw_spinlock_t in order to help | |
332 | * with performance when lockdep debugging is enabled. | |
333 | */ | |
92205c23 SR |
334 | static raw_spinlock_t ftrace_max_lock = |
335 | (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED; | |
bc0c38d1 SR |
336 | |
337 | /* | |
338 | * Copy the new maximum trace into the separate maximum-trace | |
339 | * structure. (this way the maximum trace is permanently saved, | |
340 | * for later retrieval via /debugfs/tracing/latency_trace) | |
341 | */ | |
e309b41d | 342 | static void |
bc0c38d1 SR |
343 | __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) |
344 | { | |
345 | struct trace_array_cpu *data = tr->data[cpu]; | |
346 | ||
347 | max_tr.cpu = cpu; | |
348 | max_tr.time_start = data->preempt_timestamp; | |
349 | ||
350 | data = max_tr.data[cpu]; | |
351 | data->saved_latency = tracing_max_latency; | |
352 | ||
353 | memcpy(data->comm, tsk->comm, TASK_COMM_LEN); | |
354 | data->pid = tsk->pid; | |
b6dff3ec | 355 | data->uid = task_uid(tsk); |
bc0c38d1 SR |
356 | data->nice = tsk->static_prio - 20 - MAX_RT_PRIO; |
357 | data->policy = tsk->policy; | |
358 | data->rt_priority = tsk->rt_priority; | |
359 | ||
360 | /* record this tasks comm */ | |
af513098 | 361 | tracing_record_cmdline(tsk); |
bc0c38d1 SR |
362 | } |
363 | ||
6c6c2796 PP |
364 | ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt) |
365 | { | |
366 | int len; | |
367 | int ret; | |
368 | ||
2dc5d12b SR |
369 | if (!cnt) |
370 | return 0; | |
371 | ||
6c6c2796 PP |
372 | if (s->len <= s->readpos) |
373 | return -EBUSY; | |
374 | ||
375 | len = s->len - s->readpos; | |
376 | if (cnt > len) | |
377 | cnt = len; | |
378 | ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt); | |
2dc5d12b | 379 | if (ret == cnt) |
6c6c2796 PP |
380 | return -EFAULT; |
381 | ||
2dc5d12b SR |
382 | cnt -= ret; |
383 | ||
e74da523 | 384 | s->readpos += cnt; |
6c6c2796 | 385 | return cnt; |
214023c3 SR |
386 | } |
387 | ||
b8b94265 | 388 | static ssize_t trace_seq_to_buffer(struct trace_seq *s, void *buf, size_t cnt) |
3c56819b EGM |
389 | { |
390 | int len; | |
391 | void *ret; | |
392 | ||
393 | if (s->len <= s->readpos) | |
394 | return -EBUSY; | |
395 | ||
396 | len = s->len - s->readpos; | |
397 | if (cnt > len) | |
398 | cnt = len; | |
399 | ret = memcpy(buf, s->buffer + s->readpos, cnt); | |
400 | if (!ret) | |
401 | return -EFAULT; | |
402 | ||
e74da523 | 403 | s->readpos += cnt; |
3c56819b EGM |
404 | return cnt; |
405 | } | |
406 | ||
4fcdae83 SR |
407 | /** |
408 | * update_max_tr - snapshot all trace buffers from global_trace to max_tr | |
409 | * @tr: tracer | |
410 | * @tsk: the task with the latency | |
411 | * @cpu: The cpu that initiated the trace. | |
412 | * | |
413 | * Flip the buffers between the @tr and the max_tr and record information | |
414 | * about which task was the cause of this latency. | |
415 | */ | |
e309b41d | 416 | void |
bc0c38d1 SR |
417 | update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) |
418 | { | |
3928a8a2 | 419 | struct ring_buffer *buf = tr->buffer; |
bc0c38d1 | 420 | |
4c11d7ae | 421 | WARN_ON_ONCE(!irqs_disabled()); |
92205c23 | 422 | __raw_spin_lock(&ftrace_max_lock); |
3928a8a2 SR |
423 | |
424 | tr->buffer = max_tr.buffer; | |
425 | max_tr.buffer = buf; | |
426 | ||
d769041f | 427 | ftrace_disable_cpu(); |
3928a8a2 | 428 | ring_buffer_reset(tr->buffer); |
d769041f | 429 | ftrace_enable_cpu(); |
bc0c38d1 SR |
430 | |
431 | __update_max_tr(tr, tsk, cpu); | |
92205c23 | 432 | __raw_spin_unlock(&ftrace_max_lock); |
bc0c38d1 SR |
433 | } |
434 | ||
435 | /** | |
436 | * update_max_tr_single - only copy one trace over, and reset the rest | |
437 | * @tr - tracer | |
438 | * @tsk - task with the latency | |
439 | * @cpu - the cpu of the buffer to copy. | |
4fcdae83 SR |
440 | * |
441 | * Flip the trace of a single CPU buffer between the @tr and the max_tr. | |
bc0c38d1 | 442 | */ |
e309b41d | 443 | void |
bc0c38d1 SR |
444 | update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu) |
445 | { | |
3928a8a2 | 446 | int ret; |
bc0c38d1 | 447 | |
4c11d7ae | 448 | WARN_ON_ONCE(!irqs_disabled()); |
92205c23 | 449 | __raw_spin_lock(&ftrace_max_lock); |
bc0c38d1 | 450 | |
d769041f SR |
451 | ftrace_disable_cpu(); |
452 | ||
3928a8a2 SR |
453 | ring_buffer_reset(max_tr.buffer); |
454 | ret = ring_buffer_swap_cpu(max_tr.buffer, tr->buffer, cpu); | |
455 | ||
d769041f SR |
456 | ftrace_enable_cpu(); |
457 | ||
97b17efe | 458 | WARN_ON_ONCE(ret && ret != -EAGAIN); |
bc0c38d1 SR |
459 | |
460 | __update_max_tr(tr, tsk, cpu); | |
92205c23 | 461 | __raw_spin_unlock(&ftrace_max_lock); |
bc0c38d1 SR |
462 | } |
463 | ||
4fcdae83 SR |
464 | /** |
465 | * register_tracer - register a tracer with the ftrace system. | |
466 | * @type - the plugin for the tracer | |
467 | * | |
468 | * Register a new plugin tracer. | |
469 | */ | |
bc0c38d1 | 470 | int register_tracer(struct tracer *type) |
e7669b8e HE |
471 | __releases(kernel_lock) |
472 | __acquires(kernel_lock) | |
bc0c38d1 SR |
473 | { |
474 | struct tracer *t; | |
475 | int len; | |
476 | int ret = 0; | |
477 | ||
478 | if (!type->name) { | |
479 | pr_info("Tracer must have a name\n"); | |
480 | return -1; | |
481 | } | |
482 | ||
86fa2f60 IM |
483 | /* |
484 | * When this gets called we hold the BKL which means that | |
485 | * preemption is disabled. Various trace selftests however | |
486 | * need to disable and enable preemption for successful tests. | |
487 | * So we drop the BKL here and grab it after the tests again. | |
488 | */ | |
489 | unlock_kernel(); | |
bc0c38d1 | 490 | mutex_lock(&trace_types_lock); |
86fa2f60 | 491 | |
8e1b82e0 FW |
492 | tracing_selftest_running = true; |
493 | ||
bc0c38d1 SR |
494 | for (t = trace_types; t; t = t->next) { |
495 | if (strcmp(type->name, t->name) == 0) { | |
496 | /* already found */ | |
497 | pr_info("Trace %s already registered\n", | |
498 | type->name); | |
499 | ret = -1; | |
500 | goto out; | |
501 | } | |
502 | } | |
503 | ||
adf9f195 FW |
504 | if (!type->set_flag) |
505 | type->set_flag = &dummy_set_flag; | |
506 | if (!type->flags) | |
507 | type->flags = &dummy_tracer_flags; | |
508 | else | |
509 | if (!type->flags->opts) | |
510 | type->flags->opts = dummy_tracer_opt; | |
6eaaa5d5 FW |
511 | if (!type->wait_pipe) |
512 | type->wait_pipe = default_wait_pipe; | |
513 | ||
adf9f195 | 514 | |
60a11774 | 515 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
b2821ae6 | 516 | if (type->selftest && !tracing_selftest_disabled) { |
60a11774 | 517 | struct tracer *saved_tracer = current_trace; |
60a11774 | 518 | struct trace_array *tr = &global_trace; |
60a11774 | 519 | int i; |
ff32504f | 520 | |
60a11774 SR |
521 | /* |
522 | * Run a selftest on this tracer. | |
523 | * Here we reset the trace buffer, and set the current | |
524 | * tracer to be this tracer. The tracer can then run some | |
525 | * internal tracing to verify that everything is in order. | |
526 | * If we fail, we do not register this tracer. | |
527 | */ | |
86fa2f60 | 528 | for_each_tracing_cpu(i) |
3928a8a2 | 529 | tracing_reset(tr, i); |
86fa2f60 | 530 | |
60a11774 | 531 | current_trace = type; |
60a11774 SR |
532 | /* the test is responsible for initializing and enabling */ |
533 | pr_info("Testing tracer %s: ", type->name); | |
534 | ret = type->selftest(type, tr); | |
535 | /* the test is responsible for resetting too */ | |
536 | current_trace = saved_tracer; | |
60a11774 SR |
537 | if (ret) { |
538 | printk(KERN_CONT "FAILED!\n"); | |
539 | goto out; | |
540 | } | |
1d4db00a | 541 | /* Only reset on passing, to avoid touching corrupted buffers */ |
86fa2f60 | 542 | for_each_tracing_cpu(i) |
3928a8a2 | 543 | tracing_reset(tr, i); |
86fa2f60 | 544 | |
60a11774 SR |
545 | printk(KERN_CONT "PASSED\n"); |
546 | } | |
547 | #endif | |
548 | ||
bc0c38d1 SR |
549 | type->next = trace_types; |
550 | trace_types = type; | |
551 | len = strlen(type->name); | |
552 | if (len > max_tracer_type_len) | |
553 | max_tracer_type_len = len; | |
60a11774 | 554 | |
bc0c38d1 | 555 | out: |
8e1b82e0 | 556 | tracing_selftest_running = false; |
bc0c38d1 SR |
557 | mutex_unlock(&trace_types_lock); |
558 | ||
dac74940 SR |
559 | if (ret || !default_bootup_tracer) |
560 | goto out_unlock; | |
561 | ||
562 | if (strncmp(default_bootup_tracer, type->name, BOOTUP_TRACER_SIZE)) | |
563 | goto out_unlock; | |
564 | ||
565 | printk(KERN_INFO "Starting tracer '%s'\n", type->name); | |
566 | /* Do we want this tracer to start on bootup? */ | |
567 | tracing_set_tracer(type->name); | |
568 | default_bootup_tracer = NULL; | |
569 | /* disable other selftests, since this will break it. */ | |
570 | tracing_selftest_disabled = 1; | |
b2821ae6 | 571 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
dac74940 SR |
572 | printk(KERN_INFO "Disabling FTRACE selftests due to running tracer '%s'\n", |
573 | type->name); | |
b2821ae6 | 574 | #endif |
b2821ae6 | 575 | |
dac74940 | 576 | out_unlock: |
b2821ae6 | 577 | lock_kernel(); |
bc0c38d1 SR |
578 | return ret; |
579 | } | |
580 | ||
581 | void unregister_tracer(struct tracer *type) | |
582 | { | |
583 | struct tracer **t; | |
584 | int len; | |
585 | ||
586 | mutex_lock(&trace_types_lock); | |
587 | for (t = &trace_types; *t; t = &(*t)->next) { | |
588 | if (*t == type) | |
589 | goto found; | |
590 | } | |
591 | pr_info("Trace %s not registered\n", type->name); | |
592 | goto out; | |
593 | ||
594 | found: | |
595 | *t = (*t)->next; | |
b5db03c4 ACM |
596 | |
597 | if (type == current_trace && tracer_enabled) { | |
598 | tracer_enabled = 0; | |
599 | tracing_stop(); | |
600 | if (current_trace->stop) | |
601 | current_trace->stop(&global_trace); | |
602 | current_trace = &nop_trace; | |
603 | } | |
604 | ||
bc0c38d1 SR |
605 | if (strlen(type->name) != max_tracer_type_len) |
606 | goto out; | |
607 | ||
608 | max_tracer_type_len = 0; | |
609 | for (t = &trace_types; *t; t = &(*t)->next) { | |
610 | len = strlen((*t)->name); | |
611 | if (len > max_tracer_type_len) | |
612 | max_tracer_type_len = len; | |
613 | } | |
614 | out: | |
615 | mutex_unlock(&trace_types_lock); | |
616 | } | |
617 | ||
3928a8a2 | 618 | void tracing_reset(struct trace_array *tr, int cpu) |
bc0c38d1 | 619 | { |
d769041f | 620 | ftrace_disable_cpu(); |
3928a8a2 | 621 | ring_buffer_reset_cpu(tr->buffer, cpu); |
d769041f | 622 | ftrace_enable_cpu(); |
bc0c38d1 SR |
623 | } |
624 | ||
213cc060 PE |
625 | void tracing_reset_online_cpus(struct trace_array *tr) |
626 | { | |
627 | int cpu; | |
628 | ||
629 | tr->time_start = ftrace_now(tr->cpu); | |
630 | ||
631 | for_each_online_cpu(cpu) | |
632 | tracing_reset(tr, cpu); | |
633 | } | |
634 | ||
bc0c38d1 | 635 | #define SAVED_CMDLINES 128 |
2c7eea4c | 636 | #define NO_CMDLINE_MAP UINT_MAX |
bc0c38d1 SR |
637 | static unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1]; |
638 | static unsigned map_cmdline_to_pid[SAVED_CMDLINES]; | |
639 | static char saved_cmdlines[SAVED_CMDLINES][TASK_COMM_LEN]; | |
640 | static int cmdline_idx; | |
efed792d | 641 | static raw_spinlock_t trace_cmdline_lock = __RAW_SPIN_LOCK_UNLOCKED; |
25b0b44a | 642 | |
25b0b44a | 643 | /* temporary disable recording */ |
4fd27358 | 644 | static atomic_t trace_record_cmdline_disabled __read_mostly; |
bc0c38d1 SR |
645 | |
646 | static void trace_init_cmdlines(void) | |
647 | { | |
2c7eea4c TG |
648 | memset(&map_pid_to_cmdline, NO_CMDLINE_MAP, sizeof(map_pid_to_cmdline)); |
649 | memset(&map_cmdline_to_pid, NO_CMDLINE_MAP, sizeof(map_cmdline_to_pid)); | |
bc0c38d1 SR |
650 | cmdline_idx = 0; |
651 | } | |
652 | ||
0f048701 SR |
653 | static int trace_stop_count; |
654 | static DEFINE_SPINLOCK(tracing_start_lock); | |
655 | ||
69bb54ec SR |
656 | /** |
657 | * ftrace_off_permanent - disable all ftrace code permanently | |
658 | * | |
659 | * This should only be called when a serious anomally has | |
660 | * been detected. This will turn off the function tracing, | |
661 | * ring buffers, and other tracing utilites. It takes no | |
662 | * locks and can be called from any context. | |
663 | */ | |
664 | void ftrace_off_permanent(void) | |
665 | { | |
666 | tracing_disabled = 1; | |
667 | ftrace_stop(); | |
668 | tracing_off_permanent(); | |
669 | } | |
670 | ||
0f048701 SR |
671 | /** |
672 | * tracing_start - quick start of the tracer | |
673 | * | |
674 | * If tracing is enabled but was stopped by tracing_stop, | |
675 | * this will start the tracer back up. | |
676 | */ | |
677 | void tracing_start(void) | |
678 | { | |
679 | struct ring_buffer *buffer; | |
680 | unsigned long flags; | |
681 | ||
682 | if (tracing_disabled) | |
683 | return; | |
684 | ||
685 | spin_lock_irqsave(&tracing_start_lock, flags); | |
b06a8301 SR |
686 | if (--trace_stop_count) { |
687 | if (trace_stop_count < 0) { | |
688 | /* Someone screwed up their debugging */ | |
689 | WARN_ON_ONCE(1); | |
690 | trace_stop_count = 0; | |
691 | } | |
0f048701 SR |
692 | goto out; |
693 | } | |
694 | ||
695 | ||
696 | buffer = global_trace.buffer; | |
697 | if (buffer) | |
698 | ring_buffer_record_enable(buffer); | |
699 | ||
700 | buffer = max_tr.buffer; | |
701 | if (buffer) | |
702 | ring_buffer_record_enable(buffer); | |
703 | ||
704 | ftrace_start(); | |
705 | out: | |
706 | spin_unlock_irqrestore(&tracing_start_lock, flags); | |
707 | } | |
708 | ||
709 | /** | |
710 | * tracing_stop - quick stop of the tracer | |
711 | * | |
712 | * Light weight way to stop tracing. Use in conjunction with | |
713 | * tracing_start. | |
714 | */ | |
715 | void tracing_stop(void) | |
716 | { | |
717 | struct ring_buffer *buffer; | |
718 | unsigned long flags; | |
719 | ||
720 | ftrace_stop(); | |
721 | spin_lock_irqsave(&tracing_start_lock, flags); | |
722 | if (trace_stop_count++) | |
723 | goto out; | |
724 | ||
725 | buffer = global_trace.buffer; | |
726 | if (buffer) | |
727 | ring_buffer_record_disable(buffer); | |
728 | ||
729 | buffer = max_tr.buffer; | |
730 | if (buffer) | |
731 | ring_buffer_record_disable(buffer); | |
732 | ||
733 | out: | |
734 | spin_unlock_irqrestore(&tracing_start_lock, flags); | |
735 | } | |
736 | ||
e309b41d | 737 | void trace_stop_cmdline_recording(void); |
bc0c38d1 | 738 | |
e309b41d | 739 | static void trace_save_cmdline(struct task_struct *tsk) |
bc0c38d1 | 740 | { |
a635cf04 | 741 | unsigned pid, idx; |
bc0c38d1 SR |
742 | |
743 | if (!tsk->pid || unlikely(tsk->pid > PID_MAX_DEFAULT)) | |
744 | return; | |
745 | ||
746 | /* | |
747 | * It's not the end of the world if we don't get | |
748 | * the lock, but we also don't want to spin | |
749 | * nor do we want to disable interrupts, | |
750 | * so if we miss here, then better luck next time. | |
751 | */ | |
efed792d | 752 | if (!__raw_spin_trylock(&trace_cmdline_lock)) |
bc0c38d1 SR |
753 | return; |
754 | ||
755 | idx = map_pid_to_cmdline[tsk->pid]; | |
2c7eea4c | 756 | if (idx == NO_CMDLINE_MAP) { |
bc0c38d1 SR |
757 | idx = (cmdline_idx + 1) % SAVED_CMDLINES; |
758 | ||
a635cf04 CE |
759 | /* |
760 | * Check whether the cmdline buffer at idx has a pid | |
761 | * mapped. We are going to overwrite that entry so we | |
762 | * need to clear the map_pid_to_cmdline. Otherwise we | |
763 | * would read the new comm for the old pid. | |
764 | */ | |
765 | pid = map_cmdline_to_pid[idx]; | |
766 | if (pid != NO_CMDLINE_MAP) | |
767 | map_pid_to_cmdline[pid] = NO_CMDLINE_MAP; | |
bc0c38d1 | 768 | |
a635cf04 | 769 | map_cmdline_to_pid[idx] = tsk->pid; |
bc0c38d1 SR |
770 | map_pid_to_cmdline[tsk->pid] = idx; |
771 | ||
772 | cmdline_idx = idx; | |
773 | } | |
774 | ||
775 | memcpy(&saved_cmdlines[idx], tsk->comm, TASK_COMM_LEN); | |
776 | ||
efed792d | 777 | __raw_spin_unlock(&trace_cmdline_lock); |
bc0c38d1 SR |
778 | } |
779 | ||
4ca53085 | 780 | void trace_find_cmdline(int pid, char comm[]) |
bc0c38d1 | 781 | { |
bc0c38d1 SR |
782 | unsigned map; |
783 | ||
4ca53085 SR |
784 | if (!pid) { |
785 | strcpy(comm, "<idle>"); | |
786 | return; | |
787 | } | |
bc0c38d1 | 788 | |
4ca53085 SR |
789 | if (pid > PID_MAX_DEFAULT) { |
790 | strcpy(comm, "<...>"); | |
791 | return; | |
792 | } | |
bc0c38d1 | 793 | |
4ca53085 | 794 | __raw_spin_lock(&trace_cmdline_lock); |
bc0c38d1 | 795 | map = map_pid_to_cmdline[pid]; |
50d88758 TG |
796 | if (map != NO_CMDLINE_MAP) |
797 | strcpy(comm, saved_cmdlines[map]); | |
798 | else | |
799 | strcpy(comm, "<...>"); | |
bc0c38d1 | 800 | |
4ca53085 | 801 | __raw_spin_unlock(&trace_cmdline_lock); |
bc0c38d1 SR |
802 | } |
803 | ||
e309b41d | 804 | void tracing_record_cmdline(struct task_struct *tsk) |
bc0c38d1 | 805 | { |
18aecd36 TG |
806 | if (atomic_read(&trace_record_cmdline_disabled) || !tracer_enabled || |
807 | !tracing_is_on()) | |
bc0c38d1 SR |
808 | return; |
809 | ||
810 | trace_save_cmdline(tsk); | |
811 | } | |
812 | ||
45dcd8b8 | 813 | void |
38697053 SR |
814 | tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags, |
815 | int pc) | |
bc0c38d1 SR |
816 | { |
817 | struct task_struct *tsk = current; | |
bc0c38d1 | 818 | |
777e208d SR |
819 | entry->preempt_count = pc & 0xff; |
820 | entry->pid = (tsk) ? tsk->pid : 0; | |
ef18012b | 821 | entry->tgid = (tsk) ? tsk->tgid : 0; |
777e208d | 822 | entry->flags = |
9244489a | 823 | #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT |
2e2ca155 | 824 | (irqs_disabled_flags(flags) ? TRACE_FLAG_IRQS_OFF : 0) | |
9244489a SR |
825 | #else |
826 | TRACE_FLAG_IRQS_NOSUPPORT | | |
827 | #endif | |
bc0c38d1 SR |
828 | ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) | |
829 | ((pc & SOFTIRQ_MASK) ? TRACE_FLAG_SOFTIRQ : 0) | | |
830 | (need_resched() ? TRACE_FLAG_NEED_RESCHED : 0); | |
831 | } | |
832 | ||
51a763dd ACM |
833 | struct ring_buffer_event *trace_buffer_lock_reserve(struct trace_array *tr, |
834 | unsigned char type, | |
835 | unsigned long len, | |
836 | unsigned long flags, int pc) | |
837 | { | |
838 | struct ring_buffer_event *event; | |
839 | ||
840 | event = ring_buffer_lock_reserve(tr->buffer, len); | |
841 | if (event != NULL) { | |
842 | struct trace_entry *ent = ring_buffer_event_data(event); | |
843 | ||
844 | tracing_generic_entry_update(ent, flags, pc); | |
845 | ent->type = type; | |
846 | } | |
847 | ||
848 | return event; | |
849 | } | |
850 | static void ftrace_trace_stack(struct trace_array *tr, | |
851 | unsigned long flags, int skip, int pc); | |
852 | static void ftrace_trace_userstack(struct trace_array *tr, | |
853 | unsigned long flags, int pc); | |
854 | ||
07edf712 FW |
855 | static inline void __trace_buffer_unlock_commit(struct trace_array *tr, |
856 | struct ring_buffer_event *event, | |
857 | unsigned long flags, int pc, | |
858 | int wake) | |
51a763dd ACM |
859 | { |
860 | ring_buffer_unlock_commit(tr->buffer, event); | |
861 | ||
862 | ftrace_trace_stack(tr, flags, 6, pc); | |
863 | ftrace_trace_userstack(tr, flags, pc); | |
07edf712 FW |
864 | |
865 | if (wake) | |
866 | trace_wake_up(); | |
867 | } | |
868 | ||
869 | void trace_buffer_unlock_commit(struct trace_array *tr, | |
870 | struct ring_buffer_event *event, | |
871 | unsigned long flags, int pc) | |
872 | { | |
873 | __trace_buffer_unlock_commit(tr, event, flags, pc, 1); | |
51a763dd ACM |
874 | } |
875 | ||
ef5580d0 SR |
876 | struct ring_buffer_event * |
877 | trace_current_buffer_lock_reserve(unsigned char type, unsigned long len, | |
878 | unsigned long flags, int pc) | |
879 | { | |
880 | return trace_buffer_lock_reserve(&global_trace, | |
881 | type, len, flags, pc); | |
882 | } | |
883 | ||
884 | void trace_current_buffer_unlock_commit(struct ring_buffer_event *event, | |
885 | unsigned long flags, int pc) | |
886 | { | |
07edf712 FW |
887 | return __trace_buffer_unlock_commit(&global_trace, event, flags, pc, 1); |
888 | } | |
889 | ||
890 | void trace_nowake_buffer_unlock_commit(struct ring_buffer_event *event, | |
891 | unsigned long flags, int pc) | |
892 | { | |
893 | return __trace_buffer_unlock_commit(&global_trace, event, flags, pc, 0); | |
ef5580d0 SR |
894 | } |
895 | ||
e309b41d | 896 | void |
7be42151 | 897 | trace_function(struct trace_array *tr, |
38697053 SR |
898 | unsigned long ip, unsigned long parent_ip, unsigned long flags, |
899 | int pc) | |
bc0c38d1 | 900 | { |
3928a8a2 | 901 | struct ring_buffer_event *event; |
777e208d | 902 | struct ftrace_entry *entry; |
bc0c38d1 | 903 | |
d769041f SR |
904 | /* If we are reading the ring buffer, don't trace */ |
905 | if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled)))) | |
906 | return; | |
907 | ||
51a763dd ACM |
908 | event = trace_buffer_lock_reserve(tr, TRACE_FN, sizeof(*entry), |
909 | flags, pc); | |
3928a8a2 SR |
910 | if (!event) |
911 | return; | |
912 | entry = ring_buffer_event_data(event); | |
777e208d SR |
913 | entry->ip = ip; |
914 | entry->parent_ip = parent_ip; | |
0a987751 | 915 | ring_buffer_unlock_commit(tr->buffer, event); |
bc0c38d1 SR |
916 | } |
917 | ||
fb52607a | 918 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
16185369 | 919 | static int __trace_graph_entry(struct trace_array *tr, |
287b6e68 FW |
920 | struct ftrace_graph_ent *trace, |
921 | unsigned long flags, | |
922 | int pc) | |
923 | { | |
924 | struct ring_buffer_event *event; | |
925 | struct ftrace_graph_ent_entry *entry; | |
287b6e68 FW |
926 | |
927 | if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled)))) | |
16185369 | 928 | return 0; |
287b6e68 | 929 | |
51a763dd ACM |
930 | event = trace_buffer_lock_reserve(&global_trace, TRACE_GRAPH_ENT, |
931 | sizeof(*entry), flags, pc); | |
287b6e68 | 932 | if (!event) |
16185369 | 933 | return 0; |
287b6e68 | 934 | entry = ring_buffer_event_data(event); |
287b6e68 | 935 | entry->graph_ent = *trace; |
0a987751 | 936 | ring_buffer_unlock_commit(global_trace.buffer, event); |
16185369 FW |
937 | |
938 | return 1; | |
287b6e68 FW |
939 | } |
940 | ||
941 | static void __trace_graph_return(struct trace_array *tr, | |
fb52607a | 942 | struct ftrace_graph_ret *trace, |
15e6cb36 FW |
943 | unsigned long flags, |
944 | int pc) | |
945 | { | |
946 | struct ring_buffer_event *event; | |
287b6e68 | 947 | struct ftrace_graph_ret_entry *entry; |
15e6cb36 FW |
948 | |
949 | if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled)))) | |
950 | return; | |
951 | ||
51a763dd ACM |
952 | event = trace_buffer_lock_reserve(&global_trace, TRACE_GRAPH_RET, |
953 | sizeof(*entry), flags, pc); | |
15e6cb36 FW |
954 | if (!event) |
955 | return; | |
956 | entry = ring_buffer_event_data(event); | |
287b6e68 | 957 | entry->ret = *trace; |
0a987751 | 958 | ring_buffer_unlock_commit(global_trace.buffer, event); |
15e6cb36 FW |
959 | } |
960 | #endif | |
961 | ||
e309b41d | 962 | void |
2e0f5761 | 963 | ftrace(struct trace_array *tr, struct trace_array_cpu *data, |
38697053 SR |
964 | unsigned long ip, unsigned long parent_ip, unsigned long flags, |
965 | int pc) | |
2e0f5761 IM |
966 | { |
967 | if (likely(!atomic_read(&data->disabled))) | |
7be42151 | 968 | trace_function(tr, ip, parent_ip, flags, pc); |
2e0f5761 IM |
969 | } |
970 | ||
53614991 | 971 | static void __ftrace_trace_stack(struct trace_array *tr, |
53614991 SR |
972 | unsigned long flags, |
973 | int skip, int pc) | |
86387f7e | 974 | { |
c2c80529 | 975 | #ifdef CONFIG_STACKTRACE |
3928a8a2 | 976 | struct ring_buffer_event *event; |
777e208d | 977 | struct stack_entry *entry; |
86387f7e IM |
978 | struct stack_trace trace; |
979 | ||
51a763dd ACM |
980 | event = trace_buffer_lock_reserve(tr, TRACE_STACK, |
981 | sizeof(*entry), flags, pc); | |
3928a8a2 SR |
982 | if (!event) |
983 | return; | |
984 | entry = ring_buffer_event_data(event); | |
777e208d | 985 | memset(&entry->caller, 0, sizeof(entry->caller)); |
86387f7e IM |
986 | |
987 | trace.nr_entries = 0; | |
988 | trace.max_entries = FTRACE_STACK_ENTRIES; | |
989 | trace.skip = skip; | |
777e208d | 990 | trace.entries = entry->caller; |
86387f7e IM |
991 | |
992 | save_stack_trace(&trace); | |
0a987751 | 993 | ring_buffer_unlock_commit(tr->buffer, event); |
c2c80529 | 994 | #endif |
f0a920d5 IM |
995 | } |
996 | ||
53614991 | 997 | static void ftrace_trace_stack(struct trace_array *tr, |
53614991 SR |
998 | unsigned long flags, |
999 | int skip, int pc) | |
1000 | { | |
1001 | if (!(trace_flags & TRACE_ITER_STACKTRACE)) | |
1002 | return; | |
1003 | ||
7be42151 | 1004 | __ftrace_trace_stack(tr, flags, skip, pc); |
53614991 SR |
1005 | } |
1006 | ||
38697053 | 1007 | void __trace_stack(struct trace_array *tr, |
38697053 | 1008 | unsigned long flags, |
53614991 | 1009 | int skip, int pc) |
38697053 | 1010 | { |
7be42151 | 1011 | __ftrace_trace_stack(tr, flags, skip, pc); |
38697053 SR |
1012 | } |
1013 | ||
02b67518 | 1014 | static void ftrace_trace_userstack(struct trace_array *tr, |
7be42151 | 1015 | unsigned long flags, int pc) |
02b67518 | 1016 | { |
c7425acb | 1017 | #ifdef CONFIG_STACKTRACE |
8d7c6a96 | 1018 | struct ring_buffer_event *event; |
02b67518 TE |
1019 | struct userstack_entry *entry; |
1020 | struct stack_trace trace; | |
02b67518 TE |
1021 | |
1022 | if (!(trace_flags & TRACE_ITER_USERSTACKTRACE)) | |
1023 | return; | |
1024 | ||
51a763dd ACM |
1025 | event = trace_buffer_lock_reserve(tr, TRACE_USER_STACK, |
1026 | sizeof(*entry), flags, pc); | |
02b67518 TE |
1027 | if (!event) |
1028 | return; | |
1029 | entry = ring_buffer_event_data(event); | |
02b67518 TE |
1030 | |
1031 | memset(&entry->caller, 0, sizeof(entry->caller)); | |
1032 | ||
1033 | trace.nr_entries = 0; | |
1034 | trace.max_entries = FTRACE_STACK_ENTRIES; | |
1035 | trace.skip = 0; | |
1036 | trace.entries = entry->caller; | |
1037 | ||
1038 | save_stack_trace_user(&trace); | |
0a987751 | 1039 | ring_buffer_unlock_commit(tr->buffer, event); |
c7425acb | 1040 | #endif |
02b67518 TE |
1041 | } |
1042 | ||
4fd27358 HE |
1043 | #ifdef UNUSED |
1044 | static void __trace_userstack(struct trace_array *tr, unsigned long flags) | |
02b67518 | 1045 | { |
7be42151 | 1046 | ftrace_trace_userstack(tr, flags, preempt_count()); |
02b67518 | 1047 | } |
4fd27358 | 1048 | #endif /* UNUSED */ |
02b67518 | 1049 | |
38697053 | 1050 | static void |
7be42151 | 1051 | ftrace_trace_special(void *__tr, |
38697053 SR |
1052 | unsigned long arg1, unsigned long arg2, unsigned long arg3, |
1053 | int pc) | |
a4feb834 | 1054 | { |
3928a8a2 | 1055 | struct ring_buffer_event *event; |
a4feb834 | 1056 | struct trace_array *tr = __tr; |
777e208d | 1057 | struct special_entry *entry; |
a4feb834 | 1058 | |
51a763dd ACM |
1059 | event = trace_buffer_lock_reserve(tr, TRACE_SPECIAL, |
1060 | sizeof(*entry), 0, pc); | |
3928a8a2 SR |
1061 | if (!event) |
1062 | return; | |
1063 | entry = ring_buffer_event_data(event); | |
777e208d SR |
1064 | entry->arg1 = arg1; |
1065 | entry->arg2 = arg2; | |
1066 | entry->arg3 = arg3; | |
51a763dd | 1067 | trace_buffer_unlock_commit(tr, event, 0, pc); |
a4feb834 IM |
1068 | } |
1069 | ||
38697053 SR |
1070 | void |
1071 | __trace_special(void *__tr, void *__data, | |
1072 | unsigned long arg1, unsigned long arg2, unsigned long arg3) | |
1073 | { | |
7be42151 | 1074 | ftrace_trace_special(__tr, arg1, arg2, arg3, preempt_count()); |
38697053 SR |
1075 | } |
1076 | ||
e309b41d | 1077 | void |
bc0c38d1 | 1078 | tracing_sched_switch_trace(struct trace_array *tr, |
86387f7e IM |
1079 | struct task_struct *prev, |
1080 | struct task_struct *next, | |
38697053 | 1081 | unsigned long flags, int pc) |
bc0c38d1 | 1082 | { |
3928a8a2 | 1083 | struct ring_buffer_event *event; |
777e208d | 1084 | struct ctx_switch_entry *entry; |
bc0c38d1 | 1085 | |
51a763dd ACM |
1086 | event = trace_buffer_lock_reserve(tr, TRACE_CTX, |
1087 | sizeof(*entry), flags, pc); | |
3928a8a2 SR |
1088 | if (!event) |
1089 | return; | |
1090 | entry = ring_buffer_event_data(event); | |
777e208d SR |
1091 | entry->prev_pid = prev->pid; |
1092 | entry->prev_prio = prev->prio; | |
1093 | entry->prev_state = prev->state; | |
1094 | entry->next_pid = next->pid; | |
1095 | entry->next_prio = next->prio; | |
1096 | entry->next_state = next->state; | |
1097 | entry->next_cpu = task_cpu(next); | |
51a763dd | 1098 | trace_buffer_unlock_commit(tr, event, flags, pc); |
bc0c38d1 SR |
1099 | } |
1100 | ||
57422797 IM |
1101 | void |
1102 | tracing_sched_wakeup_trace(struct trace_array *tr, | |
86387f7e IM |
1103 | struct task_struct *wakee, |
1104 | struct task_struct *curr, | |
38697053 | 1105 | unsigned long flags, int pc) |
57422797 | 1106 | { |
3928a8a2 | 1107 | struct ring_buffer_event *event; |
777e208d | 1108 | struct ctx_switch_entry *entry; |
57422797 | 1109 | |
51a763dd ACM |
1110 | event = trace_buffer_lock_reserve(tr, TRACE_WAKE, |
1111 | sizeof(*entry), flags, pc); | |
3928a8a2 SR |
1112 | if (!event) |
1113 | return; | |
1114 | entry = ring_buffer_event_data(event); | |
777e208d SR |
1115 | entry->prev_pid = curr->pid; |
1116 | entry->prev_prio = curr->prio; | |
1117 | entry->prev_state = curr->state; | |
1118 | entry->next_pid = wakee->pid; | |
1119 | entry->next_prio = wakee->prio; | |
1120 | entry->next_state = wakee->state; | |
1121 | entry->next_cpu = task_cpu(wakee); | |
6eaaa5d5 FW |
1122 | |
1123 | ring_buffer_unlock_commit(tr->buffer, event); | |
1124 | ftrace_trace_stack(tr, flags, 6, pc); | |
1125 | ftrace_trace_userstack(tr, flags, pc); | |
57422797 IM |
1126 | } |
1127 | ||
4902f884 SR |
1128 | void |
1129 | ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) | |
1130 | { | |
1131 | struct trace_array *tr = &global_trace; | |
1132 | struct trace_array_cpu *data; | |
5aa1ba6a | 1133 | unsigned long flags; |
4902f884 | 1134 | int cpu; |
38697053 | 1135 | int pc; |
4902f884 | 1136 | |
c76f0694 | 1137 | if (tracing_disabled) |
4902f884 SR |
1138 | return; |
1139 | ||
38697053 | 1140 | pc = preempt_count(); |
5aa1ba6a | 1141 | local_irq_save(flags); |
4902f884 SR |
1142 | cpu = raw_smp_processor_id(); |
1143 | data = tr->data[cpu]; | |
4902f884 | 1144 | |
5aa1ba6a | 1145 | if (likely(atomic_inc_return(&data->disabled) == 1)) |
7be42151 | 1146 | ftrace_trace_special(tr, arg1, arg2, arg3, pc); |
4902f884 | 1147 | |
5aa1ba6a SR |
1148 | atomic_dec(&data->disabled); |
1149 | local_irq_restore(flags); | |
4902f884 SR |
1150 | } |
1151 | ||
fb52607a | 1152 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
e49dc19c | 1153 | int trace_graph_entry(struct ftrace_graph_ent *trace) |
15e6cb36 FW |
1154 | { |
1155 | struct trace_array *tr = &global_trace; | |
1156 | struct trace_array_cpu *data; | |
1157 | unsigned long flags; | |
1158 | long disabled; | |
16185369 | 1159 | int ret; |
15e6cb36 FW |
1160 | int cpu; |
1161 | int pc; | |
1162 | ||
804a6851 SR |
1163 | if (!ftrace_trace_task(current)) |
1164 | return 0; | |
1165 | ||
ea4e2bc4 SR |
1166 | if (!ftrace_graph_addr(trace->func)) |
1167 | return 0; | |
1168 | ||
a5e25883 | 1169 | local_irq_save(flags); |
15e6cb36 FW |
1170 | cpu = raw_smp_processor_id(); |
1171 | data = tr->data[cpu]; | |
1172 | disabled = atomic_inc_return(&data->disabled); | |
1173 | if (likely(disabled == 1)) { | |
1174 | pc = preempt_count(); | |
16185369 FW |
1175 | ret = __trace_graph_entry(tr, trace, flags, pc); |
1176 | } else { | |
1177 | ret = 0; | |
287b6e68 | 1178 | } |
ea4e2bc4 SR |
1179 | /* Only do the atomic if it is not already set */ |
1180 | if (!test_tsk_trace_graph(current)) | |
1181 | set_tsk_trace_graph(current); | |
16185369 | 1182 | |
287b6e68 | 1183 | atomic_dec(&data->disabled); |
a5e25883 | 1184 | local_irq_restore(flags); |
e49dc19c | 1185 | |
16185369 | 1186 | return ret; |
287b6e68 FW |
1187 | } |
1188 | ||
1189 | void trace_graph_return(struct ftrace_graph_ret *trace) | |
1190 | { | |
1191 | struct trace_array *tr = &global_trace; | |
1192 | struct trace_array_cpu *data; | |
1193 | unsigned long flags; | |
1194 | long disabled; | |
1195 | int cpu; | |
1196 | int pc; | |
1197 | ||
a5e25883 | 1198 | local_irq_save(flags); |
287b6e68 FW |
1199 | cpu = raw_smp_processor_id(); |
1200 | data = tr->data[cpu]; | |
1201 | disabled = atomic_inc_return(&data->disabled); | |
1202 | if (likely(disabled == 1)) { | |
1203 | pc = preempt_count(); | |
7be42151 | 1204 | __trace_graph_return(tr, trace, flags, pc); |
15e6cb36 | 1205 | } |
ea4e2bc4 SR |
1206 | if (!trace->depth) |
1207 | clear_tsk_trace_graph(current); | |
15e6cb36 | 1208 | atomic_dec(&data->disabled); |
a5e25883 | 1209 | local_irq_restore(flags); |
15e6cb36 | 1210 | } |
fb52607a | 1211 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ |
15e6cb36 | 1212 | |
769b0441 FW |
1213 | |
1214 | /** | |
48ead020 | 1215 | * trace_vbprintk - write binary msg to tracing buffer |
769b0441 FW |
1216 | * |
1217 | */ | |
40ce74f1 | 1218 | int trace_vbprintk(unsigned long ip, const char *fmt, va_list args) |
769b0441 | 1219 | { |
80370cb7 SR |
1220 | static raw_spinlock_t trace_buf_lock = |
1221 | (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED; | |
769b0441 FW |
1222 | static u32 trace_buf[TRACE_BUF_SIZE]; |
1223 | ||
1224 | struct ring_buffer_event *event; | |
1225 | struct trace_array *tr = &global_trace; | |
1226 | struct trace_array_cpu *data; | |
48ead020 | 1227 | struct bprint_entry *entry; |
769b0441 FW |
1228 | unsigned long flags; |
1229 | int resched; | |
1230 | int cpu, len = 0, size, pc; | |
1231 | ||
1232 | if (unlikely(tracing_selftest_running || tracing_disabled)) | |
1233 | return 0; | |
1234 | ||
1235 | /* Don't pollute graph traces with trace_vprintk internals */ | |
1236 | pause_graph_tracing(); | |
1237 | ||
1238 | pc = preempt_count(); | |
1239 | resched = ftrace_preempt_disable(); | |
1240 | cpu = raw_smp_processor_id(); | |
1241 | data = tr->data[cpu]; | |
1242 | ||
1243 | if (unlikely(atomic_read(&data->disabled))) | |
1244 | goto out; | |
1245 | ||
80370cb7 SR |
1246 | /* Lockdep uses trace_printk for lock tracing */ |
1247 | local_irq_save(flags); | |
1248 | __raw_spin_lock(&trace_buf_lock); | |
769b0441 FW |
1249 | len = vbin_printf(trace_buf, TRACE_BUF_SIZE, fmt, args); |
1250 | ||
1251 | if (len > TRACE_BUF_SIZE || len < 0) | |
1252 | goto out_unlock; | |
1253 | ||
1254 | size = sizeof(*entry) + sizeof(u32) * len; | |
48ead020 | 1255 | event = trace_buffer_lock_reserve(tr, TRACE_BPRINT, size, flags, pc); |
769b0441 FW |
1256 | if (!event) |
1257 | goto out_unlock; | |
1258 | entry = ring_buffer_event_data(event); | |
1259 | entry->ip = ip; | |
769b0441 FW |
1260 | entry->fmt = fmt; |
1261 | ||
1262 | memcpy(entry->buf, trace_buf, sizeof(u32) * len); | |
1263 | ring_buffer_unlock_commit(tr->buffer, event); | |
1264 | ||
1265 | out_unlock: | |
80370cb7 SR |
1266 | __raw_spin_unlock(&trace_buf_lock); |
1267 | local_irq_restore(flags); | |
769b0441 FW |
1268 | |
1269 | out: | |
1270 | ftrace_preempt_enable(resched); | |
1271 | unpause_graph_tracing(); | |
1272 | ||
1273 | return len; | |
1274 | } | |
48ead020 FW |
1275 | EXPORT_SYMBOL_GPL(trace_vbprintk); |
1276 | ||
40ce74f1 | 1277 | int trace_vprintk(unsigned long ip, const char *fmt, va_list args) |
48ead020 FW |
1278 | { |
1279 | static raw_spinlock_t trace_buf_lock = __RAW_SPIN_LOCK_UNLOCKED; | |
1280 | static char trace_buf[TRACE_BUF_SIZE]; | |
1281 | ||
1282 | struct ring_buffer_event *event; | |
1283 | struct trace_array *tr = &global_trace; | |
1284 | struct trace_array_cpu *data; | |
1285 | int cpu, len = 0, size, pc; | |
1286 | struct print_entry *entry; | |
1287 | unsigned long irq_flags; | |
1288 | ||
1289 | if (tracing_disabled || tracing_selftest_running) | |
1290 | return 0; | |
1291 | ||
1292 | pc = preempt_count(); | |
1293 | preempt_disable_notrace(); | |
1294 | cpu = raw_smp_processor_id(); | |
1295 | data = tr->data[cpu]; | |
1296 | ||
1297 | if (unlikely(atomic_read(&data->disabled))) | |
1298 | goto out; | |
1299 | ||
1300 | pause_graph_tracing(); | |
1301 | raw_local_irq_save(irq_flags); | |
1302 | __raw_spin_lock(&trace_buf_lock); | |
1303 | len = vsnprintf(trace_buf, TRACE_BUF_SIZE, fmt, args); | |
1304 | ||
1305 | len = min(len, TRACE_BUF_SIZE-1); | |
1306 | trace_buf[len] = 0; | |
1307 | ||
1308 | size = sizeof(*entry) + len + 1; | |
1309 | event = trace_buffer_lock_reserve(tr, TRACE_PRINT, size, irq_flags, pc); | |
1310 | if (!event) | |
1311 | goto out_unlock; | |
1312 | entry = ring_buffer_event_data(event); | |
1313 | entry->ip = ip; | |
48ead020 FW |
1314 | |
1315 | memcpy(&entry->buf, trace_buf, len); | |
1316 | entry->buf[len] = 0; | |
1317 | ring_buffer_unlock_commit(tr->buffer, event); | |
1318 | ||
1319 | out_unlock: | |
1320 | __raw_spin_unlock(&trace_buf_lock); | |
1321 | raw_local_irq_restore(irq_flags); | |
1322 | unpause_graph_tracing(); | |
1323 | out: | |
1324 | preempt_enable_notrace(); | |
1325 | ||
1326 | return len; | |
1327 | } | |
769b0441 FW |
1328 | EXPORT_SYMBOL_GPL(trace_vprintk); |
1329 | ||
bc0c38d1 SR |
1330 | enum trace_file_type { |
1331 | TRACE_FILE_LAT_FMT = 1, | |
12ef7d44 | 1332 | TRACE_FILE_ANNOTATE = 2, |
bc0c38d1 SR |
1333 | }; |
1334 | ||
e2ac8ef5 | 1335 | static void trace_iterator_increment(struct trace_iterator *iter) |
5a90f577 | 1336 | { |
d769041f SR |
1337 | /* Don't allow ftrace to trace into the ring buffers */ |
1338 | ftrace_disable_cpu(); | |
1339 | ||
5a90f577 | 1340 | iter->idx++; |
d769041f SR |
1341 | if (iter->buffer_iter[iter->cpu]) |
1342 | ring_buffer_read(iter->buffer_iter[iter->cpu], NULL); | |
1343 | ||
1344 | ftrace_enable_cpu(); | |
5a90f577 SR |
1345 | } |
1346 | ||
e309b41d | 1347 | static struct trace_entry * |
3928a8a2 | 1348 | peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts) |
dd0e545f | 1349 | { |
3928a8a2 SR |
1350 | struct ring_buffer_event *event; |
1351 | struct ring_buffer_iter *buf_iter = iter->buffer_iter[cpu]; | |
dd0e545f | 1352 | |
d769041f SR |
1353 | /* Don't allow ftrace to trace into the ring buffers */ |
1354 | ftrace_disable_cpu(); | |
1355 | ||
1356 | if (buf_iter) | |
1357 | event = ring_buffer_iter_peek(buf_iter, ts); | |
1358 | else | |
1359 | event = ring_buffer_peek(iter->tr->buffer, cpu, ts); | |
1360 | ||
1361 | ftrace_enable_cpu(); | |
1362 | ||
3928a8a2 | 1363 | return event ? ring_buffer_event_data(event) : NULL; |
dd0e545f | 1364 | } |
d769041f | 1365 | |
dd0e545f | 1366 | static struct trace_entry * |
3928a8a2 | 1367 | __find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts) |
bc0c38d1 | 1368 | { |
3928a8a2 | 1369 | struct ring_buffer *buffer = iter->tr->buffer; |
bc0c38d1 | 1370 | struct trace_entry *ent, *next = NULL; |
b04cc6b1 | 1371 | int cpu_file = iter->cpu_file; |
3928a8a2 | 1372 | u64 next_ts = 0, ts; |
bc0c38d1 SR |
1373 | int next_cpu = -1; |
1374 | int cpu; | |
1375 | ||
b04cc6b1 FW |
1376 | /* |
1377 | * If we are in a per_cpu trace file, don't bother by iterating over | |
1378 | * all cpu and peek directly. | |
1379 | */ | |
1380 | if (cpu_file > TRACE_PIPE_ALL_CPU) { | |
1381 | if (ring_buffer_empty_cpu(buffer, cpu_file)) | |
1382 | return NULL; | |
1383 | ent = peek_next_entry(iter, cpu_file, ent_ts); | |
1384 | if (ent_cpu) | |
1385 | *ent_cpu = cpu_file; | |
1386 | ||
1387 | return ent; | |
1388 | } | |
1389 | ||
ab46428c | 1390 | for_each_tracing_cpu(cpu) { |
dd0e545f | 1391 | |
3928a8a2 SR |
1392 | if (ring_buffer_empty_cpu(buffer, cpu)) |
1393 | continue; | |
dd0e545f | 1394 | |
3928a8a2 | 1395 | ent = peek_next_entry(iter, cpu, &ts); |
dd0e545f | 1396 | |
cdd31cd2 IM |
1397 | /* |
1398 | * Pick the entry with the smallest timestamp: | |
1399 | */ | |
3928a8a2 | 1400 | if (ent && (!next || ts < next_ts)) { |
bc0c38d1 SR |
1401 | next = ent; |
1402 | next_cpu = cpu; | |
3928a8a2 | 1403 | next_ts = ts; |
bc0c38d1 SR |
1404 | } |
1405 | } | |
1406 | ||
1407 | if (ent_cpu) | |
1408 | *ent_cpu = next_cpu; | |
1409 | ||
3928a8a2 SR |
1410 | if (ent_ts) |
1411 | *ent_ts = next_ts; | |
1412 | ||
bc0c38d1 SR |
1413 | return next; |
1414 | } | |
1415 | ||
dd0e545f | 1416 | /* Find the next real entry, without updating the iterator itself */ |
c4a8e8be FW |
1417 | struct trace_entry *trace_find_next_entry(struct trace_iterator *iter, |
1418 | int *ent_cpu, u64 *ent_ts) | |
bc0c38d1 | 1419 | { |
3928a8a2 | 1420 | return __find_next_entry(iter, ent_cpu, ent_ts); |
dd0e545f SR |
1421 | } |
1422 | ||
1423 | /* Find the next real entry, and increment the iterator to the next entry */ | |
1424 | static void *find_next_entry_inc(struct trace_iterator *iter) | |
1425 | { | |
3928a8a2 | 1426 | iter->ent = __find_next_entry(iter, &iter->cpu, &iter->ts); |
dd0e545f | 1427 | |
3928a8a2 | 1428 | if (iter->ent) |
e2ac8ef5 | 1429 | trace_iterator_increment(iter); |
dd0e545f | 1430 | |
3928a8a2 | 1431 | return iter->ent ? iter : NULL; |
b3806b43 | 1432 | } |
bc0c38d1 | 1433 | |
e309b41d | 1434 | static void trace_consume(struct trace_iterator *iter) |
b3806b43 | 1435 | { |
d769041f SR |
1436 | /* Don't allow ftrace to trace into the ring buffers */ |
1437 | ftrace_disable_cpu(); | |
3928a8a2 | 1438 | ring_buffer_consume(iter->tr->buffer, iter->cpu, &iter->ts); |
d769041f | 1439 | ftrace_enable_cpu(); |
bc0c38d1 SR |
1440 | } |
1441 | ||
e309b41d | 1442 | static void *s_next(struct seq_file *m, void *v, loff_t *pos) |
bc0c38d1 SR |
1443 | { |
1444 | struct trace_iterator *iter = m->private; | |
bc0c38d1 | 1445 | int i = (int)*pos; |
4e3c3333 | 1446 | void *ent; |
bc0c38d1 SR |
1447 | |
1448 | (*pos)++; | |
1449 | ||
1450 | /* can't go backwards */ | |
1451 | if (iter->idx > i) | |
1452 | return NULL; | |
1453 | ||
1454 | if (iter->idx < 0) | |
1455 | ent = find_next_entry_inc(iter); | |
1456 | else | |
1457 | ent = iter; | |
1458 | ||
1459 | while (ent && iter->idx < i) | |
1460 | ent = find_next_entry_inc(iter); | |
1461 | ||
1462 | iter->pos = *pos; | |
1463 | ||
bc0c38d1 SR |
1464 | return ent; |
1465 | } | |
1466 | ||
d7350c3f FW |
1467 | /* |
1468 | * No necessary locking here. The worst thing which can | |
1469 | * happen is loosing events consumed at the same time | |
1470 | * by a trace_pipe reader. | |
1471 | * Other than that, we don't risk to crash the ring buffer | |
1472 | * because it serializes the readers. | |
1473 | * | |
1474 | * The current tracer is copied to avoid a global locking | |
1475 | * all around. | |
1476 | */ | |
bc0c38d1 SR |
1477 | static void *s_start(struct seq_file *m, loff_t *pos) |
1478 | { | |
1479 | struct trace_iterator *iter = m->private; | |
d7350c3f | 1480 | static struct tracer *old_tracer; |
b04cc6b1 | 1481 | int cpu_file = iter->cpu_file; |
bc0c38d1 SR |
1482 | void *p = NULL; |
1483 | loff_t l = 0; | |
3928a8a2 | 1484 | int cpu; |
bc0c38d1 | 1485 | |
d7350c3f | 1486 | /* copy the tracer to avoid using a global lock all around */ |
bc0c38d1 | 1487 | mutex_lock(&trace_types_lock); |
d7350c3f FW |
1488 | if (unlikely(old_tracer != current_trace && current_trace)) { |
1489 | old_tracer = current_trace; | |
1490 | *iter->trace = *current_trace; | |
d15f57f2 | 1491 | } |
d7350c3f | 1492 | mutex_unlock(&trace_types_lock); |
bc0c38d1 SR |
1493 | |
1494 | atomic_inc(&trace_record_cmdline_disabled); | |
1495 | ||
bc0c38d1 SR |
1496 | if (*pos != iter->pos) { |
1497 | iter->ent = NULL; | |
1498 | iter->cpu = 0; | |
1499 | iter->idx = -1; | |
1500 | ||
d769041f SR |
1501 | ftrace_disable_cpu(); |
1502 | ||
b04cc6b1 FW |
1503 | if (cpu_file == TRACE_PIPE_ALL_CPU) { |
1504 | for_each_tracing_cpu(cpu) | |
1505 | ring_buffer_iter_reset(iter->buffer_iter[cpu]); | |
1506 | } else | |
1507 | ring_buffer_iter_reset(iter->buffer_iter[cpu_file]); | |
1508 | ||
bc0c38d1 | 1509 | |
d769041f SR |
1510 | ftrace_enable_cpu(); |
1511 | ||
bc0c38d1 SR |
1512 | for (p = iter; p && l < *pos; p = s_next(m, p, &l)) |
1513 | ; | |
1514 | ||
1515 | } else { | |
4c11d7ae | 1516 | l = *pos - 1; |
bc0c38d1 SR |
1517 | p = s_next(m, p, &l); |
1518 | } | |
1519 | ||
1520 | return p; | |
1521 | } | |
1522 | ||
1523 | static void s_stop(struct seq_file *m, void *p) | |
1524 | { | |
bc0c38d1 | 1525 | atomic_dec(&trace_record_cmdline_disabled); |
bc0c38d1 SR |
1526 | } |
1527 | ||
e309b41d | 1528 | static void print_lat_help_header(struct seq_file *m) |
bc0c38d1 | 1529 | { |
a6168353 ME |
1530 | seq_puts(m, "# _------=> CPU# \n"); |
1531 | seq_puts(m, "# / _-----=> irqs-off \n"); | |
1532 | seq_puts(m, "# | / _----=> need-resched \n"); | |
1533 | seq_puts(m, "# || / _---=> hardirq/softirq \n"); | |
1534 | seq_puts(m, "# ||| / _--=> preempt-depth \n"); | |
1535 | seq_puts(m, "# |||| / \n"); | |
1536 | seq_puts(m, "# ||||| delay \n"); | |
1537 | seq_puts(m, "# cmd pid ||||| time | caller \n"); | |
1538 | seq_puts(m, "# \\ / ||||| \\ | / \n"); | |
bc0c38d1 SR |
1539 | } |
1540 | ||
e309b41d | 1541 | static void print_func_help_header(struct seq_file *m) |
bc0c38d1 | 1542 | { |
a6168353 ME |
1543 | seq_puts(m, "# TASK-PID CPU# TIMESTAMP FUNCTION\n"); |
1544 | seq_puts(m, "# | | | | |\n"); | |
bc0c38d1 SR |
1545 | } |
1546 | ||
1547 | ||
e309b41d | 1548 | static void |
bc0c38d1 SR |
1549 | print_trace_header(struct seq_file *m, struct trace_iterator *iter) |
1550 | { | |
1551 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); | |
1552 | struct trace_array *tr = iter->tr; | |
1553 | struct trace_array_cpu *data = tr->data[tr->cpu]; | |
1554 | struct tracer *type = current_trace; | |
3928a8a2 SR |
1555 | unsigned long total; |
1556 | unsigned long entries; | |
bc0c38d1 SR |
1557 | const char *name = "preemption"; |
1558 | ||
1559 | if (type) | |
1560 | name = type->name; | |
1561 | ||
3928a8a2 SR |
1562 | entries = ring_buffer_entries(iter->tr->buffer); |
1563 | total = entries + | |
1564 | ring_buffer_overruns(iter->tr->buffer); | |
bc0c38d1 | 1565 | |
888b55dc | 1566 | seq_printf(m, "# %s latency trace v1.1.5 on %s\n", |
bc0c38d1 | 1567 | name, UTS_RELEASE); |
888b55dc | 1568 | seq_puts(m, "# -----------------------------------" |
bc0c38d1 | 1569 | "---------------------------------\n"); |
888b55dc | 1570 | seq_printf(m, "# latency: %lu us, #%lu/%lu, CPU#%d |" |
bc0c38d1 | 1571 | " (M:%s VP:%d, KP:%d, SP:%d HP:%d", |
57f50be1 | 1572 | nsecs_to_usecs(data->saved_latency), |
bc0c38d1 | 1573 | entries, |
4c11d7ae | 1574 | total, |
bc0c38d1 SR |
1575 | tr->cpu, |
1576 | #if defined(CONFIG_PREEMPT_NONE) | |
1577 | "server", | |
1578 | #elif defined(CONFIG_PREEMPT_VOLUNTARY) | |
1579 | "desktop", | |
b5c21b45 | 1580 | #elif defined(CONFIG_PREEMPT) |
bc0c38d1 SR |
1581 | "preempt", |
1582 | #else | |
1583 | "unknown", | |
1584 | #endif | |
1585 | /* These are reserved for later use */ | |
1586 | 0, 0, 0, 0); | |
1587 | #ifdef CONFIG_SMP | |
1588 | seq_printf(m, " #P:%d)\n", num_online_cpus()); | |
1589 | #else | |
1590 | seq_puts(m, ")\n"); | |
1591 | #endif | |
888b55dc KM |
1592 | seq_puts(m, "# -----------------\n"); |
1593 | seq_printf(m, "# | task: %.16s-%d " | |
bc0c38d1 SR |
1594 | "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n", |
1595 | data->comm, data->pid, data->uid, data->nice, | |
1596 | data->policy, data->rt_priority); | |
888b55dc | 1597 | seq_puts(m, "# -----------------\n"); |
bc0c38d1 SR |
1598 | |
1599 | if (data->critical_start) { | |
888b55dc | 1600 | seq_puts(m, "# => started at: "); |
214023c3 SR |
1601 | seq_print_ip_sym(&iter->seq, data->critical_start, sym_flags); |
1602 | trace_print_seq(m, &iter->seq); | |
888b55dc | 1603 | seq_puts(m, "\n# => ended at: "); |
214023c3 SR |
1604 | seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags); |
1605 | trace_print_seq(m, &iter->seq); | |
888b55dc | 1606 | seq_puts(m, "#\n"); |
bc0c38d1 SR |
1607 | } |
1608 | ||
888b55dc | 1609 | seq_puts(m, "#\n"); |
bc0c38d1 SR |
1610 | } |
1611 | ||
a309720c SR |
1612 | static void test_cpu_buff_start(struct trace_iterator *iter) |
1613 | { | |
1614 | struct trace_seq *s = &iter->seq; | |
1615 | ||
12ef7d44 SR |
1616 | if (!(trace_flags & TRACE_ITER_ANNOTATE)) |
1617 | return; | |
1618 | ||
1619 | if (!(iter->iter_flags & TRACE_FILE_ANNOTATE)) | |
1620 | return; | |
1621 | ||
4462344e | 1622 | if (cpumask_test_cpu(iter->cpu, iter->started)) |
a309720c SR |
1623 | return; |
1624 | ||
4462344e | 1625 | cpumask_set_cpu(iter->cpu, iter->started); |
b0dfa978 FW |
1626 | |
1627 | /* Don't print started cpu buffer for the first entry of the trace */ | |
1628 | if (iter->idx > 1) | |
1629 | trace_seq_printf(s, "##### CPU %u buffer started ####\n", | |
1630 | iter->cpu); | |
a309720c SR |
1631 | } |
1632 | ||
2c4f035f | 1633 | static enum print_line_t print_trace_fmt(struct trace_iterator *iter) |
bc0c38d1 | 1634 | { |
214023c3 | 1635 | struct trace_seq *s = &iter->seq; |
bc0c38d1 | 1636 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
4e3c3333 | 1637 | struct trace_entry *entry; |
f633cef0 | 1638 | struct trace_event *event; |
bc0c38d1 | 1639 | |
4e3c3333 | 1640 | entry = iter->ent; |
dd0e545f | 1641 | |
a309720c SR |
1642 | test_cpu_buff_start(iter); |
1643 | ||
c4a8e8be | 1644 | event = ftrace_find_event(entry->type); |
bc0c38d1 | 1645 | |
c4a8e8be | 1646 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
27d48be8 SR |
1647 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) { |
1648 | if (!trace_print_lat_context(iter)) | |
1649 | goto partial; | |
1650 | } else { | |
1651 | if (!trace_print_context(iter)) | |
1652 | goto partial; | |
1653 | } | |
c4a8e8be | 1654 | } |
bc0c38d1 | 1655 | |
268ccda0 | 1656 | if (event) |
d9793bd8 ACM |
1657 | return event->trace(iter, sym_flags); |
1658 | ||
1659 | if (!trace_seq_printf(s, "Unknown type %d\n", entry->type)) | |
1660 | goto partial; | |
02b67518 | 1661 | |
2c4f035f | 1662 | return TRACE_TYPE_HANDLED; |
d9793bd8 ACM |
1663 | partial: |
1664 | return TRACE_TYPE_PARTIAL_LINE; | |
bc0c38d1 SR |
1665 | } |
1666 | ||
2c4f035f | 1667 | static enum print_line_t print_raw_fmt(struct trace_iterator *iter) |
f9896bf3 IM |
1668 | { |
1669 | struct trace_seq *s = &iter->seq; | |
1670 | struct trace_entry *entry; | |
f633cef0 | 1671 | struct trace_event *event; |
f9896bf3 IM |
1672 | |
1673 | entry = iter->ent; | |
dd0e545f | 1674 | |
c4a8e8be | 1675 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
d9793bd8 ACM |
1676 | if (!trace_seq_printf(s, "%d %d %llu ", |
1677 | entry->pid, iter->cpu, iter->ts)) | |
1678 | goto partial; | |
c4a8e8be | 1679 | } |
f9896bf3 | 1680 | |
f633cef0 | 1681 | event = ftrace_find_event(entry->type); |
268ccda0 | 1682 | if (event) |
d9793bd8 ACM |
1683 | return event->raw(iter, 0); |
1684 | ||
1685 | if (!trace_seq_printf(s, "%d ?\n", entry->type)) | |
1686 | goto partial; | |
777e208d | 1687 | |
2c4f035f | 1688 | return TRACE_TYPE_HANDLED; |
d9793bd8 ACM |
1689 | partial: |
1690 | return TRACE_TYPE_PARTIAL_LINE; | |
f9896bf3 IM |
1691 | } |
1692 | ||
2c4f035f | 1693 | static enum print_line_t print_hex_fmt(struct trace_iterator *iter) |
5e3ca0ec IM |
1694 | { |
1695 | struct trace_seq *s = &iter->seq; | |
1696 | unsigned char newline = '\n'; | |
1697 | struct trace_entry *entry; | |
f633cef0 | 1698 | struct trace_event *event; |
5e3ca0ec IM |
1699 | |
1700 | entry = iter->ent; | |
dd0e545f | 1701 | |
c4a8e8be FW |
1702 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
1703 | SEQ_PUT_HEX_FIELD_RET(s, entry->pid); | |
1704 | SEQ_PUT_HEX_FIELD_RET(s, iter->cpu); | |
1705 | SEQ_PUT_HEX_FIELD_RET(s, iter->ts); | |
1706 | } | |
5e3ca0ec | 1707 | |
f633cef0 | 1708 | event = ftrace_find_event(entry->type); |
268ccda0 | 1709 | if (event) { |
ae7462b4 | 1710 | enum print_line_t ret = event->hex(iter, 0); |
d9793bd8 ACM |
1711 | if (ret != TRACE_TYPE_HANDLED) |
1712 | return ret; | |
1713 | } | |
7104f300 | 1714 | |
5e3ca0ec IM |
1715 | SEQ_PUT_FIELD_RET(s, newline); |
1716 | ||
2c4f035f | 1717 | return TRACE_TYPE_HANDLED; |
5e3ca0ec IM |
1718 | } |
1719 | ||
2c4f035f | 1720 | static enum print_line_t print_bin_fmt(struct trace_iterator *iter) |
cb0f12aa IM |
1721 | { |
1722 | struct trace_seq *s = &iter->seq; | |
1723 | struct trace_entry *entry; | |
f633cef0 | 1724 | struct trace_event *event; |
cb0f12aa IM |
1725 | |
1726 | entry = iter->ent; | |
dd0e545f | 1727 | |
c4a8e8be FW |
1728 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
1729 | SEQ_PUT_FIELD_RET(s, entry->pid); | |
1830b52d | 1730 | SEQ_PUT_FIELD_RET(s, iter->cpu); |
c4a8e8be FW |
1731 | SEQ_PUT_FIELD_RET(s, iter->ts); |
1732 | } | |
cb0f12aa | 1733 | |
f633cef0 | 1734 | event = ftrace_find_event(entry->type); |
268ccda0 | 1735 | return event ? event->binary(iter, 0) : TRACE_TYPE_HANDLED; |
cb0f12aa IM |
1736 | } |
1737 | ||
bc0c38d1 SR |
1738 | static int trace_empty(struct trace_iterator *iter) |
1739 | { | |
bc0c38d1 SR |
1740 | int cpu; |
1741 | ||
9aba60fe SR |
1742 | /* If we are looking at one CPU buffer, only check that one */ |
1743 | if (iter->cpu_file != TRACE_PIPE_ALL_CPU) { | |
1744 | cpu = iter->cpu_file; | |
1745 | if (iter->buffer_iter[cpu]) { | |
1746 | if (!ring_buffer_iter_empty(iter->buffer_iter[cpu])) | |
1747 | return 0; | |
1748 | } else { | |
1749 | if (!ring_buffer_empty_cpu(iter->tr->buffer, cpu)) | |
1750 | return 0; | |
1751 | } | |
1752 | return 1; | |
1753 | } | |
1754 | ||
ab46428c | 1755 | for_each_tracing_cpu(cpu) { |
d769041f SR |
1756 | if (iter->buffer_iter[cpu]) { |
1757 | if (!ring_buffer_iter_empty(iter->buffer_iter[cpu])) | |
1758 | return 0; | |
1759 | } else { | |
1760 | if (!ring_buffer_empty_cpu(iter->tr->buffer, cpu)) | |
1761 | return 0; | |
1762 | } | |
bc0c38d1 | 1763 | } |
d769041f | 1764 | |
797d3712 | 1765 | return 1; |
bc0c38d1 SR |
1766 | } |
1767 | ||
2c4f035f | 1768 | static enum print_line_t print_trace_line(struct trace_iterator *iter) |
f9896bf3 | 1769 | { |
2c4f035f FW |
1770 | enum print_line_t ret; |
1771 | ||
1772 | if (iter->trace && iter->trace->print_line) { | |
1773 | ret = iter->trace->print_line(iter); | |
1774 | if (ret != TRACE_TYPE_UNHANDLED) | |
1775 | return ret; | |
1776 | } | |
72829bc3 | 1777 | |
48ead020 FW |
1778 | if (iter->ent->type == TRACE_BPRINT && |
1779 | trace_flags & TRACE_ITER_PRINTK && | |
1780 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) | |
5ef841f6 | 1781 | return trace_print_bprintk_msg_only(iter); |
48ead020 | 1782 | |
66896a85 FW |
1783 | if (iter->ent->type == TRACE_PRINT && |
1784 | trace_flags & TRACE_ITER_PRINTK && | |
1785 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) | |
5ef841f6 | 1786 | return trace_print_printk_msg_only(iter); |
66896a85 | 1787 | |
cb0f12aa IM |
1788 | if (trace_flags & TRACE_ITER_BIN) |
1789 | return print_bin_fmt(iter); | |
1790 | ||
5e3ca0ec IM |
1791 | if (trace_flags & TRACE_ITER_HEX) |
1792 | return print_hex_fmt(iter); | |
1793 | ||
f9896bf3 IM |
1794 | if (trace_flags & TRACE_ITER_RAW) |
1795 | return print_raw_fmt(iter); | |
1796 | ||
f9896bf3 IM |
1797 | return print_trace_fmt(iter); |
1798 | } | |
1799 | ||
bc0c38d1 SR |
1800 | static int s_show(struct seq_file *m, void *v) |
1801 | { | |
1802 | struct trace_iterator *iter = v; | |
1803 | ||
1804 | if (iter->ent == NULL) { | |
1805 | if (iter->tr) { | |
1806 | seq_printf(m, "# tracer: %s\n", iter->trace->name); | |
1807 | seq_puts(m, "#\n"); | |
1808 | } | |
8bba1bf5 MM |
1809 | if (iter->trace && iter->trace->print_header) |
1810 | iter->trace->print_header(m); | |
1811 | else if (iter->iter_flags & TRACE_FILE_LAT_FMT) { | |
bc0c38d1 SR |
1812 | /* print nothing if the buffers are empty */ |
1813 | if (trace_empty(iter)) | |
1814 | return 0; | |
1815 | print_trace_header(m, iter); | |
1816 | if (!(trace_flags & TRACE_ITER_VERBOSE)) | |
1817 | print_lat_help_header(m); | |
1818 | } else { | |
1819 | if (!(trace_flags & TRACE_ITER_VERBOSE)) | |
1820 | print_func_help_header(m); | |
1821 | } | |
1822 | } else { | |
f9896bf3 | 1823 | print_trace_line(iter); |
214023c3 | 1824 | trace_print_seq(m, &iter->seq); |
bc0c38d1 SR |
1825 | } |
1826 | ||
1827 | return 0; | |
1828 | } | |
1829 | ||
1830 | static struct seq_operations tracer_seq_ops = { | |
4bf39a94 IM |
1831 | .start = s_start, |
1832 | .next = s_next, | |
1833 | .stop = s_stop, | |
1834 | .show = s_show, | |
bc0c38d1 SR |
1835 | }; |
1836 | ||
e309b41d | 1837 | static struct trace_iterator * |
85a2f9b4 | 1838 | __tracing_open(struct inode *inode, struct file *file) |
bc0c38d1 | 1839 | { |
b04cc6b1 | 1840 | long cpu_file = (long) inode->i_private; |
85a2f9b4 | 1841 | void *fail_ret = ERR_PTR(-ENOMEM); |
bc0c38d1 | 1842 | struct trace_iterator *iter; |
3928a8a2 | 1843 | struct seq_file *m; |
85a2f9b4 | 1844 | int cpu, ret; |
bc0c38d1 | 1845 | |
85a2f9b4 SR |
1846 | if (tracing_disabled) |
1847 | return ERR_PTR(-ENODEV); | |
60a11774 | 1848 | |
bc0c38d1 | 1849 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
85a2f9b4 SR |
1850 | if (!iter) |
1851 | return ERR_PTR(-ENOMEM); | |
bc0c38d1 | 1852 | |
d7350c3f FW |
1853 | /* |
1854 | * We make a copy of the current tracer to avoid concurrent | |
1855 | * changes on it while we are reading. | |
1856 | */ | |
bc0c38d1 | 1857 | mutex_lock(&trace_types_lock); |
d7350c3f | 1858 | iter->trace = kzalloc(sizeof(*iter->trace), GFP_KERNEL); |
85a2f9b4 | 1859 | if (!iter->trace) |
d7350c3f | 1860 | goto fail; |
85a2f9b4 | 1861 | |
d7350c3f FW |
1862 | if (current_trace) |
1863 | *iter->trace = *current_trace; | |
1864 | ||
b0dfa978 FW |
1865 | if (!alloc_cpumask_var(&iter->started, GFP_KERNEL)) |
1866 | goto fail; | |
1867 | ||
1868 | cpumask_clear(iter->started); | |
1869 | ||
bc0c38d1 SR |
1870 | if (current_trace && current_trace->print_max) |
1871 | iter->tr = &max_tr; | |
1872 | else | |
b04cc6b1 | 1873 | iter->tr = &global_trace; |
bc0c38d1 | 1874 | iter->pos = -1; |
d7350c3f | 1875 | mutex_init(&iter->mutex); |
b04cc6b1 | 1876 | iter->cpu_file = cpu_file; |
bc0c38d1 | 1877 | |
8bba1bf5 MM |
1878 | /* Notify the tracer early; before we stop tracing. */ |
1879 | if (iter->trace && iter->trace->open) | |
a93751ca | 1880 | iter->trace->open(iter); |
8bba1bf5 | 1881 | |
12ef7d44 SR |
1882 | /* Annotate start of buffers if we had overruns */ |
1883 | if (ring_buffer_overruns(iter->tr->buffer)) | |
1884 | iter->iter_flags |= TRACE_FILE_ANNOTATE; | |
1885 | ||
b04cc6b1 FW |
1886 | if (iter->cpu_file == TRACE_PIPE_ALL_CPU) { |
1887 | for_each_tracing_cpu(cpu) { | |
12ef7d44 | 1888 | |
b04cc6b1 FW |
1889 | iter->buffer_iter[cpu] = |
1890 | ring_buffer_read_start(iter->tr->buffer, cpu); | |
b04cc6b1 FW |
1891 | } |
1892 | } else { | |
1893 | cpu = iter->cpu_file; | |
3928a8a2 | 1894 | iter->buffer_iter[cpu] = |
b04cc6b1 | 1895 | ring_buffer_read_start(iter->tr->buffer, cpu); |
3928a8a2 SR |
1896 | } |
1897 | ||
bc0c38d1 | 1898 | /* TODO stop tracer */ |
85a2f9b4 SR |
1899 | ret = seq_open(file, &tracer_seq_ops); |
1900 | if (ret < 0) { | |
1901 | fail_ret = ERR_PTR(ret); | |
3928a8a2 | 1902 | goto fail_buffer; |
85a2f9b4 | 1903 | } |
bc0c38d1 | 1904 | |
3928a8a2 SR |
1905 | m = file->private_data; |
1906 | m->private = iter; | |
bc0c38d1 | 1907 | |
3928a8a2 | 1908 | /* stop the trace while dumping */ |
9036990d | 1909 | tracing_stop(); |
3928a8a2 | 1910 | |
bc0c38d1 SR |
1911 | mutex_unlock(&trace_types_lock); |
1912 | ||
bc0c38d1 | 1913 | return iter; |
3928a8a2 SR |
1914 | |
1915 | fail_buffer: | |
1916 | for_each_tracing_cpu(cpu) { | |
1917 | if (iter->buffer_iter[cpu]) | |
1918 | ring_buffer_read_finish(iter->buffer_iter[cpu]); | |
1919 | } | |
b0dfa978 | 1920 | free_cpumask_var(iter->started); |
d7350c3f | 1921 | fail: |
3928a8a2 | 1922 | mutex_unlock(&trace_types_lock); |
d7350c3f | 1923 | kfree(iter->trace); |
0bb943c7 | 1924 | kfree(iter); |
3928a8a2 | 1925 | |
85a2f9b4 | 1926 | return fail_ret; |
bc0c38d1 SR |
1927 | } |
1928 | ||
1929 | int tracing_open_generic(struct inode *inode, struct file *filp) | |
1930 | { | |
60a11774 SR |
1931 | if (tracing_disabled) |
1932 | return -ENODEV; | |
1933 | ||
bc0c38d1 SR |
1934 | filp->private_data = inode->i_private; |
1935 | return 0; | |
1936 | } | |
1937 | ||
4fd27358 | 1938 | static int tracing_release(struct inode *inode, struct file *file) |
bc0c38d1 SR |
1939 | { |
1940 | struct seq_file *m = (struct seq_file *)file->private_data; | |
4acd4d00 | 1941 | struct trace_iterator *iter; |
3928a8a2 | 1942 | int cpu; |
bc0c38d1 | 1943 | |
4acd4d00 SR |
1944 | if (!(file->f_mode & FMODE_READ)) |
1945 | return 0; | |
1946 | ||
1947 | iter = m->private; | |
1948 | ||
bc0c38d1 | 1949 | mutex_lock(&trace_types_lock); |
3928a8a2 SR |
1950 | for_each_tracing_cpu(cpu) { |
1951 | if (iter->buffer_iter[cpu]) | |
1952 | ring_buffer_read_finish(iter->buffer_iter[cpu]); | |
1953 | } | |
1954 | ||
bc0c38d1 SR |
1955 | if (iter->trace && iter->trace->close) |
1956 | iter->trace->close(iter); | |
1957 | ||
1958 | /* reenable tracing if it was previously enabled */ | |
9036990d | 1959 | tracing_start(); |
bc0c38d1 SR |
1960 | mutex_unlock(&trace_types_lock); |
1961 | ||
1962 | seq_release(inode, file); | |
d7350c3f | 1963 | mutex_destroy(&iter->mutex); |
b0dfa978 | 1964 | free_cpumask_var(iter->started); |
d7350c3f | 1965 | kfree(iter->trace); |
bc0c38d1 SR |
1966 | kfree(iter); |
1967 | return 0; | |
1968 | } | |
1969 | ||
1970 | static int tracing_open(struct inode *inode, struct file *file) | |
1971 | { | |
85a2f9b4 SR |
1972 | struct trace_iterator *iter; |
1973 | int ret = 0; | |
bc0c38d1 | 1974 | |
4acd4d00 SR |
1975 | /* If this file was open for write, then erase contents */ |
1976 | if ((file->f_mode & FMODE_WRITE) && | |
1977 | !(file->f_flags & O_APPEND)) { | |
1978 | long cpu = (long) inode->i_private; | |
bc0c38d1 | 1979 | |
4acd4d00 SR |
1980 | if (cpu == TRACE_PIPE_ALL_CPU) |
1981 | tracing_reset_online_cpus(&global_trace); | |
1982 | else | |
1983 | tracing_reset(&global_trace, cpu); | |
1984 | } | |
bc0c38d1 | 1985 | |
4acd4d00 SR |
1986 | if (file->f_mode & FMODE_READ) { |
1987 | iter = __tracing_open(inode, file); | |
1988 | if (IS_ERR(iter)) | |
1989 | ret = PTR_ERR(iter); | |
1990 | else if (trace_flags & TRACE_ITER_LATENCY_FMT) | |
1991 | iter->iter_flags |= TRACE_FILE_LAT_FMT; | |
1992 | } | |
bc0c38d1 SR |
1993 | return ret; |
1994 | } | |
1995 | ||
e309b41d | 1996 | static void * |
bc0c38d1 SR |
1997 | t_next(struct seq_file *m, void *v, loff_t *pos) |
1998 | { | |
1999 | struct tracer *t = m->private; | |
2000 | ||
2001 | (*pos)++; | |
2002 | ||
2003 | if (t) | |
2004 | t = t->next; | |
2005 | ||
2006 | m->private = t; | |
2007 | ||
2008 | return t; | |
2009 | } | |
2010 | ||
2011 | static void *t_start(struct seq_file *m, loff_t *pos) | |
2012 | { | |
2013 | struct tracer *t = m->private; | |
2014 | loff_t l = 0; | |
2015 | ||
2016 | mutex_lock(&trace_types_lock); | |
2017 | for (; t && l < *pos; t = t_next(m, t, &l)) | |
2018 | ; | |
2019 | ||
2020 | return t; | |
2021 | } | |
2022 | ||
2023 | static void t_stop(struct seq_file *m, void *p) | |
2024 | { | |
2025 | mutex_unlock(&trace_types_lock); | |
2026 | } | |
2027 | ||
2028 | static int t_show(struct seq_file *m, void *v) | |
2029 | { | |
2030 | struct tracer *t = v; | |
2031 | ||
2032 | if (!t) | |
2033 | return 0; | |
2034 | ||
2035 | seq_printf(m, "%s", t->name); | |
2036 | if (t->next) | |
2037 | seq_putc(m, ' '); | |
2038 | else | |
2039 | seq_putc(m, '\n'); | |
2040 | ||
2041 | return 0; | |
2042 | } | |
2043 | ||
2044 | static struct seq_operations show_traces_seq_ops = { | |
4bf39a94 IM |
2045 | .start = t_start, |
2046 | .next = t_next, | |
2047 | .stop = t_stop, | |
2048 | .show = t_show, | |
bc0c38d1 SR |
2049 | }; |
2050 | ||
2051 | static int show_traces_open(struct inode *inode, struct file *file) | |
2052 | { | |
2053 | int ret; | |
2054 | ||
60a11774 SR |
2055 | if (tracing_disabled) |
2056 | return -ENODEV; | |
2057 | ||
bc0c38d1 SR |
2058 | ret = seq_open(file, &show_traces_seq_ops); |
2059 | if (!ret) { | |
2060 | struct seq_file *m = file->private_data; | |
2061 | m->private = trace_types; | |
2062 | } | |
2063 | ||
2064 | return ret; | |
2065 | } | |
2066 | ||
4acd4d00 SR |
2067 | static ssize_t |
2068 | tracing_write_stub(struct file *filp, const char __user *ubuf, | |
2069 | size_t count, loff_t *ppos) | |
2070 | { | |
2071 | return count; | |
2072 | } | |
2073 | ||
5e2336a0 | 2074 | static const struct file_operations tracing_fops = { |
4bf39a94 IM |
2075 | .open = tracing_open, |
2076 | .read = seq_read, | |
4acd4d00 | 2077 | .write = tracing_write_stub, |
4bf39a94 IM |
2078 | .llseek = seq_lseek, |
2079 | .release = tracing_release, | |
bc0c38d1 SR |
2080 | }; |
2081 | ||
5e2336a0 | 2082 | static const struct file_operations show_traces_fops = { |
c7078de1 IM |
2083 | .open = show_traces_open, |
2084 | .read = seq_read, | |
2085 | .release = seq_release, | |
2086 | }; | |
2087 | ||
36dfe925 IM |
2088 | /* |
2089 | * Only trace on a CPU if the bitmask is set: | |
2090 | */ | |
9e01c1b7 | 2091 | static cpumask_var_t tracing_cpumask; |
36dfe925 IM |
2092 | |
2093 | /* | |
2094 | * The tracer itself will not take this lock, but still we want | |
2095 | * to provide a consistent cpumask to user-space: | |
2096 | */ | |
2097 | static DEFINE_MUTEX(tracing_cpumask_update_lock); | |
2098 | ||
2099 | /* | |
2100 | * Temporary storage for the character representation of the | |
2101 | * CPU bitmask (and one more byte for the newline): | |
2102 | */ | |
2103 | static char mask_str[NR_CPUS + 1]; | |
2104 | ||
c7078de1 IM |
2105 | static ssize_t |
2106 | tracing_cpumask_read(struct file *filp, char __user *ubuf, | |
2107 | size_t count, loff_t *ppos) | |
2108 | { | |
36dfe925 | 2109 | int len; |
c7078de1 IM |
2110 | |
2111 | mutex_lock(&tracing_cpumask_update_lock); | |
36dfe925 | 2112 | |
9e01c1b7 | 2113 | len = cpumask_scnprintf(mask_str, count, tracing_cpumask); |
36dfe925 IM |
2114 | if (count - len < 2) { |
2115 | count = -EINVAL; | |
2116 | goto out_err; | |
2117 | } | |
2118 | len += sprintf(mask_str + len, "\n"); | |
2119 | count = simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+1); | |
2120 | ||
2121 | out_err: | |
c7078de1 IM |
2122 | mutex_unlock(&tracing_cpumask_update_lock); |
2123 | ||
2124 | return count; | |
2125 | } | |
2126 | ||
2127 | static ssize_t | |
2128 | tracing_cpumask_write(struct file *filp, const char __user *ubuf, | |
2129 | size_t count, loff_t *ppos) | |
2130 | { | |
36dfe925 | 2131 | int err, cpu; |
9e01c1b7 RR |
2132 | cpumask_var_t tracing_cpumask_new; |
2133 | ||
2134 | if (!alloc_cpumask_var(&tracing_cpumask_new, GFP_KERNEL)) | |
2135 | return -ENOMEM; | |
c7078de1 IM |
2136 | |
2137 | mutex_lock(&tracing_cpumask_update_lock); | |
9e01c1b7 | 2138 | err = cpumask_parse_user(ubuf, count, tracing_cpumask_new); |
c7078de1 | 2139 | if (err) |
36dfe925 IM |
2140 | goto err_unlock; |
2141 | ||
a5e25883 | 2142 | local_irq_disable(); |
92205c23 | 2143 | __raw_spin_lock(&ftrace_max_lock); |
ab46428c | 2144 | for_each_tracing_cpu(cpu) { |
36dfe925 IM |
2145 | /* |
2146 | * Increase/decrease the disabled counter if we are | |
2147 | * about to flip a bit in the cpumask: | |
2148 | */ | |
9e01c1b7 RR |
2149 | if (cpumask_test_cpu(cpu, tracing_cpumask) && |
2150 | !cpumask_test_cpu(cpu, tracing_cpumask_new)) { | |
36dfe925 IM |
2151 | atomic_inc(&global_trace.data[cpu]->disabled); |
2152 | } | |
9e01c1b7 RR |
2153 | if (!cpumask_test_cpu(cpu, tracing_cpumask) && |
2154 | cpumask_test_cpu(cpu, tracing_cpumask_new)) { | |
36dfe925 IM |
2155 | atomic_dec(&global_trace.data[cpu]->disabled); |
2156 | } | |
2157 | } | |
92205c23 | 2158 | __raw_spin_unlock(&ftrace_max_lock); |
a5e25883 | 2159 | local_irq_enable(); |
36dfe925 | 2160 | |
9e01c1b7 | 2161 | cpumask_copy(tracing_cpumask, tracing_cpumask_new); |
36dfe925 IM |
2162 | |
2163 | mutex_unlock(&tracing_cpumask_update_lock); | |
9e01c1b7 | 2164 | free_cpumask_var(tracing_cpumask_new); |
c7078de1 IM |
2165 | |
2166 | return count; | |
36dfe925 IM |
2167 | |
2168 | err_unlock: | |
2169 | mutex_unlock(&tracing_cpumask_update_lock); | |
9e01c1b7 | 2170 | free_cpumask_var(tracing_cpumask); |
36dfe925 IM |
2171 | |
2172 | return err; | |
c7078de1 IM |
2173 | } |
2174 | ||
5e2336a0 | 2175 | static const struct file_operations tracing_cpumask_fops = { |
c7078de1 IM |
2176 | .open = tracing_open_generic, |
2177 | .read = tracing_cpumask_read, | |
2178 | .write = tracing_cpumask_write, | |
bc0c38d1 SR |
2179 | }; |
2180 | ||
2181 | static ssize_t | |
ee6bce52 | 2182 | tracing_trace_options_read(struct file *filp, char __user *ubuf, |
bc0c38d1 SR |
2183 | size_t cnt, loff_t *ppos) |
2184 | { | |
d8e83d26 SR |
2185 | struct tracer_opt *trace_opts; |
2186 | u32 tracer_flags; | |
2187 | int len = 0; | |
bc0c38d1 SR |
2188 | char *buf; |
2189 | int r = 0; | |
d8e83d26 | 2190 | int i; |
adf9f195 | 2191 | |
bc0c38d1 | 2192 | |
c3706f00 | 2193 | /* calculate max size */ |
bc0c38d1 SR |
2194 | for (i = 0; trace_options[i]; i++) { |
2195 | len += strlen(trace_options[i]); | |
5c6a3ae1 | 2196 | len += 3; /* "no" and newline */ |
bc0c38d1 SR |
2197 | } |
2198 | ||
d8e83d26 SR |
2199 | mutex_lock(&trace_types_lock); |
2200 | tracer_flags = current_trace->flags->val; | |
2201 | trace_opts = current_trace->flags->opts; | |
2202 | ||
adf9f195 FW |
2203 | /* |
2204 | * Increase the size with names of options specific | |
2205 | * of the current tracer. | |
2206 | */ | |
2207 | for (i = 0; trace_opts[i].name; i++) { | |
2208 | len += strlen(trace_opts[i].name); | |
5c6a3ae1 | 2209 | len += 3; /* "no" and newline */ |
adf9f195 FW |
2210 | } |
2211 | ||
bc0c38d1 SR |
2212 | /* +2 for \n and \0 */ |
2213 | buf = kmalloc(len + 2, GFP_KERNEL); | |
d8e83d26 SR |
2214 | if (!buf) { |
2215 | mutex_unlock(&trace_types_lock); | |
bc0c38d1 | 2216 | return -ENOMEM; |
d8e83d26 | 2217 | } |
bc0c38d1 SR |
2218 | |
2219 | for (i = 0; trace_options[i]; i++) { | |
2220 | if (trace_flags & (1 << i)) | |
5c6a3ae1 | 2221 | r += sprintf(buf + r, "%s\n", trace_options[i]); |
bc0c38d1 | 2222 | else |
5c6a3ae1 | 2223 | r += sprintf(buf + r, "no%s\n", trace_options[i]); |
bc0c38d1 SR |
2224 | } |
2225 | ||
adf9f195 FW |
2226 | for (i = 0; trace_opts[i].name; i++) { |
2227 | if (tracer_flags & trace_opts[i].bit) | |
5c6a3ae1 | 2228 | r += sprintf(buf + r, "%s\n", |
adf9f195 FW |
2229 | trace_opts[i].name); |
2230 | else | |
5c6a3ae1 | 2231 | r += sprintf(buf + r, "no%s\n", |
adf9f195 FW |
2232 | trace_opts[i].name); |
2233 | } | |
d8e83d26 | 2234 | mutex_unlock(&trace_types_lock); |
adf9f195 | 2235 | |
bc0c38d1 SR |
2236 | WARN_ON(r >= len + 2); |
2237 | ||
36dfe925 | 2238 | r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
bc0c38d1 SR |
2239 | |
2240 | kfree(buf); | |
bc0c38d1 SR |
2241 | return r; |
2242 | } | |
2243 | ||
adf9f195 FW |
2244 | /* Try to assign a tracer specific option */ |
2245 | static int set_tracer_option(struct tracer *trace, char *cmp, int neg) | |
2246 | { | |
2247 | struct tracer_flags *trace_flags = trace->flags; | |
2248 | struct tracer_opt *opts = NULL; | |
2249 | int ret = 0, i = 0; | |
2250 | int len; | |
2251 | ||
2252 | for (i = 0; trace_flags->opts[i].name; i++) { | |
2253 | opts = &trace_flags->opts[i]; | |
2254 | len = strlen(opts->name); | |
2255 | ||
2256 | if (strncmp(cmp, opts->name, len) == 0) { | |
2257 | ret = trace->set_flag(trace_flags->val, | |
2258 | opts->bit, !neg); | |
2259 | break; | |
2260 | } | |
2261 | } | |
2262 | /* Not found */ | |
2263 | if (!trace_flags->opts[i].name) | |
2264 | return -EINVAL; | |
2265 | ||
2266 | /* Refused to handle */ | |
2267 | if (ret) | |
2268 | return ret; | |
2269 | ||
2270 | if (neg) | |
2271 | trace_flags->val &= ~opts->bit; | |
2272 | else | |
2273 | trace_flags->val |= opts->bit; | |
2274 | ||
2275 | return 0; | |
2276 | } | |
2277 | ||
af4617bd SR |
2278 | static void set_tracer_flags(unsigned int mask, int enabled) |
2279 | { | |
2280 | /* do nothing if flag is already set */ | |
2281 | if (!!(trace_flags & mask) == !!enabled) | |
2282 | return; | |
2283 | ||
2284 | if (enabled) | |
2285 | trace_flags |= mask; | |
2286 | else | |
2287 | trace_flags &= ~mask; | |
2288 | ||
2289 | if (mask == TRACE_ITER_GLOBAL_CLK) { | |
2290 | u64 (*func)(void); | |
2291 | ||
2292 | if (enabled) | |
2293 | func = trace_clock_global; | |
2294 | else | |
2295 | func = trace_clock_local; | |
2296 | ||
2297 | mutex_lock(&trace_types_lock); | |
2298 | ring_buffer_set_clock(global_trace.buffer, func); | |
2299 | ||
2300 | if (max_tr.buffer) | |
2301 | ring_buffer_set_clock(max_tr.buffer, func); | |
2302 | mutex_unlock(&trace_types_lock); | |
2303 | } | |
2304 | } | |
2305 | ||
bc0c38d1 | 2306 | static ssize_t |
ee6bce52 | 2307 | tracing_trace_options_write(struct file *filp, const char __user *ubuf, |
bc0c38d1 SR |
2308 | size_t cnt, loff_t *ppos) |
2309 | { | |
2310 | char buf[64]; | |
2311 | char *cmp = buf; | |
2312 | int neg = 0; | |
adf9f195 | 2313 | int ret; |
bc0c38d1 SR |
2314 | int i; |
2315 | ||
cffae437 SR |
2316 | if (cnt >= sizeof(buf)) |
2317 | return -EINVAL; | |
bc0c38d1 SR |
2318 | |
2319 | if (copy_from_user(&buf, ubuf, cnt)) | |
2320 | return -EFAULT; | |
2321 | ||
2322 | buf[cnt] = 0; | |
2323 | ||
2324 | if (strncmp(buf, "no", 2) == 0) { | |
2325 | neg = 1; | |
2326 | cmp += 2; | |
2327 | } | |
2328 | ||
2329 | for (i = 0; trace_options[i]; i++) { | |
2330 | int len = strlen(trace_options[i]); | |
2331 | ||
2332 | if (strncmp(cmp, trace_options[i], len) == 0) { | |
af4617bd | 2333 | set_tracer_flags(1 << i, !neg); |
bc0c38d1 SR |
2334 | break; |
2335 | } | |
2336 | } | |
adf9f195 FW |
2337 | |
2338 | /* If no option could be set, test the specific tracer options */ | |
2339 | if (!trace_options[i]) { | |
d8e83d26 | 2340 | mutex_lock(&trace_types_lock); |
adf9f195 | 2341 | ret = set_tracer_option(current_trace, cmp, neg); |
d8e83d26 | 2342 | mutex_unlock(&trace_types_lock); |
adf9f195 FW |
2343 | if (ret) |
2344 | return ret; | |
2345 | } | |
bc0c38d1 SR |
2346 | |
2347 | filp->f_pos += cnt; | |
2348 | ||
2349 | return cnt; | |
2350 | } | |
2351 | ||
5e2336a0 | 2352 | static const struct file_operations tracing_iter_fops = { |
c7078de1 | 2353 | .open = tracing_open_generic, |
ee6bce52 SR |
2354 | .read = tracing_trace_options_read, |
2355 | .write = tracing_trace_options_write, | |
bc0c38d1 SR |
2356 | }; |
2357 | ||
7bd2f24c IM |
2358 | static const char readme_msg[] = |
2359 | "tracing mini-HOWTO:\n\n" | |
2360 | "# mkdir /debug\n" | |
2361 | "# mount -t debugfs nodev /debug\n\n" | |
2362 | "# cat /debug/tracing/available_tracers\n" | |
bc2b6871 | 2363 | "wakeup preemptirqsoff preemptoff irqsoff function sched_switch nop\n\n" |
7bd2f24c | 2364 | "# cat /debug/tracing/current_tracer\n" |
bc2b6871 | 2365 | "nop\n" |
7bd2f24c IM |
2366 | "# echo sched_switch > /debug/tracing/current_tracer\n" |
2367 | "# cat /debug/tracing/current_tracer\n" | |
2368 | "sched_switch\n" | |
ee6bce52 | 2369 | "# cat /debug/tracing/trace_options\n" |
7bd2f24c | 2370 | "noprint-parent nosym-offset nosym-addr noverbose\n" |
ee6bce52 | 2371 | "# echo print-parent > /debug/tracing/trace_options\n" |
7bd2f24c IM |
2372 | "# echo 1 > /debug/tracing/tracing_enabled\n" |
2373 | "# cat /debug/tracing/trace > /tmp/trace.txt\n" | |
2374 | "echo 0 > /debug/tracing/tracing_enabled\n" | |
2375 | ; | |
2376 | ||
2377 | static ssize_t | |
2378 | tracing_readme_read(struct file *filp, char __user *ubuf, | |
2379 | size_t cnt, loff_t *ppos) | |
2380 | { | |
2381 | return simple_read_from_buffer(ubuf, cnt, ppos, | |
2382 | readme_msg, strlen(readme_msg)); | |
2383 | } | |
2384 | ||
5e2336a0 | 2385 | static const struct file_operations tracing_readme_fops = { |
c7078de1 IM |
2386 | .open = tracing_open_generic, |
2387 | .read = tracing_readme_read, | |
7bd2f24c IM |
2388 | }; |
2389 | ||
bc0c38d1 SR |
2390 | static ssize_t |
2391 | tracing_ctrl_read(struct file *filp, char __user *ubuf, | |
2392 | size_t cnt, loff_t *ppos) | |
2393 | { | |
bc0c38d1 SR |
2394 | char buf[64]; |
2395 | int r; | |
2396 | ||
9036990d | 2397 | r = sprintf(buf, "%u\n", tracer_enabled); |
4e3c3333 | 2398 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
bc0c38d1 SR |
2399 | } |
2400 | ||
2401 | static ssize_t | |
2402 | tracing_ctrl_write(struct file *filp, const char __user *ubuf, | |
2403 | size_t cnt, loff_t *ppos) | |
2404 | { | |
2405 | struct trace_array *tr = filp->private_data; | |
bc0c38d1 | 2406 | char buf[64]; |
5e39841c | 2407 | unsigned long val; |
c6caeeb1 | 2408 | int ret; |
bc0c38d1 | 2409 | |
cffae437 SR |
2410 | if (cnt >= sizeof(buf)) |
2411 | return -EINVAL; | |
bc0c38d1 SR |
2412 | |
2413 | if (copy_from_user(&buf, ubuf, cnt)) | |
2414 | return -EFAULT; | |
2415 | ||
2416 | buf[cnt] = 0; | |
2417 | ||
c6caeeb1 SR |
2418 | ret = strict_strtoul(buf, 10, &val); |
2419 | if (ret < 0) | |
2420 | return ret; | |
bc0c38d1 SR |
2421 | |
2422 | val = !!val; | |
2423 | ||
2424 | mutex_lock(&trace_types_lock); | |
9036990d SR |
2425 | if (tracer_enabled ^ val) { |
2426 | if (val) { | |
bc0c38d1 | 2427 | tracer_enabled = 1; |
9036990d SR |
2428 | if (current_trace->start) |
2429 | current_trace->start(tr); | |
2430 | tracing_start(); | |
2431 | } else { | |
bc0c38d1 | 2432 | tracer_enabled = 0; |
9036990d SR |
2433 | tracing_stop(); |
2434 | if (current_trace->stop) | |
2435 | current_trace->stop(tr); | |
2436 | } | |
bc0c38d1 SR |
2437 | } |
2438 | mutex_unlock(&trace_types_lock); | |
2439 | ||
2440 | filp->f_pos += cnt; | |
2441 | ||
2442 | return cnt; | |
2443 | } | |
2444 | ||
2445 | static ssize_t | |
2446 | tracing_set_trace_read(struct file *filp, char __user *ubuf, | |
2447 | size_t cnt, loff_t *ppos) | |
2448 | { | |
2449 | char buf[max_tracer_type_len+2]; | |
2450 | int r; | |
2451 | ||
2452 | mutex_lock(&trace_types_lock); | |
2453 | if (current_trace) | |
2454 | r = sprintf(buf, "%s\n", current_trace->name); | |
2455 | else | |
2456 | r = sprintf(buf, "\n"); | |
2457 | mutex_unlock(&trace_types_lock); | |
2458 | ||
4bf39a94 | 2459 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
bc0c38d1 SR |
2460 | } |
2461 | ||
b6f11df2 ACM |
2462 | int tracer_init(struct tracer *t, struct trace_array *tr) |
2463 | { | |
2464 | tracing_reset_online_cpus(tr); | |
2465 | return t->init(tr); | |
2466 | } | |
2467 | ||
73c5162a SR |
2468 | static int tracing_resize_ring_buffer(unsigned long size) |
2469 | { | |
2470 | int ret; | |
2471 | ||
2472 | /* | |
2473 | * If kernel or user changes the size of the ring buffer | |
a123c52b SR |
2474 | * we use the size that was given, and we can forget about |
2475 | * expanding it later. | |
73c5162a SR |
2476 | */ |
2477 | ring_buffer_expanded = 1; | |
2478 | ||
2479 | ret = ring_buffer_resize(global_trace.buffer, size); | |
2480 | if (ret < 0) | |
2481 | return ret; | |
2482 | ||
2483 | ret = ring_buffer_resize(max_tr.buffer, size); | |
2484 | if (ret < 0) { | |
2485 | int r; | |
2486 | ||
2487 | r = ring_buffer_resize(global_trace.buffer, | |
2488 | global_trace.entries); | |
2489 | if (r < 0) { | |
a123c52b SR |
2490 | /* |
2491 | * AARGH! We are left with different | |
2492 | * size max buffer!!!! | |
2493 | * The max buffer is our "snapshot" buffer. | |
2494 | * When a tracer needs a snapshot (one of the | |
2495 | * latency tracers), it swaps the max buffer | |
2496 | * with the saved snap shot. We succeeded to | |
2497 | * update the size of the main buffer, but failed to | |
2498 | * update the size of the max buffer. But when we tried | |
2499 | * to reset the main buffer to the original size, we | |
2500 | * failed there too. This is very unlikely to | |
2501 | * happen, but if it does, warn and kill all | |
2502 | * tracing. | |
2503 | */ | |
73c5162a SR |
2504 | WARN_ON(1); |
2505 | tracing_disabled = 1; | |
2506 | } | |
2507 | return ret; | |
2508 | } | |
2509 | ||
2510 | global_trace.entries = size; | |
2511 | ||
2512 | return ret; | |
2513 | } | |
2514 | ||
1852fcce SR |
2515 | /** |
2516 | * tracing_update_buffers - used by tracing facility to expand ring buffers | |
2517 | * | |
2518 | * To save on memory when the tracing is never used on a system with it | |
2519 | * configured in. The ring buffers are set to a minimum size. But once | |
2520 | * a user starts to use the tracing facility, then they need to grow | |
2521 | * to their default size. | |
2522 | * | |
2523 | * This function is to be called when a tracer is about to be used. | |
2524 | */ | |
2525 | int tracing_update_buffers(void) | |
2526 | { | |
2527 | int ret = 0; | |
2528 | ||
1027fcb2 | 2529 | mutex_lock(&trace_types_lock); |
1852fcce SR |
2530 | if (!ring_buffer_expanded) |
2531 | ret = tracing_resize_ring_buffer(trace_buf_size); | |
1027fcb2 | 2532 | mutex_unlock(&trace_types_lock); |
1852fcce SR |
2533 | |
2534 | return ret; | |
2535 | } | |
2536 | ||
577b785f SR |
2537 | struct trace_option_dentry; |
2538 | ||
2539 | static struct trace_option_dentry * | |
2540 | create_trace_option_files(struct tracer *tracer); | |
2541 | ||
2542 | static void | |
2543 | destroy_trace_option_files(struct trace_option_dentry *topts); | |
2544 | ||
b2821ae6 | 2545 | static int tracing_set_tracer(const char *buf) |
bc0c38d1 | 2546 | { |
577b785f | 2547 | static struct trace_option_dentry *topts; |
bc0c38d1 SR |
2548 | struct trace_array *tr = &global_trace; |
2549 | struct tracer *t; | |
d9e54076 | 2550 | int ret = 0; |
bc0c38d1 | 2551 | |
1027fcb2 SR |
2552 | mutex_lock(&trace_types_lock); |
2553 | ||
73c5162a SR |
2554 | if (!ring_buffer_expanded) { |
2555 | ret = tracing_resize_ring_buffer(trace_buf_size); | |
2556 | if (ret < 0) | |
59f586db | 2557 | goto out; |
73c5162a SR |
2558 | ret = 0; |
2559 | } | |
2560 | ||
bc0c38d1 SR |
2561 | for (t = trace_types; t; t = t->next) { |
2562 | if (strcmp(t->name, buf) == 0) | |
2563 | break; | |
2564 | } | |
c2931e05 FW |
2565 | if (!t) { |
2566 | ret = -EINVAL; | |
2567 | goto out; | |
2568 | } | |
2569 | if (t == current_trace) | |
bc0c38d1 SR |
2570 | goto out; |
2571 | ||
9f029e83 | 2572 | trace_branch_disable(); |
bc0c38d1 SR |
2573 | if (current_trace && current_trace->reset) |
2574 | current_trace->reset(tr); | |
2575 | ||
577b785f SR |
2576 | destroy_trace_option_files(topts); |
2577 | ||
bc0c38d1 | 2578 | current_trace = t; |
577b785f SR |
2579 | |
2580 | topts = create_trace_option_files(current_trace); | |
2581 | ||
1c80025a | 2582 | if (t->init) { |
b6f11df2 | 2583 | ret = tracer_init(t, tr); |
1c80025a FW |
2584 | if (ret) |
2585 | goto out; | |
2586 | } | |
bc0c38d1 | 2587 | |
9f029e83 | 2588 | trace_branch_enable(tr); |
bc0c38d1 SR |
2589 | out: |
2590 | mutex_unlock(&trace_types_lock); | |
2591 | ||
d9e54076 PZ |
2592 | return ret; |
2593 | } | |
2594 | ||
2595 | static ssize_t | |
2596 | tracing_set_trace_write(struct file *filp, const char __user *ubuf, | |
2597 | size_t cnt, loff_t *ppos) | |
2598 | { | |
2599 | char buf[max_tracer_type_len+1]; | |
2600 | int i; | |
2601 | size_t ret; | |
e6e7a65a FW |
2602 | int err; |
2603 | ||
2604 | ret = cnt; | |
d9e54076 PZ |
2605 | |
2606 | if (cnt > max_tracer_type_len) | |
2607 | cnt = max_tracer_type_len; | |
2608 | ||
2609 | if (copy_from_user(&buf, ubuf, cnt)) | |
2610 | return -EFAULT; | |
2611 | ||
2612 | buf[cnt] = 0; | |
2613 | ||
2614 | /* strip ending whitespace. */ | |
2615 | for (i = cnt - 1; i > 0 && isspace(buf[i]); i--) | |
2616 | buf[i] = 0; | |
2617 | ||
e6e7a65a FW |
2618 | err = tracing_set_tracer(buf); |
2619 | if (err) | |
2620 | return err; | |
d9e54076 | 2621 | |
e6e7a65a | 2622 | filp->f_pos += ret; |
bc0c38d1 | 2623 | |
c2931e05 | 2624 | return ret; |
bc0c38d1 SR |
2625 | } |
2626 | ||
2627 | static ssize_t | |
2628 | tracing_max_lat_read(struct file *filp, char __user *ubuf, | |
2629 | size_t cnt, loff_t *ppos) | |
2630 | { | |
2631 | unsigned long *ptr = filp->private_data; | |
2632 | char buf[64]; | |
2633 | int r; | |
2634 | ||
cffae437 | 2635 | r = snprintf(buf, sizeof(buf), "%ld\n", |
bc0c38d1 | 2636 | *ptr == (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr)); |
cffae437 SR |
2637 | if (r > sizeof(buf)) |
2638 | r = sizeof(buf); | |
4bf39a94 | 2639 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
bc0c38d1 SR |
2640 | } |
2641 | ||
2642 | static ssize_t | |
2643 | tracing_max_lat_write(struct file *filp, const char __user *ubuf, | |
2644 | size_t cnt, loff_t *ppos) | |
2645 | { | |
5e39841c | 2646 | unsigned long *ptr = filp->private_data; |
bc0c38d1 | 2647 | char buf[64]; |
5e39841c | 2648 | unsigned long val; |
c6caeeb1 | 2649 | int ret; |
bc0c38d1 | 2650 | |
cffae437 SR |
2651 | if (cnt >= sizeof(buf)) |
2652 | return -EINVAL; | |
bc0c38d1 SR |
2653 | |
2654 | if (copy_from_user(&buf, ubuf, cnt)) | |
2655 | return -EFAULT; | |
2656 | ||
2657 | buf[cnt] = 0; | |
2658 | ||
c6caeeb1 SR |
2659 | ret = strict_strtoul(buf, 10, &val); |
2660 | if (ret < 0) | |
2661 | return ret; | |
bc0c38d1 SR |
2662 | |
2663 | *ptr = val * 1000; | |
2664 | ||
2665 | return cnt; | |
2666 | } | |
2667 | ||
b3806b43 SR |
2668 | static int tracing_open_pipe(struct inode *inode, struct file *filp) |
2669 | { | |
b04cc6b1 | 2670 | long cpu_file = (long) inode->i_private; |
b3806b43 | 2671 | struct trace_iterator *iter; |
b04cc6b1 | 2672 | int ret = 0; |
b3806b43 SR |
2673 | |
2674 | if (tracing_disabled) | |
2675 | return -ENODEV; | |
2676 | ||
b04cc6b1 FW |
2677 | mutex_lock(&trace_types_lock); |
2678 | ||
2679 | /* We only allow one reader per cpu */ | |
2680 | if (cpu_file == TRACE_PIPE_ALL_CPU) { | |
2681 | if (!cpumask_empty(tracing_reader_cpumask)) { | |
2682 | ret = -EBUSY; | |
2683 | goto out; | |
2684 | } | |
2685 | cpumask_setall(tracing_reader_cpumask); | |
2686 | } else { | |
2687 | if (!cpumask_test_cpu(cpu_file, tracing_reader_cpumask)) | |
2688 | cpumask_set_cpu(cpu_file, tracing_reader_cpumask); | |
2689 | else { | |
2690 | ret = -EBUSY; | |
2691 | goto out; | |
2692 | } | |
b3806b43 SR |
2693 | } |
2694 | ||
2695 | /* create a buffer to store the information to pass to userspace */ | |
2696 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); | |
b04cc6b1 FW |
2697 | if (!iter) { |
2698 | ret = -ENOMEM; | |
2699 | goto out; | |
2700 | } | |
b3806b43 | 2701 | |
d7350c3f FW |
2702 | /* |
2703 | * We make a copy of the current tracer to avoid concurrent | |
2704 | * changes on it while we are reading. | |
2705 | */ | |
2706 | iter->trace = kmalloc(sizeof(*iter->trace), GFP_KERNEL); | |
2707 | if (!iter->trace) { | |
2708 | ret = -ENOMEM; | |
2709 | goto fail; | |
2710 | } | |
2711 | if (current_trace) | |
2712 | *iter->trace = *current_trace; | |
2713 | ||
4462344e | 2714 | if (!alloc_cpumask_var(&iter->started, GFP_KERNEL)) { |
b04cc6b1 | 2715 | ret = -ENOMEM; |
d7350c3f | 2716 | goto fail; |
4462344e RR |
2717 | } |
2718 | ||
a309720c | 2719 | /* trace pipe does not show start of buffer */ |
4462344e | 2720 | cpumask_setall(iter->started); |
a309720c | 2721 | |
b04cc6b1 | 2722 | iter->cpu_file = cpu_file; |
b3806b43 | 2723 | iter->tr = &global_trace; |
d7350c3f | 2724 | mutex_init(&iter->mutex); |
b3806b43 SR |
2725 | filp->private_data = iter; |
2726 | ||
107bad8b SR |
2727 | if (iter->trace->pipe_open) |
2728 | iter->trace->pipe_open(iter); | |
107bad8b | 2729 | |
b04cc6b1 FW |
2730 | out: |
2731 | mutex_unlock(&trace_types_lock); | |
2732 | return ret; | |
d7350c3f FW |
2733 | |
2734 | fail: | |
2735 | kfree(iter->trace); | |
2736 | kfree(iter); | |
2737 | mutex_unlock(&trace_types_lock); | |
2738 | return ret; | |
b3806b43 SR |
2739 | } |
2740 | ||
2741 | static int tracing_release_pipe(struct inode *inode, struct file *file) | |
2742 | { | |
2743 | struct trace_iterator *iter = file->private_data; | |
2744 | ||
b04cc6b1 FW |
2745 | mutex_lock(&trace_types_lock); |
2746 | ||
2747 | if (iter->cpu_file == TRACE_PIPE_ALL_CPU) | |
2748 | cpumask_clear(tracing_reader_cpumask); | |
2749 | else | |
2750 | cpumask_clear_cpu(iter->cpu_file, tracing_reader_cpumask); | |
2751 | ||
2752 | mutex_unlock(&trace_types_lock); | |
2753 | ||
4462344e | 2754 | free_cpumask_var(iter->started); |
d7350c3f FW |
2755 | mutex_destroy(&iter->mutex); |
2756 | kfree(iter->trace); | |
b3806b43 | 2757 | kfree(iter); |
b3806b43 SR |
2758 | |
2759 | return 0; | |
2760 | } | |
2761 | ||
2a2cc8f7 SSP |
2762 | static unsigned int |
2763 | tracing_poll_pipe(struct file *filp, poll_table *poll_table) | |
2764 | { | |
2765 | struct trace_iterator *iter = filp->private_data; | |
2766 | ||
2767 | if (trace_flags & TRACE_ITER_BLOCK) { | |
2768 | /* | |
2769 | * Always select as readable when in blocking mode | |
2770 | */ | |
2771 | return POLLIN | POLLRDNORM; | |
afc2abc0 | 2772 | } else { |
2a2cc8f7 SSP |
2773 | if (!trace_empty(iter)) |
2774 | return POLLIN | POLLRDNORM; | |
2775 | poll_wait(filp, &trace_wait, poll_table); | |
2776 | if (!trace_empty(iter)) | |
2777 | return POLLIN | POLLRDNORM; | |
2778 | ||
2779 | return 0; | |
2780 | } | |
2781 | } | |
2782 | ||
6eaaa5d5 FW |
2783 | |
2784 | void default_wait_pipe(struct trace_iterator *iter) | |
2785 | { | |
2786 | DEFINE_WAIT(wait); | |
2787 | ||
2788 | prepare_to_wait(&trace_wait, &wait, TASK_INTERRUPTIBLE); | |
2789 | ||
2790 | if (trace_empty(iter)) | |
2791 | schedule(); | |
2792 | ||
2793 | finish_wait(&trace_wait, &wait); | |
2794 | } | |
2795 | ||
2796 | /* | |
2797 | * This is a make-shift waitqueue. | |
2798 | * A tracer might use this callback on some rare cases: | |
2799 | * | |
2800 | * 1) the current tracer might hold the runqueue lock when it wakes up | |
2801 | * a reader, hence a deadlock (sched, function, and function graph tracers) | |
2802 | * 2) the function tracers, trace all functions, we don't want | |
2803 | * the overhead of calling wake_up and friends | |
2804 | * (and tracing them too) | |
2805 | * | |
2806 | * Anyway, this is really very primitive wakeup. | |
2807 | */ | |
2808 | void poll_wait_pipe(struct trace_iterator *iter) | |
2809 | { | |
2810 | set_current_state(TASK_INTERRUPTIBLE); | |
2811 | /* sleep for 100 msecs, and try again. */ | |
2812 | schedule_timeout(HZ / 10); | |
2813 | } | |
2814 | ||
ff98781b EGM |
2815 | /* Must be called with trace_types_lock mutex held. */ |
2816 | static int tracing_wait_pipe(struct file *filp) | |
b3806b43 SR |
2817 | { |
2818 | struct trace_iterator *iter = filp->private_data; | |
b3806b43 | 2819 | |
b3806b43 | 2820 | while (trace_empty(iter)) { |
2dc8f095 | 2821 | |
107bad8b | 2822 | if ((filp->f_flags & O_NONBLOCK)) { |
ff98781b | 2823 | return -EAGAIN; |
107bad8b | 2824 | } |
2dc8f095 | 2825 | |
d7350c3f | 2826 | mutex_unlock(&iter->mutex); |
107bad8b | 2827 | |
6eaaa5d5 | 2828 | iter->trace->wait_pipe(iter); |
b3806b43 | 2829 | |
d7350c3f | 2830 | mutex_lock(&iter->mutex); |
107bad8b | 2831 | |
6eaaa5d5 | 2832 | if (signal_pending(current)) |
ff98781b | 2833 | return -EINTR; |
b3806b43 SR |
2834 | |
2835 | /* | |
2836 | * We block until we read something and tracing is disabled. | |
2837 | * We still block if tracing is disabled, but we have never | |
2838 | * read anything. This allows a user to cat this file, and | |
2839 | * then enable tracing. But after we have read something, | |
2840 | * we give an EOF when tracing is again disabled. | |
2841 | * | |
2842 | * iter->pos will be 0 if we haven't read anything. | |
2843 | */ | |
2844 | if (!tracer_enabled && iter->pos) | |
2845 | break; | |
b3806b43 SR |
2846 | } |
2847 | ||
ff98781b EGM |
2848 | return 1; |
2849 | } | |
2850 | ||
2851 | /* | |
2852 | * Consumer reader. | |
2853 | */ | |
2854 | static ssize_t | |
2855 | tracing_read_pipe(struct file *filp, char __user *ubuf, | |
2856 | size_t cnt, loff_t *ppos) | |
2857 | { | |
2858 | struct trace_iterator *iter = filp->private_data; | |
d7350c3f | 2859 | static struct tracer *old_tracer; |
ff98781b EGM |
2860 | ssize_t sret; |
2861 | ||
2862 | /* return any leftover data */ | |
2863 | sret = trace_seq_to_user(&iter->seq, ubuf, cnt); | |
2864 | if (sret != -EBUSY) | |
2865 | return sret; | |
2866 | ||
f9520750 | 2867 | trace_seq_init(&iter->seq); |
ff98781b | 2868 | |
d7350c3f | 2869 | /* copy the tracer to avoid using a global lock all around */ |
ff98781b | 2870 | mutex_lock(&trace_types_lock); |
d7350c3f FW |
2871 | if (unlikely(old_tracer != current_trace && current_trace)) { |
2872 | old_tracer = current_trace; | |
2873 | *iter->trace = *current_trace; | |
2874 | } | |
2875 | mutex_unlock(&trace_types_lock); | |
2876 | ||
2877 | /* | |
2878 | * Avoid more than one consumer on a single file descriptor | |
2879 | * This is just a matter of traces coherency, the ring buffer itself | |
2880 | * is protected. | |
2881 | */ | |
2882 | mutex_lock(&iter->mutex); | |
ff98781b EGM |
2883 | if (iter->trace->read) { |
2884 | sret = iter->trace->read(iter, filp, ubuf, cnt, ppos); | |
2885 | if (sret) | |
2886 | goto out; | |
2887 | } | |
2888 | ||
2889 | waitagain: | |
2890 | sret = tracing_wait_pipe(filp); | |
2891 | if (sret <= 0) | |
2892 | goto out; | |
2893 | ||
b3806b43 | 2894 | /* stop when tracing is finished */ |
ff98781b EGM |
2895 | if (trace_empty(iter)) { |
2896 | sret = 0; | |
107bad8b | 2897 | goto out; |
ff98781b | 2898 | } |
b3806b43 SR |
2899 | |
2900 | if (cnt >= PAGE_SIZE) | |
2901 | cnt = PAGE_SIZE - 1; | |
2902 | ||
53d0aa77 | 2903 | /* reset all but tr, trace, and overruns */ |
53d0aa77 SR |
2904 | memset(&iter->seq, 0, |
2905 | sizeof(struct trace_iterator) - | |
2906 | offsetof(struct trace_iterator, seq)); | |
4823ed7e | 2907 | iter->pos = -1; |
b3806b43 | 2908 | |
088b1e42 | 2909 | while (find_next_entry_inc(iter) != NULL) { |
2c4f035f | 2910 | enum print_line_t ret; |
088b1e42 SR |
2911 | int len = iter->seq.len; |
2912 | ||
f9896bf3 | 2913 | ret = print_trace_line(iter); |
2c4f035f | 2914 | if (ret == TRACE_TYPE_PARTIAL_LINE) { |
088b1e42 SR |
2915 | /* don't print partial lines */ |
2916 | iter->seq.len = len; | |
b3806b43 | 2917 | break; |
088b1e42 | 2918 | } |
b91facc3 FW |
2919 | if (ret != TRACE_TYPE_NO_CONSUME) |
2920 | trace_consume(iter); | |
b3806b43 SR |
2921 | |
2922 | if (iter->seq.len >= cnt) | |
2923 | break; | |
b3806b43 SR |
2924 | } |
2925 | ||
b3806b43 | 2926 | /* Now copy what we have to the user */ |
6c6c2796 PP |
2927 | sret = trace_seq_to_user(&iter->seq, ubuf, cnt); |
2928 | if (iter->seq.readpos >= iter->seq.len) | |
f9520750 | 2929 | trace_seq_init(&iter->seq); |
9ff4b974 PP |
2930 | |
2931 | /* | |
2932 | * If there was nothing to send to user, inspite of consuming trace | |
2933 | * entries, go back to wait for more entries. | |
2934 | */ | |
6c6c2796 | 2935 | if (sret == -EBUSY) |
9ff4b974 | 2936 | goto waitagain; |
b3806b43 | 2937 | |
107bad8b | 2938 | out: |
d7350c3f | 2939 | mutex_unlock(&iter->mutex); |
107bad8b | 2940 | |
6c6c2796 | 2941 | return sret; |
b3806b43 SR |
2942 | } |
2943 | ||
3c56819b EGM |
2944 | static void tracing_pipe_buf_release(struct pipe_inode_info *pipe, |
2945 | struct pipe_buffer *buf) | |
2946 | { | |
2947 | __free_page(buf->page); | |
2948 | } | |
2949 | ||
2950 | static void tracing_spd_release_pipe(struct splice_pipe_desc *spd, | |
2951 | unsigned int idx) | |
2952 | { | |
2953 | __free_page(spd->pages[idx]); | |
2954 | } | |
2955 | ||
2956 | static struct pipe_buf_operations tracing_pipe_buf_ops = { | |
34cd4998 SR |
2957 | .can_merge = 0, |
2958 | .map = generic_pipe_buf_map, | |
2959 | .unmap = generic_pipe_buf_unmap, | |
2960 | .confirm = generic_pipe_buf_confirm, | |
2961 | .release = tracing_pipe_buf_release, | |
2962 | .steal = generic_pipe_buf_steal, | |
2963 | .get = generic_pipe_buf_get, | |
3c56819b EGM |
2964 | }; |
2965 | ||
34cd4998 | 2966 | static size_t |
fa7c7f6e | 2967 | tracing_fill_pipe_page(size_t rem, struct trace_iterator *iter) |
34cd4998 SR |
2968 | { |
2969 | size_t count; | |
2970 | int ret; | |
2971 | ||
2972 | /* Seq buffer is page-sized, exactly what we need. */ | |
2973 | for (;;) { | |
2974 | count = iter->seq.len; | |
2975 | ret = print_trace_line(iter); | |
2976 | count = iter->seq.len - count; | |
2977 | if (rem < count) { | |
2978 | rem = 0; | |
2979 | iter->seq.len -= count; | |
2980 | break; | |
2981 | } | |
2982 | if (ret == TRACE_TYPE_PARTIAL_LINE) { | |
2983 | iter->seq.len -= count; | |
2984 | break; | |
2985 | } | |
2986 | ||
2987 | trace_consume(iter); | |
2988 | rem -= count; | |
2989 | if (!find_next_entry_inc(iter)) { | |
2990 | rem = 0; | |
2991 | iter->ent = NULL; | |
2992 | break; | |
2993 | } | |
2994 | } | |
2995 | ||
2996 | return rem; | |
2997 | } | |
2998 | ||
3c56819b EGM |
2999 | static ssize_t tracing_splice_read_pipe(struct file *filp, |
3000 | loff_t *ppos, | |
3001 | struct pipe_inode_info *pipe, | |
3002 | size_t len, | |
3003 | unsigned int flags) | |
3004 | { | |
3005 | struct page *pages[PIPE_BUFFERS]; | |
3006 | struct partial_page partial[PIPE_BUFFERS]; | |
3007 | struct trace_iterator *iter = filp->private_data; | |
3008 | struct splice_pipe_desc spd = { | |
34cd4998 SR |
3009 | .pages = pages, |
3010 | .partial = partial, | |
3011 | .nr_pages = 0, /* This gets updated below. */ | |
3012 | .flags = flags, | |
3013 | .ops = &tracing_pipe_buf_ops, | |
3014 | .spd_release = tracing_spd_release_pipe, | |
3c56819b | 3015 | }; |
d7350c3f | 3016 | static struct tracer *old_tracer; |
3c56819b | 3017 | ssize_t ret; |
34cd4998 | 3018 | size_t rem; |
3c56819b EGM |
3019 | unsigned int i; |
3020 | ||
d7350c3f | 3021 | /* copy the tracer to avoid using a global lock all around */ |
3c56819b | 3022 | mutex_lock(&trace_types_lock); |
d7350c3f FW |
3023 | if (unlikely(old_tracer != current_trace && current_trace)) { |
3024 | old_tracer = current_trace; | |
3025 | *iter->trace = *current_trace; | |
3026 | } | |
3027 | mutex_unlock(&trace_types_lock); | |
3028 | ||
3029 | mutex_lock(&iter->mutex); | |
3c56819b EGM |
3030 | |
3031 | if (iter->trace->splice_read) { | |
3032 | ret = iter->trace->splice_read(iter, filp, | |
3033 | ppos, pipe, len, flags); | |
3034 | if (ret) | |
34cd4998 | 3035 | goto out_err; |
3c56819b EGM |
3036 | } |
3037 | ||
3038 | ret = tracing_wait_pipe(filp); | |
3039 | if (ret <= 0) | |
34cd4998 | 3040 | goto out_err; |
3c56819b EGM |
3041 | |
3042 | if (!iter->ent && !find_next_entry_inc(iter)) { | |
3043 | ret = -EFAULT; | |
34cd4998 | 3044 | goto out_err; |
3c56819b EGM |
3045 | } |
3046 | ||
3047 | /* Fill as many pages as possible. */ | |
3048 | for (i = 0, rem = len; i < PIPE_BUFFERS && rem; i++) { | |
3049 | pages[i] = alloc_page(GFP_KERNEL); | |
34cd4998 SR |
3050 | if (!pages[i]) |
3051 | break; | |
3c56819b | 3052 | |
fa7c7f6e | 3053 | rem = tracing_fill_pipe_page(rem, iter); |
3c56819b EGM |
3054 | |
3055 | /* Copy the data into the page, so we can start over. */ | |
3056 | ret = trace_seq_to_buffer(&iter->seq, | |
3057 | page_address(pages[i]), | |
3058 | iter->seq.len); | |
3059 | if (ret < 0) { | |
3060 | __free_page(pages[i]); | |
3061 | break; | |
3062 | } | |
3063 | partial[i].offset = 0; | |
3064 | partial[i].len = iter->seq.len; | |
3065 | ||
f9520750 | 3066 | trace_seq_init(&iter->seq); |
3c56819b EGM |
3067 | } |
3068 | ||
d7350c3f | 3069 | mutex_unlock(&iter->mutex); |
3c56819b EGM |
3070 | |
3071 | spd.nr_pages = i; | |
3072 | ||
3073 | return splice_to_pipe(pipe, &spd); | |
3074 | ||
34cd4998 | 3075 | out_err: |
d7350c3f | 3076 | mutex_unlock(&iter->mutex); |
3c56819b EGM |
3077 | |
3078 | return ret; | |
3079 | } | |
3080 | ||
a98a3c3f SR |
3081 | static ssize_t |
3082 | tracing_entries_read(struct file *filp, char __user *ubuf, | |
3083 | size_t cnt, loff_t *ppos) | |
3084 | { | |
3085 | struct trace_array *tr = filp->private_data; | |
db526ca3 | 3086 | char buf[96]; |
a98a3c3f SR |
3087 | int r; |
3088 | ||
db526ca3 SR |
3089 | mutex_lock(&trace_types_lock); |
3090 | if (!ring_buffer_expanded) | |
3091 | r = sprintf(buf, "%lu (expanded: %lu)\n", | |
3092 | tr->entries >> 10, | |
3093 | trace_buf_size >> 10); | |
3094 | else | |
3095 | r = sprintf(buf, "%lu\n", tr->entries >> 10); | |
3096 | mutex_unlock(&trace_types_lock); | |
3097 | ||
a98a3c3f SR |
3098 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
3099 | } | |
3100 | ||
3101 | static ssize_t | |
3102 | tracing_entries_write(struct file *filp, const char __user *ubuf, | |
3103 | size_t cnt, loff_t *ppos) | |
3104 | { | |
3105 | unsigned long val; | |
3106 | char buf[64]; | |
bf5e6519 | 3107 | int ret, cpu; |
a98a3c3f | 3108 | |
cffae437 SR |
3109 | if (cnt >= sizeof(buf)) |
3110 | return -EINVAL; | |
a98a3c3f SR |
3111 | |
3112 | if (copy_from_user(&buf, ubuf, cnt)) | |
3113 | return -EFAULT; | |
3114 | ||
3115 | buf[cnt] = 0; | |
3116 | ||
c6caeeb1 SR |
3117 | ret = strict_strtoul(buf, 10, &val); |
3118 | if (ret < 0) | |
3119 | return ret; | |
a98a3c3f SR |
3120 | |
3121 | /* must have at least 1 entry */ | |
3122 | if (!val) | |
3123 | return -EINVAL; | |
3124 | ||
3125 | mutex_lock(&trace_types_lock); | |
3126 | ||
c76f0694 | 3127 | tracing_stop(); |
a98a3c3f | 3128 | |
bf5e6519 SR |
3129 | /* disable all cpu buffers */ |
3130 | for_each_tracing_cpu(cpu) { | |
3131 | if (global_trace.data[cpu]) | |
3132 | atomic_inc(&global_trace.data[cpu]->disabled); | |
3133 | if (max_tr.data[cpu]) | |
3134 | atomic_inc(&max_tr.data[cpu]->disabled); | |
3135 | } | |
3136 | ||
1696b2b0 SR |
3137 | /* value is in KB */ |
3138 | val <<= 10; | |
3139 | ||
3928a8a2 | 3140 | if (val != global_trace.entries) { |
73c5162a | 3141 | ret = tracing_resize_ring_buffer(val); |
3928a8a2 SR |
3142 | if (ret < 0) { |
3143 | cnt = ret; | |
3eefae99 SR |
3144 | goto out; |
3145 | } | |
a98a3c3f SR |
3146 | } |
3147 | ||
3148 | filp->f_pos += cnt; | |
3149 | ||
19384c03 SR |
3150 | /* If check pages failed, return ENOMEM */ |
3151 | if (tracing_disabled) | |
3152 | cnt = -ENOMEM; | |
a98a3c3f | 3153 | out: |
bf5e6519 SR |
3154 | for_each_tracing_cpu(cpu) { |
3155 | if (global_trace.data[cpu]) | |
3156 | atomic_dec(&global_trace.data[cpu]->disabled); | |
3157 | if (max_tr.data[cpu]) | |
3158 | atomic_dec(&max_tr.data[cpu]->disabled); | |
3159 | } | |
3160 | ||
c76f0694 | 3161 | tracing_start(); |
a98a3c3f SR |
3162 | max_tr.entries = global_trace.entries; |
3163 | mutex_unlock(&trace_types_lock); | |
3164 | ||
3165 | return cnt; | |
3166 | } | |
3167 | ||
5bf9a1ee PP |
3168 | static int mark_printk(const char *fmt, ...) |
3169 | { | |
3170 | int ret; | |
3171 | va_list args; | |
3172 | va_start(args, fmt); | |
40ce74f1 | 3173 | ret = trace_vprintk(0, fmt, args); |
5bf9a1ee PP |
3174 | va_end(args); |
3175 | return ret; | |
3176 | } | |
3177 | ||
3178 | static ssize_t | |
3179 | tracing_mark_write(struct file *filp, const char __user *ubuf, | |
3180 | size_t cnt, loff_t *fpos) | |
3181 | { | |
3182 | char *buf; | |
3183 | char *end; | |
5bf9a1ee | 3184 | |
c76f0694 | 3185 | if (tracing_disabled) |
5bf9a1ee PP |
3186 | return -EINVAL; |
3187 | ||
3188 | if (cnt > TRACE_BUF_SIZE) | |
3189 | cnt = TRACE_BUF_SIZE; | |
3190 | ||
3191 | buf = kmalloc(cnt + 1, GFP_KERNEL); | |
3192 | if (buf == NULL) | |
3193 | return -ENOMEM; | |
3194 | ||
3195 | if (copy_from_user(buf, ubuf, cnt)) { | |
3196 | kfree(buf); | |
3197 | return -EFAULT; | |
3198 | } | |
3199 | ||
3200 | /* Cut from the first nil or newline. */ | |
3201 | buf[cnt] = '\0'; | |
3202 | end = strchr(buf, '\n'); | |
3203 | if (end) | |
3204 | *end = '\0'; | |
3205 | ||
3206 | cnt = mark_printk("%s\n", buf); | |
3207 | kfree(buf); | |
3208 | *fpos += cnt; | |
3209 | ||
3210 | return cnt; | |
3211 | } | |
3212 | ||
5e2336a0 | 3213 | static const struct file_operations tracing_max_lat_fops = { |
4bf39a94 IM |
3214 | .open = tracing_open_generic, |
3215 | .read = tracing_max_lat_read, | |
3216 | .write = tracing_max_lat_write, | |
bc0c38d1 SR |
3217 | }; |
3218 | ||
5e2336a0 | 3219 | static const struct file_operations tracing_ctrl_fops = { |
4bf39a94 IM |
3220 | .open = tracing_open_generic, |
3221 | .read = tracing_ctrl_read, | |
3222 | .write = tracing_ctrl_write, | |
bc0c38d1 SR |
3223 | }; |
3224 | ||
5e2336a0 | 3225 | static const struct file_operations set_tracer_fops = { |
4bf39a94 IM |
3226 | .open = tracing_open_generic, |
3227 | .read = tracing_set_trace_read, | |
3228 | .write = tracing_set_trace_write, | |
bc0c38d1 SR |
3229 | }; |
3230 | ||
5e2336a0 | 3231 | static const struct file_operations tracing_pipe_fops = { |
4bf39a94 | 3232 | .open = tracing_open_pipe, |
2a2cc8f7 | 3233 | .poll = tracing_poll_pipe, |
4bf39a94 | 3234 | .read = tracing_read_pipe, |
3c56819b | 3235 | .splice_read = tracing_splice_read_pipe, |
4bf39a94 | 3236 | .release = tracing_release_pipe, |
b3806b43 SR |
3237 | }; |
3238 | ||
5e2336a0 | 3239 | static const struct file_operations tracing_entries_fops = { |
a98a3c3f SR |
3240 | .open = tracing_open_generic, |
3241 | .read = tracing_entries_read, | |
3242 | .write = tracing_entries_write, | |
3243 | }; | |
3244 | ||
5e2336a0 | 3245 | static const struct file_operations tracing_mark_fops = { |
43a15386 | 3246 | .open = tracing_open_generic, |
5bf9a1ee PP |
3247 | .write = tracing_mark_write, |
3248 | }; | |
3249 | ||
2cadf913 SR |
3250 | struct ftrace_buffer_info { |
3251 | struct trace_array *tr; | |
3252 | void *spare; | |
3253 | int cpu; | |
3254 | unsigned int read; | |
3255 | }; | |
3256 | ||
3257 | static int tracing_buffers_open(struct inode *inode, struct file *filp) | |
3258 | { | |
3259 | int cpu = (int)(long)inode->i_private; | |
3260 | struct ftrace_buffer_info *info; | |
3261 | ||
3262 | if (tracing_disabled) | |
3263 | return -ENODEV; | |
3264 | ||
3265 | info = kzalloc(sizeof(*info), GFP_KERNEL); | |
3266 | if (!info) | |
3267 | return -ENOMEM; | |
3268 | ||
3269 | info->tr = &global_trace; | |
3270 | info->cpu = cpu; | |
ddd538f3 | 3271 | info->spare = NULL; |
2cadf913 SR |
3272 | /* Force reading ring buffer for first read */ |
3273 | info->read = (unsigned int)-1; | |
2cadf913 SR |
3274 | |
3275 | filp->private_data = info; | |
3276 | ||
d1e7e02f | 3277 | return nonseekable_open(inode, filp); |
2cadf913 SR |
3278 | } |
3279 | ||
3280 | static ssize_t | |
3281 | tracing_buffers_read(struct file *filp, char __user *ubuf, | |
3282 | size_t count, loff_t *ppos) | |
3283 | { | |
3284 | struct ftrace_buffer_info *info = filp->private_data; | |
3285 | unsigned int pos; | |
3286 | ssize_t ret; | |
3287 | size_t size; | |
3288 | ||
2dc5d12b SR |
3289 | if (!count) |
3290 | return 0; | |
3291 | ||
ddd538f3 LJ |
3292 | if (!info->spare) |
3293 | info->spare = ring_buffer_alloc_read_page(info->tr->buffer); | |
3294 | if (!info->spare) | |
3295 | return -ENOMEM; | |
3296 | ||
2cadf913 SR |
3297 | /* Do we have previous read data to read? */ |
3298 | if (info->read < PAGE_SIZE) | |
3299 | goto read; | |
3300 | ||
3301 | info->read = 0; | |
3302 | ||
3303 | ret = ring_buffer_read_page(info->tr->buffer, | |
3304 | &info->spare, | |
3305 | count, | |
3306 | info->cpu, 0); | |
3307 | if (ret < 0) | |
3308 | return 0; | |
3309 | ||
3310 | pos = ring_buffer_page_len(info->spare); | |
3311 | ||
3312 | if (pos < PAGE_SIZE) | |
3313 | memset(info->spare + pos, 0, PAGE_SIZE - pos); | |
3314 | ||
3315 | read: | |
3316 | size = PAGE_SIZE - info->read; | |
3317 | if (size > count) | |
3318 | size = count; | |
3319 | ||
3320 | ret = copy_to_user(ubuf, info->spare + info->read, size); | |
2dc5d12b | 3321 | if (ret == size) |
2cadf913 | 3322 | return -EFAULT; |
2dc5d12b SR |
3323 | size -= ret; |
3324 | ||
2cadf913 SR |
3325 | *ppos += size; |
3326 | info->read += size; | |
3327 | ||
3328 | return size; | |
3329 | } | |
3330 | ||
3331 | static int tracing_buffers_release(struct inode *inode, struct file *file) | |
3332 | { | |
3333 | struct ftrace_buffer_info *info = file->private_data; | |
3334 | ||
ddd538f3 LJ |
3335 | if (info->spare) |
3336 | ring_buffer_free_read_page(info->tr->buffer, info->spare); | |
2cadf913 SR |
3337 | kfree(info); |
3338 | ||
3339 | return 0; | |
3340 | } | |
3341 | ||
3342 | struct buffer_ref { | |
3343 | struct ring_buffer *buffer; | |
3344 | void *page; | |
3345 | int ref; | |
3346 | }; | |
3347 | ||
3348 | static void buffer_pipe_buf_release(struct pipe_inode_info *pipe, | |
3349 | struct pipe_buffer *buf) | |
3350 | { | |
3351 | struct buffer_ref *ref = (struct buffer_ref *)buf->private; | |
3352 | ||
3353 | if (--ref->ref) | |
3354 | return; | |
3355 | ||
3356 | ring_buffer_free_read_page(ref->buffer, ref->page); | |
3357 | kfree(ref); | |
3358 | buf->private = 0; | |
3359 | } | |
3360 | ||
3361 | static int buffer_pipe_buf_steal(struct pipe_inode_info *pipe, | |
3362 | struct pipe_buffer *buf) | |
3363 | { | |
3364 | return 1; | |
3365 | } | |
3366 | ||
3367 | static void buffer_pipe_buf_get(struct pipe_inode_info *pipe, | |
3368 | struct pipe_buffer *buf) | |
3369 | { | |
3370 | struct buffer_ref *ref = (struct buffer_ref *)buf->private; | |
3371 | ||
3372 | ref->ref++; | |
3373 | } | |
3374 | ||
3375 | /* Pipe buffer operations for a buffer. */ | |
3376 | static struct pipe_buf_operations buffer_pipe_buf_ops = { | |
3377 | .can_merge = 0, | |
3378 | .map = generic_pipe_buf_map, | |
3379 | .unmap = generic_pipe_buf_unmap, | |
3380 | .confirm = generic_pipe_buf_confirm, | |
3381 | .release = buffer_pipe_buf_release, | |
3382 | .steal = buffer_pipe_buf_steal, | |
3383 | .get = buffer_pipe_buf_get, | |
3384 | }; | |
3385 | ||
3386 | /* | |
3387 | * Callback from splice_to_pipe(), if we need to release some pages | |
3388 | * at the end of the spd in case we error'ed out in filling the pipe. | |
3389 | */ | |
3390 | static void buffer_spd_release(struct splice_pipe_desc *spd, unsigned int i) | |
3391 | { | |
3392 | struct buffer_ref *ref = | |
3393 | (struct buffer_ref *)spd->partial[i].private; | |
3394 | ||
3395 | if (--ref->ref) | |
3396 | return; | |
3397 | ||
3398 | ring_buffer_free_read_page(ref->buffer, ref->page); | |
3399 | kfree(ref); | |
3400 | spd->partial[i].private = 0; | |
3401 | } | |
3402 | ||
3403 | static ssize_t | |
3404 | tracing_buffers_splice_read(struct file *file, loff_t *ppos, | |
3405 | struct pipe_inode_info *pipe, size_t len, | |
3406 | unsigned int flags) | |
3407 | { | |
3408 | struct ftrace_buffer_info *info = file->private_data; | |
3409 | struct partial_page partial[PIPE_BUFFERS]; | |
3410 | struct page *pages[PIPE_BUFFERS]; | |
3411 | struct splice_pipe_desc spd = { | |
3412 | .pages = pages, | |
3413 | .partial = partial, | |
3414 | .flags = flags, | |
3415 | .ops = &buffer_pipe_buf_ops, | |
3416 | .spd_release = buffer_spd_release, | |
3417 | }; | |
3418 | struct buffer_ref *ref; | |
3419 | int size, i; | |
3420 | size_t ret; | |
3421 | ||
93cfb3c9 LJ |
3422 | if (*ppos & (PAGE_SIZE - 1)) { |
3423 | WARN_ONCE(1, "Ftrace: previous read must page-align\n"); | |
3424 | return -EINVAL; | |
3425 | } | |
2cadf913 | 3426 | |
93cfb3c9 LJ |
3427 | if (len & (PAGE_SIZE - 1)) { |
3428 | WARN_ONCE(1, "Ftrace: splice_read should page-align\n"); | |
3429 | if (len < PAGE_SIZE) | |
3430 | return -EINVAL; | |
3431 | len &= PAGE_MASK; | |
3432 | } | |
2cadf913 | 3433 | |
93cfb3c9 | 3434 | for (i = 0; i < PIPE_BUFFERS && len; i++, len -= PAGE_SIZE) { |
2cadf913 SR |
3435 | struct page *page; |
3436 | int r; | |
3437 | ||
3438 | ref = kzalloc(sizeof(*ref), GFP_KERNEL); | |
3439 | if (!ref) | |
3440 | break; | |
3441 | ||
3442 | ref->buffer = info->tr->buffer; | |
3443 | ref->page = ring_buffer_alloc_read_page(ref->buffer); | |
3444 | if (!ref->page) { | |
3445 | kfree(ref); | |
3446 | break; | |
3447 | } | |
3448 | ||
3449 | r = ring_buffer_read_page(ref->buffer, &ref->page, | |
3450 | len, info->cpu, 0); | |
3451 | if (r < 0) { | |
3452 | ring_buffer_free_read_page(ref->buffer, | |
3453 | ref->page); | |
3454 | kfree(ref); | |
3455 | break; | |
3456 | } | |
3457 | ||
3458 | /* | |
3459 | * zero out any left over data, this is going to | |
3460 | * user land. | |
3461 | */ | |
3462 | size = ring_buffer_page_len(ref->page); | |
3463 | if (size < PAGE_SIZE) | |
3464 | memset(ref->page + size, 0, PAGE_SIZE - size); | |
3465 | ||
3466 | page = virt_to_page(ref->page); | |
3467 | ||
3468 | spd.pages[i] = page; | |
3469 | spd.partial[i].len = PAGE_SIZE; | |
3470 | spd.partial[i].offset = 0; | |
3471 | spd.partial[i].private = (unsigned long)ref; | |
3472 | spd.nr_pages++; | |
93cfb3c9 | 3473 | *ppos += PAGE_SIZE; |
2cadf913 SR |
3474 | } |
3475 | ||
3476 | spd.nr_pages = i; | |
3477 | ||
3478 | /* did we read anything? */ | |
3479 | if (!spd.nr_pages) { | |
3480 | if (flags & SPLICE_F_NONBLOCK) | |
3481 | ret = -EAGAIN; | |
3482 | else | |
3483 | ret = 0; | |
3484 | /* TODO: block */ | |
3485 | return ret; | |
3486 | } | |
3487 | ||
3488 | ret = splice_to_pipe(pipe, &spd); | |
3489 | ||
3490 | return ret; | |
3491 | } | |
3492 | ||
3493 | static const struct file_operations tracing_buffers_fops = { | |
3494 | .open = tracing_buffers_open, | |
3495 | .read = tracing_buffers_read, | |
3496 | .release = tracing_buffers_release, | |
3497 | .splice_read = tracing_buffers_splice_read, | |
3498 | .llseek = no_llseek, | |
3499 | }; | |
3500 | ||
bc0c38d1 SR |
3501 | #ifdef CONFIG_DYNAMIC_FTRACE |
3502 | ||
b807c3d0 SR |
3503 | int __weak ftrace_arch_read_dyn_info(char *buf, int size) |
3504 | { | |
3505 | return 0; | |
3506 | } | |
3507 | ||
bc0c38d1 | 3508 | static ssize_t |
b807c3d0 | 3509 | tracing_read_dyn_info(struct file *filp, char __user *ubuf, |
bc0c38d1 SR |
3510 | size_t cnt, loff_t *ppos) |
3511 | { | |
a26a2a27 SR |
3512 | static char ftrace_dyn_info_buffer[1024]; |
3513 | static DEFINE_MUTEX(dyn_info_mutex); | |
bc0c38d1 | 3514 | unsigned long *p = filp->private_data; |
b807c3d0 | 3515 | char *buf = ftrace_dyn_info_buffer; |
a26a2a27 | 3516 | int size = ARRAY_SIZE(ftrace_dyn_info_buffer); |
bc0c38d1 SR |
3517 | int r; |
3518 | ||
b807c3d0 SR |
3519 | mutex_lock(&dyn_info_mutex); |
3520 | r = sprintf(buf, "%ld ", *p); | |
4bf39a94 | 3521 | |
a26a2a27 | 3522 | r += ftrace_arch_read_dyn_info(buf+r, (size-1)-r); |
b807c3d0 SR |
3523 | buf[r++] = '\n'; |
3524 | ||
3525 | r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); | |
3526 | ||
3527 | mutex_unlock(&dyn_info_mutex); | |
3528 | ||
3529 | return r; | |
bc0c38d1 SR |
3530 | } |
3531 | ||
5e2336a0 | 3532 | static const struct file_operations tracing_dyn_info_fops = { |
4bf39a94 | 3533 | .open = tracing_open_generic, |
b807c3d0 | 3534 | .read = tracing_read_dyn_info, |
bc0c38d1 SR |
3535 | }; |
3536 | #endif | |
3537 | ||
3538 | static struct dentry *d_tracer; | |
3539 | ||
3540 | struct dentry *tracing_init_dentry(void) | |
3541 | { | |
3542 | static int once; | |
3543 | ||
3544 | if (d_tracer) | |
3545 | return d_tracer; | |
3546 | ||
3e1f60b8 FW |
3547 | if (!debugfs_initialized()) |
3548 | return NULL; | |
3549 | ||
bc0c38d1 SR |
3550 | d_tracer = debugfs_create_dir("tracing", NULL); |
3551 | ||
3552 | if (!d_tracer && !once) { | |
3553 | once = 1; | |
3554 | pr_warning("Could not create debugfs directory 'tracing'\n"); | |
3555 | return NULL; | |
3556 | } | |
3557 | ||
3558 | return d_tracer; | |
3559 | } | |
3560 | ||
b04cc6b1 FW |
3561 | static struct dentry *d_percpu; |
3562 | ||
3563 | struct dentry *tracing_dentry_percpu(void) | |
3564 | { | |
3565 | static int once; | |
3566 | struct dentry *d_tracer; | |
3567 | ||
3568 | if (d_percpu) | |
3569 | return d_percpu; | |
3570 | ||
3571 | d_tracer = tracing_init_dentry(); | |
3572 | ||
3573 | if (!d_tracer) | |
3574 | return NULL; | |
3575 | ||
3576 | d_percpu = debugfs_create_dir("per_cpu", d_tracer); | |
3577 | ||
3578 | if (!d_percpu && !once) { | |
3579 | once = 1; | |
3580 | pr_warning("Could not create debugfs directory 'per_cpu'\n"); | |
3581 | return NULL; | |
3582 | } | |
3583 | ||
3584 | return d_percpu; | |
3585 | } | |
3586 | ||
3587 | static void tracing_init_debugfs_percpu(long cpu) | |
3588 | { | |
3589 | struct dentry *d_percpu = tracing_dentry_percpu(); | |
5452af66 | 3590 | struct dentry *d_cpu; |
8656e7a2 FW |
3591 | /* strlen(cpu) + MAX(log10(cpu)) + '\0' */ |
3592 | char cpu_dir[7]; | |
b04cc6b1 FW |
3593 | |
3594 | if (cpu > 999 || cpu < 0) | |
3595 | return; | |
3596 | ||
8656e7a2 FW |
3597 | sprintf(cpu_dir, "cpu%ld", cpu); |
3598 | d_cpu = debugfs_create_dir(cpu_dir, d_percpu); | |
3599 | if (!d_cpu) { | |
3600 | pr_warning("Could not create debugfs '%s' entry\n", cpu_dir); | |
3601 | return; | |
3602 | } | |
b04cc6b1 | 3603 | |
8656e7a2 | 3604 | /* per cpu trace_pipe */ |
5452af66 FW |
3605 | trace_create_file("trace_pipe", 0444, d_cpu, |
3606 | (void *) cpu, &tracing_pipe_fops); | |
b04cc6b1 FW |
3607 | |
3608 | /* per cpu trace */ | |
5452af66 FW |
3609 | trace_create_file("trace", 0644, d_cpu, |
3610 | (void *) cpu, &tracing_fops); | |
7f96f93f | 3611 | |
5452af66 FW |
3612 | trace_create_file("trace_pipe_raw", 0444, d_cpu, |
3613 | (void *) cpu, &tracing_buffers_fops); | |
b04cc6b1 FW |
3614 | } |
3615 | ||
60a11774 SR |
3616 | #ifdef CONFIG_FTRACE_SELFTEST |
3617 | /* Let selftest have access to static functions in this file */ | |
3618 | #include "trace_selftest.c" | |
3619 | #endif | |
3620 | ||
577b785f SR |
3621 | struct trace_option_dentry { |
3622 | struct tracer_opt *opt; | |
3623 | struct tracer_flags *flags; | |
3624 | struct dentry *entry; | |
3625 | }; | |
3626 | ||
3627 | static ssize_t | |
3628 | trace_options_read(struct file *filp, char __user *ubuf, size_t cnt, | |
3629 | loff_t *ppos) | |
3630 | { | |
3631 | struct trace_option_dentry *topt = filp->private_data; | |
3632 | char *buf; | |
3633 | ||
3634 | if (topt->flags->val & topt->opt->bit) | |
3635 | buf = "1\n"; | |
3636 | else | |
3637 | buf = "0\n"; | |
3638 | ||
3639 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); | |
3640 | } | |
3641 | ||
3642 | static ssize_t | |
3643 | trace_options_write(struct file *filp, const char __user *ubuf, size_t cnt, | |
3644 | loff_t *ppos) | |
3645 | { | |
3646 | struct trace_option_dentry *topt = filp->private_data; | |
3647 | unsigned long val; | |
3648 | char buf[64]; | |
3649 | int ret; | |
3650 | ||
3651 | if (cnt >= sizeof(buf)) | |
3652 | return -EINVAL; | |
3653 | ||
3654 | if (copy_from_user(&buf, ubuf, cnt)) | |
3655 | return -EFAULT; | |
3656 | ||
3657 | buf[cnt] = 0; | |
3658 | ||
3659 | ret = strict_strtoul(buf, 10, &val); | |
3660 | if (ret < 0) | |
3661 | return ret; | |
3662 | ||
3663 | ret = 0; | |
3664 | switch (val) { | |
3665 | case 0: | |
3666 | /* do nothing if already cleared */ | |
3667 | if (!(topt->flags->val & topt->opt->bit)) | |
3668 | break; | |
3669 | ||
3670 | mutex_lock(&trace_types_lock); | |
3671 | if (current_trace->set_flag) | |
3672 | ret = current_trace->set_flag(topt->flags->val, | |
3673 | topt->opt->bit, 0); | |
3674 | mutex_unlock(&trace_types_lock); | |
3675 | if (ret) | |
3676 | return ret; | |
3677 | topt->flags->val &= ~topt->opt->bit; | |
3678 | break; | |
3679 | case 1: | |
3680 | /* do nothing if already set */ | |
3681 | if (topt->flags->val & topt->opt->bit) | |
3682 | break; | |
3683 | ||
3684 | mutex_lock(&trace_types_lock); | |
3685 | if (current_trace->set_flag) | |
3686 | ret = current_trace->set_flag(topt->flags->val, | |
3687 | topt->opt->bit, 1); | |
3688 | mutex_unlock(&trace_types_lock); | |
3689 | if (ret) | |
3690 | return ret; | |
3691 | topt->flags->val |= topt->opt->bit; | |
3692 | break; | |
3693 | ||
3694 | default: | |
3695 | return -EINVAL; | |
3696 | } | |
3697 | ||
3698 | *ppos += cnt; | |
3699 | ||
3700 | return cnt; | |
3701 | } | |
3702 | ||
3703 | ||
3704 | static const struct file_operations trace_options_fops = { | |
3705 | .open = tracing_open_generic, | |
3706 | .read = trace_options_read, | |
3707 | .write = trace_options_write, | |
3708 | }; | |
3709 | ||
a8259075 SR |
3710 | static ssize_t |
3711 | trace_options_core_read(struct file *filp, char __user *ubuf, size_t cnt, | |
3712 | loff_t *ppos) | |
3713 | { | |
3714 | long index = (long)filp->private_data; | |
3715 | char *buf; | |
3716 | ||
3717 | if (trace_flags & (1 << index)) | |
3718 | buf = "1\n"; | |
3719 | else | |
3720 | buf = "0\n"; | |
3721 | ||
3722 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); | |
3723 | } | |
3724 | ||
3725 | static ssize_t | |
3726 | trace_options_core_write(struct file *filp, const char __user *ubuf, size_t cnt, | |
3727 | loff_t *ppos) | |
3728 | { | |
3729 | long index = (long)filp->private_data; | |
3730 | char buf[64]; | |
3731 | unsigned long val; | |
3732 | int ret; | |
3733 | ||
3734 | if (cnt >= sizeof(buf)) | |
3735 | return -EINVAL; | |
3736 | ||
3737 | if (copy_from_user(&buf, ubuf, cnt)) | |
3738 | return -EFAULT; | |
3739 | ||
3740 | buf[cnt] = 0; | |
3741 | ||
3742 | ret = strict_strtoul(buf, 10, &val); | |
3743 | if (ret < 0) | |
3744 | return ret; | |
3745 | ||
3746 | switch (val) { | |
3747 | case 0: | |
3748 | trace_flags &= ~(1 << index); | |
3749 | break; | |
3750 | case 1: | |
3751 | trace_flags |= 1 << index; | |
3752 | break; | |
3753 | ||
3754 | default: | |
3755 | return -EINVAL; | |
3756 | } | |
3757 | ||
3758 | *ppos += cnt; | |
3759 | ||
3760 | return cnt; | |
3761 | } | |
3762 | ||
a8259075 SR |
3763 | static const struct file_operations trace_options_core_fops = { |
3764 | .open = tracing_open_generic, | |
3765 | .read = trace_options_core_read, | |
3766 | .write = trace_options_core_write, | |
3767 | }; | |
3768 | ||
5452af66 FW |
3769 | struct dentry *trace_create_file(const char *name, |
3770 | mode_t mode, | |
3771 | struct dentry *parent, | |
3772 | void *data, | |
3773 | const struct file_operations *fops) | |
3774 | { | |
3775 | struct dentry *ret; | |
3776 | ||
3777 | ret = debugfs_create_file(name, mode, parent, data, fops); | |
3778 | if (!ret) | |
3779 | pr_warning("Could not create debugfs '%s' entry\n", name); | |
3780 | ||
3781 | return ret; | |
3782 | } | |
3783 | ||
3784 | ||
a8259075 SR |
3785 | static struct dentry *trace_options_init_dentry(void) |
3786 | { | |
3787 | struct dentry *d_tracer; | |
3788 | static struct dentry *t_options; | |
3789 | ||
3790 | if (t_options) | |
3791 | return t_options; | |
3792 | ||
3793 | d_tracer = tracing_init_dentry(); | |
3794 | if (!d_tracer) | |
3795 | return NULL; | |
3796 | ||
3797 | t_options = debugfs_create_dir("options", d_tracer); | |
3798 | if (!t_options) { | |
3799 | pr_warning("Could not create debugfs directory 'options'\n"); | |
3800 | return NULL; | |
3801 | } | |
3802 | ||
3803 | return t_options; | |
3804 | } | |
3805 | ||
577b785f SR |
3806 | static void |
3807 | create_trace_option_file(struct trace_option_dentry *topt, | |
3808 | struct tracer_flags *flags, | |
3809 | struct tracer_opt *opt) | |
3810 | { | |
3811 | struct dentry *t_options; | |
577b785f SR |
3812 | |
3813 | t_options = trace_options_init_dentry(); | |
3814 | if (!t_options) | |
3815 | return; | |
3816 | ||
3817 | topt->flags = flags; | |
3818 | topt->opt = opt; | |
3819 | ||
5452af66 | 3820 | topt->entry = trace_create_file(opt->name, 0644, t_options, topt, |
577b785f SR |
3821 | &trace_options_fops); |
3822 | ||
577b785f SR |
3823 | } |
3824 | ||
3825 | static struct trace_option_dentry * | |
3826 | create_trace_option_files(struct tracer *tracer) | |
3827 | { | |
3828 | struct trace_option_dentry *topts; | |
3829 | struct tracer_flags *flags; | |
3830 | struct tracer_opt *opts; | |
3831 | int cnt; | |
3832 | ||
3833 | if (!tracer) | |
3834 | return NULL; | |
3835 | ||
3836 | flags = tracer->flags; | |
3837 | ||
3838 | if (!flags || !flags->opts) | |
3839 | return NULL; | |
3840 | ||
3841 | opts = flags->opts; | |
3842 | ||
3843 | for (cnt = 0; opts[cnt].name; cnt++) | |
3844 | ; | |
3845 | ||
0cfe8245 | 3846 | topts = kcalloc(cnt + 1, sizeof(*topts), GFP_KERNEL); |
577b785f SR |
3847 | if (!topts) |
3848 | return NULL; | |
3849 | ||
3850 | for (cnt = 0; opts[cnt].name; cnt++) | |
3851 | create_trace_option_file(&topts[cnt], flags, | |
3852 | &opts[cnt]); | |
3853 | ||
3854 | return topts; | |
3855 | } | |
3856 | ||
3857 | static void | |
3858 | destroy_trace_option_files(struct trace_option_dentry *topts) | |
3859 | { | |
3860 | int cnt; | |
3861 | ||
3862 | if (!topts) | |
3863 | return; | |
3864 | ||
3865 | for (cnt = 0; topts[cnt].opt; cnt++) { | |
3866 | if (topts[cnt].entry) | |
3867 | debugfs_remove(topts[cnt].entry); | |
3868 | } | |
3869 | ||
3870 | kfree(topts); | |
3871 | } | |
3872 | ||
a8259075 SR |
3873 | static struct dentry * |
3874 | create_trace_option_core_file(const char *option, long index) | |
3875 | { | |
3876 | struct dentry *t_options; | |
a8259075 SR |
3877 | |
3878 | t_options = trace_options_init_dentry(); | |
3879 | if (!t_options) | |
3880 | return NULL; | |
3881 | ||
5452af66 | 3882 | return trace_create_file(option, 0644, t_options, (void *)index, |
a8259075 | 3883 | &trace_options_core_fops); |
a8259075 SR |
3884 | } |
3885 | ||
3886 | static __init void create_trace_options_dir(void) | |
3887 | { | |
3888 | struct dentry *t_options; | |
a8259075 SR |
3889 | int i; |
3890 | ||
3891 | t_options = trace_options_init_dentry(); | |
3892 | if (!t_options) | |
3893 | return; | |
3894 | ||
5452af66 FW |
3895 | for (i = 0; trace_options[i]; i++) |
3896 | create_trace_option_core_file(trace_options[i], i); | |
a8259075 SR |
3897 | } |
3898 | ||
b5ad384e | 3899 | static __init int tracer_init_debugfs(void) |
bc0c38d1 SR |
3900 | { |
3901 | struct dentry *d_tracer; | |
b04cc6b1 | 3902 | int cpu; |
bc0c38d1 SR |
3903 | |
3904 | d_tracer = tracing_init_dentry(); | |
3905 | ||
5452af66 FW |
3906 | trace_create_file("tracing_enabled", 0644, d_tracer, |
3907 | &global_trace, &tracing_ctrl_fops); | |
bc0c38d1 | 3908 | |
5452af66 FW |
3909 | trace_create_file("trace_options", 0644, d_tracer, |
3910 | NULL, &tracing_iter_fops); | |
bc0c38d1 | 3911 | |
5452af66 FW |
3912 | trace_create_file("tracing_cpumask", 0644, d_tracer, |
3913 | NULL, &tracing_cpumask_fops); | |
3914 | ||
3915 | trace_create_file("trace", 0644, d_tracer, | |
3916 | (void *) TRACE_PIPE_ALL_CPU, &tracing_fops); | |
3917 | ||
3918 | trace_create_file("available_tracers", 0444, d_tracer, | |
3919 | &global_trace, &show_traces_fops); | |
3920 | ||
3921 | trace_create_file("current_tracer", 0444, d_tracer, | |
3922 | &global_trace, &set_tracer_fops); | |
3923 | ||
3924 | trace_create_file("tracing_max_latency", 0644, d_tracer, | |
3925 | &tracing_max_latency, &tracing_max_lat_fops); | |
3926 | ||
3927 | trace_create_file("tracing_thresh", 0644, d_tracer, | |
3928 | &tracing_thresh, &tracing_max_lat_fops); | |
a8259075 | 3929 | |
5452af66 FW |
3930 | trace_create_file("README", 0644, d_tracer, |
3931 | NULL, &tracing_readme_fops); | |
3932 | ||
3933 | trace_create_file("trace_pipe", 0444, d_tracer, | |
b04cc6b1 | 3934 | (void *) TRACE_PIPE_ALL_CPU, &tracing_pipe_fops); |
5452af66 FW |
3935 | |
3936 | trace_create_file("buffer_size_kb", 0644, d_tracer, | |
3937 | &global_trace, &tracing_entries_fops); | |
3938 | ||
3939 | trace_create_file("trace_marker", 0220, d_tracer, | |
3940 | NULL, &tracing_mark_fops); | |
5bf9a1ee | 3941 | |
bc0c38d1 | 3942 | #ifdef CONFIG_DYNAMIC_FTRACE |
5452af66 FW |
3943 | trace_create_file("dyn_ftrace_total_info", 0444, d_tracer, |
3944 | &ftrace_update_tot_cnt, &tracing_dyn_info_fops); | |
bc0c38d1 | 3945 | #endif |
d618b3e6 IM |
3946 | #ifdef CONFIG_SYSPROF_TRACER |
3947 | init_tracer_sysprof_debugfs(d_tracer); | |
3948 | #endif | |
b04cc6b1 | 3949 | |
5452af66 FW |
3950 | create_trace_options_dir(); |
3951 | ||
b04cc6b1 FW |
3952 | for_each_tracing_cpu(cpu) |
3953 | tracing_init_debugfs_percpu(cpu); | |
3954 | ||
b5ad384e | 3955 | return 0; |
bc0c38d1 SR |
3956 | } |
3957 | ||
3f5a54e3 SR |
3958 | static int trace_panic_handler(struct notifier_block *this, |
3959 | unsigned long event, void *unused) | |
3960 | { | |
944ac425 SR |
3961 | if (ftrace_dump_on_oops) |
3962 | ftrace_dump(); | |
3f5a54e3 SR |
3963 | return NOTIFY_OK; |
3964 | } | |
3965 | ||
3966 | static struct notifier_block trace_panic_notifier = { | |
3967 | .notifier_call = trace_panic_handler, | |
3968 | .next = NULL, | |
3969 | .priority = 150 /* priority: INT_MAX >= x >= 0 */ | |
3970 | }; | |
3971 | ||
3972 | static int trace_die_handler(struct notifier_block *self, | |
3973 | unsigned long val, | |
3974 | void *data) | |
3975 | { | |
3976 | switch (val) { | |
3977 | case DIE_OOPS: | |
944ac425 SR |
3978 | if (ftrace_dump_on_oops) |
3979 | ftrace_dump(); | |
3f5a54e3 SR |
3980 | break; |
3981 | default: | |
3982 | break; | |
3983 | } | |
3984 | return NOTIFY_OK; | |
3985 | } | |
3986 | ||
3987 | static struct notifier_block trace_die_notifier = { | |
3988 | .notifier_call = trace_die_handler, | |
3989 | .priority = 200 | |
3990 | }; | |
3991 | ||
3992 | /* | |
3993 | * printk is set to max of 1024, we really don't need it that big. | |
3994 | * Nothing should be printing 1000 characters anyway. | |
3995 | */ | |
3996 | #define TRACE_MAX_PRINT 1000 | |
3997 | ||
3998 | /* | |
3999 | * Define here KERN_TRACE so that we have one place to modify | |
4000 | * it if we decide to change what log level the ftrace dump | |
4001 | * should be at. | |
4002 | */ | |
428aee14 | 4003 | #define KERN_TRACE KERN_EMERG |
3f5a54e3 SR |
4004 | |
4005 | static void | |
4006 | trace_printk_seq(struct trace_seq *s) | |
4007 | { | |
4008 | /* Probably should print a warning here. */ | |
4009 | if (s->len >= 1000) | |
4010 | s->len = 1000; | |
4011 | ||
4012 | /* should be zero ended, but we are paranoid. */ | |
4013 | s->buffer[s->len] = 0; | |
4014 | ||
4015 | printk(KERN_TRACE "%s", s->buffer); | |
4016 | ||
f9520750 | 4017 | trace_seq_init(s); |
3f5a54e3 SR |
4018 | } |
4019 | ||
cf586b61 | 4020 | static void __ftrace_dump(bool disable_tracing) |
3f5a54e3 SR |
4021 | { |
4022 | static DEFINE_SPINLOCK(ftrace_dump_lock); | |
4023 | /* use static because iter can be a bit big for the stack */ | |
4024 | static struct trace_iterator iter; | |
cf586b61 | 4025 | unsigned int old_userobj; |
3f5a54e3 | 4026 | static int dump_ran; |
d769041f SR |
4027 | unsigned long flags; |
4028 | int cnt = 0, cpu; | |
3f5a54e3 SR |
4029 | |
4030 | /* only one dump */ | |
4031 | spin_lock_irqsave(&ftrace_dump_lock, flags); | |
4032 | if (dump_ran) | |
4033 | goto out; | |
4034 | ||
4035 | dump_ran = 1; | |
4036 | ||
0ee6b6cf | 4037 | tracing_off(); |
cf586b61 FW |
4038 | |
4039 | if (disable_tracing) | |
4040 | ftrace_kill(); | |
3f5a54e3 | 4041 | |
d769041f SR |
4042 | for_each_tracing_cpu(cpu) { |
4043 | atomic_inc(&global_trace.data[cpu]->disabled); | |
4044 | } | |
4045 | ||
cf586b61 FW |
4046 | old_userobj = trace_flags & TRACE_ITER_SYM_USEROBJ; |
4047 | ||
b54d3de9 TE |
4048 | /* don't look at user memory in panic mode */ |
4049 | trace_flags &= ~TRACE_ITER_SYM_USEROBJ; | |
4050 | ||
3f5a54e3 SR |
4051 | printk(KERN_TRACE "Dumping ftrace buffer:\n"); |
4052 | ||
e543ad76 | 4053 | /* Simulate the iterator */ |
3f5a54e3 SR |
4054 | iter.tr = &global_trace; |
4055 | iter.trace = current_trace; | |
e543ad76 | 4056 | iter.cpu_file = TRACE_PIPE_ALL_CPU; |
3f5a54e3 SR |
4057 | |
4058 | /* | |
4059 | * We need to stop all tracing on all CPUS to read the | |
4060 | * the next buffer. This is a bit expensive, but is | |
4061 | * not done often. We fill all what we can read, | |
4062 | * and then release the locks again. | |
4063 | */ | |
4064 | ||
3f5a54e3 SR |
4065 | while (!trace_empty(&iter)) { |
4066 | ||
4067 | if (!cnt) | |
4068 | printk(KERN_TRACE "---------------------------------\n"); | |
4069 | ||
4070 | cnt++; | |
4071 | ||
4072 | /* reset all but tr, trace, and overruns */ | |
4073 | memset(&iter.seq, 0, | |
4074 | sizeof(struct trace_iterator) - | |
4075 | offsetof(struct trace_iterator, seq)); | |
4076 | iter.iter_flags |= TRACE_FILE_LAT_FMT; | |
4077 | iter.pos = -1; | |
4078 | ||
4079 | if (find_next_entry_inc(&iter) != NULL) { | |
4080 | print_trace_line(&iter); | |
4081 | trace_consume(&iter); | |
4082 | } | |
4083 | ||
4084 | trace_printk_seq(&iter.seq); | |
4085 | } | |
4086 | ||
4087 | if (!cnt) | |
4088 | printk(KERN_TRACE " (ftrace buffer empty)\n"); | |
4089 | else | |
4090 | printk(KERN_TRACE "---------------------------------\n"); | |
4091 | ||
cf586b61 FW |
4092 | /* Re-enable tracing if requested */ |
4093 | if (!disable_tracing) { | |
4094 | trace_flags |= old_userobj; | |
4095 | ||
4096 | for_each_tracing_cpu(cpu) { | |
4097 | atomic_dec(&global_trace.data[cpu]->disabled); | |
4098 | } | |
4099 | tracing_on(); | |
4100 | } | |
4101 | ||
3f5a54e3 SR |
4102 | out: |
4103 | spin_unlock_irqrestore(&ftrace_dump_lock, flags); | |
4104 | } | |
4105 | ||
cf586b61 FW |
4106 | /* By default: disable tracing after the dump */ |
4107 | void ftrace_dump(void) | |
4108 | { | |
4109 | __ftrace_dump(true); | |
4110 | } | |
4111 | ||
3928a8a2 | 4112 | __init static int tracer_alloc_buffers(void) |
bc0c38d1 | 4113 | { |
4c11d7ae | 4114 | struct trace_array_cpu *data; |
73c5162a | 4115 | int ring_buf_size; |
4c11d7ae | 4116 | int i; |
9e01c1b7 | 4117 | int ret = -ENOMEM; |
4c11d7ae | 4118 | |
9e01c1b7 RR |
4119 | if (!alloc_cpumask_var(&tracing_buffer_mask, GFP_KERNEL)) |
4120 | goto out; | |
4121 | ||
4122 | if (!alloc_cpumask_var(&tracing_cpumask, GFP_KERNEL)) | |
4123 | goto out_free_buffer_mask; | |
4c11d7ae | 4124 | |
b04cc6b1 FW |
4125 | if (!alloc_cpumask_var(&tracing_reader_cpumask, GFP_KERNEL)) |
4126 | goto out_free_tracing_cpumask; | |
4127 | ||
73c5162a SR |
4128 | /* To save memory, keep the ring buffer size to its minimum */ |
4129 | if (ring_buffer_expanded) | |
4130 | ring_buf_size = trace_buf_size; | |
4131 | else | |
4132 | ring_buf_size = 1; | |
4133 | ||
9e01c1b7 RR |
4134 | cpumask_copy(tracing_buffer_mask, cpu_possible_mask); |
4135 | cpumask_copy(tracing_cpumask, cpu_all_mask); | |
b04cc6b1 | 4136 | cpumask_clear(tracing_reader_cpumask); |
9e01c1b7 RR |
4137 | |
4138 | /* TODO: make the number of buffers hot pluggable with CPUS */ | |
73c5162a | 4139 | global_trace.buffer = ring_buffer_alloc(ring_buf_size, |
3928a8a2 SR |
4140 | TRACE_BUFFER_FLAGS); |
4141 | if (!global_trace.buffer) { | |
4142 | printk(KERN_ERR "tracer: failed to allocate ring buffer!\n"); | |
4143 | WARN_ON(1); | |
9e01c1b7 | 4144 | goto out_free_cpumask; |
4c11d7ae | 4145 | } |
3928a8a2 | 4146 | global_trace.entries = ring_buffer_size(global_trace.buffer); |
4c11d7ae | 4147 | |
9e01c1b7 | 4148 | |
4c11d7ae | 4149 | #ifdef CONFIG_TRACER_MAX_TRACE |
73c5162a | 4150 | max_tr.buffer = ring_buffer_alloc(ring_buf_size, |
3928a8a2 SR |
4151 | TRACE_BUFFER_FLAGS); |
4152 | if (!max_tr.buffer) { | |
4153 | printk(KERN_ERR "tracer: failed to allocate max ring buffer!\n"); | |
4154 | WARN_ON(1); | |
4155 | ring_buffer_free(global_trace.buffer); | |
9e01c1b7 | 4156 | goto out_free_cpumask; |
4c11d7ae | 4157 | } |
3928a8a2 SR |
4158 | max_tr.entries = ring_buffer_size(max_tr.buffer); |
4159 | WARN_ON(max_tr.entries != global_trace.entries); | |
a98a3c3f | 4160 | #endif |
ab46428c | 4161 | |
4c11d7ae | 4162 | /* Allocate the first page for all buffers */ |
ab46428c | 4163 | for_each_tracing_cpu(i) { |
4c11d7ae | 4164 | data = global_trace.data[i] = &per_cpu(global_trace_cpu, i); |
bc0c38d1 | 4165 | max_tr.data[i] = &per_cpu(max_data, i); |
4c11d7ae | 4166 | } |
bc0c38d1 | 4167 | |
bc0c38d1 SR |
4168 | trace_init_cmdlines(); |
4169 | ||
43a15386 | 4170 | register_tracer(&nop_trace); |
79fb0768 | 4171 | current_trace = &nop_trace; |
b5ad384e FW |
4172 | #ifdef CONFIG_BOOT_TRACER |
4173 | register_tracer(&boot_tracer); | |
b5ad384e | 4174 | #endif |
60a11774 SR |
4175 | /* All seems OK, enable tracing */ |
4176 | tracing_disabled = 0; | |
3928a8a2 | 4177 | |
3f5a54e3 SR |
4178 | atomic_notifier_chain_register(&panic_notifier_list, |
4179 | &trace_panic_notifier); | |
4180 | ||
4181 | register_die_notifier(&trace_die_notifier); | |
2fc1dfbe FW |
4182 | |
4183 | return 0; | |
3f5a54e3 | 4184 | |
9e01c1b7 | 4185 | out_free_cpumask: |
b04cc6b1 FW |
4186 | free_cpumask_var(tracing_reader_cpumask); |
4187 | out_free_tracing_cpumask: | |
9e01c1b7 RR |
4188 | free_cpumask_var(tracing_cpumask); |
4189 | out_free_buffer_mask: | |
4190 | free_cpumask_var(tracing_buffer_mask); | |
4191 | out: | |
4192 | return ret; | |
bc0c38d1 | 4193 | } |
b2821ae6 SR |
4194 | |
4195 | __init static int clear_boot_tracer(void) | |
4196 | { | |
4197 | /* | |
4198 | * The default tracer at boot buffer is an init section. | |
4199 | * This function is called in lateinit. If we did not | |
4200 | * find the boot tracer, then clear it out, to prevent | |
4201 | * later registration from accessing the buffer that is | |
4202 | * about to be freed. | |
4203 | */ | |
4204 | if (!default_bootup_tracer) | |
4205 | return 0; | |
4206 | ||
4207 | printk(KERN_INFO "ftrace bootup tracer '%s' not registered.\n", | |
4208 | default_bootup_tracer); | |
4209 | default_bootup_tracer = NULL; | |
4210 | ||
4211 | return 0; | |
4212 | } | |
4213 | ||
b5ad384e FW |
4214 | early_initcall(tracer_alloc_buffers); |
4215 | fs_initcall(tracer_init_debugfs); | |
b2821ae6 | 4216 | late_initcall(clear_boot_tracer); |