2 * ring buffer based function tracer
4 * Copyright (C) 2007-2012 Steven Rostedt <srostedt@redhat.com>
5 * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com>
7 * Originally taken from the RT patch by:
8 * Arnaldo Carvalho de Melo <acme@redhat.com>
10 * Based on code from the latency_tracer, that is:
11 * Copyright (C) 2004-2006 Ingo Molnar
12 * Copyright (C) 2004 Nadia Yvette Chambers
14 #include <linux/ring_buffer.h>
15 #include <generated/utsrelease.h>
16 #include <linux/stacktrace.h>
17 #include <linux/writeback.h>
18 #include <linux/kallsyms.h>
19 #include <linux/seq_file.h>
20 #include <linux/notifier.h>
21 #include <linux/irqflags.h>
22 #include <linux/irq_work.h>
23 #include <linux/debugfs.h>
24 #include <linux/pagemap.h>
25 #include <linux/hardirq.h>
26 #include <linux/linkage.h>
27 #include <linux/uaccess.h>
28 #include <linux/kprobes.h>
29 #include <linux/ftrace.h>
30 #include <linux/module.h>
31 #include <linux/percpu.h>
32 #include <linux/splice.h>
33 #include <linux/kdebug.h>
34 #include <linux/string.h>
35 #include <linux/rwsem.h>
36 #include <linux/slab.h>
37 #include <linux/ctype.h>
38 #include <linux/init.h>
39 #include <linux/poll.h>
40 #include <linux/nmi.h>
42 #include <linux/sched/rt.h>
45 #include "trace_output.h"
48 * On boot up, the ring buffer is set to the minimum size, so that
49 * we do not waste memory on systems that are not using tracing.
51 int ring_buffer_expanded;
54 * We need to change this state when a selftest is running.
55 * A selftest will lurk into the ring-buffer to count the
56 * entries inserted during the selftest although some concurrent
57 * insertions into the ring-buffer such as trace_printk could occurred
58 * at the same time, giving false positive or negative results.
60 static bool __read_mostly tracing_selftest_running;
63 * If a tracer is running, we do not want to run SELFTEST.
65 bool __read_mostly tracing_selftest_disabled;
67 /* For tracers that don't implement custom flags */
68 static struct tracer_opt dummy_tracer_opt[] = {
72 static struct tracer_flags dummy_tracer_flags = {
74 .opts = dummy_tracer_opt
77 static int dummy_set_flag(u32 old_flags, u32 bit, int set)
83 * To prevent the comm cache from being overwritten when no
84 * tracing is active, only save the comm when a trace event
87 static DEFINE_PER_CPU(bool, trace_cmdline_save);
90 * When a reader is waiting for data, then this variable is
93 static bool trace_wakeup_needed;
95 static struct irq_work trace_work_wakeup;
98 * Kill all tracing for good (never come back).
99 * It is initialized to 1 but will turn to zero if the initialization
100 * of the tracer is successful. But that is the only place that sets
103 static int tracing_disabled = 1;
105 DEFINE_PER_CPU(int, ftrace_cpu_disabled);
107 cpumask_var_t __read_mostly tracing_buffer_mask;
110 * ftrace_dump_on_oops - variable to dump ftrace buffer on oops
112 * If there is an oops (or kernel panic) and the ftrace_dump_on_oops
113 * is set, then ftrace_dump is called. This will output the contents
114 * of the ftrace buffers to the console. This is very useful for
115 * capturing traces that lead to crashes and outputing it to a
118 * It is default off, but you can enable it with either specifying
119 * "ftrace_dump_on_oops" in the kernel command line, or setting
120 * /proc/sys/kernel/ftrace_dump_on_oops
121 * Set 1 if you want to dump buffers of all CPUs
122 * Set 2 if you want to dump the buffer of the CPU that triggered oops
125 enum ftrace_dump_mode ftrace_dump_on_oops;
127 static int tracing_set_tracer(const char *buf);
129 #define MAX_TRACER_SIZE 100
130 static char bootup_tracer_buf[MAX_TRACER_SIZE] __initdata;
131 static char *default_bootup_tracer;
133 static int __init set_cmdline_ftrace(char *str)
135 strncpy(bootup_tracer_buf, str, MAX_TRACER_SIZE);
136 default_bootup_tracer = bootup_tracer_buf;
137 /* We are using ftrace early, expand it */
138 ring_buffer_expanded = 1;
141 __setup("ftrace=", set_cmdline_ftrace);
143 static int __init set_ftrace_dump_on_oops(char *str)
145 if (*str++ != '=' || !*str) {
146 ftrace_dump_on_oops = DUMP_ALL;
150 if (!strcmp("orig_cpu", str)) {
151 ftrace_dump_on_oops = DUMP_ORIG;
157 __setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops);
160 static char trace_boot_options_buf[MAX_TRACER_SIZE] __initdata;
161 static char *trace_boot_options __initdata;
163 static int __init set_trace_boot_options(char *str)
165 strncpy(trace_boot_options_buf, str, MAX_TRACER_SIZE);
166 trace_boot_options = trace_boot_options_buf;
169 __setup("trace_options=", set_trace_boot_options);
171 unsigned long long ns2usecs(cycle_t nsec)
179 * The global_trace is the descriptor that holds the tracing
180 * buffers for the live tracing. For each CPU, it contains
181 * a link list of pages that will store trace entries. The
182 * page descriptor of the pages in the memory is used to hold
183 * the link list by linking the lru item in the page descriptor
184 * to each of the pages in the buffer per CPU.
186 * For each active CPU there is a data field that holds the
187 * pages for the buffer for that CPU. Each CPU has the same number
188 * of pages allocated for its buffer.
190 static struct trace_array global_trace;
192 LIST_HEAD(ftrace_trace_arrays);
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 int tracing_is_enabled(void)
230 return tracing_is_on();
234 * trace_buf_size is the size in bytes that is allocated
235 * for a buffer. Note, the number of bytes is always rounded
238 * This number is purposely set to a low number of 16384.
239 * If the dump on oops happens, it will be much appreciated
240 * to not have to wait for all that output. Anyway this can be
241 * boot time and run time configurable.
243 #define TRACE_BUF_SIZE_DEFAULT 1441792UL /* 16384 * 88 (sizeof(entry)) */
245 static unsigned long trace_buf_size = TRACE_BUF_SIZE_DEFAULT;
247 /* trace_types holds a link list of available tracers. */
248 static struct tracer *trace_types __read_mostly;
251 * trace_types_lock is used to protect the trace_types list.
253 static DEFINE_MUTEX(trace_types_lock);
256 * serialize the access of the ring buffer
258 * ring buffer serializes readers, but it is low level protection.
259 * The validity of the events (which returns by ring_buffer_peek() ..etc)
260 * are not protected by ring buffer.
262 * The content of events may become garbage if we allow other process consumes
263 * these events concurrently:
264 * A) the page of the consumed events may become a normal page
265 * (not reader page) in ring buffer, and this page will be rewrited
266 * by events producer.
267 * B) The page of the consumed events may become a page for splice_read,
268 * and this page will be returned to system.
270 * These primitives allow multi process access to different cpu ring buffer
273 * These primitives don't distinguish read-only and read-consume access.
274 * Multi read-only access are also serialized.
278 static DECLARE_RWSEM(all_cpu_access_lock);
279 static DEFINE_PER_CPU(struct mutex, cpu_access_lock);
281 static inline void trace_access_lock(int cpu)
283 if (cpu == RING_BUFFER_ALL_CPUS) {
284 /* gain it for accessing the whole ring buffer. */
285 down_write(&all_cpu_access_lock);
287 /* gain it for accessing a cpu ring buffer. */
289 /* Firstly block other trace_access_lock(RING_BUFFER_ALL_CPUS). */
290 down_read(&all_cpu_access_lock);
292 /* Secondly block other access to this @cpu ring buffer. */
293 mutex_lock(&per_cpu(cpu_access_lock, cpu));
297 static inline void trace_access_unlock(int cpu)
299 if (cpu == RING_BUFFER_ALL_CPUS) {
300 up_write(&all_cpu_access_lock);
302 mutex_unlock(&per_cpu(cpu_access_lock, cpu));
303 up_read(&all_cpu_access_lock);
307 static inline void trace_access_lock_init(void)
311 for_each_possible_cpu(cpu)
312 mutex_init(&per_cpu(cpu_access_lock, cpu));
317 static DEFINE_MUTEX(access_lock);
319 static inline void trace_access_lock(int cpu)
322 mutex_lock(&access_lock);
325 static inline void trace_access_unlock(int cpu)
328 mutex_unlock(&access_lock);
331 static inline void trace_access_lock_init(void)
337 /* trace_wait is a waitqueue for tasks blocked on trace_poll */
338 static DECLARE_WAIT_QUEUE_HEAD(trace_wait);
340 /* trace_flags holds trace_options default values */
341 unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |
342 TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | TRACE_ITER_SLEEP_TIME |
343 TRACE_ITER_GRAPH_TIME | TRACE_ITER_RECORD_CMD | TRACE_ITER_OVERWRITE |
344 TRACE_ITER_IRQ_INFO | TRACE_ITER_MARKERS;
347 * trace_wake_up - wake up tasks waiting for trace input
349 * Schedules a delayed work to wake up any task that is blocked on the
350 * trace_wait queue. These is used with trace_poll for tasks polling the
353 static void trace_wake_up(struct irq_work *work)
355 wake_up_all(&trace_wait);
360 * tracing_on - enable tracing buffers
362 * This function enables tracing buffers that may have been
363 * disabled with tracing_off.
365 void tracing_on(void)
367 if (global_trace.buffer)
368 ring_buffer_record_on(global_trace.buffer);
370 * This flag is only looked at when buffers haven't been
371 * allocated yet. We don't really care about the race
372 * between setting this flag and actually turning
375 global_trace.buffer_disabled = 0;
377 EXPORT_SYMBOL_GPL(tracing_on);
380 * tracing_off - turn off tracing buffers
382 * This function stops the tracing buffers from recording data.
383 * It does not disable any overhead the tracers themselves may
384 * be causing. This function simply causes all recording to
385 * the ring buffers to fail.
387 void tracing_off(void)
389 if (global_trace.buffer)
390 ring_buffer_record_off(global_trace.buffer);
392 * This flag is only looked at when buffers haven't been
393 * allocated yet. We don't really care about the race
394 * between setting this flag and actually turning
397 global_trace.buffer_disabled = 1;
399 EXPORT_SYMBOL_GPL(tracing_off);
402 * tracing_is_on - show state of ring buffers enabled
404 int tracing_is_on(void)
406 if (global_trace.buffer)
407 return ring_buffer_record_is_on(global_trace.buffer);
408 return !global_trace.buffer_disabled;
410 EXPORT_SYMBOL_GPL(tracing_is_on);
412 static int __init set_buf_size(char *str)
414 unsigned long buf_size;
418 buf_size = memparse(str, &str);
419 /* nr_entries can not be zero */
422 trace_buf_size = buf_size;
425 __setup("trace_buf_size=", set_buf_size);
427 static int __init set_tracing_thresh(char *str)
429 unsigned long threshold;
434 ret = kstrtoul(str, 0, &threshold);
437 tracing_thresh = threshold * 1000;
440 __setup("tracing_thresh=", set_tracing_thresh);
442 unsigned long nsecs_to_usecs(unsigned long nsecs)
447 /* These must match the bit postions in trace_iterator_flags */
448 static const char *trace_options[] = {
480 int in_ns; /* is this clock in nanoseconds? */
482 { trace_clock_local, "local", 1 },
483 { trace_clock_global, "global", 1 },
484 { trace_clock_counter, "counter", 0 },
491 * trace_parser_get_init - gets the buffer for trace parser
493 int trace_parser_get_init(struct trace_parser *parser, int size)
495 memset(parser, 0, sizeof(*parser));
497 parser->buffer = kmalloc(size, GFP_KERNEL);
506 * trace_parser_put - frees the buffer for trace parser
508 void trace_parser_put(struct trace_parser *parser)
510 kfree(parser->buffer);
514 * trace_get_user - reads the user input string separated by space
515 * (matched by isspace(ch))
517 * For each string found the 'struct trace_parser' is updated,
518 * and the function returns.
520 * Returns number of bytes read.
522 * See kernel/trace/trace.h for 'struct trace_parser' details.
524 int trace_get_user(struct trace_parser *parser, const char __user *ubuf,
525 size_t cnt, loff_t *ppos)
532 trace_parser_clear(parser);
534 ret = get_user(ch, ubuf++);
542 * The parser is not finished with the last write,
543 * continue reading the user input without skipping spaces.
546 /* skip white space */
547 while (cnt && isspace(ch)) {
548 ret = get_user(ch, ubuf++);
555 /* only spaces were written */
565 /* read the non-space input */
566 while (cnt && !isspace(ch)) {
567 if (parser->idx < parser->size - 1)
568 parser->buffer[parser->idx++] = ch;
573 ret = get_user(ch, ubuf++);
580 /* We either got finished input or we have to wait for another call. */
582 parser->buffer[parser->idx] = 0;
583 parser->cont = false;
586 parser->buffer[parser->idx++] = ch;
596 ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt)
604 if (s->len <= s->readpos)
607 len = s->len - s->readpos;
610 ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt);
620 static ssize_t trace_seq_to_buffer(struct trace_seq *s, void *buf, size_t cnt)
624 if (s->len <= s->readpos)
627 len = s->len - s->readpos;
630 memcpy(buf, s->buffer + s->readpos, cnt);
637 * ftrace_max_lock is used to protect the swapping of buffers
638 * when taking a max snapshot. The buffers themselves are
639 * protected by per_cpu spinlocks. But the action of the swap
640 * needs its own lock.
642 * This is defined as a arch_spinlock_t in order to help
643 * with performance when lockdep debugging is enabled.
645 * It is also used in other places outside the update_max_tr
646 * so it needs to be defined outside of the
647 * CONFIG_TRACER_MAX_TRACE.
649 static arch_spinlock_t ftrace_max_lock =
650 (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED;
652 unsigned long __read_mostly tracing_thresh;
654 #ifdef CONFIG_TRACER_MAX_TRACE
655 unsigned long __read_mostly tracing_max_latency;
658 * Copy the new maximum trace into the separate maximum-trace
659 * structure. (this way the maximum trace is permanently saved,
660 * for later retrieval via /sys/kernel/debug/tracing/latency_trace)
663 __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
665 struct trace_array_cpu *data = per_cpu_ptr(tr->data, cpu);
666 struct trace_array_cpu *max_data;
669 max_tr.time_start = data->preempt_timestamp;
671 max_data = per_cpu_ptr(max_tr.data, cpu);
672 max_data->saved_latency = tracing_max_latency;
673 max_data->critical_start = data->critical_start;
674 max_data->critical_end = data->critical_end;
676 memcpy(max_data->comm, tsk->comm, TASK_COMM_LEN);
677 max_data->pid = tsk->pid;
678 max_data->uid = task_uid(tsk);
679 max_data->nice = tsk->static_prio - 20 - MAX_RT_PRIO;
680 max_data->policy = tsk->policy;
681 max_data->rt_priority = tsk->rt_priority;
683 /* record this tasks comm */
684 tracing_record_cmdline(tsk);
688 * update_max_tr - snapshot all trace buffers from global_trace to max_tr
690 * @tsk: the task with the latency
691 * @cpu: The cpu that initiated the trace.
693 * Flip the buffers between the @tr and the max_tr and record information
694 * about which task was the cause of this latency.
697 update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
699 struct ring_buffer *buf;
704 WARN_ON_ONCE(!irqs_disabled());
706 if (!tr->current_trace->allocated_snapshot) {
707 /* Only the nop tracer should hit this when disabling */
708 WARN_ON_ONCE(tr->current_trace != &nop_trace);
712 arch_spin_lock(&ftrace_max_lock);
715 tr->buffer = max_tr.buffer;
718 __update_max_tr(tr, tsk, cpu);
719 arch_spin_unlock(&ftrace_max_lock);
723 * update_max_tr_single - only copy one trace over, and reset the rest
725 * @tsk - task with the latency
726 * @cpu - the cpu of the buffer to copy.
728 * Flip the trace of a single CPU buffer between the @tr and the max_tr.
731 update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu)
738 WARN_ON_ONCE(!irqs_disabled());
739 if (WARN_ON_ONCE(!tr->current_trace->allocated_snapshot))
742 arch_spin_lock(&ftrace_max_lock);
744 ret = ring_buffer_swap_cpu(max_tr.buffer, tr->buffer, cpu);
748 * We failed to swap the buffer due to a commit taking
749 * place on this CPU. We fail to record, but we reset
750 * the max trace buffer (no one writes directly to it)
751 * and flag that it failed.
753 trace_array_printk(&max_tr, _THIS_IP_,
754 "Failed to swap buffers due to commit in progress\n");
757 WARN_ON_ONCE(ret && ret != -EAGAIN && ret != -EBUSY);
759 __update_max_tr(tr, tsk, cpu);
760 arch_spin_unlock(&ftrace_max_lock);
762 #endif /* CONFIG_TRACER_MAX_TRACE */
764 static void default_wait_pipe(struct trace_iterator *iter)
768 prepare_to_wait(&trace_wait, &wait, TASK_INTERRUPTIBLE);
771 * The events can happen in critical sections where
772 * checking a work queue can cause deadlocks.
773 * After adding a task to the queue, this flag is set
774 * only to notify events to try to wake up the queue
777 * We don't clear it even if the buffer is no longer
778 * empty. The flag only causes the next event to run
779 * irq_work to do the work queue wake up. The worse
780 * that can happen if we race with !trace_empty() is that
781 * an event will cause an irq_work to try to wake up
784 * There's no reason to protect this flag either, as
785 * the work queue and irq_work logic will do the necessary
786 * synchronization for the wake ups. The only thing
787 * that is necessary is that the wake up happens after
788 * a task has been queued. It's OK for spurious wake ups.
790 trace_wakeup_needed = true;
792 if (trace_empty(iter))
795 finish_wait(&trace_wait, &wait);
799 * register_tracer - register a tracer with the ftrace system.
800 * @type - the plugin for the tracer
802 * Register a new plugin tracer.
804 int register_tracer(struct tracer *type)
810 pr_info("Tracer must have a name\n");
814 if (strlen(type->name) >= MAX_TRACER_SIZE) {
815 pr_info("Tracer has a name longer than %d\n", MAX_TRACER_SIZE);
819 mutex_lock(&trace_types_lock);
821 tracing_selftest_running = true;
823 for (t = trace_types; t; t = t->next) {
824 if (strcmp(type->name, t->name) == 0) {
826 pr_info("Tracer %s already registered\n",
834 type->set_flag = &dummy_set_flag;
836 type->flags = &dummy_tracer_flags;
838 if (!type->flags->opts)
839 type->flags->opts = dummy_tracer_opt;
840 if (!type->wait_pipe)
841 type->wait_pipe = default_wait_pipe;
844 #ifdef CONFIG_FTRACE_STARTUP_TEST
845 if (type->selftest && !tracing_selftest_disabled) {
846 struct trace_array *tr = &global_trace;
847 struct tracer *saved_tracer = tr->current_trace;
850 * Run a selftest on this tracer.
851 * Here we reset the trace buffer, and set the current
852 * tracer to be this tracer. The tracer can then run some
853 * internal tracing to verify that everything is in order.
854 * If we fail, we do not register this tracer.
856 tracing_reset_online_cpus(tr);
858 tr->current_trace = type;
860 if (type->use_max_tr) {
861 /* If we expanded the buffers, make sure the max is expanded too */
862 if (ring_buffer_expanded)
863 ring_buffer_resize(max_tr.buffer, trace_buf_size,
864 RING_BUFFER_ALL_CPUS);
865 type->allocated_snapshot = true;
868 /* the test is responsible for initializing and enabling */
869 pr_info("Testing tracer %s: ", type->name);
870 ret = type->selftest(type, tr);
871 /* the test is responsible for resetting too */
872 tr->current_trace = saved_tracer;
874 printk(KERN_CONT "FAILED!\n");
875 /* Add the warning after printing 'FAILED' */
879 /* Only reset on passing, to avoid touching corrupted buffers */
880 tracing_reset_online_cpus(tr);
882 if (type->use_max_tr) {
883 type->allocated_snapshot = false;
885 /* Shrink the max buffer again */
886 if (ring_buffer_expanded)
887 ring_buffer_resize(max_tr.buffer, 1,
888 RING_BUFFER_ALL_CPUS);
891 printk(KERN_CONT "PASSED\n");
895 type->next = trace_types;
899 tracing_selftest_running = false;
900 mutex_unlock(&trace_types_lock);
902 if (ret || !default_bootup_tracer)
905 if (strncmp(default_bootup_tracer, type->name, MAX_TRACER_SIZE))
908 printk(KERN_INFO "Starting tracer '%s'\n", type->name);
909 /* Do we want this tracer to start on bootup? */
910 tracing_set_tracer(type->name);
911 default_bootup_tracer = NULL;
912 /* disable other selftests, since this will break it. */
913 tracing_selftest_disabled = 1;
914 #ifdef CONFIG_FTRACE_STARTUP_TEST
915 printk(KERN_INFO "Disabling FTRACE selftests due to running tracer '%s'\n",
923 void tracing_reset(struct trace_array *tr, int cpu)
925 struct ring_buffer *buffer = tr->buffer;
930 ring_buffer_record_disable(buffer);
932 /* Make sure all commits have finished */
934 ring_buffer_reset_cpu(buffer, cpu);
936 ring_buffer_record_enable(buffer);
939 void tracing_reset_online_cpus(struct trace_array *tr)
941 struct ring_buffer *buffer = tr->buffer;
947 ring_buffer_record_disable(buffer);
949 /* Make sure all commits have finished */
952 tr->time_start = ftrace_now(tr->cpu);
954 for_each_online_cpu(cpu)
955 ring_buffer_reset_cpu(buffer, cpu);
957 ring_buffer_record_enable(buffer);
960 void tracing_reset_current(int cpu)
962 tracing_reset(&global_trace, cpu);
965 void tracing_reset_current_online_cpus(void)
967 tracing_reset_online_cpus(&global_trace);
970 #define SAVED_CMDLINES 128
971 #define NO_CMDLINE_MAP UINT_MAX
972 static unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
973 static unsigned map_cmdline_to_pid[SAVED_CMDLINES];
974 static char saved_cmdlines[SAVED_CMDLINES][TASK_COMM_LEN];
975 static int cmdline_idx;
976 static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED;
978 /* temporary disable recording */
979 static atomic_t trace_record_cmdline_disabled __read_mostly;
981 static void trace_init_cmdlines(void)
983 memset(&map_pid_to_cmdline, NO_CMDLINE_MAP, sizeof(map_pid_to_cmdline));
984 memset(&map_cmdline_to_pid, NO_CMDLINE_MAP, sizeof(map_cmdline_to_pid));
988 int is_tracing_stopped(void)
990 return global_trace.stop_count;
994 * ftrace_off_permanent - disable all ftrace code permanently
996 * This should only be called when a serious anomally has
997 * been detected. This will turn off the function tracing,
998 * ring buffers, and other tracing utilites. It takes no
999 * locks and can be called from any context.
1001 void ftrace_off_permanent(void)
1003 tracing_disabled = 1;
1005 tracing_off_permanent();
1009 * tracing_start - quick start of the tracer
1011 * If tracing is enabled but was stopped by tracing_stop,
1012 * this will start the tracer back up.
1014 void tracing_start(void)
1016 struct ring_buffer *buffer;
1017 unsigned long flags;
1019 if (tracing_disabled)
1022 raw_spin_lock_irqsave(&global_trace.start_lock, flags);
1023 if (--global_trace.stop_count) {
1024 if (global_trace.stop_count < 0) {
1025 /* Someone screwed up their debugging */
1027 global_trace.stop_count = 0;
1032 /* Prevent the buffers from switching */
1033 arch_spin_lock(&ftrace_max_lock);
1035 buffer = global_trace.buffer;
1037 ring_buffer_record_enable(buffer);
1039 buffer = max_tr.buffer;
1041 ring_buffer_record_enable(buffer);
1043 arch_spin_unlock(&ftrace_max_lock);
1047 raw_spin_unlock_irqrestore(&global_trace.start_lock, flags);
1050 static void tracing_start_tr(struct trace_array *tr)
1052 struct ring_buffer *buffer;
1053 unsigned long flags;
1055 if (tracing_disabled)
1058 /* If global, we need to also start the max tracer */
1059 if (tr->flags & TRACE_ARRAY_FL_GLOBAL)
1060 return tracing_start();
1062 raw_spin_lock_irqsave(&tr->start_lock, flags);
1064 if (--tr->stop_count) {
1065 if (tr->stop_count < 0) {
1066 /* Someone screwed up their debugging */
1073 buffer = tr->buffer;
1075 ring_buffer_record_enable(buffer);
1078 raw_spin_unlock_irqrestore(&tr->start_lock, flags);
1082 * tracing_stop - quick stop of the tracer
1084 * Light weight way to stop tracing. Use in conjunction with
1087 void tracing_stop(void)
1089 struct ring_buffer *buffer;
1090 unsigned long flags;
1093 raw_spin_lock_irqsave(&global_trace.start_lock, flags);
1094 if (global_trace.stop_count++)
1097 /* Prevent the buffers from switching */
1098 arch_spin_lock(&ftrace_max_lock);
1100 buffer = global_trace.buffer;
1102 ring_buffer_record_disable(buffer);
1104 buffer = max_tr.buffer;
1106 ring_buffer_record_disable(buffer);
1108 arch_spin_unlock(&ftrace_max_lock);
1111 raw_spin_unlock_irqrestore(&global_trace.start_lock, flags);
1114 static void tracing_stop_tr(struct trace_array *tr)
1116 struct ring_buffer *buffer;
1117 unsigned long flags;
1119 /* If global, we need to also stop the max tracer */
1120 if (tr->flags & TRACE_ARRAY_FL_GLOBAL)
1121 return tracing_stop();
1123 raw_spin_lock_irqsave(&tr->start_lock, flags);
1124 if (tr->stop_count++)
1127 buffer = tr->buffer;
1129 ring_buffer_record_disable(buffer);
1132 raw_spin_unlock_irqrestore(&tr->start_lock, flags);
1135 void trace_stop_cmdline_recording(void);
1137 static void trace_save_cmdline(struct task_struct *tsk)
1141 if (!tsk->pid || unlikely(tsk->pid > PID_MAX_DEFAULT))
1145 * It's not the end of the world if we don't get
1146 * the lock, but we also don't want to spin
1147 * nor do we want to disable interrupts,
1148 * so if we miss here, then better luck next time.
1150 if (!arch_spin_trylock(&trace_cmdline_lock))
1153 idx = map_pid_to_cmdline[tsk->pid];
1154 if (idx == NO_CMDLINE_MAP) {
1155 idx = (cmdline_idx + 1) % SAVED_CMDLINES;
1158 * Check whether the cmdline buffer at idx has a pid
1159 * mapped. We are going to overwrite that entry so we
1160 * need to clear the map_pid_to_cmdline. Otherwise we
1161 * would read the new comm for the old pid.
1163 pid = map_cmdline_to_pid[idx];
1164 if (pid != NO_CMDLINE_MAP)
1165 map_pid_to_cmdline[pid] = NO_CMDLINE_MAP;
1167 map_cmdline_to_pid[idx] = tsk->pid;
1168 map_pid_to_cmdline[tsk->pid] = idx;
1173 memcpy(&saved_cmdlines[idx], tsk->comm, TASK_COMM_LEN);
1175 arch_spin_unlock(&trace_cmdline_lock);
1178 void trace_find_cmdline(int pid, char comm[])
1183 strcpy(comm, "<idle>");
1187 if (WARN_ON_ONCE(pid < 0)) {
1188 strcpy(comm, "<XXX>");
1192 if (pid > PID_MAX_DEFAULT) {
1193 strcpy(comm, "<...>");
1198 arch_spin_lock(&trace_cmdline_lock);
1199 map = map_pid_to_cmdline[pid];
1200 if (map != NO_CMDLINE_MAP)
1201 strcpy(comm, saved_cmdlines[map]);
1203 strcpy(comm, "<...>");
1205 arch_spin_unlock(&trace_cmdline_lock);
1209 void tracing_record_cmdline(struct task_struct *tsk)
1211 if (atomic_read(&trace_record_cmdline_disabled) || !tracing_is_on())
1214 if (!__this_cpu_read(trace_cmdline_save))
1217 __this_cpu_write(trace_cmdline_save, false);
1219 trace_save_cmdline(tsk);
1223 tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags,
1226 struct task_struct *tsk = current;
1228 entry->preempt_count = pc & 0xff;
1229 entry->pid = (tsk) ? tsk->pid : 0;
1231 #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
1232 (irqs_disabled_flags(flags) ? TRACE_FLAG_IRQS_OFF : 0) |
1234 TRACE_FLAG_IRQS_NOSUPPORT |
1236 ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) |
1237 ((pc & SOFTIRQ_MASK) ? TRACE_FLAG_SOFTIRQ : 0) |
1238 (need_resched() ? TRACE_FLAG_NEED_RESCHED : 0);
1240 EXPORT_SYMBOL_GPL(tracing_generic_entry_update);
1242 struct ring_buffer_event *
1243 trace_buffer_lock_reserve(struct ring_buffer *buffer,
1246 unsigned long flags, int pc)
1248 struct ring_buffer_event *event;
1250 event = ring_buffer_lock_reserve(buffer, len);
1251 if (event != NULL) {
1252 struct trace_entry *ent = ring_buffer_event_data(event);
1254 tracing_generic_entry_update(ent, flags, pc);
1262 __buffer_unlock_commit(struct ring_buffer *buffer, struct ring_buffer_event *event)
1264 __this_cpu_write(trace_cmdline_save, true);
1265 if (trace_wakeup_needed) {
1266 trace_wakeup_needed = false;
1267 /* irq_work_queue() supplies it's own memory barriers */
1268 irq_work_queue(&trace_work_wakeup);
1270 ring_buffer_unlock_commit(buffer, event);
1274 __trace_buffer_unlock_commit(struct ring_buffer *buffer,
1275 struct ring_buffer_event *event,
1276 unsigned long flags, int pc)
1278 __buffer_unlock_commit(buffer, event);
1280 ftrace_trace_stack(buffer, flags, 6, pc);
1281 ftrace_trace_userstack(buffer, flags, pc);
1284 void trace_buffer_unlock_commit(struct ring_buffer *buffer,
1285 struct ring_buffer_event *event,
1286 unsigned long flags, int pc)
1288 __trace_buffer_unlock_commit(buffer, event, flags, pc);
1290 EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit);
1292 struct ring_buffer_event *
1293 trace_event_buffer_lock_reserve(struct ring_buffer **current_rb,
1294 struct ftrace_event_file *ftrace_file,
1295 int type, unsigned long len,
1296 unsigned long flags, int pc)
1298 *current_rb = ftrace_file->tr->buffer;
1299 return trace_buffer_lock_reserve(*current_rb,
1300 type, len, flags, pc);
1302 EXPORT_SYMBOL_GPL(trace_event_buffer_lock_reserve);
1304 struct ring_buffer_event *
1305 trace_current_buffer_lock_reserve(struct ring_buffer **current_rb,
1306 int type, unsigned long len,
1307 unsigned long flags, int pc)
1309 *current_rb = global_trace.buffer;
1310 return trace_buffer_lock_reserve(*current_rb,
1311 type, len, flags, pc);
1313 EXPORT_SYMBOL_GPL(trace_current_buffer_lock_reserve);
1315 void trace_current_buffer_unlock_commit(struct ring_buffer *buffer,
1316 struct ring_buffer_event *event,
1317 unsigned long flags, int pc)
1319 __trace_buffer_unlock_commit(buffer, event, flags, pc);
1321 EXPORT_SYMBOL_GPL(trace_current_buffer_unlock_commit);
1323 void trace_buffer_unlock_commit_regs(struct ring_buffer *buffer,
1324 struct ring_buffer_event *event,
1325 unsigned long flags, int pc,
1326 struct pt_regs *regs)
1328 __buffer_unlock_commit(buffer, event);
1330 ftrace_trace_stack_regs(buffer, flags, 0, pc, regs);
1331 ftrace_trace_userstack(buffer, flags, pc);
1333 EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit_regs);
1335 void trace_current_buffer_discard_commit(struct ring_buffer *buffer,
1336 struct ring_buffer_event *event)
1338 ring_buffer_discard_commit(buffer, event);
1340 EXPORT_SYMBOL_GPL(trace_current_buffer_discard_commit);
1343 trace_function(struct trace_array *tr,
1344 unsigned long ip, unsigned long parent_ip, unsigned long flags,
1347 struct ftrace_event_call *call = &event_function;
1348 struct ring_buffer *buffer = tr->buffer;
1349 struct ring_buffer_event *event;
1350 struct ftrace_entry *entry;
1352 /* If we are reading the ring buffer, don't trace */
1353 if (unlikely(__this_cpu_read(ftrace_cpu_disabled)))
1356 event = trace_buffer_lock_reserve(buffer, TRACE_FN, sizeof(*entry),
1360 entry = ring_buffer_event_data(event);
1362 entry->parent_ip = parent_ip;
1364 if (!filter_check_discard(call, entry, buffer, event))
1365 __buffer_unlock_commit(buffer, event);
1369 ftrace(struct trace_array *tr, struct trace_array_cpu *data,
1370 unsigned long ip, unsigned long parent_ip, unsigned long flags,
1373 if (likely(!atomic_read(&data->disabled)))
1374 trace_function(tr, ip, parent_ip, flags, pc);
1377 #ifdef CONFIG_STACKTRACE
1379 #define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long))
1380 struct ftrace_stack {
1381 unsigned long calls[FTRACE_STACK_MAX_ENTRIES];
1384 static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);
1385 static DEFINE_PER_CPU(int, ftrace_stack_reserve);
1387 static void __ftrace_trace_stack(struct ring_buffer *buffer,
1388 unsigned long flags,
1389 int skip, int pc, struct pt_regs *regs)
1391 struct ftrace_event_call *call = &event_kernel_stack;
1392 struct ring_buffer_event *event;
1393 struct stack_entry *entry;
1394 struct stack_trace trace;
1396 int size = FTRACE_STACK_ENTRIES;
1398 trace.nr_entries = 0;
1402 * Since events can happen in NMIs there's no safe way to
1403 * use the per cpu ftrace_stacks. We reserve it and if an interrupt
1404 * or NMI comes in, it will just have to use the default
1405 * FTRACE_STACK_SIZE.
1407 preempt_disable_notrace();
1409 use_stack = __this_cpu_inc_return(ftrace_stack_reserve);
1411 * We don't need any atomic variables, just a barrier.
1412 * If an interrupt comes in, we don't care, because it would
1413 * have exited and put the counter back to what we want.
1414 * We just need a barrier to keep gcc from moving things
1418 if (use_stack == 1) {
1419 trace.entries = &__get_cpu_var(ftrace_stack).calls[0];
1420 trace.max_entries = FTRACE_STACK_MAX_ENTRIES;
1423 save_stack_trace_regs(regs, &trace);
1425 save_stack_trace(&trace);
1427 if (trace.nr_entries > size)
1428 size = trace.nr_entries;
1430 /* From now on, use_stack is a boolean */
1433 size *= sizeof(unsigned long);
1435 event = trace_buffer_lock_reserve(buffer, TRACE_STACK,
1436 sizeof(*entry) + size, flags, pc);
1439 entry = ring_buffer_event_data(event);
1441 memset(&entry->caller, 0, size);
1444 memcpy(&entry->caller, trace.entries,
1445 trace.nr_entries * sizeof(unsigned long));
1447 trace.max_entries = FTRACE_STACK_ENTRIES;
1448 trace.entries = entry->caller;
1450 save_stack_trace_regs(regs, &trace);
1452 save_stack_trace(&trace);
1455 entry->size = trace.nr_entries;
1457 if (!filter_check_discard(call, entry, buffer, event))
1458 __buffer_unlock_commit(buffer, event);
1461 /* Again, don't let gcc optimize things here */
1463 __this_cpu_dec(ftrace_stack_reserve);
1464 preempt_enable_notrace();
1468 void ftrace_trace_stack_regs(struct ring_buffer *buffer, unsigned long flags,
1469 int skip, int pc, struct pt_regs *regs)
1471 if (!(trace_flags & TRACE_ITER_STACKTRACE))
1474 __ftrace_trace_stack(buffer, flags, skip, pc, regs);
1477 void ftrace_trace_stack(struct ring_buffer *buffer, unsigned long flags,
1480 if (!(trace_flags & TRACE_ITER_STACKTRACE))
1483 __ftrace_trace_stack(buffer, flags, skip, pc, NULL);
1486 void __trace_stack(struct trace_array *tr, unsigned long flags, int skip,
1489 __ftrace_trace_stack(tr->buffer, flags, skip, pc, NULL);
1493 * trace_dump_stack - record a stack back trace in the trace buffer
1495 void trace_dump_stack(void)
1497 unsigned long flags;
1499 if (tracing_disabled || tracing_selftest_running)
1502 local_save_flags(flags);
1504 /* skipping 3 traces, seems to get us at the caller of this function */
1505 __ftrace_trace_stack(global_trace.buffer, flags, 3, preempt_count(), NULL);
1508 static DEFINE_PER_CPU(int, user_stack_count);
1511 ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags, int pc)
1513 struct ftrace_event_call *call = &event_user_stack;
1514 struct ring_buffer_event *event;
1515 struct userstack_entry *entry;
1516 struct stack_trace trace;
1518 if (!(trace_flags & TRACE_ITER_USERSTACKTRACE))
1522 * NMIs can not handle page faults, even with fix ups.
1523 * The save user stack can (and often does) fault.
1525 if (unlikely(in_nmi()))
1529 * prevent recursion, since the user stack tracing may
1530 * trigger other kernel events.
1533 if (__this_cpu_read(user_stack_count))
1536 __this_cpu_inc(user_stack_count);
1538 event = trace_buffer_lock_reserve(buffer, TRACE_USER_STACK,
1539 sizeof(*entry), flags, pc);
1541 goto out_drop_count;
1542 entry = ring_buffer_event_data(event);
1544 entry->tgid = current->tgid;
1545 memset(&entry->caller, 0, sizeof(entry->caller));
1547 trace.nr_entries = 0;
1548 trace.max_entries = FTRACE_STACK_ENTRIES;
1550 trace.entries = entry->caller;
1552 save_stack_trace_user(&trace);
1553 if (!filter_check_discard(call, entry, buffer, event))
1554 __buffer_unlock_commit(buffer, event);
1557 __this_cpu_dec(user_stack_count);
1563 static void __trace_userstack(struct trace_array *tr, unsigned long flags)
1565 ftrace_trace_userstack(tr, flags, preempt_count());
1569 #endif /* CONFIG_STACKTRACE */
1571 /* created for use with alloc_percpu */
1572 struct trace_buffer_struct {
1573 char buffer[TRACE_BUF_SIZE];
1576 static struct trace_buffer_struct *trace_percpu_buffer;
1577 static struct trace_buffer_struct *trace_percpu_sirq_buffer;
1578 static struct trace_buffer_struct *trace_percpu_irq_buffer;
1579 static struct trace_buffer_struct *trace_percpu_nmi_buffer;
1582 * The buffer used is dependent on the context. There is a per cpu
1583 * buffer for normal context, softirq contex, hard irq context and
1584 * for NMI context. Thise allows for lockless recording.
1586 * Note, if the buffers failed to be allocated, then this returns NULL
1588 static char *get_trace_buf(void)
1590 struct trace_buffer_struct *percpu_buffer;
1593 * If we have allocated per cpu buffers, then we do not
1594 * need to do any locking.
1597 percpu_buffer = trace_percpu_nmi_buffer;
1599 percpu_buffer = trace_percpu_irq_buffer;
1600 else if (in_softirq())
1601 percpu_buffer = trace_percpu_sirq_buffer;
1603 percpu_buffer = trace_percpu_buffer;
1608 return this_cpu_ptr(&percpu_buffer->buffer[0]);
1611 static int alloc_percpu_trace_buffer(void)
1613 struct trace_buffer_struct *buffers;
1614 struct trace_buffer_struct *sirq_buffers;
1615 struct trace_buffer_struct *irq_buffers;
1616 struct trace_buffer_struct *nmi_buffers;
1618 buffers = alloc_percpu(struct trace_buffer_struct);
1622 sirq_buffers = alloc_percpu(struct trace_buffer_struct);
1626 irq_buffers = alloc_percpu(struct trace_buffer_struct);
1630 nmi_buffers = alloc_percpu(struct trace_buffer_struct);
1634 trace_percpu_buffer = buffers;
1635 trace_percpu_sirq_buffer = sirq_buffers;
1636 trace_percpu_irq_buffer = irq_buffers;
1637 trace_percpu_nmi_buffer = nmi_buffers;
1642 free_percpu(irq_buffers);
1644 free_percpu(sirq_buffers);
1646 free_percpu(buffers);
1648 WARN(1, "Could not allocate percpu trace_printk buffer");
1652 static int buffers_allocated;
1654 void trace_printk_init_buffers(void)
1656 if (buffers_allocated)
1659 if (alloc_percpu_trace_buffer())
1662 pr_info("ftrace: Allocated trace_printk buffers\n");
1664 /* Expand the buffers to set size */
1665 tracing_update_buffers();
1667 buffers_allocated = 1;
1670 * trace_printk_init_buffers() can be called by modules.
1671 * If that happens, then we need to start cmdline recording
1672 * directly here. If the global_trace.buffer is already
1673 * allocated here, then this was called by module code.
1675 if (global_trace.buffer)
1676 tracing_start_cmdline_record();
1679 void trace_printk_start_comm(void)
1681 /* Start tracing comms if trace printk is set */
1682 if (!buffers_allocated)
1684 tracing_start_cmdline_record();
1687 static void trace_printk_start_stop_comm(int enabled)
1689 if (!buffers_allocated)
1693 tracing_start_cmdline_record();
1695 tracing_stop_cmdline_record();
1699 * trace_vbprintk - write binary msg to tracing buffer
1702 int trace_vbprintk(unsigned long ip, const char *fmt, va_list args)
1704 struct ftrace_event_call *call = &event_bprint;
1705 struct ring_buffer_event *event;
1706 struct ring_buffer *buffer;
1707 struct trace_array *tr = &global_trace;
1708 struct bprint_entry *entry;
1709 unsigned long flags;
1711 int len = 0, size, pc;
1713 if (unlikely(tracing_selftest_running || tracing_disabled))
1716 /* Don't pollute graph traces with trace_vprintk internals */
1717 pause_graph_tracing();
1719 pc = preempt_count();
1720 preempt_disable_notrace();
1722 tbuffer = get_trace_buf();
1728 len = vbin_printf((u32 *)tbuffer, TRACE_BUF_SIZE/sizeof(int), fmt, args);
1730 if (len > TRACE_BUF_SIZE/sizeof(int) || len < 0)
1733 local_save_flags(flags);
1734 size = sizeof(*entry) + sizeof(u32) * len;
1735 buffer = tr->buffer;
1736 event = trace_buffer_lock_reserve(buffer, TRACE_BPRINT, size,
1740 entry = ring_buffer_event_data(event);
1744 memcpy(entry->buf, tbuffer, sizeof(u32) * len);
1745 if (!filter_check_discard(call, entry, buffer, event)) {
1746 __buffer_unlock_commit(buffer, event);
1747 ftrace_trace_stack(buffer, flags, 6, pc);
1751 preempt_enable_notrace();
1752 unpause_graph_tracing();
1756 EXPORT_SYMBOL_GPL(trace_vbprintk);
1758 int trace_array_printk(struct trace_array *tr,
1759 unsigned long ip, const char *fmt, ...)
1764 if (!(trace_flags & TRACE_ITER_PRINTK))
1768 ret = trace_array_vprintk(tr, ip, fmt, ap);
1773 int trace_array_vprintk(struct trace_array *tr,
1774 unsigned long ip, const char *fmt, va_list args)
1776 struct ftrace_event_call *call = &event_print;
1777 struct ring_buffer_event *event;
1778 struct ring_buffer *buffer;
1779 int len = 0, size, pc;
1780 struct print_entry *entry;
1781 unsigned long flags;
1784 if (tracing_disabled || tracing_selftest_running)
1787 /* Don't pollute graph traces with trace_vprintk internals */
1788 pause_graph_tracing();
1790 pc = preempt_count();
1791 preempt_disable_notrace();
1794 tbuffer = get_trace_buf();
1800 len = vsnprintf(tbuffer, TRACE_BUF_SIZE, fmt, args);
1801 if (len > TRACE_BUF_SIZE)
1804 local_save_flags(flags);
1805 size = sizeof(*entry) + len + 1;
1806 buffer = tr->buffer;
1807 event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, size,
1811 entry = ring_buffer_event_data(event);
1814 memcpy(&entry->buf, tbuffer, len);
1815 entry->buf[len] = '\0';
1816 if (!filter_check_discard(call, entry, buffer, event)) {
1817 __buffer_unlock_commit(buffer, event);
1818 ftrace_trace_stack(buffer, flags, 6, pc);
1821 preempt_enable_notrace();
1822 unpause_graph_tracing();
1827 int trace_vprintk(unsigned long ip, const char *fmt, va_list args)
1829 return trace_array_vprintk(&global_trace, ip, fmt, args);
1831 EXPORT_SYMBOL_GPL(trace_vprintk);
1833 static void trace_iterator_increment(struct trace_iterator *iter)
1835 struct ring_buffer_iter *buf_iter = trace_buffer_iter(iter, iter->cpu);
1839 ring_buffer_read(buf_iter, NULL);
1842 static struct trace_entry *
1843 peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts,
1844 unsigned long *lost_events)
1846 struct ring_buffer_event *event;
1847 struct ring_buffer_iter *buf_iter = trace_buffer_iter(iter, cpu);
1850 event = ring_buffer_iter_peek(buf_iter, ts);
1852 event = ring_buffer_peek(iter->tr->buffer, cpu, ts,
1856 iter->ent_size = ring_buffer_event_length(event);
1857 return ring_buffer_event_data(event);
1863 static struct trace_entry *
1864 __find_next_entry(struct trace_iterator *iter, int *ent_cpu,
1865 unsigned long *missing_events, u64 *ent_ts)
1867 struct ring_buffer *buffer = iter->tr->buffer;
1868 struct trace_entry *ent, *next = NULL;
1869 unsigned long lost_events = 0, next_lost = 0;
1870 int cpu_file = iter->cpu_file;
1871 u64 next_ts = 0, ts;
1877 * If we are in a per_cpu trace file, don't bother by iterating over
1878 * all cpu and peek directly.
1880 if (cpu_file > RING_BUFFER_ALL_CPUS) {
1881 if (ring_buffer_empty_cpu(buffer, cpu_file))
1883 ent = peek_next_entry(iter, cpu_file, ent_ts, missing_events);
1885 *ent_cpu = cpu_file;
1890 for_each_tracing_cpu(cpu) {
1892 if (ring_buffer_empty_cpu(buffer, cpu))
1895 ent = peek_next_entry(iter, cpu, &ts, &lost_events);
1898 * Pick the entry with the smallest timestamp:
1900 if (ent && (!next || ts < next_ts)) {
1904 next_lost = lost_events;
1905 next_size = iter->ent_size;
1909 iter->ent_size = next_size;
1912 *ent_cpu = next_cpu;
1918 *missing_events = next_lost;
1923 /* Find the next real entry, without updating the iterator itself */
1924 struct trace_entry *trace_find_next_entry(struct trace_iterator *iter,
1925 int *ent_cpu, u64 *ent_ts)
1927 return __find_next_entry(iter, ent_cpu, NULL, ent_ts);
1930 /* Find the next real entry, and increment the iterator to the next entry */
1931 void *trace_find_next_entry_inc(struct trace_iterator *iter)
1933 iter->ent = __find_next_entry(iter, &iter->cpu,
1934 &iter->lost_events, &iter->ts);
1937 trace_iterator_increment(iter);
1939 return iter->ent ? iter : NULL;
1942 static void trace_consume(struct trace_iterator *iter)
1944 ring_buffer_consume(iter->tr->buffer, iter->cpu, &iter->ts,
1945 &iter->lost_events);
1948 static void *s_next(struct seq_file *m, void *v, loff_t *pos)
1950 struct trace_iterator *iter = m->private;
1954 WARN_ON_ONCE(iter->leftover);
1958 /* can't go backwards */
1963 ent = trace_find_next_entry_inc(iter);
1967 while (ent && iter->idx < i)
1968 ent = trace_find_next_entry_inc(iter);
1975 void tracing_iter_reset(struct trace_iterator *iter, int cpu)
1977 struct trace_array *tr = iter->tr;
1978 struct ring_buffer_event *event;
1979 struct ring_buffer_iter *buf_iter;
1980 unsigned long entries = 0;
1983 per_cpu_ptr(tr->data, cpu)->skipped_entries = 0;
1985 buf_iter = trace_buffer_iter(iter, cpu);
1989 ring_buffer_iter_reset(buf_iter);
1992 * We could have the case with the max latency tracers
1993 * that a reset never took place on a cpu. This is evident
1994 * by the timestamp being before the start of the buffer.
1996 while ((event = ring_buffer_iter_peek(buf_iter, &ts))) {
1997 if (ts >= iter->tr->time_start)
2000 ring_buffer_read(buf_iter, NULL);
2003 per_cpu_ptr(tr->data, cpu)->skipped_entries = entries;
2007 * The current tracer is copied to avoid a global locking
2010 static void *s_start(struct seq_file *m, loff_t *pos)
2012 struct trace_iterator *iter = m->private;
2013 struct trace_array *tr = iter->tr;
2014 int cpu_file = iter->cpu_file;
2020 * copy the tracer to avoid using a global lock all around.
2021 * iter->trace is a copy of current_trace, the pointer to the
2022 * name may be used instead of a strcmp(), as iter->trace->name
2023 * will point to the same string as current_trace->name.
2025 mutex_lock(&trace_types_lock);
2026 if (unlikely(tr->current_trace && iter->trace->name != tr->current_trace->name))
2027 *iter->trace = *tr->current_trace;
2028 mutex_unlock(&trace_types_lock);
2030 if (iter->snapshot && iter->trace->use_max_tr)
2031 return ERR_PTR(-EBUSY);
2033 if (!iter->snapshot)
2034 atomic_inc(&trace_record_cmdline_disabled);
2036 if (*pos != iter->pos) {
2041 if (cpu_file == RING_BUFFER_ALL_CPUS) {
2042 for_each_tracing_cpu(cpu)
2043 tracing_iter_reset(iter, cpu);
2045 tracing_iter_reset(iter, cpu_file);
2048 for (p = iter; p && l < *pos; p = s_next(m, p, &l))
2053 * If we overflowed the seq_file before, then we want
2054 * to just reuse the trace_seq buffer again.
2060 p = s_next(m, p, &l);
2064 trace_event_read_lock();
2065 trace_access_lock(cpu_file);
2069 static void s_stop(struct seq_file *m, void *p)
2071 struct trace_iterator *iter = m->private;
2073 if (iter->snapshot && iter->trace->use_max_tr)
2076 if (!iter->snapshot)
2077 atomic_dec(&trace_record_cmdline_disabled);
2078 trace_access_unlock(iter->cpu_file);
2079 trace_event_read_unlock();
2083 get_total_entries(struct trace_array *tr, unsigned long *total, unsigned long *entries)
2085 unsigned long count;
2091 for_each_tracing_cpu(cpu) {
2092 count = ring_buffer_entries_cpu(tr->buffer, cpu);
2094 * If this buffer has skipped entries, then we hold all
2095 * entries for the trace and we need to ignore the
2096 * ones before the time stamp.
2098 if (per_cpu_ptr(tr->data, cpu)->skipped_entries) {
2099 count -= per_cpu_ptr(tr->data, cpu)->skipped_entries;
2100 /* total is the same as the entries */
2104 ring_buffer_overrun_cpu(tr->buffer, cpu);
2109 static void print_lat_help_header(struct seq_file *m)
2111 seq_puts(m, "# _------=> CPU# \n");
2112 seq_puts(m, "# / _-----=> irqs-off \n");
2113 seq_puts(m, "# | / _----=> need-resched \n");
2114 seq_puts(m, "# || / _---=> hardirq/softirq \n");
2115 seq_puts(m, "# ||| / _--=> preempt-depth \n");
2116 seq_puts(m, "# |||| / delay \n");
2117 seq_puts(m, "# cmd pid ||||| time | caller \n");
2118 seq_puts(m, "# \\ / ||||| \\ | / \n");
2121 static void print_event_info(struct trace_array *tr, struct seq_file *m)
2123 unsigned long total;
2124 unsigned long entries;
2126 get_total_entries(tr, &total, &entries);
2127 seq_printf(m, "# entries-in-buffer/entries-written: %lu/%lu #P:%d\n",
2128 entries, total, num_online_cpus());
2132 static void print_func_help_header(struct trace_array *tr, struct seq_file *m)
2134 print_event_info(tr, m);
2135 seq_puts(m, "# TASK-PID CPU# TIMESTAMP FUNCTION\n");
2136 seq_puts(m, "# | | | | |\n");
2139 static void print_func_help_header_irq(struct trace_array *tr, struct seq_file *m)
2141 print_event_info(tr, m);
2142 seq_puts(m, "# _-----=> irqs-off\n");
2143 seq_puts(m, "# / _----=> need-resched\n");
2144 seq_puts(m, "# | / _---=> hardirq/softirq\n");
2145 seq_puts(m, "# || / _--=> preempt-depth\n");
2146 seq_puts(m, "# ||| / delay\n");
2147 seq_puts(m, "# TASK-PID CPU# |||| TIMESTAMP FUNCTION\n");
2148 seq_puts(m, "# | | | |||| | |\n");
2152 print_trace_header(struct seq_file *m, struct trace_iterator *iter)
2154 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
2155 struct trace_array *tr = iter->tr;
2156 struct trace_array_cpu *data = per_cpu_ptr(tr->data, tr->cpu);
2157 struct tracer *type = iter->trace;
2158 unsigned long entries;
2159 unsigned long total;
2160 const char *name = "preemption";
2164 get_total_entries(tr, &total, &entries);
2166 seq_printf(m, "# %s latency trace v1.1.5 on %s\n",
2168 seq_puts(m, "# -----------------------------------"
2169 "---------------------------------\n");
2170 seq_printf(m, "# latency: %lu us, #%lu/%lu, CPU#%d |"
2171 " (M:%s VP:%d, KP:%d, SP:%d HP:%d",
2172 nsecs_to_usecs(data->saved_latency),
2176 #if defined(CONFIG_PREEMPT_NONE)
2178 #elif defined(CONFIG_PREEMPT_VOLUNTARY)
2180 #elif defined(CONFIG_PREEMPT)
2185 /* These are reserved for later use */
2188 seq_printf(m, " #P:%d)\n", num_online_cpus());
2192 seq_puts(m, "# -----------------\n");
2193 seq_printf(m, "# | task: %.16s-%d "
2194 "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n",
2195 data->comm, data->pid,
2196 from_kuid_munged(seq_user_ns(m), data->uid), data->nice,
2197 data->policy, data->rt_priority);
2198 seq_puts(m, "# -----------------\n");
2200 if (data->critical_start) {
2201 seq_puts(m, "# => started at: ");
2202 seq_print_ip_sym(&iter->seq, data->critical_start, sym_flags);
2203 trace_print_seq(m, &iter->seq);
2204 seq_puts(m, "\n# => ended at: ");
2205 seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags);
2206 trace_print_seq(m, &iter->seq);
2207 seq_puts(m, "\n#\n");
2213 static void test_cpu_buff_start(struct trace_iterator *iter)
2215 struct trace_seq *s = &iter->seq;
2217 if (!(trace_flags & TRACE_ITER_ANNOTATE))
2220 if (!(iter->iter_flags & TRACE_FILE_ANNOTATE))
2223 if (cpumask_test_cpu(iter->cpu, iter->started))
2226 if (per_cpu_ptr(iter->tr->data, iter->cpu)->skipped_entries)
2229 cpumask_set_cpu(iter->cpu, iter->started);
2231 /* Don't print started cpu buffer for the first entry of the trace */
2233 trace_seq_printf(s, "##### CPU %u buffer started ####\n",
2237 static enum print_line_t print_trace_fmt(struct trace_iterator *iter)
2239 struct trace_seq *s = &iter->seq;
2240 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
2241 struct trace_entry *entry;
2242 struct trace_event *event;
2246 test_cpu_buff_start(iter);
2248 event = ftrace_find_event(entry->type);
2250 if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
2251 if (iter->iter_flags & TRACE_FILE_LAT_FMT) {
2252 if (!trace_print_lat_context(iter))
2255 if (!trace_print_context(iter))
2261 return event->funcs->trace(iter, sym_flags, event);
2263 if (!trace_seq_printf(s, "Unknown type %d\n", entry->type))
2266 return TRACE_TYPE_HANDLED;
2268 return TRACE_TYPE_PARTIAL_LINE;
2271 static enum print_line_t print_raw_fmt(struct trace_iterator *iter)
2273 struct trace_seq *s = &iter->seq;
2274 struct trace_entry *entry;
2275 struct trace_event *event;
2279 if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
2280 if (!trace_seq_printf(s, "%d %d %llu ",
2281 entry->pid, iter->cpu, iter->ts))
2285 event = ftrace_find_event(entry->type);
2287 return event->funcs->raw(iter, 0, event);
2289 if (!trace_seq_printf(s, "%d ?\n", entry->type))
2292 return TRACE_TYPE_HANDLED;
2294 return TRACE_TYPE_PARTIAL_LINE;
2297 static enum print_line_t print_hex_fmt(struct trace_iterator *iter)
2299 struct trace_seq *s = &iter->seq;
2300 unsigned char newline = '\n';
2301 struct trace_entry *entry;
2302 struct trace_event *event;
2306 if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
2307 SEQ_PUT_HEX_FIELD_RET(s, entry->pid);
2308 SEQ_PUT_HEX_FIELD_RET(s, iter->cpu);
2309 SEQ_PUT_HEX_FIELD_RET(s, iter->ts);
2312 event = ftrace_find_event(entry->type);
2314 enum print_line_t ret = event->funcs->hex(iter, 0, event);
2315 if (ret != TRACE_TYPE_HANDLED)
2319 SEQ_PUT_FIELD_RET(s, newline);
2321 return TRACE_TYPE_HANDLED;
2324 static enum print_line_t print_bin_fmt(struct trace_iterator *iter)
2326 struct trace_seq *s = &iter->seq;
2327 struct trace_entry *entry;
2328 struct trace_event *event;
2332 if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
2333 SEQ_PUT_FIELD_RET(s, entry->pid);
2334 SEQ_PUT_FIELD_RET(s, iter->cpu);
2335 SEQ_PUT_FIELD_RET(s, iter->ts);
2338 event = ftrace_find_event(entry->type);
2339 return event ? event->funcs->binary(iter, 0, event) :
2343 int trace_empty(struct trace_iterator *iter)
2345 struct ring_buffer_iter *buf_iter;
2348 /* If we are looking at one CPU buffer, only check that one */
2349 if (iter->cpu_file != RING_BUFFER_ALL_CPUS) {
2350 cpu = iter->cpu_file;
2351 buf_iter = trace_buffer_iter(iter, cpu);
2353 if (!ring_buffer_iter_empty(buf_iter))
2356 if (!ring_buffer_empty_cpu(iter->tr->buffer, cpu))
2362 for_each_tracing_cpu(cpu) {
2363 buf_iter = trace_buffer_iter(iter, cpu);
2365 if (!ring_buffer_iter_empty(buf_iter))
2368 if (!ring_buffer_empty_cpu(iter->tr->buffer, cpu))
2376 /* Called with trace_event_read_lock() held. */
2377 enum print_line_t print_trace_line(struct trace_iterator *iter)
2379 enum print_line_t ret;
2381 if (iter->lost_events &&
2382 !trace_seq_printf(&iter->seq, "CPU:%d [LOST %lu EVENTS]\n",
2383 iter->cpu, iter->lost_events))
2384 return TRACE_TYPE_PARTIAL_LINE;
2386 if (iter->trace && iter->trace->print_line) {
2387 ret = iter->trace->print_line(iter);
2388 if (ret != TRACE_TYPE_UNHANDLED)
2392 if (iter->ent->type == TRACE_BPRINT &&
2393 trace_flags & TRACE_ITER_PRINTK &&
2394 trace_flags & TRACE_ITER_PRINTK_MSGONLY)
2395 return trace_print_bprintk_msg_only(iter);
2397 if (iter->ent->type == TRACE_PRINT &&
2398 trace_flags & TRACE_ITER_PRINTK &&
2399 trace_flags & TRACE_ITER_PRINTK_MSGONLY)
2400 return trace_print_printk_msg_only(iter);
2402 if (trace_flags & TRACE_ITER_BIN)
2403 return print_bin_fmt(iter);
2405 if (trace_flags & TRACE_ITER_HEX)
2406 return print_hex_fmt(iter);
2408 if (trace_flags & TRACE_ITER_RAW)
2409 return print_raw_fmt(iter);
2411 return print_trace_fmt(iter);
2414 void trace_latency_header(struct seq_file *m)
2416 struct trace_iterator *iter = m->private;
2418 /* print nothing if the buffers are empty */
2419 if (trace_empty(iter))
2422 if (iter->iter_flags & TRACE_FILE_LAT_FMT)
2423 print_trace_header(m, iter);
2425 if (!(trace_flags & TRACE_ITER_VERBOSE))
2426 print_lat_help_header(m);
2429 void trace_default_header(struct seq_file *m)
2431 struct trace_iterator *iter = m->private;
2433 if (!(trace_flags & TRACE_ITER_CONTEXT_INFO))
2436 if (iter->iter_flags & TRACE_FILE_LAT_FMT) {
2437 /* print nothing if the buffers are empty */
2438 if (trace_empty(iter))
2440 print_trace_header(m, iter);
2441 if (!(trace_flags & TRACE_ITER_VERBOSE))
2442 print_lat_help_header(m);
2444 if (!(trace_flags & TRACE_ITER_VERBOSE)) {
2445 if (trace_flags & TRACE_ITER_IRQ_INFO)
2446 print_func_help_header_irq(iter->tr, m);
2448 print_func_help_header(iter->tr, m);
2453 static void test_ftrace_alive(struct seq_file *m)
2455 if (!ftrace_is_dead())
2457 seq_printf(m, "# WARNING: FUNCTION TRACING IS CORRUPTED\n");
2458 seq_printf(m, "# MAY BE MISSING FUNCTION EVENTS\n");
2461 #ifdef CONFIG_TRACER_MAX_TRACE
2462 static void print_snapshot_help(struct seq_file *m, struct trace_iterator *iter)
2464 if (iter->trace->allocated_snapshot)
2465 seq_printf(m, "#\n# * Snapshot is allocated *\n#\n");
2467 seq_printf(m, "#\n# * Snapshot is freed *\n#\n");
2469 seq_printf(m, "# Snapshot commands:\n");
2470 seq_printf(m, "# echo 0 > snapshot : Clears and frees snapshot buffer\n");
2471 seq_printf(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n");
2472 seq_printf(m, "# Takes a snapshot of the main buffer.\n");
2473 seq_printf(m, "# echo 2 > snapshot : Clears snapshot buffer (but does not allocate)\n");
2474 seq_printf(m, "# (Doesn't have to be '2' works with any number that\n");
2475 seq_printf(m, "# is not a '0' or '1')\n");
2478 /* Should never be called */
2479 static inline void print_snapshot_help(struct seq_file *m, struct trace_iterator *iter) { }
2482 static int s_show(struct seq_file *m, void *v)
2484 struct trace_iterator *iter = v;
2487 if (iter->ent == NULL) {
2489 seq_printf(m, "# tracer: %s\n", iter->trace->name);
2491 test_ftrace_alive(m);
2493 if (iter->snapshot && trace_empty(iter))
2494 print_snapshot_help(m, iter);
2495 else if (iter->trace && iter->trace->print_header)
2496 iter->trace->print_header(m);
2498 trace_default_header(m);
2500 } else if (iter->leftover) {
2502 * If we filled the seq_file buffer earlier, we
2503 * want to just show it now.
2505 ret = trace_print_seq(m, &iter->seq);
2507 /* ret should this time be zero, but you never know */
2508 iter->leftover = ret;
2511 print_trace_line(iter);
2512 ret = trace_print_seq(m, &iter->seq);
2514 * If we overflow the seq_file buffer, then it will
2515 * ask us for this data again at start up.
2517 * ret is 0 if seq_file write succeeded.
2520 iter->leftover = ret;
2526 static const struct seq_operations tracer_seq_ops = {
2533 static struct trace_iterator *
2534 __tracing_open(struct inode *inode, struct file *file, bool snapshot)
2536 struct trace_cpu *tc = inode->i_private;
2537 struct trace_array *tr = tc->tr;
2538 struct trace_iterator *iter;
2541 if (tracing_disabled)
2542 return ERR_PTR(-ENODEV);
2544 iter = __seq_open_private(file, &tracer_seq_ops, sizeof(*iter));
2546 return ERR_PTR(-ENOMEM);
2548 iter->buffer_iter = kzalloc(sizeof(*iter->buffer_iter) * num_possible_cpus(),
2550 if (!iter->buffer_iter)
2554 * We make a copy of the current tracer to avoid concurrent
2555 * changes on it while we are reading.
2557 mutex_lock(&trace_types_lock);
2558 iter->trace = kzalloc(sizeof(*iter->trace), GFP_KERNEL);
2562 *iter->trace = *tr->current_trace;
2564 if (!zalloc_cpumask_var(&iter->started, GFP_KERNEL))
2567 /* Currently only the top directory has a snapshot */
2568 if (tr->current_trace->print_max || snapshot)
2572 iter->snapshot = snapshot;
2574 mutex_init(&iter->mutex);
2575 iter->cpu_file = tc->cpu;
2577 /* Notify the tracer early; before we stop tracing. */
2578 if (iter->trace && iter->trace->open)
2579 iter->trace->open(iter);
2581 /* Annotate start of buffers if we had overruns */
2582 if (ring_buffer_overruns(iter->tr->buffer))
2583 iter->iter_flags |= TRACE_FILE_ANNOTATE;
2585 /* Output in nanoseconds only if we are using a clock in nanoseconds. */
2586 if (trace_clocks[trace_clock_id].in_ns)
2587 iter->iter_flags |= TRACE_FILE_TIME_IN_NS;
2589 /* stop the trace while dumping if we are not opening "snapshot" */
2590 if (!iter->snapshot)
2591 tracing_stop_tr(tr);
2593 if (iter->cpu_file == RING_BUFFER_ALL_CPUS) {
2594 for_each_tracing_cpu(cpu) {
2595 iter->buffer_iter[cpu] =
2596 ring_buffer_read_prepare(iter->tr->buffer, cpu);
2598 ring_buffer_read_prepare_sync();
2599 for_each_tracing_cpu(cpu) {
2600 ring_buffer_read_start(iter->buffer_iter[cpu]);
2601 tracing_iter_reset(iter, cpu);
2604 cpu = iter->cpu_file;
2605 iter->buffer_iter[cpu] =
2606 ring_buffer_read_prepare(iter->tr->buffer, cpu);
2607 ring_buffer_read_prepare_sync();
2608 ring_buffer_read_start(iter->buffer_iter[cpu]);
2609 tracing_iter_reset(iter, cpu);
2612 mutex_unlock(&trace_types_lock);
2617 mutex_unlock(&trace_types_lock);
2619 kfree(iter->buffer_iter);
2621 seq_release_private(inode, file);
2622 return ERR_PTR(-ENOMEM);
2625 int tracing_open_generic(struct inode *inode, struct file *filp)
2627 if (tracing_disabled)
2630 filp->private_data = inode->i_private;
2634 static int tracing_release(struct inode *inode, struct file *file)
2636 struct seq_file *m = file->private_data;
2637 struct trace_iterator *iter;
2638 struct trace_array *tr;
2641 if (!(file->f_mode & FMODE_READ))
2646 /* Only the global tracer has a matching max_tr */
2647 if (iter->tr == &max_tr)
2652 mutex_lock(&trace_types_lock);
2653 for_each_tracing_cpu(cpu) {
2654 if (iter->buffer_iter[cpu])
2655 ring_buffer_read_finish(iter->buffer_iter[cpu]);
2658 if (iter->trace && iter->trace->close)
2659 iter->trace->close(iter);
2661 if (!iter->snapshot)
2662 /* reenable tracing if it was previously enabled */
2663 tracing_start_tr(tr);
2664 mutex_unlock(&trace_types_lock);
2666 mutex_destroy(&iter->mutex);
2667 free_cpumask_var(iter->started);
2669 kfree(iter->buffer_iter);
2670 seq_release_private(inode, file);
2674 static int tracing_open(struct inode *inode, struct file *file)
2676 struct trace_iterator *iter;
2679 /* If this file was open for write, then erase contents */
2680 if ((file->f_mode & FMODE_WRITE) &&
2681 (file->f_flags & O_TRUNC)) {
2682 struct trace_cpu *tc = inode->i_private;
2683 struct trace_array *tr = tc->tr;
2685 if (tc->cpu == RING_BUFFER_ALL_CPUS)
2686 tracing_reset_online_cpus(tr);
2688 tracing_reset(tr, tc->cpu);
2691 if (file->f_mode & FMODE_READ) {
2692 iter = __tracing_open(inode, file, false);
2694 ret = PTR_ERR(iter);
2695 else if (trace_flags & TRACE_ITER_LATENCY_FMT)
2696 iter->iter_flags |= TRACE_FILE_LAT_FMT;
2702 t_next(struct seq_file *m, void *v, loff_t *pos)
2704 struct tracer *t = v;
2714 static void *t_start(struct seq_file *m, loff_t *pos)
2719 mutex_lock(&trace_types_lock);
2720 for (t = trace_types; t && l < *pos; t = t_next(m, t, &l))
2726 static void t_stop(struct seq_file *m, void *p)
2728 mutex_unlock(&trace_types_lock);
2731 static int t_show(struct seq_file *m, void *v)
2733 struct tracer *t = v;
2738 seq_printf(m, "%s", t->name);
2747 static const struct seq_operations show_traces_seq_ops = {
2754 static int show_traces_open(struct inode *inode, struct file *file)
2756 if (tracing_disabled)
2759 return seq_open(file, &show_traces_seq_ops);
2763 tracing_write_stub(struct file *filp, const char __user *ubuf,
2764 size_t count, loff_t *ppos)
2769 static loff_t tracing_seek(struct file *file, loff_t offset, int origin)
2771 if (file->f_mode & FMODE_READ)
2772 return seq_lseek(file, offset, origin);
2777 static const struct file_operations tracing_fops = {
2778 .open = tracing_open,
2780 .write = tracing_write_stub,
2781 .llseek = tracing_seek,
2782 .release = tracing_release,
2785 static const struct file_operations show_traces_fops = {
2786 .open = show_traces_open,
2788 .release = seq_release,
2789 .llseek = seq_lseek,
2793 * Only trace on a CPU if the bitmask is set:
2795 static cpumask_var_t tracing_cpumask;
2798 * The tracer itself will not take this lock, but still we want
2799 * to provide a consistent cpumask to user-space:
2801 static DEFINE_MUTEX(tracing_cpumask_update_lock);
2804 * Temporary storage for the character representation of the
2805 * CPU bitmask (and one more byte for the newline):
2807 static char mask_str[NR_CPUS + 1];
2810 tracing_cpumask_read(struct file *filp, char __user *ubuf,
2811 size_t count, loff_t *ppos)
2815 mutex_lock(&tracing_cpumask_update_lock);
2817 len = cpumask_scnprintf(mask_str, count, tracing_cpumask);
2818 if (count - len < 2) {
2822 len += sprintf(mask_str + len, "\n");
2823 count = simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+1);
2826 mutex_unlock(&tracing_cpumask_update_lock);
2832 tracing_cpumask_write(struct file *filp, const char __user *ubuf,
2833 size_t count, loff_t *ppos)
2835 struct trace_array *tr = filp->private_data;
2836 cpumask_var_t tracing_cpumask_new;
2839 if (!alloc_cpumask_var(&tracing_cpumask_new, GFP_KERNEL))
2842 err = cpumask_parse_user(ubuf, count, tracing_cpumask_new);
2846 mutex_lock(&tracing_cpumask_update_lock);
2848 local_irq_disable();
2849 arch_spin_lock(&ftrace_max_lock);
2850 for_each_tracing_cpu(cpu) {
2852 * Increase/decrease the disabled counter if we are
2853 * about to flip a bit in the cpumask:
2855 if (cpumask_test_cpu(cpu, tracing_cpumask) &&
2856 !cpumask_test_cpu(cpu, tracing_cpumask_new)) {
2857 atomic_inc(&per_cpu_ptr(tr->data, cpu)->disabled);
2858 ring_buffer_record_disable_cpu(tr->buffer, cpu);
2860 if (!cpumask_test_cpu(cpu, tracing_cpumask) &&
2861 cpumask_test_cpu(cpu, tracing_cpumask_new)) {
2862 atomic_dec(&per_cpu_ptr(tr->data, cpu)->disabled);
2863 ring_buffer_record_enable_cpu(tr->buffer, cpu);
2866 arch_spin_unlock(&ftrace_max_lock);
2869 cpumask_copy(tracing_cpumask, tracing_cpumask_new);
2871 mutex_unlock(&tracing_cpumask_update_lock);
2872 free_cpumask_var(tracing_cpumask_new);
2877 free_cpumask_var(tracing_cpumask_new);
2882 static const struct file_operations tracing_cpumask_fops = {
2883 .open = tracing_open_generic,
2884 .read = tracing_cpumask_read,
2885 .write = tracing_cpumask_write,
2886 .llseek = generic_file_llseek,
2889 static int tracing_trace_options_show(struct seq_file *m, void *v)
2891 struct tracer_opt *trace_opts;
2892 struct trace_array *tr = m->private;
2896 mutex_lock(&trace_types_lock);
2897 tracer_flags = tr->current_trace->flags->val;
2898 trace_opts = tr->current_trace->flags->opts;
2900 for (i = 0; trace_options[i]; i++) {
2901 if (trace_flags & (1 << i))
2902 seq_printf(m, "%s\n", trace_options[i]);
2904 seq_printf(m, "no%s\n", trace_options[i]);
2907 for (i = 0; trace_opts[i].name; i++) {
2908 if (tracer_flags & trace_opts[i].bit)
2909 seq_printf(m, "%s\n", trace_opts[i].name);
2911 seq_printf(m, "no%s\n", trace_opts[i].name);
2913 mutex_unlock(&trace_types_lock);
2918 static int __set_tracer_option(struct tracer *trace,
2919 struct tracer_flags *tracer_flags,
2920 struct tracer_opt *opts, int neg)
2924 ret = trace->set_flag(tracer_flags->val, opts->bit, !neg);
2929 tracer_flags->val &= ~opts->bit;
2931 tracer_flags->val |= opts->bit;
2935 /* Try to assign a tracer specific option */
2936 static int set_tracer_option(struct tracer *trace, char *cmp, int neg)
2938 struct tracer_flags *tracer_flags = trace->flags;
2939 struct tracer_opt *opts = NULL;
2942 for (i = 0; tracer_flags->opts[i].name; i++) {
2943 opts = &tracer_flags->opts[i];
2945 if (strcmp(cmp, opts->name) == 0)
2946 return __set_tracer_option(trace, trace->flags,
2953 /* Some tracers require overwrite to stay enabled */
2954 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
2956 if (tracer->enabled && (mask & TRACE_ITER_OVERWRITE) && !set)
2962 int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
2964 /* do nothing if flag is already set */
2965 if (!!(trace_flags & mask) == !!enabled)
2968 /* Give the tracer a chance to approve the change */
2969 if (tr->current_trace->flag_changed)
2970 if (tr->current_trace->flag_changed(tr->current_trace, mask, !!enabled))
2974 trace_flags |= mask;
2976 trace_flags &= ~mask;
2978 if (mask == TRACE_ITER_RECORD_CMD)
2979 trace_event_enable_cmd_record(enabled);
2981 if (mask == TRACE_ITER_OVERWRITE) {
2982 ring_buffer_change_overwrite(global_trace.buffer, enabled);
2983 #ifdef CONFIG_TRACER_MAX_TRACE
2984 ring_buffer_change_overwrite(max_tr.buffer, enabled);
2988 if (mask == TRACE_ITER_PRINTK)
2989 trace_printk_start_stop_comm(enabled);
2994 static int trace_set_options(struct trace_array *tr, char *option)
3001 cmp = strstrip(option);
3003 if (strncmp(cmp, "no", 2) == 0) {
3008 mutex_lock(&trace_types_lock);
3010 for (i = 0; trace_options[i]; i++) {
3011 if (strcmp(cmp, trace_options[i]) == 0) {
3012 ret = set_tracer_flag(tr, 1 << i, !neg);
3017 /* If no option could be set, test the specific tracer options */
3018 if (!trace_options[i])
3019 ret = set_tracer_option(tr->current_trace, cmp, neg);
3021 mutex_unlock(&trace_types_lock);
3027 tracing_trace_options_write(struct file *filp, const char __user *ubuf,
3028 size_t cnt, loff_t *ppos)
3030 struct seq_file *m = filp->private_data;
3031 struct trace_array *tr = m->private;
3035 if (cnt >= sizeof(buf))
3038 if (copy_from_user(&buf, ubuf, cnt))
3043 ret = trace_set_options(tr, buf);
3052 static int tracing_trace_options_open(struct inode *inode, struct file *file)
3054 if (tracing_disabled)
3057 return single_open(file, tracing_trace_options_show, inode->i_private);
3060 static const struct file_operations tracing_iter_fops = {
3061 .open = tracing_trace_options_open,
3063 .llseek = seq_lseek,
3064 .release = single_release,
3065 .write = tracing_trace_options_write,
3068 static const char readme_msg[] =
3069 "tracing mini-HOWTO:\n\n"
3070 "# mount -t debugfs nodev /sys/kernel/debug\n\n"
3071 "# cat /sys/kernel/debug/tracing/available_tracers\n"
3072 "wakeup wakeup_rt preemptirqsoff preemptoff irqsoff function nop\n\n"
3073 "# cat /sys/kernel/debug/tracing/current_tracer\n"
3075 "# echo wakeup > /sys/kernel/debug/tracing/current_tracer\n"
3076 "# cat /sys/kernel/debug/tracing/current_tracer\n"
3078 "# cat /sys/kernel/debug/tracing/trace_options\n"
3079 "noprint-parent nosym-offset nosym-addr noverbose\n"
3080 "# echo print-parent > /sys/kernel/debug/tracing/trace_options\n"
3081 "# echo 1 > /sys/kernel/debug/tracing/tracing_on\n"
3082 "# cat /sys/kernel/debug/tracing/trace > /tmp/trace.txt\n"
3083 "# echo 0 > /sys/kernel/debug/tracing/tracing_on\n"
3087 tracing_readme_read(struct file *filp, char __user *ubuf,
3088 size_t cnt, loff_t *ppos)
3090 return simple_read_from_buffer(ubuf, cnt, ppos,
3091 readme_msg, strlen(readme_msg));
3094 static const struct file_operations tracing_readme_fops = {
3095 .open = tracing_open_generic,
3096 .read = tracing_readme_read,
3097 .llseek = generic_file_llseek,
3101 tracing_saved_cmdlines_read(struct file *file, char __user *ubuf,
3102 size_t cnt, loff_t *ppos)
3111 file_buf = kmalloc(SAVED_CMDLINES*(16+TASK_COMM_LEN), GFP_KERNEL);
3115 buf_comm = kmalloc(TASK_COMM_LEN, GFP_KERNEL);
3123 for (i = 0; i < SAVED_CMDLINES; i++) {
3126 pid = map_cmdline_to_pid[i];
3127 if (pid == -1 || pid == NO_CMDLINE_MAP)
3130 trace_find_cmdline(pid, buf_comm);
3131 r = sprintf(buf, "%d %s\n", pid, buf_comm);
3136 len = simple_read_from_buffer(ubuf, cnt, ppos,
3145 static const struct file_operations tracing_saved_cmdlines_fops = {
3146 .open = tracing_open_generic,
3147 .read = tracing_saved_cmdlines_read,
3148 .llseek = generic_file_llseek,
3152 tracing_set_trace_read(struct file *filp, char __user *ubuf,
3153 size_t cnt, loff_t *ppos)
3155 struct trace_array *tr = filp->private_data;
3156 char buf[MAX_TRACER_SIZE+2];
3159 mutex_lock(&trace_types_lock);
3160 r = sprintf(buf, "%s\n", tr->current_trace->name);
3161 mutex_unlock(&trace_types_lock);
3163 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
3166 int tracer_init(struct tracer *t, struct trace_array *tr)
3168 tracing_reset_online_cpus(tr);
3172 static void set_buffer_entries(struct trace_array *tr, unsigned long val)
3175 for_each_tracing_cpu(cpu)
3176 per_cpu_ptr(tr->data, cpu)->entries = val;
3179 /* resize @tr's buffer to the size of @size_tr's entries */
3180 static int resize_buffer_duplicate_size(struct trace_array *tr,
3181 struct trace_array *size_tr, int cpu_id)
3185 if (cpu_id == RING_BUFFER_ALL_CPUS) {
3186 for_each_tracing_cpu(cpu) {
3187 ret = ring_buffer_resize(tr->buffer,
3188 per_cpu_ptr(size_tr->data, cpu)->entries, cpu);
3191 per_cpu_ptr(tr->data, cpu)->entries =
3192 per_cpu_ptr(size_tr->data, cpu)->entries;
3195 ret = ring_buffer_resize(tr->buffer,
3196 per_cpu_ptr(size_tr->data, cpu_id)->entries, cpu_id);
3198 per_cpu_ptr(tr->data, cpu_id)->entries =
3199 per_cpu_ptr(size_tr->data, cpu_id)->entries;
3205 static int __tracing_resize_ring_buffer(struct trace_array *tr,
3206 unsigned long size, int cpu)
3211 * If kernel or user changes the size of the ring buffer
3212 * we use the size that was given, and we can forget about
3213 * expanding it later.
3215 ring_buffer_expanded = 1;
3217 /* May be called before buffers are initialized */
3221 ret = ring_buffer_resize(tr->buffer, size, cpu);
3225 if (!(tr->flags & TRACE_ARRAY_FL_GLOBAL) ||
3226 !tr->current_trace->use_max_tr)
3229 ret = ring_buffer_resize(max_tr.buffer, size, cpu);
3231 int r = resize_buffer_duplicate_size(tr, tr, cpu);
3234 * AARGH! We are left with different
3235 * size max buffer!!!!
3236 * The max buffer is our "snapshot" buffer.
3237 * When a tracer needs a snapshot (one of the
3238 * latency tracers), it swaps the max buffer
3239 * with the saved snap shot. We succeeded to
3240 * update the size of the main buffer, but failed to
3241 * update the size of the max buffer. But when we tried
3242 * to reset the main buffer to the original size, we
3243 * failed there too. This is very unlikely to
3244 * happen, but if it does, warn and kill all
3248 tracing_disabled = 1;
3253 if (cpu == RING_BUFFER_ALL_CPUS)
3254 set_buffer_entries(&max_tr, size);
3256 per_cpu_ptr(max_tr.data, cpu)->entries = size;
3259 if (cpu == RING_BUFFER_ALL_CPUS)
3260 set_buffer_entries(tr, size);
3262 per_cpu_ptr(tr->data, cpu)->entries = size;
3267 static ssize_t tracing_resize_ring_buffer(struct trace_array *tr,
3268 unsigned long size, int cpu_id)
3272 mutex_lock(&trace_types_lock);
3274 if (cpu_id != RING_BUFFER_ALL_CPUS) {
3275 /* make sure, this cpu is enabled in the mask */
3276 if (!cpumask_test_cpu(cpu_id, tracing_buffer_mask)) {
3282 ret = __tracing_resize_ring_buffer(tr, size, cpu_id);
3287 mutex_unlock(&trace_types_lock);
3294 * tracing_update_buffers - used by tracing facility to expand ring buffers
3296 * To save on memory when the tracing is never used on a system with it
3297 * configured in. The ring buffers are set to a minimum size. But once
3298 * a user starts to use the tracing facility, then they need to grow
3299 * to their default size.
3301 * This function is to be called when a tracer is about to be used.
3303 int tracing_update_buffers(void)
3307 mutex_lock(&trace_types_lock);
3308 if (!ring_buffer_expanded)
3309 ret = __tracing_resize_ring_buffer(&global_trace, trace_buf_size,
3310 RING_BUFFER_ALL_CPUS);
3311 mutex_unlock(&trace_types_lock);
3316 struct trace_option_dentry;
3318 static struct trace_option_dentry *
3319 create_trace_option_files(struct trace_array *tr, struct tracer *tracer);
3322 destroy_trace_option_files(struct trace_option_dentry *topts);
3324 static int tracing_set_tracer(const char *buf)
3326 static struct trace_option_dentry *topts;
3327 struct trace_array *tr = &global_trace;
3332 mutex_lock(&trace_types_lock);
3334 if (!ring_buffer_expanded) {
3335 ret = __tracing_resize_ring_buffer(tr, trace_buf_size,
3336 RING_BUFFER_ALL_CPUS);
3342 for (t = trace_types; t; t = t->next) {
3343 if (strcmp(t->name, buf) == 0)
3350 if (t == tr->current_trace)
3353 trace_branch_disable();
3355 tr->current_trace->enabled = false;
3357 if (tr->current_trace->reset)
3358 tr->current_trace->reset(tr);
3360 had_max_tr = tr->current_trace->allocated_snapshot;
3361 tr->current_trace = &nop_trace;
3363 if (had_max_tr && !t->use_max_tr) {
3365 * We need to make sure that the update_max_tr sees that
3366 * current_trace changed to nop_trace to keep it from
3367 * swapping the buffers after we resize it.
3368 * The update_max_tr is called from interrupts disabled
3369 * so a synchronized_sched() is sufficient.
3371 synchronize_sched();
3373 * We don't free the ring buffer. instead, resize it because
3374 * The max_tr ring buffer has some state (e.g. ring->clock) and
3375 * we want preserve it.
3377 ring_buffer_resize(max_tr.buffer, 1, RING_BUFFER_ALL_CPUS);
3378 set_buffer_entries(&max_tr, 1);
3379 tracing_reset_online_cpus(&max_tr);
3380 tr->current_trace->allocated_snapshot = false;
3382 destroy_trace_option_files(topts);
3384 topts = create_trace_option_files(tr, t);
3385 if (t->use_max_tr && !had_max_tr) {
3386 /* we need to make per cpu buffer sizes equivalent */
3387 ret = resize_buffer_duplicate_size(&max_tr, &global_trace,
3388 RING_BUFFER_ALL_CPUS);
3391 t->allocated_snapshot = true;
3395 ret = tracer_init(t, tr);
3400 tr->current_trace = t;
3401 tr->current_trace->enabled = true;
3402 trace_branch_enable(tr);
3404 mutex_unlock(&trace_types_lock);
3410 tracing_set_trace_write(struct file *filp, const char __user *ubuf,
3411 size_t cnt, loff_t *ppos)
3413 char buf[MAX_TRACER_SIZE+1];
3420 if (cnt > MAX_TRACER_SIZE)
3421 cnt = MAX_TRACER_SIZE;
3423 if (copy_from_user(&buf, ubuf, cnt))
3428 /* strip ending whitespace. */
3429 for (i = cnt - 1; i > 0 && isspace(buf[i]); i--)
3432 err = tracing_set_tracer(buf);
3442 tracing_max_lat_read(struct file *filp, char __user *ubuf,
3443 size_t cnt, loff_t *ppos)
3445 unsigned long *ptr = filp->private_data;
3449 r = snprintf(buf, sizeof(buf), "%ld\n",
3450 *ptr == (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr));
3451 if (r > sizeof(buf))
3453 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
3457 tracing_max_lat_write(struct file *filp, const char __user *ubuf,
3458 size_t cnt, loff_t *ppos)
3460 unsigned long *ptr = filp->private_data;
3464 ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
3473 static int tracing_open_pipe(struct inode *inode, struct file *filp)
3475 struct trace_cpu *tc = inode->i_private;
3476 struct trace_array *tr = tc->tr;
3477 struct trace_iterator *iter;
3480 if (tracing_disabled)
3483 mutex_lock(&trace_types_lock);
3485 /* create a buffer to store the information to pass to userspace */
3486 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
3493 * We make a copy of the current tracer to avoid concurrent
3494 * changes on it while we are reading.
3496 iter->trace = kmalloc(sizeof(*iter->trace), GFP_KERNEL);
3501 *iter->trace = *tr->current_trace;
3503 if (!alloc_cpumask_var(&iter->started, GFP_KERNEL)) {
3508 /* trace pipe does not show start of buffer */
3509 cpumask_setall(iter->started);
3511 if (trace_flags & TRACE_ITER_LATENCY_FMT)
3512 iter->iter_flags |= TRACE_FILE_LAT_FMT;
3514 /* Output in nanoseconds only if we are using a clock in nanoseconds. */
3515 if (trace_clocks[trace_clock_id].in_ns)
3516 iter->iter_flags |= TRACE_FILE_TIME_IN_NS;
3518 iter->cpu_file = tc->cpu;
3520 mutex_init(&iter->mutex);
3521 filp->private_data = iter;
3523 if (iter->trace->pipe_open)
3524 iter->trace->pipe_open(iter);
3526 nonseekable_open(inode, filp);
3528 mutex_unlock(&trace_types_lock);
3534 mutex_unlock(&trace_types_lock);
3538 static int tracing_release_pipe(struct inode *inode, struct file *file)
3540 struct trace_iterator *iter = file->private_data;
3542 mutex_lock(&trace_types_lock);
3544 if (iter->trace->pipe_close)
3545 iter->trace->pipe_close(iter);
3547 mutex_unlock(&trace_types_lock);
3549 free_cpumask_var(iter->started);
3550 mutex_destroy(&iter->mutex);
3558 tracing_poll_pipe(struct file *filp, poll_table *poll_table)
3560 struct trace_iterator *iter = filp->private_data;
3562 if (trace_flags & TRACE_ITER_BLOCK) {
3564 * Always select as readable when in blocking mode
3566 return POLLIN | POLLRDNORM;
3568 if (!trace_empty(iter))
3569 return POLLIN | POLLRDNORM;
3570 poll_wait(filp, &trace_wait, poll_table);
3571 if (!trace_empty(iter))
3572 return POLLIN | POLLRDNORM;
3579 * This is a make-shift waitqueue.
3580 * A tracer might use this callback on some rare cases:
3582 * 1) the current tracer might hold the runqueue lock when it wakes up
3583 * a reader, hence a deadlock (sched, function, and function graph tracers)
3584 * 2) the function tracers, trace all functions, we don't want
3585 * the overhead of calling wake_up and friends
3586 * (and tracing them too)
3588 * Anyway, this is really very primitive wakeup.
3590 void poll_wait_pipe(struct trace_iterator *iter)
3592 set_current_state(TASK_INTERRUPTIBLE);
3593 /* sleep for 100 msecs, and try again. */
3594 schedule_timeout(HZ / 10);
3597 /* Must be called with trace_types_lock mutex held. */
3598 static int tracing_wait_pipe(struct file *filp)
3600 struct trace_iterator *iter = filp->private_data;
3602 while (trace_empty(iter)) {
3604 if ((filp->f_flags & O_NONBLOCK)) {
3608 mutex_unlock(&iter->mutex);
3610 iter->trace->wait_pipe(iter);
3612 mutex_lock(&iter->mutex);
3614 if (signal_pending(current))
3618 * We block until we read something and tracing is disabled.
3619 * We still block if tracing is disabled, but we have never
3620 * read anything. This allows a user to cat this file, and
3621 * then enable tracing. But after we have read something,
3622 * we give an EOF when tracing is again disabled.
3624 * iter->pos will be 0 if we haven't read anything.
3626 if (!tracing_is_enabled() && iter->pos)
3637 tracing_read_pipe(struct file *filp, char __user *ubuf,
3638 size_t cnt, loff_t *ppos)
3640 struct trace_iterator *iter = filp->private_data;
3641 struct trace_array *tr = iter->tr;
3644 /* return any leftover data */
3645 sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
3649 trace_seq_init(&iter->seq);
3651 /* copy the tracer to avoid using a global lock all around */
3652 mutex_lock(&trace_types_lock);
3653 if (unlikely(iter->trace->name != tr->current_trace->name))
3654 *iter->trace = *tr->current_trace;
3655 mutex_unlock(&trace_types_lock);
3658 * Avoid more than one consumer on a single file descriptor
3659 * This is just a matter of traces coherency, the ring buffer itself
3662 mutex_lock(&iter->mutex);
3663 if (iter->trace->read) {
3664 sret = iter->trace->read(iter, filp, ubuf, cnt, ppos);
3670 sret = tracing_wait_pipe(filp);
3674 /* stop when tracing is finished */
3675 if (trace_empty(iter)) {
3680 if (cnt >= PAGE_SIZE)
3681 cnt = PAGE_SIZE - 1;
3683 /* reset all but tr, trace, and overruns */
3684 memset(&iter->seq, 0,
3685 sizeof(struct trace_iterator) -
3686 offsetof(struct trace_iterator, seq));
3689 trace_event_read_lock();
3690 trace_access_lock(iter->cpu_file);
3691 while (trace_find_next_entry_inc(iter) != NULL) {
3692 enum print_line_t ret;
3693 int len = iter->seq.len;
3695 ret = print_trace_line(iter);
3696 if (ret == TRACE_TYPE_PARTIAL_LINE) {
3697 /* don't print partial lines */
3698 iter->seq.len = len;
3701 if (ret != TRACE_TYPE_NO_CONSUME)
3702 trace_consume(iter);
3704 if (iter->seq.len >= cnt)
3708 * Setting the full flag means we reached the trace_seq buffer
3709 * size and we should leave by partial output condition above.
3710 * One of the trace_seq_* functions is not used properly.
3712 WARN_ONCE(iter->seq.full, "full flag set for trace type %d",
3715 trace_access_unlock(iter->cpu_file);
3716 trace_event_read_unlock();
3718 /* Now copy what we have to the user */
3719 sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
3720 if (iter->seq.readpos >= iter->seq.len)
3721 trace_seq_init(&iter->seq);
3724 * If there was nothing to send to user, in spite of consuming trace
3725 * entries, go back to wait for more entries.
3731 mutex_unlock(&iter->mutex);
3736 static void tracing_pipe_buf_release(struct pipe_inode_info *pipe,
3737 struct pipe_buffer *buf)
3739 __free_page(buf->page);
3742 static void tracing_spd_release_pipe(struct splice_pipe_desc *spd,
3745 __free_page(spd->pages[idx]);
3748 static const struct pipe_buf_operations tracing_pipe_buf_ops = {
3750 .map = generic_pipe_buf_map,
3751 .unmap = generic_pipe_buf_unmap,
3752 .confirm = generic_pipe_buf_confirm,
3753 .release = tracing_pipe_buf_release,
3754 .steal = generic_pipe_buf_steal,
3755 .get = generic_pipe_buf_get,
3759 tracing_fill_pipe_page(size_t rem, struct trace_iterator *iter)
3764 /* Seq buffer is page-sized, exactly what we need. */
3766 count = iter->seq.len;
3767 ret = print_trace_line(iter);
3768 count = iter->seq.len - count;
3771 iter->seq.len -= count;
3774 if (ret == TRACE_TYPE_PARTIAL_LINE) {
3775 iter->seq.len -= count;
3779 if (ret != TRACE_TYPE_NO_CONSUME)
3780 trace_consume(iter);
3782 if (!trace_find_next_entry_inc(iter)) {
3792 static ssize_t tracing_splice_read_pipe(struct file *filp,
3794 struct pipe_inode_info *pipe,
3798 struct page *pages_def[PIPE_DEF_BUFFERS];
3799 struct partial_page partial_def[PIPE_DEF_BUFFERS];
3800 struct trace_iterator *iter = filp->private_data;
3801 struct splice_pipe_desc spd = {
3803 .partial = partial_def,
3804 .nr_pages = 0, /* This gets updated below. */
3805 .nr_pages_max = PIPE_DEF_BUFFERS,
3807 .ops = &tracing_pipe_buf_ops,
3808 .spd_release = tracing_spd_release_pipe,
3810 struct trace_array *tr = iter->tr;
3815 if (splice_grow_spd(pipe, &spd))
3818 /* copy the tracer to avoid using a global lock all around */
3819 mutex_lock(&trace_types_lock);
3820 if (unlikely(iter->trace->name != tr->current_trace->name))
3821 *iter->trace = *tr->current_trace;
3822 mutex_unlock(&trace_types_lock);
3824 mutex_lock(&iter->mutex);
3826 if (iter->trace->splice_read) {
3827 ret = iter->trace->splice_read(iter, filp,
3828 ppos, pipe, len, flags);
3833 ret = tracing_wait_pipe(filp);
3837 if (!iter->ent && !trace_find_next_entry_inc(iter)) {
3842 trace_event_read_lock();
3843 trace_access_lock(iter->cpu_file);
3845 /* Fill as many pages as possible. */
3846 for (i = 0, rem = len; i < pipe->buffers && rem; i++) {
3847 spd.pages[i] = alloc_page(GFP_KERNEL);
3851 rem = tracing_fill_pipe_page(rem, iter);
3853 /* Copy the data into the page, so we can start over. */
3854 ret = trace_seq_to_buffer(&iter->seq,
3855 page_address(spd.pages[i]),
3858 __free_page(spd.pages[i]);
3861 spd.partial[i].offset = 0;
3862 spd.partial[i].len = iter->seq.len;
3864 trace_seq_init(&iter->seq);
3867 trace_access_unlock(iter->cpu_file);
3868 trace_event_read_unlock();
3869 mutex_unlock(&iter->mutex);
3873 ret = splice_to_pipe(pipe, &spd);
3875 splice_shrink_spd(&spd);
3879 mutex_unlock(&iter->mutex);
3884 tracing_entries_read(struct file *filp, char __user *ubuf,
3885 size_t cnt, loff_t *ppos)
3887 struct trace_cpu *tc = filp->private_data;
3888 struct trace_array *tr = tc->tr;
3893 mutex_lock(&trace_types_lock);
3895 if (tc->cpu == RING_BUFFER_ALL_CPUS) {
3896 int cpu, buf_size_same;
3901 /* check if all cpu sizes are same */
3902 for_each_tracing_cpu(cpu) {
3903 /* fill in the size from first enabled cpu */
3905 size = per_cpu_ptr(tr->data, cpu)->entries;
3906 if (size != per_cpu_ptr(tr->data, cpu)->entries) {
3912 if (buf_size_same) {
3913 if (!ring_buffer_expanded)
3914 r = sprintf(buf, "%lu (expanded: %lu)\n",
3916 trace_buf_size >> 10);
3918 r = sprintf(buf, "%lu\n", size >> 10);
3920 r = sprintf(buf, "X\n");
3922 r = sprintf(buf, "%lu\n", per_cpu_ptr(tr->data, tc->cpu)->entries >> 10);
3924 mutex_unlock(&trace_types_lock);
3926 ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
3931 tracing_entries_write(struct file *filp, const char __user *ubuf,
3932 size_t cnt, loff_t *ppos)
3934 struct trace_cpu *tc = filp->private_data;
3938 ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
3942 /* must have at least 1 entry */
3946 /* value is in KB */
3949 ret = tracing_resize_ring_buffer(tc->tr, val, tc->cpu);
3959 tracing_total_entries_read(struct file *filp, char __user *ubuf,
3960 size_t cnt, loff_t *ppos)
3962 struct trace_array *tr = filp->private_data;
3965 unsigned long size = 0, expanded_size = 0;
3967 mutex_lock(&trace_types_lock);
3968 for_each_tracing_cpu(cpu) {
3969 size += per_cpu_ptr(tr->data, cpu)->entries >> 10;
3970 if (!ring_buffer_expanded)
3971 expanded_size += trace_buf_size >> 10;
3973 if (ring_buffer_expanded)
3974 r = sprintf(buf, "%lu\n", size);
3976 r = sprintf(buf, "%lu (expanded: %lu)\n", size, expanded_size);
3977 mutex_unlock(&trace_types_lock);
3979 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
3983 tracing_free_buffer_write(struct file *filp, const char __user *ubuf,
3984 size_t cnt, loff_t *ppos)
3987 * There is no need to read what the user has written, this function
3988 * is just to make sure that there is no error when "echo" is used
3997 tracing_free_buffer_release(struct inode *inode, struct file *filp)
3999 struct trace_array *tr = inode->i_private;
4001 /* disable tracing ? */
4002 if (trace_flags & TRACE_ITER_STOP_ON_FREE)
4004 /* resize the ring buffer to 0 */
4005 tracing_resize_ring_buffer(tr, 0, RING_BUFFER_ALL_CPUS);
4011 tracing_mark_write(struct file *filp, const char __user *ubuf,
4012 size_t cnt, loff_t *fpos)
4014 unsigned long addr = (unsigned long)ubuf;
4015 struct ring_buffer_event *event;
4016 struct ring_buffer *buffer;
4017 struct print_entry *entry;
4018 unsigned long irq_flags;
4019 struct page *pages[2];
4029 if (tracing_disabled)
4032 if (!(trace_flags & TRACE_ITER_MARKERS))
4035 if (cnt > TRACE_BUF_SIZE)
4036 cnt = TRACE_BUF_SIZE;
4039 * Userspace is injecting traces into the kernel trace buffer.
4040 * We want to be as non intrusive as possible.
4041 * To do so, we do not want to allocate any special buffers
4042 * or take any locks, but instead write the userspace data
4043 * straight into the ring buffer.
4045 * First we need to pin the userspace buffer into memory,
4046 * which, most likely it is, because it just referenced it.
4047 * But there's no guarantee that it is. By using get_user_pages_fast()
4048 * and kmap_atomic/kunmap_atomic() we can get access to the
4049 * pages directly. We then write the data directly into the
4052 BUILD_BUG_ON(TRACE_BUF_SIZE >= PAGE_SIZE);
4054 /* check if we cross pages */
4055 if ((addr & PAGE_MASK) != ((addr + cnt) & PAGE_MASK))
4058 offset = addr & (PAGE_SIZE - 1);
4061 ret = get_user_pages_fast(addr, nr_pages, 0, pages);
4062 if (ret < nr_pages) {
4064 put_page(pages[ret]);
4069 for (i = 0; i < nr_pages; i++)
4070 map_page[i] = kmap_atomic(pages[i]);
4072 local_save_flags(irq_flags);
4073 size = sizeof(*entry) + cnt + 2; /* possible \n added */
4074 buffer = global_trace.buffer;
4075 event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, size,
4076 irq_flags, preempt_count());
4078 /* Ring buffer disabled, return as if not open for write */
4083 entry = ring_buffer_event_data(event);
4084 entry->ip = _THIS_IP_;
4086 if (nr_pages == 2) {
4087 len = PAGE_SIZE - offset;
4088 memcpy(&entry->buf, map_page[0] + offset, len);
4089 memcpy(&entry->buf[len], map_page[1], cnt - len);
4091 memcpy(&entry->buf, map_page[0] + offset, cnt);
4093 if (entry->buf[cnt - 1] != '\n') {
4094 entry->buf[cnt] = '\n';
4095 entry->buf[cnt + 1] = '\0';
4097 entry->buf[cnt] = '\0';
4099 __buffer_unlock_commit(buffer, event);
4106 for (i = 0; i < nr_pages; i++){
4107 kunmap_atomic(map_page[i]);
4114 static int tracing_clock_show(struct seq_file *m, void *v)
4116 struct trace_array *tr = m->private;
4119 for (i = 0; i < ARRAY_SIZE(trace_clocks); i++)
4121 "%s%s%s%s", i ? " " : "",
4122 i == tr->clock_id ? "[" : "", trace_clocks[i].name,
4123 i == tr->clock_id ? "]" : "");
4129 static ssize_t tracing_clock_write(struct file *filp, const char __user *ubuf,
4130 size_t cnt, loff_t *fpos)
4132 struct seq_file *m = filp->private_data;
4133 struct trace_array *tr = m->private;
4135 const char *clockstr;
4138 if (cnt >= sizeof(buf))
4141 if (copy_from_user(&buf, ubuf, cnt))
4146 clockstr = strstrip(buf);
4148 for (i = 0; i < ARRAY_SIZE(trace_clocks); i++) {
4149 if (strcmp(trace_clocks[i].name, clockstr) == 0)
4152 if (i == ARRAY_SIZE(trace_clocks))
4155 mutex_lock(&trace_types_lock);
4159 ring_buffer_set_clock(tr->buffer, trace_clocks[i].func);
4160 if (tr->flags & TRACE_ARRAY_FL_GLOBAL && max_tr.buffer)
4161 ring_buffer_set_clock(max_tr.buffer, trace_clocks[i].func);
4164 * New clock may not be consistent with the previous clock.
4165 * Reset the buffer so that it doesn't have incomparable timestamps.
4167 tracing_reset_online_cpus(&global_trace);
4168 tracing_reset_online_cpus(&max_tr);
4170 mutex_unlock(&trace_types_lock);
4177 static int tracing_clock_open(struct inode *inode, struct file *file)
4179 if (tracing_disabled)
4182 return single_open(file, tracing_clock_show, inode->i_private);
4185 #ifdef CONFIG_TRACER_SNAPSHOT
4186 static int tracing_snapshot_open(struct inode *inode, struct file *file)
4188 struct trace_cpu *tc = inode->i_private;
4189 struct trace_iterator *iter;
4193 if (file->f_mode & FMODE_READ) {
4194 iter = __tracing_open(inode, file, true);
4196 ret = PTR_ERR(iter);
4198 /* Writes still need the seq_file to hold the private data */
4199 m = kzalloc(sizeof(*m), GFP_KERNEL);
4202 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
4209 file->private_data = m;
4216 tracing_snapshot_write(struct file *filp, const char __user *ubuf, size_t cnt,
4219 struct seq_file *m = filp->private_data;
4220 struct trace_iterator *iter = m->private;
4221 struct trace_array *tr = iter->tr;
4225 ret = tracing_update_buffers();
4229 ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
4233 mutex_lock(&trace_types_lock);
4235 if (tr->current_trace->use_max_tr) {
4242 if (tr->current_trace->allocated_snapshot) {
4243 /* free spare buffer */
4244 ring_buffer_resize(max_tr.buffer, 1,
4245 RING_BUFFER_ALL_CPUS);
4246 set_buffer_entries(&max_tr, 1);
4247 tracing_reset_online_cpus(&max_tr);
4248 tr->current_trace->allocated_snapshot = false;
4252 if (!tr->current_trace->allocated_snapshot) {
4253 /* allocate spare buffer */
4254 ret = resize_buffer_duplicate_size(&max_tr,
4255 &global_trace, RING_BUFFER_ALL_CPUS);
4258 tr->current_trace->allocated_snapshot = true;
4261 local_irq_disable();
4262 /* Now, we're going to swap */
4263 update_max_tr(&global_trace, current, smp_processor_id());
4267 if (tr->current_trace->allocated_snapshot)
4268 tracing_reset_online_cpus(&max_tr);
4277 mutex_unlock(&trace_types_lock);
4281 static int tracing_snapshot_release(struct inode *inode, struct file *file)
4283 struct seq_file *m = file->private_data;
4285 if (file->f_mode & FMODE_READ)
4286 return tracing_release(inode, file);
4288 /* If write only, the seq_file is just a stub */
4296 #endif /* CONFIG_TRACER_SNAPSHOT */
4299 static const struct file_operations tracing_max_lat_fops = {
4300 .open = tracing_open_generic,
4301 .read = tracing_max_lat_read,
4302 .write = tracing_max_lat_write,
4303 .llseek = generic_file_llseek,
4306 static const struct file_operations set_tracer_fops = {
4307 .open = tracing_open_generic,
4308 .read = tracing_set_trace_read,
4309 .write = tracing_set_trace_write,
4310 .llseek = generic_file_llseek,
4313 static const struct file_operations tracing_pipe_fops = {
4314 .open = tracing_open_pipe,
4315 .poll = tracing_poll_pipe,
4316 .read = tracing_read_pipe,
4317 .splice_read = tracing_splice_read_pipe,
4318 .release = tracing_release_pipe,
4319 .llseek = no_llseek,
4322 static const struct file_operations tracing_entries_fops = {
4323 .open = tracing_open_generic,
4324 .read = tracing_entries_read,
4325 .write = tracing_entries_write,
4326 .llseek = generic_file_llseek,
4329 static const struct file_operations tracing_total_entries_fops = {
4330 .open = tracing_open_generic,
4331 .read = tracing_total_entries_read,
4332 .llseek = generic_file_llseek,
4335 static const struct file_operations tracing_free_buffer_fops = {
4336 .write = tracing_free_buffer_write,
4337 .release = tracing_free_buffer_release,
4340 static const struct file_operations tracing_mark_fops = {
4341 .open = tracing_open_generic,
4342 .write = tracing_mark_write,
4343 .llseek = generic_file_llseek,
4346 static const struct file_operations trace_clock_fops = {
4347 .open = tracing_clock_open,
4349 .llseek = seq_lseek,
4350 .release = single_release,
4351 .write = tracing_clock_write,
4354 #ifdef CONFIG_TRACER_SNAPSHOT
4355 static const struct file_operations snapshot_fops = {
4356 .open = tracing_snapshot_open,
4358 .write = tracing_snapshot_write,
4359 .llseek = tracing_seek,
4360 .release = tracing_snapshot_release,
4362 #endif /* CONFIG_TRACER_SNAPSHOT */
4364 struct ftrace_buffer_info {
4365 struct trace_array *tr;
4371 static int tracing_buffers_open(struct inode *inode, struct file *filp)
4373 struct trace_cpu *tc = inode->i_private;
4374 struct trace_array *tr = tc->tr;
4375 struct ftrace_buffer_info *info;
4377 if (tracing_disabled)
4380 info = kzalloc(sizeof(*info), GFP_KERNEL);
4385 info->cpu = tc->cpu;
4387 /* Force reading ring buffer for first read */
4388 info->read = (unsigned int)-1;
4390 filp->private_data = info;
4392 return nonseekable_open(inode, filp);
4396 tracing_buffers_read(struct file *filp, char __user *ubuf,
4397 size_t count, loff_t *ppos)
4399 struct ftrace_buffer_info *info = filp->private_data;
4407 info->spare = ring_buffer_alloc_read_page(info->tr->buffer, info->cpu);
4411 /* Do we have previous read data to read? */
4412 if (info->read < PAGE_SIZE)
4415 trace_access_lock(info->cpu);
4416 ret = ring_buffer_read_page(info->tr->buffer,
4420 trace_access_unlock(info->cpu);
4427 size = PAGE_SIZE - info->read;
4431 ret = copy_to_user(ubuf, info->spare + info->read, size);
4442 static int tracing_buffers_release(struct inode *inode, struct file *file)
4444 struct ftrace_buffer_info *info = file->private_data;
4447 ring_buffer_free_read_page(info->tr->buffer, info->spare);
4454 struct ring_buffer *buffer;
4459 static void buffer_pipe_buf_release(struct pipe_inode_info *pipe,
4460 struct pipe_buffer *buf)
4462 struct buffer_ref *ref = (struct buffer_ref *)buf->private;
4467 ring_buffer_free_read_page(ref->buffer, ref->page);
4472 static void buffer_pipe_buf_get(struct pipe_inode_info *pipe,
4473 struct pipe_buffer *buf)
4475 struct buffer_ref *ref = (struct buffer_ref *)buf->private;
4480 /* Pipe buffer operations for a buffer. */
4481 static const struct pipe_buf_operations buffer_pipe_buf_ops = {
4483 .map = generic_pipe_buf_map,
4484 .unmap = generic_pipe_buf_unmap,
4485 .confirm = generic_pipe_buf_confirm,
4486 .release = buffer_pipe_buf_release,
4487 .steal = generic_pipe_buf_steal,
4488 .get = buffer_pipe_buf_get,
4492 * Callback from splice_to_pipe(), if we need to release some pages
4493 * at the end of the spd in case we error'ed out in filling the pipe.
4495 static void buffer_spd_release(struct splice_pipe_desc *spd, unsigned int i)
4497 struct buffer_ref *ref =
4498 (struct buffer_ref *)spd->partial[i].private;
4503 ring_buffer_free_read_page(ref->buffer, ref->page);
4505 spd->partial[i].private = 0;
4509 tracing_buffers_splice_read(struct file *file, loff_t *ppos,
4510 struct pipe_inode_info *pipe, size_t len,
4513 struct ftrace_buffer_info *info = file->private_data;
4514 struct partial_page partial_def[PIPE_DEF_BUFFERS];
4515 struct page *pages_def[PIPE_DEF_BUFFERS];
4516 struct splice_pipe_desc spd = {
4518 .partial = partial_def,
4519 .nr_pages_max = PIPE_DEF_BUFFERS,
4521 .ops = &buffer_pipe_buf_ops,
4522 .spd_release = buffer_spd_release,
4524 struct buffer_ref *ref;
4525 int entries, size, i;
4528 if (splice_grow_spd(pipe, &spd))
4531 if (*ppos & (PAGE_SIZE - 1)) {
4536 if (len & (PAGE_SIZE - 1)) {
4537 if (len < PAGE_SIZE) {
4544 trace_access_lock(info->cpu);
4545 entries = ring_buffer_entries_cpu(info->tr->buffer, info->cpu);
4547 for (i = 0; i < pipe->buffers && len && entries; i++, len -= PAGE_SIZE) {
4551 ref = kzalloc(sizeof(*ref), GFP_KERNEL);
4556 ref->buffer = info->tr->buffer;
4557 ref->page = ring_buffer_alloc_read_page(ref->buffer, info->cpu);
4563 r = ring_buffer_read_page(ref->buffer, &ref->page,
4566 ring_buffer_free_read_page(ref->buffer, ref->page);
4572 * zero out any left over data, this is going to
4575 size = ring_buffer_page_len(ref->page);
4576 if (size < PAGE_SIZE)
4577 memset(ref->page + size, 0, PAGE_SIZE - size);
4579 page = virt_to_page(ref->page);
4581 spd.pages[i] = page;
4582 spd.partial[i].len = PAGE_SIZE;
4583 spd.partial[i].offset = 0;
4584 spd.partial[i].private = (unsigned long)ref;
4588 entries = ring_buffer_entries_cpu(info->tr->buffer, info->cpu);
4591 trace_access_unlock(info->cpu);
4594 /* did we read anything? */
4595 if (!spd.nr_pages) {
4596 if (flags & SPLICE_F_NONBLOCK)
4604 ret = splice_to_pipe(pipe, &spd);
4605 splice_shrink_spd(&spd);
4610 static const struct file_operations tracing_buffers_fops = {
4611 .open = tracing_buffers_open,
4612 .read = tracing_buffers_read,
4613 .release = tracing_buffers_release,
4614 .splice_read = tracing_buffers_splice_read,
4615 .llseek = no_llseek,
4619 tracing_stats_read(struct file *filp, char __user *ubuf,
4620 size_t count, loff_t *ppos)
4622 struct trace_cpu *tc = filp->private_data;
4623 struct trace_array *tr = tc->tr;
4624 struct trace_seq *s;
4626 unsigned long long t;
4627 unsigned long usec_rem;
4630 s = kmalloc(sizeof(*s), GFP_KERNEL);
4636 cnt = ring_buffer_entries_cpu(tr->buffer, cpu);
4637 trace_seq_printf(s, "entries: %ld\n", cnt);
4639 cnt = ring_buffer_overrun_cpu(tr->buffer, cpu);
4640 trace_seq_printf(s, "overrun: %ld\n", cnt);
4642 cnt = ring_buffer_commit_overrun_cpu(tr->buffer, cpu);
4643 trace_seq_printf(s, "commit overrun: %ld\n", cnt);
4645 cnt = ring_buffer_bytes_cpu(tr->buffer, cpu);
4646 trace_seq_printf(s, "bytes: %ld\n", cnt);
4648 if (trace_clocks[trace_clock_id].in_ns) {
4649 /* local or global for trace_clock */
4650 t = ns2usecs(ring_buffer_oldest_event_ts(tr->buffer, cpu));
4651 usec_rem = do_div(t, USEC_PER_SEC);
4652 trace_seq_printf(s, "oldest event ts: %5llu.%06lu\n",
4655 t = ns2usecs(ring_buffer_time_stamp(tr->buffer, cpu));
4656 usec_rem = do_div(t, USEC_PER_SEC);
4657 trace_seq_printf(s, "now ts: %5llu.%06lu\n", t, usec_rem);
4659 /* counter or tsc mode for trace_clock */
4660 trace_seq_printf(s, "oldest event ts: %llu\n",
4661 ring_buffer_oldest_event_ts(tr->buffer, cpu));
4663 trace_seq_printf(s, "now ts: %llu\n",
4664 ring_buffer_time_stamp(tr->buffer, cpu));
4667 cnt = ring_buffer_dropped_events_cpu(tr->buffer, cpu);
4668 trace_seq_printf(s, "dropped events: %ld\n", cnt);
4670 cnt = ring_buffer_read_events_cpu(tr->buffer, cpu);
4671 trace_seq_printf(s, "read events: %ld\n", cnt);
4673 count = simple_read_from_buffer(ubuf, count, ppos, s->buffer, s->len);
4680 static const struct file_operations tracing_stats_fops = {
4681 .open = tracing_open_generic,
4682 .read = tracing_stats_read,
4683 .llseek = generic_file_llseek,
4686 #ifdef CONFIG_DYNAMIC_FTRACE
4688 int __weak ftrace_arch_read_dyn_info(char *buf, int size)
4694 tracing_read_dyn_info(struct file *filp, char __user *ubuf,
4695 size_t cnt, loff_t *ppos)
4697 static char ftrace_dyn_info_buffer[1024];
4698 static DEFINE_MUTEX(dyn_info_mutex);
4699 unsigned long *p = filp->private_data;
4700 char *buf = ftrace_dyn_info_buffer;
4701 int size = ARRAY_SIZE(ftrace_dyn_info_buffer);
4704 mutex_lock(&dyn_info_mutex);
4705 r = sprintf(buf, "%ld ", *p);
4707 r += ftrace_arch_read_dyn_info(buf+r, (size-1)-r);
4710 r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
4712 mutex_unlock(&dyn_info_mutex);
4717 static const struct file_operations tracing_dyn_info_fops = {
4718 .open = tracing_open_generic,
4719 .read = tracing_read_dyn_info,
4720 .llseek = generic_file_llseek,
4724 struct dentry *tracing_init_dentry_tr(struct trace_array *tr)
4731 if (!debugfs_initialized())
4734 if (tr->flags & TRACE_ARRAY_FL_GLOBAL)
4735 tr->dir = debugfs_create_dir("tracing", NULL);
4737 if (!tr->dir && !once) {
4739 pr_warning("Could not create debugfs directory 'tracing'\n");
4746 struct dentry *tracing_init_dentry(void)
4748 return tracing_init_dentry_tr(&global_trace);
4751 static struct dentry *tracing_dentry_percpu(struct trace_array *tr, int cpu)
4753 struct dentry *d_tracer;
4756 return tr->percpu_dir;
4758 d_tracer = tracing_init_dentry_tr(tr);
4762 tr->percpu_dir = debugfs_create_dir("per_cpu", d_tracer);
4764 WARN_ONCE(!tr->percpu_dir,
4765 "Could not create debugfs directory 'per_cpu/%d'\n", cpu);
4767 return tr->percpu_dir;
4771 tracing_init_debugfs_percpu(struct trace_array *tr, long cpu)
4773 struct trace_array_cpu *data = per_cpu_ptr(tr->data, cpu);
4774 struct dentry *d_percpu = tracing_dentry_percpu(tr, cpu);
4775 struct dentry *d_cpu;
4776 char cpu_dir[30]; /* 30 characters should be more than enough */
4781 snprintf(cpu_dir, 30, "cpu%ld", cpu);
4782 d_cpu = debugfs_create_dir(cpu_dir, d_percpu);
4784 pr_warning("Could not create debugfs '%s' entry\n", cpu_dir);
4788 /* per cpu trace_pipe */
4789 trace_create_file("trace_pipe", 0444, d_cpu,
4790 (void *)&data->trace_cpu, &tracing_pipe_fops);
4793 trace_create_file("trace", 0644, d_cpu,
4794 (void *)&data->trace_cpu, &tracing_fops);
4796 trace_create_file("trace_pipe_raw", 0444, d_cpu,
4797 (void *)&data->trace_cpu, &tracing_buffers_fops);
4799 trace_create_file("stats", 0444, d_cpu,
4800 (void *)&data->trace_cpu, &tracing_stats_fops);
4802 trace_create_file("buffer_size_kb", 0444, d_cpu,
4803 (void *)&data->trace_cpu, &tracing_entries_fops);
4806 #ifdef CONFIG_FTRACE_SELFTEST
4807 /* Let selftest have access to static functions in this file */
4808 #include "trace_selftest.c"
4811 struct trace_option_dentry {
4812 struct tracer_opt *opt;
4813 struct tracer_flags *flags;
4814 struct trace_array *tr;
4815 struct dentry *entry;
4819 trace_options_read(struct file *filp, char __user *ubuf, size_t cnt,
4822 struct trace_option_dentry *topt = filp->private_data;
4825 if (topt->flags->val & topt->opt->bit)
4830 return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2);
4834 trace_options_write(struct file *filp, const char __user *ubuf, size_t cnt,
4837 struct trace_option_dentry *topt = filp->private_data;
4841 ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
4845 if (val != 0 && val != 1)
4848 if (!!(topt->flags->val & topt->opt->bit) != val) {
4849 mutex_lock(&trace_types_lock);
4850 ret = __set_tracer_option(topt->tr->current_trace, topt->flags,
4852 mutex_unlock(&trace_types_lock);
4863 static const struct file_operations trace_options_fops = {
4864 .open = tracing_open_generic,
4865 .read = trace_options_read,
4866 .write = trace_options_write,
4867 .llseek = generic_file_llseek,
4871 trace_options_core_read(struct file *filp, char __user *ubuf, size_t cnt,
4874 long index = (long)filp->private_data;
4877 if (trace_flags & (1 << index))
4882 return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2);
4886 trace_options_core_write(struct file *filp, const char __user *ubuf, size_t cnt,
4889 struct trace_array *tr = &global_trace;
4890 long index = (long)filp->private_data;
4894 ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
4898 if (val != 0 && val != 1)
4901 mutex_lock(&trace_types_lock);
4902 ret = set_tracer_flag(tr, 1 << index, val);
4903 mutex_unlock(&trace_types_lock);
4913 static const struct file_operations trace_options_core_fops = {
4914 .open = tracing_open_generic,
4915 .read = trace_options_core_read,
4916 .write = trace_options_core_write,
4917 .llseek = generic_file_llseek,
4920 struct dentry *trace_create_file(const char *name,
4922 struct dentry *parent,
4924 const struct file_operations *fops)
4928 ret = debugfs_create_file(name, mode, parent, data, fops);
4930 pr_warning("Could not create debugfs '%s' entry\n", name);
4936 static struct dentry *trace_options_init_dentry(struct trace_array *tr)
4938 struct dentry *d_tracer;
4943 d_tracer = tracing_init_dentry_tr(tr);
4947 tr->options = debugfs_create_dir("options", d_tracer);
4949 pr_warning("Could not create debugfs directory 'options'\n");
4957 create_trace_option_file(struct trace_array *tr,
4958 struct trace_option_dentry *topt,
4959 struct tracer_flags *flags,
4960 struct tracer_opt *opt)
4962 struct dentry *t_options;
4964 t_options = trace_options_init_dentry(tr);
4968 topt->flags = flags;
4972 topt->entry = trace_create_file(opt->name, 0644, t_options, topt,
4973 &trace_options_fops);
4977 static struct trace_option_dentry *
4978 create_trace_option_files(struct trace_array *tr, struct tracer *tracer)
4980 struct trace_option_dentry *topts;
4981 struct tracer_flags *flags;
4982 struct tracer_opt *opts;
4988 flags = tracer->flags;
4990 if (!flags || !flags->opts)
4995 for (cnt = 0; opts[cnt].name; cnt++)
4998 topts = kcalloc(cnt + 1, sizeof(*topts), GFP_KERNEL);
5002 for (cnt = 0; opts[cnt].name; cnt++)
5003 create_trace_option_file(tr, &topts[cnt], flags,
5010 destroy_trace_option_files(struct trace_option_dentry *topts)
5017 for (cnt = 0; topts[cnt].opt; cnt++) {
5018 if (topts[cnt].entry)
5019 debugfs_remove(topts[cnt].entry);
5025 static struct dentry *
5026 create_trace_option_core_file(struct trace_array *tr,
5027 const char *option, long index)
5029 struct dentry *t_options;
5031 t_options = trace_options_init_dentry(tr);
5035 return trace_create_file(option, 0644, t_options, (void *)index,
5036 &trace_options_core_fops);
5039 static __init void create_trace_options_dir(struct trace_array *tr)
5041 struct dentry *t_options;
5044 t_options = trace_options_init_dentry(tr);
5048 for (i = 0; trace_options[i]; i++)
5049 create_trace_option_core_file(tr, trace_options[i], i);
5053 rb_simple_read(struct file *filp, char __user *ubuf,
5054 size_t cnt, loff_t *ppos)
5056 struct trace_array *tr = filp->private_data;
5057 struct ring_buffer *buffer = tr->buffer;
5062 r = ring_buffer_record_is_on(buffer);
5066 r = sprintf(buf, "%d\n", r);
5068 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
5072 rb_simple_write(struct file *filp, const char __user *ubuf,
5073 size_t cnt, loff_t *ppos)
5075 struct trace_array *tr = filp->private_data;
5076 struct ring_buffer *buffer = tr->buffer;
5080 ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
5085 mutex_lock(&trace_types_lock);
5087 ring_buffer_record_on(buffer);
5088 if (tr->current_trace->start)
5089 tr->current_trace->start(tr);
5091 ring_buffer_record_off(buffer);
5092 if (tr->current_trace->stop)
5093 tr->current_trace->stop(tr);
5095 mutex_unlock(&trace_types_lock);
5103 static const struct file_operations rb_simple_fops = {
5104 .open = tracing_open_generic,
5105 .read = rb_simple_read,
5106 .write = rb_simple_write,
5107 .llseek = default_llseek,
5110 struct dentry *trace_instance_dir;
5113 init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer);
5115 static int new_instance_create(const char *name)
5117 enum ring_buffer_flags rb_flags;
5118 struct trace_array *tr;
5122 mutex_lock(&trace_types_lock);
5125 list_for_each_entry(tr, &ftrace_trace_arrays, list) {
5126 if (tr->name && strcmp(tr->name, name) == 0)
5131 tr = kzalloc(sizeof(*tr), GFP_KERNEL);
5135 tr->name = kstrdup(name, GFP_KERNEL);
5139 raw_spin_lock_init(&tr->start_lock);
5141 tr->current_trace = &nop_trace;
5143 INIT_LIST_HEAD(&tr->systems);
5144 INIT_LIST_HEAD(&tr->events);
5146 rb_flags = trace_flags & TRACE_ITER_OVERWRITE ? RB_FL_OVERWRITE : 0;
5148 tr->buffer = ring_buffer_alloc(trace_buf_size, rb_flags);
5152 tr->data = alloc_percpu(struct trace_array_cpu);
5156 for_each_tracing_cpu(i) {
5157 memset(per_cpu_ptr(tr->data, i), 0, sizeof(struct trace_array_cpu));
5158 per_cpu_ptr(tr->data, i)->trace_cpu.cpu = i;
5159 per_cpu_ptr(tr->data, i)->trace_cpu.tr = tr;
5162 /* Holder for file callbacks */
5163 tr->trace_cpu.cpu = RING_BUFFER_ALL_CPUS;
5164 tr->trace_cpu.tr = tr;
5166 tr->dir = debugfs_create_dir(name, trace_instance_dir);
5170 ret = event_trace_add_tracer(tr->dir, tr);
5174 init_tracer_debugfs(tr, tr->dir);
5176 list_add(&tr->list, &ftrace_trace_arrays);
5178 mutex_unlock(&trace_types_lock);
5184 ring_buffer_free(tr->buffer);
5189 mutex_unlock(&trace_types_lock);
5195 static int instance_delete(const char *name)
5197 struct trace_array *tr;
5201 mutex_lock(&trace_types_lock);
5204 list_for_each_entry(tr, &ftrace_trace_arrays, list) {
5205 if (tr->name && strcmp(tr->name, name) == 0) {
5213 list_del(&tr->list);
5215 event_trace_del_tracer(tr);
5216 debugfs_remove_recursive(tr->dir);
5217 free_percpu(tr->data);
5218 ring_buffer_free(tr->buffer);
5226 mutex_unlock(&trace_types_lock);
5231 static int instance_mkdir (struct inode *inode, struct dentry *dentry, umode_t mode)
5233 struct dentry *parent;
5236 /* Paranoid: Make sure the parent is the "instances" directory */
5237 parent = hlist_entry(inode->i_dentry.first, struct dentry, d_alias);
5238 if (WARN_ON_ONCE(parent != trace_instance_dir))
5242 * The inode mutex is locked, but debugfs_create_dir() will also
5243 * take the mutex. As the instances directory can not be destroyed
5244 * or changed in any other way, it is safe to unlock it, and
5245 * let the dentry try. If two users try to make the same dir at
5246 * the same time, then the new_instance_create() will determine the
5249 mutex_unlock(&inode->i_mutex);
5251 ret = new_instance_create(dentry->d_iname);
5253 mutex_lock(&inode->i_mutex);
5258 static int instance_rmdir(struct inode *inode, struct dentry *dentry)
5260 struct dentry *parent;
5263 /* Paranoid: Make sure the parent is the "instances" directory */
5264 parent = hlist_entry(inode->i_dentry.first, struct dentry, d_alias);
5265 if (WARN_ON_ONCE(parent != trace_instance_dir))
5268 /* The caller did a dget() on dentry */
5269 mutex_unlock(&dentry->d_inode->i_mutex);
5272 * The inode mutex is locked, but debugfs_create_dir() will also
5273 * take the mutex. As the instances directory can not be destroyed
5274 * or changed in any other way, it is safe to unlock it, and
5275 * let the dentry try. If two users try to make the same dir at
5276 * the same time, then the instance_delete() will determine the
5279 mutex_unlock(&inode->i_mutex);
5281 ret = instance_delete(dentry->d_iname);
5283 mutex_lock_nested(&inode->i_mutex, I_MUTEX_PARENT);
5284 mutex_lock(&dentry->d_inode->i_mutex);
5289 static const struct inode_operations instance_dir_inode_operations = {
5290 .lookup = simple_lookup,
5291 .mkdir = instance_mkdir,
5292 .rmdir = instance_rmdir,
5295 static __init void create_trace_instances(struct dentry *d_tracer)
5297 trace_instance_dir = debugfs_create_dir("instances", d_tracer);
5298 if (WARN_ON(!trace_instance_dir))
5301 /* Hijack the dir inode operations, to allow mkdir */
5302 trace_instance_dir->d_inode->i_op = &instance_dir_inode_operations;
5306 init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer)
5309 trace_create_file("trace_options", 0644, d_tracer,
5310 tr, &tracing_iter_fops);
5312 trace_create_file("trace", 0644, d_tracer,
5313 (void *)&tr->trace_cpu, &tracing_fops);
5315 trace_create_file("trace_pipe", 0444, d_tracer,
5316 (void *)&tr->trace_cpu, &tracing_pipe_fops);
5318 trace_create_file("buffer_size_kb", 0644, d_tracer,
5319 (void *)&tr->trace_cpu, &tracing_entries_fops);
5321 trace_create_file("buffer_total_size_kb", 0444, d_tracer,
5322 tr, &tracing_total_entries_fops);
5324 trace_create_file("free_buffer", 0644, d_tracer,
5325 tr, &tracing_free_buffer_fops);
5327 trace_create_file("trace_marker", 0220, d_tracer,
5328 tr, &tracing_mark_fops);
5330 trace_create_file("trace_clock", 0644, d_tracer, tr,
5333 trace_create_file("tracing_on", 0644, d_tracer,
5334 tr, &rb_simple_fops);
5337 static __init int tracer_init_debugfs(void)
5339 struct dentry *d_tracer;
5342 trace_access_lock_init();
5344 d_tracer = tracing_init_dentry();
5346 init_tracer_debugfs(&global_trace, d_tracer);
5348 trace_create_file("tracing_cpumask", 0644, d_tracer,
5349 &global_trace, &tracing_cpumask_fops);
5351 trace_create_file("available_tracers", 0444, d_tracer,
5352 &global_trace, &show_traces_fops);
5354 trace_create_file("current_tracer", 0644, d_tracer,
5355 &global_trace, &set_tracer_fops);
5357 #ifdef CONFIG_TRACER_MAX_TRACE
5358 trace_create_file("tracing_max_latency", 0644, d_tracer,
5359 &tracing_max_latency, &tracing_max_lat_fops);
5362 trace_create_file("tracing_thresh", 0644, d_tracer,
5363 &tracing_thresh, &tracing_max_lat_fops);
5365 trace_create_file("README", 0444, d_tracer,
5366 NULL, &tracing_readme_fops);
5368 trace_create_file("saved_cmdlines", 0444, d_tracer,
5369 NULL, &tracing_saved_cmdlines_fops);
5371 #ifdef CONFIG_DYNAMIC_FTRACE
5372 trace_create_file("dyn_ftrace_total_info", 0444, d_tracer,
5373 &ftrace_update_tot_cnt, &tracing_dyn_info_fops);
5376 #ifdef CONFIG_TRACER_SNAPSHOT
5377 trace_create_file("snapshot", 0644, d_tracer,
5378 (void *)&global_trace.trace_cpu, &snapshot_fops);
5381 create_trace_instances(d_tracer);
5383 create_trace_options_dir(&global_trace);
5385 for_each_tracing_cpu(cpu)
5386 tracing_init_debugfs_percpu(&global_trace, cpu);
5391 static int trace_panic_handler(struct notifier_block *this,
5392 unsigned long event, void *unused)
5394 if (ftrace_dump_on_oops)
5395 ftrace_dump(ftrace_dump_on_oops);
5399 static struct notifier_block trace_panic_notifier = {
5400 .notifier_call = trace_panic_handler,
5402 .priority = 150 /* priority: INT_MAX >= x >= 0 */
5405 static int trace_die_handler(struct notifier_block *self,
5411 if (ftrace_dump_on_oops)
5412 ftrace_dump(ftrace_dump_on_oops);
5420 static struct notifier_block trace_die_notifier = {
5421 .notifier_call = trace_die_handler,
5426 * printk is set to max of 1024, we really don't need it that big.
5427 * Nothing should be printing 1000 characters anyway.
5429 #define TRACE_MAX_PRINT 1000
5432 * Define here KERN_TRACE so that we have one place to modify
5433 * it if we decide to change what log level the ftrace dump
5436 #define KERN_TRACE KERN_EMERG
5439 trace_printk_seq(struct trace_seq *s)
5441 /* Probably should print a warning here. */
5445 /* should be zero ended, but we are paranoid. */
5446 s->buffer[s->len] = 0;
5448 printk(KERN_TRACE "%s", s->buffer);
5453 void trace_init_global_iter(struct trace_iterator *iter)
5455 iter->tr = &global_trace;
5456 iter->trace = iter->tr->current_trace;
5457 iter->cpu_file = RING_BUFFER_ALL_CPUS;
5461 __ftrace_dump(bool disable_tracing, enum ftrace_dump_mode oops_dump_mode)
5463 static arch_spinlock_t ftrace_dump_lock =
5464 (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED;
5465 /* use static because iter can be a bit big for the stack */
5466 static struct trace_iterator iter;
5467 unsigned int old_userobj;
5468 static int dump_ran;
5469 unsigned long flags;
5473 local_irq_save(flags);
5474 arch_spin_lock(&ftrace_dump_lock);
5482 /* Did function tracer already get disabled? */
5483 if (ftrace_is_dead()) {
5484 printk("# WARNING: FUNCTION TRACING IS CORRUPTED\n");
5485 printk("# MAY BE MISSING FUNCTION EVENTS\n");
5488 if (disable_tracing)
5491 /* Simulate the iterator */
5492 trace_init_global_iter(&iter);
5494 for_each_tracing_cpu(cpu) {
5495 atomic_inc(&per_cpu_ptr(iter.tr->data, cpu)->disabled);
5498 old_userobj = trace_flags & TRACE_ITER_SYM_USEROBJ;
5500 /* don't look at user memory in panic mode */
5501 trace_flags &= ~TRACE_ITER_SYM_USEROBJ;
5503 switch (oops_dump_mode) {
5505 iter.cpu_file = RING_BUFFER_ALL_CPUS;
5508 iter.cpu_file = raw_smp_processor_id();
5513 printk(KERN_TRACE "Bad dumping mode, switching to all CPUs dump\n");
5514 iter.cpu_file = RING_BUFFER_ALL_CPUS;
5517 printk(KERN_TRACE "Dumping ftrace buffer:\n");
5520 * We need to stop all tracing on all CPUS to read the
5521 * the next buffer. This is a bit expensive, but is
5522 * not done often. We fill all what we can read,
5523 * and then release the locks again.
5526 while (!trace_empty(&iter)) {
5529 printk(KERN_TRACE "---------------------------------\n");
5533 /* reset all but tr, trace, and overruns */
5534 memset(&iter.seq, 0,
5535 sizeof(struct trace_iterator) -
5536 offsetof(struct trace_iterator, seq));
5537 iter.iter_flags |= TRACE_FILE_LAT_FMT;
5540 if (trace_find_next_entry_inc(&iter) != NULL) {
5543 ret = print_trace_line(&iter);
5544 if (ret != TRACE_TYPE_NO_CONSUME)
5545 trace_consume(&iter);
5547 touch_nmi_watchdog();
5549 trace_printk_seq(&iter.seq);
5553 printk(KERN_TRACE " (ftrace buffer empty)\n");
5555 printk(KERN_TRACE "---------------------------------\n");
5558 /* Re-enable tracing if requested */
5559 if (!disable_tracing) {
5560 trace_flags |= old_userobj;
5562 for_each_tracing_cpu(cpu) {
5563 atomic_dec(&per_cpu_ptr(iter.tr->data, cpu)->disabled);
5569 arch_spin_unlock(&ftrace_dump_lock);
5570 local_irq_restore(flags);
5573 /* By default: disable tracing after the dump */
5574 void ftrace_dump(enum ftrace_dump_mode oops_dump_mode)
5576 __ftrace_dump(true, oops_dump_mode);
5578 EXPORT_SYMBOL_GPL(ftrace_dump);
5580 __init static int tracer_alloc_buffers(void)
5583 enum ring_buffer_flags rb_flags;
5588 if (!alloc_cpumask_var(&tracing_buffer_mask, GFP_KERNEL))
5591 if (!alloc_cpumask_var(&tracing_cpumask, GFP_KERNEL))
5592 goto out_free_buffer_mask;
5594 /* Only allocate trace_printk buffers if a trace_printk exists */
5595 if (__stop___trace_bprintk_fmt != __start___trace_bprintk_fmt)
5596 /* Must be called before global_trace.buffer is allocated */
5597 trace_printk_init_buffers();
5599 /* To save memory, keep the ring buffer size to its minimum */
5600 if (ring_buffer_expanded)
5601 ring_buf_size = trace_buf_size;
5605 rb_flags = trace_flags & TRACE_ITER_OVERWRITE ? RB_FL_OVERWRITE : 0;
5607 cpumask_copy(tracing_buffer_mask, cpu_possible_mask);
5608 cpumask_copy(tracing_cpumask, cpu_all_mask);
5610 raw_spin_lock_init(&global_trace.start_lock);
5612 /* TODO: make the number of buffers hot pluggable with CPUS */
5613 global_trace.buffer = ring_buffer_alloc(ring_buf_size, rb_flags);
5614 if (!global_trace.buffer) {
5615 printk(KERN_ERR "tracer: failed to allocate ring buffer!\n");
5617 goto out_free_cpumask;
5620 global_trace.data = alloc_percpu(struct trace_array_cpu);
5622 if (!global_trace.data) {
5623 printk(KERN_ERR "tracer: failed to allocate percpu memory!\n");
5625 goto out_free_cpumask;
5628 for_each_tracing_cpu(i) {
5629 memset(per_cpu_ptr(global_trace.data, i), 0, sizeof(struct trace_array_cpu));
5630 per_cpu_ptr(global_trace.data, i)->trace_cpu.cpu = i;
5631 per_cpu_ptr(global_trace.data, i)->trace_cpu.tr = &global_trace;
5634 if (global_trace.buffer_disabled)
5637 #ifdef CONFIG_TRACER_MAX_TRACE
5638 max_tr.data = alloc_percpu(struct trace_array_cpu);
5640 printk(KERN_ERR "tracer: failed to allocate percpu memory!\n");
5642 goto out_free_cpumask;
5644 max_tr.buffer = ring_buffer_alloc(1, rb_flags);
5645 raw_spin_lock_init(&max_tr.start_lock);
5646 if (!max_tr.buffer) {
5647 printk(KERN_ERR "tracer: failed to allocate max ring buffer!\n");
5649 ring_buffer_free(global_trace.buffer);
5650 goto out_free_cpumask;
5653 for_each_tracing_cpu(i) {
5654 memset(per_cpu_ptr(max_tr.data, i), 0, sizeof(struct trace_array_cpu));
5655 per_cpu_ptr(max_tr.data, i)->trace_cpu.cpu = i;
5656 per_cpu_ptr(max_tr.data, i)->trace_cpu.tr = &max_tr;
5660 /* Allocate the first page for all buffers */
5661 set_buffer_entries(&global_trace,
5662 ring_buffer_size(global_trace.buffer, 0));
5663 #ifdef CONFIG_TRACER_MAX_TRACE
5664 set_buffer_entries(&max_tr, 1);
5667 trace_init_cmdlines();
5668 init_irq_work(&trace_work_wakeup, trace_wake_up);
5670 register_tracer(&nop_trace);
5672 global_trace.current_trace = &nop_trace;
5674 /* All seems OK, enable tracing */
5675 tracing_disabled = 0;
5677 atomic_notifier_chain_register(&panic_notifier_list,
5678 &trace_panic_notifier);
5680 register_die_notifier(&trace_die_notifier);
5682 global_trace.flags = TRACE_ARRAY_FL_GLOBAL;
5684 /* Holder for file callbacks */
5685 global_trace.trace_cpu.cpu = RING_BUFFER_ALL_CPUS;
5686 global_trace.trace_cpu.tr = &global_trace;
5688 INIT_LIST_HEAD(&global_trace.systems);
5689 INIT_LIST_HEAD(&global_trace.events);
5690 list_add(&global_trace.list, &ftrace_trace_arrays);
5692 while (trace_boot_options) {
5695 option = strsep(&trace_boot_options, ",");
5696 trace_set_options(&global_trace, option);
5702 free_percpu(global_trace.data);
5703 free_percpu(max_tr.data);
5704 free_cpumask_var(tracing_cpumask);
5705 out_free_buffer_mask:
5706 free_cpumask_var(tracing_buffer_mask);
5711 __init static int clear_boot_tracer(void)
5714 * The default tracer at boot buffer is an init section.
5715 * This function is called in lateinit. If we did not
5716 * find the boot tracer, then clear it out, to prevent
5717 * later registration from accessing the buffer that is
5718 * about to be freed.
5720 if (!default_bootup_tracer)
5723 printk(KERN_INFO "ftrace bootup tracer '%s' not registered.\n",
5724 default_bootup_tracer);
5725 default_bootup_tracer = NULL;
5730 early_initcall(tracer_alloc_buffers);
5731 fs_initcall(tracer_init_debugfs);
5732 late_initcall(clear_boot_tracer);