2 * ring buffer based function tracer
4 * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
5 * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com>
7 * Originally taken from the RT patch by:
8 * Arnaldo Carvalho de Melo <acme@redhat.com>
10 * Based on code from the latency_tracer, that is:
11 * Copyright (C) 2004-2006 Ingo Molnar
12 * Copyright (C) 2004 William Lee Irwin III
14 #include <linux/utsrelease.h>
15 #include <linux/kallsyms.h>
16 #include <linux/seq_file.h>
17 #include <linux/notifier.h>
18 #include <linux/debugfs.h>
19 #include <linux/pagemap.h>
20 #include <linux/hardirq.h>
21 #include <linux/linkage.h>
22 #include <linux/uaccess.h>
23 #include <linux/ftrace.h>
24 #include <linux/module.h>
25 #include <linux/percpu.h>
26 #include <linux/kdebug.h>
27 #include <linux/ctype.h>
28 #include <linux/init.h>
29 #include <linux/poll.h>
30 #include <linux/gfp.h>
32 #include <linux/kprobes.h>
33 #include <linux/seq_file.h>
34 #include <linux/writeback.h>
36 #include <linux/stacktrace.h>
37 #include <linux/ring_buffer.h>
38 #include <linux/irqflags.h>
42 #define TRACE_BUFFER_FLAGS (RB_FL_OVERWRITE)
44 unsigned long __read_mostly tracing_max_latency
= (cycle_t
)ULONG_MAX
;
45 unsigned long __read_mostly tracing_thresh
;
47 /* For tracers that don't implement custom flags */
48 static struct tracer_opt dummy_tracer_opt
[] = {
52 static struct tracer_flags dummy_tracer_flags
= {
54 .opts
= dummy_tracer_opt
57 static int dummy_set_flag(u32 old_flags
, u32 bit
, int set
)
63 * Kill all tracing for good (never come back).
64 * It is initialized to 1 but will turn to zero if the initialization
65 * of the tracer is successful. But that is the only place that sets
68 int tracing_disabled
= 1;
70 static DEFINE_PER_CPU(local_t
, ftrace_cpu_disabled
);
72 static inline void ftrace_disable_cpu(void)
75 local_inc(&__get_cpu_var(ftrace_cpu_disabled
));
78 static inline void ftrace_enable_cpu(void)
80 local_dec(&__get_cpu_var(ftrace_cpu_disabled
));
84 static cpumask_t __read_mostly tracing_buffer_mask
;
86 #define for_each_tracing_cpu(cpu) \
87 for_each_cpu_mask(cpu, tracing_buffer_mask)
90 * ftrace_dump_on_oops - variable to dump ftrace buffer on oops
92 * If there is an oops (or kernel panic) and the ftrace_dump_on_oops
93 * is set, then ftrace_dump is called. This will output the contents
94 * of the ftrace buffers to the console. This is very useful for
95 * capturing traces that lead to crashes and outputing it to a
98 * It is default off, but you can enable it with either specifying
99 * "ftrace_dump_on_oops" in the kernel command line, or setting
100 * /proc/sys/kernel/ftrace_dump_on_oops to true.
102 int ftrace_dump_on_oops
;
104 static int tracing_set_tracer(char *buf
);
106 static int __init
set_ftrace(char *str
)
108 tracing_set_tracer(str
);
111 __setup("ftrace", set_ftrace
);
113 static int __init
set_ftrace_dump_on_oops(char *str
)
115 ftrace_dump_on_oops
= 1;
118 __setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops
);
121 ns2usecs(cycle_t nsec
)
128 cycle_t
ftrace_now(int cpu
)
130 u64 ts
= ring_buffer_time_stamp(cpu
);
131 ring_buffer_normalize_time_stamp(cpu
, &ts
);
136 * The global_trace is the descriptor that holds the tracing
137 * buffers for the live tracing. For each CPU, it contains
138 * a link list of pages that will store trace entries. The
139 * page descriptor of the pages in the memory is used to hold
140 * the link list by linking the lru item in the page descriptor
141 * to each of the pages in the buffer per CPU.
143 * For each active CPU there is a data field that holds the
144 * pages for the buffer for that CPU. Each CPU has the same number
145 * of pages allocated for its buffer.
147 static struct trace_array global_trace
;
149 static DEFINE_PER_CPU(struct trace_array_cpu
, global_trace_cpu
);
152 * The max_tr is used to snapshot the global_trace when a maximum
153 * latency is reached. Some tracers will use this to store a maximum
154 * trace while it continues examining live traces.
156 * The buffers for the max_tr are set up the same as the global_trace.
157 * When a snapshot is taken, the link list of the max_tr is swapped
158 * with the link list of the global_trace and the buffers are reset for
159 * the global_trace so the tracing can continue.
161 static struct trace_array max_tr
;
163 static DEFINE_PER_CPU(struct trace_array_cpu
, max_data
);
165 /* tracer_enabled is used to toggle activation of a tracer */
166 static int tracer_enabled
= 1;
169 * tracing_is_enabled - return tracer_enabled status
171 * This function is used by other tracers to know the status
172 * of the tracer_enabled flag. Tracers may use this function
173 * to know if it should enable their features when starting
174 * up. See irqsoff tracer for an example (start_irqsoff_tracer).
176 int tracing_is_enabled(void)
178 return tracer_enabled
;
181 /* function tracing enabled */
182 int ftrace_function_enabled
;
185 * trace_buf_size is the size in bytes that is allocated
186 * for a buffer. Note, the number of bytes is always rounded
189 * This number is purposely set to a low number of 16384.
190 * If the dump on oops happens, it will be much appreciated
191 * to not have to wait for all that output. Anyway this can be
192 * boot time and run time configurable.
194 #define TRACE_BUF_SIZE_DEFAULT 1441792UL /* 16384 * 88 (sizeof(entry)) */
196 static unsigned long trace_buf_size
= TRACE_BUF_SIZE_DEFAULT
;
198 /* trace_types holds a link list of available tracers. */
199 static struct tracer
*trace_types __read_mostly
;
201 /* current_trace points to the tracer that is currently active */
202 static struct tracer
*current_trace __read_mostly
;
205 * max_tracer_type_len is used to simplify the allocating of
206 * buffers to read userspace tracer names. We keep track of
207 * the longest tracer name registered.
209 static int max_tracer_type_len
;
212 * trace_types_lock is used to protect the trace_types list.
213 * This lock is also used to keep user access serialized.
214 * Accesses from userspace will grab this lock while userspace
215 * activities happen inside the kernel.
217 static DEFINE_MUTEX(trace_types_lock
);
219 /* trace_wait is a waitqueue for tasks blocked on trace_poll */
220 static DECLARE_WAIT_QUEUE_HEAD(trace_wait
);
222 /* trace_flags holds trace_options default values */
223 unsigned long trace_flags
= TRACE_ITER_PRINT_PARENT
| TRACE_ITER_PRINTK
|
227 * trace_wake_up - wake up tasks waiting for trace input
229 * Simply wakes up any task that is blocked on the trace_wait
230 * queue. These is used with trace_poll for tasks polling the trace.
232 void trace_wake_up(void)
235 * The runqueue_is_locked() can fail, but this is the best we
238 if (!(trace_flags
& TRACE_ITER_BLOCK
) && !runqueue_is_locked())
239 wake_up(&trace_wait
);
242 static int __init
set_buf_size(char *str
)
244 unsigned long buf_size
;
249 ret
= strict_strtoul(str
, 0, &buf_size
);
250 /* nr_entries can not be zero */
251 if (ret
< 0 || buf_size
== 0)
253 trace_buf_size
= buf_size
;
256 __setup("trace_buf_size=", set_buf_size
);
258 unsigned long nsecs_to_usecs(unsigned long nsecs
)
263 /* These must match the bit postions in trace_iterator_flags */
264 static const char *trace_options
[] = {
285 * ftrace_max_lock is used to protect the swapping of buffers
286 * when taking a max snapshot. The buffers themselves are
287 * protected by per_cpu spinlocks. But the action of the swap
288 * needs its own lock.
290 * This is defined as a raw_spinlock_t in order to help
291 * with performance when lockdep debugging is enabled.
293 static raw_spinlock_t ftrace_max_lock
=
294 (raw_spinlock_t
)__RAW_SPIN_LOCK_UNLOCKED
;
297 * Copy the new maximum trace into the separate maximum-trace
298 * structure. (this way the maximum trace is permanently saved,
299 * for later retrieval via /debugfs/tracing/latency_trace)
302 __update_max_tr(struct trace_array
*tr
, struct task_struct
*tsk
, int cpu
)
304 struct trace_array_cpu
*data
= tr
->data
[cpu
];
307 max_tr
.time_start
= data
->preempt_timestamp
;
309 data
= max_tr
.data
[cpu
];
310 data
->saved_latency
= tracing_max_latency
;
312 memcpy(data
->comm
, tsk
->comm
, TASK_COMM_LEN
);
313 data
->pid
= tsk
->pid
;
314 data
->uid
= tsk
->uid
;
315 data
->nice
= tsk
->static_prio
- 20 - MAX_RT_PRIO
;
316 data
->policy
= tsk
->policy
;
317 data
->rt_priority
= tsk
->rt_priority
;
319 /* record this tasks comm */
320 tracing_record_cmdline(current
);
324 * trace_seq_printf - sequence printing of trace information
325 * @s: trace sequence descriptor
326 * @fmt: printf format string
328 * The tracer may use either sequence operations or its own
329 * copy to user routines. To simplify formating of a trace
330 * trace_seq_printf is used to store strings into a special
331 * buffer (@s). Then the output may be either used by
332 * the sequencer or pulled into another buffer.
335 trace_seq_printf(struct trace_seq
*s
, const char *fmt
, ...)
337 int len
= (PAGE_SIZE
- 1) - s
->len
;
345 ret
= vsnprintf(s
->buffer
+ s
->len
, len
, fmt
, ap
);
348 /* If we can't write it all, don't bother writing anything */
358 * trace_seq_puts - trace sequence printing of simple string
359 * @s: trace sequence descriptor
360 * @str: simple string to record
362 * The tracer may use either the sequence operations or its own
363 * copy to user routines. This function records a simple string
364 * into a special buffer (@s) for later retrieval by a sequencer
365 * or other mechanism.
368 trace_seq_puts(struct trace_seq
*s
, const char *str
)
370 int len
= strlen(str
);
372 if (len
> ((PAGE_SIZE
- 1) - s
->len
))
375 memcpy(s
->buffer
+ s
->len
, str
, len
);
382 trace_seq_putc(struct trace_seq
*s
, unsigned char c
)
384 if (s
->len
>= (PAGE_SIZE
- 1))
387 s
->buffer
[s
->len
++] = c
;
393 trace_seq_putmem(struct trace_seq
*s
, void *mem
, size_t len
)
395 if (len
> ((PAGE_SIZE
- 1) - s
->len
))
398 memcpy(s
->buffer
+ s
->len
, mem
, len
);
404 #define MAX_MEMHEX_BYTES 8
405 #define HEX_CHARS (MAX_MEMHEX_BYTES*2 + 1)
408 trace_seq_putmem_hex(struct trace_seq
*s
, void *mem
, size_t len
)
410 unsigned char hex
[HEX_CHARS
];
411 unsigned char *data
= mem
;
415 for (i
= 0, j
= 0; i
< len
; i
++) {
417 for (i
= len
-1, j
= 0; i
>= 0; i
--) {
419 hex
[j
++] = hex_asc_hi(data
[i
]);
420 hex
[j
++] = hex_asc_lo(data
[i
]);
424 return trace_seq_putmem(s
, hex
, j
);
428 trace_seq_path(struct trace_seq
*s
, struct path
*path
)
432 if (s
->len
>= (PAGE_SIZE
- 1))
434 p
= d_path(path
, s
->buffer
+ s
->len
, PAGE_SIZE
- s
->len
);
436 p
= mangle_path(s
->buffer
+ s
->len
, p
, "\n");
438 s
->len
= p
- s
->buffer
;
442 s
->buffer
[s
->len
++] = '?';
450 trace_seq_reset(struct trace_seq
*s
)
456 ssize_t
trace_seq_to_user(struct trace_seq
*s
, char __user
*ubuf
, size_t cnt
)
461 if (s
->len
<= s
->readpos
)
464 len
= s
->len
- s
->readpos
;
467 ret
= copy_to_user(ubuf
, s
->buffer
+ s
->readpos
, cnt
);
476 trace_print_seq(struct seq_file
*m
, struct trace_seq
*s
)
478 int len
= s
->len
>= PAGE_SIZE
? PAGE_SIZE
- 1 : s
->len
;
481 seq_puts(m
, s
->buffer
);
487 * update_max_tr - snapshot all trace buffers from global_trace to max_tr
489 * @tsk: the task with the latency
490 * @cpu: The cpu that initiated the trace.
492 * Flip the buffers between the @tr and the max_tr and record information
493 * about which task was the cause of this latency.
496 update_max_tr(struct trace_array
*tr
, struct task_struct
*tsk
, int cpu
)
498 struct ring_buffer
*buf
= tr
->buffer
;
500 WARN_ON_ONCE(!irqs_disabled());
501 __raw_spin_lock(&ftrace_max_lock
);
503 tr
->buffer
= max_tr
.buffer
;
506 ftrace_disable_cpu();
507 ring_buffer_reset(tr
->buffer
);
510 __update_max_tr(tr
, tsk
, cpu
);
511 __raw_spin_unlock(&ftrace_max_lock
);
515 * update_max_tr_single - only copy one trace over, and reset the rest
517 * @tsk - task with the latency
518 * @cpu - the cpu of the buffer to copy.
520 * Flip the trace of a single CPU buffer between the @tr and the max_tr.
523 update_max_tr_single(struct trace_array
*tr
, struct task_struct
*tsk
, int cpu
)
527 WARN_ON_ONCE(!irqs_disabled());
528 __raw_spin_lock(&ftrace_max_lock
);
530 ftrace_disable_cpu();
532 ring_buffer_reset(max_tr
.buffer
);
533 ret
= ring_buffer_swap_cpu(max_tr
.buffer
, tr
->buffer
, cpu
);
539 __update_max_tr(tr
, tsk
, cpu
);
540 __raw_spin_unlock(&ftrace_max_lock
);
544 * register_tracer - register a tracer with the ftrace system.
545 * @type - the plugin for the tracer
547 * Register a new plugin tracer.
549 int register_tracer(struct tracer
*type
)
556 pr_info("Tracer must have a name\n");
561 * When this gets called we hold the BKL which means that
562 * preemption is disabled. Various trace selftests however
563 * need to disable and enable preemption for successful tests.
564 * So we drop the BKL here and grab it after the tests again.
567 mutex_lock(&trace_types_lock
);
569 for (t
= trace_types
; t
; t
= t
->next
) {
570 if (strcmp(type
->name
, t
->name
) == 0) {
572 pr_info("Trace %s already registered\n",
580 type
->set_flag
= &dummy_set_flag
;
582 type
->flags
= &dummy_tracer_flags
;
584 if (!type
->flags
->opts
)
585 type
->flags
->opts
= dummy_tracer_opt
;
587 #ifdef CONFIG_FTRACE_STARTUP_TEST
588 if (type
->selftest
) {
589 struct tracer
*saved_tracer
= current_trace
;
590 struct trace_array
*tr
= &global_trace
;
593 * Run a selftest on this tracer.
594 * Here we reset the trace buffer, and set the current
595 * tracer to be this tracer. The tracer can then run some
596 * internal tracing to verify that everything is in order.
597 * If we fail, we do not register this tracer.
599 for_each_tracing_cpu(i
)
600 tracing_reset(tr
, i
);
602 current_trace
= type
;
603 /* the test is responsible for initializing and enabling */
604 pr_info("Testing tracer %s: ", type
->name
);
605 ret
= type
->selftest(type
, tr
);
606 /* the test is responsible for resetting too */
607 current_trace
= saved_tracer
;
609 printk(KERN_CONT
"FAILED!\n");
612 /* Only reset on passing, to avoid touching corrupted buffers */
613 for_each_tracing_cpu(i
)
614 tracing_reset(tr
, i
);
616 printk(KERN_CONT
"PASSED\n");
620 type
->next
= trace_types
;
622 len
= strlen(type
->name
);
623 if (len
> max_tracer_type_len
)
624 max_tracer_type_len
= len
;
627 mutex_unlock(&trace_types_lock
);
633 void unregister_tracer(struct tracer
*type
)
638 mutex_lock(&trace_types_lock
);
639 for (t
= &trace_types
; *t
; t
= &(*t
)->next
) {
643 pr_info("Trace %s not registered\n", type
->name
);
648 if (strlen(type
->name
) != max_tracer_type_len
)
651 max_tracer_type_len
= 0;
652 for (t
= &trace_types
; *t
; t
= &(*t
)->next
) {
653 len
= strlen((*t
)->name
);
654 if (len
> max_tracer_type_len
)
655 max_tracer_type_len
= len
;
658 mutex_unlock(&trace_types_lock
);
661 void tracing_reset(struct trace_array
*tr
, int cpu
)
663 ftrace_disable_cpu();
664 ring_buffer_reset_cpu(tr
->buffer
, cpu
);
668 #define SAVED_CMDLINES 128
669 static unsigned map_pid_to_cmdline
[PID_MAX_DEFAULT
+1];
670 static unsigned map_cmdline_to_pid
[SAVED_CMDLINES
];
671 static char saved_cmdlines
[SAVED_CMDLINES
][TASK_COMM_LEN
];
672 static int cmdline_idx
;
673 static DEFINE_SPINLOCK(trace_cmdline_lock
);
675 /* temporary disable recording */
676 atomic_t trace_record_cmdline_disabled __read_mostly
;
678 static void trace_init_cmdlines(void)
680 memset(&map_pid_to_cmdline
, -1, sizeof(map_pid_to_cmdline
));
681 memset(&map_cmdline_to_pid
, -1, sizeof(map_cmdline_to_pid
));
685 static int trace_stop_count
;
686 static DEFINE_SPINLOCK(tracing_start_lock
);
689 * ftrace_off_permanent - disable all ftrace code permanently
691 * This should only be called when a serious anomally has
692 * been detected. This will turn off the function tracing,
693 * ring buffers, and other tracing utilites. It takes no
694 * locks and can be called from any context.
696 void ftrace_off_permanent(void)
698 tracing_disabled
= 1;
700 tracing_off_permanent();
704 * tracing_start - quick start of the tracer
706 * If tracing is enabled but was stopped by tracing_stop,
707 * this will start the tracer back up.
709 void tracing_start(void)
711 struct ring_buffer
*buffer
;
714 if (tracing_disabled
)
717 spin_lock_irqsave(&tracing_start_lock
, flags
);
718 if (--trace_stop_count
)
721 if (trace_stop_count
< 0) {
722 /* Someone screwed up their debugging */
724 trace_stop_count
= 0;
729 buffer
= global_trace
.buffer
;
731 ring_buffer_record_enable(buffer
);
733 buffer
= max_tr
.buffer
;
735 ring_buffer_record_enable(buffer
);
739 spin_unlock_irqrestore(&tracing_start_lock
, flags
);
743 * tracing_stop - quick stop of the tracer
745 * Light weight way to stop tracing. Use in conjunction with
748 void tracing_stop(void)
750 struct ring_buffer
*buffer
;
754 spin_lock_irqsave(&tracing_start_lock
, flags
);
755 if (trace_stop_count
++)
758 buffer
= global_trace
.buffer
;
760 ring_buffer_record_disable(buffer
);
762 buffer
= max_tr
.buffer
;
764 ring_buffer_record_disable(buffer
);
767 spin_unlock_irqrestore(&tracing_start_lock
, flags
);
770 void trace_stop_cmdline_recording(void);
772 static void trace_save_cmdline(struct task_struct
*tsk
)
777 if (!tsk
->pid
|| unlikely(tsk
->pid
> PID_MAX_DEFAULT
))
781 * It's not the end of the world if we don't get
782 * the lock, but we also don't want to spin
783 * nor do we want to disable interrupts,
784 * so if we miss here, then better luck next time.
786 if (!spin_trylock(&trace_cmdline_lock
))
789 idx
= map_pid_to_cmdline
[tsk
->pid
];
790 if (idx
>= SAVED_CMDLINES
) {
791 idx
= (cmdline_idx
+ 1) % SAVED_CMDLINES
;
793 map
= map_cmdline_to_pid
[idx
];
794 if (map
<= PID_MAX_DEFAULT
)
795 map_pid_to_cmdline
[map
] = (unsigned)-1;
797 map_pid_to_cmdline
[tsk
->pid
] = idx
;
802 memcpy(&saved_cmdlines
[idx
], tsk
->comm
, TASK_COMM_LEN
);
804 spin_unlock(&trace_cmdline_lock
);
807 static char *trace_find_cmdline(int pid
)
809 char *cmdline
= "<...>";
815 if (pid
> PID_MAX_DEFAULT
)
818 map
= map_pid_to_cmdline
[pid
];
819 if (map
>= SAVED_CMDLINES
)
822 cmdline
= saved_cmdlines
[map
];
828 void tracing_record_cmdline(struct task_struct
*tsk
)
830 if (atomic_read(&trace_record_cmdline_disabled
))
833 trace_save_cmdline(tsk
);
837 tracing_generic_entry_update(struct trace_entry
*entry
, unsigned long flags
,
840 struct task_struct
*tsk
= current
;
842 entry
->preempt_count
= pc
& 0xff;
843 entry
->pid
= (tsk
) ? tsk
->pid
: 0;
844 entry
->tgid
= (tsk
) ? tsk
->tgid
: 0;
846 #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
847 (irqs_disabled_flags(flags
) ? TRACE_FLAG_IRQS_OFF
: 0) |
849 TRACE_FLAG_IRQS_NOSUPPORT
|
851 ((pc
& HARDIRQ_MASK
) ? TRACE_FLAG_HARDIRQ
: 0) |
852 ((pc
& SOFTIRQ_MASK
) ? TRACE_FLAG_SOFTIRQ
: 0) |
853 (need_resched() ? TRACE_FLAG_NEED_RESCHED
: 0);
857 trace_function(struct trace_array
*tr
, struct trace_array_cpu
*data
,
858 unsigned long ip
, unsigned long parent_ip
, unsigned long flags
,
861 struct ring_buffer_event
*event
;
862 struct ftrace_entry
*entry
;
863 unsigned long irq_flags
;
865 /* If we are reading the ring buffer, don't trace */
866 if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled
))))
869 event
= ring_buffer_lock_reserve(tr
->buffer
, sizeof(*entry
),
873 entry
= ring_buffer_event_data(event
);
874 tracing_generic_entry_update(&entry
->ent
, flags
, pc
);
875 entry
->ent
.type
= TRACE_FN
;
877 entry
->parent_ip
= parent_ip
;
878 ring_buffer_unlock_commit(tr
->buffer
, event
, irq_flags
);
881 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
882 static void __trace_graph_entry(struct trace_array
*tr
,
883 struct trace_array_cpu
*data
,
884 struct ftrace_graph_ent
*trace
,
888 struct ring_buffer_event
*event
;
889 struct ftrace_graph_ent_entry
*entry
;
890 unsigned long irq_flags
;
892 if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled
))))
895 event
= ring_buffer_lock_reserve(global_trace
.buffer
, sizeof(*entry
),
899 entry
= ring_buffer_event_data(event
);
900 tracing_generic_entry_update(&entry
->ent
, flags
, pc
);
901 entry
->ent
.type
= TRACE_GRAPH_ENT
;
902 entry
->graph_ent
= *trace
;
903 ring_buffer_unlock_commit(global_trace
.buffer
, event
, irq_flags
);
906 static void __trace_graph_return(struct trace_array
*tr
,
907 struct trace_array_cpu
*data
,
908 struct ftrace_graph_ret
*trace
,
912 struct ring_buffer_event
*event
;
913 struct ftrace_graph_ret_entry
*entry
;
914 unsigned long irq_flags
;
916 if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled
))))
919 event
= ring_buffer_lock_reserve(global_trace
.buffer
, sizeof(*entry
),
923 entry
= ring_buffer_event_data(event
);
924 tracing_generic_entry_update(&entry
->ent
, flags
, pc
);
925 entry
->ent
.type
= TRACE_GRAPH_RET
;
927 ring_buffer_unlock_commit(global_trace
.buffer
, event
, irq_flags
);
932 ftrace(struct trace_array
*tr
, struct trace_array_cpu
*data
,
933 unsigned long ip
, unsigned long parent_ip
, unsigned long flags
,
936 if (likely(!atomic_read(&data
->disabled
)))
937 trace_function(tr
, data
, ip
, parent_ip
, flags
, pc
);
940 static void ftrace_trace_stack(struct trace_array
*tr
,
941 struct trace_array_cpu
*data
,
945 #ifdef CONFIG_STACKTRACE
946 struct ring_buffer_event
*event
;
947 struct stack_entry
*entry
;
948 struct stack_trace trace
;
949 unsigned long irq_flags
;
951 if (!(trace_flags
& TRACE_ITER_STACKTRACE
))
954 event
= ring_buffer_lock_reserve(tr
->buffer
, sizeof(*entry
),
958 entry
= ring_buffer_event_data(event
);
959 tracing_generic_entry_update(&entry
->ent
, flags
, pc
);
960 entry
->ent
.type
= TRACE_STACK
;
962 memset(&entry
->caller
, 0, sizeof(entry
->caller
));
964 trace
.nr_entries
= 0;
965 trace
.max_entries
= FTRACE_STACK_ENTRIES
;
967 trace
.entries
= entry
->caller
;
969 save_stack_trace(&trace
);
970 ring_buffer_unlock_commit(tr
->buffer
, event
, irq_flags
);
974 void __trace_stack(struct trace_array
*tr
,
975 struct trace_array_cpu
*data
,
979 ftrace_trace_stack(tr
, data
, flags
, skip
, preempt_count());
982 static void ftrace_trace_userstack(struct trace_array
*tr
,
983 struct trace_array_cpu
*data
,
984 unsigned long flags
, int pc
)
986 struct ring_buffer_event
*event
;
987 struct userstack_entry
*entry
;
988 struct stack_trace trace
;
989 unsigned long irq_flags
;
991 if (!(trace_flags
& TRACE_ITER_USERSTACKTRACE
))
994 event
= ring_buffer_lock_reserve(tr
->buffer
, sizeof(*entry
),
998 entry
= ring_buffer_event_data(event
);
999 tracing_generic_entry_update(&entry
->ent
, flags
, pc
);
1000 entry
->ent
.type
= TRACE_USER_STACK
;
1002 memset(&entry
->caller
, 0, sizeof(entry
->caller
));
1004 trace
.nr_entries
= 0;
1005 trace
.max_entries
= FTRACE_STACK_ENTRIES
;
1007 trace
.entries
= entry
->caller
;
1009 save_stack_trace_user(&trace
);
1010 ring_buffer_unlock_commit(tr
->buffer
, event
, irq_flags
);
1013 void __trace_userstack(struct trace_array
*tr
,
1014 struct trace_array_cpu
*data
,
1015 unsigned long flags
)
1017 ftrace_trace_userstack(tr
, data
, flags
, preempt_count());
1021 ftrace_trace_special(void *__tr
, void *__data
,
1022 unsigned long arg1
, unsigned long arg2
, unsigned long arg3
,
1025 struct ring_buffer_event
*event
;
1026 struct trace_array_cpu
*data
= __data
;
1027 struct trace_array
*tr
= __tr
;
1028 struct special_entry
*entry
;
1029 unsigned long irq_flags
;
1031 event
= ring_buffer_lock_reserve(tr
->buffer
, sizeof(*entry
),
1035 entry
= ring_buffer_event_data(event
);
1036 tracing_generic_entry_update(&entry
->ent
, 0, pc
);
1037 entry
->ent
.type
= TRACE_SPECIAL
;
1041 ring_buffer_unlock_commit(tr
->buffer
, event
, irq_flags
);
1042 ftrace_trace_stack(tr
, data
, irq_flags
, 4, pc
);
1043 ftrace_trace_userstack(tr
, data
, irq_flags
, pc
);
1049 __trace_special(void *__tr
, void *__data
,
1050 unsigned long arg1
, unsigned long arg2
, unsigned long arg3
)
1052 ftrace_trace_special(__tr
, __data
, arg1
, arg2
, arg3
, preempt_count());
1056 tracing_sched_switch_trace(struct trace_array
*tr
,
1057 struct trace_array_cpu
*data
,
1058 struct task_struct
*prev
,
1059 struct task_struct
*next
,
1060 unsigned long flags
, int pc
)
1062 struct ring_buffer_event
*event
;
1063 struct ctx_switch_entry
*entry
;
1064 unsigned long irq_flags
;
1066 event
= ring_buffer_lock_reserve(tr
->buffer
, sizeof(*entry
),
1070 entry
= ring_buffer_event_data(event
);
1071 tracing_generic_entry_update(&entry
->ent
, flags
, pc
);
1072 entry
->ent
.type
= TRACE_CTX
;
1073 entry
->prev_pid
= prev
->pid
;
1074 entry
->prev_prio
= prev
->prio
;
1075 entry
->prev_state
= prev
->state
;
1076 entry
->next_pid
= next
->pid
;
1077 entry
->next_prio
= next
->prio
;
1078 entry
->next_state
= next
->state
;
1079 entry
->next_cpu
= task_cpu(next
);
1080 ring_buffer_unlock_commit(tr
->buffer
, event
, irq_flags
);
1081 ftrace_trace_stack(tr
, data
, flags
, 5, pc
);
1082 ftrace_trace_userstack(tr
, data
, flags
, pc
);
1086 tracing_sched_wakeup_trace(struct trace_array
*tr
,
1087 struct trace_array_cpu
*data
,
1088 struct task_struct
*wakee
,
1089 struct task_struct
*curr
,
1090 unsigned long flags
, int pc
)
1092 struct ring_buffer_event
*event
;
1093 struct ctx_switch_entry
*entry
;
1094 unsigned long irq_flags
;
1096 event
= ring_buffer_lock_reserve(tr
->buffer
, sizeof(*entry
),
1100 entry
= ring_buffer_event_data(event
);
1101 tracing_generic_entry_update(&entry
->ent
, flags
, pc
);
1102 entry
->ent
.type
= TRACE_WAKE
;
1103 entry
->prev_pid
= curr
->pid
;
1104 entry
->prev_prio
= curr
->prio
;
1105 entry
->prev_state
= curr
->state
;
1106 entry
->next_pid
= wakee
->pid
;
1107 entry
->next_prio
= wakee
->prio
;
1108 entry
->next_state
= wakee
->state
;
1109 entry
->next_cpu
= task_cpu(wakee
);
1110 ring_buffer_unlock_commit(tr
->buffer
, event
, irq_flags
);
1111 ftrace_trace_stack(tr
, data
, flags
, 6, pc
);
1112 ftrace_trace_userstack(tr
, data
, flags
, pc
);
1118 ftrace_special(unsigned long arg1
, unsigned long arg2
, unsigned long arg3
)
1120 struct trace_array
*tr
= &global_trace
;
1121 struct trace_array_cpu
*data
;
1122 unsigned long flags
;
1126 if (tracing_disabled
)
1129 pc
= preempt_count();
1130 local_irq_save(flags
);
1131 cpu
= raw_smp_processor_id();
1132 data
= tr
->data
[cpu
];
1134 if (likely(atomic_inc_return(&data
->disabled
) == 1))
1135 ftrace_trace_special(tr
, data
, arg1
, arg2
, arg3
, pc
);
1137 atomic_dec(&data
->disabled
);
1138 local_irq_restore(flags
);
1141 #ifdef CONFIG_FUNCTION_TRACER
1143 function_trace_call_preempt_only(unsigned long ip
, unsigned long parent_ip
)
1145 struct trace_array
*tr
= &global_trace
;
1146 struct trace_array_cpu
*data
;
1147 unsigned long flags
;
1152 if (unlikely(!ftrace_function_enabled
))
1155 pc
= preempt_count();
1156 resched
= ftrace_preempt_disable();
1157 local_save_flags(flags
);
1158 cpu
= raw_smp_processor_id();
1159 data
= tr
->data
[cpu
];
1160 disabled
= atomic_inc_return(&data
->disabled
);
1162 if (likely(disabled
== 1))
1163 trace_function(tr
, data
, ip
, parent_ip
, flags
, pc
);
1165 atomic_dec(&data
->disabled
);
1166 ftrace_preempt_enable(resched
);
1170 function_trace_call(unsigned long ip
, unsigned long parent_ip
)
1172 struct trace_array
*tr
= &global_trace
;
1173 struct trace_array_cpu
*data
;
1174 unsigned long flags
;
1179 if (unlikely(!ftrace_function_enabled
))
1183 * Need to use raw, since this must be called before the
1184 * recursive protection is performed.
1186 local_irq_save(flags
);
1187 cpu
= raw_smp_processor_id();
1188 data
= tr
->data
[cpu
];
1189 disabled
= atomic_inc_return(&data
->disabled
);
1191 if (likely(disabled
== 1)) {
1192 pc
= preempt_count();
1193 trace_function(tr
, data
, ip
, parent_ip
, flags
, pc
);
1196 atomic_dec(&data
->disabled
);
1197 local_irq_restore(flags
);
1200 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
1201 void trace_graph_entry(struct ftrace_graph_ent
*trace
)
1203 struct trace_array
*tr
= &global_trace
;
1204 struct trace_array_cpu
*data
;
1205 unsigned long flags
;
1210 raw_local_irq_save(flags
);
1211 cpu
= raw_smp_processor_id();
1212 data
= tr
->data
[cpu
];
1213 disabled
= atomic_inc_return(&data
->disabled
);
1214 if (likely(disabled
== 1)) {
1215 pc
= preempt_count();
1216 __trace_graph_entry(tr
, data
, trace
, flags
, pc
);
1218 atomic_dec(&data
->disabled
);
1219 raw_local_irq_restore(flags
);
1222 void trace_graph_return(struct ftrace_graph_ret
*trace
)
1224 struct trace_array
*tr
= &global_trace
;
1225 struct trace_array_cpu
*data
;
1226 unsigned long flags
;
1231 raw_local_irq_save(flags
);
1232 cpu
= raw_smp_processor_id();
1233 data
= tr
->data
[cpu
];
1234 disabled
= atomic_inc_return(&data
->disabled
);
1235 if (likely(disabled
== 1)) {
1236 pc
= preempt_count();
1237 __trace_graph_return(tr
, data
, trace
, flags
, pc
);
1239 atomic_dec(&data
->disabled
);
1240 raw_local_irq_restore(flags
);
1242 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
1244 static struct ftrace_ops trace_ops __read_mostly
=
1246 .func
= function_trace_call
,
1249 void tracing_start_function_trace(void)
1251 ftrace_function_enabled
= 0;
1253 if (trace_flags
& TRACE_ITER_PREEMPTONLY
)
1254 trace_ops
.func
= function_trace_call_preempt_only
;
1256 trace_ops
.func
= function_trace_call
;
1258 register_ftrace_function(&trace_ops
);
1259 ftrace_function_enabled
= 1;
1262 void tracing_stop_function_trace(void)
1264 ftrace_function_enabled
= 0;
1265 unregister_ftrace_function(&trace_ops
);
1269 enum trace_file_type
{
1270 TRACE_FILE_LAT_FMT
= 1,
1271 TRACE_FILE_ANNOTATE
= 2,
1274 static void trace_iterator_increment(struct trace_iterator
*iter
, int cpu
)
1276 /* Don't allow ftrace to trace into the ring buffers */
1277 ftrace_disable_cpu();
1280 if (iter
->buffer_iter
[iter
->cpu
])
1281 ring_buffer_read(iter
->buffer_iter
[iter
->cpu
], NULL
);
1283 ftrace_enable_cpu();
1286 static struct trace_entry
*
1287 peek_next_entry(struct trace_iterator
*iter
, int cpu
, u64
*ts
)
1289 struct ring_buffer_event
*event
;
1290 struct ring_buffer_iter
*buf_iter
= iter
->buffer_iter
[cpu
];
1292 /* Don't allow ftrace to trace into the ring buffers */
1293 ftrace_disable_cpu();
1296 event
= ring_buffer_iter_peek(buf_iter
, ts
);
1298 event
= ring_buffer_peek(iter
->tr
->buffer
, cpu
, ts
);
1300 ftrace_enable_cpu();
1302 return event
? ring_buffer_event_data(event
) : NULL
;
1305 static struct trace_entry
*
1306 __find_next_entry(struct trace_iterator
*iter
, int *ent_cpu
, u64
*ent_ts
)
1308 struct ring_buffer
*buffer
= iter
->tr
->buffer
;
1309 struct trace_entry
*ent
, *next
= NULL
;
1310 u64 next_ts
= 0, ts
;
1314 for_each_tracing_cpu(cpu
) {
1316 if (ring_buffer_empty_cpu(buffer
, cpu
))
1319 ent
= peek_next_entry(iter
, cpu
, &ts
);
1322 * Pick the entry with the smallest timestamp:
1324 if (ent
&& (!next
|| ts
< next_ts
)) {
1332 *ent_cpu
= next_cpu
;
1340 /* Find the next real entry, without updating the iterator itself */
1341 static struct trace_entry
*
1342 find_next_entry(struct trace_iterator
*iter
, int *ent_cpu
, u64
*ent_ts
)
1344 return __find_next_entry(iter
, ent_cpu
, ent_ts
);
1347 /* Find the next real entry, and increment the iterator to the next entry */
1348 static void *find_next_entry_inc(struct trace_iterator
*iter
)
1350 iter
->ent
= __find_next_entry(iter
, &iter
->cpu
, &iter
->ts
);
1353 trace_iterator_increment(iter
, iter
->cpu
);
1355 return iter
->ent
? iter
: NULL
;
1358 static void trace_consume(struct trace_iterator
*iter
)
1360 /* Don't allow ftrace to trace into the ring buffers */
1361 ftrace_disable_cpu();
1362 ring_buffer_consume(iter
->tr
->buffer
, iter
->cpu
, &iter
->ts
);
1363 ftrace_enable_cpu();
1366 static void *s_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
1368 struct trace_iterator
*iter
= m
->private;
1374 /* can't go backwards */
1379 ent
= find_next_entry_inc(iter
);
1383 while (ent
&& iter
->idx
< i
)
1384 ent
= find_next_entry_inc(iter
);
1391 static void *s_start(struct seq_file
*m
, loff_t
*pos
)
1393 struct trace_iterator
*iter
= m
->private;
1398 mutex_lock(&trace_types_lock
);
1400 if (!current_trace
|| current_trace
!= iter
->trace
) {
1401 mutex_unlock(&trace_types_lock
);
1405 atomic_inc(&trace_record_cmdline_disabled
);
1407 if (*pos
!= iter
->pos
) {
1412 ftrace_disable_cpu();
1414 for_each_tracing_cpu(cpu
) {
1415 ring_buffer_iter_reset(iter
->buffer_iter
[cpu
]);
1418 ftrace_enable_cpu();
1420 for (p
= iter
; p
&& l
< *pos
; p
= s_next(m
, p
, &l
))
1425 p
= s_next(m
, p
, &l
);
1431 static void s_stop(struct seq_file
*m
, void *p
)
1433 atomic_dec(&trace_record_cmdline_disabled
);
1434 mutex_unlock(&trace_types_lock
);
1437 #ifdef CONFIG_KRETPROBES
1438 static inline const char *kretprobed(const char *name
)
1440 static const char tramp_name
[] = "kretprobe_trampoline";
1441 int size
= sizeof(tramp_name
);
1443 if (strncmp(tramp_name
, name
, size
) == 0)
1444 return "[unknown/kretprobe'd]";
1448 static inline const char *kretprobed(const char *name
)
1452 #endif /* CONFIG_KRETPROBES */
1455 seq_print_sym_short(struct trace_seq
*s
, const char *fmt
, unsigned long address
)
1457 #ifdef CONFIG_KALLSYMS
1458 char str
[KSYM_SYMBOL_LEN
];
1461 kallsyms_lookup(address
, NULL
, NULL
, NULL
, str
);
1463 name
= kretprobed(str
);
1465 return trace_seq_printf(s
, fmt
, name
);
1471 seq_print_sym_offset(struct trace_seq
*s
, const char *fmt
,
1472 unsigned long address
)
1474 #ifdef CONFIG_KALLSYMS
1475 char str
[KSYM_SYMBOL_LEN
];
1478 sprint_symbol(str
, address
);
1479 name
= kretprobed(str
);
1481 return trace_seq_printf(s
, fmt
, name
);
1486 #ifndef CONFIG_64BIT
1487 # define IP_FMT "%08lx"
1489 # define IP_FMT "%016lx"
1493 seq_print_ip_sym(struct trace_seq
*s
, unsigned long ip
, unsigned long sym_flags
)
1498 return trace_seq_printf(s
, "0");
1500 if (sym_flags
& TRACE_ITER_SYM_OFFSET
)
1501 ret
= seq_print_sym_offset(s
, "%s", ip
);
1503 ret
= seq_print_sym_short(s
, "%s", ip
);
1508 if (sym_flags
& TRACE_ITER_SYM_ADDR
)
1509 ret
= trace_seq_printf(s
, " <" IP_FMT
">", ip
);
1513 static inline int seq_print_user_ip(struct trace_seq
*s
, struct mm_struct
*mm
,
1514 unsigned long ip
, unsigned long sym_flags
)
1516 struct file
*file
= NULL
;
1517 unsigned long vmstart
= 0;
1521 const struct vm_area_struct
*vma
;
1523 down_read(&mm
->mmap_sem
);
1524 vma
= find_vma(mm
, ip
);
1526 file
= vma
->vm_file
;
1527 vmstart
= vma
->vm_start
;
1530 ret
= trace_seq_path(s
, &file
->f_path
);
1532 ret
= trace_seq_printf(s
, "[+0x%lx]", ip
- vmstart
);
1534 up_read(&mm
->mmap_sem
);
1536 if (ret
&& ((sym_flags
& TRACE_ITER_SYM_ADDR
) || !file
))
1537 ret
= trace_seq_printf(s
, " <" IP_FMT
">", ip
);
1542 seq_print_userip_objs(const struct userstack_entry
*entry
, struct trace_seq
*s
,
1543 unsigned long sym_flags
)
1545 struct mm_struct
*mm
= NULL
;
1549 if (trace_flags
& TRACE_ITER_SYM_USEROBJ
) {
1550 struct task_struct
*task
;
1552 * we do the lookup on the thread group leader,
1553 * since individual threads might have already quit!
1556 task
= find_task_by_vpid(entry
->ent
.tgid
);
1558 mm
= get_task_mm(task
);
1562 for (i
= 0; i
< FTRACE_STACK_ENTRIES
; i
++) {
1563 unsigned long ip
= entry
->caller
[i
];
1565 if (ip
== ULONG_MAX
|| !ret
)
1568 ret
= trace_seq_puts(s
, " <- ");
1571 ret
= trace_seq_puts(s
, "??");
1577 ret
= seq_print_user_ip(s
, mm
, ip
, sym_flags
);
1585 static void print_lat_help_header(struct seq_file
*m
)
1587 seq_puts(m
, "# _------=> CPU# \n");
1588 seq_puts(m
, "# / _-----=> irqs-off \n");
1589 seq_puts(m
, "# | / _----=> need-resched \n");
1590 seq_puts(m
, "# || / _---=> hardirq/softirq \n");
1591 seq_puts(m
, "# ||| / _--=> preempt-depth \n");
1592 seq_puts(m
, "# |||| / \n");
1593 seq_puts(m
, "# ||||| delay \n");
1594 seq_puts(m
, "# cmd pid ||||| time | caller \n");
1595 seq_puts(m
, "# \\ / ||||| \\ | / \n");
1598 static void print_func_help_header(struct seq_file
*m
)
1600 seq_puts(m
, "# TASK-PID CPU# TIMESTAMP FUNCTION\n");
1601 seq_puts(m
, "# | | | | |\n");
1606 print_trace_header(struct seq_file
*m
, struct trace_iterator
*iter
)
1608 unsigned long sym_flags
= (trace_flags
& TRACE_ITER_SYM_MASK
);
1609 struct trace_array
*tr
= iter
->tr
;
1610 struct trace_array_cpu
*data
= tr
->data
[tr
->cpu
];
1611 struct tracer
*type
= current_trace
;
1612 unsigned long total
;
1613 unsigned long entries
;
1614 const char *name
= "preemption";
1619 entries
= ring_buffer_entries(iter
->tr
->buffer
);
1621 ring_buffer_overruns(iter
->tr
->buffer
);
1623 seq_printf(m
, "%s latency trace v1.1.5 on %s\n",
1625 seq_puts(m
, "-----------------------------------"
1626 "---------------------------------\n");
1627 seq_printf(m
, " latency: %lu us, #%lu/%lu, CPU#%d |"
1628 " (M:%s VP:%d, KP:%d, SP:%d HP:%d",
1629 nsecs_to_usecs(data
->saved_latency
),
1633 #if defined(CONFIG_PREEMPT_NONE)
1635 #elif defined(CONFIG_PREEMPT_VOLUNTARY)
1637 #elif defined(CONFIG_PREEMPT)
1642 /* These are reserved for later use */
1645 seq_printf(m
, " #P:%d)\n", num_online_cpus());
1649 seq_puts(m
, " -----------------\n");
1650 seq_printf(m
, " | task: %.16s-%d "
1651 "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n",
1652 data
->comm
, data
->pid
, data
->uid
, data
->nice
,
1653 data
->policy
, data
->rt_priority
);
1654 seq_puts(m
, " -----------------\n");
1656 if (data
->critical_start
) {
1657 seq_puts(m
, " => started at: ");
1658 seq_print_ip_sym(&iter
->seq
, data
->critical_start
, sym_flags
);
1659 trace_print_seq(m
, &iter
->seq
);
1660 seq_puts(m
, "\n => ended at: ");
1661 seq_print_ip_sym(&iter
->seq
, data
->critical_end
, sym_flags
);
1662 trace_print_seq(m
, &iter
->seq
);
1670 lat_print_generic(struct trace_seq
*s
, struct trace_entry
*entry
, int cpu
)
1672 int hardirq
, softirq
;
1675 comm
= trace_find_cmdline(entry
->pid
);
1677 trace_seq_printf(s
, "%8.8s-%-5d ", comm
, entry
->pid
);
1678 trace_seq_printf(s
, "%3d", cpu
);
1679 trace_seq_printf(s
, "%c%c",
1680 (entry
->flags
& TRACE_FLAG_IRQS_OFF
) ? 'd' :
1681 (entry
->flags
& TRACE_FLAG_IRQS_NOSUPPORT
) ? 'X' : '.',
1682 ((entry
->flags
& TRACE_FLAG_NEED_RESCHED
) ? 'N' : '.'));
1684 hardirq
= entry
->flags
& TRACE_FLAG_HARDIRQ
;
1685 softirq
= entry
->flags
& TRACE_FLAG_SOFTIRQ
;
1686 if (hardirq
&& softirq
) {
1687 trace_seq_putc(s
, 'H');
1690 trace_seq_putc(s
, 'h');
1693 trace_seq_putc(s
, 's');
1695 trace_seq_putc(s
, '.');
1699 if (entry
->preempt_count
)
1700 trace_seq_printf(s
, "%x", entry
->preempt_count
);
1702 trace_seq_puts(s
, ".");
1705 unsigned long preempt_mark_thresh
= 100;
1708 lat_print_timestamp(struct trace_seq
*s
, u64 abs_usecs
,
1709 unsigned long rel_usecs
)
1711 trace_seq_printf(s
, " %4lldus", abs_usecs
);
1712 if (rel_usecs
> preempt_mark_thresh
)
1713 trace_seq_puts(s
, "!: ");
1714 else if (rel_usecs
> 1)
1715 trace_seq_puts(s
, "+: ");
1717 trace_seq_puts(s
, " : ");
1720 static const char state_to_char
[] = TASK_STATE_TO_CHAR_STR
;
1723 * The message is supposed to contain an ending newline.
1724 * If the printing stops prematurely, try to add a newline of our own.
1726 void trace_seq_print_cont(struct trace_seq
*s
, struct trace_iterator
*iter
)
1728 struct trace_entry
*ent
;
1729 struct trace_field_cont
*cont
;
1732 ent
= peek_next_entry(iter
, iter
->cpu
, NULL
);
1733 if (!ent
|| ent
->type
!= TRACE_CONT
) {
1734 trace_seq_putc(s
, '\n');
1739 cont
= (struct trace_field_cont
*)ent
;
1741 ok
= (trace_seq_printf(s
, "%s", cont
->buf
) > 0);
1743 ftrace_disable_cpu();
1745 if (iter
->buffer_iter
[iter
->cpu
])
1746 ring_buffer_read(iter
->buffer_iter
[iter
->cpu
], NULL
);
1748 ring_buffer_consume(iter
->tr
->buffer
, iter
->cpu
, NULL
);
1750 ftrace_enable_cpu();
1752 ent
= peek_next_entry(iter
, iter
->cpu
, NULL
);
1753 } while (ent
&& ent
->type
== TRACE_CONT
);
1756 trace_seq_putc(s
, '\n');
1759 static void test_cpu_buff_start(struct trace_iterator
*iter
)
1761 struct trace_seq
*s
= &iter
->seq
;
1763 if (!(trace_flags
& TRACE_ITER_ANNOTATE
))
1766 if (!(iter
->iter_flags
& TRACE_FILE_ANNOTATE
))
1769 if (cpu_isset(iter
->cpu
, iter
->started
))
1772 cpu_set(iter
->cpu
, iter
->started
);
1773 trace_seq_printf(s
, "##### CPU %u buffer started ####\n", iter
->cpu
);
1776 static enum print_line_t
1777 print_lat_fmt(struct trace_iterator
*iter
, unsigned int trace_idx
, int cpu
)
1779 struct trace_seq
*s
= &iter
->seq
;
1780 unsigned long sym_flags
= (trace_flags
& TRACE_ITER_SYM_MASK
);
1781 struct trace_entry
*next_entry
;
1782 unsigned long verbose
= (trace_flags
& TRACE_ITER_VERBOSE
);
1783 struct trace_entry
*entry
= iter
->ent
;
1784 unsigned long abs_usecs
;
1785 unsigned long rel_usecs
;
1792 if (entry
->type
== TRACE_CONT
)
1793 return TRACE_TYPE_HANDLED
;
1795 test_cpu_buff_start(iter
);
1797 next_entry
= find_next_entry(iter
, NULL
, &next_ts
);
1800 rel_usecs
= ns2usecs(next_ts
- iter
->ts
);
1801 abs_usecs
= ns2usecs(iter
->ts
- iter
->tr
->time_start
);
1804 comm
= trace_find_cmdline(entry
->pid
);
1805 trace_seq_printf(s
, "%16s %5d %3d %d %08x %08x [%08lx]"
1806 " %ld.%03ldms (+%ld.%03ldms): ",
1808 entry
->pid
, cpu
, entry
->flags
,
1809 entry
->preempt_count
, trace_idx
,
1812 abs_usecs
% 1000, rel_usecs
/1000,
1815 lat_print_generic(s
, entry
, cpu
);
1816 lat_print_timestamp(s
, abs_usecs
, rel_usecs
);
1818 switch (entry
->type
) {
1820 struct ftrace_entry
*field
;
1822 trace_assign_type(field
, entry
);
1824 seq_print_ip_sym(s
, field
->ip
, sym_flags
);
1825 trace_seq_puts(s
, " (");
1826 seq_print_ip_sym(s
, field
->parent_ip
, sym_flags
);
1827 trace_seq_puts(s
, ")\n");
1832 struct ctx_switch_entry
*field
;
1834 trace_assign_type(field
, entry
);
1836 T
= field
->next_state
< sizeof(state_to_char
) ?
1837 state_to_char
[field
->next_state
] : 'X';
1839 state
= field
->prev_state
?
1840 __ffs(field
->prev_state
) + 1 : 0;
1841 S
= state
< sizeof(state_to_char
) - 1 ? state_to_char
[state
] : 'X';
1842 comm
= trace_find_cmdline(field
->next_pid
);
1843 trace_seq_printf(s
, " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
1846 S
, entry
->type
== TRACE_CTX
? "==>" : " +",
1853 case TRACE_SPECIAL
: {
1854 struct special_entry
*field
;
1856 trace_assign_type(field
, entry
);
1858 trace_seq_printf(s
, "# %ld %ld %ld\n",
1865 struct stack_entry
*field
;
1867 trace_assign_type(field
, entry
);
1869 for (i
= 0; i
< FTRACE_STACK_ENTRIES
; i
++) {
1871 trace_seq_puts(s
, " <= ");
1872 seq_print_ip_sym(s
, field
->caller
[i
], sym_flags
);
1874 trace_seq_puts(s
, "\n");
1878 struct print_entry
*field
;
1880 trace_assign_type(field
, entry
);
1882 seq_print_ip_sym(s
, field
->ip
, sym_flags
);
1883 trace_seq_printf(s
, ": %s", field
->buf
);
1884 if (entry
->flags
& TRACE_FLAG_CONT
)
1885 trace_seq_print_cont(s
, iter
);
1888 case TRACE_BRANCH
: {
1889 struct trace_branch
*field
;
1891 trace_assign_type(field
, entry
);
1893 trace_seq_printf(s
, "[%s] %s:%s:%d\n",
1894 field
->correct
? " ok " : " MISS ",
1900 case TRACE_USER_STACK
: {
1901 struct userstack_entry
*field
;
1903 trace_assign_type(field
, entry
);
1905 seq_print_userip_objs(field
, s
, sym_flags
);
1906 trace_seq_putc(s
, '\n');
1910 trace_seq_printf(s
, "Unknown type %d\n", entry
->type
);
1912 return TRACE_TYPE_HANDLED
;
1915 static enum print_line_t
print_trace_fmt(struct trace_iterator
*iter
)
1917 struct trace_seq
*s
= &iter
->seq
;
1918 unsigned long sym_flags
= (trace_flags
& TRACE_ITER_SYM_MASK
);
1919 struct trace_entry
*entry
;
1920 unsigned long usec_rem
;
1921 unsigned long long t
;
1930 if (entry
->type
== TRACE_CONT
)
1931 return TRACE_TYPE_HANDLED
;
1933 test_cpu_buff_start(iter
);
1935 comm
= trace_find_cmdline(iter
->ent
->pid
);
1937 t
= ns2usecs(iter
->ts
);
1938 usec_rem
= do_div(t
, 1000000ULL);
1939 secs
= (unsigned long)t
;
1941 ret
= trace_seq_printf(s
, "%16s-%-5d ", comm
, entry
->pid
);
1943 return TRACE_TYPE_PARTIAL_LINE
;
1944 ret
= trace_seq_printf(s
, "[%03d] ", iter
->cpu
);
1946 return TRACE_TYPE_PARTIAL_LINE
;
1947 ret
= trace_seq_printf(s
, "%5lu.%06lu: ", secs
, usec_rem
);
1949 return TRACE_TYPE_PARTIAL_LINE
;
1951 switch (entry
->type
) {
1953 struct ftrace_entry
*field
;
1955 trace_assign_type(field
, entry
);
1957 ret
= seq_print_ip_sym(s
, field
->ip
, sym_flags
);
1959 return TRACE_TYPE_PARTIAL_LINE
;
1960 if ((sym_flags
& TRACE_ITER_PRINT_PARENT
) &&
1962 ret
= trace_seq_printf(s
, " <-");
1964 return TRACE_TYPE_PARTIAL_LINE
;
1965 ret
= seq_print_ip_sym(s
,
1969 return TRACE_TYPE_PARTIAL_LINE
;
1971 ret
= trace_seq_printf(s
, "\n");
1973 return TRACE_TYPE_PARTIAL_LINE
;
1978 struct ctx_switch_entry
*field
;
1980 trace_assign_type(field
, entry
);
1982 S
= field
->prev_state
< sizeof(state_to_char
) ?
1983 state_to_char
[field
->prev_state
] : 'X';
1984 T
= field
->next_state
< sizeof(state_to_char
) ?
1985 state_to_char
[field
->next_state
] : 'X';
1986 ret
= trace_seq_printf(s
, " %5d:%3d:%c %s [%03d] %5d:%3d:%c\n",
1990 entry
->type
== TRACE_CTX
? "==>" : " +",
1996 return TRACE_TYPE_PARTIAL_LINE
;
1999 case TRACE_SPECIAL
: {
2000 struct special_entry
*field
;
2002 trace_assign_type(field
, entry
);
2004 ret
= trace_seq_printf(s
, "# %ld %ld %ld\n",
2009 return TRACE_TYPE_PARTIAL_LINE
;
2013 struct stack_entry
*field
;
2015 trace_assign_type(field
, entry
);
2017 for (i
= 0; i
< FTRACE_STACK_ENTRIES
; i
++) {
2019 ret
= trace_seq_puts(s
, " <= ");
2021 return TRACE_TYPE_PARTIAL_LINE
;
2023 ret
= seq_print_ip_sym(s
, field
->caller
[i
],
2026 return TRACE_TYPE_PARTIAL_LINE
;
2028 ret
= trace_seq_puts(s
, "\n");
2030 return TRACE_TYPE_PARTIAL_LINE
;
2034 struct print_entry
*field
;
2036 trace_assign_type(field
, entry
);
2038 seq_print_ip_sym(s
, field
->ip
, sym_flags
);
2039 trace_seq_printf(s
, ": %s", field
->buf
);
2040 if (entry
->flags
& TRACE_FLAG_CONT
)
2041 trace_seq_print_cont(s
, iter
);
2044 case TRACE_GRAPH_RET
: {
2045 return print_graph_function(iter
);
2047 case TRACE_GRAPH_ENT
: {
2048 return print_graph_function(iter
);
2050 case TRACE_BRANCH
: {
2051 struct trace_branch
*field
;
2053 trace_assign_type(field
, entry
);
2055 trace_seq_printf(s
, "[%s] %s:%s:%d\n",
2056 field
->correct
? " ok " : " MISS ",
2062 case TRACE_USER_STACK
: {
2063 struct userstack_entry
*field
;
2065 trace_assign_type(field
, entry
);
2067 ret
= seq_print_userip_objs(field
, s
, sym_flags
);
2069 return TRACE_TYPE_PARTIAL_LINE
;
2070 ret
= trace_seq_putc(s
, '\n');
2072 return TRACE_TYPE_PARTIAL_LINE
;
2076 return TRACE_TYPE_HANDLED
;
2079 static enum print_line_t
print_raw_fmt(struct trace_iterator
*iter
)
2081 struct trace_seq
*s
= &iter
->seq
;
2082 struct trace_entry
*entry
;
2088 if (entry
->type
== TRACE_CONT
)
2089 return TRACE_TYPE_HANDLED
;
2091 ret
= trace_seq_printf(s
, "%d %d %llu ",
2092 entry
->pid
, iter
->cpu
, iter
->ts
);
2094 return TRACE_TYPE_PARTIAL_LINE
;
2096 switch (entry
->type
) {
2098 struct ftrace_entry
*field
;
2100 trace_assign_type(field
, entry
);
2102 ret
= trace_seq_printf(s
, "%x %x\n",
2106 return TRACE_TYPE_PARTIAL_LINE
;
2111 struct ctx_switch_entry
*field
;
2113 trace_assign_type(field
, entry
);
2115 S
= field
->prev_state
< sizeof(state_to_char
) ?
2116 state_to_char
[field
->prev_state
] : 'X';
2117 T
= field
->next_state
< sizeof(state_to_char
) ?
2118 state_to_char
[field
->next_state
] : 'X';
2119 if (entry
->type
== TRACE_WAKE
)
2121 ret
= trace_seq_printf(s
, "%d %d %c %d %d %d %c\n",
2130 return TRACE_TYPE_PARTIAL_LINE
;
2134 case TRACE_USER_STACK
:
2136 struct special_entry
*field
;
2138 trace_assign_type(field
, entry
);
2140 ret
= trace_seq_printf(s
, "# %ld %ld %ld\n",
2145 return TRACE_TYPE_PARTIAL_LINE
;
2149 struct print_entry
*field
;
2151 trace_assign_type(field
, entry
);
2153 trace_seq_printf(s
, "# %lx %s", field
->ip
, field
->buf
);
2154 if (entry
->flags
& TRACE_FLAG_CONT
)
2155 trace_seq_print_cont(s
, iter
);
2159 return TRACE_TYPE_HANDLED
;
2162 #define SEQ_PUT_FIELD_RET(s, x) \
2164 if (!trace_seq_putmem(s, &(x), sizeof(x))) \
2168 #define SEQ_PUT_HEX_FIELD_RET(s, x) \
2170 BUILD_BUG_ON(sizeof(x) > MAX_MEMHEX_BYTES); \
2171 if (!trace_seq_putmem_hex(s, &(x), sizeof(x))) \
2175 static enum print_line_t
print_hex_fmt(struct trace_iterator
*iter
)
2177 struct trace_seq
*s
= &iter
->seq
;
2178 unsigned char newline
= '\n';
2179 struct trace_entry
*entry
;
2184 if (entry
->type
== TRACE_CONT
)
2185 return TRACE_TYPE_HANDLED
;
2187 SEQ_PUT_HEX_FIELD_RET(s
, entry
->pid
);
2188 SEQ_PUT_HEX_FIELD_RET(s
, iter
->cpu
);
2189 SEQ_PUT_HEX_FIELD_RET(s
, iter
->ts
);
2191 switch (entry
->type
) {
2193 struct ftrace_entry
*field
;
2195 trace_assign_type(field
, entry
);
2197 SEQ_PUT_HEX_FIELD_RET(s
, field
->ip
);
2198 SEQ_PUT_HEX_FIELD_RET(s
, field
->parent_ip
);
2203 struct ctx_switch_entry
*field
;
2205 trace_assign_type(field
, entry
);
2207 S
= field
->prev_state
< sizeof(state_to_char
) ?
2208 state_to_char
[field
->prev_state
] : 'X';
2209 T
= field
->next_state
< sizeof(state_to_char
) ?
2210 state_to_char
[field
->next_state
] : 'X';
2211 if (entry
->type
== TRACE_WAKE
)
2213 SEQ_PUT_HEX_FIELD_RET(s
, field
->prev_pid
);
2214 SEQ_PUT_HEX_FIELD_RET(s
, field
->prev_prio
);
2215 SEQ_PUT_HEX_FIELD_RET(s
, S
);
2216 SEQ_PUT_HEX_FIELD_RET(s
, field
->next_cpu
);
2217 SEQ_PUT_HEX_FIELD_RET(s
, field
->next_pid
);
2218 SEQ_PUT_HEX_FIELD_RET(s
, field
->next_prio
);
2219 SEQ_PUT_HEX_FIELD_RET(s
, T
);
2223 case TRACE_USER_STACK
:
2225 struct special_entry
*field
;
2227 trace_assign_type(field
, entry
);
2229 SEQ_PUT_HEX_FIELD_RET(s
, field
->arg1
);
2230 SEQ_PUT_HEX_FIELD_RET(s
, field
->arg2
);
2231 SEQ_PUT_HEX_FIELD_RET(s
, field
->arg3
);
2235 SEQ_PUT_FIELD_RET(s
, newline
);
2237 return TRACE_TYPE_HANDLED
;
2240 static enum print_line_t
print_bin_fmt(struct trace_iterator
*iter
)
2242 struct trace_seq
*s
= &iter
->seq
;
2243 struct trace_entry
*entry
;
2247 if (entry
->type
== TRACE_CONT
)
2248 return TRACE_TYPE_HANDLED
;
2250 SEQ_PUT_FIELD_RET(s
, entry
->pid
);
2251 SEQ_PUT_FIELD_RET(s
, entry
->cpu
);
2252 SEQ_PUT_FIELD_RET(s
, iter
->ts
);
2254 switch (entry
->type
) {
2256 struct ftrace_entry
*field
;
2258 trace_assign_type(field
, entry
);
2260 SEQ_PUT_FIELD_RET(s
, field
->ip
);
2261 SEQ_PUT_FIELD_RET(s
, field
->parent_ip
);
2265 struct ctx_switch_entry
*field
;
2267 trace_assign_type(field
, entry
);
2269 SEQ_PUT_FIELD_RET(s
, field
->prev_pid
);
2270 SEQ_PUT_FIELD_RET(s
, field
->prev_prio
);
2271 SEQ_PUT_FIELD_RET(s
, field
->prev_state
);
2272 SEQ_PUT_FIELD_RET(s
, field
->next_pid
);
2273 SEQ_PUT_FIELD_RET(s
, field
->next_prio
);
2274 SEQ_PUT_FIELD_RET(s
, field
->next_state
);
2278 case TRACE_USER_STACK
:
2280 struct special_entry
*field
;
2282 trace_assign_type(field
, entry
);
2284 SEQ_PUT_FIELD_RET(s
, field
->arg1
);
2285 SEQ_PUT_FIELD_RET(s
, field
->arg2
);
2286 SEQ_PUT_FIELD_RET(s
, field
->arg3
);
2293 static int trace_empty(struct trace_iterator
*iter
)
2297 for_each_tracing_cpu(cpu
) {
2298 if (iter
->buffer_iter
[cpu
]) {
2299 if (!ring_buffer_iter_empty(iter
->buffer_iter
[cpu
]))
2302 if (!ring_buffer_empty_cpu(iter
->tr
->buffer
, cpu
))
2310 static enum print_line_t
print_trace_line(struct trace_iterator
*iter
)
2312 enum print_line_t ret
;
2314 if (iter
->trace
&& iter
->trace
->print_line
) {
2315 ret
= iter
->trace
->print_line(iter
);
2316 if (ret
!= TRACE_TYPE_UNHANDLED
)
2320 if (trace_flags
& TRACE_ITER_BIN
)
2321 return print_bin_fmt(iter
);
2323 if (trace_flags
& TRACE_ITER_HEX
)
2324 return print_hex_fmt(iter
);
2326 if (trace_flags
& TRACE_ITER_RAW
)
2327 return print_raw_fmt(iter
);
2329 if (iter
->iter_flags
& TRACE_FILE_LAT_FMT
)
2330 return print_lat_fmt(iter
, iter
->idx
, iter
->cpu
);
2332 return print_trace_fmt(iter
);
2335 static int s_show(struct seq_file
*m
, void *v
)
2337 struct trace_iterator
*iter
= v
;
2339 if (iter
->ent
== NULL
) {
2341 seq_printf(m
, "# tracer: %s\n", iter
->trace
->name
);
2344 if (iter
->trace
&& iter
->trace
->print_header
)
2345 iter
->trace
->print_header(m
);
2346 else if (iter
->iter_flags
& TRACE_FILE_LAT_FMT
) {
2347 /* print nothing if the buffers are empty */
2348 if (trace_empty(iter
))
2350 print_trace_header(m
, iter
);
2351 if (!(trace_flags
& TRACE_ITER_VERBOSE
))
2352 print_lat_help_header(m
);
2354 if (!(trace_flags
& TRACE_ITER_VERBOSE
))
2355 print_func_help_header(m
);
2358 print_trace_line(iter
);
2359 trace_print_seq(m
, &iter
->seq
);
2365 static struct seq_operations tracer_seq_ops
= {
2372 static struct trace_iterator
*
2373 __tracing_open(struct inode
*inode
, struct file
*file
, int *ret
)
2375 struct trace_iterator
*iter
;
2379 if (tracing_disabled
) {
2384 iter
= kzalloc(sizeof(*iter
), GFP_KERNEL
);
2390 mutex_lock(&trace_types_lock
);
2391 if (current_trace
&& current_trace
->print_max
)
2394 iter
->tr
= inode
->i_private
;
2395 iter
->trace
= current_trace
;
2398 /* Notify the tracer early; before we stop tracing. */
2399 if (iter
->trace
&& iter
->trace
->open
)
2400 iter
->trace
->open(iter
);
2402 /* Annotate start of buffers if we had overruns */
2403 if (ring_buffer_overruns(iter
->tr
->buffer
))
2404 iter
->iter_flags
|= TRACE_FILE_ANNOTATE
;
2407 for_each_tracing_cpu(cpu
) {
2409 iter
->buffer_iter
[cpu
] =
2410 ring_buffer_read_start(iter
->tr
->buffer
, cpu
);
2412 if (!iter
->buffer_iter
[cpu
])
2416 /* TODO stop tracer */
2417 *ret
= seq_open(file
, &tracer_seq_ops
);
2421 m
= file
->private_data
;
2424 /* stop the trace while dumping */
2427 mutex_unlock(&trace_types_lock
);
2433 for_each_tracing_cpu(cpu
) {
2434 if (iter
->buffer_iter
[cpu
])
2435 ring_buffer_read_finish(iter
->buffer_iter
[cpu
]);
2437 mutex_unlock(&trace_types_lock
);
2440 return ERR_PTR(-ENOMEM
);
2443 int tracing_open_generic(struct inode
*inode
, struct file
*filp
)
2445 if (tracing_disabled
)
2448 filp
->private_data
= inode
->i_private
;
2452 int tracing_release(struct inode
*inode
, struct file
*file
)
2454 struct seq_file
*m
= (struct seq_file
*)file
->private_data
;
2455 struct trace_iterator
*iter
= m
->private;
2458 mutex_lock(&trace_types_lock
);
2459 for_each_tracing_cpu(cpu
) {
2460 if (iter
->buffer_iter
[cpu
])
2461 ring_buffer_read_finish(iter
->buffer_iter
[cpu
]);
2464 if (iter
->trace
&& iter
->trace
->close
)
2465 iter
->trace
->close(iter
);
2467 /* reenable tracing if it was previously enabled */
2469 mutex_unlock(&trace_types_lock
);
2471 seq_release(inode
, file
);
2476 static int tracing_open(struct inode
*inode
, struct file
*file
)
2480 __tracing_open(inode
, file
, &ret
);
2485 static int tracing_lt_open(struct inode
*inode
, struct file
*file
)
2487 struct trace_iterator
*iter
;
2490 iter
= __tracing_open(inode
, file
, &ret
);
2493 iter
->iter_flags
|= TRACE_FILE_LAT_FMT
;
2500 t_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
2502 struct tracer
*t
= m
->private;
2514 static void *t_start(struct seq_file
*m
, loff_t
*pos
)
2516 struct tracer
*t
= m
->private;
2519 mutex_lock(&trace_types_lock
);
2520 for (; t
&& l
< *pos
; t
= t_next(m
, t
, &l
))
2526 static void t_stop(struct seq_file
*m
, void *p
)
2528 mutex_unlock(&trace_types_lock
);
2531 static int t_show(struct seq_file
*m
, void *v
)
2533 struct tracer
*t
= v
;
2538 seq_printf(m
, "%s", t
->name
);
2547 static struct seq_operations show_traces_seq_ops
= {
2554 static int show_traces_open(struct inode
*inode
, struct file
*file
)
2558 if (tracing_disabled
)
2561 ret
= seq_open(file
, &show_traces_seq_ops
);
2563 struct seq_file
*m
= file
->private_data
;
2564 m
->private = trace_types
;
2570 static struct file_operations tracing_fops
= {
2571 .open
= tracing_open
,
2573 .llseek
= seq_lseek
,
2574 .release
= tracing_release
,
2577 static struct file_operations tracing_lt_fops
= {
2578 .open
= tracing_lt_open
,
2580 .llseek
= seq_lseek
,
2581 .release
= tracing_release
,
2584 static struct file_operations show_traces_fops
= {
2585 .open
= show_traces_open
,
2587 .release
= seq_release
,
2591 * Only trace on a CPU if the bitmask is set:
2593 static cpumask_t tracing_cpumask
= CPU_MASK_ALL
;
2596 * When tracing/tracing_cpu_mask is modified then this holds
2597 * the new bitmask we are about to install:
2599 static cpumask_t tracing_cpumask_new
;
2602 * The tracer itself will not take this lock, but still we want
2603 * to provide a consistent cpumask to user-space:
2605 static DEFINE_MUTEX(tracing_cpumask_update_lock
);
2608 * Temporary storage for the character representation of the
2609 * CPU bitmask (and one more byte for the newline):
2611 static char mask_str
[NR_CPUS
+ 1];
2614 tracing_cpumask_read(struct file
*filp
, char __user
*ubuf
,
2615 size_t count
, loff_t
*ppos
)
2619 mutex_lock(&tracing_cpumask_update_lock
);
2621 len
= cpumask_scnprintf(mask_str
, count
, tracing_cpumask
);
2622 if (count
- len
< 2) {
2626 len
+= sprintf(mask_str
+ len
, "\n");
2627 count
= simple_read_from_buffer(ubuf
, count
, ppos
, mask_str
, NR_CPUS
+1);
2630 mutex_unlock(&tracing_cpumask_update_lock
);
2636 tracing_cpumask_write(struct file
*filp
, const char __user
*ubuf
,
2637 size_t count
, loff_t
*ppos
)
2641 mutex_lock(&tracing_cpumask_update_lock
);
2642 err
= cpumask_parse_user(ubuf
, count
, tracing_cpumask_new
);
2646 raw_local_irq_disable();
2647 __raw_spin_lock(&ftrace_max_lock
);
2648 for_each_tracing_cpu(cpu
) {
2650 * Increase/decrease the disabled counter if we are
2651 * about to flip a bit in the cpumask:
2653 if (cpu_isset(cpu
, tracing_cpumask
) &&
2654 !cpu_isset(cpu
, tracing_cpumask_new
)) {
2655 atomic_inc(&global_trace
.data
[cpu
]->disabled
);
2657 if (!cpu_isset(cpu
, tracing_cpumask
) &&
2658 cpu_isset(cpu
, tracing_cpumask_new
)) {
2659 atomic_dec(&global_trace
.data
[cpu
]->disabled
);
2662 __raw_spin_unlock(&ftrace_max_lock
);
2663 raw_local_irq_enable();
2665 tracing_cpumask
= tracing_cpumask_new
;
2667 mutex_unlock(&tracing_cpumask_update_lock
);
2672 mutex_unlock(&tracing_cpumask_update_lock
);
2677 static struct file_operations tracing_cpumask_fops
= {
2678 .open
= tracing_open_generic
,
2679 .read
= tracing_cpumask_read
,
2680 .write
= tracing_cpumask_write
,
2684 tracing_trace_options_read(struct file
*filp
, char __user
*ubuf
,
2685 size_t cnt
, loff_t
*ppos
)
2691 u32 tracer_flags
= current_trace
->flags
->val
;
2692 struct tracer_opt
*trace_opts
= current_trace
->flags
->opts
;
2695 /* calulate max size */
2696 for (i
= 0; trace_options
[i
]; i
++) {
2697 len
+= strlen(trace_options
[i
]);
2698 len
+= 3; /* "no" and space */
2702 * Increase the size with names of options specific
2703 * of the current tracer.
2705 for (i
= 0; trace_opts
[i
].name
; i
++) {
2706 len
+= strlen(trace_opts
[i
].name
);
2707 len
+= 3; /* "no" and space */
2710 /* +2 for \n and \0 */
2711 buf
= kmalloc(len
+ 2, GFP_KERNEL
);
2715 for (i
= 0; trace_options
[i
]; i
++) {
2716 if (trace_flags
& (1 << i
))
2717 r
+= sprintf(buf
+ r
, "%s ", trace_options
[i
]);
2719 r
+= sprintf(buf
+ r
, "no%s ", trace_options
[i
]);
2722 for (i
= 0; trace_opts
[i
].name
; i
++) {
2723 if (tracer_flags
& trace_opts
[i
].bit
)
2724 r
+= sprintf(buf
+ r
, "%s ",
2725 trace_opts
[i
].name
);
2727 r
+= sprintf(buf
+ r
, "no%s ",
2728 trace_opts
[i
].name
);
2731 r
+= sprintf(buf
+ r
, "\n");
2732 WARN_ON(r
>= len
+ 2);
2734 r
= simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
2741 /* Try to assign a tracer specific option */
2742 static int set_tracer_option(struct tracer
*trace
, char *cmp
, int neg
)
2744 struct tracer_flags
*trace_flags
= trace
->flags
;
2745 struct tracer_opt
*opts
= NULL
;
2749 for (i
= 0; trace_flags
->opts
[i
].name
; i
++) {
2750 opts
= &trace_flags
->opts
[i
];
2751 len
= strlen(opts
->name
);
2753 if (strncmp(cmp
, opts
->name
, len
) == 0) {
2754 ret
= trace
->set_flag(trace_flags
->val
,
2760 if (!trace_flags
->opts
[i
].name
)
2763 /* Refused to handle */
2768 trace_flags
->val
&= ~opts
->bit
;
2770 trace_flags
->val
|= opts
->bit
;
2776 tracing_trace_options_write(struct file
*filp
, const char __user
*ubuf
,
2777 size_t cnt
, loff_t
*ppos
)
2785 if (cnt
>= sizeof(buf
))
2788 if (copy_from_user(&buf
, ubuf
, cnt
))
2793 if (strncmp(buf
, "no", 2) == 0) {
2798 for (i
= 0; trace_options
[i
]; i
++) {
2799 int len
= strlen(trace_options
[i
]);
2801 if (strncmp(cmp
, trace_options
[i
], len
) == 0) {
2803 trace_flags
&= ~(1 << i
);
2805 trace_flags
|= (1 << i
);
2810 /* If no option could be set, test the specific tracer options */
2811 if (!trace_options
[i
]) {
2812 ret
= set_tracer_option(current_trace
, cmp
, neg
);
2822 static struct file_operations tracing_iter_fops
= {
2823 .open
= tracing_open_generic
,
2824 .read
= tracing_trace_options_read
,
2825 .write
= tracing_trace_options_write
,
2828 static const char readme_msg
[] =
2829 "tracing mini-HOWTO:\n\n"
2831 "# mount -t debugfs nodev /debug\n\n"
2832 "# cat /debug/tracing/available_tracers\n"
2833 "wakeup preemptirqsoff preemptoff irqsoff ftrace sched_switch none\n\n"
2834 "# cat /debug/tracing/current_tracer\n"
2836 "# echo sched_switch > /debug/tracing/current_tracer\n"
2837 "# cat /debug/tracing/current_tracer\n"
2839 "# cat /debug/tracing/trace_options\n"
2840 "noprint-parent nosym-offset nosym-addr noverbose\n"
2841 "# echo print-parent > /debug/tracing/trace_options\n"
2842 "# echo 1 > /debug/tracing/tracing_enabled\n"
2843 "# cat /debug/tracing/trace > /tmp/trace.txt\n"
2844 "echo 0 > /debug/tracing/tracing_enabled\n"
2848 tracing_readme_read(struct file
*filp
, char __user
*ubuf
,
2849 size_t cnt
, loff_t
*ppos
)
2851 return simple_read_from_buffer(ubuf
, cnt
, ppos
,
2852 readme_msg
, strlen(readme_msg
));
2855 static struct file_operations tracing_readme_fops
= {
2856 .open
= tracing_open_generic
,
2857 .read
= tracing_readme_read
,
2861 tracing_ctrl_read(struct file
*filp
, char __user
*ubuf
,
2862 size_t cnt
, loff_t
*ppos
)
2867 r
= sprintf(buf
, "%u\n", tracer_enabled
);
2868 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
2872 tracing_ctrl_write(struct file
*filp
, const char __user
*ubuf
,
2873 size_t cnt
, loff_t
*ppos
)
2875 struct trace_array
*tr
= filp
->private_data
;
2880 if (cnt
>= sizeof(buf
))
2883 if (copy_from_user(&buf
, ubuf
, cnt
))
2888 ret
= strict_strtoul(buf
, 10, &val
);
2894 mutex_lock(&trace_types_lock
);
2895 if (tracer_enabled
^ val
) {
2898 if (current_trace
->start
)
2899 current_trace
->start(tr
);
2904 if (current_trace
->stop
)
2905 current_trace
->stop(tr
);
2908 mutex_unlock(&trace_types_lock
);
2916 tracing_set_trace_read(struct file
*filp
, char __user
*ubuf
,
2917 size_t cnt
, loff_t
*ppos
)
2919 char buf
[max_tracer_type_len
+2];
2922 mutex_lock(&trace_types_lock
);
2924 r
= sprintf(buf
, "%s\n", current_trace
->name
);
2926 r
= sprintf(buf
, "\n");
2927 mutex_unlock(&trace_types_lock
);
2929 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
2932 static int tracing_set_tracer(char *buf
)
2934 struct trace_array
*tr
= &global_trace
;
2938 mutex_lock(&trace_types_lock
);
2939 for (t
= trace_types
; t
; t
= t
->next
) {
2940 if (strcmp(t
->name
, buf
) == 0)
2947 if (t
== current_trace
)
2950 trace_branch_disable();
2951 if (current_trace
&& current_trace
->reset
)
2952 current_trace
->reset(tr
);
2961 trace_branch_enable(tr
);
2963 mutex_unlock(&trace_types_lock
);
2969 tracing_set_trace_write(struct file
*filp
, const char __user
*ubuf
,
2970 size_t cnt
, loff_t
*ppos
)
2972 char buf
[max_tracer_type_len
+1];
2979 if (cnt
> max_tracer_type_len
)
2980 cnt
= max_tracer_type_len
;
2982 if (copy_from_user(&buf
, ubuf
, cnt
))
2987 /* strip ending whitespace. */
2988 for (i
= cnt
- 1; i
> 0 && isspace(buf
[i
]); i
--)
2991 err
= tracing_set_tracer(buf
);
3001 tracing_max_lat_read(struct file
*filp
, char __user
*ubuf
,
3002 size_t cnt
, loff_t
*ppos
)
3004 unsigned long *ptr
= filp
->private_data
;
3008 r
= snprintf(buf
, sizeof(buf
), "%ld\n",
3009 *ptr
== (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr
));
3010 if (r
> sizeof(buf
))
3012 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
3016 tracing_max_lat_write(struct file
*filp
, const char __user
*ubuf
,
3017 size_t cnt
, loff_t
*ppos
)
3019 long *ptr
= filp
->private_data
;
3024 if (cnt
>= sizeof(buf
))
3027 if (copy_from_user(&buf
, ubuf
, cnt
))
3032 ret
= strict_strtoul(buf
, 10, &val
);
3041 static atomic_t tracing_reader
;
3043 static int tracing_open_pipe(struct inode
*inode
, struct file
*filp
)
3045 struct trace_iterator
*iter
;
3047 if (tracing_disabled
)
3050 /* We only allow for reader of the pipe */
3051 if (atomic_inc_return(&tracing_reader
) != 1) {
3052 atomic_dec(&tracing_reader
);
3056 /* create a buffer to store the information to pass to userspace */
3057 iter
= kzalloc(sizeof(*iter
), GFP_KERNEL
);
3061 mutex_lock(&trace_types_lock
);
3063 /* trace pipe does not show start of buffer */
3064 cpus_setall(iter
->started
);
3066 iter
->tr
= &global_trace
;
3067 iter
->trace
= current_trace
;
3068 filp
->private_data
= iter
;
3070 if (iter
->trace
->pipe_open
)
3071 iter
->trace
->pipe_open(iter
);
3072 mutex_unlock(&trace_types_lock
);
3077 static int tracing_release_pipe(struct inode
*inode
, struct file
*file
)
3079 struct trace_iterator
*iter
= file
->private_data
;
3082 atomic_dec(&tracing_reader
);
3088 tracing_poll_pipe(struct file
*filp
, poll_table
*poll_table
)
3090 struct trace_iterator
*iter
= filp
->private_data
;
3092 if (trace_flags
& TRACE_ITER_BLOCK
) {
3094 * Always select as readable when in blocking mode
3096 return POLLIN
| POLLRDNORM
;
3098 if (!trace_empty(iter
))
3099 return POLLIN
| POLLRDNORM
;
3100 poll_wait(filp
, &trace_wait
, poll_table
);
3101 if (!trace_empty(iter
))
3102 return POLLIN
| POLLRDNORM
;
3112 tracing_read_pipe(struct file
*filp
, char __user
*ubuf
,
3113 size_t cnt
, loff_t
*ppos
)
3115 struct trace_iterator
*iter
= filp
->private_data
;
3118 /* return any leftover data */
3119 sret
= trace_seq_to_user(&iter
->seq
, ubuf
, cnt
);
3123 trace_seq_reset(&iter
->seq
);
3125 mutex_lock(&trace_types_lock
);
3126 if (iter
->trace
->read
) {
3127 sret
= iter
->trace
->read(iter
, filp
, ubuf
, cnt
, ppos
);
3134 while (trace_empty(iter
)) {
3136 if ((filp
->f_flags
& O_NONBLOCK
)) {
3142 * This is a make-shift waitqueue. The reason we don't use
3143 * an actual wait queue is because:
3144 * 1) we only ever have one waiter
3145 * 2) the tracing, traces all functions, we don't want
3146 * the overhead of calling wake_up and friends
3147 * (and tracing them too)
3148 * Anyway, this is really very primitive wakeup.
3150 set_current_state(TASK_INTERRUPTIBLE
);
3151 iter
->tr
->waiter
= current
;
3153 mutex_unlock(&trace_types_lock
);
3155 /* sleep for 100 msecs, and try again. */
3156 schedule_timeout(HZ
/10);
3158 mutex_lock(&trace_types_lock
);
3160 iter
->tr
->waiter
= NULL
;
3162 if (signal_pending(current
)) {
3167 if (iter
->trace
!= current_trace
)
3171 * We block until we read something and tracing is disabled.
3172 * We still block if tracing is disabled, but we have never
3173 * read anything. This allows a user to cat this file, and
3174 * then enable tracing. But after we have read something,
3175 * we give an EOF when tracing is again disabled.
3177 * iter->pos will be 0 if we haven't read anything.
3179 if (!tracer_enabled
&& iter
->pos
)
3185 /* stop when tracing is finished */
3186 if (trace_empty(iter
))
3189 if (cnt
>= PAGE_SIZE
)
3190 cnt
= PAGE_SIZE
- 1;
3192 /* reset all but tr, trace, and overruns */
3193 memset(&iter
->seq
, 0,
3194 sizeof(struct trace_iterator
) -
3195 offsetof(struct trace_iterator
, seq
));
3198 while (find_next_entry_inc(iter
) != NULL
) {
3199 enum print_line_t ret
;
3200 int len
= iter
->seq
.len
;
3202 ret
= print_trace_line(iter
);
3203 if (ret
== TRACE_TYPE_PARTIAL_LINE
) {
3204 /* don't print partial lines */
3205 iter
->seq
.len
= len
;
3209 trace_consume(iter
);
3211 if (iter
->seq
.len
>= cnt
)
3215 /* Now copy what we have to the user */
3216 sret
= trace_seq_to_user(&iter
->seq
, ubuf
, cnt
);
3217 if (iter
->seq
.readpos
>= iter
->seq
.len
)
3218 trace_seq_reset(&iter
->seq
);
3221 * If there was nothing to send to user, inspite of consuming trace
3222 * entries, go back to wait for more entries.
3228 mutex_unlock(&trace_types_lock
);
3234 tracing_entries_read(struct file
*filp
, char __user
*ubuf
,
3235 size_t cnt
, loff_t
*ppos
)
3237 struct trace_array
*tr
= filp
->private_data
;
3241 r
= sprintf(buf
, "%lu\n", tr
->entries
>> 10);
3242 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
3246 tracing_entries_write(struct file
*filp
, const char __user
*ubuf
,
3247 size_t cnt
, loff_t
*ppos
)
3253 if (cnt
>= sizeof(buf
))
3256 if (copy_from_user(&buf
, ubuf
, cnt
))
3261 ret
= strict_strtoul(buf
, 10, &val
);
3265 /* must have at least 1 entry */
3269 mutex_lock(&trace_types_lock
);
3273 /* disable all cpu buffers */
3274 for_each_tracing_cpu(cpu
) {
3275 if (global_trace
.data
[cpu
])
3276 atomic_inc(&global_trace
.data
[cpu
]->disabled
);
3277 if (max_tr
.data
[cpu
])
3278 atomic_inc(&max_tr
.data
[cpu
]->disabled
);
3281 /* value is in KB */
3284 if (val
!= global_trace
.entries
) {
3285 ret
= ring_buffer_resize(global_trace
.buffer
, val
);
3291 ret
= ring_buffer_resize(max_tr
.buffer
, val
);
3295 r
= ring_buffer_resize(global_trace
.buffer
,
3296 global_trace
.entries
);
3298 /* AARGH! We are left with different
3299 * size max buffer!!!! */
3301 tracing_disabled
= 1;
3306 global_trace
.entries
= val
;
3311 /* If check pages failed, return ENOMEM */
3312 if (tracing_disabled
)
3315 for_each_tracing_cpu(cpu
) {
3316 if (global_trace
.data
[cpu
])
3317 atomic_dec(&global_trace
.data
[cpu
]->disabled
);
3318 if (max_tr
.data
[cpu
])
3319 atomic_dec(&max_tr
.data
[cpu
]->disabled
);
3323 max_tr
.entries
= global_trace
.entries
;
3324 mutex_unlock(&trace_types_lock
);
3329 static int mark_printk(const char *fmt
, ...)
3333 va_start(args
, fmt
);
3334 ret
= trace_vprintk(0, fmt
, args
);
3340 tracing_mark_write(struct file
*filp
, const char __user
*ubuf
,
3341 size_t cnt
, loff_t
*fpos
)
3346 if (tracing_disabled
)
3349 if (cnt
> TRACE_BUF_SIZE
)
3350 cnt
= TRACE_BUF_SIZE
;
3352 buf
= kmalloc(cnt
+ 1, GFP_KERNEL
);
3356 if (copy_from_user(buf
, ubuf
, cnt
)) {
3361 /* Cut from the first nil or newline. */
3363 end
= strchr(buf
, '\n');
3367 cnt
= mark_printk("%s\n", buf
);
3374 static struct file_operations tracing_max_lat_fops
= {
3375 .open
= tracing_open_generic
,
3376 .read
= tracing_max_lat_read
,
3377 .write
= tracing_max_lat_write
,
3380 static struct file_operations tracing_ctrl_fops
= {
3381 .open
= tracing_open_generic
,
3382 .read
= tracing_ctrl_read
,
3383 .write
= tracing_ctrl_write
,
3386 static struct file_operations set_tracer_fops
= {
3387 .open
= tracing_open_generic
,
3388 .read
= tracing_set_trace_read
,
3389 .write
= tracing_set_trace_write
,
3392 static struct file_operations tracing_pipe_fops
= {
3393 .open
= tracing_open_pipe
,
3394 .poll
= tracing_poll_pipe
,
3395 .read
= tracing_read_pipe
,
3396 .release
= tracing_release_pipe
,
3399 static struct file_operations tracing_entries_fops
= {
3400 .open
= tracing_open_generic
,
3401 .read
= tracing_entries_read
,
3402 .write
= tracing_entries_write
,
3405 static struct file_operations tracing_mark_fops
= {
3406 .open
= tracing_open_generic
,
3407 .write
= tracing_mark_write
,
3410 #ifdef CONFIG_DYNAMIC_FTRACE
3412 int __weak
ftrace_arch_read_dyn_info(char *buf
, int size
)
3418 tracing_read_dyn_info(struct file
*filp
, char __user
*ubuf
,
3419 size_t cnt
, loff_t
*ppos
)
3421 static char ftrace_dyn_info_buffer
[1024];
3422 static DEFINE_MUTEX(dyn_info_mutex
);
3423 unsigned long *p
= filp
->private_data
;
3424 char *buf
= ftrace_dyn_info_buffer
;
3425 int size
= ARRAY_SIZE(ftrace_dyn_info_buffer
);
3428 mutex_lock(&dyn_info_mutex
);
3429 r
= sprintf(buf
, "%ld ", *p
);
3431 r
+= ftrace_arch_read_dyn_info(buf
+r
, (size
-1)-r
);
3434 r
= simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
3436 mutex_unlock(&dyn_info_mutex
);
3441 static struct file_operations tracing_dyn_info_fops
= {
3442 .open
= tracing_open_generic
,
3443 .read
= tracing_read_dyn_info
,
3447 static struct dentry
*d_tracer
;
3449 struct dentry
*tracing_init_dentry(void)
3456 d_tracer
= debugfs_create_dir("tracing", NULL
);
3458 if (!d_tracer
&& !once
) {
3460 pr_warning("Could not create debugfs directory 'tracing'\n");
3467 #ifdef CONFIG_FTRACE_SELFTEST
3468 /* Let selftest have access to static functions in this file */
3469 #include "trace_selftest.c"
3472 static __init
int tracer_init_debugfs(void)
3474 struct dentry
*d_tracer
;
3475 struct dentry
*entry
;
3477 d_tracer
= tracing_init_dentry();
3479 entry
= debugfs_create_file("tracing_enabled", 0644, d_tracer
,
3480 &global_trace
, &tracing_ctrl_fops
);
3482 pr_warning("Could not create debugfs 'tracing_enabled' entry\n");
3484 entry
= debugfs_create_file("trace_options", 0644, d_tracer
,
3485 NULL
, &tracing_iter_fops
);
3487 pr_warning("Could not create debugfs 'trace_options' entry\n");
3489 entry
= debugfs_create_file("tracing_cpumask", 0644, d_tracer
,
3490 NULL
, &tracing_cpumask_fops
);
3492 pr_warning("Could not create debugfs 'tracing_cpumask' entry\n");
3494 entry
= debugfs_create_file("latency_trace", 0444, d_tracer
,
3495 &global_trace
, &tracing_lt_fops
);
3497 pr_warning("Could not create debugfs 'latency_trace' entry\n");
3499 entry
= debugfs_create_file("trace", 0444, d_tracer
,
3500 &global_trace
, &tracing_fops
);
3502 pr_warning("Could not create debugfs 'trace' entry\n");
3504 entry
= debugfs_create_file("available_tracers", 0444, d_tracer
,
3505 &global_trace
, &show_traces_fops
);
3507 pr_warning("Could not create debugfs 'available_tracers' entry\n");
3509 entry
= debugfs_create_file("current_tracer", 0444, d_tracer
,
3510 &global_trace
, &set_tracer_fops
);
3512 pr_warning("Could not create debugfs 'current_tracer' entry\n");
3514 entry
= debugfs_create_file("tracing_max_latency", 0644, d_tracer
,
3515 &tracing_max_latency
,
3516 &tracing_max_lat_fops
);
3518 pr_warning("Could not create debugfs "
3519 "'tracing_max_latency' entry\n");
3521 entry
= debugfs_create_file("tracing_thresh", 0644, d_tracer
,
3522 &tracing_thresh
, &tracing_max_lat_fops
);
3524 pr_warning("Could not create debugfs "
3525 "'tracing_thresh' entry\n");
3526 entry
= debugfs_create_file("README", 0644, d_tracer
,
3527 NULL
, &tracing_readme_fops
);
3529 pr_warning("Could not create debugfs 'README' entry\n");
3531 entry
= debugfs_create_file("trace_pipe", 0644, d_tracer
,
3532 NULL
, &tracing_pipe_fops
);
3534 pr_warning("Could not create debugfs "
3535 "'trace_pipe' entry\n");
3537 entry
= debugfs_create_file("buffer_size_kb", 0644, d_tracer
,
3538 &global_trace
, &tracing_entries_fops
);
3540 pr_warning("Could not create debugfs "
3541 "'buffer_size_kb' entry\n");
3543 entry
= debugfs_create_file("trace_marker", 0220, d_tracer
,
3544 NULL
, &tracing_mark_fops
);
3546 pr_warning("Could not create debugfs "
3547 "'trace_marker' entry\n");
3549 #ifdef CONFIG_DYNAMIC_FTRACE
3550 entry
= debugfs_create_file("dyn_ftrace_total_info", 0444, d_tracer
,
3551 &ftrace_update_tot_cnt
,
3552 &tracing_dyn_info_fops
);
3554 pr_warning("Could not create debugfs "
3555 "'dyn_ftrace_total_info' entry\n");
3557 #ifdef CONFIG_SYSPROF_TRACER
3558 init_tracer_sysprof_debugfs(d_tracer
);
3563 int trace_vprintk(unsigned long ip
, const char *fmt
, va_list args
)
3565 static DEFINE_SPINLOCK(trace_buf_lock
);
3566 static char trace_buf
[TRACE_BUF_SIZE
];
3568 struct ring_buffer_event
*event
;
3569 struct trace_array
*tr
= &global_trace
;
3570 struct trace_array_cpu
*data
;
3571 struct print_entry
*entry
;
3572 unsigned long flags
, irq_flags
;
3573 int cpu
, len
= 0, size
, pc
;
3575 if (tracing_disabled
)
3578 pc
= preempt_count();
3579 preempt_disable_notrace();
3580 cpu
= raw_smp_processor_id();
3581 data
= tr
->data
[cpu
];
3583 if (unlikely(atomic_read(&data
->disabled
)))
3586 spin_lock_irqsave(&trace_buf_lock
, flags
);
3587 len
= vsnprintf(trace_buf
, TRACE_BUF_SIZE
, fmt
, args
);
3589 len
= min(len
, TRACE_BUF_SIZE
-1);
3592 size
= sizeof(*entry
) + len
+ 1;
3593 event
= ring_buffer_lock_reserve(tr
->buffer
, size
, &irq_flags
);
3596 entry
= ring_buffer_event_data(event
);
3597 tracing_generic_entry_update(&entry
->ent
, flags
, pc
);
3598 entry
->ent
.type
= TRACE_PRINT
;
3601 memcpy(&entry
->buf
, trace_buf
, len
);
3602 entry
->buf
[len
] = 0;
3603 ring_buffer_unlock_commit(tr
->buffer
, event
, irq_flags
);
3606 spin_unlock_irqrestore(&trace_buf_lock
, flags
);
3609 preempt_enable_notrace();
3613 EXPORT_SYMBOL_GPL(trace_vprintk
);
3615 int __ftrace_printk(unsigned long ip
, const char *fmt
, ...)
3620 if (!(trace_flags
& TRACE_ITER_PRINTK
))
3624 ret
= trace_vprintk(ip
, fmt
, ap
);
3628 EXPORT_SYMBOL_GPL(__ftrace_printk
);
3630 static int trace_panic_handler(struct notifier_block
*this,
3631 unsigned long event
, void *unused
)
3633 if (ftrace_dump_on_oops
)
3638 static struct notifier_block trace_panic_notifier
= {
3639 .notifier_call
= trace_panic_handler
,
3641 .priority
= 150 /* priority: INT_MAX >= x >= 0 */
3644 static int trace_die_handler(struct notifier_block
*self
,
3650 if (ftrace_dump_on_oops
)
3659 static struct notifier_block trace_die_notifier
= {
3660 .notifier_call
= trace_die_handler
,
3665 * printk is set to max of 1024, we really don't need it that big.
3666 * Nothing should be printing 1000 characters anyway.
3668 #define TRACE_MAX_PRINT 1000
3671 * Define here KERN_TRACE so that we have one place to modify
3672 * it if we decide to change what log level the ftrace dump
3675 #define KERN_TRACE KERN_INFO
3678 trace_printk_seq(struct trace_seq
*s
)
3680 /* Probably should print a warning here. */
3684 /* should be zero ended, but we are paranoid. */
3685 s
->buffer
[s
->len
] = 0;
3687 printk(KERN_TRACE
"%s", s
->buffer
);
3692 void ftrace_dump(void)
3694 static DEFINE_SPINLOCK(ftrace_dump_lock
);
3695 /* use static because iter can be a bit big for the stack */
3696 static struct trace_iterator iter
;
3697 static cpumask_t mask
;
3698 static int dump_ran
;
3699 unsigned long flags
;
3703 spin_lock_irqsave(&ftrace_dump_lock
, flags
);
3709 /* No turning back! */
3712 for_each_tracing_cpu(cpu
) {
3713 atomic_inc(&global_trace
.data
[cpu
]->disabled
);
3716 /* don't look at user memory in panic mode */
3717 trace_flags
&= ~TRACE_ITER_SYM_USEROBJ
;
3719 printk(KERN_TRACE
"Dumping ftrace buffer:\n");
3721 iter
.tr
= &global_trace
;
3722 iter
.trace
= current_trace
;
3725 * We need to stop all tracing on all CPUS to read the
3726 * the next buffer. This is a bit expensive, but is
3727 * not done often. We fill all what we can read,
3728 * and then release the locks again.
3733 while (!trace_empty(&iter
)) {
3736 printk(KERN_TRACE
"---------------------------------\n");
3740 /* reset all but tr, trace, and overruns */
3741 memset(&iter
.seq
, 0,
3742 sizeof(struct trace_iterator
) -
3743 offsetof(struct trace_iterator
, seq
));
3744 iter
.iter_flags
|= TRACE_FILE_LAT_FMT
;
3747 if (find_next_entry_inc(&iter
) != NULL
) {
3748 print_trace_line(&iter
);
3749 trace_consume(&iter
);
3752 trace_printk_seq(&iter
.seq
);
3756 printk(KERN_TRACE
" (ftrace buffer empty)\n");
3758 printk(KERN_TRACE
"---------------------------------\n");
3761 spin_unlock_irqrestore(&ftrace_dump_lock
, flags
);
3764 __init
static int tracer_alloc_buffers(void)
3766 struct trace_array_cpu
*data
;
3769 /* TODO: make the number of buffers hot pluggable with CPUS */
3770 tracing_buffer_mask
= cpu_possible_map
;
3772 global_trace
.buffer
= ring_buffer_alloc(trace_buf_size
,
3773 TRACE_BUFFER_FLAGS
);
3774 if (!global_trace
.buffer
) {
3775 printk(KERN_ERR
"tracer: failed to allocate ring buffer!\n");
3779 global_trace
.entries
= ring_buffer_size(global_trace
.buffer
);
3781 #ifdef CONFIG_TRACER_MAX_TRACE
3782 max_tr
.buffer
= ring_buffer_alloc(trace_buf_size
,
3783 TRACE_BUFFER_FLAGS
);
3784 if (!max_tr
.buffer
) {
3785 printk(KERN_ERR
"tracer: failed to allocate max ring buffer!\n");
3787 ring_buffer_free(global_trace
.buffer
);
3790 max_tr
.entries
= ring_buffer_size(max_tr
.buffer
);
3791 WARN_ON(max_tr
.entries
!= global_trace
.entries
);
3794 /* Allocate the first page for all buffers */
3795 for_each_tracing_cpu(i
) {
3796 data
= global_trace
.data
[i
] = &per_cpu(global_trace_cpu
, i
);
3797 max_tr
.data
[i
] = &per_cpu(max_data
, i
);
3800 trace_init_cmdlines();
3802 register_tracer(&nop_trace
);
3803 #ifdef CONFIG_BOOT_TRACER
3804 register_tracer(&boot_tracer
);
3805 current_trace
= &boot_tracer
;
3806 current_trace
->init(&global_trace
);
3808 current_trace
= &nop_trace
;
3811 /* All seems OK, enable tracing */
3812 tracing_disabled
= 0;
3814 atomic_notifier_chain_register(&panic_notifier_list
,
3815 &trace_panic_notifier
);
3817 register_die_notifier(&trace_die_notifier
);
3821 early_initcall(tracer_alloc_buffers
);
3822 fs_initcall(tracer_init_debugfs
);