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/debugfs.h>
23 #include <linux/pagemap.h>
24 #include <linux/hardirq.h>
25 #include <linux/linkage.h>
26 #include <linux/uaccess.h>
27 #include <linux/kprobes.h>
28 #include <linux/ftrace.h>
29 #include <linux/module.h>
30 #include <linux/percpu.h>
31 #include <linux/splice.h>
32 #include <linux/kdebug.h>
33 #include <linux/string.h>
34 #include <linux/rwsem.h>
35 #include <linux/slab.h>
36 #include <linux/ctype.h>
37 #include <linux/init.h>
38 #include <linux/poll.h>
39 #include <linux/nmi.h>
41 #include <linux/sched/rt.h>
44 #include "trace_output.h"
47 * On boot up, the ring buffer is set to the minimum size, so that
48 * we do not waste memory on systems that are not using tracing.
50 int ring_buffer_expanded;
53 * We need to change this state when a selftest is running.
54 * A selftest will lurk into the ring-buffer to count the
55 * entries inserted during the selftest although some concurrent
56 * insertions into the ring-buffer such as trace_printk could occurred
57 * at the same time, giving false positive or negative results.
59 static bool __read_mostly tracing_selftest_running;
62 * If a tracer is running, we do not want to run SELFTEST.
64 bool __read_mostly tracing_selftest_disabled;
66 /* For tracers that don't implement custom flags */
67 static struct tracer_opt dummy_tracer_opt[] = {
71 static struct tracer_flags dummy_tracer_flags = {
73 .opts = dummy_tracer_opt
76 static int dummy_set_flag(u32 old_flags, u32 bit, int set)
82 * To prevent the comm cache from being overwritten when no
83 * tracing is active, only save the comm when a trace event
86 static DEFINE_PER_CPU(bool, trace_cmdline_save);
89 * Kill all tracing for good (never come back).
90 * It is initialized to 1 but will turn to zero if the initialization
91 * of the tracer is successful. But that is the only place that sets
94 static int tracing_disabled = 1;
96 DEFINE_PER_CPU(int, ftrace_cpu_disabled);
98 cpumask_var_t __read_mostly tracing_buffer_mask;
101 * ftrace_dump_on_oops - variable to dump ftrace buffer on oops
103 * If there is an oops (or kernel panic) and the ftrace_dump_on_oops
104 * is set, then ftrace_dump is called. This will output the contents
105 * of the ftrace buffers to the console. This is very useful for
106 * capturing traces that lead to crashes and outputing it to a
109 * It is default off, but you can enable it with either specifying
110 * "ftrace_dump_on_oops" in the kernel command line, or setting
111 * /proc/sys/kernel/ftrace_dump_on_oops
112 * Set 1 if you want to dump buffers of all CPUs
113 * Set 2 if you want to dump the buffer of the CPU that triggered oops
116 enum ftrace_dump_mode ftrace_dump_on_oops;
118 static int tracing_set_tracer(const char *buf);
120 #define MAX_TRACER_SIZE 100
121 static char bootup_tracer_buf[MAX_TRACER_SIZE] __initdata;
122 static char *default_bootup_tracer;
124 static int __init set_cmdline_ftrace(char *str)
126 strncpy(bootup_tracer_buf, str, MAX_TRACER_SIZE);
127 default_bootup_tracer = bootup_tracer_buf;
128 /* We are using ftrace early, expand it */
129 ring_buffer_expanded = 1;
132 __setup("ftrace=", set_cmdline_ftrace);
134 static int __init set_ftrace_dump_on_oops(char *str)
136 if (*str++ != '=' || !*str) {
137 ftrace_dump_on_oops = DUMP_ALL;
141 if (!strcmp("orig_cpu", str)) {
142 ftrace_dump_on_oops = DUMP_ORIG;
148 __setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops);
151 static char trace_boot_options_buf[MAX_TRACER_SIZE] __initdata;
152 static char *trace_boot_options __initdata;
154 static int __init set_trace_boot_options(char *str)
156 strncpy(trace_boot_options_buf, str, MAX_TRACER_SIZE);
157 trace_boot_options = trace_boot_options_buf;
160 __setup("trace_options=", set_trace_boot_options);
162 unsigned long long ns2usecs(cycle_t nsec)
170 * The global_trace is the descriptor that holds the tracing
171 * buffers for the live tracing. For each CPU, it contains
172 * a link list of pages that will store trace entries. The
173 * page descriptor of the pages in the memory is used to hold
174 * the link list by linking the lru item in the page descriptor
175 * to each of the pages in the buffer per CPU.
177 * For each active CPU there is a data field that holds the
178 * pages for the buffer for that CPU. Each CPU has the same number
179 * of pages allocated for its buffer.
181 static struct trace_array global_trace;
183 LIST_HEAD(ftrace_trace_arrays);
185 int filter_current_check_discard(struct ring_buffer *buffer,
186 struct ftrace_event_call *call, void *rec,
187 struct ring_buffer_event *event)
189 return filter_check_discard(call, rec, buffer, event);
191 EXPORT_SYMBOL_GPL(filter_current_check_discard);
193 cycle_t ftrace_now(int cpu)
197 /* Early boot up does not have a buffer yet */
198 if (!global_trace.buffer)
199 return trace_clock_local();
201 ts = ring_buffer_time_stamp(global_trace.buffer, cpu);
202 ring_buffer_normalize_time_stamp(global_trace.buffer, cpu, &ts);
208 * The max_tr is used to snapshot the global_trace when a maximum
209 * latency is reached. Some tracers will use this to store a maximum
210 * trace while it continues examining live traces.
212 * The buffers for the max_tr are set up the same as the global_trace.
213 * When a snapshot is taken, the link list of the max_tr is swapped
214 * with the link list of the global_trace and the buffers are reset for
215 * the global_trace so the tracing can continue.
217 static struct trace_array max_tr;
219 int tracing_is_enabled(void)
221 return tracing_is_on();
225 * trace_buf_size is the size in bytes that is allocated
226 * for a buffer. Note, the number of bytes is always rounded
229 * This number is purposely set to a low number of 16384.
230 * If the dump on oops happens, it will be much appreciated
231 * to not have to wait for all that output. Anyway this can be
232 * boot time and run time configurable.
234 #define TRACE_BUF_SIZE_DEFAULT 1441792UL /* 16384 * 88 (sizeof(entry)) */
236 static unsigned long trace_buf_size = TRACE_BUF_SIZE_DEFAULT;
238 /* trace_types holds a link list of available tracers. */
239 static struct tracer *trace_types __read_mostly;
242 * trace_types_lock is used to protect the trace_types list.
244 static DEFINE_MUTEX(trace_types_lock);
247 * serialize the access of the ring buffer
249 * ring buffer serializes readers, but it is low level protection.
250 * The validity of the events (which returns by ring_buffer_peek() ..etc)
251 * are not protected by ring buffer.
253 * The content of events may become garbage if we allow other process consumes
254 * these events concurrently:
255 * A) the page of the consumed events may become a normal page
256 * (not reader page) in ring buffer, and this page will be rewrited
257 * by events producer.
258 * B) The page of the consumed events may become a page for splice_read,
259 * and this page will be returned to system.
261 * These primitives allow multi process access to different cpu ring buffer
264 * These primitives don't distinguish read-only and read-consume access.
265 * Multi read-only access are also serialized.
269 static DECLARE_RWSEM(all_cpu_access_lock);
270 static DEFINE_PER_CPU(struct mutex, cpu_access_lock);
272 static inline void trace_access_lock(int cpu)
274 if (cpu == RING_BUFFER_ALL_CPUS) {
275 /* gain it for accessing the whole ring buffer. */
276 down_write(&all_cpu_access_lock);
278 /* gain it for accessing a cpu ring buffer. */
280 /* Firstly block other trace_access_lock(RING_BUFFER_ALL_CPUS). */
281 down_read(&all_cpu_access_lock);
283 /* Secondly block other access to this @cpu ring buffer. */
284 mutex_lock(&per_cpu(cpu_access_lock, cpu));
288 static inline void trace_access_unlock(int cpu)
290 if (cpu == RING_BUFFER_ALL_CPUS) {
291 up_write(&all_cpu_access_lock);
293 mutex_unlock(&per_cpu(cpu_access_lock, cpu));
294 up_read(&all_cpu_access_lock);
298 static inline void trace_access_lock_init(void)
302 for_each_possible_cpu(cpu)
303 mutex_init(&per_cpu(cpu_access_lock, cpu));
308 static DEFINE_MUTEX(access_lock);
310 static inline void trace_access_lock(int cpu)
313 mutex_lock(&access_lock);
316 static inline void trace_access_unlock(int cpu)
319 mutex_unlock(&access_lock);
322 static inline void trace_access_lock_init(void)
328 /* trace_flags holds trace_options default values */
329 unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |
330 TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | TRACE_ITER_SLEEP_TIME |
331 TRACE_ITER_GRAPH_TIME | TRACE_ITER_RECORD_CMD | TRACE_ITER_OVERWRITE |
332 TRACE_ITER_IRQ_INFO | TRACE_ITER_MARKERS;
335 * tracing_on - enable tracing buffers
337 * This function enables tracing buffers that may have been
338 * disabled with tracing_off.
340 void tracing_on(void)
342 if (global_trace.buffer)
343 ring_buffer_record_on(global_trace.buffer);
345 * This flag is only looked at when buffers haven't been
346 * allocated yet. We don't really care about the race
347 * between setting this flag and actually turning
350 global_trace.buffer_disabled = 0;
352 EXPORT_SYMBOL_GPL(tracing_on);
355 * tracing_off - turn off tracing buffers
357 * This function stops the tracing buffers from recording data.
358 * It does not disable any overhead the tracers themselves may
359 * be causing. This function simply causes all recording to
360 * the ring buffers to fail.
362 void tracing_off(void)
364 if (global_trace.buffer)
365 ring_buffer_record_off(global_trace.buffer);
367 * This flag is only looked at when buffers haven't been
368 * allocated yet. We don't really care about the race
369 * between setting this flag and actually turning
372 global_trace.buffer_disabled = 1;
374 EXPORT_SYMBOL_GPL(tracing_off);
377 * tracing_is_on - show state of ring buffers enabled
379 int tracing_is_on(void)
381 if (global_trace.buffer)
382 return ring_buffer_record_is_on(global_trace.buffer);
383 return !global_trace.buffer_disabled;
385 EXPORT_SYMBOL_GPL(tracing_is_on);
387 static int __init set_buf_size(char *str)
389 unsigned long buf_size;
393 buf_size = memparse(str, &str);
394 /* nr_entries can not be zero */
397 trace_buf_size = buf_size;
400 __setup("trace_buf_size=", set_buf_size);
402 static int __init set_tracing_thresh(char *str)
404 unsigned long threshold;
409 ret = kstrtoul(str, 0, &threshold);
412 tracing_thresh = threshold * 1000;
415 __setup("tracing_thresh=", set_tracing_thresh);
417 unsigned long nsecs_to_usecs(unsigned long nsecs)
422 /* These must match the bit postions in trace_iterator_flags */
423 static const char *trace_options[] = {
455 int in_ns; /* is this clock in nanoseconds? */
457 { trace_clock_local, "local", 1 },
458 { trace_clock_global, "global", 1 },
459 { trace_clock_counter, "counter", 0 },
466 * trace_parser_get_init - gets the buffer for trace parser
468 int trace_parser_get_init(struct trace_parser *parser, int size)
470 memset(parser, 0, sizeof(*parser));
472 parser->buffer = kmalloc(size, GFP_KERNEL);
481 * trace_parser_put - frees the buffer for trace parser
483 void trace_parser_put(struct trace_parser *parser)
485 kfree(parser->buffer);
489 * trace_get_user - reads the user input string separated by space
490 * (matched by isspace(ch))
492 * For each string found the 'struct trace_parser' is updated,
493 * and the function returns.
495 * Returns number of bytes read.
497 * See kernel/trace/trace.h for 'struct trace_parser' details.
499 int trace_get_user(struct trace_parser *parser, const char __user *ubuf,
500 size_t cnt, loff_t *ppos)
507 trace_parser_clear(parser);
509 ret = get_user(ch, ubuf++);
517 * The parser is not finished with the last write,
518 * continue reading the user input without skipping spaces.
521 /* skip white space */
522 while (cnt && isspace(ch)) {
523 ret = get_user(ch, ubuf++);
530 /* only spaces were written */
540 /* read the non-space input */
541 while (cnt && !isspace(ch)) {
542 if (parser->idx < parser->size - 1)
543 parser->buffer[parser->idx++] = ch;
548 ret = get_user(ch, ubuf++);
555 /* We either got finished input or we have to wait for another call. */
557 parser->buffer[parser->idx] = 0;
558 parser->cont = false;
561 parser->buffer[parser->idx++] = ch;
571 ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt)
579 if (s->len <= s->readpos)
582 len = s->len - s->readpos;
585 ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt);
595 static ssize_t trace_seq_to_buffer(struct trace_seq *s, void *buf, size_t cnt)
599 if (s->len <= s->readpos)
602 len = s->len - s->readpos;
605 memcpy(buf, s->buffer + s->readpos, cnt);
612 * ftrace_max_lock is used to protect the swapping of buffers
613 * when taking a max snapshot. The buffers themselves are
614 * protected by per_cpu spinlocks. But the action of the swap
615 * needs its own lock.
617 * This is defined as a arch_spinlock_t in order to help
618 * with performance when lockdep debugging is enabled.
620 * It is also used in other places outside the update_max_tr
621 * so it needs to be defined outside of the
622 * CONFIG_TRACER_MAX_TRACE.
624 static arch_spinlock_t ftrace_max_lock =
625 (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED;
627 unsigned long __read_mostly tracing_thresh;
629 #ifdef CONFIG_TRACER_MAX_TRACE
630 unsigned long __read_mostly tracing_max_latency;
633 * Copy the new maximum trace into the separate maximum-trace
634 * structure. (this way the maximum trace is permanently saved,
635 * for later retrieval via /sys/kernel/debug/tracing/latency_trace)
638 __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
640 struct trace_array_cpu *data = per_cpu_ptr(tr->data, cpu);
641 struct trace_array_cpu *max_data;
644 max_tr.time_start = data->preempt_timestamp;
646 max_data = per_cpu_ptr(max_tr.data, cpu);
647 max_data->saved_latency = tracing_max_latency;
648 max_data->critical_start = data->critical_start;
649 max_data->critical_end = data->critical_end;
651 memcpy(max_data->comm, tsk->comm, TASK_COMM_LEN);
652 max_data->pid = tsk->pid;
653 max_data->uid = task_uid(tsk);
654 max_data->nice = tsk->static_prio - 20 - MAX_RT_PRIO;
655 max_data->policy = tsk->policy;
656 max_data->rt_priority = tsk->rt_priority;
658 /* record this tasks comm */
659 tracing_record_cmdline(tsk);
663 * update_max_tr - snapshot all trace buffers from global_trace to max_tr
665 * @tsk: the task with the latency
666 * @cpu: The cpu that initiated the trace.
668 * Flip the buffers between the @tr and the max_tr and record information
669 * about which task was the cause of this latency.
672 update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
674 struct ring_buffer *buf;
679 WARN_ON_ONCE(!irqs_disabled());
681 if (!tr->current_trace->allocated_snapshot) {
682 /* Only the nop tracer should hit this when disabling */
683 WARN_ON_ONCE(tr->current_trace != &nop_trace);
687 arch_spin_lock(&ftrace_max_lock);
690 tr->buffer = max_tr.buffer;
693 __update_max_tr(tr, tsk, cpu);
694 arch_spin_unlock(&ftrace_max_lock);
698 * update_max_tr_single - only copy one trace over, and reset the rest
700 * @tsk - task with the latency
701 * @cpu - the cpu of the buffer to copy.
703 * Flip the trace of a single CPU buffer between the @tr and the max_tr.
706 update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu)
713 WARN_ON_ONCE(!irqs_disabled());
714 if (WARN_ON_ONCE(!tr->current_trace->allocated_snapshot))
717 arch_spin_lock(&ftrace_max_lock);
719 ret = ring_buffer_swap_cpu(max_tr.buffer, tr->buffer, cpu);
723 * We failed to swap the buffer due to a commit taking
724 * place on this CPU. We fail to record, but we reset
725 * the max trace buffer (no one writes directly to it)
726 * and flag that it failed.
728 trace_array_printk(&max_tr, _THIS_IP_,
729 "Failed to swap buffers due to commit in progress\n");
732 WARN_ON_ONCE(ret && ret != -EAGAIN && ret != -EBUSY);
734 __update_max_tr(tr, tsk, cpu);
735 arch_spin_unlock(&ftrace_max_lock);
737 #endif /* CONFIG_TRACER_MAX_TRACE */
739 static void default_wait_pipe(struct trace_iterator *iter)
741 /* Iterators are static, they should be filled or empty */
742 if (trace_buffer_iter(iter, iter->cpu_file))
745 ring_buffer_wait(iter->tr->buffer, iter->cpu_file);
749 * register_tracer - register a tracer with the ftrace system.
750 * @type - the plugin for the tracer
752 * Register a new plugin tracer.
754 int register_tracer(struct tracer *type)
760 pr_info("Tracer must have a name\n");
764 if (strlen(type->name) >= MAX_TRACER_SIZE) {
765 pr_info("Tracer has a name longer than %d\n", MAX_TRACER_SIZE);
769 mutex_lock(&trace_types_lock);
771 tracing_selftest_running = true;
773 for (t = trace_types; t; t = t->next) {
774 if (strcmp(type->name, t->name) == 0) {
776 pr_info("Tracer %s already registered\n",
784 type->set_flag = &dummy_set_flag;
786 type->flags = &dummy_tracer_flags;
788 if (!type->flags->opts)
789 type->flags->opts = dummy_tracer_opt;
790 if (!type->wait_pipe)
791 type->wait_pipe = default_wait_pipe;
794 #ifdef CONFIG_FTRACE_STARTUP_TEST
795 if (type->selftest && !tracing_selftest_disabled) {
796 struct trace_array *tr = &global_trace;
797 struct tracer *saved_tracer = tr->current_trace;
800 * Run a selftest on this tracer.
801 * Here we reset the trace buffer, and set the current
802 * tracer to be this tracer. The tracer can then run some
803 * internal tracing to verify that everything is in order.
804 * If we fail, we do not register this tracer.
806 tracing_reset_online_cpus(tr);
808 tr->current_trace = type;
810 if (type->use_max_tr) {
811 /* If we expanded the buffers, make sure the max is expanded too */
812 if (ring_buffer_expanded)
813 ring_buffer_resize(max_tr.buffer, trace_buf_size,
814 RING_BUFFER_ALL_CPUS);
815 type->allocated_snapshot = true;
818 /* the test is responsible for initializing and enabling */
819 pr_info("Testing tracer %s: ", type->name);
820 ret = type->selftest(type, tr);
821 /* the test is responsible for resetting too */
822 tr->current_trace = saved_tracer;
824 printk(KERN_CONT "FAILED!\n");
825 /* Add the warning after printing 'FAILED' */
829 /* Only reset on passing, to avoid touching corrupted buffers */
830 tracing_reset_online_cpus(tr);
832 if (type->use_max_tr) {
833 type->allocated_snapshot = false;
835 /* Shrink the max buffer again */
836 if (ring_buffer_expanded)
837 ring_buffer_resize(max_tr.buffer, 1,
838 RING_BUFFER_ALL_CPUS);
841 printk(KERN_CONT "PASSED\n");
845 type->next = trace_types;
849 tracing_selftest_running = false;
850 mutex_unlock(&trace_types_lock);
852 if (ret || !default_bootup_tracer)
855 if (strncmp(default_bootup_tracer, type->name, MAX_TRACER_SIZE))
858 printk(KERN_INFO "Starting tracer '%s'\n", type->name);
859 /* Do we want this tracer to start on bootup? */
860 tracing_set_tracer(type->name);
861 default_bootup_tracer = NULL;
862 /* disable other selftests, since this will break it. */
863 tracing_selftest_disabled = 1;
864 #ifdef CONFIG_FTRACE_STARTUP_TEST
865 printk(KERN_INFO "Disabling FTRACE selftests due to running tracer '%s'\n",
873 void tracing_reset(struct trace_array *tr, int cpu)
875 struct ring_buffer *buffer = tr->buffer;
880 ring_buffer_record_disable(buffer);
882 /* Make sure all commits have finished */
884 ring_buffer_reset_cpu(buffer, cpu);
886 ring_buffer_record_enable(buffer);
889 void tracing_reset_online_cpus(struct trace_array *tr)
891 struct ring_buffer *buffer = tr->buffer;
897 ring_buffer_record_disable(buffer);
899 /* Make sure all commits have finished */
902 tr->time_start = ftrace_now(tr->cpu);
904 for_each_online_cpu(cpu)
905 ring_buffer_reset_cpu(buffer, cpu);
907 ring_buffer_record_enable(buffer);
910 void tracing_reset_current(int cpu)
912 tracing_reset(&global_trace, cpu);
915 void tracing_reset_current_online_cpus(void)
917 tracing_reset_online_cpus(&global_trace);
920 #define SAVED_CMDLINES 128
921 #define NO_CMDLINE_MAP UINT_MAX
922 static unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
923 static unsigned map_cmdline_to_pid[SAVED_CMDLINES];
924 static char saved_cmdlines[SAVED_CMDLINES][TASK_COMM_LEN];
925 static int cmdline_idx;
926 static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED;
928 /* temporary disable recording */
929 static atomic_t trace_record_cmdline_disabled __read_mostly;
931 static void trace_init_cmdlines(void)
933 memset(&map_pid_to_cmdline, NO_CMDLINE_MAP, sizeof(map_pid_to_cmdline));
934 memset(&map_cmdline_to_pid, NO_CMDLINE_MAP, sizeof(map_cmdline_to_pid));
938 int is_tracing_stopped(void)
940 return global_trace.stop_count;
944 * ftrace_off_permanent - disable all ftrace code permanently
946 * This should only be called when a serious anomally has
947 * been detected. This will turn off the function tracing,
948 * ring buffers, and other tracing utilites. It takes no
949 * locks and can be called from any context.
951 void ftrace_off_permanent(void)
953 tracing_disabled = 1;
955 tracing_off_permanent();
959 * tracing_start - quick start of the tracer
961 * If tracing is enabled but was stopped by tracing_stop,
962 * this will start the tracer back up.
964 void tracing_start(void)
966 struct ring_buffer *buffer;
969 if (tracing_disabled)
972 raw_spin_lock_irqsave(&global_trace.start_lock, flags);
973 if (--global_trace.stop_count) {
974 if (global_trace.stop_count < 0) {
975 /* Someone screwed up their debugging */
977 global_trace.stop_count = 0;
982 /* Prevent the buffers from switching */
983 arch_spin_lock(&ftrace_max_lock);
985 buffer = global_trace.buffer;
987 ring_buffer_record_enable(buffer);
989 buffer = max_tr.buffer;
991 ring_buffer_record_enable(buffer);
993 arch_spin_unlock(&ftrace_max_lock);
997 raw_spin_unlock_irqrestore(&global_trace.start_lock, flags);
1000 static void tracing_start_tr(struct trace_array *tr)
1002 struct ring_buffer *buffer;
1003 unsigned long flags;
1005 if (tracing_disabled)
1008 /* If global, we need to also start the max tracer */
1009 if (tr->flags & TRACE_ARRAY_FL_GLOBAL)
1010 return tracing_start();
1012 raw_spin_lock_irqsave(&tr->start_lock, flags);
1014 if (--tr->stop_count) {
1015 if (tr->stop_count < 0) {
1016 /* Someone screwed up their debugging */
1023 buffer = tr->buffer;
1025 ring_buffer_record_enable(buffer);
1028 raw_spin_unlock_irqrestore(&tr->start_lock, flags);
1032 * tracing_stop - quick stop of the tracer
1034 * Light weight way to stop tracing. Use in conjunction with
1037 void tracing_stop(void)
1039 struct ring_buffer *buffer;
1040 unsigned long flags;
1043 raw_spin_lock_irqsave(&global_trace.start_lock, flags);
1044 if (global_trace.stop_count++)
1047 /* Prevent the buffers from switching */
1048 arch_spin_lock(&ftrace_max_lock);
1050 buffer = global_trace.buffer;
1052 ring_buffer_record_disable(buffer);
1054 buffer = max_tr.buffer;
1056 ring_buffer_record_disable(buffer);
1058 arch_spin_unlock(&ftrace_max_lock);
1061 raw_spin_unlock_irqrestore(&global_trace.start_lock, flags);
1064 static void tracing_stop_tr(struct trace_array *tr)
1066 struct ring_buffer *buffer;
1067 unsigned long flags;
1069 /* If global, we need to also stop the max tracer */
1070 if (tr->flags & TRACE_ARRAY_FL_GLOBAL)
1071 return tracing_stop();
1073 raw_spin_lock_irqsave(&tr->start_lock, flags);
1074 if (tr->stop_count++)
1077 buffer = tr->buffer;
1079 ring_buffer_record_disable(buffer);
1082 raw_spin_unlock_irqrestore(&tr->start_lock, flags);
1085 void trace_stop_cmdline_recording(void);
1087 static void trace_save_cmdline(struct task_struct *tsk)
1091 if (!tsk->pid || unlikely(tsk->pid > PID_MAX_DEFAULT))
1095 * It's not the end of the world if we don't get
1096 * the lock, but we also don't want to spin
1097 * nor do we want to disable interrupts,
1098 * so if we miss here, then better luck next time.
1100 if (!arch_spin_trylock(&trace_cmdline_lock))
1103 idx = map_pid_to_cmdline[tsk->pid];
1104 if (idx == NO_CMDLINE_MAP) {
1105 idx = (cmdline_idx + 1) % SAVED_CMDLINES;
1108 * Check whether the cmdline buffer at idx has a pid
1109 * mapped. We are going to overwrite that entry so we
1110 * need to clear the map_pid_to_cmdline. Otherwise we
1111 * would read the new comm for the old pid.
1113 pid = map_cmdline_to_pid[idx];
1114 if (pid != NO_CMDLINE_MAP)
1115 map_pid_to_cmdline[pid] = NO_CMDLINE_MAP;
1117 map_cmdline_to_pid[idx] = tsk->pid;
1118 map_pid_to_cmdline[tsk->pid] = idx;
1123 memcpy(&saved_cmdlines[idx], tsk->comm, TASK_COMM_LEN);
1125 arch_spin_unlock(&trace_cmdline_lock);
1128 void trace_find_cmdline(int pid, char comm[])
1133 strcpy(comm, "<idle>");
1137 if (WARN_ON_ONCE(pid < 0)) {
1138 strcpy(comm, "<XXX>");
1142 if (pid > PID_MAX_DEFAULT) {
1143 strcpy(comm, "<...>");
1148 arch_spin_lock(&trace_cmdline_lock);
1149 map = map_pid_to_cmdline[pid];
1150 if (map != NO_CMDLINE_MAP)
1151 strcpy(comm, saved_cmdlines[map]);
1153 strcpy(comm, "<...>");
1155 arch_spin_unlock(&trace_cmdline_lock);
1159 void tracing_record_cmdline(struct task_struct *tsk)
1161 if (atomic_read(&trace_record_cmdline_disabled) || !tracing_is_on())
1164 if (!__this_cpu_read(trace_cmdline_save))
1167 __this_cpu_write(trace_cmdline_save, false);
1169 trace_save_cmdline(tsk);
1173 tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags,
1176 struct task_struct *tsk = current;
1178 entry->preempt_count = pc & 0xff;
1179 entry->pid = (tsk) ? tsk->pid : 0;
1181 #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
1182 (irqs_disabled_flags(flags) ? TRACE_FLAG_IRQS_OFF : 0) |
1184 TRACE_FLAG_IRQS_NOSUPPORT |
1186 ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) |
1187 ((pc & SOFTIRQ_MASK) ? TRACE_FLAG_SOFTIRQ : 0) |
1188 (need_resched() ? TRACE_FLAG_NEED_RESCHED : 0);
1190 EXPORT_SYMBOL_GPL(tracing_generic_entry_update);
1192 struct ring_buffer_event *
1193 trace_buffer_lock_reserve(struct ring_buffer *buffer,
1196 unsigned long flags, int pc)
1198 struct ring_buffer_event *event;
1200 event = ring_buffer_lock_reserve(buffer, len);
1201 if (event != NULL) {
1202 struct trace_entry *ent = ring_buffer_event_data(event);
1204 tracing_generic_entry_update(ent, flags, pc);
1212 __buffer_unlock_commit(struct ring_buffer *buffer, struct ring_buffer_event *event)
1214 __this_cpu_write(trace_cmdline_save, true);
1215 ring_buffer_unlock_commit(buffer, event);
1219 __trace_buffer_unlock_commit(struct ring_buffer *buffer,
1220 struct ring_buffer_event *event,
1221 unsigned long flags, int pc)
1223 __buffer_unlock_commit(buffer, event);
1225 ftrace_trace_stack(buffer, flags, 6, pc);
1226 ftrace_trace_userstack(buffer, flags, pc);
1229 void trace_buffer_unlock_commit(struct ring_buffer *buffer,
1230 struct ring_buffer_event *event,
1231 unsigned long flags, int pc)
1233 __trace_buffer_unlock_commit(buffer, event, flags, pc);
1235 EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit);
1237 struct ring_buffer_event *
1238 trace_event_buffer_lock_reserve(struct ring_buffer **current_rb,
1239 struct ftrace_event_file *ftrace_file,
1240 int type, unsigned long len,
1241 unsigned long flags, int pc)
1243 *current_rb = ftrace_file->tr->buffer;
1244 return trace_buffer_lock_reserve(*current_rb,
1245 type, len, flags, pc);
1247 EXPORT_SYMBOL_GPL(trace_event_buffer_lock_reserve);
1249 struct ring_buffer_event *
1250 trace_current_buffer_lock_reserve(struct ring_buffer **current_rb,
1251 int type, unsigned long len,
1252 unsigned long flags, int pc)
1254 *current_rb = global_trace.buffer;
1255 return trace_buffer_lock_reserve(*current_rb,
1256 type, len, flags, pc);
1258 EXPORT_SYMBOL_GPL(trace_current_buffer_lock_reserve);
1260 void trace_current_buffer_unlock_commit(struct ring_buffer *buffer,
1261 struct ring_buffer_event *event,
1262 unsigned long flags, int pc)
1264 __trace_buffer_unlock_commit(buffer, event, flags, pc);
1266 EXPORT_SYMBOL_GPL(trace_current_buffer_unlock_commit);
1268 void trace_buffer_unlock_commit_regs(struct ring_buffer *buffer,
1269 struct ring_buffer_event *event,
1270 unsigned long flags, int pc,
1271 struct pt_regs *regs)
1273 __buffer_unlock_commit(buffer, event);
1275 ftrace_trace_stack_regs(buffer, flags, 0, pc, regs);
1276 ftrace_trace_userstack(buffer, flags, pc);
1278 EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit_regs);
1280 void trace_current_buffer_discard_commit(struct ring_buffer *buffer,
1281 struct ring_buffer_event *event)
1283 ring_buffer_discard_commit(buffer, event);
1285 EXPORT_SYMBOL_GPL(trace_current_buffer_discard_commit);
1288 trace_function(struct trace_array *tr,
1289 unsigned long ip, unsigned long parent_ip, unsigned long flags,
1292 struct ftrace_event_call *call = &event_function;
1293 struct ring_buffer *buffer = tr->buffer;
1294 struct ring_buffer_event *event;
1295 struct ftrace_entry *entry;
1297 /* If we are reading the ring buffer, don't trace */
1298 if (unlikely(__this_cpu_read(ftrace_cpu_disabled)))
1301 event = trace_buffer_lock_reserve(buffer, TRACE_FN, sizeof(*entry),
1305 entry = ring_buffer_event_data(event);
1307 entry->parent_ip = parent_ip;
1309 if (!filter_check_discard(call, entry, buffer, event))
1310 __buffer_unlock_commit(buffer, event);
1314 ftrace(struct trace_array *tr, struct trace_array_cpu *data,
1315 unsigned long ip, unsigned long parent_ip, unsigned long flags,
1318 if (likely(!atomic_read(&data->disabled)))
1319 trace_function(tr, ip, parent_ip, flags, pc);
1322 #ifdef CONFIG_STACKTRACE
1324 #define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long))
1325 struct ftrace_stack {
1326 unsigned long calls[FTRACE_STACK_MAX_ENTRIES];
1329 static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);
1330 static DEFINE_PER_CPU(int, ftrace_stack_reserve);
1332 static void __ftrace_trace_stack(struct ring_buffer *buffer,
1333 unsigned long flags,
1334 int skip, int pc, struct pt_regs *regs)
1336 struct ftrace_event_call *call = &event_kernel_stack;
1337 struct ring_buffer_event *event;
1338 struct stack_entry *entry;
1339 struct stack_trace trace;
1341 int size = FTRACE_STACK_ENTRIES;
1343 trace.nr_entries = 0;
1347 * Since events can happen in NMIs there's no safe way to
1348 * use the per cpu ftrace_stacks. We reserve it and if an interrupt
1349 * or NMI comes in, it will just have to use the default
1350 * FTRACE_STACK_SIZE.
1352 preempt_disable_notrace();
1354 use_stack = __this_cpu_inc_return(ftrace_stack_reserve);
1356 * We don't need any atomic variables, just a barrier.
1357 * If an interrupt comes in, we don't care, because it would
1358 * have exited and put the counter back to what we want.
1359 * We just need a barrier to keep gcc from moving things
1363 if (use_stack == 1) {
1364 trace.entries = &__get_cpu_var(ftrace_stack).calls[0];
1365 trace.max_entries = FTRACE_STACK_MAX_ENTRIES;
1368 save_stack_trace_regs(regs, &trace);
1370 save_stack_trace(&trace);
1372 if (trace.nr_entries > size)
1373 size = trace.nr_entries;
1375 /* From now on, use_stack is a boolean */
1378 size *= sizeof(unsigned long);
1380 event = trace_buffer_lock_reserve(buffer, TRACE_STACK,
1381 sizeof(*entry) + size, flags, pc);
1384 entry = ring_buffer_event_data(event);
1386 memset(&entry->caller, 0, size);
1389 memcpy(&entry->caller, trace.entries,
1390 trace.nr_entries * sizeof(unsigned long));
1392 trace.max_entries = FTRACE_STACK_ENTRIES;
1393 trace.entries = entry->caller;
1395 save_stack_trace_regs(regs, &trace);
1397 save_stack_trace(&trace);
1400 entry->size = trace.nr_entries;
1402 if (!filter_check_discard(call, entry, buffer, event))
1403 __buffer_unlock_commit(buffer, event);
1406 /* Again, don't let gcc optimize things here */
1408 __this_cpu_dec(ftrace_stack_reserve);
1409 preempt_enable_notrace();
1413 void ftrace_trace_stack_regs(struct ring_buffer *buffer, unsigned long flags,
1414 int skip, int pc, struct pt_regs *regs)
1416 if (!(trace_flags & TRACE_ITER_STACKTRACE))
1419 __ftrace_trace_stack(buffer, flags, skip, pc, regs);
1422 void ftrace_trace_stack(struct ring_buffer *buffer, unsigned long flags,
1425 if (!(trace_flags & TRACE_ITER_STACKTRACE))
1428 __ftrace_trace_stack(buffer, flags, skip, pc, NULL);
1431 void __trace_stack(struct trace_array *tr, unsigned long flags, int skip,
1434 __ftrace_trace_stack(tr->buffer, flags, skip, pc, NULL);
1438 * trace_dump_stack - record a stack back trace in the trace buffer
1440 void trace_dump_stack(void)
1442 unsigned long flags;
1444 if (tracing_disabled || tracing_selftest_running)
1447 local_save_flags(flags);
1449 /* skipping 3 traces, seems to get us at the caller of this function */
1450 __ftrace_trace_stack(global_trace.buffer, flags, 3, preempt_count(), NULL);
1453 static DEFINE_PER_CPU(int, user_stack_count);
1456 ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags, int pc)
1458 struct ftrace_event_call *call = &event_user_stack;
1459 struct ring_buffer_event *event;
1460 struct userstack_entry *entry;
1461 struct stack_trace trace;
1463 if (!(trace_flags & TRACE_ITER_USERSTACKTRACE))
1467 * NMIs can not handle page faults, even with fix ups.
1468 * The save user stack can (and often does) fault.
1470 if (unlikely(in_nmi()))
1474 * prevent recursion, since the user stack tracing may
1475 * trigger other kernel events.
1478 if (__this_cpu_read(user_stack_count))
1481 __this_cpu_inc(user_stack_count);
1483 event = trace_buffer_lock_reserve(buffer, TRACE_USER_STACK,
1484 sizeof(*entry), flags, pc);
1486 goto out_drop_count;
1487 entry = ring_buffer_event_data(event);
1489 entry->tgid = current->tgid;
1490 memset(&entry->caller, 0, sizeof(entry->caller));
1492 trace.nr_entries = 0;
1493 trace.max_entries = FTRACE_STACK_ENTRIES;
1495 trace.entries = entry->caller;
1497 save_stack_trace_user(&trace);
1498 if (!filter_check_discard(call, entry, buffer, event))
1499 __buffer_unlock_commit(buffer, event);
1502 __this_cpu_dec(user_stack_count);
1508 static void __trace_userstack(struct trace_array *tr, unsigned long flags)
1510 ftrace_trace_userstack(tr, flags, preempt_count());
1514 #endif /* CONFIG_STACKTRACE */
1516 /* created for use with alloc_percpu */
1517 struct trace_buffer_struct {
1518 char buffer[TRACE_BUF_SIZE];
1521 static struct trace_buffer_struct *trace_percpu_buffer;
1522 static struct trace_buffer_struct *trace_percpu_sirq_buffer;
1523 static struct trace_buffer_struct *trace_percpu_irq_buffer;
1524 static struct trace_buffer_struct *trace_percpu_nmi_buffer;
1527 * The buffer used is dependent on the context. There is a per cpu
1528 * buffer for normal context, softirq contex, hard irq context and
1529 * for NMI context. Thise allows for lockless recording.
1531 * Note, if the buffers failed to be allocated, then this returns NULL
1533 static char *get_trace_buf(void)
1535 struct trace_buffer_struct *percpu_buffer;
1538 * If we have allocated per cpu buffers, then we do not
1539 * need to do any locking.
1542 percpu_buffer = trace_percpu_nmi_buffer;
1544 percpu_buffer = trace_percpu_irq_buffer;
1545 else if (in_softirq())
1546 percpu_buffer = trace_percpu_sirq_buffer;
1548 percpu_buffer = trace_percpu_buffer;
1553 return this_cpu_ptr(&percpu_buffer->buffer[0]);
1556 static int alloc_percpu_trace_buffer(void)
1558 struct trace_buffer_struct *buffers;
1559 struct trace_buffer_struct *sirq_buffers;
1560 struct trace_buffer_struct *irq_buffers;
1561 struct trace_buffer_struct *nmi_buffers;
1563 buffers = alloc_percpu(struct trace_buffer_struct);
1567 sirq_buffers = alloc_percpu(struct trace_buffer_struct);
1571 irq_buffers = alloc_percpu(struct trace_buffer_struct);
1575 nmi_buffers = alloc_percpu(struct trace_buffer_struct);
1579 trace_percpu_buffer = buffers;
1580 trace_percpu_sirq_buffer = sirq_buffers;
1581 trace_percpu_irq_buffer = irq_buffers;
1582 trace_percpu_nmi_buffer = nmi_buffers;
1587 free_percpu(irq_buffers);
1589 free_percpu(sirq_buffers);
1591 free_percpu(buffers);
1593 WARN(1, "Could not allocate percpu trace_printk buffer");
1597 static int buffers_allocated;
1599 void trace_printk_init_buffers(void)
1601 if (buffers_allocated)
1604 if (alloc_percpu_trace_buffer())
1607 pr_info("ftrace: Allocated trace_printk buffers\n");
1609 /* Expand the buffers to set size */
1610 tracing_update_buffers();
1612 buffers_allocated = 1;
1615 * trace_printk_init_buffers() can be called by modules.
1616 * If that happens, then we need to start cmdline recording
1617 * directly here. If the global_trace.buffer is already
1618 * allocated here, then this was called by module code.
1620 if (global_trace.buffer)
1621 tracing_start_cmdline_record();
1624 void trace_printk_start_comm(void)
1626 /* Start tracing comms if trace printk is set */
1627 if (!buffers_allocated)
1629 tracing_start_cmdline_record();
1632 static void trace_printk_start_stop_comm(int enabled)
1634 if (!buffers_allocated)
1638 tracing_start_cmdline_record();
1640 tracing_stop_cmdline_record();
1644 * trace_vbprintk - write binary msg to tracing buffer
1647 int trace_vbprintk(unsigned long ip, const char *fmt, va_list args)
1649 struct ftrace_event_call *call = &event_bprint;
1650 struct ring_buffer_event *event;
1651 struct ring_buffer *buffer;
1652 struct trace_array *tr = &global_trace;
1653 struct bprint_entry *entry;
1654 unsigned long flags;
1656 int len = 0, size, pc;
1658 if (unlikely(tracing_selftest_running || tracing_disabled))
1661 /* Don't pollute graph traces with trace_vprintk internals */
1662 pause_graph_tracing();
1664 pc = preempt_count();
1665 preempt_disable_notrace();
1667 tbuffer = get_trace_buf();
1673 len = vbin_printf((u32 *)tbuffer, TRACE_BUF_SIZE/sizeof(int), fmt, args);
1675 if (len > TRACE_BUF_SIZE/sizeof(int) || len < 0)
1678 local_save_flags(flags);
1679 size = sizeof(*entry) + sizeof(u32) * len;
1680 buffer = tr->buffer;
1681 event = trace_buffer_lock_reserve(buffer, TRACE_BPRINT, size,
1685 entry = ring_buffer_event_data(event);
1689 memcpy(entry->buf, tbuffer, sizeof(u32) * len);
1690 if (!filter_check_discard(call, entry, buffer, event)) {
1691 __buffer_unlock_commit(buffer, event);
1692 ftrace_trace_stack(buffer, flags, 6, pc);
1696 preempt_enable_notrace();
1697 unpause_graph_tracing();
1701 EXPORT_SYMBOL_GPL(trace_vbprintk);
1703 int trace_array_printk(struct trace_array *tr,
1704 unsigned long ip, const char *fmt, ...)
1709 if (!(trace_flags & TRACE_ITER_PRINTK))
1713 ret = trace_array_vprintk(tr, ip, fmt, ap);
1718 int trace_array_vprintk(struct trace_array *tr,
1719 unsigned long ip, const char *fmt, va_list args)
1721 struct ftrace_event_call *call = &event_print;
1722 struct ring_buffer_event *event;
1723 struct ring_buffer *buffer;
1724 int len = 0, size, pc;
1725 struct print_entry *entry;
1726 unsigned long flags;
1729 if (tracing_disabled || tracing_selftest_running)
1732 /* Don't pollute graph traces with trace_vprintk internals */
1733 pause_graph_tracing();
1735 pc = preempt_count();
1736 preempt_disable_notrace();
1739 tbuffer = get_trace_buf();
1745 len = vsnprintf(tbuffer, TRACE_BUF_SIZE, fmt, args);
1746 if (len > TRACE_BUF_SIZE)
1749 local_save_flags(flags);
1750 size = sizeof(*entry) + len + 1;
1751 buffer = tr->buffer;
1752 event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, size,
1756 entry = ring_buffer_event_data(event);
1759 memcpy(&entry->buf, tbuffer, len);
1760 entry->buf[len] = '\0';
1761 if (!filter_check_discard(call, entry, buffer, event)) {
1762 __buffer_unlock_commit(buffer, event);
1763 ftrace_trace_stack(buffer, flags, 6, pc);
1766 preempt_enable_notrace();
1767 unpause_graph_tracing();
1772 int trace_vprintk(unsigned long ip, const char *fmt, va_list args)
1774 return trace_array_vprintk(&global_trace, ip, fmt, args);
1776 EXPORT_SYMBOL_GPL(trace_vprintk);
1778 static void trace_iterator_increment(struct trace_iterator *iter)
1780 struct ring_buffer_iter *buf_iter = trace_buffer_iter(iter, iter->cpu);
1784 ring_buffer_read(buf_iter, NULL);
1787 static struct trace_entry *
1788 peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts,
1789 unsigned long *lost_events)
1791 struct ring_buffer_event *event;
1792 struct ring_buffer_iter *buf_iter = trace_buffer_iter(iter, cpu);
1795 event = ring_buffer_iter_peek(buf_iter, ts);
1797 event = ring_buffer_peek(iter->tr->buffer, cpu, ts,
1801 iter->ent_size = ring_buffer_event_length(event);
1802 return ring_buffer_event_data(event);
1808 static struct trace_entry *
1809 __find_next_entry(struct trace_iterator *iter, int *ent_cpu,
1810 unsigned long *missing_events, u64 *ent_ts)
1812 struct ring_buffer *buffer = iter->tr->buffer;
1813 struct trace_entry *ent, *next = NULL;
1814 unsigned long lost_events = 0, next_lost = 0;
1815 int cpu_file = iter->cpu_file;
1816 u64 next_ts = 0, ts;
1822 * If we are in a per_cpu trace file, don't bother by iterating over
1823 * all cpu and peek directly.
1825 if (cpu_file > RING_BUFFER_ALL_CPUS) {
1826 if (ring_buffer_empty_cpu(buffer, cpu_file))
1828 ent = peek_next_entry(iter, cpu_file, ent_ts, missing_events);
1830 *ent_cpu = cpu_file;
1835 for_each_tracing_cpu(cpu) {
1837 if (ring_buffer_empty_cpu(buffer, cpu))
1840 ent = peek_next_entry(iter, cpu, &ts, &lost_events);
1843 * Pick the entry with the smallest timestamp:
1845 if (ent && (!next || ts < next_ts)) {
1849 next_lost = lost_events;
1850 next_size = iter->ent_size;
1854 iter->ent_size = next_size;
1857 *ent_cpu = next_cpu;
1863 *missing_events = next_lost;
1868 /* Find the next real entry, without updating the iterator itself */
1869 struct trace_entry *trace_find_next_entry(struct trace_iterator *iter,
1870 int *ent_cpu, u64 *ent_ts)
1872 return __find_next_entry(iter, ent_cpu, NULL, ent_ts);
1875 /* Find the next real entry, and increment the iterator to the next entry */
1876 void *trace_find_next_entry_inc(struct trace_iterator *iter)
1878 iter->ent = __find_next_entry(iter, &iter->cpu,
1879 &iter->lost_events, &iter->ts);
1882 trace_iterator_increment(iter);
1884 return iter->ent ? iter : NULL;
1887 static void trace_consume(struct trace_iterator *iter)
1889 ring_buffer_consume(iter->tr->buffer, iter->cpu, &iter->ts,
1890 &iter->lost_events);
1893 static void *s_next(struct seq_file *m, void *v, loff_t *pos)
1895 struct trace_iterator *iter = m->private;
1899 WARN_ON_ONCE(iter->leftover);
1903 /* can't go backwards */
1908 ent = trace_find_next_entry_inc(iter);
1912 while (ent && iter->idx < i)
1913 ent = trace_find_next_entry_inc(iter);
1920 void tracing_iter_reset(struct trace_iterator *iter, int cpu)
1922 struct trace_array *tr = iter->tr;
1923 struct ring_buffer_event *event;
1924 struct ring_buffer_iter *buf_iter;
1925 unsigned long entries = 0;
1928 per_cpu_ptr(tr->data, cpu)->skipped_entries = 0;
1930 buf_iter = trace_buffer_iter(iter, cpu);
1934 ring_buffer_iter_reset(buf_iter);
1937 * We could have the case with the max latency tracers
1938 * that a reset never took place on a cpu. This is evident
1939 * by the timestamp being before the start of the buffer.
1941 while ((event = ring_buffer_iter_peek(buf_iter, &ts))) {
1942 if (ts >= iter->tr->time_start)
1945 ring_buffer_read(buf_iter, NULL);
1948 per_cpu_ptr(tr->data, cpu)->skipped_entries = entries;
1952 * The current tracer is copied to avoid a global locking
1955 static void *s_start(struct seq_file *m, loff_t *pos)
1957 struct trace_iterator *iter = m->private;
1958 struct trace_array *tr = iter->tr;
1959 int cpu_file = iter->cpu_file;
1965 * copy the tracer to avoid using a global lock all around.
1966 * iter->trace is a copy of current_trace, the pointer to the
1967 * name may be used instead of a strcmp(), as iter->trace->name
1968 * will point to the same string as current_trace->name.
1970 mutex_lock(&trace_types_lock);
1971 if (unlikely(tr->current_trace && iter->trace->name != tr->current_trace->name))
1972 *iter->trace = *tr->current_trace;
1973 mutex_unlock(&trace_types_lock);
1975 if (iter->snapshot && iter->trace->use_max_tr)
1976 return ERR_PTR(-EBUSY);
1978 if (!iter->snapshot)
1979 atomic_inc(&trace_record_cmdline_disabled);
1981 if (*pos != iter->pos) {
1986 if (cpu_file == RING_BUFFER_ALL_CPUS) {
1987 for_each_tracing_cpu(cpu)
1988 tracing_iter_reset(iter, cpu);
1990 tracing_iter_reset(iter, cpu_file);
1993 for (p = iter; p && l < *pos; p = s_next(m, p, &l))
1998 * If we overflowed the seq_file before, then we want
1999 * to just reuse the trace_seq buffer again.
2005 p = s_next(m, p, &l);
2009 trace_event_read_lock();
2010 trace_access_lock(cpu_file);
2014 static void s_stop(struct seq_file *m, void *p)
2016 struct trace_iterator *iter = m->private;
2018 if (iter->snapshot && iter->trace->use_max_tr)
2021 if (!iter->snapshot)
2022 atomic_dec(&trace_record_cmdline_disabled);
2023 trace_access_unlock(iter->cpu_file);
2024 trace_event_read_unlock();
2028 get_total_entries(struct trace_array *tr, unsigned long *total, unsigned long *entries)
2030 unsigned long count;
2036 for_each_tracing_cpu(cpu) {
2037 count = ring_buffer_entries_cpu(tr->buffer, cpu);
2039 * If this buffer has skipped entries, then we hold all
2040 * entries for the trace and we need to ignore the
2041 * ones before the time stamp.
2043 if (per_cpu_ptr(tr->data, cpu)->skipped_entries) {
2044 count -= per_cpu_ptr(tr->data, cpu)->skipped_entries;
2045 /* total is the same as the entries */
2049 ring_buffer_overrun_cpu(tr->buffer, cpu);
2054 static void print_lat_help_header(struct seq_file *m)
2056 seq_puts(m, "# _------=> CPU# \n");
2057 seq_puts(m, "# / _-----=> irqs-off \n");
2058 seq_puts(m, "# | / _----=> need-resched \n");
2059 seq_puts(m, "# || / _---=> hardirq/softirq \n");
2060 seq_puts(m, "# ||| / _--=> preempt-depth \n");
2061 seq_puts(m, "# |||| / delay \n");
2062 seq_puts(m, "# cmd pid ||||| time | caller \n");
2063 seq_puts(m, "# \\ / ||||| \\ | / \n");
2066 static void print_event_info(struct trace_array *tr, struct seq_file *m)
2068 unsigned long total;
2069 unsigned long entries;
2071 get_total_entries(tr, &total, &entries);
2072 seq_printf(m, "# entries-in-buffer/entries-written: %lu/%lu #P:%d\n",
2073 entries, total, num_online_cpus());
2077 static void print_func_help_header(struct trace_array *tr, struct seq_file *m)
2079 print_event_info(tr, m);
2080 seq_puts(m, "# TASK-PID CPU# TIMESTAMP FUNCTION\n");
2081 seq_puts(m, "# | | | | |\n");
2084 static void print_func_help_header_irq(struct trace_array *tr, struct seq_file *m)
2086 print_event_info(tr, m);
2087 seq_puts(m, "# _-----=> irqs-off\n");
2088 seq_puts(m, "# / _----=> need-resched\n");
2089 seq_puts(m, "# | / _---=> hardirq/softirq\n");
2090 seq_puts(m, "# || / _--=> preempt-depth\n");
2091 seq_puts(m, "# ||| / delay\n");
2092 seq_puts(m, "# TASK-PID CPU# |||| TIMESTAMP FUNCTION\n");
2093 seq_puts(m, "# | | | |||| | |\n");
2097 print_trace_header(struct seq_file *m, struct trace_iterator *iter)
2099 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
2100 struct trace_array *tr = iter->tr;
2101 struct trace_array_cpu *data = per_cpu_ptr(tr->data, tr->cpu);
2102 struct tracer *type = iter->trace;
2103 unsigned long entries;
2104 unsigned long total;
2105 const char *name = "preemption";
2109 get_total_entries(tr, &total, &entries);
2111 seq_printf(m, "# %s latency trace v1.1.5 on %s\n",
2113 seq_puts(m, "# -----------------------------------"
2114 "---------------------------------\n");
2115 seq_printf(m, "# latency: %lu us, #%lu/%lu, CPU#%d |"
2116 " (M:%s VP:%d, KP:%d, SP:%d HP:%d",
2117 nsecs_to_usecs(data->saved_latency),
2121 #if defined(CONFIG_PREEMPT_NONE)
2123 #elif defined(CONFIG_PREEMPT_VOLUNTARY)
2125 #elif defined(CONFIG_PREEMPT)
2130 /* These are reserved for later use */
2133 seq_printf(m, " #P:%d)\n", num_online_cpus());
2137 seq_puts(m, "# -----------------\n");
2138 seq_printf(m, "# | task: %.16s-%d "
2139 "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n",
2140 data->comm, data->pid,
2141 from_kuid_munged(seq_user_ns(m), data->uid), data->nice,
2142 data->policy, data->rt_priority);
2143 seq_puts(m, "# -----------------\n");
2145 if (data->critical_start) {
2146 seq_puts(m, "# => started at: ");
2147 seq_print_ip_sym(&iter->seq, data->critical_start, sym_flags);
2148 trace_print_seq(m, &iter->seq);
2149 seq_puts(m, "\n# => ended at: ");
2150 seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags);
2151 trace_print_seq(m, &iter->seq);
2152 seq_puts(m, "\n#\n");
2158 static void test_cpu_buff_start(struct trace_iterator *iter)
2160 struct trace_seq *s = &iter->seq;
2162 if (!(trace_flags & TRACE_ITER_ANNOTATE))
2165 if (!(iter->iter_flags & TRACE_FILE_ANNOTATE))
2168 if (cpumask_test_cpu(iter->cpu, iter->started))
2171 if (per_cpu_ptr(iter->tr->data, iter->cpu)->skipped_entries)
2174 cpumask_set_cpu(iter->cpu, iter->started);
2176 /* Don't print started cpu buffer for the first entry of the trace */
2178 trace_seq_printf(s, "##### CPU %u buffer started ####\n",
2182 static enum print_line_t print_trace_fmt(struct trace_iterator *iter)
2184 struct trace_seq *s = &iter->seq;
2185 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
2186 struct trace_entry *entry;
2187 struct trace_event *event;
2191 test_cpu_buff_start(iter);
2193 event = ftrace_find_event(entry->type);
2195 if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
2196 if (iter->iter_flags & TRACE_FILE_LAT_FMT) {
2197 if (!trace_print_lat_context(iter))
2200 if (!trace_print_context(iter))
2206 return event->funcs->trace(iter, sym_flags, event);
2208 if (!trace_seq_printf(s, "Unknown type %d\n", entry->type))
2211 return TRACE_TYPE_HANDLED;
2213 return TRACE_TYPE_PARTIAL_LINE;
2216 static enum print_line_t print_raw_fmt(struct trace_iterator *iter)
2218 struct trace_seq *s = &iter->seq;
2219 struct trace_entry *entry;
2220 struct trace_event *event;
2224 if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
2225 if (!trace_seq_printf(s, "%d %d %llu ",
2226 entry->pid, iter->cpu, iter->ts))
2230 event = ftrace_find_event(entry->type);
2232 return event->funcs->raw(iter, 0, event);
2234 if (!trace_seq_printf(s, "%d ?\n", entry->type))
2237 return TRACE_TYPE_HANDLED;
2239 return TRACE_TYPE_PARTIAL_LINE;
2242 static enum print_line_t print_hex_fmt(struct trace_iterator *iter)
2244 struct trace_seq *s = &iter->seq;
2245 unsigned char newline = '\n';
2246 struct trace_entry *entry;
2247 struct trace_event *event;
2251 if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
2252 SEQ_PUT_HEX_FIELD_RET(s, entry->pid);
2253 SEQ_PUT_HEX_FIELD_RET(s, iter->cpu);
2254 SEQ_PUT_HEX_FIELD_RET(s, iter->ts);
2257 event = ftrace_find_event(entry->type);
2259 enum print_line_t ret = event->funcs->hex(iter, 0, event);
2260 if (ret != TRACE_TYPE_HANDLED)
2264 SEQ_PUT_FIELD_RET(s, newline);
2266 return TRACE_TYPE_HANDLED;
2269 static enum print_line_t print_bin_fmt(struct trace_iterator *iter)
2271 struct trace_seq *s = &iter->seq;
2272 struct trace_entry *entry;
2273 struct trace_event *event;
2277 if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
2278 SEQ_PUT_FIELD_RET(s, entry->pid);
2279 SEQ_PUT_FIELD_RET(s, iter->cpu);
2280 SEQ_PUT_FIELD_RET(s, iter->ts);
2283 event = ftrace_find_event(entry->type);
2284 return event ? event->funcs->binary(iter, 0, event) :
2288 int trace_empty(struct trace_iterator *iter)
2290 struct ring_buffer_iter *buf_iter;
2293 /* If we are looking at one CPU buffer, only check that one */
2294 if (iter->cpu_file != RING_BUFFER_ALL_CPUS) {
2295 cpu = iter->cpu_file;
2296 buf_iter = trace_buffer_iter(iter, cpu);
2298 if (!ring_buffer_iter_empty(buf_iter))
2301 if (!ring_buffer_empty_cpu(iter->tr->buffer, cpu))
2307 for_each_tracing_cpu(cpu) {
2308 buf_iter = trace_buffer_iter(iter, cpu);
2310 if (!ring_buffer_iter_empty(buf_iter))
2313 if (!ring_buffer_empty_cpu(iter->tr->buffer, cpu))
2321 /* Called with trace_event_read_lock() held. */
2322 enum print_line_t print_trace_line(struct trace_iterator *iter)
2324 enum print_line_t ret;
2326 if (iter->lost_events &&
2327 !trace_seq_printf(&iter->seq, "CPU:%d [LOST %lu EVENTS]\n",
2328 iter->cpu, iter->lost_events))
2329 return TRACE_TYPE_PARTIAL_LINE;
2331 if (iter->trace && iter->trace->print_line) {
2332 ret = iter->trace->print_line(iter);
2333 if (ret != TRACE_TYPE_UNHANDLED)
2337 if (iter->ent->type == TRACE_BPRINT &&
2338 trace_flags & TRACE_ITER_PRINTK &&
2339 trace_flags & TRACE_ITER_PRINTK_MSGONLY)
2340 return trace_print_bprintk_msg_only(iter);
2342 if (iter->ent->type == TRACE_PRINT &&
2343 trace_flags & TRACE_ITER_PRINTK &&
2344 trace_flags & TRACE_ITER_PRINTK_MSGONLY)
2345 return trace_print_printk_msg_only(iter);
2347 if (trace_flags & TRACE_ITER_BIN)
2348 return print_bin_fmt(iter);
2350 if (trace_flags & TRACE_ITER_HEX)
2351 return print_hex_fmt(iter);
2353 if (trace_flags & TRACE_ITER_RAW)
2354 return print_raw_fmt(iter);
2356 return print_trace_fmt(iter);
2359 void trace_latency_header(struct seq_file *m)
2361 struct trace_iterator *iter = m->private;
2363 /* print nothing if the buffers are empty */
2364 if (trace_empty(iter))
2367 if (iter->iter_flags & TRACE_FILE_LAT_FMT)
2368 print_trace_header(m, iter);
2370 if (!(trace_flags & TRACE_ITER_VERBOSE))
2371 print_lat_help_header(m);
2374 void trace_default_header(struct seq_file *m)
2376 struct trace_iterator *iter = m->private;
2378 if (!(trace_flags & TRACE_ITER_CONTEXT_INFO))
2381 if (iter->iter_flags & TRACE_FILE_LAT_FMT) {
2382 /* print nothing if the buffers are empty */
2383 if (trace_empty(iter))
2385 print_trace_header(m, iter);
2386 if (!(trace_flags & TRACE_ITER_VERBOSE))
2387 print_lat_help_header(m);
2389 if (!(trace_flags & TRACE_ITER_VERBOSE)) {
2390 if (trace_flags & TRACE_ITER_IRQ_INFO)
2391 print_func_help_header_irq(iter->tr, m);
2393 print_func_help_header(iter->tr, m);
2398 static void test_ftrace_alive(struct seq_file *m)
2400 if (!ftrace_is_dead())
2402 seq_printf(m, "# WARNING: FUNCTION TRACING IS CORRUPTED\n");
2403 seq_printf(m, "# MAY BE MISSING FUNCTION EVENTS\n");
2406 #ifdef CONFIG_TRACER_MAX_TRACE
2407 static void print_snapshot_help(struct seq_file *m, struct trace_iterator *iter)
2409 if (iter->trace->allocated_snapshot)
2410 seq_printf(m, "#\n# * Snapshot is allocated *\n#\n");
2412 seq_printf(m, "#\n# * Snapshot is freed *\n#\n");
2414 seq_printf(m, "# Snapshot commands:\n");
2415 seq_printf(m, "# echo 0 > snapshot : Clears and frees snapshot buffer\n");
2416 seq_printf(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n");
2417 seq_printf(m, "# Takes a snapshot of the main buffer.\n");
2418 seq_printf(m, "# echo 2 > snapshot : Clears snapshot buffer (but does not allocate)\n");
2419 seq_printf(m, "# (Doesn't have to be '2' works with any number that\n");
2420 seq_printf(m, "# is not a '0' or '1')\n");
2423 /* Should never be called */
2424 static inline void print_snapshot_help(struct seq_file *m, struct trace_iterator *iter) { }
2427 static int s_show(struct seq_file *m, void *v)
2429 struct trace_iterator *iter = v;
2432 if (iter->ent == NULL) {
2434 seq_printf(m, "# tracer: %s\n", iter->trace->name);
2436 test_ftrace_alive(m);
2438 if (iter->snapshot && trace_empty(iter))
2439 print_snapshot_help(m, iter);
2440 else if (iter->trace && iter->trace->print_header)
2441 iter->trace->print_header(m);
2443 trace_default_header(m);
2445 } else if (iter->leftover) {
2447 * If we filled the seq_file buffer earlier, we
2448 * want to just show it now.
2450 ret = trace_print_seq(m, &iter->seq);
2452 /* ret should this time be zero, but you never know */
2453 iter->leftover = ret;
2456 print_trace_line(iter);
2457 ret = trace_print_seq(m, &iter->seq);
2459 * If we overflow the seq_file buffer, then it will
2460 * ask us for this data again at start up.
2462 * ret is 0 if seq_file write succeeded.
2465 iter->leftover = ret;
2471 static const struct seq_operations tracer_seq_ops = {
2478 static struct trace_iterator *
2479 __tracing_open(struct inode *inode, struct file *file, bool snapshot)
2481 struct trace_cpu *tc = inode->i_private;
2482 struct trace_array *tr = tc->tr;
2483 struct trace_iterator *iter;
2486 if (tracing_disabled)
2487 return ERR_PTR(-ENODEV);
2489 iter = __seq_open_private(file, &tracer_seq_ops, sizeof(*iter));
2491 return ERR_PTR(-ENOMEM);
2493 iter->buffer_iter = kzalloc(sizeof(*iter->buffer_iter) * num_possible_cpus(),
2495 if (!iter->buffer_iter)
2499 * We make a copy of the current tracer to avoid concurrent
2500 * changes on it while we are reading.
2502 mutex_lock(&trace_types_lock);
2503 iter->trace = kzalloc(sizeof(*iter->trace), GFP_KERNEL);
2507 *iter->trace = *tr->current_trace;
2509 if (!zalloc_cpumask_var(&iter->started, GFP_KERNEL))
2512 /* Currently only the top directory has a snapshot */
2513 if (tr->current_trace->print_max || snapshot)
2517 iter->snapshot = snapshot;
2519 mutex_init(&iter->mutex);
2520 iter->cpu_file = tc->cpu;
2522 /* Notify the tracer early; before we stop tracing. */
2523 if (iter->trace && iter->trace->open)
2524 iter->trace->open(iter);
2526 /* Annotate start of buffers if we had overruns */
2527 if (ring_buffer_overruns(iter->tr->buffer))
2528 iter->iter_flags |= TRACE_FILE_ANNOTATE;
2530 /* Output in nanoseconds only if we are using a clock in nanoseconds. */
2531 if (trace_clocks[trace_clock_id].in_ns)
2532 iter->iter_flags |= TRACE_FILE_TIME_IN_NS;
2534 /* stop the trace while dumping if we are not opening "snapshot" */
2535 if (!iter->snapshot)
2536 tracing_stop_tr(tr);
2538 if (iter->cpu_file == RING_BUFFER_ALL_CPUS) {
2539 for_each_tracing_cpu(cpu) {
2540 iter->buffer_iter[cpu] =
2541 ring_buffer_read_prepare(iter->tr->buffer, cpu);
2543 ring_buffer_read_prepare_sync();
2544 for_each_tracing_cpu(cpu) {
2545 ring_buffer_read_start(iter->buffer_iter[cpu]);
2546 tracing_iter_reset(iter, cpu);
2549 cpu = iter->cpu_file;
2550 iter->buffer_iter[cpu] =
2551 ring_buffer_read_prepare(iter->tr->buffer, cpu);
2552 ring_buffer_read_prepare_sync();
2553 ring_buffer_read_start(iter->buffer_iter[cpu]);
2554 tracing_iter_reset(iter, cpu);
2557 mutex_unlock(&trace_types_lock);
2562 mutex_unlock(&trace_types_lock);
2564 kfree(iter->buffer_iter);
2566 seq_release_private(inode, file);
2567 return ERR_PTR(-ENOMEM);
2570 int tracing_open_generic(struct inode *inode, struct file *filp)
2572 if (tracing_disabled)
2575 filp->private_data = inode->i_private;
2579 static int tracing_release(struct inode *inode, struct file *file)
2581 struct seq_file *m = file->private_data;
2582 struct trace_iterator *iter;
2583 struct trace_array *tr;
2586 if (!(file->f_mode & FMODE_READ))
2591 /* Only the global tracer has a matching max_tr */
2592 if (iter->tr == &max_tr)
2597 mutex_lock(&trace_types_lock);
2598 for_each_tracing_cpu(cpu) {
2599 if (iter->buffer_iter[cpu])
2600 ring_buffer_read_finish(iter->buffer_iter[cpu]);
2603 if (iter->trace && iter->trace->close)
2604 iter->trace->close(iter);
2606 if (!iter->snapshot)
2607 /* reenable tracing if it was previously enabled */
2608 tracing_start_tr(tr);
2609 mutex_unlock(&trace_types_lock);
2611 mutex_destroy(&iter->mutex);
2612 free_cpumask_var(iter->started);
2614 kfree(iter->buffer_iter);
2615 seq_release_private(inode, file);
2619 static int tracing_open(struct inode *inode, struct file *file)
2621 struct trace_iterator *iter;
2624 /* If this file was open for write, then erase contents */
2625 if ((file->f_mode & FMODE_WRITE) &&
2626 (file->f_flags & O_TRUNC)) {
2627 struct trace_cpu *tc = inode->i_private;
2628 struct trace_array *tr = tc->tr;
2630 if (tc->cpu == RING_BUFFER_ALL_CPUS)
2631 tracing_reset_online_cpus(tr);
2633 tracing_reset(tr, tc->cpu);
2636 if (file->f_mode & FMODE_READ) {
2637 iter = __tracing_open(inode, file, false);
2639 ret = PTR_ERR(iter);
2640 else if (trace_flags & TRACE_ITER_LATENCY_FMT)
2641 iter->iter_flags |= TRACE_FILE_LAT_FMT;
2647 t_next(struct seq_file *m, void *v, loff_t *pos)
2649 struct tracer *t = v;
2659 static void *t_start(struct seq_file *m, loff_t *pos)
2664 mutex_lock(&trace_types_lock);
2665 for (t = trace_types; t && l < *pos; t = t_next(m, t, &l))
2671 static void t_stop(struct seq_file *m, void *p)
2673 mutex_unlock(&trace_types_lock);
2676 static int t_show(struct seq_file *m, void *v)
2678 struct tracer *t = v;
2683 seq_printf(m, "%s", t->name);
2692 static const struct seq_operations show_traces_seq_ops = {
2699 static int show_traces_open(struct inode *inode, struct file *file)
2701 if (tracing_disabled)
2704 return seq_open(file, &show_traces_seq_ops);
2708 tracing_write_stub(struct file *filp, const char __user *ubuf,
2709 size_t count, loff_t *ppos)
2714 static loff_t tracing_seek(struct file *file, loff_t offset, int origin)
2716 if (file->f_mode & FMODE_READ)
2717 return seq_lseek(file, offset, origin);
2722 static const struct file_operations tracing_fops = {
2723 .open = tracing_open,
2725 .write = tracing_write_stub,
2726 .llseek = tracing_seek,
2727 .release = tracing_release,
2730 static const struct file_operations show_traces_fops = {
2731 .open = show_traces_open,
2733 .release = seq_release,
2734 .llseek = seq_lseek,
2738 * Only trace on a CPU if the bitmask is set:
2740 static cpumask_var_t tracing_cpumask;
2743 * The tracer itself will not take this lock, but still we want
2744 * to provide a consistent cpumask to user-space:
2746 static DEFINE_MUTEX(tracing_cpumask_update_lock);
2749 * Temporary storage for the character representation of the
2750 * CPU bitmask (and one more byte for the newline):
2752 static char mask_str[NR_CPUS + 1];
2755 tracing_cpumask_read(struct file *filp, char __user *ubuf,
2756 size_t count, loff_t *ppos)
2760 mutex_lock(&tracing_cpumask_update_lock);
2762 len = cpumask_scnprintf(mask_str, count, tracing_cpumask);
2763 if (count - len < 2) {
2767 len += sprintf(mask_str + len, "\n");
2768 count = simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+1);
2771 mutex_unlock(&tracing_cpumask_update_lock);
2777 tracing_cpumask_write(struct file *filp, const char __user *ubuf,
2778 size_t count, loff_t *ppos)
2780 struct trace_array *tr = filp->private_data;
2781 cpumask_var_t tracing_cpumask_new;
2784 if (!alloc_cpumask_var(&tracing_cpumask_new, GFP_KERNEL))
2787 err = cpumask_parse_user(ubuf, count, tracing_cpumask_new);
2791 mutex_lock(&tracing_cpumask_update_lock);
2793 local_irq_disable();
2794 arch_spin_lock(&ftrace_max_lock);
2795 for_each_tracing_cpu(cpu) {
2797 * Increase/decrease the disabled counter if we are
2798 * about to flip a bit in the cpumask:
2800 if (cpumask_test_cpu(cpu, tracing_cpumask) &&
2801 !cpumask_test_cpu(cpu, tracing_cpumask_new)) {
2802 atomic_inc(&per_cpu_ptr(tr->data, cpu)->disabled);
2803 ring_buffer_record_disable_cpu(tr->buffer, cpu);
2805 if (!cpumask_test_cpu(cpu, tracing_cpumask) &&
2806 cpumask_test_cpu(cpu, tracing_cpumask_new)) {
2807 atomic_dec(&per_cpu_ptr(tr->data, cpu)->disabled);
2808 ring_buffer_record_enable_cpu(tr->buffer, cpu);
2811 arch_spin_unlock(&ftrace_max_lock);
2814 cpumask_copy(tracing_cpumask, tracing_cpumask_new);
2816 mutex_unlock(&tracing_cpumask_update_lock);
2817 free_cpumask_var(tracing_cpumask_new);
2822 free_cpumask_var(tracing_cpumask_new);
2827 static const struct file_operations tracing_cpumask_fops = {
2828 .open = tracing_open_generic,
2829 .read = tracing_cpumask_read,
2830 .write = tracing_cpumask_write,
2831 .llseek = generic_file_llseek,
2834 static int tracing_trace_options_show(struct seq_file *m, void *v)
2836 struct tracer_opt *trace_opts;
2837 struct trace_array *tr = m->private;
2841 mutex_lock(&trace_types_lock);
2842 tracer_flags = tr->current_trace->flags->val;
2843 trace_opts = tr->current_trace->flags->opts;
2845 for (i = 0; trace_options[i]; i++) {
2846 if (trace_flags & (1 << i))
2847 seq_printf(m, "%s\n", trace_options[i]);
2849 seq_printf(m, "no%s\n", trace_options[i]);
2852 for (i = 0; trace_opts[i].name; i++) {
2853 if (tracer_flags & trace_opts[i].bit)
2854 seq_printf(m, "%s\n", trace_opts[i].name);
2856 seq_printf(m, "no%s\n", trace_opts[i].name);
2858 mutex_unlock(&trace_types_lock);
2863 static int __set_tracer_option(struct tracer *trace,
2864 struct tracer_flags *tracer_flags,
2865 struct tracer_opt *opts, int neg)
2869 ret = trace->set_flag(tracer_flags->val, opts->bit, !neg);
2874 tracer_flags->val &= ~opts->bit;
2876 tracer_flags->val |= opts->bit;
2880 /* Try to assign a tracer specific option */
2881 static int set_tracer_option(struct tracer *trace, char *cmp, int neg)
2883 struct tracer_flags *tracer_flags = trace->flags;
2884 struct tracer_opt *opts = NULL;
2887 for (i = 0; tracer_flags->opts[i].name; i++) {
2888 opts = &tracer_flags->opts[i];
2890 if (strcmp(cmp, opts->name) == 0)
2891 return __set_tracer_option(trace, trace->flags,
2898 /* Some tracers require overwrite to stay enabled */
2899 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
2901 if (tracer->enabled && (mask & TRACE_ITER_OVERWRITE) && !set)
2907 int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
2909 /* do nothing if flag is already set */
2910 if (!!(trace_flags & mask) == !!enabled)
2913 /* Give the tracer a chance to approve the change */
2914 if (tr->current_trace->flag_changed)
2915 if (tr->current_trace->flag_changed(tr->current_trace, mask, !!enabled))
2919 trace_flags |= mask;
2921 trace_flags &= ~mask;
2923 if (mask == TRACE_ITER_RECORD_CMD)
2924 trace_event_enable_cmd_record(enabled);
2926 if (mask == TRACE_ITER_OVERWRITE) {
2927 ring_buffer_change_overwrite(global_trace.buffer, enabled);
2928 #ifdef CONFIG_TRACER_MAX_TRACE
2929 ring_buffer_change_overwrite(max_tr.buffer, enabled);
2933 if (mask == TRACE_ITER_PRINTK)
2934 trace_printk_start_stop_comm(enabled);
2939 static int trace_set_options(struct trace_array *tr, char *option)
2946 cmp = strstrip(option);
2948 if (strncmp(cmp, "no", 2) == 0) {
2953 mutex_lock(&trace_types_lock);
2955 for (i = 0; trace_options[i]; i++) {
2956 if (strcmp(cmp, trace_options[i]) == 0) {
2957 ret = set_tracer_flag(tr, 1 << i, !neg);
2962 /* If no option could be set, test the specific tracer options */
2963 if (!trace_options[i])
2964 ret = set_tracer_option(tr->current_trace, cmp, neg);
2966 mutex_unlock(&trace_types_lock);
2972 tracing_trace_options_write(struct file *filp, const char __user *ubuf,
2973 size_t cnt, loff_t *ppos)
2975 struct seq_file *m = filp->private_data;
2976 struct trace_array *tr = m->private;
2980 if (cnt >= sizeof(buf))
2983 if (copy_from_user(&buf, ubuf, cnt))
2988 ret = trace_set_options(tr, buf);
2997 static int tracing_trace_options_open(struct inode *inode, struct file *file)
2999 if (tracing_disabled)
3002 return single_open(file, tracing_trace_options_show, inode->i_private);
3005 static const struct file_operations tracing_iter_fops = {
3006 .open = tracing_trace_options_open,
3008 .llseek = seq_lseek,
3009 .release = single_release,
3010 .write = tracing_trace_options_write,
3013 static const char readme_msg[] =
3014 "tracing mini-HOWTO:\n\n"
3015 "# mount -t debugfs nodev /sys/kernel/debug\n\n"
3016 "# cat /sys/kernel/debug/tracing/available_tracers\n"
3017 "wakeup wakeup_rt preemptirqsoff preemptoff irqsoff function nop\n\n"
3018 "# cat /sys/kernel/debug/tracing/current_tracer\n"
3020 "# echo wakeup > /sys/kernel/debug/tracing/current_tracer\n"
3021 "# cat /sys/kernel/debug/tracing/current_tracer\n"
3023 "# cat /sys/kernel/debug/tracing/trace_options\n"
3024 "noprint-parent nosym-offset nosym-addr noverbose\n"
3025 "# echo print-parent > /sys/kernel/debug/tracing/trace_options\n"
3026 "# echo 1 > /sys/kernel/debug/tracing/tracing_on\n"
3027 "# cat /sys/kernel/debug/tracing/trace > /tmp/trace.txt\n"
3028 "# echo 0 > /sys/kernel/debug/tracing/tracing_on\n"
3032 tracing_readme_read(struct file *filp, char __user *ubuf,
3033 size_t cnt, loff_t *ppos)
3035 return simple_read_from_buffer(ubuf, cnt, ppos,
3036 readme_msg, strlen(readme_msg));
3039 static const struct file_operations tracing_readme_fops = {
3040 .open = tracing_open_generic,
3041 .read = tracing_readme_read,
3042 .llseek = generic_file_llseek,
3046 tracing_saved_cmdlines_read(struct file *file, char __user *ubuf,
3047 size_t cnt, loff_t *ppos)
3056 file_buf = kmalloc(SAVED_CMDLINES*(16+TASK_COMM_LEN), GFP_KERNEL);
3060 buf_comm = kmalloc(TASK_COMM_LEN, GFP_KERNEL);
3068 for (i = 0; i < SAVED_CMDLINES; i++) {
3071 pid = map_cmdline_to_pid[i];
3072 if (pid == -1 || pid == NO_CMDLINE_MAP)
3075 trace_find_cmdline(pid, buf_comm);
3076 r = sprintf(buf, "%d %s\n", pid, buf_comm);
3081 len = simple_read_from_buffer(ubuf, cnt, ppos,
3090 static const struct file_operations tracing_saved_cmdlines_fops = {
3091 .open = tracing_open_generic,
3092 .read = tracing_saved_cmdlines_read,
3093 .llseek = generic_file_llseek,
3097 tracing_set_trace_read(struct file *filp, char __user *ubuf,
3098 size_t cnt, loff_t *ppos)
3100 struct trace_array *tr = filp->private_data;
3101 char buf[MAX_TRACER_SIZE+2];
3104 mutex_lock(&trace_types_lock);
3105 r = sprintf(buf, "%s\n", tr->current_trace->name);
3106 mutex_unlock(&trace_types_lock);
3108 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
3111 int tracer_init(struct tracer *t, struct trace_array *tr)
3113 tracing_reset_online_cpus(tr);
3117 static void set_buffer_entries(struct trace_array *tr, unsigned long val)
3120 for_each_tracing_cpu(cpu)
3121 per_cpu_ptr(tr->data, cpu)->entries = val;
3124 /* resize @tr's buffer to the size of @size_tr's entries */
3125 static int resize_buffer_duplicate_size(struct trace_array *tr,
3126 struct trace_array *size_tr, int cpu_id)
3130 if (cpu_id == RING_BUFFER_ALL_CPUS) {
3131 for_each_tracing_cpu(cpu) {
3132 ret = ring_buffer_resize(tr->buffer,
3133 per_cpu_ptr(size_tr->data, cpu)->entries, cpu);
3136 per_cpu_ptr(tr->data, cpu)->entries =
3137 per_cpu_ptr(size_tr->data, cpu)->entries;
3140 ret = ring_buffer_resize(tr->buffer,
3141 per_cpu_ptr(size_tr->data, cpu_id)->entries, cpu_id);
3143 per_cpu_ptr(tr->data, cpu_id)->entries =
3144 per_cpu_ptr(size_tr->data, cpu_id)->entries;
3150 static int __tracing_resize_ring_buffer(struct trace_array *tr,
3151 unsigned long size, int cpu)
3156 * If kernel or user changes the size of the ring buffer
3157 * we use the size that was given, and we can forget about
3158 * expanding it later.
3160 ring_buffer_expanded = 1;
3162 /* May be called before buffers are initialized */
3166 ret = ring_buffer_resize(tr->buffer, size, cpu);
3170 if (!(tr->flags & TRACE_ARRAY_FL_GLOBAL) ||
3171 !tr->current_trace->use_max_tr)
3174 ret = ring_buffer_resize(max_tr.buffer, size, cpu);
3176 int r = resize_buffer_duplicate_size(tr, tr, cpu);
3179 * AARGH! We are left with different
3180 * size max buffer!!!!
3181 * The max buffer is our "snapshot" buffer.
3182 * When a tracer needs a snapshot (one of the
3183 * latency tracers), it swaps the max buffer
3184 * with the saved snap shot. We succeeded to
3185 * update the size of the main buffer, but failed to
3186 * update the size of the max buffer. But when we tried
3187 * to reset the main buffer to the original size, we
3188 * failed there too. This is very unlikely to
3189 * happen, but if it does, warn and kill all
3193 tracing_disabled = 1;
3198 if (cpu == RING_BUFFER_ALL_CPUS)
3199 set_buffer_entries(&max_tr, size);
3201 per_cpu_ptr(max_tr.data, cpu)->entries = size;
3204 if (cpu == RING_BUFFER_ALL_CPUS)
3205 set_buffer_entries(tr, size);
3207 per_cpu_ptr(tr->data, cpu)->entries = size;
3212 static ssize_t tracing_resize_ring_buffer(struct trace_array *tr,
3213 unsigned long size, int cpu_id)
3217 mutex_lock(&trace_types_lock);
3219 if (cpu_id != RING_BUFFER_ALL_CPUS) {
3220 /* make sure, this cpu is enabled in the mask */
3221 if (!cpumask_test_cpu(cpu_id, tracing_buffer_mask)) {
3227 ret = __tracing_resize_ring_buffer(tr, size, cpu_id);
3232 mutex_unlock(&trace_types_lock);
3239 * tracing_update_buffers - used by tracing facility to expand ring buffers
3241 * To save on memory when the tracing is never used on a system with it
3242 * configured in. The ring buffers are set to a minimum size. But once
3243 * a user starts to use the tracing facility, then they need to grow
3244 * to their default size.
3246 * This function is to be called when a tracer is about to be used.
3248 int tracing_update_buffers(void)
3252 mutex_lock(&trace_types_lock);
3253 if (!ring_buffer_expanded)
3254 ret = __tracing_resize_ring_buffer(&global_trace, trace_buf_size,
3255 RING_BUFFER_ALL_CPUS);
3256 mutex_unlock(&trace_types_lock);
3261 struct trace_option_dentry;
3263 static struct trace_option_dentry *
3264 create_trace_option_files(struct trace_array *tr, struct tracer *tracer);
3267 destroy_trace_option_files(struct trace_option_dentry *topts);
3269 static int tracing_set_tracer(const char *buf)
3271 static struct trace_option_dentry *topts;
3272 struct trace_array *tr = &global_trace;
3277 mutex_lock(&trace_types_lock);
3279 if (!ring_buffer_expanded) {
3280 ret = __tracing_resize_ring_buffer(tr, trace_buf_size,
3281 RING_BUFFER_ALL_CPUS);
3287 for (t = trace_types; t; t = t->next) {
3288 if (strcmp(t->name, buf) == 0)
3295 if (t == tr->current_trace)
3298 trace_branch_disable();
3300 tr->current_trace->enabled = false;
3302 if (tr->current_trace->reset)
3303 tr->current_trace->reset(tr);
3305 had_max_tr = tr->current_trace->allocated_snapshot;
3306 tr->current_trace = &nop_trace;
3308 if (had_max_tr && !t->use_max_tr) {
3310 * We need to make sure that the update_max_tr sees that
3311 * current_trace changed to nop_trace to keep it from
3312 * swapping the buffers after we resize it.
3313 * The update_max_tr is called from interrupts disabled
3314 * so a synchronized_sched() is sufficient.
3316 synchronize_sched();
3318 * We don't free the ring buffer. instead, resize it because
3319 * The max_tr ring buffer has some state (e.g. ring->clock) and
3320 * we want preserve it.
3322 ring_buffer_resize(max_tr.buffer, 1, RING_BUFFER_ALL_CPUS);
3323 set_buffer_entries(&max_tr, 1);
3324 tracing_reset_online_cpus(&max_tr);
3325 tr->current_trace->allocated_snapshot = false;
3327 destroy_trace_option_files(topts);
3329 topts = create_trace_option_files(tr, t);
3330 if (t->use_max_tr && !had_max_tr) {
3331 /* we need to make per cpu buffer sizes equivalent */
3332 ret = resize_buffer_duplicate_size(&max_tr, &global_trace,
3333 RING_BUFFER_ALL_CPUS);
3336 t->allocated_snapshot = true;
3340 ret = tracer_init(t, tr);
3345 tr->current_trace = t;
3346 tr->current_trace->enabled = true;
3347 trace_branch_enable(tr);
3349 mutex_unlock(&trace_types_lock);
3355 tracing_set_trace_write(struct file *filp, const char __user *ubuf,
3356 size_t cnt, loff_t *ppos)
3358 char buf[MAX_TRACER_SIZE+1];
3365 if (cnt > MAX_TRACER_SIZE)
3366 cnt = MAX_TRACER_SIZE;
3368 if (copy_from_user(&buf, ubuf, cnt))
3373 /* strip ending whitespace. */
3374 for (i = cnt - 1; i > 0 && isspace(buf[i]); i--)
3377 err = tracing_set_tracer(buf);
3387 tracing_max_lat_read(struct file *filp, char __user *ubuf,
3388 size_t cnt, loff_t *ppos)
3390 unsigned long *ptr = filp->private_data;
3394 r = snprintf(buf, sizeof(buf), "%ld\n",
3395 *ptr == (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr));
3396 if (r > sizeof(buf))
3398 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
3402 tracing_max_lat_write(struct file *filp, const char __user *ubuf,
3403 size_t cnt, loff_t *ppos)
3405 unsigned long *ptr = filp->private_data;
3409 ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
3418 static int tracing_open_pipe(struct inode *inode, struct file *filp)
3420 struct trace_cpu *tc = inode->i_private;
3421 struct trace_array *tr = tc->tr;
3422 struct trace_iterator *iter;
3425 if (tracing_disabled)
3428 mutex_lock(&trace_types_lock);
3430 /* create a buffer to store the information to pass to userspace */
3431 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
3438 * We make a copy of the current tracer to avoid concurrent
3439 * changes on it while we are reading.
3441 iter->trace = kmalloc(sizeof(*iter->trace), GFP_KERNEL);
3446 *iter->trace = *tr->current_trace;
3448 if (!alloc_cpumask_var(&iter->started, GFP_KERNEL)) {
3453 /* trace pipe does not show start of buffer */
3454 cpumask_setall(iter->started);
3456 if (trace_flags & TRACE_ITER_LATENCY_FMT)
3457 iter->iter_flags |= TRACE_FILE_LAT_FMT;
3459 /* Output in nanoseconds only if we are using a clock in nanoseconds. */
3460 if (trace_clocks[trace_clock_id].in_ns)
3461 iter->iter_flags |= TRACE_FILE_TIME_IN_NS;
3463 iter->cpu_file = tc->cpu;
3465 mutex_init(&iter->mutex);
3466 filp->private_data = iter;
3468 if (iter->trace->pipe_open)
3469 iter->trace->pipe_open(iter);
3471 nonseekable_open(inode, filp);
3473 mutex_unlock(&trace_types_lock);
3479 mutex_unlock(&trace_types_lock);
3483 static int tracing_release_pipe(struct inode *inode, struct file *file)
3485 struct trace_iterator *iter = file->private_data;
3487 mutex_lock(&trace_types_lock);
3489 if (iter->trace->pipe_close)
3490 iter->trace->pipe_close(iter);
3492 mutex_unlock(&trace_types_lock);
3494 free_cpumask_var(iter->started);
3495 mutex_destroy(&iter->mutex);
3503 trace_poll(struct trace_iterator *iter, struct file *filp, poll_table *poll_table)
3505 /* Iterators are static, they should be filled or empty */
3506 if (trace_buffer_iter(iter, iter->cpu_file))
3507 return POLLIN | POLLRDNORM;
3509 if (trace_flags & TRACE_ITER_BLOCK)
3511 * Always select as readable when in blocking mode
3513 return POLLIN | POLLRDNORM;
3515 return ring_buffer_poll_wait(iter->tr->buffer, iter->cpu_file,
3520 tracing_poll_pipe(struct file *filp, poll_table *poll_table)
3522 struct trace_iterator *iter = filp->private_data;
3524 return trace_poll(iter, filp, poll_table);
3528 * This is a make-shift waitqueue.
3529 * A tracer might use this callback on some rare cases:
3531 * 1) the current tracer might hold the runqueue lock when it wakes up
3532 * a reader, hence a deadlock (sched, function, and function graph tracers)
3533 * 2) the function tracers, trace all functions, we don't want
3534 * the overhead of calling wake_up and friends
3535 * (and tracing them too)
3537 * Anyway, this is really very primitive wakeup.
3539 void poll_wait_pipe(struct trace_iterator *iter)
3541 set_current_state(TASK_INTERRUPTIBLE);
3542 /* sleep for 100 msecs, and try again. */
3543 schedule_timeout(HZ / 10);
3546 /* Must be called with trace_types_lock mutex held. */
3547 static int tracing_wait_pipe(struct file *filp)
3549 struct trace_iterator *iter = filp->private_data;
3551 while (trace_empty(iter)) {
3553 if ((filp->f_flags & O_NONBLOCK)) {
3557 mutex_unlock(&iter->mutex);
3559 iter->trace->wait_pipe(iter);
3561 mutex_lock(&iter->mutex);
3563 if (signal_pending(current))
3567 * We block until we read something and tracing is disabled.
3568 * We still block if tracing is disabled, but we have never
3569 * read anything. This allows a user to cat this file, and
3570 * then enable tracing. But after we have read something,
3571 * we give an EOF when tracing is again disabled.
3573 * iter->pos will be 0 if we haven't read anything.
3575 if (!tracing_is_enabled() && iter->pos)
3586 tracing_read_pipe(struct file *filp, char __user *ubuf,
3587 size_t cnt, loff_t *ppos)
3589 struct trace_iterator *iter = filp->private_data;
3590 struct trace_array *tr = iter->tr;
3593 /* return any leftover data */
3594 sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
3598 trace_seq_init(&iter->seq);
3600 /* copy the tracer to avoid using a global lock all around */
3601 mutex_lock(&trace_types_lock);
3602 if (unlikely(iter->trace->name != tr->current_trace->name))
3603 *iter->trace = *tr->current_trace;
3604 mutex_unlock(&trace_types_lock);
3607 * Avoid more than one consumer on a single file descriptor
3608 * This is just a matter of traces coherency, the ring buffer itself
3611 mutex_lock(&iter->mutex);
3612 if (iter->trace->read) {
3613 sret = iter->trace->read(iter, filp, ubuf, cnt, ppos);
3619 sret = tracing_wait_pipe(filp);
3623 /* stop when tracing is finished */
3624 if (trace_empty(iter)) {
3629 if (cnt >= PAGE_SIZE)
3630 cnt = PAGE_SIZE - 1;
3632 /* reset all but tr, trace, and overruns */
3633 memset(&iter->seq, 0,
3634 sizeof(struct trace_iterator) -
3635 offsetof(struct trace_iterator, seq));
3638 trace_event_read_lock();
3639 trace_access_lock(iter->cpu_file);
3640 while (trace_find_next_entry_inc(iter) != NULL) {
3641 enum print_line_t ret;
3642 int len = iter->seq.len;
3644 ret = print_trace_line(iter);
3645 if (ret == TRACE_TYPE_PARTIAL_LINE) {
3646 /* don't print partial lines */
3647 iter->seq.len = len;
3650 if (ret != TRACE_TYPE_NO_CONSUME)
3651 trace_consume(iter);
3653 if (iter->seq.len >= cnt)
3657 * Setting the full flag means we reached the trace_seq buffer
3658 * size and we should leave by partial output condition above.
3659 * One of the trace_seq_* functions is not used properly.
3661 WARN_ONCE(iter->seq.full, "full flag set for trace type %d",
3664 trace_access_unlock(iter->cpu_file);
3665 trace_event_read_unlock();
3667 /* Now copy what we have to the user */
3668 sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
3669 if (iter->seq.readpos >= iter->seq.len)
3670 trace_seq_init(&iter->seq);
3673 * If there was nothing to send to user, in spite of consuming trace
3674 * entries, go back to wait for more entries.
3680 mutex_unlock(&iter->mutex);
3685 static void tracing_pipe_buf_release(struct pipe_inode_info *pipe,
3686 struct pipe_buffer *buf)
3688 __free_page(buf->page);
3691 static void tracing_spd_release_pipe(struct splice_pipe_desc *spd,
3694 __free_page(spd->pages[idx]);
3697 static const struct pipe_buf_operations tracing_pipe_buf_ops = {
3699 .map = generic_pipe_buf_map,
3700 .unmap = generic_pipe_buf_unmap,
3701 .confirm = generic_pipe_buf_confirm,
3702 .release = tracing_pipe_buf_release,
3703 .steal = generic_pipe_buf_steal,
3704 .get = generic_pipe_buf_get,
3708 tracing_fill_pipe_page(size_t rem, struct trace_iterator *iter)
3713 /* Seq buffer is page-sized, exactly what we need. */
3715 count = iter->seq.len;
3716 ret = print_trace_line(iter);
3717 count = iter->seq.len - count;
3720 iter->seq.len -= count;
3723 if (ret == TRACE_TYPE_PARTIAL_LINE) {
3724 iter->seq.len -= count;
3728 if (ret != TRACE_TYPE_NO_CONSUME)
3729 trace_consume(iter);
3731 if (!trace_find_next_entry_inc(iter)) {
3741 static ssize_t tracing_splice_read_pipe(struct file *filp,
3743 struct pipe_inode_info *pipe,
3747 struct page *pages_def[PIPE_DEF_BUFFERS];
3748 struct partial_page partial_def[PIPE_DEF_BUFFERS];
3749 struct trace_iterator *iter = filp->private_data;
3750 struct splice_pipe_desc spd = {
3752 .partial = partial_def,
3753 .nr_pages = 0, /* This gets updated below. */
3754 .nr_pages_max = PIPE_DEF_BUFFERS,
3756 .ops = &tracing_pipe_buf_ops,
3757 .spd_release = tracing_spd_release_pipe,
3759 struct trace_array *tr = iter->tr;
3764 if (splice_grow_spd(pipe, &spd))
3767 /* copy the tracer to avoid using a global lock all around */
3768 mutex_lock(&trace_types_lock);
3769 if (unlikely(iter->trace->name != tr->current_trace->name))
3770 *iter->trace = *tr->current_trace;
3771 mutex_unlock(&trace_types_lock);
3773 mutex_lock(&iter->mutex);
3775 if (iter->trace->splice_read) {
3776 ret = iter->trace->splice_read(iter, filp,
3777 ppos, pipe, len, flags);
3782 ret = tracing_wait_pipe(filp);
3786 if (!iter->ent && !trace_find_next_entry_inc(iter)) {
3791 trace_event_read_lock();
3792 trace_access_lock(iter->cpu_file);
3794 /* Fill as many pages as possible. */
3795 for (i = 0, rem = len; i < pipe->buffers && rem; i++) {
3796 spd.pages[i] = alloc_page(GFP_KERNEL);
3800 rem = tracing_fill_pipe_page(rem, iter);
3802 /* Copy the data into the page, so we can start over. */
3803 ret = trace_seq_to_buffer(&iter->seq,
3804 page_address(spd.pages[i]),
3807 __free_page(spd.pages[i]);
3810 spd.partial[i].offset = 0;
3811 spd.partial[i].len = iter->seq.len;
3813 trace_seq_init(&iter->seq);
3816 trace_access_unlock(iter->cpu_file);
3817 trace_event_read_unlock();
3818 mutex_unlock(&iter->mutex);
3822 ret = splice_to_pipe(pipe, &spd);
3824 splice_shrink_spd(&spd);
3828 mutex_unlock(&iter->mutex);
3833 tracing_entries_read(struct file *filp, char __user *ubuf,
3834 size_t cnt, loff_t *ppos)
3836 struct trace_cpu *tc = filp->private_data;
3837 struct trace_array *tr = tc->tr;
3842 mutex_lock(&trace_types_lock);
3844 if (tc->cpu == RING_BUFFER_ALL_CPUS) {
3845 int cpu, buf_size_same;
3850 /* check if all cpu sizes are same */
3851 for_each_tracing_cpu(cpu) {
3852 /* fill in the size from first enabled cpu */
3854 size = per_cpu_ptr(tr->data, cpu)->entries;
3855 if (size != per_cpu_ptr(tr->data, cpu)->entries) {
3861 if (buf_size_same) {
3862 if (!ring_buffer_expanded)
3863 r = sprintf(buf, "%lu (expanded: %lu)\n",
3865 trace_buf_size >> 10);
3867 r = sprintf(buf, "%lu\n", size >> 10);
3869 r = sprintf(buf, "X\n");
3871 r = sprintf(buf, "%lu\n", per_cpu_ptr(tr->data, tc->cpu)->entries >> 10);
3873 mutex_unlock(&trace_types_lock);
3875 ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
3880 tracing_entries_write(struct file *filp, const char __user *ubuf,
3881 size_t cnt, loff_t *ppos)
3883 struct trace_cpu *tc = filp->private_data;
3887 ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
3891 /* must have at least 1 entry */
3895 /* value is in KB */
3898 ret = tracing_resize_ring_buffer(tc->tr, val, tc->cpu);
3908 tracing_total_entries_read(struct file *filp, char __user *ubuf,
3909 size_t cnt, loff_t *ppos)
3911 struct trace_array *tr = filp->private_data;
3914 unsigned long size = 0, expanded_size = 0;
3916 mutex_lock(&trace_types_lock);
3917 for_each_tracing_cpu(cpu) {
3918 size += per_cpu_ptr(tr->data, cpu)->entries >> 10;
3919 if (!ring_buffer_expanded)
3920 expanded_size += trace_buf_size >> 10;
3922 if (ring_buffer_expanded)
3923 r = sprintf(buf, "%lu\n", size);
3925 r = sprintf(buf, "%lu (expanded: %lu)\n", size, expanded_size);
3926 mutex_unlock(&trace_types_lock);
3928 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
3932 tracing_free_buffer_write(struct file *filp, const char __user *ubuf,
3933 size_t cnt, loff_t *ppos)
3936 * There is no need to read what the user has written, this function
3937 * is just to make sure that there is no error when "echo" is used
3946 tracing_free_buffer_release(struct inode *inode, struct file *filp)
3948 struct trace_array *tr = inode->i_private;
3950 /* disable tracing ? */
3951 if (trace_flags & TRACE_ITER_STOP_ON_FREE)
3953 /* resize the ring buffer to 0 */
3954 tracing_resize_ring_buffer(tr, 0, RING_BUFFER_ALL_CPUS);
3960 tracing_mark_write(struct file *filp, const char __user *ubuf,
3961 size_t cnt, loff_t *fpos)
3963 unsigned long addr = (unsigned long)ubuf;
3964 struct ring_buffer_event *event;
3965 struct ring_buffer *buffer;
3966 struct print_entry *entry;
3967 unsigned long irq_flags;
3968 struct page *pages[2];
3978 if (tracing_disabled)
3981 if (!(trace_flags & TRACE_ITER_MARKERS))
3984 if (cnt > TRACE_BUF_SIZE)
3985 cnt = TRACE_BUF_SIZE;
3988 * Userspace is injecting traces into the kernel trace buffer.
3989 * We want to be as non intrusive as possible.
3990 * To do so, we do not want to allocate any special buffers
3991 * or take any locks, but instead write the userspace data
3992 * straight into the ring buffer.
3994 * First we need to pin the userspace buffer into memory,
3995 * which, most likely it is, because it just referenced it.
3996 * But there's no guarantee that it is. By using get_user_pages_fast()
3997 * and kmap_atomic/kunmap_atomic() we can get access to the
3998 * pages directly. We then write the data directly into the
4001 BUILD_BUG_ON(TRACE_BUF_SIZE >= PAGE_SIZE);
4003 /* check if we cross pages */
4004 if ((addr & PAGE_MASK) != ((addr + cnt) & PAGE_MASK))
4007 offset = addr & (PAGE_SIZE - 1);
4010 ret = get_user_pages_fast(addr, nr_pages, 0, pages);
4011 if (ret < nr_pages) {
4013 put_page(pages[ret]);
4018 for (i = 0; i < nr_pages; i++)
4019 map_page[i] = kmap_atomic(pages[i]);
4021 local_save_flags(irq_flags);
4022 size = sizeof(*entry) + cnt + 2; /* possible \n added */
4023 buffer = global_trace.buffer;
4024 event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, size,
4025 irq_flags, preempt_count());
4027 /* Ring buffer disabled, return as if not open for write */
4032 entry = ring_buffer_event_data(event);
4033 entry->ip = _THIS_IP_;
4035 if (nr_pages == 2) {
4036 len = PAGE_SIZE - offset;
4037 memcpy(&entry->buf, map_page[0] + offset, len);
4038 memcpy(&entry->buf[len], map_page[1], cnt - len);
4040 memcpy(&entry->buf, map_page[0] + offset, cnt);
4042 if (entry->buf[cnt - 1] != '\n') {
4043 entry->buf[cnt] = '\n';
4044 entry->buf[cnt + 1] = '\0';
4046 entry->buf[cnt] = '\0';
4048 __buffer_unlock_commit(buffer, event);
4055 for (i = 0; i < nr_pages; i++){
4056 kunmap_atomic(map_page[i]);
4063 static int tracing_clock_show(struct seq_file *m, void *v)
4065 struct trace_array *tr = m->private;
4068 for (i = 0; i < ARRAY_SIZE(trace_clocks); i++)
4070 "%s%s%s%s", i ? " " : "",
4071 i == tr->clock_id ? "[" : "", trace_clocks[i].name,
4072 i == tr->clock_id ? "]" : "");
4078 static ssize_t tracing_clock_write(struct file *filp, const char __user *ubuf,
4079 size_t cnt, loff_t *fpos)
4081 struct seq_file *m = filp->private_data;
4082 struct trace_array *tr = m->private;
4084 const char *clockstr;
4087 if (cnt >= sizeof(buf))
4090 if (copy_from_user(&buf, ubuf, cnt))
4095 clockstr = strstrip(buf);
4097 for (i = 0; i < ARRAY_SIZE(trace_clocks); i++) {
4098 if (strcmp(trace_clocks[i].name, clockstr) == 0)
4101 if (i == ARRAY_SIZE(trace_clocks))
4104 mutex_lock(&trace_types_lock);
4108 ring_buffer_set_clock(tr->buffer, trace_clocks[i].func);
4109 if (tr->flags & TRACE_ARRAY_FL_GLOBAL && max_tr.buffer)
4110 ring_buffer_set_clock(max_tr.buffer, trace_clocks[i].func);
4113 * New clock may not be consistent with the previous clock.
4114 * Reset the buffer so that it doesn't have incomparable timestamps.
4116 tracing_reset_online_cpus(&global_trace);
4117 tracing_reset_online_cpus(&max_tr);
4119 mutex_unlock(&trace_types_lock);
4126 static int tracing_clock_open(struct inode *inode, struct file *file)
4128 if (tracing_disabled)
4131 return single_open(file, tracing_clock_show, inode->i_private);
4134 #ifdef CONFIG_TRACER_SNAPSHOT
4135 static int tracing_snapshot_open(struct inode *inode, struct file *file)
4137 struct trace_cpu *tc = inode->i_private;
4138 struct trace_iterator *iter;
4142 if (file->f_mode & FMODE_READ) {
4143 iter = __tracing_open(inode, file, true);
4145 ret = PTR_ERR(iter);
4147 /* Writes still need the seq_file to hold the private data */
4148 m = kzalloc(sizeof(*m), GFP_KERNEL);
4151 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
4158 file->private_data = m;
4165 tracing_snapshot_write(struct file *filp, const char __user *ubuf, size_t cnt,
4168 struct seq_file *m = filp->private_data;
4169 struct trace_iterator *iter = m->private;
4170 struct trace_array *tr = iter->tr;
4174 ret = tracing_update_buffers();
4178 ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
4182 mutex_lock(&trace_types_lock);
4184 if (tr->current_trace->use_max_tr) {
4191 if (tr->current_trace->allocated_snapshot) {
4192 /* free spare buffer */
4193 ring_buffer_resize(max_tr.buffer, 1,
4194 RING_BUFFER_ALL_CPUS);
4195 set_buffer_entries(&max_tr, 1);
4196 tracing_reset_online_cpus(&max_tr);
4197 tr->current_trace->allocated_snapshot = false;
4201 if (!tr->current_trace->allocated_snapshot) {
4202 /* allocate spare buffer */
4203 ret = resize_buffer_duplicate_size(&max_tr,
4204 &global_trace, RING_BUFFER_ALL_CPUS);
4207 tr->current_trace->allocated_snapshot = true;
4210 local_irq_disable();
4211 /* Now, we're going to swap */
4212 update_max_tr(&global_trace, current, smp_processor_id());
4216 if (tr->current_trace->allocated_snapshot)
4217 tracing_reset_online_cpus(&max_tr);
4226 mutex_unlock(&trace_types_lock);
4230 static int tracing_snapshot_release(struct inode *inode, struct file *file)
4232 struct seq_file *m = file->private_data;
4234 if (file->f_mode & FMODE_READ)
4235 return tracing_release(inode, file);
4237 /* If write only, the seq_file is just a stub */
4245 #endif /* CONFIG_TRACER_SNAPSHOT */
4248 static const struct file_operations tracing_max_lat_fops = {
4249 .open = tracing_open_generic,
4250 .read = tracing_max_lat_read,
4251 .write = tracing_max_lat_write,
4252 .llseek = generic_file_llseek,
4255 static const struct file_operations set_tracer_fops = {
4256 .open = tracing_open_generic,
4257 .read = tracing_set_trace_read,
4258 .write = tracing_set_trace_write,
4259 .llseek = generic_file_llseek,
4262 static const struct file_operations tracing_pipe_fops = {
4263 .open = tracing_open_pipe,
4264 .poll = tracing_poll_pipe,
4265 .read = tracing_read_pipe,
4266 .splice_read = tracing_splice_read_pipe,
4267 .release = tracing_release_pipe,
4268 .llseek = no_llseek,
4271 static const struct file_operations tracing_entries_fops = {
4272 .open = tracing_open_generic,
4273 .read = tracing_entries_read,
4274 .write = tracing_entries_write,
4275 .llseek = generic_file_llseek,
4278 static const struct file_operations tracing_total_entries_fops = {
4279 .open = tracing_open_generic,
4280 .read = tracing_total_entries_read,
4281 .llseek = generic_file_llseek,
4284 static const struct file_operations tracing_free_buffer_fops = {
4285 .write = tracing_free_buffer_write,
4286 .release = tracing_free_buffer_release,
4289 static const struct file_operations tracing_mark_fops = {
4290 .open = tracing_open_generic,
4291 .write = tracing_mark_write,
4292 .llseek = generic_file_llseek,
4295 static const struct file_operations trace_clock_fops = {
4296 .open = tracing_clock_open,
4298 .llseek = seq_lseek,
4299 .release = single_release,
4300 .write = tracing_clock_write,
4303 #ifdef CONFIG_TRACER_SNAPSHOT
4304 static const struct file_operations snapshot_fops = {
4305 .open = tracing_snapshot_open,
4307 .write = tracing_snapshot_write,
4308 .llseek = tracing_seek,
4309 .release = tracing_snapshot_release,
4311 #endif /* CONFIG_TRACER_SNAPSHOT */
4313 struct ftrace_buffer_info {
4314 struct trace_iterator iter;
4319 static int tracing_buffers_open(struct inode *inode, struct file *filp)
4321 struct trace_cpu *tc = inode->i_private;
4322 struct trace_array *tr = tc->tr;
4323 struct ftrace_buffer_info *info;
4325 if (tracing_disabled)
4328 info = kzalloc(sizeof(*info), GFP_KERNEL);
4333 info->iter.cpu_file = tc->cpu;
4334 info->iter.trace = tr->current_trace;
4336 /* Force reading ring buffer for first read */
4337 info->read = (unsigned int)-1;
4339 filp->private_data = info;
4341 return nonseekable_open(inode, filp);
4345 tracing_buffers_poll(struct file *filp, poll_table *poll_table)
4347 struct ftrace_buffer_info *info = filp->private_data;
4348 struct trace_iterator *iter = &info->iter;
4350 return trace_poll(iter, filp, poll_table);
4354 tracing_buffers_read(struct file *filp, char __user *ubuf,
4355 size_t count, loff_t *ppos)
4357 struct ftrace_buffer_info *info = filp->private_data;
4358 struct trace_iterator *iter = &info->iter;
4366 info->spare = ring_buffer_alloc_read_page(iter->tr->buffer, iter->cpu_file);
4370 /* Do we have previous read data to read? */
4371 if (info->read < PAGE_SIZE)
4375 trace_access_lock(iter->cpu_file);
4376 ret = ring_buffer_read_page(iter->tr->buffer,
4380 trace_access_unlock(iter->cpu_file);
4383 if (trace_empty(iter)) {
4384 if ((filp->f_flags & O_NONBLOCK))
4386 iter->trace->wait_pipe(iter);
4387 if (signal_pending(current))
4397 size = PAGE_SIZE - info->read;
4401 ret = copy_to_user(ubuf, info->spare + info->read, size);
4412 static int tracing_buffers_release(struct inode *inode, struct file *file)
4414 struct ftrace_buffer_info *info = file->private_data;
4415 struct trace_iterator *iter = &info->iter;
4418 ring_buffer_free_read_page(iter->tr->buffer, info->spare);
4425 struct ring_buffer *buffer;
4430 static void buffer_pipe_buf_release(struct pipe_inode_info *pipe,
4431 struct pipe_buffer *buf)
4433 struct buffer_ref *ref = (struct buffer_ref *)buf->private;
4438 ring_buffer_free_read_page(ref->buffer, ref->page);
4443 static void buffer_pipe_buf_get(struct pipe_inode_info *pipe,
4444 struct pipe_buffer *buf)
4446 struct buffer_ref *ref = (struct buffer_ref *)buf->private;
4451 /* Pipe buffer operations for a buffer. */
4452 static const struct pipe_buf_operations buffer_pipe_buf_ops = {
4454 .map = generic_pipe_buf_map,
4455 .unmap = generic_pipe_buf_unmap,
4456 .confirm = generic_pipe_buf_confirm,
4457 .release = buffer_pipe_buf_release,
4458 .steal = generic_pipe_buf_steal,
4459 .get = buffer_pipe_buf_get,
4463 * Callback from splice_to_pipe(), if we need to release some pages
4464 * at the end of the spd in case we error'ed out in filling the pipe.
4466 static void buffer_spd_release(struct splice_pipe_desc *spd, unsigned int i)
4468 struct buffer_ref *ref =
4469 (struct buffer_ref *)spd->partial[i].private;
4474 ring_buffer_free_read_page(ref->buffer, ref->page);
4476 spd->partial[i].private = 0;
4480 tracing_buffers_splice_read(struct file *file, loff_t *ppos,
4481 struct pipe_inode_info *pipe, size_t len,
4484 struct ftrace_buffer_info *info = file->private_data;
4485 struct trace_iterator *iter = &info->iter;
4486 struct partial_page partial_def[PIPE_DEF_BUFFERS];
4487 struct page *pages_def[PIPE_DEF_BUFFERS];
4488 struct splice_pipe_desc spd = {
4490 .partial = partial_def,
4491 .nr_pages_max = PIPE_DEF_BUFFERS,
4493 .ops = &buffer_pipe_buf_ops,
4494 .spd_release = buffer_spd_release,
4496 struct buffer_ref *ref;
4497 int entries, size, i;
4500 if (splice_grow_spd(pipe, &spd))
4503 if (*ppos & (PAGE_SIZE - 1)) {
4508 if (len & (PAGE_SIZE - 1)) {
4509 if (len < PAGE_SIZE) {
4517 trace_access_lock(iter->cpu_file);
4518 entries = ring_buffer_entries_cpu(iter->tr->buffer, iter->cpu_file);
4520 for (i = 0; i < pipe->buffers && len && entries; i++, len -= PAGE_SIZE) {
4524 ref = kzalloc(sizeof(*ref), GFP_KERNEL);
4529 ref->buffer = iter->tr->buffer;
4530 ref->page = ring_buffer_alloc_read_page(ref->buffer, iter->cpu_file);
4536 r = ring_buffer_read_page(ref->buffer, &ref->page,
4537 len, iter->cpu_file, 1);
4539 ring_buffer_free_read_page(ref->buffer, ref->page);
4545 * zero out any left over data, this is going to
4548 size = ring_buffer_page_len(ref->page);
4549 if (size < PAGE_SIZE)
4550 memset(ref->page + size, 0, PAGE_SIZE - size);
4552 page = virt_to_page(ref->page);
4554 spd.pages[i] = page;
4555 spd.partial[i].len = PAGE_SIZE;
4556 spd.partial[i].offset = 0;
4557 spd.partial[i].private = (unsigned long)ref;
4561 entries = ring_buffer_entries_cpu(iter->tr->buffer, iter->cpu_file);
4564 trace_access_unlock(iter->cpu_file);
4567 /* did we read anything? */
4568 if (!spd.nr_pages) {
4569 if ((file->f_flags & O_NONBLOCK) || (flags & SPLICE_F_NONBLOCK)) {
4573 iter->trace->wait_pipe(iter);
4574 if (signal_pending(current)) {
4581 ret = splice_to_pipe(pipe, &spd);
4582 splice_shrink_spd(&spd);
4587 static const struct file_operations tracing_buffers_fops = {
4588 .open = tracing_buffers_open,
4589 .read = tracing_buffers_read,
4590 .poll = tracing_buffers_poll,
4591 .release = tracing_buffers_release,
4592 .splice_read = tracing_buffers_splice_read,
4593 .llseek = no_llseek,
4597 tracing_stats_read(struct file *filp, char __user *ubuf,
4598 size_t count, loff_t *ppos)
4600 struct trace_cpu *tc = filp->private_data;
4601 struct trace_array *tr = tc->tr;
4602 struct trace_seq *s;
4604 unsigned long long t;
4605 unsigned long usec_rem;
4608 s = kmalloc(sizeof(*s), GFP_KERNEL);
4614 cnt = ring_buffer_entries_cpu(tr->buffer, cpu);
4615 trace_seq_printf(s, "entries: %ld\n", cnt);
4617 cnt = ring_buffer_overrun_cpu(tr->buffer, cpu);
4618 trace_seq_printf(s, "overrun: %ld\n", cnt);
4620 cnt = ring_buffer_commit_overrun_cpu(tr->buffer, cpu);
4621 trace_seq_printf(s, "commit overrun: %ld\n", cnt);
4623 cnt = ring_buffer_bytes_cpu(tr->buffer, cpu);
4624 trace_seq_printf(s, "bytes: %ld\n", cnt);
4626 if (trace_clocks[trace_clock_id].in_ns) {
4627 /* local or global for trace_clock */
4628 t = ns2usecs(ring_buffer_oldest_event_ts(tr->buffer, cpu));
4629 usec_rem = do_div(t, USEC_PER_SEC);
4630 trace_seq_printf(s, "oldest event ts: %5llu.%06lu\n",
4633 t = ns2usecs(ring_buffer_time_stamp(tr->buffer, cpu));
4634 usec_rem = do_div(t, USEC_PER_SEC);
4635 trace_seq_printf(s, "now ts: %5llu.%06lu\n", t, usec_rem);
4637 /* counter or tsc mode for trace_clock */
4638 trace_seq_printf(s, "oldest event ts: %llu\n",
4639 ring_buffer_oldest_event_ts(tr->buffer, cpu));
4641 trace_seq_printf(s, "now ts: %llu\n",
4642 ring_buffer_time_stamp(tr->buffer, cpu));
4645 cnt = ring_buffer_dropped_events_cpu(tr->buffer, cpu);
4646 trace_seq_printf(s, "dropped events: %ld\n", cnt);
4648 cnt = ring_buffer_read_events_cpu(tr->buffer, cpu);
4649 trace_seq_printf(s, "read events: %ld\n", cnt);
4651 count = simple_read_from_buffer(ubuf, count, ppos, s->buffer, s->len);
4658 static const struct file_operations tracing_stats_fops = {
4659 .open = tracing_open_generic,
4660 .read = tracing_stats_read,
4661 .llseek = generic_file_llseek,
4664 #ifdef CONFIG_DYNAMIC_FTRACE
4666 int __weak ftrace_arch_read_dyn_info(char *buf, int size)
4672 tracing_read_dyn_info(struct file *filp, char __user *ubuf,
4673 size_t cnt, loff_t *ppos)
4675 static char ftrace_dyn_info_buffer[1024];
4676 static DEFINE_MUTEX(dyn_info_mutex);
4677 unsigned long *p = filp->private_data;
4678 char *buf = ftrace_dyn_info_buffer;
4679 int size = ARRAY_SIZE(ftrace_dyn_info_buffer);
4682 mutex_lock(&dyn_info_mutex);
4683 r = sprintf(buf, "%ld ", *p);
4685 r += ftrace_arch_read_dyn_info(buf+r, (size-1)-r);
4688 r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
4690 mutex_unlock(&dyn_info_mutex);
4695 static const struct file_operations tracing_dyn_info_fops = {
4696 .open = tracing_open_generic,
4697 .read = tracing_read_dyn_info,
4698 .llseek = generic_file_llseek,
4702 struct dentry *tracing_init_dentry_tr(struct trace_array *tr)
4709 if (!debugfs_initialized())
4712 if (tr->flags & TRACE_ARRAY_FL_GLOBAL)
4713 tr->dir = debugfs_create_dir("tracing", NULL);
4715 if (!tr->dir && !once) {
4717 pr_warning("Could not create debugfs directory 'tracing'\n");
4724 struct dentry *tracing_init_dentry(void)
4726 return tracing_init_dentry_tr(&global_trace);
4729 static struct dentry *tracing_dentry_percpu(struct trace_array *tr, int cpu)
4731 struct dentry *d_tracer;
4734 return tr->percpu_dir;
4736 d_tracer = tracing_init_dentry_tr(tr);
4740 tr->percpu_dir = debugfs_create_dir("per_cpu", d_tracer);
4742 WARN_ONCE(!tr->percpu_dir,
4743 "Could not create debugfs directory 'per_cpu/%d'\n", cpu);
4745 return tr->percpu_dir;
4749 tracing_init_debugfs_percpu(struct trace_array *tr, long cpu)
4751 struct trace_array_cpu *data = per_cpu_ptr(tr->data, cpu);
4752 struct dentry *d_percpu = tracing_dentry_percpu(tr, cpu);
4753 struct dentry *d_cpu;
4754 char cpu_dir[30]; /* 30 characters should be more than enough */
4759 snprintf(cpu_dir, 30, "cpu%ld", cpu);
4760 d_cpu = debugfs_create_dir(cpu_dir, d_percpu);
4762 pr_warning("Could not create debugfs '%s' entry\n", cpu_dir);
4766 /* per cpu trace_pipe */
4767 trace_create_file("trace_pipe", 0444, d_cpu,
4768 (void *)&data->trace_cpu, &tracing_pipe_fops);
4771 trace_create_file("trace", 0644, d_cpu,
4772 (void *)&data->trace_cpu, &tracing_fops);
4774 trace_create_file("trace_pipe_raw", 0444, d_cpu,
4775 (void *)&data->trace_cpu, &tracing_buffers_fops);
4777 trace_create_file("stats", 0444, d_cpu,
4778 (void *)&data->trace_cpu, &tracing_stats_fops);
4780 trace_create_file("buffer_size_kb", 0444, d_cpu,
4781 (void *)&data->trace_cpu, &tracing_entries_fops);
4784 #ifdef CONFIG_FTRACE_SELFTEST
4785 /* Let selftest have access to static functions in this file */
4786 #include "trace_selftest.c"
4789 struct trace_option_dentry {
4790 struct tracer_opt *opt;
4791 struct tracer_flags *flags;
4792 struct trace_array *tr;
4793 struct dentry *entry;
4797 trace_options_read(struct file *filp, char __user *ubuf, size_t cnt,
4800 struct trace_option_dentry *topt = filp->private_data;
4803 if (topt->flags->val & topt->opt->bit)
4808 return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2);
4812 trace_options_write(struct file *filp, const char __user *ubuf, size_t cnt,
4815 struct trace_option_dentry *topt = filp->private_data;
4819 ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
4823 if (val != 0 && val != 1)
4826 if (!!(topt->flags->val & topt->opt->bit) != val) {
4827 mutex_lock(&trace_types_lock);
4828 ret = __set_tracer_option(topt->tr->current_trace, topt->flags,
4830 mutex_unlock(&trace_types_lock);
4841 static const struct file_operations trace_options_fops = {
4842 .open = tracing_open_generic,
4843 .read = trace_options_read,
4844 .write = trace_options_write,
4845 .llseek = generic_file_llseek,
4849 trace_options_core_read(struct file *filp, char __user *ubuf, size_t cnt,
4852 long index = (long)filp->private_data;
4855 if (trace_flags & (1 << index))
4860 return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2);
4864 trace_options_core_write(struct file *filp, const char __user *ubuf, size_t cnt,
4867 struct trace_array *tr = &global_trace;
4868 long index = (long)filp->private_data;
4872 ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
4876 if (val != 0 && val != 1)
4879 mutex_lock(&trace_types_lock);
4880 ret = set_tracer_flag(tr, 1 << index, val);
4881 mutex_unlock(&trace_types_lock);
4891 static const struct file_operations trace_options_core_fops = {
4892 .open = tracing_open_generic,
4893 .read = trace_options_core_read,
4894 .write = trace_options_core_write,
4895 .llseek = generic_file_llseek,
4898 struct dentry *trace_create_file(const char *name,
4900 struct dentry *parent,
4902 const struct file_operations *fops)
4906 ret = debugfs_create_file(name, mode, parent, data, fops);
4908 pr_warning("Could not create debugfs '%s' entry\n", name);
4914 static struct dentry *trace_options_init_dentry(struct trace_array *tr)
4916 struct dentry *d_tracer;
4921 d_tracer = tracing_init_dentry_tr(tr);
4925 tr->options = debugfs_create_dir("options", d_tracer);
4927 pr_warning("Could not create debugfs directory 'options'\n");
4935 create_trace_option_file(struct trace_array *tr,
4936 struct trace_option_dentry *topt,
4937 struct tracer_flags *flags,
4938 struct tracer_opt *opt)
4940 struct dentry *t_options;
4942 t_options = trace_options_init_dentry(tr);
4946 topt->flags = flags;
4950 topt->entry = trace_create_file(opt->name, 0644, t_options, topt,
4951 &trace_options_fops);
4955 static struct trace_option_dentry *
4956 create_trace_option_files(struct trace_array *tr, struct tracer *tracer)
4958 struct trace_option_dentry *topts;
4959 struct tracer_flags *flags;
4960 struct tracer_opt *opts;
4966 flags = tracer->flags;
4968 if (!flags || !flags->opts)
4973 for (cnt = 0; opts[cnt].name; cnt++)
4976 topts = kcalloc(cnt + 1, sizeof(*topts), GFP_KERNEL);
4980 for (cnt = 0; opts[cnt].name; cnt++)
4981 create_trace_option_file(tr, &topts[cnt], flags,
4988 destroy_trace_option_files(struct trace_option_dentry *topts)
4995 for (cnt = 0; topts[cnt].opt; cnt++) {
4996 if (topts[cnt].entry)
4997 debugfs_remove(topts[cnt].entry);
5003 static struct dentry *
5004 create_trace_option_core_file(struct trace_array *tr,
5005 const char *option, long index)
5007 struct dentry *t_options;
5009 t_options = trace_options_init_dentry(tr);
5013 return trace_create_file(option, 0644, t_options, (void *)index,
5014 &trace_options_core_fops);
5017 static __init void create_trace_options_dir(struct trace_array *tr)
5019 struct dentry *t_options;
5022 t_options = trace_options_init_dentry(tr);
5026 for (i = 0; trace_options[i]; i++)
5027 create_trace_option_core_file(tr, trace_options[i], i);
5031 rb_simple_read(struct file *filp, char __user *ubuf,
5032 size_t cnt, loff_t *ppos)
5034 struct trace_array *tr = filp->private_data;
5035 struct ring_buffer *buffer = tr->buffer;
5040 r = ring_buffer_record_is_on(buffer);
5044 r = sprintf(buf, "%d\n", r);
5046 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
5050 rb_simple_write(struct file *filp, const char __user *ubuf,
5051 size_t cnt, loff_t *ppos)
5053 struct trace_array *tr = filp->private_data;
5054 struct ring_buffer *buffer = tr->buffer;
5058 ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
5063 mutex_lock(&trace_types_lock);
5065 ring_buffer_record_on(buffer);
5066 if (tr->current_trace->start)
5067 tr->current_trace->start(tr);
5069 ring_buffer_record_off(buffer);
5070 if (tr->current_trace->stop)
5071 tr->current_trace->stop(tr);
5073 mutex_unlock(&trace_types_lock);
5081 static const struct file_operations rb_simple_fops = {
5082 .open = tracing_open_generic,
5083 .read = rb_simple_read,
5084 .write = rb_simple_write,
5085 .llseek = default_llseek,
5088 struct dentry *trace_instance_dir;
5091 init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer);
5093 static int new_instance_create(const char *name)
5095 enum ring_buffer_flags rb_flags;
5096 struct trace_array *tr;
5100 mutex_lock(&trace_types_lock);
5103 list_for_each_entry(tr, &ftrace_trace_arrays, list) {
5104 if (tr->name && strcmp(tr->name, name) == 0)
5109 tr = kzalloc(sizeof(*tr), GFP_KERNEL);
5113 tr->name = kstrdup(name, GFP_KERNEL);
5117 raw_spin_lock_init(&tr->start_lock);
5119 tr->current_trace = &nop_trace;
5121 INIT_LIST_HEAD(&tr->systems);
5122 INIT_LIST_HEAD(&tr->events);
5124 rb_flags = trace_flags & TRACE_ITER_OVERWRITE ? RB_FL_OVERWRITE : 0;
5126 tr->buffer = ring_buffer_alloc(trace_buf_size, rb_flags);
5130 tr->data = alloc_percpu(struct trace_array_cpu);
5134 for_each_tracing_cpu(i) {
5135 memset(per_cpu_ptr(tr->data, i), 0, sizeof(struct trace_array_cpu));
5136 per_cpu_ptr(tr->data, i)->trace_cpu.cpu = i;
5137 per_cpu_ptr(tr->data, i)->trace_cpu.tr = tr;
5140 /* Holder for file callbacks */
5141 tr->trace_cpu.cpu = RING_BUFFER_ALL_CPUS;
5142 tr->trace_cpu.tr = tr;
5144 tr->dir = debugfs_create_dir(name, trace_instance_dir);
5148 ret = event_trace_add_tracer(tr->dir, tr);
5152 init_tracer_debugfs(tr, tr->dir);
5154 list_add(&tr->list, &ftrace_trace_arrays);
5156 mutex_unlock(&trace_types_lock);
5162 ring_buffer_free(tr->buffer);
5167 mutex_unlock(&trace_types_lock);
5173 static int instance_delete(const char *name)
5175 struct trace_array *tr;
5179 mutex_lock(&trace_types_lock);
5182 list_for_each_entry(tr, &ftrace_trace_arrays, list) {
5183 if (tr->name && strcmp(tr->name, name) == 0) {
5191 list_del(&tr->list);
5193 event_trace_del_tracer(tr);
5194 debugfs_remove_recursive(tr->dir);
5195 free_percpu(tr->data);
5196 ring_buffer_free(tr->buffer);
5204 mutex_unlock(&trace_types_lock);
5209 static int instance_mkdir (struct inode *inode, struct dentry *dentry, umode_t mode)
5211 struct dentry *parent;
5214 /* Paranoid: Make sure the parent is the "instances" directory */
5215 parent = hlist_entry(inode->i_dentry.first, struct dentry, d_alias);
5216 if (WARN_ON_ONCE(parent != trace_instance_dir))
5220 * The inode mutex is locked, but debugfs_create_dir() will also
5221 * take the mutex. As the instances directory can not be destroyed
5222 * or changed in any other way, it is safe to unlock it, and
5223 * let the dentry try. If two users try to make the same dir at
5224 * the same time, then the new_instance_create() will determine the
5227 mutex_unlock(&inode->i_mutex);
5229 ret = new_instance_create(dentry->d_iname);
5231 mutex_lock(&inode->i_mutex);
5236 static int instance_rmdir(struct inode *inode, struct dentry *dentry)
5238 struct dentry *parent;
5241 /* Paranoid: Make sure the parent is the "instances" directory */
5242 parent = hlist_entry(inode->i_dentry.first, struct dentry, d_alias);
5243 if (WARN_ON_ONCE(parent != trace_instance_dir))
5246 /* The caller did a dget() on dentry */
5247 mutex_unlock(&dentry->d_inode->i_mutex);
5250 * The inode mutex is locked, but debugfs_create_dir() will also
5251 * take the mutex. As the instances directory can not be destroyed
5252 * or changed in any other way, it is safe to unlock it, and
5253 * let the dentry try. If two users try to make the same dir at
5254 * the same time, then the instance_delete() will determine the
5257 mutex_unlock(&inode->i_mutex);
5259 ret = instance_delete(dentry->d_iname);
5261 mutex_lock_nested(&inode->i_mutex, I_MUTEX_PARENT);
5262 mutex_lock(&dentry->d_inode->i_mutex);
5267 static const struct inode_operations instance_dir_inode_operations = {
5268 .lookup = simple_lookup,
5269 .mkdir = instance_mkdir,
5270 .rmdir = instance_rmdir,
5273 static __init void create_trace_instances(struct dentry *d_tracer)
5275 trace_instance_dir = debugfs_create_dir("instances", d_tracer);
5276 if (WARN_ON(!trace_instance_dir))
5279 /* Hijack the dir inode operations, to allow mkdir */
5280 trace_instance_dir->d_inode->i_op = &instance_dir_inode_operations;
5284 init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer)
5287 trace_create_file("trace_options", 0644, d_tracer,
5288 tr, &tracing_iter_fops);
5290 trace_create_file("trace", 0644, d_tracer,
5291 (void *)&tr->trace_cpu, &tracing_fops);
5293 trace_create_file("trace_pipe", 0444, d_tracer,
5294 (void *)&tr->trace_cpu, &tracing_pipe_fops);
5296 trace_create_file("buffer_size_kb", 0644, d_tracer,
5297 (void *)&tr->trace_cpu, &tracing_entries_fops);
5299 trace_create_file("buffer_total_size_kb", 0444, d_tracer,
5300 tr, &tracing_total_entries_fops);
5302 trace_create_file("free_buffer", 0644, d_tracer,
5303 tr, &tracing_free_buffer_fops);
5305 trace_create_file("trace_marker", 0220, d_tracer,
5306 tr, &tracing_mark_fops);
5308 trace_create_file("trace_clock", 0644, d_tracer, tr,
5311 trace_create_file("tracing_on", 0644, d_tracer,
5312 tr, &rb_simple_fops);
5315 static __init int tracer_init_debugfs(void)
5317 struct dentry *d_tracer;
5320 trace_access_lock_init();
5322 d_tracer = tracing_init_dentry();
5324 init_tracer_debugfs(&global_trace, d_tracer);
5326 trace_create_file("tracing_cpumask", 0644, d_tracer,
5327 &global_trace, &tracing_cpumask_fops);
5329 trace_create_file("available_tracers", 0444, d_tracer,
5330 &global_trace, &show_traces_fops);
5332 trace_create_file("current_tracer", 0644, d_tracer,
5333 &global_trace, &set_tracer_fops);
5335 #ifdef CONFIG_TRACER_MAX_TRACE
5336 trace_create_file("tracing_max_latency", 0644, d_tracer,
5337 &tracing_max_latency, &tracing_max_lat_fops);
5340 trace_create_file("tracing_thresh", 0644, d_tracer,
5341 &tracing_thresh, &tracing_max_lat_fops);
5343 trace_create_file("README", 0444, d_tracer,
5344 NULL, &tracing_readme_fops);
5346 trace_create_file("saved_cmdlines", 0444, d_tracer,
5347 NULL, &tracing_saved_cmdlines_fops);
5349 #ifdef CONFIG_DYNAMIC_FTRACE
5350 trace_create_file("dyn_ftrace_total_info", 0444, d_tracer,
5351 &ftrace_update_tot_cnt, &tracing_dyn_info_fops);
5354 #ifdef CONFIG_TRACER_SNAPSHOT
5355 trace_create_file("snapshot", 0644, d_tracer,
5356 (void *)&global_trace.trace_cpu, &snapshot_fops);
5359 create_trace_instances(d_tracer);
5361 create_trace_options_dir(&global_trace);
5363 for_each_tracing_cpu(cpu)
5364 tracing_init_debugfs_percpu(&global_trace, cpu);
5369 static int trace_panic_handler(struct notifier_block *this,
5370 unsigned long event, void *unused)
5372 if (ftrace_dump_on_oops)
5373 ftrace_dump(ftrace_dump_on_oops);
5377 static struct notifier_block trace_panic_notifier = {
5378 .notifier_call = trace_panic_handler,
5380 .priority = 150 /* priority: INT_MAX >= x >= 0 */
5383 static int trace_die_handler(struct notifier_block *self,
5389 if (ftrace_dump_on_oops)
5390 ftrace_dump(ftrace_dump_on_oops);
5398 static struct notifier_block trace_die_notifier = {
5399 .notifier_call = trace_die_handler,
5404 * printk is set to max of 1024, we really don't need it that big.
5405 * Nothing should be printing 1000 characters anyway.
5407 #define TRACE_MAX_PRINT 1000
5410 * Define here KERN_TRACE so that we have one place to modify
5411 * it if we decide to change what log level the ftrace dump
5414 #define KERN_TRACE KERN_EMERG
5417 trace_printk_seq(struct trace_seq *s)
5419 /* Probably should print a warning here. */
5423 /* should be zero ended, but we are paranoid. */
5424 s->buffer[s->len] = 0;
5426 printk(KERN_TRACE "%s", s->buffer);
5431 void trace_init_global_iter(struct trace_iterator *iter)
5433 iter->tr = &global_trace;
5434 iter->trace = iter->tr->current_trace;
5435 iter->cpu_file = RING_BUFFER_ALL_CPUS;
5439 __ftrace_dump(bool disable_tracing, enum ftrace_dump_mode oops_dump_mode)
5441 static arch_spinlock_t ftrace_dump_lock =
5442 (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED;
5443 /* use static because iter can be a bit big for the stack */
5444 static struct trace_iterator iter;
5445 unsigned int old_userobj;
5446 static int dump_ran;
5447 unsigned long flags;
5451 local_irq_save(flags);
5452 arch_spin_lock(&ftrace_dump_lock);
5460 /* Did function tracer already get disabled? */
5461 if (ftrace_is_dead()) {
5462 printk("# WARNING: FUNCTION TRACING IS CORRUPTED\n");
5463 printk("# MAY BE MISSING FUNCTION EVENTS\n");
5466 if (disable_tracing)
5469 /* Simulate the iterator */
5470 trace_init_global_iter(&iter);
5472 for_each_tracing_cpu(cpu) {
5473 atomic_inc(&per_cpu_ptr(iter.tr->data, cpu)->disabled);
5476 old_userobj = trace_flags & TRACE_ITER_SYM_USEROBJ;
5478 /* don't look at user memory in panic mode */
5479 trace_flags &= ~TRACE_ITER_SYM_USEROBJ;
5481 switch (oops_dump_mode) {
5483 iter.cpu_file = RING_BUFFER_ALL_CPUS;
5486 iter.cpu_file = raw_smp_processor_id();
5491 printk(KERN_TRACE "Bad dumping mode, switching to all CPUs dump\n");
5492 iter.cpu_file = RING_BUFFER_ALL_CPUS;
5495 printk(KERN_TRACE "Dumping ftrace buffer:\n");
5498 * We need to stop all tracing on all CPUS to read the
5499 * the next buffer. This is a bit expensive, but is
5500 * not done often. We fill all what we can read,
5501 * and then release the locks again.
5504 while (!trace_empty(&iter)) {
5507 printk(KERN_TRACE "---------------------------------\n");
5511 /* reset all but tr, trace, and overruns */
5512 memset(&iter.seq, 0,
5513 sizeof(struct trace_iterator) -
5514 offsetof(struct trace_iterator, seq));
5515 iter.iter_flags |= TRACE_FILE_LAT_FMT;
5518 if (trace_find_next_entry_inc(&iter) != NULL) {
5521 ret = print_trace_line(&iter);
5522 if (ret != TRACE_TYPE_NO_CONSUME)
5523 trace_consume(&iter);
5525 touch_nmi_watchdog();
5527 trace_printk_seq(&iter.seq);
5531 printk(KERN_TRACE " (ftrace buffer empty)\n");
5533 printk(KERN_TRACE "---------------------------------\n");
5536 /* Re-enable tracing if requested */
5537 if (!disable_tracing) {
5538 trace_flags |= old_userobj;
5540 for_each_tracing_cpu(cpu) {
5541 atomic_dec(&per_cpu_ptr(iter.tr->data, cpu)->disabled);
5547 arch_spin_unlock(&ftrace_dump_lock);
5548 local_irq_restore(flags);
5551 /* By default: disable tracing after the dump */
5552 void ftrace_dump(enum ftrace_dump_mode oops_dump_mode)
5554 __ftrace_dump(true, oops_dump_mode);
5556 EXPORT_SYMBOL_GPL(ftrace_dump);
5558 __init static int tracer_alloc_buffers(void)
5561 enum ring_buffer_flags rb_flags;
5566 if (!alloc_cpumask_var(&tracing_buffer_mask, GFP_KERNEL))
5569 if (!alloc_cpumask_var(&tracing_cpumask, GFP_KERNEL))
5570 goto out_free_buffer_mask;
5572 /* Only allocate trace_printk buffers if a trace_printk exists */
5573 if (__stop___trace_bprintk_fmt != __start___trace_bprintk_fmt)
5574 /* Must be called before global_trace.buffer is allocated */
5575 trace_printk_init_buffers();
5577 /* To save memory, keep the ring buffer size to its minimum */
5578 if (ring_buffer_expanded)
5579 ring_buf_size = trace_buf_size;
5583 rb_flags = trace_flags & TRACE_ITER_OVERWRITE ? RB_FL_OVERWRITE : 0;
5585 cpumask_copy(tracing_buffer_mask, cpu_possible_mask);
5586 cpumask_copy(tracing_cpumask, cpu_all_mask);
5588 raw_spin_lock_init(&global_trace.start_lock);
5590 /* TODO: make the number of buffers hot pluggable with CPUS */
5591 global_trace.buffer = ring_buffer_alloc(ring_buf_size, rb_flags);
5592 if (!global_trace.buffer) {
5593 printk(KERN_ERR "tracer: failed to allocate ring buffer!\n");
5595 goto out_free_cpumask;
5598 global_trace.data = alloc_percpu(struct trace_array_cpu);
5600 if (!global_trace.data) {
5601 printk(KERN_ERR "tracer: failed to allocate percpu memory!\n");
5603 goto out_free_cpumask;
5606 for_each_tracing_cpu(i) {
5607 memset(per_cpu_ptr(global_trace.data, i), 0, sizeof(struct trace_array_cpu));
5608 per_cpu_ptr(global_trace.data, i)->trace_cpu.cpu = i;
5609 per_cpu_ptr(global_trace.data, i)->trace_cpu.tr = &global_trace;
5612 if (global_trace.buffer_disabled)
5615 #ifdef CONFIG_TRACER_MAX_TRACE
5616 max_tr.data = alloc_percpu(struct trace_array_cpu);
5618 printk(KERN_ERR "tracer: failed to allocate percpu memory!\n");
5620 goto out_free_cpumask;
5622 max_tr.buffer = ring_buffer_alloc(1, rb_flags);
5623 raw_spin_lock_init(&max_tr.start_lock);
5624 if (!max_tr.buffer) {
5625 printk(KERN_ERR "tracer: failed to allocate max ring buffer!\n");
5627 ring_buffer_free(global_trace.buffer);
5628 goto out_free_cpumask;
5631 for_each_tracing_cpu(i) {
5632 memset(per_cpu_ptr(max_tr.data, i), 0, sizeof(struct trace_array_cpu));
5633 per_cpu_ptr(max_tr.data, i)->trace_cpu.cpu = i;
5634 per_cpu_ptr(max_tr.data, i)->trace_cpu.tr = &max_tr;
5638 /* Allocate the first page for all buffers */
5639 set_buffer_entries(&global_trace,
5640 ring_buffer_size(global_trace.buffer, 0));
5641 #ifdef CONFIG_TRACER_MAX_TRACE
5642 set_buffer_entries(&max_tr, 1);
5645 trace_init_cmdlines();
5647 register_tracer(&nop_trace);
5649 global_trace.current_trace = &nop_trace;
5651 /* All seems OK, enable tracing */
5652 tracing_disabled = 0;
5654 atomic_notifier_chain_register(&panic_notifier_list,
5655 &trace_panic_notifier);
5657 register_die_notifier(&trace_die_notifier);
5659 global_trace.flags = TRACE_ARRAY_FL_GLOBAL;
5661 /* Holder for file callbacks */
5662 global_trace.trace_cpu.cpu = RING_BUFFER_ALL_CPUS;
5663 global_trace.trace_cpu.tr = &global_trace;
5665 INIT_LIST_HEAD(&global_trace.systems);
5666 INIT_LIST_HEAD(&global_trace.events);
5667 list_add(&global_trace.list, &ftrace_trace_arrays);
5669 while (trace_boot_options) {
5672 option = strsep(&trace_boot_options, ",");
5673 trace_set_options(&global_trace, option);
5679 free_percpu(global_trace.data);
5680 free_percpu(max_tr.data);
5681 free_cpumask_var(tracing_cpumask);
5682 out_free_buffer_mask:
5683 free_cpumask_var(tracing_buffer_mask);
5688 __init static int clear_boot_tracer(void)
5691 * The default tracer at boot buffer is an init section.
5692 * This function is called in lateinit. If we did not
5693 * find the boot tracer, then clear it out, to prevent
5694 * later registration from accessing the buffer that is
5695 * about to be freed.
5697 if (!default_bootup_tracer)
5700 printk(KERN_INFO "ftrace bootup tracer '%s' not registered.\n",
5701 default_bootup_tracer);
5702 default_bootup_tracer = NULL;
5707 early_initcall(tracer_alloc_buffers);
5708 fs_initcall(tracer_init_debugfs);
5709 late_initcall(clear_boot_tracer);