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/writeback.h>
35 #include <linux/stacktrace.h>
36 #include <linux/ring_buffer.h>
40 #define TRACE_BUFFER_FLAGS (RB_FL_OVERWRITE)
42 unsigned long __read_mostly tracing_max_latency = (cycle_t)ULONG_MAX;
43 unsigned long __read_mostly tracing_thresh;
45 static cpumask_t __read_mostly tracing_buffer_mask;
47 #define for_each_tracing_cpu(cpu) \
48 for_each_cpu_mask(cpu, tracing_buffer_mask)
50 static int tracing_disabled = 1;
53 ns2usecs(cycle_t nsec)
60 cycle_t ftrace_now(int cpu)
62 u64 ts = ring_buffer_time_stamp(cpu);
63 ring_buffer_normalize_time_stamp(cpu, &ts);
68 * The global_trace is the descriptor that holds the tracing
69 * buffers for the live tracing. For each CPU, it contains
70 * a link list of pages that will store trace entries. The
71 * page descriptor of the pages in the memory is used to hold
72 * the link list by linking the lru item in the page descriptor
73 * to each of the pages in the buffer per CPU.
75 * For each active CPU there is a data field that holds the
76 * pages for the buffer for that CPU. Each CPU has the same number
77 * of pages allocated for its buffer.
79 static struct trace_array global_trace;
81 static DEFINE_PER_CPU(struct trace_array_cpu, global_trace_cpu);
84 * The max_tr is used to snapshot the global_trace when a maximum
85 * latency is reached. Some tracers will use this to store a maximum
86 * trace while it continues examining live traces.
88 * The buffers for the max_tr are set up the same as the global_trace.
89 * When a snapshot is taken, the link list of the max_tr is swapped
90 * with the link list of the global_trace and the buffers are reset for
91 * the global_trace so the tracing can continue.
93 static struct trace_array max_tr;
95 static DEFINE_PER_CPU(struct trace_array_cpu, max_data);
97 /* tracer_enabled is used to toggle activation of a tracer */
98 static int tracer_enabled = 1;
100 /* function tracing enabled */
101 int ftrace_function_enabled;
104 * trace_buf_size is the size in bytes that is allocated
105 * for a buffer. Note, the number of bytes is always rounded
108 * This number is purposely set to a low number of 16384.
109 * If the dump on oops happens, it will be much appreciated
110 * to not have to wait for all that output. Anyway this can be
111 * boot time and run time configurable.
113 #define TRACE_BUF_SIZE_DEFAULT 1441792UL /* 16384 * 88 (sizeof(entry)) */
115 static unsigned long trace_buf_size = TRACE_BUF_SIZE_DEFAULT;
117 /* trace_types holds a link list of available tracers. */
118 static struct tracer *trace_types __read_mostly;
120 /* current_trace points to the tracer that is currently active */
121 static struct tracer *current_trace __read_mostly;
124 * max_tracer_type_len is used to simplify the allocating of
125 * buffers to read userspace tracer names. We keep track of
126 * the longest tracer name registered.
128 static int max_tracer_type_len;
131 * trace_types_lock is used to protect the trace_types list.
132 * This lock is also used to keep user access serialized.
133 * Accesses from userspace will grab this lock while userspace
134 * activities happen inside the kernel.
136 static DEFINE_MUTEX(trace_types_lock);
138 /* trace_wait is a waitqueue for tasks blocked on trace_poll */
139 static DECLARE_WAIT_QUEUE_HEAD(trace_wait);
141 /* trace_flags holds iter_ctrl options */
142 unsigned long trace_flags = TRACE_ITER_PRINT_PARENT;
145 * trace_wake_up - wake up tasks waiting for trace input
147 * Simply wakes up any task that is blocked on the trace_wait
148 * queue. These is used with trace_poll for tasks polling the trace.
150 void trace_wake_up(void)
153 * The runqueue_is_locked() can fail, but this is the best we
156 if (!(trace_flags & TRACE_ITER_BLOCK) && !runqueue_is_locked())
157 wake_up(&trace_wait);
160 static int __init set_buf_size(char *str)
162 unsigned long buf_size;
167 ret = strict_strtoul(str, 0, &buf_size);
168 /* nr_entries can not be zero */
169 if (ret < 0 || buf_size == 0)
171 trace_buf_size = buf_size;
174 __setup("trace_buf_size=", set_buf_size);
176 unsigned long nsecs_to_usecs(unsigned long nsecs)
182 * TRACE_ITER_SYM_MASK masks the options in trace_flags that
183 * control the output of kernel symbols.
185 #define TRACE_ITER_SYM_MASK \
186 (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
188 /* These must match the bit postions in trace_iterator_flags */
189 static const char *trace_options[] = {
205 * ftrace_max_lock is used to protect the swapping of buffers
206 * when taking a max snapshot. The buffers themselves are
207 * protected by per_cpu spinlocks. But the action of the swap
208 * needs its own lock.
210 * This is defined as a raw_spinlock_t in order to help
211 * with performance when lockdep debugging is enabled.
213 static raw_spinlock_t ftrace_max_lock =
214 (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED;
217 * Copy the new maximum trace into the separate maximum-trace
218 * structure. (this way the maximum trace is permanently saved,
219 * for later retrieval via /debugfs/tracing/latency_trace)
222 __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
224 struct trace_array_cpu *data = tr->data[cpu];
227 max_tr.time_start = data->preempt_timestamp;
229 data = max_tr.data[cpu];
230 data->saved_latency = tracing_max_latency;
232 memcpy(data->comm, tsk->comm, TASK_COMM_LEN);
233 data->pid = tsk->pid;
234 data->uid = tsk->uid;
235 data->nice = tsk->static_prio - 20 - MAX_RT_PRIO;
236 data->policy = tsk->policy;
237 data->rt_priority = tsk->rt_priority;
239 /* record this tasks comm */
240 tracing_record_cmdline(current);
244 * trace_seq_printf - sequence printing of trace information
245 * @s: trace sequence descriptor
246 * @fmt: printf format string
248 * The tracer may use either sequence operations or its own
249 * copy to user routines. To simplify formating of a trace
250 * trace_seq_printf is used to store strings into a special
251 * buffer (@s). Then the output may be either used by
252 * the sequencer or pulled into another buffer.
255 trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
257 int len = (PAGE_SIZE - 1) - s->len;
265 ret = vsnprintf(s->buffer + s->len, len, fmt, ap);
268 /* If we can't write it all, don't bother writing anything */
278 * trace_seq_puts - trace sequence printing of simple string
279 * @s: trace sequence descriptor
280 * @str: simple string to record
282 * The tracer may use either the sequence operations or its own
283 * copy to user routines. This function records a simple string
284 * into a special buffer (@s) for later retrieval by a sequencer
285 * or other mechanism.
288 trace_seq_puts(struct trace_seq *s, const char *str)
290 int len = strlen(str);
292 if (len > ((PAGE_SIZE - 1) - s->len))
295 memcpy(s->buffer + s->len, str, len);
302 trace_seq_putc(struct trace_seq *s, unsigned char c)
304 if (s->len >= (PAGE_SIZE - 1))
307 s->buffer[s->len++] = c;
313 trace_seq_putmem(struct trace_seq *s, void *mem, size_t len)
315 if (len > ((PAGE_SIZE - 1) - s->len))
318 memcpy(s->buffer + s->len, mem, len);
325 static const char hex2asc[] = "0123456789abcdef";
328 trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len)
330 unsigned char hex[HEX_CHARS];
331 unsigned char *data = mem;
335 BUG_ON(len >= HEX_CHARS);
338 for (i = 0, j = 0; i < len; i++) {
340 for (i = len-1, j = 0; i >= 0; i--) {
344 hex[j++] = hex2asc[byte & 0x0f];
345 hex[j++] = hex2asc[byte >> 4];
349 return trace_seq_putmem(s, hex, j);
353 trace_seq_reset(struct trace_seq *s)
359 ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt)
364 if (s->len <= s->readpos)
367 len = s->len - s->readpos;
370 ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt);
379 trace_print_seq(struct seq_file *m, struct trace_seq *s)
381 int len = s->len >= PAGE_SIZE ? PAGE_SIZE - 1 : s->len;
384 seq_puts(m, s->buffer);
390 * update_max_tr - snapshot all trace buffers from global_trace to max_tr
392 * @tsk: the task with the latency
393 * @cpu: The cpu that initiated the trace.
395 * Flip the buffers between the @tr and the max_tr and record information
396 * about which task was the cause of this latency.
399 update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
401 struct ring_buffer *buf = tr->buffer;
403 WARN_ON_ONCE(!irqs_disabled());
404 __raw_spin_lock(&ftrace_max_lock);
406 tr->buffer = max_tr.buffer;
409 ring_buffer_reset(tr->buffer);
411 __update_max_tr(tr, tsk, cpu);
412 __raw_spin_unlock(&ftrace_max_lock);
416 * update_max_tr_single - only copy one trace over, and reset the rest
418 * @tsk - task with the latency
419 * @cpu - the cpu of the buffer to copy.
421 * Flip the trace of a single CPU buffer between the @tr and the max_tr.
424 update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu)
428 WARN_ON_ONCE(!irqs_disabled());
429 __raw_spin_lock(&ftrace_max_lock);
431 ring_buffer_reset(max_tr.buffer);
432 ret = ring_buffer_swap_cpu(max_tr.buffer, tr->buffer, cpu);
436 __update_max_tr(tr, tsk, cpu);
437 __raw_spin_unlock(&ftrace_max_lock);
441 * register_tracer - register a tracer with the ftrace system.
442 * @type - the plugin for the tracer
444 * Register a new plugin tracer.
446 int register_tracer(struct tracer *type)
453 pr_info("Tracer must have a name\n");
457 mutex_lock(&trace_types_lock);
458 for (t = trace_types; t; t = t->next) {
459 if (strcmp(type->name, t->name) == 0) {
461 pr_info("Trace %s already registered\n",
468 #ifdef CONFIG_FTRACE_STARTUP_TEST
469 if (type->selftest) {
470 struct tracer *saved_tracer = current_trace;
471 struct trace_array *tr = &global_trace;
472 int saved_ctrl = tr->ctrl;
475 * Run a selftest on this tracer.
476 * Here we reset the trace buffer, and set the current
477 * tracer to be this tracer. The tracer can then run some
478 * internal tracing to verify that everything is in order.
479 * If we fail, we do not register this tracer.
481 for_each_tracing_cpu(i) {
482 tracing_reset(tr, i);
484 current_trace = type;
486 /* the test is responsible for initializing and enabling */
487 pr_info("Testing tracer %s: ", type->name);
488 ret = type->selftest(type, tr);
489 /* the test is responsible for resetting too */
490 current_trace = saved_tracer;
491 tr->ctrl = saved_ctrl;
493 printk(KERN_CONT "FAILED!\n");
496 /* Only reset on passing, to avoid touching corrupted buffers */
497 for_each_tracing_cpu(i) {
498 tracing_reset(tr, i);
500 printk(KERN_CONT "PASSED\n");
504 type->next = trace_types;
506 len = strlen(type->name);
507 if (len > max_tracer_type_len)
508 max_tracer_type_len = len;
511 mutex_unlock(&trace_types_lock);
516 void unregister_tracer(struct tracer *type)
521 mutex_lock(&trace_types_lock);
522 for (t = &trace_types; *t; t = &(*t)->next) {
526 pr_info("Trace %s not registered\n", type->name);
531 if (strlen(type->name) != max_tracer_type_len)
534 max_tracer_type_len = 0;
535 for (t = &trace_types; *t; t = &(*t)->next) {
536 len = strlen((*t)->name);
537 if (len > max_tracer_type_len)
538 max_tracer_type_len = len;
541 mutex_unlock(&trace_types_lock);
544 void tracing_reset(struct trace_array *tr, int cpu)
546 ring_buffer_reset_cpu(tr->buffer, cpu);
549 #define SAVED_CMDLINES 128
550 static unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
551 static unsigned map_cmdline_to_pid[SAVED_CMDLINES];
552 static char saved_cmdlines[SAVED_CMDLINES][TASK_COMM_LEN];
553 static int cmdline_idx;
554 static DEFINE_SPINLOCK(trace_cmdline_lock);
556 /* temporary disable recording */
557 atomic_t trace_record_cmdline_disabled __read_mostly;
559 static void trace_init_cmdlines(void)
561 memset(&map_pid_to_cmdline, -1, sizeof(map_pid_to_cmdline));
562 memset(&map_cmdline_to_pid, -1, sizeof(map_cmdline_to_pid));
566 void trace_stop_cmdline_recording(void);
568 static void trace_save_cmdline(struct task_struct *tsk)
573 if (!tsk->pid || unlikely(tsk->pid > PID_MAX_DEFAULT))
577 * It's not the end of the world if we don't get
578 * the lock, but we also don't want to spin
579 * nor do we want to disable interrupts,
580 * so if we miss here, then better luck next time.
582 if (!spin_trylock(&trace_cmdline_lock))
585 idx = map_pid_to_cmdline[tsk->pid];
586 if (idx >= SAVED_CMDLINES) {
587 idx = (cmdline_idx + 1) % SAVED_CMDLINES;
589 map = map_cmdline_to_pid[idx];
590 if (map <= PID_MAX_DEFAULT)
591 map_pid_to_cmdline[map] = (unsigned)-1;
593 map_pid_to_cmdline[tsk->pid] = idx;
598 memcpy(&saved_cmdlines[idx], tsk->comm, TASK_COMM_LEN);
600 spin_unlock(&trace_cmdline_lock);
603 static char *trace_find_cmdline(int pid)
605 char *cmdline = "<...>";
611 if (pid > PID_MAX_DEFAULT)
614 map = map_pid_to_cmdline[pid];
615 if (map >= SAVED_CMDLINES)
618 cmdline = saved_cmdlines[map];
624 void tracing_record_cmdline(struct task_struct *tsk)
626 if (atomic_read(&trace_record_cmdline_disabled))
629 trace_save_cmdline(tsk);
633 tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags)
635 struct task_struct *tsk = current;
638 pc = preempt_count();
640 entry->preempt_count = pc & 0xff;
641 entry->pid = (tsk) ? tsk->pid : 0;
643 (irqs_disabled_flags(flags) ? TRACE_FLAG_IRQS_OFF : 0) |
644 ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) |
645 ((pc & SOFTIRQ_MASK) ? TRACE_FLAG_SOFTIRQ : 0) |
646 (need_resched() ? TRACE_FLAG_NEED_RESCHED : 0);
650 trace_function(struct trace_array *tr, struct trace_array_cpu *data,
651 unsigned long ip, unsigned long parent_ip, unsigned long flags)
653 struct ring_buffer_event *event;
654 struct ftrace_entry *entry;
655 unsigned long irq_flags;
657 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
661 entry = ring_buffer_event_data(event);
662 tracing_generic_entry_update(&entry->ent, flags);
663 entry->ent.type = TRACE_FN;
665 entry->parent_ip = parent_ip;
666 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
670 ftrace(struct trace_array *tr, struct trace_array_cpu *data,
671 unsigned long ip, unsigned long parent_ip, unsigned long flags)
673 if (likely(!atomic_read(&data->disabled)))
674 trace_function(tr, data, ip, parent_ip, flags);
677 void __trace_stack(struct trace_array *tr,
678 struct trace_array_cpu *data,
682 struct ring_buffer_event *event;
683 struct stack_entry *entry;
684 struct stack_trace trace;
685 unsigned long irq_flags;
687 if (!(trace_flags & TRACE_ITER_STACKTRACE))
690 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
694 entry = ring_buffer_event_data(event);
695 tracing_generic_entry_update(&entry->ent, flags);
696 entry->ent.type = TRACE_STACK;
698 memset(&entry->caller, 0, sizeof(entry->caller));
700 trace.nr_entries = 0;
701 trace.max_entries = FTRACE_STACK_ENTRIES;
703 trace.entries = entry->caller;
705 save_stack_trace(&trace);
706 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
710 __trace_special(void *__tr, void *__data,
711 unsigned long arg1, unsigned long arg2, unsigned long arg3)
713 struct ring_buffer_event *event;
714 struct trace_array_cpu *data = __data;
715 struct trace_array *tr = __tr;
716 struct special_entry *entry;
717 unsigned long irq_flags;
719 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
723 entry = ring_buffer_event_data(event);
724 tracing_generic_entry_update(&entry->ent, 0);
725 entry->ent.type = TRACE_SPECIAL;
729 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
730 __trace_stack(tr, data, irq_flags, 4);
736 tracing_sched_switch_trace(struct trace_array *tr,
737 struct trace_array_cpu *data,
738 struct task_struct *prev,
739 struct task_struct *next,
742 struct ring_buffer_event *event;
743 struct ctx_switch_entry *entry;
744 unsigned long irq_flags;
746 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
750 entry = ring_buffer_event_data(event);
751 tracing_generic_entry_update(&entry->ent, flags);
752 entry->ent.type = TRACE_CTX;
753 entry->prev_pid = prev->pid;
754 entry->prev_prio = prev->prio;
755 entry->prev_state = prev->state;
756 entry->next_pid = next->pid;
757 entry->next_prio = next->prio;
758 entry->next_state = next->state;
759 entry->next_cpu = task_cpu(next);
760 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
761 __trace_stack(tr, data, flags, 5);
765 tracing_sched_wakeup_trace(struct trace_array *tr,
766 struct trace_array_cpu *data,
767 struct task_struct *wakee,
768 struct task_struct *curr,
771 struct ring_buffer_event *event;
772 struct ctx_switch_entry *entry;
773 unsigned long irq_flags;
775 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
779 entry = ring_buffer_event_data(event);
780 tracing_generic_entry_update(&entry->ent, flags);
781 entry->ent.type = TRACE_WAKE;
782 entry->prev_pid = curr->pid;
783 entry->prev_prio = curr->prio;
784 entry->prev_state = curr->state;
785 entry->next_pid = wakee->pid;
786 entry->next_prio = wakee->prio;
787 entry->next_state = wakee->state;
788 entry->next_cpu = task_cpu(wakee);
789 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
790 __trace_stack(tr, data, flags, 6);
796 ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3)
798 struct trace_array *tr = &global_trace;
799 struct trace_array_cpu *data;
804 if (tracing_disabled || !tr->ctrl)
807 local_irq_save(flags);
808 cpu = raw_smp_processor_id();
809 data = tr->data[cpu];
810 disabled = atomic_inc_return(&data->disabled);
812 if (likely(disabled == 1))
813 __trace_special(tr, data, arg1, arg2, arg3);
815 atomic_dec(&data->disabled);
816 local_irq_restore(flags);
821 function_trace_call(unsigned long ip, unsigned long parent_ip)
823 struct trace_array *tr = &global_trace;
824 struct trace_array_cpu *data;
829 if (unlikely(!ftrace_function_enabled))
835 local_irq_save(flags);
836 cpu = raw_smp_processor_id();
837 data = tr->data[cpu];
838 disabled = atomic_inc_return(&data->disabled);
840 if (likely(disabled == 1))
841 trace_function(tr, data, ip, parent_ip, flags);
843 atomic_dec(&data->disabled);
844 local_irq_restore(flags);
847 static struct ftrace_ops trace_ops __read_mostly =
849 .func = function_trace_call,
852 void tracing_start_function_trace(void)
854 ftrace_function_enabled = 0;
855 register_ftrace_function(&trace_ops);
857 ftrace_function_enabled = 1;
860 void tracing_stop_function_trace(void)
862 ftrace_function_enabled = 0;
863 unregister_ftrace_function(&trace_ops);
867 enum trace_file_type {
868 TRACE_FILE_LAT_FMT = 1,
871 static void trace_iterator_increment(struct trace_iterator *iter, int cpu)
874 ring_buffer_read(iter->buffer_iter[iter->cpu], NULL);
877 static struct trace_entry *
878 peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts)
880 struct ring_buffer_event *event;
881 struct ring_buffer_iter *buf_iter = iter->buffer_iter[cpu];
883 event = ring_buffer_iter_peek(buf_iter, ts);
884 return event ? ring_buffer_event_data(event) : NULL;
886 static struct trace_entry *
887 __find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts)
889 struct ring_buffer *buffer = iter->tr->buffer;
890 struct trace_entry *ent, *next = NULL;
895 for_each_tracing_cpu(cpu) {
897 if (ring_buffer_empty_cpu(buffer, cpu))
900 ent = peek_next_entry(iter, cpu, &ts);
903 * Pick the entry with the smallest timestamp:
905 if (ent && (!next || ts < next_ts)) {
921 /* Find the next real entry, without updating the iterator itself */
922 static struct trace_entry *
923 find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts)
925 return __find_next_entry(iter, ent_cpu, ent_ts);
928 /* Find the next real entry, and increment the iterator to the next entry */
929 static void *find_next_entry_inc(struct trace_iterator *iter)
931 iter->ent = __find_next_entry(iter, &iter->cpu, &iter->ts);
934 trace_iterator_increment(iter, iter->cpu);
936 return iter->ent ? iter : NULL;
939 static void trace_consume(struct trace_iterator *iter)
941 ring_buffer_consume(iter->tr->buffer, iter->cpu, &iter->ts);
944 static void *s_next(struct seq_file *m, void *v, loff_t *pos)
946 struct trace_iterator *iter = m->private;
952 /* can't go backwards */
957 ent = find_next_entry_inc(iter);
961 while (ent && iter->idx < i)
962 ent = find_next_entry_inc(iter);
969 static void *s_start(struct seq_file *m, loff_t *pos)
971 struct trace_iterator *iter = m->private;
976 mutex_lock(&trace_types_lock);
978 if (!current_trace || current_trace != iter->trace) {
979 mutex_unlock(&trace_types_lock);
983 atomic_inc(&trace_record_cmdline_disabled);
985 /* let the tracer grab locks here if needed */
986 if (current_trace->start)
987 current_trace->start(iter);
989 if (*pos != iter->pos) {
994 for_each_tracing_cpu(cpu) {
995 ring_buffer_iter_reset(iter->buffer_iter[cpu]);
998 for (p = iter; p && l < *pos; p = s_next(m, p, &l))
1003 p = s_next(m, p, &l);
1009 static void s_stop(struct seq_file *m, void *p)
1011 struct trace_iterator *iter = m->private;
1013 atomic_dec(&trace_record_cmdline_disabled);
1015 /* let the tracer release locks here if needed */
1016 if (current_trace && current_trace == iter->trace && iter->trace->stop)
1017 iter->trace->stop(iter);
1019 mutex_unlock(&trace_types_lock);
1022 #define KRETPROBE_MSG "[unknown/kretprobe'd]"
1024 #ifdef CONFIG_KRETPROBES
1025 static inline int kretprobed(unsigned long addr)
1027 return addr == (unsigned long)kretprobe_trampoline;
1030 static inline int kretprobed(unsigned long addr)
1034 #endif /* CONFIG_KRETPROBES */
1037 seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
1039 #ifdef CONFIG_KALLSYMS
1040 char str[KSYM_SYMBOL_LEN];
1042 kallsyms_lookup(address, NULL, NULL, NULL, str);
1044 return trace_seq_printf(s, fmt, str);
1050 seq_print_sym_offset(struct trace_seq *s, const char *fmt,
1051 unsigned long address)
1053 #ifdef CONFIG_KALLSYMS
1054 char str[KSYM_SYMBOL_LEN];
1056 sprint_symbol(str, address);
1057 return trace_seq_printf(s, fmt, str);
1062 #ifndef CONFIG_64BIT
1063 # define IP_FMT "%08lx"
1065 # define IP_FMT "%016lx"
1069 seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
1074 return trace_seq_printf(s, "0");
1076 if (sym_flags & TRACE_ITER_SYM_OFFSET)
1077 ret = seq_print_sym_offset(s, "%s", ip);
1079 ret = seq_print_sym_short(s, "%s", ip);
1084 if (sym_flags & TRACE_ITER_SYM_ADDR)
1085 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
1089 static void print_lat_help_header(struct seq_file *m)
1091 seq_puts(m, "# _------=> CPU# \n");
1092 seq_puts(m, "# / _-----=> irqs-off \n");
1093 seq_puts(m, "# | / _----=> need-resched \n");
1094 seq_puts(m, "# || / _---=> hardirq/softirq \n");
1095 seq_puts(m, "# ||| / _--=> preempt-depth \n");
1096 seq_puts(m, "# |||| / \n");
1097 seq_puts(m, "# ||||| delay \n");
1098 seq_puts(m, "# cmd pid ||||| time | caller \n");
1099 seq_puts(m, "# \\ / ||||| \\ | / \n");
1102 static void print_func_help_header(struct seq_file *m)
1104 seq_puts(m, "# TASK-PID CPU# TIMESTAMP FUNCTION\n");
1105 seq_puts(m, "# | | | | |\n");
1110 print_trace_header(struct seq_file *m, struct trace_iterator *iter)
1112 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
1113 struct trace_array *tr = iter->tr;
1114 struct trace_array_cpu *data = tr->data[tr->cpu];
1115 struct tracer *type = current_trace;
1116 unsigned long total;
1117 unsigned long entries;
1118 const char *name = "preemption";
1123 entries = ring_buffer_entries(iter->tr->buffer);
1125 ring_buffer_overruns(iter->tr->buffer);
1127 seq_printf(m, "%s latency trace v1.1.5 on %s\n",
1129 seq_puts(m, "-----------------------------------"
1130 "---------------------------------\n");
1131 seq_printf(m, " latency: %lu us, #%lu/%lu, CPU#%d |"
1132 " (M:%s VP:%d, KP:%d, SP:%d HP:%d",
1133 nsecs_to_usecs(data->saved_latency),
1137 #if defined(CONFIG_PREEMPT_NONE)
1139 #elif defined(CONFIG_PREEMPT_VOLUNTARY)
1141 #elif defined(CONFIG_PREEMPT)
1146 /* These are reserved for later use */
1149 seq_printf(m, " #P:%d)\n", num_online_cpus());
1153 seq_puts(m, " -----------------\n");
1154 seq_printf(m, " | task: %.16s-%d "
1155 "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n",
1156 data->comm, data->pid, data->uid, data->nice,
1157 data->policy, data->rt_priority);
1158 seq_puts(m, " -----------------\n");
1160 if (data->critical_start) {
1161 seq_puts(m, " => started at: ");
1162 seq_print_ip_sym(&iter->seq, data->critical_start, sym_flags);
1163 trace_print_seq(m, &iter->seq);
1164 seq_puts(m, "\n => ended at: ");
1165 seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags);
1166 trace_print_seq(m, &iter->seq);
1174 lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
1176 int hardirq, softirq;
1179 comm = trace_find_cmdline(entry->pid);
1181 trace_seq_printf(s, "%8.8s-%-5d ", comm, entry->pid);
1182 trace_seq_printf(s, "%3d", cpu);
1183 trace_seq_printf(s, "%c%c",
1184 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' : '.',
1185 ((entry->flags & TRACE_FLAG_NEED_RESCHED) ? 'N' : '.'));
1187 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
1188 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
1189 if (hardirq && softirq) {
1190 trace_seq_putc(s, 'H');
1193 trace_seq_putc(s, 'h');
1196 trace_seq_putc(s, 's');
1198 trace_seq_putc(s, '.');
1202 if (entry->preempt_count)
1203 trace_seq_printf(s, "%x", entry->preempt_count);
1205 trace_seq_puts(s, ".");
1208 unsigned long preempt_mark_thresh = 100;
1211 lat_print_timestamp(struct trace_seq *s, u64 abs_usecs,
1212 unsigned long rel_usecs)
1214 trace_seq_printf(s, " %4lldus", abs_usecs);
1215 if (rel_usecs > preempt_mark_thresh)
1216 trace_seq_puts(s, "!: ");
1217 else if (rel_usecs > 1)
1218 trace_seq_puts(s, "+: ");
1220 trace_seq_puts(s, " : ");
1223 static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
1226 * The message is supposed to contain an ending newline.
1227 * If the printing stops prematurely, try to add a newline of our own.
1229 void trace_seq_print_cont(struct trace_seq *s, struct trace_iterator *iter)
1231 struct trace_entry *ent;
1232 struct trace_field_cont *cont;
1235 ent = peek_next_entry(iter, iter->cpu, NULL);
1236 if (!ent || ent->type != TRACE_CONT) {
1237 trace_seq_putc(s, '\n');
1242 cont = (struct trace_field_cont *)ent;
1244 ok = (trace_seq_printf(s, "%s", cont->buf) > 0);
1245 ring_buffer_read(iter->buffer_iter[iter->cpu], NULL);
1246 ent = peek_next_entry(iter, iter->cpu, NULL);
1247 } while (ent && ent->type == TRACE_CONT);
1250 trace_seq_putc(s, '\n');
1254 print_lat_fmt(struct trace_iterator *iter, unsigned int trace_idx, int cpu)
1256 struct trace_seq *s = &iter->seq;
1257 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
1258 struct trace_entry *next_entry;
1259 unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
1260 struct trace_entry *entry = iter->ent;
1261 unsigned long abs_usecs;
1262 unsigned long rel_usecs;
1269 if (entry->type == TRACE_CONT)
1272 next_entry = find_next_entry(iter, NULL, &next_ts);
1275 rel_usecs = ns2usecs(next_ts - iter->ts);
1276 abs_usecs = ns2usecs(iter->ts - iter->tr->time_start);
1279 comm = trace_find_cmdline(entry->pid);
1280 trace_seq_printf(s, "%16s %5d %3d %d %08x %08x [%08lx]"
1281 " %ld.%03ldms (+%ld.%03ldms): ",
1283 entry->pid, cpu, entry->flags,
1284 entry->preempt_count, trace_idx,
1287 abs_usecs % 1000, rel_usecs/1000,
1290 lat_print_generic(s, entry, cpu);
1291 lat_print_timestamp(s, abs_usecs, rel_usecs);
1293 switch (entry->type) {
1295 struct ftrace_entry *field = (struct ftrace_entry *)entry;
1297 seq_print_ip_sym(s, field->ip, sym_flags);
1298 trace_seq_puts(s, " (");
1299 if (kretprobed(field->parent_ip))
1300 trace_seq_puts(s, KRETPROBE_MSG);
1302 seq_print_ip_sym(s, field->parent_ip, sym_flags);
1303 trace_seq_puts(s, ")\n");
1308 struct ctx_switch_entry *field =
1309 (struct ctx_switch_entry *)entry;
1311 T = field->next_state < sizeof(state_to_char) ?
1312 state_to_char[field->next_state] : 'X';
1314 state = field->prev_state ?
1315 __ffs(field->prev_state) + 1 : 0;
1316 S = state < sizeof(state_to_char) - 1 ? state_to_char[state] : 'X';
1317 comm = trace_find_cmdline(field->next_pid);
1318 trace_seq_printf(s, " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
1321 S, entry->type == TRACE_CTX ? "==>" : " +",
1328 case TRACE_SPECIAL: {
1329 struct special_entry *field = (struct special_entry *)entry;
1331 trace_seq_printf(s, "# %ld %ld %ld\n",
1338 struct stack_entry *field = (struct stack_entry *)entry;
1340 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
1342 trace_seq_puts(s, " <= ");
1343 seq_print_ip_sym(s, field->caller[i], sym_flags);
1345 trace_seq_puts(s, "\n");
1349 struct print_entry *field = (struct print_entry *)entry;
1351 seq_print_ip_sym(s, field->ip, sym_flags);
1352 trace_seq_printf(s, ": %s", field->buf);
1353 if (entry->flags & TRACE_FLAG_CONT)
1354 trace_seq_print_cont(s, iter);
1358 trace_seq_printf(s, "Unknown type %d\n", entry->type);
1363 static int print_trace_fmt(struct trace_iterator *iter)
1365 struct trace_seq *s = &iter->seq;
1366 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
1367 struct trace_entry *entry;
1368 unsigned long usec_rem;
1369 unsigned long long t;
1378 if (entry->type == TRACE_CONT)
1381 comm = trace_find_cmdline(iter->ent->pid);
1383 t = ns2usecs(iter->ts);
1384 usec_rem = do_div(t, 1000000ULL);
1385 secs = (unsigned long)t;
1387 ret = trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid);
1390 ret = trace_seq_printf(s, "[%03d] ", iter->cpu);
1393 ret = trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem);
1397 switch (entry->type) {
1399 struct ftrace_entry *field = (struct ftrace_entry *)entry;
1401 ret = seq_print_ip_sym(s, field->ip, sym_flags);
1404 if ((sym_flags & TRACE_ITER_PRINT_PARENT) &&
1406 ret = trace_seq_printf(s, " <-");
1409 if (kretprobed(field->parent_ip))
1410 ret = trace_seq_puts(s, KRETPROBE_MSG);
1412 ret = seq_print_ip_sym(s,
1418 ret = trace_seq_printf(s, "\n");
1425 struct ctx_switch_entry *field =
1426 (struct ctx_switch_entry *)entry;
1428 S = field->prev_state < sizeof(state_to_char) ?
1429 state_to_char[field->prev_state] : 'X';
1430 T = field->next_state < sizeof(state_to_char) ?
1431 state_to_char[field->next_state] : 'X';
1432 ret = trace_seq_printf(s, " %5d:%3d:%c %s [%03d] %5d:%3d:%c\n",
1436 entry->type == TRACE_CTX ? "==>" : " +",
1445 case TRACE_SPECIAL: {
1446 struct special_entry *field = (struct special_entry *)entry;
1448 ret = trace_seq_printf(s, "# %ld %ld %ld\n",
1457 struct stack_entry *field = (struct stack_entry *)entry;
1459 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
1461 ret = trace_seq_puts(s, " <= ");
1465 ret = seq_print_ip_sym(s, field->caller[i],
1470 ret = trace_seq_puts(s, "\n");
1476 struct print_entry *field = (struct print_entry *)entry;
1478 seq_print_ip_sym(s, field->ip, sym_flags);
1479 trace_seq_printf(s, ": %s", field->buf);
1480 if (entry->flags & TRACE_FLAG_CONT)
1481 trace_seq_print_cont(s, iter);
1488 static int print_raw_fmt(struct trace_iterator *iter)
1490 struct trace_seq *s = &iter->seq;
1491 struct trace_entry *entry;
1497 if (entry->type == TRACE_CONT)
1500 ret = trace_seq_printf(s, "%d %d %llu ",
1501 entry->pid, iter->cpu, iter->ts);
1505 switch (entry->type) {
1507 struct ftrace_entry *field = (struct ftrace_entry *)entry;
1509 ret = trace_seq_printf(s, "%x %x\n",
1518 struct ctx_switch_entry *field =
1519 (struct ctx_switch_entry *)entry;
1521 S = field->prev_state < sizeof(state_to_char) ?
1522 state_to_char[field->prev_state] : 'X';
1523 T = field->next_state < sizeof(state_to_char) ?
1524 state_to_char[field->next_state] : 'X';
1525 if (entry->type == TRACE_WAKE)
1527 ret = trace_seq_printf(s, "%d %d %c %d %d %d %c\n",
1541 struct special_entry *field = (struct special_entry *)entry;
1543 ret = trace_seq_printf(s, "# %ld %ld %ld\n",
1552 struct print_entry *field = (struct print_entry *)entry;
1554 trace_seq_printf(s, "# %lx %s", field->ip, field->buf);
1555 if (entry->flags & TRACE_FLAG_CONT)
1556 trace_seq_print_cont(s, iter);
1563 #define SEQ_PUT_FIELD_RET(s, x) \
1565 if (!trace_seq_putmem(s, &(x), sizeof(x))) \
1569 #define SEQ_PUT_HEX_FIELD_RET(s, x) \
1571 if (!trace_seq_putmem_hex(s, &(x), sizeof(x))) \
1575 static int print_hex_fmt(struct trace_iterator *iter)
1577 struct trace_seq *s = &iter->seq;
1578 unsigned char newline = '\n';
1579 struct trace_entry *entry;
1584 if (entry->type == TRACE_CONT)
1587 SEQ_PUT_HEX_FIELD_RET(s, entry->pid);
1588 SEQ_PUT_HEX_FIELD_RET(s, iter->cpu);
1589 SEQ_PUT_HEX_FIELD_RET(s, iter->ts);
1591 switch (entry->type) {
1593 struct ftrace_entry *field = (struct ftrace_entry *)entry;
1595 SEQ_PUT_HEX_FIELD_RET(s, field->ip);
1596 SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip);
1601 struct ctx_switch_entry *field =
1602 (struct ctx_switch_entry *)entry;
1604 S = field->prev_state < sizeof(state_to_char) ?
1605 state_to_char[field->prev_state] : 'X';
1606 T = field->next_state < sizeof(state_to_char) ?
1607 state_to_char[field->next_state] : 'X';
1608 if (entry->type == TRACE_WAKE)
1610 SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid);
1611 SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio);
1612 SEQ_PUT_HEX_FIELD_RET(s, S);
1613 SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu);
1614 SEQ_PUT_HEX_FIELD_RET(s, field->next_pid);
1615 SEQ_PUT_HEX_FIELD_RET(s, field->next_prio);
1616 SEQ_PUT_HEX_FIELD_RET(s, T);
1621 struct special_entry *field = (struct special_entry *)entry;
1623 SEQ_PUT_HEX_FIELD_RET(s, field->arg1);
1624 SEQ_PUT_HEX_FIELD_RET(s, field->arg2);
1625 SEQ_PUT_HEX_FIELD_RET(s, field->arg3);
1629 SEQ_PUT_FIELD_RET(s, newline);
1634 static int print_bin_fmt(struct trace_iterator *iter)
1636 struct trace_seq *s = &iter->seq;
1637 struct trace_entry *entry;
1641 if (entry->type == TRACE_CONT)
1644 SEQ_PUT_FIELD_RET(s, entry->pid);
1645 SEQ_PUT_FIELD_RET(s, iter->cpu);
1646 SEQ_PUT_FIELD_RET(s, iter->ts);
1648 switch (entry->type) {
1650 struct ftrace_entry *field = (struct ftrace_entry *)entry;
1652 SEQ_PUT_FIELD_RET(s, field->ip);
1653 SEQ_PUT_FIELD_RET(s, field->parent_ip);
1657 struct ctx_switch_entry *field =
1658 (struct ctx_switch_entry *)entry;
1660 SEQ_PUT_FIELD_RET(s, field->prev_pid);
1661 SEQ_PUT_FIELD_RET(s, field->prev_prio);
1662 SEQ_PUT_FIELD_RET(s, field->prev_state);
1663 SEQ_PUT_FIELD_RET(s, field->next_pid);
1664 SEQ_PUT_FIELD_RET(s, field->next_prio);
1665 SEQ_PUT_FIELD_RET(s, field->next_state);
1670 struct special_entry *field = (struct special_entry *)entry;
1672 SEQ_PUT_FIELD_RET(s, field->arg1);
1673 SEQ_PUT_FIELD_RET(s, field->arg2);
1674 SEQ_PUT_FIELD_RET(s, field->arg3);
1681 static int trace_empty(struct trace_iterator *iter)
1685 for_each_tracing_cpu(cpu) {
1686 if (!ring_buffer_iter_empty(iter->buffer_iter[cpu]))
1692 static int print_trace_line(struct trace_iterator *iter)
1694 if (iter->trace && iter->trace->print_line)
1695 return iter->trace->print_line(iter);
1697 if (trace_flags & TRACE_ITER_BIN)
1698 return print_bin_fmt(iter);
1700 if (trace_flags & TRACE_ITER_HEX)
1701 return print_hex_fmt(iter);
1703 if (trace_flags & TRACE_ITER_RAW)
1704 return print_raw_fmt(iter);
1706 if (iter->iter_flags & TRACE_FILE_LAT_FMT)
1707 return print_lat_fmt(iter, iter->idx, iter->cpu);
1709 return print_trace_fmt(iter);
1712 static int s_show(struct seq_file *m, void *v)
1714 struct trace_iterator *iter = v;
1716 if (iter->ent == NULL) {
1718 seq_printf(m, "# tracer: %s\n", iter->trace->name);
1721 if (iter->iter_flags & TRACE_FILE_LAT_FMT) {
1722 /* print nothing if the buffers are empty */
1723 if (trace_empty(iter))
1725 print_trace_header(m, iter);
1726 if (!(trace_flags & TRACE_ITER_VERBOSE))
1727 print_lat_help_header(m);
1729 if (!(trace_flags & TRACE_ITER_VERBOSE))
1730 print_func_help_header(m);
1733 print_trace_line(iter);
1734 trace_print_seq(m, &iter->seq);
1740 static struct seq_operations tracer_seq_ops = {
1747 static struct trace_iterator *
1748 __tracing_open(struct inode *inode, struct file *file, int *ret)
1750 struct trace_iterator *iter;
1754 if (tracing_disabled) {
1759 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
1765 mutex_lock(&trace_types_lock);
1766 if (current_trace && current_trace->print_max)
1769 iter->tr = inode->i_private;
1770 iter->trace = current_trace;
1773 for_each_tracing_cpu(cpu) {
1774 iter->buffer_iter[cpu] =
1775 ring_buffer_read_start(iter->tr->buffer, cpu);
1776 if (!iter->buffer_iter[cpu])
1780 /* TODO stop tracer */
1781 *ret = seq_open(file, &tracer_seq_ops);
1785 m = file->private_data;
1788 /* stop the trace while dumping */
1789 if (iter->tr->ctrl) {
1791 ftrace_function_enabled = 0;
1794 if (iter->trace && iter->trace->open)
1795 iter->trace->open(iter);
1797 mutex_unlock(&trace_types_lock);
1803 for_each_tracing_cpu(cpu) {
1804 if (iter->buffer_iter[cpu])
1805 ring_buffer_read_finish(iter->buffer_iter[cpu]);
1807 mutex_unlock(&trace_types_lock);
1809 return ERR_PTR(-ENOMEM);
1812 int tracing_open_generic(struct inode *inode, struct file *filp)
1814 if (tracing_disabled)
1817 filp->private_data = inode->i_private;
1821 int tracing_release(struct inode *inode, struct file *file)
1823 struct seq_file *m = (struct seq_file *)file->private_data;
1824 struct trace_iterator *iter = m->private;
1827 mutex_lock(&trace_types_lock);
1828 for_each_tracing_cpu(cpu) {
1829 if (iter->buffer_iter[cpu])
1830 ring_buffer_read_finish(iter->buffer_iter[cpu]);
1833 if (iter->trace && iter->trace->close)
1834 iter->trace->close(iter);
1836 /* reenable tracing if it was previously enabled */
1837 if (iter->tr->ctrl) {
1840 * It is safe to enable function tracing even if it
1843 ftrace_function_enabled = 1;
1845 mutex_unlock(&trace_types_lock);
1847 seq_release(inode, file);
1852 static int tracing_open(struct inode *inode, struct file *file)
1856 __tracing_open(inode, file, &ret);
1861 static int tracing_lt_open(struct inode *inode, struct file *file)
1863 struct trace_iterator *iter;
1866 iter = __tracing_open(inode, file, &ret);
1869 iter->iter_flags |= TRACE_FILE_LAT_FMT;
1876 t_next(struct seq_file *m, void *v, loff_t *pos)
1878 struct tracer *t = m->private;
1890 static void *t_start(struct seq_file *m, loff_t *pos)
1892 struct tracer *t = m->private;
1895 mutex_lock(&trace_types_lock);
1896 for (; t && l < *pos; t = t_next(m, t, &l))
1902 static void t_stop(struct seq_file *m, void *p)
1904 mutex_unlock(&trace_types_lock);
1907 static int t_show(struct seq_file *m, void *v)
1909 struct tracer *t = v;
1914 seq_printf(m, "%s", t->name);
1923 static struct seq_operations show_traces_seq_ops = {
1930 static int show_traces_open(struct inode *inode, struct file *file)
1934 if (tracing_disabled)
1937 ret = seq_open(file, &show_traces_seq_ops);
1939 struct seq_file *m = file->private_data;
1940 m->private = trace_types;
1946 static struct file_operations tracing_fops = {
1947 .open = tracing_open,
1949 .llseek = seq_lseek,
1950 .release = tracing_release,
1953 static struct file_operations tracing_lt_fops = {
1954 .open = tracing_lt_open,
1956 .llseek = seq_lseek,
1957 .release = tracing_release,
1960 static struct file_operations show_traces_fops = {
1961 .open = show_traces_open,
1963 .release = seq_release,
1967 * Only trace on a CPU if the bitmask is set:
1969 static cpumask_t tracing_cpumask = CPU_MASK_ALL;
1972 * When tracing/tracing_cpu_mask is modified then this holds
1973 * the new bitmask we are about to install:
1975 static cpumask_t tracing_cpumask_new;
1978 * The tracer itself will not take this lock, but still we want
1979 * to provide a consistent cpumask to user-space:
1981 static DEFINE_MUTEX(tracing_cpumask_update_lock);
1984 * Temporary storage for the character representation of the
1985 * CPU bitmask (and one more byte for the newline):
1987 static char mask_str[NR_CPUS + 1];
1990 tracing_cpumask_read(struct file *filp, char __user *ubuf,
1991 size_t count, loff_t *ppos)
1995 mutex_lock(&tracing_cpumask_update_lock);
1997 len = cpumask_scnprintf(mask_str, count, tracing_cpumask);
1998 if (count - len < 2) {
2002 len += sprintf(mask_str + len, "\n");
2003 count = simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+1);
2006 mutex_unlock(&tracing_cpumask_update_lock);
2012 tracing_cpumask_write(struct file *filp, const char __user *ubuf,
2013 size_t count, loff_t *ppos)
2017 mutex_lock(&tracing_cpumask_update_lock);
2018 err = cpumask_parse_user(ubuf, count, tracing_cpumask_new);
2022 raw_local_irq_disable();
2023 __raw_spin_lock(&ftrace_max_lock);
2024 for_each_tracing_cpu(cpu) {
2026 * Increase/decrease the disabled counter if we are
2027 * about to flip a bit in the cpumask:
2029 if (cpu_isset(cpu, tracing_cpumask) &&
2030 !cpu_isset(cpu, tracing_cpumask_new)) {
2031 atomic_inc(&global_trace.data[cpu]->disabled);
2033 if (!cpu_isset(cpu, tracing_cpumask) &&
2034 cpu_isset(cpu, tracing_cpumask_new)) {
2035 atomic_dec(&global_trace.data[cpu]->disabled);
2038 __raw_spin_unlock(&ftrace_max_lock);
2039 raw_local_irq_enable();
2041 tracing_cpumask = tracing_cpumask_new;
2043 mutex_unlock(&tracing_cpumask_update_lock);
2048 mutex_unlock(&tracing_cpumask_update_lock);
2053 static struct file_operations tracing_cpumask_fops = {
2054 .open = tracing_open_generic,
2055 .read = tracing_cpumask_read,
2056 .write = tracing_cpumask_write,
2060 tracing_iter_ctrl_read(struct file *filp, char __user *ubuf,
2061 size_t cnt, loff_t *ppos)
2068 /* calulate max size */
2069 for (i = 0; trace_options[i]; i++) {
2070 len += strlen(trace_options[i]);
2071 len += 3; /* "no" and space */
2074 /* +2 for \n and \0 */
2075 buf = kmalloc(len + 2, GFP_KERNEL);
2079 for (i = 0; trace_options[i]; i++) {
2080 if (trace_flags & (1 << i))
2081 r += sprintf(buf + r, "%s ", trace_options[i]);
2083 r += sprintf(buf + r, "no%s ", trace_options[i]);
2086 r += sprintf(buf + r, "\n");
2087 WARN_ON(r >= len + 2);
2089 r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
2097 tracing_iter_ctrl_write(struct file *filp, const char __user *ubuf,
2098 size_t cnt, loff_t *ppos)
2105 if (cnt >= sizeof(buf))
2108 if (copy_from_user(&buf, ubuf, cnt))
2113 if (strncmp(buf, "no", 2) == 0) {
2118 for (i = 0; trace_options[i]; i++) {
2119 int len = strlen(trace_options[i]);
2121 if (strncmp(cmp, trace_options[i], len) == 0) {
2123 trace_flags &= ~(1 << i);
2125 trace_flags |= (1 << i);
2130 * If no option could be set, return an error:
2132 if (!trace_options[i])
2140 static struct file_operations tracing_iter_fops = {
2141 .open = tracing_open_generic,
2142 .read = tracing_iter_ctrl_read,
2143 .write = tracing_iter_ctrl_write,
2146 static const char readme_msg[] =
2147 "tracing mini-HOWTO:\n\n"
2149 "# mount -t debugfs nodev /debug\n\n"
2150 "# cat /debug/tracing/available_tracers\n"
2151 "wakeup preemptirqsoff preemptoff irqsoff ftrace sched_switch none\n\n"
2152 "# cat /debug/tracing/current_tracer\n"
2154 "# echo sched_switch > /debug/tracing/current_tracer\n"
2155 "# cat /debug/tracing/current_tracer\n"
2157 "# cat /debug/tracing/iter_ctrl\n"
2158 "noprint-parent nosym-offset nosym-addr noverbose\n"
2159 "# echo print-parent > /debug/tracing/iter_ctrl\n"
2160 "# echo 1 > /debug/tracing/tracing_enabled\n"
2161 "# cat /debug/tracing/trace > /tmp/trace.txt\n"
2162 "echo 0 > /debug/tracing/tracing_enabled\n"
2166 tracing_readme_read(struct file *filp, char __user *ubuf,
2167 size_t cnt, loff_t *ppos)
2169 return simple_read_from_buffer(ubuf, cnt, ppos,
2170 readme_msg, strlen(readme_msg));
2173 static struct file_operations tracing_readme_fops = {
2174 .open = tracing_open_generic,
2175 .read = tracing_readme_read,
2179 tracing_ctrl_read(struct file *filp, char __user *ubuf,
2180 size_t cnt, loff_t *ppos)
2182 struct trace_array *tr = filp->private_data;
2186 r = sprintf(buf, "%ld\n", tr->ctrl);
2187 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
2191 tracing_ctrl_write(struct file *filp, const char __user *ubuf,
2192 size_t cnt, loff_t *ppos)
2194 struct trace_array *tr = filp->private_data;
2199 if (cnt >= sizeof(buf))
2202 if (copy_from_user(&buf, ubuf, cnt))
2207 ret = strict_strtoul(buf, 10, &val);
2213 mutex_lock(&trace_types_lock);
2214 if (tr->ctrl ^ val) {
2222 if (current_trace && current_trace->ctrl_update)
2223 current_trace->ctrl_update(tr);
2225 mutex_unlock(&trace_types_lock);
2233 tracing_set_trace_read(struct file *filp, char __user *ubuf,
2234 size_t cnt, loff_t *ppos)
2236 char buf[max_tracer_type_len+2];
2239 mutex_lock(&trace_types_lock);
2241 r = sprintf(buf, "%s\n", current_trace->name);
2243 r = sprintf(buf, "\n");
2244 mutex_unlock(&trace_types_lock);
2246 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
2250 tracing_set_trace_write(struct file *filp, const char __user *ubuf,
2251 size_t cnt, loff_t *ppos)
2253 struct trace_array *tr = &global_trace;
2255 char buf[max_tracer_type_len+1];
2258 if (cnt > max_tracer_type_len)
2259 cnt = max_tracer_type_len;
2261 if (copy_from_user(&buf, ubuf, cnt))
2266 /* strip ending whitespace. */
2267 for (i = cnt - 1; i > 0 && isspace(buf[i]); i--)
2270 mutex_lock(&trace_types_lock);
2271 for (t = trace_types; t; t = t->next) {
2272 if (strcmp(t->name, buf) == 0)
2275 if (!t || t == current_trace)
2278 if (current_trace && current_trace->reset)
2279 current_trace->reset(tr);
2286 mutex_unlock(&trace_types_lock);
2294 tracing_max_lat_read(struct file *filp, char __user *ubuf,
2295 size_t cnt, loff_t *ppos)
2297 unsigned long *ptr = filp->private_data;
2301 r = snprintf(buf, sizeof(buf), "%ld\n",
2302 *ptr == (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr));
2303 if (r > sizeof(buf))
2305 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
2309 tracing_max_lat_write(struct file *filp, const char __user *ubuf,
2310 size_t cnt, loff_t *ppos)
2312 long *ptr = filp->private_data;
2317 if (cnt >= sizeof(buf))
2320 if (copy_from_user(&buf, ubuf, cnt))
2325 ret = strict_strtoul(buf, 10, &val);
2334 static atomic_t tracing_reader;
2336 static int tracing_open_pipe(struct inode *inode, struct file *filp)
2338 struct trace_iterator *iter;
2341 if (tracing_disabled)
2344 /* We only allow for reader of the pipe */
2345 if (atomic_inc_return(&tracing_reader) != 1) {
2346 atomic_dec(&tracing_reader);
2350 /* create a buffer to store the information to pass to userspace */
2351 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
2355 mutex_lock(&trace_types_lock);
2356 iter->tr = &global_trace;
2357 iter->trace = current_trace;
2358 filp->private_data = iter;
2360 for_each_tracing_cpu(cpu) {
2361 iter->buffer_iter[cpu] =
2362 ring_buffer_read_start(iter->tr->buffer, cpu);
2363 if (!iter->buffer_iter[cpu])
2367 if (iter->trace->pipe_open)
2368 iter->trace->pipe_open(iter);
2369 mutex_unlock(&trace_types_lock);
2374 for_each_tracing_cpu(cpu) {
2375 if (iter->buffer_iter[cpu])
2376 ring_buffer_read_finish(iter->buffer_iter[cpu]);
2378 mutex_unlock(&trace_types_lock);
2383 static int tracing_release_pipe(struct inode *inode, struct file *file)
2385 struct trace_iterator *iter = file->private_data;
2388 for_each_tracing_cpu(cpu) {
2389 if (iter->buffer_iter[cpu])
2390 ring_buffer_read_finish(iter->buffer_iter[cpu]);
2393 atomic_dec(&tracing_reader);
2399 tracing_poll_pipe(struct file *filp, poll_table *poll_table)
2401 struct trace_iterator *iter = filp->private_data;
2403 if (trace_flags & TRACE_ITER_BLOCK) {
2405 * Always select as readable when in blocking mode
2407 return POLLIN | POLLRDNORM;
2409 if (!trace_empty(iter))
2410 return POLLIN | POLLRDNORM;
2411 poll_wait(filp, &trace_wait, poll_table);
2412 if (!trace_empty(iter))
2413 return POLLIN | POLLRDNORM;
2423 tracing_read_pipe(struct file *filp, char __user *ubuf,
2424 size_t cnt, loff_t *ppos)
2426 struct trace_iterator *iter = filp->private_data;
2427 unsigned long flags;
2428 #ifdef CONFIG_FTRACE
2433 /* return any leftover data */
2434 sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
2439 trace_seq_reset(&iter->seq);
2441 mutex_lock(&trace_types_lock);
2442 if (iter->trace->read) {
2443 sret = iter->trace->read(iter, filp, ubuf, cnt, ppos);
2448 while (trace_empty(iter)) {
2450 if ((filp->f_flags & O_NONBLOCK)) {
2456 * This is a make-shift waitqueue. The reason we don't use
2457 * an actual wait queue is because:
2458 * 1) we only ever have one waiter
2459 * 2) the tracing, traces all functions, we don't want
2460 * the overhead of calling wake_up and friends
2461 * (and tracing them too)
2462 * Anyway, this is really very primitive wakeup.
2464 set_current_state(TASK_INTERRUPTIBLE);
2465 iter->tr->waiter = current;
2467 mutex_unlock(&trace_types_lock);
2469 /* sleep for 100 msecs, and try again. */
2470 schedule_timeout(HZ/10);
2472 mutex_lock(&trace_types_lock);
2474 iter->tr->waiter = NULL;
2476 if (signal_pending(current)) {
2481 if (iter->trace != current_trace)
2485 * We block until we read something and tracing is disabled.
2486 * We still block if tracing is disabled, but we have never
2487 * read anything. This allows a user to cat this file, and
2488 * then enable tracing. But after we have read something,
2489 * we give an EOF when tracing is again disabled.
2491 * iter->pos will be 0 if we haven't read anything.
2493 if (!tracer_enabled && iter->pos)
2499 /* stop when tracing is finished */
2500 if (trace_empty(iter))
2503 if (cnt >= PAGE_SIZE)
2504 cnt = PAGE_SIZE - 1;
2506 /* reset all but tr, trace, and overruns */
2507 memset(&iter->seq, 0,
2508 sizeof(struct trace_iterator) -
2509 offsetof(struct trace_iterator, seq));
2513 * We need to stop all tracing on all CPUS to read the
2514 * the next buffer. This is a bit expensive, but is
2515 * not done often. We fill all what we can read,
2516 * and then release the locks again.
2519 local_irq_disable();
2520 #ifdef CONFIG_FTRACE
2521 ftrace_save = ftrace_enabled;
2525 ring_buffer_lock(iter->tr->buffer, &flags);
2527 while (find_next_entry_inc(iter) != NULL) {
2529 int len = iter->seq.len;
2531 ret = print_trace_line(iter);
2533 /* don't print partial lines */
2534 iter->seq.len = len;
2538 trace_consume(iter);
2540 if (iter->seq.len >= cnt)
2544 ring_buffer_unlock(iter->tr->buffer, flags);
2545 #ifdef CONFIG_FTRACE
2546 ftrace_enabled = ftrace_save;
2550 /* Now copy what we have to the user */
2551 sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
2552 if (iter->seq.readpos >= iter->seq.len)
2553 trace_seq_reset(&iter->seq);
2558 mutex_unlock(&trace_types_lock);
2564 tracing_entries_read(struct file *filp, char __user *ubuf,
2565 size_t cnt, loff_t *ppos)
2567 struct trace_array *tr = filp->private_data;
2571 r = sprintf(buf, "%lu\n", tr->entries);
2572 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
2576 tracing_entries_write(struct file *filp, const char __user *ubuf,
2577 size_t cnt, loff_t *ppos)
2582 struct trace_array *tr = filp->private_data;
2584 if (cnt >= sizeof(buf))
2587 if (copy_from_user(&buf, ubuf, cnt))
2592 ret = strict_strtoul(buf, 10, &val);
2596 /* must have at least 1 entry */
2600 mutex_lock(&trace_types_lock);
2604 pr_info("ftrace: please disable tracing"
2605 " before modifying buffer size\n");
2609 if (val != global_trace.entries) {
2610 ret = ring_buffer_resize(global_trace.buffer, val);
2616 ret = ring_buffer_resize(max_tr.buffer, val);
2620 r = ring_buffer_resize(global_trace.buffer,
2621 global_trace.entries);
2623 /* AARGH! We are left with different
2624 * size max buffer!!!! */
2626 tracing_disabled = 1;
2631 global_trace.entries = val;
2636 /* If check pages failed, return ENOMEM */
2637 if (tracing_disabled)
2640 max_tr.entries = global_trace.entries;
2641 mutex_unlock(&trace_types_lock);
2646 static int mark_printk(const char *fmt, ...)
2650 va_start(args, fmt);
2651 ret = trace_vprintk(0, fmt, args);
2657 tracing_mark_write(struct file *filp, const char __user *ubuf,
2658 size_t cnt, loff_t *fpos)
2662 struct trace_array *tr = &global_trace;
2664 if (!tr->ctrl || tracing_disabled)
2667 if (cnt > TRACE_BUF_SIZE)
2668 cnt = TRACE_BUF_SIZE;
2670 buf = kmalloc(cnt + 1, GFP_KERNEL);
2674 if (copy_from_user(buf, ubuf, cnt)) {
2679 /* Cut from the first nil or newline. */
2681 end = strchr(buf, '\n');
2685 cnt = mark_printk("%s\n", buf);
2692 static struct file_operations tracing_max_lat_fops = {
2693 .open = tracing_open_generic,
2694 .read = tracing_max_lat_read,
2695 .write = tracing_max_lat_write,
2698 static struct file_operations tracing_ctrl_fops = {
2699 .open = tracing_open_generic,
2700 .read = tracing_ctrl_read,
2701 .write = tracing_ctrl_write,
2704 static struct file_operations set_tracer_fops = {
2705 .open = tracing_open_generic,
2706 .read = tracing_set_trace_read,
2707 .write = tracing_set_trace_write,
2710 static struct file_operations tracing_pipe_fops = {
2711 .open = tracing_open_pipe,
2712 .poll = tracing_poll_pipe,
2713 .read = tracing_read_pipe,
2714 .release = tracing_release_pipe,
2717 static struct file_operations tracing_entries_fops = {
2718 .open = tracing_open_generic,
2719 .read = tracing_entries_read,
2720 .write = tracing_entries_write,
2723 static struct file_operations tracing_mark_fops = {
2724 .open = tracing_open_generic,
2725 .write = tracing_mark_write,
2728 #ifdef CONFIG_DYNAMIC_FTRACE
2731 tracing_read_long(struct file *filp, char __user *ubuf,
2732 size_t cnt, loff_t *ppos)
2734 unsigned long *p = filp->private_data;
2738 r = sprintf(buf, "%ld\n", *p);
2740 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
2743 static struct file_operations tracing_read_long_fops = {
2744 .open = tracing_open_generic,
2745 .read = tracing_read_long,
2749 static struct dentry *d_tracer;
2751 struct dentry *tracing_init_dentry(void)
2758 d_tracer = debugfs_create_dir("tracing", NULL);
2760 if (!d_tracer && !once) {
2762 pr_warning("Could not create debugfs directory 'tracing'\n");
2769 #ifdef CONFIG_FTRACE_SELFTEST
2770 /* Let selftest have access to static functions in this file */
2771 #include "trace_selftest.c"
2774 static __init int tracer_init_debugfs(void)
2776 struct dentry *d_tracer;
2777 struct dentry *entry;
2779 d_tracer = tracing_init_dentry();
2781 entry = debugfs_create_file("tracing_enabled", 0644, d_tracer,
2782 &global_trace, &tracing_ctrl_fops);
2784 pr_warning("Could not create debugfs 'tracing_enabled' entry\n");
2786 entry = debugfs_create_file("iter_ctrl", 0644, d_tracer,
2787 NULL, &tracing_iter_fops);
2789 pr_warning("Could not create debugfs 'iter_ctrl' entry\n");
2791 entry = debugfs_create_file("tracing_cpumask", 0644, d_tracer,
2792 NULL, &tracing_cpumask_fops);
2794 pr_warning("Could not create debugfs 'tracing_cpumask' entry\n");
2796 entry = debugfs_create_file("latency_trace", 0444, d_tracer,
2797 &global_trace, &tracing_lt_fops);
2799 pr_warning("Could not create debugfs 'latency_trace' entry\n");
2801 entry = debugfs_create_file("trace", 0444, d_tracer,
2802 &global_trace, &tracing_fops);
2804 pr_warning("Could not create debugfs 'trace' entry\n");
2806 entry = debugfs_create_file("available_tracers", 0444, d_tracer,
2807 &global_trace, &show_traces_fops);
2809 pr_warning("Could not create debugfs 'available_tracers' entry\n");
2811 entry = debugfs_create_file("current_tracer", 0444, d_tracer,
2812 &global_trace, &set_tracer_fops);
2814 pr_warning("Could not create debugfs 'current_tracer' entry\n");
2816 entry = debugfs_create_file("tracing_max_latency", 0644, d_tracer,
2817 &tracing_max_latency,
2818 &tracing_max_lat_fops);
2820 pr_warning("Could not create debugfs "
2821 "'tracing_max_latency' entry\n");
2823 entry = debugfs_create_file("tracing_thresh", 0644, d_tracer,
2824 &tracing_thresh, &tracing_max_lat_fops);
2826 pr_warning("Could not create debugfs "
2827 "'tracing_thresh' entry\n");
2828 entry = debugfs_create_file("README", 0644, d_tracer,
2829 NULL, &tracing_readme_fops);
2831 pr_warning("Could not create debugfs 'README' entry\n");
2833 entry = debugfs_create_file("trace_pipe", 0644, d_tracer,
2834 NULL, &tracing_pipe_fops);
2836 pr_warning("Could not create debugfs "
2837 "'trace_pipe' entry\n");
2839 entry = debugfs_create_file("trace_entries", 0644, d_tracer,
2840 &global_trace, &tracing_entries_fops);
2842 pr_warning("Could not create debugfs "
2843 "'trace_entries' entry\n");
2845 entry = debugfs_create_file("trace_marker", 0220, d_tracer,
2846 NULL, &tracing_mark_fops);
2848 pr_warning("Could not create debugfs "
2849 "'trace_marker' entry\n");
2851 #ifdef CONFIG_DYNAMIC_FTRACE
2852 entry = debugfs_create_file("dyn_ftrace_total_info", 0444, d_tracer,
2853 &ftrace_update_tot_cnt,
2854 &tracing_read_long_fops);
2856 pr_warning("Could not create debugfs "
2857 "'dyn_ftrace_total_info' entry\n");
2859 #ifdef CONFIG_SYSPROF_TRACER
2860 init_tracer_sysprof_debugfs(d_tracer);
2865 int trace_vprintk(unsigned long ip, const char *fmt, va_list args)
2867 static DEFINE_SPINLOCK(trace_buf_lock);
2868 static char trace_buf[TRACE_BUF_SIZE];
2870 struct ring_buffer_event *event;
2871 struct trace_array *tr = &global_trace;
2872 struct trace_array_cpu *data;
2873 struct print_entry *entry;
2874 unsigned long flags, irq_flags;
2876 int cpu, len = 0, size;
2878 if (!tr->ctrl || tracing_disabled)
2881 local_irq_save(flags);
2882 cpu = raw_smp_processor_id();
2883 data = tr->data[cpu];
2884 disabled = atomic_inc_return(&data->disabled);
2886 if (unlikely(disabled != 1))
2889 spin_lock(&trace_buf_lock);
2890 len = vsnprintf(trace_buf, TRACE_BUF_SIZE, fmt, args);
2892 len = min(len, TRACE_BUF_SIZE-1);
2895 size = sizeof(*entry) + len + 1;
2896 event = ring_buffer_lock_reserve(tr->buffer, size, &irq_flags);
2899 entry = ring_buffer_event_data(event);
2900 tracing_generic_entry_update(&entry->ent, flags);
2901 entry->ent.type = TRACE_PRINT;
2904 memcpy(&entry->buf, trace_buf, len);
2905 entry->buf[len] = 0;
2906 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
2909 spin_unlock(&trace_buf_lock);
2912 atomic_dec(&data->disabled);
2913 local_irq_restore(flags);
2917 EXPORT_SYMBOL_GPL(trace_vprintk);
2919 int __ftrace_printk(unsigned long ip, const char *fmt, ...)
2924 if (!(trace_flags & TRACE_ITER_PRINTK))
2928 ret = trace_vprintk(ip, fmt, ap);
2932 EXPORT_SYMBOL_GPL(__ftrace_printk);
2934 static int trace_panic_handler(struct notifier_block *this,
2935 unsigned long event, void *unused)
2941 static struct notifier_block trace_panic_notifier = {
2942 .notifier_call = trace_panic_handler,
2944 .priority = 150 /* priority: INT_MAX >= x >= 0 */
2947 static int trace_die_handler(struct notifier_block *self,
2961 static struct notifier_block trace_die_notifier = {
2962 .notifier_call = trace_die_handler,
2967 * printk is set to max of 1024, we really don't need it that big.
2968 * Nothing should be printing 1000 characters anyway.
2970 #define TRACE_MAX_PRINT 1000
2973 * Define here KERN_TRACE so that we have one place to modify
2974 * it if we decide to change what log level the ftrace dump
2977 #define KERN_TRACE KERN_INFO
2980 trace_printk_seq(struct trace_seq *s)
2982 /* Probably should print a warning here. */
2986 /* should be zero ended, but we are paranoid. */
2987 s->buffer[s->len] = 0;
2989 printk(KERN_TRACE "%s", s->buffer);
2995 void ftrace_dump(void)
2997 static DEFINE_SPINLOCK(ftrace_dump_lock);
2998 /* use static because iter can be a bit big for the stack */
2999 static struct trace_iterator iter;
3000 static cpumask_t mask;
3001 static int dump_ran;
3002 unsigned long flags, irq_flags;
3006 spin_lock_irqsave(&ftrace_dump_lock, flags);
3012 /* No turning back! */
3013 ftrace_kill_atomic();
3015 printk(KERN_TRACE "Dumping ftrace buffer:\n");
3017 iter.tr = &global_trace;
3018 iter.trace = current_trace;
3021 * We need to stop all tracing on all CPUS to read the
3022 * the next buffer. This is a bit expensive, but is
3023 * not done often. We fill all what we can read,
3024 * and then release the locks again.
3029 ring_buffer_lock(iter.tr->buffer, &irq_flags);
3031 while (!trace_empty(&iter)) {
3034 printk(KERN_TRACE "---------------------------------\n");
3038 /* reset all but tr, trace, and overruns */
3039 memset(&iter.seq, 0,
3040 sizeof(struct trace_iterator) -
3041 offsetof(struct trace_iterator, seq));
3042 iter.iter_flags |= TRACE_FILE_LAT_FMT;
3045 if (find_next_entry_inc(&iter) != NULL) {
3046 print_trace_line(&iter);
3047 trace_consume(&iter);
3050 trace_printk_seq(&iter.seq);
3054 printk(KERN_TRACE " (ftrace buffer empty)\n");
3056 printk(KERN_TRACE "---------------------------------\n");
3058 ring_buffer_unlock(iter.tr->buffer, irq_flags);
3061 spin_unlock_irqrestore(&ftrace_dump_lock, flags);
3064 __init static int tracer_alloc_buffers(void)
3066 struct trace_array_cpu *data;
3069 /* TODO: make the number of buffers hot pluggable with CPUS */
3070 tracing_buffer_mask = cpu_possible_map;
3072 global_trace.buffer = ring_buffer_alloc(trace_buf_size,
3073 TRACE_BUFFER_FLAGS);
3074 if (!global_trace.buffer) {
3075 printk(KERN_ERR "tracer: failed to allocate ring buffer!\n");
3079 global_trace.entries = ring_buffer_size(global_trace.buffer);
3081 #ifdef CONFIG_TRACER_MAX_TRACE
3082 max_tr.buffer = ring_buffer_alloc(trace_buf_size,
3083 TRACE_BUFFER_FLAGS);
3084 if (!max_tr.buffer) {
3085 printk(KERN_ERR "tracer: failed to allocate max ring buffer!\n");
3087 ring_buffer_free(global_trace.buffer);
3090 max_tr.entries = ring_buffer_size(max_tr.buffer);
3091 WARN_ON(max_tr.entries != global_trace.entries);
3094 /* Allocate the first page for all buffers */
3095 for_each_tracing_cpu(i) {
3096 data = global_trace.data[i] = &per_cpu(global_trace_cpu, i);
3097 max_tr.data[i] = &per_cpu(max_data, i);
3100 trace_init_cmdlines();
3102 register_tracer(&nop_trace);
3103 #ifdef CONFIG_BOOT_TRACER
3104 register_tracer(&boot_tracer);
3105 current_trace = &boot_tracer;
3106 current_trace->init(&global_trace);
3108 current_trace = &nop_trace;
3111 /* All seems OK, enable tracing */
3112 global_trace.ctrl = tracer_enabled;
3113 tracing_disabled = 0;
3115 atomic_notifier_chain_register(&panic_notifier_list,
3116 &trace_panic_notifier);
3118 register_die_notifier(&trace_die_notifier);
3122 early_initcall(tracer_alloc_buffers);
3123 fs_initcall(tracer_init_debugfs);