2 * ring buffer based function tracer
4 * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
5 * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com>
7 * Originally taken from the RT patch by:
8 * Arnaldo Carvalho de Melo <acme@redhat.com>
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
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/notifier.h>
21 #include <linux/irqflags.h>
22 #include <linux/debugfs.h>
23 #include <linux/pagemap.h>
24 #include <linux/hardirq.h>
25 #include <linux/linkage.h>
26 #include <linux/uaccess.h>
27 #include <linux/kprobes.h>
28 #include <linux/ftrace.h>
29 #include <linux/module.h>
30 #include <linux/percpu.h>
31 #include <linux/splice.h>
32 #include <linux/kdebug.h>
33 #include <linux/string.h>
34 #include <linux/rwsem.h>
35 #include <linux/slab.h>
36 #include <linux/ctype.h>
37 #include <linux/init.h>
38 #include <linux/poll.h>
42 #include "trace_output.h"
45 * On boot up, the ring buffer is set to the minimum size, so that
46 * we do not waste memory on systems that are not using tracing.
48 int ring_buffer_expanded
;
51 * We need to change this state when a selftest is running.
52 * A selftest will lurk into the ring-buffer to count the
53 * entries inserted during the selftest although some concurrent
54 * insertions into the ring-buffer such as trace_printk could occurred
55 * at the same time, giving false positive or negative results.
57 static bool __read_mostly tracing_selftest_running
;
60 * If a tracer is running, we do not want to run SELFTEST.
62 bool __read_mostly tracing_selftest_disabled
;
64 /* For tracers that don't implement custom flags */
65 static struct tracer_opt dummy_tracer_opt
[] = {
69 static struct tracer_flags dummy_tracer_flags
= {
71 .opts
= dummy_tracer_opt
74 static int dummy_set_flag(u32 old_flags
, u32 bit
, int set
)
80 * Kill all tracing for good (never come back).
81 * It is initialized to 1 but will turn to zero if the initialization
82 * of the tracer is successful. But that is the only place that sets
85 static int tracing_disabled
= 1;
87 DEFINE_PER_CPU(int, ftrace_cpu_disabled
);
89 static inline void ftrace_disable_cpu(void)
92 __this_cpu_inc(ftrace_cpu_disabled
);
95 static inline void ftrace_enable_cpu(void)
97 __this_cpu_dec(ftrace_cpu_disabled
);
101 cpumask_var_t __read_mostly tracing_buffer_mask
;
104 * ftrace_dump_on_oops - variable to dump ftrace buffer on oops
106 * If there is an oops (or kernel panic) and the ftrace_dump_on_oops
107 * is set, then ftrace_dump is called. This will output the contents
108 * of the ftrace buffers to the console. This is very useful for
109 * capturing traces that lead to crashes and outputing it to a
112 * It is default off, but you can enable it with either specifying
113 * "ftrace_dump_on_oops" in the kernel command line, or setting
114 * /proc/sys/kernel/ftrace_dump_on_oops
115 * Set 1 if you want to dump buffers of all CPUs
116 * Set 2 if you want to dump the buffer of the CPU that triggered oops
119 enum ftrace_dump_mode ftrace_dump_on_oops
;
121 static int tracing_set_tracer(const char *buf
);
123 #define MAX_TRACER_SIZE 100
124 static char bootup_tracer_buf
[MAX_TRACER_SIZE
] __initdata
;
125 static char *default_bootup_tracer
;
127 static int __init
set_cmdline_ftrace(char *str
)
129 strncpy(bootup_tracer_buf
, str
, MAX_TRACER_SIZE
);
130 default_bootup_tracer
= bootup_tracer_buf
;
131 /* We are using ftrace early, expand it */
132 ring_buffer_expanded
= 1;
135 __setup("ftrace=", set_cmdline_ftrace
);
137 static int __init
set_ftrace_dump_on_oops(char *str
)
139 if (*str
++ != '=' || !*str
) {
140 ftrace_dump_on_oops
= DUMP_ALL
;
144 if (!strcmp("orig_cpu", str
)) {
145 ftrace_dump_on_oops
= DUMP_ORIG
;
151 __setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops
);
153 unsigned long long ns2usecs(cycle_t nsec
)
161 * The global_trace is the descriptor that holds the tracing
162 * buffers for the live tracing. For each CPU, it contains
163 * a link list of pages that will store trace entries. The
164 * page descriptor of the pages in the memory is used to hold
165 * the link list by linking the lru item in the page descriptor
166 * to each of the pages in the buffer per CPU.
168 * For each active CPU there is a data field that holds the
169 * pages for the buffer for that CPU. Each CPU has the same number
170 * of pages allocated for its buffer.
172 static struct trace_array global_trace
;
174 static DEFINE_PER_CPU(struct trace_array_cpu
, global_trace_cpu
);
176 int filter_current_check_discard(struct ring_buffer
*buffer
,
177 struct ftrace_event_call
*call
, void *rec
,
178 struct ring_buffer_event
*event
)
180 return filter_check_discard(call
, rec
, buffer
, event
);
182 EXPORT_SYMBOL_GPL(filter_current_check_discard
);
184 cycle_t
ftrace_now(int cpu
)
188 /* Early boot up does not have a buffer yet */
189 if (!global_trace
.buffer
)
190 return trace_clock_local();
192 ts
= ring_buffer_time_stamp(global_trace
.buffer
, cpu
);
193 ring_buffer_normalize_time_stamp(global_trace
.buffer
, cpu
, &ts
);
199 * The max_tr is used to snapshot the global_trace when a maximum
200 * latency is reached. Some tracers will use this to store a maximum
201 * trace while it continues examining live traces.
203 * The buffers for the max_tr are set up the same as the global_trace.
204 * When a snapshot is taken, the link list of the max_tr is swapped
205 * with the link list of the global_trace and the buffers are reset for
206 * the global_trace so the tracing can continue.
208 static struct trace_array max_tr
;
210 static DEFINE_PER_CPU(struct trace_array_cpu
, max_tr_data
);
212 /* tracer_enabled is used to toggle activation of a tracer */
213 static int tracer_enabled
= 1;
216 * tracing_is_enabled - return tracer_enabled status
218 * This function is used by other tracers to know the status
219 * of the tracer_enabled flag. Tracers may use this function
220 * to know if it should enable their features when starting
221 * up. See irqsoff tracer for an example (start_irqsoff_tracer).
223 int tracing_is_enabled(void)
225 return tracer_enabled
;
229 * trace_buf_size is the size in bytes that is allocated
230 * for a buffer. Note, the number of bytes is always rounded
233 * This number is purposely set to a low number of 16384.
234 * If the dump on oops happens, it will be much appreciated
235 * to not have to wait for all that output. Anyway this can be
236 * boot time and run time configurable.
238 #define TRACE_BUF_SIZE_DEFAULT 1441792UL /* 16384 * 88 (sizeof(entry)) */
240 static unsigned long trace_buf_size
= TRACE_BUF_SIZE_DEFAULT
;
242 /* trace_types holds a link list of available tracers. */
243 static struct tracer
*trace_types __read_mostly
;
245 /* current_trace points to the tracer that is currently active */
246 static struct tracer
*current_trace __read_mostly
;
249 * trace_types_lock is used to protect the trace_types list.
251 static DEFINE_MUTEX(trace_types_lock
);
254 * serialize the access of the ring buffer
256 * ring buffer serializes readers, but it is low level protection.
257 * The validity of the events (which returns by ring_buffer_peek() ..etc)
258 * are not protected by ring buffer.
260 * The content of events may become garbage if we allow other process consumes
261 * these events concurrently:
262 * A) the page of the consumed events may become a normal page
263 * (not reader page) in ring buffer, and this page will be rewrited
264 * by events producer.
265 * B) The page of the consumed events may become a page for splice_read,
266 * and this page will be returned to system.
268 * These primitives allow multi process access to different cpu ring buffer
271 * These primitives don't distinguish read-only and read-consume access.
272 * Multi read-only access are also serialized.
276 static DECLARE_RWSEM(all_cpu_access_lock
);
277 static DEFINE_PER_CPU(struct mutex
, cpu_access_lock
);
279 static inline void trace_access_lock(int cpu
)
281 if (cpu
== TRACE_PIPE_ALL_CPU
) {
282 /* gain it for accessing the whole ring buffer. */
283 down_write(&all_cpu_access_lock
);
285 /* gain it for accessing a cpu ring buffer. */
287 /* Firstly block other trace_access_lock(TRACE_PIPE_ALL_CPU). */
288 down_read(&all_cpu_access_lock
);
290 /* Secondly block other access to this @cpu ring buffer. */
291 mutex_lock(&per_cpu(cpu_access_lock
, cpu
));
295 static inline void trace_access_unlock(int cpu
)
297 if (cpu
== TRACE_PIPE_ALL_CPU
) {
298 up_write(&all_cpu_access_lock
);
300 mutex_unlock(&per_cpu(cpu_access_lock
, cpu
));
301 up_read(&all_cpu_access_lock
);
305 static inline void trace_access_lock_init(void)
309 for_each_possible_cpu(cpu
)
310 mutex_init(&per_cpu(cpu_access_lock
, cpu
));
315 static DEFINE_MUTEX(access_lock
);
317 static inline void trace_access_lock(int cpu
)
320 mutex_lock(&access_lock
);
323 static inline void trace_access_unlock(int cpu
)
326 mutex_unlock(&access_lock
);
329 static inline void trace_access_lock_init(void)
335 /* trace_wait is a waitqueue for tasks blocked on trace_poll */
336 static DECLARE_WAIT_QUEUE_HEAD(trace_wait
);
338 /* trace_flags holds trace_options default values */
339 unsigned long trace_flags
= TRACE_ITER_PRINT_PARENT
| TRACE_ITER_PRINTK
|
340 TRACE_ITER_ANNOTATE
| TRACE_ITER_CONTEXT_INFO
| TRACE_ITER_SLEEP_TIME
|
341 TRACE_ITER_GRAPH_TIME
| TRACE_ITER_RECORD_CMD
| TRACE_ITER_OVERWRITE
;
343 static int trace_stop_count
;
344 static DEFINE_SPINLOCK(tracing_start_lock
);
347 * trace_wake_up - wake up tasks waiting for trace input
349 * Simply wakes up any task that is blocked on the trace_wait
350 * queue. These is used with trace_poll for tasks polling the trace.
352 void trace_wake_up(void)
356 if (trace_flags
& TRACE_ITER_BLOCK
)
359 * The runqueue_is_locked() can fail, but this is the best we
363 if (!runqueue_is_locked(cpu
))
364 wake_up(&trace_wait
);
368 static int __init
set_buf_size(char *str
)
370 unsigned long buf_size
;
374 buf_size
= memparse(str
, &str
);
375 /* nr_entries can not be zero */
378 trace_buf_size
= buf_size
;
381 __setup("trace_buf_size=", set_buf_size
);
383 static int __init
set_tracing_thresh(char *str
)
385 unsigned long threshhold
;
390 ret
= strict_strtoul(str
, 0, &threshhold
);
393 tracing_thresh
= threshhold
* 1000;
396 __setup("tracing_thresh=", set_tracing_thresh
);
398 unsigned long nsecs_to_usecs(unsigned long nsecs
)
403 /* These must match the bit postions in trace_iterator_flags */
404 static const char *trace_options
[] = {
434 { trace_clock_local
, "local" },
435 { trace_clock_global
, "global" },
441 * trace_parser_get_init - gets the buffer for trace parser
443 int trace_parser_get_init(struct trace_parser
*parser
, int size
)
445 memset(parser
, 0, sizeof(*parser
));
447 parser
->buffer
= kmalloc(size
, GFP_KERNEL
);
456 * trace_parser_put - frees the buffer for trace parser
458 void trace_parser_put(struct trace_parser
*parser
)
460 kfree(parser
->buffer
);
464 * trace_get_user - reads the user input string separated by space
465 * (matched by isspace(ch))
467 * For each string found the 'struct trace_parser' is updated,
468 * and the function returns.
470 * Returns number of bytes read.
472 * See kernel/trace/trace.h for 'struct trace_parser' details.
474 int trace_get_user(struct trace_parser
*parser
, const char __user
*ubuf
,
475 size_t cnt
, loff_t
*ppos
)
482 trace_parser_clear(parser
);
484 ret
= get_user(ch
, ubuf
++);
492 * The parser is not finished with the last write,
493 * continue reading the user input without skipping spaces.
496 /* skip white space */
497 while (cnt
&& isspace(ch
)) {
498 ret
= get_user(ch
, ubuf
++);
505 /* only spaces were written */
515 /* read the non-space input */
516 while (cnt
&& !isspace(ch
)) {
517 if (parser
->idx
< parser
->size
- 1)
518 parser
->buffer
[parser
->idx
++] = ch
;
523 ret
= get_user(ch
, ubuf
++);
530 /* We either got finished input or we have to wait for another call. */
532 parser
->buffer
[parser
->idx
] = 0;
533 parser
->cont
= false;
536 parser
->buffer
[parser
->idx
++] = ch
;
546 ssize_t
trace_seq_to_user(struct trace_seq
*s
, char __user
*ubuf
, size_t cnt
)
554 if (s
->len
<= s
->readpos
)
557 len
= s
->len
- s
->readpos
;
560 ret
= copy_to_user(ubuf
, s
->buffer
+ s
->readpos
, cnt
);
570 static ssize_t
trace_seq_to_buffer(struct trace_seq
*s
, void *buf
, size_t cnt
)
575 if (s
->len
<= s
->readpos
)
578 len
= s
->len
- s
->readpos
;
581 ret
= memcpy(buf
, s
->buffer
+ s
->readpos
, cnt
);
590 * ftrace_max_lock is used to protect the swapping of buffers
591 * when taking a max snapshot. The buffers themselves are
592 * protected by per_cpu spinlocks. But the action of the swap
593 * needs its own lock.
595 * This is defined as a arch_spinlock_t in order to help
596 * with performance when lockdep debugging is enabled.
598 * It is also used in other places outside the update_max_tr
599 * so it needs to be defined outside of the
600 * CONFIG_TRACER_MAX_TRACE.
602 static arch_spinlock_t ftrace_max_lock
=
603 (arch_spinlock_t
)__ARCH_SPIN_LOCK_UNLOCKED
;
605 unsigned long __read_mostly tracing_thresh
;
607 #ifdef CONFIG_TRACER_MAX_TRACE
608 unsigned long __read_mostly tracing_max_latency
;
611 * Copy the new maximum trace into the separate maximum-trace
612 * structure. (this way the maximum trace is permanently saved,
613 * for later retrieval via /sys/kernel/debug/tracing/latency_trace)
616 __update_max_tr(struct trace_array
*tr
, struct task_struct
*tsk
, int cpu
)
618 struct trace_array_cpu
*data
= tr
->data
[cpu
];
619 struct trace_array_cpu
*max_data
;
622 max_tr
.time_start
= data
->preempt_timestamp
;
624 max_data
= max_tr
.data
[cpu
];
625 max_data
->saved_latency
= tracing_max_latency
;
626 max_data
->critical_start
= data
->critical_start
;
627 max_data
->critical_end
= data
->critical_end
;
629 memcpy(max_data
->comm
, tsk
->comm
, TASK_COMM_LEN
);
630 max_data
->pid
= tsk
->pid
;
631 max_data
->uid
= task_uid(tsk
);
632 max_data
->nice
= tsk
->static_prio
- 20 - MAX_RT_PRIO
;
633 max_data
->policy
= tsk
->policy
;
634 max_data
->rt_priority
= tsk
->rt_priority
;
636 /* record this tasks comm */
637 tracing_record_cmdline(tsk
);
641 * update_max_tr - snapshot all trace buffers from global_trace to max_tr
643 * @tsk: the task with the latency
644 * @cpu: The cpu that initiated the trace.
646 * Flip the buffers between the @tr and the max_tr and record information
647 * about which task was the cause of this latency.
650 update_max_tr(struct trace_array
*tr
, struct task_struct
*tsk
, int cpu
)
652 struct ring_buffer
*buf
= tr
->buffer
;
654 if (trace_stop_count
)
657 WARN_ON_ONCE(!irqs_disabled());
658 if (!current_trace
->use_max_tr
) {
662 arch_spin_lock(&ftrace_max_lock
);
664 tr
->buffer
= max_tr
.buffer
;
667 __update_max_tr(tr
, tsk
, cpu
);
668 arch_spin_unlock(&ftrace_max_lock
);
672 * update_max_tr_single - only copy one trace over, and reset the rest
674 * @tsk - task with the latency
675 * @cpu - the cpu of the buffer to copy.
677 * Flip the trace of a single CPU buffer between the @tr and the max_tr.
680 update_max_tr_single(struct trace_array
*tr
, struct task_struct
*tsk
, int cpu
)
684 if (trace_stop_count
)
687 WARN_ON_ONCE(!irqs_disabled());
688 if (!current_trace
->use_max_tr
) {
693 arch_spin_lock(&ftrace_max_lock
);
695 ftrace_disable_cpu();
697 ret
= ring_buffer_swap_cpu(max_tr
.buffer
, tr
->buffer
, cpu
);
701 * We failed to swap the buffer due to a commit taking
702 * place on this CPU. We fail to record, but we reset
703 * the max trace buffer (no one writes directly to it)
704 * and flag that it failed.
706 trace_array_printk(&max_tr
, _THIS_IP_
,
707 "Failed to swap buffers due to commit in progress\n");
712 WARN_ON_ONCE(ret
&& ret
!= -EAGAIN
&& ret
!= -EBUSY
);
714 __update_max_tr(tr
, tsk
, cpu
);
715 arch_spin_unlock(&ftrace_max_lock
);
717 #endif /* CONFIG_TRACER_MAX_TRACE */
720 * register_tracer - register a tracer with the ftrace system.
721 * @type - the plugin for the tracer
723 * Register a new plugin tracer.
725 int register_tracer(struct tracer
*type
)
726 __releases(kernel_lock
)
727 __acquires(kernel_lock
)
733 pr_info("Tracer must have a name\n");
737 if (strlen(type
->name
) >= MAX_TRACER_SIZE
) {
738 pr_info("Tracer has a name longer than %d\n", MAX_TRACER_SIZE
);
742 mutex_lock(&trace_types_lock
);
744 tracing_selftest_running
= true;
746 for (t
= trace_types
; t
; t
= t
->next
) {
747 if (strcmp(type
->name
, t
->name
) == 0) {
749 pr_info("Tracer %s already registered\n",
757 type
->set_flag
= &dummy_set_flag
;
759 type
->flags
= &dummy_tracer_flags
;
761 if (!type
->flags
->opts
)
762 type
->flags
->opts
= dummy_tracer_opt
;
763 if (!type
->wait_pipe
)
764 type
->wait_pipe
= default_wait_pipe
;
767 #ifdef CONFIG_FTRACE_STARTUP_TEST
768 if (type
->selftest
&& !tracing_selftest_disabled
) {
769 struct tracer
*saved_tracer
= current_trace
;
770 struct trace_array
*tr
= &global_trace
;
773 * Run a selftest on this tracer.
774 * Here we reset the trace buffer, and set the current
775 * tracer to be this tracer. The tracer can then run some
776 * internal tracing to verify that everything is in order.
777 * If we fail, we do not register this tracer.
779 tracing_reset_online_cpus(tr
);
781 current_trace
= type
;
783 /* If we expanded the buffers, make sure the max is expanded too */
784 if (ring_buffer_expanded
&& type
->use_max_tr
)
785 ring_buffer_resize(max_tr
.buffer
, trace_buf_size
);
787 /* the test is responsible for initializing and enabling */
788 pr_info("Testing tracer %s: ", type
->name
);
789 ret
= type
->selftest(type
, tr
);
790 /* the test is responsible for resetting too */
791 current_trace
= saved_tracer
;
793 printk(KERN_CONT
"FAILED!\n");
796 /* Only reset on passing, to avoid touching corrupted buffers */
797 tracing_reset_online_cpus(tr
);
799 /* Shrink the max buffer again */
800 if (ring_buffer_expanded
&& type
->use_max_tr
)
801 ring_buffer_resize(max_tr
.buffer
, 1);
803 printk(KERN_CONT
"PASSED\n");
807 type
->next
= trace_types
;
811 tracing_selftest_running
= false;
812 mutex_unlock(&trace_types_lock
);
814 if (ret
|| !default_bootup_tracer
)
817 if (strncmp(default_bootup_tracer
, type
->name
, MAX_TRACER_SIZE
))
820 printk(KERN_INFO
"Starting tracer '%s'\n", type
->name
);
821 /* Do we want this tracer to start on bootup? */
822 tracing_set_tracer(type
->name
);
823 default_bootup_tracer
= NULL
;
824 /* disable other selftests, since this will break it. */
825 tracing_selftest_disabled
= 1;
826 #ifdef CONFIG_FTRACE_STARTUP_TEST
827 printk(KERN_INFO
"Disabling FTRACE selftests due to running tracer '%s'\n",
835 void unregister_tracer(struct tracer
*type
)
839 mutex_lock(&trace_types_lock
);
840 for (t
= &trace_types
; *t
; t
= &(*t
)->next
) {
844 pr_info("Tracer %s not registered\n", type
->name
);
850 if (type
== current_trace
&& tracer_enabled
) {
853 if (current_trace
->stop
)
854 current_trace
->stop(&global_trace
);
855 current_trace
= &nop_trace
;
858 mutex_unlock(&trace_types_lock
);
861 static void __tracing_reset(struct ring_buffer
*buffer
, int cpu
)
863 ftrace_disable_cpu();
864 ring_buffer_reset_cpu(buffer
, cpu
);
868 void tracing_reset(struct trace_array
*tr
, int cpu
)
870 struct ring_buffer
*buffer
= tr
->buffer
;
872 ring_buffer_record_disable(buffer
);
874 /* Make sure all commits have finished */
876 __tracing_reset(buffer
, cpu
);
878 ring_buffer_record_enable(buffer
);
881 void tracing_reset_online_cpus(struct trace_array
*tr
)
883 struct ring_buffer
*buffer
= tr
->buffer
;
886 ring_buffer_record_disable(buffer
);
888 /* Make sure all commits have finished */
891 tr
->time_start
= ftrace_now(tr
->cpu
);
893 for_each_online_cpu(cpu
)
894 __tracing_reset(buffer
, cpu
);
896 ring_buffer_record_enable(buffer
);
899 void tracing_reset_current(int cpu
)
901 tracing_reset(&global_trace
, cpu
);
904 void tracing_reset_current_online_cpus(void)
906 tracing_reset_online_cpus(&global_trace
);
909 #define SAVED_CMDLINES 128
910 #define NO_CMDLINE_MAP UINT_MAX
911 static unsigned map_pid_to_cmdline
[PID_MAX_DEFAULT
+1];
912 static unsigned map_cmdline_to_pid
[SAVED_CMDLINES
];
913 static char saved_cmdlines
[SAVED_CMDLINES
][TASK_COMM_LEN
];
914 static int cmdline_idx
;
915 static arch_spinlock_t trace_cmdline_lock
= __ARCH_SPIN_LOCK_UNLOCKED
;
917 /* temporary disable recording */
918 static atomic_t trace_record_cmdline_disabled __read_mostly
;
920 static void trace_init_cmdlines(void)
922 memset(&map_pid_to_cmdline
, NO_CMDLINE_MAP
, sizeof(map_pid_to_cmdline
));
923 memset(&map_cmdline_to_pid
, NO_CMDLINE_MAP
, sizeof(map_cmdline_to_pid
));
927 int is_tracing_stopped(void)
929 return trace_stop_count
;
933 * ftrace_off_permanent - disable all ftrace code permanently
935 * This should only be called when a serious anomally has
936 * been detected. This will turn off the function tracing,
937 * ring buffers, and other tracing utilites. It takes no
938 * locks and can be called from any context.
940 void ftrace_off_permanent(void)
942 tracing_disabled
= 1;
944 tracing_off_permanent();
948 * tracing_start - quick start of the tracer
950 * If tracing is enabled but was stopped by tracing_stop,
951 * this will start the tracer back up.
953 void tracing_start(void)
955 struct ring_buffer
*buffer
;
958 if (tracing_disabled
)
961 spin_lock_irqsave(&tracing_start_lock
, flags
);
962 if (--trace_stop_count
) {
963 if (trace_stop_count
< 0) {
964 /* Someone screwed up their debugging */
966 trace_stop_count
= 0;
971 /* Prevent the buffers from switching */
972 arch_spin_lock(&ftrace_max_lock
);
974 buffer
= global_trace
.buffer
;
976 ring_buffer_record_enable(buffer
);
978 buffer
= max_tr
.buffer
;
980 ring_buffer_record_enable(buffer
);
982 arch_spin_unlock(&ftrace_max_lock
);
986 spin_unlock_irqrestore(&tracing_start_lock
, flags
);
990 * tracing_stop - quick stop of the tracer
992 * Light weight way to stop tracing. Use in conjunction with
995 void tracing_stop(void)
997 struct ring_buffer
*buffer
;
1001 spin_lock_irqsave(&tracing_start_lock
, flags
);
1002 if (trace_stop_count
++)
1005 /* Prevent the buffers from switching */
1006 arch_spin_lock(&ftrace_max_lock
);
1008 buffer
= global_trace
.buffer
;
1010 ring_buffer_record_disable(buffer
);
1012 buffer
= max_tr
.buffer
;
1014 ring_buffer_record_disable(buffer
);
1016 arch_spin_unlock(&ftrace_max_lock
);
1019 spin_unlock_irqrestore(&tracing_start_lock
, flags
);
1022 void trace_stop_cmdline_recording(void);
1024 static void trace_save_cmdline(struct task_struct
*tsk
)
1028 if (!tsk
->pid
|| unlikely(tsk
->pid
> PID_MAX_DEFAULT
))
1032 * It's not the end of the world if we don't get
1033 * the lock, but we also don't want to spin
1034 * nor do we want to disable interrupts,
1035 * so if we miss here, then better luck next time.
1037 if (!arch_spin_trylock(&trace_cmdline_lock
))
1040 idx
= map_pid_to_cmdline
[tsk
->pid
];
1041 if (idx
== NO_CMDLINE_MAP
) {
1042 idx
= (cmdline_idx
+ 1) % SAVED_CMDLINES
;
1045 * Check whether the cmdline buffer at idx has a pid
1046 * mapped. We are going to overwrite that entry so we
1047 * need to clear the map_pid_to_cmdline. Otherwise we
1048 * would read the new comm for the old pid.
1050 pid
= map_cmdline_to_pid
[idx
];
1051 if (pid
!= NO_CMDLINE_MAP
)
1052 map_pid_to_cmdline
[pid
] = NO_CMDLINE_MAP
;
1054 map_cmdline_to_pid
[idx
] = tsk
->pid
;
1055 map_pid_to_cmdline
[tsk
->pid
] = idx
;
1060 memcpy(&saved_cmdlines
[idx
], tsk
->comm
, TASK_COMM_LEN
);
1062 arch_spin_unlock(&trace_cmdline_lock
);
1065 void trace_find_cmdline(int pid
, char comm
[])
1070 strcpy(comm
, "<idle>");
1074 if (WARN_ON_ONCE(pid
< 0)) {
1075 strcpy(comm
, "<XXX>");
1079 if (pid
> PID_MAX_DEFAULT
) {
1080 strcpy(comm
, "<...>");
1085 arch_spin_lock(&trace_cmdline_lock
);
1086 map
= map_pid_to_cmdline
[pid
];
1087 if (map
!= NO_CMDLINE_MAP
)
1088 strcpy(comm
, saved_cmdlines
[map
]);
1090 strcpy(comm
, "<...>");
1092 arch_spin_unlock(&trace_cmdline_lock
);
1096 void tracing_record_cmdline(struct task_struct
*tsk
)
1098 if (atomic_read(&trace_record_cmdline_disabled
) || !tracer_enabled
||
1102 trace_save_cmdline(tsk
);
1106 tracing_generic_entry_update(struct trace_entry
*entry
, unsigned long flags
,
1109 struct task_struct
*tsk
= current
;
1111 entry
->preempt_count
= pc
& 0xff;
1112 entry
->pid
= (tsk
) ? tsk
->pid
: 0;
1114 #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
1115 (irqs_disabled_flags(flags
) ? TRACE_FLAG_IRQS_OFF
: 0) |
1117 TRACE_FLAG_IRQS_NOSUPPORT
|
1119 ((pc
& HARDIRQ_MASK
) ? TRACE_FLAG_HARDIRQ
: 0) |
1120 ((pc
& SOFTIRQ_MASK
) ? TRACE_FLAG_SOFTIRQ
: 0) |
1121 (need_resched() ? TRACE_FLAG_NEED_RESCHED
: 0);
1123 EXPORT_SYMBOL_GPL(tracing_generic_entry_update
);
1125 struct ring_buffer_event
*
1126 trace_buffer_lock_reserve(struct ring_buffer
*buffer
,
1129 unsigned long flags
, int pc
)
1131 struct ring_buffer_event
*event
;
1133 event
= ring_buffer_lock_reserve(buffer
, len
);
1134 if (event
!= NULL
) {
1135 struct trace_entry
*ent
= ring_buffer_event_data(event
);
1137 tracing_generic_entry_update(ent
, flags
, pc
);
1145 __trace_buffer_unlock_commit(struct ring_buffer
*buffer
,
1146 struct ring_buffer_event
*event
,
1147 unsigned long flags
, int pc
,
1150 ring_buffer_unlock_commit(buffer
, event
);
1152 ftrace_trace_stack(buffer
, flags
, 6, pc
);
1153 ftrace_trace_userstack(buffer
, flags
, pc
);
1159 void trace_buffer_unlock_commit(struct ring_buffer
*buffer
,
1160 struct ring_buffer_event
*event
,
1161 unsigned long flags
, int pc
)
1163 __trace_buffer_unlock_commit(buffer
, event
, flags
, pc
, 1);
1166 struct ring_buffer_event
*
1167 trace_current_buffer_lock_reserve(struct ring_buffer
**current_rb
,
1168 int type
, unsigned long len
,
1169 unsigned long flags
, int pc
)
1171 *current_rb
= global_trace
.buffer
;
1172 return trace_buffer_lock_reserve(*current_rb
,
1173 type
, len
, flags
, pc
);
1175 EXPORT_SYMBOL_GPL(trace_current_buffer_lock_reserve
);
1177 void trace_current_buffer_unlock_commit(struct ring_buffer
*buffer
,
1178 struct ring_buffer_event
*event
,
1179 unsigned long flags
, int pc
)
1181 __trace_buffer_unlock_commit(buffer
, event
, flags
, pc
, 1);
1183 EXPORT_SYMBOL_GPL(trace_current_buffer_unlock_commit
);
1185 void trace_nowake_buffer_unlock_commit(struct ring_buffer
*buffer
,
1186 struct ring_buffer_event
*event
,
1187 unsigned long flags
, int pc
)
1189 __trace_buffer_unlock_commit(buffer
, event
, flags
, pc
, 0);
1191 EXPORT_SYMBOL_GPL(trace_nowake_buffer_unlock_commit
);
1193 void trace_current_buffer_discard_commit(struct ring_buffer
*buffer
,
1194 struct ring_buffer_event
*event
)
1196 ring_buffer_discard_commit(buffer
, event
);
1198 EXPORT_SYMBOL_GPL(trace_current_buffer_discard_commit
);
1201 trace_function(struct trace_array
*tr
,
1202 unsigned long ip
, unsigned long parent_ip
, unsigned long flags
,
1205 struct ftrace_event_call
*call
= &event_function
;
1206 struct ring_buffer
*buffer
= tr
->buffer
;
1207 struct ring_buffer_event
*event
;
1208 struct ftrace_entry
*entry
;
1210 /* If we are reading the ring buffer, don't trace */
1211 if (unlikely(__this_cpu_read(ftrace_cpu_disabled
)))
1214 event
= trace_buffer_lock_reserve(buffer
, TRACE_FN
, sizeof(*entry
),
1218 entry
= ring_buffer_event_data(event
);
1220 entry
->parent_ip
= parent_ip
;
1222 if (!filter_check_discard(call
, entry
, buffer
, event
))
1223 ring_buffer_unlock_commit(buffer
, event
);
1227 ftrace(struct trace_array
*tr
, struct trace_array_cpu
*data
,
1228 unsigned long ip
, unsigned long parent_ip
, unsigned long flags
,
1231 if (likely(!atomic_read(&data
->disabled
)))
1232 trace_function(tr
, ip
, parent_ip
, flags
, pc
);
1235 #ifdef CONFIG_STACKTRACE
1236 static void __ftrace_trace_stack(struct ring_buffer
*buffer
,
1237 unsigned long flags
,
1240 struct ftrace_event_call
*call
= &event_kernel_stack
;
1241 struct ring_buffer_event
*event
;
1242 struct stack_entry
*entry
;
1243 struct stack_trace trace
;
1245 event
= trace_buffer_lock_reserve(buffer
, TRACE_STACK
,
1246 sizeof(*entry
), flags
, pc
);
1249 entry
= ring_buffer_event_data(event
);
1250 memset(&entry
->caller
, 0, sizeof(entry
->caller
));
1252 trace
.nr_entries
= 0;
1253 trace
.max_entries
= FTRACE_STACK_ENTRIES
;
1255 trace
.entries
= entry
->caller
;
1257 save_stack_trace(&trace
);
1258 if (!filter_check_discard(call
, entry
, buffer
, event
))
1259 ring_buffer_unlock_commit(buffer
, event
);
1262 void ftrace_trace_stack(struct ring_buffer
*buffer
, unsigned long flags
,
1265 if (!(trace_flags
& TRACE_ITER_STACKTRACE
))
1268 __ftrace_trace_stack(buffer
, flags
, skip
, pc
);
1271 void __trace_stack(struct trace_array
*tr
, unsigned long flags
, int skip
,
1274 __ftrace_trace_stack(tr
->buffer
, flags
, skip
, pc
);
1278 * trace_dump_stack - record a stack back trace in the trace buffer
1280 void trace_dump_stack(void)
1282 unsigned long flags
;
1284 if (tracing_disabled
|| tracing_selftest_running
)
1287 local_save_flags(flags
);
1289 /* skipping 3 traces, seems to get us at the caller of this function */
1290 __ftrace_trace_stack(global_trace
.buffer
, flags
, 3, preempt_count());
1293 static DEFINE_PER_CPU(int, user_stack_count
);
1296 ftrace_trace_userstack(struct ring_buffer
*buffer
, unsigned long flags
, int pc
)
1298 struct ftrace_event_call
*call
= &event_user_stack
;
1299 struct ring_buffer_event
*event
;
1300 struct userstack_entry
*entry
;
1301 struct stack_trace trace
;
1303 if (!(trace_flags
& TRACE_ITER_USERSTACKTRACE
))
1307 * NMIs can not handle page faults, even with fix ups.
1308 * The save user stack can (and often does) fault.
1310 if (unlikely(in_nmi()))
1314 * prevent recursion, since the user stack tracing may
1315 * trigger other kernel events.
1318 if (__this_cpu_read(user_stack_count
))
1321 __this_cpu_inc(user_stack_count
);
1323 event
= trace_buffer_lock_reserve(buffer
, TRACE_USER_STACK
,
1324 sizeof(*entry
), flags
, pc
);
1326 goto out_drop_count
;
1327 entry
= ring_buffer_event_data(event
);
1329 entry
->tgid
= current
->tgid
;
1330 memset(&entry
->caller
, 0, sizeof(entry
->caller
));
1332 trace
.nr_entries
= 0;
1333 trace
.max_entries
= FTRACE_STACK_ENTRIES
;
1335 trace
.entries
= entry
->caller
;
1337 save_stack_trace_user(&trace
);
1338 if (!filter_check_discard(call
, entry
, buffer
, event
))
1339 ring_buffer_unlock_commit(buffer
, event
);
1342 __this_cpu_dec(user_stack_count
);
1348 static void __trace_userstack(struct trace_array
*tr
, unsigned long flags
)
1350 ftrace_trace_userstack(tr
, flags
, preempt_count());
1354 #endif /* CONFIG_STACKTRACE */
1357 * trace_vbprintk - write binary msg to tracing buffer
1360 int trace_vbprintk(unsigned long ip
, const char *fmt
, va_list args
)
1362 static arch_spinlock_t trace_buf_lock
=
1363 (arch_spinlock_t
)__ARCH_SPIN_LOCK_UNLOCKED
;
1364 static u32 trace_buf
[TRACE_BUF_SIZE
];
1366 struct ftrace_event_call
*call
= &event_bprint
;
1367 struct ring_buffer_event
*event
;
1368 struct ring_buffer
*buffer
;
1369 struct trace_array
*tr
= &global_trace
;
1370 struct trace_array_cpu
*data
;
1371 struct bprint_entry
*entry
;
1372 unsigned long flags
;
1374 int cpu
, len
= 0, size
, pc
;
1376 if (unlikely(tracing_selftest_running
|| tracing_disabled
))
1379 /* Don't pollute graph traces with trace_vprintk internals */
1380 pause_graph_tracing();
1382 pc
= preempt_count();
1383 preempt_disable_notrace();
1384 cpu
= raw_smp_processor_id();
1385 data
= tr
->data
[cpu
];
1387 disable
= atomic_inc_return(&data
->disabled
);
1388 if (unlikely(disable
!= 1))
1391 /* Lockdep uses trace_printk for lock tracing */
1392 local_irq_save(flags
);
1393 arch_spin_lock(&trace_buf_lock
);
1394 len
= vbin_printf(trace_buf
, TRACE_BUF_SIZE
, fmt
, args
);
1396 if (len
> TRACE_BUF_SIZE
|| len
< 0)
1399 size
= sizeof(*entry
) + sizeof(u32
) * len
;
1400 buffer
= tr
->buffer
;
1401 event
= trace_buffer_lock_reserve(buffer
, TRACE_BPRINT
, size
,
1405 entry
= ring_buffer_event_data(event
);
1409 memcpy(entry
->buf
, trace_buf
, sizeof(u32
) * len
);
1410 if (!filter_check_discard(call
, entry
, buffer
, event
)) {
1411 ring_buffer_unlock_commit(buffer
, event
);
1412 ftrace_trace_stack(buffer
, flags
, 6, pc
);
1416 arch_spin_unlock(&trace_buf_lock
);
1417 local_irq_restore(flags
);
1420 atomic_dec_return(&data
->disabled
);
1421 preempt_enable_notrace();
1422 unpause_graph_tracing();
1426 EXPORT_SYMBOL_GPL(trace_vbprintk
);
1428 int trace_array_printk(struct trace_array
*tr
,
1429 unsigned long ip
, const char *fmt
, ...)
1434 if (!(trace_flags
& TRACE_ITER_PRINTK
))
1438 ret
= trace_array_vprintk(tr
, ip
, fmt
, ap
);
1443 int trace_array_vprintk(struct trace_array
*tr
,
1444 unsigned long ip
, const char *fmt
, va_list args
)
1446 static arch_spinlock_t trace_buf_lock
= __ARCH_SPIN_LOCK_UNLOCKED
;
1447 static char trace_buf
[TRACE_BUF_SIZE
];
1449 struct ftrace_event_call
*call
= &event_print
;
1450 struct ring_buffer_event
*event
;
1451 struct ring_buffer
*buffer
;
1452 struct trace_array_cpu
*data
;
1453 int cpu
, len
= 0, size
, pc
;
1454 struct print_entry
*entry
;
1455 unsigned long irq_flags
;
1458 if (tracing_disabled
|| tracing_selftest_running
)
1461 pc
= preempt_count();
1462 preempt_disable_notrace();
1463 cpu
= raw_smp_processor_id();
1464 data
= tr
->data
[cpu
];
1466 disable
= atomic_inc_return(&data
->disabled
);
1467 if (unlikely(disable
!= 1))
1470 pause_graph_tracing();
1471 raw_local_irq_save(irq_flags
);
1472 arch_spin_lock(&trace_buf_lock
);
1473 len
= vsnprintf(trace_buf
, TRACE_BUF_SIZE
, fmt
, args
);
1475 size
= sizeof(*entry
) + len
+ 1;
1476 buffer
= tr
->buffer
;
1477 event
= trace_buffer_lock_reserve(buffer
, TRACE_PRINT
, size
,
1481 entry
= ring_buffer_event_data(event
);
1484 memcpy(&entry
->buf
, trace_buf
, len
);
1485 entry
->buf
[len
] = '\0';
1486 if (!filter_check_discard(call
, entry
, buffer
, event
)) {
1487 ring_buffer_unlock_commit(buffer
, event
);
1488 ftrace_trace_stack(buffer
, irq_flags
, 6, pc
);
1492 arch_spin_unlock(&trace_buf_lock
);
1493 raw_local_irq_restore(irq_flags
);
1494 unpause_graph_tracing();
1496 atomic_dec_return(&data
->disabled
);
1497 preempt_enable_notrace();
1502 int trace_vprintk(unsigned long ip
, const char *fmt
, va_list args
)
1504 return trace_array_vprintk(&global_trace
, ip
, fmt
, args
);
1506 EXPORT_SYMBOL_GPL(trace_vprintk
);
1508 static void trace_iterator_increment(struct trace_iterator
*iter
)
1510 /* Don't allow ftrace to trace into the ring buffers */
1511 ftrace_disable_cpu();
1514 if (iter
->buffer_iter
[iter
->cpu
])
1515 ring_buffer_read(iter
->buffer_iter
[iter
->cpu
], NULL
);
1517 ftrace_enable_cpu();
1520 static struct trace_entry
*
1521 peek_next_entry(struct trace_iterator
*iter
, int cpu
, u64
*ts
,
1522 unsigned long *lost_events
)
1524 struct ring_buffer_event
*event
;
1525 struct ring_buffer_iter
*buf_iter
= iter
->buffer_iter
[cpu
];
1527 /* Don't allow ftrace to trace into the ring buffers */
1528 ftrace_disable_cpu();
1531 event
= ring_buffer_iter_peek(buf_iter
, ts
);
1533 event
= ring_buffer_peek(iter
->tr
->buffer
, cpu
, ts
,
1536 ftrace_enable_cpu();
1538 return event
? ring_buffer_event_data(event
) : NULL
;
1541 static struct trace_entry
*
1542 __find_next_entry(struct trace_iterator
*iter
, int *ent_cpu
,
1543 unsigned long *missing_events
, u64
*ent_ts
)
1545 struct ring_buffer
*buffer
= iter
->tr
->buffer
;
1546 struct trace_entry
*ent
, *next
= NULL
;
1547 unsigned long lost_events
= 0, next_lost
= 0;
1548 int cpu_file
= iter
->cpu_file
;
1549 u64 next_ts
= 0, ts
;
1554 * If we are in a per_cpu trace file, don't bother by iterating over
1555 * all cpu and peek directly.
1557 if (cpu_file
> TRACE_PIPE_ALL_CPU
) {
1558 if (ring_buffer_empty_cpu(buffer
, cpu_file
))
1560 ent
= peek_next_entry(iter
, cpu_file
, ent_ts
, missing_events
);
1562 *ent_cpu
= cpu_file
;
1567 for_each_tracing_cpu(cpu
) {
1569 if (ring_buffer_empty_cpu(buffer
, cpu
))
1572 ent
= peek_next_entry(iter
, cpu
, &ts
, &lost_events
);
1575 * Pick the entry with the smallest timestamp:
1577 if (ent
&& (!next
|| ts
< next_ts
)) {
1581 next_lost
= lost_events
;
1586 *ent_cpu
= next_cpu
;
1592 *missing_events
= next_lost
;
1597 /* Find the next real entry, without updating the iterator itself */
1598 struct trace_entry
*trace_find_next_entry(struct trace_iterator
*iter
,
1599 int *ent_cpu
, u64
*ent_ts
)
1601 return __find_next_entry(iter
, ent_cpu
, NULL
, ent_ts
);
1604 /* Find the next real entry, and increment the iterator to the next entry */
1605 void *trace_find_next_entry_inc(struct trace_iterator
*iter
)
1607 iter
->ent
= __find_next_entry(iter
, &iter
->cpu
,
1608 &iter
->lost_events
, &iter
->ts
);
1611 trace_iterator_increment(iter
);
1613 return iter
->ent
? iter
: NULL
;
1616 static void trace_consume(struct trace_iterator
*iter
)
1618 /* Don't allow ftrace to trace into the ring buffers */
1619 ftrace_disable_cpu();
1620 ring_buffer_consume(iter
->tr
->buffer
, iter
->cpu
, &iter
->ts
,
1621 &iter
->lost_events
);
1622 ftrace_enable_cpu();
1625 static void *s_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
1627 struct trace_iterator
*iter
= m
->private;
1631 WARN_ON_ONCE(iter
->leftover
);
1635 /* can't go backwards */
1640 ent
= trace_find_next_entry_inc(iter
);
1644 while (ent
&& iter
->idx
< i
)
1645 ent
= trace_find_next_entry_inc(iter
);
1652 void tracing_iter_reset(struct trace_iterator
*iter
, int cpu
)
1654 struct trace_array
*tr
= iter
->tr
;
1655 struct ring_buffer_event
*event
;
1656 struct ring_buffer_iter
*buf_iter
;
1657 unsigned long entries
= 0;
1660 tr
->data
[cpu
]->skipped_entries
= 0;
1662 if (!iter
->buffer_iter
[cpu
])
1665 buf_iter
= iter
->buffer_iter
[cpu
];
1666 ring_buffer_iter_reset(buf_iter
);
1669 * We could have the case with the max latency tracers
1670 * that a reset never took place on a cpu. This is evident
1671 * by the timestamp being before the start of the buffer.
1673 while ((event
= ring_buffer_iter_peek(buf_iter
, &ts
))) {
1674 if (ts
>= iter
->tr
->time_start
)
1677 ring_buffer_read(buf_iter
, NULL
);
1680 tr
->data
[cpu
]->skipped_entries
= entries
;
1684 * The current tracer is copied to avoid a global locking
1687 static void *s_start(struct seq_file
*m
, loff_t
*pos
)
1689 struct trace_iterator
*iter
= m
->private;
1690 static struct tracer
*old_tracer
;
1691 int cpu_file
= iter
->cpu_file
;
1696 /* copy the tracer to avoid using a global lock all around */
1697 mutex_lock(&trace_types_lock
);
1698 if (unlikely(old_tracer
!= current_trace
&& current_trace
)) {
1699 old_tracer
= current_trace
;
1700 *iter
->trace
= *current_trace
;
1702 mutex_unlock(&trace_types_lock
);
1704 atomic_inc(&trace_record_cmdline_disabled
);
1706 if (*pos
!= iter
->pos
) {
1711 ftrace_disable_cpu();
1713 if (cpu_file
== TRACE_PIPE_ALL_CPU
) {
1714 for_each_tracing_cpu(cpu
)
1715 tracing_iter_reset(iter
, cpu
);
1717 tracing_iter_reset(iter
, cpu_file
);
1719 ftrace_enable_cpu();
1722 for (p
= iter
; p
&& l
< *pos
; p
= s_next(m
, p
, &l
))
1727 * If we overflowed the seq_file before, then we want
1728 * to just reuse the trace_seq buffer again.
1734 p
= s_next(m
, p
, &l
);
1738 trace_event_read_lock();
1739 trace_access_lock(cpu_file
);
1743 static void s_stop(struct seq_file
*m
, void *p
)
1745 struct trace_iterator
*iter
= m
->private;
1747 atomic_dec(&trace_record_cmdline_disabled
);
1748 trace_access_unlock(iter
->cpu_file
);
1749 trace_event_read_unlock();
1752 static void print_lat_help_header(struct seq_file
*m
)
1754 seq_puts(m
, "# _------=> CPU# \n");
1755 seq_puts(m
, "# / _-----=> irqs-off \n");
1756 seq_puts(m
, "# | / _----=> need-resched \n");
1757 seq_puts(m
, "# || / _---=> hardirq/softirq \n");
1758 seq_puts(m
, "# ||| / _--=> preempt-depth \n");
1759 seq_puts(m
, "# |||| / delay \n");
1760 seq_puts(m
, "# cmd pid ||||| time | caller \n");
1761 seq_puts(m
, "# \\ / ||||| \\ | / \n");
1764 static void print_func_help_header(struct seq_file
*m
)
1766 seq_puts(m
, "# TASK-PID CPU# TIMESTAMP FUNCTION\n");
1767 seq_puts(m
, "# | | | | |\n");
1772 print_trace_header(struct seq_file
*m
, struct trace_iterator
*iter
)
1774 unsigned long sym_flags
= (trace_flags
& TRACE_ITER_SYM_MASK
);
1775 struct trace_array
*tr
= iter
->tr
;
1776 struct trace_array_cpu
*data
= tr
->data
[tr
->cpu
];
1777 struct tracer
*type
= current_trace
;
1778 unsigned long entries
= 0;
1779 unsigned long total
= 0;
1780 unsigned long count
;
1781 const char *name
= "preemption";
1788 for_each_tracing_cpu(cpu
) {
1789 count
= ring_buffer_entries_cpu(tr
->buffer
, cpu
);
1791 * If this buffer has skipped entries, then we hold all
1792 * entries for the trace and we need to ignore the
1793 * ones before the time stamp.
1795 if (tr
->data
[cpu
]->skipped_entries
) {
1796 count
-= tr
->data
[cpu
]->skipped_entries
;
1797 /* total is the same as the entries */
1801 ring_buffer_overrun_cpu(tr
->buffer
, cpu
);
1805 seq_printf(m
, "# %s latency trace v1.1.5 on %s\n",
1807 seq_puts(m
, "# -----------------------------------"
1808 "---------------------------------\n");
1809 seq_printf(m
, "# latency: %lu us, #%lu/%lu, CPU#%d |"
1810 " (M:%s VP:%d, KP:%d, SP:%d HP:%d",
1811 nsecs_to_usecs(data
->saved_latency
),
1815 #if defined(CONFIG_PREEMPT_NONE)
1817 #elif defined(CONFIG_PREEMPT_VOLUNTARY)
1819 #elif defined(CONFIG_PREEMPT)
1824 /* These are reserved for later use */
1827 seq_printf(m
, " #P:%d)\n", num_online_cpus());
1831 seq_puts(m
, "# -----------------\n");
1832 seq_printf(m
, "# | task: %.16s-%d "
1833 "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n",
1834 data
->comm
, data
->pid
, data
->uid
, data
->nice
,
1835 data
->policy
, data
->rt_priority
);
1836 seq_puts(m
, "# -----------------\n");
1838 if (data
->critical_start
) {
1839 seq_puts(m
, "# => started at: ");
1840 seq_print_ip_sym(&iter
->seq
, data
->critical_start
, sym_flags
);
1841 trace_print_seq(m
, &iter
->seq
);
1842 seq_puts(m
, "\n# => ended at: ");
1843 seq_print_ip_sym(&iter
->seq
, data
->critical_end
, sym_flags
);
1844 trace_print_seq(m
, &iter
->seq
);
1845 seq_puts(m
, "\n#\n");
1851 static void test_cpu_buff_start(struct trace_iterator
*iter
)
1853 struct trace_seq
*s
= &iter
->seq
;
1855 if (!(trace_flags
& TRACE_ITER_ANNOTATE
))
1858 if (!(iter
->iter_flags
& TRACE_FILE_ANNOTATE
))
1861 if (cpumask_test_cpu(iter
->cpu
, iter
->started
))
1864 if (iter
->tr
->data
[iter
->cpu
]->skipped_entries
)
1867 cpumask_set_cpu(iter
->cpu
, iter
->started
);
1869 /* Don't print started cpu buffer for the first entry of the trace */
1871 trace_seq_printf(s
, "##### CPU %u buffer started ####\n",
1875 static enum print_line_t
print_trace_fmt(struct trace_iterator
*iter
)
1877 struct trace_seq
*s
= &iter
->seq
;
1878 unsigned long sym_flags
= (trace_flags
& TRACE_ITER_SYM_MASK
);
1879 struct trace_entry
*entry
;
1880 struct trace_event
*event
;
1884 test_cpu_buff_start(iter
);
1886 event
= ftrace_find_event(entry
->type
);
1888 if (trace_flags
& TRACE_ITER_CONTEXT_INFO
) {
1889 if (iter
->iter_flags
& TRACE_FILE_LAT_FMT
) {
1890 if (!trace_print_lat_context(iter
))
1893 if (!trace_print_context(iter
))
1899 return event
->funcs
->trace(iter
, sym_flags
, event
);
1901 if (!trace_seq_printf(s
, "Unknown type %d\n", entry
->type
))
1904 return TRACE_TYPE_HANDLED
;
1906 return TRACE_TYPE_PARTIAL_LINE
;
1909 static enum print_line_t
print_raw_fmt(struct trace_iterator
*iter
)
1911 struct trace_seq
*s
= &iter
->seq
;
1912 struct trace_entry
*entry
;
1913 struct trace_event
*event
;
1917 if (trace_flags
& TRACE_ITER_CONTEXT_INFO
) {
1918 if (!trace_seq_printf(s
, "%d %d %llu ",
1919 entry
->pid
, iter
->cpu
, iter
->ts
))
1923 event
= ftrace_find_event(entry
->type
);
1925 return event
->funcs
->raw(iter
, 0, event
);
1927 if (!trace_seq_printf(s
, "%d ?\n", entry
->type
))
1930 return TRACE_TYPE_HANDLED
;
1932 return TRACE_TYPE_PARTIAL_LINE
;
1935 static enum print_line_t
print_hex_fmt(struct trace_iterator
*iter
)
1937 struct trace_seq
*s
= &iter
->seq
;
1938 unsigned char newline
= '\n';
1939 struct trace_entry
*entry
;
1940 struct trace_event
*event
;
1944 if (trace_flags
& TRACE_ITER_CONTEXT_INFO
) {
1945 SEQ_PUT_HEX_FIELD_RET(s
, entry
->pid
);
1946 SEQ_PUT_HEX_FIELD_RET(s
, iter
->cpu
);
1947 SEQ_PUT_HEX_FIELD_RET(s
, iter
->ts
);
1950 event
= ftrace_find_event(entry
->type
);
1952 enum print_line_t ret
= event
->funcs
->hex(iter
, 0, event
);
1953 if (ret
!= TRACE_TYPE_HANDLED
)
1957 SEQ_PUT_FIELD_RET(s
, newline
);
1959 return TRACE_TYPE_HANDLED
;
1962 static enum print_line_t
print_bin_fmt(struct trace_iterator
*iter
)
1964 struct trace_seq
*s
= &iter
->seq
;
1965 struct trace_entry
*entry
;
1966 struct trace_event
*event
;
1970 if (trace_flags
& TRACE_ITER_CONTEXT_INFO
) {
1971 SEQ_PUT_FIELD_RET(s
, entry
->pid
);
1972 SEQ_PUT_FIELD_RET(s
, iter
->cpu
);
1973 SEQ_PUT_FIELD_RET(s
, iter
->ts
);
1976 event
= ftrace_find_event(entry
->type
);
1977 return event
? event
->funcs
->binary(iter
, 0, event
) :
1981 int trace_empty(struct trace_iterator
*iter
)
1985 /* If we are looking at one CPU buffer, only check that one */
1986 if (iter
->cpu_file
!= TRACE_PIPE_ALL_CPU
) {
1987 cpu
= iter
->cpu_file
;
1988 if (iter
->buffer_iter
[cpu
]) {
1989 if (!ring_buffer_iter_empty(iter
->buffer_iter
[cpu
]))
1992 if (!ring_buffer_empty_cpu(iter
->tr
->buffer
, cpu
))
1998 for_each_tracing_cpu(cpu
) {
1999 if (iter
->buffer_iter
[cpu
]) {
2000 if (!ring_buffer_iter_empty(iter
->buffer_iter
[cpu
]))
2003 if (!ring_buffer_empty_cpu(iter
->tr
->buffer
, cpu
))
2011 /* Called with trace_event_read_lock() held. */
2012 enum print_line_t
print_trace_line(struct trace_iterator
*iter
)
2014 enum print_line_t ret
;
2016 if (iter
->lost_events
)
2017 trace_seq_printf(&iter
->seq
, "CPU:%d [LOST %lu EVENTS]\n",
2018 iter
->cpu
, iter
->lost_events
);
2020 if (iter
->trace
&& iter
->trace
->print_line
) {
2021 ret
= iter
->trace
->print_line(iter
);
2022 if (ret
!= TRACE_TYPE_UNHANDLED
)
2026 if (iter
->ent
->type
== TRACE_BPRINT
&&
2027 trace_flags
& TRACE_ITER_PRINTK
&&
2028 trace_flags
& TRACE_ITER_PRINTK_MSGONLY
)
2029 return trace_print_bprintk_msg_only(iter
);
2031 if (iter
->ent
->type
== TRACE_PRINT
&&
2032 trace_flags
& TRACE_ITER_PRINTK
&&
2033 trace_flags
& TRACE_ITER_PRINTK_MSGONLY
)
2034 return trace_print_printk_msg_only(iter
);
2036 if (trace_flags
& TRACE_ITER_BIN
)
2037 return print_bin_fmt(iter
);
2039 if (trace_flags
& TRACE_ITER_HEX
)
2040 return print_hex_fmt(iter
);
2042 if (trace_flags
& TRACE_ITER_RAW
)
2043 return print_raw_fmt(iter
);
2045 return print_trace_fmt(iter
);
2048 void trace_default_header(struct seq_file
*m
)
2050 struct trace_iterator
*iter
= m
->private;
2052 if (iter
->iter_flags
& TRACE_FILE_LAT_FMT
) {
2053 /* print nothing if the buffers are empty */
2054 if (trace_empty(iter
))
2056 print_trace_header(m
, iter
);
2057 if (!(trace_flags
& TRACE_ITER_VERBOSE
))
2058 print_lat_help_header(m
);
2060 if (!(trace_flags
& TRACE_ITER_VERBOSE
))
2061 print_func_help_header(m
);
2065 static int s_show(struct seq_file
*m
, void *v
)
2067 struct trace_iterator
*iter
= v
;
2070 if (iter
->ent
== NULL
) {
2072 seq_printf(m
, "# tracer: %s\n", iter
->trace
->name
);
2075 if (iter
->trace
&& iter
->trace
->print_header
)
2076 iter
->trace
->print_header(m
);
2078 trace_default_header(m
);
2080 } else if (iter
->leftover
) {
2082 * If we filled the seq_file buffer earlier, we
2083 * want to just show it now.
2085 ret
= trace_print_seq(m
, &iter
->seq
);
2087 /* ret should this time be zero, but you never know */
2088 iter
->leftover
= ret
;
2091 print_trace_line(iter
);
2092 ret
= trace_print_seq(m
, &iter
->seq
);
2094 * If we overflow the seq_file buffer, then it will
2095 * ask us for this data again at start up.
2097 * ret is 0 if seq_file write succeeded.
2100 iter
->leftover
= ret
;
2106 static const struct seq_operations tracer_seq_ops
= {
2113 static struct trace_iterator
*
2114 __tracing_open(struct inode
*inode
, struct file
*file
)
2116 long cpu_file
= (long) inode
->i_private
;
2117 void *fail_ret
= ERR_PTR(-ENOMEM
);
2118 struct trace_iterator
*iter
;
2122 if (tracing_disabled
)
2123 return ERR_PTR(-ENODEV
);
2125 iter
= kzalloc(sizeof(*iter
), GFP_KERNEL
);
2127 return ERR_PTR(-ENOMEM
);
2130 * We make a copy of the current tracer to avoid concurrent
2131 * changes on it while we are reading.
2133 mutex_lock(&trace_types_lock
);
2134 iter
->trace
= kzalloc(sizeof(*iter
->trace
), GFP_KERNEL
);
2139 *iter
->trace
= *current_trace
;
2141 if (!zalloc_cpumask_var(&iter
->started
, GFP_KERNEL
))
2144 if (current_trace
&& current_trace
->print_max
)
2147 iter
->tr
= &global_trace
;
2149 mutex_init(&iter
->mutex
);
2150 iter
->cpu_file
= cpu_file
;
2152 /* Notify the tracer early; before we stop tracing. */
2153 if (iter
->trace
&& iter
->trace
->open
)
2154 iter
->trace
->open(iter
);
2156 /* Annotate start of buffers if we had overruns */
2157 if (ring_buffer_overruns(iter
->tr
->buffer
))
2158 iter
->iter_flags
|= TRACE_FILE_ANNOTATE
;
2160 /* stop the trace while dumping */
2163 if (iter
->cpu_file
== TRACE_PIPE_ALL_CPU
) {
2164 for_each_tracing_cpu(cpu
) {
2165 iter
->buffer_iter
[cpu
] =
2166 ring_buffer_read_prepare(iter
->tr
->buffer
, cpu
);
2168 ring_buffer_read_prepare_sync();
2169 for_each_tracing_cpu(cpu
) {
2170 ring_buffer_read_start(iter
->buffer_iter
[cpu
]);
2171 tracing_iter_reset(iter
, cpu
);
2174 cpu
= iter
->cpu_file
;
2175 iter
->buffer_iter
[cpu
] =
2176 ring_buffer_read_prepare(iter
->tr
->buffer
, cpu
);
2177 ring_buffer_read_prepare_sync();
2178 ring_buffer_read_start(iter
->buffer_iter
[cpu
]);
2179 tracing_iter_reset(iter
, cpu
);
2182 ret
= seq_open(file
, &tracer_seq_ops
);
2184 fail_ret
= ERR_PTR(ret
);
2188 m
= file
->private_data
;
2191 mutex_unlock(&trace_types_lock
);
2196 for_each_tracing_cpu(cpu
) {
2197 if (iter
->buffer_iter
[cpu
])
2198 ring_buffer_read_finish(iter
->buffer_iter
[cpu
]);
2200 free_cpumask_var(iter
->started
);
2203 mutex_unlock(&trace_types_lock
);
2210 int tracing_open_generic(struct inode
*inode
, struct file
*filp
)
2212 if (tracing_disabled
)
2215 filp
->private_data
= inode
->i_private
;
2219 static int tracing_release(struct inode
*inode
, struct file
*file
)
2221 struct seq_file
*m
= file
->private_data
;
2222 struct trace_iterator
*iter
;
2225 if (!(file
->f_mode
& FMODE_READ
))
2230 mutex_lock(&trace_types_lock
);
2231 for_each_tracing_cpu(cpu
) {
2232 if (iter
->buffer_iter
[cpu
])
2233 ring_buffer_read_finish(iter
->buffer_iter
[cpu
]);
2236 if (iter
->trace
&& iter
->trace
->close
)
2237 iter
->trace
->close(iter
);
2239 /* reenable tracing if it was previously enabled */
2241 mutex_unlock(&trace_types_lock
);
2243 seq_release(inode
, file
);
2244 mutex_destroy(&iter
->mutex
);
2245 free_cpumask_var(iter
->started
);
2251 static int tracing_open(struct inode
*inode
, struct file
*file
)
2253 struct trace_iterator
*iter
;
2256 /* If this file was open for write, then erase contents */
2257 if ((file
->f_mode
& FMODE_WRITE
) &&
2258 (file
->f_flags
& O_TRUNC
)) {
2259 long cpu
= (long) inode
->i_private
;
2261 if (cpu
== TRACE_PIPE_ALL_CPU
)
2262 tracing_reset_online_cpus(&global_trace
);
2264 tracing_reset(&global_trace
, cpu
);
2267 if (file
->f_mode
& FMODE_READ
) {
2268 iter
= __tracing_open(inode
, file
);
2270 ret
= PTR_ERR(iter
);
2271 else if (trace_flags
& TRACE_ITER_LATENCY_FMT
)
2272 iter
->iter_flags
|= TRACE_FILE_LAT_FMT
;
2278 t_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
2280 struct tracer
*t
= v
;
2290 static void *t_start(struct seq_file
*m
, loff_t
*pos
)
2295 mutex_lock(&trace_types_lock
);
2296 for (t
= trace_types
; t
&& l
< *pos
; t
= t_next(m
, t
, &l
))
2302 static void t_stop(struct seq_file
*m
, void *p
)
2304 mutex_unlock(&trace_types_lock
);
2307 static int t_show(struct seq_file
*m
, void *v
)
2309 struct tracer
*t
= v
;
2314 seq_printf(m
, "%s", t
->name
);
2323 static const struct seq_operations show_traces_seq_ops
= {
2330 static int show_traces_open(struct inode
*inode
, struct file
*file
)
2332 if (tracing_disabled
)
2335 return seq_open(file
, &show_traces_seq_ops
);
2339 tracing_write_stub(struct file
*filp
, const char __user
*ubuf
,
2340 size_t count
, loff_t
*ppos
)
2345 static loff_t
tracing_seek(struct file
*file
, loff_t offset
, int origin
)
2347 if (file
->f_mode
& FMODE_READ
)
2348 return seq_lseek(file
, offset
, origin
);
2353 static const struct file_operations tracing_fops
= {
2354 .open
= tracing_open
,
2356 .write
= tracing_write_stub
,
2357 .llseek
= tracing_seek
,
2358 .release
= tracing_release
,
2361 static const struct file_operations show_traces_fops
= {
2362 .open
= show_traces_open
,
2364 .release
= seq_release
,
2365 .llseek
= seq_lseek
,
2369 * Only trace on a CPU if the bitmask is set:
2371 static cpumask_var_t tracing_cpumask
;
2374 * The tracer itself will not take this lock, but still we want
2375 * to provide a consistent cpumask to user-space:
2377 static DEFINE_MUTEX(tracing_cpumask_update_lock
);
2380 * Temporary storage for the character representation of the
2381 * CPU bitmask (and one more byte for the newline):
2383 static char mask_str
[NR_CPUS
+ 1];
2386 tracing_cpumask_read(struct file
*filp
, char __user
*ubuf
,
2387 size_t count
, loff_t
*ppos
)
2391 mutex_lock(&tracing_cpumask_update_lock
);
2393 len
= cpumask_scnprintf(mask_str
, count
, tracing_cpumask
);
2394 if (count
- len
< 2) {
2398 len
+= sprintf(mask_str
+ len
, "\n");
2399 count
= simple_read_from_buffer(ubuf
, count
, ppos
, mask_str
, NR_CPUS
+1);
2402 mutex_unlock(&tracing_cpumask_update_lock
);
2408 tracing_cpumask_write(struct file
*filp
, const char __user
*ubuf
,
2409 size_t count
, loff_t
*ppos
)
2412 cpumask_var_t tracing_cpumask_new
;
2414 if (!alloc_cpumask_var(&tracing_cpumask_new
, GFP_KERNEL
))
2417 err
= cpumask_parse_user(ubuf
, count
, tracing_cpumask_new
);
2421 mutex_lock(&tracing_cpumask_update_lock
);
2423 local_irq_disable();
2424 arch_spin_lock(&ftrace_max_lock
);
2425 for_each_tracing_cpu(cpu
) {
2427 * Increase/decrease the disabled counter if we are
2428 * about to flip a bit in the cpumask:
2430 if (cpumask_test_cpu(cpu
, tracing_cpumask
) &&
2431 !cpumask_test_cpu(cpu
, tracing_cpumask_new
)) {
2432 atomic_inc(&global_trace
.data
[cpu
]->disabled
);
2434 if (!cpumask_test_cpu(cpu
, tracing_cpumask
) &&
2435 cpumask_test_cpu(cpu
, tracing_cpumask_new
)) {
2436 atomic_dec(&global_trace
.data
[cpu
]->disabled
);
2439 arch_spin_unlock(&ftrace_max_lock
);
2442 cpumask_copy(tracing_cpumask
, tracing_cpumask_new
);
2444 mutex_unlock(&tracing_cpumask_update_lock
);
2445 free_cpumask_var(tracing_cpumask_new
);
2450 free_cpumask_var(tracing_cpumask_new
);
2455 static const struct file_operations tracing_cpumask_fops
= {
2456 .open
= tracing_open_generic
,
2457 .read
= tracing_cpumask_read
,
2458 .write
= tracing_cpumask_write
,
2459 .llseek
= generic_file_llseek
,
2462 static int tracing_trace_options_show(struct seq_file
*m
, void *v
)
2464 struct tracer_opt
*trace_opts
;
2468 mutex_lock(&trace_types_lock
);
2469 tracer_flags
= current_trace
->flags
->val
;
2470 trace_opts
= current_trace
->flags
->opts
;
2472 for (i
= 0; trace_options
[i
]; i
++) {
2473 if (trace_flags
& (1 << i
))
2474 seq_printf(m
, "%s\n", trace_options
[i
]);
2476 seq_printf(m
, "no%s\n", trace_options
[i
]);
2479 for (i
= 0; trace_opts
[i
].name
; i
++) {
2480 if (tracer_flags
& trace_opts
[i
].bit
)
2481 seq_printf(m
, "%s\n", trace_opts
[i
].name
);
2483 seq_printf(m
, "no%s\n", trace_opts
[i
].name
);
2485 mutex_unlock(&trace_types_lock
);
2490 static int __set_tracer_option(struct tracer
*trace
,
2491 struct tracer_flags
*tracer_flags
,
2492 struct tracer_opt
*opts
, int neg
)
2496 ret
= trace
->set_flag(tracer_flags
->val
, opts
->bit
, !neg
);
2501 tracer_flags
->val
&= ~opts
->bit
;
2503 tracer_flags
->val
|= opts
->bit
;
2507 /* Try to assign a tracer specific option */
2508 static int set_tracer_option(struct tracer
*trace
, char *cmp
, int neg
)
2510 struct tracer_flags
*tracer_flags
= trace
->flags
;
2511 struct tracer_opt
*opts
= NULL
;
2514 for (i
= 0; tracer_flags
->opts
[i
].name
; i
++) {
2515 opts
= &tracer_flags
->opts
[i
];
2517 if (strcmp(cmp
, opts
->name
) == 0)
2518 return __set_tracer_option(trace
, trace
->flags
,
2525 static void set_tracer_flags(unsigned int mask
, int enabled
)
2527 /* do nothing if flag is already set */
2528 if (!!(trace_flags
& mask
) == !!enabled
)
2532 trace_flags
|= mask
;
2534 trace_flags
&= ~mask
;
2536 if (mask
== TRACE_ITER_RECORD_CMD
)
2537 trace_event_enable_cmd_record(enabled
);
2539 if (mask
== TRACE_ITER_OVERWRITE
)
2540 ring_buffer_change_overwrite(global_trace
.buffer
, enabled
);
2544 tracing_trace_options_write(struct file
*filp
, const char __user
*ubuf
,
2545 size_t cnt
, loff_t
*ppos
)
2553 if (cnt
>= sizeof(buf
))
2556 if (copy_from_user(&buf
, ubuf
, cnt
))
2560 cmp
= strstrip(buf
);
2562 if (strncmp(cmp
, "no", 2) == 0) {
2567 for (i
= 0; trace_options
[i
]; i
++) {
2568 if (strcmp(cmp
, trace_options
[i
]) == 0) {
2569 set_tracer_flags(1 << i
, !neg
);
2574 /* If no option could be set, test the specific tracer options */
2575 if (!trace_options
[i
]) {
2576 mutex_lock(&trace_types_lock
);
2577 ret
= set_tracer_option(current_trace
, cmp
, neg
);
2578 mutex_unlock(&trace_types_lock
);
2588 static int tracing_trace_options_open(struct inode
*inode
, struct file
*file
)
2590 if (tracing_disabled
)
2592 return single_open(file
, tracing_trace_options_show
, NULL
);
2595 static const struct file_operations tracing_iter_fops
= {
2596 .open
= tracing_trace_options_open
,
2598 .llseek
= seq_lseek
,
2599 .release
= single_release
,
2600 .write
= tracing_trace_options_write
,
2603 static const char readme_msg
[] =
2604 "tracing mini-HOWTO:\n\n"
2605 "# mount -t debugfs nodev /sys/kernel/debug\n\n"
2606 "# cat /sys/kernel/debug/tracing/available_tracers\n"
2607 "wakeup preemptirqsoff preemptoff irqsoff function sched_switch nop\n\n"
2608 "# cat /sys/kernel/debug/tracing/current_tracer\n"
2610 "# echo sched_switch > /sys/kernel/debug/tracing/current_tracer\n"
2611 "# cat /sys/kernel/debug/tracing/current_tracer\n"
2613 "# cat /sys/kernel/debug/tracing/trace_options\n"
2614 "noprint-parent nosym-offset nosym-addr noverbose\n"
2615 "# echo print-parent > /sys/kernel/debug/tracing/trace_options\n"
2616 "# echo 1 > /sys/kernel/debug/tracing/tracing_enabled\n"
2617 "# cat /sys/kernel/debug/tracing/trace > /tmp/trace.txt\n"
2618 "# echo 0 > /sys/kernel/debug/tracing/tracing_enabled\n"
2622 tracing_readme_read(struct file
*filp
, char __user
*ubuf
,
2623 size_t cnt
, loff_t
*ppos
)
2625 return simple_read_from_buffer(ubuf
, cnt
, ppos
,
2626 readme_msg
, strlen(readme_msg
));
2629 static const struct file_operations tracing_readme_fops
= {
2630 .open
= tracing_open_generic
,
2631 .read
= tracing_readme_read
,
2632 .llseek
= generic_file_llseek
,
2636 tracing_saved_cmdlines_read(struct file
*file
, char __user
*ubuf
,
2637 size_t cnt
, loff_t
*ppos
)
2646 file_buf
= kmalloc(SAVED_CMDLINES
*(16+TASK_COMM_LEN
), GFP_KERNEL
);
2650 buf_comm
= kmalloc(TASK_COMM_LEN
, GFP_KERNEL
);
2658 for (i
= 0; i
< SAVED_CMDLINES
; i
++) {
2661 pid
= map_cmdline_to_pid
[i
];
2662 if (pid
== -1 || pid
== NO_CMDLINE_MAP
)
2665 trace_find_cmdline(pid
, buf_comm
);
2666 r
= sprintf(buf
, "%d %s\n", pid
, buf_comm
);
2671 len
= simple_read_from_buffer(ubuf
, cnt
, ppos
,
2680 static const struct file_operations tracing_saved_cmdlines_fops
= {
2681 .open
= tracing_open_generic
,
2682 .read
= tracing_saved_cmdlines_read
,
2683 .llseek
= generic_file_llseek
,
2687 tracing_ctrl_read(struct file
*filp
, char __user
*ubuf
,
2688 size_t cnt
, loff_t
*ppos
)
2693 r
= sprintf(buf
, "%u\n", tracer_enabled
);
2694 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
2698 tracing_ctrl_write(struct file
*filp
, const char __user
*ubuf
,
2699 size_t cnt
, loff_t
*ppos
)
2701 struct trace_array
*tr
= filp
->private_data
;
2706 if (cnt
>= sizeof(buf
))
2709 if (copy_from_user(&buf
, ubuf
, cnt
))
2714 ret
= strict_strtoul(buf
, 10, &val
);
2720 mutex_lock(&trace_types_lock
);
2721 if (tracer_enabled
^ val
) {
2723 /* Only need to warn if this is used to change the state */
2724 WARN_ONCE(1, "tracing_enabled is deprecated. Use tracing_on");
2728 if (current_trace
->start
)
2729 current_trace
->start(tr
);
2734 if (current_trace
->stop
)
2735 current_trace
->stop(tr
);
2738 mutex_unlock(&trace_types_lock
);
2746 tracing_set_trace_read(struct file
*filp
, char __user
*ubuf
,
2747 size_t cnt
, loff_t
*ppos
)
2749 char buf
[MAX_TRACER_SIZE
+2];
2752 mutex_lock(&trace_types_lock
);
2754 r
= sprintf(buf
, "%s\n", current_trace
->name
);
2756 r
= sprintf(buf
, "\n");
2757 mutex_unlock(&trace_types_lock
);
2759 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
2762 int tracer_init(struct tracer
*t
, struct trace_array
*tr
)
2764 tracing_reset_online_cpus(tr
);
2768 static int tracing_resize_ring_buffer(unsigned long size
)
2773 * If kernel or user changes the size of the ring buffer
2774 * we use the size that was given, and we can forget about
2775 * expanding it later.
2777 ring_buffer_expanded
= 1;
2779 ret
= ring_buffer_resize(global_trace
.buffer
, size
);
2783 if (!current_trace
->use_max_tr
)
2786 ret
= ring_buffer_resize(max_tr
.buffer
, size
);
2790 r
= ring_buffer_resize(global_trace
.buffer
,
2791 global_trace
.entries
);
2794 * AARGH! We are left with different
2795 * size max buffer!!!!
2796 * The max buffer is our "snapshot" buffer.
2797 * When a tracer needs a snapshot (one of the
2798 * latency tracers), it swaps the max buffer
2799 * with the saved snap shot. We succeeded to
2800 * update the size of the main buffer, but failed to
2801 * update the size of the max buffer. But when we tried
2802 * to reset the main buffer to the original size, we
2803 * failed there too. This is very unlikely to
2804 * happen, but if it does, warn and kill all
2808 tracing_disabled
= 1;
2813 max_tr
.entries
= size
;
2815 global_trace
.entries
= size
;
2822 * tracing_update_buffers - used by tracing facility to expand ring buffers
2824 * To save on memory when the tracing is never used on a system with it
2825 * configured in. The ring buffers are set to a minimum size. But once
2826 * a user starts to use the tracing facility, then they need to grow
2827 * to their default size.
2829 * This function is to be called when a tracer is about to be used.
2831 int tracing_update_buffers(void)
2835 mutex_lock(&trace_types_lock
);
2836 if (!ring_buffer_expanded
)
2837 ret
= tracing_resize_ring_buffer(trace_buf_size
);
2838 mutex_unlock(&trace_types_lock
);
2843 struct trace_option_dentry
;
2845 static struct trace_option_dentry
*
2846 create_trace_option_files(struct tracer
*tracer
);
2849 destroy_trace_option_files(struct trace_option_dentry
*topts
);
2851 static int tracing_set_tracer(const char *buf
)
2853 static struct trace_option_dentry
*topts
;
2854 struct trace_array
*tr
= &global_trace
;
2858 mutex_lock(&trace_types_lock
);
2860 if (!ring_buffer_expanded
) {
2861 ret
= tracing_resize_ring_buffer(trace_buf_size
);
2867 for (t
= trace_types
; t
; t
= t
->next
) {
2868 if (strcmp(t
->name
, buf
) == 0)
2875 if (t
== current_trace
)
2878 trace_branch_disable();
2879 if (current_trace
&& current_trace
->reset
)
2880 current_trace
->reset(tr
);
2881 if (current_trace
&& current_trace
->use_max_tr
) {
2883 * We don't free the ring buffer. instead, resize it because
2884 * The max_tr ring buffer has some state (e.g. ring->clock) and
2885 * we want preserve it.
2887 ring_buffer_resize(max_tr
.buffer
, 1);
2890 destroy_trace_option_files(topts
);
2894 topts
= create_trace_option_files(current_trace
);
2895 if (current_trace
->use_max_tr
) {
2896 ret
= ring_buffer_resize(max_tr
.buffer
, global_trace
.entries
);
2899 max_tr
.entries
= global_trace
.entries
;
2903 ret
= tracer_init(t
, tr
);
2908 trace_branch_enable(tr
);
2910 mutex_unlock(&trace_types_lock
);
2916 tracing_set_trace_write(struct file
*filp
, const char __user
*ubuf
,
2917 size_t cnt
, loff_t
*ppos
)
2919 char buf
[MAX_TRACER_SIZE
+1];
2926 if (cnt
> MAX_TRACER_SIZE
)
2927 cnt
= MAX_TRACER_SIZE
;
2929 if (copy_from_user(&buf
, ubuf
, cnt
))
2934 /* strip ending whitespace. */
2935 for (i
= cnt
- 1; i
> 0 && isspace(buf
[i
]); i
--)
2938 err
= tracing_set_tracer(buf
);
2948 tracing_max_lat_read(struct file
*filp
, char __user
*ubuf
,
2949 size_t cnt
, loff_t
*ppos
)
2951 unsigned long *ptr
= filp
->private_data
;
2955 r
= snprintf(buf
, sizeof(buf
), "%ld\n",
2956 *ptr
== (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr
));
2957 if (r
> sizeof(buf
))
2959 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
2963 tracing_max_lat_write(struct file
*filp
, const char __user
*ubuf
,
2964 size_t cnt
, loff_t
*ppos
)
2966 unsigned long *ptr
= filp
->private_data
;
2971 if (cnt
>= sizeof(buf
))
2974 if (copy_from_user(&buf
, ubuf
, cnt
))
2979 ret
= strict_strtoul(buf
, 10, &val
);
2988 static int tracing_open_pipe(struct inode
*inode
, struct file
*filp
)
2990 long cpu_file
= (long) inode
->i_private
;
2991 struct trace_iterator
*iter
;
2994 if (tracing_disabled
)
2997 mutex_lock(&trace_types_lock
);
2999 /* create a buffer to store the information to pass to userspace */
3000 iter
= kzalloc(sizeof(*iter
), GFP_KERNEL
);
3007 * We make a copy of the current tracer to avoid concurrent
3008 * changes on it while we are reading.
3010 iter
->trace
= kmalloc(sizeof(*iter
->trace
), GFP_KERNEL
);
3016 *iter
->trace
= *current_trace
;
3018 if (!alloc_cpumask_var(&iter
->started
, GFP_KERNEL
)) {
3023 /* trace pipe does not show start of buffer */
3024 cpumask_setall(iter
->started
);
3026 if (trace_flags
& TRACE_ITER_LATENCY_FMT
)
3027 iter
->iter_flags
|= TRACE_FILE_LAT_FMT
;
3029 iter
->cpu_file
= cpu_file
;
3030 iter
->tr
= &global_trace
;
3031 mutex_init(&iter
->mutex
);
3032 filp
->private_data
= iter
;
3034 if (iter
->trace
->pipe_open
)
3035 iter
->trace
->pipe_open(iter
);
3037 nonseekable_open(inode
, filp
);
3039 mutex_unlock(&trace_types_lock
);
3045 mutex_unlock(&trace_types_lock
);
3049 static int tracing_release_pipe(struct inode
*inode
, struct file
*file
)
3051 struct trace_iterator
*iter
= file
->private_data
;
3053 mutex_lock(&trace_types_lock
);
3055 if (iter
->trace
->pipe_close
)
3056 iter
->trace
->pipe_close(iter
);
3058 mutex_unlock(&trace_types_lock
);
3060 free_cpumask_var(iter
->started
);
3061 mutex_destroy(&iter
->mutex
);
3069 tracing_poll_pipe(struct file
*filp
, poll_table
*poll_table
)
3071 struct trace_iterator
*iter
= filp
->private_data
;
3073 if (trace_flags
& TRACE_ITER_BLOCK
) {
3075 * Always select as readable when in blocking mode
3077 return POLLIN
| POLLRDNORM
;
3079 if (!trace_empty(iter
))
3080 return POLLIN
| POLLRDNORM
;
3081 poll_wait(filp
, &trace_wait
, poll_table
);
3082 if (!trace_empty(iter
))
3083 return POLLIN
| POLLRDNORM
;
3090 void default_wait_pipe(struct trace_iterator
*iter
)
3094 prepare_to_wait(&trace_wait
, &wait
, TASK_INTERRUPTIBLE
);
3096 if (trace_empty(iter
))
3099 finish_wait(&trace_wait
, &wait
);
3103 * This is a make-shift waitqueue.
3104 * A tracer might use this callback on some rare cases:
3106 * 1) the current tracer might hold the runqueue lock when it wakes up
3107 * a reader, hence a deadlock (sched, function, and function graph tracers)
3108 * 2) the function tracers, trace all functions, we don't want
3109 * the overhead of calling wake_up and friends
3110 * (and tracing them too)
3112 * Anyway, this is really very primitive wakeup.
3114 void poll_wait_pipe(struct trace_iterator
*iter
)
3116 set_current_state(TASK_INTERRUPTIBLE
);
3117 /* sleep for 100 msecs, and try again. */
3118 schedule_timeout(HZ
/ 10);
3121 /* Must be called with trace_types_lock mutex held. */
3122 static int tracing_wait_pipe(struct file
*filp
)
3124 struct trace_iterator
*iter
= filp
->private_data
;
3126 while (trace_empty(iter
)) {
3128 if ((filp
->f_flags
& O_NONBLOCK
)) {
3132 mutex_unlock(&iter
->mutex
);
3134 iter
->trace
->wait_pipe(iter
);
3136 mutex_lock(&iter
->mutex
);
3138 if (signal_pending(current
))
3142 * We block until we read something and tracing is disabled.
3143 * We still block if tracing is disabled, but we have never
3144 * read anything. This allows a user to cat this file, and
3145 * then enable tracing. But after we have read something,
3146 * we give an EOF when tracing is again disabled.
3148 * iter->pos will be 0 if we haven't read anything.
3150 if (!tracer_enabled
&& iter
->pos
)
3161 tracing_read_pipe(struct file
*filp
, char __user
*ubuf
,
3162 size_t cnt
, loff_t
*ppos
)
3164 struct trace_iterator
*iter
= filp
->private_data
;
3165 static struct tracer
*old_tracer
;
3168 /* return any leftover data */
3169 sret
= trace_seq_to_user(&iter
->seq
, ubuf
, cnt
);
3173 trace_seq_init(&iter
->seq
);
3175 /* copy the tracer to avoid using a global lock all around */
3176 mutex_lock(&trace_types_lock
);
3177 if (unlikely(old_tracer
!= current_trace
&& current_trace
)) {
3178 old_tracer
= current_trace
;
3179 *iter
->trace
= *current_trace
;
3181 mutex_unlock(&trace_types_lock
);
3184 * Avoid more than one consumer on a single file descriptor
3185 * This is just a matter of traces coherency, the ring buffer itself
3188 mutex_lock(&iter
->mutex
);
3189 if (iter
->trace
->read
) {
3190 sret
= iter
->trace
->read(iter
, filp
, ubuf
, cnt
, ppos
);
3196 sret
= tracing_wait_pipe(filp
);
3200 /* stop when tracing is finished */
3201 if (trace_empty(iter
)) {
3206 if (cnt
>= PAGE_SIZE
)
3207 cnt
= PAGE_SIZE
- 1;
3209 /* reset all but tr, trace, and overruns */
3210 memset(&iter
->seq
, 0,
3211 sizeof(struct trace_iterator
) -
3212 offsetof(struct trace_iterator
, seq
));
3215 trace_event_read_lock();
3216 trace_access_lock(iter
->cpu_file
);
3217 while (trace_find_next_entry_inc(iter
) != NULL
) {
3218 enum print_line_t ret
;
3219 int len
= iter
->seq
.len
;
3221 ret
= print_trace_line(iter
);
3222 if (ret
== TRACE_TYPE_PARTIAL_LINE
) {
3223 /* don't print partial lines */
3224 iter
->seq
.len
= len
;
3227 if (ret
!= TRACE_TYPE_NO_CONSUME
)
3228 trace_consume(iter
);
3230 if (iter
->seq
.len
>= cnt
)
3233 trace_access_unlock(iter
->cpu_file
);
3234 trace_event_read_unlock();
3236 /* Now copy what we have to the user */
3237 sret
= trace_seq_to_user(&iter
->seq
, ubuf
, cnt
);
3238 if (iter
->seq
.readpos
>= iter
->seq
.len
)
3239 trace_seq_init(&iter
->seq
);
3242 * If there was nothing to send to user, in spite of consuming trace
3243 * entries, go back to wait for more entries.
3249 mutex_unlock(&iter
->mutex
);
3254 static void tracing_pipe_buf_release(struct pipe_inode_info
*pipe
,
3255 struct pipe_buffer
*buf
)
3257 __free_page(buf
->page
);
3260 static void tracing_spd_release_pipe(struct splice_pipe_desc
*spd
,
3263 __free_page(spd
->pages
[idx
]);
3266 static const struct pipe_buf_operations tracing_pipe_buf_ops
= {
3268 .map
= generic_pipe_buf_map
,
3269 .unmap
= generic_pipe_buf_unmap
,
3270 .confirm
= generic_pipe_buf_confirm
,
3271 .release
= tracing_pipe_buf_release
,
3272 .steal
= generic_pipe_buf_steal
,
3273 .get
= generic_pipe_buf_get
,
3277 tracing_fill_pipe_page(size_t rem
, struct trace_iterator
*iter
)
3282 /* Seq buffer is page-sized, exactly what we need. */
3284 count
= iter
->seq
.len
;
3285 ret
= print_trace_line(iter
);
3286 count
= iter
->seq
.len
- count
;
3289 iter
->seq
.len
-= count
;
3292 if (ret
== TRACE_TYPE_PARTIAL_LINE
) {
3293 iter
->seq
.len
-= count
;
3297 if (ret
!= TRACE_TYPE_NO_CONSUME
)
3298 trace_consume(iter
);
3300 if (!trace_find_next_entry_inc(iter
)) {
3310 static ssize_t
tracing_splice_read_pipe(struct file
*filp
,
3312 struct pipe_inode_info
*pipe
,
3316 struct page
*pages_def
[PIPE_DEF_BUFFERS
];
3317 struct partial_page partial_def
[PIPE_DEF_BUFFERS
];
3318 struct trace_iterator
*iter
= filp
->private_data
;
3319 struct splice_pipe_desc spd
= {
3321 .partial
= partial_def
,
3322 .nr_pages
= 0, /* This gets updated below. */
3324 .ops
= &tracing_pipe_buf_ops
,
3325 .spd_release
= tracing_spd_release_pipe
,
3327 static struct tracer
*old_tracer
;
3332 if (splice_grow_spd(pipe
, &spd
))
3335 /* copy the tracer to avoid using a global lock all around */
3336 mutex_lock(&trace_types_lock
);
3337 if (unlikely(old_tracer
!= current_trace
&& current_trace
)) {
3338 old_tracer
= current_trace
;
3339 *iter
->trace
= *current_trace
;
3341 mutex_unlock(&trace_types_lock
);
3343 mutex_lock(&iter
->mutex
);
3345 if (iter
->trace
->splice_read
) {
3346 ret
= iter
->trace
->splice_read(iter
, filp
,
3347 ppos
, pipe
, len
, flags
);
3352 ret
= tracing_wait_pipe(filp
);
3356 if (!iter
->ent
&& !trace_find_next_entry_inc(iter
)) {
3361 trace_event_read_lock();
3362 trace_access_lock(iter
->cpu_file
);
3364 /* Fill as many pages as possible. */
3365 for (i
= 0, rem
= len
; i
< pipe
->buffers
&& rem
; i
++) {
3366 spd
.pages
[i
] = alloc_page(GFP_KERNEL
);
3370 rem
= tracing_fill_pipe_page(rem
, iter
);
3372 /* Copy the data into the page, so we can start over. */
3373 ret
= trace_seq_to_buffer(&iter
->seq
,
3374 page_address(spd
.pages
[i
]),
3377 __free_page(spd
.pages
[i
]);
3380 spd
.partial
[i
].offset
= 0;
3381 spd
.partial
[i
].len
= iter
->seq
.len
;
3383 trace_seq_init(&iter
->seq
);
3386 trace_access_unlock(iter
->cpu_file
);
3387 trace_event_read_unlock();
3388 mutex_unlock(&iter
->mutex
);
3392 ret
= splice_to_pipe(pipe
, &spd
);
3394 splice_shrink_spd(pipe
, &spd
);
3398 mutex_unlock(&iter
->mutex
);
3403 tracing_entries_read(struct file
*filp
, char __user
*ubuf
,
3404 size_t cnt
, loff_t
*ppos
)
3406 struct trace_array
*tr
= filp
->private_data
;
3410 mutex_lock(&trace_types_lock
);
3411 if (!ring_buffer_expanded
)
3412 r
= sprintf(buf
, "%lu (expanded: %lu)\n",
3414 trace_buf_size
>> 10);
3416 r
= sprintf(buf
, "%lu\n", tr
->entries
>> 10);
3417 mutex_unlock(&trace_types_lock
);
3419 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
3423 tracing_entries_write(struct file
*filp
, const char __user
*ubuf
,
3424 size_t cnt
, loff_t
*ppos
)
3430 if (cnt
>= sizeof(buf
))
3433 if (copy_from_user(&buf
, ubuf
, cnt
))
3438 ret
= strict_strtoul(buf
, 10, &val
);
3442 /* must have at least 1 entry */
3446 mutex_lock(&trace_types_lock
);
3450 /* disable all cpu buffers */
3451 for_each_tracing_cpu(cpu
) {
3452 if (global_trace
.data
[cpu
])
3453 atomic_inc(&global_trace
.data
[cpu
]->disabled
);
3454 if (max_tr
.data
[cpu
])
3455 atomic_inc(&max_tr
.data
[cpu
]->disabled
);
3458 /* value is in KB */
3461 if (val
!= global_trace
.entries
) {
3462 ret
= tracing_resize_ring_buffer(val
);
3471 /* If check pages failed, return ENOMEM */
3472 if (tracing_disabled
)
3475 for_each_tracing_cpu(cpu
) {
3476 if (global_trace
.data
[cpu
])
3477 atomic_dec(&global_trace
.data
[cpu
]->disabled
);
3478 if (max_tr
.data
[cpu
])
3479 atomic_dec(&max_tr
.data
[cpu
]->disabled
);
3483 mutex_unlock(&trace_types_lock
);
3488 static int mark_printk(const char *fmt
, ...)
3492 va_start(args
, fmt
);
3493 ret
= trace_vprintk(0, fmt
, args
);
3499 tracing_mark_write(struct file
*filp
, const char __user
*ubuf
,
3500 size_t cnt
, loff_t
*fpos
)
3505 if (tracing_disabled
)
3508 if (cnt
> TRACE_BUF_SIZE
)
3509 cnt
= TRACE_BUF_SIZE
;
3511 buf
= kmalloc(cnt
+ 2, GFP_KERNEL
);
3515 if (copy_from_user(buf
, ubuf
, cnt
)) {
3519 if (buf
[cnt
-1] != '\n') {
3525 written
= mark_printk("%s", buf
);
3529 /* don't tell userspace we wrote more - it might confuse them */
3536 static int tracing_clock_show(struct seq_file
*m
, void *v
)
3540 for (i
= 0; i
< ARRAY_SIZE(trace_clocks
); i
++)
3542 "%s%s%s%s", i
? " " : "",
3543 i
== trace_clock_id
? "[" : "", trace_clocks
[i
].name
,
3544 i
== trace_clock_id
? "]" : "");
3550 static ssize_t
tracing_clock_write(struct file
*filp
, const char __user
*ubuf
,
3551 size_t cnt
, loff_t
*fpos
)
3554 const char *clockstr
;
3557 if (cnt
>= sizeof(buf
))
3560 if (copy_from_user(&buf
, ubuf
, cnt
))
3565 clockstr
= strstrip(buf
);
3567 for (i
= 0; i
< ARRAY_SIZE(trace_clocks
); i
++) {
3568 if (strcmp(trace_clocks
[i
].name
, clockstr
) == 0)
3571 if (i
== ARRAY_SIZE(trace_clocks
))
3576 mutex_lock(&trace_types_lock
);
3578 ring_buffer_set_clock(global_trace
.buffer
, trace_clocks
[i
].func
);
3580 ring_buffer_set_clock(max_tr
.buffer
, trace_clocks
[i
].func
);
3582 mutex_unlock(&trace_types_lock
);
3589 static int tracing_clock_open(struct inode
*inode
, struct file
*file
)
3591 if (tracing_disabled
)
3593 return single_open(file
, tracing_clock_show
, NULL
);
3596 static const struct file_operations tracing_max_lat_fops
= {
3597 .open
= tracing_open_generic
,
3598 .read
= tracing_max_lat_read
,
3599 .write
= tracing_max_lat_write
,
3600 .llseek
= generic_file_llseek
,
3603 static const struct file_operations tracing_ctrl_fops
= {
3604 .open
= tracing_open_generic
,
3605 .read
= tracing_ctrl_read
,
3606 .write
= tracing_ctrl_write
,
3607 .llseek
= generic_file_llseek
,
3610 static const struct file_operations set_tracer_fops
= {
3611 .open
= tracing_open_generic
,
3612 .read
= tracing_set_trace_read
,
3613 .write
= tracing_set_trace_write
,
3614 .llseek
= generic_file_llseek
,
3617 static const struct file_operations tracing_pipe_fops
= {
3618 .open
= tracing_open_pipe
,
3619 .poll
= tracing_poll_pipe
,
3620 .read
= tracing_read_pipe
,
3621 .splice_read
= tracing_splice_read_pipe
,
3622 .release
= tracing_release_pipe
,
3623 .llseek
= no_llseek
,
3626 static const struct file_operations tracing_entries_fops
= {
3627 .open
= tracing_open_generic
,
3628 .read
= tracing_entries_read
,
3629 .write
= tracing_entries_write
,
3630 .llseek
= generic_file_llseek
,
3633 static const struct file_operations tracing_mark_fops
= {
3634 .open
= tracing_open_generic
,
3635 .write
= tracing_mark_write
,
3636 .llseek
= generic_file_llseek
,
3639 static const struct file_operations trace_clock_fops
= {
3640 .open
= tracing_clock_open
,
3642 .llseek
= seq_lseek
,
3643 .release
= single_release
,
3644 .write
= tracing_clock_write
,
3647 struct ftrace_buffer_info
{
3648 struct trace_array
*tr
;
3654 static int tracing_buffers_open(struct inode
*inode
, struct file
*filp
)
3656 int cpu
= (int)(long)inode
->i_private
;
3657 struct ftrace_buffer_info
*info
;
3659 if (tracing_disabled
)
3662 info
= kzalloc(sizeof(*info
), GFP_KERNEL
);
3666 info
->tr
= &global_trace
;
3669 /* Force reading ring buffer for first read */
3670 info
->read
= (unsigned int)-1;
3672 filp
->private_data
= info
;
3674 return nonseekable_open(inode
, filp
);
3678 tracing_buffers_read(struct file
*filp
, char __user
*ubuf
,
3679 size_t count
, loff_t
*ppos
)
3681 struct ftrace_buffer_info
*info
= filp
->private_data
;
3689 info
->spare
= ring_buffer_alloc_read_page(info
->tr
->buffer
);
3693 /* Do we have previous read data to read? */
3694 if (info
->read
< PAGE_SIZE
)
3699 trace_access_lock(info
->cpu
);
3700 ret
= ring_buffer_read_page(info
->tr
->buffer
,
3704 trace_access_unlock(info
->cpu
);
3709 size
= PAGE_SIZE
- info
->read
;
3713 ret
= copy_to_user(ubuf
, info
->spare
+ info
->read
, size
);
3724 static int tracing_buffers_release(struct inode
*inode
, struct file
*file
)
3726 struct ftrace_buffer_info
*info
= file
->private_data
;
3729 ring_buffer_free_read_page(info
->tr
->buffer
, info
->spare
);
3736 struct ring_buffer
*buffer
;
3741 static void buffer_pipe_buf_release(struct pipe_inode_info
*pipe
,
3742 struct pipe_buffer
*buf
)
3744 struct buffer_ref
*ref
= (struct buffer_ref
*)buf
->private;
3749 ring_buffer_free_read_page(ref
->buffer
, ref
->page
);
3754 static int buffer_pipe_buf_steal(struct pipe_inode_info
*pipe
,
3755 struct pipe_buffer
*buf
)
3760 static void buffer_pipe_buf_get(struct pipe_inode_info
*pipe
,
3761 struct pipe_buffer
*buf
)
3763 struct buffer_ref
*ref
= (struct buffer_ref
*)buf
->private;
3768 /* Pipe buffer operations for a buffer. */
3769 static const struct pipe_buf_operations buffer_pipe_buf_ops
= {
3771 .map
= generic_pipe_buf_map
,
3772 .unmap
= generic_pipe_buf_unmap
,
3773 .confirm
= generic_pipe_buf_confirm
,
3774 .release
= buffer_pipe_buf_release
,
3775 .steal
= buffer_pipe_buf_steal
,
3776 .get
= buffer_pipe_buf_get
,
3780 * Callback from splice_to_pipe(), if we need to release some pages
3781 * at the end of the spd in case we error'ed out in filling the pipe.
3783 static void buffer_spd_release(struct splice_pipe_desc
*spd
, unsigned int i
)
3785 struct buffer_ref
*ref
=
3786 (struct buffer_ref
*)spd
->partial
[i
].private;
3791 ring_buffer_free_read_page(ref
->buffer
, ref
->page
);
3793 spd
->partial
[i
].private = 0;
3797 tracing_buffers_splice_read(struct file
*file
, loff_t
*ppos
,
3798 struct pipe_inode_info
*pipe
, size_t len
,
3801 struct ftrace_buffer_info
*info
= file
->private_data
;
3802 struct partial_page partial_def
[PIPE_DEF_BUFFERS
];
3803 struct page
*pages_def
[PIPE_DEF_BUFFERS
];
3804 struct splice_pipe_desc spd
= {
3806 .partial
= partial_def
,
3808 .ops
= &buffer_pipe_buf_ops
,
3809 .spd_release
= buffer_spd_release
,
3811 struct buffer_ref
*ref
;
3812 int entries
, size
, i
;
3815 if (splice_grow_spd(pipe
, &spd
))
3818 if (*ppos
& (PAGE_SIZE
- 1)) {
3819 WARN_ONCE(1, "Ftrace: previous read must page-align\n");
3824 if (len
& (PAGE_SIZE
- 1)) {
3825 WARN_ONCE(1, "Ftrace: splice_read should page-align\n");
3826 if (len
< PAGE_SIZE
) {
3833 trace_access_lock(info
->cpu
);
3834 entries
= ring_buffer_entries_cpu(info
->tr
->buffer
, info
->cpu
);
3836 for (i
= 0; i
< pipe
->buffers
&& len
&& entries
; i
++, len
-= PAGE_SIZE
) {
3840 ref
= kzalloc(sizeof(*ref
), GFP_KERNEL
);
3845 ref
->buffer
= info
->tr
->buffer
;
3846 ref
->page
= ring_buffer_alloc_read_page(ref
->buffer
);
3852 r
= ring_buffer_read_page(ref
->buffer
, &ref
->page
,
3855 ring_buffer_free_read_page(ref
->buffer
,
3862 * zero out any left over data, this is going to
3865 size
= ring_buffer_page_len(ref
->page
);
3866 if (size
< PAGE_SIZE
)
3867 memset(ref
->page
+ size
, 0, PAGE_SIZE
- size
);
3869 page
= virt_to_page(ref
->page
);
3871 spd
.pages
[i
] = page
;
3872 spd
.partial
[i
].len
= PAGE_SIZE
;
3873 spd
.partial
[i
].offset
= 0;
3874 spd
.partial
[i
].private = (unsigned long)ref
;
3878 entries
= ring_buffer_entries_cpu(info
->tr
->buffer
, info
->cpu
);
3881 trace_access_unlock(info
->cpu
);
3884 /* did we read anything? */
3885 if (!spd
.nr_pages
) {
3886 if (flags
& SPLICE_F_NONBLOCK
)
3894 ret
= splice_to_pipe(pipe
, &spd
);
3895 splice_shrink_spd(pipe
, &spd
);
3900 static const struct file_operations tracing_buffers_fops
= {
3901 .open
= tracing_buffers_open
,
3902 .read
= tracing_buffers_read
,
3903 .release
= tracing_buffers_release
,
3904 .splice_read
= tracing_buffers_splice_read
,
3905 .llseek
= no_llseek
,
3909 tracing_stats_read(struct file
*filp
, char __user
*ubuf
,
3910 size_t count
, loff_t
*ppos
)
3912 unsigned long cpu
= (unsigned long)filp
->private_data
;
3913 struct trace_array
*tr
= &global_trace
;
3914 struct trace_seq
*s
;
3917 s
= kmalloc(sizeof(*s
), GFP_KERNEL
);
3923 cnt
= ring_buffer_entries_cpu(tr
->buffer
, cpu
);
3924 trace_seq_printf(s
, "entries: %ld\n", cnt
);
3926 cnt
= ring_buffer_overrun_cpu(tr
->buffer
, cpu
);
3927 trace_seq_printf(s
, "overrun: %ld\n", cnt
);
3929 cnt
= ring_buffer_commit_overrun_cpu(tr
->buffer
, cpu
);
3930 trace_seq_printf(s
, "commit overrun: %ld\n", cnt
);
3932 count
= simple_read_from_buffer(ubuf
, count
, ppos
, s
->buffer
, s
->len
);
3939 static const struct file_operations tracing_stats_fops
= {
3940 .open
= tracing_open_generic
,
3941 .read
= tracing_stats_read
,
3942 .llseek
= generic_file_llseek
,
3945 #ifdef CONFIG_DYNAMIC_FTRACE
3947 int __weak
ftrace_arch_read_dyn_info(char *buf
, int size
)
3953 tracing_read_dyn_info(struct file
*filp
, char __user
*ubuf
,
3954 size_t cnt
, loff_t
*ppos
)
3956 static char ftrace_dyn_info_buffer
[1024];
3957 static DEFINE_MUTEX(dyn_info_mutex
);
3958 unsigned long *p
= filp
->private_data
;
3959 char *buf
= ftrace_dyn_info_buffer
;
3960 int size
= ARRAY_SIZE(ftrace_dyn_info_buffer
);
3963 mutex_lock(&dyn_info_mutex
);
3964 r
= sprintf(buf
, "%ld ", *p
);
3966 r
+= ftrace_arch_read_dyn_info(buf
+r
, (size
-1)-r
);
3969 r
= simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
3971 mutex_unlock(&dyn_info_mutex
);
3976 static const struct file_operations tracing_dyn_info_fops
= {
3977 .open
= tracing_open_generic
,
3978 .read
= tracing_read_dyn_info
,
3979 .llseek
= generic_file_llseek
,
3983 static struct dentry
*d_tracer
;
3985 struct dentry
*tracing_init_dentry(void)
3992 if (!debugfs_initialized())
3995 d_tracer
= debugfs_create_dir("tracing", NULL
);
3997 if (!d_tracer
&& !once
) {
3999 pr_warning("Could not create debugfs directory 'tracing'\n");
4006 static struct dentry
*d_percpu
;
4008 struct dentry
*tracing_dentry_percpu(void)
4011 struct dentry
*d_tracer
;
4016 d_tracer
= tracing_init_dentry();
4021 d_percpu
= debugfs_create_dir("per_cpu", d_tracer
);
4023 if (!d_percpu
&& !once
) {
4025 pr_warning("Could not create debugfs directory 'per_cpu'\n");
4032 static void tracing_init_debugfs_percpu(long cpu
)
4034 struct dentry
*d_percpu
= tracing_dentry_percpu();
4035 struct dentry
*d_cpu
;
4036 char cpu_dir
[30]; /* 30 characters should be more than enough */
4038 snprintf(cpu_dir
, 30, "cpu%ld", cpu
);
4039 d_cpu
= debugfs_create_dir(cpu_dir
, d_percpu
);
4041 pr_warning("Could not create debugfs '%s' entry\n", cpu_dir
);
4045 /* per cpu trace_pipe */
4046 trace_create_file("trace_pipe", 0444, d_cpu
,
4047 (void *) cpu
, &tracing_pipe_fops
);
4050 trace_create_file("trace", 0644, d_cpu
,
4051 (void *) cpu
, &tracing_fops
);
4053 trace_create_file("trace_pipe_raw", 0444, d_cpu
,
4054 (void *) cpu
, &tracing_buffers_fops
);
4056 trace_create_file("stats", 0444, d_cpu
,
4057 (void *) cpu
, &tracing_stats_fops
);
4060 #ifdef CONFIG_FTRACE_SELFTEST
4061 /* Let selftest have access to static functions in this file */
4062 #include "trace_selftest.c"
4065 struct trace_option_dentry
{
4066 struct tracer_opt
*opt
;
4067 struct tracer_flags
*flags
;
4068 struct dentry
*entry
;
4072 trace_options_read(struct file
*filp
, char __user
*ubuf
, size_t cnt
,
4075 struct trace_option_dentry
*topt
= filp
->private_data
;
4078 if (topt
->flags
->val
& topt
->opt
->bit
)
4083 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, 2);
4087 trace_options_write(struct file
*filp
, const char __user
*ubuf
, size_t cnt
,
4090 struct trace_option_dentry
*topt
= filp
->private_data
;
4095 if (cnt
>= sizeof(buf
))
4098 if (copy_from_user(&buf
, ubuf
, cnt
))
4103 ret
= strict_strtoul(buf
, 10, &val
);
4107 if (val
!= 0 && val
!= 1)
4110 if (!!(topt
->flags
->val
& topt
->opt
->bit
) != val
) {
4111 mutex_lock(&trace_types_lock
);
4112 ret
= __set_tracer_option(current_trace
, topt
->flags
,
4114 mutex_unlock(&trace_types_lock
);
4125 static const struct file_operations trace_options_fops
= {
4126 .open
= tracing_open_generic
,
4127 .read
= trace_options_read
,
4128 .write
= trace_options_write
,
4129 .llseek
= generic_file_llseek
,
4133 trace_options_core_read(struct file
*filp
, char __user
*ubuf
, size_t cnt
,
4136 long index
= (long)filp
->private_data
;
4139 if (trace_flags
& (1 << index
))
4144 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, 2);
4148 trace_options_core_write(struct file
*filp
, const char __user
*ubuf
, size_t cnt
,
4151 long index
= (long)filp
->private_data
;
4156 if (cnt
>= sizeof(buf
))
4159 if (copy_from_user(&buf
, ubuf
, cnt
))
4164 ret
= strict_strtoul(buf
, 10, &val
);
4168 if (val
!= 0 && val
!= 1)
4170 set_tracer_flags(1 << index
, val
);
4177 static const struct file_operations trace_options_core_fops
= {
4178 .open
= tracing_open_generic
,
4179 .read
= trace_options_core_read
,
4180 .write
= trace_options_core_write
,
4181 .llseek
= generic_file_llseek
,
4184 struct dentry
*trace_create_file(const char *name
,
4186 struct dentry
*parent
,
4188 const struct file_operations
*fops
)
4192 ret
= debugfs_create_file(name
, mode
, parent
, data
, fops
);
4194 pr_warning("Could not create debugfs '%s' entry\n", name
);
4200 static struct dentry
*trace_options_init_dentry(void)
4202 struct dentry
*d_tracer
;
4203 static struct dentry
*t_options
;
4208 d_tracer
= tracing_init_dentry();
4212 t_options
= debugfs_create_dir("options", d_tracer
);
4214 pr_warning("Could not create debugfs directory 'options'\n");
4222 create_trace_option_file(struct trace_option_dentry
*topt
,
4223 struct tracer_flags
*flags
,
4224 struct tracer_opt
*opt
)
4226 struct dentry
*t_options
;
4228 t_options
= trace_options_init_dentry();
4232 topt
->flags
= flags
;
4235 topt
->entry
= trace_create_file(opt
->name
, 0644, t_options
, topt
,
4236 &trace_options_fops
);
4240 static struct trace_option_dentry
*
4241 create_trace_option_files(struct tracer
*tracer
)
4243 struct trace_option_dentry
*topts
;
4244 struct tracer_flags
*flags
;
4245 struct tracer_opt
*opts
;
4251 flags
= tracer
->flags
;
4253 if (!flags
|| !flags
->opts
)
4258 for (cnt
= 0; opts
[cnt
].name
; cnt
++)
4261 topts
= kcalloc(cnt
+ 1, sizeof(*topts
), GFP_KERNEL
);
4265 for (cnt
= 0; opts
[cnt
].name
; cnt
++)
4266 create_trace_option_file(&topts
[cnt
], flags
,
4273 destroy_trace_option_files(struct trace_option_dentry
*topts
)
4280 for (cnt
= 0; topts
[cnt
].opt
; cnt
++) {
4281 if (topts
[cnt
].entry
)
4282 debugfs_remove(topts
[cnt
].entry
);
4288 static struct dentry
*
4289 create_trace_option_core_file(const char *option
, long index
)
4291 struct dentry
*t_options
;
4293 t_options
= trace_options_init_dentry();
4297 return trace_create_file(option
, 0644, t_options
, (void *)index
,
4298 &trace_options_core_fops
);
4301 static __init
void create_trace_options_dir(void)
4303 struct dentry
*t_options
;
4306 t_options
= trace_options_init_dentry();
4310 for (i
= 0; trace_options
[i
]; i
++)
4311 create_trace_option_core_file(trace_options
[i
], i
);
4314 static __init
int tracer_init_debugfs(void)
4316 struct dentry
*d_tracer
;
4319 trace_access_lock_init();
4321 d_tracer
= tracing_init_dentry();
4323 trace_create_file("tracing_enabled", 0644, d_tracer
,
4324 &global_trace
, &tracing_ctrl_fops
);
4326 trace_create_file("trace_options", 0644, d_tracer
,
4327 NULL
, &tracing_iter_fops
);
4329 trace_create_file("tracing_cpumask", 0644, d_tracer
,
4330 NULL
, &tracing_cpumask_fops
);
4332 trace_create_file("trace", 0644, d_tracer
,
4333 (void *) TRACE_PIPE_ALL_CPU
, &tracing_fops
);
4335 trace_create_file("available_tracers", 0444, d_tracer
,
4336 &global_trace
, &show_traces_fops
);
4338 trace_create_file("current_tracer", 0644, d_tracer
,
4339 &global_trace
, &set_tracer_fops
);
4341 #ifdef CONFIG_TRACER_MAX_TRACE
4342 trace_create_file("tracing_max_latency", 0644, d_tracer
,
4343 &tracing_max_latency
, &tracing_max_lat_fops
);
4346 trace_create_file("tracing_thresh", 0644, d_tracer
,
4347 &tracing_thresh
, &tracing_max_lat_fops
);
4349 trace_create_file("README", 0444, d_tracer
,
4350 NULL
, &tracing_readme_fops
);
4352 trace_create_file("trace_pipe", 0444, d_tracer
,
4353 (void *) TRACE_PIPE_ALL_CPU
, &tracing_pipe_fops
);
4355 trace_create_file("buffer_size_kb", 0644, d_tracer
,
4356 &global_trace
, &tracing_entries_fops
);
4358 trace_create_file("trace_marker", 0220, d_tracer
,
4359 NULL
, &tracing_mark_fops
);
4361 trace_create_file("saved_cmdlines", 0444, d_tracer
,
4362 NULL
, &tracing_saved_cmdlines_fops
);
4364 trace_create_file("trace_clock", 0644, d_tracer
, NULL
,
4367 #ifdef CONFIG_DYNAMIC_FTRACE
4368 trace_create_file("dyn_ftrace_total_info", 0444, d_tracer
,
4369 &ftrace_update_tot_cnt
, &tracing_dyn_info_fops
);
4372 create_trace_options_dir();
4374 for_each_tracing_cpu(cpu
)
4375 tracing_init_debugfs_percpu(cpu
);
4380 static int trace_panic_handler(struct notifier_block
*this,
4381 unsigned long event
, void *unused
)
4383 if (ftrace_dump_on_oops
)
4384 ftrace_dump(ftrace_dump_on_oops
);
4388 static struct notifier_block trace_panic_notifier
= {
4389 .notifier_call
= trace_panic_handler
,
4391 .priority
= 150 /* priority: INT_MAX >= x >= 0 */
4394 static int trace_die_handler(struct notifier_block
*self
,
4400 if (ftrace_dump_on_oops
)
4401 ftrace_dump(ftrace_dump_on_oops
);
4409 static struct notifier_block trace_die_notifier
= {
4410 .notifier_call
= trace_die_handler
,
4415 * printk is set to max of 1024, we really don't need it that big.
4416 * Nothing should be printing 1000 characters anyway.
4418 #define TRACE_MAX_PRINT 1000
4421 * Define here KERN_TRACE so that we have one place to modify
4422 * it if we decide to change what log level the ftrace dump
4425 #define KERN_TRACE KERN_EMERG
4428 trace_printk_seq(struct trace_seq
*s
)
4430 /* Probably should print a warning here. */
4434 /* should be zero ended, but we are paranoid. */
4435 s
->buffer
[s
->len
] = 0;
4437 printk(KERN_TRACE
"%s", s
->buffer
);
4442 void trace_init_global_iter(struct trace_iterator
*iter
)
4444 iter
->tr
= &global_trace
;
4445 iter
->trace
= current_trace
;
4446 iter
->cpu_file
= TRACE_PIPE_ALL_CPU
;
4450 __ftrace_dump(bool disable_tracing
, enum ftrace_dump_mode oops_dump_mode
)
4452 static arch_spinlock_t ftrace_dump_lock
=
4453 (arch_spinlock_t
)__ARCH_SPIN_LOCK_UNLOCKED
;
4454 /* use static because iter can be a bit big for the stack */
4455 static struct trace_iterator iter
;
4456 unsigned int old_userobj
;
4457 static int dump_ran
;
4458 unsigned long flags
;
4462 local_irq_save(flags
);
4463 arch_spin_lock(&ftrace_dump_lock
);
4471 if (disable_tracing
)
4474 trace_init_global_iter(&iter
);
4476 for_each_tracing_cpu(cpu
) {
4477 atomic_inc(&iter
.tr
->data
[cpu
]->disabled
);
4480 old_userobj
= trace_flags
& TRACE_ITER_SYM_USEROBJ
;
4482 /* don't look at user memory in panic mode */
4483 trace_flags
&= ~TRACE_ITER_SYM_USEROBJ
;
4485 /* Simulate the iterator */
4486 iter
.tr
= &global_trace
;
4487 iter
.trace
= current_trace
;
4489 switch (oops_dump_mode
) {
4491 iter
.cpu_file
= TRACE_PIPE_ALL_CPU
;
4494 iter
.cpu_file
= raw_smp_processor_id();
4499 printk(KERN_TRACE
"Bad dumping mode, switching to all CPUs dump\n");
4500 iter
.cpu_file
= TRACE_PIPE_ALL_CPU
;
4503 printk(KERN_TRACE
"Dumping ftrace buffer:\n");
4506 * We need to stop all tracing on all CPUS to read the
4507 * the next buffer. This is a bit expensive, but is
4508 * not done often. We fill all what we can read,
4509 * and then release the locks again.
4512 while (!trace_empty(&iter
)) {
4515 printk(KERN_TRACE
"---------------------------------\n");
4519 /* reset all but tr, trace, and overruns */
4520 memset(&iter
.seq
, 0,
4521 sizeof(struct trace_iterator
) -
4522 offsetof(struct trace_iterator
, seq
));
4523 iter
.iter_flags
|= TRACE_FILE_LAT_FMT
;
4526 if (trace_find_next_entry_inc(&iter
) != NULL
) {
4529 ret
= print_trace_line(&iter
);
4530 if (ret
!= TRACE_TYPE_NO_CONSUME
)
4531 trace_consume(&iter
);
4534 trace_printk_seq(&iter
.seq
);
4538 printk(KERN_TRACE
" (ftrace buffer empty)\n");
4540 printk(KERN_TRACE
"---------------------------------\n");
4543 /* Re-enable tracing if requested */
4544 if (!disable_tracing
) {
4545 trace_flags
|= old_userobj
;
4547 for_each_tracing_cpu(cpu
) {
4548 atomic_dec(&iter
.tr
->data
[cpu
]->disabled
);
4554 arch_spin_unlock(&ftrace_dump_lock
);
4555 local_irq_restore(flags
);
4558 /* By default: disable tracing after the dump */
4559 void ftrace_dump(enum ftrace_dump_mode oops_dump_mode
)
4561 __ftrace_dump(true, oops_dump_mode
);
4564 __init
static int tracer_alloc_buffers(void)
4567 enum ring_buffer_flags rb_flags
;
4572 if (!alloc_cpumask_var(&tracing_buffer_mask
, GFP_KERNEL
))
4575 if (!alloc_cpumask_var(&tracing_cpumask
, GFP_KERNEL
))
4576 goto out_free_buffer_mask
;
4578 /* To save memory, keep the ring buffer size to its minimum */
4579 if (ring_buffer_expanded
)
4580 ring_buf_size
= trace_buf_size
;
4584 rb_flags
= trace_flags
& TRACE_ITER_OVERWRITE
? RB_FL_OVERWRITE
: 0;
4586 cpumask_copy(tracing_buffer_mask
, cpu_possible_mask
);
4587 cpumask_copy(tracing_cpumask
, cpu_all_mask
);
4589 /* TODO: make the number of buffers hot pluggable with CPUS */
4590 global_trace
.buffer
= ring_buffer_alloc(ring_buf_size
, rb_flags
);
4591 if (!global_trace
.buffer
) {
4592 printk(KERN_ERR
"tracer: failed to allocate ring buffer!\n");
4594 goto out_free_cpumask
;
4596 global_trace
.entries
= ring_buffer_size(global_trace
.buffer
);
4599 #ifdef CONFIG_TRACER_MAX_TRACE
4600 max_tr
.buffer
= ring_buffer_alloc(1, rb_flags
);
4601 if (!max_tr
.buffer
) {
4602 printk(KERN_ERR
"tracer: failed to allocate max ring buffer!\n");
4604 ring_buffer_free(global_trace
.buffer
);
4605 goto out_free_cpumask
;
4610 /* Allocate the first page for all buffers */
4611 for_each_tracing_cpu(i
) {
4612 global_trace
.data
[i
] = &per_cpu(global_trace_cpu
, i
);
4613 max_tr
.data
[i
] = &per_cpu(max_tr_data
, i
);
4616 trace_init_cmdlines();
4618 register_tracer(&nop_trace
);
4619 current_trace
= &nop_trace
;
4620 /* All seems OK, enable tracing */
4621 tracing_disabled
= 0;
4623 atomic_notifier_chain_register(&panic_notifier_list
,
4624 &trace_panic_notifier
);
4626 register_die_notifier(&trace_die_notifier
);
4631 free_cpumask_var(tracing_cpumask
);
4632 out_free_buffer_mask
:
4633 free_cpumask_var(tracing_buffer_mask
);
4638 __init
static int clear_boot_tracer(void)
4641 * The default tracer at boot buffer is an init section.
4642 * This function is called in lateinit. If we did not
4643 * find the boot tracer, then clear it out, to prevent
4644 * later registration from accessing the buffer that is
4645 * about to be freed.
4647 if (!default_bootup_tracer
)
4650 printk(KERN_INFO
"ftrace bootup tracer '%s' not registered.\n",
4651 default_bootup_tracer
);
4652 default_bootup_tracer
= NULL
;
4657 early_initcall(tracer_alloc_buffers
);
4658 fs_initcall(tracer_init_debugfs
);
4659 late_initcall(clear_boot_tracer
);