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