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 Nadia Yvette Chambers
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/irq_work.h>
23 #include <linux/debugfs.h>
24 #include <linux/pagemap.h>
25 #include <linux/hardirq.h>
26 #include <linux/linkage.h>
27 #include <linux/uaccess.h>
28 #include <linux/kprobes.h>
29 #include <linux/ftrace.h>
30 #include <linux/module.h>
31 #include <linux/percpu.h>
32 #include <linux/splice.h>
33 #include <linux/kdebug.h>
34 #include <linux/string.h>
35 #include <linux/rwsem.h>
36 #include <linux/slab.h>
37 #include <linux/ctype.h>
38 #include <linux/init.h>
39 #include <linux/poll.h>
40 #include <linux/nmi.h>
42 #include <linux/sched/rt.h>
45 #include "trace_output.h"
48 * On boot up, the ring buffer is set to the minimum size, so that
49 * we do not waste memory on systems that are not using tracing.
51 int ring_buffer_expanded
;
54 * We need to change this state when a selftest is running.
55 * A selftest will lurk into the ring-buffer to count the
56 * entries inserted during the selftest although some concurrent
57 * insertions into the ring-buffer such as trace_printk could occurred
58 * at the same time, giving false positive or negative results.
60 static bool __read_mostly tracing_selftest_running
;
63 * If a tracer is running, we do not want to run SELFTEST.
65 bool __read_mostly tracing_selftest_disabled
;
67 /* For tracers that don't implement custom flags */
68 static struct tracer_opt dummy_tracer_opt
[] = {
72 static struct tracer_flags dummy_tracer_flags
= {
74 .opts
= dummy_tracer_opt
77 static int dummy_set_flag(u32 old_flags
, u32 bit
, int set
)
83 * To prevent the comm cache from being overwritten when no
84 * tracing is active, only save the comm when a trace event
87 static DEFINE_PER_CPU(bool, trace_cmdline_save
);
90 * When a reader is waiting for data, then this variable is
93 static bool trace_wakeup_needed
;
95 static struct irq_work trace_work_wakeup
;
98 * Kill all tracing for good (never come back).
99 * It is initialized to 1 but will turn to zero if the initialization
100 * of the tracer is successful. But that is the only place that sets
103 static int tracing_disabled
= 1;
105 DEFINE_PER_CPU(int, ftrace_cpu_disabled
);
107 cpumask_var_t __read_mostly tracing_buffer_mask
;
110 * ftrace_dump_on_oops - variable to dump ftrace buffer on oops
112 * If there is an oops (or kernel panic) and the ftrace_dump_on_oops
113 * is set, then ftrace_dump is called. This will output the contents
114 * of the ftrace buffers to the console. This is very useful for
115 * capturing traces that lead to crashes and outputing it to a
118 * It is default off, but you can enable it with either specifying
119 * "ftrace_dump_on_oops" in the kernel command line, or setting
120 * /proc/sys/kernel/ftrace_dump_on_oops
121 * Set 1 if you want to dump buffers of all CPUs
122 * Set 2 if you want to dump the buffer of the CPU that triggered oops
125 enum ftrace_dump_mode ftrace_dump_on_oops
;
127 static int tracing_set_tracer(const char *buf
);
129 #define MAX_TRACER_SIZE 100
130 static char bootup_tracer_buf
[MAX_TRACER_SIZE
] __initdata
;
131 static char *default_bootup_tracer
;
133 static int __init
set_cmdline_ftrace(char *str
)
135 strncpy(bootup_tracer_buf
, str
, MAX_TRACER_SIZE
);
136 default_bootup_tracer
= bootup_tracer_buf
;
137 /* We are using ftrace early, expand it */
138 ring_buffer_expanded
= 1;
141 __setup("ftrace=", set_cmdline_ftrace
);
143 static int __init
set_ftrace_dump_on_oops(char *str
)
145 if (*str
++ != '=' || !*str
) {
146 ftrace_dump_on_oops
= DUMP_ALL
;
150 if (!strcmp("orig_cpu", str
)) {
151 ftrace_dump_on_oops
= DUMP_ORIG
;
157 __setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops
);
160 static char trace_boot_options_buf
[MAX_TRACER_SIZE
] __initdata
;
161 static char *trace_boot_options __initdata
;
163 static int __init
set_trace_boot_options(char *str
)
165 strncpy(trace_boot_options_buf
, str
, MAX_TRACER_SIZE
);
166 trace_boot_options
= trace_boot_options_buf
;
169 __setup("trace_options=", set_trace_boot_options
);
171 unsigned long long ns2usecs(cycle_t nsec
)
179 * The global_trace is the descriptor that holds the tracing
180 * buffers for the live tracing. For each CPU, it contains
181 * a link list of pages that will store trace entries. The
182 * page descriptor of the pages in the memory is used to hold
183 * the link list by linking the lru item in the page descriptor
184 * to each of the pages in the buffer per CPU.
186 * For each active CPU there is a data field that holds the
187 * pages for the buffer for that CPU. Each CPU has the same number
188 * of pages allocated for its buffer.
190 static struct trace_array global_trace
;
192 static DEFINE_PER_CPU(struct trace_array_cpu
, global_trace_cpu
);
194 int filter_current_check_discard(struct ring_buffer
*buffer
,
195 struct ftrace_event_call
*call
, void *rec
,
196 struct ring_buffer_event
*event
)
198 return filter_check_discard(call
, rec
, buffer
, event
);
200 EXPORT_SYMBOL_GPL(filter_current_check_discard
);
202 cycle_t
ftrace_now(int cpu
)
206 /* Early boot up does not have a buffer yet */
207 if (!global_trace
.buffer
)
208 return trace_clock_local();
210 ts
= ring_buffer_time_stamp(global_trace
.buffer
, cpu
);
211 ring_buffer_normalize_time_stamp(global_trace
.buffer
, cpu
, &ts
);
217 * The max_tr is used to snapshot the global_trace when a maximum
218 * latency is reached. Some tracers will use this to store a maximum
219 * trace while it continues examining live traces.
221 * The buffers for the max_tr are set up the same as the global_trace.
222 * When a snapshot is taken, the link list of the max_tr is swapped
223 * with the link list of the global_trace and the buffers are reset for
224 * the global_trace so the tracing can continue.
226 static struct trace_array max_tr
;
228 static DEFINE_PER_CPU(struct trace_array_cpu
, max_tr_data
);
230 int tracing_is_enabled(void)
232 return tracing_is_on();
236 * trace_buf_size is the size in bytes that is allocated
237 * for a buffer. Note, the number of bytes is always rounded
240 * This number is purposely set to a low number of 16384.
241 * If the dump on oops happens, it will be much appreciated
242 * to not have to wait for all that output. Anyway this can be
243 * boot time and run time configurable.
245 #define TRACE_BUF_SIZE_DEFAULT 1441792UL /* 16384 * 88 (sizeof(entry)) */
247 static unsigned long trace_buf_size
= TRACE_BUF_SIZE_DEFAULT
;
249 /* trace_types holds a link list of available tracers. */
250 static struct tracer
*trace_types __read_mostly
;
252 /* current_trace points to the tracer that is currently active */
253 static struct tracer
*current_trace __read_mostly
= &nop_trace
;
256 * trace_types_lock is used to protect the trace_types list.
258 static DEFINE_MUTEX(trace_types_lock
);
261 * serialize the access of the ring buffer
263 * ring buffer serializes readers, but it is low level protection.
264 * The validity of the events (which returns by ring_buffer_peek() ..etc)
265 * are not protected by ring buffer.
267 * The content of events may become garbage if we allow other process consumes
268 * these events concurrently:
269 * A) the page of the consumed events may become a normal page
270 * (not reader page) in ring buffer, and this page will be rewrited
271 * by events producer.
272 * B) The page of the consumed events may become a page for splice_read,
273 * and this page will be returned to system.
275 * These primitives allow multi process access to different cpu ring buffer
278 * These primitives don't distinguish read-only and read-consume access.
279 * Multi read-only access are also serialized.
283 static DECLARE_RWSEM(all_cpu_access_lock
);
284 static DEFINE_PER_CPU(struct mutex
, cpu_access_lock
);
286 static inline void trace_access_lock(int cpu
)
288 if (cpu
== TRACE_PIPE_ALL_CPU
) {
289 /* gain it for accessing the whole ring buffer. */
290 down_write(&all_cpu_access_lock
);
292 /* gain it for accessing a cpu ring buffer. */
294 /* Firstly block other trace_access_lock(TRACE_PIPE_ALL_CPU). */
295 down_read(&all_cpu_access_lock
);
297 /* Secondly block other access to this @cpu ring buffer. */
298 mutex_lock(&per_cpu(cpu_access_lock
, cpu
));
302 static inline void trace_access_unlock(int cpu
)
304 if (cpu
== TRACE_PIPE_ALL_CPU
) {
305 up_write(&all_cpu_access_lock
);
307 mutex_unlock(&per_cpu(cpu_access_lock
, cpu
));
308 up_read(&all_cpu_access_lock
);
312 static inline void trace_access_lock_init(void)
316 for_each_possible_cpu(cpu
)
317 mutex_init(&per_cpu(cpu_access_lock
, cpu
));
322 static DEFINE_MUTEX(access_lock
);
324 static inline void trace_access_lock(int cpu
)
327 mutex_lock(&access_lock
);
330 static inline void trace_access_unlock(int cpu
)
333 mutex_unlock(&access_lock
);
336 static inline void trace_access_lock_init(void)
342 /* trace_wait is a waitqueue for tasks blocked on trace_poll */
343 static DECLARE_WAIT_QUEUE_HEAD(trace_wait
);
345 /* trace_flags holds trace_options default values */
346 unsigned long trace_flags
= TRACE_ITER_PRINT_PARENT
| TRACE_ITER_PRINTK
|
347 TRACE_ITER_ANNOTATE
| TRACE_ITER_CONTEXT_INFO
| TRACE_ITER_SLEEP_TIME
|
348 TRACE_ITER_GRAPH_TIME
| TRACE_ITER_RECORD_CMD
| TRACE_ITER_OVERWRITE
|
349 TRACE_ITER_IRQ_INFO
| TRACE_ITER_MARKERS
;
351 static int trace_stop_count
;
352 static DEFINE_RAW_SPINLOCK(tracing_start_lock
);
355 * trace_wake_up - wake up tasks waiting for trace input
357 * Schedules a delayed work to wake up any task that is blocked on the
358 * trace_wait queue. These is used with trace_poll for tasks polling the
361 static void trace_wake_up(struct irq_work
*work
)
363 wake_up_all(&trace_wait
);
368 * tracing_on - enable tracing buffers
370 * This function enables tracing buffers that may have been
371 * disabled with tracing_off.
373 void tracing_on(void)
375 if (global_trace
.buffer
)
376 ring_buffer_record_on(global_trace
.buffer
);
378 * This flag is only looked at when buffers haven't been
379 * allocated yet. We don't really care about the race
380 * between setting this flag and actually turning
383 global_trace
.buffer_disabled
= 0;
385 EXPORT_SYMBOL_GPL(tracing_on
);
388 * tracing_off - turn off tracing buffers
390 * This function stops the tracing buffers from recording data.
391 * It does not disable any overhead the tracers themselves may
392 * be causing. This function simply causes all recording to
393 * the ring buffers to fail.
395 void tracing_off(void)
397 if (global_trace
.buffer
)
398 ring_buffer_record_off(global_trace
.buffer
);
400 * This flag is only looked at when buffers haven't been
401 * allocated yet. We don't really care about the race
402 * between setting this flag and actually turning
405 global_trace
.buffer_disabled
= 1;
407 EXPORT_SYMBOL_GPL(tracing_off
);
410 * tracing_is_on - show state of ring buffers enabled
412 int tracing_is_on(void)
414 if (global_trace
.buffer
)
415 return ring_buffer_record_is_on(global_trace
.buffer
);
416 return !global_trace
.buffer_disabled
;
418 EXPORT_SYMBOL_GPL(tracing_is_on
);
420 static int __init
set_buf_size(char *str
)
422 unsigned long buf_size
;
426 buf_size
= memparse(str
, &str
);
427 /* nr_entries can not be zero */
430 trace_buf_size
= buf_size
;
433 __setup("trace_buf_size=", set_buf_size
);
435 static int __init
set_tracing_thresh(char *str
)
437 unsigned long threshold
;
442 ret
= kstrtoul(str
, 0, &threshold
);
445 tracing_thresh
= threshold
* 1000;
448 __setup("tracing_thresh=", set_tracing_thresh
);
450 unsigned long nsecs_to_usecs(unsigned long nsecs
)
455 /* These must match the bit postions in trace_iterator_flags */
456 static const char *trace_options
[] = {
488 int in_ns
; /* is this clock in nanoseconds? */
490 { trace_clock_local
, "local", 1 },
491 { trace_clock_global
, "global", 1 },
492 { trace_clock_counter
, "counter", 0 },
499 * trace_parser_get_init - gets the buffer for trace parser
501 int trace_parser_get_init(struct trace_parser
*parser
, int size
)
503 memset(parser
, 0, sizeof(*parser
));
505 parser
->buffer
= kmalloc(size
, GFP_KERNEL
);
514 * trace_parser_put - frees the buffer for trace parser
516 void trace_parser_put(struct trace_parser
*parser
)
518 kfree(parser
->buffer
);
522 * trace_get_user - reads the user input string separated by space
523 * (matched by isspace(ch))
525 * For each string found the 'struct trace_parser' is updated,
526 * and the function returns.
528 * Returns number of bytes read.
530 * See kernel/trace/trace.h for 'struct trace_parser' details.
532 int trace_get_user(struct trace_parser
*parser
, const char __user
*ubuf
,
533 size_t cnt
, loff_t
*ppos
)
540 trace_parser_clear(parser
);
542 ret
= get_user(ch
, ubuf
++);
550 * The parser is not finished with the last write,
551 * continue reading the user input without skipping spaces.
554 /* skip white space */
555 while (cnt
&& isspace(ch
)) {
556 ret
= get_user(ch
, ubuf
++);
563 /* only spaces were written */
573 /* read the non-space input */
574 while (cnt
&& !isspace(ch
)) {
575 if (parser
->idx
< parser
->size
- 1)
576 parser
->buffer
[parser
->idx
++] = ch
;
581 ret
= get_user(ch
, ubuf
++);
588 /* We either got finished input or we have to wait for another call. */
590 parser
->buffer
[parser
->idx
] = 0;
591 parser
->cont
= false;
594 parser
->buffer
[parser
->idx
++] = ch
;
604 ssize_t
trace_seq_to_user(struct trace_seq
*s
, char __user
*ubuf
, size_t cnt
)
612 if (s
->len
<= s
->readpos
)
615 len
= s
->len
- s
->readpos
;
618 ret
= copy_to_user(ubuf
, s
->buffer
+ s
->readpos
, cnt
);
628 static ssize_t
trace_seq_to_buffer(struct trace_seq
*s
, void *buf
, size_t cnt
)
632 if (s
->len
<= s
->readpos
)
635 len
= s
->len
- s
->readpos
;
638 memcpy(buf
, s
->buffer
+ s
->readpos
, cnt
);
645 * ftrace_max_lock is used to protect the swapping of buffers
646 * when taking a max snapshot. The buffers themselves are
647 * protected by per_cpu spinlocks. But the action of the swap
648 * needs its own lock.
650 * This is defined as a arch_spinlock_t in order to help
651 * with performance when lockdep debugging is enabled.
653 * It is also used in other places outside the update_max_tr
654 * so it needs to be defined outside of the
655 * CONFIG_TRACER_MAX_TRACE.
657 static arch_spinlock_t ftrace_max_lock
=
658 (arch_spinlock_t
)__ARCH_SPIN_LOCK_UNLOCKED
;
660 unsigned long __read_mostly tracing_thresh
;
662 #ifdef CONFIG_TRACER_MAX_TRACE
663 unsigned long __read_mostly tracing_max_latency
;
666 * Copy the new maximum trace into the separate maximum-trace
667 * structure. (this way the maximum trace is permanently saved,
668 * for later retrieval via /sys/kernel/debug/tracing/latency_trace)
671 __update_max_tr(struct trace_array
*tr
, struct task_struct
*tsk
, int cpu
)
673 struct trace_array_cpu
*data
= tr
->data
[cpu
];
674 struct trace_array_cpu
*max_data
;
677 max_tr
.time_start
= data
->preempt_timestamp
;
679 max_data
= max_tr
.data
[cpu
];
680 max_data
->saved_latency
= tracing_max_latency
;
681 max_data
->critical_start
= data
->critical_start
;
682 max_data
->critical_end
= data
->critical_end
;
684 memcpy(max_data
->comm
, tsk
->comm
, TASK_COMM_LEN
);
685 max_data
->pid
= tsk
->pid
;
686 max_data
->uid
= task_uid(tsk
);
687 max_data
->nice
= tsk
->static_prio
- 20 - MAX_RT_PRIO
;
688 max_data
->policy
= tsk
->policy
;
689 max_data
->rt_priority
= tsk
->rt_priority
;
691 /* record this tasks comm */
692 tracing_record_cmdline(tsk
);
696 * update_max_tr - snapshot all trace buffers from global_trace to max_tr
698 * @tsk: the task with the latency
699 * @cpu: The cpu that initiated the trace.
701 * Flip the buffers between the @tr and the max_tr and record information
702 * about which task was the cause of this latency.
705 update_max_tr(struct trace_array
*tr
, struct task_struct
*tsk
, int cpu
)
707 struct ring_buffer
*buf
;
709 if (trace_stop_count
)
712 WARN_ON_ONCE(!irqs_disabled());
714 if (!current_trace
->allocated_snapshot
) {
715 /* Only the nop tracer should hit this when disabling */
716 WARN_ON_ONCE(current_trace
!= &nop_trace
);
720 arch_spin_lock(&ftrace_max_lock
);
723 tr
->buffer
= max_tr
.buffer
;
726 __update_max_tr(tr
, tsk
, cpu
);
727 arch_spin_unlock(&ftrace_max_lock
);
731 * update_max_tr_single - only copy one trace over, and reset the rest
733 * @tsk - task with the latency
734 * @cpu - the cpu of the buffer to copy.
736 * Flip the trace of a single CPU buffer between the @tr and the max_tr.
739 update_max_tr_single(struct trace_array
*tr
, struct task_struct
*tsk
, int cpu
)
743 if (trace_stop_count
)
746 WARN_ON_ONCE(!irqs_disabled());
747 if (WARN_ON_ONCE(!current_trace
->allocated_snapshot
))
750 arch_spin_lock(&ftrace_max_lock
);
752 ret
= ring_buffer_swap_cpu(max_tr
.buffer
, tr
->buffer
, cpu
);
756 * We failed to swap the buffer due to a commit taking
757 * place on this CPU. We fail to record, but we reset
758 * the max trace buffer (no one writes directly to it)
759 * and flag that it failed.
761 trace_array_printk(&max_tr
, _THIS_IP_
,
762 "Failed to swap buffers due to commit in progress\n");
765 WARN_ON_ONCE(ret
&& ret
!= -EAGAIN
&& ret
!= -EBUSY
);
767 __update_max_tr(tr
, tsk
, cpu
);
768 arch_spin_unlock(&ftrace_max_lock
);
770 #endif /* CONFIG_TRACER_MAX_TRACE */
772 static void default_wait_pipe(struct trace_iterator
*iter
)
776 prepare_to_wait(&trace_wait
, &wait
, TASK_INTERRUPTIBLE
);
779 * The events can happen in critical sections where
780 * checking a work queue can cause deadlocks.
781 * After adding a task to the queue, this flag is set
782 * only to notify events to try to wake up the queue
785 * We don't clear it even if the buffer is no longer
786 * empty. The flag only causes the next event to run
787 * irq_work to do the work queue wake up. The worse
788 * that can happen if we race with !trace_empty() is that
789 * an event will cause an irq_work to try to wake up
792 * There's no reason to protect this flag either, as
793 * the work queue and irq_work logic will do the necessary
794 * synchronization for the wake ups. The only thing
795 * that is necessary is that the wake up happens after
796 * a task has been queued. It's OK for spurious wake ups.
798 trace_wakeup_needed
= true;
800 if (trace_empty(iter
))
803 finish_wait(&trace_wait
, &wait
);
807 * register_tracer - register a tracer with the ftrace system.
808 * @type - the plugin for the tracer
810 * Register a new plugin tracer.
812 int register_tracer(struct tracer
*type
)
818 pr_info("Tracer must have a name\n");
822 if (strlen(type
->name
) >= MAX_TRACER_SIZE
) {
823 pr_info("Tracer has a name longer than %d\n", MAX_TRACER_SIZE
);
827 mutex_lock(&trace_types_lock
);
829 tracing_selftest_running
= true;
831 for (t
= trace_types
; t
; t
= t
->next
) {
832 if (strcmp(type
->name
, t
->name
) == 0) {
834 pr_info("Tracer %s already registered\n",
842 type
->set_flag
= &dummy_set_flag
;
844 type
->flags
= &dummy_tracer_flags
;
846 if (!type
->flags
->opts
)
847 type
->flags
->opts
= dummy_tracer_opt
;
848 if (!type
->wait_pipe
)
849 type
->wait_pipe
= default_wait_pipe
;
852 #ifdef CONFIG_FTRACE_STARTUP_TEST
853 if (type
->selftest
&& !tracing_selftest_disabled
) {
854 struct tracer
*saved_tracer
= current_trace
;
855 struct trace_array
*tr
= &global_trace
;
858 * Run a selftest on this tracer.
859 * Here we reset the trace buffer, and set the current
860 * tracer to be this tracer. The tracer can then run some
861 * internal tracing to verify that everything is in order.
862 * If we fail, we do not register this tracer.
864 tracing_reset_online_cpus(tr
);
866 current_trace
= type
;
868 if (type
->use_max_tr
) {
869 /* If we expanded the buffers, make sure the max is expanded too */
870 if (ring_buffer_expanded
)
871 ring_buffer_resize(max_tr
.buffer
, trace_buf_size
,
872 RING_BUFFER_ALL_CPUS
);
873 type
->allocated_snapshot
= true;
876 /* the test is responsible for initializing and enabling */
877 pr_info("Testing tracer %s: ", type
->name
);
878 ret
= type
->selftest(type
, tr
);
879 /* the test is responsible for resetting too */
880 current_trace
= saved_tracer
;
882 printk(KERN_CONT
"FAILED!\n");
883 /* Add the warning after printing 'FAILED' */
887 /* Only reset on passing, to avoid touching corrupted buffers */
888 tracing_reset_online_cpus(tr
);
890 if (type
->use_max_tr
) {
891 type
->allocated_snapshot
= false;
893 /* Shrink the max buffer again */
894 if (ring_buffer_expanded
)
895 ring_buffer_resize(max_tr
.buffer
, 1,
896 RING_BUFFER_ALL_CPUS
);
899 printk(KERN_CONT
"PASSED\n");
903 type
->next
= trace_types
;
907 tracing_selftest_running
= false;
908 mutex_unlock(&trace_types_lock
);
910 if (ret
|| !default_bootup_tracer
)
913 if (strncmp(default_bootup_tracer
, type
->name
, MAX_TRACER_SIZE
))
916 printk(KERN_INFO
"Starting tracer '%s'\n", type
->name
);
917 /* Do we want this tracer to start on bootup? */
918 tracing_set_tracer(type
->name
);
919 default_bootup_tracer
= NULL
;
920 /* disable other selftests, since this will break it. */
921 tracing_selftest_disabled
= 1;
922 #ifdef CONFIG_FTRACE_STARTUP_TEST
923 printk(KERN_INFO
"Disabling FTRACE selftests due to running tracer '%s'\n",
931 void tracing_reset(struct trace_array
*tr
, int cpu
)
933 struct ring_buffer
*buffer
= tr
->buffer
;
938 ring_buffer_record_disable(buffer
);
940 /* Make sure all commits have finished */
942 ring_buffer_reset_cpu(buffer
, cpu
);
944 ring_buffer_record_enable(buffer
);
947 void tracing_reset_online_cpus(struct trace_array
*tr
)
949 struct ring_buffer
*buffer
= tr
->buffer
;
955 ring_buffer_record_disable(buffer
);
957 /* Make sure all commits have finished */
960 tr
->time_start
= ftrace_now(tr
->cpu
);
962 for_each_online_cpu(cpu
)
963 ring_buffer_reset_cpu(buffer
, cpu
);
965 ring_buffer_record_enable(buffer
);
968 void tracing_reset_current(int cpu
)
970 tracing_reset(&global_trace
, cpu
);
973 void tracing_reset_current_online_cpus(void)
975 tracing_reset_online_cpus(&global_trace
);
978 #define SAVED_CMDLINES 128
979 #define NO_CMDLINE_MAP UINT_MAX
980 static unsigned map_pid_to_cmdline
[PID_MAX_DEFAULT
+1];
981 static unsigned map_cmdline_to_pid
[SAVED_CMDLINES
];
982 static char saved_cmdlines
[SAVED_CMDLINES
][TASK_COMM_LEN
];
983 static int cmdline_idx
;
984 static arch_spinlock_t trace_cmdline_lock
= __ARCH_SPIN_LOCK_UNLOCKED
;
986 /* temporary disable recording */
987 static atomic_t trace_record_cmdline_disabled __read_mostly
;
989 static void trace_init_cmdlines(void)
991 memset(&map_pid_to_cmdline
, NO_CMDLINE_MAP
, sizeof(map_pid_to_cmdline
));
992 memset(&map_cmdline_to_pid
, NO_CMDLINE_MAP
, sizeof(map_cmdline_to_pid
));
996 int is_tracing_stopped(void)
998 return trace_stop_count
;
1002 * ftrace_off_permanent - disable all ftrace code permanently
1004 * This should only be called when a serious anomally has
1005 * been detected. This will turn off the function tracing,
1006 * ring buffers, and other tracing utilites. It takes no
1007 * locks and can be called from any context.
1009 void ftrace_off_permanent(void)
1011 tracing_disabled
= 1;
1013 tracing_off_permanent();
1017 * tracing_start - quick start of the tracer
1019 * If tracing is enabled but was stopped by tracing_stop,
1020 * this will start the tracer back up.
1022 void tracing_start(void)
1024 struct ring_buffer
*buffer
;
1025 unsigned long flags
;
1027 if (tracing_disabled
)
1030 raw_spin_lock_irqsave(&tracing_start_lock
, flags
);
1031 if (--trace_stop_count
) {
1032 if (trace_stop_count
< 0) {
1033 /* Someone screwed up their debugging */
1035 trace_stop_count
= 0;
1040 /* Prevent the buffers from switching */
1041 arch_spin_lock(&ftrace_max_lock
);
1043 buffer
= global_trace
.buffer
;
1045 ring_buffer_record_enable(buffer
);
1047 buffer
= max_tr
.buffer
;
1049 ring_buffer_record_enable(buffer
);
1051 arch_spin_unlock(&ftrace_max_lock
);
1055 raw_spin_unlock_irqrestore(&tracing_start_lock
, flags
);
1059 * tracing_stop - quick stop of the tracer
1061 * Light weight way to stop tracing. Use in conjunction with
1064 void tracing_stop(void)
1066 struct ring_buffer
*buffer
;
1067 unsigned long flags
;
1070 raw_spin_lock_irqsave(&tracing_start_lock
, flags
);
1071 if (trace_stop_count
++)
1074 /* Prevent the buffers from switching */
1075 arch_spin_lock(&ftrace_max_lock
);
1077 buffer
= global_trace
.buffer
;
1079 ring_buffer_record_disable(buffer
);
1081 buffer
= max_tr
.buffer
;
1083 ring_buffer_record_disable(buffer
);
1085 arch_spin_unlock(&ftrace_max_lock
);
1088 raw_spin_unlock_irqrestore(&tracing_start_lock
, flags
);
1091 void trace_stop_cmdline_recording(void);
1093 static void trace_save_cmdline(struct task_struct
*tsk
)
1097 if (!tsk
->pid
|| unlikely(tsk
->pid
> PID_MAX_DEFAULT
))
1101 * It's not the end of the world if we don't get
1102 * the lock, but we also don't want to spin
1103 * nor do we want to disable interrupts,
1104 * so if we miss here, then better luck next time.
1106 if (!arch_spin_trylock(&trace_cmdline_lock
))
1109 idx
= map_pid_to_cmdline
[tsk
->pid
];
1110 if (idx
== NO_CMDLINE_MAP
) {
1111 idx
= (cmdline_idx
+ 1) % SAVED_CMDLINES
;
1114 * Check whether the cmdline buffer at idx has a pid
1115 * mapped. We are going to overwrite that entry so we
1116 * need to clear the map_pid_to_cmdline. Otherwise we
1117 * would read the new comm for the old pid.
1119 pid
= map_cmdline_to_pid
[idx
];
1120 if (pid
!= NO_CMDLINE_MAP
)
1121 map_pid_to_cmdline
[pid
] = NO_CMDLINE_MAP
;
1123 map_cmdline_to_pid
[idx
] = tsk
->pid
;
1124 map_pid_to_cmdline
[tsk
->pid
] = idx
;
1129 memcpy(&saved_cmdlines
[idx
], tsk
->comm
, TASK_COMM_LEN
);
1131 arch_spin_unlock(&trace_cmdline_lock
);
1134 void trace_find_cmdline(int pid
, char comm
[])
1139 strcpy(comm
, "<idle>");
1143 if (WARN_ON_ONCE(pid
< 0)) {
1144 strcpy(comm
, "<XXX>");
1148 if (pid
> PID_MAX_DEFAULT
) {
1149 strcpy(comm
, "<...>");
1154 arch_spin_lock(&trace_cmdline_lock
);
1155 map
= map_pid_to_cmdline
[pid
];
1156 if (map
!= NO_CMDLINE_MAP
)
1157 strcpy(comm
, saved_cmdlines
[map
]);
1159 strcpy(comm
, "<...>");
1161 arch_spin_unlock(&trace_cmdline_lock
);
1165 void tracing_record_cmdline(struct task_struct
*tsk
)
1167 if (atomic_read(&trace_record_cmdline_disabled
) || !tracing_is_on())
1170 if (!__this_cpu_read(trace_cmdline_save
))
1173 __this_cpu_write(trace_cmdline_save
, false);
1175 trace_save_cmdline(tsk
);
1179 tracing_generic_entry_update(struct trace_entry
*entry
, unsigned long flags
,
1182 struct task_struct
*tsk
= current
;
1184 entry
->preempt_count
= pc
& 0xff;
1185 entry
->pid
= (tsk
) ? tsk
->pid
: 0;
1187 #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
1188 (irqs_disabled_flags(flags
) ? TRACE_FLAG_IRQS_OFF
: 0) |
1190 TRACE_FLAG_IRQS_NOSUPPORT
|
1192 ((pc
& HARDIRQ_MASK
) ? TRACE_FLAG_HARDIRQ
: 0) |
1193 ((pc
& SOFTIRQ_MASK
) ? TRACE_FLAG_SOFTIRQ
: 0) |
1194 (need_resched() ? TRACE_FLAG_NEED_RESCHED
: 0);
1196 EXPORT_SYMBOL_GPL(tracing_generic_entry_update
);
1198 struct ring_buffer_event
*
1199 trace_buffer_lock_reserve(struct ring_buffer
*buffer
,
1202 unsigned long flags
, int pc
)
1204 struct ring_buffer_event
*event
;
1206 event
= ring_buffer_lock_reserve(buffer
, len
);
1207 if (event
!= NULL
) {
1208 struct trace_entry
*ent
= ring_buffer_event_data(event
);
1210 tracing_generic_entry_update(ent
, flags
, pc
);
1218 __buffer_unlock_commit(struct ring_buffer
*buffer
, struct ring_buffer_event
*event
)
1220 __this_cpu_write(trace_cmdline_save
, true);
1221 if (trace_wakeup_needed
) {
1222 trace_wakeup_needed
= false;
1223 /* irq_work_queue() supplies it's own memory barriers */
1224 irq_work_queue(&trace_work_wakeup
);
1226 ring_buffer_unlock_commit(buffer
, event
);
1230 __trace_buffer_unlock_commit(struct ring_buffer
*buffer
,
1231 struct ring_buffer_event
*event
,
1232 unsigned long flags
, int pc
)
1234 __buffer_unlock_commit(buffer
, event
);
1236 ftrace_trace_stack(buffer
, flags
, 6, pc
);
1237 ftrace_trace_userstack(buffer
, flags
, pc
);
1240 void trace_buffer_unlock_commit(struct ring_buffer
*buffer
,
1241 struct ring_buffer_event
*event
,
1242 unsigned long flags
, int pc
)
1244 __trace_buffer_unlock_commit(buffer
, event
, flags
, pc
);
1246 EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit
);
1248 struct ring_buffer_event
*
1249 trace_current_buffer_lock_reserve(struct ring_buffer
**current_rb
,
1250 int type
, unsigned long len
,
1251 unsigned long flags
, int pc
)
1253 *current_rb
= global_trace
.buffer
;
1254 return trace_buffer_lock_reserve(*current_rb
,
1255 type
, len
, flags
, pc
);
1257 EXPORT_SYMBOL_GPL(trace_current_buffer_lock_reserve
);
1259 void trace_current_buffer_unlock_commit(struct ring_buffer
*buffer
,
1260 struct ring_buffer_event
*event
,
1261 unsigned long flags
, int pc
)
1263 __trace_buffer_unlock_commit(buffer
, event
, flags
, pc
);
1265 EXPORT_SYMBOL_GPL(trace_current_buffer_unlock_commit
);
1267 void trace_buffer_unlock_commit_regs(struct ring_buffer
*buffer
,
1268 struct ring_buffer_event
*event
,
1269 unsigned long flags
, int pc
,
1270 struct pt_regs
*regs
)
1272 __buffer_unlock_commit(buffer
, event
);
1274 ftrace_trace_stack_regs(buffer
, flags
, 0, pc
, regs
);
1275 ftrace_trace_userstack(buffer
, flags
, pc
);
1277 EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit_regs
);
1279 void trace_current_buffer_discard_commit(struct ring_buffer
*buffer
,
1280 struct ring_buffer_event
*event
)
1282 ring_buffer_discard_commit(buffer
, event
);
1284 EXPORT_SYMBOL_GPL(trace_current_buffer_discard_commit
);
1287 trace_function(struct trace_array
*tr
,
1288 unsigned long ip
, unsigned long parent_ip
, unsigned long flags
,
1291 struct ftrace_event_call
*call
= &event_function
;
1292 struct ring_buffer
*buffer
= tr
->buffer
;
1293 struct ring_buffer_event
*event
;
1294 struct ftrace_entry
*entry
;
1296 /* If we are reading the ring buffer, don't trace */
1297 if (unlikely(__this_cpu_read(ftrace_cpu_disabled
)))
1300 event
= trace_buffer_lock_reserve(buffer
, TRACE_FN
, sizeof(*entry
),
1304 entry
= ring_buffer_event_data(event
);
1306 entry
->parent_ip
= parent_ip
;
1308 if (!filter_check_discard(call
, entry
, buffer
, event
))
1309 __buffer_unlock_commit(buffer
, event
);
1313 ftrace(struct trace_array
*tr
, struct trace_array_cpu
*data
,
1314 unsigned long ip
, unsigned long parent_ip
, unsigned long flags
,
1317 if (likely(!atomic_read(&data
->disabled
)))
1318 trace_function(tr
, ip
, parent_ip
, flags
, pc
);
1321 #ifdef CONFIG_STACKTRACE
1323 #define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long))
1324 struct ftrace_stack
{
1325 unsigned long calls
[FTRACE_STACK_MAX_ENTRIES
];
1328 static DEFINE_PER_CPU(struct ftrace_stack
, ftrace_stack
);
1329 static DEFINE_PER_CPU(int, ftrace_stack_reserve
);
1331 static void __ftrace_trace_stack(struct ring_buffer
*buffer
,
1332 unsigned long flags
,
1333 int skip
, int pc
, struct pt_regs
*regs
)
1335 struct ftrace_event_call
*call
= &event_kernel_stack
;
1336 struct ring_buffer_event
*event
;
1337 struct stack_entry
*entry
;
1338 struct stack_trace trace
;
1340 int size
= FTRACE_STACK_ENTRIES
;
1342 trace
.nr_entries
= 0;
1346 * Since events can happen in NMIs there's no safe way to
1347 * use the per cpu ftrace_stacks. We reserve it and if an interrupt
1348 * or NMI comes in, it will just have to use the default
1349 * FTRACE_STACK_SIZE.
1351 preempt_disable_notrace();
1353 use_stack
= __this_cpu_inc_return(ftrace_stack_reserve
);
1355 * We don't need any atomic variables, just a barrier.
1356 * If an interrupt comes in, we don't care, because it would
1357 * have exited and put the counter back to what we want.
1358 * We just need a barrier to keep gcc from moving things
1362 if (use_stack
== 1) {
1363 trace
.entries
= &__get_cpu_var(ftrace_stack
).calls
[0];
1364 trace
.max_entries
= FTRACE_STACK_MAX_ENTRIES
;
1367 save_stack_trace_regs(regs
, &trace
);
1369 save_stack_trace(&trace
);
1371 if (trace
.nr_entries
> size
)
1372 size
= trace
.nr_entries
;
1374 /* From now on, use_stack is a boolean */
1377 size
*= sizeof(unsigned long);
1379 event
= trace_buffer_lock_reserve(buffer
, TRACE_STACK
,
1380 sizeof(*entry
) + size
, flags
, pc
);
1383 entry
= ring_buffer_event_data(event
);
1385 memset(&entry
->caller
, 0, size
);
1388 memcpy(&entry
->caller
, trace
.entries
,
1389 trace
.nr_entries
* sizeof(unsigned long));
1391 trace
.max_entries
= FTRACE_STACK_ENTRIES
;
1392 trace
.entries
= entry
->caller
;
1394 save_stack_trace_regs(regs
, &trace
);
1396 save_stack_trace(&trace
);
1399 entry
->size
= trace
.nr_entries
;
1401 if (!filter_check_discard(call
, entry
, buffer
, event
))
1402 __buffer_unlock_commit(buffer
, event
);
1405 /* Again, don't let gcc optimize things here */
1407 __this_cpu_dec(ftrace_stack_reserve
);
1408 preempt_enable_notrace();
1412 void ftrace_trace_stack_regs(struct ring_buffer
*buffer
, unsigned long flags
,
1413 int skip
, int pc
, struct pt_regs
*regs
)
1415 if (!(trace_flags
& TRACE_ITER_STACKTRACE
))
1418 __ftrace_trace_stack(buffer
, flags
, skip
, pc
, regs
);
1421 void ftrace_trace_stack(struct ring_buffer
*buffer
, unsigned long flags
,
1424 if (!(trace_flags
& TRACE_ITER_STACKTRACE
))
1427 __ftrace_trace_stack(buffer
, flags
, skip
, pc
, NULL
);
1430 void __trace_stack(struct trace_array
*tr
, unsigned long flags
, int skip
,
1433 __ftrace_trace_stack(tr
->buffer
, flags
, skip
, pc
, NULL
);
1437 * trace_dump_stack - record a stack back trace in the trace buffer
1439 void trace_dump_stack(void)
1441 unsigned long flags
;
1443 if (tracing_disabled
|| tracing_selftest_running
)
1446 local_save_flags(flags
);
1448 /* skipping 3 traces, seems to get us at the caller of this function */
1449 __ftrace_trace_stack(global_trace
.buffer
, flags
, 3, preempt_count(), NULL
);
1452 static DEFINE_PER_CPU(int, user_stack_count
);
1455 ftrace_trace_userstack(struct ring_buffer
*buffer
, unsigned long flags
, int pc
)
1457 struct ftrace_event_call
*call
= &event_user_stack
;
1458 struct ring_buffer_event
*event
;
1459 struct userstack_entry
*entry
;
1460 struct stack_trace trace
;
1462 if (!(trace_flags
& TRACE_ITER_USERSTACKTRACE
))
1466 * NMIs can not handle page faults, even with fix ups.
1467 * The save user stack can (and often does) fault.
1469 if (unlikely(in_nmi()))
1473 * prevent recursion, since the user stack tracing may
1474 * trigger other kernel events.
1477 if (__this_cpu_read(user_stack_count
))
1480 __this_cpu_inc(user_stack_count
);
1482 event
= trace_buffer_lock_reserve(buffer
, TRACE_USER_STACK
,
1483 sizeof(*entry
), flags
, pc
);
1485 goto out_drop_count
;
1486 entry
= ring_buffer_event_data(event
);
1488 entry
->tgid
= current
->tgid
;
1489 memset(&entry
->caller
, 0, sizeof(entry
->caller
));
1491 trace
.nr_entries
= 0;
1492 trace
.max_entries
= FTRACE_STACK_ENTRIES
;
1494 trace
.entries
= entry
->caller
;
1496 save_stack_trace_user(&trace
);
1497 if (!filter_check_discard(call
, entry
, buffer
, event
))
1498 __buffer_unlock_commit(buffer
, event
);
1501 __this_cpu_dec(user_stack_count
);
1507 static void __trace_userstack(struct trace_array
*tr
, unsigned long flags
)
1509 ftrace_trace_userstack(tr
, flags
, preempt_count());
1513 #endif /* CONFIG_STACKTRACE */
1515 /* created for use with alloc_percpu */
1516 struct trace_buffer_struct
{
1517 char buffer
[TRACE_BUF_SIZE
];
1520 static struct trace_buffer_struct
*trace_percpu_buffer
;
1521 static struct trace_buffer_struct
*trace_percpu_sirq_buffer
;
1522 static struct trace_buffer_struct
*trace_percpu_irq_buffer
;
1523 static struct trace_buffer_struct
*trace_percpu_nmi_buffer
;
1526 * The buffer used is dependent on the context. There is a per cpu
1527 * buffer for normal context, softirq contex, hard irq context and
1528 * for NMI context. Thise allows for lockless recording.
1530 * Note, if the buffers failed to be allocated, then this returns NULL
1532 static char *get_trace_buf(void)
1534 struct trace_buffer_struct
*percpu_buffer
;
1537 * If we have allocated per cpu buffers, then we do not
1538 * need to do any locking.
1541 percpu_buffer
= trace_percpu_nmi_buffer
;
1543 percpu_buffer
= trace_percpu_irq_buffer
;
1544 else if (in_softirq())
1545 percpu_buffer
= trace_percpu_sirq_buffer
;
1547 percpu_buffer
= trace_percpu_buffer
;
1552 return this_cpu_ptr(&percpu_buffer
->buffer
[0]);
1555 static int alloc_percpu_trace_buffer(void)
1557 struct trace_buffer_struct
*buffers
;
1558 struct trace_buffer_struct
*sirq_buffers
;
1559 struct trace_buffer_struct
*irq_buffers
;
1560 struct trace_buffer_struct
*nmi_buffers
;
1562 buffers
= alloc_percpu(struct trace_buffer_struct
);
1566 sirq_buffers
= alloc_percpu(struct trace_buffer_struct
);
1570 irq_buffers
= alloc_percpu(struct trace_buffer_struct
);
1574 nmi_buffers
= alloc_percpu(struct trace_buffer_struct
);
1578 trace_percpu_buffer
= buffers
;
1579 trace_percpu_sirq_buffer
= sirq_buffers
;
1580 trace_percpu_irq_buffer
= irq_buffers
;
1581 trace_percpu_nmi_buffer
= nmi_buffers
;
1586 free_percpu(irq_buffers
);
1588 free_percpu(sirq_buffers
);
1590 free_percpu(buffers
);
1592 WARN(1, "Could not allocate percpu trace_printk buffer");
1596 static int buffers_allocated
;
1598 void trace_printk_init_buffers(void)
1600 if (buffers_allocated
)
1603 if (alloc_percpu_trace_buffer())
1606 pr_info("ftrace: Allocated trace_printk buffers\n");
1608 /* Expand the buffers to set size */
1609 tracing_update_buffers();
1611 buffers_allocated
= 1;
1614 * trace_printk_init_buffers() can be called by modules.
1615 * If that happens, then we need to start cmdline recording
1616 * directly here. If the global_trace.buffer is already
1617 * allocated here, then this was called by module code.
1619 if (global_trace
.buffer
)
1620 tracing_start_cmdline_record();
1623 void trace_printk_start_comm(void)
1625 /* Start tracing comms if trace printk is set */
1626 if (!buffers_allocated
)
1628 tracing_start_cmdline_record();
1631 static void trace_printk_start_stop_comm(int enabled
)
1633 if (!buffers_allocated
)
1637 tracing_start_cmdline_record();
1639 tracing_stop_cmdline_record();
1643 * trace_vbprintk - write binary msg to tracing buffer
1646 int trace_vbprintk(unsigned long ip
, const char *fmt
, va_list args
)
1648 struct ftrace_event_call
*call
= &event_bprint
;
1649 struct ring_buffer_event
*event
;
1650 struct ring_buffer
*buffer
;
1651 struct trace_array
*tr
= &global_trace
;
1652 struct bprint_entry
*entry
;
1653 unsigned long flags
;
1655 int len
= 0, size
, pc
;
1657 if (unlikely(tracing_selftest_running
|| tracing_disabled
))
1660 /* Don't pollute graph traces with trace_vprintk internals */
1661 pause_graph_tracing();
1663 pc
= preempt_count();
1664 preempt_disable_notrace();
1666 tbuffer
= get_trace_buf();
1672 len
= vbin_printf((u32
*)tbuffer
, TRACE_BUF_SIZE
/sizeof(int), fmt
, args
);
1674 if (len
> TRACE_BUF_SIZE
/sizeof(int) || len
< 0)
1677 local_save_flags(flags
);
1678 size
= sizeof(*entry
) + sizeof(u32
) * len
;
1679 buffer
= tr
->buffer
;
1680 event
= trace_buffer_lock_reserve(buffer
, TRACE_BPRINT
, size
,
1684 entry
= ring_buffer_event_data(event
);
1688 memcpy(entry
->buf
, tbuffer
, sizeof(u32
) * len
);
1689 if (!filter_check_discard(call
, entry
, buffer
, event
)) {
1690 __buffer_unlock_commit(buffer
, event
);
1691 ftrace_trace_stack(buffer
, flags
, 6, pc
);
1695 preempt_enable_notrace();
1696 unpause_graph_tracing();
1700 EXPORT_SYMBOL_GPL(trace_vbprintk
);
1702 int trace_array_printk(struct trace_array
*tr
,
1703 unsigned long ip
, const char *fmt
, ...)
1708 if (!(trace_flags
& TRACE_ITER_PRINTK
))
1712 ret
= trace_array_vprintk(tr
, ip
, fmt
, ap
);
1717 int trace_array_vprintk(struct trace_array
*tr
,
1718 unsigned long ip
, const char *fmt
, va_list args
)
1720 struct ftrace_event_call
*call
= &event_print
;
1721 struct ring_buffer_event
*event
;
1722 struct ring_buffer
*buffer
;
1723 int len
= 0, size
, pc
;
1724 struct print_entry
*entry
;
1725 unsigned long flags
;
1728 if (tracing_disabled
|| tracing_selftest_running
)
1731 /* Don't pollute graph traces with trace_vprintk internals */
1732 pause_graph_tracing();
1734 pc
= preempt_count();
1735 preempt_disable_notrace();
1738 tbuffer
= get_trace_buf();
1744 len
= vsnprintf(tbuffer
, TRACE_BUF_SIZE
, fmt
, args
);
1745 if (len
> TRACE_BUF_SIZE
)
1748 local_save_flags(flags
);
1749 size
= sizeof(*entry
) + len
+ 1;
1750 buffer
= tr
->buffer
;
1751 event
= trace_buffer_lock_reserve(buffer
, TRACE_PRINT
, size
,
1755 entry
= ring_buffer_event_data(event
);
1758 memcpy(&entry
->buf
, tbuffer
, len
);
1759 entry
->buf
[len
] = '\0';
1760 if (!filter_check_discard(call
, entry
, buffer
, event
)) {
1761 __buffer_unlock_commit(buffer
, event
);
1762 ftrace_trace_stack(buffer
, flags
, 6, pc
);
1765 preempt_enable_notrace();
1766 unpause_graph_tracing();
1771 int trace_vprintk(unsigned long ip
, const char *fmt
, va_list args
)
1773 return trace_array_vprintk(&global_trace
, ip
, fmt
, args
);
1775 EXPORT_SYMBOL_GPL(trace_vprintk
);
1777 static void trace_iterator_increment(struct trace_iterator
*iter
)
1779 struct ring_buffer_iter
*buf_iter
= trace_buffer_iter(iter
, iter
->cpu
);
1783 ring_buffer_read(buf_iter
, NULL
);
1786 static struct trace_entry
*
1787 peek_next_entry(struct trace_iterator
*iter
, int cpu
, u64
*ts
,
1788 unsigned long *lost_events
)
1790 struct ring_buffer_event
*event
;
1791 struct ring_buffer_iter
*buf_iter
= trace_buffer_iter(iter
, cpu
);
1794 event
= ring_buffer_iter_peek(buf_iter
, ts
);
1796 event
= ring_buffer_peek(iter
->tr
->buffer
, cpu
, ts
,
1800 iter
->ent_size
= ring_buffer_event_length(event
);
1801 return ring_buffer_event_data(event
);
1807 static struct trace_entry
*
1808 __find_next_entry(struct trace_iterator
*iter
, int *ent_cpu
,
1809 unsigned long *missing_events
, u64
*ent_ts
)
1811 struct ring_buffer
*buffer
= iter
->tr
->buffer
;
1812 struct trace_entry
*ent
, *next
= NULL
;
1813 unsigned long lost_events
= 0, next_lost
= 0;
1814 int cpu_file
= iter
->cpu_file
;
1815 u64 next_ts
= 0, ts
;
1821 * If we are in a per_cpu trace file, don't bother by iterating over
1822 * all cpu and peek directly.
1824 if (cpu_file
> TRACE_PIPE_ALL_CPU
) {
1825 if (ring_buffer_empty_cpu(buffer
, cpu_file
))
1827 ent
= peek_next_entry(iter
, cpu_file
, ent_ts
, missing_events
);
1829 *ent_cpu
= cpu_file
;
1834 for_each_tracing_cpu(cpu
) {
1836 if (ring_buffer_empty_cpu(buffer
, cpu
))
1839 ent
= peek_next_entry(iter
, cpu
, &ts
, &lost_events
);
1842 * Pick the entry with the smallest timestamp:
1844 if (ent
&& (!next
|| ts
< next_ts
)) {
1848 next_lost
= lost_events
;
1849 next_size
= iter
->ent_size
;
1853 iter
->ent_size
= next_size
;
1856 *ent_cpu
= next_cpu
;
1862 *missing_events
= next_lost
;
1867 /* Find the next real entry, without updating the iterator itself */
1868 struct trace_entry
*trace_find_next_entry(struct trace_iterator
*iter
,
1869 int *ent_cpu
, u64
*ent_ts
)
1871 return __find_next_entry(iter
, ent_cpu
, NULL
, ent_ts
);
1874 /* Find the next real entry, and increment the iterator to the next entry */
1875 void *trace_find_next_entry_inc(struct trace_iterator
*iter
)
1877 iter
->ent
= __find_next_entry(iter
, &iter
->cpu
,
1878 &iter
->lost_events
, &iter
->ts
);
1881 trace_iterator_increment(iter
);
1883 return iter
->ent
? iter
: NULL
;
1886 static void trace_consume(struct trace_iterator
*iter
)
1888 ring_buffer_consume(iter
->tr
->buffer
, iter
->cpu
, &iter
->ts
,
1889 &iter
->lost_events
);
1892 static void *s_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
1894 struct trace_iterator
*iter
= m
->private;
1898 WARN_ON_ONCE(iter
->leftover
);
1902 /* can't go backwards */
1907 ent
= trace_find_next_entry_inc(iter
);
1911 while (ent
&& iter
->idx
< i
)
1912 ent
= trace_find_next_entry_inc(iter
);
1919 void tracing_iter_reset(struct trace_iterator
*iter
, int cpu
)
1921 struct trace_array
*tr
= iter
->tr
;
1922 struct ring_buffer_event
*event
;
1923 struct ring_buffer_iter
*buf_iter
;
1924 unsigned long entries
= 0;
1927 tr
->data
[cpu
]->skipped_entries
= 0;
1929 buf_iter
= trace_buffer_iter(iter
, cpu
);
1933 ring_buffer_iter_reset(buf_iter
);
1936 * We could have the case with the max latency tracers
1937 * that a reset never took place on a cpu. This is evident
1938 * by the timestamp being before the start of the buffer.
1940 while ((event
= ring_buffer_iter_peek(buf_iter
, &ts
))) {
1941 if (ts
>= iter
->tr
->time_start
)
1944 ring_buffer_read(buf_iter
, NULL
);
1947 tr
->data
[cpu
]->skipped_entries
= entries
;
1951 * The current tracer is copied to avoid a global locking
1954 static void *s_start(struct seq_file
*m
, loff_t
*pos
)
1956 struct trace_iterator
*iter
= m
->private;
1957 int cpu_file
= iter
->cpu_file
;
1963 * copy the tracer to avoid using a global lock all around.
1964 * iter->trace is a copy of current_trace, the pointer to the
1965 * name may be used instead of a strcmp(), as iter->trace->name
1966 * will point to the same string as current_trace->name.
1968 mutex_lock(&trace_types_lock
);
1969 if (unlikely(current_trace
&& iter
->trace
->name
!= current_trace
->name
))
1970 *iter
->trace
= *current_trace
;
1971 mutex_unlock(&trace_types_lock
);
1973 if (iter
->snapshot
&& iter
->trace
->use_max_tr
)
1974 return ERR_PTR(-EBUSY
);
1976 if (!iter
->snapshot
)
1977 atomic_inc(&trace_record_cmdline_disabled
);
1979 if (*pos
!= iter
->pos
) {
1984 if (cpu_file
== TRACE_PIPE_ALL_CPU
) {
1985 for_each_tracing_cpu(cpu
)
1986 tracing_iter_reset(iter
, cpu
);
1988 tracing_iter_reset(iter
, cpu_file
);
1991 for (p
= iter
; p
&& l
< *pos
; p
= s_next(m
, p
, &l
))
1996 * If we overflowed the seq_file before, then we want
1997 * to just reuse the trace_seq buffer again.
2003 p
= s_next(m
, p
, &l
);
2007 trace_event_read_lock();
2008 trace_access_lock(cpu_file
);
2012 static void s_stop(struct seq_file
*m
, void *p
)
2014 struct trace_iterator
*iter
= m
->private;
2016 if (iter
->snapshot
&& iter
->trace
->use_max_tr
)
2019 if (!iter
->snapshot
)
2020 atomic_dec(&trace_record_cmdline_disabled
);
2021 trace_access_unlock(iter
->cpu_file
);
2022 trace_event_read_unlock();
2026 get_total_entries(struct trace_array
*tr
, unsigned long *total
, unsigned long *entries
)
2028 unsigned long count
;
2034 for_each_tracing_cpu(cpu
) {
2035 count
= ring_buffer_entries_cpu(tr
->buffer
, cpu
);
2037 * If this buffer has skipped entries, then we hold all
2038 * entries for the trace and we need to ignore the
2039 * ones before the time stamp.
2041 if (tr
->data
[cpu
]->skipped_entries
) {
2042 count
-= tr
->data
[cpu
]->skipped_entries
;
2043 /* total is the same as the entries */
2047 ring_buffer_overrun_cpu(tr
->buffer
, cpu
);
2052 static void print_lat_help_header(struct seq_file
*m
)
2054 seq_puts(m
, "# _------=> CPU# \n");
2055 seq_puts(m
, "# / _-----=> irqs-off \n");
2056 seq_puts(m
, "# | / _----=> need-resched \n");
2057 seq_puts(m
, "# || / _---=> hardirq/softirq \n");
2058 seq_puts(m
, "# ||| / _--=> preempt-depth \n");
2059 seq_puts(m
, "# |||| / delay \n");
2060 seq_puts(m
, "# cmd pid ||||| time | caller \n");
2061 seq_puts(m
, "# \\ / ||||| \\ | / \n");
2064 static void print_event_info(struct trace_array
*tr
, struct seq_file
*m
)
2066 unsigned long total
;
2067 unsigned long entries
;
2069 get_total_entries(tr
, &total
, &entries
);
2070 seq_printf(m
, "# entries-in-buffer/entries-written: %lu/%lu #P:%d\n",
2071 entries
, total
, num_online_cpus());
2075 static void print_func_help_header(struct trace_array
*tr
, struct seq_file
*m
)
2077 print_event_info(tr
, m
);
2078 seq_puts(m
, "# TASK-PID CPU# TIMESTAMP FUNCTION\n");
2079 seq_puts(m
, "# | | | | |\n");
2082 static void print_func_help_header_irq(struct trace_array
*tr
, struct seq_file
*m
)
2084 print_event_info(tr
, m
);
2085 seq_puts(m
, "# _-----=> irqs-off\n");
2086 seq_puts(m
, "# / _----=> need-resched\n");
2087 seq_puts(m
, "# | / _---=> hardirq/softirq\n");
2088 seq_puts(m
, "# || / _--=> preempt-depth\n");
2089 seq_puts(m
, "# ||| / delay\n");
2090 seq_puts(m
, "# TASK-PID CPU# |||| TIMESTAMP FUNCTION\n");
2091 seq_puts(m
, "# | | | |||| | |\n");
2095 print_trace_header(struct seq_file
*m
, struct trace_iterator
*iter
)
2097 unsigned long sym_flags
= (trace_flags
& TRACE_ITER_SYM_MASK
);
2098 struct trace_array
*tr
= iter
->tr
;
2099 struct trace_array_cpu
*data
= tr
->data
[tr
->cpu
];
2100 struct tracer
*type
= current_trace
;
2101 unsigned long entries
;
2102 unsigned long total
;
2103 const char *name
= "preemption";
2107 get_total_entries(tr
, &total
, &entries
);
2109 seq_printf(m
, "# %s latency trace v1.1.5 on %s\n",
2111 seq_puts(m
, "# -----------------------------------"
2112 "---------------------------------\n");
2113 seq_printf(m
, "# latency: %lu us, #%lu/%lu, CPU#%d |"
2114 " (M:%s VP:%d, KP:%d, SP:%d HP:%d",
2115 nsecs_to_usecs(data
->saved_latency
),
2119 #if defined(CONFIG_PREEMPT_NONE)
2121 #elif defined(CONFIG_PREEMPT_VOLUNTARY)
2123 #elif defined(CONFIG_PREEMPT)
2128 /* These are reserved for later use */
2131 seq_printf(m
, " #P:%d)\n", num_online_cpus());
2135 seq_puts(m
, "# -----------------\n");
2136 seq_printf(m
, "# | task: %.16s-%d "
2137 "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n",
2138 data
->comm
, data
->pid
,
2139 from_kuid_munged(seq_user_ns(m
), data
->uid
), data
->nice
,
2140 data
->policy
, data
->rt_priority
);
2141 seq_puts(m
, "# -----------------\n");
2143 if (data
->critical_start
) {
2144 seq_puts(m
, "# => started at: ");
2145 seq_print_ip_sym(&iter
->seq
, data
->critical_start
, sym_flags
);
2146 trace_print_seq(m
, &iter
->seq
);
2147 seq_puts(m
, "\n# => ended at: ");
2148 seq_print_ip_sym(&iter
->seq
, data
->critical_end
, sym_flags
);
2149 trace_print_seq(m
, &iter
->seq
);
2150 seq_puts(m
, "\n#\n");
2156 static void test_cpu_buff_start(struct trace_iterator
*iter
)
2158 struct trace_seq
*s
= &iter
->seq
;
2160 if (!(trace_flags
& TRACE_ITER_ANNOTATE
))
2163 if (!(iter
->iter_flags
& TRACE_FILE_ANNOTATE
))
2166 if (cpumask_test_cpu(iter
->cpu
, iter
->started
))
2169 if (iter
->tr
->data
[iter
->cpu
]->skipped_entries
)
2172 cpumask_set_cpu(iter
->cpu
, iter
->started
);
2174 /* Don't print started cpu buffer for the first entry of the trace */
2176 trace_seq_printf(s
, "##### CPU %u buffer started ####\n",
2180 static enum print_line_t
print_trace_fmt(struct trace_iterator
*iter
)
2182 struct trace_seq
*s
= &iter
->seq
;
2183 unsigned long sym_flags
= (trace_flags
& TRACE_ITER_SYM_MASK
);
2184 struct trace_entry
*entry
;
2185 struct trace_event
*event
;
2189 test_cpu_buff_start(iter
);
2191 event
= ftrace_find_event(entry
->type
);
2193 if (trace_flags
& TRACE_ITER_CONTEXT_INFO
) {
2194 if (iter
->iter_flags
& TRACE_FILE_LAT_FMT
) {
2195 if (!trace_print_lat_context(iter
))
2198 if (!trace_print_context(iter
))
2204 return event
->funcs
->trace(iter
, sym_flags
, event
);
2206 if (!trace_seq_printf(s
, "Unknown type %d\n", entry
->type
))
2209 return TRACE_TYPE_HANDLED
;
2211 return TRACE_TYPE_PARTIAL_LINE
;
2214 static enum print_line_t
print_raw_fmt(struct trace_iterator
*iter
)
2216 struct trace_seq
*s
= &iter
->seq
;
2217 struct trace_entry
*entry
;
2218 struct trace_event
*event
;
2222 if (trace_flags
& TRACE_ITER_CONTEXT_INFO
) {
2223 if (!trace_seq_printf(s
, "%d %d %llu ",
2224 entry
->pid
, iter
->cpu
, iter
->ts
))
2228 event
= ftrace_find_event(entry
->type
);
2230 return event
->funcs
->raw(iter
, 0, event
);
2232 if (!trace_seq_printf(s
, "%d ?\n", entry
->type
))
2235 return TRACE_TYPE_HANDLED
;
2237 return TRACE_TYPE_PARTIAL_LINE
;
2240 static enum print_line_t
print_hex_fmt(struct trace_iterator
*iter
)
2242 struct trace_seq
*s
= &iter
->seq
;
2243 unsigned char newline
= '\n';
2244 struct trace_entry
*entry
;
2245 struct trace_event
*event
;
2249 if (trace_flags
& TRACE_ITER_CONTEXT_INFO
) {
2250 SEQ_PUT_HEX_FIELD_RET(s
, entry
->pid
);
2251 SEQ_PUT_HEX_FIELD_RET(s
, iter
->cpu
);
2252 SEQ_PUT_HEX_FIELD_RET(s
, iter
->ts
);
2255 event
= ftrace_find_event(entry
->type
);
2257 enum print_line_t ret
= event
->funcs
->hex(iter
, 0, event
);
2258 if (ret
!= TRACE_TYPE_HANDLED
)
2262 SEQ_PUT_FIELD_RET(s
, newline
);
2264 return TRACE_TYPE_HANDLED
;
2267 static enum print_line_t
print_bin_fmt(struct trace_iterator
*iter
)
2269 struct trace_seq
*s
= &iter
->seq
;
2270 struct trace_entry
*entry
;
2271 struct trace_event
*event
;
2275 if (trace_flags
& TRACE_ITER_CONTEXT_INFO
) {
2276 SEQ_PUT_FIELD_RET(s
, entry
->pid
);
2277 SEQ_PUT_FIELD_RET(s
, iter
->cpu
);
2278 SEQ_PUT_FIELD_RET(s
, iter
->ts
);
2281 event
= ftrace_find_event(entry
->type
);
2282 return event
? event
->funcs
->binary(iter
, 0, event
) :
2286 int trace_empty(struct trace_iterator
*iter
)
2288 struct ring_buffer_iter
*buf_iter
;
2291 /* If we are looking at one CPU buffer, only check that one */
2292 if (iter
->cpu_file
!= TRACE_PIPE_ALL_CPU
) {
2293 cpu
= iter
->cpu_file
;
2294 buf_iter
= trace_buffer_iter(iter
, cpu
);
2296 if (!ring_buffer_iter_empty(buf_iter
))
2299 if (!ring_buffer_empty_cpu(iter
->tr
->buffer
, cpu
))
2305 for_each_tracing_cpu(cpu
) {
2306 buf_iter
= trace_buffer_iter(iter
, cpu
);
2308 if (!ring_buffer_iter_empty(buf_iter
))
2311 if (!ring_buffer_empty_cpu(iter
->tr
->buffer
, cpu
))
2319 /* Called with trace_event_read_lock() held. */
2320 enum print_line_t
print_trace_line(struct trace_iterator
*iter
)
2322 enum print_line_t ret
;
2324 if (iter
->lost_events
&&
2325 !trace_seq_printf(&iter
->seq
, "CPU:%d [LOST %lu EVENTS]\n",
2326 iter
->cpu
, iter
->lost_events
))
2327 return TRACE_TYPE_PARTIAL_LINE
;
2329 if (iter
->trace
&& iter
->trace
->print_line
) {
2330 ret
= iter
->trace
->print_line(iter
);
2331 if (ret
!= TRACE_TYPE_UNHANDLED
)
2335 if (iter
->ent
->type
== TRACE_BPRINT
&&
2336 trace_flags
& TRACE_ITER_PRINTK
&&
2337 trace_flags
& TRACE_ITER_PRINTK_MSGONLY
)
2338 return trace_print_bprintk_msg_only(iter
);
2340 if (iter
->ent
->type
== TRACE_PRINT
&&
2341 trace_flags
& TRACE_ITER_PRINTK
&&
2342 trace_flags
& TRACE_ITER_PRINTK_MSGONLY
)
2343 return trace_print_printk_msg_only(iter
);
2345 if (trace_flags
& TRACE_ITER_BIN
)
2346 return print_bin_fmt(iter
);
2348 if (trace_flags
& TRACE_ITER_HEX
)
2349 return print_hex_fmt(iter
);
2351 if (trace_flags
& TRACE_ITER_RAW
)
2352 return print_raw_fmt(iter
);
2354 return print_trace_fmt(iter
);
2357 void trace_latency_header(struct seq_file
*m
)
2359 struct trace_iterator
*iter
= m
->private;
2361 /* print nothing if the buffers are empty */
2362 if (trace_empty(iter
))
2365 if (iter
->iter_flags
& TRACE_FILE_LAT_FMT
)
2366 print_trace_header(m
, iter
);
2368 if (!(trace_flags
& TRACE_ITER_VERBOSE
))
2369 print_lat_help_header(m
);
2372 void trace_default_header(struct seq_file
*m
)
2374 struct trace_iterator
*iter
= m
->private;
2376 if (!(trace_flags
& TRACE_ITER_CONTEXT_INFO
))
2379 if (iter
->iter_flags
& TRACE_FILE_LAT_FMT
) {
2380 /* print nothing if the buffers are empty */
2381 if (trace_empty(iter
))
2383 print_trace_header(m
, iter
);
2384 if (!(trace_flags
& TRACE_ITER_VERBOSE
))
2385 print_lat_help_header(m
);
2387 if (!(trace_flags
& TRACE_ITER_VERBOSE
)) {
2388 if (trace_flags
& TRACE_ITER_IRQ_INFO
)
2389 print_func_help_header_irq(iter
->tr
, m
);
2391 print_func_help_header(iter
->tr
, m
);
2396 static void test_ftrace_alive(struct seq_file
*m
)
2398 if (!ftrace_is_dead())
2400 seq_printf(m
, "# WARNING: FUNCTION TRACING IS CORRUPTED\n");
2401 seq_printf(m
, "# MAY BE MISSING FUNCTION EVENTS\n");
2404 #ifdef CONFIG_TRACER_MAX_TRACE
2405 static void print_snapshot_help(struct seq_file
*m
, struct trace_iterator
*iter
)
2407 if (iter
->trace
->allocated_snapshot
)
2408 seq_printf(m
, "#\n# * Snapshot is allocated *\n#\n");
2410 seq_printf(m
, "#\n# * Snapshot is freed *\n#\n");
2412 seq_printf(m
, "# Snapshot commands:\n");
2413 seq_printf(m
, "# echo 0 > snapshot : Clears and frees snapshot buffer\n");
2414 seq_printf(m
, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n");
2415 seq_printf(m
, "# Takes a snapshot of the main buffer.\n");
2416 seq_printf(m
, "# echo 2 > snapshot : Clears snapshot buffer (but does not allocate)\n");
2417 seq_printf(m
, "# (Doesn't have to be '2' works with any number that\n");
2418 seq_printf(m
, "# is not a '0' or '1')\n");
2421 /* Should never be called */
2422 static inline void print_snapshot_help(struct seq_file
*m
, struct trace_iterator
*iter
) { }
2425 static int s_show(struct seq_file
*m
, void *v
)
2427 struct trace_iterator
*iter
= v
;
2430 if (iter
->ent
== NULL
) {
2432 seq_printf(m
, "# tracer: %s\n", iter
->trace
->name
);
2434 test_ftrace_alive(m
);
2436 if (iter
->snapshot
&& trace_empty(iter
))
2437 print_snapshot_help(m
, iter
);
2438 else if (iter
->trace
&& iter
->trace
->print_header
)
2439 iter
->trace
->print_header(m
);
2441 trace_default_header(m
);
2443 } else if (iter
->leftover
) {
2445 * If we filled the seq_file buffer earlier, we
2446 * want to just show it now.
2448 ret
= trace_print_seq(m
, &iter
->seq
);
2450 /* ret should this time be zero, but you never know */
2451 iter
->leftover
= ret
;
2454 print_trace_line(iter
);
2455 ret
= trace_print_seq(m
, &iter
->seq
);
2457 * If we overflow the seq_file buffer, then it will
2458 * ask us for this data again at start up.
2460 * ret is 0 if seq_file write succeeded.
2463 iter
->leftover
= ret
;
2469 static const struct seq_operations tracer_seq_ops
= {
2476 static struct trace_iterator
*
2477 __tracing_open(struct inode
*inode
, struct file
*file
, bool snapshot
)
2479 long cpu_file
= (long) inode
->i_private
;
2480 struct trace_iterator
*iter
;
2483 if (tracing_disabled
)
2484 return ERR_PTR(-ENODEV
);
2486 iter
= __seq_open_private(file
, &tracer_seq_ops
, sizeof(*iter
));
2488 return ERR_PTR(-ENOMEM
);
2490 iter
->buffer_iter
= kzalloc(sizeof(*iter
->buffer_iter
) * num_possible_cpus(),
2492 if (!iter
->buffer_iter
)
2496 * We make a copy of the current tracer to avoid concurrent
2497 * changes on it while we are reading.
2499 mutex_lock(&trace_types_lock
);
2500 iter
->trace
= kzalloc(sizeof(*iter
->trace
), GFP_KERNEL
);
2504 *iter
->trace
= *current_trace
;
2506 if (!zalloc_cpumask_var(&iter
->started
, GFP_KERNEL
))
2509 if (current_trace
->print_max
|| snapshot
)
2512 iter
->tr
= &global_trace
;
2513 iter
->snapshot
= snapshot
;
2515 mutex_init(&iter
->mutex
);
2516 iter
->cpu_file
= cpu_file
;
2518 /* Notify the tracer early; before we stop tracing. */
2519 if (iter
->trace
&& iter
->trace
->open
)
2520 iter
->trace
->open(iter
);
2522 /* Annotate start of buffers if we had overruns */
2523 if (ring_buffer_overruns(iter
->tr
->buffer
))
2524 iter
->iter_flags
|= TRACE_FILE_ANNOTATE
;
2526 /* Output in nanoseconds only if we are using a clock in nanoseconds. */
2527 if (trace_clocks
[trace_clock_id
].in_ns
)
2528 iter
->iter_flags
|= TRACE_FILE_TIME_IN_NS
;
2530 /* stop the trace while dumping if we are not opening "snapshot" */
2531 if (!iter
->snapshot
)
2534 if (iter
->cpu_file
== TRACE_PIPE_ALL_CPU
) {
2535 for_each_tracing_cpu(cpu
) {
2536 iter
->buffer_iter
[cpu
] =
2537 ring_buffer_read_prepare(iter
->tr
->buffer
, cpu
);
2539 ring_buffer_read_prepare_sync();
2540 for_each_tracing_cpu(cpu
) {
2541 ring_buffer_read_start(iter
->buffer_iter
[cpu
]);
2542 tracing_iter_reset(iter
, cpu
);
2545 cpu
= iter
->cpu_file
;
2546 iter
->buffer_iter
[cpu
] =
2547 ring_buffer_read_prepare(iter
->tr
->buffer
, cpu
);
2548 ring_buffer_read_prepare_sync();
2549 ring_buffer_read_start(iter
->buffer_iter
[cpu
]);
2550 tracing_iter_reset(iter
, cpu
);
2553 mutex_unlock(&trace_types_lock
);
2558 mutex_unlock(&trace_types_lock
);
2560 kfree(iter
->buffer_iter
);
2562 seq_release_private(inode
, file
);
2563 return ERR_PTR(-ENOMEM
);
2566 int tracing_open_generic(struct inode
*inode
, struct file
*filp
)
2568 if (tracing_disabled
)
2571 filp
->private_data
= inode
->i_private
;
2575 static int tracing_release(struct inode
*inode
, struct file
*file
)
2577 struct seq_file
*m
= file
->private_data
;
2578 struct trace_iterator
*iter
;
2581 if (!(file
->f_mode
& FMODE_READ
))
2586 mutex_lock(&trace_types_lock
);
2587 for_each_tracing_cpu(cpu
) {
2588 if (iter
->buffer_iter
[cpu
])
2589 ring_buffer_read_finish(iter
->buffer_iter
[cpu
]);
2592 if (iter
->trace
&& iter
->trace
->close
)
2593 iter
->trace
->close(iter
);
2595 if (!iter
->snapshot
)
2596 /* reenable tracing if it was previously enabled */
2598 mutex_unlock(&trace_types_lock
);
2600 mutex_destroy(&iter
->mutex
);
2601 free_cpumask_var(iter
->started
);
2603 kfree(iter
->buffer_iter
);
2604 seq_release_private(inode
, file
);
2608 static int tracing_open(struct inode
*inode
, struct file
*file
)
2610 struct trace_iterator
*iter
;
2613 /* If this file was open for write, then erase contents */
2614 if ((file
->f_mode
& FMODE_WRITE
) &&
2615 (file
->f_flags
& O_TRUNC
)) {
2616 long cpu
= (long) inode
->i_private
;
2618 if (cpu
== TRACE_PIPE_ALL_CPU
)
2619 tracing_reset_online_cpus(&global_trace
);
2621 tracing_reset(&global_trace
, cpu
);
2624 if (file
->f_mode
& FMODE_READ
) {
2625 iter
= __tracing_open(inode
, file
, false);
2627 ret
= PTR_ERR(iter
);
2628 else if (trace_flags
& TRACE_ITER_LATENCY_FMT
)
2629 iter
->iter_flags
|= TRACE_FILE_LAT_FMT
;
2635 t_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
2637 struct tracer
*t
= v
;
2647 static void *t_start(struct seq_file
*m
, loff_t
*pos
)
2652 mutex_lock(&trace_types_lock
);
2653 for (t
= trace_types
; t
&& l
< *pos
; t
= t_next(m
, t
, &l
))
2659 static void t_stop(struct seq_file
*m
, void *p
)
2661 mutex_unlock(&trace_types_lock
);
2664 static int t_show(struct seq_file
*m
, void *v
)
2666 struct tracer
*t
= v
;
2671 seq_printf(m
, "%s", t
->name
);
2680 static const struct seq_operations show_traces_seq_ops
= {
2687 static int show_traces_open(struct inode
*inode
, struct file
*file
)
2689 if (tracing_disabled
)
2692 return seq_open(file
, &show_traces_seq_ops
);
2696 tracing_write_stub(struct file
*filp
, const char __user
*ubuf
,
2697 size_t count
, loff_t
*ppos
)
2702 static loff_t
tracing_seek(struct file
*file
, loff_t offset
, int origin
)
2704 if (file
->f_mode
& FMODE_READ
)
2705 return seq_lseek(file
, offset
, origin
);
2710 static const struct file_operations tracing_fops
= {
2711 .open
= tracing_open
,
2713 .write
= tracing_write_stub
,
2714 .llseek
= tracing_seek
,
2715 .release
= tracing_release
,
2718 static const struct file_operations show_traces_fops
= {
2719 .open
= show_traces_open
,
2721 .release
= seq_release
,
2722 .llseek
= seq_lseek
,
2726 * Only trace on a CPU if the bitmask is set:
2728 static cpumask_var_t tracing_cpumask
;
2731 * The tracer itself will not take this lock, but still we want
2732 * to provide a consistent cpumask to user-space:
2734 static DEFINE_MUTEX(tracing_cpumask_update_lock
);
2737 * Temporary storage for the character representation of the
2738 * CPU bitmask (and one more byte for the newline):
2740 static char mask_str
[NR_CPUS
+ 1];
2743 tracing_cpumask_read(struct file
*filp
, char __user
*ubuf
,
2744 size_t count
, loff_t
*ppos
)
2748 mutex_lock(&tracing_cpumask_update_lock
);
2750 len
= cpumask_scnprintf(mask_str
, count
, tracing_cpumask
);
2751 if (count
- len
< 2) {
2755 len
+= sprintf(mask_str
+ len
, "\n");
2756 count
= simple_read_from_buffer(ubuf
, count
, ppos
, mask_str
, NR_CPUS
+1);
2759 mutex_unlock(&tracing_cpumask_update_lock
);
2765 tracing_cpumask_write(struct file
*filp
, const char __user
*ubuf
,
2766 size_t count
, loff_t
*ppos
)
2769 cpumask_var_t tracing_cpumask_new
;
2771 if (!alloc_cpumask_var(&tracing_cpumask_new
, GFP_KERNEL
))
2774 err
= cpumask_parse_user(ubuf
, count
, tracing_cpumask_new
);
2778 mutex_lock(&tracing_cpumask_update_lock
);
2780 local_irq_disable();
2781 arch_spin_lock(&ftrace_max_lock
);
2782 for_each_tracing_cpu(cpu
) {
2784 * Increase/decrease the disabled counter if we are
2785 * about to flip a bit in the cpumask:
2787 if (cpumask_test_cpu(cpu
, tracing_cpumask
) &&
2788 !cpumask_test_cpu(cpu
, tracing_cpumask_new
)) {
2789 atomic_inc(&global_trace
.data
[cpu
]->disabled
);
2790 ring_buffer_record_disable_cpu(global_trace
.buffer
, cpu
);
2792 if (!cpumask_test_cpu(cpu
, tracing_cpumask
) &&
2793 cpumask_test_cpu(cpu
, tracing_cpumask_new
)) {
2794 atomic_dec(&global_trace
.data
[cpu
]->disabled
);
2795 ring_buffer_record_enable_cpu(global_trace
.buffer
, cpu
);
2798 arch_spin_unlock(&ftrace_max_lock
);
2801 cpumask_copy(tracing_cpumask
, tracing_cpumask_new
);
2803 mutex_unlock(&tracing_cpumask_update_lock
);
2804 free_cpumask_var(tracing_cpumask_new
);
2809 free_cpumask_var(tracing_cpumask_new
);
2814 static const struct file_operations tracing_cpumask_fops
= {
2815 .open
= tracing_open_generic
,
2816 .read
= tracing_cpumask_read
,
2817 .write
= tracing_cpumask_write
,
2818 .llseek
= generic_file_llseek
,
2821 static int tracing_trace_options_show(struct seq_file
*m
, void *v
)
2823 struct tracer_opt
*trace_opts
;
2827 mutex_lock(&trace_types_lock
);
2828 tracer_flags
= current_trace
->flags
->val
;
2829 trace_opts
= current_trace
->flags
->opts
;
2831 for (i
= 0; trace_options
[i
]; i
++) {
2832 if (trace_flags
& (1 << i
))
2833 seq_printf(m
, "%s\n", trace_options
[i
]);
2835 seq_printf(m
, "no%s\n", trace_options
[i
]);
2838 for (i
= 0; trace_opts
[i
].name
; i
++) {
2839 if (tracer_flags
& trace_opts
[i
].bit
)
2840 seq_printf(m
, "%s\n", trace_opts
[i
].name
);
2842 seq_printf(m
, "no%s\n", trace_opts
[i
].name
);
2844 mutex_unlock(&trace_types_lock
);
2849 static int __set_tracer_option(struct tracer
*trace
,
2850 struct tracer_flags
*tracer_flags
,
2851 struct tracer_opt
*opts
, int neg
)
2855 ret
= trace
->set_flag(tracer_flags
->val
, opts
->bit
, !neg
);
2860 tracer_flags
->val
&= ~opts
->bit
;
2862 tracer_flags
->val
|= opts
->bit
;
2866 /* Try to assign a tracer specific option */
2867 static int set_tracer_option(struct tracer
*trace
, char *cmp
, int neg
)
2869 struct tracer_flags
*tracer_flags
= trace
->flags
;
2870 struct tracer_opt
*opts
= NULL
;
2873 for (i
= 0; tracer_flags
->opts
[i
].name
; i
++) {
2874 opts
= &tracer_flags
->opts
[i
];
2876 if (strcmp(cmp
, opts
->name
) == 0)
2877 return __set_tracer_option(trace
, trace
->flags
,
2884 /* Some tracers require overwrite to stay enabled */
2885 int trace_keep_overwrite(struct tracer
*tracer
, u32 mask
, int set
)
2887 if (tracer
->enabled
&& (mask
& TRACE_ITER_OVERWRITE
) && !set
)
2893 int set_tracer_flag(unsigned int mask
, int enabled
)
2895 /* do nothing if flag is already set */
2896 if (!!(trace_flags
& mask
) == !!enabled
)
2899 /* Give the tracer a chance to approve the change */
2900 if (current_trace
->flag_changed
)
2901 if (current_trace
->flag_changed(current_trace
, mask
, !!enabled
))
2905 trace_flags
|= mask
;
2907 trace_flags
&= ~mask
;
2909 if (mask
== TRACE_ITER_RECORD_CMD
)
2910 trace_event_enable_cmd_record(enabled
);
2912 if (mask
== TRACE_ITER_OVERWRITE
) {
2913 ring_buffer_change_overwrite(global_trace
.buffer
, enabled
);
2914 #ifdef CONFIG_TRACER_MAX_TRACE
2915 ring_buffer_change_overwrite(max_tr
.buffer
, enabled
);
2919 if (mask
== TRACE_ITER_PRINTK
)
2920 trace_printk_start_stop_comm(enabled
);
2925 static int trace_set_options(char *option
)
2932 cmp
= strstrip(option
);
2934 if (strncmp(cmp
, "no", 2) == 0) {
2939 mutex_lock(&trace_types_lock
);
2941 for (i
= 0; trace_options
[i
]; i
++) {
2942 if (strcmp(cmp
, trace_options
[i
]) == 0) {
2943 ret
= set_tracer_flag(1 << i
, !neg
);
2948 /* If no option could be set, test the specific tracer options */
2949 if (!trace_options
[i
])
2950 ret
= set_tracer_option(current_trace
, cmp
, neg
);
2952 mutex_unlock(&trace_types_lock
);
2958 tracing_trace_options_write(struct file
*filp
, const char __user
*ubuf
,
2959 size_t cnt
, loff_t
*ppos
)
2964 if (cnt
>= sizeof(buf
))
2967 if (copy_from_user(&buf
, ubuf
, cnt
))
2972 ret
= trace_set_options(buf
);
2981 static int tracing_trace_options_open(struct inode
*inode
, struct file
*file
)
2983 if (tracing_disabled
)
2985 return single_open(file
, tracing_trace_options_show
, NULL
);
2988 static const struct file_operations tracing_iter_fops
= {
2989 .open
= tracing_trace_options_open
,
2991 .llseek
= seq_lseek
,
2992 .release
= single_release
,
2993 .write
= tracing_trace_options_write
,
2996 static const char readme_msg
[] =
2997 "tracing mini-HOWTO:\n\n"
2998 "# mount -t debugfs nodev /sys/kernel/debug\n\n"
2999 "# cat /sys/kernel/debug/tracing/available_tracers\n"
3000 "wakeup wakeup_rt preemptirqsoff preemptoff irqsoff function nop\n\n"
3001 "# cat /sys/kernel/debug/tracing/current_tracer\n"
3003 "# echo wakeup > /sys/kernel/debug/tracing/current_tracer\n"
3004 "# cat /sys/kernel/debug/tracing/current_tracer\n"
3006 "# cat /sys/kernel/debug/tracing/trace_options\n"
3007 "noprint-parent nosym-offset nosym-addr noverbose\n"
3008 "# echo print-parent > /sys/kernel/debug/tracing/trace_options\n"
3009 "# echo 1 > /sys/kernel/debug/tracing/tracing_on\n"
3010 "# cat /sys/kernel/debug/tracing/trace > /tmp/trace.txt\n"
3011 "# echo 0 > /sys/kernel/debug/tracing/tracing_on\n"
3015 tracing_readme_read(struct file
*filp
, char __user
*ubuf
,
3016 size_t cnt
, loff_t
*ppos
)
3018 return simple_read_from_buffer(ubuf
, cnt
, ppos
,
3019 readme_msg
, strlen(readme_msg
));
3022 static const struct file_operations tracing_readme_fops
= {
3023 .open
= tracing_open_generic
,
3024 .read
= tracing_readme_read
,
3025 .llseek
= generic_file_llseek
,
3029 tracing_saved_cmdlines_read(struct file
*file
, char __user
*ubuf
,
3030 size_t cnt
, loff_t
*ppos
)
3039 file_buf
= kmalloc(SAVED_CMDLINES
*(16+TASK_COMM_LEN
), GFP_KERNEL
);
3043 buf_comm
= kmalloc(TASK_COMM_LEN
, GFP_KERNEL
);
3051 for (i
= 0; i
< SAVED_CMDLINES
; i
++) {
3054 pid
= map_cmdline_to_pid
[i
];
3055 if (pid
== -1 || pid
== NO_CMDLINE_MAP
)
3058 trace_find_cmdline(pid
, buf_comm
);
3059 r
= sprintf(buf
, "%d %s\n", pid
, buf_comm
);
3064 len
= simple_read_from_buffer(ubuf
, cnt
, ppos
,
3073 static const struct file_operations tracing_saved_cmdlines_fops
= {
3074 .open
= tracing_open_generic
,
3075 .read
= tracing_saved_cmdlines_read
,
3076 .llseek
= generic_file_llseek
,
3080 tracing_set_trace_read(struct file
*filp
, char __user
*ubuf
,
3081 size_t cnt
, loff_t
*ppos
)
3083 char buf
[MAX_TRACER_SIZE
+2];
3086 mutex_lock(&trace_types_lock
);
3087 r
= sprintf(buf
, "%s\n", current_trace
->name
);
3088 mutex_unlock(&trace_types_lock
);
3090 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
3093 int tracer_init(struct tracer
*t
, struct trace_array
*tr
)
3095 tracing_reset_online_cpus(tr
);
3099 static void set_buffer_entries(struct trace_array
*tr
, unsigned long val
)
3102 for_each_tracing_cpu(cpu
)
3103 tr
->data
[cpu
]->entries
= val
;
3106 /* resize @tr's buffer to the size of @size_tr's entries */
3107 static int resize_buffer_duplicate_size(struct trace_array
*tr
,
3108 struct trace_array
*size_tr
, int cpu_id
)
3112 if (cpu_id
== RING_BUFFER_ALL_CPUS
) {
3113 for_each_tracing_cpu(cpu
) {
3114 ret
= ring_buffer_resize(tr
->buffer
,
3115 size_tr
->data
[cpu
]->entries
, cpu
);
3118 tr
->data
[cpu
]->entries
= size_tr
->data
[cpu
]->entries
;
3121 ret
= ring_buffer_resize(tr
->buffer
,
3122 size_tr
->data
[cpu_id
]->entries
, cpu_id
);
3124 tr
->data
[cpu_id
]->entries
=
3125 size_tr
->data
[cpu_id
]->entries
;
3131 static int __tracing_resize_ring_buffer(unsigned long size
, int cpu
)
3136 * If kernel or user changes the size of the ring buffer
3137 * we use the size that was given, and we can forget about
3138 * expanding it later.
3140 ring_buffer_expanded
= 1;
3142 /* May be called before buffers are initialized */
3143 if (!global_trace
.buffer
)
3146 ret
= ring_buffer_resize(global_trace
.buffer
, size
, cpu
);
3150 if (!current_trace
->use_max_tr
)
3153 ret
= ring_buffer_resize(max_tr
.buffer
, size
, cpu
);
3155 int r
= resize_buffer_duplicate_size(&global_trace
,
3156 &global_trace
, cpu
);
3159 * AARGH! We are left with different
3160 * size max buffer!!!!
3161 * The max buffer is our "snapshot" buffer.
3162 * When a tracer needs a snapshot (one of the
3163 * latency tracers), it swaps the max buffer
3164 * with the saved snap shot. We succeeded to
3165 * update the size of the main buffer, but failed to
3166 * update the size of the max buffer. But when we tried
3167 * to reset the main buffer to the original size, we
3168 * failed there too. This is very unlikely to
3169 * happen, but if it does, warn and kill all
3173 tracing_disabled
= 1;
3178 if (cpu
== RING_BUFFER_ALL_CPUS
)
3179 set_buffer_entries(&max_tr
, size
);
3181 max_tr
.data
[cpu
]->entries
= size
;
3184 if (cpu
== RING_BUFFER_ALL_CPUS
)
3185 set_buffer_entries(&global_trace
, size
);
3187 global_trace
.data
[cpu
]->entries
= size
;
3192 static ssize_t
tracing_resize_ring_buffer(unsigned long size
, int cpu_id
)
3196 mutex_lock(&trace_types_lock
);
3198 if (cpu_id
!= RING_BUFFER_ALL_CPUS
) {
3199 /* make sure, this cpu is enabled in the mask */
3200 if (!cpumask_test_cpu(cpu_id
, tracing_buffer_mask
)) {
3206 ret
= __tracing_resize_ring_buffer(size
, cpu_id
);
3211 mutex_unlock(&trace_types_lock
);
3218 * tracing_update_buffers - used by tracing facility to expand ring buffers
3220 * To save on memory when the tracing is never used on a system with it
3221 * configured in. The ring buffers are set to a minimum size. But once
3222 * a user starts to use the tracing facility, then they need to grow
3223 * to their default size.
3225 * This function is to be called when a tracer is about to be used.
3227 int tracing_update_buffers(void)
3231 mutex_lock(&trace_types_lock
);
3232 if (!ring_buffer_expanded
)
3233 ret
= __tracing_resize_ring_buffer(trace_buf_size
,
3234 RING_BUFFER_ALL_CPUS
);
3235 mutex_unlock(&trace_types_lock
);
3240 struct trace_option_dentry
;
3242 static struct trace_option_dentry
*
3243 create_trace_option_files(struct tracer
*tracer
);
3246 destroy_trace_option_files(struct trace_option_dentry
*topts
);
3248 static int tracing_set_tracer(const char *buf
)
3250 static struct trace_option_dentry
*topts
;
3251 struct trace_array
*tr
= &global_trace
;
3256 mutex_lock(&trace_types_lock
);
3258 if (!ring_buffer_expanded
) {
3259 ret
= __tracing_resize_ring_buffer(trace_buf_size
,
3260 RING_BUFFER_ALL_CPUS
);
3266 for (t
= trace_types
; t
; t
= t
->next
) {
3267 if (strcmp(t
->name
, buf
) == 0)
3274 if (t
== current_trace
)
3277 trace_branch_disable();
3279 current_trace
->enabled
= false;
3281 if (current_trace
->reset
)
3282 current_trace
->reset(tr
);
3284 had_max_tr
= current_trace
->allocated_snapshot
;
3285 current_trace
= &nop_trace
;
3287 if (had_max_tr
&& !t
->use_max_tr
) {
3289 * We need to make sure that the update_max_tr sees that
3290 * current_trace changed to nop_trace to keep it from
3291 * swapping the buffers after we resize it.
3292 * The update_max_tr is called from interrupts disabled
3293 * so a synchronized_sched() is sufficient.
3295 synchronize_sched();
3297 * We don't free the ring buffer. instead, resize it because
3298 * The max_tr ring buffer has some state (e.g. ring->clock) and
3299 * we want preserve it.
3301 ring_buffer_resize(max_tr
.buffer
, 1, RING_BUFFER_ALL_CPUS
);
3302 set_buffer_entries(&max_tr
, 1);
3303 tracing_reset_online_cpus(&max_tr
);
3304 current_trace
->allocated_snapshot
= false;
3306 destroy_trace_option_files(topts
);
3308 topts
= create_trace_option_files(t
);
3309 if (t
->use_max_tr
&& !had_max_tr
) {
3310 /* we need to make per cpu buffer sizes equivalent */
3311 ret
= resize_buffer_duplicate_size(&max_tr
, &global_trace
,
3312 RING_BUFFER_ALL_CPUS
);
3315 t
->allocated_snapshot
= true;
3319 ret
= tracer_init(t
, tr
);
3325 current_trace
->enabled
= true;
3326 trace_branch_enable(tr
);
3328 mutex_unlock(&trace_types_lock
);
3334 tracing_set_trace_write(struct file
*filp
, const char __user
*ubuf
,
3335 size_t cnt
, loff_t
*ppos
)
3337 char buf
[MAX_TRACER_SIZE
+1];
3344 if (cnt
> MAX_TRACER_SIZE
)
3345 cnt
= MAX_TRACER_SIZE
;
3347 if (copy_from_user(&buf
, ubuf
, cnt
))
3352 /* strip ending whitespace. */
3353 for (i
= cnt
- 1; i
> 0 && isspace(buf
[i
]); i
--)
3356 err
= tracing_set_tracer(buf
);
3366 tracing_max_lat_read(struct file
*filp
, char __user
*ubuf
,
3367 size_t cnt
, loff_t
*ppos
)
3369 unsigned long *ptr
= filp
->private_data
;
3373 r
= snprintf(buf
, sizeof(buf
), "%ld\n",
3374 *ptr
== (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr
));
3375 if (r
> sizeof(buf
))
3377 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
3381 tracing_max_lat_write(struct file
*filp
, const char __user
*ubuf
,
3382 size_t cnt
, loff_t
*ppos
)
3384 unsigned long *ptr
= filp
->private_data
;
3388 ret
= kstrtoul_from_user(ubuf
, cnt
, 10, &val
);
3397 static int tracing_open_pipe(struct inode
*inode
, struct file
*filp
)
3399 long cpu_file
= (long) inode
->i_private
;
3400 struct trace_iterator
*iter
;
3403 if (tracing_disabled
)
3406 mutex_lock(&trace_types_lock
);
3408 /* create a buffer to store the information to pass to userspace */
3409 iter
= kzalloc(sizeof(*iter
), GFP_KERNEL
);
3416 * We make a copy of the current tracer to avoid concurrent
3417 * changes on it while we are reading.
3419 iter
->trace
= kmalloc(sizeof(*iter
->trace
), GFP_KERNEL
);
3424 *iter
->trace
= *current_trace
;
3426 if (!alloc_cpumask_var(&iter
->started
, GFP_KERNEL
)) {
3431 /* trace pipe does not show start of buffer */
3432 cpumask_setall(iter
->started
);
3434 if (trace_flags
& TRACE_ITER_LATENCY_FMT
)
3435 iter
->iter_flags
|= TRACE_FILE_LAT_FMT
;
3437 /* Output in nanoseconds only if we are using a clock in nanoseconds. */
3438 if (trace_clocks
[trace_clock_id
].in_ns
)
3439 iter
->iter_flags
|= TRACE_FILE_TIME_IN_NS
;
3441 iter
->cpu_file
= cpu_file
;
3442 iter
->tr
= &global_trace
;
3443 mutex_init(&iter
->mutex
);
3444 filp
->private_data
= iter
;
3446 if (iter
->trace
->pipe_open
)
3447 iter
->trace
->pipe_open(iter
);
3449 nonseekable_open(inode
, filp
);
3451 mutex_unlock(&trace_types_lock
);
3457 mutex_unlock(&trace_types_lock
);
3461 static int tracing_release_pipe(struct inode
*inode
, struct file
*file
)
3463 struct trace_iterator
*iter
= file
->private_data
;
3465 mutex_lock(&trace_types_lock
);
3467 if (iter
->trace
->pipe_close
)
3468 iter
->trace
->pipe_close(iter
);
3470 mutex_unlock(&trace_types_lock
);
3472 free_cpumask_var(iter
->started
);
3473 mutex_destroy(&iter
->mutex
);
3481 tracing_poll_pipe(struct file
*filp
, poll_table
*poll_table
)
3483 struct trace_iterator
*iter
= filp
->private_data
;
3485 if (trace_flags
& TRACE_ITER_BLOCK
) {
3487 * Always select as readable when in blocking mode
3489 return POLLIN
| POLLRDNORM
;
3491 if (!trace_empty(iter
))
3492 return POLLIN
| POLLRDNORM
;
3493 poll_wait(filp
, &trace_wait
, poll_table
);
3494 if (!trace_empty(iter
))
3495 return POLLIN
| POLLRDNORM
;
3502 * This is a make-shift waitqueue.
3503 * A tracer might use this callback on some rare cases:
3505 * 1) the current tracer might hold the runqueue lock when it wakes up
3506 * a reader, hence a deadlock (sched, function, and function graph tracers)
3507 * 2) the function tracers, trace all functions, we don't want
3508 * the overhead of calling wake_up and friends
3509 * (and tracing them too)
3511 * Anyway, this is really very primitive wakeup.
3513 void poll_wait_pipe(struct trace_iterator
*iter
)
3515 set_current_state(TASK_INTERRUPTIBLE
);
3516 /* sleep for 100 msecs, and try again. */
3517 schedule_timeout(HZ
/ 10);
3520 /* Must be called with trace_types_lock mutex held. */
3521 static int tracing_wait_pipe(struct file
*filp
)
3523 struct trace_iterator
*iter
= filp
->private_data
;
3525 while (trace_empty(iter
)) {
3527 if ((filp
->f_flags
& O_NONBLOCK
)) {
3531 mutex_unlock(&iter
->mutex
);
3533 iter
->trace
->wait_pipe(iter
);
3535 mutex_lock(&iter
->mutex
);
3537 if (signal_pending(current
))
3541 * We block until we read something and tracing is disabled.
3542 * We still block if tracing is disabled, but we have never
3543 * read anything. This allows a user to cat this file, and
3544 * then enable tracing. But after we have read something,
3545 * we give an EOF when tracing is again disabled.
3547 * iter->pos will be 0 if we haven't read anything.
3549 if (!tracing_is_enabled() && iter
->pos
)
3560 tracing_read_pipe(struct file
*filp
, char __user
*ubuf
,
3561 size_t cnt
, loff_t
*ppos
)
3563 struct trace_iterator
*iter
= filp
->private_data
;
3566 /* return any leftover data */
3567 sret
= trace_seq_to_user(&iter
->seq
, ubuf
, cnt
);
3571 trace_seq_init(&iter
->seq
);
3573 /* copy the tracer to avoid using a global lock all around */
3574 mutex_lock(&trace_types_lock
);
3575 if (unlikely(iter
->trace
->name
!= current_trace
->name
))
3576 *iter
->trace
= *current_trace
;
3577 mutex_unlock(&trace_types_lock
);
3580 * Avoid more than one consumer on a single file descriptor
3581 * This is just a matter of traces coherency, the ring buffer itself
3584 mutex_lock(&iter
->mutex
);
3585 if (iter
->trace
->read
) {
3586 sret
= iter
->trace
->read(iter
, filp
, ubuf
, cnt
, ppos
);
3592 sret
= tracing_wait_pipe(filp
);
3596 /* stop when tracing is finished */
3597 if (trace_empty(iter
)) {
3602 if (cnt
>= PAGE_SIZE
)
3603 cnt
= PAGE_SIZE
- 1;
3605 /* reset all but tr, trace, and overruns */
3606 memset(&iter
->seq
, 0,
3607 sizeof(struct trace_iterator
) -
3608 offsetof(struct trace_iterator
, seq
));
3611 trace_event_read_lock();
3612 trace_access_lock(iter
->cpu_file
);
3613 while (trace_find_next_entry_inc(iter
) != NULL
) {
3614 enum print_line_t ret
;
3615 int len
= iter
->seq
.len
;
3617 ret
= print_trace_line(iter
);
3618 if (ret
== TRACE_TYPE_PARTIAL_LINE
) {
3619 /* don't print partial lines */
3620 iter
->seq
.len
= len
;
3623 if (ret
!= TRACE_TYPE_NO_CONSUME
)
3624 trace_consume(iter
);
3626 if (iter
->seq
.len
>= cnt
)
3630 * Setting the full flag means we reached the trace_seq buffer
3631 * size and we should leave by partial output condition above.
3632 * One of the trace_seq_* functions is not used properly.
3634 WARN_ONCE(iter
->seq
.full
, "full flag set for trace type %d",
3637 trace_access_unlock(iter
->cpu_file
);
3638 trace_event_read_unlock();
3640 /* Now copy what we have to the user */
3641 sret
= trace_seq_to_user(&iter
->seq
, ubuf
, cnt
);
3642 if (iter
->seq
.readpos
>= iter
->seq
.len
)
3643 trace_seq_init(&iter
->seq
);
3646 * If there was nothing to send to user, in spite of consuming trace
3647 * entries, go back to wait for more entries.
3653 mutex_unlock(&iter
->mutex
);
3658 static void tracing_pipe_buf_release(struct pipe_inode_info
*pipe
,
3659 struct pipe_buffer
*buf
)
3661 __free_page(buf
->page
);
3664 static void tracing_spd_release_pipe(struct splice_pipe_desc
*spd
,
3667 __free_page(spd
->pages
[idx
]);
3670 static const struct pipe_buf_operations tracing_pipe_buf_ops
= {
3672 .map
= generic_pipe_buf_map
,
3673 .unmap
= generic_pipe_buf_unmap
,
3674 .confirm
= generic_pipe_buf_confirm
,
3675 .release
= tracing_pipe_buf_release
,
3676 .steal
= generic_pipe_buf_steal
,
3677 .get
= generic_pipe_buf_get
,
3681 tracing_fill_pipe_page(size_t rem
, struct trace_iterator
*iter
)
3686 /* Seq buffer is page-sized, exactly what we need. */
3688 count
= iter
->seq
.len
;
3689 ret
= print_trace_line(iter
);
3690 count
= iter
->seq
.len
- count
;
3693 iter
->seq
.len
-= count
;
3696 if (ret
== TRACE_TYPE_PARTIAL_LINE
) {
3697 iter
->seq
.len
-= count
;
3701 if (ret
!= TRACE_TYPE_NO_CONSUME
)
3702 trace_consume(iter
);
3704 if (!trace_find_next_entry_inc(iter
)) {
3714 static ssize_t
tracing_splice_read_pipe(struct file
*filp
,
3716 struct pipe_inode_info
*pipe
,
3720 struct page
*pages_def
[PIPE_DEF_BUFFERS
];
3721 struct partial_page partial_def
[PIPE_DEF_BUFFERS
];
3722 struct trace_iterator
*iter
= filp
->private_data
;
3723 struct splice_pipe_desc spd
= {
3725 .partial
= partial_def
,
3726 .nr_pages
= 0, /* This gets updated below. */
3727 .nr_pages_max
= PIPE_DEF_BUFFERS
,
3729 .ops
= &tracing_pipe_buf_ops
,
3730 .spd_release
= tracing_spd_release_pipe
,
3736 if (splice_grow_spd(pipe
, &spd
))
3739 /* copy the tracer to avoid using a global lock all around */
3740 mutex_lock(&trace_types_lock
);
3741 if (unlikely(iter
->trace
->name
!= current_trace
->name
))
3742 *iter
->trace
= *current_trace
;
3743 mutex_unlock(&trace_types_lock
);
3745 mutex_lock(&iter
->mutex
);
3747 if (iter
->trace
->splice_read
) {
3748 ret
= iter
->trace
->splice_read(iter
, filp
,
3749 ppos
, pipe
, len
, flags
);
3754 ret
= tracing_wait_pipe(filp
);
3758 if (!iter
->ent
&& !trace_find_next_entry_inc(iter
)) {
3763 trace_event_read_lock();
3764 trace_access_lock(iter
->cpu_file
);
3766 /* Fill as many pages as possible. */
3767 for (i
= 0, rem
= len
; i
< pipe
->buffers
&& rem
; i
++) {
3768 spd
.pages
[i
] = alloc_page(GFP_KERNEL
);
3772 rem
= tracing_fill_pipe_page(rem
, iter
);
3774 /* Copy the data into the page, so we can start over. */
3775 ret
= trace_seq_to_buffer(&iter
->seq
,
3776 page_address(spd
.pages
[i
]),
3779 __free_page(spd
.pages
[i
]);
3782 spd
.partial
[i
].offset
= 0;
3783 spd
.partial
[i
].len
= iter
->seq
.len
;
3785 trace_seq_init(&iter
->seq
);
3788 trace_access_unlock(iter
->cpu_file
);
3789 trace_event_read_unlock();
3790 mutex_unlock(&iter
->mutex
);
3794 ret
= splice_to_pipe(pipe
, &spd
);
3796 splice_shrink_spd(&spd
);
3800 mutex_unlock(&iter
->mutex
);
3804 struct ftrace_entries_info
{
3805 struct trace_array
*tr
;
3809 static int tracing_entries_open(struct inode
*inode
, struct file
*filp
)
3811 struct ftrace_entries_info
*info
;
3813 if (tracing_disabled
)
3816 info
= kzalloc(sizeof(*info
), GFP_KERNEL
);
3820 info
->tr
= &global_trace
;
3821 info
->cpu
= (unsigned long)inode
->i_private
;
3823 filp
->private_data
= info
;
3829 tracing_entries_read(struct file
*filp
, char __user
*ubuf
,
3830 size_t cnt
, loff_t
*ppos
)
3832 struct ftrace_entries_info
*info
= filp
->private_data
;
3833 struct trace_array
*tr
= info
->tr
;
3838 mutex_lock(&trace_types_lock
);
3840 if (info
->cpu
== RING_BUFFER_ALL_CPUS
) {
3841 int cpu
, buf_size_same
;
3846 /* check if all cpu sizes are same */
3847 for_each_tracing_cpu(cpu
) {
3848 /* fill in the size from first enabled cpu */
3850 size
= tr
->data
[cpu
]->entries
;
3851 if (size
!= tr
->data
[cpu
]->entries
) {
3857 if (buf_size_same
) {
3858 if (!ring_buffer_expanded
)
3859 r
= sprintf(buf
, "%lu (expanded: %lu)\n",
3861 trace_buf_size
>> 10);
3863 r
= sprintf(buf
, "%lu\n", size
>> 10);
3865 r
= sprintf(buf
, "X\n");
3867 r
= sprintf(buf
, "%lu\n", tr
->data
[info
->cpu
]->entries
>> 10);
3869 mutex_unlock(&trace_types_lock
);
3871 ret
= simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
3876 tracing_entries_write(struct file
*filp
, const char __user
*ubuf
,
3877 size_t cnt
, loff_t
*ppos
)
3879 struct ftrace_entries_info
*info
= filp
->private_data
;
3883 ret
= kstrtoul_from_user(ubuf
, cnt
, 10, &val
);
3887 /* must have at least 1 entry */
3891 /* value is in KB */
3894 ret
= tracing_resize_ring_buffer(val
, info
->cpu
);
3904 tracing_entries_release(struct inode
*inode
, struct file
*filp
)
3906 struct ftrace_entries_info
*info
= filp
->private_data
;
3914 tracing_total_entries_read(struct file
*filp
, char __user
*ubuf
,
3915 size_t cnt
, loff_t
*ppos
)
3917 struct trace_array
*tr
= filp
->private_data
;
3920 unsigned long size
= 0, expanded_size
= 0;
3922 mutex_lock(&trace_types_lock
);
3923 for_each_tracing_cpu(cpu
) {
3924 size
+= tr
->data
[cpu
]->entries
>> 10;
3925 if (!ring_buffer_expanded
)
3926 expanded_size
+= trace_buf_size
>> 10;
3928 if (ring_buffer_expanded
)
3929 r
= sprintf(buf
, "%lu\n", size
);
3931 r
= sprintf(buf
, "%lu (expanded: %lu)\n", size
, expanded_size
);
3932 mutex_unlock(&trace_types_lock
);
3934 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
3938 tracing_free_buffer_write(struct file
*filp
, const char __user
*ubuf
,
3939 size_t cnt
, loff_t
*ppos
)
3942 * There is no need to read what the user has written, this function
3943 * is just to make sure that there is no error when "echo" is used
3952 tracing_free_buffer_release(struct inode
*inode
, struct file
*filp
)
3954 /* disable tracing ? */
3955 if (trace_flags
& TRACE_ITER_STOP_ON_FREE
)
3957 /* resize the ring buffer to 0 */
3958 tracing_resize_ring_buffer(0, RING_BUFFER_ALL_CPUS
);
3964 tracing_mark_write(struct file
*filp
, const char __user
*ubuf
,
3965 size_t cnt
, loff_t
*fpos
)
3967 unsigned long addr
= (unsigned long)ubuf
;
3968 struct ring_buffer_event
*event
;
3969 struct ring_buffer
*buffer
;
3970 struct print_entry
*entry
;
3971 unsigned long irq_flags
;
3972 struct page
*pages
[2];
3982 if (tracing_disabled
)
3985 if (!(trace_flags
& TRACE_ITER_MARKERS
))
3988 if (cnt
> TRACE_BUF_SIZE
)
3989 cnt
= TRACE_BUF_SIZE
;
3992 * Userspace is injecting traces into the kernel trace buffer.
3993 * We want to be as non intrusive as possible.
3994 * To do so, we do not want to allocate any special buffers
3995 * or take any locks, but instead write the userspace data
3996 * straight into the ring buffer.
3998 * First we need to pin the userspace buffer into memory,
3999 * which, most likely it is, because it just referenced it.
4000 * But there's no guarantee that it is. By using get_user_pages_fast()
4001 * and kmap_atomic/kunmap_atomic() we can get access to the
4002 * pages directly. We then write the data directly into the
4005 BUILD_BUG_ON(TRACE_BUF_SIZE
>= PAGE_SIZE
);
4007 /* check if we cross pages */
4008 if ((addr
& PAGE_MASK
) != ((addr
+ cnt
) & PAGE_MASK
))
4011 offset
= addr
& (PAGE_SIZE
- 1);
4014 ret
= get_user_pages_fast(addr
, nr_pages
, 0, pages
);
4015 if (ret
< nr_pages
) {
4017 put_page(pages
[ret
]);
4022 for (i
= 0; i
< nr_pages
; i
++)
4023 map_page
[i
] = kmap_atomic(pages
[i
]);
4025 local_save_flags(irq_flags
);
4026 size
= sizeof(*entry
) + cnt
+ 2; /* possible \n added */
4027 buffer
= global_trace
.buffer
;
4028 event
= trace_buffer_lock_reserve(buffer
, TRACE_PRINT
, size
,
4029 irq_flags
, preempt_count());
4031 /* Ring buffer disabled, return as if not open for write */
4036 entry
= ring_buffer_event_data(event
);
4037 entry
->ip
= _THIS_IP_
;
4039 if (nr_pages
== 2) {
4040 len
= PAGE_SIZE
- offset
;
4041 memcpy(&entry
->buf
, map_page
[0] + offset
, len
);
4042 memcpy(&entry
->buf
[len
], map_page
[1], cnt
- len
);
4044 memcpy(&entry
->buf
, map_page
[0] + offset
, cnt
);
4046 if (entry
->buf
[cnt
- 1] != '\n') {
4047 entry
->buf
[cnt
] = '\n';
4048 entry
->buf
[cnt
+ 1] = '\0';
4050 entry
->buf
[cnt
] = '\0';
4052 __buffer_unlock_commit(buffer
, event
);
4059 for (i
= 0; i
< nr_pages
; i
++){
4060 kunmap_atomic(map_page
[i
]);
4067 static int tracing_clock_show(struct seq_file
*m
, void *v
)
4071 for (i
= 0; i
< ARRAY_SIZE(trace_clocks
); i
++)
4073 "%s%s%s%s", i
? " " : "",
4074 i
== trace_clock_id
? "[" : "", trace_clocks
[i
].name
,
4075 i
== trace_clock_id
? "]" : "");
4081 static ssize_t
tracing_clock_write(struct file
*filp
, const char __user
*ubuf
,
4082 size_t cnt
, loff_t
*fpos
)
4085 const char *clockstr
;
4088 if (cnt
>= sizeof(buf
))
4091 if (copy_from_user(&buf
, ubuf
, cnt
))
4096 clockstr
= strstrip(buf
);
4098 for (i
= 0; i
< ARRAY_SIZE(trace_clocks
); i
++) {
4099 if (strcmp(trace_clocks
[i
].name
, clockstr
) == 0)
4102 if (i
== ARRAY_SIZE(trace_clocks
))
4107 mutex_lock(&trace_types_lock
);
4109 ring_buffer_set_clock(global_trace
.buffer
, trace_clocks
[i
].func
);
4111 ring_buffer_set_clock(max_tr
.buffer
, trace_clocks
[i
].func
);
4114 * New clock may not be consistent with the previous clock.
4115 * Reset the buffer so that it doesn't have incomparable timestamps.
4117 tracing_reset_online_cpus(&global_trace
);
4118 tracing_reset_online_cpus(&max_tr
);
4120 mutex_unlock(&trace_types_lock
);
4127 static int tracing_clock_open(struct inode
*inode
, struct file
*file
)
4129 if (tracing_disabled
)
4131 return single_open(file
, tracing_clock_show
, NULL
);
4134 #ifdef CONFIG_TRACER_SNAPSHOT
4135 static int tracing_snapshot_open(struct inode
*inode
, struct file
*file
)
4137 struct trace_iterator
*iter
;
4140 if (file
->f_mode
& FMODE_READ
) {
4141 iter
= __tracing_open(inode
, file
, true);
4143 ret
= PTR_ERR(iter
);
4149 tracing_snapshot_write(struct file
*filp
, const char __user
*ubuf
, size_t cnt
,
4155 ret
= tracing_update_buffers();
4159 ret
= kstrtoul_from_user(ubuf
, cnt
, 10, &val
);
4163 mutex_lock(&trace_types_lock
);
4165 if (current_trace
->use_max_tr
) {
4172 if (current_trace
->allocated_snapshot
) {
4173 /* free spare buffer */
4174 ring_buffer_resize(max_tr
.buffer
, 1,
4175 RING_BUFFER_ALL_CPUS
);
4176 set_buffer_entries(&max_tr
, 1);
4177 tracing_reset_online_cpus(&max_tr
);
4178 current_trace
->allocated_snapshot
= false;
4182 if (!current_trace
->allocated_snapshot
) {
4183 /* allocate spare buffer */
4184 ret
= resize_buffer_duplicate_size(&max_tr
,
4185 &global_trace
, RING_BUFFER_ALL_CPUS
);
4188 current_trace
->allocated_snapshot
= true;
4191 local_irq_disable();
4192 /* Now, we're going to swap */
4193 update_max_tr(&global_trace
, current
, smp_processor_id());
4197 if (current_trace
->allocated_snapshot
)
4198 tracing_reset_online_cpus(&max_tr
);
4207 mutex_unlock(&trace_types_lock
);
4210 #endif /* CONFIG_TRACER_SNAPSHOT */
4213 static const struct file_operations tracing_max_lat_fops
= {
4214 .open
= tracing_open_generic
,
4215 .read
= tracing_max_lat_read
,
4216 .write
= tracing_max_lat_write
,
4217 .llseek
= generic_file_llseek
,
4220 static const struct file_operations set_tracer_fops
= {
4221 .open
= tracing_open_generic
,
4222 .read
= tracing_set_trace_read
,
4223 .write
= tracing_set_trace_write
,
4224 .llseek
= generic_file_llseek
,
4227 static const struct file_operations tracing_pipe_fops
= {
4228 .open
= tracing_open_pipe
,
4229 .poll
= tracing_poll_pipe
,
4230 .read
= tracing_read_pipe
,
4231 .splice_read
= tracing_splice_read_pipe
,
4232 .release
= tracing_release_pipe
,
4233 .llseek
= no_llseek
,
4236 static const struct file_operations tracing_entries_fops
= {
4237 .open
= tracing_entries_open
,
4238 .read
= tracing_entries_read
,
4239 .write
= tracing_entries_write
,
4240 .release
= tracing_entries_release
,
4241 .llseek
= generic_file_llseek
,
4244 static const struct file_operations tracing_total_entries_fops
= {
4245 .open
= tracing_open_generic
,
4246 .read
= tracing_total_entries_read
,
4247 .llseek
= generic_file_llseek
,
4250 static const struct file_operations tracing_free_buffer_fops
= {
4251 .write
= tracing_free_buffer_write
,
4252 .release
= tracing_free_buffer_release
,
4255 static const struct file_operations tracing_mark_fops
= {
4256 .open
= tracing_open_generic
,
4257 .write
= tracing_mark_write
,
4258 .llseek
= generic_file_llseek
,
4261 static const struct file_operations trace_clock_fops
= {
4262 .open
= tracing_clock_open
,
4264 .llseek
= seq_lseek
,
4265 .release
= single_release
,
4266 .write
= tracing_clock_write
,
4269 #ifdef CONFIG_TRACER_SNAPSHOT
4270 static const struct file_operations snapshot_fops
= {
4271 .open
= tracing_snapshot_open
,
4273 .write
= tracing_snapshot_write
,
4274 .llseek
= tracing_seek
,
4275 .release
= tracing_release
,
4277 #endif /* CONFIG_TRACER_SNAPSHOT */
4279 struct ftrace_buffer_info
{
4280 struct trace_array
*tr
;
4286 static int tracing_buffers_open(struct inode
*inode
, struct file
*filp
)
4288 int cpu
= (int)(long)inode
->i_private
;
4289 struct ftrace_buffer_info
*info
;
4291 if (tracing_disabled
)
4294 info
= kzalloc(sizeof(*info
), GFP_KERNEL
);
4298 info
->tr
= &global_trace
;
4301 /* Force reading ring buffer for first read */
4302 info
->read
= (unsigned int)-1;
4304 filp
->private_data
= info
;
4306 return nonseekable_open(inode
, filp
);
4310 tracing_buffers_read(struct file
*filp
, char __user
*ubuf
,
4311 size_t count
, loff_t
*ppos
)
4313 struct ftrace_buffer_info
*info
= filp
->private_data
;
4321 info
->spare
= ring_buffer_alloc_read_page(info
->tr
->buffer
, info
->cpu
);
4325 /* Do we have previous read data to read? */
4326 if (info
->read
< PAGE_SIZE
)
4329 trace_access_lock(info
->cpu
);
4330 ret
= ring_buffer_read_page(info
->tr
->buffer
,
4334 trace_access_unlock(info
->cpu
);
4341 size
= PAGE_SIZE
- info
->read
;
4345 ret
= copy_to_user(ubuf
, info
->spare
+ info
->read
, size
);
4356 static int tracing_buffers_release(struct inode
*inode
, struct file
*file
)
4358 struct ftrace_buffer_info
*info
= file
->private_data
;
4361 ring_buffer_free_read_page(info
->tr
->buffer
, info
->spare
);
4368 struct ring_buffer
*buffer
;
4373 static void buffer_pipe_buf_release(struct pipe_inode_info
*pipe
,
4374 struct pipe_buffer
*buf
)
4376 struct buffer_ref
*ref
= (struct buffer_ref
*)buf
->private;
4381 ring_buffer_free_read_page(ref
->buffer
, ref
->page
);
4386 static void buffer_pipe_buf_get(struct pipe_inode_info
*pipe
,
4387 struct pipe_buffer
*buf
)
4389 struct buffer_ref
*ref
= (struct buffer_ref
*)buf
->private;
4394 /* Pipe buffer operations for a buffer. */
4395 static const struct pipe_buf_operations buffer_pipe_buf_ops
= {
4397 .map
= generic_pipe_buf_map
,
4398 .unmap
= generic_pipe_buf_unmap
,
4399 .confirm
= generic_pipe_buf_confirm
,
4400 .release
= buffer_pipe_buf_release
,
4401 .steal
= generic_pipe_buf_steal
,
4402 .get
= buffer_pipe_buf_get
,
4406 * Callback from splice_to_pipe(), if we need to release some pages
4407 * at the end of the spd in case we error'ed out in filling the pipe.
4409 static void buffer_spd_release(struct splice_pipe_desc
*spd
, unsigned int i
)
4411 struct buffer_ref
*ref
=
4412 (struct buffer_ref
*)spd
->partial
[i
].private;
4417 ring_buffer_free_read_page(ref
->buffer
, ref
->page
);
4419 spd
->partial
[i
].private = 0;
4423 tracing_buffers_splice_read(struct file
*file
, loff_t
*ppos
,
4424 struct pipe_inode_info
*pipe
, size_t len
,
4427 struct ftrace_buffer_info
*info
= file
->private_data
;
4428 struct partial_page partial_def
[PIPE_DEF_BUFFERS
];
4429 struct page
*pages_def
[PIPE_DEF_BUFFERS
];
4430 struct splice_pipe_desc spd
= {
4432 .partial
= partial_def
,
4433 .nr_pages_max
= PIPE_DEF_BUFFERS
,
4435 .ops
= &buffer_pipe_buf_ops
,
4436 .spd_release
= buffer_spd_release
,
4438 struct buffer_ref
*ref
;
4439 int entries
, size
, i
;
4442 if (splice_grow_spd(pipe
, &spd
))
4445 if (*ppos
& (PAGE_SIZE
- 1)) {
4450 if (len
& (PAGE_SIZE
- 1)) {
4451 if (len
< PAGE_SIZE
) {
4458 trace_access_lock(info
->cpu
);
4459 entries
= ring_buffer_entries_cpu(info
->tr
->buffer
, info
->cpu
);
4461 for (i
= 0; i
< pipe
->buffers
&& len
&& entries
; i
++, len
-= PAGE_SIZE
) {
4465 ref
= kzalloc(sizeof(*ref
), GFP_KERNEL
);
4470 ref
->buffer
= info
->tr
->buffer
;
4471 ref
->page
= ring_buffer_alloc_read_page(ref
->buffer
, info
->cpu
);
4477 r
= ring_buffer_read_page(ref
->buffer
, &ref
->page
,
4480 ring_buffer_free_read_page(ref
->buffer
, ref
->page
);
4486 * zero out any left over data, this is going to
4489 size
= ring_buffer_page_len(ref
->page
);
4490 if (size
< PAGE_SIZE
)
4491 memset(ref
->page
+ size
, 0, PAGE_SIZE
- size
);
4493 page
= virt_to_page(ref
->page
);
4495 spd
.pages
[i
] = page
;
4496 spd
.partial
[i
].len
= PAGE_SIZE
;
4497 spd
.partial
[i
].offset
= 0;
4498 spd
.partial
[i
].private = (unsigned long)ref
;
4502 entries
= ring_buffer_entries_cpu(info
->tr
->buffer
, info
->cpu
);
4505 trace_access_unlock(info
->cpu
);
4508 /* did we read anything? */
4509 if (!spd
.nr_pages
) {
4510 if (flags
& SPLICE_F_NONBLOCK
)
4518 ret
= splice_to_pipe(pipe
, &spd
);
4519 splice_shrink_spd(&spd
);
4524 static const struct file_operations tracing_buffers_fops
= {
4525 .open
= tracing_buffers_open
,
4526 .read
= tracing_buffers_read
,
4527 .release
= tracing_buffers_release
,
4528 .splice_read
= tracing_buffers_splice_read
,
4529 .llseek
= no_llseek
,
4533 tracing_stats_read(struct file
*filp
, char __user
*ubuf
,
4534 size_t count
, loff_t
*ppos
)
4536 unsigned long cpu
= (unsigned long)filp
->private_data
;
4537 struct trace_array
*tr
= &global_trace
;
4538 struct trace_seq
*s
;
4540 unsigned long long t
;
4541 unsigned long usec_rem
;
4543 s
= kmalloc(sizeof(*s
), GFP_KERNEL
);
4549 cnt
= ring_buffer_entries_cpu(tr
->buffer
, cpu
);
4550 trace_seq_printf(s
, "entries: %ld\n", cnt
);
4552 cnt
= ring_buffer_overrun_cpu(tr
->buffer
, cpu
);
4553 trace_seq_printf(s
, "overrun: %ld\n", cnt
);
4555 cnt
= ring_buffer_commit_overrun_cpu(tr
->buffer
, cpu
);
4556 trace_seq_printf(s
, "commit overrun: %ld\n", cnt
);
4558 cnt
= ring_buffer_bytes_cpu(tr
->buffer
, cpu
);
4559 trace_seq_printf(s
, "bytes: %ld\n", cnt
);
4561 if (trace_clocks
[trace_clock_id
].in_ns
) {
4562 /* local or global for trace_clock */
4563 t
= ns2usecs(ring_buffer_oldest_event_ts(tr
->buffer
, cpu
));
4564 usec_rem
= do_div(t
, USEC_PER_SEC
);
4565 trace_seq_printf(s
, "oldest event ts: %5llu.%06lu\n",
4568 t
= ns2usecs(ring_buffer_time_stamp(tr
->buffer
, cpu
));
4569 usec_rem
= do_div(t
, USEC_PER_SEC
);
4570 trace_seq_printf(s
, "now ts: %5llu.%06lu\n", t
, usec_rem
);
4572 /* counter or tsc mode for trace_clock */
4573 trace_seq_printf(s
, "oldest event ts: %llu\n",
4574 ring_buffer_oldest_event_ts(tr
->buffer
, cpu
));
4576 trace_seq_printf(s
, "now ts: %llu\n",
4577 ring_buffer_time_stamp(tr
->buffer
, cpu
));
4580 cnt
= ring_buffer_dropped_events_cpu(tr
->buffer
, cpu
);
4581 trace_seq_printf(s
, "dropped events: %ld\n", cnt
);
4583 cnt
= ring_buffer_read_events_cpu(tr
->buffer
, cpu
);
4584 trace_seq_printf(s
, "read events: %ld\n", cnt
);
4586 count
= simple_read_from_buffer(ubuf
, count
, ppos
, s
->buffer
, s
->len
);
4593 static const struct file_operations tracing_stats_fops
= {
4594 .open
= tracing_open_generic
,
4595 .read
= tracing_stats_read
,
4596 .llseek
= generic_file_llseek
,
4599 #ifdef CONFIG_DYNAMIC_FTRACE
4601 int __weak
ftrace_arch_read_dyn_info(char *buf
, int size
)
4607 tracing_read_dyn_info(struct file
*filp
, char __user
*ubuf
,
4608 size_t cnt
, loff_t
*ppos
)
4610 static char ftrace_dyn_info_buffer
[1024];
4611 static DEFINE_MUTEX(dyn_info_mutex
);
4612 unsigned long *p
= filp
->private_data
;
4613 char *buf
= ftrace_dyn_info_buffer
;
4614 int size
= ARRAY_SIZE(ftrace_dyn_info_buffer
);
4617 mutex_lock(&dyn_info_mutex
);
4618 r
= sprintf(buf
, "%ld ", *p
);
4620 r
+= ftrace_arch_read_dyn_info(buf
+r
, (size
-1)-r
);
4623 r
= simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
4625 mutex_unlock(&dyn_info_mutex
);
4630 static const struct file_operations tracing_dyn_info_fops
= {
4631 .open
= tracing_open_generic
,
4632 .read
= tracing_read_dyn_info
,
4633 .llseek
= generic_file_llseek
,
4637 static struct dentry
*d_tracer
;
4639 struct dentry
*tracing_init_dentry(void)
4646 if (!debugfs_initialized())
4649 d_tracer
= debugfs_create_dir("tracing", NULL
);
4651 if (!d_tracer
&& !once
) {
4653 pr_warning("Could not create debugfs directory 'tracing'\n");
4660 static struct dentry
*d_percpu
;
4662 static struct dentry
*tracing_dentry_percpu(void)
4665 struct dentry
*d_tracer
;
4670 d_tracer
= tracing_init_dentry();
4675 d_percpu
= debugfs_create_dir("per_cpu", d_tracer
);
4677 if (!d_percpu
&& !once
) {
4679 pr_warning("Could not create debugfs directory 'per_cpu'\n");
4686 static void tracing_init_debugfs_percpu(long cpu
)
4688 struct dentry
*d_percpu
= tracing_dentry_percpu();
4689 struct dentry
*d_cpu
;
4690 char cpu_dir
[30]; /* 30 characters should be more than enough */
4695 snprintf(cpu_dir
, 30, "cpu%ld", cpu
);
4696 d_cpu
= debugfs_create_dir(cpu_dir
, d_percpu
);
4698 pr_warning("Could not create debugfs '%s' entry\n", cpu_dir
);
4702 /* per cpu trace_pipe */
4703 trace_create_file("trace_pipe", 0444, d_cpu
,
4704 (void *) cpu
, &tracing_pipe_fops
);
4707 trace_create_file("trace", 0644, d_cpu
,
4708 (void *) cpu
, &tracing_fops
);
4710 trace_create_file("trace_pipe_raw", 0444, d_cpu
,
4711 (void *) cpu
, &tracing_buffers_fops
);
4713 trace_create_file("stats", 0444, d_cpu
,
4714 (void *) cpu
, &tracing_stats_fops
);
4716 trace_create_file("buffer_size_kb", 0444, d_cpu
,
4717 (void *) cpu
, &tracing_entries_fops
);
4720 #ifdef CONFIG_FTRACE_SELFTEST
4721 /* Let selftest have access to static functions in this file */
4722 #include "trace_selftest.c"
4725 struct trace_option_dentry
{
4726 struct tracer_opt
*opt
;
4727 struct tracer_flags
*flags
;
4728 struct dentry
*entry
;
4732 trace_options_read(struct file
*filp
, char __user
*ubuf
, size_t cnt
,
4735 struct trace_option_dentry
*topt
= filp
->private_data
;
4738 if (topt
->flags
->val
& topt
->opt
->bit
)
4743 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, 2);
4747 trace_options_write(struct file
*filp
, const char __user
*ubuf
, size_t cnt
,
4750 struct trace_option_dentry
*topt
= filp
->private_data
;
4754 ret
= kstrtoul_from_user(ubuf
, cnt
, 10, &val
);
4758 if (val
!= 0 && val
!= 1)
4761 if (!!(topt
->flags
->val
& topt
->opt
->bit
) != val
) {
4762 mutex_lock(&trace_types_lock
);
4763 ret
= __set_tracer_option(current_trace
, topt
->flags
,
4765 mutex_unlock(&trace_types_lock
);
4776 static const struct file_operations trace_options_fops
= {
4777 .open
= tracing_open_generic
,
4778 .read
= trace_options_read
,
4779 .write
= trace_options_write
,
4780 .llseek
= generic_file_llseek
,
4784 trace_options_core_read(struct file
*filp
, char __user
*ubuf
, size_t cnt
,
4787 long index
= (long)filp
->private_data
;
4790 if (trace_flags
& (1 << index
))
4795 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, 2);
4799 trace_options_core_write(struct file
*filp
, const char __user
*ubuf
, size_t cnt
,
4802 long index
= (long)filp
->private_data
;
4806 ret
= kstrtoul_from_user(ubuf
, cnt
, 10, &val
);
4810 if (val
!= 0 && val
!= 1)
4813 mutex_lock(&trace_types_lock
);
4814 ret
= set_tracer_flag(1 << index
, val
);
4815 mutex_unlock(&trace_types_lock
);
4825 static const struct file_operations trace_options_core_fops
= {
4826 .open
= tracing_open_generic
,
4827 .read
= trace_options_core_read
,
4828 .write
= trace_options_core_write
,
4829 .llseek
= generic_file_llseek
,
4832 struct dentry
*trace_create_file(const char *name
,
4834 struct dentry
*parent
,
4836 const struct file_operations
*fops
)
4840 ret
= debugfs_create_file(name
, mode
, parent
, data
, fops
);
4842 pr_warning("Could not create debugfs '%s' entry\n", name
);
4848 static struct dentry
*trace_options_init_dentry(void)
4850 struct dentry
*d_tracer
;
4851 static struct dentry
*t_options
;
4856 d_tracer
= tracing_init_dentry();
4860 t_options
= debugfs_create_dir("options", d_tracer
);
4862 pr_warning("Could not create debugfs directory 'options'\n");
4870 create_trace_option_file(struct trace_option_dentry
*topt
,
4871 struct tracer_flags
*flags
,
4872 struct tracer_opt
*opt
)
4874 struct dentry
*t_options
;
4876 t_options
= trace_options_init_dentry();
4880 topt
->flags
= flags
;
4883 topt
->entry
= trace_create_file(opt
->name
, 0644, t_options
, topt
,
4884 &trace_options_fops
);
4888 static struct trace_option_dentry
*
4889 create_trace_option_files(struct tracer
*tracer
)
4891 struct trace_option_dentry
*topts
;
4892 struct tracer_flags
*flags
;
4893 struct tracer_opt
*opts
;
4899 flags
= tracer
->flags
;
4901 if (!flags
|| !flags
->opts
)
4906 for (cnt
= 0; opts
[cnt
].name
; cnt
++)
4909 topts
= kcalloc(cnt
+ 1, sizeof(*topts
), GFP_KERNEL
);
4913 for (cnt
= 0; opts
[cnt
].name
; cnt
++)
4914 create_trace_option_file(&topts
[cnt
], flags
,
4921 destroy_trace_option_files(struct trace_option_dentry
*topts
)
4928 for (cnt
= 0; topts
[cnt
].opt
; cnt
++) {
4929 if (topts
[cnt
].entry
)
4930 debugfs_remove(topts
[cnt
].entry
);
4936 static struct dentry
*
4937 create_trace_option_core_file(const char *option
, long index
)
4939 struct dentry
*t_options
;
4941 t_options
= trace_options_init_dentry();
4945 return trace_create_file(option
, 0644, t_options
, (void *)index
,
4946 &trace_options_core_fops
);
4949 static __init
void create_trace_options_dir(void)
4951 struct dentry
*t_options
;
4954 t_options
= trace_options_init_dentry();
4958 for (i
= 0; trace_options
[i
]; i
++)
4959 create_trace_option_core_file(trace_options
[i
], i
);
4963 rb_simple_read(struct file
*filp
, char __user
*ubuf
,
4964 size_t cnt
, loff_t
*ppos
)
4966 struct trace_array
*tr
= filp
->private_data
;
4967 struct ring_buffer
*buffer
= tr
->buffer
;
4972 r
= ring_buffer_record_is_on(buffer
);
4976 r
= sprintf(buf
, "%d\n", r
);
4978 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
4982 rb_simple_write(struct file
*filp
, const char __user
*ubuf
,
4983 size_t cnt
, loff_t
*ppos
)
4985 struct trace_array
*tr
= filp
->private_data
;
4986 struct ring_buffer
*buffer
= tr
->buffer
;
4990 ret
= kstrtoul_from_user(ubuf
, cnt
, 10, &val
);
4995 mutex_lock(&trace_types_lock
);
4997 ring_buffer_record_on(buffer
);
4998 if (current_trace
->start
)
4999 current_trace
->start(tr
);
5001 ring_buffer_record_off(buffer
);
5002 if (current_trace
->stop
)
5003 current_trace
->stop(tr
);
5005 mutex_unlock(&trace_types_lock
);
5013 static const struct file_operations rb_simple_fops
= {
5014 .open
= tracing_open_generic
,
5015 .read
= rb_simple_read
,
5016 .write
= rb_simple_write
,
5017 .llseek
= default_llseek
,
5020 static __init
int tracer_init_debugfs(void)
5022 struct dentry
*d_tracer
;
5025 trace_access_lock_init();
5027 d_tracer
= tracing_init_dentry();
5029 trace_create_file("trace_options", 0644, d_tracer
,
5030 NULL
, &tracing_iter_fops
);
5032 trace_create_file("tracing_cpumask", 0644, d_tracer
,
5033 NULL
, &tracing_cpumask_fops
);
5035 trace_create_file("trace", 0644, d_tracer
,
5036 (void *) TRACE_PIPE_ALL_CPU
, &tracing_fops
);
5038 trace_create_file("available_tracers", 0444, d_tracer
,
5039 &global_trace
, &show_traces_fops
);
5041 trace_create_file("current_tracer", 0644, d_tracer
,
5042 &global_trace
, &set_tracer_fops
);
5044 #ifdef CONFIG_TRACER_MAX_TRACE
5045 trace_create_file("tracing_max_latency", 0644, d_tracer
,
5046 &tracing_max_latency
, &tracing_max_lat_fops
);
5049 trace_create_file("tracing_thresh", 0644, d_tracer
,
5050 &tracing_thresh
, &tracing_max_lat_fops
);
5052 trace_create_file("README", 0444, d_tracer
,
5053 NULL
, &tracing_readme_fops
);
5055 trace_create_file("trace_pipe", 0444, d_tracer
,
5056 (void *) TRACE_PIPE_ALL_CPU
, &tracing_pipe_fops
);
5058 trace_create_file("buffer_size_kb", 0644, d_tracer
,
5059 (void *) RING_BUFFER_ALL_CPUS
, &tracing_entries_fops
);
5061 trace_create_file("buffer_total_size_kb", 0444, d_tracer
,
5062 &global_trace
, &tracing_total_entries_fops
);
5064 trace_create_file("free_buffer", 0644, d_tracer
,
5065 &global_trace
, &tracing_free_buffer_fops
);
5067 trace_create_file("trace_marker", 0220, d_tracer
,
5068 NULL
, &tracing_mark_fops
);
5070 trace_create_file("saved_cmdlines", 0444, d_tracer
,
5071 NULL
, &tracing_saved_cmdlines_fops
);
5073 trace_create_file("trace_clock", 0644, d_tracer
, NULL
,
5076 trace_create_file("tracing_on", 0644, d_tracer
,
5077 &global_trace
, &rb_simple_fops
);
5079 #ifdef CONFIG_DYNAMIC_FTRACE
5080 trace_create_file("dyn_ftrace_total_info", 0444, d_tracer
,
5081 &ftrace_update_tot_cnt
, &tracing_dyn_info_fops
);
5084 #ifdef CONFIG_TRACER_SNAPSHOT
5085 trace_create_file("snapshot", 0644, d_tracer
,
5086 (void *) TRACE_PIPE_ALL_CPU
, &snapshot_fops
);
5089 create_trace_options_dir();
5091 for_each_tracing_cpu(cpu
)
5092 tracing_init_debugfs_percpu(cpu
);
5097 static int trace_panic_handler(struct notifier_block
*this,
5098 unsigned long event
, void *unused
)
5100 if (ftrace_dump_on_oops
)
5101 ftrace_dump(ftrace_dump_on_oops
);
5105 static struct notifier_block trace_panic_notifier
= {
5106 .notifier_call
= trace_panic_handler
,
5108 .priority
= 150 /* priority: INT_MAX >= x >= 0 */
5111 static int trace_die_handler(struct notifier_block
*self
,
5117 if (ftrace_dump_on_oops
)
5118 ftrace_dump(ftrace_dump_on_oops
);
5126 static struct notifier_block trace_die_notifier
= {
5127 .notifier_call
= trace_die_handler
,
5132 * printk is set to max of 1024, we really don't need it that big.
5133 * Nothing should be printing 1000 characters anyway.
5135 #define TRACE_MAX_PRINT 1000
5138 * Define here KERN_TRACE so that we have one place to modify
5139 * it if we decide to change what log level the ftrace dump
5142 #define KERN_TRACE KERN_EMERG
5145 trace_printk_seq(struct trace_seq
*s
)
5147 /* Probably should print a warning here. */
5151 /* should be zero ended, but we are paranoid. */
5152 s
->buffer
[s
->len
] = 0;
5154 printk(KERN_TRACE
"%s", s
->buffer
);
5159 void trace_init_global_iter(struct trace_iterator
*iter
)
5161 iter
->tr
= &global_trace
;
5162 iter
->trace
= current_trace
;
5163 iter
->cpu_file
= TRACE_PIPE_ALL_CPU
;
5167 __ftrace_dump(bool disable_tracing
, enum ftrace_dump_mode oops_dump_mode
)
5169 static arch_spinlock_t ftrace_dump_lock
=
5170 (arch_spinlock_t
)__ARCH_SPIN_LOCK_UNLOCKED
;
5171 /* use static because iter can be a bit big for the stack */
5172 static struct trace_iterator iter
;
5173 unsigned int old_userobj
;
5174 static int dump_ran
;
5175 unsigned long flags
;
5179 local_irq_save(flags
);
5180 arch_spin_lock(&ftrace_dump_lock
);
5188 /* Did function tracer already get disabled? */
5189 if (ftrace_is_dead()) {
5190 printk("# WARNING: FUNCTION TRACING IS CORRUPTED\n");
5191 printk("# MAY BE MISSING FUNCTION EVENTS\n");
5194 if (disable_tracing
)
5197 /* Simulate the iterator */
5198 trace_init_global_iter(&iter
);
5200 for_each_tracing_cpu(cpu
) {
5201 atomic_inc(&iter
.tr
->data
[cpu
]->disabled
);
5204 old_userobj
= trace_flags
& TRACE_ITER_SYM_USEROBJ
;
5206 /* don't look at user memory in panic mode */
5207 trace_flags
&= ~TRACE_ITER_SYM_USEROBJ
;
5209 switch (oops_dump_mode
) {
5211 iter
.cpu_file
= TRACE_PIPE_ALL_CPU
;
5214 iter
.cpu_file
= raw_smp_processor_id();
5219 printk(KERN_TRACE
"Bad dumping mode, switching to all CPUs dump\n");
5220 iter
.cpu_file
= TRACE_PIPE_ALL_CPU
;
5223 printk(KERN_TRACE
"Dumping ftrace buffer:\n");
5226 * We need to stop all tracing on all CPUS to read the
5227 * the next buffer. This is a bit expensive, but is
5228 * not done often. We fill all what we can read,
5229 * and then release the locks again.
5232 while (!trace_empty(&iter
)) {
5235 printk(KERN_TRACE
"---------------------------------\n");
5239 /* reset all but tr, trace, and overruns */
5240 memset(&iter
.seq
, 0,
5241 sizeof(struct trace_iterator
) -
5242 offsetof(struct trace_iterator
, seq
));
5243 iter
.iter_flags
|= TRACE_FILE_LAT_FMT
;
5246 if (trace_find_next_entry_inc(&iter
) != NULL
) {
5249 ret
= print_trace_line(&iter
);
5250 if (ret
!= TRACE_TYPE_NO_CONSUME
)
5251 trace_consume(&iter
);
5253 touch_nmi_watchdog();
5255 trace_printk_seq(&iter
.seq
);
5259 printk(KERN_TRACE
" (ftrace buffer empty)\n");
5261 printk(KERN_TRACE
"---------------------------------\n");
5264 /* Re-enable tracing if requested */
5265 if (!disable_tracing
) {
5266 trace_flags
|= old_userobj
;
5268 for_each_tracing_cpu(cpu
) {
5269 atomic_dec(&iter
.tr
->data
[cpu
]->disabled
);
5275 arch_spin_unlock(&ftrace_dump_lock
);
5276 local_irq_restore(flags
);
5279 /* By default: disable tracing after the dump */
5280 void ftrace_dump(enum ftrace_dump_mode oops_dump_mode
)
5282 __ftrace_dump(true, oops_dump_mode
);
5284 EXPORT_SYMBOL_GPL(ftrace_dump
);
5286 __init
static int tracer_alloc_buffers(void)
5289 enum ring_buffer_flags rb_flags
;
5294 if (!alloc_cpumask_var(&tracing_buffer_mask
, GFP_KERNEL
))
5297 if (!alloc_cpumask_var(&tracing_cpumask
, GFP_KERNEL
))
5298 goto out_free_buffer_mask
;
5300 /* Only allocate trace_printk buffers if a trace_printk exists */
5301 if (__stop___trace_bprintk_fmt
!= __start___trace_bprintk_fmt
)
5302 /* Must be called before global_trace.buffer is allocated */
5303 trace_printk_init_buffers();
5305 /* To save memory, keep the ring buffer size to its minimum */
5306 if (ring_buffer_expanded
)
5307 ring_buf_size
= trace_buf_size
;
5311 rb_flags
= trace_flags
& TRACE_ITER_OVERWRITE
? RB_FL_OVERWRITE
: 0;
5313 cpumask_copy(tracing_buffer_mask
, cpu_possible_mask
);
5314 cpumask_copy(tracing_cpumask
, cpu_all_mask
);
5316 /* TODO: make the number of buffers hot pluggable with CPUS */
5317 global_trace
.buffer
= ring_buffer_alloc(ring_buf_size
, rb_flags
);
5318 if (!global_trace
.buffer
) {
5319 printk(KERN_ERR
"tracer: failed to allocate ring buffer!\n");
5321 goto out_free_cpumask
;
5323 if (global_trace
.buffer_disabled
)
5327 #ifdef CONFIG_TRACER_MAX_TRACE
5328 max_tr
.buffer
= ring_buffer_alloc(1, rb_flags
);
5329 if (!max_tr
.buffer
) {
5330 printk(KERN_ERR
"tracer: failed to allocate max ring buffer!\n");
5332 ring_buffer_free(global_trace
.buffer
);
5333 goto out_free_cpumask
;
5337 /* Allocate the first page for all buffers */
5338 for_each_tracing_cpu(i
) {
5339 global_trace
.data
[i
] = &per_cpu(global_trace_cpu
, i
);
5340 max_tr
.data
[i
] = &per_cpu(max_tr_data
, i
);
5343 set_buffer_entries(&global_trace
,
5344 ring_buffer_size(global_trace
.buffer
, 0));
5345 #ifdef CONFIG_TRACER_MAX_TRACE
5346 set_buffer_entries(&max_tr
, 1);
5349 trace_init_cmdlines();
5350 init_irq_work(&trace_work_wakeup
, trace_wake_up
);
5352 register_tracer(&nop_trace
);
5354 /* All seems OK, enable tracing */
5355 tracing_disabled
= 0;
5357 atomic_notifier_chain_register(&panic_notifier_list
,
5358 &trace_panic_notifier
);
5360 register_die_notifier(&trace_die_notifier
);
5362 while (trace_boot_options
) {
5365 option
= strsep(&trace_boot_options
, ",");
5366 trace_set_options(option
);
5372 free_cpumask_var(tracing_cpumask
);
5373 out_free_buffer_mask
:
5374 free_cpumask_var(tracing_buffer_mask
);
5379 __init
static int clear_boot_tracer(void)
5382 * The default tracer at boot buffer is an init section.
5383 * This function is called in lateinit. If we did not
5384 * find the boot tracer, then clear it out, to prevent
5385 * later registration from accessing the buffer that is
5386 * about to be freed.
5388 if (!default_bootup_tracer
)
5391 printk(KERN_INFO
"ftrace bootup tracer '%s' not registered.\n",
5392 default_bootup_tracer
);
5393 default_bootup_tracer
= NULL
;
5398 early_initcall(tracer_alloc_buffers
);
5399 fs_initcall(tracer_init_debugfs
);
5400 late_initcall(clear_boot_tracer
);