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/debugfs.h>
18 #include <linux/pagemap.h>
19 #include <linux/hardirq.h>
20 #include <linux/linkage.h>
21 #include <linux/uaccess.h>
22 #include <linux/ftrace.h>
23 #include <linux/module.h>
24 #include <linux/percpu.h>
25 #include <linux/ctype.h>
26 #include <linux/init.h>
27 #include <linux/poll.h>
28 #include <linux/gfp.h>
31 #include <linux/stacktrace.h>
35 unsigned long __read_mostly tracing_max_latency = (cycle_t)ULONG_MAX;
36 unsigned long __read_mostly tracing_thresh;
38 static unsigned long __read_mostly tracing_nr_buffers;
39 static cpumask_t __read_mostly tracing_buffer_mask;
41 #define for_each_tracing_cpu(cpu) \
42 for_each_cpu_mask(cpu, tracing_buffer_mask)
44 /* dummy trace to disable tracing */
45 static struct tracer no_tracer __read_mostly = {
49 static int trace_alloc_page(void);
50 static int trace_free_page(void);
52 static int tracing_disabled = 1;
55 ns2usecs(cycle_t nsec)
62 cycle_t ftrace_now(int cpu)
64 return cpu_clock(cpu);
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;
101 * trace_nr_entries is the number of entries that is allocated
102 * for a buffer. Note, the number of entries is always rounded
103 * to ENTRIES_PER_PAGE.
105 static unsigned long trace_nr_entries = 65536UL;
107 /* trace_types holds a link list of available tracers. */
108 static struct tracer *trace_types __read_mostly;
110 /* current_trace points to the tracer that is currently active */
111 static struct tracer *current_trace __read_mostly;
114 * max_tracer_type_len is used to simplify the allocating of
115 * buffers to read userspace tracer names. We keep track of
116 * the longest tracer name registered.
118 static int max_tracer_type_len;
121 * trace_types_lock is used to protect the trace_types list.
122 * This lock is also used to keep user access serialized.
123 * Accesses from userspace will grab this lock while userspace
124 * activities happen inside the kernel.
126 static DEFINE_MUTEX(trace_types_lock);
128 /* trace_wait is a waitqueue for tasks blocked on trace_poll */
129 static DECLARE_WAIT_QUEUE_HEAD(trace_wait);
131 /* trace_flags holds iter_ctrl options */
132 unsigned long trace_flags = TRACE_ITER_PRINT_PARENT;
135 * trace_wake_up - wake up tasks waiting for trace input
137 * Simply wakes up any task that is blocked on the trace_wait
138 * queue. These is used with trace_poll for tasks polling the trace.
140 void trace_wake_up(void)
143 * The runqueue_is_locked() can fail, but this is the best we
146 if (!(trace_flags & TRACE_ITER_BLOCK) && !runqueue_is_locked())
147 wake_up(&trace_wait);
150 #define ENTRIES_PER_PAGE (PAGE_SIZE / sizeof(struct trace_entry))
152 static int __init set_nr_entries(char *str)
154 unsigned long nr_entries;
159 ret = strict_strtoul(str, 0, &nr_entries);
160 /* nr_entries can not be zero */
161 if (ret < 0 || nr_entries == 0)
163 trace_nr_entries = nr_entries;
166 __setup("trace_entries=", set_nr_entries);
168 unsigned long nsecs_to_usecs(unsigned long nsecs)
174 * trace_flag_type is an enumeration that holds different
175 * states when a trace occurs. These are:
176 * IRQS_OFF - interrupts were disabled
177 * NEED_RESCED - reschedule is requested
178 * HARDIRQ - inside an interrupt handler
179 * SOFTIRQ - inside a softirq handler
181 enum trace_flag_type {
182 TRACE_FLAG_IRQS_OFF = 0x01,
183 TRACE_FLAG_NEED_RESCHED = 0x02,
184 TRACE_FLAG_HARDIRQ = 0x04,
185 TRACE_FLAG_SOFTIRQ = 0x08,
189 * TRACE_ITER_SYM_MASK masks the options in trace_flags that
190 * control the output of kernel symbols.
192 #define TRACE_ITER_SYM_MASK \
193 (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
195 /* These must match the bit postions in trace_iterator_flags */
196 static const char *trace_options[] = {
211 * ftrace_max_lock is used to protect the swapping of buffers
212 * when taking a max snapshot. The buffers themselves are
213 * protected by per_cpu spinlocks. But the action of the swap
214 * needs its own lock.
216 * This is defined as a raw_spinlock_t in order to help
217 * with performance when lockdep debugging is enabled.
219 static raw_spinlock_t ftrace_max_lock =
220 (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED;
223 * Copy the new maximum trace into the separate maximum-trace
224 * structure. (this way the maximum trace is permanently saved,
225 * for later retrieval via /debugfs/tracing/latency_trace)
228 __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
230 struct trace_array_cpu *data = tr->data[cpu];
233 max_tr.time_start = data->preempt_timestamp;
235 data = max_tr.data[cpu];
236 data->saved_latency = tracing_max_latency;
238 memcpy(data->comm, tsk->comm, TASK_COMM_LEN);
239 data->pid = tsk->pid;
240 data->uid = tsk->uid;
241 data->nice = tsk->static_prio - 20 - MAX_RT_PRIO;
242 data->policy = tsk->policy;
243 data->rt_priority = tsk->rt_priority;
245 /* record this tasks comm */
246 tracing_record_cmdline(current);
250 * check_pages - integrity check of trace buffers
252 * As a safty measure we check to make sure the data pages have not
253 * been corrupted. TODO: configure to disable this because it adds
256 void check_pages(struct trace_array_cpu *data)
258 struct page *page, *tmp;
260 BUG_ON(data->trace_pages.next->prev != &data->trace_pages);
261 BUG_ON(data->trace_pages.prev->next != &data->trace_pages);
263 list_for_each_entry_safe(page, tmp, &data->trace_pages, lru) {
264 BUG_ON(page->lru.next->prev != &page->lru);
265 BUG_ON(page->lru.prev->next != &page->lru);
270 * head_page - page address of the first page in per_cpu buffer.
272 * head_page returns the page address of the first page in
273 * a per_cpu buffer. This also preforms various consistency
274 * checks to make sure the buffer has not been corrupted.
276 void *head_page(struct trace_array_cpu *data)
281 if (list_empty(&data->trace_pages))
284 page = list_entry(data->trace_pages.next, struct page, lru);
285 BUG_ON(&page->lru == &data->trace_pages);
287 return page_address(page);
291 * trace_seq_printf - sequence printing of trace information
292 * @s: trace sequence descriptor
293 * @fmt: printf format string
295 * The tracer may use either sequence operations or its own
296 * copy to user routines. To simplify formating of a trace
297 * trace_seq_printf is used to store strings into a special
298 * buffer (@s). Then the output may be either used by
299 * the sequencer or pulled into another buffer.
302 trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
304 int len = (PAGE_SIZE - 1) - s->len;
312 ret = vsnprintf(s->buffer + s->len, len, fmt, ap);
315 /* If we can't write it all, don't bother writing anything */
325 * trace_seq_puts - trace sequence printing of simple string
326 * @s: trace sequence descriptor
327 * @str: simple string to record
329 * The tracer may use either the sequence operations or its own
330 * copy to user routines. This function records a simple string
331 * into a special buffer (@s) for later retrieval by a sequencer
332 * or other mechanism.
335 trace_seq_puts(struct trace_seq *s, const char *str)
337 int len = strlen(str);
339 if (len > ((PAGE_SIZE - 1) - s->len))
342 memcpy(s->buffer + s->len, str, len);
349 trace_seq_putc(struct trace_seq *s, unsigned char c)
351 if (s->len >= (PAGE_SIZE - 1))
354 s->buffer[s->len++] = c;
360 trace_seq_putmem(struct trace_seq *s, void *mem, size_t len)
362 if (len > ((PAGE_SIZE - 1) - s->len))
365 memcpy(s->buffer + s->len, mem, len);
372 static const char hex2asc[] = "0123456789abcdef";
375 trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len)
377 unsigned char hex[HEX_CHARS];
378 unsigned char *data = mem;
382 BUG_ON(len >= HEX_CHARS);
385 for (i = 0, j = 0; i < len; i++) {
387 for (i = len-1, j = 0; i >= 0; i--) {
391 hex[j++] = hex2asc[byte & 0x0f];
392 hex[j++] = hex2asc[byte >> 4];
396 return trace_seq_putmem(s, hex, j);
400 trace_seq_reset(struct trace_seq *s)
406 trace_print_seq(struct seq_file *m, struct trace_seq *s)
408 int len = s->len >= PAGE_SIZE ? PAGE_SIZE - 1 : s->len;
411 seq_puts(m, s->buffer);
417 * flip the trace buffers between two trace descriptors.
418 * This usually is the buffers between the global_trace and
419 * the max_tr to record a snapshot of a current trace.
421 * The ftrace_max_lock must be held.
424 flip_trace(struct trace_array_cpu *tr1, struct trace_array_cpu *tr2)
426 struct list_head flip_pages;
428 INIT_LIST_HEAD(&flip_pages);
430 memcpy(&tr1->trace_head_idx, &tr2->trace_head_idx,
431 sizeof(struct trace_array_cpu) -
432 offsetof(struct trace_array_cpu, trace_head_idx));
436 list_splice_init(&tr1->trace_pages, &flip_pages);
437 list_splice_init(&tr2->trace_pages, &tr1->trace_pages);
438 list_splice_init(&flip_pages, &tr2->trace_pages);
439 BUG_ON(!list_empty(&flip_pages));
445 * update_max_tr - snapshot all trace buffers from global_trace to max_tr
447 * @tsk: the task with the latency
448 * @cpu: The cpu that initiated the trace.
450 * Flip the buffers between the @tr and the max_tr and record information
451 * about which task was the cause of this latency.
454 update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
456 struct trace_array_cpu *data;
459 WARN_ON_ONCE(!irqs_disabled());
460 __raw_spin_lock(&ftrace_max_lock);
461 /* clear out all the previous traces */
462 for_each_tracing_cpu(i) {
464 flip_trace(max_tr.data[i], data);
468 __update_max_tr(tr, tsk, cpu);
469 __raw_spin_unlock(&ftrace_max_lock);
473 * update_max_tr_single - only copy one trace over, and reset the rest
475 * @tsk - task with the latency
476 * @cpu - the cpu of the buffer to copy.
478 * Flip the trace of a single CPU buffer between the @tr and the max_tr.
481 update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu)
483 struct trace_array_cpu *data = tr->data[cpu];
486 WARN_ON_ONCE(!irqs_disabled());
487 __raw_spin_lock(&ftrace_max_lock);
488 for_each_tracing_cpu(i)
489 tracing_reset(max_tr.data[i]);
491 flip_trace(max_tr.data[cpu], data);
494 __update_max_tr(tr, tsk, cpu);
495 __raw_spin_unlock(&ftrace_max_lock);
499 * register_tracer - register a tracer with the ftrace system.
500 * @type - the plugin for the tracer
502 * Register a new plugin tracer.
504 int register_tracer(struct tracer *type)
511 pr_info("Tracer must have a name\n");
515 mutex_lock(&trace_types_lock);
516 for (t = trace_types; t; t = t->next) {
517 if (strcmp(type->name, t->name) == 0) {
519 pr_info("Trace %s already registered\n",
526 #ifdef CONFIG_FTRACE_STARTUP_TEST
527 if (type->selftest) {
528 struct tracer *saved_tracer = current_trace;
529 struct trace_array_cpu *data;
530 struct trace_array *tr = &global_trace;
531 int saved_ctrl = tr->ctrl;
534 * Run a selftest on this tracer.
535 * Here we reset the trace buffer, and set the current
536 * tracer to be this tracer. The tracer can then run some
537 * internal tracing to verify that everything is in order.
538 * If we fail, we do not register this tracer.
540 for_each_tracing_cpu(i) {
542 if (!head_page(data))
546 current_trace = type;
548 /* the test is responsible for initializing and enabling */
549 pr_info("Testing tracer %s: ", type->name);
550 ret = type->selftest(type, tr);
551 /* the test is responsible for resetting too */
552 current_trace = saved_tracer;
553 tr->ctrl = saved_ctrl;
555 printk(KERN_CONT "FAILED!\n");
558 /* Only reset on passing, to avoid touching corrupted buffers */
559 for_each_tracing_cpu(i) {
561 if (!head_page(data))
565 printk(KERN_CONT "PASSED\n");
569 type->next = trace_types;
571 len = strlen(type->name);
572 if (len > max_tracer_type_len)
573 max_tracer_type_len = len;
576 mutex_unlock(&trace_types_lock);
581 void unregister_tracer(struct tracer *type)
586 mutex_lock(&trace_types_lock);
587 for (t = &trace_types; *t; t = &(*t)->next) {
591 pr_info("Trace %s not registered\n", type->name);
596 if (strlen(type->name) != max_tracer_type_len)
599 max_tracer_type_len = 0;
600 for (t = &trace_types; *t; t = &(*t)->next) {
601 len = strlen((*t)->name);
602 if (len > max_tracer_type_len)
603 max_tracer_type_len = len;
606 mutex_unlock(&trace_types_lock);
609 void tracing_reset(struct trace_array_cpu *data)
613 data->trace_head = data->trace_tail = head_page(data);
614 data->trace_head_idx = 0;
615 data->trace_tail_idx = 0;
618 #define SAVED_CMDLINES 128
619 static unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
620 static unsigned map_cmdline_to_pid[SAVED_CMDLINES];
621 static char saved_cmdlines[SAVED_CMDLINES][TASK_COMM_LEN];
622 static int cmdline_idx;
623 static DEFINE_SPINLOCK(trace_cmdline_lock);
625 /* trace in all context switches */
626 atomic_t trace_record_cmdline_enabled __read_mostly;
628 /* temporary disable recording */
629 atomic_t trace_record_cmdline_disabled __read_mostly;
631 static void trace_init_cmdlines(void)
633 memset(&map_pid_to_cmdline, -1, sizeof(map_pid_to_cmdline));
634 memset(&map_cmdline_to_pid, -1, sizeof(map_cmdline_to_pid));
638 void trace_stop_cmdline_recording(void);
640 static void trace_save_cmdline(struct task_struct *tsk)
645 if (!tsk->pid || unlikely(tsk->pid > PID_MAX_DEFAULT))
649 * It's not the end of the world if we don't get
650 * the lock, but we also don't want to spin
651 * nor do we want to disable interrupts,
652 * so if we miss here, then better luck next time.
654 if (!spin_trylock(&trace_cmdline_lock))
657 idx = map_pid_to_cmdline[tsk->pid];
658 if (idx >= SAVED_CMDLINES) {
659 idx = (cmdline_idx + 1) % SAVED_CMDLINES;
661 map = map_cmdline_to_pid[idx];
662 if (map <= PID_MAX_DEFAULT)
663 map_pid_to_cmdline[map] = (unsigned)-1;
665 map_pid_to_cmdline[tsk->pid] = idx;
670 memcpy(&saved_cmdlines[idx], tsk->comm, TASK_COMM_LEN);
672 spin_unlock(&trace_cmdline_lock);
675 static char *trace_find_cmdline(int pid)
677 char *cmdline = "<...>";
683 if (pid > PID_MAX_DEFAULT)
686 map = map_pid_to_cmdline[pid];
687 if (map >= SAVED_CMDLINES)
690 cmdline = saved_cmdlines[map];
696 void tracing_record_cmdline(struct task_struct *tsk)
698 if (atomic_read(&trace_record_cmdline_disabled))
701 trace_save_cmdline(tsk);
704 static inline struct list_head *
705 trace_next_list(struct trace_array_cpu *data, struct list_head *next)
708 * Roundrobin - but skip the head (which is not a real page):
711 if (unlikely(next == &data->trace_pages))
713 BUG_ON(next == &data->trace_pages);
719 trace_next_page(struct trace_array_cpu *data, void *addr)
721 struct list_head *next;
724 page = virt_to_page(addr);
726 next = trace_next_list(data, &page->lru);
727 page = list_entry(next, struct page, lru);
729 return page_address(page);
732 static inline struct trace_entry *
733 tracing_get_trace_entry(struct trace_array *tr, struct trace_array_cpu *data)
735 unsigned long idx, idx_next;
736 struct trace_entry *entry;
739 idx = data->trace_head_idx;
742 BUG_ON(idx * TRACE_ENTRY_SIZE >= PAGE_SIZE);
744 entry = data->trace_head + idx * TRACE_ENTRY_SIZE;
746 if (unlikely(idx_next >= ENTRIES_PER_PAGE)) {
747 data->trace_head = trace_next_page(data, data->trace_head);
751 if (data->trace_head == data->trace_tail &&
752 idx_next == data->trace_tail_idx) {
755 data->trace_tail_idx++;
756 if (data->trace_tail_idx >= ENTRIES_PER_PAGE) {
758 trace_next_page(data, data->trace_tail);
759 data->trace_tail_idx = 0;
763 data->trace_head_idx = idx_next;
769 tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags)
771 struct task_struct *tsk = current;
774 pc = preempt_count();
776 entry->preempt_count = pc & 0xff;
777 entry->pid = (tsk) ? tsk->pid : 0;
778 entry->t = ftrace_now(raw_smp_processor_id());
779 entry->flags = (irqs_disabled_flags(flags) ? TRACE_FLAG_IRQS_OFF : 0) |
780 ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) |
781 ((pc & SOFTIRQ_MASK) ? TRACE_FLAG_SOFTIRQ : 0) |
782 (need_resched() ? TRACE_FLAG_NEED_RESCHED : 0);
786 trace_function(struct trace_array *tr, struct trace_array_cpu *data,
787 unsigned long ip, unsigned long parent_ip, unsigned long flags)
789 struct trace_entry *entry;
790 unsigned long irq_flags;
792 raw_local_irq_save(irq_flags);
793 __raw_spin_lock(&data->lock);
794 entry = tracing_get_trace_entry(tr, data);
795 tracing_generic_entry_update(entry, flags);
796 entry->type = TRACE_FN;
798 entry->fn.parent_ip = parent_ip;
799 __raw_spin_unlock(&data->lock);
800 raw_local_irq_restore(irq_flags);
804 ftrace(struct trace_array *tr, struct trace_array_cpu *data,
805 unsigned long ip, unsigned long parent_ip, unsigned long flags)
807 if (likely(!atomic_read(&data->disabled)))
808 trace_function(tr, data, ip, parent_ip, flags);
811 void __trace_stack(struct trace_array *tr,
812 struct trace_array_cpu *data,
816 struct trace_entry *entry;
817 struct stack_trace trace;
819 if (!(trace_flags & TRACE_ITER_STACKTRACE))
822 entry = tracing_get_trace_entry(tr, data);
823 tracing_generic_entry_update(entry, flags);
824 entry->type = TRACE_STACK;
826 memset(&entry->stack, 0, sizeof(entry->stack));
828 trace.nr_entries = 0;
829 trace.max_entries = FTRACE_STACK_ENTRIES;
831 trace.entries = entry->stack.caller;
833 save_stack_trace(&trace);
837 __trace_special(void *__tr, void *__data,
838 unsigned long arg1, unsigned long arg2, unsigned long arg3)
840 struct trace_array_cpu *data = __data;
841 struct trace_array *tr = __tr;
842 struct trace_entry *entry;
843 unsigned long irq_flags;
845 raw_local_irq_save(irq_flags);
846 __raw_spin_lock(&data->lock);
847 entry = tracing_get_trace_entry(tr, data);
848 tracing_generic_entry_update(entry, 0);
849 entry->type = TRACE_SPECIAL;
850 entry->special.arg1 = arg1;
851 entry->special.arg2 = arg2;
852 entry->special.arg3 = arg3;
853 __trace_stack(tr, data, irq_flags, 4);
854 __raw_spin_unlock(&data->lock);
855 raw_local_irq_restore(irq_flags);
861 tracing_sched_switch_trace(struct trace_array *tr,
862 struct trace_array_cpu *data,
863 struct task_struct *prev,
864 struct task_struct *next,
867 struct trace_entry *entry;
868 unsigned long irq_flags;
870 raw_local_irq_save(irq_flags);
871 __raw_spin_lock(&data->lock);
872 entry = tracing_get_trace_entry(tr, data);
873 tracing_generic_entry_update(entry, flags);
874 entry->type = TRACE_CTX;
875 entry->ctx.prev_pid = prev->pid;
876 entry->ctx.prev_prio = prev->prio;
877 entry->ctx.prev_state = prev->state;
878 entry->ctx.next_pid = next->pid;
879 entry->ctx.next_prio = next->prio;
880 entry->ctx.next_state = next->state;
881 __trace_stack(tr, data, flags, 4);
882 __raw_spin_unlock(&data->lock);
883 raw_local_irq_restore(irq_flags);
887 tracing_sched_wakeup_trace(struct trace_array *tr,
888 struct trace_array_cpu *data,
889 struct task_struct *wakee,
890 struct task_struct *curr,
893 struct trace_entry *entry;
894 unsigned long irq_flags;
896 raw_local_irq_save(irq_flags);
897 __raw_spin_lock(&data->lock);
898 entry = tracing_get_trace_entry(tr, data);
899 tracing_generic_entry_update(entry, flags);
900 entry->type = TRACE_WAKE;
901 entry->ctx.prev_pid = curr->pid;
902 entry->ctx.prev_prio = curr->prio;
903 entry->ctx.prev_state = curr->state;
904 entry->ctx.next_pid = wakee->pid;
905 entry->ctx.next_prio = wakee->prio;
906 entry->ctx.next_state = wakee->state;
907 __trace_stack(tr, data, flags, 5);
908 __raw_spin_unlock(&data->lock);
909 raw_local_irq_restore(irq_flags);
916 function_trace_call(unsigned long ip, unsigned long parent_ip)
918 struct trace_array *tr = &global_trace;
919 struct trace_array_cpu *data;
924 if (unlikely(!tracer_enabled))
927 local_irq_save(flags);
928 cpu = raw_smp_processor_id();
929 data = tr->data[cpu];
930 disabled = atomic_inc_return(&data->disabled);
932 if (likely(disabled == 1))
933 trace_function(tr, data, ip, parent_ip, flags);
935 atomic_dec(&data->disabled);
936 local_irq_restore(flags);
939 static struct ftrace_ops trace_ops __read_mostly =
941 .func = function_trace_call,
944 void tracing_start_function_trace(void)
946 register_ftrace_function(&trace_ops);
949 void tracing_stop_function_trace(void)
951 unregister_ftrace_function(&trace_ops);
955 enum trace_file_type {
956 TRACE_FILE_LAT_FMT = 1,
959 static struct trace_entry *
960 trace_entry_idx(struct trace_array *tr, struct trace_array_cpu *data,
961 struct trace_iterator *iter, int cpu)
964 struct trace_entry *array;
966 if (iter->next_idx[cpu] >= tr->entries ||
967 iter->next_idx[cpu] >= data->trace_idx ||
968 (data->trace_head == data->trace_tail &&
969 data->trace_head_idx == data->trace_tail_idx))
972 if (!iter->next_page[cpu]) {
973 /* Initialize the iterator for this cpu trace buffer */
974 WARN_ON(!data->trace_tail);
975 page = virt_to_page(data->trace_tail);
976 iter->next_page[cpu] = &page->lru;
977 iter->next_page_idx[cpu] = data->trace_tail_idx;
980 page = list_entry(iter->next_page[cpu], struct page, lru);
981 BUG_ON(&data->trace_pages == &page->lru);
983 array = page_address(page);
985 WARN_ON(iter->next_page_idx[cpu] >= ENTRIES_PER_PAGE);
986 return &array[iter->next_page_idx[cpu]];
989 static struct trace_entry *
990 find_next_entry(struct trace_iterator *iter, int *ent_cpu)
992 struct trace_array *tr = iter->tr;
993 struct trace_entry *ent, *next = NULL;
997 for_each_tracing_cpu(cpu) {
998 if (!head_page(tr->data[cpu]))
1000 ent = trace_entry_idx(tr, tr->data[cpu], iter, cpu);
1002 * Pick the entry with the smallest timestamp:
1004 if (ent && (!next || ent->t < next->t)) {
1011 *ent_cpu = next_cpu;
1016 static void trace_iterator_increment(struct trace_iterator *iter)
1019 iter->next_idx[iter->cpu]++;
1020 iter->next_page_idx[iter->cpu]++;
1022 if (iter->next_page_idx[iter->cpu] >= ENTRIES_PER_PAGE) {
1023 struct trace_array_cpu *data = iter->tr->data[iter->cpu];
1025 iter->next_page_idx[iter->cpu] = 0;
1026 iter->next_page[iter->cpu] =
1027 trace_next_list(data, iter->next_page[iter->cpu]);
1031 static void trace_consume(struct trace_iterator *iter)
1033 struct trace_array_cpu *data = iter->tr->data[iter->cpu];
1035 data->trace_tail_idx++;
1036 if (data->trace_tail_idx >= ENTRIES_PER_PAGE) {
1037 data->trace_tail = trace_next_page(data, data->trace_tail);
1038 data->trace_tail_idx = 0;
1041 /* Check if we empty it, then reset the index */
1042 if (data->trace_head == data->trace_tail &&
1043 data->trace_head_idx == data->trace_tail_idx)
1044 data->trace_idx = 0;
1047 static void *find_next_entry_inc(struct trace_iterator *iter)
1049 struct trace_entry *next;
1052 next = find_next_entry(iter, &next_cpu);
1054 iter->prev_ent = iter->ent;
1055 iter->prev_cpu = iter->cpu;
1058 iter->cpu = next_cpu;
1061 trace_iterator_increment(iter);
1063 return next ? iter : NULL;
1066 static void *s_next(struct seq_file *m, void *v, loff_t *pos)
1068 struct trace_iterator *iter = m->private;
1069 void *last_ent = iter->ent;
1075 /* can't go backwards */
1080 ent = find_next_entry_inc(iter);
1084 while (ent && iter->idx < i)
1085 ent = find_next_entry_inc(iter);
1089 if (last_ent && !ent)
1090 seq_puts(m, "\n\nvim:ft=help\n");
1095 static void *s_start(struct seq_file *m, loff_t *pos)
1097 struct trace_iterator *iter = m->private;
1102 mutex_lock(&trace_types_lock);
1104 if (!current_trace || current_trace != iter->trace) {
1105 mutex_unlock(&trace_types_lock);
1109 atomic_inc(&trace_record_cmdline_disabled);
1111 /* let the tracer grab locks here if needed */
1112 if (current_trace->start)
1113 current_trace->start(iter);
1115 if (*pos != iter->pos) {
1119 iter->prev_ent = NULL;
1120 iter->prev_cpu = -1;
1122 for_each_tracing_cpu(i) {
1123 iter->next_idx[i] = 0;
1124 iter->next_page[i] = NULL;
1127 for (p = iter; p && l < *pos; p = s_next(m, p, &l))
1132 p = s_next(m, p, &l);
1138 static void s_stop(struct seq_file *m, void *p)
1140 struct trace_iterator *iter = m->private;
1142 atomic_dec(&trace_record_cmdline_disabled);
1144 /* let the tracer release locks here if needed */
1145 if (current_trace && current_trace == iter->trace && iter->trace->stop)
1146 iter->trace->stop(iter);
1148 mutex_unlock(&trace_types_lock);
1152 seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
1154 #ifdef CONFIG_KALLSYMS
1155 char str[KSYM_SYMBOL_LEN];
1157 kallsyms_lookup(address, NULL, NULL, NULL, str);
1159 return trace_seq_printf(s, fmt, str);
1165 seq_print_sym_offset(struct trace_seq *s, const char *fmt,
1166 unsigned long address)
1168 #ifdef CONFIG_KALLSYMS
1169 char str[KSYM_SYMBOL_LEN];
1171 sprint_symbol(str, address);
1172 return trace_seq_printf(s, fmt, str);
1177 #ifndef CONFIG_64BIT
1178 # define IP_FMT "%08lx"
1180 # define IP_FMT "%016lx"
1184 seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
1189 return trace_seq_printf(s, "0");
1191 if (sym_flags & TRACE_ITER_SYM_OFFSET)
1192 ret = seq_print_sym_offset(s, "%s", ip);
1194 ret = seq_print_sym_short(s, "%s", ip);
1199 if (sym_flags & TRACE_ITER_SYM_ADDR)
1200 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
1204 static void print_lat_help_header(struct seq_file *m)
1206 seq_puts(m, "# _------=> CPU# \n");
1207 seq_puts(m, "# / _-----=> irqs-off \n");
1208 seq_puts(m, "# | / _----=> need-resched \n");
1209 seq_puts(m, "# || / _---=> hardirq/softirq \n");
1210 seq_puts(m, "# ||| / _--=> preempt-depth \n");
1211 seq_puts(m, "# |||| / \n");
1212 seq_puts(m, "# ||||| delay \n");
1213 seq_puts(m, "# cmd pid ||||| time | caller \n");
1214 seq_puts(m, "# \\ / ||||| \\ | / \n");
1217 static void print_func_help_header(struct seq_file *m)
1219 seq_puts(m, "# TASK-PID CPU# TIMESTAMP FUNCTION\n");
1220 seq_puts(m, "# | | | | |\n");
1225 print_trace_header(struct seq_file *m, struct trace_iterator *iter)
1227 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
1228 struct trace_array *tr = iter->tr;
1229 struct trace_array_cpu *data = tr->data[tr->cpu];
1230 struct tracer *type = current_trace;
1231 unsigned long total = 0;
1232 unsigned long entries = 0;
1234 const char *name = "preemption";
1239 for_each_tracing_cpu(cpu) {
1240 if (head_page(tr->data[cpu])) {
1241 total += tr->data[cpu]->trace_idx;
1242 if (tr->data[cpu]->trace_idx > tr->entries)
1243 entries += tr->entries;
1245 entries += tr->data[cpu]->trace_idx;
1249 seq_printf(m, "%s latency trace v1.1.5 on %s\n",
1251 seq_puts(m, "-----------------------------------"
1252 "---------------------------------\n");
1253 seq_printf(m, " latency: %lu us, #%lu/%lu, CPU#%d |"
1254 " (M:%s VP:%d, KP:%d, SP:%d HP:%d",
1255 nsecs_to_usecs(data->saved_latency),
1259 #if defined(CONFIG_PREEMPT_NONE)
1261 #elif defined(CONFIG_PREEMPT_VOLUNTARY)
1263 #elif defined(CONFIG_PREEMPT_DESKTOP)
1268 /* These are reserved for later use */
1271 seq_printf(m, " #P:%d)\n", num_online_cpus());
1275 seq_puts(m, " -----------------\n");
1276 seq_printf(m, " | task: %.16s-%d "
1277 "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n",
1278 data->comm, data->pid, data->uid, data->nice,
1279 data->policy, data->rt_priority);
1280 seq_puts(m, " -----------------\n");
1282 if (data->critical_start) {
1283 seq_puts(m, " => started at: ");
1284 seq_print_ip_sym(&iter->seq, data->critical_start, sym_flags);
1285 trace_print_seq(m, &iter->seq);
1286 seq_puts(m, "\n => ended at: ");
1287 seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags);
1288 trace_print_seq(m, &iter->seq);
1296 lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
1298 int hardirq, softirq;
1301 comm = trace_find_cmdline(entry->pid);
1303 trace_seq_printf(s, "%8.8s-%-5d ", comm, entry->pid);
1304 trace_seq_printf(s, "%d", cpu);
1305 trace_seq_printf(s, "%c%c",
1306 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' : '.',
1307 ((entry->flags & TRACE_FLAG_NEED_RESCHED) ? 'N' : '.'));
1309 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
1310 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
1311 if (hardirq && softirq) {
1312 trace_seq_putc(s, 'H');
1315 trace_seq_putc(s, 'h');
1318 trace_seq_putc(s, 's');
1320 trace_seq_putc(s, '.');
1324 if (entry->preempt_count)
1325 trace_seq_printf(s, "%x", entry->preempt_count);
1327 trace_seq_puts(s, ".");
1330 unsigned long preempt_mark_thresh = 100;
1333 lat_print_timestamp(struct trace_seq *s, unsigned long long abs_usecs,
1334 unsigned long rel_usecs)
1336 trace_seq_printf(s, " %4lldus", abs_usecs);
1337 if (rel_usecs > preempt_mark_thresh)
1338 trace_seq_puts(s, "!: ");
1339 else if (rel_usecs > 1)
1340 trace_seq_puts(s, "+: ");
1342 trace_seq_puts(s, " : ");
1345 static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
1348 print_lat_fmt(struct trace_iterator *iter, unsigned int trace_idx, int cpu)
1350 struct trace_seq *s = &iter->seq;
1351 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
1352 struct trace_entry *next_entry = find_next_entry(iter, NULL);
1353 unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
1354 struct trace_entry *entry = iter->ent;
1355 unsigned long abs_usecs;
1356 unsigned long rel_usecs;
1364 rel_usecs = ns2usecs(next_entry->t - entry->t);
1365 abs_usecs = ns2usecs(entry->t - iter->tr->time_start);
1368 comm = trace_find_cmdline(entry->pid);
1369 trace_seq_printf(s, "%16s %5d %d %d %08x %08x [%08lx]"
1370 " %ld.%03ldms (+%ld.%03ldms): ",
1372 entry->pid, cpu, entry->flags,
1373 entry->preempt_count, trace_idx,
1376 abs_usecs % 1000, rel_usecs/1000,
1379 lat_print_generic(s, entry, cpu);
1380 lat_print_timestamp(s, abs_usecs, rel_usecs);
1382 switch (entry->type) {
1384 seq_print_ip_sym(s, entry->fn.ip, sym_flags);
1385 trace_seq_puts(s, " (");
1386 seq_print_ip_sym(s, entry->fn.parent_ip, sym_flags);
1387 trace_seq_puts(s, ")\n");
1391 T = entry->ctx.next_state < sizeof(state_to_char) ?
1392 state_to_char[entry->ctx.next_state] : 'X';
1394 state = entry->ctx.prev_state ? __ffs(entry->ctx.prev_state) + 1 : 0;
1395 S = state < sizeof(state_to_char) - 1 ? state_to_char[state] : 'X';
1396 comm = trace_find_cmdline(entry->ctx.next_pid);
1397 trace_seq_printf(s, " %5d:%3d:%c %s %5d:%3d:%c %s\n",
1398 entry->ctx.prev_pid,
1399 entry->ctx.prev_prio,
1400 S, entry->type == TRACE_CTX ? "==>" : " +",
1401 entry->ctx.next_pid,
1402 entry->ctx.next_prio,
1406 trace_seq_printf(s, "# %ld %ld %ld\n",
1407 entry->special.arg1,
1408 entry->special.arg2,
1409 entry->special.arg3);
1412 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
1414 trace_seq_puts(s, " <= ");
1415 seq_print_ip_sym(s, entry->stack.caller[i], sym_flags);
1417 trace_seq_puts(s, "\n");
1420 trace_seq_printf(s, "Unknown type %d\n", entry->type);
1425 static int print_trace_fmt(struct trace_iterator *iter)
1427 struct trace_seq *s = &iter->seq;
1428 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
1429 struct trace_entry *entry;
1430 unsigned long usec_rem;
1431 unsigned long long t;
1440 comm = trace_find_cmdline(iter->ent->pid);
1442 t = ns2usecs(entry->t);
1443 usec_rem = do_div(t, 1000000ULL);
1444 secs = (unsigned long)t;
1446 ret = trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid);
1449 ret = trace_seq_printf(s, "[%02d] ", iter->cpu);
1452 ret = trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem);
1456 switch (entry->type) {
1458 ret = seq_print_ip_sym(s, entry->fn.ip, sym_flags);
1461 if ((sym_flags & TRACE_ITER_PRINT_PARENT) &&
1462 entry->fn.parent_ip) {
1463 ret = trace_seq_printf(s, " <-");
1466 ret = seq_print_ip_sym(s, entry->fn.parent_ip,
1471 ret = trace_seq_printf(s, "\n");
1477 S = entry->ctx.prev_state < sizeof(state_to_char) ?
1478 state_to_char[entry->ctx.prev_state] : 'X';
1479 T = entry->ctx.next_state < sizeof(state_to_char) ?
1480 state_to_char[entry->ctx.next_state] : 'X';
1481 ret = trace_seq_printf(s, " %5d:%3d:%c %s %5d:%3d:%c\n",
1482 entry->ctx.prev_pid,
1483 entry->ctx.prev_prio,
1485 entry->type == TRACE_CTX ? "==>" : " +",
1486 entry->ctx.next_pid,
1487 entry->ctx.next_prio,
1493 ret = trace_seq_printf(s, "# %ld %ld %ld\n",
1494 entry->special.arg1,
1495 entry->special.arg2,
1496 entry->special.arg3);
1501 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
1503 ret = trace_seq_puts(s, " <= ");
1507 ret = seq_print_ip_sym(s, entry->stack.caller[i],
1512 ret = trace_seq_puts(s, "\n");
1520 static int print_raw_fmt(struct trace_iterator *iter)
1522 struct trace_seq *s = &iter->seq;
1523 struct trace_entry *entry;
1529 ret = trace_seq_printf(s, "%d %d %llu ",
1530 entry->pid, iter->cpu, entry->t);
1534 switch (entry->type) {
1536 ret = trace_seq_printf(s, "%x %x\n",
1537 entry->fn.ip, entry->fn.parent_ip);
1543 S = entry->ctx.prev_state < sizeof(state_to_char) ?
1544 state_to_char[entry->ctx.prev_state] : 'X';
1545 T = entry->ctx.next_state < sizeof(state_to_char) ?
1546 state_to_char[entry->ctx.next_state] : 'X';
1547 if (entry->type == TRACE_WAKE)
1549 ret = trace_seq_printf(s, "%d %d %c %d %d %c\n",
1550 entry->ctx.prev_pid,
1551 entry->ctx.prev_prio,
1553 entry->ctx.next_pid,
1554 entry->ctx.next_prio,
1561 ret = trace_seq_printf(s, "# %ld %ld %ld\n",
1562 entry->special.arg1,
1563 entry->special.arg2,
1564 entry->special.arg3);
1572 #define SEQ_PUT_FIELD_RET(s, x) \
1574 if (!trace_seq_putmem(s, &(x), sizeof(x))) \
1578 #define SEQ_PUT_HEX_FIELD_RET(s, x) \
1580 if (!trace_seq_putmem_hex(s, &(x), sizeof(x))) \
1584 static int print_hex_fmt(struct trace_iterator *iter)
1586 struct trace_seq *s = &iter->seq;
1587 unsigned char newline = '\n';
1588 struct trace_entry *entry;
1593 SEQ_PUT_HEX_FIELD_RET(s, entry->pid);
1594 SEQ_PUT_HEX_FIELD_RET(s, iter->cpu);
1595 SEQ_PUT_HEX_FIELD_RET(s, entry->t);
1597 switch (entry->type) {
1599 SEQ_PUT_HEX_FIELD_RET(s, entry->fn.ip);
1600 SEQ_PUT_HEX_FIELD_RET(s, entry->fn.parent_ip);
1604 S = entry->ctx.prev_state < sizeof(state_to_char) ?
1605 state_to_char[entry->ctx.prev_state] : 'X';
1606 T = entry->ctx.next_state < sizeof(state_to_char) ?
1607 state_to_char[entry->ctx.next_state] : 'X';
1608 if (entry->type == TRACE_WAKE)
1610 SEQ_PUT_HEX_FIELD_RET(s, entry->ctx.prev_pid);
1611 SEQ_PUT_HEX_FIELD_RET(s, entry->ctx.prev_prio);
1612 SEQ_PUT_HEX_FIELD_RET(s, S);
1613 SEQ_PUT_HEX_FIELD_RET(s, entry->ctx.next_pid);
1614 SEQ_PUT_HEX_FIELD_RET(s, entry->ctx.next_prio);
1615 SEQ_PUT_HEX_FIELD_RET(s, entry->fn.parent_ip);
1616 SEQ_PUT_HEX_FIELD_RET(s, T);
1620 SEQ_PUT_HEX_FIELD_RET(s, entry->special.arg1);
1621 SEQ_PUT_HEX_FIELD_RET(s, entry->special.arg2);
1622 SEQ_PUT_HEX_FIELD_RET(s, entry->special.arg3);
1625 SEQ_PUT_FIELD_RET(s, newline);
1630 static int print_bin_fmt(struct trace_iterator *iter)
1632 struct trace_seq *s = &iter->seq;
1633 struct trace_entry *entry;
1637 SEQ_PUT_FIELD_RET(s, entry->pid);
1638 SEQ_PUT_FIELD_RET(s, entry->cpu);
1639 SEQ_PUT_FIELD_RET(s, entry->t);
1641 switch (entry->type) {
1643 SEQ_PUT_FIELD_RET(s, entry->fn.ip);
1644 SEQ_PUT_FIELD_RET(s, entry->fn.parent_ip);
1647 SEQ_PUT_FIELD_RET(s, entry->ctx.prev_pid);
1648 SEQ_PUT_FIELD_RET(s, entry->ctx.prev_prio);
1649 SEQ_PUT_FIELD_RET(s, entry->ctx.prev_state);
1650 SEQ_PUT_FIELD_RET(s, entry->ctx.next_pid);
1651 SEQ_PUT_FIELD_RET(s, entry->ctx.next_prio);
1652 SEQ_PUT_FIELD_RET(s, entry->ctx.next_state);
1656 SEQ_PUT_FIELD_RET(s, entry->special.arg1);
1657 SEQ_PUT_FIELD_RET(s, entry->special.arg2);
1658 SEQ_PUT_FIELD_RET(s, entry->special.arg3);
1664 static int trace_empty(struct trace_iterator *iter)
1666 struct trace_array_cpu *data;
1669 for_each_tracing_cpu(cpu) {
1670 data = iter->tr->data[cpu];
1672 if (head_page(data) && data->trace_idx &&
1673 (data->trace_tail != data->trace_head ||
1674 data->trace_tail_idx != data->trace_head_idx))
1680 static int print_trace_line(struct trace_iterator *iter)
1682 if (iter->trace && iter->trace->print_line)
1683 return iter->trace->print_line(iter);
1685 if (trace_flags & TRACE_ITER_BIN)
1686 return print_bin_fmt(iter);
1688 if (trace_flags & TRACE_ITER_HEX)
1689 return print_hex_fmt(iter);
1691 if (trace_flags & TRACE_ITER_RAW)
1692 return print_raw_fmt(iter);
1694 if (iter->iter_flags & TRACE_FILE_LAT_FMT)
1695 return print_lat_fmt(iter, iter->idx, iter->cpu);
1697 return print_trace_fmt(iter);
1700 static int s_show(struct seq_file *m, void *v)
1702 struct trace_iterator *iter = v;
1704 if (iter->ent == NULL) {
1706 seq_printf(m, "# tracer: %s\n", iter->trace->name);
1709 if (iter->iter_flags & TRACE_FILE_LAT_FMT) {
1710 /* print nothing if the buffers are empty */
1711 if (trace_empty(iter))
1713 print_trace_header(m, iter);
1714 if (!(trace_flags & TRACE_ITER_VERBOSE))
1715 print_lat_help_header(m);
1717 if (!(trace_flags & TRACE_ITER_VERBOSE))
1718 print_func_help_header(m);
1721 print_trace_line(iter);
1722 trace_print_seq(m, &iter->seq);
1728 static struct seq_operations tracer_seq_ops = {
1735 static struct trace_iterator *
1736 __tracing_open(struct inode *inode, struct file *file, int *ret)
1738 struct trace_iterator *iter;
1740 if (tracing_disabled) {
1745 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
1751 mutex_lock(&trace_types_lock);
1752 if (current_trace && current_trace->print_max)
1755 iter->tr = inode->i_private;
1756 iter->trace = current_trace;
1759 /* TODO stop tracer */
1760 *ret = seq_open(file, &tracer_seq_ops);
1762 struct seq_file *m = file->private_data;
1765 /* stop the trace while dumping */
1769 if (iter->trace && iter->trace->open)
1770 iter->trace->open(iter);
1775 mutex_unlock(&trace_types_lock);
1781 int tracing_open_generic(struct inode *inode, struct file *filp)
1783 if (tracing_disabled)
1786 filp->private_data = inode->i_private;
1790 int tracing_release(struct inode *inode, struct file *file)
1792 struct seq_file *m = (struct seq_file *)file->private_data;
1793 struct trace_iterator *iter = m->private;
1795 mutex_lock(&trace_types_lock);
1796 if (iter->trace && iter->trace->close)
1797 iter->trace->close(iter);
1799 /* reenable tracing if it was previously enabled */
1802 mutex_unlock(&trace_types_lock);
1804 seq_release(inode, file);
1809 static int tracing_open(struct inode *inode, struct file *file)
1813 __tracing_open(inode, file, &ret);
1818 static int tracing_lt_open(struct inode *inode, struct file *file)
1820 struct trace_iterator *iter;
1823 iter = __tracing_open(inode, file, &ret);
1826 iter->iter_flags |= TRACE_FILE_LAT_FMT;
1833 t_next(struct seq_file *m, void *v, loff_t *pos)
1835 struct tracer *t = m->private;
1847 static void *t_start(struct seq_file *m, loff_t *pos)
1849 struct tracer *t = m->private;
1852 mutex_lock(&trace_types_lock);
1853 for (; t && l < *pos; t = t_next(m, t, &l))
1859 static void t_stop(struct seq_file *m, void *p)
1861 mutex_unlock(&trace_types_lock);
1864 static int t_show(struct seq_file *m, void *v)
1866 struct tracer *t = v;
1871 seq_printf(m, "%s", t->name);
1880 static struct seq_operations show_traces_seq_ops = {
1887 static int show_traces_open(struct inode *inode, struct file *file)
1891 if (tracing_disabled)
1894 ret = seq_open(file, &show_traces_seq_ops);
1896 struct seq_file *m = file->private_data;
1897 m->private = trace_types;
1903 static struct file_operations tracing_fops = {
1904 .open = tracing_open,
1906 .llseek = seq_lseek,
1907 .release = tracing_release,
1910 static struct file_operations tracing_lt_fops = {
1911 .open = tracing_lt_open,
1913 .llseek = seq_lseek,
1914 .release = tracing_release,
1917 static struct file_operations show_traces_fops = {
1918 .open = show_traces_open,
1920 .release = seq_release,
1924 * Only trace on a CPU if the bitmask is set:
1926 static cpumask_t tracing_cpumask = CPU_MASK_ALL;
1929 * When tracing/tracing_cpu_mask is modified then this holds
1930 * the new bitmask we are about to install:
1932 static cpumask_t tracing_cpumask_new;
1935 * The tracer itself will not take this lock, but still we want
1936 * to provide a consistent cpumask to user-space:
1938 static DEFINE_MUTEX(tracing_cpumask_update_lock);
1941 * Temporary storage for the character representation of the
1942 * CPU bitmask (and one more byte for the newline):
1944 static char mask_str[NR_CPUS + 1];
1947 tracing_cpumask_read(struct file *filp, char __user *ubuf,
1948 size_t count, loff_t *ppos)
1952 mutex_lock(&tracing_cpumask_update_lock);
1954 len = cpumask_scnprintf(mask_str, count, tracing_cpumask);
1955 if (count - len < 2) {
1959 len += sprintf(mask_str + len, "\n");
1960 count = simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+1);
1963 mutex_unlock(&tracing_cpumask_update_lock);
1969 tracing_cpumask_write(struct file *filp, const char __user *ubuf,
1970 size_t count, loff_t *ppos)
1974 mutex_lock(&tracing_cpumask_update_lock);
1975 err = cpumask_parse_user(ubuf, count, tracing_cpumask_new);
1979 raw_local_irq_disable();
1980 __raw_spin_lock(&ftrace_max_lock);
1981 for_each_tracing_cpu(cpu) {
1983 * Increase/decrease the disabled counter if we are
1984 * about to flip a bit in the cpumask:
1986 if (cpu_isset(cpu, tracing_cpumask) &&
1987 !cpu_isset(cpu, tracing_cpumask_new)) {
1988 atomic_inc(&global_trace.data[cpu]->disabled);
1990 if (!cpu_isset(cpu, tracing_cpumask) &&
1991 cpu_isset(cpu, tracing_cpumask_new)) {
1992 atomic_dec(&global_trace.data[cpu]->disabled);
1995 __raw_spin_unlock(&ftrace_max_lock);
1996 raw_local_irq_enable();
1998 tracing_cpumask = tracing_cpumask_new;
2000 mutex_unlock(&tracing_cpumask_update_lock);
2005 mutex_unlock(&tracing_cpumask_update_lock);
2010 static struct file_operations tracing_cpumask_fops = {
2011 .open = tracing_open_generic,
2012 .read = tracing_cpumask_read,
2013 .write = tracing_cpumask_write,
2017 tracing_iter_ctrl_read(struct file *filp, char __user *ubuf,
2018 size_t cnt, loff_t *ppos)
2025 /* calulate max size */
2026 for (i = 0; trace_options[i]; i++) {
2027 len += strlen(trace_options[i]);
2028 len += 3; /* "no" and space */
2031 /* +2 for \n and \0 */
2032 buf = kmalloc(len + 2, GFP_KERNEL);
2036 for (i = 0; trace_options[i]; i++) {
2037 if (trace_flags & (1 << i))
2038 r += sprintf(buf + r, "%s ", trace_options[i]);
2040 r += sprintf(buf + r, "no%s ", trace_options[i]);
2043 r += sprintf(buf + r, "\n");
2044 WARN_ON(r >= len + 2);
2046 r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
2054 tracing_iter_ctrl_write(struct file *filp, const char __user *ubuf,
2055 size_t cnt, loff_t *ppos)
2062 if (cnt >= sizeof(buf))
2065 if (copy_from_user(&buf, ubuf, cnt))
2070 if (strncmp(buf, "no", 2) == 0) {
2075 for (i = 0; trace_options[i]; i++) {
2076 int len = strlen(trace_options[i]);
2078 if (strncmp(cmp, trace_options[i], len) == 0) {
2080 trace_flags &= ~(1 << i);
2082 trace_flags |= (1 << i);
2087 * If no option could be set, return an error:
2089 if (!trace_options[i])
2097 static struct file_operations tracing_iter_fops = {
2098 .open = tracing_open_generic,
2099 .read = tracing_iter_ctrl_read,
2100 .write = tracing_iter_ctrl_write,
2103 static const char readme_msg[] =
2104 "tracing mini-HOWTO:\n\n"
2106 "# mount -t debugfs nodev /debug\n\n"
2107 "# cat /debug/tracing/available_tracers\n"
2108 "wakeup preemptirqsoff preemptoff irqsoff ftrace sched_switch none\n\n"
2109 "# cat /debug/tracing/current_tracer\n"
2111 "# echo sched_switch > /debug/tracing/current_tracer\n"
2112 "# cat /debug/tracing/current_tracer\n"
2114 "# cat /debug/tracing/iter_ctrl\n"
2115 "noprint-parent nosym-offset nosym-addr noverbose\n"
2116 "# echo print-parent > /debug/tracing/iter_ctrl\n"
2117 "# echo 1 > /debug/tracing/tracing_enabled\n"
2118 "# cat /debug/tracing/trace > /tmp/trace.txt\n"
2119 "echo 0 > /debug/tracing/tracing_enabled\n"
2123 tracing_readme_read(struct file *filp, char __user *ubuf,
2124 size_t cnt, loff_t *ppos)
2126 return simple_read_from_buffer(ubuf, cnt, ppos,
2127 readme_msg, strlen(readme_msg));
2130 static struct file_operations tracing_readme_fops = {
2131 .open = tracing_open_generic,
2132 .read = tracing_readme_read,
2136 tracing_ctrl_read(struct file *filp, char __user *ubuf,
2137 size_t cnt, loff_t *ppos)
2139 struct trace_array *tr = filp->private_data;
2143 r = sprintf(buf, "%ld\n", tr->ctrl);
2144 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
2148 tracing_ctrl_write(struct file *filp, const char __user *ubuf,
2149 size_t cnt, loff_t *ppos)
2151 struct trace_array *tr = filp->private_data;
2156 if (cnt >= sizeof(buf))
2159 if (copy_from_user(&buf, ubuf, cnt))
2164 ret = strict_strtoul(buf, 10, &val);
2170 mutex_lock(&trace_types_lock);
2171 if (tr->ctrl ^ val) {
2179 if (current_trace && current_trace->ctrl_update)
2180 current_trace->ctrl_update(tr);
2182 mutex_unlock(&trace_types_lock);
2190 tracing_set_trace_read(struct file *filp, char __user *ubuf,
2191 size_t cnt, loff_t *ppos)
2193 char buf[max_tracer_type_len+2];
2196 mutex_lock(&trace_types_lock);
2198 r = sprintf(buf, "%s\n", current_trace->name);
2200 r = sprintf(buf, "\n");
2201 mutex_unlock(&trace_types_lock);
2203 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
2207 tracing_set_trace_write(struct file *filp, const char __user *ubuf,
2208 size_t cnt, loff_t *ppos)
2210 struct trace_array *tr = &global_trace;
2212 char buf[max_tracer_type_len+1];
2215 if (cnt > max_tracer_type_len)
2216 cnt = max_tracer_type_len;
2218 if (copy_from_user(&buf, ubuf, cnt))
2223 /* strip ending whitespace. */
2224 for (i = cnt - 1; i > 0 && isspace(buf[i]); i--)
2227 mutex_lock(&trace_types_lock);
2228 for (t = trace_types; t; t = t->next) {
2229 if (strcmp(t->name, buf) == 0)
2232 if (!t || t == current_trace)
2235 if (current_trace && current_trace->reset)
2236 current_trace->reset(tr);
2243 mutex_unlock(&trace_types_lock);
2251 tracing_max_lat_read(struct file *filp, char __user *ubuf,
2252 size_t cnt, loff_t *ppos)
2254 unsigned long *ptr = filp->private_data;
2258 r = snprintf(buf, sizeof(buf), "%ld\n",
2259 *ptr == (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr));
2260 if (r > sizeof(buf))
2262 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
2266 tracing_max_lat_write(struct file *filp, const char __user *ubuf,
2267 size_t cnt, loff_t *ppos)
2269 long *ptr = filp->private_data;
2274 if (cnt >= sizeof(buf))
2277 if (copy_from_user(&buf, ubuf, cnt))
2282 ret = strict_strtoul(buf, 10, &val);
2291 static atomic_t tracing_reader;
2293 static int tracing_open_pipe(struct inode *inode, struct file *filp)
2295 struct trace_iterator *iter;
2297 if (tracing_disabled)
2300 /* We only allow for reader of the pipe */
2301 if (atomic_inc_return(&tracing_reader) != 1) {
2302 atomic_dec(&tracing_reader);
2306 /* create a buffer to store the information to pass to userspace */
2307 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
2311 mutex_lock(&trace_types_lock);
2312 iter->tr = &global_trace;
2313 iter->trace = current_trace;
2314 filp->private_data = iter;
2316 if (iter->trace->pipe_open)
2317 iter->trace->pipe_open(iter);
2318 mutex_unlock(&trace_types_lock);
2323 static int tracing_release_pipe(struct inode *inode, struct file *file)
2325 struct trace_iterator *iter = file->private_data;
2328 atomic_dec(&tracing_reader);
2334 tracing_poll_pipe(struct file *filp, poll_table *poll_table)
2336 struct trace_iterator *iter = filp->private_data;
2338 if (trace_flags & TRACE_ITER_BLOCK) {
2340 * Always select as readable when in blocking mode
2342 return POLLIN | POLLRDNORM;
2344 if (!trace_empty(iter))
2345 return POLLIN | POLLRDNORM;
2346 poll_wait(filp, &trace_wait, poll_table);
2347 if (!trace_empty(iter))
2348 return POLLIN | POLLRDNORM;
2358 tracing_read_pipe(struct file *filp, char __user *ubuf,
2359 size_t cnt, loff_t *ppos)
2361 struct trace_iterator *iter = filp->private_data;
2362 struct trace_array_cpu *data;
2363 static cpumask_t mask;
2365 unsigned long flags;
2366 #ifdef CONFIG_FTRACE
2374 /* return any leftover data */
2375 if (iter->seq.len > start) {
2376 len = iter->seq.len - start;
2379 ret = copy_to_user(ubuf, iter->seq.buffer + start, cnt);
2388 mutex_lock(&trace_types_lock);
2389 if (iter->trace->read) {
2390 ret = iter->trace->read(iter, filp, ubuf, cnt, ppos);
2397 trace_seq_reset(&iter->seq);
2400 while (trace_empty(iter)) {
2402 if ((filp->f_flags & O_NONBLOCK)) {
2408 * This is a make-shift waitqueue. The reason we don't use
2409 * an actual wait queue is because:
2410 * 1) we only ever have one waiter
2411 * 2) the tracing, traces all functions, we don't want
2412 * the overhead of calling wake_up and friends
2413 * (and tracing them too)
2414 * Anyway, this is really very primitive wakeup.
2416 set_current_state(TASK_INTERRUPTIBLE);
2417 iter->tr->waiter = current;
2419 mutex_unlock(&trace_types_lock);
2421 /* sleep for 100 msecs, and try again. */
2422 schedule_timeout(HZ/10);
2424 mutex_lock(&trace_types_lock);
2426 iter->tr->waiter = NULL;
2428 if (signal_pending(current)) {
2433 if (iter->trace != current_trace)
2437 * We block until we read something and tracing is disabled.
2438 * We still block if tracing is disabled, but we have never
2439 * read anything. This allows a user to cat this file, and
2440 * then enable tracing. But after we have read something,
2441 * we give an EOF when tracing is again disabled.
2443 * iter->pos will be 0 if we haven't read anything.
2445 if (!tracer_enabled && iter->pos)
2451 /* stop when tracing is finished */
2452 if (trace_empty(iter))
2455 if (cnt >= PAGE_SIZE)
2456 cnt = PAGE_SIZE - 1;
2458 /* reset all but tr, trace, and overruns */
2459 memset(&iter->seq, 0,
2460 sizeof(struct trace_iterator) -
2461 offsetof(struct trace_iterator, seq));
2465 * We need to stop all tracing on all CPUS to read the
2466 * the next buffer. This is a bit expensive, but is
2467 * not done often. We fill all what we can read,
2468 * and then release the locks again.
2472 local_irq_save(flags);
2473 #ifdef CONFIG_FTRACE
2474 ftrace_save = ftrace_enabled;
2478 for_each_tracing_cpu(cpu) {
2479 data = iter->tr->data[cpu];
2481 if (!head_page(data) || !data->trace_idx)
2484 atomic_inc(&data->disabled);
2488 for_each_cpu_mask(cpu, mask) {
2489 data = iter->tr->data[cpu];
2490 __raw_spin_lock(&data->lock);
2492 if (data->overrun > iter->last_overrun[cpu])
2493 iter->overrun[cpu] +=
2494 data->overrun - iter->last_overrun[cpu];
2495 iter->last_overrun[cpu] = data->overrun;
2498 while (find_next_entry_inc(iter) != NULL) {
2499 int len = iter->seq.len;
2501 ret = print_trace_line(iter);
2503 /* don't print partial lines */
2504 iter->seq.len = len;
2508 trace_consume(iter);
2510 if (iter->seq.len >= cnt)
2514 for_each_cpu_mask(cpu, mask) {
2515 data = iter->tr->data[cpu];
2516 __raw_spin_unlock(&data->lock);
2519 for_each_cpu_mask(cpu, mask) {
2520 data = iter->tr->data[cpu];
2521 atomic_dec(&data->disabled);
2523 #ifdef CONFIG_FTRACE
2524 ftrace_enabled = ftrace_save;
2526 local_irq_restore(flags);
2528 /* Now copy what we have to the user */
2529 read = iter->seq.len;
2533 ret = copy_to_user(ubuf, iter->seq.buffer, read);
2535 if (read < iter->seq.len)
2538 trace_seq_reset(&iter->seq);
2544 mutex_unlock(&trace_types_lock);
2550 tracing_entries_read(struct file *filp, char __user *ubuf,
2551 size_t cnt, loff_t *ppos)
2553 struct trace_array *tr = filp->private_data;
2557 r = sprintf(buf, "%lu\n", tr->entries);
2558 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
2562 tracing_entries_write(struct file *filp, const char __user *ubuf,
2563 size_t cnt, loff_t *ppos)
2569 if (cnt >= sizeof(buf))
2572 if (copy_from_user(&buf, ubuf, cnt))
2577 ret = strict_strtoul(buf, 10, &val);
2581 /* must have at least 1 entry */
2585 mutex_lock(&trace_types_lock);
2587 if (current_trace != &no_tracer) {
2589 pr_info("ftrace: set current_tracer to none"
2590 " before modifying buffer size\n");
2594 if (val > global_trace.entries) {
2595 while (global_trace.entries < val) {
2596 if (trace_alloc_page()) {
2602 /* include the number of entries in val (inc of page entries) */
2603 while (global_trace.entries > val + (ENTRIES_PER_PAGE - 1))
2610 max_tr.entries = global_trace.entries;
2611 mutex_unlock(&trace_types_lock);
2616 static struct file_operations tracing_max_lat_fops = {
2617 .open = tracing_open_generic,
2618 .read = tracing_max_lat_read,
2619 .write = tracing_max_lat_write,
2622 static struct file_operations tracing_ctrl_fops = {
2623 .open = tracing_open_generic,
2624 .read = tracing_ctrl_read,
2625 .write = tracing_ctrl_write,
2628 static struct file_operations set_tracer_fops = {
2629 .open = tracing_open_generic,
2630 .read = tracing_set_trace_read,
2631 .write = tracing_set_trace_write,
2634 static struct file_operations tracing_pipe_fops = {
2635 .open = tracing_open_pipe,
2636 .poll = tracing_poll_pipe,
2637 .read = tracing_read_pipe,
2638 .release = tracing_release_pipe,
2641 static struct file_operations tracing_entries_fops = {
2642 .open = tracing_open_generic,
2643 .read = tracing_entries_read,
2644 .write = tracing_entries_write,
2647 #ifdef CONFIG_DYNAMIC_FTRACE
2650 tracing_read_long(struct file *filp, char __user *ubuf,
2651 size_t cnt, loff_t *ppos)
2653 unsigned long *p = filp->private_data;
2657 r = sprintf(buf, "%ld\n", *p);
2659 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
2662 static struct file_operations tracing_read_long_fops = {
2663 .open = tracing_open_generic,
2664 .read = tracing_read_long,
2668 static struct dentry *d_tracer;
2670 struct dentry *tracing_init_dentry(void)
2677 d_tracer = debugfs_create_dir("tracing", NULL);
2679 if (!d_tracer && !once) {
2681 pr_warning("Could not create debugfs directory 'tracing'\n");
2688 #ifdef CONFIG_FTRACE_SELFTEST
2689 /* Let selftest have access to static functions in this file */
2690 #include "trace_selftest.c"
2693 static __init void tracer_init_debugfs(void)
2695 struct dentry *d_tracer;
2696 struct dentry *entry;
2698 d_tracer = tracing_init_dentry();
2700 entry = debugfs_create_file("tracing_enabled", 0644, d_tracer,
2701 &global_trace, &tracing_ctrl_fops);
2703 pr_warning("Could not create debugfs 'tracing_enabled' entry\n");
2705 entry = debugfs_create_file("iter_ctrl", 0644, d_tracer,
2706 NULL, &tracing_iter_fops);
2708 pr_warning("Could not create debugfs 'iter_ctrl' entry\n");
2710 entry = debugfs_create_file("tracing_cpumask", 0644, d_tracer,
2711 NULL, &tracing_cpumask_fops);
2713 pr_warning("Could not create debugfs 'tracing_cpumask' entry\n");
2715 entry = debugfs_create_file("latency_trace", 0444, d_tracer,
2716 &global_trace, &tracing_lt_fops);
2718 pr_warning("Could not create debugfs 'latency_trace' entry\n");
2720 entry = debugfs_create_file("trace", 0444, d_tracer,
2721 &global_trace, &tracing_fops);
2723 pr_warning("Could not create debugfs 'trace' entry\n");
2725 entry = debugfs_create_file("available_tracers", 0444, d_tracer,
2726 &global_trace, &show_traces_fops);
2728 pr_warning("Could not create debugfs 'trace' entry\n");
2730 entry = debugfs_create_file("current_tracer", 0444, d_tracer,
2731 &global_trace, &set_tracer_fops);
2733 pr_warning("Could not create debugfs 'trace' entry\n");
2735 entry = debugfs_create_file("tracing_max_latency", 0644, d_tracer,
2736 &tracing_max_latency,
2737 &tracing_max_lat_fops);
2739 pr_warning("Could not create debugfs "
2740 "'tracing_max_latency' entry\n");
2742 entry = debugfs_create_file("tracing_thresh", 0644, d_tracer,
2743 &tracing_thresh, &tracing_max_lat_fops);
2745 pr_warning("Could not create debugfs "
2746 "'tracing_threash' entry\n");
2747 entry = debugfs_create_file("README", 0644, d_tracer,
2748 NULL, &tracing_readme_fops);
2750 pr_warning("Could not create debugfs 'README' entry\n");
2752 entry = debugfs_create_file("trace_pipe", 0644, d_tracer,
2753 NULL, &tracing_pipe_fops);
2755 pr_warning("Could not create debugfs "
2756 "'tracing_threash' entry\n");
2758 entry = debugfs_create_file("trace_entries", 0644, d_tracer,
2759 &global_trace, &tracing_entries_fops);
2761 pr_warning("Could not create debugfs "
2762 "'tracing_threash' entry\n");
2764 #ifdef CONFIG_DYNAMIC_FTRACE
2765 entry = debugfs_create_file("dyn_ftrace_total_info", 0444, d_tracer,
2766 &ftrace_update_tot_cnt,
2767 &tracing_read_long_fops);
2769 pr_warning("Could not create debugfs "
2770 "'dyn_ftrace_total_info' entry\n");
2774 static int trace_alloc_page(void)
2776 struct trace_array_cpu *data;
2777 struct page *page, *tmp;
2782 /* first allocate a page for each CPU */
2783 for_each_tracing_cpu(i) {
2784 array = (void *)__get_free_page(GFP_KERNEL);
2785 if (array == NULL) {
2786 printk(KERN_ERR "tracer: failed to allocate page"
2787 "for trace buffer!\n");
2791 page = virt_to_page(array);
2792 list_add(&page->lru, &pages);
2794 /* Only allocate if we are actually using the max trace */
2795 #ifdef CONFIG_TRACER_MAX_TRACE
2796 array = (void *)__get_free_page(GFP_KERNEL);
2797 if (array == NULL) {
2798 printk(KERN_ERR "tracer: failed to allocate page"
2799 "for trace buffer!\n");
2802 page = virt_to_page(array);
2803 list_add(&page->lru, &pages);
2807 /* Now that we successfully allocate a page per CPU, add them */
2808 for_each_tracing_cpu(i) {
2809 data = global_trace.data[i];
2810 page = list_entry(pages.next, struct page, lru);
2811 list_del_init(&page->lru);
2812 list_add_tail(&page->lru, &data->trace_pages);
2815 #ifdef CONFIG_TRACER_MAX_TRACE
2816 data = max_tr.data[i];
2817 page = list_entry(pages.next, struct page, lru);
2818 list_del_init(&page->lru);
2819 list_add_tail(&page->lru, &data->trace_pages);
2823 global_trace.entries += ENTRIES_PER_PAGE;
2828 list_for_each_entry_safe(page, tmp, &pages, lru) {
2829 list_del_init(&page->lru);
2835 static int trace_free_page(void)
2837 struct trace_array_cpu *data;
2839 struct list_head *p;
2843 /* free one page from each buffer */
2844 for_each_tracing_cpu(i) {
2845 data = global_trace.data[i];
2846 p = data->trace_pages.next;
2847 if (p == &data->trace_pages) {
2848 /* should never happen */
2850 tracing_disabled = 1;
2854 page = list_entry(p, struct page, lru);
2856 list_del(&page->lru);
2859 tracing_reset(data);
2861 #ifdef CONFIG_TRACER_MAX_TRACE
2862 data = max_tr.data[i];
2863 p = data->trace_pages.next;
2864 if (p == &data->trace_pages) {
2865 /* should never happen */
2867 tracing_disabled = 1;
2871 page = list_entry(p, struct page, lru);
2873 list_del(&page->lru);
2876 tracing_reset(data);
2879 global_trace.entries -= ENTRIES_PER_PAGE;
2884 __init static int tracer_alloc_buffers(void)
2886 struct trace_array_cpu *data;
2893 global_trace.ctrl = tracer_enabled;
2895 /* TODO: make the number of buffers hot pluggable with CPUS */
2896 tracing_nr_buffers = num_possible_cpus();
2897 tracing_buffer_mask = cpu_possible_map;
2899 /* Allocate the first page for all buffers */
2900 for_each_tracing_cpu(i) {
2901 data = global_trace.data[i] = &per_cpu(global_trace_cpu, i);
2902 max_tr.data[i] = &per_cpu(max_data, i);
2904 array = (void *)__get_free_page(GFP_KERNEL);
2905 if (array == NULL) {
2906 printk(KERN_ERR "tracer: failed to allocate page"
2907 "for trace buffer!\n");
2911 /* set the array to the list */
2912 INIT_LIST_HEAD(&data->trace_pages);
2913 page = virt_to_page(array);
2914 list_add(&page->lru, &data->trace_pages);
2915 /* use the LRU flag to differentiate the two buffers */
2918 data->lock = (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED;
2919 max_tr.data[i]->lock = (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED;
2921 /* Only allocate if we are actually using the max trace */
2922 #ifdef CONFIG_TRACER_MAX_TRACE
2923 array = (void *)__get_free_page(GFP_KERNEL);
2924 if (array == NULL) {
2925 printk(KERN_ERR "tracer: failed to allocate page"
2926 "for trace buffer!\n");
2930 INIT_LIST_HEAD(&max_tr.data[i]->trace_pages);
2931 page = virt_to_page(array);
2932 list_add(&page->lru, &max_tr.data[i]->trace_pages);
2938 * Since we allocate by orders of pages, we may be able to
2941 global_trace.entries = ENTRIES_PER_PAGE;
2944 while (global_trace.entries < trace_nr_entries) {
2945 if (trace_alloc_page())
2949 max_tr.entries = global_trace.entries;
2951 pr_info("tracer: %d pages allocated for %ld",
2952 pages, trace_nr_entries);
2953 pr_info(" entries of %ld bytes\n", (long)TRACE_ENTRY_SIZE);
2954 pr_info(" actual entries %ld\n", global_trace.entries);
2956 tracer_init_debugfs();
2958 trace_init_cmdlines();
2960 register_tracer(&no_tracer);
2961 current_trace = &no_tracer;
2963 /* All seems OK, enable tracing */
2964 tracing_disabled = 0;
2969 for (i-- ; i >= 0; i--) {
2970 struct page *page, *tmp;
2971 struct trace_array_cpu *data = global_trace.data[i];
2974 list_for_each_entry_safe(page, tmp,
2975 &data->trace_pages, lru) {
2976 list_del_init(&page->lru);
2981 #ifdef CONFIG_TRACER_MAX_TRACE
2982 data = max_tr.data[i];
2984 list_for_each_entry_safe(page, tmp,
2985 &data->trace_pages, lru) {
2986 list_del_init(&page->lru);
2994 fs_initcall(tracer_alloc_buffers);