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>
39 unsigned long __read_mostly tracing_max_latency
= (cycle_t
)ULONG_MAX
;
40 unsigned long __read_mostly tracing_thresh
;
42 static unsigned long __read_mostly tracing_nr_buffers
;
43 static cpumask_t __read_mostly tracing_buffer_mask
;
45 #define for_each_tracing_cpu(cpu) \
46 for_each_cpu_mask(cpu, tracing_buffer_mask)
48 static int trace_alloc_page(void);
49 static int trace_free_page(void);
51 static int tracing_disabled
= 1;
53 static unsigned long tracing_pages_allocated
;
56 ns2usecs(cycle_t nsec
)
63 cycle_t
ftrace_now(int cpu
)
65 return cpu_clock(cpu
);
69 * The global_trace is the descriptor that holds the tracing
70 * buffers for the live tracing. For each CPU, it contains
71 * a link list of pages that will store trace entries. The
72 * page descriptor of the pages in the memory is used to hold
73 * the link list by linking the lru item in the page descriptor
74 * to each of the pages in the buffer per CPU.
76 * For each active CPU there is a data field that holds the
77 * pages for the buffer for that CPU. Each CPU has the same number
78 * of pages allocated for its buffer.
80 static struct trace_array global_trace
;
82 static DEFINE_PER_CPU(struct trace_array_cpu
, global_trace_cpu
);
85 * The max_tr is used to snapshot the global_trace when a maximum
86 * latency is reached. Some tracers will use this to store a maximum
87 * trace while it continues examining live traces.
89 * The buffers for the max_tr are set up the same as the global_trace.
90 * When a snapshot is taken, the link list of the max_tr is swapped
91 * with the link list of the global_trace and the buffers are reset for
92 * the global_trace so the tracing can continue.
94 static struct trace_array max_tr
;
96 static DEFINE_PER_CPU(struct trace_array_cpu
, max_data
);
98 /* tracer_enabled is used to toggle activation of a tracer */
99 static int tracer_enabled
= 1;
101 /* function tracing enabled */
102 int ftrace_function_enabled
;
105 * trace_nr_entries is the number of entries that is allocated
106 * for a buffer. Note, the number of entries is always rounded
107 * to ENTRIES_PER_PAGE.
109 * This number is purposely set to a low number of 16384.
110 * If the dump on oops happens, it will be much appreciated
111 * to not have to wait for all that output. Anyway this can be
112 * boot time and run time configurable.
114 #define TRACE_ENTRIES_DEFAULT 16384UL
116 static unsigned long trace_nr_entries
= TRACE_ENTRIES_DEFAULT
;
118 /* trace_types holds a link list of available tracers. */
119 static struct tracer
*trace_types __read_mostly
;
121 /* current_trace points to the tracer that is currently active */
122 static struct tracer
*current_trace __read_mostly
;
125 * max_tracer_type_len is used to simplify the allocating of
126 * buffers to read userspace tracer names. We keep track of
127 * the longest tracer name registered.
129 static int max_tracer_type_len
;
132 * trace_types_lock is used to protect the trace_types list.
133 * This lock is also used to keep user access serialized.
134 * Accesses from userspace will grab this lock while userspace
135 * activities happen inside the kernel.
137 static DEFINE_MUTEX(trace_types_lock
);
139 /* trace_wait is a waitqueue for tasks blocked on trace_poll */
140 static DECLARE_WAIT_QUEUE_HEAD(trace_wait
);
142 /* trace_flags holds iter_ctrl options */
143 unsigned long trace_flags
= TRACE_ITER_PRINT_PARENT
;
145 static notrace
void no_trace_init(struct trace_array
*tr
)
149 ftrace_function_enabled
= 0;
151 for_each_online_cpu(cpu
)
152 tracing_reset(tr
->data
[cpu
]);
156 /* dummy trace to disable tracing */
157 static struct tracer no_tracer __read_mostly
= {
159 .init
= no_trace_init
164 * trace_wake_up - wake up tasks waiting for trace input
166 * Simply wakes up any task that is blocked on the trace_wait
167 * queue. These is used with trace_poll for tasks polling the trace.
169 void trace_wake_up(void)
172 * The runqueue_is_locked() can fail, but this is the best we
175 if (!(trace_flags
& TRACE_ITER_BLOCK
) && !runqueue_is_locked())
176 wake_up(&trace_wait
);
179 #define ENTRIES_PER_PAGE (PAGE_SIZE / sizeof(struct trace_entry))
181 static int __init
set_nr_entries(char *str
)
183 unsigned long nr_entries
;
188 ret
= strict_strtoul(str
, 0, &nr_entries
);
189 /* nr_entries can not be zero */
190 if (ret
< 0 || nr_entries
== 0)
192 trace_nr_entries
= nr_entries
;
195 __setup("trace_entries=", set_nr_entries
);
197 unsigned long nsecs_to_usecs(unsigned long nsecs
)
203 * trace_flag_type is an enumeration that holds different
204 * states when a trace occurs. These are:
205 * IRQS_OFF - interrupts were disabled
206 * NEED_RESCED - reschedule is requested
207 * HARDIRQ - inside an interrupt handler
208 * SOFTIRQ - inside a softirq handler
209 * CONT - multiple entries hold the trace item
211 enum trace_flag_type
{
212 TRACE_FLAG_IRQS_OFF
= 0x01,
213 TRACE_FLAG_NEED_RESCHED
= 0x02,
214 TRACE_FLAG_HARDIRQ
= 0x04,
215 TRACE_FLAG_SOFTIRQ
= 0x08,
216 TRACE_FLAG_CONT
= 0x10,
220 * TRACE_ITER_SYM_MASK masks the options in trace_flags that
221 * control the output of kernel symbols.
223 #define TRACE_ITER_SYM_MASK \
224 (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
226 /* These must match the bit postions in trace_iterator_flags */
227 static const char *trace_options
[] = {
243 * ftrace_max_lock is used to protect the swapping of buffers
244 * when taking a max snapshot. The buffers themselves are
245 * protected by per_cpu spinlocks. But the action of the swap
246 * needs its own lock.
248 * This is defined as a raw_spinlock_t in order to help
249 * with performance when lockdep debugging is enabled.
251 static raw_spinlock_t ftrace_max_lock
=
252 (raw_spinlock_t
)__RAW_SPIN_LOCK_UNLOCKED
;
255 * Copy the new maximum trace into the separate maximum-trace
256 * structure. (this way the maximum trace is permanently saved,
257 * for later retrieval via /debugfs/tracing/latency_trace)
260 __update_max_tr(struct trace_array
*tr
, struct task_struct
*tsk
, int cpu
)
262 struct trace_array_cpu
*data
= tr
->data
[cpu
];
265 max_tr
.time_start
= data
->preempt_timestamp
;
267 data
= max_tr
.data
[cpu
];
268 data
->saved_latency
= tracing_max_latency
;
270 memcpy(data
->comm
, tsk
->comm
, TASK_COMM_LEN
);
271 data
->pid
= tsk
->pid
;
272 data
->uid
= tsk
->uid
;
273 data
->nice
= tsk
->static_prio
- 20 - MAX_RT_PRIO
;
274 data
->policy
= tsk
->policy
;
275 data
->rt_priority
= tsk
->rt_priority
;
277 /* record this tasks comm */
278 tracing_record_cmdline(current
);
281 #define CHECK_COND(cond) \
282 if (unlikely(cond)) { \
283 tracing_disabled = 1; \
289 * check_pages - integrity check of trace buffers
291 * As a safty measure we check to make sure the data pages have not
294 int check_pages(struct trace_array_cpu
*data
)
296 struct page
*page
, *tmp
;
298 CHECK_COND(data
->trace_pages
.next
->prev
!= &data
->trace_pages
);
299 CHECK_COND(data
->trace_pages
.prev
->next
!= &data
->trace_pages
);
301 list_for_each_entry_safe(page
, tmp
, &data
->trace_pages
, lru
) {
302 CHECK_COND(page
->lru
.next
->prev
!= &page
->lru
);
303 CHECK_COND(page
->lru
.prev
->next
!= &page
->lru
);
310 * head_page - page address of the first page in per_cpu buffer.
312 * head_page returns the page address of the first page in
313 * a per_cpu buffer. This also preforms various consistency
314 * checks to make sure the buffer has not been corrupted.
316 void *head_page(struct trace_array_cpu
*data
)
320 if (list_empty(&data
->trace_pages
))
323 page
= list_entry(data
->trace_pages
.next
, struct page
, lru
);
324 BUG_ON(&page
->lru
== &data
->trace_pages
);
326 return page_address(page
);
330 * trace_seq_printf - sequence printing of trace information
331 * @s: trace sequence descriptor
332 * @fmt: printf format string
334 * The tracer may use either sequence operations or its own
335 * copy to user routines. To simplify formating of a trace
336 * trace_seq_printf is used to store strings into a special
337 * buffer (@s). Then the output may be either used by
338 * the sequencer or pulled into another buffer.
341 trace_seq_printf(struct trace_seq
*s
, const char *fmt
, ...)
343 int len
= (PAGE_SIZE
- 1) - s
->len
;
351 ret
= vsnprintf(s
->buffer
+ s
->len
, len
, fmt
, ap
);
354 /* If we can't write it all, don't bother writing anything */
364 * trace_seq_puts - trace sequence printing of simple string
365 * @s: trace sequence descriptor
366 * @str: simple string to record
368 * The tracer may use either the sequence operations or its own
369 * copy to user routines. This function records a simple string
370 * into a special buffer (@s) for later retrieval by a sequencer
371 * or other mechanism.
374 trace_seq_puts(struct trace_seq
*s
, const char *str
)
376 int len
= strlen(str
);
378 if (len
> ((PAGE_SIZE
- 1) - s
->len
))
381 memcpy(s
->buffer
+ s
->len
, str
, len
);
388 trace_seq_putc(struct trace_seq
*s
, unsigned char c
)
390 if (s
->len
>= (PAGE_SIZE
- 1))
393 s
->buffer
[s
->len
++] = c
;
399 trace_seq_putmem(struct trace_seq
*s
, void *mem
, size_t len
)
401 if (len
> ((PAGE_SIZE
- 1) - s
->len
))
404 memcpy(s
->buffer
+ s
->len
, mem
, len
);
411 static const char hex2asc
[] = "0123456789abcdef";
414 trace_seq_putmem_hex(struct trace_seq
*s
, void *mem
, size_t len
)
416 unsigned char hex
[HEX_CHARS
];
417 unsigned char *data
= mem
;
421 BUG_ON(len
>= HEX_CHARS
);
424 for (i
= 0, j
= 0; i
< len
; i
++) {
426 for (i
= len
-1, j
= 0; i
>= 0; i
--) {
430 hex
[j
++] = hex2asc
[byte
& 0x0f];
431 hex
[j
++] = hex2asc
[byte
>> 4];
435 return trace_seq_putmem(s
, hex
, j
);
439 trace_seq_reset(struct trace_seq
*s
)
445 ssize_t
trace_seq_to_user(struct trace_seq
*s
, char __user
*ubuf
, size_t cnt
)
450 if (s
->len
<= s
->readpos
)
453 len
= s
->len
- s
->readpos
;
456 ret
= copy_to_user(ubuf
, s
->buffer
+ s
->readpos
, cnt
);
465 trace_print_seq(struct seq_file
*m
, struct trace_seq
*s
)
467 int len
= s
->len
>= PAGE_SIZE
? PAGE_SIZE
- 1 : s
->len
;
470 seq_puts(m
, s
->buffer
);
476 * flip the trace buffers between two trace descriptors.
477 * This usually is the buffers between the global_trace and
478 * the max_tr to record a snapshot of a current trace.
480 * The ftrace_max_lock must be held.
483 flip_trace(struct trace_array_cpu
*tr1
, struct trace_array_cpu
*tr2
)
485 struct list_head flip_pages
;
487 INIT_LIST_HEAD(&flip_pages
);
489 memcpy(&tr1
->trace_head_idx
, &tr2
->trace_head_idx
,
490 sizeof(struct trace_array_cpu
) -
491 offsetof(struct trace_array_cpu
, trace_head_idx
));
495 list_splice_init(&tr1
->trace_pages
, &flip_pages
);
496 list_splice_init(&tr2
->trace_pages
, &tr1
->trace_pages
);
497 list_splice_init(&flip_pages
, &tr2
->trace_pages
);
498 BUG_ON(!list_empty(&flip_pages
));
504 * update_max_tr - snapshot all trace buffers from global_trace to max_tr
506 * @tsk: the task with the latency
507 * @cpu: The cpu that initiated the trace.
509 * Flip the buffers between the @tr and the max_tr and record information
510 * about which task was the cause of this latency.
513 update_max_tr(struct trace_array
*tr
, struct task_struct
*tsk
, int cpu
)
515 struct trace_array_cpu
*data
;
518 WARN_ON_ONCE(!irqs_disabled());
519 __raw_spin_lock(&ftrace_max_lock
);
520 /* clear out all the previous traces */
521 for_each_tracing_cpu(i
) {
523 flip_trace(max_tr
.data
[i
], data
);
527 __update_max_tr(tr
, tsk
, cpu
);
528 __raw_spin_unlock(&ftrace_max_lock
);
532 * update_max_tr_single - only copy one trace over, and reset the rest
534 * @tsk - task with the latency
535 * @cpu - the cpu of the buffer to copy.
537 * Flip the trace of a single CPU buffer between the @tr and the max_tr.
540 update_max_tr_single(struct trace_array
*tr
, struct task_struct
*tsk
, int cpu
)
542 struct trace_array_cpu
*data
= tr
->data
[cpu
];
545 WARN_ON_ONCE(!irqs_disabled());
546 __raw_spin_lock(&ftrace_max_lock
);
547 for_each_tracing_cpu(i
)
548 tracing_reset(max_tr
.data
[i
]);
550 flip_trace(max_tr
.data
[cpu
], data
);
553 __update_max_tr(tr
, tsk
, cpu
);
554 __raw_spin_unlock(&ftrace_max_lock
);
558 * register_tracer - register a tracer with the ftrace system.
559 * @type - the plugin for the tracer
561 * Register a new plugin tracer.
563 int register_tracer(struct tracer
*type
)
570 pr_info("Tracer must have a name\n");
574 mutex_lock(&trace_types_lock
);
575 for (t
= trace_types
; t
; t
= t
->next
) {
576 if (strcmp(type
->name
, t
->name
) == 0) {
578 pr_info("Trace %s already registered\n",
585 #ifdef CONFIG_FTRACE_STARTUP_TEST
586 if (type
->selftest
) {
587 struct tracer
*saved_tracer
= current_trace
;
588 struct trace_array_cpu
*data
;
589 struct trace_array
*tr
= &global_trace
;
590 int saved_ctrl
= tr
->ctrl
;
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
) {
601 if (!head_page(data
))
605 current_trace
= type
;
607 /* the test is responsible for initializing and enabling */
608 pr_info("Testing tracer %s: ", type
->name
);
609 ret
= type
->selftest(type
, tr
);
610 /* the test is responsible for resetting too */
611 current_trace
= saved_tracer
;
612 tr
->ctrl
= saved_ctrl
;
614 printk(KERN_CONT
"FAILED!\n");
617 /* Only reset on passing, to avoid touching corrupted buffers */
618 for_each_tracing_cpu(i
) {
620 if (!head_page(data
))
624 printk(KERN_CONT
"PASSED\n");
628 type
->next
= trace_types
;
630 len
= strlen(type
->name
);
631 if (len
> max_tracer_type_len
)
632 max_tracer_type_len
= len
;
635 mutex_unlock(&trace_types_lock
);
640 void unregister_tracer(struct tracer
*type
)
645 mutex_lock(&trace_types_lock
);
646 for (t
= &trace_types
; *t
; t
= &(*t
)->next
) {
650 pr_info("Trace %s not registered\n", type
->name
);
655 if (strlen(type
->name
) != max_tracer_type_len
)
658 max_tracer_type_len
= 0;
659 for (t
= &trace_types
; *t
; t
= &(*t
)->next
) {
660 len
= strlen((*t
)->name
);
661 if (len
> max_tracer_type_len
)
662 max_tracer_type_len
= len
;
665 mutex_unlock(&trace_types_lock
);
668 void tracing_reset(struct trace_array_cpu
*data
)
672 data
->trace_head
= data
->trace_tail
= head_page(data
);
673 data
->trace_head_idx
= 0;
674 data
->trace_tail_idx
= 0;
677 #define SAVED_CMDLINES 128
678 static unsigned map_pid_to_cmdline
[PID_MAX_DEFAULT
+1];
679 static unsigned map_cmdline_to_pid
[SAVED_CMDLINES
];
680 static char saved_cmdlines
[SAVED_CMDLINES
][TASK_COMM_LEN
];
681 static int cmdline_idx
;
682 static DEFINE_SPINLOCK(trace_cmdline_lock
);
684 /* temporary disable recording */
685 atomic_t trace_record_cmdline_disabled __read_mostly
;
687 static void trace_init_cmdlines(void)
689 memset(&map_pid_to_cmdline
, -1, sizeof(map_pid_to_cmdline
));
690 memset(&map_cmdline_to_pid
, -1, sizeof(map_cmdline_to_pid
));
694 void trace_stop_cmdline_recording(void);
696 static void trace_save_cmdline(struct task_struct
*tsk
)
701 if (!tsk
->pid
|| unlikely(tsk
->pid
> PID_MAX_DEFAULT
))
705 * It's not the end of the world if we don't get
706 * the lock, but we also don't want to spin
707 * nor do we want to disable interrupts,
708 * so if we miss here, then better luck next time.
710 if (!spin_trylock(&trace_cmdline_lock
))
713 idx
= map_pid_to_cmdline
[tsk
->pid
];
714 if (idx
>= SAVED_CMDLINES
) {
715 idx
= (cmdline_idx
+ 1) % SAVED_CMDLINES
;
717 map
= map_cmdline_to_pid
[idx
];
718 if (map
<= PID_MAX_DEFAULT
)
719 map_pid_to_cmdline
[map
] = (unsigned)-1;
721 map_pid_to_cmdline
[tsk
->pid
] = idx
;
726 memcpy(&saved_cmdlines
[idx
], tsk
->comm
, TASK_COMM_LEN
);
728 spin_unlock(&trace_cmdline_lock
);
731 static char *trace_find_cmdline(int pid
)
733 char *cmdline
= "<...>";
739 if (pid
> PID_MAX_DEFAULT
)
742 map
= map_pid_to_cmdline
[pid
];
743 if (map
>= SAVED_CMDLINES
)
746 cmdline
= saved_cmdlines
[map
];
752 void tracing_record_cmdline(struct task_struct
*tsk
)
754 if (atomic_read(&trace_record_cmdline_disabled
))
757 trace_save_cmdline(tsk
);
760 static inline struct list_head
*
761 trace_next_list(struct trace_array_cpu
*data
, struct list_head
*next
)
764 * Roundrobin - but skip the head (which is not a real page):
767 if (unlikely(next
== &data
->trace_pages
))
769 BUG_ON(next
== &data
->trace_pages
);
775 trace_next_page(struct trace_array_cpu
*data
, void *addr
)
777 struct list_head
*next
;
780 page
= virt_to_page(addr
);
782 next
= trace_next_list(data
, &page
->lru
);
783 page
= list_entry(next
, struct page
, lru
);
785 return page_address(page
);
789 tracing_get_trace_entry(struct trace_array
*tr
, struct trace_array_cpu
*data
)
791 unsigned long idx
, idx_next
;
792 struct trace_entry
*entry
;
795 idx
= data
->trace_head_idx
;
798 BUG_ON(idx
* TRACE_ENTRY_SIZE
>= PAGE_SIZE
);
800 entry
= data
->trace_head
+ idx
* TRACE_ENTRY_SIZE
;
802 if (unlikely(idx_next
>= ENTRIES_PER_PAGE
)) {
803 data
->trace_head
= trace_next_page(data
, data
->trace_head
);
807 if (data
->trace_head
== data
->trace_tail
&&
808 idx_next
== data
->trace_tail_idx
) {
811 data
->trace_tail_idx
++;
812 if (data
->trace_tail_idx
>= ENTRIES_PER_PAGE
) {
814 trace_next_page(data
, data
->trace_tail
);
815 data
->trace_tail_idx
= 0;
819 data
->trace_head_idx
= idx_next
;
825 tracing_generic_entry_update(struct trace_entry
*entry
, unsigned long flags
)
827 struct task_struct
*tsk
= current
;
830 pc
= preempt_count();
832 entry
->field
.preempt_count
= pc
& 0xff;
833 entry
->field
.pid
= (tsk
) ? tsk
->pid
: 0;
834 entry
->field
.t
= ftrace_now(raw_smp_processor_id());
836 (irqs_disabled_flags(flags
) ? TRACE_FLAG_IRQS_OFF
: 0) |
837 ((pc
& HARDIRQ_MASK
) ? TRACE_FLAG_HARDIRQ
: 0) |
838 ((pc
& SOFTIRQ_MASK
) ? TRACE_FLAG_SOFTIRQ
: 0) |
839 (need_resched() ? TRACE_FLAG_NEED_RESCHED
: 0);
843 trace_function(struct trace_array
*tr
, struct trace_array_cpu
*data
,
844 unsigned long ip
, unsigned long parent_ip
, unsigned long flags
)
846 struct trace_entry
*entry
;
847 unsigned long irq_flags
;
849 raw_local_irq_save(irq_flags
);
850 __raw_spin_lock(&data
->lock
);
851 entry
= tracing_get_trace_entry(tr
, data
);
852 tracing_generic_entry_update(entry
, flags
);
853 entry
->type
= TRACE_FN
;
854 entry
->field
.fn
.ip
= ip
;
855 entry
->field
.fn
.parent_ip
= parent_ip
;
856 __raw_spin_unlock(&data
->lock
);
857 raw_local_irq_restore(irq_flags
);
861 ftrace(struct trace_array
*tr
, struct trace_array_cpu
*data
,
862 unsigned long ip
, unsigned long parent_ip
, unsigned long flags
)
864 if (likely(!atomic_read(&data
->disabled
)))
865 trace_function(tr
, data
, ip
, parent_ip
, flags
);
868 void __trace_stack(struct trace_array
*tr
,
869 struct trace_array_cpu
*data
,
873 struct trace_entry
*entry
;
874 struct stack_trace trace
;
876 if (!(trace_flags
& TRACE_ITER_STACKTRACE
))
879 entry
= tracing_get_trace_entry(tr
, data
);
880 tracing_generic_entry_update(entry
, flags
);
881 entry
->type
= TRACE_STACK
;
883 memset(&entry
->field
.stack
, 0, sizeof(entry
->field
.stack
));
885 trace
.nr_entries
= 0;
886 trace
.max_entries
= FTRACE_STACK_ENTRIES
;
888 trace
.entries
= entry
->field
.stack
.caller
;
890 save_stack_trace(&trace
);
894 __trace_special(void *__tr
, void *__data
,
895 unsigned long arg1
, unsigned long arg2
, unsigned long arg3
)
897 struct trace_array_cpu
*data
= __data
;
898 struct trace_array
*tr
= __tr
;
899 struct trace_entry
*entry
;
900 unsigned long irq_flags
;
902 raw_local_irq_save(irq_flags
);
903 __raw_spin_lock(&data
->lock
);
904 entry
= tracing_get_trace_entry(tr
, data
);
905 tracing_generic_entry_update(entry
, 0);
906 entry
->type
= TRACE_SPECIAL
;
907 entry
->field
.special
.arg1
= arg1
;
908 entry
->field
.special
.arg2
= arg2
;
909 entry
->field
.special
.arg3
= arg3
;
910 __trace_stack(tr
, data
, irq_flags
, 4);
911 __raw_spin_unlock(&data
->lock
);
912 raw_local_irq_restore(irq_flags
);
918 tracing_sched_switch_trace(struct trace_array
*tr
,
919 struct trace_array_cpu
*data
,
920 struct task_struct
*prev
,
921 struct task_struct
*next
,
924 struct trace_entry
*entry
;
925 unsigned long irq_flags
;
927 raw_local_irq_save(irq_flags
);
928 __raw_spin_lock(&data
->lock
);
929 entry
= tracing_get_trace_entry(tr
, data
);
930 tracing_generic_entry_update(entry
, flags
);
931 entry
->type
= TRACE_CTX
;
932 entry
->field
.ctx
.prev_pid
= prev
->pid
;
933 entry
->field
.ctx
.prev_prio
= prev
->prio
;
934 entry
->field
.ctx
.prev_state
= prev
->state
;
935 entry
->field
.ctx
.next_pid
= next
->pid
;
936 entry
->field
.ctx
.next_prio
= next
->prio
;
937 entry
->field
.ctx
.next_state
= next
->state
;
938 entry
->field
.ctx
.next_cpu
= task_cpu(next
);
939 __trace_stack(tr
, data
, flags
, 5);
940 __raw_spin_unlock(&data
->lock
);
941 raw_local_irq_restore(irq_flags
);
945 tracing_sched_wakeup_trace(struct trace_array
*tr
,
946 struct trace_array_cpu
*data
,
947 struct task_struct
*wakee
,
948 struct task_struct
*curr
,
951 struct trace_entry
*entry
;
952 unsigned long irq_flags
;
954 raw_local_irq_save(irq_flags
);
955 __raw_spin_lock(&data
->lock
);
956 entry
= tracing_get_trace_entry(tr
, data
);
957 tracing_generic_entry_update(entry
, flags
);
958 entry
->type
= TRACE_WAKE
;
959 entry
->field
.ctx
.prev_pid
= curr
->pid
;
960 entry
->field
.ctx
.prev_prio
= curr
->prio
;
961 entry
->field
.ctx
.prev_state
= curr
->state
;
962 entry
->field
.ctx
.next_pid
= wakee
->pid
;
963 entry
->field
.ctx
.next_prio
= wakee
->prio
;
964 entry
->field
.ctx
.next_state
= wakee
->state
;
965 entry
->field
.ctx
.next_cpu
= task_cpu(wakee
);
966 __trace_stack(tr
, data
, flags
, 6);
967 __raw_spin_unlock(&data
->lock
);
968 raw_local_irq_restore(irq_flags
);
974 ftrace_special(unsigned long arg1
, unsigned long arg2
, unsigned long arg3
)
976 struct trace_array
*tr
= &global_trace
;
977 struct trace_array_cpu
*data
;
982 if (tracing_disabled
|| current_trace
== &no_tracer
|| !tr
->ctrl
)
985 local_irq_save(flags
);
986 cpu
= raw_smp_processor_id();
987 data
= tr
->data
[cpu
];
988 disabled
= atomic_inc_return(&data
->disabled
);
990 if (likely(disabled
== 1))
991 __trace_special(tr
, data
, arg1
, arg2
, arg3
);
993 atomic_dec(&data
->disabled
);
994 local_irq_restore(flags
);
999 function_trace_call(unsigned long ip
, unsigned long parent_ip
)
1001 struct trace_array
*tr
= &global_trace
;
1002 struct trace_array_cpu
*data
;
1003 unsigned long flags
;
1007 if (unlikely(!ftrace_function_enabled
))
1013 local_irq_save(flags
);
1014 cpu
= raw_smp_processor_id();
1015 data
= tr
->data
[cpu
];
1016 disabled
= atomic_inc_return(&data
->disabled
);
1018 if (likely(disabled
== 1))
1019 trace_function(tr
, data
, ip
, parent_ip
, flags
);
1021 atomic_dec(&data
->disabled
);
1022 local_irq_restore(flags
);
1025 static struct ftrace_ops trace_ops __read_mostly
=
1027 .func
= function_trace_call
,
1030 void tracing_start_function_trace(void)
1032 ftrace_function_enabled
= 0;
1033 register_ftrace_function(&trace_ops
);
1035 ftrace_function_enabled
= 1;
1038 void tracing_stop_function_trace(void)
1040 ftrace_function_enabled
= 0;
1041 unregister_ftrace_function(&trace_ops
);
1045 enum trace_file_type
{
1046 TRACE_FILE_LAT_FMT
= 1,
1049 /* Return the current entry. */
1050 static struct trace_entry
*
1051 trace_entry_idx(struct trace_array
*tr
, struct trace_array_cpu
*data
,
1052 struct trace_iterator
*iter
, int cpu
)
1055 struct trace_entry
*array
;
1057 if (iter
->next_idx
[cpu
] >= tr
->entries
||
1058 iter
->next_idx
[cpu
] >= data
->trace_idx
||
1059 (data
->trace_head
== data
->trace_tail
&&
1060 data
->trace_head_idx
== data
->trace_tail_idx
))
1063 if (!iter
->next_page
[cpu
]) {
1064 /* Initialize the iterator for this cpu trace buffer */
1065 WARN_ON(!data
->trace_tail
);
1066 page
= virt_to_page(data
->trace_tail
);
1067 iter
->next_page
[cpu
] = &page
->lru
;
1068 iter
->next_page_idx
[cpu
] = data
->trace_tail_idx
;
1071 page
= list_entry(iter
->next_page
[cpu
], struct page
, lru
);
1072 BUG_ON(&data
->trace_pages
== &page
->lru
);
1074 array
= page_address(page
);
1076 WARN_ON(iter
->next_page_idx
[cpu
] >= ENTRIES_PER_PAGE
);
1077 return &array
[iter
->next_page_idx
[cpu
]];
1080 /* Increment the index counter of an iterator by one */
1081 static void __trace_iterator_increment(struct trace_iterator
*iter
, int cpu
)
1083 iter
->next_idx
[cpu
]++;
1084 iter
->next_page_idx
[cpu
]++;
1086 if (iter
->next_page_idx
[cpu
] >= ENTRIES_PER_PAGE
) {
1087 struct trace_array_cpu
*data
= iter
->tr
->data
[cpu
];
1089 iter
->next_page_idx
[cpu
] = 0;
1090 iter
->next_page
[cpu
] =
1091 trace_next_list(data
, iter
->next_page
[cpu
]);
1095 static void trace_iterator_increment(struct trace_iterator
*iter
, int cpu
)
1098 __trace_iterator_increment(iter
, cpu
);
1101 static struct trace_entry
*
1102 trace_entry_next(struct trace_array
*tr
, struct trace_array_cpu
*data
,
1103 struct trace_iterator
*iter
, int cpu
)
1105 struct list_head
*next_page
;
1106 struct trace_entry
*ent
;
1107 int idx
, next_idx
, next_page_idx
;
1109 ent
= trace_entry_idx(tr
, tr
->data
[cpu
], iter
, cpu
);
1111 if (likely(!ent
|| ent
->type
!= TRACE_CONT
))
1114 /* save the iterator details */
1116 next_idx
= iter
->next_idx
[cpu
];
1117 next_page_idx
= iter
->next_page_idx
[cpu
];
1118 next_page
= iter
->next_page
[cpu
];
1120 /* find a real entry */
1122 __trace_iterator_increment(iter
, cpu
);
1123 ent
= trace_entry_idx(tr
, tr
->data
[cpu
], iter
, cpu
);
1124 } while (ent
&& ent
->type
!= TRACE_CONT
);
1126 /* reset the iterator */
1128 iter
->next_idx
[cpu
] = next_idx
;
1129 iter
->next_page_idx
[cpu
] = next_page_idx
;
1130 iter
->next_page
[cpu
] = next_page
;
1135 static struct trace_entry
*
1136 __find_next_entry(struct trace_iterator
*iter
, int *ent_cpu
, int inc
)
1138 struct trace_array
*tr
= iter
->tr
;
1139 struct trace_entry
*ent
, *next
= NULL
;
1143 for_each_tracing_cpu(cpu
) {
1144 if (!head_page(tr
->data
[cpu
]))
1147 ent
= trace_entry_idx(tr
, tr
->data
[cpu
], iter
, cpu
);
1149 if (ent
&& ent
->type
== TRACE_CONT
) {
1150 struct trace_array_cpu
*data
= tr
->data
[cpu
];
1153 ent
= trace_entry_next(tr
, data
, iter
, cpu
);
1155 while (ent
&& ent
->type
== TRACE_CONT
) {
1156 __trace_iterator_increment(iter
, cpu
);
1157 ent
= trace_entry_idx(tr
, tr
->data
[cpu
],
1164 * Pick the entry with the smallest timestamp:
1166 if (ent
&& (!next
|| ent
->field
.t
< next
->field
.t
)) {
1173 *ent_cpu
= next_cpu
;
1178 /* Find the next real entry, without updating the iterator itself */
1179 static struct trace_entry
*
1180 find_next_entry(struct trace_iterator
*iter
, int *ent_cpu
)
1182 return __find_next_entry(iter
, ent_cpu
, 0);
1185 /* Find the next real entry, and increment the iterator to the next entry */
1186 static void *find_next_entry_inc(struct trace_iterator
*iter
)
1188 struct trace_entry
*next
;
1191 next
= __find_next_entry(iter
, &next_cpu
, 1);
1193 iter
->prev_ent
= iter
->ent
;
1194 iter
->prev_cpu
= iter
->cpu
;
1197 iter
->cpu
= next_cpu
;
1200 trace_iterator_increment(iter
, iter
->cpu
);
1202 return next
? iter
: NULL
;
1205 static void trace_consume(struct trace_iterator
*iter
)
1207 struct trace_array_cpu
*data
= iter
->tr
->data
[iter
->cpu
];
1208 struct trace_entry
*ent
;
1211 data
->trace_tail_idx
++;
1212 if (data
->trace_tail_idx
>= ENTRIES_PER_PAGE
) {
1213 data
->trace_tail
= trace_next_page(data
, data
->trace_tail
);
1214 data
->trace_tail_idx
= 0;
1217 /* Check if we empty it, then reset the index */
1218 if (data
->trace_head
== data
->trace_tail
&&
1219 data
->trace_head_idx
== data
->trace_tail_idx
)
1220 data
->trace_idx
= 0;
1222 ent
= trace_entry_idx(iter
->tr
, iter
->tr
->data
[iter
->cpu
],
1224 if (ent
&& ent
->type
== TRACE_CONT
)
1228 static void *s_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
1230 struct trace_iterator
*iter
= m
->private;
1236 /* can't go backwards */
1241 ent
= find_next_entry_inc(iter
);
1245 while (ent
&& iter
->idx
< i
)
1246 ent
= find_next_entry_inc(iter
);
1253 static void *s_start(struct seq_file
*m
, loff_t
*pos
)
1255 struct trace_iterator
*iter
= m
->private;
1260 mutex_lock(&trace_types_lock
);
1262 if (!current_trace
|| current_trace
!= iter
->trace
) {
1263 mutex_unlock(&trace_types_lock
);
1267 atomic_inc(&trace_record_cmdline_disabled
);
1269 /* let the tracer grab locks here if needed */
1270 if (current_trace
->start
)
1271 current_trace
->start(iter
);
1273 if (*pos
!= iter
->pos
) {
1277 iter
->prev_ent
= NULL
;
1278 iter
->prev_cpu
= -1;
1280 for_each_tracing_cpu(i
) {
1281 iter
->next_idx
[i
] = 0;
1282 iter
->next_page
[i
] = NULL
;
1285 for (p
= iter
; p
&& l
< *pos
; p
= s_next(m
, p
, &l
))
1290 p
= s_next(m
, p
, &l
);
1296 static void s_stop(struct seq_file
*m
, void *p
)
1298 struct trace_iterator
*iter
= m
->private;
1300 atomic_dec(&trace_record_cmdline_disabled
);
1302 /* let the tracer release locks here if needed */
1303 if (current_trace
&& current_trace
== iter
->trace
&& iter
->trace
->stop
)
1304 iter
->trace
->stop(iter
);
1306 mutex_unlock(&trace_types_lock
);
1309 #define KRETPROBE_MSG "[unknown/kretprobe'd]"
1311 #ifdef CONFIG_KRETPROBES
1312 static inline int kretprobed(unsigned long addr
)
1314 return addr
== (unsigned long)kretprobe_trampoline
;
1317 static inline int kretprobed(unsigned long addr
)
1321 #endif /* CONFIG_KRETPROBES */
1324 seq_print_sym_short(struct trace_seq
*s
, const char *fmt
, unsigned long address
)
1326 #ifdef CONFIG_KALLSYMS
1327 char str
[KSYM_SYMBOL_LEN
];
1329 kallsyms_lookup(address
, NULL
, NULL
, NULL
, str
);
1331 return trace_seq_printf(s
, fmt
, str
);
1337 seq_print_sym_offset(struct trace_seq
*s
, const char *fmt
,
1338 unsigned long address
)
1340 #ifdef CONFIG_KALLSYMS
1341 char str
[KSYM_SYMBOL_LEN
];
1343 sprint_symbol(str
, address
);
1344 return trace_seq_printf(s
, fmt
, str
);
1349 #ifndef CONFIG_64BIT
1350 # define IP_FMT "%08lx"
1352 # define IP_FMT "%016lx"
1356 seq_print_ip_sym(struct trace_seq
*s
, unsigned long ip
, unsigned long sym_flags
)
1361 return trace_seq_printf(s
, "0");
1363 if (sym_flags
& TRACE_ITER_SYM_OFFSET
)
1364 ret
= seq_print_sym_offset(s
, "%s", ip
);
1366 ret
= seq_print_sym_short(s
, "%s", ip
);
1371 if (sym_flags
& TRACE_ITER_SYM_ADDR
)
1372 ret
= trace_seq_printf(s
, " <" IP_FMT
">", ip
);
1376 static void print_lat_help_header(struct seq_file
*m
)
1378 seq_puts(m
, "# _------=> CPU# \n");
1379 seq_puts(m
, "# / _-----=> irqs-off \n");
1380 seq_puts(m
, "# | / _----=> need-resched \n");
1381 seq_puts(m
, "# || / _---=> hardirq/softirq \n");
1382 seq_puts(m
, "# ||| / _--=> preempt-depth \n");
1383 seq_puts(m
, "# |||| / \n");
1384 seq_puts(m
, "# ||||| delay \n");
1385 seq_puts(m
, "# cmd pid ||||| time | caller \n");
1386 seq_puts(m
, "# \\ / ||||| \\ | / \n");
1389 static void print_func_help_header(struct seq_file
*m
)
1391 seq_puts(m
, "# TASK-PID CPU# TIMESTAMP FUNCTION\n");
1392 seq_puts(m
, "# | | | | |\n");
1397 print_trace_header(struct seq_file
*m
, struct trace_iterator
*iter
)
1399 unsigned long sym_flags
= (trace_flags
& TRACE_ITER_SYM_MASK
);
1400 struct trace_array
*tr
= iter
->tr
;
1401 struct trace_array_cpu
*data
= tr
->data
[tr
->cpu
];
1402 struct tracer
*type
= current_trace
;
1403 unsigned long total
= 0;
1404 unsigned long entries
= 0;
1406 const char *name
= "preemption";
1411 for_each_tracing_cpu(cpu
) {
1412 if (head_page(tr
->data
[cpu
])) {
1413 total
+= tr
->data
[cpu
]->trace_idx
;
1414 if (tr
->data
[cpu
]->trace_idx
> tr
->entries
)
1415 entries
+= tr
->entries
;
1417 entries
+= tr
->data
[cpu
]->trace_idx
;
1421 seq_printf(m
, "%s latency trace v1.1.5 on %s\n",
1423 seq_puts(m
, "-----------------------------------"
1424 "---------------------------------\n");
1425 seq_printf(m
, " latency: %lu us, #%lu/%lu, CPU#%d |"
1426 " (M:%s VP:%d, KP:%d, SP:%d HP:%d",
1427 nsecs_to_usecs(data
->saved_latency
),
1431 #if defined(CONFIG_PREEMPT_NONE)
1433 #elif defined(CONFIG_PREEMPT_VOLUNTARY)
1435 #elif defined(CONFIG_PREEMPT)
1440 /* These are reserved for later use */
1443 seq_printf(m
, " #P:%d)\n", num_online_cpus());
1447 seq_puts(m
, " -----------------\n");
1448 seq_printf(m
, " | task: %.16s-%d "
1449 "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n",
1450 data
->comm
, data
->pid
, data
->uid
, data
->nice
,
1451 data
->policy
, data
->rt_priority
);
1452 seq_puts(m
, " -----------------\n");
1454 if (data
->critical_start
) {
1455 seq_puts(m
, " => started at: ");
1456 seq_print_ip_sym(&iter
->seq
, data
->critical_start
, sym_flags
);
1457 trace_print_seq(m
, &iter
->seq
);
1458 seq_puts(m
, "\n => ended at: ");
1459 seq_print_ip_sym(&iter
->seq
, data
->critical_end
, sym_flags
);
1460 trace_print_seq(m
, &iter
->seq
);
1468 lat_print_generic(struct trace_seq
*s
, struct trace_entry
*entry
, int cpu
)
1470 struct trace_field
*field
= &entry
->field
;
1471 int hardirq
, softirq
;
1474 comm
= trace_find_cmdline(field
->pid
);
1476 trace_seq_printf(s
, "%8.8s-%-5d ", comm
, field
->pid
);
1477 trace_seq_printf(s
, "%3d", cpu
);
1478 trace_seq_printf(s
, "%c%c",
1479 (field
->flags
& TRACE_FLAG_IRQS_OFF
) ? 'd' : '.',
1480 ((field
->flags
& TRACE_FLAG_NEED_RESCHED
) ? 'N' : '.'));
1482 hardirq
= field
->flags
& TRACE_FLAG_HARDIRQ
;
1483 softirq
= field
->flags
& TRACE_FLAG_SOFTIRQ
;
1484 if (hardirq
&& softirq
) {
1485 trace_seq_putc(s
, 'H');
1488 trace_seq_putc(s
, 'h');
1491 trace_seq_putc(s
, 's');
1493 trace_seq_putc(s
, '.');
1497 if (field
->preempt_count
)
1498 trace_seq_printf(s
, "%x", field
->preempt_count
);
1500 trace_seq_puts(s
, ".");
1503 unsigned long preempt_mark_thresh
= 100;
1506 lat_print_timestamp(struct trace_seq
*s
, unsigned long long abs_usecs
,
1507 unsigned long rel_usecs
)
1509 trace_seq_printf(s
, " %4lldus", abs_usecs
);
1510 if (rel_usecs
> preempt_mark_thresh
)
1511 trace_seq_puts(s
, "!: ");
1512 else if (rel_usecs
> 1)
1513 trace_seq_puts(s
, "+: ");
1515 trace_seq_puts(s
, " : ");
1518 static const char state_to_char
[] = TASK_STATE_TO_CHAR_STR
;
1521 trace_seq_print_cont(struct trace_seq
*s
, struct trace_iterator
*iter
)
1523 struct trace_array
*tr
= iter
->tr
;
1524 struct trace_array_cpu
*data
= tr
->data
[iter
->cpu
];
1525 struct trace_entry
*ent
;
1527 ent
= trace_entry_idx(tr
, data
, iter
, iter
->cpu
);
1528 if (!ent
|| ent
->type
!= TRACE_CONT
) {
1529 trace_seq_putc(s
, '\n');
1534 trace_seq_printf(s
, "%s", ent
->cont
.buf
);
1535 __trace_iterator_increment(iter
, iter
->cpu
);
1536 ent
= trace_entry_idx(tr
, data
, iter
, iter
->cpu
);
1537 } while (ent
&& ent
->type
== TRACE_CONT
);
1541 print_lat_fmt(struct trace_iterator
*iter
, unsigned int trace_idx
, int cpu
)
1543 struct trace_seq
*s
= &iter
->seq
;
1544 unsigned long sym_flags
= (trace_flags
& TRACE_ITER_SYM_MASK
);
1545 struct trace_entry
*next_entry
= find_next_entry(iter
, NULL
);
1546 unsigned long verbose
= (trace_flags
& TRACE_ITER_VERBOSE
);
1547 struct trace_entry
*entry
= iter
->ent
;
1548 struct trace_field
*field
= &entry
->field
;
1549 unsigned long abs_usecs
;
1550 unsigned long rel_usecs
;
1559 if (entry
->type
== TRACE_CONT
)
1562 rel_usecs
= ns2usecs(next_entry
->field
.t
- entry
->field
.t
);
1563 abs_usecs
= ns2usecs(entry
->field
.t
- iter
->tr
->time_start
);
1566 comm
= trace_find_cmdline(field
->pid
);
1567 trace_seq_printf(s
, "%16s %5d %3d %d %08x %08x [%08lx]"
1568 " %ld.%03ldms (+%ld.%03ldms): ",
1570 field
->pid
, cpu
, field
->flags
,
1571 field
->preempt_count
, trace_idx
,
1574 abs_usecs
% 1000, rel_usecs
/1000,
1577 lat_print_generic(s
, entry
, cpu
);
1578 lat_print_timestamp(s
, abs_usecs
, rel_usecs
);
1580 switch (entry
->type
) {
1582 seq_print_ip_sym(s
, field
->fn
.ip
, sym_flags
);
1583 trace_seq_puts(s
, " (");
1584 if (kretprobed(field
->fn
.parent_ip
))
1585 trace_seq_puts(s
, KRETPROBE_MSG
);
1587 seq_print_ip_sym(s
, field
->fn
.parent_ip
, sym_flags
);
1588 trace_seq_puts(s
, ")\n");
1592 T
= field
->ctx
.next_state
< sizeof(state_to_char
) ?
1593 state_to_char
[field
->ctx
.next_state
] : 'X';
1595 state
= field
->ctx
.prev_state
?
1596 __ffs(field
->ctx
.prev_state
) + 1 : 0;
1597 S
= state
< sizeof(state_to_char
) - 1 ? state_to_char
[state
] : 'X';
1598 comm
= trace_find_cmdline(field
->ctx
.next_pid
);
1599 trace_seq_printf(s
, " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
1600 field
->ctx
.prev_pid
,
1601 field
->ctx
.prev_prio
,
1602 S
, entry
->type
== TRACE_CTX
? "==>" : " +",
1603 field
->ctx
.next_cpu
,
1604 field
->ctx
.next_pid
,
1605 field
->ctx
.next_prio
,
1609 trace_seq_printf(s
, "# %ld %ld %ld\n",
1610 field
->special
.arg1
,
1611 field
->special
.arg2
,
1612 field
->special
.arg3
);
1615 for (i
= 0; i
< FTRACE_STACK_ENTRIES
; i
++) {
1617 trace_seq_puts(s
, " <= ");
1618 seq_print_ip_sym(s
, field
->stack
.caller
[i
], sym_flags
);
1620 trace_seq_puts(s
, "\n");
1623 seq_print_ip_sym(s
, field
->print
.ip
, sym_flags
);
1624 trace_seq_printf(s
, ": %s", field
->print
.buf
);
1625 if (field
->flags
& TRACE_FLAG_CONT
)
1626 trace_seq_print_cont(s
, iter
);
1629 trace_seq_printf(s
, "Unknown type %d\n", entry
->type
);
1634 static int print_trace_fmt(struct trace_iterator
*iter
)
1636 struct trace_seq
*s
= &iter
->seq
;
1637 unsigned long sym_flags
= (trace_flags
& TRACE_ITER_SYM_MASK
);
1638 struct trace_entry
*entry
;
1639 struct trace_field
*field
;
1640 unsigned long usec_rem
;
1641 unsigned long long t
;
1650 if (entry
->type
== TRACE_CONT
)
1653 field
= &entry
->field
;
1655 comm
= trace_find_cmdline(iter
->ent
->field
.pid
);
1657 t
= ns2usecs(field
->t
);
1658 usec_rem
= do_div(t
, 1000000ULL);
1659 secs
= (unsigned long)t
;
1661 ret
= trace_seq_printf(s
, "%16s-%-5d ", comm
, field
->pid
);
1664 ret
= trace_seq_printf(s
, "[%03d] ", iter
->cpu
);
1667 ret
= trace_seq_printf(s
, "%5lu.%06lu: ", secs
, usec_rem
);
1671 switch (entry
->type
) {
1673 ret
= seq_print_ip_sym(s
, field
->fn
.ip
, sym_flags
);
1676 if ((sym_flags
& TRACE_ITER_PRINT_PARENT
) &&
1677 field
->fn
.parent_ip
) {
1678 ret
= trace_seq_printf(s
, " <-");
1681 if (kretprobed(field
->fn
.parent_ip
))
1682 ret
= trace_seq_puts(s
, KRETPROBE_MSG
);
1684 ret
= seq_print_ip_sym(s
,
1685 field
->fn
.parent_ip
,
1690 ret
= trace_seq_printf(s
, "\n");
1696 S
= field
->ctx
.prev_state
< sizeof(state_to_char
) ?
1697 state_to_char
[field
->ctx
.prev_state
] : 'X';
1698 T
= field
->ctx
.next_state
< sizeof(state_to_char
) ?
1699 state_to_char
[field
->ctx
.next_state
] : 'X';
1700 ret
= trace_seq_printf(s
, " %5d:%3d:%c %s [%03d] %5d:%3d:%c\n",
1701 field
->ctx
.prev_pid
,
1702 field
->ctx
.prev_prio
,
1704 entry
->type
== TRACE_CTX
? "==>" : " +",
1705 field
->ctx
.next_cpu
,
1706 field
->ctx
.next_pid
,
1707 field
->ctx
.next_prio
,
1713 ret
= trace_seq_printf(s
, "# %ld %ld %ld\n",
1714 field
->special
.arg1
,
1715 field
->special
.arg2
,
1716 field
->special
.arg3
);
1721 for (i
= 0; i
< FTRACE_STACK_ENTRIES
; i
++) {
1723 ret
= trace_seq_puts(s
, " <= ");
1727 ret
= seq_print_ip_sym(s
, field
->stack
.caller
[i
],
1732 ret
= trace_seq_puts(s
, "\n");
1737 seq_print_ip_sym(s
, field
->print
.ip
, sym_flags
);
1738 trace_seq_printf(s
, ": %s", field
->print
.buf
);
1739 if (field
->flags
& TRACE_FLAG_CONT
)
1740 trace_seq_print_cont(s
, iter
);
1746 static int print_raw_fmt(struct trace_iterator
*iter
)
1748 struct trace_seq
*s
= &iter
->seq
;
1749 struct trace_entry
*entry
;
1750 struct trace_field
*field
;
1756 if (entry
->type
== TRACE_CONT
)
1759 field
= &entry
->field
;
1761 ret
= trace_seq_printf(s
, "%d %d %llu ",
1762 field
->pid
, iter
->cpu
, field
->t
);
1766 switch (entry
->type
) {
1768 ret
= trace_seq_printf(s
, "%x %x\n",
1770 field
->fn
.parent_ip
);
1776 S
= field
->ctx
.prev_state
< sizeof(state_to_char
) ?
1777 state_to_char
[field
->ctx
.prev_state
] : 'X';
1778 T
= field
->ctx
.next_state
< sizeof(state_to_char
) ?
1779 state_to_char
[field
->ctx
.next_state
] : 'X';
1780 if (entry
->type
== TRACE_WAKE
)
1782 ret
= trace_seq_printf(s
, "%d %d %c %d %d %d %c\n",
1783 field
->ctx
.prev_pid
,
1784 field
->ctx
.prev_prio
,
1786 field
->ctx
.next_cpu
,
1787 field
->ctx
.next_pid
,
1788 field
->ctx
.next_prio
,
1795 ret
= trace_seq_printf(s
, "# %ld %ld %ld\n",
1796 field
->special
.arg1
,
1797 field
->special
.arg2
,
1798 field
->special
.arg3
);
1803 trace_seq_printf(s
, "# %lx %s",
1804 field
->print
.ip
, field
->print
.buf
);
1805 if (field
->flags
& TRACE_FLAG_CONT
)
1806 trace_seq_print_cont(s
, iter
);
1812 #define SEQ_PUT_FIELD_RET(s, x) \
1814 if (!trace_seq_putmem(s, &(x), sizeof(x))) \
1818 #define SEQ_PUT_HEX_FIELD_RET(s, x) \
1820 if (!trace_seq_putmem_hex(s, &(x), sizeof(x))) \
1824 static int print_hex_fmt(struct trace_iterator
*iter
)
1826 struct trace_seq
*s
= &iter
->seq
;
1827 unsigned char newline
= '\n';
1828 struct trace_entry
*entry
;
1829 struct trace_field
*field
;
1834 if (entry
->type
== TRACE_CONT
)
1837 field
= &entry
->field
;
1839 SEQ_PUT_HEX_FIELD_RET(s
, field
->pid
);
1840 SEQ_PUT_HEX_FIELD_RET(s
, iter
->cpu
);
1841 SEQ_PUT_HEX_FIELD_RET(s
, field
->t
);
1843 switch (entry
->type
) {
1845 SEQ_PUT_HEX_FIELD_RET(s
, field
->fn
.ip
);
1846 SEQ_PUT_HEX_FIELD_RET(s
, field
->fn
.parent_ip
);
1850 S
= field
->ctx
.prev_state
< sizeof(state_to_char
) ?
1851 state_to_char
[field
->ctx
.prev_state
] : 'X';
1852 T
= field
->ctx
.next_state
< sizeof(state_to_char
) ?
1853 state_to_char
[field
->ctx
.next_state
] : 'X';
1854 if (entry
->type
== TRACE_WAKE
)
1856 SEQ_PUT_HEX_FIELD_RET(s
, field
->ctx
.prev_pid
);
1857 SEQ_PUT_HEX_FIELD_RET(s
, field
->ctx
.prev_prio
);
1858 SEQ_PUT_HEX_FIELD_RET(s
, S
);
1859 SEQ_PUT_HEX_FIELD_RET(s
, field
->ctx
.next_cpu
);
1860 SEQ_PUT_HEX_FIELD_RET(s
, field
->ctx
.next_pid
);
1861 SEQ_PUT_HEX_FIELD_RET(s
, field
->ctx
.next_prio
);
1862 SEQ_PUT_HEX_FIELD_RET(s
, T
);
1866 SEQ_PUT_HEX_FIELD_RET(s
, field
->special
.arg1
);
1867 SEQ_PUT_HEX_FIELD_RET(s
, field
->special
.arg2
);
1868 SEQ_PUT_HEX_FIELD_RET(s
, field
->special
.arg3
);
1871 SEQ_PUT_FIELD_RET(s
, newline
);
1876 static int print_bin_fmt(struct trace_iterator
*iter
)
1878 struct trace_seq
*s
= &iter
->seq
;
1879 struct trace_entry
*entry
;
1880 struct trace_field
*field
;
1884 if (entry
->type
== TRACE_CONT
)
1887 field
= &entry
->field
;
1889 SEQ_PUT_FIELD_RET(s
, field
->pid
);
1890 SEQ_PUT_FIELD_RET(s
, field
->cpu
);
1891 SEQ_PUT_FIELD_RET(s
, field
->t
);
1893 switch (entry
->type
) {
1895 SEQ_PUT_FIELD_RET(s
, field
->fn
.ip
);
1896 SEQ_PUT_FIELD_RET(s
, field
->fn
.parent_ip
);
1899 SEQ_PUT_FIELD_RET(s
, field
->ctx
.prev_pid
);
1900 SEQ_PUT_FIELD_RET(s
, field
->ctx
.prev_prio
);
1901 SEQ_PUT_FIELD_RET(s
, field
->ctx
.prev_state
);
1902 SEQ_PUT_FIELD_RET(s
, field
->ctx
.next_pid
);
1903 SEQ_PUT_FIELD_RET(s
, field
->ctx
.next_prio
);
1904 SEQ_PUT_FIELD_RET(s
, field
->ctx
.next_state
);
1908 SEQ_PUT_FIELD_RET(s
, field
->special
.arg1
);
1909 SEQ_PUT_FIELD_RET(s
, field
->special
.arg2
);
1910 SEQ_PUT_FIELD_RET(s
, field
->special
.arg3
);
1916 static int trace_empty(struct trace_iterator
*iter
)
1918 struct trace_array_cpu
*data
;
1921 for_each_tracing_cpu(cpu
) {
1922 data
= iter
->tr
->data
[cpu
];
1924 if (head_page(data
) && data
->trace_idx
&&
1925 (data
->trace_tail
!= data
->trace_head
||
1926 data
->trace_tail_idx
!= data
->trace_head_idx
))
1932 static int print_trace_line(struct trace_iterator
*iter
)
1934 if (iter
->trace
&& iter
->trace
->print_line
)
1935 return iter
->trace
->print_line(iter
);
1937 if (trace_flags
& TRACE_ITER_BIN
)
1938 return print_bin_fmt(iter
);
1940 if (trace_flags
& TRACE_ITER_HEX
)
1941 return print_hex_fmt(iter
);
1943 if (trace_flags
& TRACE_ITER_RAW
)
1944 return print_raw_fmt(iter
);
1946 if (iter
->iter_flags
& TRACE_FILE_LAT_FMT
)
1947 return print_lat_fmt(iter
, iter
->idx
, iter
->cpu
);
1949 return print_trace_fmt(iter
);
1952 static int s_show(struct seq_file
*m
, void *v
)
1954 struct trace_iterator
*iter
= v
;
1956 if (iter
->ent
== NULL
) {
1958 seq_printf(m
, "# tracer: %s\n", iter
->trace
->name
);
1961 if (iter
->iter_flags
& TRACE_FILE_LAT_FMT
) {
1962 /* print nothing if the buffers are empty */
1963 if (trace_empty(iter
))
1965 print_trace_header(m
, iter
);
1966 if (!(trace_flags
& TRACE_ITER_VERBOSE
))
1967 print_lat_help_header(m
);
1969 if (!(trace_flags
& TRACE_ITER_VERBOSE
))
1970 print_func_help_header(m
);
1973 print_trace_line(iter
);
1974 trace_print_seq(m
, &iter
->seq
);
1980 static struct seq_operations tracer_seq_ops
= {
1987 static struct trace_iterator
*
1988 __tracing_open(struct inode
*inode
, struct file
*file
, int *ret
)
1990 struct trace_iterator
*iter
;
1992 if (tracing_disabled
) {
1997 iter
= kzalloc(sizeof(*iter
), GFP_KERNEL
);
2003 mutex_lock(&trace_types_lock
);
2004 if (current_trace
&& current_trace
->print_max
)
2007 iter
->tr
= inode
->i_private
;
2008 iter
->trace
= current_trace
;
2011 /* TODO stop tracer */
2012 *ret
= seq_open(file
, &tracer_seq_ops
);
2014 struct seq_file
*m
= file
->private_data
;
2017 /* stop the trace while dumping */
2018 if (iter
->tr
->ctrl
) {
2020 ftrace_function_enabled
= 0;
2023 if (iter
->trace
&& iter
->trace
->open
)
2024 iter
->trace
->open(iter
);
2029 mutex_unlock(&trace_types_lock
);
2035 int tracing_open_generic(struct inode
*inode
, struct file
*filp
)
2037 if (tracing_disabled
)
2040 filp
->private_data
= inode
->i_private
;
2044 int tracing_release(struct inode
*inode
, struct file
*file
)
2046 struct seq_file
*m
= (struct seq_file
*)file
->private_data
;
2047 struct trace_iterator
*iter
= m
->private;
2049 mutex_lock(&trace_types_lock
);
2050 if (iter
->trace
&& iter
->trace
->close
)
2051 iter
->trace
->close(iter
);
2053 /* reenable tracing if it was previously enabled */
2054 if (iter
->tr
->ctrl
) {
2057 * It is safe to enable function tracing even if it
2060 ftrace_function_enabled
= 1;
2062 mutex_unlock(&trace_types_lock
);
2064 seq_release(inode
, file
);
2069 static int tracing_open(struct inode
*inode
, struct file
*file
)
2073 __tracing_open(inode
, file
, &ret
);
2078 static int tracing_lt_open(struct inode
*inode
, struct file
*file
)
2080 struct trace_iterator
*iter
;
2083 iter
= __tracing_open(inode
, file
, &ret
);
2086 iter
->iter_flags
|= TRACE_FILE_LAT_FMT
;
2093 t_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
2095 struct tracer
*t
= m
->private;
2107 static void *t_start(struct seq_file
*m
, loff_t
*pos
)
2109 struct tracer
*t
= m
->private;
2112 mutex_lock(&trace_types_lock
);
2113 for (; t
&& l
< *pos
; t
= t_next(m
, t
, &l
))
2119 static void t_stop(struct seq_file
*m
, void *p
)
2121 mutex_unlock(&trace_types_lock
);
2124 static int t_show(struct seq_file
*m
, void *v
)
2126 struct tracer
*t
= v
;
2131 seq_printf(m
, "%s", t
->name
);
2140 static struct seq_operations show_traces_seq_ops
= {
2147 static int show_traces_open(struct inode
*inode
, struct file
*file
)
2151 if (tracing_disabled
)
2154 ret
= seq_open(file
, &show_traces_seq_ops
);
2156 struct seq_file
*m
= file
->private_data
;
2157 m
->private = trace_types
;
2163 static struct file_operations tracing_fops
= {
2164 .open
= tracing_open
,
2166 .llseek
= seq_lseek
,
2167 .release
= tracing_release
,
2170 static struct file_operations tracing_lt_fops
= {
2171 .open
= tracing_lt_open
,
2173 .llseek
= seq_lseek
,
2174 .release
= tracing_release
,
2177 static struct file_operations show_traces_fops
= {
2178 .open
= show_traces_open
,
2180 .release
= seq_release
,
2184 * Only trace on a CPU if the bitmask is set:
2186 static cpumask_t tracing_cpumask
= CPU_MASK_ALL
;
2189 * When tracing/tracing_cpu_mask is modified then this holds
2190 * the new bitmask we are about to install:
2192 static cpumask_t tracing_cpumask_new
;
2195 * The tracer itself will not take this lock, but still we want
2196 * to provide a consistent cpumask to user-space:
2198 static DEFINE_MUTEX(tracing_cpumask_update_lock
);
2201 * Temporary storage for the character representation of the
2202 * CPU bitmask (and one more byte for the newline):
2204 static char mask_str
[NR_CPUS
+ 1];
2207 tracing_cpumask_read(struct file
*filp
, char __user
*ubuf
,
2208 size_t count
, loff_t
*ppos
)
2212 mutex_lock(&tracing_cpumask_update_lock
);
2214 len
= cpumask_scnprintf(mask_str
, count
, tracing_cpumask
);
2215 if (count
- len
< 2) {
2219 len
+= sprintf(mask_str
+ len
, "\n");
2220 count
= simple_read_from_buffer(ubuf
, count
, ppos
, mask_str
, NR_CPUS
+1);
2223 mutex_unlock(&tracing_cpumask_update_lock
);
2229 tracing_cpumask_write(struct file
*filp
, const char __user
*ubuf
,
2230 size_t count
, loff_t
*ppos
)
2234 mutex_lock(&tracing_cpumask_update_lock
);
2235 err
= cpumask_parse_user(ubuf
, count
, tracing_cpumask_new
);
2239 raw_local_irq_disable();
2240 __raw_spin_lock(&ftrace_max_lock
);
2241 for_each_tracing_cpu(cpu
) {
2243 * Increase/decrease the disabled counter if we are
2244 * about to flip a bit in the cpumask:
2246 if (cpu_isset(cpu
, tracing_cpumask
) &&
2247 !cpu_isset(cpu
, tracing_cpumask_new
)) {
2248 atomic_inc(&global_trace
.data
[cpu
]->disabled
);
2250 if (!cpu_isset(cpu
, tracing_cpumask
) &&
2251 cpu_isset(cpu
, tracing_cpumask_new
)) {
2252 atomic_dec(&global_trace
.data
[cpu
]->disabled
);
2255 __raw_spin_unlock(&ftrace_max_lock
);
2256 raw_local_irq_enable();
2258 tracing_cpumask
= tracing_cpumask_new
;
2260 mutex_unlock(&tracing_cpumask_update_lock
);
2265 mutex_unlock(&tracing_cpumask_update_lock
);
2270 static struct file_operations tracing_cpumask_fops
= {
2271 .open
= tracing_open_generic
,
2272 .read
= tracing_cpumask_read
,
2273 .write
= tracing_cpumask_write
,
2277 tracing_iter_ctrl_read(struct file
*filp
, char __user
*ubuf
,
2278 size_t cnt
, loff_t
*ppos
)
2285 /* calulate max size */
2286 for (i
= 0; trace_options
[i
]; i
++) {
2287 len
+= strlen(trace_options
[i
]);
2288 len
+= 3; /* "no" and space */
2291 /* +2 for \n and \0 */
2292 buf
= kmalloc(len
+ 2, GFP_KERNEL
);
2296 for (i
= 0; trace_options
[i
]; i
++) {
2297 if (trace_flags
& (1 << i
))
2298 r
+= sprintf(buf
+ r
, "%s ", trace_options
[i
]);
2300 r
+= sprintf(buf
+ r
, "no%s ", trace_options
[i
]);
2303 r
+= sprintf(buf
+ r
, "\n");
2304 WARN_ON(r
>= len
+ 2);
2306 r
= simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
2314 tracing_iter_ctrl_write(struct file
*filp
, const char __user
*ubuf
,
2315 size_t cnt
, loff_t
*ppos
)
2322 if (cnt
>= sizeof(buf
))
2325 if (copy_from_user(&buf
, ubuf
, cnt
))
2330 if (strncmp(buf
, "no", 2) == 0) {
2335 for (i
= 0; trace_options
[i
]; i
++) {
2336 int len
= strlen(trace_options
[i
]);
2338 if (strncmp(cmp
, trace_options
[i
], len
) == 0) {
2340 trace_flags
&= ~(1 << i
);
2342 trace_flags
|= (1 << i
);
2347 * If no option could be set, return an error:
2349 if (!trace_options
[i
])
2357 static struct file_operations tracing_iter_fops
= {
2358 .open
= tracing_open_generic
,
2359 .read
= tracing_iter_ctrl_read
,
2360 .write
= tracing_iter_ctrl_write
,
2363 static const char readme_msg
[] =
2364 "tracing mini-HOWTO:\n\n"
2366 "# mount -t debugfs nodev /debug\n\n"
2367 "# cat /debug/tracing/available_tracers\n"
2368 "wakeup preemptirqsoff preemptoff irqsoff ftrace sched_switch none\n\n"
2369 "# cat /debug/tracing/current_tracer\n"
2371 "# echo sched_switch > /debug/tracing/current_tracer\n"
2372 "# cat /debug/tracing/current_tracer\n"
2374 "# cat /debug/tracing/iter_ctrl\n"
2375 "noprint-parent nosym-offset nosym-addr noverbose\n"
2376 "# echo print-parent > /debug/tracing/iter_ctrl\n"
2377 "# echo 1 > /debug/tracing/tracing_enabled\n"
2378 "# cat /debug/tracing/trace > /tmp/trace.txt\n"
2379 "echo 0 > /debug/tracing/tracing_enabled\n"
2383 tracing_readme_read(struct file
*filp
, char __user
*ubuf
,
2384 size_t cnt
, loff_t
*ppos
)
2386 return simple_read_from_buffer(ubuf
, cnt
, ppos
,
2387 readme_msg
, strlen(readme_msg
));
2390 static struct file_operations tracing_readme_fops
= {
2391 .open
= tracing_open_generic
,
2392 .read
= tracing_readme_read
,
2396 tracing_ctrl_read(struct file
*filp
, char __user
*ubuf
,
2397 size_t cnt
, loff_t
*ppos
)
2399 struct trace_array
*tr
= filp
->private_data
;
2403 r
= sprintf(buf
, "%ld\n", tr
->ctrl
);
2404 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
2408 tracing_ctrl_write(struct file
*filp
, const char __user
*ubuf
,
2409 size_t cnt
, loff_t
*ppos
)
2411 struct trace_array
*tr
= filp
->private_data
;
2416 if (cnt
>= sizeof(buf
))
2419 if (copy_from_user(&buf
, ubuf
, cnt
))
2424 ret
= strict_strtoul(buf
, 10, &val
);
2430 mutex_lock(&trace_types_lock
);
2431 if (tr
->ctrl
^ val
) {
2439 if (current_trace
&& current_trace
->ctrl_update
)
2440 current_trace
->ctrl_update(tr
);
2442 mutex_unlock(&trace_types_lock
);
2450 tracing_set_trace_read(struct file
*filp
, char __user
*ubuf
,
2451 size_t cnt
, loff_t
*ppos
)
2453 char buf
[max_tracer_type_len
+2];
2456 mutex_lock(&trace_types_lock
);
2458 r
= sprintf(buf
, "%s\n", current_trace
->name
);
2460 r
= sprintf(buf
, "\n");
2461 mutex_unlock(&trace_types_lock
);
2463 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
2467 tracing_set_trace_write(struct file
*filp
, const char __user
*ubuf
,
2468 size_t cnt
, loff_t
*ppos
)
2470 struct trace_array
*tr
= &global_trace
;
2472 char buf
[max_tracer_type_len
+1];
2475 if (cnt
> max_tracer_type_len
)
2476 cnt
= max_tracer_type_len
;
2478 if (copy_from_user(&buf
, ubuf
, cnt
))
2483 /* strip ending whitespace. */
2484 for (i
= cnt
- 1; i
> 0 && isspace(buf
[i
]); i
--)
2487 mutex_lock(&trace_types_lock
);
2488 for (t
= trace_types
; t
; t
= t
->next
) {
2489 if (strcmp(t
->name
, buf
) == 0)
2492 if (!t
|| t
== current_trace
)
2495 if (current_trace
&& current_trace
->reset
)
2496 current_trace
->reset(tr
);
2503 mutex_unlock(&trace_types_lock
);
2511 tracing_max_lat_read(struct file
*filp
, char __user
*ubuf
,
2512 size_t cnt
, loff_t
*ppos
)
2514 unsigned long *ptr
= filp
->private_data
;
2518 r
= snprintf(buf
, sizeof(buf
), "%ld\n",
2519 *ptr
== (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr
));
2520 if (r
> sizeof(buf
))
2522 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
2526 tracing_max_lat_write(struct file
*filp
, const char __user
*ubuf
,
2527 size_t cnt
, loff_t
*ppos
)
2529 long *ptr
= filp
->private_data
;
2534 if (cnt
>= sizeof(buf
))
2537 if (copy_from_user(&buf
, ubuf
, cnt
))
2542 ret
= strict_strtoul(buf
, 10, &val
);
2551 static atomic_t tracing_reader
;
2553 static int tracing_open_pipe(struct inode
*inode
, struct file
*filp
)
2555 struct trace_iterator
*iter
;
2557 if (tracing_disabled
)
2560 /* We only allow for reader of the pipe */
2561 if (atomic_inc_return(&tracing_reader
) != 1) {
2562 atomic_dec(&tracing_reader
);
2566 /* create a buffer to store the information to pass to userspace */
2567 iter
= kzalloc(sizeof(*iter
), GFP_KERNEL
);
2571 mutex_lock(&trace_types_lock
);
2572 iter
->tr
= &global_trace
;
2573 iter
->trace
= current_trace
;
2574 filp
->private_data
= iter
;
2576 if (iter
->trace
->pipe_open
)
2577 iter
->trace
->pipe_open(iter
);
2578 mutex_unlock(&trace_types_lock
);
2583 static int tracing_release_pipe(struct inode
*inode
, struct file
*file
)
2585 struct trace_iterator
*iter
= file
->private_data
;
2588 atomic_dec(&tracing_reader
);
2594 tracing_poll_pipe(struct file
*filp
, poll_table
*poll_table
)
2596 struct trace_iterator
*iter
= filp
->private_data
;
2598 if (trace_flags
& TRACE_ITER_BLOCK
) {
2600 * Always select as readable when in blocking mode
2602 return POLLIN
| POLLRDNORM
;
2604 if (!trace_empty(iter
))
2605 return POLLIN
| POLLRDNORM
;
2606 poll_wait(filp
, &trace_wait
, poll_table
);
2607 if (!trace_empty(iter
))
2608 return POLLIN
| POLLRDNORM
;
2618 tracing_read_pipe(struct file
*filp
, char __user
*ubuf
,
2619 size_t cnt
, loff_t
*ppos
)
2621 struct trace_iterator
*iter
= filp
->private_data
;
2622 struct trace_array_cpu
*data
;
2623 static cpumask_t mask
;
2624 unsigned long flags
;
2625 #ifdef CONFIG_FTRACE
2631 /* return any leftover data */
2632 sret
= trace_seq_to_user(&iter
->seq
, ubuf
, cnt
);
2637 trace_seq_reset(&iter
->seq
);
2639 mutex_lock(&trace_types_lock
);
2640 if (iter
->trace
->read
) {
2641 sret
= iter
->trace
->read(iter
, filp
, ubuf
, cnt
, ppos
);
2646 while (trace_empty(iter
)) {
2648 if ((filp
->f_flags
& O_NONBLOCK
)) {
2654 * This is a make-shift waitqueue. The reason we don't use
2655 * an actual wait queue is because:
2656 * 1) we only ever have one waiter
2657 * 2) the tracing, traces all functions, we don't want
2658 * the overhead of calling wake_up and friends
2659 * (and tracing them too)
2660 * Anyway, this is really very primitive wakeup.
2662 set_current_state(TASK_INTERRUPTIBLE
);
2663 iter
->tr
->waiter
= current
;
2665 mutex_unlock(&trace_types_lock
);
2667 /* sleep for 100 msecs, and try again. */
2668 schedule_timeout(HZ
/10);
2670 mutex_lock(&trace_types_lock
);
2672 iter
->tr
->waiter
= NULL
;
2674 if (signal_pending(current
)) {
2679 if (iter
->trace
!= current_trace
)
2683 * We block until we read something and tracing is disabled.
2684 * We still block if tracing is disabled, but we have never
2685 * read anything. This allows a user to cat this file, and
2686 * then enable tracing. But after we have read something,
2687 * we give an EOF when tracing is again disabled.
2689 * iter->pos will be 0 if we haven't read anything.
2691 if (!tracer_enabled
&& iter
->pos
)
2697 /* stop when tracing is finished */
2698 if (trace_empty(iter
))
2701 if (cnt
>= PAGE_SIZE
)
2702 cnt
= PAGE_SIZE
- 1;
2704 /* reset all but tr, trace, and overruns */
2705 memset(&iter
->seq
, 0,
2706 sizeof(struct trace_iterator
) -
2707 offsetof(struct trace_iterator
, seq
));
2711 * We need to stop all tracing on all CPUS to read the
2712 * the next buffer. This is a bit expensive, but is
2713 * not done often. We fill all what we can read,
2714 * and then release the locks again.
2718 local_irq_save(flags
);
2719 #ifdef CONFIG_FTRACE
2720 ftrace_save
= ftrace_enabled
;
2724 for_each_tracing_cpu(cpu
) {
2725 data
= iter
->tr
->data
[cpu
];
2727 if (!head_page(data
) || !data
->trace_idx
)
2730 atomic_inc(&data
->disabled
);
2734 for_each_cpu_mask(cpu
, mask
) {
2735 data
= iter
->tr
->data
[cpu
];
2736 __raw_spin_lock(&data
->lock
);
2738 if (data
->overrun
> iter
->last_overrun
[cpu
])
2739 iter
->overrun
[cpu
] +=
2740 data
->overrun
- iter
->last_overrun
[cpu
];
2741 iter
->last_overrun
[cpu
] = data
->overrun
;
2744 while (find_next_entry_inc(iter
) != NULL
) {
2746 int len
= iter
->seq
.len
;
2748 ret
= print_trace_line(iter
);
2750 /* don't print partial lines */
2751 iter
->seq
.len
= len
;
2755 trace_consume(iter
);
2757 if (iter
->seq
.len
>= cnt
)
2761 for_each_cpu_mask(cpu
, mask
) {
2762 data
= iter
->tr
->data
[cpu
];
2763 __raw_spin_unlock(&data
->lock
);
2766 for_each_cpu_mask(cpu
, mask
) {
2767 data
= iter
->tr
->data
[cpu
];
2768 atomic_dec(&data
->disabled
);
2770 #ifdef CONFIG_FTRACE
2771 ftrace_enabled
= ftrace_save
;
2773 local_irq_restore(flags
);
2775 /* Now copy what we have to the user */
2776 sret
= trace_seq_to_user(&iter
->seq
, ubuf
, cnt
);
2777 if (iter
->seq
.readpos
>= iter
->seq
.len
)
2778 trace_seq_reset(&iter
->seq
);
2783 mutex_unlock(&trace_types_lock
);
2789 tracing_entries_read(struct file
*filp
, char __user
*ubuf
,
2790 size_t cnt
, loff_t
*ppos
)
2792 struct trace_array
*tr
= filp
->private_data
;
2796 r
= sprintf(buf
, "%lu\n", tr
->entries
);
2797 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
2801 tracing_entries_write(struct file
*filp
, const char __user
*ubuf
,
2802 size_t cnt
, loff_t
*ppos
)
2808 if (cnt
>= sizeof(buf
))
2811 if (copy_from_user(&buf
, ubuf
, cnt
))
2816 ret
= strict_strtoul(buf
, 10, &val
);
2820 /* must have at least 1 entry */
2824 mutex_lock(&trace_types_lock
);
2826 if (current_trace
!= &no_tracer
) {
2828 pr_info("ftrace: set current_tracer to none"
2829 " before modifying buffer size\n");
2833 if (val
> global_trace
.entries
) {
2834 long pages_requested
;
2835 unsigned long freeable_pages
;
2837 /* make sure we have enough memory before mapping */
2839 (val
+ (ENTRIES_PER_PAGE
-1)) / ENTRIES_PER_PAGE
;
2841 /* account for each buffer (and max_tr) */
2842 pages_requested
*= tracing_nr_buffers
* 2;
2844 /* Check for overflow */
2845 if (pages_requested
< 0) {
2850 freeable_pages
= determine_dirtyable_memory();
2852 /* we only allow to request 1/4 of useable memory */
2853 if (pages_requested
>
2854 ((freeable_pages
+ tracing_pages_allocated
) / 4)) {
2859 while (global_trace
.entries
< val
) {
2860 if (trace_alloc_page()) {
2864 /* double check that we don't go over the known pages */
2865 if (tracing_pages_allocated
> pages_requested
)
2870 /* include the number of entries in val (inc of page entries) */
2871 while (global_trace
.entries
> val
+ (ENTRIES_PER_PAGE
- 1))
2875 /* check integrity */
2876 for_each_tracing_cpu(i
)
2877 check_pages(global_trace
.data
[i
]);
2881 /* If check pages failed, return ENOMEM */
2882 if (tracing_disabled
)
2885 max_tr
.entries
= global_trace
.entries
;
2886 mutex_unlock(&trace_types_lock
);
2891 static struct file_operations tracing_max_lat_fops
= {
2892 .open
= tracing_open_generic
,
2893 .read
= tracing_max_lat_read
,
2894 .write
= tracing_max_lat_write
,
2897 static struct file_operations tracing_ctrl_fops
= {
2898 .open
= tracing_open_generic
,
2899 .read
= tracing_ctrl_read
,
2900 .write
= tracing_ctrl_write
,
2903 static struct file_operations set_tracer_fops
= {
2904 .open
= tracing_open_generic
,
2905 .read
= tracing_set_trace_read
,
2906 .write
= tracing_set_trace_write
,
2909 static struct file_operations tracing_pipe_fops
= {
2910 .open
= tracing_open_pipe
,
2911 .poll
= tracing_poll_pipe
,
2912 .read
= tracing_read_pipe
,
2913 .release
= tracing_release_pipe
,
2916 static struct file_operations tracing_entries_fops
= {
2917 .open
= tracing_open_generic
,
2918 .read
= tracing_entries_read
,
2919 .write
= tracing_entries_write
,
2922 #ifdef CONFIG_DYNAMIC_FTRACE
2925 tracing_read_long(struct file
*filp
, char __user
*ubuf
,
2926 size_t cnt
, loff_t
*ppos
)
2928 unsigned long *p
= filp
->private_data
;
2932 r
= sprintf(buf
, "%ld\n", *p
);
2934 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, r
);
2937 static struct file_operations tracing_read_long_fops
= {
2938 .open
= tracing_open_generic
,
2939 .read
= tracing_read_long
,
2943 static struct dentry
*d_tracer
;
2945 struct dentry
*tracing_init_dentry(void)
2952 d_tracer
= debugfs_create_dir("tracing", NULL
);
2954 if (!d_tracer
&& !once
) {
2956 pr_warning("Could not create debugfs directory 'tracing'\n");
2963 #ifdef CONFIG_FTRACE_SELFTEST
2964 /* Let selftest have access to static functions in this file */
2965 #include "trace_selftest.c"
2968 static __init
void tracer_init_debugfs(void)
2970 struct dentry
*d_tracer
;
2971 struct dentry
*entry
;
2973 d_tracer
= tracing_init_dentry();
2975 entry
= debugfs_create_file("tracing_enabled", 0644, d_tracer
,
2976 &global_trace
, &tracing_ctrl_fops
);
2978 pr_warning("Could not create debugfs 'tracing_enabled' entry\n");
2980 entry
= debugfs_create_file("iter_ctrl", 0644, d_tracer
,
2981 NULL
, &tracing_iter_fops
);
2983 pr_warning("Could not create debugfs 'iter_ctrl' entry\n");
2985 entry
= debugfs_create_file("tracing_cpumask", 0644, d_tracer
,
2986 NULL
, &tracing_cpumask_fops
);
2988 pr_warning("Could not create debugfs 'tracing_cpumask' entry\n");
2990 entry
= debugfs_create_file("latency_trace", 0444, d_tracer
,
2991 &global_trace
, &tracing_lt_fops
);
2993 pr_warning("Could not create debugfs 'latency_trace' entry\n");
2995 entry
= debugfs_create_file("trace", 0444, d_tracer
,
2996 &global_trace
, &tracing_fops
);
2998 pr_warning("Could not create debugfs 'trace' entry\n");
3000 entry
= debugfs_create_file("available_tracers", 0444, d_tracer
,
3001 &global_trace
, &show_traces_fops
);
3003 pr_warning("Could not create debugfs 'available_tracers' entry\n");
3005 entry
= debugfs_create_file("current_tracer", 0444, d_tracer
,
3006 &global_trace
, &set_tracer_fops
);
3008 pr_warning("Could not create debugfs 'current_tracer' entry\n");
3010 entry
= debugfs_create_file("tracing_max_latency", 0644, d_tracer
,
3011 &tracing_max_latency
,
3012 &tracing_max_lat_fops
);
3014 pr_warning("Could not create debugfs "
3015 "'tracing_max_latency' entry\n");
3017 entry
= debugfs_create_file("tracing_thresh", 0644, d_tracer
,
3018 &tracing_thresh
, &tracing_max_lat_fops
);
3020 pr_warning("Could not create debugfs "
3021 "'tracing_thresh' entry\n");
3022 entry
= debugfs_create_file("README", 0644, d_tracer
,
3023 NULL
, &tracing_readme_fops
);
3025 pr_warning("Could not create debugfs 'README' entry\n");
3027 entry
= debugfs_create_file("trace_pipe", 0644, d_tracer
,
3028 NULL
, &tracing_pipe_fops
);
3030 pr_warning("Could not create debugfs "
3031 "'trace_pipe' entry\n");
3033 entry
= debugfs_create_file("trace_entries", 0644, d_tracer
,
3034 &global_trace
, &tracing_entries_fops
);
3036 pr_warning("Could not create debugfs "
3037 "'trace_entries' entry\n");
3039 #ifdef CONFIG_DYNAMIC_FTRACE
3040 entry
= debugfs_create_file("dyn_ftrace_total_info", 0444, d_tracer
,
3041 &ftrace_update_tot_cnt
,
3042 &tracing_read_long_fops
);
3044 pr_warning("Could not create debugfs "
3045 "'dyn_ftrace_total_info' entry\n");
3047 #ifdef CONFIG_SYSPROF_TRACER
3048 init_tracer_sysprof_debugfs(d_tracer
);
3052 #define TRACE_BUF_SIZE 1024
3053 #define TRACE_PRINT_BUF_SIZE \
3054 (sizeof(struct trace_field) - offsetof(struct trace_field, print.buf))
3055 #define TRACE_CONT_BUF_SIZE sizeof(struct trace_field)
3057 int trace_vprintk(unsigned long ip
, const char *fmt
, va_list args
)
3059 static DEFINE_SPINLOCK(trace_buf_lock
);
3060 static char trace_buf
[TRACE_BUF_SIZE
];
3062 struct trace_array
*tr
= &global_trace
;
3063 struct trace_array_cpu
*data
;
3064 struct trace_entry
*entry
;
3065 unsigned long flags
;
3067 int cpu
, len
= 0, write
, written
= 0;
3069 if (current_trace
== &no_tracer
|| !tr
->ctrl
|| tracing_disabled
)
3072 local_irq_save(flags
);
3073 cpu
= raw_smp_processor_id();
3074 data
= tr
->data
[cpu
];
3075 disabled
= atomic_inc_return(&data
->disabled
);
3077 if (unlikely(disabled
!= 1))
3080 spin_lock(&trace_buf_lock
);
3081 len
= vsnprintf(trace_buf
, TRACE_BUF_SIZE
, fmt
, args
);
3083 len
= min(len
, TRACE_BUF_SIZE
-1);
3086 __raw_spin_lock(&data
->lock
);
3087 entry
= tracing_get_trace_entry(tr
, data
);
3088 tracing_generic_entry_update(entry
, flags
);
3089 entry
->type
= TRACE_PRINT
;
3090 entry
->field
.print
.ip
= ip
;
3092 write
= min(len
, (int)(TRACE_PRINT_BUF_SIZE
-1));
3094 memcpy(&entry
->field
.print
.buf
, trace_buf
, write
);
3095 entry
->field
.print
.buf
[write
] = 0;
3099 entry
->field
.flags
|= TRACE_FLAG_CONT
;
3101 while (written
!= len
) {
3102 entry
= tracing_get_trace_entry(tr
, data
);
3104 entry
->type
= TRACE_CONT
;
3105 write
= min(len
- written
, (int)(TRACE_CONT_BUF_SIZE
-1));
3106 memcpy(&entry
->cont
.buf
, trace_buf
+written
, write
);
3107 entry
->cont
.buf
[write
] = 0;
3110 __raw_spin_unlock(&data
->lock
);
3112 spin_unlock(&trace_buf_lock
);
3115 atomic_dec(&data
->disabled
);
3116 local_irq_restore(flags
);
3120 EXPORT_SYMBOL_GPL(trace_vprintk
);
3122 int __ftrace_printk(unsigned long ip
, const char *fmt
, ...)
3127 if (!(trace_flags
& TRACE_ITER_PRINTK
))
3131 ret
= trace_vprintk(ip
, fmt
, ap
);
3135 EXPORT_SYMBOL_GPL(__ftrace_printk
);
3137 static int trace_panic_handler(struct notifier_block
*this,
3138 unsigned long event
, void *unused
)
3144 static struct notifier_block trace_panic_notifier
= {
3145 .notifier_call
= trace_panic_handler
,
3147 .priority
= 150 /* priority: INT_MAX >= x >= 0 */
3150 static int trace_die_handler(struct notifier_block
*self
,
3164 static struct notifier_block trace_die_notifier
= {
3165 .notifier_call
= trace_die_handler
,
3170 * printk is set to max of 1024, we really don't need it that big.
3171 * Nothing should be printing 1000 characters anyway.
3173 #define TRACE_MAX_PRINT 1000
3176 * Define here KERN_TRACE so that we have one place to modify
3177 * it if we decide to change what log level the ftrace dump
3180 #define KERN_TRACE KERN_INFO
3183 trace_printk_seq(struct trace_seq
*s
)
3185 /* Probably should print a warning here. */
3189 /* should be zero ended, but we are paranoid. */
3190 s
->buffer
[s
->len
] = 0;
3192 printk(KERN_TRACE
"%s", s
->buffer
);
3198 void ftrace_dump(void)
3200 static DEFINE_SPINLOCK(ftrace_dump_lock
);
3201 /* use static because iter can be a bit big for the stack */
3202 static struct trace_iterator iter
;
3203 struct trace_array_cpu
*data
;
3204 static cpumask_t mask
;
3205 static int dump_ran
;
3206 unsigned long flags
;
3211 spin_lock_irqsave(&ftrace_dump_lock
, flags
);
3217 /* No turning back! */
3218 ftrace_kill_atomic();
3220 printk(KERN_TRACE
"Dumping ftrace buffer:\n");
3222 iter
.tr
= &global_trace
;
3223 iter
.trace
= current_trace
;
3226 * We need to stop all tracing on all CPUS to read the
3227 * the next buffer. This is a bit expensive, but is
3228 * not done often. We fill all what we can read,
3229 * and then release the locks again.
3234 for_each_tracing_cpu(cpu
) {
3235 data
= iter
.tr
->data
[cpu
];
3237 if (!head_page(data
) || !data
->trace_idx
)
3240 atomic_inc(&data
->disabled
);
3244 for_each_cpu_mask(cpu
, mask
) {
3245 data
= iter
.tr
->data
[cpu
];
3246 __raw_spin_lock(&data
->lock
);
3248 if (data
->overrun
> iter
.last_overrun
[cpu
])
3249 iter
.overrun
[cpu
] +=
3250 data
->overrun
- iter
.last_overrun
[cpu
];
3251 iter
.last_overrun
[cpu
] = data
->overrun
;
3254 while (!trace_empty(&iter
)) {
3257 printk(KERN_TRACE
"---------------------------------\n");
3261 /* reset all but tr, trace, and overruns */
3262 memset(&iter
.seq
, 0,
3263 sizeof(struct trace_iterator
) -
3264 offsetof(struct trace_iterator
, seq
));
3265 iter
.iter_flags
|= TRACE_FILE_LAT_FMT
;
3268 if (find_next_entry_inc(&iter
) != NULL
) {
3269 print_trace_line(&iter
);
3270 trace_consume(&iter
);
3273 trace_printk_seq(&iter
.seq
);
3277 printk(KERN_TRACE
" (ftrace buffer empty)\n");
3279 printk(KERN_TRACE
"---------------------------------\n");
3281 for_each_cpu_mask(cpu
, mask
) {
3282 data
= iter
.tr
->data
[cpu
];
3283 __raw_spin_unlock(&data
->lock
);
3286 for_each_cpu_mask(cpu
, mask
) {
3287 data
= iter
.tr
->data
[cpu
];
3288 atomic_dec(&data
->disabled
);
3293 spin_unlock_irqrestore(&ftrace_dump_lock
, flags
);
3296 static int trace_alloc_page(void)
3298 struct trace_array_cpu
*data
;
3299 struct page
*page
, *tmp
;
3302 unsigned pages_allocated
= 0;
3305 /* first allocate a page for each CPU */
3306 for_each_tracing_cpu(i
) {
3307 array
= (void *)__get_free_page(GFP_KERNEL
);
3308 if (array
== NULL
) {
3309 printk(KERN_ERR
"tracer: failed to allocate page"
3310 "for trace buffer!\n");
3315 page
= virt_to_page(array
);
3316 list_add(&page
->lru
, &pages
);
3318 /* Only allocate if we are actually using the max trace */
3319 #ifdef CONFIG_TRACER_MAX_TRACE
3320 array
= (void *)__get_free_page(GFP_KERNEL
);
3321 if (array
== NULL
) {
3322 printk(KERN_ERR
"tracer: failed to allocate page"
3323 "for trace buffer!\n");
3327 page
= virt_to_page(array
);
3328 list_add(&page
->lru
, &pages
);
3332 /* Now that we successfully allocate a page per CPU, add them */
3333 for_each_tracing_cpu(i
) {
3334 data
= global_trace
.data
[i
];
3335 page
= list_entry(pages
.next
, struct page
, lru
);
3336 list_del_init(&page
->lru
);
3337 list_add_tail(&page
->lru
, &data
->trace_pages
);
3340 #ifdef CONFIG_TRACER_MAX_TRACE
3341 data
= max_tr
.data
[i
];
3342 page
= list_entry(pages
.next
, struct page
, lru
);
3343 list_del_init(&page
->lru
);
3344 list_add_tail(&page
->lru
, &data
->trace_pages
);
3348 tracing_pages_allocated
+= pages_allocated
;
3349 global_trace
.entries
+= ENTRIES_PER_PAGE
;
3354 list_for_each_entry_safe(page
, tmp
, &pages
, lru
) {
3355 list_del_init(&page
->lru
);
3361 static int trace_free_page(void)
3363 struct trace_array_cpu
*data
;
3365 struct list_head
*p
;
3369 /* free one page from each buffer */
3370 for_each_tracing_cpu(i
) {
3371 data
= global_trace
.data
[i
];
3372 p
= data
->trace_pages
.next
;
3373 if (p
== &data
->trace_pages
) {
3374 /* should never happen */
3376 tracing_disabled
= 1;
3380 page
= list_entry(p
, struct page
, lru
);
3382 list_del(&page
->lru
);
3383 tracing_pages_allocated
--;
3384 tracing_pages_allocated
--;
3387 tracing_reset(data
);
3389 #ifdef CONFIG_TRACER_MAX_TRACE
3390 data
= max_tr
.data
[i
];
3391 p
= data
->trace_pages
.next
;
3392 if (p
== &data
->trace_pages
) {
3393 /* should never happen */
3395 tracing_disabled
= 1;
3399 page
= list_entry(p
, struct page
, lru
);
3401 list_del(&page
->lru
);
3404 tracing_reset(data
);
3407 global_trace
.entries
-= ENTRIES_PER_PAGE
;
3412 __init
static int tracer_alloc_buffers(void)
3414 struct trace_array_cpu
*data
;
3421 /* TODO: make the number of buffers hot pluggable with CPUS */
3422 tracing_nr_buffers
= num_possible_cpus();
3423 tracing_buffer_mask
= cpu_possible_map
;
3425 /* Allocate the first page for all buffers */
3426 for_each_tracing_cpu(i
) {
3427 data
= global_trace
.data
[i
] = &per_cpu(global_trace_cpu
, i
);
3428 max_tr
.data
[i
] = &per_cpu(max_data
, i
);
3430 array
= (void *)__get_free_page(GFP_KERNEL
);
3431 if (array
== NULL
) {
3432 printk(KERN_ERR
"tracer: failed to allocate page"
3433 "for trace buffer!\n");
3437 /* set the array to the list */
3438 INIT_LIST_HEAD(&data
->trace_pages
);
3439 page
= virt_to_page(array
);
3440 list_add(&page
->lru
, &data
->trace_pages
);
3441 /* use the LRU flag to differentiate the two buffers */
3444 data
->lock
= (raw_spinlock_t
)__RAW_SPIN_LOCK_UNLOCKED
;
3445 max_tr
.data
[i
]->lock
= (raw_spinlock_t
)__RAW_SPIN_LOCK_UNLOCKED
;
3447 /* Only allocate if we are actually using the max trace */
3448 #ifdef CONFIG_TRACER_MAX_TRACE
3449 array
= (void *)__get_free_page(GFP_KERNEL
);
3450 if (array
== NULL
) {
3451 printk(KERN_ERR
"tracer: failed to allocate page"
3452 "for trace buffer!\n");
3456 INIT_LIST_HEAD(&max_tr
.data
[i
]->trace_pages
);
3457 page
= virt_to_page(array
);
3458 list_add(&page
->lru
, &max_tr
.data
[i
]->trace_pages
);
3464 * Since we allocate by orders of pages, we may be able to
3467 global_trace
.entries
= ENTRIES_PER_PAGE
;
3470 while (global_trace
.entries
< trace_nr_entries
) {
3471 if (trace_alloc_page())
3475 max_tr
.entries
= global_trace
.entries
;
3477 pr_info("tracer: %d pages allocated for %ld entries of %ld bytes\n",
3478 pages
, trace_nr_entries
, (long)TRACE_ENTRY_SIZE
);
3479 pr_info(" actual entries %ld\n", global_trace
.entries
);
3481 tracer_init_debugfs();
3483 trace_init_cmdlines();
3485 register_tracer(&no_tracer
);
3486 current_trace
= &no_tracer
;
3488 /* All seems OK, enable tracing */
3489 global_trace
.ctrl
= tracer_enabled
;
3490 tracing_disabled
= 0;
3492 atomic_notifier_chain_register(&panic_notifier_list
,
3493 &trace_panic_notifier
);
3495 register_die_notifier(&trace_die_notifier
);
3500 for (i
-- ; i
>= 0; i
--) {
3501 struct page
*page
, *tmp
;
3502 struct trace_array_cpu
*data
= global_trace
.data
[i
];
3505 list_for_each_entry_safe(page
, tmp
,
3506 &data
->trace_pages
, lru
) {
3507 list_del_init(&page
->lru
);
3512 #ifdef CONFIG_TRACER_MAX_TRACE
3513 data
= max_tr
.data
[i
];
3515 list_for_each_entry_safe(page
, tmp
,
3516 &data
->trace_pages
, lru
) {
3517 list_del_init(&page
->lru
);
3525 fs_initcall(tracer_alloc_buffers
);