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 strlcpy(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 strlcpy(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 (!current_trace
->allocated_snapshot
) {
748 /* Only the nop tracer should hit this when disabling */
749 WARN_ON_ONCE(current_trace
!= &nop_trace
);
753 arch_spin_lock(&ftrace_max_lock
);
755 ret
= ring_buffer_swap_cpu(max_tr
.buffer
, tr
->buffer
, cpu
);
759 * We failed to swap the buffer due to a commit taking
760 * place on this CPU. We fail to record, but we reset
761 * the max trace buffer (no one writes directly to it)
762 * and flag that it failed.
764 trace_array_printk(&max_tr
, _THIS_IP_
,
765 "Failed to swap buffers due to commit in progress\n");
768 WARN_ON_ONCE(ret
&& ret
!= -EAGAIN
&& ret
!= -EBUSY
);
770 __update_max_tr(tr
, tsk
, cpu
);
771 arch_spin_unlock(&ftrace_max_lock
);
773 #endif /* CONFIG_TRACER_MAX_TRACE */
775 static void default_wait_pipe(struct trace_iterator
*iter
)
779 prepare_to_wait(&trace_wait
, &wait
, TASK_INTERRUPTIBLE
);
782 * The events can happen in critical sections where
783 * checking a work queue can cause deadlocks.
784 * After adding a task to the queue, this flag is set
785 * only to notify events to try to wake up the queue
788 * We don't clear it even if the buffer is no longer
789 * empty. The flag only causes the next event to run
790 * irq_work to do the work queue wake up. The worse
791 * that can happen if we race with !trace_empty() is that
792 * an event will cause an irq_work to try to wake up
795 * There's no reason to protect this flag either, as
796 * the work queue and irq_work logic will do the necessary
797 * synchronization for the wake ups. The only thing
798 * that is necessary is that the wake up happens after
799 * a task has been queued. It's OK for spurious wake ups.
801 trace_wakeup_needed
= true;
803 if (trace_empty(iter
))
806 finish_wait(&trace_wait
, &wait
);
810 * register_tracer - register a tracer with the ftrace system.
811 * @type - the plugin for the tracer
813 * Register a new plugin tracer.
815 int register_tracer(struct tracer
*type
)
821 pr_info("Tracer must have a name\n");
825 if (strlen(type
->name
) >= MAX_TRACER_SIZE
) {
826 pr_info("Tracer has a name longer than %d\n", MAX_TRACER_SIZE
);
830 mutex_lock(&trace_types_lock
);
832 tracing_selftest_running
= true;
834 for (t
= trace_types
; t
; t
= t
->next
) {
835 if (strcmp(type
->name
, t
->name
) == 0) {
837 pr_info("Tracer %s already registered\n",
845 type
->set_flag
= &dummy_set_flag
;
847 type
->flags
= &dummy_tracer_flags
;
849 if (!type
->flags
->opts
)
850 type
->flags
->opts
= dummy_tracer_opt
;
851 if (!type
->wait_pipe
)
852 type
->wait_pipe
= default_wait_pipe
;
855 #ifdef CONFIG_FTRACE_STARTUP_TEST
856 if (type
->selftest
&& !tracing_selftest_disabled
) {
857 struct tracer
*saved_tracer
= current_trace
;
858 struct trace_array
*tr
= &global_trace
;
861 * Run a selftest on this tracer.
862 * Here we reset the trace buffer, and set the current
863 * tracer to be this tracer. The tracer can then run some
864 * internal tracing to verify that everything is in order.
865 * If we fail, we do not register this tracer.
867 tracing_reset_online_cpus(tr
);
869 current_trace
= type
;
871 if (type
->use_max_tr
) {
872 /* If we expanded the buffers, make sure the max is expanded too */
873 if (ring_buffer_expanded
)
874 ring_buffer_resize(max_tr
.buffer
, trace_buf_size
,
875 RING_BUFFER_ALL_CPUS
);
876 type
->allocated_snapshot
= true;
879 /* the test is responsible for initializing and enabling */
880 pr_info("Testing tracer %s: ", type
->name
);
881 ret
= type
->selftest(type
, tr
);
882 /* the test is responsible for resetting too */
883 current_trace
= saved_tracer
;
885 printk(KERN_CONT
"FAILED!\n");
886 /* Add the warning after printing 'FAILED' */
890 /* Only reset on passing, to avoid touching corrupted buffers */
891 tracing_reset_online_cpus(tr
);
893 if (type
->use_max_tr
) {
894 type
->allocated_snapshot
= false;
896 /* Shrink the max buffer again */
897 if (ring_buffer_expanded
)
898 ring_buffer_resize(max_tr
.buffer
, 1,
899 RING_BUFFER_ALL_CPUS
);
902 printk(KERN_CONT
"PASSED\n");
906 type
->next
= trace_types
;
910 tracing_selftest_running
= false;
911 mutex_unlock(&trace_types_lock
);
913 if (ret
|| !default_bootup_tracer
)
916 if (strncmp(default_bootup_tracer
, type
->name
, MAX_TRACER_SIZE
))
919 printk(KERN_INFO
"Starting tracer '%s'\n", type
->name
);
920 /* Do we want this tracer to start on bootup? */
921 tracing_set_tracer(type
->name
);
922 default_bootup_tracer
= NULL
;
923 /* disable other selftests, since this will break it. */
924 tracing_selftest_disabled
= 1;
925 #ifdef CONFIG_FTRACE_STARTUP_TEST
926 printk(KERN_INFO
"Disabling FTRACE selftests due to running tracer '%s'\n",
934 void tracing_reset(struct trace_array
*tr
, int cpu
)
936 struct ring_buffer
*buffer
= tr
->buffer
;
941 ring_buffer_record_disable(buffer
);
943 /* Make sure all commits have finished */
945 ring_buffer_reset_cpu(buffer
, cpu
);
947 ring_buffer_record_enable(buffer
);
950 void tracing_reset_online_cpus(struct trace_array
*tr
)
952 struct ring_buffer
*buffer
= tr
->buffer
;
958 ring_buffer_record_disable(buffer
);
960 /* Make sure all commits have finished */
963 tr
->time_start
= ftrace_now(tr
->cpu
);
965 for_each_online_cpu(cpu
)
966 ring_buffer_reset_cpu(buffer
, cpu
);
968 ring_buffer_record_enable(buffer
);
971 void tracing_reset_current(int cpu
)
973 tracing_reset(&global_trace
, cpu
);
976 void tracing_reset_current_online_cpus(void)
978 tracing_reset_online_cpus(&global_trace
);
981 #define SAVED_CMDLINES 128
982 #define NO_CMDLINE_MAP UINT_MAX
983 static unsigned map_pid_to_cmdline
[PID_MAX_DEFAULT
+1];
984 static unsigned map_cmdline_to_pid
[SAVED_CMDLINES
];
985 static char saved_cmdlines
[SAVED_CMDLINES
][TASK_COMM_LEN
];
986 static int cmdline_idx
;
987 static arch_spinlock_t trace_cmdline_lock
= __ARCH_SPIN_LOCK_UNLOCKED
;
989 /* temporary disable recording */
990 static atomic_t trace_record_cmdline_disabled __read_mostly
;
992 static void trace_init_cmdlines(void)
994 memset(&map_pid_to_cmdline
, NO_CMDLINE_MAP
, sizeof(map_pid_to_cmdline
));
995 memset(&map_cmdline_to_pid
, NO_CMDLINE_MAP
, sizeof(map_cmdline_to_pid
));
999 int is_tracing_stopped(void)
1001 return trace_stop_count
;
1005 * ftrace_off_permanent - disable all ftrace code permanently
1007 * This should only be called when a serious anomally has
1008 * been detected. This will turn off the function tracing,
1009 * ring buffers, and other tracing utilites. It takes no
1010 * locks and can be called from any context.
1012 void ftrace_off_permanent(void)
1014 tracing_disabled
= 1;
1016 tracing_off_permanent();
1020 * tracing_start - quick start of the tracer
1022 * If tracing is enabled but was stopped by tracing_stop,
1023 * this will start the tracer back up.
1025 void tracing_start(void)
1027 struct ring_buffer
*buffer
;
1028 unsigned long flags
;
1030 if (tracing_disabled
)
1033 raw_spin_lock_irqsave(&tracing_start_lock
, flags
);
1034 if (--trace_stop_count
) {
1035 if (trace_stop_count
< 0) {
1036 /* Someone screwed up their debugging */
1038 trace_stop_count
= 0;
1043 /* Prevent the buffers from switching */
1044 arch_spin_lock(&ftrace_max_lock
);
1046 buffer
= global_trace
.buffer
;
1048 ring_buffer_record_enable(buffer
);
1050 buffer
= max_tr
.buffer
;
1052 ring_buffer_record_enable(buffer
);
1054 arch_spin_unlock(&ftrace_max_lock
);
1058 raw_spin_unlock_irqrestore(&tracing_start_lock
, flags
);
1062 * tracing_stop - quick stop of the tracer
1064 * Light weight way to stop tracing. Use in conjunction with
1067 void tracing_stop(void)
1069 struct ring_buffer
*buffer
;
1070 unsigned long flags
;
1073 raw_spin_lock_irqsave(&tracing_start_lock
, flags
);
1074 if (trace_stop_count
++)
1077 /* Prevent the buffers from switching */
1078 arch_spin_lock(&ftrace_max_lock
);
1080 buffer
= global_trace
.buffer
;
1082 ring_buffer_record_disable(buffer
);
1084 buffer
= max_tr
.buffer
;
1086 ring_buffer_record_disable(buffer
);
1088 arch_spin_unlock(&ftrace_max_lock
);
1091 raw_spin_unlock_irqrestore(&tracing_start_lock
, flags
);
1094 void trace_stop_cmdline_recording(void);
1096 static void trace_save_cmdline(struct task_struct
*tsk
)
1100 if (!tsk
->pid
|| unlikely(tsk
->pid
> PID_MAX_DEFAULT
))
1104 * It's not the end of the world if we don't get
1105 * the lock, but we also don't want to spin
1106 * nor do we want to disable interrupts,
1107 * so if we miss here, then better luck next time.
1109 if (!arch_spin_trylock(&trace_cmdline_lock
))
1112 idx
= map_pid_to_cmdline
[tsk
->pid
];
1113 if (idx
== NO_CMDLINE_MAP
) {
1114 idx
= (cmdline_idx
+ 1) % SAVED_CMDLINES
;
1117 * Check whether the cmdline buffer at idx has a pid
1118 * mapped. We are going to overwrite that entry so we
1119 * need to clear the map_pid_to_cmdline. Otherwise we
1120 * would read the new comm for the old pid.
1122 pid
= map_cmdline_to_pid
[idx
];
1123 if (pid
!= NO_CMDLINE_MAP
)
1124 map_pid_to_cmdline
[pid
] = NO_CMDLINE_MAP
;
1126 map_cmdline_to_pid
[idx
] = tsk
->pid
;
1127 map_pid_to_cmdline
[tsk
->pid
] = idx
;
1132 memcpy(&saved_cmdlines
[idx
], tsk
->comm
, TASK_COMM_LEN
);
1134 arch_spin_unlock(&trace_cmdline_lock
);
1137 void trace_find_cmdline(int pid
, char comm
[])
1142 strcpy(comm
, "<idle>");
1146 if (WARN_ON_ONCE(pid
< 0)) {
1147 strcpy(comm
, "<XXX>");
1151 if (pid
> PID_MAX_DEFAULT
) {
1152 strcpy(comm
, "<...>");
1157 arch_spin_lock(&trace_cmdline_lock
);
1158 map
= map_pid_to_cmdline
[pid
];
1159 if (map
!= NO_CMDLINE_MAP
)
1160 strcpy(comm
, saved_cmdlines
[map
]);
1162 strcpy(comm
, "<...>");
1164 arch_spin_unlock(&trace_cmdline_lock
);
1168 void tracing_record_cmdline(struct task_struct
*tsk
)
1170 if (atomic_read(&trace_record_cmdline_disabled
) || !tracing_is_on())
1173 if (!__this_cpu_read(trace_cmdline_save
))
1176 __this_cpu_write(trace_cmdline_save
, false);
1178 trace_save_cmdline(tsk
);
1182 tracing_generic_entry_update(struct trace_entry
*entry
, unsigned long flags
,
1185 struct task_struct
*tsk
= current
;
1187 entry
->preempt_count
= pc
& 0xff;
1188 entry
->pid
= (tsk
) ? tsk
->pid
: 0;
1190 #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
1191 (irqs_disabled_flags(flags
) ? TRACE_FLAG_IRQS_OFF
: 0) |
1193 TRACE_FLAG_IRQS_NOSUPPORT
|
1195 ((pc
& HARDIRQ_MASK
) ? TRACE_FLAG_HARDIRQ
: 0) |
1196 ((pc
& SOFTIRQ_MASK
) ? TRACE_FLAG_SOFTIRQ
: 0) |
1197 (need_resched() ? TRACE_FLAG_NEED_RESCHED
: 0);
1199 EXPORT_SYMBOL_GPL(tracing_generic_entry_update
);
1201 struct ring_buffer_event
*
1202 trace_buffer_lock_reserve(struct ring_buffer
*buffer
,
1205 unsigned long flags
, int pc
)
1207 struct ring_buffer_event
*event
;
1209 event
= ring_buffer_lock_reserve(buffer
, len
);
1210 if (event
!= NULL
) {
1211 struct trace_entry
*ent
= ring_buffer_event_data(event
);
1213 tracing_generic_entry_update(ent
, flags
, pc
);
1221 __buffer_unlock_commit(struct ring_buffer
*buffer
, struct ring_buffer_event
*event
)
1223 __this_cpu_write(trace_cmdline_save
, true);
1224 if (trace_wakeup_needed
) {
1225 trace_wakeup_needed
= false;
1226 /* irq_work_queue() supplies it's own memory barriers */
1227 irq_work_queue(&trace_work_wakeup
);
1229 ring_buffer_unlock_commit(buffer
, event
);
1233 __trace_buffer_unlock_commit(struct ring_buffer
*buffer
,
1234 struct ring_buffer_event
*event
,
1235 unsigned long flags
, int pc
)
1237 __buffer_unlock_commit(buffer
, event
);
1239 ftrace_trace_stack(buffer
, flags
, 6, pc
);
1240 ftrace_trace_userstack(buffer
, flags
, pc
);
1243 void trace_buffer_unlock_commit(struct ring_buffer
*buffer
,
1244 struct ring_buffer_event
*event
,
1245 unsigned long flags
, int pc
)
1247 __trace_buffer_unlock_commit(buffer
, event
, flags
, pc
);
1249 EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit
);
1251 struct ring_buffer_event
*
1252 trace_current_buffer_lock_reserve(struct ring_buffer
**current_rb
,
1253 int type
, unsigned long len
,
1254 unsigned long flags
, int pc
)
1256 *current_rb
= global_trace
.buffer
;
1257 return trace_buffer_lock_reserve(*current_rb
,
1258 type
, len
, flags
, pc
);
1260 EXPORT_SYMBOL_GPL(trace_current_buffer_lock_reserve
);
1262 void trace_current_buffer_unlock_commit(struct ring_buffer
*buffer
,
1263 struct ring_buffer_event
*event
,
1264 unsigned long flags
, int pc
)
1266 __trace_buffer_unlock_commit(buffer
, event
, flags
, pc
);
1268 EXPORT_SYMBOL_GPL(trace_current_buffer_unlock_commit
);
1270 void trace_buffer_unlock_commit_regs(struct ring_buffer
*buffer
,
1271 struct ring_buffer_event
*event
,
1272 unsigned long flags
, int pc
,
1273 struct pt_regs
*regs
)
1275 __buffer_unlock_commit(buffer
, event
);
1277 ftrace_trace_stack_regs(buffer
, flags
, 0, pc
, regs
);
1278 ftrace_trace_userstack(buffer
, flags
, pc
);
1280 EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit_regs
);
1282 void trace_current_buffer_discard_commit(struct ring_buffer
*buffer
,
1283 struct ring_buffer_event
*event
)
1285 ring_buffer_discard_commit(buffer
, event
);
1287 EXPORT_SYMBOL_GPL(trace_current_buffer_discard_commit
);
1290 trace_function(struct trace_array
*tr
,
1291 unsigned long ip
, unsigned long parent_ip
, unsigned long flags
,
1294 struct ftrace_event_call
*call
= &event_function
;
1295 struct ring_buffer
*buffer
= tr
->buffer
;
1296 struct ring_buffer_event
*event
;
1297 struct ftrace_entry
*entry
;
1299 /* If we are reading the ring buffer, don't trace */
1300 if (unlikely(__this_cpu_read(ftrace_cpu_disabled
)))
1303 event
= trace_buffer_lock_reserve(buffer
, TRACE_FN
, sizeof(*entry
),
1307 entry
= ring_buffer_event_data(event
);
1309 entry
->parent_ip
= parent_ip
;
1311 if (!filter_check_discard(call
, entry
, buffer
, event
))
1312 __buffer_unlock_commit(buffer
, event
);
1316 ftrace(struct trace_array
*tr
, struct trace_array_cpu
*data
,
1317 unsigned long ip
, unsigned long parent_ip
, unsigned long flags
,
1320 if (likely(!atomic_read(&data
->disabled
)))
1321 trace_function(tr
, ip
, parent_ip
, flags
, pc
);
1324 #ifdef CONFIG_STACKTRACE
1326 #define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long))
1327 struct ftrace_stack
{
1328 unsigned long calls
[FTRACE_STACK_MAX_ENTRIES
];
1331 static DEFINE_PER_CPU(struct ftrace_stack
, ftrace_stack
);
1332 static DEFINE_PER_CPU(int, ftrace_stack_reserve
);
1334 static void __ftrace_trace_stack(struct ring_buffer
*buffer
,
1335 unsigned long flags
,
1336 int skip
, int pc
, struct pt_regs
*regs
)
1338 struct ftrace_event_call
*call
= &event_kernel_stack
;
1339 struct ring_buffer_event
*event
;
1340 struct stack_entry
*entry
;
1341 struct stack_trace trace
;
1343 int size
= FTRACE_STACK_ENTRIES
;
1345 trace
.nr_entries
= 0;
1349 * Since events can happen in NMIs there's no safe way to
1350 * use the per cpu ftrace_stacks. We reserve it and if an interrupt
1351 * or NMI comes in, it will just have to use the default
1352 * FTRACE_STACK_SIZE.
1354 preempt_disable_notrace();
1356 use_stack
= __this_cpu_inc_return(ftrace_stack_reserve
);
1358 * We don't need any atomic variables, just a barrier.
1359 * If an interrupt comes in, we don't care, because it would
1360 * have exited and put the counter back to what we want.
1361 * We just need a barrier to keep gcc from moving things
1365 if (use_stack
== 1) {
1366 trace
.entries
= &__get_cpu_var(ftrace_stack
).calls
[0];
1367 trace
.max_entries
= FTRACE_STACK_MAX_ENTRIES
;
1370 save_stack_trace_regs(regs
, &trace
);
1372 save_stack_trace(&trace
);
1374 if (trace
.nr_entries
> size
)
1375 size
= trace
.nr_entries
;
1377 /* From now on, use_stack is a boolean */
1380 size
*= sizeof(unsigned long);
1382 event
= trace_buffer_lock_reserve(buffer
, TRACE_STACK
,
1383 sizeof(*entry
) + size
, flags
, pc
);
1386 entry
= ring_buffer_event_data(event
);
1388 memset(&entry
->caller
, 0, size
);
1391 memcpy(&entry
->caller
, trace
.entries
,
1392 trace
.nr_entries
* sizeof(unsigned long));
1394 trace
.max_entries
= FTRACE_STACK_ENTRIES
;
1395 trace
.entries
= entry
->caller
;
1397 save_stack_trace_regs(regs
, &trace
);
1399 save_stack_trace(&trace
);
1402 entry
->size
= trace
.nr_entries
;
1404 if (!filter_check_discard(call
, entry
, buffer
, event
))
1405 __buffer_unlock_commit(buffer
, event
);
1408 /* Again, don't let gcc optimize things here */
1410 __this_cpu_dec(ftrace_stack_reserve
);
1411 preempt_enable_notrace();
1415 void ftrace_trace_stack_regs(struct ring_buffer
*buffer
, unsigned long flags
,
1416 int skip
, int pc
, struct pt_regs
*regs
)
1418 if (!(trace_flags
& TRACE_ITER_STACKTRACE
))
1421 __ftrace_trace_stack(buffer
, flags
, skip
, pc
, regs
);
1424 void ftrace_trace_stack(struct ring_buffer
*buffer
, unsigned long flags
,
1427 if (!(trace_flags
& TRACE_ITER_STACKTRACE
))
1430 __ftrace_trace_stack(buffer
, flags
, skip
, pc
, NULL
);
1433 void __trace_stack(struct trace_array
*tr
, unsigned long flags
, int skip
,
1436 __ftrace_trace_stack(tr
->buffer
, flags
, skip
, pc
, NULL
);
1440 * trace_dump_stack - record a stack back trace in the trace buffer
1442 void trace_dump_stack(void)
1444 unsigned long flags
;
1446 if (tracing_disabled
|| tracing_selftest_running
)
1449 local_save_flags(flags
);
1451 /* skipping 3 traces, seems to get us at the caller of this function */
1452 __ftrace_trace_stack(global_trace
.buffer
, flags
, 3, preempt_count(), NULL
);
1455 static DEFINE_PER_CPU(int, user_stack_count
);
1458 ftrace_trace_userstack(struct ring_buffer
*buffer
, unsigned long flags
, int pc
)
1460 struct ftrace_event_call
*call
= &event_user_stack
;
1461 struct ring_buffer_event
*event
;
1462 struct userstack_entry
*entry
;
1463 struct stack_trace trace
;
1465 if (!(trace_flags
& TRACE_ITER_USERSTACKTRACE
))
1469 * NMIs can not handle page faults, even with fix ups.
1470 * The save user stack can (and often does) fault.
1472 if (unlikely(in_nmi()))
1476 * prevent recursion, since the user stack tracing may
1477 * trigger other kernel events.
1480 if (__this_cpu_read(user_stack_count
))
1483 __this_cpu_inc(user_stack_count
);
1485 event
= trace_buffer_lock_reserve(buffer
, TRACE_USER_STACK
,
1486 sizeof(*entry
), flags
, pc
);
1488 goto out_drop_count
;
1489 entry
= ring_buffer_event_data(event
);
1491 entry
->tgid
= current
->tgid
;
1492 memset(&entry
->caller
, 0, sizeof(entry
->caller
));
1494 trace
.nr_entries
= 0;
1495 trace
.max_entries
= FTRACE_STACK_ENTRIES
;
1497 trace
.entries
= entry
->caller
;
1499 save_stack_trace_user(&trace
);
1500 if (!filter_check_discard(call
, entry
, buffer
, event
))
1501 __buffer_unlock_commit(buffer
, event
);
1504 __this_cpu_dec(user_stack_count
);
1510 static void __trace_userstack(struct trace_array
*tr
, unsigned long flags
)
1512 ftrace_trace_userstack(tr
, flags
, preempt_count());
1516 #endif /* CONFIG_STACKTRACE */
1518 /* created for use with alloc_percpu */
1519 struct trace_buffer_struct
{
1520 char buffer
[TRACE_BUF_SIZE
];
1523 static struct trace_buffer_struct
*trace_percpu_buffer
;
1524 static struct trace_buffer_struct
*trace_percpu_sirq_buffer
;
1525 static struct trace_buffer_struct
*trace_percpu_irq_buffer
;
1526 static struct trace_buffer_struct
*trace_percpu_nmi_buffer
;
1529 * The buffer used is dependent on the context. There is a per cpu
1530 * buffer for normal context, softirq contex, hard irq context and
1531 * for NMI context. Thise allows for lockless recording.
1533 * Note, if the buffers failed to be allocated, then this returns NULL
1535 static char *get_trace_buf(void)
1537 struct trace_buffer_struct
*percpu_buffer
;
1540 * If we have allocated per cpu buffers, then we do not
1541 * need to do any locking.
1544 percpu_buffer
= trace_percpu_nmi_buffer
;
1546 percpu_buffer
= trace_percpu_irq_buffer
;
1547 else if (in_softirq())
1548 percpu_buffer
= trace_percpu_sirq_buffer
;
1550 percpu_buffer
= trace_percpu_buffer
;
1555 return this_cpu_ptr(&percpu_buffer
->buffer
[0]);
1558 static int alloc_percpu_trace_buffer(void)
1560 struct trace_buffer_struct
*buffers
;
1561 struct trace_buffer_struct
*sirq_buffers
;
1562 struct trace_buffer_struct
*irq_buffers
;
1563 struct trace_buffer_struct
*nmi_buffers
;
1565 buffers
= alloc_percpu(struct trace_buffer_struct
);
1569 sirq_buffers
= alloc_percpu(struct trace_buffer_struct
);
1573 irq_buffers
= alloc_percpu(struct trace_buffer_struct
);
1577 nmi_buffers
= alloc_percpu(struct trace_buffer_struct
);
1581 trace_percpu_buffer
= buffers
;
1582 trace_percpu_sirq_buffer
= sirq_buffers
;
1583 trace_percpu_irq_buffer
= irq_buffers
;
1584 trace_percpu_nmi_buffer
= nmi_buffers
;
1589 free_percpu(irq_buffers
);
1591 free_percpu(sirq_buffers
);
1593 free_percpu(buffers
);
1595 WARN(1, "Could not allocate percpu trace_printk buffer");
1599 static int buffers_allocated
;
1601 void trace_printk_init_buffers(void)
1603 if (buffers_allocated
)
1606 if (alloc_percpu_trace_buffer())
1609 pr_info("ftrace: Allocated trace_printk buffers\n");
1611 /* Expand the buffers to set size */
1612 tracing_update_buffers();
1614 buffers_allocated
= 1;
1617 * trace_printk_init_buffers() can be called by modules.
1618 * If that happens, then we need to start cmdline recording
1619 * directly here. If the global_trace.buffer is already
1620 * allocated here, then this was called by module code.
1622 if (global_trace
.buffer
)
1623 tracing_start_cmdline_record();
1626 void trace_printk_start_comm(void)
1628 /* Start tracing comms if trace printk is set */
1629 if (!buffers_allocated
)
1631 tracing_start_cmdline_record();
1634 static void trace_printk_start_stop_comm(int enabled
)
1636 if (!buffers_allocated
)
1640 tracing_start_cmdline_record();
1642 tracing_stop_cmdline_record();
1646 * trace_vbprintk - write binary msg to tracing buffer
1649 int trace_vbprintk(unsigned long ip
, const char *fmt
, va_list args
)
1651 struct ftrace_event_call
*call
= &event_bprint
;
1652 struct ring_buffer_event
*event
;
1653 struct ring_buffer
*buffer
;
1654 struct trace_array
*tr
= &global_trace
;
1655 struct bprint_entry
*entry
;
1656 unsigned long flags
;
1658 int len
= 0, size
, pc
;
1660 if (unlikely(tracing_selftest_running
|| tracing_disabled
))
1663 /* Don't pollute graph traces with trace_vprintk internals */
1664 pause_graph_tracing();
1666 pc
= preempt_count();
1667 preempt_disable_notrace();
1669 tbuffer
= get_trace_buf();
1675 len
= vbin_printf((u32
*)tbuffer
, TRACE_BUF_SIZE
/sizeof(int), fmt
, args
);
1677 if (len
> TRACE_BUF_SIZE
/sizeof(int) || len
< 0)
1680 local_save_flags(flags
);
1681 size
= sizeof(*entry
) + sizeof(u32
) * len
;
1682 buffer
= tr
->buffer
;
1683 event
= trace_buffer_lock_reserve(buffer
, TRACE_BPRINT
, size
,
1687 entry
= ring_buffer_event_data(event
);
1691 memcpy(entry
->buf
, tbuffer
, sizeof(u32
) * len
);
1692 if (!filter_check_discard(call
, entry
, buffer
, event
)) {
1693 __buffer_unlock_commit(buffer
, event
);
1694 ftrace_trace_stack(buffer
, flags
, 6, pc
);
1698 preempt_enable_notrace();
1699 unpause_graph_tracing();
1703 EXPORT_SYMBOL_GPL(trace_vbprintk
);
1705 int trace_array_printk(struct trace_array
*tr
,
1706 unsigned long ip
, const char *fmt
, ...)
1711 if (!(trace_flags
& TRACE_ITER_PRINTK
))
1715 ret
= trace_array_vprintk(tr
, ip
, fmt
, ap
);
1720 int trace_array_vprintk(struct trace_array
*tr
,
1721 unsigned long ip
, const char *fmt
, va_list args
)
1723 struct ftrace_event_call
*call
= &event_print
;
1724 struct ring_buffer_event
*event
;
1725 struct ring_buffer
*buffer
;
1726 int len
= 0, size
, pc
;
1727 struct print_entry
*entry
;
1728 unsigned long flags
;
1731 if (tracing_disabled
|| tracing_selftest_running
)
1734 /* Don't pollute graph traces with trace_vprintk internals */
1735 pause_graph_tracing();
1737 pc
= preempt_count();
1738 preempt_disable_notrace();
1741 tbuffer
= get_trace_buf();
1747 len
= vsnprintf(tbuffer
, TRACE_BUF_SIZE
, fmt
, args
);
1748 if (len
> TRACE_BUF_SIZE
)
1751 local_save_flags(flags
);
1752 size
= sizeof(*entry
) + len
+ 1;
1753 buffer
= tr
->buffer
;
1754 event
= trace_buffer_lock_reserve(buffer
, TRACE_PRINT
, size
,
1758 entry
= ring_buffer_event_data(event
);
1761 memcpy(&entry
->buf
, tbuffer
, len
);
1762 entry
->buf
[len
] = '\0';
1763 if (!filter_check_discard(call
, entry
, buffer
, event
)) {
1764 __buffer_unlock_commit(buffer
, event
);
1765 ftrace_trace_stack(buffer
, flags
, 6, pc
);
1768 preempt_enable_notrace();
1769 unpause_graph_tracing();
1774 int trace_vprintk(unsigned long ip
, const char *fmt
, va_list args
)
1776 return trace_array_vprintk(&global_trace
, ip
, fmt
, args
);
1778 EXPORT_SYMBOL_GPL(trace_vprintk
);
1780 static void trace_iterator_increment(struct trace_iterator
*iter
)
1782 struct ring_buffer_iter
*buf_iter
= trace_buffer_iter(iter
, iter
->cpu
);
1786 ring_buffer_read(buf_iter
, NULL
);
1789 static struct trace_entry
*
1790 peek_next_entry(struct trace_iterator
*iter
, int cpu
, u64
*ts
,
1791 unsigned long *lost_events
)
1793 struct ring_buffer_event
*event
;
1794 struct ring_buffer_iter
*buf_iter
= trace_buffer_iter(iter
, cpu
);
1797 event
= ring_buffer_iter_peek(buf_iter
, ts
);
1799 event
= ring_buffer_peek(iter
->tr
->buffer
, cpu
, ts
,
1803 iter
->ent_size
= ring_buffer_event_length(event
);
1804 return ring_buffer_event_data(event
);
1810 static struct trace_entry
*
1811 __find_next_entry(struct trace_iterator
*iter
, int *ent_cpu
,
1812 unsigned long *missing_events
, u64
*ent_ts
)
1814 struct ring_buffer
*buffer
= iter
->tr
->buffer
;
1815 struct trace_entry
*ent
, *next
= NULL
;
1816 unsigned long lost_events
= 0, next_lost
= 0;
1817 int cpu_file
= iter
->cpu_file
;
1818 u64 next_ts
= 0, ts
;
1824 * If we are in a per_cpu trace file, don't bother by iterating over
1825 * all cpu and peek directly.
1827 if (cpu_file
> TRACE_PIPE_ALL_CPU
) {
1828 if (ring_buffer_empty_cpu(buffer
, cpu_file
))
1830 ent
= peek_next_entry(iter
, cpu_file
, ent_ts
, missing_events
);
1832 *ent_cpu
= cpu_file
;
1837 for_each_tracing_cpu(cpu
) {
1839 if (ring_buffer_empty_cpu(buffer
, cpu
))
1842 ent
= peek_next_entry(iter
, cpu
, &ts
, &lost_events
);
1845 * Pick the entry with the smallest timestamp:
1847 if (ent
&& (!next
|| ts
< next_ts
)) {
1851 next_lost
= lost_events
;
1852 next_size
= iter
->ent_size
;
1856 iter
->ent_size
= next_size
;
1859 *ent_cpu
= next_cpu
;
1865 *missing_events
= next_lost
;
1870 /* Find the next real entry, without updating the iterator itself */
1871 struct trace_entry
*trace_find_next_entry(struct trace_iterator
*iter
,
1872 int *ent_cpu
, u64
*ent_ts
)
1874 return __find_next_entry(iter
, ent_cpu
, NULL
, ent_ts
);
1877 /* Find the next real entry, and increment the iterator to the next entry */
1878 void *trace_find_next_entry_inc(struct trace_iterator
*iter
)
1880 iter
->ent
= __find_next_entry(iter
, &iter
->cpu
,
1881 &iter
->lost_events
, &iter
->ts
);
1884 trace_iterator_increment(iter
);
1886 return iter
->ent
? iter
: NULL
;
1889 static void trace_consume(struct trace_iterator
*iter
)
1891 ring_buffer_consume(iter
->tr
->buffer
, iter
->cpu
, &iter
->ts
,
1892 &iter
->lost_events
);
1895 static void *s_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
1897 struct trace_iterator
*iter
= m
->private;
1901 WARN_ON_ONCE(iter
->leftover
);
1905 /* can't go backwards */
1910 ent
= trace_find_next_entry_inc(iter
);
1914 while (ent
&& iter
->idx
< i
)
1915 ent
= trace_find_next_entry_inc(iter
);
1922 void tracing_iter_reset(struct trace_iterator
*iter
, int cpu
)
1924 struct trace_array
*tr
= iter
->tr
;
1925 struct ring_buffer_event
*event
;
1926 struct ring_buffer_iter
*buf_iter
;
1927 unsigned long entries
= 0;
1930 tr
->data
[cpu
]->skipped_entries
= 0;
1932 buf_iter
= trace_buffer_iter(iter
, cpu
);
1936 ring_buffer_iter_reset(buf_iter
);
1939 * We could have the case with the max latency tracers
1940 * that a reset never took place on a cpu. This is evident
1941 * by the timestamp being before the start of the buffer.
1943 while ((event
= ring_buffer_iter_peek(buf_iter
, &ts
))) {
1944 if (ts
>= iter
->tr
->time_start
)
1947 ring_buffer_read(buf_iter
, NULL
);
1950 tr
->data
[cpu
]->skipped_entries
= entries
;
1954 * The current tracer is copied to avoid a global locking
1957 static void *s_start(struct seq_file
*m
, loff_t
*pos
)
1959 struct trace_iterator
*iter
= m
->private;
1960 int cpu_file
= iter
->cpu_file
;
1966 * copy the tracer to avoid using a global lock all around.
1967 * iter->trace is a copy of current_trace, the pointer to the
1968 * name may be used instead of a strcmp(), as iter->trace->name
1969 * will point to the same string as current_trace->name.
1971 mutex_lock(&trace_types_lock
);
1972 if (unlikely(current_trace
&& iter
->trace
->name
!= current_trace
->name
))
1973 *iter
->trace
= *current_trace
;
1974 mutex_unlock(&trace_types_lock
);
1976 if (iter
->snapshot
&& iter
->trace
->use_max_tr
)
1977 return ERR_PTR(-EBUSY
);
1979 if (!iter
->snapshot
)
1980 atomic_inc(&trace_record_cmdline_disabled
);
1982 if (*pos
!= iter
->pos
) {
1987 if (cpu_file
== TRACE_PIPE_ALL_CPU
) {
1988 for_each_tracing_cpu(cpu
)
1989 tracing_iter_reset(iter
, cpu
);
1991 tracing_iter_reset(iter
, cpu_file
);
1994 for (p
= iter
; p
&& l
< *pos
; p
= s_next(m
, p
, &l
))
1999 * If we overflowed the seq_file before, then we want
2000 * to just reuse the trace_seq buffer again.
2006 p
= s_next(m
, p
, &l
);
2010 trace_event_read_lock();
2011 trace_access_lock(cpu_file
);
2015 static void s_stop(struct seq_file
*m
, void *p
)
2017 struct trace_iterator
*iter
= m
->private;
2019 if (iter
->snapshot
&& iter
->trace
->use_max_tr
)
2022 if (!iter
->snapshot
)
2023 atomic_dec(&trace_record_cmdline_disabled
);
2024 trace_access_unlock(iter
->cpu_file
);
2025 trace_event_read_unlock();
2029 get_total_entries(struct trace_array
*tr
, unsigned long *total
, unsigned long *entries
)
2031 unsigned long count
;
2037 for_each_tracing_cpu(cpu
) {
2038 count
= ring_buffer_entries_cpu(tr
->buffer
, cpu
);
2040 * If this buffer has skipped entries, then we hold all
2041 * entries for the trace and we need to ignore the
2042 * ones before the time stamp.
2044 if (tr
->data
[cpu
]->skipped_entries
) {
2045 count
-= tr
->data
[cpu
]->skipped_entries
;
2046 /* total is the same as the entries */
2050 ring_buffer_overrun_cpu(tr
->buffer
, cpu
);
2055 static void print_lat_help_header(struct seq_file
*m
)
2057 seq_puts(m
, "# _------=> CPU# \n");
2058 seq_puts(m
, "# / _-----=> irqs-off \n");
2059 seq_puts(m
, "# | / _----=> need-resched \n");
2060 seq_puts(m
, "# || / _---=> hardirq/softirq \n");
2061 seq_puts(m
, "# ||| / _--=> preempt-depth \n");
2062 seq_puts(m
, "# |||| / delay \n");
2063 seq_puts(m
, "# cmd pid ||||| time | caller \n");
2064 seq_puts(m
, "# \\ / ||||| \\ | / \n");
2067 static void print_event_info(struct trace_array
*tr
, struct seq_file
*m
)
2069 unsigned long total
;
2070 unsigned long entries
;
2072 get_total_entries(tr
, &total
, &entries
);
2073 seq_printf(m
, "# entries-in-buffer/entries-written: %lu/%lu #P:%d\n",
2074 entries
, total
, num_online_cpus());
2078 static void print_func_help_header(struct trace_array
*tr
, struct seq_file
*m
)
2080 print_event_info(tr
, m
);
2081 seq_puts(m
, "# TASK-PID CPU# TIMESTAMP FUNCTION\n");
2082 seq_puts(m
, "# | | | | |\n");
2085 static void print_func_help_header_irq(struct trace_array
*tr
, struct seq_file
*m
)
2087 print_event_info(tr
, m
);
2088 seq_puts(m
, "# _-----=> irqs-off\n");
2089 seq_puts(m
, "# / _----=> need-resched\n");
2090 seq_puts(m
, "# | / _---=> hardirq/softirq\n");
2091 seq_puts(m
, "# || / _--=> preempt-depth\n");
2092 seq_puts(m
, "# ||| / delay\n");
2093 seq_puts(m
, "# TASK-PID CPU# |||| TIMESTAMP FUNCTION\n");
2094 seq_puts(m
, "# | | | |||| | |\n");
2098 print_trace_header(struct seq_file
*m
, struct trace_iterator
*iter
)
2100 unsigned long sym_flags
= (trace_flags
& TRACE_ITER_SYM_MASK
);
2101 struct trace_array
*tr
= iter
->tr
;
2102 struct trace_array_cpu
*data
= tr
->data
[tr
->cpu
];
2103 struct tracer
*type
= current_trace
;
2104 unsigned long entries
;
2105 unsigned long total
;
2106 const char *name
= "preemption";
2110 get_total_entries(tr
, &total
, &entries
);
2112 seq_printf(m
, "# %s latency trace v1.1.5 on %s\n",
2114 seq_puts(m
, "# -----------------------------------"
2115 "---------------------------------\n");
2116 seq_printf(m
, "# latency: %lu us, #%lu/%lu, CPU#%d |"
2117 " (M:%s VP:%d, KP:%d, SP:%d HP:%d",
2118 nsecs_to_usecs(data
->saved_latency
),
2122 #if defined(CONFIG_PREEMPT_NONE)
2124 #elif defined(CONFIG_PREEMPT_VOLUNTARY)
2126 #elif defined(CONFIG_PREEMPT)
2131 /* These are reserved for later use */
2134 seq_printf(m
, " #P:%d)\n", num_online_cpus());
2138 seq_puts(m
, "# -----------------\n");
2139 seq_printf(m
, "# | task: %.16s-%d "
2140 "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n",
2141 data
->comm
, data
->pid
,
2142 from_kuid_munged(seq_user_ns(m
), data
->uid
), data
->nice
,
2143 data
->policy
, data
->rt_priority
);
2144 seq_puts(m
, "# -----------------\n");
2146 if (data
->critical_start
) {
2147 seq_puts(m
, "# => started at: ");
2148 seq_print_ip_sym(&iter
->seq
, data
->critical_start
, sym_flags
);
2149 trace_print_seq(m
, &iter
->seq
);
2150 seq_puts(m
, "\n# => ended at: ");
2151 seq_print_ip_sym(&iter
->seq
, data
->critical_end
, sym_flags
);
2152 trace_print_seq(m
, &iter
->seq
);
2153 seq_puts(m
, "\n#\n");
2159 static void test_cpu_buff_start(struct trace_iterator
*iter
)
2161 struct trace_seq
*s
= &iter
->seq
;
2163 if (!(trace_flags
& TRACE_ITER_ANNOTATE
))
2166 if (!(iter
->iter_flags
& TRACE_FILE_ANNOTATE
))
2169 if (cpumask_test_cpu(iter
->cpu
, iter
->started
))
2172 if (iter
->tr
->data
[iter
->cpu
]->skipped_entries
)
2175 cpumask_set_cpu(iter
->cpu
, iter
->started
);
2177 /* Don't print started cpu buffer for the first entry of the trace */
2179 trace_seq_printf(s
, "##### CPU %u buffer started ####\n",
2183 static enum print_line_t
print_trace_fmt(struct trace_iterator
*iter
)
2185 struct trace_seq
*s
= &iter
->seq
;
2186 unsigned long sym_flags
= (trace_flags
& TRACE_ITER_SYM_MASK
);
2187 struct trace_entry
*entry
;
2188 struct trace_event
*event
;
2192 test_cpu_buff_start(iter
);
2194 event
= ftrace_find_event(entry
->type
);
2196 if (trace_flags
& TRACE_ITER_CONTEXT_INFO
) {
2197 if (iter
->iter_flags
& TRACE_FILE_LAT_FMT
) {
2198 if (!trace_print_lat_context(iter
))
2201 if (!trace_print_context(iter
))
2207 return event
->funcs
->trace(iter
, sym_flags
, event
);
2209 if (!trace_seq_printf(s
, "Unknown type %d\n", entry
->type
))
2212 return TRACE_TYPE_HANDLED
;
2214 return TRACE_TYPE_PARTIAL_LINE
;
2217 static enum print_line_t
print_raw_fmt(struct trace_iterator
*iter
)
2219 struct trace_seq
*s
= &iter
->seq
;
2220 struct trace_entry
*entry
;
2221 struct trace_event
*event
;
2225 if (trace_flags
& TRACE_ITER_CONTEXT_INFO
) {
2226 if (!trace_seq_printf(s
, "%d %d %llu ",
2227 entry
->pid
, iter
->cpu
, iter
->ts
))
2231 event
= ftrace_find_event(entry
->type
);
2233 return event
->funcs
->raw(iter
, 0, event
);
2235 if (!trace_seq_printf(s
, "%d ?\n", entry
->type
))
2238 return TRACE_TYPE_HANDLED
;
2240 return TRACE_TYPE_PARTIAL_LINE
;
2243 static enum print_line_t
print_hex_fmt(struct trace_iterator
*iter
)
2245 struct trace_seq
*s
= &iter
->seq
;
2246 unsigned char newline
= '\n';
2247 struct trace_entry
*entry
;
2248 struct trace_event
*event
;
2252 if (trace_flags
& TRACE_ITER_CONTEXT_INFO
) {
2253 SEQ_PUT_HEX_FIELD_RET(s
, entry
->pid
);
2254 SEQ_PUT_HEX_FIELD_RET(s
, iter
->cpu
);
2255 SEQ_PUT_HEX_FIELD_RET(s
, iter
->ts
);
2258 event
= ftrace_find_event(entry
->type
);
2260 enum print_line_t ret
= event
->funcs
->hex(iter
, 0, event
);
2261 if (ret
!= TRACE_TYPE_HANDLED
)
2265 SEQ_PUT_FIELD_RET(s
, newline
);
2267 return TRACE_TYPE_HANDLED
;
2270 static enum print_line_t
print_bin_fmt(struct trace_iterator
*iter
)
2272 struct trace_seq
*s
= &iter
->seq
;
2273 struct trace_entry
*entry
;
2274 struct trace_event
*event
;
2278 if (trace_flags
& TRACE_ITER_CONTEXT_INFO
) {
2279 SEQ_PUT_FIELD_RET(s
, entry
->pid
);
2280 SEQ_PUT_FIELD_RET(s
, iter
->cpu
);
2281 SEQ_PUT_FIELD_RET(s
, iter
->ts
);
2284 event
= ftrace_find_event(entry
->type
);
2285 return event
? event
->funcs
->binary(iter
, 0, event
) :
2289 int trace_empty(struct trace_iterator
*iter
)
2291 struct ring_buffer_iter
*buf_iter
;
2294 /* If we are looking at one CPU buffer, only check that one */
2295 if (iter
->cpu_file
!= TRACE_PIPE_ALL_CPU
) {
2296 cpu
= iter
->cpu_file
;
2297 buf_iter
= trace_buffer_iter(iter
, cpu
);
2299 if (!ring_buffer_iter_empty(buf_iter
))
2302 if (!ring_buffer_empty_cpu(iter
->tr
->buffer
, cpu
))
2308 for_each_tracing_cpu(cpu
) {
2309 buf_iter
= trace_buffer_iter(iter
, cpu
);
2311 if (!ring_buffer_iter_empty(buf_iter
))
2314 if (!ring_buffer_empty_cpu(iter
->tr
->buffer
, cpu
))
2322 /* Called with trace_event_read_lock() held. */
2323 enum print_line_t
print_trace_line(struct trace_iterator
*iter
)
2325 enum print_line_t ret
;
2327 if (iter
->lost_events
&&
2328 !trace_seq_printf(&iter
->seq
, "CPU:%d [LOST %lu EVENTS]\n",
2329 iter
->cpu
, iter
->lost_events
))
2330 return TRACE_TYPE_PARTIAL_LINE
;
2332 if (iter
->trace
&& iter
->trace
->print_line
) {
2333 ret
= iter
->trace
->print_line(iter
);
2334 if (ret
!= TRACE_TYPE_UNHANDLED
)
2338 if (iter
->ent
->type
== TRACE_BPRINT
&&
2339 trace_flags
& TRACE_ITER_PRINTK
&&
2340 trace_flags
& TRACE_ITER_PRINTK_MSGONLY
)
2341 return trace_print_bprintk_msg_only(iter
);
2343 if (iter
->ent
->type
== TRACE_PRINT
&&
2344 trace_flags
& TRACE_ITER_PRINTK
&&
2345 trace_flags
& TRACE_ITER_PRINTK_MSGONLY
)
2346 return trace_print_printk_msg_only(iter
);
2348 if (trace_flags
& TRACE_ITER_BIN
)
2349 return print_bin_fmt(iter
);
2351 if (trace_flags
& TRACE_ITER_HEX
)
2352 return print_hex_fmt(iter
);
2354 if (trace_flags
& TRACE_ITER_RAW
)
2355 return print_raw_fmt(iter
);
2357 return print_trace_fmt(iter
);
2360 void trace_latency_header(struct seq_file
*m
)
2362 struct trace_iterator
*iter
= m
->private;
2364 /* print nothing if the buffers are empty */
2365 if (trace_empty(iter
))
2368 if (iter
->iter_flags
& TRACE_FILE_LAT_FMT
)
2369 print_trace_header(m
, iter
);
2371 if (!(trace_flags
& TRACE_ITER_VERBOSE
))
2372 print_lat_help_header(m
);
2375 void trace_default_header(struct seq_file
*m
)
2377 struct trace_iterator
*iter
= m
->private;
2379 if (!(trace_flags
& TRACE_ITER_CONTEXT_INFO
))
2382 if (iter
->iter_flags
& TRACE_FILE_LAT_FMT
) {
2383 /* print nothing if the buffers are empty */
2384 if (trace_empty(iter
))
2386 print_trace_header(m
, iter
);
2387 if (!(trace_flags
& TRACE_ITER_VERBOSE
))
2388 print_lat_help_header(m
);
2390 if (!(trace_flags
& TRACE_ITER_VERBOSE
)) {
2391 if (trace_flags
& TRACE_ITER_IRQ_INFO
)
2392 print_func_help_header_irq(iter
->tr
, m
);
2394 print_func_help_header(iter
->tr
, m
);
2399 static void test_ftrace_alive(struct seq_file
*m
)
2401 if (!ftrace_is_dead())
2403 seq_printf(m
, "# WARNING: FUNCTION TRACING IS CORRUPTED\n");
2404 seq_printf(m
, "# MAY BE MISSING FUNCTION EVENTS\n");
2407 #ifdef CONFIG_TRACER_MAX_TRACE
2408 static void print_snapshot_help(struct seq_file
*m
, struct trace_iterator
*iter
)
2410 if (iter
->trace
->allocated_snapshot
)
2411 seq_printf(m
, "#\n# * Snapshot is allocated *\n#\n");
2413 seq_printf(m
, "#\n# * Snapshot is freed *\n#\n");
2415 seq_printf(m
, "# Snapshot commands:\n");
2416 seq_printf(m
, "# echo 0 > snapshot : Clears and frees snapshot buffer\n");
2417 seq_printf(m
, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n");
2418 seq_printf(m
, "# Takes a snapshot of the main buffer.\n");
2419 seq_printf(m
, "# echo 2 > snapshot : Clears snapshot buffer (but does not allocate)\n");
2420 seq_printf(m
, "# (Doesn't have to be '2' works with any number that\n");
2421 seq_printf(m
, "# is not a '0' or '1')\n");
2424 /* Should never be called */
2425 static inline void print_snapshot_help(struct seq_file
*m
, struct trace_iterator
*iter
) { }
2428 static int s_show(struct seq_file
*m
, void *v
)
2430 struct trace_iterator
*iter
= v
;
2433 if (iter
->ent
== NULL
) {
2435 seq_printf(m
, "# tracer: %s\n", iter
->trace
->name
);
2437 test_ftrace_alive(m
);
2439 if (iter
->snapshot
&& trace_empty(iter
))
2440 print_snapshot_help(m
, iter
);
2441 else if (iter
->trace
&& iter
->trace
->print_header
)
2442 iter
->trace
->print_header(m
);
2444 trace_default_header(m
);
2446 } else if (iter
->leftover
) {
2448 * If we filled the seq_file buffer earlier, we
2449 * want to just show it now.
2451 ret
= trace_print_seq(m
, &iter
->seq
);
2453 /* ret should this time be zero, but you never know */
2454 iter
->leftover
= ret
;
2457 print_trace_line(iter
);
2458 ret
= trace_print_seq(m
, &iter
->seq
);
2460 * If we overflow the seq_file buffer, then it will
2461 * ask us for this data again at start up.
2463 * ret is 0 if seq_file write succeeded.
2466 iter
->leftover
= ret
;
2472 static const struct seq_operations tracer_seq_ops
= {
2479 static struct trace_iterator
*
2480 __tracing_open(struct inode
*inode
, struct file
*file
, bool snapshot
)
2482 long cpu_file
= (long) inode
->i_private
;
2483 struct trace_iterator
*iter
;
2486 if (tracing_disabled
)
2487 return ERR_PTR(-ENODEV
);
2489 iter
= __seq_open_private(file
, &tracer_seq_ops
, sizeof(*iter
));
2491 return ERR_PTR(-ENOMEM
);
2493 iter
->buffer_iter
= kzalloc(sizeof(*iter
->buffer_iter
) * num_possible_cpus(),
2495 if (!iter
->buffer_iter
)
2499 * We make a copy of the current tracer to avoid concurrent
2500 * changes on it while we are reading.
2502 mutex_lock(&trace_types_lock
);
2503 iter
->trace
= kzalloc(sizeof(*iter
->trace
), GFP_KERNEL
);
2507 *iter
->trace
= *current_trace
;
2509 if (!zalloc_cpumask_var(&iter
->started
, GFP_KERNEL
))
2512 if (current_trace
->print_max
|| snapshot
)
2515 iter
->tr
= &global_trace
;
2516 iter
->snapshot
= snapshot
;
2518 mutex_init(&iter
->mutex
);
2519 iter
->cpu_file
= cpu_file
;
2521 /* Notify the tracer early; before we stop tracing. */
2522 if (iter
->trace
&& iter
->trace
->open
)
2523 iter
->trace
->open(iter
);
2525 /* Annotate start of buffers if we had overruns */
2526 if (ring_buffer_overruns(iter
->tr
->buffer
))
2527 iter
->iter_flags
|= TRACE_FILE_ANNOTATE
;
2529 /* Output in nanoseconds only if we are using a clock in nanoseconds. */
2530 if (trace_clocks
[trace_clock_id
].in_ns
)
2531 iter
->iter_flags
|= TRACE_FILE_TIME_IN_NS
;
2533 /* stop the trace while dumping if we are not opening "snapshot" */
2534 if (!iter
->snapshot
)
2537 if (iter
->cpu_file
== TRACE_PIPE_ALL_CPU
) {
2538 for_each_tracing_cpu(cpu
) {
2539 iter
->buffer_iter
[cpu
] =
2540 ring_buffer_read_prepare(iter
->tr
->buffer
, cpu
);
2542 ring_buffer_read_prepare_sync();
2543 for_each_tracing_cpu(cpu
) {
2544 ring_buffer_read_start(iter
->buffer_iter
[cpu
]);
2545 tracing_iter_reset(iter
, cpu
);
2548 cpu
= iter
->cpu_file
;
2549 iter
->buffer_iter
[cpu
] =
2550 ring_buffer_read_prepare(iter
->tr
->buffer
, cpu
);
2551 ring_buffer_read_prepare_sync();
2552 ring_buffer_read_start(iter
->buffer_iter
[cpu
]);
2553 tracing_iter_reset(iter
, cpu
);
2556 mutex_unlock(&trace_types_lock
);
2561 mutex_unlock(&trace_types_lock
);
2563 kfree(iter
->buffer_iter
);
2565 seq_release_private(inode
, file
);
2566 return ERR_PTR(-ENOMEM
);
2569 int tracing_open_generic(struct inode
*inode
, struct file
*filp
)
2571 if (tracing_disabled
)
2574 filp
->private_data
= inode
->i_private
;
2578 static int tracing_release(struct inode
*inode
, struct file
*file
)
2580 struct seq_file
*m
= file
->private_data
;
2581 struct trace_iterator
*iter
;
2584 if (!(file
->f_mode
& FMODE_READ
))
2589 mutex_lock(&trace_types_lock
);
2590 for_each_tracing_cpu(cpu
) {
2591 if (iter
->buffer_iter
[cpu
])
2592 ring_buffer_read_finish(iter
->buffer_iter
[cpu
]);
2595 if (iter
->trace
&& iter
->trace
->close
)
2596 iter
->trace
->close(iter
);
2598 if (!iter
->snapshot
)
2599 /* reenable tracing if it was previously enabled */
2601 mutex_unlock(&trace_types_lock
);
2603 mutex_destroy(&iter
->mutex
);
2604 free_cpumask_var(iter
->started
);
2606 kfree(iter
->buffer_iter
);
2607 seq_release_private(inode
, file
);
2611 static int tracing_open(struct inode
*inode
, struct file
*file
)
2613 struct trace_iterator
*iter
;
2616 /* If this file was open for write, then erase contents */
2617 if ((file
->f_mode
& FMODE_WRITE
) &&
2618 (file
->f_flags
& O_TRUNC
)) {
2619 long cpu
= (long) inode
->i_private
;
2621 if (cpu
== TRACE_PIPE_ALL_CPU
)
2622 tracing_reset_online_cpus(&global_trace
);
2624 tracing_reset(&global_trace
, cpu
);
2627 if (file
->f_mode
& FMODE_READ
) {
2628 iter
= __tracing_open(inode
, file
, false);
2630 ret
= PTR_ERR(iter
);
2631 else if (trace_flags
& TRACE_ITER_LATENCY_FMT
)
2632 iter
->iter_flags
|= TRACE_FILE_LAT_FMT
;
2638 t_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
2640 struct tracer
*t
= v
;
2650 static void *t_start(struct seq_file
*m
, loff_t
*pos
)
2655 mutex_lock(&trace_types_lock
);
2656 for (t
= trace_types
; t
&& l
< *pos
; t
= t_next(m
, t
, &l
))
2662 static void t_stop(struct seq_file
*m
, void *p
)
2664 mutex_unlock(&trace_types_lock
);
2667 static int t_show(struct seq_file
*m
, void *v
)
2669 struct tracer
*t
= v
;
2674 seq_printf(m
, "%s", t
->name
);
2683 static const struct seq_operations show_traces_seq_ops
= {
2690 static int show_traces_open(struct inode
*inode
, struct file
*file
)
2692 if (tracing_disabled
)
2695 return seq_open(file
, &show_traces_seq_ops
);
2699 tracing_write_stub(struct file
*filp
, const char __user
*ubuf
,
2700 size_t count
, loff_t
*ppos
)
2705 static loff_t
tracing_seek(struct file
*file
, loff_t offset
, int origin
)
2707 if (file
->f_mode
& FMODE_READ
)
2708 return seq_lseek(file
, offset
, origin
);
2713 static const struct file_operations tracing_fops
= {
2714 .open
= tracing_open
,
2716 .write
= tracing_write_stub
,
2717 .llseek
= tracing_seek
,
2718 .release
= tracing_release
,
2721 static const struct file_operations show_traces_fops
= {
2722 .open
= show_traces_open
,
2724 .release
= seq_release
,
2725 .llseek
= seq_lseek
,
2729 * Only trace on a CPU if the bitmask is set:
2731 static cpumask_var_t tracing_cpumask
;
2734 * The tracer itself will not take this lock, but still we want
2735 * to provide a consistent cpumask to user-space:
2737 static DEFINE_MUTEX(tracing_cpumask_update_lock
);
2740 * Temporary storage for the character representation of the
2741 * CPU bitmask (and one more byte for the newline):
2743 static char mask_str
[NR_CPUS
+ 1];
2746 tracing_cpumask_read(struct file
*filp
, char __user
*ubuf
,
2747 size_t count
, loff_t
*ppos
)
2751 mutex_lock(&tracing_cpumask_update_lock
);
2753 len
= cpumask_scnprintf(mask_str
, count
, tracing_cpumask
);
2754 if (count
- len
< 2) {
2758 len
+= sprintf(mask_str
+ len
, "\n");
2759 count
= simple_read_from_buffer(ubuf
, count
, ppos
, mask_str
, NR_CPUS
+1);
2762 mutex_unlock(&tracing_cpumask_update_lock
);
2768 tracing_cpumask_write(struct file
*filp
, const char __user
*ubuf
,
2769 size_t count
, loff_t
*ppos
)
2772 cpumask_var_t tracing_cpumask_new
;
2774 if (!alloc_cpumask_var(&tracing_cpumask_new
, GFP_KERNEL
))
2777 err
= cpumask_parse_user(ubuf
, count
, tracing_cpumask_new
);
2781 mutex_lock(&tracing_cpumask_update_lock
);
2783 local_irq_disable();
2784 arch_spin_lock(&ftrace_max_lock
);
2785 for_each_tracing_cpu(cpu
) {
2787 * Increase/decrease the disabled counter if we are
2788 * about to flip a bit in the cpumask:
2790 if (cpumask_test_cpu(cpu
, tracing_cpumask
) &&
2791 !cpumask_test_cpu(cpu
, tracing_cpumask_new
)) {
2792 atomic_inc(&global_trace
.data
[cpu
]->disabled
);
2793 ring_buffer_record_disable_cpu(global_trace
.buffer
, cpu
);
2795 if (!cpumask_test_cpu(cpu
, tracing_cpumask
) &&
2796 cpumask_test_cpu(cpu
, tracing_cpumask_new
)) {
2797 atomic_dec(&global_trace
.data
[cpu
]->disabled
);
2798 ring_buffer_record_enable_cpu(global_trace
.buffer
, cpu
);
2801 arch_spin_unlock(&ftrace_max_lock
);
2804 cpumask_copy(tracing_cpumask
, tracing_cpumask_new
);
2806 mutex_unlock(&tracing_cpumask_update_lock
);
2807 free_cpumask_var(tracing_cpumask_new
);
2812 free_cpumask_var(tracing_cpumask_new
);
2817 static const struct file_operations tracing_cpumask_fops
= {
2818 .open
= tracing_open_generic
,
2819 .read
= tracing_cpumask_read
,
2820 .write
= tracing_cpumask_write
,
2821 .llseek
= generic_file_llseek
,
2824 static int tracing_trace_options_show(struct seq_file
*m
, void *v
)
2826 struct tracer_opt
*trace_opts
;
2830 mutex_lock(&trace_types_lock
);
2831 tracer_flags
= current_trace
->flags
->val
;
2832 trace_opts
= current_trace
->flags
->opts
;
2834 for (i
= 0; trace_options
[i
]; i
++) {
2835 if (trace_flags
& (1 << i
))
2836 seq_printf(m
, "%s\n", trace_options
[i
]);
2838 seq_printf(m
, "no%s\n", trace_options
[i
]);
2841 for (i
= 0; trace_opts
[i
].name
; i
++) {
2842 if (tracer_flags
& trace_opts
[i
].bit
)
2843 seq_printf(m
, "%s\n", trace_opts
[i
].name
);
2845 seq_printf(m
, "no%s\n", trace_opts
[i
].name
);
2847 mutex_unlock(&trace_types_lock
);
2852 static int __set_tracer_option(struct tracer
*trace
,
2853 struct tracer_flags
*tracer_flags
,
2854 struct tracer_opt
*opts
, int neg
)
2858 ret
= trace
->set_flag(tracer_flags
->val
, opts
->bit
, !neg
);
2863 tracer_flags
->val
&= ~opts
->bit
;
2865 tracer_flags
->val
|= opts
->bit
;
2869 /* Try to assign a tracer specific option */
2870 static int set_tracer_option(struct tracer
*trace
, char *cmp
, int neg
)
2872 struct tracer_flags
*tracer_flags
= trace
->flags
;
2873 struct tracer_opt
*opts
= NULL
;
2876 for (i
= 0; tracer_flags
->opts
[i
].name
; i
++) {
2877 opts
= &tracer_flags
->opts
[i
];
2879 if (strcmp(cmp
, opts
->name
) == 0)
2880 return __set_tracer_option(trace
, trace
->flags
,
2887 /* Some tracers require overwrite to stay enabled */
2888 int trace_keep_overwrite(struct tracer
*tracer
, u32 mask
, int set
)
2890 if (tracer
->enabled
&& (mask
& TRACE_ITER_OVERWRITE
) && !set
)
2896 int set_tracer_flag(unsigned int mask
, int enabled
)
2898 /* do nothing if flag is already set */
2899 if (!!(trace_flags
& mask
) == !!enabled
)
2902 /* Give the tracer a chance to approve the change */
2903 if (current_trace
->flag_changed
)
2904 if (current_trace
->flag_changed(current_trace
, mask
, !!enabled
))
2908 trace_flags
|= mask
;
2910 trace_flags
&= ~mask
;
2912 if (mask
== TRACE_ITER_RECORD_CMD
)
2913 trace_event_enable_cmd_record(enabled
);
2915 if (mask
== TRACE_ITER_OVERWRITE
) {
2916 ring_buffer_change_overwrite(global_trace
.buffer
, enabled
);
2917 #ifdef CONFIG_TRACER_MAX_TRACE
2918 ring_buffer_change_overwrite(max_tr
.buffer
, enabled
);
2922 if (mask
== TRACE_ITER_PRINTK
)
2923 trace_printk_start_stop_comm(enabled
);
2928 static int trace_set_options(char *option
)
2935 cmp
= strstrip(option
);
2937 if (strncmp(cmp
, "no", 2) == 0) {
2942 mutex_lock(&trace_types_lock
);
2944 for (i
= 0; trace_options
[i
]; i
++) {
2945 if (strcmp(cmp
, trace_options
[i
]) == 0) {
2946 ret
= set_tracer_flag(1 << i
, !neg
);
2951 /* If no option could be set, test the specific tracer options */
2952 if (!trace_options
[i
])
2953 ret
= set_tracer_option(current_trace
, cmp
, neg
);
2955 mutex_unlock(&trace_types_lock
);
2961 tracing_trace_options_write(struct file
*filp
, const char __user
*ubuf
,
2962 size_t cnt
, loff_t
*ppos
)
2967 if (cnt
>= sizeof(buf
))
2970 if (copy_from_user(&buf
, ubuf
, cnt
))
2975 ret
= trace_set_options(buf
);
2984 static int tracing_trace_options_open(struct inode
*inode
, struct file
*file
)
2986 if (tracing_disabled
)
2988 return single_open(file
, tracing_trace_options_show
, NULL
);
2991 static const struct file_operations tracing_iter_fops
= {
2992 .open
= tracing_trace_options_open
,
2994 .llseek
= seq_lseek
,
2995 .release
= single_release
,
2996 .write
= tracing_trace_options_write
,
2999 static const char readme_msg
[] =
3000 "tracing mini-HOWTO:\n\n"
3001 "# mount -t debugfs nodev /sys/kernel/debug\n\n"
3002 "# cat /sys/kernel/debug/tracing/available_tracers\n"
3003 "wakeup wakeup_rt preemptirqsoff preemptoff irqsoff function nop\n\n"
3004 "# cat /sys/kernel/debug/tracing/current_tracer\n"
3006 "# echo wakeup > /sys/kernel/debug/tracing/current_tracer\n"
3007 "# cat /sys/kernel/debug/tracing/current_tracer\n"
3009 "# cat /sys/kernel/debug/tracing/trace_options\n"
3010 "noprint-parent nosym-offset nosym-addr noverbose\n"
3011 "# echo print-parent > /sys/kernel/debug/tracing/trace_options\n"
3012 "# echo 1 > /sys/kernel/debug/tracing/tracing_on\n"
3013 "# cat /sys/kernel/debug/tracing/trace > /tmp/trace.txt\n"
3014 "# echo 0 > /sys/kernel/debug/tracing/tracing_on\n"
3018 tracing_readme_read(struct file
*filp
, char __user
*ubuf
,
3019 size_t cnt
, loff_t
*ppos
)
3021 return simple_read_from_buffer(ubuf
, cnt
, ppos
,
3022 readme_msg
, strlen(readme_msg
));
3025 static const struct file_operations tracing_readme_fops
= {
3026 .open
= tracing_open_generic
,
3027 .read
= tracing_readme_read
,
3028 .llseek
= generic_file_llseek
,
3032 tracing_saved_cmdlines_read(struct file
*file
, char __user
*ubuf
,
3033 size_t cnt
, loff_t
*ppos
)
3042 file_buf
= kmalloc(SAVED_CMDLINES
*(16+TASK_COMM_LEN
), GFP_KERNEL
);
3046 buf_comm
= kmalloc(TASK_COMM_LEN
, GFP_KERNEL
);
3054 for (i
= 0; i
< SAVED_CMDLINES
; i
++) {
3057 pid
= map_cmdline_to_pid
[i
];
3058 if (pid
== -1 || pid
== NO_CMDLINE_MAP
)
3061 trace_find_cmdline(pid
, buf_comm
);
3062 r
= sprintf(buf
, "%d %s\n", pid
, buf_comm
);
3067 len
= simple_read_from_buffer(ubuf
, cnt
, ppos
,
3076 static const struct file_operations tracing_saved_cmdlines_fops
= {
3077 .open
= tracing_open_generic
,
3078 .read
= tracing_saved_cmdlines_read
,
3079 .llseek
= generic_file_llseek
,
3083 tracing_set_trace_read(struct file
*filp
, char __user
*ubuf
,
3084 size_t cnt
, loff_t
*ppos
)
3086 char buf
[MAX_TRACER_SIZE
+2];
3089 mutex_lock(&trace_types_lock
);
3090 r
= sprintf(buf
, "%s\n", current_trace
->name
);
3091 mutex_unlock(&trace_types_lock
);
3093 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
3096 int tracer_init(struct tracer
*t
, struct trace_array
*tr
)
3098 tracing_reset_online_cpus(tr
);
3102 static void set_buffer_entries(struct trace_array
*tr
, unsigned long val
)
3105 for_each_tracing_cpu(cpu
)
3106 tr
->data
[cpu
]->entries
= val
;
3109 /* resize @tr's buffer to the size of @size_tr's entries */
3110 static int resize_buffer_duplicate_size(struct trace_array
*tr
,
3111 struct trace_array
*size_tr
, int cpu_id
)
3115 if (cpu_id
== RING_BUFFER_ALL_CPUS
) {
3116 for_each_tracing_cpu(cpu
) {
3117 ret
= ring_buffer_resize(tr
->buffer
,
3118 size_tr
->data
[cpu
]->entries
, cpu
);
3121 tr
->data
[cpu
]->entries
= size_tr
->data
[cpu
]->entries
;
3124 ret
= ring_buffer_resize(tr
->buffer
,
3125 size_tr
->data
[cpu_id
]->entries
, cpu_id
);
3127 tr
->data
[cpu_id
]->entries
=
3128 size_tr
->data
[cpu_id
]->entries
;
3134 static int __tracing_resize_ring_buffer(unsigned long size
, int cpu
)
3139 * If kernel or user changes the size of the ring buffer
3140 * we use the size that was given, and we can forget about
3141 * expanding it later.
3143 ring_buffer_expanded
= 1;
3145 /* May be called before buffers are initialized */
3146 if (!global_trace
.buffer
)
3149 ret
= ring_buffer_resize(global_trace
.buffer
, size
, cpu
);
3153 if (!current_trace
->use_max_tr
)
3156 ret
= ring_buffer_resize(max_tr
.buffer
, size
, cpu
);
3158 int r
= resize_buffer_duplicate_size(&global_trace
,
3159 &global_trace
, cpu
);
3162 * AARGH! We are left with different
3163 * size max buffer!!!!
3164 * The max buffer is our "snapshot" buffer.
3165 * When a tracer needs a snapshot (one of the
3166 * latency tracers), it swaps the max buffer
3167 * with the saved snap shot. We succeeded to
3168 * update the size of the main buffer, but failed to
3169 * update the size of the max buffer. But when we tried
3170 * to reset the main buffer to the original size, we
3171 * failed there too. This is very unlikely to
3172 * happen, but if it does, warn and kill all
3176 tracing_disabled
= 1;
3181 if (cpu
== RING_BUFFER_ALL_CPUS
)
3182 set_buffer_entries(&max_tr
, size
);
3184 max_tr
.data
[cpu
]->entries
= size
;
3187 if (cpu
== RING_BUFFER_ALL_CPUS
)
3188 set_buffer_entries(&global_trace
, size
);
3190 global_trace
.data
[cpu
]->entries
= size
;
3195 static ssize_t
tracing_resize_ring_buffer(unsigned long size
, int cpu_id
)
3199 mutex_lock(&trace_types_lock
);
3201 if (cpu_id
!= RING_BUFFER_ALL_CPUS
) {
3202 /* make sure, this cpu is enabled in the mask */
3203 if (!cpumask_test_cpu(cpu_id
, tracing_buffer_mask
)) {
3209 ret
= __tracing_resize_ring_buffer(size
, cpu_id
);
3214 mutex_unlock(&trace_types_lock
);
3221 * tracing_update_buffers - used by tracing facility to expand ring buffers
3223 * To save on memory when the tracing is never used on a system with it
3224 * configured in. The ring buffers are set to a minimum size. But once
3225 * a user starts to use the tracing facility, then they need to grow
3226 * to their default size.
3228 * This function is to be called when a tracer is about to be used.
3230 int tracing_update_buffers(void)
3234 mutex_lock(&trace_types_lock
);
3235 if (!ring_buffer_expanded
)
3236 ret
= __tracing_resize_ring_buffer(trace_buf_size
,
3237 RING_BUFFER_ALL_CPUS
);
3238 mutex_unlock(&trace_types_lock
);
3243 struct trace_option_dentry
;
3245 static struct trace_option_dentry
*
3246 create_trace_option_files(struct tracer
*tracer
);
3249 destroy_trace_option_files(struct trace_option_dentry
*topts
);
3251 static int tracing_set_tracer(const char *buf
)
3253 static struct trace_option_dentry
*topts
;
3254 struct trace_array
*tr
= &global_trace
;
3259 mutex_lock(&trace_types_lock
);
3261 if (!ring_buffer_expanded
) {
3262 ret
= __tracing_resize_ring_buffer(trace_buf_size
,
3263 RING_BUFFER_ALL_CPUS
);
3269 for (t
= trace_types
; t
; t
= t
->next
) {
3270 if (strcmp(t
->name
, buf
) == 0)
3277 if (t
== current_trace
)
3280 trace_branch_disable();
3282 current_trace
->enabled
= false;
3284 if (current_trace
->reset
)
3285 current_trace
->reset(tr
);
3287 had_max_tr
= current_trace
->allocated_snapshot
;
3288 current_trace
= &nop_trace
;
3290 if (had_max_tr
&& !t
->use_max_tr
) {
3292 * We need to make sure that the update_max_tr sees that
3293 * current_trace changed to nop_trace to keep it from
3294 * swapping the buffers after we resize it.
3295 * The update_max_tr is called from interrupts disabled
3296 * so a synchronized_sched() is sufficient.
3298 synchronize_sched();
3300 * We don't free the ring buffer. instead, resize it because
3301 * The max_tr ring buffer has some state (e.g. ring->clock) and
3302 * we want preserve it.
3304 ring_buffer_resize(max_tr
.buffer
, 1, RING_BUFFER_ALL_CPUS
);
3305 set_buffer_entries(&max_tr
, 1);
3306 tracing_reset_online_cpus(&max_tr
);
3307 current_trace
->allocated_snapshot
= false;
3309 destroy_trace_option_files(topts
);
3311 topts
= create_trace_option_files(t
);
3312 if (t
->use_max_tr
&& !had_max_tr
) {
3313 /* we need to make per cpu buffer sizes equivalent */
3314 ret
= resize_buffer_duplicate_size(&max_tr
, &global_trace
,
3315 RING_BUFFER_ALL_CPUS
);
3318 t
->allocated_snapshot
= true;
3322 ret
= tracer_init(t
, tr
);
3328 current_trace
->enabled
= true;
3329 trace_branch_enable(tr
);
3331 mutex_unlock(&trace_types_lock
);
3337 tracing_set_trace_write(struct file
*filp
, const char __user
*ubuf
,
3338 size_t cnt
, loff_t
*ppos
)
3340 char buf
[MAX_TRACER_SIZE
+1];
3347 if (cnt
> MAX_TRACER_SIZE
)
3348 cnt
= MAX_TRACER_SIZE
;
3350 if (copy_from_user(&buf
, ubuf
, cnt
))
3355 /* strip ending whitespace. */
3356 for (i
= cnt
- 1; i
> 0 && isspace(buf
[i
]); i
--)
3359 err
= tracing_set_tracer(buf
);
3369 tracing_max_lat_read(struct file
*filp
, char __user
*ubuf
,
3370 size_t cnt
, loff_t
*ppos
)
3372 unsigned long *ptr
= filp
->private_data
;
3376 r
= snprintf(buf
, sizeof(buf
), "%ld\n",
3377 *ptr
== (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr
));
3378 if (r
> sizeof(buf
))
3380 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
3384 tracing_max_lat_write(struct file
*filp
, const char __user
*ubuf
,
3385 size_t cnt
, loff_t
*ppos
)
3387 unsigned long *ptr
= filp
->private_data
;
3391 ret
= kstrtoul_from_user(ubuf
, cnt
, 10, &val
);
3400 static int tracing_open_pipe(struct inode
*inode
, struct file
*filp
)
3402 long cpu_file
= (long) inode
->i_private
;
3403 struct trace_iterator
*iter
;
3406 if (tracing_disabled
)
3409 mutex_lock(&trace_types_lock
);
3411 /* create a buffer to store the information to pass to userspace */
3412 iter
= kzalloc(sizeof(*iter
), GFP_KERNEL
);
3419 * We make a copy of the current tracer to avoid concurrent
3420 * changes on it while we are reading.
3422 iter
->trace
= kmalloc(sizeof(*iter
->trace
), GFP_KERNEL
);
3427 *iter
->trace
= *current_trace
;
3429 if (!alloc_cpumask_var(&iter
->started
, GFP_KERNEL
)) {
3434 /* trace pipe does not show start of buffer */
3435 cpumask_setall(iter
->started
);
3437 if (trace_flags
& TRACE_ITER_LATENCY_FMT
)
3438 iter
->iter_flags
|= TRACE_FILE_LAT_FMT
;
3440 /* Output in nanoseconds only if we are using a clock in nanoseconds. */
3441 if (trace_clocks
[trace_clock_id
].in_ns
)
3442 iter
->iter_flags
|= TRACE_FILE_TIME_IN_NS
;
3444 iter
->cpu_file
= cpu_file
;
3445 iter
->tr
= &global_trace
;
3446 mutex_init(&iter
->mutex
);
3447 filp
->private_data
= iter
;
3449 if (iter
->trace
->pipe_open
)
3450 iter
->trace
->pipe_open(iter
);
3452 nonseekable_open(inode
, filp
);
3454 mutex_unlock(&trace_types_lock
);
3460 mutex_unlock(&trace_types_lock
);
3464 static int tracing_release_pipe(struct inode
*inode
, struct file
*file
)
3466 struct trace_iterator
*iter
= file
->private_data
;
3468 mutex_lock(&trace_types_lock
);
3470 if (iter
->trace
->pipe_close
)
3471 iter
->trace
->pipe_close(iter
);
3473 mutex_unlock(&trace_types_lock
);
3475 free_cpumask_var(iter
->started
);
3476 mutex_destroy(&iter
->mutex
);
3484 tracing_poll_pipe(struct file
*filp
, poll_table
*poll_table
)
3486 struct trace_iterator
*iter
= filp
->private_data
;
3488 if (trace_flags
& TRACE_ITER_BLOCK
) {
3490 * Always select as readable when in blocking mode
3492 return POLLIN
| POLLRDNORM
;
3494 if (!trace_empty(iter
))
3495 return POLLIN
| POLLRDNORM
;
3496 poll_wait(filp
, &trace_wait
, poll_table
);
3497 if (!trace_empty(iter
))
3498 return POLLIN
| POLLRDNORM
;
3505 * This is a make-shift waitqueue.
3506 * A tracer might use this callback on some rare cases:
3508 * 1) the current tracer might hold the runqueue lock when it wakes up
3509 * a reader, hence a deadlock (sched, function, and function graph tracers)
3510 * 2) the function tracers, trace all functions, we don't want
3511 * the overhead of calling wake_up and friends
3512 * (and tracing them too)
3514 * Anyway, this is really very primitive wakeup.
3516 void poll_wait_pipe(struct trace_iterator
*iter
)
3518 set_current_state(TASK_INTERRUPTIBLE
);
3519 /* sleep for 100 msecs, and try again. */
3520 schedule_timeout(HZ
/ 10);
3523 /* Must be called with trace_types_lock mutex held. */
3524 static int tracing_wait_pipe(struct file
*filp
)
3526 struct trace_iterator
*iter
= filp
->private_data
;
3528 while (trace_empty(iter
)) {
3530 if ((filp
->f_flags
& O_NONBLOCK
)) {
3534 mutex_unlock(&iter
->mutex
);
3536 iter
->trace
->wait_pipe(iter
);
3538 mutex_lock(&iter
->mutex
);
3540 if (signal_pending(current
))
3544 * We block until we read something and tracing is disabled.
3545 * We still block if tracing is disabled, but we have never
3546 * read anything. This allows a user to cat this file, and
3547 * then enable tracing. But after we have read something,
3548 * we give an EOF when tracing is again disabled.
3550 * iter->pos will be 0 if we haven't read anything.
3552 if (!tracing_is_enabled() && iter
->pos
)
3563 tracing_read_pipe(struct file
*filp
, char __user
*ubuf
,
3564 size_t cnt
, loff_t
*ppos
)
3566 struct trace_iterator
*iter
= filp
->private_data
;
3569 /* return any leftover data */
3570 sret
= trace_seq_to_user(&iter
->seq
, ubuf
, cnt
);
3574 trace_seq_init(&iter
->seq
);
3576 /* copy the tracer to avoid using a global lock all around */
3577 mutex_lock(&trace_types_lock
);
3578 if (unlikely(iter
->trace
->name
!= current_trace
->name
))
3579 *iter
->trace
= *current_trace
;
3580 mutex_unlock(&trace_types_lock
);
3583 * Avoid more than one consumer on a single file descriptor
3584 * This is just a matter of traces coherency, the ring buffer itself
3587 mutex_lock(&iter
->mutex
);
3588 if (iter
->trace
->read
) {
3589 sret
= iter
->trace
->read(iter
, filp
, ubuf
, cnt
, ppos
);
3595 sret
= tracing_wait_pipe(filp
);
3599 /* stop when tracing is finished */
3600 if (trace_empty(iter
)) {
3605 if (cnt
>= PAGE_SIZE
)
3606 cnt
= PAGE_SIZE
- 1;
3608 /* reset all but tr, trace, and overruns */
3609 memset(&iter
->seq
, 0,
3610 sizeof(struct trace_iterator
) -
3611 offsetof(struct trace_iterator
, seq
));
3614 trace_event_read_lock();
3615 trace_access_lock(iter
->cpu_file
);
3616 while (trace_find_next_entry_inc(iter
) != NULL
) {
3617 enum print_line_t ret
;
3618 int len
= iter
->seq
.len
;
3620 ret
= print_trace_line(iter
);
3621 if (ret
== TRACE_TYPE_PARTIAL_LINE
) {
3622 /* don't print partial lines */
3623 iter
->seq
.len
= len
;
3626 if (ret
!= TRACE_TYPE_NO_CONSUME
)
3627 trace_consume(iter
);
3629 if (iter
->seq
.len
>= cnt
)
3633 * Setting the full flag means we reached the trace_seq buffer
3634 * size and we should leave by partial output condition above.
3635 * One of the trace_seq_* functions is not used properly.
3637 WARN_ONCE(iter
->seq
.full
, "full flag set for trace type %d",
3640 trace_access_unlock(iter
->cpu_file
);
3641 trace_event_read_unlock();
3643 /* Now copy what we have to the user */
3644 sret
= trace_seq_to_user(&iter
->seq
, ubuf
, cnt
);
3645 if (iter
->seq
.readpos
>= iter
->seq
.len
)
3646 trace_seq_init(&iter
->seq
);
3649 * If there was nothing to send to user, in spite of consuming trace
3650 * entries, go back to wait for more entries.
3656 mutex_unlock(&iter
->mutex
);
3661 static void tracing_pipe_buf_release(struct pipe_inode_info
*pipe
,
3662 struct pipe_buffer
*buf
)
3664 __free_page(buf
->page
);
3667 static void tracing_spd_release_pipe(struct splice_pipe_desc
*spd
,
3670 __free_page(spd
->pages
[idx
]);
3673 static const struct pipe_buf_operations tracing_pipe_buf_ops
= {
3675 .map
= generic_pipe_buf_map
,
3676 .unmap
= generic_pipe_buf_unmap
,
3677 .confirm
= generic_pipe_buf_confirm
,
3678 .release
= tracing_pipe_buf_release
,
3679 .steal
= generic_pipe_buf_steal
,
3680 .get
= generic_pipe_buf_get
,
3684 tracing_fill_pipe_page(size_t rem
, struct trace_iterator
*iter
)
3689 /* Seq buffer is page-sized, exactly what we need. */
3691 count
= iter
->seq
.len
;
3692 ret
= print_trace_line(iter
);
3693 count
= iter
->seq
.len
- count
;
3696 iter
->seq
.len
-= count
;
3699 if (ret
== TRACE_TYPE_PARTIAL_LINE
) {
3700 iter
->seq
.len
-= count
;
3704 if (ret
!= TRACE_TYPE_NO_CONSUME
)
3705 trace_consume(iter
);
3707 if (!trace_find_next_entry_inc(iter
)) {
3717 static ssize_t
tracing_splice_read_pipe(struct file
*filp
,
3719 struct pipe_inode_info
*pipe
,
3723 struct page
*pages_def
[PIPE_DEF_BUFFERS
];
3724 struct partial_page partial_def
[PIPE_DEF_BUFFERS
];
3725 struct trace_iterator
*iter
= filp
->private_data
;
3726 struct splice_pipe_desc spd
= {
3728 .partial
= partial_def
,
3729 .nr_pages
= 0, /* This gets updated below. */
3730 .nr_pages_max
= PIPE_DEF_BUFFERS
,
3732 .ops
= &tracing_pipe_buf_ops
,
3733 .spd_release
= tracing_spd_release_pipe
,
3739 if (splice_grow_spd(pipe
, &spd
))
3742 /* copy the tracer to avoid using a global lock all around */
3743 mutex_lock(&trace_types_lock
);
3744 if (unlikely(iter
->trace
->name
!= current_trace
->name
))
3745 *iter
->trace
= *current_trace
;
3746 mutex_unlock(&trace_types_lock
);
3748 mutex_lock(&iter
->mutex
);
3750 if (iter
->trace
->splice_read
) {
3751 ret
= iter
->trace
->splice_read(iter
, filp
,
3752 ppos
, pipe
, len
, flags
);
3757 ret
= tracing_wait_pipe(filp
);
3761 if (!iter
->ent
&& !trace_find_next_entry_inc(iter
)) {
3766 trace_event_read_lock();
3767 trace_access_lock(iter
->cpu_file
);
3769 /* Fill as many pages as possible. */
3770 for (i
= 0, rem
= len
; i
< pipe
->buffers
&& rem
; i
++) {
3771 spd
.pages
[i
] = alloc_page(GFP_KERNEL
);
3775 rem
= tracing_fill_pipe_page(rem
, iter
);
3777 /* Copy the data into the page, so we can start over. */
3778 ret
= trace_seq_to_buffer(&iter
->seq
,
3779 page_address(spd
.pages
[i
]),
3782 __free_page(spd
.pages
[i
]);
3785 spd
.partial
[i
].offset
= 0;
3786 spd
.partial
[i
].len
= iter
->seq
.len
;
3788 trace_seq_init(&iter
->seq
);
3791 trace_access_unlock(iter
->cpu_file
);
3792 trace_event_read_unlock();
3793 mutex_unlock(&iter
->mutex
);
3797 ret
= splice_to_pipe(pipe
, &spd
);
3799 splice_shrink_spd(&spd
);
3803 mutex_unlock(&iter
->mutex
);
3807 struct ftrace_entries_info
{
3808 struct trace_array
*tr
;
3812 static int tracing_entries_open(struct inode
*inode
, struct file
*filp
)
3814 struct ftrace_entries_info
*info
;
3816 if (tracing_disabled
)
3819 info
= kzalloc(sizeof(*info
), GFP_KERNEL
);
3823 info
->tr
= &global_trace
;
3824 info
->cpu
= (unsigned long)inode
->i_private
;
3826 filp
->private_data
= info
;
3832 tracing_entries_read(struct file
*filp
, char __user
*ubuf
,
3833 size_t cnt
, loff_t
*ppos
)
3835 struct ftrace_entries_info
*info
= filp
->private_data
;
3836 struct trace_array
*tr
= info
->tr
;
3841 mutex_lock(&trace_types_lock
);
3843 if (info
->cpu
== RING_BUFFER_ALL_CPUS
) {
3844 int cpu
, buf_size_same
;
3849 /* check if all cpu sizes are same */
3850 for_each_tracing_cpu(cpu
) {
3851 /* fill in the size from first enabled cpu */
3853 size
= tr
->data
[cpu
]->entries
;
3854 if (size
!= tr
->data
[cpu
]->entries
) {
3860 if (buf_size_same
) {
3861 if (!ring_buffer_expanded
)
3862 r
= sprintf(buf
, "%lu (expanded: %lu)\n",
3864 trace_buf_size
>> 10);
3866 r
= sprintf(buf
, "%lu\n", size
>> 10);
3868 r
= sprintf(buf
, "X\n");
3870 r
= sprintf(buf
, "%lu\n", tr
->data
[info
->cpu
]->entries
>> 10);
3872 mutex_unlock(&trace_types_lock
);
3874 ret
= simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
3879 tracing_entries_write(struct file
*filp
, const char __user
*ubuf
,
3880 size_t cnt
, loff_t
*ppos
)
3882 struct ftrace_entries_info
*info
= filp
->private_data
;
3886 ret
= kstrtoul_from_user(ubuf
, cnt
, 10, &val
);
3890 /* must have at least 1 entry */
3894 /* value is in KB */
3897 ret
= tracing_resize_ring_buffer(val
, info
->cpu
);
3907 tracing_entries_release(struct inode
*inode
, struct file
*filp
)
3909 struct ftrace_entries_info
*info
= filp
->private_data
;
3917 tracing_total_entries_read(struct file
*filp
, char __user
*ubuf
,
3918 size_t cnt
, loff_t
*ppos
)
3920 struct trace_array
*tr
= filp
->private_data
;
3923 unsigned long size
= 0, expanded_size
= 0;
3925 mutex_lock(&trace_types_lock
);
3926 for_each_tracing_cpu(cpu
) {
3927 size
+= tr
->data
[cpu
]->entries
>> 10;
3928 if (!ring_buffer_expanded
)
3929 expanded_size
+= trace_buf_size
>> 10;
3931 if (ring_buffer_expanded
)
3932 r
= sprintf(buf
, "%lu\n", size
);
3934 r
= sprintf(buf
, "%lu (expanded: %lu)\n", size
, expanded_size
);
3935 mutex_unlock(&trace_types_lock
);
3937 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
3941 tracing_free_buffer_write(struct file
*filp
, const char __user
*ubuf
,
3942 size_t cnt
, loff_t
*ppos
)
3945 * There is no need to read what the user has written, this function
3946 * is just to make sure that there is no error when "echo" is used
3955 tracing_free_buffer_release(struct inode
*inode
, struct file
*filp
)
3957 /* disable tracing ? */
3958 if (trace_flags
& TRACE_ITER_STOP_ON_FREE
)
3960 /* resize the ring buffer to 0 */
3961 tracing_resize_ring_buffer(0, RING_BUFFER_ALL_CPUS
);
3967 tracing_mark_write(struct file
*filp
, const char __user
*ubuf
,
3968 size_t cnt
, loff_t
*fpos
)
3970 unsigned long addr
= (unsigned long)ubuf
;
3971 struct ring_buffer_event
*event
;
3972 struct ring_buffer
*buffer
;
3973 struct print_entry
*entry
;
3974 unsigned long irq_flags
;
3975 struct page
*pages
[2];
3985 if (tracing_disabled
)
3988 if (!(trace_flags
& TRACE_ITER_MARKERS
))
3991 if (cnt
> TRACE_BUF_SIZE
)
3992 cnt
= TRACE_BUF_SIZE
;
3995 * Userspace is injecting traces into the kernel trace buffer.
3996 * We want to be as non intrusive as possible.
3997 * To do so, we do not want to allocate any special buffers
3998 * or take any locks, but instead write the userspace data
3999 * straight into the ring buffer.
4001 * First we need to pin the userspace buffer into memory,
4002 * which, most likely it is, because it just referenced it.
4003 * But there's no guarantee that it is. By using get_user_pages_fast()
4004 * and kmap_atomic/kunmap_atomic() we can get access to the
4005 * pages directly. We then write the data directly into the
4008 BUILD_BUG_ON(TRACE_BUF_SIZE
>= PAGE_SIZE
);
4010 /* check if we cross pages */
4011 if ((addr
& PAGE_MASK
) != ((addr
+ cnt
) & PAGE_MASK
))
4014 offset
= addr
& (PAGE_SIZE
- 1);
4017 ret
= get_user_pages_fast(addr
, nr_pages
, 0, pages
);
4018 if (ret
< nr_pages
) {
4020 put_page(pages
[ret
]);
4025 for (i
= 0; i
< nr_pages
; i
++)
4026 map_page
[i
] = kmap_atomic(pages
[i
]);
4028 local_save_flags(irq_flags
);
4029 size
= sizeof(*entry
) + cnt
+ 2; /* possible \n added */
4030 buffer
= global_trace
.buffer
;
4031 event
= trace_buffer_lock_reserve(buffer
, TRACE_PRINT
, size
,
4032 irq_flags
, preempt_count());
4034 /* Ring buffer disabled, return as if not open for write */
4039 entry
= ring_buffer_event_data(event
);
4040 entry
->ip
= _THIS_IP_
;
4042 if (nr_pages
== 2) {
4043 len
= PAGE_SIZE
- offset
;
4044 memcpy(&entry
->buf
, map_page
[0] + offset
, len
);
4045 memcpy(&entry
->buf
[len
], map_page
[1], cnt
- len
);
4047 memcpy(&entry
->buf
, map_page
[0] + offset
, cnt
);
4049 if (entry
->buf
[cnt
- 1] != '\n') {
4050 entry
->buf
[cnt
] = '\n';
4051 entry
->buf
[cnt
+ 1] = '\0';
4053 entry
->buf
[cnt
] = '\0';
4055 __buffer_unlock_commit(buffer
, event
);
4062 for (i
= 0; i
< nr_pages
; i
++){
4063 kunmap_atomic(map_page
[i
]);
4070 static int tracing_clock_show(struct seq_file
*m
, void *v
)
4074 for (i
= 0; i
< ARRAY_SIZE(trace_clocks
); i
++)
4076 "%s%s%s%s", i
? " " : "",
4077 i
== trace_clock_id
? "[" : "", trace_clocks
[i
].name
,
4078 i
== trace_clock_id
? "]" : "");
4084 static ssize_t
tracing_clock_write(struct file
*filp
, const char __user
*ubuf
,
4085 size_t cnt
, loff_t
*fpos
)
4088 const char *clockstr
;
4091 if (cnt
>= sizeof(buf
))
4094 if (copy_from_user(&buf
, ubuf
, cnt
))
4099 clockstr
= strstrip(buf
);
4101 for (i
= 0; i
< ARRAY_SIZE(trace_clocks
); i
++) {
4102 if (strcmp(trace_clocks
[i
].name
, clockstr
) == 0)
4105 if (i
== ARRAY_SIZE(trace_clocks
))
4110 mutex_lock(&trace_types_lock
);
4112 ring_buffer_set_clock(global_trace
.buffer
, trace_clocks
[i
].func
);
4114 ring_buffer_set_clock(max_tr
.buffer
, trace_clocks
[i
].func
);
4117 * New clock may not be consistent with the previous clock.
4118 * Reset the buffer so that it doesn't have incomparable timestamps.
4120 tracing_reset_online_cpus(&global_trace
);
4121 tracing_reset_online_cpus(&max_tr
);
4123 mutex_unlock(&trace_types_lock
);
4130 static int tracing_clock_open(struct inode
*inode
, struct file
*file
)
4132 if (tracing_disabled
)
4134 return single_open(file
, tracing_clock_show
, NULL
);
4137 #ifdef CONFIG_TRACER_SNAPSHOT
4138 static int tracing_snapshot_open(struct inode
*inode
, struct file
*file
)
4140 struct trace_iterator
*iter
;
4143 if (file
->f_mode
& FMODE_READ
) {
4144 iter
= __tracing_open(inode
, file
, true);
4146 ret
= PTR_ERR(iter
);
4152 tracing_snapshot_write(struct file
*filp
, const char __user
*ubuf
, size_t cnt
,
4158 ret
= tracing_update_buffers();
4162 ret
= kstrtoul_from_user(ubuf
, cnt
, 10, &val
);
4166 mutex_lock(&trace_types_lock
);
4168 if (current_trace
->use_max_tr
) {
4175 if (current_trace
->allocated_snapshot
) {
4176 /* free spare buffer */
4177 ring_buffer_resize(max_tr
.buffer
, 1,
4178 RING_BUFFER_ALL_CPUS
);
4179 set_buffer_entries(&max_tr
, 1);
4180 tracing_reset_online_cpus(&max_tr
);
4181 current_trace
->allocated_snapshot
= false;
4185 if (!current_trace
->allocated_snapshot
) {
4186 /* allocate spare buffer */
4187 ret
= resize_buffer_duplicate_size(&max_tr
,
4188 &global_trace
, RING_BUFFER_ALL_CPUS
);
4191 current_trace
->allocated_snapshot
= true;
4194 local_irq_disable();
4195 /* Now, we're going to swap */
4196 update_max_tr(&global_trace
, current
, smp_processor_id());
4200 if (current_trace
->allocated_snapshot
)
4201 tracing_reset_online_cpus(&max_tr
);
4210 mutex_unlock(&trace_types_lock
);
4213 #endif /* CONFIG_TRACER_SNAPSHOT */
4216 static const struct file_operations tracing_max_lat_fops
= {
4217 .open
= tracing_open_generic
,
4218 .read
= tracing_max_lat_read
,
4219 .write
= tracing_max_lat_write
,
4220 .llseek
= generic_file_llseek
,
4223 static const struct file_operations set_tracer_fops
= {
4224 .open
= tracing_open_generic
,
4225 .read
= tracing_set_trace_read
,
4226 .write
= tracing_set_trace_write
,
4227 .llseek
= generic_file_llseek
,
4230 static const struct file_operations tracing_pipe_fops
= {
4231 .open
= tracing_open_pipe
,
4232 .poll
= tracing_poll_pipe
,
4233 .read
= tracing_read_pipe
,
4234 .splice_read
= tracing_splice_read_pipe
,
4235 .release
= tracing_release_pipe
,
4236 .llseek
= no_llseek
,
4239 static const struct file_operations tracing_entries_fops
= {
4240 .open
= tracing_entries_open
,
4241 .read
= tracing_entries_read
,
4242 .write
= tracing_entries_write
,
4243 .release
= tracing_entries_release
,
4244 .llseek
= generic_file_llseek
,
4247 static const struct file_operations tracing_total_entries_fops
= {
4248 .open
= tracing_open_generic
,
4249 .read
= tracing_total_entries_read
,
4250 .llseek
= generic_file_llseek
,
4253 static const struct file_operations tracing_free_buffer_fops
= {
4254 .write
= tracing_free_buffer_write
,
4255 .release
= tracing_free_buffer_release
,
4258 static const struct file_operations tracing_mark_fops
= {
4259 .open
= tracing_open_generic
,
4260 .write
= tracing_mark_write
,
4261 .llseek
= generic_file_llseek
,
4264 static const struct file_operations trace_clock_fops
= {
4265 .open
= tracing_clock_open
,
4267 .llseek
= seq_lseek
,
4268 .release
= single_release
,
4269 .write
= tracing_clock_write
,
4272 #ifdef CONFIG_TRACER_SNAPSHOT
4273 static const struct file_operations snapshot_fops
= {
4274 .open
= tracing_snapshot_open
,
4276 .write
= tracing_snapshot_write
,
4277 .llseek
= tracing_seek
,
4278 .release
= tracing_release
,
4280 #endif /* CONFIG_TRACER_SNAPSHOT */
4282 struct ftrace_buffer_info
{
4283 struct trace_array
*tr
;
4289 static int tracing_buffers_open(struct inode
*inode
, struct file
*filp
)
4291 int cpu
= (int)(long)inode
->i_private
;
4292 struct ftrace_buffer_info
*info
;
4294 if (tracing_disabled
)
4297 info
= kzalloc(sizeof(*info
), GFP_KERNEL
);
4301 info
->tr
= &global_trace
;
4304 /* Force reading ring buffer for first read */
4305 info
->read
= (unsigned int)-1;
4307 filp
->private_data
= info
;
4309 return nonseekable_open(inode
, filp
);
4313 tracing_buffers_read(struct file
*filp
, char __user
*ubuf
,
4314 size_t count
, loff_t
*ppos
)
4316 struct ftrace_buffer_info
*info
= filp
->private_data
;
4324 info
->spare
= ring_buffer_alloc_read_page(info
->tr
->buffer
, info
->cpu
);
4328 /* Do we have previous read data to read? */
4329 if (info
->read
< PAGE_SIZE
)
4332 trace_access_lock(info
->cpu
);
4333 ret
= ring_buffer_read_page(info
->tr
->buffer
,
4337 trace_access_unlock(info
->cpu
);
4344 size
= PAGE_SIZE
- info
->read
;
4348 ret
= copy_to_user(ubuf
, info
->spare
+ info
->read
, size
);
4359 static int tracing_buffers_release(struct inode
*inode
, struct file
*file
)
4361 struct ftrace_buffer_info
*info
= file
->private_data
;
4364 ring_buffer_free_read_page(info
->tr
->buffer
, info
->spare
);
4371 struct ring_buffer
*buffer
;
4376 static void buffer_pipe_buf_release(struct pipe_inode_info
*pipe
,
4377 struct pipe_buffer
*buf
)
4379 struct buffer_ref
*ref
= (struct buffer_ref
*)buf
->private;
4384 ring_buffer_free_read_page(ref
->buffer
, ref
->page
);
4389 static void buffer_pipe_buf_get(struct pipe_inode_info
*pipe
,
4390 struct pipe_buffer
*buf
)
4392 struct buffer_ref
*ref
= (struct buffer_ref
*)buf
->private;
4397 /* Pipe buffer operations for a buffer. */
4398 static const struct pipe_buf_operations buffer_pipe_buf_ops
= {
4400 .map
= generic_pipe_buf_map
,
4401 .unmap
= generic_pipe_buf_unmap
,
4402 .confirm
= generic_pipe_buf_confirm
,
4403 .release
= buffer_pipe_buf_release
,
4404 .steal
= generic_pipe_buf_steal
,
4405 .get
= buffer_pipe_buf_get
,
4409 * Callback from splice_to_pipe(), if we need to release some pages
4410 * at the end of the spd in case we error'ed out in filling the pipe.
4412 static void buffer_spd_release(struct splice_pipe_desc
*spd
, unsigned int i
)
4414 struct buffer_ref
*ref
=
4415 (struct buffer_ref
*)spd
->partial
[i
].private;
4420 ring_buffer_free_read_page(ref
->buffer
, ref
->page
);
4422 spd
->partial
[i
].private = 0;
4426 tracing_buffers_splice_read(struct file
*file
, loff_t
*ppos
,
4427 struct pipe_inode_info
*pipe
, size_t len
,
4430 struct ftrace_buffer_info
*info
= file
->private_data
;
4431 struct partial_page partial_def
[PIPE_DEF_BUFFERS
];
4432 struct page
*pages_def
[PIPE_DEF_BUFFERS
];
4433 struct splice_pipe_desc spd
= {
4435 .partial
= partial_def
,
4436 .nr_pages_max
= PIPE_DEF_BUFFERS
,
4438 .ops
= &buffer_pipe_buf_ops
,
4439 .spd_release
= buffer_spd_release
,
4441 struct buffer_ref
*ref
;
4442 int entries
, size
, i
;
4445 if (splice_grow_spd(pipe
, &spd
))
4448 if (*ppos
& (PAGE_SIZE
- 1)) {
4453 if (len
& (PAGE_SIZE
- 1)) {
4454 if (len
< PAGE_SIZE
) {
4461 trace_access_lock(info
->cpu
);
4462 entries
= ring_buffer_entries_cpu(info
->tr
->buffer
, info
->cpu
);
4464 for (i
= 0; i
< pipe
->buffers
&& len
&& entries
; i
++, len
-= PAGE_SIZE
) {
4468 ref
= kzalloc(sizeof(*ref
), GFP_KERNEL
);
4473 ref
->buffer
= info
->tr
->buffer
;
4474 ref
->page
= ring_buffer_alloc_read_page(ref
->buffer
, info
->cpu
);
4480 r
= ring_buffer_read_page(ref
->buffer
, &ref
->page
,
4483 ring_buffer_free_read_page(ref
->buffer
, ref
->page
);
4489 * zero out any left over data, this is going to
4492 size
= ring_buffer_page_len(ref
->page
);
4493 if (size
< PAGE_SIZE
)
4494 memset(ref
->page
+ size
, 0, PAGE_SIZE
- size
);
4496 page
= virt_to_page(ref
->page
);
4498 spd
.pages
[i
] = page
;
4499 spd
.partial
[i
].len
= PAGE_SIZE
;
4500 spd
.partial
[i
].offset
= 0;
4501 spd
.partial
[i
].private = (unsigned long)ref
;
4505 entries
= ring_buffer_entries_cpu(info
->tr
->buffer
, info
->cpu
);
4508 trace_access_unlock(info
->cpu
);
4511 /* did we read anything? */
4512 if (!spd
.nr_pages
) {
4513 if (flags
& SPLICE_F_NONBLOCK
)
4521 ret
= splice_to_pipe(pipe
, &spd
);
4522 splice_shrink_spd(&spd
);
4527 static const struct file_operations tracing_buffers_fops
= {
4528 .open
= tracing_buffers_open
,
4529 .read
= tracing_buffers_read
,
4530 .release
= tracing_buffers_release
,
4531 .splice_read
= tracing_buffers_splice_read
,
4532 .llseek
= no_llseek
,
4536 tracing_stats_read(struct file
*filp
, char __user
*ubuf
,
4537 size_t count
, loff_t
*ppos
)
4539 unsigned long cpu
= (unsigned long)filp
->private_data
;
4540 struct trace_array
*tr
= &global_trace
;
4541 struct trace_seq
*s
;
4543 unsigned long long t
;
4544 unsigned long usec_rem
;
4546 s
= kmalloc(sizeof(*s
), GFP_KERNEL
);
4552 cnt
= ring_buffer_entries_cpu(tr
->buffer
, cpu
);
4553 trace_seq_printf(s
, "entries: %ld\n", cnt
);
4555 cnt
= ring_buffer_overrun_cpu(tr
->buffer
, cpu
);
4556 trace_seq_printf(s
, "overrun: %ld\n", cnt
);
4558 cnt
= ring_buffer_commit_overrun_cpu(tr
->buffer
, cpu
);
4559 trace_seq_printf(s
, "commit overrun: %ld\n", cnt
);
4561 cnt
= ring_buffer_bytes_cpu(tr
->buffer
, cpu
);
4562 trace_seq_printf(s
, "bytes: %ld\n", cnt
);
4564 if (trace_clocks
[trace_clock_id
].in_ns
) {
4565 /* local or global for trace_clock */
4566 t
= ns2usecs(ring_buffer_oldest_event_ts(tr
->buffer
, cpu
));
4567 usec_rem
= do_div(t
, USEC_PER_SEC
);
4568 trace_seq_printf(s
, "oldest event ts: %5llu.%06lu\n",
4571 t
= ns2usecs(ring_buffer_time_stamp(tr
->buffer
, cpu
));
4572 usec_rem
= do_div(t
, USEC_PER_SEC
);
4573 trace_seq_printf(s
, "now ts: %5llu.%06lu\n", t
, usec_rem
);
4575 /* counter or tsc mode for trace_clock */
4576 trace_seq_printf(s
, "oldest event ts: %llu\n",
4577 ring_buffer_oldest_event_ts(tr
->buffer
, cpu
));
4579 trace_seq_printf(s
, "now ts: %llu\n",
4580 ring_buffer_time_stamp(tr
->buffer
, cpu
));
4583 cnt
= ring_buffer_dropped_events_cpu(tr
->buffer
, cpu
);
4584 trace_seq_printf(s
, "dropped events: %ld\n", cnt
);
4586 cnt
= ring_buffer_read_events_cpu(tr
->buffer
, cpu
);
4587 trace_seq_printf(s
, "read events: %ld\n", cnt
);
4589 count
= simple_read_from_buffer(ubuf
, count
, ppos
, s
->buffer
, s
->len
);
4596 static const struct file_operations tracing_stats_fops
= {
4597 .open
= tracing_open_generic
,
4598 .read
= tracing_stats_read
,
4599 .llseek
= generic_file_llseek
,
4602 #ifdef CONFIG_DYNAMIC_FTRACE
4604 int __weak
ftrace_arch_read_dyn_info(char *buf
, int size
)
4610 tracing_read_dyn_info(struct file
*filp
, char __user
*ubuf
,
4611 size_t cnt
, loff_t
*ppos
)
4613 static char ftrace_dyn_info_buffer
[1024];
4614 static DEFINE_MUTEX(dyn_info_mutex
);
4615 unsigned long *p
= filp
->private_data
;
4616 char *buf
= ftrace_dyn_info_buffer
;
4617 int size
= ARRAY_SIZE(ftrace_dyn_info_buffer
);
4620 mutex_lock(&dyn_info_mutex
);
4621 r
= sprintf(buf
, "%ld ", *p
);
4623 r
+= ftrace_arch_read_dyn_info(buf
+r
, (size
-1)-r
);
4626 r
= simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
4628 mutex_unlock(&dyn_info_mutex
);
4633 static const struct file_operations tracing_dyn_info_fops
= {
4634 .open
= tracing_open_generic
,
4635 .read
= tracing_read_dyn_info
,
4636 .llseek
= generic_file_llseek
,
4640 static struct dentry
*d_tracer
;
4642 struct dentry
*tracing_init_dentry(void)
4649 if (!debugfs_initialized())
4652 d_tracer
= debugfs_create_dir("tracing", NULL
);
4654 if (!d_tracer
&& !once
) {
4656 pr_warning("Could not create debugfs directory 'tracing'\n");
4663 static struct dentry
*d_percpu
;
4665 static struct dentry
*tracing_dentry_percpu(void)
4668 struct dentry
*d_tracer
;
4673 d_tracer
= tracing_init_dentry();
4678 d_percpu
= debugfs_create_dir("per_cpu", d_tracer
);
4680 if (!d_percpu
&& !once
) {
4682 pr_warning("Could not create debugfs directory 'per_cpu'\n");
4689 static void tracing_init_debugfs_percpu(long cpu
)
4691 struct dentry
*d_percpu
= tracing_dentry_percpu();
4692 struct dentry
*d_cpu
;
4693 char cpu_dir
[30]; /* 30 characters should be more than enough */
4698 snprintf(cpu_dir
, 30, "cpu%ld", cpu
);
4699 d_cpu
= debugfs_create_dir(cpu_dir
, d_percpu
);
4701 pr_warning("Could not create debugfs '%s' entry\n", cpu_dir
);
4705 /* per cpu trace_pipe */
4706 trace_create_file("trace_pipe", 0444, d_cpu
,
4707 (void *) cpu
, &tracing_pipe_fops
);
4710 trace_create_file("trace", 0644, d_cpu
,
4711 (void *) cpu
, &tracing_fops
);
4713 trace_create_file("trace_pipe_raw", 0444, d_cpu
,
4714 (void *) cpu
, &tracing_buffers_fops
);
4716 trace_create_file("stats", 0444, d_cpu
,
4717 (void *) cpu
, &tracing_stats_fops
);
4719 trace_create_file("buffer_size_kb", 0444, d_cpu
,
4720 (void *) cpu
, &tracing_entries_fops
);
4723 #ifdef CONFIG_FTRACE_SELFTEST
4724 /* Let selftest have access to static functions in this file */
4725 #include "trace_selftest.c"
4728 struct trace_option_dentry
{
4729 struct tracer_opt
*opt
;
4730 struct tracer_flags
*flags
;
4731 struct dentry
*entry
;
4735 trace_options_read(struct file
*filp
, char __user
*ubuf
, size_t cnt
,
4738 struct trace_option_dentry
*topt
= filp
->private_data
;
4741 if (topt
->flags
->val
& topt
->opt
->bit
)
4746 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, 2);
4750 trace_options_write(struct file
*filp
, const char __user
*ubuf
, size_t cnt
,
4753 struct trace_option_dentry
*topt
= filp
->private_data
;
4757 ret
= kstrtoul_from_user(ubuf
, cnt
, 10, &val
);
4761 if (val
!= 0 && val
!= 1)
4764 if (!!(topt
->flags
->val
& topt
->opt
->bit
) != val
) {
4765 mutex_lock(&trace_types_lock
);
4766 ret
= __set_tracer_option(current_trace
, topt
->flags
,
4768 mutex_unlock(&trace_types_lock
);
4779 static const struct file_operations trace_options_fops
= {
4780 .open
= tracing_open_generic
,
4781 .read
= trace_options_read
,
4782 .write
= trace_options_write
,
4783 .llseek
= generic_file_llseek
,
4787 trace_options_core_read(struct file
*filp
, char __user
*ubuf
, size_t cnt
,
4790 long index
= (long)filp
->private_data
;
4793 if (trace_flags
& (1 << index
))
4798 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, 2);
4802 trace_options_core_write(struct file
*filp
, const char __user
*ubuf
, size_t cnt
,
4805 long index
= (long)filp
->private_data
;
4809 ret
= kstrtoul_from_user(ubuf
, cnt
, 10, &val
);
4813 if (val
!= 0 && val
!= 1)
4816 mutex_lock(&trace_types_lock
);
4817 ret
= set_tracer_flag(1 << index
, val
);
4818 mutex_unlock(&trace_types_lock
);
4828 static const struct file_operations trace_options_core_fops
= {
4829 .open
= tracing_open_generic
,
4830 .read
= trace_options_core_read
,
4831 .write
= trace_options_core_write
,
4832 .llseek
= generic_file_llseek
,
4835 struct dentry
*trace_create_file(const char *name
,
4837 struct dentry
*parent
,
4839 const struct file_operations
*fops
)
4843 ret
= debugfs_create_file(name
, mode
, parent
, data
, fops
);
4845 pr_warning("Could not create debugfs '%s' entry\n", name
);
4851 static struct dentry
*trace_options_init_dentry(void)
4853 struct dentry
*d_tracer
;
4854 static struct dentry
*t_options
;
4859 d_tracer
= tracing_init_dentry();
4863 t_options
= debugfs_create_dir("options", d_tracer
);
4865 pr_warning("Could not create debugfs directory 'options'\n");
4873 create_trace_option_file(struct trace_option_dentry
*topt
,
4874 struct tracer_flags
*flags
,
4875 struct tracer_opt
*opt
)
4877 struct dentry
*t_options
;
4879 t_options
= trace_options_init_dentry();
4883 topt
->flags
= flags
;
4886 topt
->entry
= trace_create_file(opt
->name
, 0644, t_options
, topt
,
4887 &trace_options_fops
);
4891 static struct trace_option_dentry
*
4892 create_trace_option_files(struct tracer
*tracer
)
4894 struct trace_option_dentry
*topts
;
4895 struct tracer_flags
*flags
;
4896 struct tracer_opt
*opts
;
4902 flags
= tracer
->flags
;
4904 if (!flags
|| !flags
->opts
)
4909 for (cnt
= 0; opts
[cnt
].name
; cnt
++)
4912 topts
= kcalloc(cnt
+ 1, sizeof(*topts
), GFP_KERNEL
);
4916 for (cnt
= 0; opts
[cnt
].name
; cnt
++)
4917 create_trace_option_file(&topts
[cnt
], flags
,
4924 destroy_trace_option_files(struct trace_option_dentry
*topts
)
4931 for (cnt
= 0; topts
[cnt
].opt
; cnt
++) {
4932 if (topts
[cnt
].entry
)
4933 debugfs_remove(topts
[cnt
].entry
);
4939 static struct dentry
*
4940 create_trace_option_core_file(const char *option
, long index
)
4942 struct dentry
*t_options
;
4944 t_options
= trace_options_init_dentry();
4948 return trace_create_file(option
, 0644, t_options
, (void *)index
,
4949 &trace_options_core_fops
);
4952 static __init
void create_trace_options_dir(void)
4954 struct dentry
*t_options
;
4957 t_options
= trace_options_init_dentry();
4961 for (i
= 0; trace_options
[i
]; i
++)
4962 create_trace_option_core_file(trace_options
[i
], i
);
4966 rb_simple_read(struct file
*filp
, char __user
*ubuf
,
4967 size_t cnt
, loff_t
*ppos
)
4969 struct trace_array
*tr
= filp
->private_data
;
4970 struct ring_buffer
*buffer
= tr
->buffer
;
4975 r
= ring_buffer_record_is_on(buffer
);
4979 r
= sprintf(buf
, "%d\n", r
);
4981 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
4985 rb_simple_write(struct file
*filp
, const char __user
*ubuf
,
4986 size_t cnt
, loff_t
*ppos
)
4988 struct trace_array
*tr
= filp
->private_data
;
4989 struct ring_buffer
*buffer
= tr
->buffer
;
4993 ret
= kstrtoul_from_user(ubuf
, cnt
, 10, &val
);
4998 mutex_lock(&trace_types_lock
);
5000 ring_buffer_record_on(buffer
);
5001 if (current_trace
->start
)
5002 current_trace
->start(tr
);
5004 ring_buffer_record_off(buffer
);
5005 if (current_trace
->stop
)
5006 current_trace
->stop(tr
);
5008 mutex_unlock(&trace_types_lock
);
5016 static const struct file_operations rb_simple_fops
= {
5017 .open
= tracing_open_generic
,
5018 .read
= rb_simple_read
,
5019 .write
= rb_simple_write
,
5020 .llseek
= default_llseek
,
5023 static __init
int tracer_init_debugfs(void)
5025 struct dentry
*d_tracer
;
5028 trace_access_lock_init();
5030 d_tracer
= tracing_init_dentry();
5032 trace_create_file("trace_options", 0644, d_tracer
,
5033 NULL
, &tracing_iter_fops
);
5035 trace_create_file("tracing_cpumask", 0644, d_tracer
,
5036 NULL
, &tracing_cpumask_fops
);
5038 trace_create_file("trace", 0644, d_tracer
,
5039 (void *) TRACE_PIPE_ALL_CPU
, &tracing_fops
);
5041 trace_create_file("available_tracers", 0444, d_tracer
,
5042 &global_trace
, &show_traces_fops
);
5044 trace_create_file("current_tracer", 0644, d_tracer
,
5045 &global_trace
, &set_tracer_fops
);
5047 #ifdef CONFIG_TRACER_MAX_TRACE
5048 trace_create_file("tracing_max_latency", 0644, d_tracer
,
5049 &tracing_max_latency
, &tracing_max_lat_fops
);
5052 trace_create_file("tracing_thresh", 0644, d_tracer
,
5053 &tracing_thresh
, &tracing_max_lat_fops
);
5055 trace_create_file("README", 0444, d_tracer
,
5056 NULL
, &tracing_readme_fops
);
5058 trace_create_file("trace_pipe", 0444, d_tracer
,
5059 (void *) TRACE_PIPE_ALL_CPU
, &tracing_pipe_fops
);
5061 trace_create_file("buffer_size_kb", 0644, d_tracer
,
5062 (void *) RING_BUFFER_ALL_CPUS
, &tracing_entries_fops
);
5064 trace_create_file("buffer_total_size_kb", 0444, d_tracer
,
5065 &global_trace
, &tracing_total_entries_fops
);
5067 trace_create_file("free_buffer", 0644, d_tracer
,
5068 &global_trace
, &tracing_free_buffer_fops
);
5070 trace_create_file("trace_marker", 0220, d_tracer
,
5071 NULL
, &tracing_mark_fops
);
5073 trace_create_file("saved_cmdlines", 0444, d_tracer
,
5074 NULL
, &tracing_saved_cmdlines_fops
);
5076 trace_create_file("trace_clock", 0644, d_tracer
, NULL
,
5079 trace_create_file("tracing_on", 0644, d_tracer
,
5080 &global_trace
, &rb_simple_fops
);
5082 #ifdef CONFIG_DYNAMIC_FTRACE
5083 trace_create_file("dyn_ftrace_total_info", 0444, d_tracer
,
5084 &ftrace_update_tot_cnt
, &tracing_dyn_info_fops
);
5087 #ifdef CONFIG_TRACER_SNAPSHOT
5088 trace_create_file("snapshot", 0644, d_tracer
,
5089 (void *) TRACE_PIPE_ALL_CPU
, &snapshot_fops
);
5092 create_trace_options_dir();
5094 for_each_tracing_cpu(cpu
)
5095 tracing_init_debugfs_percpu(cpu
);
5100 static int trace_panic_handler(struct notifier_block
*this,
5101 unsigned long event
, void *unused
)
5103 if (ftrace_dump_on_oops
)
5104 ftrace_dump(ftrace_dump_on_oops
);
5108 static struct notifier_block trace_panic_notifier
= {
5109 .notifier_call
= trace_panic_handler
,
5111 .priority
= 150 /* priority: INT_MAX >= x >= 0 */
5114 static int trace_die_handler(struct notifier_block
*self
,
5120 if (ftrace_dump_on_oops
)
5121 ftrace_dump(ftrace_dump_on_oops
);
5129 static struct notifier_block trace_die_notifier
= {
5130 .notifier_call
= trace_die_handler
,
5135 * printk is set to max of 1024, we really don't need it that big.
5136 * Nothing should be printing 1000 characters anyway.
5138 #define TRACE_MAX_PRINT 1000
5141 * Define here KERN_TRACE so that we have one place to modify
5142 * it if we decide to change what log level the ftrace dump
5145 #define KERN_TRACE KERN_EMERG
5148 trace_printk_seq(struct trace_seq
*s
)
5150 /* Probably should print a warning here. */
5154 /* should be zero ended, but we are paranoid. */
5155 s
->buffer
[s
->len
] = 0;
5157 printk(KERN_TRACE
"%s", s
->buffer
);
5162 void trace_init_global_iter(struct trace_iterator
*iter
)
5164 iter
->tr
= &global_trace
;
5165 iter
->trace
= current_trace
;
5166 iter
->cpu_file
= TRACE_PIPE_ALL_CPU
;
5170 __ftrace_dump(bool disable_tracing
, enum ftrace_dump_mode oops_dump_mode
)
5172 static arch_spinlock_t ftrace_dump_lock
=
5173 (arch_spinlock_t
)__ARCH_SPIN_LOCK_UNLOCKED
;
5174 /* use static because iter can be a bit big for the stack */
5175 static struct trace_iterator iter
;
5176 unsigned int old_userobj
;
5177 static int dump_ran
;
5178 unsigned long flags
;
5182 local_irq_save(flags
);
5183 arch_spin_lock(&ftrace_dump_lock
);
5191 /* Did function tracer already get disabled? */
5192 if (ftrace_is_dead()) {
5193 printk("# WARNING: FUNCTION TRACING IS CORRUPTED\n");
5194 printk("# MAY BE MISSING FUNCTION EVENTS\n");
5197 if (disable_tracing
)
5200 /* Simulate the iterator */
5201 trace_init_global_iter(&iter
);
5203 for_each_tracing_cpu(cpu
) {
5204 atomic_inc(&iter
.tr
->data
[cpu
]->disabled
);
5207 old_userobj
= trace_flags
& TRACE_ITER_SYM_USEROBJ
;
5209 /* don't look at user memory in panic mode */
5210 trace_flags
&= ~TRACE_ITER_SYM_USEROBJ
;
5212 switch (oops_dump_mode
) {
5214 iter
.cpu_file
= TRACE_PIPE_ALL_CPU
;
5217 iter
.cpu_file
= raw_smp_processor_id();
5222 printk(KERN_TRACE
"Bad dumping mode, switching to all CPUs dump\n");
5223 iter
.cpu_file
= TRACE_PIPE_ALL_CPU
;
5226 printk(KERN_TRACE
"Dumping ftrace buffer:\n");
5229 * We need to stop all tracing on all CPUS to read the
5230 * the next buffer. This is a bit expensive, but is
5231 * not done often. We fill all what we can read,
5232 * and then release the locks again.
5235 while (!trace_empty(&iter
)) {
5238 printk(KERN_TRACE
"---------------------------------\n");
5242 /* reset all but tr, trace, and overruns */
5243 memset(&iter
.seq
, 0,
5244 sizeof(struct trace_iterator
) -
5245 offsetof(struct trace_iterator
, seq
));
5246 iter
.iter_flags
|= TRACE_FILE_LAT_FMT
;
5249 if (trace_find_next_entry_inc(&iter
) != NULL
) {
5252 ret
= print_trace_line(&iter
);
5253 if (ret
!= TRACE_TYPE_NO_CONSUME
)
5254 trace_consume(&iter
);
5256 touch_nmi_watchdog();
5258 trace_printk_seq(&iter
.seq
);
5262 printk(KERN_TRACE
" (ftrace buffer empty)\n");
5264 printk(KERN_TRACE
"---------------------------------\n");
5267 /* Re-enable tracing if requested */
5268 if (!disable_tracing
) {
5269 trace_flags
|= old_userobj
;
5271 for_each_tracing_cpu(cpu
) {
5272 atomic_dec(&iter
.tr
->data
[cpu
]->disabled
);
5278 arch_spin_unlock(&ftrace_dump_lock
);
5279 local_irq_restore(flags
);
5282 /* By default: disable tracing after the dump */
5283 void ftrace_dump(enum ftrace_dump_mode oops_dump_mode
)
5285 __ftrace_dump(true, oops_dump_mode
);
5287 EXPORT_SYMBOL_GPL(ftrace_dump
);
5289 __init
static int tracer_alloc_buffers(void)
5292 enum ring_buffer_flags rb_flags
;
5297 if (!alloc_cpumask_var(&tracing_buffer_mask
, GFP_KERNEL
))
5300 if (!alloc_cpumask_var(&tracing_cpumask
, GFP_KERNEL
))
5301 goto out_free_buffer_mask
;
5303 /* Only allocate trace_printk buffers if a trace_printk exists */
5304 if (__stop___trace_bprintk_fmt
!= __start___trace_bprintk_fmt
)
5305 /* Must be called before global_trace.buffer is allocated */
5306 trace_printk_init_buffers();
5308 /* To save memory, keep the ring buffer size to its minimum */
5309 if (ring_buffer_expanded
)
5310 ring_buf_size
= trace_buf_size
;
5314 rb_flags
= trace_flags
& TRACE_ITER_OVERWRITE
? RB_FL_OVERWRITE
: 0;
5316 cpumask_copy(tracing_buffer_mask
, cpu_possible_mask
);
5317 cpumask_copy(tracing_cpumask
, cpu_all_mask
);
5319 /* TODO: make the number of buffers hot pluggable with CPUS */
5320 global_trace
.buffer
= ring_buffer_alloc(ring_buf_size
, rb_flags
);
5321 if (!global_trace
.buffer
) {
5322 printk(KERN_ERR
"tracer: failed to allocate ring buffer!\n");
5324 goto out_free_cpumask
;
5326 if (global_trace
.buffer_disabled
)
5330 #ifdef CONFIG_TRACER_MAX_TRACE
5331 max_tr
.buffer
= ring_buffer_alloc(1, rb_flags
);
5332 if (!max_tr
.buffer
) {
5333 printk(KERN_ERR
"tracer: failed to allocate max ring buffer!\n");
5335 ring_buffer_free(global_trace
.buffer
);
5336 goto out_free_cpumask
;
5340 /* Allocate the first page for all buffers */
5341 for_each_tracing_cpu(i
) {
5342 global_trace
.data
[i
] = &per_cpu(global_trace_cpu
, i
);
5343 max_tr
.data
[i
] = &per_cpu(max_tr_data
, i
);
5346 set_buffer_entries(&global_trace
,
5347 ring_buffer_size(global_trace
.buffer
, 0));
5348 #ifdef CONFIG_TRACER_MAX_TRACE
5349 set_buffer_entries(&max_tr
, 1);
5352 trace_init_cmdlines();
5353 init_irq_work(&trace_work_wakeup
, trace_wake_up
);
5355 register_tracer(&nop_trace
);
5357 /* All seems OK, enable tracing */
5358 tracing_disabled
= 0;
5360 atomic_notifier_chain_register(&panic_notifier_list
,
5361 &trace_panic_notifier
);
5363 register_die_notifier(&trace_die_notifier
);
5365 while (trace_boot_options
) {
5368 option
= strsep(&trace_boot_options
, ",");
5369 trace_set_options(option
);
5375 free_cpumask_var(tracing_cpumask
);
5376 out_free_buffer_mask
:
5377 free_cpumask_var(tracing_buffer_mask
);
5382 __init
static int clear_boot_tracer(void)
5385 * The default tracer at boot buffer is an init section.
5386 * This function is called in lateinit. If we did not
5387 * find the boot tracer, then clear it out, to prevent
5388 * later registration from accessing the buffer that is
5389 * about to be freed.
5391 if (!default_bootup_tracer
)
5394 printk(KERN_INFO
"ftrace bootup tracer '%s' not registered.\n",
5395 default_bootup_tracer
);
5396 default_bootup_tracer
= NULL
;
5401 early_initcall(tracer_alloc_buffers
);
5402 fs_initcall(tracer_init_debugfs
);
5403 late_initcall(clear_boot_tracer
);