blob: c232d8248a0909af2b525f001a1eb70432d20f3d [file] [log] [blame]
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001/*
2 * ring buffer based function tracer
3 *
4 * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
5 * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com>
6 *
7 * Originally taken from the RT patch by:
8 * Arnaldo Carvalho de Melo <acme@redhat.com>
9 *
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
13 */
14#include <linux/utsrelease.h>
15#include <linux/kallsyms.h>
16#include <linux/seq_file.h>
17#include <linux/debugfs.h>
Steven Rostedt4c11d7a2008-05-12 21:20:43 +020018#include <linux/pagemap.h>
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020019#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>
Soeren Sandmann Pedersen2a2cc8f2008-05-12 21:20:49 +020027#include <linux/poll.h>
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020028#include <linux/gfp.h>
29#include <linux/fs.h>
30
Ingo Molnar86387f72008-05-12 21:20:51 +020031#include <linux/stacktrace.h>
32
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020033#include "trace.h"
34
35unsigned long __read_mostly tracing_max_latency = (cycle_t)ULONG_MAX;
36unsigned long __read_mostly tracing_thresh;
37
Steven Rostedtab464282008-05-12 21:21:00 +020038static unsigned long __read_mostly tracing_nr_buffers;
39static cpumask_t __read_mostly tracing_buffer_mask;
40
41#define for_each_tracing_cpu(cpu) \
42 for_each_cpu_mask(cpu, tracing_buffer_mask)
43
Steven Rostedta98a3c32008-05-12 21:20:59 +020044/* dummy trace to disable tracing */
Steven Rostedtcffae432008-05-12 21:21:00 +020045static struct tracer no_tracer __read_mostly = {
Steven Rostedta98a3c32008-05-12 21:20:59 +020046 .name = "none",
47};
48
49static int trace_alloc_page(void);
50static int trace_free_page(void);
51
Steven Rostedt60a11772008-05-12 21:20:44 +020052static int tracing_disabled = 1;
53
Thomas Gleixner72829bc2008-05-23 21:37:28 +020054long
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020055ns2usecs(cycle_t nsec)
56{
57 nsec += 500;
58 do_div(nsec, 1000);
59 return nsec;
60}
61
Ingo Molnare309b412008-05-12 21:20:51 +020062cycle_t ftrace_now(int cpu)
Ingo Molnar750ed1a2008-05-12 21:20:46 +020063{
Ingo Molnar0fd9e0d2008-05-12 21:20:48 +020064 return cpu_clock(cpu);
Ingo Molnar750ed1a2008-05-12 21:20:46 +020065}
66
Steven Rostedt4fcdae82008-05-12 21:21:00 +020067/*
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.
74 *
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.
78 */
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020079static struct trace_array global_trace;
80
81static DEFINE_PER_CPU(struct trace_array_cpu, global_trace_cpu);
82
Steven Rostedt4fcdae82008-05-12 21:21:00 +020083/*
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.
87 *
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.
92 */
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020093static struct trace_array max_tr;
94
95static DEFINE_PER_CPU(struct trace_array_cpu, max_data);
96
Steven Rostedt4fcdae82008-05-12 21:21:00 +020097/* tracer_enabled is used to toggle activation of a tracer */
Steven Rostedt26994ea2008-05-12 21:20:48 +020098static int tracer_enabled = 1;
Steven Rostedt4fcdae82008-05-12 21:21:00 +020099
100/*
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.
104 */
Ingo Molnar57422792008-05-12 21:20:51 +0200105static unsigned long trace_nr_entries = 65536UL;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200106
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200107/* trace_types holds a link list of available tracers. */
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200108static struct tracer *trace_types __read_mostly;
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200109
110/* current_trace points to the tracer that is currently active */
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200111static struct tracer *current_trace __read_mostly;
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200112
113/*
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.
117 */
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200118static int max_tracer_type_len;
119
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200120/*
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.
125 */
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200126static DEFINE_MUTEX(trace_types_lock);
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200127
128/* trace_wait is a waitqueue for tasks blocked on trace_poll */
Ingo Molnar4e655512008-05-12 21:20:52 +0200129static DECLARE_WAIT_QUEUE_HEAD(trace_wait);
130
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200131/* trace_flags holds iter_ctrl options */
Ingo Molnar4e655512008-05-12 21:20:52 +0200132unsigned long trace_flags = TRACE_ITER_PRINT_PARENT;
133
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200134/**
135 * trace_wake_up - wake up tasks waiting for trace input
136 *
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.
139 */
Ingo Molnar4e655512008-05-12 21:20:52 +0200140void trace_wake_up(void)
141{
Ingo Molnar017730c2008-05-12 21:20:52 +0200142 /*
143 * The runqueue_is_locked() can fail, but this is the best we
144 * have for now:
145 */
146 if (!(trace_flags & TRACE_ITER_BLOCK) && !runqueue_is_locked())
Ingo Molnar4e655512008-05-12 21:20:52 +0200147 wake_up(&trace_wait);
148}
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200149
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200150#define ENTRIES_PER_PAGE (PAGE_SIZE / sizeof(struct trace_entry))
151
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200152static int __init set_nr_entries(char *str)
153{
Steven Rostedtc6caeeb2008-05-12 21:21:00 +0200154 unsigned long nr_entries;
155 int ret;
156
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200157 if (!str)
158 return 0;
Steven Rostedtc6caeeb2008-05-12 21:21:00 +0200159 ret = strict_strtoul(str, 0, &nr_entries);
160 /* nr_entries can not be zero */
161 if (ret < 0 || nr_entries == 0)
162 return 0;
163 trace_nr_entries = nr_entries;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200164 return 1;
165}
166__setup("trace_entries=", set_nr_entries);
167
Steven Rostedt57f50be2008-05-12 21:20:44 +0200168unsigned long nsecs_to_usecs(unsigned long nsecs)
169{
170 return nsecs / 1000;
171}
172
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200173/*
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
180 */
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200181enum 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,
186};
187
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200188/*
189 * TRACE_ITER_SYM_MASK masks the options in trace_flags that
190 * control the output of kernel symbols.
191 */
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200192#define TRACE_ITER_SYM_MASK \
193 (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
194
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200195/* These must match the bit postions in trace_iterator_flags */
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200196static const char *trace_options[] = {
197 "print-parent",
198 "sym-offset",
199 "sym-addr",
200 "verbose",
Ingo Molnarf9896bf2008-05-12 21:20:47 +0200201 "raw",
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +0200202 "hex",
Ingo Molnarcb0f12a2008-05-12 21:20:47 +0200203 "bin",
Soeren Sandmann Pedersen2a2cc8f2008-05-12 21:20:49 +0200204 "block",
Ingo Molnar86387f72008-05-12 21:20:51 +0200205 "stacktrace",
Ingo Molnar4ac3ba42008-05-12 21:20:52 +0200206 "sched-tree",
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200207 NULL
208};
209
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200210/*
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.
215 *
216 * This is defined as a raw_spinlock_t in order to help
217 * with performance when lockdep debugging is enabled.
218 */
Steven Rostedt92205c22008-05-12 21:20:55 +0200219static raw_spinlock_t ftrace_max_lock =
220 (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200221
222/*
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)
226 */
Ingo Molnare309b412008-05-12 21:20:51 +0200227static void
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200228__update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
229{
230 struct trace_array_cpu *data = tr->data[cpu];
231
232 max_tr.cpu = cpu;
233 max_tr.time_start = data->preempt_timestamp;
234
235 data = max_tr.data[cpu];
236 data->saved_latency = tracing_max_latency;
237
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;
244
245 /* record this tasks comm */
246 tracing_record_cmdline(current);
247}
248
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200249/**
250 * check_pages - integrity check of trace buffers
251 *
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
254 * a bit of overhead.
255 */
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200256void check_pages(struct trace_array_cpu *data)
257{
258 struct page *page, *tmp;
259
260 BUG_ON(data->trace_pages.next->prev != &data->trace_pages);
261 BUG_ON(data->trace_pages.prev->next != &data->trace_pages);
262
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);
266 }
267}
268
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200269/**
270 * head_page - page address of the first page in per_cpu buffer.
271 *
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.
275 */
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200276void *head_page(struct trace_array_cpu *data)
277{
278 struct page *page;
279
280 check_pages(data);
281 if (list_empty(&data->trace_pages))
282 return NULL;
283
284 page = list_entry(data->trace_pages.next, struct page, lru);
285 BUG_ON(&page->lru == &data->trace_pages);
286
287 return page_address(page);
288}
289
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200290/**
291 * trace_seq_printf - sequence printing of trace information
292 * @s: trace sequence descriptor
293 * @fmt: printf format string
294 *
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.
300 */
Thomas Gleixner72829bc2008-05-23 21:37:28 +0200301int
Steven Rostedt214023c2008-05-12 21:20:46 +0200302trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
303{
304 int len = (PAGE_SIZE - 1) - s->len;
305 va_list ap;
Steven Rostedtb3806b42008-05-12 21:20:46 +0200306 int ret;
Steven Rostedt214023c2008-05-12 21:20:46 +0200307
308 if (!len)
309 return 0;
310
311 va_start(ap, fmt);
Steven Rostedtb3806b42008-05-12 21:20:46 +0200312 ret = vsnprintf(s->buffer + s->len, len, fmt, ap);
Steven Rostedt214023c2008-05-12 21:20:46 +0200313 va_end(ap);
314
Steven Rostedtb3806b42008-05-12 21:20:46 +0200315 /* If we can't write it all, don't bother writing anything */
Thomas Gleixner72829bc2008-05-23 21:37:28 +0200316 if (ret >= len)
Steven Rostedtb3806b42008-05-12 21:20:46 +0200317 return 0;
318
319 s->len += ret;
Steven Rostedt214023c2008-05-12 21:20:46 +0200320
321 return len;
322}
323
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200324/**
325 * trace_seq_puts - trace sequence printing of simple string
326 * @s: trace sequence descriptor
327 * @str: simple string to record
328 *
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.
333 */
Ingo Molnare309b412008-05-12 21:20:51 +0200334static int
Steven Rostedt214023c2008-05-12 21:20:46 +0200335trace_seq_puts(struct trace_seq *s, const char *str)
336{
337 int len = strlen(str);
338
339 if (len > ((PAGE_SIZE - 1) - s->len))
Steven Rostedtb3806b42008-05-12 21:20:46 +0200340 return 0;
Steven Rostedt214023c2008-05-12 21:20:46 +0200341
342 memcpy(s->buffer + s->len, str, len);
343 s->len += len;
344
345 return len;
346}
347
Ingo Molnare309b412008-05-12 21:20:51 +0200348static int
Steven Rostedt214023c2008-05-12 21:20:46 +0200349trace_seq_putc(struct trace_seq *s, unsigned char c)
350{
351 if (s->len >= (PAGE_SIZE - 1))
352 return 0;
353
354 s->buffer[s->len++] = c;
355
356 return 1;
357}
358
Ingo Molnare309b412008-05-12 21:20:51 +0200359static int
Ingo Molnarcb0f12a2008-05-12 21:20:47 +0200360trace_seq_putmem(struct trace_seq *s, void *mem, size_t len)
361{
362 if (len > ((PAGE_SIZE - 1) - s->len))
363 return 0;
364
365 memcpy(s->buffer + s->len, mem, len);
366 s->len += len;
367
368 return len;
369}
370
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +0200371#define HEX_CHARS 17
Thomas Gleixner93dcc6e2008-05-12 21:21:00 +0200372static const char hex2asc[] = "0123456789abcdef";
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +0200373
Ingo Molnare309b412008-05-12 21:20:51 +0200374static int
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +0200375trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len)
376{
377 unsigned char hex[HEX_CHARS];
Thomas Gleixner93dcc6e2008-05-12 21:21:00 +0200378 unsigned char *data = mem;
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +0200379 unsigned char byte;
380 int i, j;
381
382 BUG_ON(len >= HEX_CHARS);
383
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +0200384#ifdef __BIG_ENDIAN
385 for (i = 0, j = 0; i < len; i++) {
386#else
387 for (i = len-1, j = 0; i >= 0; i--) {
388#endif
389 byte = data[i];
390
Thomas Gleixner93dcc6e2008-05-12 21:21:00 +0200391 hex[j++] = hex2asc[byte & 0x0f];
392 hex[j++] = hex2asc[byte >> 4];
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +0200393 }
Thomas Gleixner93dcc6e2008-05-12 21:21:00 +0200394 hex[j++] = ' ';
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +0200395
396 return trace_seq_putmem(s, hex, j);
397}
398
Ingo Molnare309b412008-05-12 21:20:51 +0200399static void
Steven Rostedt214023c2008-05-12 21:20:46 +0200400trace_seq_reset(struct trace_seq *s)
401{
402 s->len = 0;
403}
404
Ingo Molnare309b412008-05-12 21:20:51 +0200405static void
Steven Rostedt214023c2008-05-12 21:20:46 +0200406trace_print_seq(struct seq_file *m, struct trace_seq *s)
407{
408 int len = s->len >= PAGE_SIZE ? PAGE_SIZE - 1 : s->len;
409
410 s->buffer[len] = 0;
411 seq_puts(m, s->buffer);
412
413 trace_seq_reset(s);
414}
415
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200416/*
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.
420 *
421 * The ftrace_max_lock must be held.
422 */
Ingo Molnare309b412008-05-12 21:20:51 +0200423static void
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200424flip_trace(struct trace_array_cpu *tr1, struct trace_array_cpu *tr2)
425{
426 struct list_head flip_pages;
427
428 INIT_LIST_HEAD(&flip_pages);
429
Steven Rostedt93a588f2008-05-12 21:20:45 +0200430 memcpy(&tr1->trace_head_idx, &tr2->trace_head_idx,
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200431 sizeof(struct trace_array_cpu) -
Steven Rostedt93a588f2008-05-12 21:20:45 +0200432 offsetof(struct trace_array_cpu, trace_head_idx));
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200433
434 check_pages(tr1);
435 check_pages(tr2);
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));
440 check_pages(tr1);
441 check_pages(tr2);
442}
443
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200444/**
445 * update_max_tr - snapshot all trace buffers from global_trace to max_tr
446 * @tr: tracer
447 * @tsk: the task with the latency
448 * @cpu: The cpu that initiated the trace.
449 *
450 * Flip the buffers between the @tr and the max_tr and record information
451 * about which task was the cause of this latency.
452 */
Ingo Molnare309b412008-05-12 21:20:51 +0200453void
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200454update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
455{
456 struct trace_array_cpu *data;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200457 int i;
458
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200459 WARN_ON_ONCE(!irqs_disabled());
Steven Rostedt92205c22008-05-12 21:20:55 +0200460 __raw_spin_lock(&ftrace_max_lock);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200461 /* clear out all the previous traces */
Steven Rostedtab464282008-05-12 21:21:00 +0200462 for_each_tracing_cpu(i) {
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200463 data = tr->data[i];
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200464 flip_trace(max_tr.data[i], data);
Steven Rostedt89b2f972008-05-12 21:20:44 +0200465 tracing_reset(data);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200466 }
467
468 __update_max_tr(tr, tsk, cpu);
Steven Rostedt92205c22008-05-12 21:20:55 +0200469 __raw_spin_unlock(&ftrace_max_lock);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200470}
471
472/**
473 * update_max_tr_single - only copy one trace over, and reset the rest
474 * @tr - tracer
475 * @tsk - task with the latency
476 * @cpu - the cpu of the buffer to copy.
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200477 *
478 * Flip the trace of a single CPU buffer between the @tr and the max_tr.
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200479 */
Ingo Molnare309b412008-05-12 21:20:51 +0200480void
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200481update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu)
482{
483 struct trace_array_cpu *data = tr->data[cpu];
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200484 int i;
485
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200486 WARN_ON_ONCE(!irqs_disabled());
Steven Rostedt92205c22008-05-12 21:20:55 +0200487 __raw_spin_lock(&ftrace_max_lock);
Steven Rostedtab464282008-05-12 21:21:00 +0200488 for_each_tracing_cpu(i)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200489 tracing_reset(max_tr.data[i]);
490
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200491 flip_trace(max_tr.data[cpu], data);
Steven Rostedt89b2f972008-05-12 21:20:44 +0200492 tracing_reset(data);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200493
494 __update_max_tr(tr, tsk, cpu);
Steven Rostedt92205c22008-05-12 21:20:55 +0200495 __raw_spin_unlock(&ftrace_max_lock);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200496}
497
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200498/**
499 * register_tracer - register a tracer with the ftrace system.
500 * @type - the plugin for the tracer
501 *
502 * Register a new plugin tracer.
503 */
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200504int register_tracer(struct tracer *type)
505{
506 struct tracer *t;
507 int len;
508 int ret = 0;
509
510 if (!type->name) {
511 pr_info("Tracer must have a name\n");
512 return -1;
513 }
514
515 mutex_lock(&trace_types_lock);
516 for (t = trace_types; t; t = t->next) {
517 if (strcmp(type->name, t->name) == 0) {
518 /* already found */
519 pr_info("Trace %s already registered\n",
520 type->name);
521 ret = -1;
522 goto out;
523 }
524 }
525
Steven Rostedt60a11772008-05-12 21:20:44 +0200526#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;
532 int i;
533 /*
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.
539 */
Steven Rostedtab464282008-05-12 21:21:00 +0200540 for_each_tracing_cpu(i) {
Steven Rostedt60a11772008-05-12 21:20:44 +0200541 data = tr->data[i];
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200542 if (!head_page(data))
543 continue;
Steven Rostedt60a11772008-05-12 21:20:44 +0200544 tracing_reset(data);
545 }
546 current_trace = type;
547 tr->ctrl = 0;
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;
554 if (ret) {
555 printk(KERN_CONT "FAILED!\n");
556 goto out;
557 }
Steven Rostedt1d4db002008-05-12 21:20:45 +0200558 /* Only reset on passing, to avoid touching corrupted buffers */
Steven Rostedtab464282008-05-12 21:21:00 +0200559 for_each_tracing_cpu(i) {
Steven Rostedt1d4db002008-05-12 21:20:45 +0200560 data = tr->data[i];
561 if (!head_page(data))
562 continue;
563 tracing_reset(data);
564 }
Steven Rostedt60a11772008-05-12 21:20:44 +0200565 printk(KERN_CONT "PASSED\n");
566 }
567#endif
568
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200569 type->next = trace_types;
570 trace_types = type;
571 len = strlen(type->name);
572 if (len > max_tracer_type_len)
573 max_tracer_type_len = len;
Steven Rostedt60a11772008-05-12 21:20:44 +0200574
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200575 out:
576 mutex_unlock(&trace_types_lock);
577
578 return ret;
579}
580
581void unregister_tracer(struct tracer *type)
582{
583 struct tracer **t;
584 int len;
585
586 mutex_lock(&trace_types_lock);
587 for (t = &trace_types; *t; t = &(*t)->next) {
588 if (*t == type)
589 goto found;
590 }
591 pr_info("Trace %s not registered\n", type->name);
592 goto out;
593
594 found:
595 *t = (*t)->next;
596 if (strlen(type->name) != max_tracer_type_len)
597 goto out;
598
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;
604 }
605 out:
606 mutex_unlock(&trace_types_lock);
607}
608
Ingo Molnare309b412008-05-12 21:20:51 +0200609void tracing_reset(struct trace_array_cpu *data)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200610{
611 data->trace_idx = 0;
Steven Rostedt53d0aa72008-05-12 21:21:01 +0200612 data->overrun = 0;
Steven Rostedt93a588f2008-05-12 21:20:45 +0200613 data->trace_head = data->trace_tail = head_page(data);
614 data->trace_head_idx = 0;
615 data->trace_tail_idx = 0;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200616}
617
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200618#define SAVED_CMDLINES 128
619static unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
620static unsigned map_cmdline_to_pid[SAVED_CMDLINES];
621static char saved_cmdlines[SAVED_CMDLINES][TASK_COMM_LEN];
622static int cmdline_idx;
623static DEFINE_SPINLOCK(trace_cmdline_lock);
Steven Rostedt25b0b442008-05-12 21:21:00 +0200624
625/* trace in all context switches */
626atomic_t trace_record_cmdline_enabled __read_mostly;
627
628/* temporary disable recording */
629atomic_t trace_record_cmdline_disabled __read_mostly;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200630
631static void trace_init_cmdlines(void)
632{
633 memset(&map_pid_to_cmdline, -1, sizeof(map_pid_to_cmdline));
634 memset(&map_cmdline_to_pid, -1, sizeof(map_cmdline_to_pid));
635 cmdline_idx = 0;
636}
637
Ingo Molnare309b412008-05-12 21:20:51 +0200638void trace_stop_cmdline_recording(void);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200639
Ingo Molnare309b412008-05-12 21:20:51 +0200640static void trace_save_cmdline(struct task_struct *tsk)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200641{
642 unsigned map;
643 unsigned idx;
644
645 if (!tsk->pid || unlikely(tsk->pid > PID_MAX_DEFAULT))
646 return;
647
648 /*
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.
653 */
654 if (!spin_trylock(&trace_cmdline_lock))
655 return;
656
657 idx = map_pid_to_cmdline[tsk->pid];
658 if (idx >= SAVED_CMDLINES) {
659 idx = (cmdline_idx + 1) % SAVED_CMDLINES;
660
661 map = map_cmdline_to_pid[idx];
662 if (map <= PID_MAX_DEFAULT)
663 map_pid_to_cmdline[map] = (unsigned)-1;
664
665 map_pid_to_cmdline[tsk->pid] = idx;
666
667 cmdline_idx = idx;
668 }
669
670 memcpy(&saved_cmdlines[idx], tsk->comm, TASK_COMM_LEN);
671
672 spin_unlock(&trace_cmdline_lock);
673}
674
Ingo Molnare309b412008-05-12 21:20:51 +0200675static char *trace_find_cmdline(int pid)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200676{
677 char *cmdline = "<...>";
678 unsigned map;
679
680 if (!pid)
681 return "<idle>";
682
683 if (pid > PID_MAX_DEFAULT)
684 goto out;
685
686 map = map_pid_to_cmdline[pid];
687 if (map >= SAVED_CMDLINES)
688 goto out;
689
690 cmdline = saved_cmdlines[map];
691
692 out:
693 return cmdline;
694}
695
Ingo Molnare309b412008-05-12 21:20:51 +0200696void tracing_record_cmdline(struct task_struct *tsk)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200697{
698 if (atomic_read(&trace_record_cmdline_disabled))
699 return;
700
701 trace_save_cmdline(tsk);
702}
703
Ingo Molnare309b412008-05-12 21:20:51 +0200704static inline struct list_head *
Steven Rostedt93a588f2008-05-12 21:20:45 +0200705trace_next_list(struct trace_array_cpu *data, struct list_head *next)
706{
707 /*
708 * Roundrobin - but skip the head (which is not a real page):
709 */
710 next = next->next;
711 if (unlikely(next == &data->trace_pages))
712 next = next->next;
713 BUG_ON(next == &data->trace_pages);
714
715 return next;
716}
717
Ingo Molnare309b412008-05-12 21:20:51 +0200718static inline void *
Steven Rostedt93a588f2008-05-12 21:20:45 +0200719trace_next_page(struct trace_array_cpu *data, void *addr)
720{
721 struct list_head *next;
722 struct page *page;
723
724 page = virt_to_page(addr);
725
726 next = trace_next_list(data, &page->lru);
727 page = list_entry(next, struct page, lru);
728
729 return page_address(page);
730}
731
Ingo Molnare309b412008-05-12 21:20:51 +0200732static inline struct trace_entry *
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200733tracing_get_trace_entry(struct trace_array *tr, struct trace_array_cpu *data)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200734{
735 unsigned long idx, idx_next;
736 struct trace_entry *entry;
737
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200738 data->trace_idx++;
Steven Rostedt93a588f2008-05-12 21:20:45 +0200739 idx = data->trace_head_idx;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200740 idx_next = idx + 1;
741
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200742 BUG_ON(idx * TRACE_ENTRY_SIZE >= PAGE_SIZE);
743
Steven Rostedt93a588f2008-05-12 21:20:45 +0200744 entry = data->trace_head + idx * TRACE_ENTRY_SIZE;
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200745
746 if (unlikely(idx_next >= ENTRIES_PER_PAGE)) {
Steven Rostedt93a588f2008-05-12 21:20:45 +0200747 data->trace_head = trace_next_page(data, data->trace_head);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200748 idx_next = 0;
749 }
750
Steven Rostedt93a588f2008-05-12 21:20:45 +0200751 if (data->trace_head == data->trace_tail &&
752 idx_next == data->trace_tail_idx) {
753 /* overrun */
Steven Rostedt53d0aa72008-05-12 21:21:01 +0200754 data->overrun++;
Steven Rostedt93a588f2008-05-12 21:20:45 +0200755 data->trace_tail_idx++;
756 if (data->trace_tail_idx >= ENTRIES_PER_PAGE) {
757 data->trace_tail =
758 trace_next_page(data, data->trace_tail);
759 data->trace_tail_idx = 0;
760 }
761 }
762
763 data->trace_head_idx = idx_next;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200764
765 return entry;
766}
767
Ingo Molnare309b412008-05-12 21:20:51 +0200768static inline void
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200769tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200770{
771 struct task_struct *tsk = current;
772 unsigned long pc;
773
774 pc = preempt_count();
775
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200776 entry->preempt_count = pc & 0xff;
Thomas Gleixner72829bc2008-05-23 21:37:28 +0200777 entry->pid = (tsk) ? tsk->pid : 0;
Ingo Molnar750ed1a2008-05-12 21:20:46 +0200778 entry->t = ftrace_now(raw_smp_processor_id());
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200779 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);
783}
784
Ingo Molnare309b412008-05-12 21:20:51 +0200785void
Steven Rostedt6fb44b72008-05-12 21:20:49 +0200786trace_function(struct trace_array *tr, struct trace_array_cpu *data,
787 unsigned long ip, unsigned long parent_ip, unsigned long flags)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200788{
789 struct trace_entry *entry;
Ingo Molnardcb63082008-05-12 21:20:48 +0200790 unsigned long irq_flags;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200791
Steven Rostedt92205c22008-05-12 21:20:55 +0200792 raw_local_irq_save(irq_flags);
793 __raw_spin_lock(&data->lock);
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200794 entry = tracing_get_trace_entry(tr, data);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200795 tracing_generic_entry_update(entry, flags);
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200796 entry->type = TRACE_FN;
797 entry->fn.ip = ip;
798 entry->fn.parent_ip = parent_ip;
Steven Rostedt92205c22008-05-12 21:20:55 +0200799 __raw_spin_unlock(&data->lock);
800 raw_local_irq_restore(irq_flags);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200801}
802
Ingo Molnare309b412008-05-12 21:20:51 +0200803void
Ingo Molnar2e0f5762008-05-12 21:20:49 +0200804ftrace(struct trace_array *tr, struct trace_array_cpu *data,
805 unsigned long ip, unsigned long parent_ip, unsigned long flags)
806{
807 if (likely(!atomic_read(&data->disabled)))
Steven Rostedt6fb44b72008-05-12 21:20:49 +0200808 trace_function(tr, data, ip, parent_ip, flags);
Ingo Molnar2e0f5762008-05-12 21:20:49 +0200809}
810
Ingo Molnar86387f72008-05-12 21:20:51 +0200811void __trace_stack(struct trace_array *tr,
812 struct trace_array_cpu *data,
813 unsigned long flags,
814 int skip)
815{
816 struct trace_entry *entry;
817 struct stack_trace trace;
818
819 if (!(trace_flags & TRACE_ITER_STACKTRACE))
820 return;
821
822 entry = tracing_get_trace_entry(tr, data);
823 tracing_generic_entry_update(entry, flags);
824 entry->type = TRACE_STACK;
825
826 memset(&entry->stack, 0, sizeof(entry->stack));
827
828 trace.nr_entries = 0;
829 trace.max_entries = FTRACE_STACK_ENTRIES;
830 trace.skip = skip;
831 trace.entries = entry->stack.caller;
832
833 save_stack_trace(&trace);
Ingo Molnarf0a920d2008-05-12 21:20:47 +0200834}
835
Ingo Molnare309b412008-05-12 21:20:51 +0200836void
Ingo Molnara4feb832008-05-12 21:21:02 +0200837__trace_special(void *__tr, void *__data,
838 unsigned long arg1, unsigned long arg2, unsigned long arg3)
839{
840 struct trace_array_cpu *data = __data;
841 struct trace_array *tr = __tr;
842 struct trace_entry *entry;
843 unsigned long irq_flags;
844
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);
856
857 trace_wake_up();
858}
859
860void
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200861tracing_sched_switch_trace(struct trace_array *tr,
862 struct trace_array_cpu *data,
Ingo Molnar86387f72008-05-12 21:20:51 +0200863 struct task_struct *prev,
864 struct task_struct *next,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200865 unsigned long flags)
866{
867 struct trace_entry *entry;
Ingo Molnardcb63082008-05-12 21:20:48 +0200868 unsigned long irq_flags;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200869
Steven Rostedt92205c22008-05-12 21:20:55 +0200870 raw_local_irq_save(irq_flags);
871 __raw_spin_lock(&data->lock);
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200872 entry = tracing_get_trace_entry(tr, data);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200873 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;
Peter Zijlstrabac524d2008-05-12 21:20:53 +0200880 entry->ctx.next_state = next->state;
Ingo Molnar86387f72008-05-12 21:20:51 +0200881 __trace_stack(tr, data, flags, 4);
Steven Rostedt92205c22008-05-12 21:20:55 +0200882 __raw_spin_unlock(&data->lock);
883 raw_local_irq_restore(irq_flags);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200884}
885
Ingo Molnar57422792008-05-12 21:20:51 +0200886void
887tracing_sched_wakeup_trace(struct trace_array *tr,
888 struct trace_array_cpu *data,
Ingo Molnar86387f72008-05-12 21:20:51 +0200889 struct task_struct *wakee,
890 struct task_struct *curr,
Ingo Molnar57422792008-05-12 21:20:51 +0200891 unsigned long flags)
892{
893 struct trace_entry *entry;
894 unsigned long irq_flags;
895
Steven Rostedt92205c22008-05-12 21:20:55 +0200896 raw_local_irq_save(irq_flags);
897 __raw_spin_lock(&data->lock);
Ingo Molnar57422792008-05-12 21:20:51 +0200898 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;
Peter Zijlstrabac524d2008-05-12 21:20:53 +0200906 entry->ctx.next_state = wakee->state;
Ingo Molnar86387f72008-05-12 21:20:51 +0200907 __trace_stack(tr, data, flags, 5);
Steven Rostedt92205c22008-05-12 21:20:55 +0200908 __raw_spin_unlock(&data->lock);
909 raw_local_irq_restore(irq_flags);
Ingo Molnar017730c2008-05-12 21:20:52 +0200910
911 trace_wake_up();
Ingo Molnar57422792008-05-12 21:20:51 +0200912}
913
Ingo Molnar2e0f5762008-05-12 21:20:49 +0200914#ifdef CONFIG_FTRACE
Ingo Molnare309b412008-05-12 21:20:51 +0200915static void
Ingo Molnar2e0f5762008-05-12 21:20:49 +0200916function_trace_call(unsigned long ip, unsigned long parent_ip)
917{
918 struct trace_array *tr = &global_trace;
919 struct trace_array_cpu *data;
920 unsigned long flags;
921 long disabled;
922 int cpu;
923
924 if (unlikely(!tracer_enabled))
925 return;
926
927 local_irq_save(flags);
928 cpu = raw_smp_processor_id();
929 data = tr->data[cpu];
930 disabled = atomic_inc_return(&data->disabled);
931
932 if (likely(disabled == 1))
Steven Rostedt6fb44b72008-05-12 21:20:49 +0200933 trace_function(tr, data, ip, parent_ip, flags);
Ingo Molnar2e0f5762008-05-12 21:20:49 +0200934
935 atomic_dec(&data->disabled);
936 local_irq_restore(flags);
937}
938
939static struct ftrace_ops trace_ops __read_mostly =
940{
941 .func = function_trace_call,
942};
943
Ingo Molnare309b412008-05-12 21:20:51 +0200944void tracing_start_function_trace(void)
Ingo Molnar2e0f5762008-05-12 21:20:49 +0200945{
946 register_ftrace_function(&trace_ops);
947}
948
Ingo Molnare309b412008-05-12 21:20:51 +0200949void tracing_stop_function_trace(void)
Ingo Molnar2e0f5762008-05-12 21:20:49 +0200950{
951 unregister_ftrace_function(&trace_ops);
952}
953#endif
954
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200955enum trace_file_type {
956 TRACE_FILE_LAT_FMT = 1,
957};
958
959static struct trace_entry *
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200960trace_entry_idx(struct trace_array *tr, struct trace_array_cpu *data,
961 struct trace_iterator *iter, int cpu)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200962{
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200963 struct page *page;
964 struct trace_entry *array;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200965
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200966 if (iter->next_idx[cpu] >= tr->entries ||
Steven Rostedtb3806b42008-05-12 21:20:46 +0200967 iter->next_idx[cpu] >= data->trace_idx ||
968 (data->trace_head == data->trace_tail &&
969 data->trace_head_idx == data->trace_tail_idx))
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200970 return NULL;
971
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200972 if (!iter->next_page[cpu]) {
Steven Rostedt93a588f2008-05-12 21:20:45 +0200973 /* 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;
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200978 }
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200979
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200980 page = list_entry(iter->next_page[cpu], struct page, lru);
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200981 BUG_ON(&data->trace_pages == &page->lru);
982
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200983 array = page_address(page);
984
Steven Rostedt93a588f2008-05-12 21:20:45 +0200985 WARN_ON(iter->next_page_idx[cpu] >= ENTRIES_PER_PAGE);
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200986 return &array[iter->next_page_idx[cpu]];
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200987}
988
Ingo Molnare309b412008-05-12 21:20:51 +0200989static struct trace_entry *
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200990find_next_entry(struct trace_iterator *iter, int *ent_cpu)
991{
992 struct trace_array *tr = iter->tr;
993 struct trace_entry *ent, *next = NULL;
994 int next_cpu = -1;
995 int cpu;
996
Steven Rostedtab464282008-05-12 21:21:00 +0200997 for_each_tracing_cpu(cpu) {
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200998 if (!head_page(tr->data[cpu]))
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200999 continue;
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02001000 ent = trace_entry_idx(tr, tr->data[cpu], iter, cpu);
Ingo Molnarcdd31cd2008-05-12 21:20:46 +02001001 /*
1002 * Pick the entry with the smallest timestamp:
1003 */
1004 if (ent && (!next || ent->t < next->t)) {
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001005 next = ent;
1006 next_cpu = cpu;
1007 }
1008 }
1009
1010 if (ent_cpu)
1011 *ent_cpu = next_cpu;
1012
1013 return next;
1014}
1015
Ingo Molnare309b412008-05-12 21:20:51 +02001016static void trace_iterator_increment(struct trace_iterator *iter)
Steven Rostedtb3806b42008-05-12 21:20:46 +02001017{
1018 iter->idx++;
1019 iter->next_idx[iter->cpu]++;
1020 iter->next_page_idx[iter->cpu]++;
Ingo Molnar8c523a92008-05-12 21:20:46 +02001021
Steven Rostedtb3806b42008-05-12 21:20:46 +02001022 if (iter->next_page_idx[iter->cpu] >= ENTRIES_PER_PAGE) {
1023 struct trace_array_cpu *data = iter->tr->data[iter->cpu];
1024
1025 iter->next_page_idx[iter->cpu] = 0;
1026 iter->next_page[iter->cpu] =
1027 trace_next_list(data, iter->next_page[iter->cpu]);
1028 }
1029}
1030
Ingo Molnare309b412008-05-12 21:20:51 +02001031static void trace_consume(struct trace_iterator *iter)
Steven Rostedtb3806b42008-05-12 21:20:46 +02001032{
1033 struct trace_array_cpu *data = iter->tr->data[iter->cpu];
1034
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;
1039 }
1040
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;
Steven Rostedtb3806b42008-05-12 21:20:46 +02001045}
1046
Ingo Molnare309b412008-05-12 21:20:51 +02001047static void *find_next_entry_inc(struct trace_iterator *iter)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001048{
1049 struct trace_entry *next;
1050 int next_cpu = -1;
1051
1052 next = find_next_entry(iter, &next_cpu);
1053
Ingo Molnar4e3c3332008-05-12 21:20:45 +02001054 iter->prev_ent = iter->ent;
1055 iter->prev_cpu = iter->cpu;
1056
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001057 iter->ent = next;
1058 iter->cpu = next_cpu;
1059
Steven Rostedtb3806b42008-05-12 21:20:46 +02001060 if (next)
1061 trace_iterator_increment(iter);
1062
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001063 return next ? iter : NULL;
1064}
1065
Ingo Molnare309b412008-05-12 21:20:51 +02001066static void *s_next(struct seq_file *m, void *v, loff_t *pos)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001067{
1068 struct trace_iterator *iter = m->private;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001069 void *last_ent = iter->ent;
1070 int i = (int)*pos;
Ingo Molnar4e3c3332008-05-12 21:20:45 +02001071 void *ent;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001072
1073 (*pos)++;
1074
1075 /* can't go backwards */
1076 if (iter->idx > i)
1077 return NULL;
1078
1079 if (iter->idx < 0)
1080 ent = find_next_entry_inc(iter);
1081 else
1082 ent = iter;
1083
1084 while (ent && iter->idx < i)
1085 ent = find_next_entry_inc(iter);
1086
1087 iter->pos = *pos;
1088
1089 if (last_ent && !ent)
1090 seq_puts(m, "\n\nvim:ft=help\n");
1091
1092 return ent;
1093}
1094
1095static void *s_start(struct seq_file *m, loff_t *pos)
1096{
1097 struct trace_iterator *iter = m->private;
1098 void *p = NULL;
1099 loff_t l = 0;
1100 int i;
1101
1102 mutex_lock(&trace_types_lock);
1103
Steven Rostedtd15f57f2008-05-12 21:20:56 +02001104 if (!current_trace || current_trace != iter->trace) {
1105 mutex_unlock(&trace_types_lock);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001106 return NULL;
Steven Rostedtd15f57f2008-05-12 21:20:56 +02001107 }
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001108
1109 atomic_inc(&trace_record_cmdline_disabled);
1110
1111 /* let the tracer grab locks here if needed */
1112 if (current_trace->start)
1113 current_trace->start(iter);
1114
1115 if (*pos != iter->pos) {
1116 iter->ent = NULL;
1117 iter->cpu = 0;
1118 iter->idx = -1;
Ingo Molnar4e3c3332008-05-12 21:20:45 +02001119 iter->prev_ent = NULL;
1120 iter->prev_cpu = -1;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001121
Steven Rostedtab464282008-05-12 21:21:00 +02001122 for_each_tracing_cpu(i) {
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001123 iter->next_idx[i] = 0;
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02001124 iter->next_page[i] = NULL;
1125 }
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001126
1127 for (p = iter; p && l < *pos; p = s_next(m, p, &l))
1128 ;
1129
1130 } else {
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02001131 l = *pos - 1;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001132 p = s_next(m, p, &l);
1133 }
1134
1135 return p;
1136}
1137
1138static void s_stop(struct seq_file *m, void *p)
1139{
1140 struct trace_iterator *iter = m->private;
1141
1142 atomic_dec(&trace_record_cmdline_disabled);
1143
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);
1147
1148 mutex_unlock(&trace_types_lock);
1149}
1150
Steven Rostedtb3806b42008-05-12 21:20:46 +02001151static int
Steven Rostedt214023c2008-05-12 21:20:46 +02001152seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001153{
1154#ifdef CONFIG_KALLSYMS
1155 char str[KSYM_SYMBOL_LEN];
1156
1157 kallsyms_lookup(address, NULL, NULL, NULL, str);
1158
Steven Rostedtb3806b42008-05-12 21:20:46 +02001159 return trace_seq_printf(s, fmt, str);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001160#endif
Steven Rostedtb3806b42008-05-12 21:20:46 +02001161 return 1;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001162}
1163
Steven Rostedtb3806b42008-05-12 21:20:46 +02001164static int
Steven Rostedt214023c2008-05-12 21:20:46 +02001165seq_print_sym_offset(struct trace_seq *s, const char *fmt,
1166 unsigned long address)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001167{
1168#ifdef CONFIG_KALLSYMS
1169 char str[KSYM_SYMBOL_LEN];
1170
1171 sprint_symbol(str, address);
Steven Rostedtb3806b42008-05-12 21:20:46 +02001172 return trace_seq_printf(s, fmt, str);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001173#endif
Steven Rostedtb3806b42008-05-12 21:20:46 +02001174 return 1;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001175}
1176
1177#ifndef CONFIG_64BIT
1178# define IP_FMT "%08lx"
1179#else
1180# define IP_FMT "%016lx"
1181#endif
1182
Ingo Molnare309b412008-05-12 21:20:51 +02001183static int
Steven Rostedt214023c2008-05-12 21:20:46 +02001184seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001185{
Steven Rostedtb3806b42008-05-12 21:20:46 +02001186 int ret;
1187
1188 if (!ip)
1189 return trace_seq_printf(s, "0");
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001190
1191 if (sym_flags & TRACE_ITER_SYM_OFFSET)
Steven Rostedtb3806b42008-05-12 21:20:46 +02001192 ret = seq_print_sym_offset(s, "%s", ip);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001193 else
Steven Rostedtb3806b42008-05-12 21:20:46 +02001194 ret = seq_print_sym_short(s, "%s", ip);
1195
1196 if (!ret)
1197 return 0;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001198
1199 if (sym_flags & TRACE_ITER_SYM_ADDR)
Steven Rostedtb3806b42008-05-12 21:20:46 +02001200 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
1201 return ret;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001202}
1203
Ingo Molnare309b412008-05-12 21:20:51 +02001204static void print_lat_help_header(struct seq_file *m)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001205{
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");
1215}
1216
Ingo Molnare309b412008-05-12 21:20:51 +02001217static void print_func_help_header(struct seq_file *m)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001218{
1219 seq_puts(m, "# TASK-PID CPU# TIMESTAMP FUNCTION\n");
1220 seq_puts(m, "# | | | | |\n");
1221}
1222
1223
Ingo Molnare309b412008-05-12 21:20:51 +02001224static void
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001225print_trace_header(struct seq_file *m, struct trace_iterator *iter)
1226{
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;
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02001231 unsigned long total = 0;
1232 unsigned long entries = 0;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001233 int cpu;
1234 const char *name = "preemption";
1235
1236 if (type)
1237 name = type->name;
1238
Steven Rostedtab464282008-05-12 21:21:00 +02001239 for_each_tracing_cpu(cpu) {
Ingo Molnarc7aafc52008-05-12 21:20:45 +02001240 if (head_page(tr->data[cpu])) {
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02001241 total += tr->data[cpu]->trace_idx;
1242 if (tr->data[cpu]->trace_idx > tr->entries)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001243 entries += tr->entries;
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02001244 else
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001245 entries += tr->data[cpu]->trace_idx;
1246 }
1247 }
1248
1249 seq_printf(m, "%s latency trace v1.1.5 on %s\n",
1250 name, UTS_RELEASE);
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",
Steven Rostedt57f50be2008-05-12 21:20:44 +02001255 nsecs_to_usecs(data->saved_latency),
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001256 entries,
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02001257 total,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001258 tr->cpu,
1259#if defined(CONFIG_PREEMPT_NONE)
1260 "server",
1261#elif defined(CONFIG_PREEMPT_VOLUNTARY)
1262 "desktop",
1263#elif defined(CONFIG_PREEMPT_DESKTOP)
1264 "preempt",
1265#else
1266 "unknown",
1267#endif
1268 /* These are reserved for later use */
1269 0, 0, 0, 0);
1270#ifdef CONFIG_SMP
1271 seq_printf(m, " #P:%d)\n", num_online_cpus());
1272#else
1273 seq_puts(m, ")\n");
1274#endif
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");
1281
1282 if (data->critical_start) {
1283 seq_puts(m, " => started at: ");
Steven Rostedt214023c2008-05-12 21:20:46 +02001284 seq_print_ip_sym(&iter->seq, data->critical_start, sym_flags);
1285 trace_print_seq(m, &iter->seq);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001286 seq_puts(m, "\n => ended at: ");
Steven Rostedt214023c2008-05-12 21:20:46 +02001287 seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags);
1288 trace_print_seq(m, &iter->seq);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001289 seq_puts(m, "\n");
1290 }
1291
1292 seq_puts(m, "\n");
1293}
1294
Ingo Molnare309b412008-05-12 21:20:51 +02001295static void
Steven Rostedt214023c2008-05-12 21:20:46 +02001296lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001297{
1298 int hardirq, softirq;
1299 char *comm;
1300
1301 comm = trace_find_cmdline(entry->pid);
1302
Steven Rostedt214023c2008-05-12 21:20:46 +02001303 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' : '.'));
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001308
1309 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
1310 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
Ingo Molnarafc2abc2008-05-12 21:21:00 +02001311 if (hardirq && softirq) {
Steven Rostedt214023c2008-05-12 21:20:46 +02001312 trace_seq_putc(s, 'H');
Ingo Molnarafc2abc2008-05-12 21:21:00 +02001313 } else {
1314 if (hardirq) {
Steven Rostedt214023c2008-05-12 21:20:46 +02001315 trace_seq_putc(s, 'h');
Ingo Molnarafc2abc2008-05-12 21:21:00 +02001316 } else {
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001317 if (softirq)
Steven Rostedt214023c2008-05-12 21:20:46 +02001318 trace_seq_putc(s, 's');
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001319 else
Steven Rostedt214023c2008-05-12 21:20:46 +02001320 trace_seq_putc(s, '.');
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001321 }
1322 }
1323
1324 if (entry->preempt_count)
Steven Rostedt214023c2008-05-12 21:20:46 +02001325 trace_seq_printf(s, "%x", entry->preempt_count);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001326 else
Steven Rostedt214023c2008-05-12 21:20:46 +02001327 trace_seq_puts(s, ".");
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001328}
1329
1330unsigned long preempt_mark_thresh = 100;
1331
Ingo Molnare309b412008-05-12 21:20:51 +02001332static void
Steven Rostedt214023c2008-05-12 21:20:46 +02001333lat_print_timestamp(struct trace_seq *s, unsigned long long abs_usecs,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001334 unsigned long rel_usecs)
1335{
Steven Rostedt214023c2008-05-12 21:20:46 +02001336 trace_seq_printf(s, " %4lldus", abs_usecs);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001337 if (rel_usecs > preempt_mark_thresh)
Steven Rostedt214023c2008-05-12 21:20:46 +02001338 trace_seq_puts(s, "!: ");
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001339 else if (rel_usecs > 1)
Steven Rostedt214023c2008-05-12 21:20:46 +02001340 trace_seq_puts(s, "+: ");
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001341 else
Steven Rostedt214023c2008-05-12 21:20:46 +02001342 trace_seq_puts(s, " : ");
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001343}
1344
1345static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
1346
Ingo Molnare309b412008-05-12 21:20:51 +02001347static int
Steven Rostedt214023c2008-05-12 21:20:46 +02001348print_lat_fmt(struct trace_iterator *iter, unsigned int trace_idx, int cpu)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001349{
Steven Rostedt214023c2008-05-12 21:20:46 +02001350 struct trace_seq *s = &iter->seq;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001351 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;
1357 char *comm;
Peter Zijlstrabac524d2008-05-12 21:20:53 +02001358 int S, T;
Ingo Molnar86387f72008-05-12 21:20:51 +02001359 int i;
Ankita Gargd17d9692008-05-12 21:20:58 +02001360 unsigned state;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001361
1362 if (!next_entry)
1363 next_entry = entry;
1364 rel_usecs = ns2usecs(next_entry->t - entry->t);
1365 abs_usecs = ns2usecs(entry->t - iter->tr->time_start);
1366
1367 if (verbose) {
1368 comm = trace_find_cmdline(entry->pid);
Steven Rostedt214023c2008-05-12 21:20:46 +02001369 trace_seq_printf(s, "%16s %5d %d %d %08x %08x [%08lx]"
1370 " %ld.%03ldms (+%ld.%03ldms): ",
1371 comm,
1372 entry->pid, cpu, entry->flags,
1373 entry->preempt_count, trace_idx,
1374 ns2usecs(entry->t),
1375 abs_usecs/1000,
1376 abs_usecs % 1000, rel_usecs/1000,
1377 rel_usecs % 1000);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001378 } else {
Ingo Molnarf29c73f2008-05-12 21:20:53 +02001379 lat_print_generic(s, entry, cpu);
1380 lat_print_timestamp(s, abs_usecs, rel_usecs);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001381 }
1382 switch (entry->type) {
1383 case TRACE_FN:
Steven Rostedt214023c2008-05-12 21:20:46 +02001384 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");
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001388 break;
1389 case TRACE_CTX:
Ingo Molnar57422792008-05-12 21:20:51 +02001390 case TRACE_WAKE:
Peter Zijlstrabac524d2008-05-12 21:20:53 +02001391 T = entry->ctx.next_state < sizeof(state_to_char) ?
1392 state_to_char[entry->ctx.next_state] : 'X';
1393
Ankita Gargd17d9692008-05-12 21:20:58 +02001394 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';
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001396 comm = trace_find_cmdline(entry->ctx.next_pid);
Peter Zijlstrabac524d2008-05-12 21:20:53 +02001397 trace_seq_printf(s, " %5d:%3d:%c %s %5d:%3d:%c %s\n",
Steven Rostedt214023c2008-05-12 21:20:46 +02001398 entry->ctx.prev_pid,
1399 entry->ctx.prev_prio,
Ingo Molnar57422792008-05-12 21:20:51 +02001400 S, entry->type == TRACE_CTX ? "==>" : " +",
Steven Rostedt214023c2008-05-12 21:20:46 +02001401 entry->ctx.next_pid,
1402 entry->ctx.next_prio,
Peter Zijlstrabac524d2008-05-12 21:20:53 +02001403 T, comm);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001404 break;
Ingo Molnarf0a920d2008-05-12 21:20:47 +02001405 case TRACE_SPECIAL:
Ingo Molnar88a42162008-05-12 21:20:53 +02001406 trace_seq_printf(s, "# %ld %ld %ld\n",
Ingo Molnarf0a920d2008-05-12 21:20:47 +02001407 entry->special.arg1,
1408 entry->special.arg2,
1409 entry->special.arg3);
1410 break;
Ingo Molnar86387f72008-05-12 21:20:51 +02001411 case TRACE_STACK:
1412 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
1413 if (i)
1414 trace_seq_puts(s, " <= ");
1415 seq_print_ip_sym(s, entry->stack.caller[i], sym_flags);
1416 }
1417 trace_seq_puts(s, "\n");
1418 break;
Steven Rostedt89b2f972008-05-12 21:20:44 +02001419 default:
Steven Rostedt214023c2008-05-12 21:20:46 +02001420 trace_seq_printf(s, "Unknown type %d\n", entry->type);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001421 }
Ingo Molnarf9896bf2008-05-12 21:20:47 +02001422 return 1;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001423}
1424
Ingo Molnare309b412008-05-12 21:20:51 +02001425static int print_trace_fmt(struct trace_iterator *iter)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001426{
Steven Rostedt214023c2008-05-12 21:20:46 +02001427 struct trace_seq *s = &iter->seq;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001428 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
Ingo Molnar4e3c3332008-05-12 21:20:45 +02001429 struct trace_entry *entry;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001430 unsigned long usec_rem;
1431 unsigned long long t;
1432 unsigned long secs;
1433 char *comm;
Steven Rostedtb3806b42008-05-12 21:20:46 +02001434 int ret;
Peter Zijlstrabac524d2008-05-12 21:20:53 +02001435 int S, T;
Ingo Molnar86387f72008-05-12 21:20:51 +02001436 int i;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001437
Ingo Molnar4e3c3332008-05-12 21:20:45 +02001438 entry = iter->ent;
1439
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001440 comm = trace_find_cmdline(iter->ent->pid);
1441
Ingo Molnarcdd31cd2008-05-12 21:20:46 +02001442 t = ns2usecs(entry->t);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001443 usec_rem = do_div(t, 1000000ULL);
1444 secs = (unsigned long)t;
1445
Ingo Molnarf29c73f2008-05-12 21:20:53 +02001446 ret = trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid);
1447 if (!ret)
1448 return 0;
1449 ret = trace_seq_printf(s, "[%02d] ", iter->cpu);
1450 if (!ret)
1451 return 0;
1452 ret = trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem);
1453 if (!ret)
1454 return 0;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001455
1456 switch (entry->type) {
1457 case TRACE_FN:
Steven Rostedtb3806b42008-05-12 21:20:46 +02001458 ret = seq_print_ip_sym(s, entry->fn.ip, sym_flags);
1459 if (!ret)
1460 return 0;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001461 if ((sym_flags & TRACE_ITER_PRINT_PARENT) &&
1462 entry->fn.parent_ip) {
Steven Rostedtb3806b42008-05-12 21:20:46 +02001463 ret = trace_seq_printf(s, " <-");
1464 if (!ret)
1465 return 0;
1466 ret = seq_print_ip_sym(s, entry->fn.parent_ip,
1467 sym_flags);
1468 if (!ret)
1469 return 0;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001470 }
Steven Rostedtb3806b42008-05-12 21:20:46 +02001471 ret = trace_seq_printf(s, "\n");
1472 if (!ret)
1473 return 0;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001474 break;
1475 case TRACE_CTX:
Ingo Molnar57422792008-05-12 21:20:51 +02001476 case TRACE_WAKE:
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001477 S = entry->ctx.prev_state < sizeof(state_to_char) ?
1478 state_to_char[entry->ctx.prev_state] : 'X';
Peter Zijlstrabac524d2008-05-12 21:20:53 +02001479 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",
Steven Rostedtb3806b42008-05-12 21:20:46 +02001482 entry->ctx.prev_pid,
1483 entry->ctx.prev_prio,
1484 S,
Ingo Molnar57422792008-05-12 21:20:51 +02001485 entry->type == TRACE_CTX ? "==>" : " +",
Steven Rostedtb3806b42008-05-12 21:20:46 +02001486 entry->ctx.next_pid,
Peter Zijlstrabac524d2008-05-12 21:20:53 +02001487 entry->ctx.next_prio,
1488 T);
Steven Rostedtb3806b42008-05-12 21:20:46 +02001489 if (!ret)
1490 return 0;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001491 break;
Ingo Molnarf0a920d2008-05-12 21:20:47 +02001492 case TRACE_SPECIAL:
Ingo Molnar88a42162008-05-12 21:20:53 +02001493 ret = trace_seq_printf(s, "# %ld %ld %ld\n",
Ingo Molnarf0a920d2008-05-12 21:20:47 +02001494 entry->special.arg1,
1495 entry->special.arg2,
1496 entry->special.arg3);
1497 if (!ret)
1498 return 0;
1499 break;
Ingo Molnar86387f72008-05-12 21:20:51 +02001500 case TRACE_STACK:
1501 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
1502 if (i) {
1503 ret = trace_seq_puts(s, " <= ");
1504 if (!ret)
1505 return 0;
1506 }
1507 ret = seq_print_ip_sym(s, entry->stack.caller[i],
1508 sym_flags);
1509 if (!ret)
1510 return 0;
1511 }
1512 ret = trace_seq_puts(s, "\n");
1513 if (!ret)
1514 return 0;
1515 break;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001516 }
Steven Rostedtb3806b42008-05-12 21:20:46 +02001517 return 1;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001518}
1519
Ingo Molnare309b412008-05-12 21:20:51 +02001520static int print_raw_fmt(struct trace_iterator *iter)
Ingo Molnarf9896bf2008-05-12 21:20:47 +02001521{
1522 struct trace_seq *s = &iter->seq;
1523 struct trace_entry *entry;
1524 int ret;
Peter Zijlstrabac524d2008-05-12 21:20:53 +02001525 int S, T;
Ingo Molnarf9896bf2008-05-12 21:20:47 +02001526
1527 entry = iter->ent;
1528
1529 ret = trace_seq_printf(s, "%d %d %llu ",
1530 entry->pid, iter->cpu, entry->t);
1531 if (!ret)
1532 return 0;
1533
1534 switch (entry->type) {
1535 case TRACE_FN:
1536 ret = trace_seq_printf(s, "%x %x\n",
1537 entry->fn.ip, entry->fn.parent_ip);
1538 if (!ret)
1539 return 0;
1540 break;
1541 case TRACE_CTX:
Ingo Molnar57422792008-05-12 21:20:51 +02001542 case TRACE_WAKE:
Ingo Molnarf9896bf2008-05-12 21:20:47 +02001543 S = entry->ctx.prev_state < sizeof(state_to_char) ?
1544 state_to_char[entry->ctx.prev_state] : 'X';
Peter Zijlstrabac524d2008-05-12 21:20:53 +02001545 T = entry->ctx.next_state < sizeof(state_to_char) ?
1546 state_to_char[entry->ctx.next_state] : 'X';
Ingo Molnar57422792008-05-12 21:20:51 +02001547 if (entry->type == TRACE_WAKE)
1548 S = '+';
Peter Zijlstrabac524d2008-05-12 21:20:53 +02001549 ret = trace_seq_printf(s, "%d %d %c %d %d %c\n",
Ingo Molnarf9896bf2008-05-12 21:20:47 +02001550 entry->ctx.prev_pid,
1551 entry->ctx.prev_prio,
1552 S,
1553 entry->ctx.next_pid,
Peter Zijlstrabac524d2008-05-12 21:20:53 +02001554 entry->ctx.next_prio,
1555 T);
Ingo Molnarf9896bf2008-05-12 21:20:47 +02001556 if (!ret)
1557 return 0;
1558 break;
Ingo Molnarf0a920d2008-05-12 21:20:47 +02001559 case TRACE_SPECIAL:
Ingo Molnar86387f72008-05-12 21:20:51 +02001560 case TRACE_STACK:
Ingo Molnar88a42162008-05-12 21:20:53 +02001561 ret = trace_seq_printf(s, "# %ld %ld %ld\n",
Ingo Molnarf0a920d2008-05-12 21:20:47 +02001562 entry->special.arg1,
1563 entry->special.arg2,
1564 entry->special.arg3);
1565 if (!ret)
1566 return 0;
1567 break;
Ingo Molnarf9896bf2008-05-12 21:20:47 +02001568 }
1569 return 1;
1570}
1571
Ingo Molnarcb0f12a2008-05-12 21:20:47 +02001572#define SEQ_PUT_FIELD_RET(s, x) \
1573do { \
1574 if (!trace_seq_putmem(s, &(x), sizeof(x))) \
1575 return 0; \
1576} while (0)
1577
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +02001578#define SEQ_PUT_HEX_FIELD_RET(s, x) \
1579do { \
1580 if (!trace_seq_putmem_hex(s, &(x), sizeof(x))) \
1581 return 0; \
1582} while (0)
1583
Ingo Molnare309b412008-05-12 21:20:51 +02001584static int print_hex_fmt(struct trace_iterator *iter)
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +02001585{
1586 struct trace_seq *s = &iter->seq;
1587 unsigned char newline = '\n';
1588 struct trace_entry *entry;
Peter Zijlstrabac524d2008-05-12 21:20:53 +02001589 int S, T;
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +02001590
1591 entry = iter->ent;
1592
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);
1596
1597 switch (entry->type) {
1598 case TRACE_FN:
1599 SEQ_PUT_HEX_FIELD_RET(s, entry->fn.ip);
1600 SEQ_PUT_HEX_FIELD_RET(s, entry->fn.parent_ip);
1601 break;
1602 case TRACE_CTX:
Ingo Molnar57422792008-05-12 21:20:51 +02001603 case TRACE_WAKE:
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +02001604 S = entry->ctx.prev_state < sizeof(state_to_char) ?
1605 state_to_char[entry->ctx.prev_state] : 'X';
Peter Zijlstrabac524d2008-05-12 21:20:53 +02001606 T = entry->ctx.next_state < sizeof(state_to_char) ?
1607 state_to_char[entry->ctx.next_state] : 'X';
Ingo Molnar57422792008-05-12 21:20:51 +02001608 if (entry->type == TRACE_WAKE)
1609 S = '+';
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +02001610 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);
Peter Zijlstrabac524d2008-05-12 21:20:53 +02001616 SEQ_PUT_HEX_FIELD_RET(s, T);
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +02001617 break;
1618 case TRACE_SPECIAL:
Ingo Molnar86387f72008-05-12 21:20:51 +02001619 case TRACE_STACK:
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +02001620 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);
1623 break;
1624 }
1625 SEQ_PUT_FIELD_RET(s, newline);
1626
1627 return 1;
1628}
1629
Ingo Molnare309b412008-05-12 21:20:51 +02001630static int print_bin_fmt(struct trace_iterator *iter)
Ingo Molnarcb0f12a2008-05-12 21:20:47 +02001631{
1632 struct trace_seq *s = &iter->seq;
1633 struct trace_entry *entry;
1634
1635 entry = iter->ent;
1636
1637 SEQ_PUT_FIELD_RET(s, entry->pid);
1638 SEQ_PUT_FIELD_RET(s, entry->cpu);
1639 SEQ_PUT_FIELD_RET(s, entry->t);
1640
1641 switch (entry->type) {
1642 case TRACE_FN:
1643 SEQ_PUT_FIELD_RET(s, entry->fn.ip);
1644 SEQ_PUT_FIELD_RET(s, entry->fn.parent_ip);
1645 break;
1646 case TRACE_CTX:
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);
Peter Zijlstrabac524d2008-05-12 21:20:53 +02001652 SEQ_PUT_FIELD_RET(s, entry->ctx.next_state);
Ingo Molnarcb0f12a2008-05-12 21:20:47 +02001653 break;
Ingo Molnarf0a920d2008-05-12 21:20:47 +02001654 case TRACE_SPECIAL:
Ingo Molnar86387f72008-05-12 21:20:51 +02001655 case TRACE_STACK:
Ingo Molnarf0a920d2008-05-12 21:20:47 +02001656 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);
1659 break;
Ingo Molnarcb0f12a2008-05-12 21:20:47 +02001660 }
1661 return 1;
1662}
1663
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001664static int trace_empty(struct trace_iterator *iter)
1665{
1666 struct trace_array_cpu *data;
1667 int cpu;
1668
Steven Rostedtab464282008-05-12 21:21:00 +02001669 for_each_tracing_cpu(cpu) {
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001670 data = iter->tr->data[cpu];
1671
Steven Rostedtb3806b42008-05-12 21:20:46 +02001672 if (head_page(data) && data->trace_idx &&
1673 (data->trace_tail != data->trace_head ||
1674 data->trace_tail_idx != data->trace_head_idx))
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001675 return 0;
1676 }
1677 return 1;
1678}
1679
Ingo Molnarf9896bf2008-05-12 21:20:47 +02001680static int print_trace_line(struct trace_iterator *iter)
1681{
Thomas Gleixner72829bc2008-05-23 21:37:28 +02001682 if (iter->trace && iter->trace->print_line)
1683 return iter->trace->print_line(iter);
1684
Ingo Molnarcb0f12a2008-05-12 21:20:47 +02001685 if (trace_flags & TRACE_ITER_BIN)
1686 return print_bin_fmt(iter);
1687
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +02001688 if (trace_flags & TRACE_ITER_HEX)
1689 return print_hex_fmt(iter);
1690
Ingo Molnarf9896bf2008-05-12 21:20:47 +02001691 if (trace_flags & TRACE_ITER_RAW)
1692 return print_raw_fmt(iter);
1693
1694 if (iter->iter_flags & TRACE_FILE_LAT_FMT)
1695 return print_lat_fmt(iter, iter->idx, iter->cpu);
1696
1697 return print_trace_fmt(iter);
1698}
1699
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001700static int s_show(struct seq_file *m, void *v)
1701{
1702 struct trace_iterator *iter = v;
1703
1704 if (iter->ent == NULL) {
1705 if (iter->tr) {
1706 seq_printf(m, "# tracer: %s\n", iter->trace->name);
1707 seq_puts(m, "#\n");
1708 }
1709 if (iter->iter_flags & TRACE_FILE_LAT_FMT) {
1710 /* print nothing if the buffers are empty */
1711 if (trace_empty(iter))
1712 return 0;
1713 print_trace_header(m, iter);
1714 if (!(trace_flags & TRACE_ITER_VERBOSE))
1715 print_lat_help_header(m);
1716 } else {
1717 if (!(trace_flags & TRACE_ITER_VERBOSE))
1718 print_func_help_header(m);
1719 }
1720 } else {
Ingo Molnarf9896bf2008-05-12 21:20:47 +02001721 print_trace_line(iter);
Steven Rostedt214023c2008-05-12 21:20:46 +02001722 trace_print_seq(m, &iter->seq);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001723 }
1724
1725 return 0;
1726}
1727
1728static struct seq_operations tracer_seq_ops = {
Ingo Molnar4bf39a92008-05-12 21:20:46 +02001729 .start = s_start,
1730 .next = s_next,
1731 .stop = s_stop,
1732 .show = s_show,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001733};
1734
Ingo Molnare309b412008-05-12 21:20:51 +02001735static struct trace_iterator *
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001736__tracing_open(struct inode *inode, struct file *file, int *ret)
1737{
1738 struct trace_iterator *iter;
1739
Steven Rostedt60a11772008-05-12 21:20:44 +02001740 if (tracing_disabled) {
1741 *ret = -ENODEV;
1742 return NULL;
1743 }
1744
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001745 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
1746 if (!iter) {
1747 *ret = -ENOMEM;
1748 goto out;
1749 }
1750
1751 mutex_lock(&trace_types_lock);
1752 if (current_trace && current_trace->print_max)
1753 iter->tr = &max_tr;
1754 else
1755 iter->tr = inode->i_private;
1756 iter->trace = current_trace;
1757 iter->pos = -1;
1758
1759 /* TODO stop tracer */
1760 *ret = seq_open(file, &tracer_seq_ops);
1761 if (!*ret) {
1762 struct seq_file *m = file->private_data;
1763 m->private = iter;
1764
1765 /* stop the trace while dumping */
1766 if (iter->tr->ctrl)
1767 tracer_enabled = 0;
1768
1769 if (iter->trace && iter->trace->open)
1770 iter->trace->open(iter);
1771 } else {
1772 kfree(iter);
1773 iter = NULL;
1774 }
1775 mutex_unlock(&trace_types_lock);
1776
1777 out:
1778 return iter;
1779}
1780
1781int tracing_open_generic(struct inode *inode, struct file *filp)
1782{
Steven Rostedt60a11772008-05-12 21:20:44 +02001783 if (tracing_disabled)
1784 return -ENODEV;
1785
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001786 filp->private_data = inode->i_private;
1787 return 0;
1788}
1789
1790int tracing_release(struct inode *inode, struct file *file)
1791{
1792 struct seq_file *m = (struct seq_file *)file->private_data;
1793 struct trace_iterator *iter = m->private;
1794
1795 mutex_lock(&trace_types_lock);
1796 if (iter->trace && iter->trace->close)
1797 iter->trace->close(iter);
1798
1799 /* reenable tracing if it was previously enabled */
1800 if (iter->tr->ctrl)
1801 tracer_enabled = 1;
1802 mutex_unlock(&trace_types_lock);
1803
1804 seq_release(inode, file);
1805 kfree(iter);
1806 return 0;
1807}
1808
1809static int tracing_open(struct inode *inode, struct file *file)
1810{
1811 int ret;
1812
1813 __tracing_open(inode, file, &ret);
1814
1815 return ret;
1816}
1817
1818static int tracing_lt_open(struct inode *inode, struct file *file)
1819{
1820 struct trace_iterator *iter;
1821 int ret;
1822
1823 iter = __tracing_open(inode, file, &ret);
1824
1825 if (!ret)
1826 iter->iter_flags |= TRACE_FILE_LAT_FMT;
1827
1828 return ret;
1829}
1830
1831
Ingo Molnare309b412008-05-12 21:20:51 +02001832static void *
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001833t_next(struct seq_file *m, void *v, loff_t *pos)
1834{
1835 struct tracer *t = m->private;
1836
1837 (*pos)++;
1838
1839 if (t)
1840 t = t->next;
1841
1842 m->private = t;
1843
1844 return t;
1845}
1846
1847static void *t_start(struct seq_file *m, loff_t *pos)
1848{
1849 struct tracer *t = m->private;
1850 loff_t l = 0;
1851
1852 mutex_lock(&trace_types_lock);
1853 for (; t && l < *pos; t = t_next(m, t, &l))
1854 ;
1855
1856 return t;
1857}
1858
1859static void t_stop(struct seq_file *m, void *p)
1860{
1861 mutex_unlock(&trace_types_lock);
1862}
1863
1864static int t_show(struct seq_file *m, void *v)
1865{
1866 struct tracer *t = v;
1867
1868 if (!t)
1869 return 0;
1870
1871 seq_printf(m, "%s", t->name);
1872 if (t->next)
1873 seq_putc(m, ' ');
1874 else
1875 seq_putc(m, '\n');
1876
1877 return 0;
1878}
1879
1880static struct seq_operations show_traces_seq_ops = {
Ingo Molnar4bf39a92008-05-12 21:20:46 +02001881 .start = t_start,
1882 .next = t_next,
1883 .stop = t_stop,
1884 .show = t_show,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001885};
1886
1887static int show_traces_open(struct inode *inode, struct file *file)
1888{
1889 int ret;
1890
Steven Rostedt60a11772008-05-12 21:20:44 +02001891 if (tracing_disabled)
1892 return -ENODEV;
1893
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001894 ret = seq_open(file, &show_traces_seq_ops);
1895 if (!ret) {
1896 struct seq_file *m = file->private_data;
1897 m->private = trace_types;
1898 }
1899
1900 return ret;
1901}
1902
1903static struct file_operations tracing_fops = {
Ingo Molnar4bf39a92008-05-12 21:20:46 +02001904 .open = tracing_open,
1905 .read = seq_read,
1906 .llseek = seq_lseek,
1907 .release = tracing_release,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001908};
1909
1910static struct file_operations tracing_lt_fops = {
Ingo Molnar4bf39a92008-05-12 21:20:46 +02001911 .open = tracing_lt_open,
1912 .read = seq_read,
1913 .llseek = seq_lseek,
1914 .release = tracing_release,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001915};
1916
1917static struct file_operations show_traces_fops = {
Ingo Molnarc7078de2008-05-12 21:20:52 +02001918 .open = show_traces_open,
1919 .read = seq_read,
1920 .release = seq_release,
1921};
1922
Ingo Molnar36dfe922008-05-12 21:20:52 +02001923/*
1924 * Only trace on a CPU if the bitmask is set:
1925 */
1926static cpumask_t tracing_cpumask = CPU_MASK_ALL;
1927
1928/*
1929 * When tracing/tracing_cpu_mask is modified then this holds
1930 * the new bitmask we are about to install:
1931 */
1932static cpumask_t tracing_cpumask_new;
1933
1934/*
1935 * The tracer itself will not take this lock, but still we want
1936 * to provide a consistent cpumask to user-space:
1937 */
1938static DEFINE_MUTEX(tracing_cpumask_update_lock);
1939
1940/*
1941 * Temporary storage for the character representation of the
1942 * CPU bitmask (and one more byte for the newline):
1943 */
1944static char mask_str[NR_CPUS + 1];
1945
Ingo Molnarc7078de2008-05-12 21:20:52 +02001946static ssize_t
1947tracing_cpumask_read(struct file *filp, char __user *ubuf,
1948 size_t count, loff_t *ppos)
1949{
Ingo Molnar36dfe922008-05-12 21:20:52 +02001950 int len;
Ingo Molnarc7078de2008-05-12 21:20:52 +02001951
1952 mutex_lock(&tracing_cpumask_update_lock);
Ingo Molnar36dfe922008-05-12 21:20:52 +02001953
1954 len = cpumask_scnprintf(mask_str, count, tracing_cpumask);
1955 if (count - len < 2) {
1956 count = -EINVAL;
1957 goto out_err;
1958 }
1959 len += sprintf(mask_str + len, "\n");
1960 count = simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+1);
1961
1962out_err:
Ingo Molnarc7078de2008-05-12 21:20:52 +02001963 mutex_unlock(&tracing_cpumask_update_lock);
1964
1965 return count;
1966}
1967
1968static ssize_t
1969tracing_cpumask_write(struct file *filp, const char __user *ubuf,
1970 size_t count, loff_t *ppos)
1971{
Ingo Molnar36dfe922008-05-12 21:20:52 +02001972 int err, cpu;
Ingo Molnarc7078de2008-05-12 21:20:52 +02001973
1974 mutex_lock(&tracing_cpumask_update_lock);
Ingo Molnar36dfe922008-05-12 21:20:52 +02001975 err = cpumask_parse_user(ubuf, count, tracing_cpumask_new);
1976 if (err)
1977 goto err_unlock;
1978
Steven Rostedt92205c22008-05-12 21:20:55 +02001979 raw_local_irq_disable();
1980 __raw_spin_lock(&ftrace_max_lock);
Steven Rostedtab464282008-05-12 21:21:00 +02001981 for_each_tracing_cpu(cpu) {
Ingo Molnar36dfe922008-05-12 21:20:52 +02001982 /*
1983 * Increase/decrease the disabled counter if we are
1984 * about to flip a bit in the cpumask:
1985 */
1986 if (cpu_isset(cpu, tracing_cpumask) &&
1987 !cpu_isset(cpu, tracing_cpumask_new)) {
1988 atomic_inc(&global_trace.data[cpu]->disabled);
1989 }
1990 if (!cpu_isset(cpu, tracing_cpumask) &&
1991 cpu_isset(cpu, tracing_cpumask_new)) {
1992 atomic_dec(&global_trace.data[cpu]->disabled);
1993 }
1994 }
Steven Rostedt92205c22008-05-12 21:20:55 +02001995 __raw_spin_unlock(&ftrace_max_lock);
1996 raw_local_irq_enable();
Ingo Molnar36dfe922008-05-12 21:20:52 +02001997
1998 tracing_cpumask = tracing_cpumask_new;
1999
Ingo Molnarc7078de2008-05-12 21:20:52 +02002000 mutex_unlock(&tracing_cpumask_update_lock);
2001
Ingo Molnarc7078de2008-05-12 21:20:52 +02002002 return count;
Ingo Molnar36dfe922008-05-12 21:20:52 +02002003
2004err_unlock:
2005 mutex_unlock(&tracing_cpumask_update_lock);
2006
2007 return err;
Ingo Molnarc7078de2008-05-12 21:20:52 +02002008}
2009
2010static struct file_operations tracing_cpumask_fops = {
2011 .open = tracing_open_generic,
2012 .read = tracing_cpumask_read,
2013 .write = tracing_cpumask_write,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002014};
2015
2016static ssize_t
2017tracing_iter_ctrl_read(struct file *filp, char __user *ubuf,
2018 size_t cnt, loff_t *ppos)
2019{
2020 char *buf;
2021 int r = 0;
2022 int len = 0;
2023 int i;
2024
2025 /* calulate max size */
2026 for (i = 0; trace_options[i]; i++) {
2027 len += strlen(trace_options[i]);
2028 len += 3; /* "no" and space */
2029 }
2030
2031 /* +2 for \n and \0 */
2032 buf = kmalloc(len + 2, GFP_KERNEL);
2033 if (!buf)
2034 return -ENOMEM;
2035
2036 for (i = 0; trace_options[i]; i++) {
2037 if (trace_flags & (1 << i))
2038 r += sprintf(buf + r, "%s ", trace_options[i]);
2039 else
2040 r += sprintf(buf + r, "no%s ", trace_options[i]);
2041 }
2042
2043 r += sprintf(buf + r, "\n");
2044 WARN_ON(r >= len + 2);
2045
Ingo Molnar36dfe922008-05-12 21:20:52 +02002046 r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002047
2048 kfree(buf);
2049
2050 return r;
2051}
2052
2053static ssize_t
2054tracing_iter_ctrl_write(struct file *filp, const char __user *ubuf,
2055 size_t cnt, loff_t *ppos)
2056{
2057 char buf[64];
2058 char *cmp = buf;
2059 int neg = 0;
2060 int i;
2061
Steven Rostedtcffae432008-05-12 21:21:00 +02002062 if (cnt >= sizeof(buf))
2063 return -EINVAL;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002064
2065 if (copy_from_user(&buf, ubuf, cnt))
2066 return -EFAULT;
2067
2068 buf[cnt] = 0;
2069
2070 if (strncmp(buf, "no", 2) == 0) {
2071 neg = 1;
2072 cmp += 2;
2073 }
2074
2075 for (i = 0; trace_options[i]; i++) {
2076 int len = strlen(trace_options[i]);
2077
2078 if (strncmp(cmp, trace_options[i], len) == 0) {
2079 if (neg)
2080 trace_flags &= ~(1 << i);
2081 else
2082 trace_flags |= (1 << i);
2083 break;
2084 }
2085 }
Ingo Molnar442e5442008-05-12 21:20:53 +02002086 /*
2087 * If no option could be set, return an error:
2088 */
2089 if (!trace_options[i])
2090 return -EINVAL;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002091
2092 filp->f_pos += cnt;
2093
2094 return cnt;
2095}
2096
2097static struct file_operations tracing_iter_fops = {
Ingo Molnarc7078de2008-05-12 21:20:52 +02002098 .open = tracing_open_generic,
2099 .read = tracing_iter_ctrl_read,
2100 .write = tracing_iter_ctrl_write,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002101};
2102
Ingo Molnar7bd2f242008-05-12 21:20:45 +02002103static const char readme_msg[] =
2104 "tracing mini-HOWTO:\n\n"
2105 "# mkdir /debug\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"
2110 "none\n"
2111 "# echo sched_switch > /debug/tracing/current_tracer\n"
2112 "# cat /debug/tracing/current_tracer\n"
2113 "sched_switch\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"
2120;
2121
2122static ssize_t
2123tracing_readme_read(struct file *filp, char __user *ubuf,
2124 size_t cnt, loff_t *ppos)
2125{
2126 return simple_read_from_buffer(ubuf, cnt, ppos,
2127 readme_msg, strlen(readme_msg));
2128}
2129
2130static struct file_operations tracing_readme_fops = {
Ingo Molnarc7078de2008-05-12 21:20:52 +02002131 .open = tracing_open_generic,
2132 .read = tracing_readme_read,
Ingo Molnar7bd2f242008-05-12 21:20:45 +02002133};
2134
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002135static ssize_t
2136tracing_ctrl_read(struct file *filp, char __user *ubuf,
2137 size_t cnt, loff_t *ppos)
2138{
2139 struct trace_array *tr = filp->private_data;
2140 char buf[64];
2141 int r;
2142
2143 r = sprintf(buf, "%ld\n", tr->ctrl);
Ingo Molnar4e3c3332008-05-12 21:20:45 +02002144 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002145}
2146
2147static ssize_t
2148tracing_ctrl_write(struct file *filp, const char __user *ubuf,
2149 size_t cnt, loff_t *ppos)
2150{
2151 struct trace_array *tr = filp->private_data;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002152 char buf[64];
Steven Rostedtc6caeeb2008-05-12 21:21:00 +02002153 long val;
2154 int ret;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002155
Steven Rostedtcffae432008-05-12 21:21:00 +02002156 if (cnt >= sizeof(buf))
2157 return -EINVAL;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002158
2159 if (copy_from_user(&buf, ubuf, cnt))
2160 return -EFAULT;
2161
2162 buf[cnt] = 0;
2163
Steven Rostedtc6caeeb2008-05-12 21:21:00 +02002164 ret = strict_strtoul(buf, 10, &val);
2165 if (ret < 0)
2166 return ret;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002167
2168 val = !!val;
2169
2170 mutex_lock(&trace_types_lock);
2171 if (tr->ctrl ^ val) {
2172 if (val)
2173 tracer_enabled = 1;
2174 else
2175 tracer_enabled = 0;
2176
2177 tr->ctrl = val;
2178
2179 if (current_trace && current_trace->ctrl_update)
2180 current_trace->ctrl_update(tr);
2181 }
2182 mutex_unlock(&trace_types_lock);
2183
2184 filp->f_pos += cnt;
2185
2186 return cnt;
2187}
2188
2189static ssize_t
2190tracing_set_trace_read(struct file *filp, char __user *ubuf,
2191 size_t cnt, loff_t *ppos)
2192{
2193 char buf[max_tracer_type_len+2];
2194 int r;
2195
2196 mutex_lock(&trace_types_lock);
2197 if (current_trace)
2198 r = sprintf(buf, "%s\n", current_trace->name);
2199 else
2200 r = sprintf(buf, "\n");
2201 mutex_unlock(&trace_types_lock);
2202
Ingo Molnar4bf39a92008-05-12 21:20:46 +02002203 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002204}
2205
2206static ssize_t
2207tracing_set_trace_write(struct file *filp, const char __user *ubuf,
2208 size_t cnt, loff_t *ppos)
2209{
2210 struct trace_array *tr = &global_trace;
2211 struct tracer *t;
2212 char buf[max_tracer_type_len+1];
2213 int i;
2214
2215 if (cnt > max_tracer_type_len)
2216 cnt = max_tracer_type_len;
2217
2218 if (copy_from_user(&buf, ubuf, cnt))
2219 return -EFAULT;
2220
2221 buf[cnt] = 0;
2222
2223 /* strip ending whitespace. */
2224 for (i = cnt - 1; i > 0 && isspace(buf[i]); i--)
2225 buf[i] = 0;
2226
2227 mutex_lock(&trace_types_lock);
2228 for (t = trace_types; t; t = t->next) {
2229 if (strcmp(t->name, buf) == 0)
2230 break;
2231 }
2232 if (!t || t == current_trace)
2233 goto out;
2234
2235 if (current_trace && current_trace->reset)
2236 current_trace->reset(tr);
2237
2238 current_trace = t;
2239 if (t->init)
2240 t->init(tr);
2241
2242 out:
2243 mutex_unlock(&trace_types_lock);
2244
2245 filp->f_pos += cnt;
2246
2247 return cnt;
2248}
2249
2250static ssize_t
2251tracing_max_lat_read(struct file *filp, char __user *ubuf,
2252 size_t cnt, loff_t *ppos)
2253{
2254 unsigned long *ptr = filp->private_data;
2255 char buf[64];
2256 int r;
2257
Steven Rostedtcffae432008-05-12 21:21:00 +02002258 r = snprintf(buf, sizeof(buf), "%ld\n",
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002259 *ptr == (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr));
Steven Rostedtcffae432008-05-12 21:21:00 +02002260 if (r > sizeof(buf))
2261 r = sizeof(buf);
Ingo Molnar4bf39a92008-05-12 21:20:46 +02002262 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002263}
2264
2265static ssize_t
2266tracing_max_lat_write(struct file *filp, const char __user *ubuf,
2267 size_t cnt, loff_t *ppos)
2268{
2269 long *ptr = filp->private_data;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002270 char buf[64];
Steven Rostedtc6caeeb2008-05-12 21:21:00 +02002271 long val;
2272 int ret;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002273
Steven Rostedtcffae432008-05-12 21:21:00 +02002274 if (cnt >= sizeof(buf))
2275 return -EINVAL;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002276
2277 if (copy_from_user(&buf, ubuf, cnt))
2278 return -EFAULT;
2279
2280 buf[cnt] = 0;
2281
Steven Rostedtc6caeeb2008-05-12 21:21:00 +02002282 ret = strict_strtoul(buf, 10, &val);
2283 if (ret < 0)
2284 return ret;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002285
2286 *ptr = val * 1000;
2287
2288 return cnt;
2289}
2290
Steven Rostedtb3806b42008-05-12 21:20:46 +02002291static atomic_t tracing_reader;
2292
2293static int tracing_open_pipe(struct inode *inode, struct file *filp)
2294{
2295 struct trace_iterator *iter;
2296
2297 if (tracing_disabled)
2298 return -ENODEV;
2299
2300 /* We only allow for reader of the pipe */
2301 if (atomic_inc_return(&tracing_reader) != 1) {
2302 atomic_dec(&tracing_reader);
2303 return -EBUSY;
2304 }
2305
2306 /* create a buffer to store the information to pass to userspace */
2307 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
2308 if (!iter)
2309 return -ENOMEM;
2310
Steven Rostedt107bad82008-05-12 21:21:01 +02002311 mutex_lock(&trace_types_lock);
Steven Rostedtb3806b42008-05-12 21:20:46 +02002312 iter->tr = &global_trace;
Thomas Gleixner72829bc2008-05-23 21:37:28 +02002313 iter->trace = current_trace;
Steven Rostedtb3806b42008-05-12 21:20:46 +02002314 filp->private_data = iter;
2315
Steven Rostedt107bad82008-05-12 21:21:01 +02002316 if (iter->trace->pipe_open)
2317 iter->trace->pipe_open(iter);
2318 mutex_unlock(&trace_types_lock);
2319
Steven Rostedtb3806b42008-05-12 21:20:46 +02002320 return 0;
2321}
2322
2323static int tracing_release_pipe(struct inode *inode, struct file *file)
2324{
2325 struct trace_iterator *iter = file->private_data;
2326
2327 kfree(iter);
2328 atomic_dec(&tracing_reader);
2329
2330 return 0;
2331}
2332
Soeren Sandmann Pedersen2a2cc8f2008-05-12 21:20:49 +02002333static unsigned int
2334tracing_poll_pipe(struct file *filp, poll_table *poll_table)
2335{
2336 struct trace_iterator *iter = filp->private_data;
2337
2338 if (trace_flags & TRACE_ITER_BLOCK) {
2339 /*
2340 * Always select as readable when in blocking mode
2341 */
2342 return POLLIN | POLLRDNORM;
Ingo Molnarafc2abc2008-05-12 21:21:00 +02002343 } else {
Soeren Sandmann Pedersen2a2cc8f2008-05-12 21:20:49 +02002344 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;
2349
2350 return 0;
2351 }
2352}
2353
Steven Rostedtb3806b42008-05-12 21:20:46 +02002354/*
2355 * Consumer reader.
2356 */
2357static ssize_t
2358tracing_read_pipe(struct file *filp, char __user *ubuf,
2359 size_t cnt, loff_t *ppos)
2360{
2361 struct trace_iterator *iter = filp->private_data;
2362 struct trace_array_cpu *data;
2363 static cpumask_t mask;
Steven Rostedtb3806b42008-05-12 21:20:46 +02002364 static int start;
2365 unsigned long flags;
Ingo Molnar25770462008-05-12 21:20:49 +02002366#ifdef CONFIG_FTRACE
Ingo Molnar2e0f5762008-05-12 21:20:49 +02002367 int ftrace_save;
Ingo Molnar25770462008-05-12 21:20:49 +02002368#endif
Steven Rostedtb3806b42008-05-12 21:20:46 +02002369 int read = 0;
2370 int cpu;
2371 int len;
2372 int ret;
2373
2374 /* return any leftover data */
2375 if (iter->seq.len > start) {
2376 len = iter->seq.len - start;
2377 if (cnt > len)
2378 cnt = len;
2379 ret = copy_to_user(ubuf, iter->seq.buffer + start, cnt);
2380 if (ret)
2381 cnt = -EFAULT;
2382
2383 start += len;
2384
2385 return cnt;
2386 }
2387
Steven Rostedt107bad82008-05-12 21:21:01 +02002388 mutex_lock(&trace_types_lock);
2389 if (iter->trace->read) {
2390 ret = iter->trace->read(iter, filp, ubuf, cnt, ppos);
2391 if (ret) {
2392 read = ret;
2393 goto out;
2394 }
2395 }
2396
Steven Rostedtb3806b42008-05-12 21:20:46 +02002397 trace_seq_reset(&iter->seq);
2398 start = 0;
2399
2400 while (trace_empty(iter)) {
Steven Rostedt2dc8f092008-05-12 21:20:58 +02002401
Steven Rostedt107bad82008-05-12 21:21:01 +02002402 if ((filp->f_flags & O_NONBLOCK)) {
2403 read = -EAGAIN;
2404 goto out;
2405 }
Steven Rostedt2dc8f092008-05-12 21:20:58 +02002406
Steven Rostedtb3806b42008-05-12 21:20:46 +02002407 /*
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.
2415 */
2416 set_current_state(TASK_INTERRUPTIBLE);
2417 iter->tr->waiter = current;
2418
Steven Rostedt107bad82008-05-12 21:21:01 +02002419 mutex_unlock(&trace_types_lock);
2420
Ingo Molnar9fe068e2008-05-12 21:21:02 +02002421 /* sleep for 100 msecs, and try again. */
2422 schedule_timeout(HZ/10);
Steven Rostedtb3806b42008-05-12 21:20:46 +02002423
Steven Rostedt107bad82008-05-12 21:21:01 +02002424 mutex_lock(&trace_types_lock);
2425
Steven Rostedtb3806b42008-05-12 21:20:46 +02002426 iter->tr->waiter = NULL;
2427
Steven Rostedt107bad82008-05-12 21:21:01 +02002428 if (signal_pending(current)) {
2429 read = -EINTR;
2430 goto out;
2431 }
Steven Rostedtb3806b42008-05-12 21:20:46 +02002432
Steven Rostedt84527992008-05-12 21:20:58 +02002433 if (iter->trace != current_trace)
Steven Rostedt107bad82008-05-12 21:21:01 +02002434 goto out;
Steven Rostedt84527992008-05-12 21:20:58 +02002435
Steven Rostedtb3806b42008-05-12 21:20:46 +02002436 /*
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.
2442 *
2443 * iter->pos will be 0 if we haven't read anything.
2444 */
2445 if (!tracer_enabled && iter->pos)
2446 break;
2447
2448 continue;
2449 }
2450
2451 /* stop when tracing is finished */
2452 if (trace_empty(iter))
Steven Rostedt107bad82008-05-12 21:21:01 +02002453 goto out;
Steven Rostedtb3806b42008-05-12 21:20:46 +02002454
2455 if (cnt >= PAGE_SIZE)
2456 cnt = PAGE_SIZE - 1;
2457
Steven Rostedt53d0aa72008-05-12 21:21:01 +02002458 /* reset all but tr, trace, and overruns */
Steven Rostedt53d0aa72008-05-12 21:21:01 +02002459 memset(&iter->seq, 0,
2460 sizeof(struct trace_iterator) -
2461 offsetof(struct trace_iterator, seq));
Steven Rostedt4823ed72008-05-12 21:21:01 +02002462 iter->pos = -1;
Steven Rostedtb3806b42008-05-12 21:20:46 +02002463
2464 /*
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.
2469 */
2470
2471 cpus_clear(mask);
2472 local_irq_save(flags);
Ingo Molnar25770462008-05-12 21:20:49 +02002473#ifdef CONFIG_FTRACE
Ingo Molnar2e0f5762008-05-12 21:20:49 +02002474 ftrace_save = ftrace_enabled;
2475 ftrace_enabled = 0;
Ingo Molnar25770462008-05-12 21:20:49 +02002476#endif
Ingo Molnar2e0f5762008-05-12 21:20:49 +02002477 smp_wmb();
Steven Rostedtab464282008-05-12 21:21:00 +02002478 for_each_tracing_cpu(cpu) {
Steven Rostedtb3806b42008-05-12 21:20:46 +02002479 data = iter->tr->data[cpu];
2480
2481 if (!head_page(data) || !data->trace_idx)
2482 continue;
2483
2484 atomic_inc(&data->disabled);
Steven Rostedtb3806b42008-05-12 21:20:46 +02002485 cpu_set(cpu, mask);
2486 }
2487
Ingo Molnar2e0f5762008-05-12 21:20:49 +02002488 for_each_cpu_mask(cpu, mask) {
2489 data = iter->tr->data[cpu];
Steven Rostedt92205c22008-05-12 21:20:55 +02002490 __raw_spin_lock(&data->lock);
Steven Rostedt53d0aa72008-05-12 21:21:01 +02002491
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;
Ingo Molnar2e0f5762008-05-12 21:20:49 +02002496 }
2497
Steven Rostedt088b1e42008-05-12 21:20:48 +02002498 while (find_next_entry_inc(iter) != NULL) {
2499 int len = iter->seq.len;
2500
Ingo Molnarf9896bf2008-05-12 21:20:47 +02002501 ret = print_trace_line(iter);
Steven Rostedt088b1e42008-05-12 21:20:48 +02002502 if (!ret) {
2503 /* don't print partial lines */
2504 iter->seq.len = len;
Steven Rostedtb3806b42008-05-12 21:20:46 +02002505 break;
Steven Rostedt088b1e42008-05-12 21:20:48 +02002506 }
Steven Rostedtb3806b42008-05-12 21:20:46 +02002507
2508 trace_consume(iter);
2509
2510 if (iter->seq.len >= cnt)
2511 break;
Steven Rostedtb3806b42008-05-12 21:20:46 +02002512 }
2513
Ingo Molnard4c5a2f2008-05-12 21:20:46 +02002514 for_each_cpu_mask(cpu, mask) {
Steven Rostedtb3806b42008-05-12 21:20:46 +02002515 data = iter->tr->data[cpu];
Steven Rostedt92205c22008-05-12 21:20:55 +02002516 __raw_spin_unlock(&data->lock);
Ingo Molnar2e0f5762008-05-12 21:20:49 +02002517 }
2518
2519 for_each_cpu_mask(cpu, mask) {
2520 data = iter->tr->data[cpu];
Steven Rostedtb3806b42008-05-12 21:20:46 +02002521 atomic_dec(&data->disabled);
2522 }
Ingo Molnar25770462008-05-12 21:20:49 +02002523#ifdef CONFIG_FTRACE
Ingo Molnar2e0f5762008-05-12 21:20:49 +02002524 ftrace_enabled = ftrace_save;
Ingo Molnar25770462008-05-12 21:20:49 +02002525#endif
Steven Rostedtb3806b42008-05-12 21:20:46 +02002526 local_irq_restore(flags);
2527
2528 /* Now copy what we have to the user */
2529 read = iter->seq.len;
2530 if (read > cnt)
2531 read = cnt;
2532
2533 ret = copy_to_user(ubuf, iter->seq.buffer, read);
2534
2535 if (read < iter->seq.len)
2536 start = read;
2537 else
2538 trace_seq_reset(&iter->seq);
2539
2540 if (ret)
2541 read = -EFAULT;
2542
Steven Rostedt107bad82008-05-12 21:21:01 +02002543out:
2544 mutex_unlock(&trace_types_lock);
2545
Steven Rostedtb3806b42008-05-12 21:20:46 +02002546 return read;
2547}
2548
Steven Rostedta98a3c32008-05-12 21:20:59 +02002549static ssize_t
2550tracing_entries_read(struct file *filp, char __user *ubuf,
2551 size_t cnt, loff_t *ppos)
2552{
2553 struct trace_array *tr = filp->private_data;
2554 char buf[64];
2555 int r;
2556
2557 r = sprintf(buf, "%lu\n", tr->entries);
2558 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
2559}
2560
2561static ssize_t
2562tracing_entries_write(struct file *filp, const char __user *ubuf,
2563 size_t cnt, loff_t *ppos)
2564{
2565 unsigned long val;
2566 char buf[64];
Steven Rostedtc6caeeb2008-05-12 21:21:00 +02002567 int ret;
Steven Rostedta98a3c32008-05-12 21:20:59 +02002568
Steven Rostedtcffae432008-05-12 21:21:00 +02002569 if (cnt >= sizeof(buf))
2570 return -EINVAL;
Steven Rostedta98a3c32008-05-12 21:20:59 +02002571
2572 if (copy_from_user(&buf, ubuf, cnt))
2573 return -EFAULT;
2574
2575 buf[cnt] = 0;
2576
Steven Rostedtc6caeeb2008-05-12 21:21:00 +02002577 ret = strict_strtoul(buf, 10, &val);
2578 if (ret < 0)
2579 return ret;
Steven Rostedta98a3c32008-05-12 21:20:59 +02002580
2581 /* must have at least 1 entry */
2582 if (!val)
2583 return -EINVAL;
2584
2585 mutex_lock(&trace_types_lock);
2586
2587 if (current_trace != &no_tracer) {
2588 cnt = -EBUSY;
2589 pr_info("ftrace: set current_tracer to none"
2590 " before modifying buffer size\n");
2591 goto out;
2592 }
2593
2594 if (val > global_trace.entries) {
2595 while (global_trace.entries < val) {
2596 if (trace_alloc_page()) {
2597 cnt = -ENOMEM;
2598 goto out;
2599 }
2600 }
2601 } else {
2602 /* include the number of entries in val (inc of page entries) */
2603 while (global_trace.entries > val + (ENTRIES_PER_PAGE - 1))
2604 trace_free_page();
2605 }
2606
2607 filp->f_pos += cnt;
2608
2609 out:
2610 max_tr.entries = global_trace.entries;
2611 mutex_unlock(&trace_types_lock);
2612
2613 return cnt;
2614}
2615
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002616static struct file_operations tracing_max_lat_fops = {
Ingo Molnar4bf39a92008-05-12 21:20:46 +02002617 .open = tracing_open_generic,
2618 .read = tracing_max_lat_read,
2619 .write = tracing_max_lat_write,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002620};
2621
2622static struct file_operations tracing_ctrl_fops = {
Ingo Molnar4bf39a92008-05-12 21:20:46 +02002623 .open = tracing_open_generic,
2624 .read = tracing_ctrl_read,
2625 .write = tracing_ctrl_write,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002626};
2627
2628static struct file_operations set_tracer_fops = {
Ingo Molnar4bf39a92008-05-12 21:20:46 +02002629 .open = tracing_open_generic,
2630 .read = tracing_set_trace_read,
2631 .write = tracing_set_trace_write,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002632};
2633
Steven Rostedtb3806b42008-05-12 21:20:46 +02002634static struct file_operations tracing_pipe_fops = {
Ingo Molnar4bf39a92008-05-12 21:20:46 +02002635 .open = tracing_open_pipe,
Soeren Sandmann Pedersen2a2cc8f2008-05-12 21:20:49 +02002636 .poll = tracing_poll_pipe,
Ingo Molnar4bf39a92008-05-12 21:20:46 +02002637 .read = tracing_read_pipe,
2638 .release = tracing_release_pipe,
Steven Rostedtb3806b42008-05-12 21:20:46 +02002639};
2640
Steven Rostedta98a3c32008-05-12 21:20:59 +02002641static struct file_operations tracing_entries_fops = {
2642 .open = tracing_open_generic,
2643 .read = tracing_entries_read,
2644 .write = tracing_entries_write,
2645};
2646
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002647#ifdef CONFIG_DYNAMIC_FTRACE
2648
2649static ssize_t
2650tracing_read_long(struct file *filp, char __user *ubuf,
2651 size_t cnt, loff_t *ppos)
2652{
2653 unsigned long *p = filp->private_data;
2654 char buf[64];
2655 int r;
2656
2657 r = sprintf(buf, "%ld\n", *p);
Ingo Molnar4bf39a92008-05-12 21:20:46 +02002658
2659 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002660}
2661
2662static struct file_operations tracing_read_long_fops = {
Ingo Molnar4bf39a92008-05-12 21:20:46 +02002663 .open = tracing_open_generic,
2664 .read = tracing_read_long,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002665};
2666#endif
2667
2668static struct dentry *d_tracer;
2669
2670struct dentry *tracing_init_dentry(void)
2671{
2672 static int once;
2673
2674 if (d_tracer)
2675 return d_tracer;
2676
2677 d_tracer = debugfs_create_dir("tracing", NULL);
2678
2679 if (!d_tracer && !once) {
2680 once = 1;
2681 pr_warning("Could not create debugfs directory 'tracing'\n");
2682 return NULL;
2683 }
2684
2685 return d_tracer;
2686}
2687
Steven Rostedt60a11772008-05-12 21:20:44 +02002688#ifdef CONFIG_FTRACE_SELFTEST
2689/* Let selftest have access to static functions in this file */
2690#include "trace_selftest.c"
2691#endif
2692
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002693static __init void tracer_init_debugfs(void)
2694{
2695 struct dentry *d_tracer;
2696 struct dentry *entry;
2697
2698 d_tracer = tracing_init_dentry();
2699
2700 entry = debugfs_create_file("tracing_enabled", 0644, d_tracer,
2701 &global_trace, &tracing_ctrl_fops);
2702 if (!entry)
2703 pr_warning("Could not create debugfs 'tracing_enabled' entry\n");
2704
2705 entry = debugfs_create_file("iter_ctrl", 0644, d_tracer,
2706 NULL, &tracing_iter_fops);
2707 if (!entry)
2708 pr_warning("Could not create debugfs 'iter_ctrl' entry\n");
2709
Ingo Molnarc7078de2008-05-12 21:20:52 +02002710 entry = debugfs_create_file("tracing_cpumask", 0644, d_tracer,
2711 NULL, &tracing_cpumask_fops);
2712 if (!entry)
2713 pr_warning("Could not create debugfs 'tracing_cpumask' entry\n");
2714
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002715 entry = debugfs_create_file("latency_trace", 0444, d_tracer,
2716 &global_trace, &tracing_lt_fops);
2717 if (!entry)
2718 pr_warning("Could not create debugfs 'latency_trace' entry\n");
2719
2720 entry = debugfs_create_file("trace", 0444, d_tracer,
2721 &global_trace, &tracing_fops);
2722 if (!entry)
2723 pr_warning("Could not create debugfs 'trace' entry\n");
2724
2725 entry = debugfs_create_file("available_tracers", 0444, d_tracer,
2726 &global_trace, &show_traces_fops);
2727 if (!entry)
2728 pr_warning("Could not create debugfs 'trace' entry\n");
2729
2730 entry = debugfs_create_file("current_tracer", 0444, d_tracer,
2731 &global_trace, &set_tracer_fops);
2732 if (!entry)
2733 pr_warning("Could not create debugfs 'trace' entry\n");
2734
2735 entry = debugfs_create_file("tracing_max_latency", 0644, d_tracer,
2736 &tracing_max_latency,
2737 &tracing_max_lat_fops);
2738 if (!entry)
2739 pr_warning("Could not create debugfs "
2740 "'tracing_max_latency' entry\n");
2741
2742 entry = debugfs_create_file("tracing_thresh", 0644, d_tracer,
2743 &tracing_thresh, &tracing_max_lat_fops);
2744 if (!entry)
2745 pr_warning("Could not create debugfs "
2746 "'tracing_threash' entry\n");
Ingo Molnar7bd2f242008-05-12 21:20:45 +02002747 entry = debugfs_create_file("README", 0644, d_tracer,
2748 NULL, &tracing_readme_fops);
2749 if (!entry)
2750 pr_warning("Could not create debugfs 'README' entry\n");
2751
Steven Rostedtb3806b42008-05-12 21:20:46 +02002752 entry = debugfs_create_file("trace_pipe", 0644, d_tracer,
2753 NULL, &tracing_pipe_fops);
2754 if (!entry)
2755 pr_warning("Could not create debugfs "
2756 "'tracing_threash' entry\n");
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002757
Steven Rostedta98a3c32008-05-12 21:20:59 +02002758 entry = debugfs_create_file("trace_entries", 0644, d_tracer,
2759 &global_trace, &tracing_entries_fops);
2760 if (!entry)
2761 pr_warning("Could not create debugfs "
2762 "'tracing_threash' entry\n");
2763
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002764#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);
2768 if (!entry)
2769 pr_warning("Could not create debugfs "
2770 "'dyn_ftrace_total_info' entry\n");
2771#endif
2772}
2773
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02002774static int trace_alloc_page(void)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002775{
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02002776 struct trace_array_cpu *data;
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02002777 struct page *page, *tmp;
2778 LIST_HEAD(pages);
Ingo Molnarc7aafc52008-05-12 21:20:45 +02002779 void *array;
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02002780 int i;
2781
2782 /* first allocate a page for each CPU */
Steven Rostedtab464282008-05-12 21:21:00 +02002783 for_each_tracing_cpu(i) {
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02002784 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");
2788 goto free_pages;
2789 }
2790
2791 page = virt_to_page(array);
2792 list_add(&page->lru, &pages);
2793
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");
2800 goto free_pages;
2801 }
2802 page = virt_to_page(array);
2803 list_add(&page->lru, &pages);
2804#endif
2805 }
2806
2807 /* Now that we successfully allocate a page per CPU, add them */
Steven Rostedtab464282008-05-12 21:21:00 +02002808 for_each_tracing_cpu(i) {
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02002809 data = global_trace.data[i];
2810 page = list_entry(pages.next, struct page, lru);
Ingo Molnarc7aafc52008-05-12 21:20:45 +02002811 list_del_init(&page->lru);
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02002812 list_add_tail(&page->lru, &data->trace_pages);
2813 ClearPageLRU(page);
2814
2815#ifdef CONFIG_TRACER_MAX_TRACE
2816 data = max_tr.data[i];
2817 page = list_entry(pages.next, struct page, lru);
Ingo Molnarc7aafc52008-05-12 21:20:45 +02002818 list_del_init(&page->lru);
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02002819 list_add_tail(&page->lru, &data->trace_pages);
2820 SetPageLRU(page);
2821#endif
2822 }
2823 global_trace.entries += ENTRIES_PER_PAGE;
2824
2825 return 0;
2826
2827 free_pages:
2828 list_for_each_entry_safe(page, tmp, &pages, lru) {
Ingo Molnarc7aafc52008-05-12 21:20:45 +02002829 list_del_init(&page->lru);
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02002830 __free_page(page);
2831 }
2832 return -ENOMEM;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002833}
2834
Steven Rostedta98a3c32008-05-12 21:20:59 +02002835static int trace_free_page(void)
2836{
2837 struct trace_array_cpu *data;
2838 struct page *page;
2839 struct list_head *p;
2840 int i;
2841 int ret = 0;
2842
2843 /* free one page from each buffer */
Steven Rostedtab464282008-05-12 21:21:00 +02002844 for_each_tracing_cpu(i) {
Steven Rostedta98a3c32008-05-12 21:20:59 +02002845 data = global_trace.data[i];
2846 p = data->trace_pages.next;
2847 if (p == &data->trace_pages) {
2848 /* should never happen */
2849 WARN_ON(1);
2850 tracing_disabled = 1;
2851 ret = -1;
2852 break;
2853 }
2854 page = list_entry(p, struct page, lru);
2855 ClearPageLRU(page);
2856 list_del(&page->lru);
2857 __free_page(page);
2858
2859 tracing_reset(data);
2860
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 */
2866 WARN_ON(1);
2867 tracing_disabled = 1;
2868 ret = -1;
2869 break;
2870 }
2871 page = list_entry(p, struct page, lru);
2872 ClearPageLRU(page);
2873 list_del(&page->lru);
2874 __free_page(page);
2875
2876 tracing_reset(data);
2877#endif
2878 }
2879 global_trace.entries -= ENTRIES_PER_PAGE;
2880
2881 return ret;
2882}
2883
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002884__init static int tracer_alloc_buffers(void)
2885{
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02002886 struct trace_array_cpu *data;
2887 void *array;
2888 struct page *page;
2889 int pages = 0;
Steven Rostedt60a11772008-05-12 21:20:44 +02002890 int ret = -ENOMEM;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002891 int i;
2892
Steven Rostedt26994ea2008-05-12 21:20:48 +02002893 global_trace.ctrl = tracer_enabled;
2894
Steven Rostedtab464282008-05-12 21:21:00 +02002895 /* TODO: make the number of buffers hot pluggable with CPUS */
2896 tracing_nr_buffers = num_possible_cpus();
2897 tracing_buffer_mask = cpu_possible_map;
2898
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02002899 /* Allocate the first page for all buffers */
Steven Rostedtab464282008-05-12 21:21:00 +02002900 for_each_tracing_cpu(i) {
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02002901 data = global_trace.data[i] = &per_cpu(global_trace_cpu, i);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002902 max_tr.data[i] = &per_cpu(max_data, i);
2903
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02002904 array = (void *)__get_free_page(GFP_KERNEL);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002905 if (array == NULL) {
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02002906 printk(KERN_ERR "tracer: failed to allocate page"
2907 "for trace buffer!\n");
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002908 goto free_buffers;
2909 }
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02002910
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 */
2916 ClearPageLRU(page);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002917
Steven Rostedta98a3c32008-05-12 21:20:59 +02002918 data->lock = (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED;
2919 max_tr.data[i]->lock = (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED;
2920
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002921/* Only allocate if we are actually using the max trace */
2922#ifdef CONFIG_TRACER_MAX_TRACE
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02002923 array = (void *)__get_free_page(GFP_KERNEL);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002924 if (array == NULL) {
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02002925 printk(KERN_ERR "tracer: failed to allocate page"
2926 "for trace buffer!\n");
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002927 goto free_buffers;
2928 }
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02002929
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);
2933 SetPageLRU(page);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002934#endif
2935 }
2936
2937 /*
2938 * Since we allocate by orders of pages, we may be able to
2939 * round up a bit.
2940 */
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02002941 global_trace.entries = ENTRIES_PER_PAGE;
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02002942 pages++;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002943
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02002944 while (global_trace.entries < trace_nr_entries) {
2945 if (trace_alloc_page())
2946 break;
2947 pages++;
2948 }
Steven Rostedt89b2f972008-05-12 21:20:44 +02002949 max_tr.entries = global_trace.entries;
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02002950
2951 pr_info("tracer: %d pages allocated for %ld",
2952 pages, trace_nr_entries);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002953 pr_info(" entries of %ld bytes\n", (long)TRACE_ENTRY_SIZE);
2954 pr_info(" actual entries %ld\n", global_trace.entries);
2955
2956 tracer_init_debugfs();
2957
2958 trace_init_cmdlines();
2959
2960 register_tracer(&no_tracer);
2961 current_trace = &no_tracer;
2962
Steven Rostedt60a11772008-05-12 21:20:44 +02002963 /* All seems OK, enable tracing */
2964 tracing_disabled = 0;
2965
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002966 return 0;
2967
2968 free_buffers:
2969 for (i-- ; i >= 0; i--) {
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02002970 struct page *page, *tmp;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002971 struct trace_array_cpu *data = global_trace.data[i];
2972
Ingo Molnarc7aafc52008-05-12 21:20:45 +02002973 if (data) {
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02002974 list_for_each_entry_safe(page, tmp,
2975 &data->trace_pages, lru) {
Ingo Molnarc7aafc52008-05-12 21:20:45 +02002976 list_del_init(&page->lru);
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02002977 __free_page(page);
2978 }
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002979 }
2980
2981#ifdef CONFIG_TRACER_MAX_TRACE
2982 data = max_tr.data[i];
Ingo Molnarc7aafc52008-05-12 21:20:45 +02002983 if (data) {
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02002984 list_for_each_entry_safe(page, tmp,
2985 &data->trace_pages, lru) {
Ingo Molnarc7aafc52008-05-12 21:20:45 +02002986 list_del_init(&page->lru);
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02002987 __free_page(page);
2988 }
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002989 }
2990#endif
2991 }
Steven Rostedt60a11772008-05-12 21:20:44 +02002992 return ret;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002993}
Steven Rostedt60a11772008-05-12 21:20:44 +02002994fs_initcall(tracer_alloc_buffers);