blob: e97c29a6e7b09cb6850dfb8cb1caaab9c24f65bc [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>
Steven Rostedt3f5a54e2008-07-30 22:36:46 -040017#include <linux/notifier.h>
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020018#include <linux/debugfs.h>
Steven Rostedt4c11d7a2008-05-12 21:20:43 +020019#include <linux/pagemap.h>
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020020#include <linux/hardirq.h>
21#include <linux/linkage.h>
22#include <linux/uaccess.h>
23#include <linux/ftrace.h>
24#include <linux/module.h>
25#include <linux/percpu.h>
Steven Rostedt3f5a54e2008-07-30 22:36:46 -040026#include <linux/kdebug.h>
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020027#include <linux/ctype.h>
28#include <linux/init.h>
Soeren Sandmann Pedersen2a2cc8f2008-05-12 21:20:49 +020029#include <linux/poll.h>
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020030#include <linux/gfp.h>
31#include <linux/fs.h>
Abhishek Sagar76094a22008-05-28 00:03:18 +053032#include <linux/kprobes.h>
Steven Rostedt3eefae92008-05-12 21:21:04 +020033#include <linux/writeback.h>
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020034
Ingo Molnar86387f72008-05-12 21:20:51 +020035#include <linux/stacktrace.h>
Steven Rostedt3928a8a2008-09-29 23:02:41 -040036#include <linux/ring_buffer.h>
Frederic Weisbecker21798a82008-10-28 09:43:26 +010037#include <linux/irqflags.h>
Ingo Molnar86387f72008-05-12 21:20:51 +020038
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020039#include "trace.h"
40
Steven Rostedt3928a8a2008-09-29 23:02:41 -040041#define TRACE_BUFFER_FLAGS (RB_FL_OVERWRITE)
42
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020043unsigned long __read_mostly tracing_max_latency = (cycle_t)ULONG_MAX;
44unsigned long __read_mostly tracing_thresh;
45
Frederic Weisbeckeradf9f192008-11-17 19:23:42 +010046/* For tracers that don't implement custom flags */
47static struct tracer_opt dummy_tracer_opt[] = {
48 { }
49};
50
51static struct tracer_flags dummy_tracer_flags = {
52 .val = 0,
53 .opts = dummy_tracer_opt
54};
55
56static int dummy_set_flag(u32 old_flags, u32 bit, int set)
57{
58 return 0;
59}
Steven Rostedt0f048702008-11-05 16:05:44 -050060
61/*
62 * Kill all tracing for good (never come back).
63 * It is initialized to 1 but will turn to zero if the initialization
64 * of the tracer is successful. But that is the only place that sets
65 * this back to zero.
66 */
67int tracing_disabled = 1;
68
Steven Rostedtd7690412008-10-01 00:29:53 -040069static DEFINE_PER_CPU(local_t, ftrace_cpu_disabled);
70
71static inline void ftrace_disable_cpu(void)
72{
73 preempt_disable();
74 local_inc(&__get_cpu_var(ftrace_cpu_disabled));
75}
76
77static inline void ftrace_enable_cpu(void)
78{
79 local_dec(&__get_cpu_var(ftrace_cpu_disabled));
80 preempt_enable();
81}
82
Steven Rostedtab464282008-05-12 21:21:00 +020083static cpumask_t __read_mostly tracing_buffer_mask;
84
85#define for_each_tracing_cpu(cpu) \
86 for_each_cpu_mask(cpu, tracing_buffer_mask)
87
Steven Rostedt944ac422008-10-23 19:26:08 -040088/*
89 * ftrace_dump_on_oops - variable to dump ftrace buffer on oops
90 *
91 * If there is an oops (or kernel panic) and the ftrace_dump_on_oops
92 * is set, then ftrace_dump is called. This will output the contents
93 * of the ftrace buffers to the console. This is very useful for
94 * capturing traces that lead to crashes and outputing it to a
95 * serial console.
96 *
97 * It is default off, but you can enable it with either specifying
98 * "ftrace_dump_on_oops" in the kernel command line, or setting
99 * /proc/sys/kernel/ftrace_dump_on_oops to true.
100 */
101int ftrace_dump_on_oops;
102
Peter Zijlstrad9e54072008-11-01 19:57:37 +0100103static int tracing_set_tracer(char *buf);
104
105static int __init set_ftrace(char *str)
106{
107 tracing_set_tracer(str);
108 return 1;
109}
110__setup("ftrace", set_ftrace);
111
Steven Rostedt944ac422008-10-23 19:26:08 -0400112static int __init set_ftrace_dump_on_oops(char *str)
113{
114 ftrace_dump_on_oops = 1;
115 return 1;
116}
117__setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops);
118
Thomas Gleixner72829bc2008-05-23 21:37:28 +0200119long
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200120ns2usecs(cycle_t nsec)
121{
122 nsec += 500;
123 do_div(nsec, 1000);
124 return nsec;
125}
126
Ingo Molnare309b412008-05-12 21:20:51 +0200127cycle_t ftrace_now(int cpu)
Ingo Molnar750ed1a2008-05-12 21:20:46 +0200128{
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400129 u64 ts = ring_buffer_time_stamp(cpu);
130 ring_buffer_normalize_time_stamp(cpu, &ts);
131 return ts;
Ingo Molnar750ed1a2008-05-12 21:20:46 +0200132}
133
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200134/*
135 * The global_trace is the descriptor that holds the tracing
136 * buffers for the live tracing. For each CPU, it contains
137 * a link list of pages that will store trace entries. The
138 * page descriptor of the pages in the memory is used to hold
139 * the link list by linking the lru item in the page descriptor
140 * to each of the pages in the buffer per CPU.
141 *
142 * For each active CPU there is a data field that holds the
143 * pages for the buffer for that CPU. Each CPU has the same number
144 * of pages allocated for its buffer.
145 */
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200146static struct trace_array global_trace;
147
148static DEFINE_PER_CPU(struct trace_array_cpu, global_trace_cpu);
149
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200150/*
151 * The max_tr is used to snapshot the global_trace when a maximum
152 * latency is reached. Some tracers will use this to store a maximum
153 * trace while it continues examining live traces.
154 *
155 * The buffers for the max_tr are set up the same as the global_trace.
156 * When a snapshot is taken, the link list of the max_tr is swapped
157 * with the link list of the global_trace and the buffers are reset for
158 * the global_trace so the tracing can continue.
159 */
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200160static struct trace_array max_tr;
161
162static DEFINE_PER_CPU(struct trace_array_cpu, max_data);
163
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200164/* tracer_enabled is used to toggle activation of a tracer */
Steven Rostedt26994ea2008-05-12 21:20:48 +0200165static int tracer_enabled = 1;
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200166
Steven Rostedt90369902008-11-05 16:05:44 -0500167/**
168 * tracing_is_enabled - return tracer_enabled status
169 *
170 * This function is used by other tracers to know the status
171 * of the tracer_enabled flag. Tracers may use this function
172 * to know if it should enable their features when starting
173 * up. See irqsoff tracer for an example (start_irqsoff_tracer).
174 */
175int tracing_is_enabled(void)
176{
177 return tracer_enabled;
178}
179
Steven Rostedt60bc0802008-07-10 20:58:16 -0400180/* function tracing enabled */
181int ftrace_function_enabled;
182
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200183/*
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400184 * trace_buf_size is the size in bytes that is allocated
185 * for a buffer. Note, the number of bytes is always rounded
186 * to page size.
Steven Rostedt3f5a54e2008-07-30 22:36:46 -0400187 *
188 * This number is purposely set to a low number of 16384.
189 * If the dump on oops happens, it will be much appreciated
190 * to not have to wait for all that output. Anyway this can be
191 * boot time and run time configurable.
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200192 */
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400193#define TRACE_BUF_SIZE_DEFAULT 1441792UL /* 16384 * 88 (sizeof(entry)) */
Steven Rostedt3f5a54e2008-07-30 22:36:46 -0400194
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400195static unsigned long trace_buf_size = TRACE_BUF_SIZE_DEFAULT;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200196
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200197/* trace_types holds a link list of available tracers. */
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200198static struct tracer *trace_types __read_mostly;
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200199
200/* current_trace points to the tracer that is currently active */
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200201static struct tracer *current_trace __read_mostly;
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200202
203/*
204 * max_tracer_type_len is used to simplify the allocating of
205 * buffers to read userspace tracer names. We keep track of
206 * the longest tracer name registered.
207 */
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200208static int max_tracer_type_len;
209
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200210/*
211 * trace_types_lock is used to protect the trace_types list.
212 * This lock is also used to keep user access serialized.
213 * Accesses from userspace will grab this lock while userspace
214 * activities happen inside the kernel.
215 */
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200216static DEFINE_MUTEX(trace_types_lock);
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200217
218/* trace_wait is a waitqueue for tasks blocked on trace_poll */
Ingo Molnar4e655512008-05-12 21:20:52 +0200219static DECLARE_WAIT_QUEUE_HEAD(trace_wait);
220
Steven Rostedtee6bce52008-11-12 17:52:37 -0500221/* trace_flags holds trace_options default values */
Steven Rostedt12ef7d42008-11-12 17:52:38 -0500222unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |
223 TRACE_ITER_ANNOTATE;
Ingo Molnar4e655512008-05-12 21:20:52 +0200224
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200225/**
226 * trace_wake_up - wake up tasks waiting for trace input
227 *
228 * Simply wakes up any task that is blocked on the trace_wait
229 * queue. These is used with trace_poll for tasks polling the trace.
230 */
Ingo Molnar4e655512008-05-12 21:20:52 +0200231void trace_wake_up(void)
232{
Ingo Molnar017730c2008-05-12 21:20:52 +0200233 /*
234 * The runqueue_is_locked() can fail, but this is the best we
235 * have for now:
236 */
237 if (!(trace_flags & TRACE_ITER_BLOCK) && !runqueue_is_locked())
Ingo Molnar4e655512008-05-12 21:20:52 +0200238 wake_up(&trace_wait);
239}
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200240
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400241static int __init set_buf_size(char *str)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200242{
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400243 unsigned long buf_size;
Steven Rostedtc6caeeb2008-05-12 21:21:00 +0200244 int ret;
245
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200246 if (!str)
247 return 0;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400248 ret = strict_strtoul(str, 0, &buf_size);
Steven Rostedtc6caeeb2008-05-12 21:21:00 +0200249 /* nr_entries can not be zero */
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400250 if (ret < 0 || buf_size == 0)
Steven Rostedtc6caeeb2008-05-12 21:21:00 +0200251 return 0;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400252 trace_buf_size = buf_size;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200253 return 1;
254}
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400255__setup("trace_buf_size=", set_buf_size);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200256
Steven Rostedt57f50be2008-05-12 21:20:44 +0200257unsigned long nsecs_to_usecs(unsigned long nsecs)
258{
259 return nsecs / 1000;
260}
261
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200262/* These must match the bit postions in trace_iterator_flags */
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200263static const char *trace_options[] = {
264 "print-parent",
265 "sym-offset",
266 "sym-addr",
267 "verbose",
Ingo Molnarf9896bf2008-05-12 21:20:47 +0200268 "raw",
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +0200269 "hex",
Ingo Molnarcb0f12a2008-05-12 21:20:47 +0200270 "bin",
Soeren Sandmann Pedersen2a2cc8f2008-05-12 21:20:49 +0200271 "block",
Ingo Molnar86387f72008-05-12 21:20:51 +0200272 "stacktrace",
Ingo Molnar4ac3ba42008-05-12 21:20:52 +0200273 "sched-tree",
Peter Zijlstraf09ce572008-09-04 10:24:14 +0200274 "ftrace_printk",
Steven Rostedtb2a866f2008-11-03 23:15:57 -0500275 "ftrace_preempt",
Steven Rostedt9f029e82008-11-12 15:24:24 -0500276 "branch",
Steven Rostedt12ef7d42008-11-12 17:52:38 -0500277 "annotate",
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200278 NULL
279};
280
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200281/*
282 * ftrace_max_lock is used to protect the swapping of buffers
283 * when taking a max snapshot. The buffers themselves are
284 * protected by per_cpu spinlocks. But the action of the swap
285 * needs its own lock.
286 *
287 * This is defined as a raw_spinlock_t in order to help
288 * with performance when lockdep debugging is enabled.
289 */
Steven Rostedt92205c22008-05-12 21:20:55 +0200290static raw_spinlock_t ftrace_max_lock =
291 (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200292
293/*
294 * Copy the new maximum trace into the separate maximum-trace
295 * structure. (this way the maximum trace is permanently saved,
296 * for later retrieval via /debugfs/tracing/latency_trace)
297 */
Ingo Molnare309b412008-05-12 21:20:51 +0200298static void
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200299__update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
300{
301 struct trace_array_cpu *data = tr->data[cpu];
302
303 max_tr.cpu = cpu;
304 max_tr.time_start = data->preempt_timestamp;
305
306 data = max_tr.data[cpu];
307 data->saved_latency = tracing_max_latency;
308
309 memcpy(data->comm, tsk->comm, TASK_COMM_LEN);
310 data->pid = tsk->pid;
311 data->uid = tsk->uid;
312 data->nice = tsk->static_prio - 20 - MAX_RT_PRIO;
313 data->policy = tsk->policy;
314 data->rt_priority = tsk->rt_priority;
315
316 /* record this tasks comm */
317 tracing_record_cmdline(current);
318}
319
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200320/**
321 * trace_seq_printf - sequence printing of trace information
322 * @s: trace sequence descriptor
323 * @fmt: printf format string
324 *
325 * The tracer may use either sequence operations or its own
326 * copy to user routines. To simplify formating of a trace
327 * trace_seq_printf is used to store strings into a special
328 * buffer (@s). Then the output may be either used by
329 * the sequencer or pulled into another buffer.
330 */
Thomas Gleixner72829bc2008-05-23 21:37:28 +0200331int
Steven Rostedt214023c2008-05-12 21:20:46 +0200332trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
333{
334 int len = (PAGE_SIZE - 1) - s->len;
335 va_list ap;
Steven Rostedtb3806b42008-05-12 21:20:46 +0200336 int ret;
Steven Rostedt214023c2008-05-12 21:20:46 +0200337
338 if (!len)
339 return 0;
340
341 va_start(ap, fmt);
Steven Rostedtb3806b42008-05-12 21:20:46 +0200342 ret = vsnprintf(s->buffer + s->len, len, fmt, ap);
Steven Rostedt214023c2008-05-12 21:20:46 +0200343 va_end(ap);
344
Steven Rostedtb3806b42008-05-12 21:20:46 +0200345 /* If we can't write it all, don't bother writing anything */
Thomas Gleixner72829bc2008-05-23 21:37:28 +0200346 if (ret >= len)
Steven Rostedtb3806b42008-05-12 21:20:46 +0200347 return 0;
348
349 s->len += ret;
Steven Rostedt214023c2008-05-12 21:20:46 +0200350
351 return len;
352}
353
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200354/**
355 * trace_seq_puts - trace sequence printing of simple string
356 * @s: trace sequence descriptor
357 * @str: simple string to record
358 *
359 * The tracer may use either the sequence operations or its own
360 * copy to user routines. This function records a simple string
361 * into a special buffer (@s) for later retrieval by a sequencer
362 * or other mechanism.
363 */
Ingo Molnare309b412008-05-12 21:20:51 +0200364static int
Steven Rostedt214023c2008-05-12 21:20:46 +0200365trace_seq_puts(struct trace_seq *s, const char *str)
366{
367 int len = strlen(str);
368
369 if (len > ((PAGE_SIZE - 1) - s->len))
Steven Rostedtb3806b42008-05-12 21:20:46 +0200370 return 0;
Steven Rostedt214023c2008-05-12 21:20:46 +0200371
372 memcpy(s->buffer + s->len, str, len);
373 s->len += len;
374
375 return len;
376}
377
Ingo Molnare309b412008-05-12 21:20:51 +0200378static int
Steven Rostedt214023c2008-05-12 21:20:46 +0200379trace_seq_putc(struct trace_seq *s, unsigned char c)
380{
381 if (s->len >= (PAGE_SIZE - 1))
382 return 0;
383
384 s->buffer[s->len++] = c;
385
386 return 1;
387}
388
Ingo Molnare309b412008-05-12 21:20:51 +0200389static int
Ingo Molnarcb0f12a2008-05-12 21:20:47 +0200390trace_seq_putmem(struct trace_seq *s, void *mem, size_t len)
391{
392 if (len > ((PAGE_SIZE - 1) - s->len))
393 return 0;
394
395 memcpy(s->buffer + s->len, mem, len);
396 s->len += len;
397
398 return len;
399}
400
Harvey Harrisonad0a3b62008-10-08 17:44:55 -0700401#define MAX_MEMHEX_BYTES 8
402#define HEX_CHARS (MAX_MEMHEX_BYTES*2 + 1)
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +0200403
Ingo Molnare309b412008-05-12 21:20:51 +0200404static int
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +0200405trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len)
406{
407 unsigned char hex[HEX_CHARS];
Thomas Gleixner93dcc6e2008-05-12 21:21:00 +0200408 unsigned char *data = mem;
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +0200409 int i, j;
410
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +0200411#ifdef __BIG_ENDIAN
412 for (i = 0, j = 0; i < len; i++) {
413#else
414 for (i = len-1, j = 0; i >= 0; i--) {
415#endif
Harvey Harrison2fbc4742008-10-08 16:51:49 -0700416 hex[j++] = hex_asc_hi(data[i]);
417 hex[j++] = hex_asc_lo(data[i]);
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +0200418 }
Thomas Gleixner93dcc6e2008-05-12 21:21:00 +0200419 hex[j++] = ' ';
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +0200420
421 return trace_seq_putmem(s, hex, j);
422}
423
Ingo Molnare309b412008-05-12 21:20:51 +0200424static void
Steven Rostedt214023c2008-05-12 21:20:46 +0200425trace_seq_reset(struct trace_seq *s)
426{
427 s->len = 0;
Pekka Paalanen6c6c2792008-05-12 21:21:02 +0200428 s->readpos = 0;
429}
430
431ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt)
432{
433 int len;
434 int ret;
435
436 if (s->len <= s->readpos)
437 return -EBUSY;
438
439 len = s->len - s->readpos;
440 if (cnt > len)
441 cnt = len;
442 ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt);
443 if (ret)
444 return -EFAULT;
445
446 s->readpos += len;
447 return cnt;
Steven Rostedt214023c2008-05-12 21:20:46 +0200448}
449
Ingo Molnare309b412008-05-12 21:20:51 +0200450static void
Steven Rostedt214023c2008-05-12 21:20:46 +0200451trace_print_seq(struct seq_file *m, struct trace_seq *s)
452{
453 int len = s->len >= PAGE_SIZE ? PAGE_SIZE - 1 : s->len;
454
455 s->buffer[len] = 0;
456 seq_puts(m, s->buffer);
457
458 trace_seq_reset(s);
459}
460
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200461/**
462 * update_max_tr - snapshot all trace buffers from global_trace to max_tr
463 * @tr: tracer
464 * @tsk: the task with the latency
465 * @cpu: The cpu that initiated the trace.
466 *
467 * Flip the buffers between the @tr and the max_tr and record information
468 * about which task was the cause of this latency.
469 */
Ingo Molnare309b412008-05-12 21:20:51 +0200470void
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200471update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
472{
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400473 struct ring_buffer *buf = tr->buffer;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200474
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200475 WARN_ON_ONCE(!irqs_disabled());
Steven Rostedt92205c22008-05-12 21:20:55 +0200476 __raw_spin_lock(&ftrace_max_lock);
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400477
478 tr->buffer = max_tr.buffer;
479 max_tr.buffer = buf;
480
Steven Rostedtd7690412008-10-01 00:29:53 -0400481 ftrace_disable_cpu();
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400482 ring_buffer_reset(tr->buffer);
Steven Rostedtd7690412008-10-01 00:29:53 -0400483 ftrace_enable_cpu();
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200484
485 __update_max_tr(tr, tsk, cpu);
Steven Rostedt92205c22008-05-12 21:20:55 +0200486 __raw_spin_unlock(&ftrace_max_lock);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200487}
488
489/**
490 * update_max_tr_single - only copy one trace over, and reset the rest
491 * @tr - tracer
492 * @tsk - task with the latency
493 * @cpu - the cpu of the buffer to copy.
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200494 *
495 * Flip the trace of a single CPU buffer between the @tr and the max_tr.
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200496 */
Ingo Molnare309b412008-05-12 21:20:51 +0200497void
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200498update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu)
499{
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400500 int ret;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200501
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200502 WARN_ON_ONCE(!irqs_disabled());
Steven Rostedt92205c22008-05-12 21:20:55 +0200503 __raw_spin_lock(&ftrace_max_lock);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200504
Steven Rostedtd7690412008-10-01 00:29:53 -0400505 ftrace_disable_cpu();
506
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400507 ring_buffer_reset(max_tr.buffer);
508 ret = ring_buffer_swap_cpu(max_tr.buffer, tr->buffer, cpu);
509
Steven Rostedtd7690412008-10-01 00:29:53 -0400510 ftrace_enable_cpu();
511
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400512 WARN_ON_ONCE(ret);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200513
514 __update_max_tr(tr, tsk, cpu);
Steven Rostedt92205c22008-05-12 21:20:55 +0200515 __raw_spin_unlock(&ftrace_max_lock);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200516}
517
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200518/**
519 * register_tracer - register a tracer with the ftrace system.
520 * @type - the plugin for the tracer
521 *
522 * Register a new plugin tracer.
523 */
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200524int register_tracer(struct tracer *type)
525{
526 struct tracer *t;
527 int len;
528 int ret = 0;
529
530 if (!type->name) {
531 pr_info("Tracer must have a name\n");
532 return -1;
533 }
534
535 mutex_lock(&trace_types_lock);
536 for (t = trace_types; t; t = t->next) {
537 if (strcmp(type->name, t->name) == 0) {
538 /* already found */
539 pr_info("Trace %s already registered\n",
540 type->name);
541 ret = -1;
542 goto out;
543 }
544 }
545
Frederic Weisbeckeradf9f192008-11-17 19:23:42 +0100546 if (!type->set_flag)
547 type->set_flag = &dummy_set_flag;
548 if (!type->flags)
549 type->flags = &dummy_tracer_flags;
550 else
551 if (!type->flags->opts)
552 type->flags->opts = dummy_tracer_opt;
553
Steven Rostedt60a11772008-05-12 21:20:44 +0200554#ifdef CONFIG_FTRACE_STARTUP_TEST
555 if (type->selftest) {
556 struct tracer *saved_tracer = current_trace;
Steven Rostedt60a11772008-05-12 21:20:44 +0200557 struct trace_array *tr = &global_trace;
Steven Rostedt60a11772008-05-12 21:20:44 +0200558 int i;
559 /*
560 * Run a selftest on this tracer.
561 * Here we reset the trace buffer, and set the current
562 * tracer to be this tracer. The tracer can then run some
563 * internal tracing to verify that everything is in order.
564 * If we fail, we do not register this tracer.
565 */
Steven Rostedtab464282008-05-12 21:21:00 +0200566 for_each_tracing_cpu(i) {
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400567 tracing_reset(tr, i);
Steven Rostedt60a11772008-05-12 21:20:44 +0200568 }
569 current_trace = type;
Steven Rostedt60a11772008-05-12 21:20:44 +0200570 /* the test is responsible for initializing and enabling */
571 pr_info("Testing tracer %s: ", type->name);
572 ret = type->selftest(type, tr);
573 /* the test is responsible for resetting too */
574 current_trace = saved_tracer;
Steven Rostedt60a11772008-05-12 21:20:44 +0200575 if (ret) {
576 printk(KERN_CONT "FAILED!\n");
577 goto out;
578 }
Steven Rostedt1d4db002008-05-12 21:20:45 +0200579 /* Only reset on passing, to avoid touching corrupted buffers */
Steven Rostedtab464282008-05-12 21:21:00 +0200580 for_each_tracing_cpu(i) {
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400581 tracing_reset(tr, i);
Steven Rostedt1d4db002008-05-12 21:20:45 +0200582 }
Steven Rostedt60a11772008-05-12 21:20:44 +0200583 printk(KERN_CONT "PASSED\n");
584 }
585#endif
586
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200587 type->next = trace_types;
588 trace_types = type;
589 len = strlen(type->name);
590 if (len > max_tracer_type_len)
591 max_tracer_type_len = len;
Steven Rostedt60a11772008-05-12 21:20:44 +0200592
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200593 out:
594 mutex_unlock(&trace_types_lock);
595
596 return ret;
597}
598
599void unregister_tracer(struct tracer *type)
600{
601 struct tracer **t;
602 int len;
603
604 mutex_lock(&trace_types_lock);
605 for (t = &trace_types; *t; t = &(*t)->next) {
606 if (*t == type)
607 goto found;
608 }
609 pr_info("Trace %s not registered\n", type->name);
610 goto out;
611
612 found:
613 *t = (*t)->next;
614 if (strlen(type->name) != max_tracer_type_len)
615 goto out;
616
617 max_tracer_type_len = 0;
618 for (t = &trace_types; *t; t = &(*t)->next) {
619 len = strlen((*t)->name);
620 if (len > max_tracer_type_len)
621 max_tracer_type_len = len;
622 }
623 out:
624 mutex_unlock(&trace_types_lock);
625}
626
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400627void tracing_reset(struct trace_array *tr, int cpu)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200628{
Steven Rostedtd7690412008-10-01 00:29:53 -0400629 ftrace_disable_cpu();
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400630 ring_buffer_reset_cpu(tr->buffer, cpu);
Steven Rostedtd7690412008-10-01 00:29:53 -0400631 ftrace_enable_cpu();
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200632}
633
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200634#define SAVED_CMDLINES 128
635static unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
636static unsigned map_cmdline_to_pid[SAVED_CMDLINES];
637static char saved_cmdlines[SAVED_CMDLINES][TASK_COMM_LEN];
638static int cmdline_idx;
639static DEFINE_SPINLOCK(trace_cmdline_lock);
Steven Rostedt25b0b442008-05-12 21:21:00 +0200640
Steven Rostedt25b0b442008-05-12 21:21:00 +0200641/* temporary disable recording */
642atomic_t trace_record_cmdline_disabled __read_mostly;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200643
644static void trace_init_cmdlines(void)
645{
646 memset(&map_pid_to_cmdline, -1, sizeof(map_pid_to_cmdline));
647 memset(&map_cmdline_to_pid, -1, sizeof(map_cmdline_to_pid));
648 cmdline_idx = 0;
649}
650
Steven Rostedt0f048702008-11-05 16:05:44 -0500651static int trace_stop_count;
652static DEFINE_SPINLOCK(tracing_start_lock);
653
654/**
655 * tracing_start - quick start of the tracer
656 *
657 * If tracing is enabled but was stopped by tracing_stop,
658 * this will start the tracer back up.
659 */
660void tracing_start(void)
661{
662 struct ring_buffer *buffer;
663 unsigned long flags;
664
665 if (tracing_disabled)
666 return;
667
668 spin_lock_irqsave(&tracing_start_lock, flags);
669 if (--trace_stop_count)
670 goto out;
671
672 if (trace_stop_count < 0) {
673 /* Someone screwed up their debugging */
674 WARN_ON_ONCE(1);
675 trace_stop_count = 0;
676 goto out;
677 }
678
679
680 buffer = global_trace.buffer;
681 if (buffer)
682 ring_buffer_record_enable(buffer);
683
684 buffer = max_tr.buffer;
685 if (buffer)
686 ring_buffer_record_enable(buffer);
687
688 ftrace_start();
689 out:
690 spin_unlock_irqrestore(&tracing_start_lock, flags);
691}
692
693/**
694 * tracing_stop - quick stop of the tracer
695 *
696 * Light weight way to stop tracing. Use in conjunction with
697 * tracing_start.
698 */
699void tracing_stop(void)
700{
701 struct ring_buffer *buffer;
702 unsigned long flags;
703
704 ftrace_stop();
705 spin_lock_irqsave(&tracing_start_lock, flags);
706 if (trace_stop_count++)
707 goto out;
708
709 buffer = global_trace.buffer;
710 if (buffer)
711 ring_buffer_record_disable(buffer);
712
713 buffer = max_tr.buffer;
714 if (buffer)
715 ring_buffer_record_disable(buffer);
716
717 out:
718 spin_unlock_irqrestore(&tracing_start_lock, flags);
719}
720
Ingo Molnare309b412008-05-12 21:20:51 +0200721void trace_stop_cmdline_recording(void);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200722
Ingo Molnare309b412008-05-12 21:20:51 +0200723static void trace_save_cmdline(struct task_struct *tsk)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200724{
725 unsigned map;
726 unsigned idx;
727
728 if (!tsk->pid || unlikely(tsk->pid > PID_MAX_DEFAULT))
729 return;
730
731 /*
732 * It's not the end of the world if we don't get
733 * the lock, but we also don't want to spin
734 * nor do we want to disable interrupts,
735 * so if we miss here, then better luck next time.
736 */
737 if (!spin_trylock(&trace_cmdline_lock))
738 return;
739
740 idx = map_pid_to_cmdline[tsk->pid];
741 if (idx >= SAVED_CMDLINES) {
742 idx = (cmdline_idx + 1) % SAVED_CMDLINES;
743
744 map = map_cmdline_to_pid[idx];
745 if (map <= PID_MAX_DEFAULT)
746 map_pid_to_cmdline[map] = (unsigned)-1;
747
748 map_pid_to_cmdline[tsk->pid] = idx;
749
750 cmdline_idx = idx;
751 }
752
753 memcpy(&saved_cmdlines[idx], tsk->comm, TASK_COMM_LEN);
754
755 spin_unlock(&trace_cmdline_lock);
756}
757
Ingo Molnare309b412008-05-12 21:20:51 +0200758static char *trace_find_cmdline(int pid)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200759{
760 char *cmdline = "<...>";
761 unsigned map;
762
763 if (!pid)
764 return "<idle>";
765
766 if (pid > PID_MAX_DEFAULT)
767 goto out;
768
769 map = map_pid_to_cmdline[pid];
770 if (map >= SAVED_CMDLINES)
771 goto out;
772
773 cmdline = saved_cmdlines[map];
774
775 out:
776 return cmdline;
777}
778
Ingo Molnare309b412008-05-12 21:20:51 +0200779void tracing_record_cmdline(struct task_struct *tsk)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200780{
781 if (atomic_read(&trace_record_cmdline_disabled))
782 return;
783
784 trace_save_cmdline(tsk);
785}
786
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300787void
Steven Rostedt38697052008-10-01 13:14:09 -0400788tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags,
789 int pc)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200790{
791 struct task_struct *tsk = current;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200792
Steven Rostedt777e2082008-09-29 23:02:42 -0400793 entry->preempt_count = pc & 0xff;
794 entry->pid = (tsk) ? tsk->pid : 0;
795 entry->flags =
Steven Rostedt92444892008-10-24 09:42:59 -0400796#ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
Steven Rostedt2e2ca152008-08-01 12:26:40 -0400797 (irqs_disabled_flags(flags) ? TRACE_FLAG_IRQS_OFF : 0) |
Steven Rostedt92444892008-10-24 09:42:59 -0400798#else
799 TRACE_FLAG_IRQS_NOSUPPORT |
800#endif
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200801 ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) |
802 ((pc & SOFTIRQ_MASK) ? TRACE_FLAG_SOFTIRQ : 0) |
803 (need_resched() ? TRACE_FLAG_NEED_RESCHED : 0);
804}
805
Ingo Molnare309b412008-05-12 21:20:51 +0200806void
Steven Rostedt6fb44b72008-05-12 21:20:49 +0200807trace_function(struct trace_array *tr, struct trace_array_cpu *data,
Steven Rostedt38697052008-10-01 13:14:09 -0400808 unsigned long ip, unsigned long parent_ip, unsigned long flags,
809 int pc)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200810{
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400811 struct ring_buffer_event *event;
Steven Rostedt777e2082008-09-29 23:02:42 -0400812 struct ftrace_entry *entry;
Ingo Molnardcb63082008-05-12 21:20:48 +0200813 unsigned long irq_flags;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200814
Steven Rostedtd7690412008-10-01 00:29:53 -0400815 /* If we are reading the ring buffer, don't trace */
816 if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled))))
817 return;
818
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400819 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
820 &irq_flags);
821 if (!event)
822 return;
823 entry = ring_buffer_event_data(event);
Steven Rostedt38697052008-10-01 13:14:09 -0400824 tracing_generic_entry_update(&entry->ent, flags, pc);
Steven Rostedt777e2082008-09-29 23:02:42 -0400825 entry->ent.type = TRACE_FN;
826 entry->ip = ip;
827 entry->parent_ip = parent_ip;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400828 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200829}
830
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100831#ifdef CONFIG_FUNCTION_RET_TRACER
832static void __trace_function_return(struct trace_array *tr,
833 struct trace_array_cpu *data,
834 struct ftrace_retfunc *trace,
835 unsigned long flags,
836 int pc)
837{
838 struct ring_buffer_event *event;
839 struct ftrace_ret_entry *entry;
840 unsigned long irq_flags;
841
842 if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled))))
843 return;
844
845 event = ring_buffer_lock_reserve(global_trace.buffer, sizeof(*entry),
846 &irq_flags);
847 if (!event)
848 return;
849 entry = ring_buffer_event_data(event);
850 tracing_generic_entry_update(&entry->ent, flags, pc);
851 entry->ent.type = TRACE_FN_RET;
852 entry->ip = trace->func;
853 entry->parent_ip = trace->ret;
854 entry->rettime = trace->rettime;
855 entry->calltime = trace->calltime;
Frederic Weisbecker02310222008-11-17 03:22:41 +0100856 entry->overrun = trace->overrun;
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100857 ring_buffer_unlock_commit(global_trace.buffer, event, irq_flags);
858}
859#endif
860
Ingo Molnare309b412008-05-12 21:20:51 +0200861void
Ingo Molnar2e0f5762008-05-12 21:20:49 +0200862ftrace(struct trace_array *tr, struct trace_array_cpu *data,
Steven Rostedt38697052008-10-01 13:14:09 -0400863 unsigned long ip, unsigned long parent_ip, unsigned long flags,
864 int pc)
Ingo Molnar2e0f5762008-05-12 21:20:49 +0200865{
866 if (likely(!atomic_read(&data->disabled)))
Steven Rostedt38697052008-10-01 13:14:09 -0400867 trace_function(tr, data, ip, parent_ip, flags, pc);
Ingo Molnar2e0f5762008-05-12 21:20:49 +0200868}
869
Steven Rostedt38697052008-10-01 13:14:09 -0400870static void ftrace_trace_stack(struct trace_array *tr,
871 struct trace_array_cpu *data,
872 unsigned long flags,
873 int skip, int pc)
Ingo Molnar86387f72008-05-12 21:20:51 +0200874{
Al Viroc2c80522008-10-31 19:50:41 +0000875#ifdef CONFIG_STACKTRACE
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400876 struct ring_buffer_event *event;
Steven Rostedt777e2082008-09-29 23:02:42 -0400877 struct stack_entry *entry;
Ingo Molnar86387f72008-05-12 21:20:51 +0200878 struct stack_trace trace;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400879 unsigned long irq_flags;
Ingo Molnar86387f72008-05-12 21:20:51 +0200880
881 if (!(trace_flags & TRACE_ITER_STACKTRACE))
882 return;
883
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400884 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
885 &irq_flags);
886 if (!event)
887 return;
888 entry = ring_buffer_event_data(event);
Steven Rostedt38697052008-10-01 13:14:09 -0400889 tracing_generic_entry_update(&entry->ent, flags, pc);
Steven Rostedt777e2082008-09-29 23:02:42 -0400890 entry->ent.type = TRACE_STACK;
Ingo Molnar86387f72008-05-12 21:20:51 +0200891
Steven Rostedt777e2082008-09-29 23:02:42 -0400892 memset(&entry->caller, 0, sizeof(entry->caller));
Ingo Molnar86387f72008-05-12 21:20:51 +0200893
894 trace.nr_entries = 0;
895 trace.max_entries = FTRACE_STACK_ENTRIES;
896 trace.skip = skip;
Steven Rostedt777e2082008-09-29 23:02:42 -0400897 trace.entries = entry->caller;
Ingo Molnar86387f72008-05-12 21:20:51 +0200898
899 save_stack_trace(&trace);
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400900 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
Al Viroc2c80522008-10-31 19:50:41 +0000901#endif
Ingo Molnarf0a920d2008-05-12 21:20:47 +0200902}
903
Steven Rostedt38697052008-10-01 13:14:09 -0400904void __trace_stack(struct trace_array *tr,
905 struct trace_array_cpu *data,
906 unsigned long flags,
907 int skip)
908{
909 ftrace_trace_stack(tr, data, flags, skip, preempt_count());
910}
911
912static void
913ftrace_trace_special(void *__tr, void *__data,
914 unsigned long arg1, unsigned long arg2, unsigned long arg3,
915 int pc)
Ingo Molnara4feb832008-05-12 21:21:02 +0200916{
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400917 struct ring_buffer_event *event;
Ingo Molnara4feb832008-05-12 21:21:02 +0200918 struct trace_array_cpu *data = __data;
919 struct trace_array *tr = __tr;
Steven Rostedt777e2082008-09-29 23:02:42 -0400920 struct special_entry *entry;
Ingo Molnara4feb832008-05-12 21:21:02 +0200921 unsigned long irq_flags;
922
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400923 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
924 &irq_flags);
925 if (!event)
926 return;
927 entry = ring_buffer_event_data(event);
Steven Rostedt38697052008-10-01 13:14:09 -0400928 tracing_generic_entry_update(&entry->ent, 0, pc);
Steven Rostedt777e2082008-09-29 23:02:42 -0400929 entry->ent.type = TRACE_SPECIAL;
930 entry->arg1 = arg1;
931 entry->arg2 = arg2;
932 entry->arg3 = arg3;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400933 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
Steven Rostedt38697052008-10-01 13:14:09 -0400934 ftrace_trace_stack(tr, data, irq_flags, 4, pc);
Ingo Molnara4feb832008-05-12 21:21:02 +0200935
936 trace_wake_up();
937}
938
939void
Steven Rostedt38697052008-10-01 13:14:09 -0400940__trace_special(void *__tr, void *__data,
941 unsigned long arg1, unsigned long arg2, unsigned long arg3)
942{
943 ftrace_trace_special(__tr, __data, arg1, arg2, arg3, preempt_count());
944}
945
946void
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200947tracing_sched_switch_trace(struct trace_array *tr,
948 struct trace_array_cpu *data,
Ingo Molnar86387f72008-05-12 21:20:51 +0200949 struct task_struct *prev,
950 struct task_struct *next,
Steven Rostedt38697052008-10-01 13:14:09 -0400951 unsigned long flags, int pc)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200952{
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400953 struct ring_buffer_event *event;
Steven Rostedt777e2082008-09-29 23:02:42 -0400954 struct ctx_switch_entry *entry;
Ingo Molnardcb63082008-05-12 21:20:48 +0200955 unsigned long irq_flags;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200956
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400957 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
958 &irq_flags);
959 if (!event)
960 return;
961 entry = ring_buffer_event_data(event);
Steven Rostedt38697052008-10-01 13:14:09 -0400962 tracing_generic_entry_update(&entry->ent, flags, pc);
Steven Rostedt777e2082008-09-29 23:02:42 -0400963 entry->ent.type = TRACE_CTX;
964 entry->prev_pid = prev->pid;
965 entry->prev_prio = prev->prio;
966 entry->prev_state = prev->state;
967 entry->next_pid = next->pid;
968 entry->next_prio = next->prio;
969 entry->next_state = next->state;
970 entry->next_cpu = task_cpu(next);
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400971 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
Steven Rostedt38697052008-10-01 13:14:09 -0400972 ftrace_trace_stack(tr, data, flags, 5, pc);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200973}
974
Ingo Molnar57422792008-05-12 21:20:51 +0200975void
976tracing_sched_wakeup_trace(struct trace_array *tr,
977 struct trace_array_cpu *data,
Ingo Molnar86387f72008-05-12 21:20:51 +0200978 struct task_struct *wakee,
979 struct task_struct *curr,
Steven Rostedt38697052008-10-01 13:14:09 -0400980 unsigned long flags, int pc)
Ingo Molnar57422792008-05-12 21:20:51 +0200981{
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400982 struct ring_buffer_event *event;
Steven Rostedt777e2082008-09-29 23:02:42 -0400983 struct ctx_switch_entry *entry;
Ingo Molnar57422792008-05-12 21:20:51 +0200984 unsigned long irq_flags;
985
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400986 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
987 &irq_flags);
988 if (!event)
989 return;
990 entry = ring_buffer_event_data(event);
Steven Rostedt38697052008-10-01 13:14:09 -0400991 tracing_generic_entry_update(&entry->ent, flags, pc);
Steven Rostedt777e2082008-09-29 23:02:42 -0400992 entry->ent.type = TRACE_WAKE;
993 entry->prev_pid = curr->pid;
994 entry->prev_prio = curr->prio;
995 entry->prev_state = curr->state;
996 entry->next_pid = wakee->pid;
997 entry->next_prio = wakee->prio;
998 entry->next_state = wakee->state;
999 entry->next_cpu = task_cpu(wakee);
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001000 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
Steven Rostedt38697052008-10-01 13:14:09 -04001001 ftrace_trace_stack(tr, data, flags, 6, pc);
Ingo Molnar017730c2008-05-12 21:20:52 +02001002
1003 trace_wake_up();
Ingo Molnar57422792008-05-12 21:20:51 +02001004}
1005
Steven Rostedt4902f882008-05-22 00:22:18 -04001006void
1007ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3)
1008{
1009 struct trace_array *tr = &global_trace;
1010 struct trace_array_cpu *data;
Steven Rostedt5aa1ba62008-11-10 23:07:30 -05001011 unsigned long flags;
Steven Rostedt4902f882008-05-22 00:22:18 -04001012 int cpu;
Steven Rostedt38697052008-10-01 13:14:09 -04001013 int pc;
Steven Rostedt4902f882008-05-22 00:22:18 -04001014
Steven Rostedtc76f0692008-11-07 22:36:02 -05001015 if (tracing_disabled)
Steven Rostedt4902f882008-05-22 00:22:18 -04001016 return;
1017
Steven Rostedt38697052008-10-01 13:14:09 -04001018 pc = preempt_count();
Steven Rostedt5aa1ba62008-11-10 23:07:30 -05001019 local_irq_save(flags);
Steven Rostedt4902f882008-05-22 00:22:18 -04001020 cpu = raw_smp_processor_id();
1021 data = tr->data[cpu];
Steven Rostedt4902f882008-05-22 00:22:18 -04001022
Steven Rostedt5aa1ba62008-11-10 23:07:30 -05001023 if (likely(atomic_inc_return(&data->disabled) == 1))
Steven Rostedt38697052008-10-01 13:14:09 -04001024 ftrace_trace_special(tr, data, arg1, arg2, arg3, pc);
Steven Rostedt4902f882008-05-22 00:22:18 -04001025
Steven Rostedt5aa1ba62008-11-10 23:07:30 -05001026 atomic_dec(&data->disabled);
1027 local_irq_restore(flags);
Steven Rostedt4902f882008-05-22 00:22:18 -04001028}
1029
Steven Rostedt606576c2008-10-06 19:06:12 -04001030#ifdef CONFIG_FUNCTION_TRACER
Ingo Molnare309b412008-05-12 21:20:51 +02001031static void
Steven Rostedtb2a866f2008-11-03 23:15:57 -05001032function_trace_call_preempt_only(unsigned long ip, unsigned long parent_ip)
Ingo Molnar2e0f5762008-05-12 21:20:49 +02001033{
1034 struct trace_array *tr = &global_trace;
1035 struct trace_array_cpu *data;
1036 unsigned long flags;
1037 long disabled;
Steven Rostedt38697052008-10-01 13:14:09 -04001038 int cpu, resched;
1039 int pc;
Ingo Molnar2e0f5762008-05-12 21:20:49 +02001040
Steven Rostedt60bc0802008-07-10 20:58:16 -04001041 if (unlikely(!ftrace_function_enabled))
Ingo Molnar2e0f5762008-05-12 21:20:49 +02001042 return;
1043
Steven Rostedt38697052008-10-01 13:14:09 -04001044 pc = preempt_count();
Steven Rostedt182e9f52008-11-03 23:15:56 -05001045 resched = ftrace_preempt_disable();
Steven Rostedt38697052008-10-01 13:14:09 -04001046 local_save_flags(flags);
Ingo Molnar2e0f5762008-05-12 21:20:49 +02001047 cpu = raw_smp_processor_id();
1048 data = tr->data[cpu];
1049 disabled = atomic_inc_return(&data->disabled);
1050
1051 if (likely(disabled == 1))
Steven Rostedt38697052008-10-01 13:14:09 -04001052 trace_function(tr, data, ip, parent_ip, flags, pc);
Ingo Molnar2e0f5762008-05-12 21:20:49 +02001053
1054 atomic_dec(&data->disabled);
Steven Rostedt182e9f52008-11-03 23:15:56 -05001055 ftrace_preempt_enable(resched);
Ingo Molnar2e0f5762008-05-12 21:20:49 +02001056}
1057
Steven Rostedtb2a866f2008-11-03 23:15:57 -05001058static void
1059function_trace_call(unsigned long ip, unsigned long parent_ip)
1060{
1061 struct trace_array *tr = &global_trace;
1062 struct trace_array_cpu *data;
1063 unsigned long flags;
1064 long disabled;
1065 int cpu;
1066 int pc;
1067
1068 if (unlikely(!ftrace_function_enabled))
1069 return;
1070
1071 /*
1072 * Need to use raw, since this must be called before the
1073 * recursive protection is performed.
1074 */
Steven Rostedtd51ad7a2008-11-15 15:48:29 -05001075 local_irq_save(flags);
Steven Rostedtb2a866f2008-11-03 23:15:57 -05001076 cpu = raw_smp_processor_id();
1077 data = tr->data[cpu];
1078 disabled = atomic_inc_return(&data->disabled);
1079
1080 if (likely(disabled == 1)) {
1081 pc = preempt_count();
1082 trace_function(tr, data, ip, parent_ip, flags, pc);
1083 }
1084
1085 atomic_dec(&data->disabled);
Steven Rostedtd51ad7a2008-11-15 15:48:29 -05001086 local_irq_restore(flags);
Steven Rostedtb2a866f2008-11-03 23:15:57 -05001087}
1088
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +01001089#ifdef CONFIG_FUNCTION_RET_TRACER
1090void trace_function_return(struct ftrace_retfunc *trace)
1091{
1092 struct trace_array *tr = &global_trace;
1093 struct trace_array_cpu *data;
1094 unsigned long flags;
1095 long disabled;
1096 int cpu;
1097 int pc;
1098
1099 raw_local_irq_save(flags);
1100 cpu = raw_smp_processor_id();
1101 data = tr->data[cpu];
1102 disabled = atomic_inc_return(&data->disabled);
1103 if (likely(disabled == 1)) {
1104 pc = preempt_count();
1105 __trace_function_return(tr, data, trace, flags, pc);
1106 }
1107 atomic_dec(&data->disabled);
1108 raw_local_irq_restore(flags);
1109}
1110#endif /* CONFIG_FUNCTION_RET_TRACER */
1111
Ingo Molnar2e0f5762008-05-12 21:20:49 +02001112static struct ftrace_ops trace_ops __read_mostly =
1113{
1114 .func = function_trace_call,
1115};
1116
Ingo Molnare309b412008-05-12 21:20:51 +02001117void tracing_start_function_trace(void)
Ingo Molnar2e0f5762008-05-12 21:20:49 +02001118{
Steven Rostedt60bc0802008-07-10 20:58:16 -04001119 ftrace_function_enabled = 0;
Steven Rostedtb2a866f2008-11-03 23:15:57 -05001120
1121 if (trace_flags & TRACE_ITER_PREEMPTONLY)
1122 trace_ops.func = function_trace_call_preempt_only;
1123 else
1124 trace_ops.func = function_trace_call;
1125
Ingo Molnar2e0f5762008-05-12 21:20:49 +02001126 register_ftrace_function(&trace_ops);
Steven Rostedt90369902008-11-05 16:05:44 -05001127 ftrace_function_enabled = 1;
Ingo Molnar2e0f5762008-05-12 21:20:49 +02001128}
1129
Ingo Molnare309b412008-05-12 21:20:51 +02001130void tracing_stop_function_trace(void)
Ingo Molnar2e0f5762008-05-12 21:20:49 +02001131{
Steven Rostedt60bc0802008-07-10 20:58:16 -04001132 ftrace_function_enabled = 0;
Ingo Molnar2e0f5762008-05-12 21:20:49 +02001133 unregister_ftrace_function(&trace_ops);
1134}
1135#endif
1136
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001137enum trace_file_type {
1138 TRACE_FILE_LAT_FMT = 1,
Steven Rostedt12ef7d42008-11-12 17:52:38 -05001139 TRACE_FILE_ANNOTATE = 2,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001140};
1141
Steven Rostedt5a90f572008-09-03 17:42:51 -04001142static void trace_iterator_increment(struct trace_iterator *iter, int cpu)
1143{
Steven Rostedtd7690412008-10-01 00:29:53 -04001144 /* Don't allow ftrace to trace into the ring buffers */
1145 ftrace_disable_cpu();
1146
Steven Rostedt5a90f572008-09-03 17:42:51 -04001147 iter->idx++;
Steven Rostedtd7690412008-10-01 00:29:53 -04001148 if (iter->buffer_iter[iter->cpu])
1149 ring_buffer_read(iter->buffer_iter[iter->cpu], NULL);
1150
1151 ftrace_enable_cpu();
Steven Rostedt5a90f572008-09-03 17:42:51 -04001152}
1153
Ingo Molnare309b412008-05-12 21:20:51 +02001154static struct trace_entry *
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001155peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts)
Steven Rostedtdd0e5452008-08-01 12:26:41 -04001156{
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001157 struct ring_buffer_event *event;
1158 struct ring_buffer_iter *buf_iter = iter->buffer_iter[cpu];
Steven Rostedtdd0e5452008-08-01 12:26:41 -04001159
Steven Rostedtd7690412008-10-01 00:29:53 -04001160 /* Don't allow ftrace to trace into the ring buffers */
1161 ftrace_disable_cpu();
1162
1163 if (buf_iter)
1164 event = ring_buffer_iter_peek(buf_iter, ts);
1165 else
1166 event = ring_buffer_peek(iter->tr->buffer, cpu, ts);
1167
1168 ftrace_enable_cpu();
1169
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001170 return event ? ring_buffer_event_data(event) : NULL;
Steven Rostedtdd0e5452008-08-01 12:26:41 -04001171}
Steven Rostedtd7690412008-10-01 00:29:53 -04001172
Steven Rostedtdd0e5452008-08-01 12:26:41 -04001173static struct trace_entry *
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001174__find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001175{
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001176 struct ring_buffer *buffer = iter->tr->buffer;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001177 struct trace_entry *ent, *next = NULL;
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001178 u64 next_ts = 0, ts;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001179 int next_cpu = -1;
1180 int cpu;
1181
Steven Rostedtab464282008-05-12 21:21:00 +02001182 for_each_tracing_cpu(cpu) {
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001183
1184 if (ring_buffer_empty_cpu(buffer, cpu))
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001185 continue;
Steven Rostedtdd0e5452008-08-01 12:26:41 -04001186
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001187 ent = peek_next_entry(iter, cpu, &ts);
Steven Rostedtdd0e5452008-08-01 12:26:41 -04001188
Ingo Molnarcdd31cd2008-05-12 21:20:46 +02001189 /*
1190 * Pick the entry with the smallest timestamp:
1191 */
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001192 if (ent && (!next || ts < next_ts)) {
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001193 next = ent;
1194 next_cpu = cpu;
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001195 next_ts = ts;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001196 }
1197 }
1198
1199 if (ent_cpu)
1200 *ent_cpu = next_cpu;
1201
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001202 if (ent_ts)
1203 *ent_ts = next_ts;
1204
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001205 return next;
1206}
1207
Steven Rostedtdd0e5452008-08-01 12:26:41 -04001208/* Find the next real entry, without updating the iterator itself */
1209static struct trace_entry *
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001210find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts)
Steven Rostedtb3806b42008-05-12 21:20:46 +02001211{
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001212 return __find_next_entry(iter, ent_cpu, ent_ts);
Steven Rostedtdd0e5452008-08-01 12:26:41 -04001213}
Ingo Molnar8c523a92008-05-12 21:20:46 +02001214
Steven Rostedtdd0e5452008-08-01 12:26:41 -04001215/* Find the next real entry, and increment the iterator to the next entry */
1216static void *find_next_entry_inc(struct trace_iterator *iter)
1217{
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001218 iter->ent = __find_next_entry(iter, &iter->cpu, &iter->ts);
Steven Rostedtb3806b42008-05-12 21:20:46 +02001219
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001220 if (iter->ent)
Steven Rostedtdd0e5452008-08-01 12:26:41 -04001221 trace_iterator_increment(iter, iter->cpu);
1222
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001223 return iter->ent ? iter : NULL;
Steven Rostedtb3806b42008-05-12 21:20:46 +02001224}
1225
Ingo Molnare309b412008-05-12 21:20:51 +02001226static void trace_consume(struct trace_iterator *iter)
Steven Rostedtb3806b42008-05-12 21:20:46 +02001227{
Steven Rostedtd7690412008-10-01 00:29:53 -04001228 /* Don't allow ftrace to trace into the ring buffers */
1229 ftrace_disable_cpu();
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001230 ring_buffer_consume(iter->tr->buffer, iter->cpu, &iter->ts);
Steven Rostedtd7690412008-10-01 00:29:53 -04001231 ftrace_enable_cpu();
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001232}
1233
Ingo Molnare309b412008-05-12 21:20:51 +02001234static void *s_next(struct seq_file *m, void *v, loff_t *pos)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001235{
1236 struct trace_iterator *iter = m->private;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001237 int i = (int)*pos;
Ingo Molnar4e3c3332008-05-12 21:20:45 +02001238 void *ent;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001239
1240 (*pos)++;
1241
1242 /* can't go backwards */
1243 if (iter->idx > i)
1244 return NULL;
1245
1246 if (iter->idx < 0)
1247 ent = find_next_entry_inc(iter);
1248 else
1249 ent = iter;
1250
1251 while (ent && iter->idx < i)
1252 ent = find_next_entry_inc(iter);
1253
1254 iter->pos = *pos;
1255
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001256 return ent;
1257}
1258
1259static void *s_start(struct seq_file *m, loff_t *pos)
1260{
1261 struct trace_iterator *iter = m->private;
1262 void *p = NULL;
1263 loff_t l = 0;
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001264 int cpu;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001265
1266 mutex_lock(&trace_types_lock);
1267
Steven Rostedtd15f57f2008-05-12 21:20:56 +02001268 if (!current_trace || current_trace != iter->trace) {
1269 mutex_unlock(&trace_types_lock);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001270 return NULL;
Steven Rostedtd15f57f2008-05-12 21:20:56 +02001271 }
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001272
1273 atomic_inc(&trace_record_cmdline_disabled);
1274
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001275 if (*pos != iter->pos) {
1276 iter->ent = NULL;
1277 iter->cpu = 0;
1278 iter->idx = -1;
1279
Steven Rostedtd7690412008-10-01 00:29:53 -04001280 ftrace_disable_cpu();
1281
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001282 for_each_tracing_cpu(cpu) {
1283 ring_buffer_iter_reset(iter->buffer_iter[cpu]);
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02001284 }
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001285
Steven Rostedtd7690412008-10-01 00:29:53 -04001286 ftrace_enable_cpu();
1287
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001288 for (p = iter; p && l < *pos; p = s_next(m, p, &l))
1289 ;
1290
1291 } else {
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02001292 l = *pos - 1;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001293 p = s_next(m, p, &l);
1294 }
1295
1296 return p;
1297}
1298
1299static void s_stop(struct seq_file *m, void *p)
1300{
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001301 atomic_dec(&trace_record_cmdline_disabled);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001302 mutex_unlock(&trace_types_lock);
1303}
1304
Abhishek Sagar76094a22008-05-28 00:03:18 +05301305#ifdef CONFIG_KRETPROBES
Steven Rostedtb3aa5572008-10-31 15:44:07 -04001306static inline const char *kretprobed(const char *name)
Abhishek Sagar76094a22008-05-28 00:03:18 +05301307{
Steven Rostedtb3aa5572008-10-31 15:44:07 -04001308 static const char tramp_name[] = "kretprobe_trampoline";
1309 int size = sizeof(tramp_name);
1310
1311 if (strncmp(tramp_name, name, size) == 0)
1312 return "[unknown/kretprobe'd]";
1313 return name;
Abhishek Sagar76094a22008-05-28 00:03:18 +05301314}
1315#else
Steven Rostedtb3aa5572008-10-31 15:44:07 -04001316static inline const char *kretprobed(const char *name)
Abhishek Sagar76094a22008-05-28 00:03:18 +05301317{
Steven Rostedtb3aa5572008-10-31 15:44:07 -04001318 return name;
Abhishek Sagar76094a22008-05-28 00:03:18 +05301319}
1320#endif /* CONFIG_KRETPROBES */
1321
Steven Rostedtb3806b42008-05-12 21:20:46 +02001322static int
Steven Rostedt214023c2008-05-12 21:20:46 +02001323seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001324{
1325#ifdef CONFIG_KALLSYMS
1326 char str[KSYM_SYMBOL_LEN];
Steven Rostedtb3aa5572008-10-31 15:44:07 -04001327 const char *name;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001328
1329 kallsyms_lookup(address, NULL, NULL, NULL, str);
1330
Steven Rostedtb3aa5572008-10-31 15:44:07 -04001331 name = kretprobed(str);
1332
1333 return trace_seq_printf(s, fmt, name);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001334#endif
Steven Rostedtb3806b42008-05-12 21:20:46 +02001335 return 1;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001336}
1337
Steven Rostedtb3806b42008-05-12 21:20:46 +02001338static int
Steven Rostedt214023c2008-05-12 21:20:46 +02001339seq_print_sym_offset(struct trace_seq *s, const char *fmt,
1340 unsigned long address)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001341{
1342#ifdef CONFIG_KALLSYMS
1343 char str[KSYM_SYMBOL_LEN];
Steven Rostedtb3aa5572008-10-31 15:44:07 -04001344 const char *name;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001345
1346 sprint_symbol(str, address);
Steven Rostedtb3aa5572008-10-31 15:44:07 -04001347 name = kretprobed(str);
1348
1349 return trace_seq_printf(s, fmt, name);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001350#endif
Steven Rostedtb3806b42008-05-12 21:20:46 +02001351 return 1;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001352}
1353
1354#ifndef CONFIG_64BIT
1355# define IP_FMT "%08lx"
1356#else
1357# define IP_FMT "%016lx"
1358#endif
1359
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +01001360int
Steven Rostedt214023c2008-05-12 21:20:46 +02001361seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001362{
Steven Rostedtb3806b42008-05-12 21:20:46 +02001363 int ret;
1364
1365 if (!ip)
1366 return trace_seq_printf(s, "0");
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001367
1368 if (sym_flags & TRACE_ITER_SYM_OFFSET)
Steven Rostedtb3806b42008-05-12 21:20:46 +02001369 ret = seq_print_sym_offset(s, "%s", ip);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001370 else
Steven Rostedtb3806b42008-05-12 21:20:46 +02001371 ret = seq_print_sym_short(s, "%s", ip);
1372
1373 if (!ret)
1374 return 0;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001375
1376 if (sym_flags & TRACE_ITER_SYM_ADDR)
Steven Rostedtb3806b42008-05-12 21:20:46 +02001377 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
1378 return ret;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001379}
1380
Ingo Molnare309b412008-05-12 21:20:51 +02001381static void print_lat_help_header(struct seq_file *m)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001382{
Michael Ellermana6168352008-08-20 16:36:11 -07001383 seq_puts(m, "# _------=> CPU# \n");
1384 seq_puts(m, "# / _-----=> irqs-off \n");
1385 seq_puts(m, "# | / _----=> need-resched \n");
1386 seq_puts(m, "# || / _---=> hardirq/softirq \n");
1387 seq_puts(m, "# ||| / _--=> preempt-depth \n");
1388 seq_puts(m, "# |||| / \n");
1389 seq_puts(m, "# ||||| delay \n");
1390 seq_puts(m, "# cmd pid ||||| time | caller \n");
1391 seq_puts(m, "# \\ / ||||| \\ | / \n");
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001392}
1393
Ingo Molnare309b412008-05-12 21:20:51 +02001394static void print_func_help_header(struct seq_file *m)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001395{
Michael Ellermana6168352008-08-20 16:36:11 -07001396 seq_puts(m, "# TASK-PID CPU# TIMESTAMP FUNCTION\n");
1397 seq_puts(m, "# | | | | |\n");
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001398}
1399
1400
Ingo Molnare309b412008-05-12 21:20:51 +02001401static void
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001402print_trace_header(struct seq_file *m, struct trace_iterator *iter)
1403{
1404 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
1405 struct trace_array *tr = iter->tr;
1406 struct trace_array_cpu *data = tr->data[tr->cpu];
1407 struct tracer *type = current_trace;
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001408 unsigned long total;
1409 unsigned long entries;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001410 const char *name = "preemption";
1411
1412 if (type)
1413 name = type->name;
1414
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001415 entries = ring_buffer_entries(iter->tr->buffer);
1416 total = entries +
1417 ring_buffer_overruns(iter->tr->buffer);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001418
1419 seq_printf(m, "%s latency trace v1.1.5 on %s\n",
1420 name, UTS_RELEASE);
1421 seq_puts(m, "-----------------------------------"
1422 "---------------------------------\n");
1423 seq_printf(m, " latency: %lu us, #%lu/%lu, CPU#%d |"
1424 " (M:%s VP:%d, KP:%d, SP:%d HP:%d",
Steven Rostedt57f50be2008-05-12 21:20:44 +02001425 nsecs_to_usecs(data->saved_latency),
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001426 entries,
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02001427 total,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001428 tr->cpu,
1429#if defined(CONFIG_PREEMPT_NONE)
1430 "server",
1431#elif defined(CONFIG_PREEMPT_VOLUNTARY)
1432 "desktop",
Steven Rostedtb5c21b42008-07-10 20:58:12 -04001433#elif defined(CONFIG_PREEMPT)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001434 "preempt",
1435#else
1436 "unknown",
1437#endif
1438 /* These are reserved for later use */
1439 0, 0, 0, 0);
1440#ifdef CONFIG_SMP
1441 seq_printf(m, " #P:%d)\n", num_online_cpus());
1442#else
1443 seq_puts(m, ")\n");
1444#endif
1445 seq_puts(m, " -----------------\n");
1446 seq_printf(m, " | task: %.16s-%d "
1447 "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n",
1448 data->comm, data->pid, data->uid, data->nice,
1449 data->policy, data->rt_priority);
1450 seq_puts(m, " -----------------\n");
1451
1452 if (data->critical_start) {
1453 seq_puts(m, " => started at: ");
Steven Rostedt214023c2008-05-12 21:20:46 +02001454 seq_print_ip_sym(&iter->seq, data->critical_start, sym_flags);
1455 trace_print_seq(m, &iter->seq);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001456 seq_puts(m, "\n => ended at: ");
Steven Rostedt214023c2008-05-12 21:20:46 +02001457 seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags);
1458 trace_print_seq(m, &iter->seq);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001459 seq_puts(m, "\n");
1460 }
1461
1462 seq_puts(m, "\n");
1463}
1464
Ingo Molnare309b412008-05-12 21:20:51 +02001465static void
Steven Rostedt214023c2008-05-12 21:20:46 +02001466lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001467{
1468 int hardirq, softirq;
1469 char *comm;
1470
Steven Rostedt777e2082008-09-29 23:02:42 -04001471 comm = trace_find_cmdline(entry->pid);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001472
Steven Rostedt777e2082008-09-29 23:02:42 -04001473 trace_seq_printf(s, "%8.8s-%-5d ", comm, entry->pid);
Michael Ellermana6168352008-08-20 16:36:11 -07001474 trace_seq_printf(s, "%3d", cpu);
Steven Rostedt214023c2008-05-12 21:20:46 +02001475 trace_seq_printf(s, "%c%c",
Steven Rostedt92444892008-10-24 09:42:59 -04001476 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
1477 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' : '.',
Steven Rostedt777e2082008-09-29 23:02:42 -04001478 ((entry->flags & TRACE_FLAG_NEED_RESCHED) ? 'N' : '.'));
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001479
Steven Rostedt777e2082008-09-29 23:02:42 -04001480 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
1481 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
Ingo Molnarafc2abc2008-05-12 21:21:00 +02001482 if (hardirq && softirq) {
Steven Rostedt214023c2008-05-12 21:20:46 +02001483 trace_seq_putc(s, 'H');
Ingo Molnarafc2abc2008-05-12 21:21:00 +02001484 } else {
1485 if (hardirq) {
Steven Rostedt214023c2008-05-12 21:20:46 +02001486 trace_seq_putc(s, 'h');
Ingo Molnarafc2abc2008-05-12 21:21:00 +02001487 } else {
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001488 if (softirq)
Steven Rostedt214023c2008-05-12 21:20:46 +02001489 trace_seq_putc(s, 's');
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001490 else
Steven Rostedt214023c2008-05-12 21:20:46 +02001491 trace_seq_putc(s, '.');
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001492 }
1493 }
1494
Steven Rostedt777e2082008-09-29 23:02:42 -04001495 if (entry->preempt_count)
1496 trace_seq_printf(s, "%x", entry->preempt_count);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001497 else
Steven Rostedt214023c2008-05-12 21:20:46 +02001498 trace_seq_puts(s, ".");
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001499}
1500
1501unsigned long preempt_mark_thresh = 100;
1502
Ingo Molnare309b412008-05-12 21:20:51 +02001503static void
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001504lat_print_timestamp(struct trace_seq *s, u64 abs_usecs,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001505 unsigned long rel_usecs)
1506{
Steven Rostedt214023c2008-05-12 21:20:46 +02001507 trace_seq_printf(s, " %4lldus", abs_usecs);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001508 if (rel_usecs > preempt_mark_thresh)
Steven Rostedt214023c2008-05-12 21:20:46 +02001509 trace_seq_puts(s, "!: ");
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001510 else if (rel_usecs > 1)
Steven Rostedt214023c2008-05-12 21:20:46 +02001511 trace_seq_puts(s, "+: ");
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001512 else
Steven Rostedt214023c2008-05-12 21:20:46 +02001513 trace_seq_puts(s, " : ");
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001514}
1515
1516static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
1517
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +03001518/*
1519 * The message is supposed to contain an ending newline.
1520 * If the printing stops prematurely, try to add a newline of our own.
1521 */
1522void trace_seq_print_cont(struct trace_seq *s, struct trace_iterator *iter)
Steven Rostedtdd0e5452008-08-01 12:26:41 -04001523{
Steven Rostedtdd0e5452008-08-01 12:26:41 -04001524 struct trace_entry *ent;
Steven Rostedt777e2082008-09-29 23:02:42 -04001525 struct trace_field_cont *cont;
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +03001526 bool ok = true;
Steven Rostedtdd0e5452008-08-01 12:26:41 -04001527
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001528 ent = peek_next_entry(iter, iter->cpu, NULL);
Steven Rostedtdd0e5452008-08-01 12:26:41 -04001529 if (!ent || ent->type != TRACE_CONT) {
1530 trace_seq_putc(s, '\n');
1531 return;
1532 }
1533
1534 do {
Steven Rostedt777e2082008-09-29 23:02:42 -04001535 cont = (struct trace_field_cont *)ent;
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +03001536 if (ok)
Steven Rostedt777e2082008-09-29 23:02:42 -04001537 ok = (trace_seq_printf(s, "%s", cont->buf) > 0);
Steven Rostedtd7690412008-10-01 00:29:53 -04001538
1539 ftrace_disable_cpu();
1540
1541 if (iter->buffer_iter[iter->cpu])
1542 ring_buffer_read(iter->buffer_iter[iter->cpu], NULL);
1543 else
1544 ring_buffer_consume(iter->tr->buffer, iter->cpu, NULL);
1545
1546 ftrace_enable_cpu();
1547
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001548 ent = peek_next_entry(iter, iter->cpu, NULL);
Steven Rostedtdd0e5452008-08-01 12:26:41 -04001549 } while (ent && ent->type == TRACE_CONT);
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +03001550
1551 if (!ok)
1552 trace_seq_putc(s, '\n');
Steven Rostedtdd0e5452008-08-01 12:26:41 -04001553}
1554
Steven Rostedta3097202008-11-07 22:36:02 -05001555static void test_cpu_buff_start(struct trace_iterator *iter)
1556{
1557 struct trace_seq *s = &iter->seq;
1558
Steven Rostedt12ef7d42008-11-12 17:52:38 -05001559 if (!(trace_flags & TRACE_ITER_ANNOTATE))
1560 return;
1561
1562 if (!(iter->iter_flags & TRACE_FILE_ANNOTATE))
1563 return;
1564
Steven Rostedta3097202008-11-07 22:36:02 -05001565 if (cpu_isset(iter->cpu, iter->started))
1566 return;
1567
1568 cpu_set(iter->cpu, iter->started);
1569 trace_seq_printf(s, "##### CPU %u buffer started ####\n", iter->cpu);
1570}
1571
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02001572static enum print_line_t
Steven Rostedt214023c2008-05-12 21:20:46 +02001573print_lat_fmt(struct trace_iterator *iter, unsigned int trace_idx, int cpu)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001574{
Steven Rostedt214023c2008-05-12 21:20:46 +02001575 struct trace_seq *s = &iter->seq;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001576 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001577 struct trace_entry *next_entry;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001578 unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
1579 struct trace_entry *entry = iter->ent;
1580 unsigned long abs_usecs;
1581 unsigned long rel_usecs;
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001582 u64 next_ts;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001583 char *comm;
Peter Zijlstrabac524d2008-05-12 21:20:53 +02001584 int S, T;
Ingo Molnar86387f72008-05-12 21:20:51 +02001585 int i;
Ankita Gargd17d9692008-05-12 21:20:58 +02001586 unsigned state;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001587
Steven Rostedtdd0e5452008-08-01 12:26:41 -04001588 if (entry->type == TRACE_CONT)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02001589 return TRACE_TYPE_HANDLED;
Steven Rostedtdd0e5452008-08-01 12:26:41 -04001590
Steven Rostedta3097202008-11-07 22:36:02 -05001591 test_cpu_buff_start(iter);
1592
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001593 next_entry = find_next_entry(iter, NULL, &next_ts);
1594 if (!next_entry)
1595 next_ts = iter->ts;
1596 rel_usecs = ns2usecs(next_ts - iter->ts);
1597 abs_usecs = ns2usecs(iter->ts - iter->tr->time_start);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001598
1599 if (verbose) {
Steven Rostedt777e2082008-09-29 23:02:42 -04001600 comm = trace_find_cmdline(entry->pid);
Michael Ellermana6168352008-08-20 16:36:11 -07001601 trace_seq_printf(s, "%16s %5d %3d %d %08x %08x [%08lx]"
Steven Rostedt214023c2008-05-12 21:20:46 +02001602 " %ld.%03ldms (+%ld.%03ldms): ",
1603 comm,
Steven Rostedt777e2082008-09-29 23:02:42 -04001604 entry->pid, cpu, entry->flags,
1605 entry->preempt_count, trace_idx,
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001606 ns2usecs(iter->ts),
Steven Rostedt214023c2008-05-12 21:20:46 +02001607 abs_usecs/1000,
1608 abs_usecs % 1000, rel_usecs/1000,
1609 rel_usecs % 1000);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001610 } else {
Ingo Molnarf29c73f2008-05-12 21:20:53 +02001611 lat_print_generic(s, entry, cpu);
1612 lat_print_timestamp(s, abs_usecs, rel_usecs);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001613 }
1614 switch (entry->type) {
Steven Rostedt777e2082008-09-29 23:02:42 -04001615 case TRACE_FN: {
Steven Rostedt7104f302008-10-01 10:52:51 -04001616 struct ftrace_entry *field;
1617
1618 trace_assign_type(field, entry);
Steven Rostedt777e2082008-09-29 23:02:42 -04001619
1620 seq_print_ip_sym(s, field->ip, sym_flags);
Steven Rostedt214023c2008-05-12 21:20:46 +02001621 trace_seq_puts(s, " (");
Steven Rostedtb3aa5572008-10-31 15:44:07 -04001622 seq_print_ip_sym(s, field->parent_ip, sym_flags);
Steven Rostedt214023c2008-05-12 21:20:46 +02001623 trace_seq_puts(s, ")\n");
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001624 break;
Steven Rostedt777e2082008-09-29 23:02:42 -04001625 }
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001626 case TRACE_CTX:
Steven Rostedt777e2082008-09-29 23:02:42 -04001627 case TRACE_WAKE: {
Steven Rostedt7104f302008-10-01 10:52:51 -04001628 struct ctx_switch_entry *field;
1629
1630 trace_assign_type(field, entry);
Peter Zijlstrabac524d2008-05-12 21:20:53 +02001631
Steven Rostedt777e2082008-09-29 23:02:42 -04001632 T = field->next_state < sizeof(state_to_char) ?
1633 state_to_char[field->next_state] : 'X';
1634
1635 state = field->prev_state ?
1636 __ffs(field->prev_state) + 1 : 0;
Ankita Gargd17d9692008-05-12 21:20:58 +02001637 S = state < sizeof(state_to_char) - 1 ? state_to_char[state] : 'X';
Steven Rostedt777e2082008-09-29 23:02:42 -04001638 comm = trace_find_cmdline(field->next_pid);
Peter Zijlstra80b5e942008-09-04 10:24:16 +02001639 trace_seq_printf(s, " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
Steven Rostedt777e2082008-09-29 23:02:42 -04001640 field->prev_pid,
1641 field->prev_prio,
Ingo Molnar57422792008-05-12 21:20:51 +02001642 S, entry->type == TRACE_CTX ? "==>" : " +",
Steven Rostedt777e2082008-09-29 23:02:42 -04001643 field->next_cpu,
1644 field->next_pid,
1645 field->next_prio,
Peter Zijlstrabac524d2008-05-12 21:20:53 +02001646 T, comm);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001647 break;
Steven Rostedt777e2082008-09-29 23:02:42 -04001648 }
1649 case TRACE_SPECIAL: {
Steven Rostedt7104f302008-10-01 10:52:51 -04001650 struct special_entry *field;
1651
1652 trace_assign_type(field, entry);
Steven Rostedt777e2082008-09-29 23:02:42 -04001653
Ingo Molnar88a42162008-05-12 21:20:53 +02001654 trace_seq_printf(s, "# %ld %ld %ld\n",
Steven Rostedt777e2082008-09-29 23:02:42 -04001655 field->arg1,
1656 field->arg2,
1657 field->arg3);
Ingo Molnarf0a920d2008-05-12 21:20:47 +02001658 break;
Steven Rostedt777e2082008-09-29 23:02:42 -04001659 }
1660 case TRACE_STACK: {
Steven Rostedt7104f302008-10-01 10:52:51 -04001661 struct stack_entry *field;
1662
1663 trace_assign_type(field, entry);
Steven Rostedt777e2082008-09-29 23:02:42 -04001664
Ingo Molnar86387f72008-05-12 21:20:51 +02001665 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
1666 if (i)
1667 trace_seq_puts(s, " <= ");
Steven Rostedt777e2082008-09-29 23:02:42 -04001668 seq_print_ip_sym(s, field->caller[i], sym_flags);
Ingo Molnar86387f72008-05-12 21:20:51 +02001669 }
1670 trace_seq_puts(s, "\n");
1671 break;
Steven Rostedt777e2082008-09-29 23:02:42 -04001672 }
1673 case TRACE_PRINT: {
Steven Rostedt7104f302008-10-01 10:52:51 -04001674 struct print_entry *field;
1675
1676 trace_assign_type(field, entry);
Steven Rostedt777e2082008-09-29 23:02:42 -04001677
1678 seq_print_ip_sym(s, field->ip, sym_flags);
1679 trace_seq_printf(s, ": %s", field->buf);
1680 if (entry->flags & TRACE_FLAG_CONT)
Steven Rostedtdd0e5452008-08-01 12:26:41 -04001681 trace_seq_print_cont(s, iter);
1682 break;
Steven Rostedt777e2082008-09-29 23:02:42 -04001683 }
Steven Rostedt9f029e82008-11-12 15:24:24 -05001684 case TRACE_BRANCH: {
1685 struct trace_branch *field;
Steven Rostedt52f232c2008-11-12 00:14:40 -05001686
1687 trace_assign_type(field, entry);
1688
1689 trace_seq_printf(s, "[%s] %s:%s:%d\n",
Ingo Molnar68d119f2008-11-12 14:09:30 +01001690 field->correct ? " ok " : " MISS ",
Steven Rostedt52f232c2008-11-12 00:14:40 -05001691 field->func,
1692 field->file,
1693 field->line);
1694 break;
1695 }
Steven Rostedt89b2f972008-05-12 21:20:44 +02001696 default:
Steven Rostedt214023c2008-05-12 21:20:46 +02001697 trace_seq_printf(s, "Unknown type %d\n", entry->type);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001698 }
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02001699 return TRACE_TYPE_HANDLED;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001700}
1701
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02001702static enum print_line_t print_trace_fmt(struct trace_iterator *iter)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001703{
Steven Rostedt214023c2008-05-12 21:20:46 +02001704 struct trace_seq *s = &iter->seq;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001705 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
Ingo Molnar4e3c3332008-05-12 21:20:45 +02001706 struct trace_entry *entry;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001707 unsigned long usec_rem;
1708 unsigned long long t;
1709 unsigned long secs;
1710 char *comm;
Steven Rostedtb3806b42008-05-12 21:20:46 +02001711 int ret;
Peter Zijlstrabac524d2008-05-12 21:20:53 +02001712 int S, T;
Ingo Molnar86387f72008-05-12 21:20:51 +02001713 int i;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001714
Ingo Molnar4e3c3332008-05-12 21:20:45 +02001715 entry = iter->ent;
Steven Rostedtdd0e5452008-08-01 12:26:41 -04001716
1717 if (entry->type == TRACE_CONT)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02001718 return TRACE_TYPE_HANDLED;
Steven Rostedtdd0e5452008-08-01 12:26:41 -04001719
Steven Rostedta3097202008-11-07 22:36:02 -05001720 test_cpu_buff_start(iter);
1721
Steven Rostedt777e2082008-09-29 23:02:42 -04001722 comm = trace_find_cmdline(iter->ent->pid);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001723
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001724 t = ns2usecs(iter->ts);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001725 usec_rem = do_div(t, 1000000ULL);
1726 secs = (unsigned long)t;
1727
Steven Rostedt777e2082008-09-29 23:02:42 -04001728 ret = trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid);
Ingo Molnarf29c73f2008-05-12 21:20:53 +02001729 if (!ret)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02001730 return TRACE_TYPE_PARTIAL_LINE;
Michael Ellermana6168352008-08-20 16:36:11 -07001731 ret = trace_seq_printf(s, "[%03d] ", iter->cpu);
Ingo Molnarf29c73f2008-05-12 21:20:53 +02001732 if (!ret)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02001733 return TRACE_TYPE_PARTIAL_LINE;
Ingo Molnarf29c73f2008-05-12 21:20:53 +02001734 ret = trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem);
1735 if (!ret)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02001736 return TRACE_TYPE_PARTIAL_LINE;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001737
1738 switch (entry->type) {
Steven Rostedt777e2082008-09-29 23:02:42 -04001739 case TRACE_FN: {
Steven Rostedt7104f302008-10-01 10:52:51 -04001740 struct ftrace_entry *field;
1741
1742 trace_assign_type(field, entry);
Steven Rostedt777e2082008-09-29 23:02:42 -04001743
1744 ret = seq_print_ip_sym(s, field->ip, sym_flags);
Steven Rostedtb3806b42008-05-12 21:20:46 +02001745 if (!ret)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02001746 return TRACE_TYPE_PARTIAL_LINE;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001747 if ((sym_flags & TRACE_ITER_PRINT_PARENT) &&
Steven Rostedt777e2082008-09-29 23:02:42 -04001748 field->parent_ip) {
Steven Rostedtb3806b42008-05-12 21:20:46 +02001749 ret = trace_seq_printf(s, " <-");
1750 if (!ret)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02001751 return TRACE_TYPE_PARTIAL_LINE;
Steven Rostedtb3aa5572008-10-31 15:44:07 -04001752 ret = seq_print_ip_sym(s,
1753 field->parent_ip,
1754 sym_flags);
Steven Rostedtb3806b42008-05-12 21:20:46 +02001755 if (!ret)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02001756 return TRACE_TYPE_PARTIAL_LINE;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001757 }
Steven Rostedtb3806b42008-05-12 21:20:46 +02001758 ret = trace_seq_printf(s, "\n");
1759 if (!ret)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02001760 return TRACE_TYPE_PARTIAL_LINE;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001761 break;
Steven Rostedt777e2082008-09-29 23:02:42 -04001762 }
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001763 case TRACE_CTX:
Steven Rostedt777e2082008-09-29 23:02:42 -04001764 case TRACE_WAKE: {
Steven Rostedt7104f302008-10-01 10:52:51 -04001765 struct ctx_switch_entry *field;
1766
1767 trace_assign_type(field, entry);
Steven Rostedt777e2082008-09-29 23:02:42 -04001768
1769 S = field->prev_state < sizeof(state_to_char) ?
1770 state_to_char[field->prev_state] : 'X';
1771 T = field->next_state < sizeof(state_to_char) ?
1772 state_to_char[field->next_state] : 'X';
Peter Zijlstra80b5e942008-09-04 10:24:16 +02001773 ret = trace_seq_printf(s, " %5d:%3d:%c %s [%03d] %5d:%3d:%c\n",
Steven Rostedt777e2082008-09-29 23:02:42 -04001774 field->prev_pid,
1775 field->prev_prio,
Steven Rostedtb3806b42008-05-12 21:20:46 +02001776 S,
Ingo Molnar57422792008-05-12 21:20:51 +02001777 entry->type == TRACE_CTX ? "==>" : " +",
Steven Rostedt777e2082008-09-29 23:02:42 -04001778 field->next_cpu,
1779 field->next_pid,
1780 field->next_prio,
Peter Zijlstrabac524d2008-05-12 21:20:53 +02001781 T);
Steven Rostedtb3806b42008-05-12 21:20:46 +02001782 if (!ret)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02001783 return TRACE_TYPE_PARTIAL_LINE;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001784 break;
Steven Rostedt777e2082008-09-29 23:02:42 -04001785 }
1786 case TRACE_SPECIAL: {
Steven Rostedt7104f302008-10-01 10:52:51 -04001787 struct special_entry *field;
1788
1789 trace_assign_type(field, entry);
Steven Rostedt777e2082008-09-29 23:02:42 -04001790
Ingo Molnar88a42162008-05-12 21:20:53 +02001791 ret = trace_seq_printf(s, "# %ld %ld %ld\n",
Steven Rostedt777e2082008-09-29 23:02:42 -04001792 field->arg1,
1793 field->arg2,
1794 field->arg3);
Ingo Molnarf0a920d2008-05-12 21:20:47 +02001795 if (!ret)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02001796 return TRACE_TYPE_PARTIAL_LINE;
Ingo Molnarf0a920d2008-05-12 21:20:47 +02001797 break;
Steven Rostedt777e2082008-09-29 23:02:42 -04001798 }
1799 case TRACE_STACK: {
Steven Rostedt7104f302008-10-01 10:52:51 -04001800 struct stack_entry *field;
1801
1802 trace_assign_type(field, entry);
Steven Rostedt777e2082008-09-29 23:02:42 -04001803
Ingo Molnar86387f72008-05-12 21:20:51 +02001804 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
1805 if (i) {
1806 ret = trace_seq_puts(s, " <= ");
1807 if (!ret)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02001808 return TRACE_TYPE_PARTIAL_LINE;
Ingo Molnar86387f72008-05-12 21:20:51 +02001809 }
Steven Rostedt777e2082008-09-29 23:02:42 -04001810 ret = seq_print_ip_sym(s, field->caller[i],
Ingo Molnar86387f72008-05-12 21:20:51 +02001811 sym_flags);
1812 if (!ret)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02001813 return TRACE_TYPE_PARTIAL_LINE;
Ingo Molnar86387f72008-05-12 21:20:51 +02001814 }
1815 ret = trace_seq_puts(s, "\n");
1816 if (!ret)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02001817 return TRACE_TYPE_PARTIAL_LINE;
Ingo Molnar86387f72008-05-12 21:20:51 +02001818 break;
Steven Rostedt777e2082008-09-29 23:02:42 -04001819 }
1820 case TRACE_PRINT: {
Steven Rostedt7104f302008-10-01 10:52:51 -04001821 struct print_entry *field;
1822
1823 trace_assign_type(field, entry);
Steven Rostedt777e2082008-09-29 23:02:42 -04001824
1825 seq_print_ip_sym(s, field->ip, sym_flags);
1826 trace_seq_printf(s, ": %s", field->buf);
1827 if (entry->flags & TRACE_FLAG_CONT)
Steven Rostedtdd0e5452008-08-01 12:26:41 -04001828 trace_seq_print_cont(s, iter);
1829 break;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001830 }
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +01001831 case TRACE_FN_RET: {
1832 return print_return_function(iter);
1833 break;
1834 }
Steven Rostedt9f029e82008-11-12 15:24:24 -05001835 case TRACE_BRANCH: {
1836 struct trace_branch *field;
Steven Rostedt52f232c2008-11-12 00:14:40 -05001837
1838 trace_assign_type(field, entry);
1839
1840 trace_seq_printf(s, "[%s] %s:%s:%d\n",
Ingo Molnar68d119f2008-11-12 14:09:30 +01001841 field->correct ? " ok " : " MISS ",
Steven Rostedt52f232c2008-11-12 00:14:40 -05001842 field->func,
1843 field->file,
1844 field->line);
1845 break;
1846 }
Steven Rostedt777e2082008-09-29 23:02:42 -04001847 }
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02001848 return TRACE_TYPE_HANDLED;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001849}
1850
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02001851static enum print_line_t print_raw_fmt(struct trace_iterator *iter)
Ingo Molnarf9896bf2008-05-12 21:20:47 +02001852{
1853 struct trace_seq *s = &iter->seq;
1854 struct trace_entry *entry;
1855 int ret;
Peter Zijlstrabac524d2008-05-12 21:20:53 +02001856 int S, T;
Ingo Molnarf9896bf2008-05-12 21:20:47 +02001857
1858 entry = iter->ent;
Steven Rostedtdd0e5452008-08-01 12:26:41 -04001859
1860 if (entry->type == TRACE_CONT)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02001861 return TRACE_TYPE_HANDLED;
Steven Rostedtdd0e5452008-08-01 12:26:41 -04001862
Ingo Molnarf9896bf2008-05-12 21:20:47 +02001863 ret = trace_seq_printf(s, "%d %d %llu ",
Steven Rostedt777e2082008-09-29 23:02:42 -04001864 entry->pid, iter->cpu, iter->ts);
Ingo Molnarf9896bf2008-05-12 21:20:47 +02001865 if (!ret)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02001866 return TRACE_TYPE_PARTIAL_LINE;
Ingo Molnarf9896bf2008-05-12 21:20:47 +02001867
1868 switch (entry->type) {
Steven Rostedt777e2082008-09-29 23:02:42 -04001869 case TRACE_FN: {
Steven Rostedt7104f302008-10-01 10:52:51 -04001870 struct ftrace_entry *field;
1871
1872 trace_assign_type(field, entry);
Steven Rostedt777e2082008-09-29 23:02:42 -04001873
Ingo Molnarf9896bf2008-05-12 21:20:47 +02001874 ret = trace_seq_printf(s, "%x %x\n",
Steven Rostedt777e2082008-09-29 23:02:42 -04001875 field->ip,
1876 field->parent_ip);
Ingo Molnarf9896bf2008-05-12 21:20:47 +02001877 if (!ret)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02001878 return TRACE_TYPE_PARTIAL_LINE;
Ingo Molnarf9896bf2008-05-12 21:20:47 +02001879 break;
Steven Rostedt777e2082008-09-29 23:02:42 -04001880 }
Ingo Molnarf9896bf2008-05-12 21:20:47 +02001881 case TRACE_CTX:
Steven Rostedt777e2082008-09-29 23:02:42 -04001882 case TRACE_WAKE: {
Steven Rostedt7104f302008-10-01 10:52:51 -04001883 struct ctx_switch_entry *field;
1884
1885 trace_assign_type(field, entry);
Steven Rostedt777e2082008-09-29 23:02:42 -04001886
1887 S = field->prev_state < sizeof(state_to_char) ?
1888 state_to_char[field->prev_state] : 'X';
1889 T = field->next_state < sizeof(state_to_char) ?
1890 state_to_char[field->next_state] : 'X';
Ingo Molnar57422792008-05-12 21:20:51 +02001891 if (entry->type == TRACE_WAKE)
1892 S = '+';
Peter Zijlstra80b5e942008-09-04 10:24:16 +02001893 ret = trace_seq_printf(s, "%d %d %c %d %d %d %c\n",
Steven Rostedt777e2082008-09-29 23:02:42 -04001894 field->prev_pid,
1895 field->prev_prio,
Ingo Molnarf9896bf2008-05-12 21:20:47 +02001896 S,
Steven Rostedt777e2082008-09-29 23:02:42 -04001897 field->next_cpu,
1898 field->next_pid,
1899 field->next_prio,
Peter Zijlstrabac524d2008-05-12 21:20:53 +02001900 T);
Ingo Molnarf9896bf2008-05-12 21:20:47 +02001901 if (!ret)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02001902 return TRACE_TYPE_PARTIAL_LINE;
Ingo Molnarf9896bf2008-05-12 21:20:47 +02001903 break;
Steven Rostedt777e2082008-09-29 23:02:42 -04001904 }
Ingo Molnarf0a920d2008-05-12 21:20:47 +02001905 case TRACE_SPECIAL:
Steven Rostedt777e2082008-09-29 23:02:42 -04001906 case TRACE_STACK: {
Steven Rostedt7104f302008-10-01 10:52:51 -04001907 struct special_entry *field;
1908
1909 trace_assign_type(field, entry);
Steven Rostedt777e2082008-09-29 23:02:42 -04001910
Ingo Molnar88a42162008-05-12 21:20:53 +02001911 ret = trace_seq_printf(s, "# %ld %ld %ld\n",
Steven Rostedt777e2082008-09-29 23:02:42 -04001912 field->arg1,
1913 field->arg2,
1914 field->arg3);
Ingo Molnarf0a920d2008-05-12 21:20:47 +02001915 if (!ret)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02001916 return TRACE_TYPE_PARTIAL_LINE;
Ingo Molnarf0a920d2008-05-12 21:20:47 +02001917 break;
Steven Rostedt777e2082008-09-29 23:02:42 -04001918 }
1919 case TRACE_PRINT: {
Steven Rostedt7104f302008-10-01 10:52:51 -04001920 struct print_entry *field;
1921
1922 trace_assign_type(field, entry);
Steven Rostedt777e2082008-09-29 23:02:42 -04001923
1924 trace_seq_printf(s, "# %lx %s", field->ip, field->buf);
1925 if (entry->flags & TRACE_FLAG_CONT)
Steven Rostedtdd0e5452008-08-01 12:26:41 -04001926 trace_seq_print_cont(s, iter);
1927 break;
Ingo Molnarf9896bf2008-05-12 21:20:47 +02001928 }
Steven Rostedt777e2082008-09-29 23:02:42 -04001929 }
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02001930 return TRACE_TYPE_HANDLED;
Ingo Molnarf9896bf2008-05-12 21:20:47 +02001931}
1932
Ingo Molnarcb0f12a2008-05-12 21:20:47 +02001933#define SEQ_PUT_FIELD_RET(s, x) \
1934do { \
1935 if (!trace_seq_putmem(s, &(x), sizeof(x))) \
1936 return 0; \
1937} while (0)
1938
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +02001939#define SEQ_PUT_HEX_FIELD_RET(s, x) \
1940do { \
Harvey Harrisonad0a3b62008-10-08 17:44:55 -07001941 BUILD_BUG_ON(sizeof(x) > MAX_MEMHEX_BYTES); \
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +02001942 if (!trace_seq_putmem_hex(s, &(x), sizeof(x))) \
1943 return 0; \
1944} while (0)
1945
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02001946static enum print_line_t print_hex_fmt(struct trace_iterator *iter)
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +02001947{
1948 struct trace_seq *s = &iter->seq;
1949 unsigned char newline = '\n';
1950 struct trace_entry *entry;
Peter Zijlstrabac524d2008-05-12 21:20:53 +02001951 int S, T;
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +02001952
1953 entry = iter->ent;
Steven Rostedtdd0e5452008-08-01 12:26:41 -04001954
1955 if (entry->type == TRACE_CONT)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02001956 return TRACE_TYPE_HANDLED;
Steven Rostedtdd0e5452008-08-01 12:26:41 -04001957
Steven Rostedt777e2082008-09-29 23:02:42 -04001958 SEQ_PUT_HEX_FIELD_RET(s, entry->pid);
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +02001959 SEQ_PUT_HEX_FIELD_RET(s, iter->cpu);
Steven Rostedt3928a8a2008-09-29 23:02:41 -04001960 SEQ_PUT_HEX_FIELD_RET(s, iter->ts);
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +02001961
1962 switch (entry->type) {
Steven Rostedt777e2082008-09-29 23:02:42 -04001963 case TRACE_FN: {
Steven Rostedt7104f302008-10-01 10:52:51 -04001964 struct ftrace_entry *field;
1965
1966 trace_assign_type(field, entry);
Steven Rostedt777e2082008-09-29 23:02:42 -04001967
1968 SEQ_PUT_HEX_FIELD_RET(s, field->ip);
1969 SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip);
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +02001970 break;
Steven Rostedt777e2082008-09-29 23:02:42 -04001971 }
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +02001972 case TRACE_CTX:
Steven Rostedt777e2082008-09-29 23:02:42 -04001973 case TRACE_WAKE: {
Steven Rostedt7104f302008-10-01 10:52:51 -04001974 struct ctx_switch_entry *field;
1975
1976 trace_assign_type(field, entry);
Steven Rostedt777e2082008-09-29 23:02:42 -04001977
1978 S = field->prev_state < sizeof(state_to_char) ?
1979 state_to_char[field->prev_state] : 'X';
1980 T = field->next_state < sizeof(state_to_char) ?
1981 state_to_char[field->next_state] : 'X';
Ingo Molnar57422792008-05-12 21:20:51 +02001982 if (entry->type == TRACE_WAKE)
1983 S = '+';
Steven Rostedt777e2082008-09-29 23:02:42 -04001984 SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid);
1985 SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio);
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +02001986 SEQ_PUT_HEX_FIELD_RET(s, S);
Steven Rostedt777e2082008-09-29 23:02:42 -04001987 SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu);
1988 SEQ_PUT_HEX_FIELD_RET(s, field->next_pid);
1989 SEQ_PUT_HEX_FIELD_RET(s, field->next_prio);
Peter Zijlstrabac524d2008-05-12 21:20:53 +02001990 SEQ_PUT_HEX_FIELD_RET(s, T);
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +02001991 break;
Steven Rostedt777e2082008-09-29 23:02:42 -04001992 }
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +02001993 case TRACE_SPECIAL:
Steven Rostedt777e2082008-09-29 23:02:42 -04001994 case TRACE_STACK: {
Steven Rostedt7104f302008-10-01 10:52:51 -04001995 struct special_entry *field;
1996
1997 trace_assign_type(field, entry);
Steven Rostedt777e2082008-09-29 23:02:42 -04001998
1999 SEQ_PUT_HEX_FIELD_RET(s, field->arg1);
2000 SEQ_PUT_HEX_FIELD_RET(s, field->arg2);
2001 SEQ_PUT_HEX_FIELD_RET(s, field->arg3);
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +02002002 break;
2003 }
Steven Rostedt777e2082008-09-29 23:02:42 -04002004 }
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +02002005 SEQ_PUT_FIELD_RET(s, newline);
2006
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02002007 return TRACE_TYPE_HANDLED;
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +02002008}
2009
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02002010static enum print_line_t print_bin_fmt(struct trace_iterator *iter)
Ingo Molnarcb0f12a2008-05-12 21:20:47 +02002011{
2012 struct trace_seq *s = &iter->seq;
2013 struct trace_entry *entry;
2014
2015 entry = iter->ent;
Steven Rostedtdd0e5452008-08-01 12:26:41 -04002016
2017 if (entry->type == TRACE_CONT)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02002018 return TRACE_TYPE_HANDLED;
Steven Rostedtdd0e5452008-08-01 12:26:41 -04002019
Steven Rostedt777e2082008-09-29 23:02:42 -04002020 SEQ_PUT_FIELD_RET(s, entry->pid);
Eric Anholt072ba492008-10-26 15:26:57 -07002021 SEQ_PUT_FIELD_RET(s, entry->cpu);
Steven Rostedt3928a8a2008-09-29 23:02:41 -04002022 SEQ_PUT_FIELD_RET(s, iter->ts);
Ingo Molnarcb0f12a2008-05-12 21:20:47 +02002023
2024 switch (entry->type) {
Steven Rostedt777e2082008-09-29 23:02:42 -04002025 case TRACE_FN: {
Steven Rostedt7104f302008-10-01 10:52:51 -04002026 struct ftrace_entry *field;
2027
2028 trace_assign_type(field, entry);
Steven Rostedt777e2082008-09-29 23:02:42 -04002029
2030 SEQ_PUT_FIELD_RET(s, field->ip);
2031 SEQ_PUT_FIELD_RET(s, field->parent_ip);
Ingo Molnarcb0f12a2008-05-12 21:20:47 +02002032 break;
Steven Rostedt777e2082008-09-29 23:02:42 -04002033 }
2034 case TRACE_CTX: {
Steven Rostedt7104f302008-10-01 10:52:51 -04002035 struct ctx_switch_entry *field;
2036
2037 trace_assign_type(field, entry);
Steven Rostedt777e2082008-09-29 23:02:42 -04002038
2039 SEQ_PUT_FIELD_RET(s, field->prev_pid);
2040 SEQ_PUT_FIELD_RET(s, field->prev_prio);
2041 SEQ_PUT_FIELD_RET(s, field->prev_state);
2042 SEQ_PUT_FIELD_RET(s, field->next_pid);
2043 SEQ_PUT_FIELD_RET(s, field->next_prio);
2044 SEQ_PUT_FIELD_RET(s, field->next_state);
Ingo Molnarcb0f12a2008-05-12 21:20:47 +02002045 break;
Steven Rostedt777e2082008-09-29 23:02:42 -04002046 }
Ingo Molnarf0a920d2008-05-12 21:20:47 +02002047 case TRACE_SPECIAL:
Steven Rostedt777e2082008-09-29 23:02:42 -04002048 case TRACE_STACK: {
Steven Rostedt7104f302008-10-01 10:52:51 -04002049 struct special_entry *field;
2050
2051 trace_assign_type(field, entry);
Steven Rostedt777e2082008-09-29 23:02:42 -04002052
2053 SEQ_PUT_FIELD_RET(s, field->arg1);
2054 SEQ_PUT_FIELD_RET(s, field->arg2);
2055 SEQ_PUT_FIELD_RET(s, field->arg3);
Ingo Molnarf0a920d2008-05-12 21:20:47 +02002056 break;
Ingo Molnarcb0f12a2008-05-12 21:20:47 +02002057 }
Steven Rostedt777e2082008-09-29 23:02:42 -04002058 }
Ingo Molnarcb0f12a2008-05-12 21:20:47 +02002059 return 1;
2060}
2061
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002062static int trace_empty(struct trace_iterator *iter)
2063{
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002064 int cpu;
2065
Steven Rostedtab464282008-05-12 21:21:00 +02002066 for_each_tracing_cpu(cpu) {
Steven Rostedtd7690412008-10-01 00:29:53 -04002067 if (iter->buffer_iter[cpu]) {
2068 if (!ring_buffer_iter_empty(iter->buffer_iter[cpu]))
2069 return 0;
2070 } else {
2071 if (!ring_buffer_empty_cpu(iter->tr->buffer, cpu))
2072 return 0;
2073 }
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002074 }
Steven Rostedtd7690412008-10-01 00:29:53 -04002075
Frederic Weisbecker797d3712008-09-30 18:13:45 +02002076 return 1;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002077}
2078
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02002079static enum print_line_t print_trace_line(struct trace_iterator *iter)
Ingo Molnarf9896bf2008-05-12 21:20:47 +02002080{
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02002081 enum print_line_t ret;
2082
2083 if (iter->trace && iter->trace->print_line) {
2084 ret = iter->trace->print_line(iter);
2085 if (ret != TRACE_TYPE_UNHANDLED)
2086 return ret;
2087 }
Thomas Gleixner72829bc2008-05-23 21:37:28 +02002088
Ingo Molnarcb0f12a2008-05-12 21:20:47 +02002089 if (trace_flags & TRACE_ITER_BIN)
2090 return print_bin_fmt(iter);
2091
Ingo Molnar5e3ca0e2008-05-12 21:20:49 +02002092 if (trace_flags & TRACE_ITER_HEX)
2093 return print_hex_fmt(iter);
2094
Ingo Molnarf9896bf2008-05-12 21:20:47 +02002095 if (trace_flags & TRACE_ITER_RAW)
2096 return print_raw_fmt(iter);
2097
2098 if (iter->iter_flags & TRACE_FILE_LAT_FMT)
2099 return print_lat_fmt(iter, iter->idx, iter->cpu);
2100
2101 return print_trace_fmt(iter);
2102}
2103
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002104static int s_show(struct seq_file *m, void *v)
2105{
2106 struct trace_iterator *iter = v;
2107
2108 if (iter->ent == NULL) {
2109 if (iter->tr) {
2110 seq_printf(m, "# tracer: %s\n", iter->trace->name);
2111 seq_puts(m, "#\n");
2112 }
2113 if (iter->iter_flags & TRACE_FILE_LAT_FMT) {
2114 /* print nothing if the buffers are empty */
2115 if (trace_empty(iter))
2116 return 0;
2117 print_trace_header(m, iter);
2118 if (!(trace_flags & TRACE_ITER_VERBOSE))
2119 print_lat_help_header(m);
2120 } else {
2121 if (!(trace_flags & TRACE_ITER_VERBOSE))
2122 print_func_help_header(m);
2123 }
2124 } else {
Ingo Molnarf9896bf2008-05-12 21:20:47 +02002125 print_trace_line(iter);
Steven Rostedt214023c2008-05-12 21:20:46 +02002126 trace_print_seq(m, &iter->seq);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002127 }
2128
2129 return 0;
2130}
2131
2132static struct seq_operations tracer_seq_ops = {
Ingo Molnar4bf39a92008-05-12 21:20:46 +02002133 .start = s_start,
2134 .next = s_next,
2135 .stop = s_stop,
2136 .show = s_show,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002137};
2138
Ingo Molnare309b412008-05-12 21:20:51 +02002139static struct trace_iterator *
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002140__tracing_open(struct inode *inode, struct file *file, int *ret)
2141{
2142 struct trace_iterator *iter;
Steven Rostedt3928a8a2008-09-29 23:02:41 -04002143 struct seq_file *m;
2144 int cpu;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002145
Steven Rostedt60a11772008-05-12 21:20:44 +02002146 if (tracing_disabled) {
2147 *ret = -ENODEV;
2148 return NULL;
2149 }
2150
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002151 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
2152 if (!iter) {
2153 *ret = -ENOMEM;
2154 goto out;
2155 }
2156
2157 mutex_lock(&trace_types_lock);
2158 if (current_trace && current_trace->print_max)
2159 iter->tr = &max_tr;
2160 else
2161 iter->tr = inode->i_private;
2162 iter->trace = current_trace;
2163 iter->pos = -1;
2164
Steven Rostedt12ef7d42008-11-12 17:52:38 -05002165 /* Annotate start of buffers if we had overruns */
2166 if (ring_buffer_overruns(iter->tr->buffer))
2167 iter->iter_flags |= TRACE_FILE_ANNOTATE;
2168
2169
Steven Rostedt3928a8a2008-09-29 23:02:41 -04002170 for_each_tracing_cpu(cpu) {
Steven Rostedtd7690412008-10-01 00:29:53 -04002171
Steven Rostedt3928a8a2008-09-29 23:02:41 -04002172 iter->buffer_iter[cpu] =
2173 ring_buffer_read_start(iter->tr->buffer, cpu);
Steven Rostedtd7690412008-10-01 00:29:53 -04002174
Steven Rostedt3928a8a2008-09-29 23:02:41 -04002175 if (!iter->buffer_iter[cpu])
2176 goto fail_buffer;
2177 }
2178
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002179 /* TODO stop tracer */
2180 *ret = seq_open(file, &tracer_seq_ops);
Steven Rostedt3928a8a2008-09-29 23:02:41 -04002181 if (*ret)
2182 goto fail_buffer;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002183
Steven Rostedt3928a8a2008-09-29 23:02:41 -04002184 m = file->private_data;
2185 m->private = iter;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002186
Steven Rostedt3928a8a2008-09-29 23:02:41 -04002187 /* stop the trace while dumping */
Steven Rostedt90369902008-11-05 16:05:44 -05002188 tracing_stop();
Steven Rostedt3928a8a2008-09-29 23:02:41 -04002189
2190 if (iter->trace && iter->trace->open)
2191 iter->trace->open(iter);
2192
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002193 mutex_unlock(&trace_types_lock);
2194
2195 out:
2196 return iter;
Steven Rostedt3928a8a2008-09-29 23:02:41 -04002197
2198 fail_buffer:
2199 for_each_tracing_cpu(cpu) {
2200 if (iter->buffer_iter[cpu])
2201 ring_buffer_read_finish(iter->buffer_iter[cpu]);
2202 }
2203 mutex_unlock(&trace_types_lock);
2204
2205 return ERR_PTR(-ENOMEM);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002206}
2207
2208int tracing_open_generic(struct inode *inode, struct file *filp)
2209{
Steven Rostedt60a11772008-05-12 21:20:44 +02002210 if (tracing_disabled)
2211 return -ENODEV;
2212
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002213 filp->private_data = inode->i_private;
2214 return 0;
2215}
2216
2217int tracing_release(struct inode *inode, struct file *file)
2218{
2219 struct seq_file *m = (struct seq_file *)file->private_data;
2220 struct trace_iterator *iter = m->private;
Steven Rostedt3928a8a2008-09-29 23:02:41 -04002221 int cpu;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002222
2223 mutex_lock(&trace_types_lock);
Steven Rostedt3928a8a2008-09-29 23:02:41 -04002224 for_each_tracing_cpu(cpu) {
2225 if (iter->buffer_iter[cpu])
2226 ring_buffer_read_finish(iter->buffer_iter[cpu]);
2227 }
2228
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002229 if (iter->trace && iter->trace->close)
2230 iter->trace->close(iter);
2231
2232 /* reenable tracing if it was previously enabled */
Steven Rostedt90369902008-11-05 16:05:44 -05002233 tracing_start();
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002234 mutex_unlock(&trace_types_lock);
2235
2236 seq_release(inode, file);
2237 kfree(iter);
2238 return 0;
2239}
2240
2241static int tracing_open(struct inode *inode, struct file *file)
2242{
2243 int ret;
2244
2245 __tracing_open(inode, file, &ret);
2246
2247 return ret;
2248}
2249
2250static int tracing_lt_open(struct inode *inode, struct file *file)
2251{
2252 struct trace_iterator *iter;
2253 int ret;
2254
2255 iter = __tracing_open(inode, file, &ret);
2256
2257 if (!ret)
2258 iter->iter_flags |= TRACE_FILE_LAT_FMT;
2259
2260 return ret;
2261}
2262
2263
Ingo Molnare309b412008-05-12 21:20:51 +02002264static void *
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002265t_next(struct seq_file *m, void *v, loff_t *pos)
2266{
2267 struct tracer *t = m->private;
2268
2269 (*pos)++;
2270
2271 if (t)
2272 t = t->next;
2273
2274 m->private = t;
2275
2276 return t;
2277}
2278
2279static void *t_start(struct seq_file *m, loff_t *pos)
2280{
2281 struct tracer *t = m->private;
2282 loff_t l = 0;
2283
2284 mutex_lock(&trace_types_lock);
2285 for (; t && l < *pos; t = t_next(m, t, &l))
2286 ;
2287
2288 return t;
2289}
2290
2291static void t_stop(struct seq_file *m, void *p)
2292{
2293 mutex_unlock(&trace_types_lock);
2294}
2295
2296static int t_show(struct seq_file *m, void *v)
2297{
2298 struct tracer *t = v;
2299
2300 if (!t)
2301 return 0;
2302
2303 seq_printf(m, "%s", t->name);
2304 if (t->next)
2305 seq_putc(m, ' ');
2306 else
2307 seq_putc(m, '\n');
2308
2309 return 0;
2310}
2311
2312static struct seq_operations show_traces_seq_ops = {
Ingo Molnar4bf39a92008-05-12 21:20:46 +02002313 .start = t_start,
2314 .next = t_next,
2315 .stop = t_stop,
2316 .show = t_show,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002317};
2318
2319static int show_traces_open(struct inode *inode, struct file *file)
2320{
2321 int ret;
2322
Steven Rostedt60a11772008-05-12 21:20:44 +02002323 if (tracing_disabled)
2324 return -ENODEV;
2325
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002326 ret = seq_open(file, &show_traces_seq_ops);
2327 if (!ret) {
2328 struct seq_file *m = file->private_data;
2329 m->private = trace_types;
2330 }
2331
2332 return ret;
2333}
2334
2335static struct file_operations tracing_fops = {
Ingo Molnar4bf39a92008-05-12 21:20:46 +02002336 .open = tracing_open,
2337 .read = seq_read,
2338 .llseek = seq_lseek,
2339 .release = tracing_release,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002340};
2341
2342static struct file_operations tracing_lt_fops = {
Ingo Molnar4bf39a92008-05-12 21:20:46 +02002343 .open = tracing_lt_open,
2344 .read = seq_read,
2345 .llseek = seq_lseek,
2346 .release = tracing_release,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002347};
2348
2349static struct file_operations show_traces_fops = {
Ingo Molnarc7078de2008-05-12 21:20:52 +02002350 .open = show_traces_open,
2351 .read = seq_read,
2352 .release = seq_release,
2353};
2354
Ingo Molnar36dfe922008-05-12 21:20:52 +02002355/*
2356 * Only trace on a CPU if the bitmask is set:
2357 */
2358static cpumask_t tracing_cpumask = CPU_MASK_ALL;
2359
2360/*
2361 * When tracing/tracing_cpu_mask is modified then this holds
2362 * the new bitmask we are about to install:
2363 */
2364static cpumask_t tracing_cpumask_new;
2365
2366/*
2367 * The tracer itself will not take this lock, but still we want
2368 * to provide a consistent cpumask to user-space:
2369 */
2370static DEFINE_MUTEX(tracing_cpumask_update_lock);
2371
2372/*
2373 * Temporary storage for the character representation of the
2374 * CPU bitmask (and one more byte for the newline):
2375 */
2376static char mask_str[NR_CPUS + 1];
2377
Ingo Molnarc7078de2008-05-12 21:20:52 +02002378static ssize_t
2379tracing_cpumask_read(struct file *filp, char __user *ubuf,
2380 size_t count, loff_t *ppos)
2381{
Ingo Molnar36dfe922008-05-12 21:20:52 +02002382 int len;
Ingo Molnarc7078de2008-05-12 21:20:52 +02002383
2384 mutex_lock(&tracing_cpumask_update_lock);
Ingo Molnar36dfe922008-05-12 21:20:52 +02002385
2386 len = cpumask_scnprintf(mask_str, count, tracing_cpumask);
2387 if (count - len < 2) {
2388 count = -EINVAL;
2389 goto out_err;
2390 }
2391 len += sprintf(mask_str + len, "\n");
2392 count = simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+1);
2393
2394out_err:
Ingo Molnarc7078de2008-05-12 21:20:52 +02002395 mutex_unlock(&tracing_cpumask_update_lock);
2396
2397 return count;
2398}
2399
2400static ssize_t
2401tracing_cpumask_write(struct file *filp, const char __user *ubuf,
2402 size_t count, loff_t *ppos)
2403{
Ingo Molnar36dfe922008-05-12 21:20:52 +02002404 int err, cpu;
Ingo Molnarc7078de2008-05-12 21:20:52 +02002405
2406 mutex_lock(&tracing_cpumask_update_lock);
Ingo Molnar36dfe922008-05-12 21:20:52 +02002407 err = cpumask_parse_user(ubuf, count, tracing_cpumask_new);
2408 if (err)
2409 goto err_unlock;
2410
Steven Rostedt92205c22008-05-12 21:20:55 +02002411 raw_local_irq_disable();
2412 __raw_spin_lock(&ftrace_max_lock);
Steven Rostedtab464282008-05-12 21:21:00 +02002413 for_each_tracing_cpu(cpu) {
Ingo Molnar36dfe922008-05-12 21:20:52 +02002414 /*
2415 * Increase/decrease the disabled counter if we are
2416 * about to flip a bit in the cpumask:
2417 */
2418 if (cpu_isset(cpu, tracing_cpumask) &&
2419 !cpu_isset(cpu, tracing_cpumask_new)) {
2420 atomic_inc(&global_trace.data[cpu]->disabled);
2421 }
2422 if (!cpu_isset(cpu, tracing_cpumask) &&
2423 cpu_isset(cpu, tracing_cpumask_new)) {
2424 atomic_dec(&global_trace.data[cpu]->disabled);
2425 }
2426 }
Steven Rostedt92205c22008-05-12 21:20:55 +02002427 __raw_spin_unlock(&ftrace_max_lock);
2428 raw_local_irq_enable();
Ingo Molnar36dfe922008-05-12 21:20:52 +02002429
2430 tracing_cpumask = tracing_cpumask_new;
2431
Ingo Molnarc7078de2008-05-12 21:20:52 +02002432 mutex_unlock(&tracing_cpumask_update_lock);
2433
Ingo Molnarc7078de2008-05-12 21:20:52 +02002434 return count;
Ingo Molnar36dfe922008-05-12 21:20:52 +02002435
2436err_unlock:
2437 mutex_unlock(&tracing_cpumask_update_lock);
2438
2439 return err;
Ingo Molnarc7078de2008-05-12 21:20:52 +02002440}
2441
2442static struct file_operations tracing_cpumask_fops = {
2443 .open = tracing_open_generic,
2444 .read = tracing_cpumask_read,
2445 .write = tracing_cpumask_write,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002446};
2447
2448static ssize_t
Steven Rostedtee6bce52008-11-12 17:52:37 -05002449tracing_trace_options_read(struct file *filp, char __user *ubuf,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002450 size_t cnt, loff_t *ppos)
2451{
Frederic Weisbeckeradf9f192008-11-17 19:23:42 +01002452 int i;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002453 char *buf;
2454 int r = 0;
2455 int len = 0;
Frederic Weisbeckeradf9f192008-11-17 19:23:42 +01002456 u32 tracer_flags = current_trace->flags->val;
2457 struct tracer_opt *trace_opts = current_trace->flags->opts;
2458
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002459
2460 /* calulate max size */
2461 for (i = 0; trace_options[i]; i++) {
2462 len += strlen(trace_options[i]);
2463 len += 3; /* "no" and space */
2464 }
2465
Frederic Weisbeckeradf9f192008-11-17 19:23:42 +01002466 /*
2467 * Increase the size with names of options specific
2468 * of the current tracer.
2469 */
2470 for (i = 0; trace_opts[i].name; i++) {
2471 len += strlen(trace_opts[i].name);
2472 len += 3; /* "no" and space */
2473 }
2474
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002475 /* +2 for \n and \0 */
2476 buf = kmalloc(len + 2, GFP_KERNEL);
2477 if (!buf)
2478 return -ENOMEM;
2479
2480 for (i = 0; trace_options[i]; i++) {
2481 if (trace_flags & (1 << i))
2482 r += sprintf(buf + r, "%s ", trace_options[i]);
2483 else
2484 r += sprintf(buf + r, "no%s ", trace_options[i]);
2485 }
2486
Frederic Weisbeckeradf9f192008-11-17 19:23:42 +01002487 for (i = 0; trace_opts[i].name; i++) {
2488 if (tracer_flags & trace_opts[i].bit)
2489 r += sprintf(buf + r, "%s ",
2490 trace_opts[i].name);
2491 else
2492 r += sprintf(buf + r, "no%s ",
2493 trace_opts[i].name);
2494 }
2495
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002496 r += sprintf(buf + r, "\n");
2497 WARN_ON(r >= len + 2);
2498
Ingo Molnar36dfe922008-05-12 21:20:52 +02002499 r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002500
2501 kfree(buf);
2502
2503 return r;
2504}
2505
Frederic Weisbeckeradf9f192008-11-17 19:23:42 +01002506/* Try to assign a tracer specific option */
2507static int set_tracer_option(struct tracer *trace, char *cmp, int neg)
2508{
2509 struct tracer_flags *trace_flags = trace->flags;
2510 struct tracer_opt *opts = NULL;
2511 int ret = 0, i = 0;
2512 int len;
2513
2514 for (i = 0; trace_flags->opts[i].name; i++) {
2515 opts = &trace_flags->opts[i];
2516 len = strlen(opts->name);
2517
2518 if (strncmp(cmp, opts->name, len) == 0) {
2519 ret = trace->set_flag(trace_flags->val,
2520 opts->bit, !neg);
2521 break;
2522 }
2523 }
2524 /* Not found */
2525 if (!trace_flags->opts[i].name)
2526 return -EINVAL;
2527
2528 /* Refused to handle */
2529 if (ret)
2530 return ret;
2531
2532 if (neg)
2533 trace_flags->val &= ~opts->bit;
2534 else
2535 trace_flags->val |= opts->bit;
2536
2537 return 0;
2538}
2539
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002540static ssize_t
Steven Rostedtee6bce52008-11-12 17:52:37 -05002541tracing_trace_options_write(struct file *filp, const char __user *ubuf,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002542 size_t cnt, loff_t *ppos)
2543{
2544 char buf[64];
2545 char *cmp = buf;
2546 int neg = 0;
Frederic Weisbeckeradf9f192008-11-17 19:23:42 +01002547 int ret;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002548 int i;
2549
Steven Rostedtcffae432008-05-12 21:21:00 +02002550 if (cnt >= sizeof(buf))
2551 return -EINVAL;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002552
2553 if (copy_from_user(&buf, ubuf, cnt))
2554 return -EFAULT;
2555
2556 buf[cnt] = 0;
2557
2558 if (strncmp(buf, "no", 2) == 0) {
2559 neg = 1;
2560 cmp += 2;
2561 }
2562
2563 for (i = 0; trace_options[i]; i++) {
2564 int len = strlen(trace_options[i]);
2565
2566 if (strncmp(cmp, trace_options[i], len) == 0) {
2567 if (neg)
2568 trace_flags &= ~(1 << i);
2569 else
2570 trace_flags |= (1 << i);
2571 break;
2572 }
2573 }
Frederic Weisbeckeradf9f192008-11-17 19:23:42 +01002574
2575 /* If no option could be set, test the specific tracer options */
2576 if (!trace_options[i]) {
2577 ret = set_tracer_option(current_trace, cmp, neg);
2578 if (ret)
2579 return ret;
2580 }
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002581
2582 filp->f_pos += cnt;
2583
2584 return cnt;
2585}
2586
2587static struct file_operations tracing_iter_fops = {
Ingo Molnarc7078de2008-05-12 21:20:52 +02002588 .open = tracing_open_generic,
Steven Rostedtee6bce52008-11-12 17:52:37 -05002589 .read = tracing_trace_options_read,
2590 .write = tracing_trace_options_write,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002591};
2592
Ingo Molnar7bd2f242008-05-12 21:20:45 +02002593static const char readme_msg[] =
2594 "tracing mini-HOWTO:\n\n"
2595 "# mkdir /debug\n"
2596 "# mount -t debugfs nodev /debug\n\n"
2597 "# cat /debug/tracing/available_tracers\n"
2598 "wakeup preemptirqsoff preemptoff irqsoff ftrace sched_switch none\n\n"
2599 "# cat /debug/tracing/current_tracer\n"
2600 "none\n"
2601 "# echo sched_switch > /debug/tracing/current_tracer\n"
2602 "# cat /debug/tracing/current_tracer\n"
2603 "sched_switch\n"
Steven Rostedtee6bce52008-11-12 17:52:37 -05002604 "# cat /debug/tracing/trace_options\n"
Ingo Molnar7bd2f242008-05-12 21:20:45 +02002605 "noprint-parent nosym-offset nosym-addr noverbose\n"
Steven Rostedtee6bce52008-11-12 17:52:37 -05002606 "# echo print-parent > /debug/tracing/trace_options\n"
Ingo Molnar7bd2f242008-05-12 21:20:45 +02002607 "# echo 1 > /debug/tracing/tracing_enabled\n"
2608 "# cat /debug/tracing/trace > /tmp/trace.txt\n"
2609 "echo 0 > /debug/tracing/tracing_enabled\n"
2610;
2611
2612static ssize_t
2613tracing_readme_read(struct file *filp, char __user *ubuf,
2614 size_t cnt, loff_t *ppos)
2615{
2616 return simple_read_from_buffer(ubuf, cnt, ppos,
2617 readme_msg, strlen(readme_msg));
2618}
2619
2620static struct file_operations tracing_readme_fops = {
Ingo Molnarc7078de2008-05-12 21:20:52 +02002621 .open = tracing_open_generic,
2622 .read = tracing_readme_read,
Ingo Molnar7bd2f242008-05-12 21:20:45 +02002623};
2624
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002625static ssize_t
2626tracing_ctrl_read(struct file *filp, char __user *ubuf,
2627 size_t cnt, loff_t *ppos)
2628{
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002629 char buf[64];
2630 int r;
2631
Steven Rostedt90369902008-11-05 16:05:44 -05002632 r = sprintf(buf, "%u\n", tracer_enabled);
Ingo Molnar4e3c3332008-05-12 21:20:45 +02002633 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002634}
2635
2636static ssize_t
2637tracing_ctrl_write(struct file *filp, const char __user *ubuf,
2638 size_t cnt, loff_t *ppos)
2639{
2640 struct trace_array *tr = filp->private_data;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002641 char buf[64];
Steven Rostedtc6caeeb2008-05-12 21:21:00 +02002642 long val;
2643 int ret;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002644
Steven Rostedtcffae432008-05-12 21:21:00 +02002645 if (cnt >= sizeof(buf))
2646 return -EINVAL;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002647
2648 if (copy_from_user(&buf, ubuf, cnt))
2649 return -EFAULT;
2650
2651 buf[cnt] = 0;
2652
Steven Rostedtc6caeeb2008-05-12 21:21:00 +02002653 ret = strict_strtoul(buf, 10, &val);
2654 if (ret < 0)
2655 return ret;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002656
2657 val = !!val;
2658
2659 mutex_lock(&trace_types_lock);
Steven Rostedt90369902008-11-05 16:05:44 -05002660 if (tracer_enabled ^ val) {
2661 if (val) {
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002662 tracer_enabled = 1;
Steven Rostedt90369902008-11-05 16:05:44 -05002663 if (current_trace->start)
2664 current_trace->start(tr);
2665 tracing_start();
2666 } else {
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002667 tracer_enabled = 0;
Steven Rostedt90369902008-11-05 16:05:44 -05002668 tracing_stop();
2669 if (current_trace->stop)
2670 current_trace->stop(tr);
2671 }
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002672 }
2673 mutex_unlock(&trace_types_lock);
2674
2675 filp->f_pos += cnt;
2676
2677 return cnt;
2678}
2679
2680static ssize_t
2681tracing_set_trace_read(struct file *filp, char __user *ubuf,
2682 size_t cnt, loff_t *ppos)
2683{
2684 char buf[max_tracer_type_len+2];
2685 int r;
2686
2687 mutex_lock(&trace_types_lock);
2688 if (current_trace)
2689 r = sprintf(buf, "%s\n", current_trace->name);
2690 else
2691 r = sprintf(buf, "\n");
2692 mutex_unlock(&trace_types_lock);
2693
Ingo Molnar4bf39a92008-05-12 21:20:46 +02002694 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002695}
2696
Peter Zijlstrad9e54072008-11-01 19:57:37 +01002697static int tracing_set_tracer(char *buf)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002698{
2699 struct trace_array *tr = &global_trace;
2700 struct tracer *t;
Peter Zijlstrad9e54072008-11-01 19:57:37 +01002701 int ret = 0;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002702
2703 mutex_lock(&trace_types_lock);
2704 for (t = trace_types; t; t = t->next) {
2705 if (strcmp(t->name, buf) == 0)
2706 break;
2707 }
Frederic Weisbeckerc2931e02008-10-04 22:04:44 +02002708 if (!t) {
2709 ret = -EINVAL;
2710 goto out;
2711 }
2712 if (t == current_trace)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002713 goto out;
2714
Steven Rostedt9f029e82008-11-12 15:24:24 -05002715 trace_branch_disable();
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002716 if (current_trace && current_trace->reset)
2717 current_trace->reset(tr);
2718
2719 current_trace = t;
Frederic Weisbecker1c800252008-11-16 05:57:26 +01002720 if (t->init) {
2721 ret = t->init(tr);
2722 if (ret)
2723 goto out;
2724 }
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002725
Steven Rostedt9f029e82008-11-12 15:24:24 -05002726 trace_branch_enable(tr);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002727 out:
2728 mutex_unlock(&trace_types_lock);
2729
Peter Zijlstrad9e54072008-11-01 19:57:37 +01002730 return ret;
2731}
2732
2733static ssize_t
2734tracing_set_trace_write(struct file *filp, const char __user *ubuf,
2735 size_t cnt, loff_t *ppos)
2736{
2737 char buf[max_tracer_type_len+1];
2738 int i;
2739 size_t ret;
Frederic Weisbeckere6e7a652008-11-16 05:53:19 +01002740 int err;
2741
2742 ret = cnt;
Peter Zijlstrad9e54072008-11-01 19:57:37 +01002743
2744 if (cnt > max_tracer_type_len)
2745 cnt = max_tracer_type_len;
2746
2747 if (copy_from_user(&buf, ubuf, cnt))
2748 return -EFAULT;
2749
2750 buf[cnt] = 0;
2751
2752 /* strip ending whitespace. */
2753 for (i = cnt - 1; i > 0 && isspace(buf[i]); i--)
2754 buf[i] = 0;
2755
Frederic Weisbeckere6e7a652008-11-16 05:53:19 +01002756 err = tracing_set_tracer(buf);
2757 if (err)
2758 return err;
Peter Zijlstrad9e54072008-11-01 19:57:37 +01002759
Frederic Weisbeckere6e7a652008-11-16 05:53:19 +01002760 filp->f_pos += ret;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002761
Frederic Weisbeckerc2931e02008-10-04 22:04:44 +02002762 return ret;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002763}
2764
2765static ssize_t
2766tracing_max_lat_read(struct file *filp, char __user *ubuf,
2767 size_t cnt, loff_t *ppos)
2768{
2769 unsigned long *ptr = filp->private_data;
2770 char buf[64];
2771 int r;
2772
Steven Rostedtcffae432008-05-12 21:21:00 +02002773 r = snprintf(buf, sizeof(buf), "%ld\n",
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002774 *ptr == (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr));
Steven Rostedtcffae432008-05-12 21:21:00 +02002775 if (r > sizeof(buf))
2776 r = sizeof(buf);
Ingo Molnar4bf39a92008-05-12 21:20:46 +02002777 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002778}
2779
2780static ssize_t
2781tracing_max_lat_write(struct file *filp, const char __user *ubuf,
2782 size_t cnt, loff_t *ppos)
2783{
2784 long *ptr = filp->private_data;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002785 char buf[64];
Steven Rostedtc6caeeb2008-05-12 21:21:00 +02002786 long val;
2787 int ret;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002788
Steven Rostedtcffae432008-05-12 21:21:00 +02002789 if (cnt >= sizeof(buf))
2790 return -EINVAL;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002791
2792 if (copy_from_user(&buf, ubuf, cnt))
2793 return -EFAULT;
2794
2795 buf[cnt] = 0;
2796
Steven Rostedtc6caeeb2008-05-12 21:21:00 +02002797 ret = strict_strtoul(buf, 10, &val);
2798 if (ret < 0)
2799 return ret;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02002800
2801 *ptr = val * 1000;
2802
2803 return cnt;
2804}
2805
Steven Rostedtb3806b42008-05-12 21:20:46 +02002806static atomic_t tracing_reader;
2807
2808static int tracing_open_pipe(struct inode *inode, struct file *filp)
2809{
2810 struct trace_iterator *iter;
2811
2812 if (tracing_disabled)
2813 return -ENODEV;
2814
2815 /* We only allow for reader of the pipe */
2816 if (atomic_inc_return(&tracing_reader) != 1) {
2817 atomic_dec(&tracing_reader);
2818 return -EBUSY;
2819 }
2820
2821 /* create a buffer to store the information to pass to userspace */
2822 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
2823 if (!iter)
2824 return -ENOMEM;
2825
Steven Rostedt107bad82008-05-12 21:21:01 +02002826 mutex_lock(&trace_types_lock);
Steven Rostedta3097202008-11-07 22:36:02 -05002827
2828 /* trace pipe does not show start of buffer */
2829 cpus_setall(iter->started);
2830
Steven Rostedtb3806b42008-05-12 21:20:46 +02002831 iter->tr = &global_trace;
Thomas Gleixner72829bc2008-05-23 21:37:28 +02002832 iter->trace = current_trace;
Steven Rostedtb3806b42008-05-12 21:20:46 +02002833 filp->private_data = iter;
2834
Steven Rostedt107bad82008-05-12 21:21:01 +02002835 if (iter->trace->pipe_open)
2836 iter->trace->pipe_open(iter);
2837 mutex_unlock(&trace_types_lock);
2838
Steven Rostedtb3806b42008-05-12 21:20:46 +02002839 return 0;
2840}
2841
2842static int tracing_release_pipe(struct inode *inode, struct file *file)
2843{
2844 struct trace_iterator *iter = file->private_data;
2845
2846 kfree(iter);
2847 atomic_dec(&tracing_reader);
2848
2849 return 0;
2850}
2851
Soeren Sandmann Pedersen2a2cc8f2008-05-12 21:20:49 +02002852static unsigned int
2853tracing_poll_pipe(struct file *filp, poll_table *poll_table)
2854{
2855 struct trace_iterator *iter = filp->private_data;
2856
2857 if (trace_flags & TRACE_ITER_BLOCK) {
2858 /*
2859 * Always select as readable when in blocking mode
2860 */
2861 return POLLIN | POLLRDNORM;
Ingo Molnarafc2abc2008-05-12 21:21:00 +02002862 } else {
Soeren Sandmann Pedersen2a2cc8f2008-05-12 21:20:49 +02002863 if (!trace_empty(iter))
2864 return POLLIN | POLLRDNORM;
2865 poll_wait(filp, &trace_wait, poll_table);
2866 if (!trace_empty(iter))
2867 return POLLIN | POLLRDNORM;
2868
2869 return 0;
2870 }
2871}
2872
Steven Rostedtb3806b42008-05-12 21:20:46 +02002873/*
2874 * Consumer reader.
2875 */
2876static ssize_t
2877tracing_read_pipe(struct file *filp, char __user *ubuf,
2878 size_t cnt, loff_t *ppos)
2879{
2880 struct trace_iterator *iter = filp->private_data;
Pekka Paalanen6c6c2792008-05-12 21:21:02 +02002881 ssize_t sret;
Steven Rostedtb3806b42008-05-12 21:20:46 +02002882
2883 /* return any leftover data */
Pekka Paalanen6c6c2792008-05-12 21:21:02 +02002884 sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
2885 if (sret != -EBUSY)
2886 return sret;
Steven Rostedtb3806b42008-05-12 21:20:46 +02002887
Pekka Paalanen6c6c2792008-05-12 21:21:02 +02002888 trace_seq_reset(&iter->seq);
Steven Rostedtb3806b42008-05-12 21:20:46 +02002889
Steven Rostedt107bad82008-05-12 21:21:01 +02002890 mutex_lock(&trace_types_lock);
2891 if (iter->trace->read) {
Pekka Paalanen6c6c2792008-05-12 21:21:02 +02002892 sret = iter->trace->read(iter, filp, ubuf, cnt, ppos);
2893 if (sret)
Steven Rostedt107bad82008-05-12 21:21:01 +02002894 goto out;
Steven Rostedt107bad82008-05-12 21:21:01 +02002895 }
2896
Pekka Paalanen9ff4b972008-09-29 20:23:48 +02002897waitagain:
2898 sret = 0;
Steven Rostedtb3806b42008-05-12 21:20:46 +02002899 while (trace_empty(iter)) {
Steven Rostedt2dc8f092008-05-12 21:20:58 +02002900
Steven Rostedt107bad82008-05-12 21:21:01 +02002901 if ((filp->f_flags & O_NONBLOCK)) {
Pekka Paalanen6c6c2792008-05-12 21:21:02 +02002902 sret = -EAGAIN;
Steven Rostedt107bad82008-05-12 21:21:01 +02002903 goto out;
2904 }
Steven Rostedt2dc8f092008-05-12 21:20:58 +02002905
Steven Rostedtb3806b42008-05-12 21:20:46 +02002906 /*
2907 * This is a make-shift waitqueue. The reason we don't use
2908 * an actual wait queue is because:
2909 * 1) we only ever have one waiter
2910 * 2) the tracing, traces all functions, we don't want
2911 * the overhead of calling wake_up and friends
2912 * (and tracing them too)
2913 * Anyway, this is really very primitive wakeup.
2914 */
2915 set_current_state(TASK_INTERRUPTIBLE);
2916 iter->tr->waiter = current;
2917
Steven Rostedt107bad82008-05-12 21:21:01 +02002918 mutex_unlock(&trace_types_lock);
2919
Ingo Molnar9fe068e2008-05-12 21:21:02 +02002920 /* sleep for 100 msecs, and try again. */
2921 schedule_timeout(HZ/10);
Steven Rostedtb3806b42008-05-12 21:20:46 +02002922
Steven Rostedt107bad82008-05-12 21:21:01 +02002923 mutex_lock(&trace_types_lock);
2924
Steven Rostedtb3806b42008-05-12 21:20:46 +02002925 iter->tr->waiter = NULL;
2926
Steven Rostedt107bad82008-05-12 21:21:01 +02002927 if (signal_pending(current)) {
Pekka Paalanen6c6c2792008-05-12 21:21:02 +02002928 sret = -EINTR;
Steven Rostedt107bad82008-05-12 21:21:01 +02002929 goto out;
2930 }
Steven Rostedtb3806b42008-05-12 21:20:46 +02002931
Steven Rostedt84527992008-05-12 21:20:58 +02002932 if (iter->trace != current_trace)
Steven Rostedt107bad82008-05-12 21:21:01 +02002933 goto out;
Steven Rostedt84527992008-05-12 21:20:58 +02002934
Steven Rostedtb3806b42008-05-12 21:20:46 +02002935 /*
2936 * We block until we read something and tracing is disabled.
2937 * We still block if tracing is disabled, but we have never
2938 * read anything. This allows a user to cat this file, and
2939 * then enable tracing. But after we have read something,
2940 * we give an EOF when tracing is again disabled.
2941 *
2942 * iter->pos will be 0 if we haven't read anything.
2943 */
2944 if (!tracer_enabled && iter->pos)
2945 break;
2946
2947 continue;
2948 }
2949
2950 /* stop when tracing is finished */
2951 if (trace_empty(iter))
Steven Rostedt107bad82008-05-12 21:21:01 +02002952 goto out;
Steven Rostedtb3806b42008-05-12 21:20:46 +02002953
2954 if (cnt >= PAGE_SIZE)
2955 cnt = PAGE_SIZE - 1;
2956
Steven Rostedt53d0aa72008-05-12 21:21:01 +02002957 /* reset all but tr, trace, and overruns */
Steven Rostedt53d0aa72008-05-12 21:21:01 +02002958 memset(&iter->seq, 0,
2959 sizeof(struct trace_iterator) -
2960 offsetof(struct trace_iterator, seq));
Steven Rostedt4823ed72008-05-12 21:21:01 +02002961 iter->pos = -1;
Steven Rostedtb3806b42008-05-12 21:20:46 +02002962
Steven Rostedt088b1e422008-05-12 21:20:48 +02002963 while (find_next_entry_inc(iter) != NULL) {
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02002964 enum print_line_t ret;
Steven Rostedt088b1e422008-05-12 21:20:48 +02002965 int len = iter->seq.len;
2966
Ingo Molnarf9896bf2008-05-12 21:20:47 +02002967 ret = print_trace_line(iter);
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +02002968 if (ret == TRACE_TYPE_PARTIAL_LINE) {
Steven Rostedt088b1e422008-05-12 21:20:48 +02002969 /* don't print partial lines */
2970 iter->seq.len = len;
Steven Rostedtb3806b42008-05-12 21:20:46 +02002971 break;
Steven Rostedt088b1e422008-05-12 21:20:48 +02002972 }
Steven Rostedtb3806b42008-05-12 21:20:46 +02002973
2974 trace_consume(iter);
2975
2976 if (iter->seq.len >= cnt)
2977 break;
Steven Rostedtb3806b42008-05-12 21:20:46 +02002978 }
2979
Steven Rostedtb3806b42008-05-12 21:20:46 +02002980 /* Now copy what we have to the user */
Pekka Paalanen6c6c2792008-05-12 21:21:02 +02002981 sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
2982 if (iter->seq.readpos >= iter->seq.len)
Steven Rostedtb3806b42008-05-12 21:20:46 +02002983 trace_seq_reset(&iter->seq);
Pekka Paalanen9ff4b972008-09-29 20:23:48 +02002984
2985 /*
2986 * If there was nothing to send to user, inspite of consuming trace
2987 * entries, go back to wait for more entries.
2988 */
Pekka Paalanen6c6c2792008-05-12 21:21:02 +02002989 if (sret == -EBUSY)
Pekka Paalanen9ff4b972008-09-29 20:23:48 +02002990 goto waitagain;
Steven Rostedtb3806b42008-05-12 21:20:46 +02002991
Steven Rostedt107bad82008-05-12 21:21:01 +02002992out:
2993 mutex_unlock(&trace_types_lock);
2994
Pekka Paalanen6c6c2792008-05-12 21:21:02 +02002995 return sret;
Steven Rostedtb3806b42008-05-12 21:20:46 +02002996}
2997
Steven Rostedta98a3c32008-05-12 21:20:59 +02002998static ssize_t
2999tracing_entries_read(struct file *filp, char __user *ubuf,
3000 size_t cnt, loff_t *ppos)
3001{
3002 struct trace_array *tr = filp->private_data;
3003 char buf[64];
3004 int r;
3005
Steven Rostedt1696b2b2008-11-13 00:09:35 -05003006 r = sprintf(buf, "%lu\n", tr->entries >> 10);
Steven Rostedta98a3c32008-05-12 21:20:59 +02003007 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
3008}
3009
3010static ssize_t
3011tracing_entries_write(struct file *filp, const char __user *ubuf,
3012 size_t cnt, loff_t *ppos)
3013{
3014 unsigned long val;
3015 char buf[64];
Steven Rostedtbf5e6512008-11-10 21:46:00 -05003016 int ret, cpu;
Steven Rostedta98a3c32008-05-12 21:20:59 +02003017
Steven Rostedtcffae432008-05-12 21:21:00 +02003018 if (cnt >= sizeof(buf))
3019 return -EINVAL;
Steven Rostedta98a3c32008-05-12 21:20:59 +02003020
3021 if (copy_from_user(&buf, ubuf, cnt))
3022 return -EFAULT;
3023
3024 buf[cnt] = 0;
3025
Steven Rostedtc6caeeb2008-05-12 21:21:00 +02003026 ret = strict_strtoul(buf, 10, &val);
3027 if (ret < 0)
3028 return ret;
Steven Rostedta98a3c32008-05-12 21:20:59 +02003029
3030 /* must have at least 1 entry */
3031 if (!val)
3032 return -EINVAL;
3033
3034 mutex_lock(&trace_types_lock);
3035
Steven Rostedtc76f0692008-11-07 22:36:02 -05003036 tracing_stop();
Steven Rostedta98a3c32008-05-12 21:20:59 +02003037
Steven Rostedtbf5e6512008-11-10 21:46:00 -05003038 /* disable all cpu buffers */
3039 for_each_tracing_cpu(cpu) {
3040 if (global_trace.data[cpu])
3041 atomic_inc(&global_trace.data[cpu]->disabled);
3042 if (max_tr.data[cpu])
3043 atomic_inc(&max_tr.data[cpu]->disabled);
3044 }
3045
Steven Rostedt1696b2b2008-11-13 00:09:35 -05003046 /* value is in KB */
3047 val <<= 10;
3048
Steven Rostedt3928a8a2008-09-29 23:02:41 -04003049 if (val != global_trace.entries) {
3050 ret = ring_buffer_resize(global_trace.buffer, val);
3051 if (ret < 0) {
3052 cnt = ret;
Steven Rostedt3eefae92008-05-12 21:21:04 +02003053 goto out;
3054 }
3055
Steven Rostedt3928a8a2008-09-29 23:02:41 -04003056 ret = ring_buffer_resize(max_tr.buffer, val);
3057 if (ret < 0) {
3058 int r;
3059 cnt = ret;
3060 r = ring_buffer_resize(global_trace.buffer,
3061 global_trace.entries);
3062 if (r < 0) {
3063 /* AARGH! We are left with different
3064 * size max buffer!!!! */
3065 WARN_ON(1);
3066 tracing_disabled = 1;
Steven Rostedta98a3c32008-05-12 21:20:59 +02003067 }
Steven Rostedt3928a8a2008-09-29 23:02:41 -04003068 goto out;
Steven Rostedta98a3c32008-05-12 21:20:59 +02003069 }
Steven Rostedt3eefae92008-05-12 21:21:04 +02003070
Steven Rostedt3928a8a2008-09-29 23:02:41 -04003071 global_trace.entries = val;
Steven Rostedta98a3c32008-05-12 21:20:59 +02003072 }
3073
3074 filp->f_pos += cnt;
3075
Steven Rostedt19384c02008-05-22 00:22:16 -04003076 /* If check pages failed, return ENOMEM */
3077 if (tracing_disabled)
3078 cnt = -ENOMEM;
Steven Rostedta98a3c32008-05-12 21:20:59 +02003079 out:
Steven Rostedtbf5e6512008-11-10 21:46:00 -05003080 for_each_tracing_cpu(cpu) {
3081 if (global_trace.data[cpu])
3082 atomic_dec(&global_trace.data[cpu]->disabled);
3083 if (max_tr.data[cpu])
3084 atomic_dec(&max_tr.data[cpu]->disabled);
3085 }
3086
Steven Rostedtc76f0692008-11-07 22:36:02 -05003087 tracing_start();
Steven Rostedta98a3c32008-05-12 21:20:59 +02003088 max_tr.entries = global_trace.entries;
3089 mutex_unlock(&trace_types_lock);
3090
3091 return cnt;
3092}
3093
Pekka Paalanen5bf9a1e2008-09-16 22:06:42 +03003094static int mark_printk(const char *fmt, ...)
3095{
3096 int ret;
3097 va_list args;
3098 va_start(args, fmt);
3099 ret = trace_vprintk(0, fmt, args);
3100 va_end(args);
3101 return ret;
3102}
3103
3104static ssize_t
3105tracing_mark_write(struct file *filp, const char __user *ubuf,
3106 size_t cnt, loff_t *fpos)
3107{
3108 char *buf;
3109 char *end;
Pekka Paalanen5bf9a1e2008-09-16 22:06:42 +03003110
Steven Rostedtc76f0692008-11-07 22:36:02 -05003111 if (tracing_disabled)
Pekka Paalanen5bf9a1e2008-09-16 22:06:42 +03003112 return -EINVAL;
3113
3114 if (cnt > TRACE_BUF_SIZE)
3115 cnt = TRACE_BUF_SIZE;
3116
3117 buf = kmalloc(cnt + 1, GFP_KERNEL);
3118 if (buf == NULL)
3119 return -ENOMEM;
3120
3121 if (copy_from_user(buf, ubuf, cnt)) {
3122 kfree(buf);
3123 return -EFAULT;
3124 }
3125
3126 /* Cut from the first nil or newline. */
3127 buf[cnt] = '\0';
3128 end = strchr(buf, '\n');
3129 if (end)
3130 *end = '\0';
3131
3132 cnt = mark_printk("%s\n", buf);
3133 kfree(buf);
3134 *fpos += cnt;
3135
3136 return cnt;
3137}
3138
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003139static struct file_operations tracing_max_lat_fops = {
Ingo Molnar4bf39a92008-05-12 21:20:46 +02003140 .open = tracing_open_generic,
3141 .read = tracing_max_lat_read,
3142 .write = tracing_max_lat_write,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003143};
3144
3145static struct file_operations tracing_ctrl_fops = {
Ingo Molnar4bf39a92008-05-12 21:20:46 +02003146 .open = tracing_open_generic,
3147 .read = tracing_ctrl_read,
3148 .write = tracing_ctrl_write,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003149};
3150
3151static struct file_operations set_tracer_fops = {
Ingo Molnar4bf39a92008-05-12 21:20:46 +02003152 .open = tracing_open_generic,
3153 .read = tracing_set_trace_read,
3154 .write = tracing_set_trace_write,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003155};
3156
Steven Rostedtb3806b42008-05-12 21:20:46 +02003157static struct file_operations tracing_pipe_fops = {
Ingo Molnar4bf39a92008-05-12 21:20:46 +02003158 .open = tracing_open_pipe,
Soeren Sandmann Pedersen2a2cc8f2008-05-12 21:20:49 +02003159 .poll = tracing_poll_pipe,
Ingo Molnar4bf39a92008-05-12 21:20:46 +02003160 .read = tracing_read_pipe,
3161 .release = tracing_release_pipe,
Steven Rostedtb3806b42008-05-12 21:20:46 +02003162};
3163
Steven Rostedta98a3c32008-05-12 21:20:59 +02003164static struct file_operations tracing_entries_fops = {
3165 .open = tracing_open_generic,
3166 .read = tracing_entries_read,
3167 .write = tracing_entries_write,
3168};
3169
Pekka Paalanen5bf9a1e2008-09-16 22:06:42 +03003170static struct file_operations tracing_mark_fops = {
Frédéric Weisbecker43a15382008-09-21 20:16:30 +02003171 .open = tracing_open_generic,
Pekka Paalanen5bf9a1e2008-09-16 22:06:42 +03003172 .write = tracing_mark_write,
3173};
3174
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003175#ifdef CONFIG_DYNAMIC_FTRACE
3176
Steven Rostedtb807c3d2008-10-30 16:08:33 -04003177int __weak ftrace_arch_read_dyn_info(char *buf, int size)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003178{
Steven Rostedtb807c3d2008-10-30 16:08:33 -04003179 return 0;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003180}
3181
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003182static ssize_t
Steven Rostedtb807c3d2008-10-30 16:08:33 -04003183tracing_read_dyn_info(struct file *filp, char __user *ubuf,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003184 size_t cnt, loff_t *ppos)
3185{
Steven Rostedta26a2a22008-10-31 00:03:22 -04003186 static char ftrace_dyn_info_buffer[1024];
3187 static DEFINE_MUTEX(dyn_info_mutex);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003188 unsigned long *p = filp->private_data;
Steven Rostedtb807c3d2008-10-30 16:08:33 -04003189 char *buf = ftrace_dyn_info_buffer;
Steven Rostedta26a2a22008-10-31 00:03:22 -04003190 int size = ARRAY_SIZE(ftrace_dyn_info_buffer);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003191 int r;
3192
Steven Rostedtb807c3d2008-10-30 16:08:33 -04003193 mutex_lock(&dyn_info_mutex);
3194 r = sprintf(buf, "%ld ", *p);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003195
Steven Rostedta26a2a22008-10-31 00:03:22 -04003196 r += ftrace_arch_read_dyn_info(buf+r, (size-1)-r);
Steven Rostedtb807c3d2008-10-30 16:08:33 -04003197 buf[r++] = '\n';
3198
3199 r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
3200
3201 mutex_unlock(&dyn_info_mutex);
3202
3203 return r;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003204}
3205
Steven Rostedtb807c3d2008-10-30 16:08:33 -04003206static struct file_operations tracing_dyn_info_fops = {
Ingo Molnar4bf39a92008-05-12 21:20:46 +02003207 .open = tracing_open_generic,
Steven Rostedtb807c3d2008-10-30 16:08:33 -04003208 .read = tracing_read_dyn_info,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003209};
3210#endif
3211
3212static struct dentry *d_tracer;
3213
3214struct dentry *tracing_init_dentry(void)
3215{
3216 static int once;
3217
3218 if (d_tracer)
3219 return d_tracer;
3220
3221 d_tracer = debugfs_create_dir("tracing", NULL);
3222
3223 if (!d_tracer && !once) {
3224 once = 1;
3225 pr_warning("Could not create debugfs directory 'tracing'\n");
3226 return NULL;
3227 }
3228
3229 return d_tracer;
3230}
3231
Steven Rostedt60a11772008-05-12 21:20:44 +02003232#ifdef CONFIG_FTRACE_SELFTEST
3233/* Let selftest have access to static functions in this file */
3234#include "trace_selftest.c"
3235#endif
3236
Frédéric Weisbeckerb5ad3842008-09-23 11:34:32 +01003237static __init int tracer_init_debugfs(void)
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003238{
3239 struct dentry *d_tracer;
3240 struct dentry *entry;
3241
3242 d_tracer = tracing_init_dentry();
3243
3244 entry = debugfs_create_file("tracing_enabled", 0644, d_tracer,
3245 &global_trace, &tracing_ctrl_fops);
3246 if (!entry)
3247 pr_warning("Could not create debugfs 'tracing_enabled' entry\n");
3248
Steven Rostedtee6bce52008-11-12 17:52:37 -05003249 entry = debugfs_create_file("trace_options", 0644, d_tracer,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003250 NULL, &tracing_iter_fops);
3251 if (!entry)
Steven Rostedtee6bce52008-11-12 17:52:37 -05003252 pr_warning("Could not create debugfs 'trace_options' entry\n");
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003253
Ingo Molnarc7078de2008-05-12 21:20:52 +02003254 entry = debugfs_create_file("tracing_cpumask", 0644, d_tracer,
3255 NULL, &tracing_cpumask_fops);
3256 if (!entry)
3257 pr_warning("Could not create debugfs 'tracing_cpumask' entry\n");
3258
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003259 entry = debugfs_create_file("latency_trace", 0444, d_tracer,
3260 &global_trace, &tracing_lt_fops);
3261 if (!entry)
3262 pr_warning("Could not create debugfs 'latency_trace' entry\n");
3263
3264 entry = debugfs_create_file("trace", 0444, d_tracer,
3265 &global_trace, &tracing_fops);
3266 if (!entry)
3267 pr_warning("Could not create debugfs 'trace' entry\n");
3268
3269 entry = debugfs_create_file("available_tracers", 0444, d_tracer,
3270 &global_trace, &show_traces_fops);
3271 if (!entry)
Frédéric Weisbecker98a983a2008-08-15 21:08:22 +02003272 pr_warning("Could not create debugfs 'available_tracers' entry\n");
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003273
3274 entry = debugfs_create_file("current_tracer", 0444, d_tracer,
3275 &global_trace, &set_tracer_fops);
3276 if (!entry)
Frédéric Weisbecker98a983a2008-08-15 21:08:22 +02003277 pr_warning("Could not create debugfs 'current_tracer' entry\n");
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003278
3279 entry = debugfs_create_file("tracing_max_latency", 0644, d_tracer,
3280 &tracing_max_latency,
3281 &tracing_max_lat_fops);
3282 if (!entry)
3283 pr_warning("Could not create debugfs "
3284 "'tracing_max_latency' entry\n");
3285
3286 entry = debugfs_create_file("tracing_thresh", 0644, d_tracer,
3287 &tracing_thresh, &tracing_max_lat_fops);
3288 if (!entry)
3289 pr_warning("Could not create debugfs "
Frédéric Weisbecker98a983a2008-08-15 21:08:22 +02003290 "'tracing_thresh' entry\n");
Ingo Molnar7bd2f242008-05-12 21:20:45 +02003291 entry = debugfs_create_file("README", 0644, d_tracer,
3292 NULL, &tracing_readme_fops);
3293 if (!entry)
3294 pr_warning("Could not create debugfs 'README' entry\n");
3295
Steven Rostedtb3806b42008-05-12 21:20:46 +02003296 entry = debugfs_create_file("trace_pipe", 0644, d_tracer,
3297 NULL, &tracing_pipe_fops);
3298 if (!entry)
3299 pr_warning("Could not create debugfs "
Frédéric Weisbecker98a983a2008-08-15 21:08:22 +02003300 "'trace_pipe' entry\n");
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003301
Steven Rostedta94c80e2008-11-12 17:52:36 -05003302 entry = debugfs_create_file("buffer_size_kb", 0644, d_tracer,
Steven Rostedta98a3c32008-05-12 21:20:59 +02003303 &global_trace, &tracing_entries_fops);
3304 if (!entry)
3305 pr_warning("Could not create debugfs "
Steven Rostedta94c80e2008-11-12 17:52:36 -05003306 "'buffer_size_kb' entry\n");
Steven Rostedta98a3c32008-05-12 21:20:59 +02003307
Pekka Paalanen5bf9a1e2008-09-16 22:06:42 +03003308 entry = debugfs_create_file("trace_marker", 0220, d_tracer,
3309 NULL, &tracing_mark_fops);
3310 if (!entry)
3311 pr_warning("Could not create debugfs "
3312 "'trace_marker' entry\n");
3313
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003314#ifdef CONFIG_DYNAMIC_FTRACE
3315 entry = debugfs_create_file("dyn_ftrace_total_info", 0444, d_tracer,
3316 &ftrace_update_tot_cnt,
Steven Rostedtb807c3d2008-10-30 16:08:33 -04003317 &tracing_dyn_info_fops);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003318 if (!entry)
3319 pr_warning("Could not create debugfs "
3320 "'dyn_ftrace_total_info' entry\n");
3321#endif
Ingo Molnard618b3e2008-05-12 21:20:49 +02003322#ifdef CONFIG_SYSPROF_TRACER
3323 init_tracer_sysprof_debugfs(d_tracer);
3324#endif
Frédéric Weisbeckerb5ad3842008-09-23 11:34:32 +01003325 return 0;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003326}
3327
Pekka Paalanen801fe402008-09-16 21:58:24 +03003328int trace_vprintk(unsigned long ip, const char *fmt, va_list args)
Steven Rostedtdd0e5452008-08-01 12:26:41 -04003329{
Steven Rostedtdd0e5452008-08-01 12:26:41 -04003330 static DEFINE_SPINLOCK(trace_buf_lock);
3331 static char trace_buf[TRACE_BUF_SIZE];
Peter Zijlstraf09ce572008-09-04 10:24:14 +02003332
Steven Rostedt3928a8a2008-09-29 23:02:41 -04003333 struct ring_buffer_event *event;
Peter Zijlstraf09ce572008-09-04 10:24:14 +02003334 struct trace_array *tr = &global_trace;
Steven Rostedtdd0e5452008-08-01 12:26:41 -04003335 struct trace_array_cpu *data;
Steven Rostedt777e2082008-09-29 23:02:42 -04003336 struct print_entry *entry;
Steven Rostedt3928a8a2008-09-29 23:02:41 -04003337 unsigned long flags, irq_flags;
Steven Rostedt38697052008-10-01 13:14:09 -04003338 int cpu, len = 0, size, pc;
Steven Rostedtdd0e5452008-08-01 12:26:41 -04003339
Steven Rostedtc76f0692008-11-07 22:36:02 -05003340 if (tracing_disabled)
Steven Rostedtdd0e5452008-08-01 12:26:41 -04003341 return 0;
3342
Steven Rostedt38697052008-10-01 13:14:09 -04003343 pc = preempt_count();
3344 preempt_disable_notrace();
Steven Rostedtdd0e5452008-08-01 12:26:41 -04003345 cpu = raw_smp_processor_id();
3346 data = tr->data[cpu];
Steven Rostedtdd0e5452008-08-01 12:26:41 -04003347
Steven Rostedt3ea2e6d2008-10-04 02:01:00 -04003348 if (unlikely(atomic_read(&data->disabled)))
Steven Rostedtdd0e5452008-08-01 12:26:41 -04003349 goto out;
3350
Steven Rostedt38697052008-10-01 13:14:09 -04003351 spin_lock_irqsave(&trace_buf_lock, flags);
Pekka Paalanen801fe402008-09-16 21:58:24 +03003352 len = vsnprintf(trace_buf, TRACE_BUF_SIZE, fmt, args);
Steven Rostedtdd0e5452008-08-01 12:26:41 -04003353
3354 len = min(len, TRACE_BUF_SIZE-1);
3355 trace_buf[len] = 0;
3356
Steven Rostedt777e2082008-09-29 23:02:42 -04003357 size = sizeof(*entry) + len + 1;
3358 event = ring_buffer_lock_reserve(tr->buffer, size, &irq_flags);
Steven Rostedt3928a8a2008-09-29 23:02:41 -04003359 if (!event)
3360 goto out_unlock;
Steven Rostedt777e2082008-09-29 23:02:42 -04003361 entry = ring_buffer_event_data(event);
Steven Rostedt38697052008-10-01 13:14:09 -04003362 tracing_generic_entry_update(&entry->ent, flags, pc);
Steven Rostedt777e2082008-09-29 23:02:42 -04003363 entry->ent.type = TRACE_PRINT;
3364 entry->ip = ip;
Steven Rostedtdd0e5452008-08-01 12:26:41 -04003365
Steven Rostedt777e2082008-09-29 23:02:42 -04003366 memcpy(&entry->buf, trace_buf, len);
3367 entry->buf[len] = 0;
Steven Rostedt3928a8a2008-09-29 23:02:41 -04003368 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
Steven Rostedtdd0e5452008-08-01 12:26:41 -04003369
Steven Rostedt3928a8a2008-09-29 23:02:41 -04003370 out_unlock:
Steven Rostedt38697052008-10-01 13:14:09 -04003371 spin_unlock_irqrestore(&trace_buf_lock, flags);
Steven Rostedtdd0e5452008-08-01 12:26:41 -04003372
3373 out:
Steven Rostedt38697052008-10-01 13:14:09 -04003374 preempt_enable_notrace();
Steven Rostedtdd0e5452008-08-01 12:26:41 -04003375
3376 return len;
3377}
Pekka Paalanen801fe402008-09-16 21:58:24 +03003378EXPORT_SYMBOL_GPL(trace_vprintk);
3379
3380int __ftrace_printk(unsigned long ip, const char *fmt, ...)
3381{
3382 int ret;
3383 va_list ap;
3384
3385 if (!(trace_flags & TRACE_ITER_PRINTK))
3386 return 0;
3387
3388 va_start(ap, fmt);
3389 ret = trace_vprintk(ip, fmt, ap);
3390 va_end(ap);
3391 return ret;
3392}
Steven Rostedtdd0e5452008-08-01 12:26:41 -04003393EXPORT_SYMBOL_GPL(__ftrace_printk);
3394
Steven Rostedt3f5a54e2008-07-30 22:36:46 -04003395static int trace_panic_handler(struct notifier_block *this,
3396 unsigned long event, void *unused)
3397{
Steven Rostedt944ac422008-10-23 19:26:08 -04003398 if (ftrace_dump_on_oops)
3399 ftrace_dump();
Steven Rostedt3f5a54e2008-07-30 22:36:46 -04003400 return NOTIFY_OK;
3401}
3402
3403static struct notifier_block trace_panic_notifier = {
3404 .notifier_call = trace_panic_handler,
3405 .next = NULL,
3406 .priority = 150 /* priority: INT_MAX >= x >= 0 */
3407};
3408
3409static int trace_die_handler(struct notifier_block *self,
3410 unsigned long val,
3411 void *data)
3412{
3413 switch (val) {
3414 case DIE_OOPS:
Steven Rostedt944ac422008-10-23 19:26:08 -04003415 if (ftrace_dump_on_oops)
3416 ftrace_dump();
Steven Rostedt3f5a54e2008-07-30 22:36:46 -04003417 break;
3418 default:
3419 break;
3420 }
3421 return NOTIFY_OK;
3422}
3423
3424static struct notifier_block trace_die_notifier = {
3425 .notifier_call = trace_die_handler,
3426 .priority = 200
3427};
3428
3429/*
3430 * printk is set to max of 1024, we really don't need it that big.
3431 * Nothing should be printing 1000 characters anyway.
3432 */
3433#define TRACE_MAX_PRINT 1000
3434
3435/*
3436 * Define here KERN_TRACE so that we have one place to modify
3437 * it if we decide to change what log level the ftrace dump
3438 * should be at.
3439 */
3440#define KERN_TRACE KERN_INFO
3441
3442static void
3443trace_printk_seq(struct trace_seq *s)
3444{
3445 /* Probably should print a warning here. */
3446 if (s->len >= 1000)
3447 s->len = 1000;
3448
3449 /* should be zero ended, but we are paranoid. */
3450 s->buffer[s->len] = 0;
3451
3452 printk(KERN_TRACE "%s", s->buffer);
3453
3454 trace_seq_reset(s);
3455}
3456
Steven Rostedt3f5a54e2008-07-30 22:36:46 -04003457void ftrace_dump(void)
3458{
3459 static DEFINE_SPINLOCK(ftrace_dump_lock);
3460 /* use static because iter can be a bit big for the stack */
3461 static struct trace_iterator iter;
Steven Rostedt3f5a54e2008-07-30 22:36:46 -04003462 static cpumask_t mask;
3463 static int dump_ran;
Steven Rostedtd7690412008-10-01 00:29:53 -04003464 unsigned long flags;
3465 int cnt = 0, cpu;
Steven Rostedt3f5a54e2008-07-30 22:36:46 -04003466
3467 /* only one dump */
3468 spin_lock_irqsave(&ftrace_dump_lock, flags);
3469 if (dump_ran)
3470 goto out;
3471
3472 dump_ran = 1;
3473
3474 /* No turning back! */
Steven Rostedt81adbdc2008-10-23 09:33:02 -04003475 ftrace_kill();
Steven Rostedt3f5a54e2008-07-30 22:36:46 -04003476
Steven Rostedtd7690412008-10-01 00:29:53 -04003477 for_each_tracing_cpu(cpu) {
3478 atomic_inc(&global_trace.data[cpu]->disabled);
3479 }
3480
Steven Rostedt3f5a54e2008-07-30 22:36:46 -04003481 printk(KERN_TRACE "Dumping ftrace buffer:\n");
3482
3483 iter.tr = &global_trace;
3484 iter.trace = current_trace;
3485
3486 /*
3487 * We need to stop all tracing on all CPUS to read the
3488 * the next buffer. This is a bit expensive, but is
3489 * not done often. We fill all what we can read,
3490 * and then release the locks again.
3491 */
3492
3493 cpus_clear(mask);
3494
Steven Rostedt3f5a54e2008-07-30 22:36:46 -04003495 while (!trace_empty(&iter)) {
3496
3497 if (!cnt)
3498 printk(KERN_TRACE "---------------------------------\n");
3499
3500 cnt++;
3501
3502 /* reset all but tr, trace, and overruns */
3503 memset(&iter.seq, 0,
3504 sizeof(struct trace_iterator) -
3505 offsetof(struct trace_iterator, seq));
3506 iter.iter_flags |= TRACE_FILE_LAT_FMT;
3507 iter.pos = -1;
3508
3509 if (find_next_entry_inc(&iter) != NULL) {
3510 print_trace_line(&iter);
3511 trace_consume(&iter);
3512 }
3513
3514 trace_printk_seq(&iter.seq);
3515 }
3516
3517 if (!cnt)
3518 printk(KERN_TRACE " (ftrace buffer empty)\n");
3519 else
3520 printk(KERN_TRACE "---------------------------------\n");
3521
Steven Rostedt3f5a54e2008-07-30 22:36:46 -04003522 out:
3523 spin_unlock_irqrestore(&ftrace_dump_lock, flags);
3524}
3525
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003526__init static int tracer_alloc_buffers(void)
3527{
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02003528 struct trace_array_cpu *data;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003529 int i;
3530
Steven Rostedtab464282008-05-12 21:21:00 +02003531 /* TODO: make the number of buffers hot pluggable with CPUS */
Steven Rostedtab464282008-05-12 21:21:00 +02003532 tracing_buffer_mask = cpu_possible_map;
3533
Steven Rostedt3928a8a2008-09-29 23:02:41 -04003534 global_trace.buffer = ring_buffer_alloc(trace_buf_size,
3535 TRACE_BUFFER_FLAGS);
3536 if (!global_trace.buffer) {
3537 printk(KERN_ERR "tracer: failed to allocate ring buffer!\n");
3538 WARN_ON(1);
3539 return 0;
3540 }
3541 global_trace.entries = ring_buffer_size(global_trace.buffer);
3542
3543#ifdef CONFIG_TRACER_MAX_TRACE
3544 max_tr.buffer = ring_buffer_alloc(trace_buf_size,
3545 TRACE_BUFFER_FLAGS);
3546 if (!max_tr.buffer) {
3547 printk(KERN_ERR "tracer: failed to allocate max ring buffer!\n");
3548 WARN_ON(1);
3549 ring_buffer_free(global_trace.buffer);
3550 return 0;
3551 }
3552 max_tr.entries = ring_buffer_size(max_tr.buffer);
3553 WARN_ON(max_tr.entries != global_trace.entries);
3554#endif
3555
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02003556 /* Allocate the first page for all buffers */
Steven Rostedtab464282008-05-12 21:21:00 +02003557 for_each_tracing_cpu(i) {
Steven Rostedt4c11d7a2008-05-12 21:20:43 +02003558 data = global_trace.data[i] = &per_cpu(global_trace_cpu, i);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003559 max_tr.data[i] = &per_cpu(max_data, i);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003560 }
3561
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003562 trace_init_cmdlines();
3563
Frédéric Weisbecker43a15382008-09-21 20:16:30 +02003564 register_tracer(&nop_trace);
Frédéric Weisbeckerb5ad3842008-09-23 11:34:32 +01003565#ifdef CONFIG_BOOT_TRACER
3566 register_tracer(&boot_tracer);
3567 current_trace = &boot_tracer;
3568 current_trace->init(&global_trace);
3569#else
Frédéric Weisbecker43a15382008-09-21 20:16:30 +02003570 current_trace = &nop_trace;
Frédéric Weisbeckerb5ad3842008-09-23 11:34:32 +01003571#endif
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003572
Steven Rostedt60a11772008-05-12 21:20:44 +02003573 /* All seems OK, enable tracing */
3574 tracing_disabled = 0;
Steven Rostedt3928a8a2008-09-29 23:02:41 -04003575
Steven Rostedt3f5a54e2008-07-30 22:36:46 -04003576 atomic_notifier_chain_register(&panic_notifier_list,
3577 &trace_panic_notifier);
3578
3579 register_die_notifier(&trace_die_notifier);
3580
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003581 return 0;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02003582}
Frédéric Weisbeckerb5ad3842008-09-23 11:34:32 +01003583early_initcall(tracer_alloc_buffers);
3584fs_initcall(tracer_init_debugfs);