x86, bts, ptrace: move BTS buffer allocation from ds.c into ptrace.c
[deliverable/linux.git] / kernel / trace / trace.c
CommitLineData
bc0c38d1
SR
1/*
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>
3f5a54e3 17#include <linux/notifier.h>
bc0c38d1 18#include <linux/debugfs.h>
4c11d7ae 19#include <linux/pagemap.h>
bc0c38d1
SR
20#include <linux/hardirq.h>
21#include <linux/linkage.h>
22#include <linux/uaccess.h>
23#include <linux/ftrace.h>
24#include <linux/module.h>
25#include <linux/percpu.h>
3f5a54e3 26#include <linux/kdebug.h>
bc0c38d1
SR
27#include <linux/ctype.h>
28#include <linux/init.h>
2a2cc8f7 29#include <linux/poll.h>
bc0c38d1
SR
30#include <linux/gfp.h>
31#include <linux/fs.h>
76094a2c 32#include <linux/kprobes.h>
b54d3de9 33#include <linux/seq_file.h>
3eefae99 34#include <linux/writeback.h>
bc0c38d1 35
86387f7e 36#include <linux/stacktrace.h>
3928a8a2 37#include <linux/ring_buffer.h>
21798a84 38#include <linux/irqflags.h>
86387f7e 39
bc0c38d1
SR
40#include "trace.h"
41
3928a8a2
SR
42#define TRACE_BUFFER_FLAGS (RB_FL_OVERWRITE)
43
bc0c38d1
SR
44unsigned long __read_mostly tracing_max_latency = (cycle_t)ULONG_MAX;
45unsigned long __read_mostly tracing_thresh;
46
adf9f195
FW
47/* For tracers that don't implement custom flags */
48static struct tracer_opt dummy_tracer_opt[] = {
49 { }
50};
51
52static struct tracer_flags dummy_tracer_flags = {
53 .val = 0,
54 .opts = dummy_tracer_opt
55};
56
57static int dummy_set_flag(u32 old_flags, u32 bit, int set)
58{
59 return 0;
60}
0f048701
SR
61
62/*
63 * Kill all tracing for good (never come back).
64 * It is initialized to 1 but will turn to zero if the initialization
65 * of the tracer is successful. But that is the only place that sets
66 * this back to zero.
67 */
68int tracing_disabled = 1;
69
d769041f
SR
70static DEFINE_PER_CPU(local_t, ftrace_cpu_disabled);
71
72static inline void ftrace_disable_cpu(void)
73{
74 preempt_disable();
75 local_inc(&__get_cpu_var(ftrace_cpu_disabled));
76}
77
78static inline void ftrace_enable_cpu(void)
79{
80 local_dec(&__get_cpu_var(ftrace_cpu_disabled));
81 preempt_enable();
82}
83
ab46428c
SR
84static cpumask_t __read_mostly tracing_buffer_mask;
85
86#define for_each_tracing_cpu(cpu) \
87 for_each_cpu_mask(cpu, tracing_buffer_mask)
88
944ac425
SR
89/*
90 * ftrace_dump_on_oops - variable to dump ftrace buffer on oops
91 *
92 * If there is an oops (or kernel panic) and the ftrace_dump_on_oops
93 * is set, then ftrace_dump is called. This will output the contents
94 * of the ftrace buffers to the console. This is very useful for
95 * capturing traces that lead to crashes and outputing it to a
96 * serial console.
97 *
98 * It is default off, but you can enable it with either specifying
99 * "ftrace_dump_on_oops" in the kernel command line, or setting
100 * /proc/sys/kernel/ftrace_dump_on_oops to true.
101 */
102int ftrace_dump_on_oops;
103
d9e54076
PZ
104static int tracing_set_tracer(char *buf);
105
106static int __init set_ftrace(char *str)
107{
108 tracing_set_tracer(str);
109 return 1;
110}
111__setup("ftrace", set_ftrace);
112
944ac425
SR
113static int __init set_ftrace_dump_on_oops(char *str)
114{
115 ftrace_dump_on_oops = 1;
116 return 1;
117}
118__setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops);
119
72829bc3 120long
bc0c38d1
SR
121ns2usecs(cycle_t nsec)
122{
123 nsec += 500;
124 do_div(nsec, 1000);
125 return nsec;
126}
127
e309b41d 128cycle_t ftrace_now(int cpu)
750ed1a4 129{
3928a8a2
SR
130 u64 ts = ring_buffer_time_stamp(cpu);
131 ring_buffer_normalize_time_stamp(cpu, &ts);
132 return ts;
750ed1a4
IM
133}
134
4fcdae83
SR
135/*
136 * The global_trace is the descriptor that holds the tracing
137 * buffers for the live tracing. For each CPU, it contains
138 * a link list of pages that will store trace entries. The
139 * page descriptor of the pages in the memory is used to hold
140 * the link list by linking the lru item in the page descriptor
141 * to each of the pages in the buffer per CPU.
142 *
143 * For each active CPU there is a data field that holds the
144 * pages for the buffer for that CPU. Each CPU has the same number
145 * of pages allocated for its buffer.
146 */
bc0c38d1
SR
147static struct trace_array global_trace;
148
149static DEFINE_PER_CPU(struct trace_array_cpu, global_trace_cpu);
150
4fcdae83
SR
151/*
152 * The max_tr is used to snapshot the global_trace when a maximum
153 * latency is reached. Some tracers will use this to store a maximum
154 * trace while it continues examining live traces.
155 *
156 * The buffers for the max_tr are set up the same as the global_trace.
157 * When a snapshot is taken, the link list of the max_tr is swapped
158 * with the link list of the global_trace and the buffers are reset for
159 * the global_trace so the tracing can continue.
160 */
bc0c38d1
SR
161static struct trace_array max_tr;
162
163static DEFINE_PER_CPU(struct trace_array_cpu, max_data);
164
4fcdae83 165/* tracer_enabled is used to toggle activation of a tracer */
26994ead 166static int tracer_enabled = 1;
4fcdae83 167
9036990d
SR
168/**
169 * tracing_is_enabled - return tracer_enabled status
170 *
171 * This function is used by other tracers to know the status
172 * of the tracer_enabled flag. Tracers may use this function
173 * to know if it should enable their features when starting
174 * up. See irqsoff tracer for an example (start_irqsoff_tracer).
175 */
176int tracing_is_enabled(void)
177{
178 return tracer_enabled;
179}
180
60bc0800
SR
181/* function tracing enabled */
182int ftrace_function_enabled;
183
4fcdae83 184/*
3928a8a2
SR
185 * trace_buf_size is the size in bytes that is allocated
186 * for a buffer. Note, the number of bytes is always rounded
187 * to page size.
3f5a54e3
SR
188 *
189 * This number is purposely set to a low number of 16384.
190 * If the dump on oops happens, it will be much appreciated
191 * to not have to wait for all that output. Anyway this can be
192 * boot time and run time configurable.
4fcdae83 193 */
3928a8a2 194#define TRACE_BUF_SIZE_DEFAULT 1441792UL /* 16384 * 88 (sizeof(entry)) */
3f5a54e3 195
3928a8a2 196static unsigned long trace_buf_size = TRACE_BUF_SIZE_DEFAULT;
bc0c38d1 197
4fcdae83 198/* trace_types holds a link list of available tracers. */
bc0c38d1 199static struct tracer *trace_types __read_mostly;
4fcdae83
SR
200
201/* current_trace points to the tracer that is currently active */
bc0c38d1 202static struct tracer *current_trace __read_mostly;
4fcdae83
SR
203
204/*
205 * max_tracer_type_len is used to simplify the allocating of
206 * buffers to read userspace tracer names. We keep track of
207 * the longest tracer name registered.
208 */
bc0c38d1
SR
209static int max_tracer_type_len;
210
4fcdae83
SR
211/*
212 * trace_types_lock is used to protect the trace_types list.
213 * This lock is also used to keep user access serialized.
214 * Accesses from userspace will grab this lock while userspace
215 * activities happen inside the kernel.
216 */
bc0c38d1 217static DEFINE_MUTEX(trace_types_lock);
4fcdae83
SR
218
219/* trace_wait is a waitqueue for tasks blocked on trace_poll */
4e655519
IM
220static DECLARE_WAIT_QUEUE_HEAD(trace_wait);
221
ee6bce52 222/* trace_flags holds trace_options default values */
12ef7d44
SR
223unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |
224 TRACE_ITER_ANNOTATE;
4e655519 225
4fcdae83
SR
226/**
227 * trace_wake_up - wake up tasks waiting for trace input
228 *
229 * Simply wakes up any task that is blocked on the trace_wait
230 * queue. These is used with trace_poll for tasks polling the trace.
231 */
4e655519
IM
232void trace_wake_up(void)
233{
017730c1
IM
234 /*
235 * The runqueue_is_locked() can fail, but this is the best we
236 * have for now:
237 */
238 if (!(trace_flags & TRACE_ITER_BLOCK) && !runqueue_is_locked())
4e655519
IM
239 wake_up(&trace_wait);
240}
bc0c38d1 241
3928a8a2 242static int __init set_buf_size(char *str)
bc0c38d1 243{
3928a8a2 244 unsigned long buf_size;
c6caeeb1
SR
245 int ret;
246
bc0c38d1
SR
247 if (!str)
248 return 0;
3928a8a2 249 ret = strict_strtoul(str, 0, &buf_size);
c6caeeb1 250 /* nr_entries can not be zero */
3928a8a2 251 if (ret < 0 || buf_size == 0)
c6caeeb1 252 return 0;
3928a8a2 253 trace_buf_size = buf_size;
bc0c38d1
SR
254 return 1;
255}
3928a8a2 256__setup("trace_buf_size=", set_buf_size);
bc0c38d1 257
57f50be1
SR
258unsigned long nsecs_to_usecs(unsigned long nsecs)
259{
260 return nsecs / 1000;
261}
262
4fcdae83 263/* These must match the bit postions in trace_iterator_flags */
bc0c38d1
SR
264static const char *trace_options[] = {
265 "print-parent",
266 "sym-offset",
267 "sym-addr",
268 "verbose",
f9896bf3 269 "raw",
5e3ca0ec 270 "hex",
cb0f12aa 271 "bin",
2a2cc8f7 272 "block",
86387f7e 273 "stacktrace",
4ac3ba41 274 "sched-tree",
f09ce573 275 "ftrace_printk",
b2a866f9 276 "ftrace_preempt",
9f029e83 277 "branch",
12ef7d44 278 "annotate",
02b67518 279 "userstacktrace",
b54d3de9 280 "sym-userobj",
bc0c38d1
SR
281 NULL
282};
283
4fcdae83
SR
284/*
285 * ftrace_max_lock is used to protect the swapping of buffers
286 * when taking a max snapshot. The buffers themselves are
287 * protected by per_cpu spinlocks. But the action of the swap
288 * needs its own lock.
289 *
290 * This is defined as a raw_spinlock_t in order to help
291 * with performance when lockdep debugging is enabled.
292 */
92205c23
SR
293static raw_spinlock_t ftrace_max_lock =
294 (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED;
bc0c38d1
SR
295
296/*
297 * Copy the new maximum trace into the separate maximum-trace
298 * structure. (this way the maximum trace is permanently saved,
299 * for later retrieval via /debugfs/tracing/latency_trace)
300 */
e309b41d 301static void
bc0c38d1
SR
302__update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
303{
304 struct trace_array_cpu *data = tr->data[cpu];
305
306 max_tr.cpu = cpu;
307 max_tr.time_start = data->preempt_timestamp;
308
309 data = max_tr.data[cpu];
310 data->saved_latency = tracing_max_latency;
311
312 memcpy(data->comm, tsk->comm, TASK_COMM_LEN);
313 data->pid = tsk->pid;
314 data->uid = tsk->uid;
315 data->nice = tsk->static_prio - 20 - MAX_RT_PRIO;
316 data->policy = tsk->policy;
317 data->rt_priority = tsk->rt_priority;
318
319 /* record this tasks comm */
320 tracing_record_cmdline(current);
321}
322
4fcdae83
SR
323/**
324 * trace_seq_printf - sequence printing of trace information
325 * @s: trace sequence descriptor
326 * @fmt: printf format string
327 *
328 * The tracer may use either sequence operations or its own
329 * copy to user routines. To simplify formating of a trace
330 * trace_seq_printf is used to store strings into a special
331 * buffer (@s). Then the output may be either used by
332 * the sequencer or pulled into another buffer.
333 */
72829bc3 334int
214023c3
SR
335trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
336{
337 int len = (PAGE_SIZE - 1) - s->len;
338 va_list ap;
b3806b43 339 int ret;
214023c3
SR
340
341 if (!len)
342 return 0;
343
344 va_start(ap, fmt);
b3806b43 345 ret = vsnprintf(s->buffer + s->len, len, fmt, ap);
214023c3
SR
346 va_end(ap);
347
b3806b43 348 /* If we can't write it all, don't bother writing anything */
72829bc3 349 if (ret >= len)
b3806b43
SR
350 return 0;
351
352 s->len += ret;
214023c3
SR
353
354 return len;
355}
356
4fcdae83
SR
357/**
358 * trace_seq_puts - trace sequence printing of simple string
359 * @s: trace sequence descriptor
360 * @str: simple string to record
361 *
362 * The tracer may use either the sequence operations or its own
363 * copy to user routines. This function records a simple string
364 * into a special buffer (@s) for later retrieval by a sequencer
365 * or other mechanism.
366 */
e309b41d 367static int
214023c3
SR
368trace_seq_puts(struct trace_seq *s, const char *str)
369{
370 int len = strlen(str);
371
372 if (len > ((PAGE_SIZE - 1) - s->len))
b3806b43 373 return 0;
214023c3
SR
374
375 memcpy(s->buffer + s->len, str, len);
376 s->len += len;
377
378 return len;
379}
380
e309b41d 381static int
214023c3
SR
382trace_seq_putc(struct trace_seq *s, unsigned char c)
383{
384 if (s->len >= (PAGE_SIZE - 1))
385 return 0;
386
387 s->buffer[s->len++] = c;
388
389 return 1;
390}
391
e309b41d 392static int
cb0f12aa
IM
393trace_seq_putmem(struct trace_seq *s, void *mem, size_t len)
394{
395 if (len > ((PAGE_SIZE - 1) - s->len))
396 return 0;
397
398 memcpy(s->buffer + s->len, mem, len);
399 s->len += len;
400
401 return len;
402}
403
ad0a3b68
HH
404#define MAX_MEMHEX_BYTES 8
405#define HEX_CHARS (MAX_MEMHEX_BYTES*2 + 1)
5e3ca0ec 406
e309b41d 407static int
5e3ca0ec
IM
408trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len)
409{
410 unsigned char hex[HEX_CHARS];
93dcc6ea 411 unsigned char *data = mem;
5e3ca0ec
IM
412 int i, j;
413
5e3ca0ec
IM
414#ifdef __BIG_ENDIAN
415 for (i = 0, j = 0; i < len; i++) {
416#else
417 for (i = len-1, j = 0; i >= 0; i--) {
418#endif
2fbc4749
HH
419 hex[j++] = hex_asc_hi(data[i]);
420 hex[j++] = hex_asc_lo(data[i]);
5e3ca0ec 421 }
93dcc6ea 422 hex[j++] = ' ';
5e3ca0ec
IM
423
424 return trace_seq_putmem(s, hex, j);
425}
426
b54d3de9
TE
427static int
428trace_seq_path(struct trace_seq *s, struct path *path)
429{
430 unsigned char *p;
431
432 if (s->len >= (PAGE_SIZE - 1))
433 return 0;
434 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
435 if (!IS_ERR(p)) {
436 p = mangle_path(s->buffer + s->len, p, "\n");
437 if (p) {
438 s->len = p - s->buffer;
439 return 1;
440 }
441 } else {
442 s->buffer[s->len++] = '?';
443 return 1;
444 }
445
446 return 0;
447}
448
e309b41d 449static void
214023c3
SR
450trace_seq_reset(struct trace_seq *s)
451{
452 s->len = 0;
6c6c2796
PP
453 s->readpos = 0;
454}
455
456ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt)
457{
458 int len;
459 int ret;
460
461 if (s->len <= s->readpos)
462 return -EBUSY;
463
464 len = s->len - s->readpos;
465 if (cnt > len)
466 cnt = len;
467 ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt);
468 if (ret)
469 return -EFAULT;
470
471 s->readpos += len;
472 return cnt;
214023c3
SR
473}
474
e309b41d 475static void
214023c3
SR
476trace_print_seq(struct seq_file *m, struct trace_seq *s)
477{
478 int len = s->len >= PAGE_SIZE ? PAGE_SIZE - 1 : s->len;
479
480 s->buffer[len] = 0;
481 seq_puts(m, s->buffer);
482
483 trace_seq_reset(s);
484}
485
4fcdae83
SR
486/**
487 * update_max_tr - snapshot all trace buffers from global_trace to max_tr
488 * @tr: tracer
489 * @tsk: the task with the latency
490 * @cpu: The cpu that initiated the trace.
491 *
492 * Flip the buffers between the @tr and the max_tr and record information
493 * about which task was the cause of this latency.
494 */
e309b41d 495void
bc0c38d1
SR
496update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
497{
3928a8a2 498 struct ring_buffer *buf = tr->buffer;
bc0c38d1 499
4c11d7ae 500 WARN_ON_ONCE(!irqs_disabled());
92205c23 501 __raw_spin_lock(&ftrace_max_lock);
3928a8a2
SR
502
503 tr->buffer = max_tr.buffer;
504 max_tr.buffer = buf;
505
d769041f 506 ftrace_disable_cpu();
3928a8a2 507 ring_buffer_reset(tr->buffer);
d769041f 508 ftrace_enable_cpu();
bc0c38d1
SR
509
510 __update_max_tr(tr, tsk, cpu);
92205c23 511 __raw_spin_unlock(&ftrace_max_lock);
bc0c38d1
SR
512}
513
514/**
515 * update_max_tr_single - only copy one trace over, and reset the rest
516 * @tr - tracer
517 * @tsk - task with the latency
518 * @cpu - the cpu of the buffer to copy.
4fcdae83
SR
519 *
520 * Flip the trace of a single CPU buffer between the @tr and the max_tr.
bc0c38d1 521 */
e309b41d 522void
bc0c38d1
SR
523update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu)
524{
3928a8a2 525 int ret;
bc0c38d1 526
4c11d7ae 527 WARN_ON_ONCE(!irqs_disabled());
92205c23 528 __raw_spin_lock(&ftrace_max_lock);
bc0c38d1 529
d769041f
SR
530 ftrace_disable_cpu();
531
3928a8a2
SR
532 ring_buffer_reset(max_tr.buffer);
533 ret = ring_buffer_swap_cpu(max_tr.buffer, tr->buffer, cpu);
534
d769041f
SR
535 ftrace_enable_cpu();
536
3928a8a2 537 WARN_ON_ONCE(ret);
bc0c38d1
SR
538
539 __update_max_tr(tr, tsk, cpu);
92205c23 540 __raw_spin_unlock(&ftrace_max_lock);
bc0c38d1
SR
541}
542
4fcdae83
SR
543/**
544 * register_tracer - register a tracer with the ftrace system.
545 * @type - the plugin for the tracer
546 *
547 * Register a new plugin tracer.
548 */
bc0c38d1
SR
549int register_tracer(struct tracer *type)
550{
551 struct tracer *t;
552 int len;
553 int ret = 0;
554
555 if (!type->name) {
556 pr_info("Tracer must have a name\n");
557 return -1;
558 }
559
86fa2f60
IM
560 /*
561 * When this gets called we hold the BKL which means that
562 * preemption is disabled. Various trace selftests however
563 * need to disable and enable preemption for successful tests.
564 * So we drop the BKL here and grab it after the tests again.
565 */
566 unlock_kernel();
bc0c38d1 567 mutex_lock(&trace_types_lock);
86fa2f60 568
bc0c38d1
SR
569 for (t = trace_types; t; t = t->next) {
570 if (strcmp(type->name, t->name) == 0) {
571 /* already found */
572 pr_info("Trace %s already registered\n",
573 type->name);
574 ret = -1;
575 goto out;
576 }
577 }
578
adf9f195
FW
579 if (!type->set_flag)
580 type->set_flag = &dummy_set_flag;
581 if (!type->flags)
582 type->flags = &dummy_tracer_flags;
583 else
584 if (!type->flags->opts)
585 type->flags->opts = dummy_tracer_opt;
586
60a11774
SR
587#ifdef CONFIG_FTRACE_STARTUP_TEST
588 if (type->selftest) {
589 struct tracer *saved_tracer = current_trace;
60a11774 590 struct trace_array *tr = &global_trace;
60a11774
SR
591 int i;
592 /*
593 * Run a selftest on this tracer.
594 * Here we reset the trace buffer, and set the current
595 * tracer to be this tracer. The tracer can then run some
596 * internal tracing to verify that everything is in order.
597 * If we fail, we do not register this tracer.
598 */
86fa2f60 599 for_each_tracing_cpu(i)
3928a8a2 600 tracing_reset(tr, i);
86fa2f60 601
60a11774 602 current_trace = type;
60a11774
SR
603 /* the test is responsible for initializing and enabling */
604 pr_info("Testing tracer %s: ", type->name);
605 ret = type->selftest(type, tr);
606 /* the test is responsible for resetting too */
607 current_trace = saved_tracer;
60a11774
SR
608 if (ret) {
609 printk(KERN_CONT "FAILED!\n");
610 goto out;
611 }
1d4db00a 612 /* Only reset on passing, to avoid touching corrupted buffers */
86fa2f60 613 for_each_tracing_cpu(i)
3928a8a2 614 tracing_reset(tr, i);
86fa2f60 615
60a11774
SR
616 printk(KERN_CONT "PASSED\n");
617 }
618#endif
619
bc0c38d1
SR
620 type->next = trace_types;
621 trace_types = type;
622 len = strlen(type->name);
623 if (len > max_tracer_type_len)
624 max_tracer_type_len = len;
60a11774 625
bc0c38d1
SR
626 out:
627 mutex_unlock(&trace_types_lock);
86fa2f60 628 lock_kernel();
bc0c38d1
SR
629
630 return ret;
631}
632
633void unregister_tracer(struct tracer *type)
634{
635 struct tracer **t;
636 int len;
637
638 mutex_lock(&trace_types_lock);
639 for (t = &trace_types; *t; t = &(*t)->next) {
640 if (*t == type)
641 goto found;
642 }
643 pr_info("Trace %s not registered\n", type->name);
644 goto out;
645
646 found:
647 *t = (*t)->next;
648 if (strlen(type->name) != max_tracer_type_len)
649 goto out;
650
651 max_tracer_type_len = 0;
652 for (t = &trace_types; *t; t = &(*t)->next) {
653 len = strlen((*t)->name);
654 if (len > max_tracer_type_len)
655 max_tracer_type_len = len;
656 }
657 out:
658 mutex_unlock(&trace_types_lock);
659}
660
3928a8a2 661void tracing_reset(struct trace_array *tr, int cpu)
bc0c38d1 662{
d769041f 663 ftrace_disable_cpu();
3928a8a2 664 ring_buffer_reset_cpu(tr->buffer, cpu);
d769041f 665 ftrace_enable_cpu();
bc0c38d1
SR
666}
667
bc0c38d1
SR
668#define SAVED_CMDLINES 128
669static unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
670static unsigned map_cmdline_to_pid[SAVED_CMDLINES];
671static char saved_cmdlines[SAVED_CMDLINES][TASK_COMM_LEN];
672static int cmdline_idx;
673static DEFINE_SPINLOCK(trace_cmdline_lock);
25b0b44a 674
25b0b44a
SR
675/* temporary disable recording */
676atomic_t trace_record_cmdline_disabled __read_mostly;
bc0c38d1
SR
677
678static void trace_init_cmdlines(void)
679{
680 memset(&map_pid_to_cmdline, -1, sizeof(map_pid_to_cmdline));
681 memset(&map_cmdline_to_pid, -1, sizeof(map_cmdline_to_pid));
682 cmdline_idx = 0;
683}
684
0f048701
SR
685static int trace_stop_count;
686static DEFINE_SPINLOCK(tracing_start_lock);
687
69bb54ec
SR
688/**
689 * ftrace_off_permanent - disable all ftrace code permanently
690 *
691 * This should only be called when a serious anomally has
692 * been detected. This will turn off the function tracing,
693 * ring buffers, and other tracing utilites. It takes no
694 * locks and can be called from any context.
695 */
696void ftrace_off_permanent(void)
697{
698 tracing_disabled = 1;
699 ftrace_stop();
700 tracing_off_permanent();
701}
702
0f048701
SR
703/**
704 * tracing_start - quick start of the tracer
705 *
706 * If tracing is enabled but was stopped by tracing_stop,
707 * this will start the tracer back up.
708 */
709void tracing_start(void)
710{
711 struct ring_buffer *buffer;
712 unsigned long flags;
713
714 if (tracing_disabled)
715 return;
716
717 spin_lock_irqsave(&tracing_start_lock, flags);
718 if (--trace_stop_count)
719 goto out;
720
721 if (trace_stop_count < 0) {
722 /* Someone screwed up their debugging */
723 WARN_ON_ONCE(1);
724 trace_stop_count = 0;
725 goto out;
726 }
727
728
729 buffer = global_trace.buffer;
730 if (buffer)
731 ring_buffer_record_enable(buffer);
732
733 buffer = max_tr.buffer;
734 if (buffer)
735 ring_buffer_record_enable(buffer);
736
737 ftrace_start();
738 out:
739 spin_unlock_irqrestore(&tracing_start_lock, flags);
740}
741
742/**
743 * tracing_stop - quick stop of the tracer
744 *
745 * Light weight way to stop tracing. Use in conjunction with
746 * tracing_start.
747 */
748void tracing_stop(void)
749{
750 struct ring_buffer *buffer;
751 unsigned long flags;
752
753 ftrace_stop();
754 spin_lock_irqsave(&tracing_start_lock, flags);
755 if (trace_stop_count++)
756 goto out;
757
758 buffer = global_trace.buffer;
759 if (buffer)
760 ring_buffer_record_disable(buffer);
761
762 buffer = max_tr.buffer;
763 if (buffer)
764 ring_buffer_record_disable(buffer);
765
766 out:
767 spin_unlock_irqrestore(&tracing_start_lock, flags);
768}
769
e309b41d 770void trace_stop_cmdline_recording(void);
bc0c38d1 771
e309b41d 772static void trace_save_cmdline(struct task_struct *tsk)
bc0c38d1
SR
773{
774 unsigned map;
775 unsigned idx;
776
777 if (!tsk->pid || unlikely(tsk->pid > PID_MAX_DEFAULT))
778 return;
779
780 /*
781 * It's not the end of the world if we don't get
782 * the lock, but we also don't want to spin
783 * nor do we want to disable interrupts,
784 * so if we miss here, then better luck next time.
785 */
786 if (!spin_trylock(&trace_cmdline_lock))
787 return;
788
789 idx = map_pid_to_cmdline[tsk->pid];
790 if (idx >= SAVED_CMDLINES) {
791 idx = (cmdline_idx + 1) % SAVED_CMDLINES;
792
793 map = map_cmdline_to_pid[idx];
794 if (map <= PID_MAX_DEFAULT)
795 map_pid_to_cmdline[map] = (unsigned)-1;
796
797 map_pid_to_cmdline[tsk->pid] = idx;
798
799 cmdline_idx = idx;
800 }
801
802 memcpy(&saved_cmdlines[idx], tsk->comm, TASK_COMM_LEN);
803
804 spin_unlock(&trace_cmdline_lock);
805}
806
e309b41d 807static char *trace_find_cmdline(int pid)
bc0c38d1
SR
808{
809 char *cmdline = "<...>";
810 unsigned map;
811
812 if (!pid)
813 return "<idle>";
814
815 if (pid > PID_MAX_DEFAULT)
816 goto out;
817
818 map = map_pid_to_cmdline[pid];
819 if (map >= SAVED_CMDLINES)
820 goto out;
821
822 cmdline = saved_cmdlines[map];
823
824 out:
825 return cmdline;
826}
827
e309b41d 828void tracing_record_cmdline(struct task_struct *tsk)
bc0c38d1
SR
829{
830 if (atomic_read(&trace_record_cmdline_disabled))
831 return;
832
833 trace_save_cmdline(tsk);
834}
835
45dcd8b8 836void
38697053
SR
837tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags,
838 int pc)
bc0c38d1
SR
839{
840 struct task_struct *tsk = current;
bc0c38d1 841
777e208d
SR
842 entry->preempt_count = pc & 0xff;
843 entry->pid = (tsk) ? tsk->pid : 0;
b54d3de9 844 entry->tgid = (tsk) ? tsk->tgid : 0;
777e208d 845 entry->flags =
9244489a 846#ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
2e2ca155 847 (irqs_disabled_flags(flags) ? TRACE_FLAG_IRQS_OFF : 0) |
9244489a
SR
848#else
849 TRACE_FLAG_IRQS_NOSUPPORT |
850#endif
bc0c38d1
SR
851 ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) |
852 ((pc & SOFTIRQ_MASK) ? TRACE_FLAG_SOFTIRQ : 0) |
853 (need_resched() ? TRACE_FLAG_NEED_RESCHED : 0);
854}
855
e309b41d 856void
6fb44b71 857trace_function(struct trace_array *tr, struct trace_array_cpu *data,
38697053
SR
858 unsigned long ip, unsigned long parent_ip, unsigned long flags,
859 int pc)
bc0c38d1 860{
3928a8a2 861 struct ring_buffer_event *event;
777e208d 862 struct ftrace_entry *entry;
dcb6308f 863 unsigned long irq_flags;
bc0c38d1 864
d769041f
SR
865 /* If we are reading the ring buffer, don't trace */
866 if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled))))
867 return;
868
3928a8a2
SR
869 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
870 &irq_flags);
871 if (!event)
872 return;
873 entry = ring_buffer_event_data(event);
38697053 874 tracing_generic_entry_update(&entry->ent, flags, pc);
777e208d
SR
875 entry->ent.type = TRACE_FN;
876 entry->ip = ip;
877 entry->parent_ip = parent_ip;
3928a8a2 878 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
bc0c38d1
SR
879}
880
15e6cb36
FW
881#ifdef CONFIG_FUNCTION_RET_TRACER
882static void __trace_function_return(struct trace_array *tr,
883 struct trace_array_cpu *data,
884 struct ftrace_retfunc *trace,
885 unsigned long flags,
886 int pc)
887{
888 struct ring_buffer_event *event;
889 struct ftrace_ret_entry *entry;
890 unsigned long irq_flags;
891
892 if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled))))
893 return;
894
895 event = ring_buffer_lock_reserve(global_trace.buffer, sizeof(*entry),
896 &irq_flags);
897 if (!event)
898 return;
899 entry = ring_buffer_event_data(event);
900 tracing_generic_entry_update(&entry->ent, flags, pc);
901 entry->ent.type = TRACE_FN_RET;
902 entry->ip = trace->func;
903 entry->parent_ip = trace->ret;
904 entry->rettime = trace->rettime;
905 entry->calltime = trace->calltime;
0231022c 906 entry->overrun = trace->overrun;
15e6cb36
FW
907 ring_buffer_unlock_commit(global_trace.buffer, event, irq_flags);
908}
909#endif
910
e309b41d 911void
2e0f5761 912ftrace(struct trace_array *tr, struct trace_array_cpu *data,
38697053
SR
913 unsigned long ip, unsigned long parent_ip, unsigned long flags,
914 int pc)
2e0f5761
IM
915{
916 if (likely(!atomic_read(&data->disabled)))
38697053 917 trace_function(tr, data, ip, parent_ip, flags, pc);
2e0f5761
IM
918}
919
38697053
SR
920static void ftrace_trace_stack(struct trace_array *tr,
921 struct trace_array_cpu *data,
922 unsigned long flags,
923 int skip, int pc)
86387f7e 924{
c2c80529 925#ifdef CONFIG_STACKTRACE
3928a8a2 926 struct ring_buffer_event *event;
777e208d 927 struct stack_entry *entry;
86387f7e 928 struct stack_trace trace;
3928a8a2 929 unsigned long irq_flags;
86387f7e
IM
930
931 if (!(trace_flags & TRACE_ITER_STACKTRACE))
932 return;
933
3928a8a2
SR
934 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
935 &irq_flags);
936 if (!event)
937 return;
938 entry = ring_buffer_event_data(event);
38697053 939 tracing_generic_entry_update(&entry->ent, flags, pc);
777e208d 940 entry->ent.type = TRACE_STACK;
86387f7e 941
777e208d 942 memset(&entry->caller, 0, sizeof(entry->caller));
86387f7e
IM
943
944 trace.nr_entries = 0;
945 trace.max_entries = FTRACE_STACK_ENTRIES;
946 trace.skip = skip;
777e208d 947 trace.entries = entry->caller;
86387f7e
IM
948
949 save_stack_trace(&trace);
3928a8a2 950 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
c2c80529 951#endif
f0a920d5
IM
952}
953
38697053
SR
954void __trace_stack(struct trace_array *tr,
955 struct trace_array_cpu *data,
956 unsigned long flags,
957 int skip)
958{
959 ftrace_trace_stack(tr, data, flags, skip, preempt_count());
960}
961
02b67518
TE
962static void ftrace_trace_userstack(struct trace_array *tr,
963 struct trace_array_cpu *data,
964 unsigned long flags, int pc)
965{
8d7c6a96 966 struct ring_buffer_event *event;
02b67518
TE
967 struct userstack_entry *entry;
968 struct stack_trace trace;
02b67518
TE
969 unsigned long irq_flags;
970
971 if (!(trace_flags & TRACE_ITER_USERSTACKTRACE))
972 return;
973
974 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
975 &irq_flags);
976 if (!event)
977 return;
978 entry = ring_buffer_event_data(event);
979 tracing_generic_entry_update(&entry->ent, flags, pc);
980 entry->ent.type = TRACE_USER_STACK;
981
982 memset(&entry->caller, 0, sizeof(entry->caller));
983
984 trace.nr_entries = 0;
985 trace.max_entries = FTRACE_STACK_ENTRIES;
986 trace.skip = 0;
987 trace.entries = entry->caller;
988
989 save_stack_trace_user(&trace);
990 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
991}
992
993void __trace_userstack(struct trace_array *tr,
994 struct trace_array_cpu *data,
995 unsigned long flags)
996{
997 ftrace_trace_userstack(tr, data, flags, preempt_count());
998}
999
38697053
SR
1000static void
1001ftrace_trace_special(void *__tr, void *__data,
1002 unsigned long arg1, unsigned long arg2, unsigned long arg3,
1003 int pc)
a4feb834 1004{
3928a8a2 1005 struct ring_buffer_event *event;
a4feb834
IM
1006 struct trace_array_cpu *data = __data;
1007 struct trace_array *tr = __tr;
777e208d 1008 struct special_entry *entry;
a4feb834
IM
1009 unsigned long irq_flags;
1010
3928a8a2
SR
1011 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
1012 &irq_flags);
1013 if (!event)
1014 return;
1015 entry = ring_buffer_event_data(event);
38697053 1016 tracing_generic_entry_update(&entry->ent, 0, pc);
777e208d
SR
1017 entry->ent.type = TRACE_SPECIAL;
1018 entry->arg1 = arg1;
1019 entry->arg2 = arg2;
1020 entry->arg3 = arg3;
3928a8a2 1021 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
38697053 1022 ftrace_trace_stack(tr, data, irq_flags, 4, pc);
02b67518 1023 ftrace_trace_userstack(tr, data, irq_flags, pc);
a4feb834
IM
1024
1025 trace_wake_up();
1026}
1027
38697053
SR
1028void
1029__trace_special(void *__tr, void *__data,
1030 unsigned long arg1, unsigned long arg2, unsigned long arg3)
1031{
1032 ftrace_trace_special(__tr, __data, arg1, arg2, arg3, preempt_count());
1033}
1034
e309b41d 1035void
bc0c38d1
SR
1036tracing_sched_switch_trace(struct trace_array *tr,
1037 struct trace_array_cpu *data,
86387f7e
IM
1038 struct task_struct *prev,
1039 struct task_struct *next,
38697053 1040 unsigned long flags, int pc)
bc0c38d1 1041{
3928a8a2 1042 struct ring_buffer_event *event;
777e208d 1043 struct ctx_switch_entry *entry;
dcb6308f 1044 unsigned long irq_flags;
bc0c38d1 1045
3928a8a2
SR
1046 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
1047 &irq_flags);
1048 if (!event)
1049 return;
1050 entry = ring_buffer_event_data(event);
38697053 1051 tracing_generic_entry_update(&entry->ent, flags, pc);
777e208d
SR
1052 entry->ent.type = TRACE_CTX;
1053 entry->prev_pid = prev->pid;
1054 entry->prev_prio = prev->prio;
1055 entry->prev_state = prev->state;
1056 entry->next_pid = next->pid;
1057 entry->next_prio = next->prio;
1058 entry->next_state = next->state;
1059 entry->next_cpu = task_cpu(next);
3928a8a2 1060 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
38697053 1061 ftrace_trace_stack(tr, data, flags, 5, pc);
02b67518 1062 ftrace_trace_userstack(tr, data, flags, pc);
bc0c38d1
SR
1063}
1064
57422797
IM
1065void
1066tracing_sched_wakeup_trace(struct trace_array *tr,
1067 struct trace_array_cpu *data,
86387f7e
IM
1068 struct task_struct *wakee,
1069 struct task_struct *curr,
38697053 1070 unsigned long flags, int pc)
57422797 1071{
3928a8a2 1072 struct ring_buffer_event *event;
777e208d 1073 struct ctx_switch_entry *entry;
57422797
IM
1074 unsigned long irq_flags;
1075
3928a8a2
SR
1076 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
1077 &irq_flags);
1078 if (!event)
1079 return;
1080 entry = ring_buffer_event_data(event);
38697053 1081 tracing_generic_entry_update(&entry->ent, flags, pc);
777e208d
SR
1082 entry->ent.type = TRACE_WAKE;
1083 entry->prev_pid = curr->pid;
1084 entry->prev_prio = curr->prio;
1085 entry->prev_state = curr->state;
1086 entry->next_pid = wakee->pid;
1087 entry->next_prio = wakee->prio;
1088 entry->next_state = wakee->state;
1089 entry->next_cpu = task_cpu(wakee);
3928a8a2 1090 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
38697053 1091 ftrace_trace_stack(tr, data, flags, 6, pc);
02b67518 1092 ftrace_trace_userstack(tr, data, flags, pc);
017730c1
IM
1093
1094 trace_wake_up();
57422797
IM
1095}
1096
4902f884
SR
1097void
1098ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3)
1099{
1100 struct trace_array *tr = &global_trace;
1101 struct trace_array_cpu *data;
5aa1ba6a 1102 unsigned long flags;
4902f884 1103 int cpu;
38697053 1104 int pc;
4902f884 1105
c76f0694 1106 if (tracing_disabled)
4902f884
SR
1107 return;
1108
38697053 1109 pc = preempt_count();
5aa1ba6a 1110 local_irq_save(flags);
4902f884
SR
1111 cpu = raw_smp_processor_id();
1112 data = tr->data[cpu];
4902f884 1113
5aa1ba6a 1114 if (likely(atomic_inc_return(&data->disabled) == 1))
38697053 1115 ftrace_trace_special(tr, data, arg1, arg2, arg3, pc);
4902f884 1116
5aa1ba6a
SR
1117 atomic_dec(&data->disabled);
1118 local_irq_restore(flags);
4902f884
SR
1119}
1120
606576ce 1121#ifdef CONFIG_FUNCTION_TRACER
e309b41d 1122static void
b2a866f9 1123function_trace_call_preempt_only(unsigned long ip, unsigned long parent_ip)
2e0f5761
IM
1124{
1125 struct trace_array *tr = &global_trace;
1126 struct trace_array_cpu *data;
1127 unsigned long flags;
1128 long disabled;
38697053
SR
1129 int cpu, resched;
1130 int pc;
2e0f5761 1131
60bc0800 1132 if (unlikely(!ftrace_function_enabled))
2e0f5761
IM
1133 return;
1134
38697053 1135 pc = preempt_count();
182e9f5f 1136 resched = ftrace_preempt_disable();
38697053 1137 local_save_flags(flags);
2e0f5761
IM
1138 cpu = raw_smp_processor_id();
1139 data = tr->data[cpu];
1140 disabled = atomic_inc_return(&data->disabled);
1141
1142 if (likely(disabled == 1))
38697053 1143 trace_function(tr, data, ip, parent_ip, flags, pc);
2e0f5761
IM
1144
1145 atomic_dec(&data->disabled);
182e9f5f 1146 ftrace_preempt_enable(resched);
2e0f5761
IM
1147}
1148
b2a866f9
SR
1149static void
1150function_trace_call(unsigned long ip, unsigned long parent_ip)
1151{
1152 struct trace_array *tr = &global_trace;
1153 struct trace_array_cpu *data;
1154 unsigned long flags;
1155 long disabled;
1156 int cpu;
1157 int pc;
1158
1159 if (unlikely(!ftrace_function_enabled))
1160 return;
1161
1162 /*
1163 * Need to use raw, since this must be called before the
1164 * recursive protection is performed.
1165 */
d51ad7ac 1166 local_irq_save(flags);
b2a866f9
SR
1167 cpu = raw_smp_processor_id();
1168 data = tr->data[cpu];
1169 disabled = atomic_inc_return(&data->disabled);
1170
1171 if (likely(disabled == 1)) {
1172 pc = preempt_count();
1173 trace_function(tr, data, ip, parent_ip, flags, pc);
1174 }
1175
1176 atomic_dec(&data->disabled);
d51ad7ac 1177 local_irq_restore(flags);
b2a866f9
SR
1178}
1179
15e6cb36
FW
1180#ifdef CONFIG_FUNCTION_RET_TRACER
1181void trace_function_return(struct ftrace_retfunc *trace)
1182{
1183 struct trace_array *tr = &global_trace;
1184 struct trace_array_cpu *data;
1185 unsigned long flags;
1186 long disabled;
1187 int cpu;
1188 int pc;
1189
1190 raw_local_irq_save(flags);
1191 cpu = raw_smp_processor_id();
1192 data = tr->data[cpu];
1193 disabled = atomic_inc_return(&data->disabled);
1194 if (likely(disabled == 1)) {
1195 pc = preempt_count();
1196 __trace_function_return(tr, data, trace, flags, pc);
1197 }
1198 atomic_dec(&data->disabled);
1199 raw_local_irq_restore(flags);
1200}
1201#endif /* CONFIG_FUNCTION_RET_TRACER */
1202
2e0f5761
IM
1203static struct ftrace_ops trace_ops __read_mostly =
1204{
1205 .func = function_trace_call,
1206};
1207
e309b41d 1208void tracing_start_function_trace(void)
2e0f5761 1209{
60bc0800 1210 ftrace_function_enabled = 0;
b2a866f9
SR
1211
1212 if (trace_flags & TRACE_ITER_PREEMPTONLY)
1213 trace_ops.func = function_trace_call_preempt_only;
1214 else
1215 trace_ops.func = function_trace_call;
1216
2e0f5761 1217 register_ftrace_function(&trace_ops);
9036990d 1218 ftrace_function_enabled = 1;
2e0f5761
IM
1219}
1220
e309b41d 1221void tracing_stop_function_trace(void)
2e0f5761 1222{
60bc0800 1223 ftrace_function_enabled = 0;
2e0f5761
IM
1224 unregister_ftrace_function(&trace_ops);
1225}
1226#endif
1227
bc0c38d1
SR
1228enum trace_file_type {
1229 TRACE_FILE_LAT_FMT = 1,
12ef7d44 1230 TRACE_FILE_ANNOTATE = 2,
bc0c38d1
SR
1231};
1232
5a90f577
SR
1233static void trace_iterator_increment(struct trace_iterator *iter, int cpu)
1234{
d769041f
SR
1235 /* Don't allow ftrace to trace into the ring buffers */
1236 ftrace_disable_cpu();
1237
5a90f577 1238 iter->idx++;
d769041f
SR
1239 if (iter->buffer_iter[iter->cpu])
1240 ring_buffer_read(iter->buffer_iter[iter->cpu], NULL);
1241
1242 ftrace_enable_cpu();
5a90f577
SR
1243}
1244
e309b41d 1245static struct trace_entry *
3928a8a2 1246peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts)
dd0e545f 1247{
3928a8a2
SR
1248 struct ring_buffer_event *event;
1249 struct ring_buffer_iter *buf_iter = iter->buffer_iter[cpu];
dd0e545f 1250
d769041f
SR
1251 /* Don't allow ftrace to trace into the ring buffers */
1252 ftrace_disable_cpu();
1253
1254 if (buf_iter)
1255 event = ring_buffer_iter_peek(buf_iter, ts);
1256 else
1257 event = ring_buffer_peek(iter->tr->buffer, cpu, ts);
1258
1259 ftrace_enable_cpu();
1260
3928a8a2 1261 return event ? ring_buffer_event_data(event) : NULL;
dd0e545f 1262}
d769041f 1263
dd0e545f 1264static struct trace_entry *
3928a8a2 1265__find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts)
bc0c38d1 1266{
3928a8a2 1267 struct ring_buffer *buffer = iter->tr->buffer;
bc0c38d1 1268 struct trace_entry *ent, *next = NULL;
3928a8a2 1269 u64 next_ts = 0, ts;
bc0c38d1
SR
1270 int next_cpu = -1;
1271 int cpu;
1272
ab46428c 1273 for_each_tracing_cpu(cpu) {
dd0e545f 1274
3928a8a2
SR
1275 if (ring_buffer_empty_cpu(buffer, cpu))
1276 continue;
dd0e545f 1277
3928a8a2 1278 ent = peek_next_entry(iter, cpu, &ts);
dd0e545f 1279
cdd31cd2
IM
1280 /*
1281 * Pick the entry with the smallest timestamp:
1282 */
3928a8a2 1283 if (ent && (!next || ts < next_ts)) {
bc0c38d1
SR
1284 next = ent;
1285 next_cpu = cpu;
3928a8a2 1286 next_ts = ts;
bc0c38d1
SR
1287 }
1288 }
1289
1290 if (ent_cpu)
1291 *ent_cpu = next_cpu;
1292
3928a8a2
SR
1293 if (ent_ts)
1294 *ent_ts = next_ts;
1295
bc0c38d1
SR
1296 return next;
1297}
1298
dd0e545f
SR
1299/* Find the next real entry, without updating the iterator itself */
1300static struct trace_entry *
3928a8a2 1301find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts)
bc0c38d1 1302{
3928a8a2 1303 return __find_next_entry(iter, ent_cpu, ent_ts);
dd0e545f
SR
1304}
1305
1306/* Find the next real entry, and increment the iterator to the next entry */
1307static void *find_next_entry_inc(struct trace_iterator *iter)
1308{
3928a8a2 1309 iter->ent = __find_next_entry(iter, &iter->cpu, &iter->ts);
dd0e545f 1310
3928a8a2 1311 if (iter->ent)
dd0e545f
SR
1312 trace_iterator_increment(iter, iter->cpu);
1313
3928a8a2 1314 return iter->ent ? iter : NULL;
b3806b43 1315}
bc0c38d1 1316
e309b41d 1317static void trace_consume(struct trace_iterator *iter)
b3806b43 1318{
d769041f
SR
1319 /* Don't allow ftrace to trace into the ring buffers */
1320 ftrace_disable_cpu();
3928a8a2 1321 ring_buffer_consume(iter->tr->buffer, iter->cpu, &iter->ts);
d769041f 1322 ftrace_enable_cpu();
bc0c38d1
SR
1323}
1324
e309b41d 1325static void *s_next(struct seq_file *m, void *v, loff_t *pos)
bc0c38d1
SR
1326{
1327 struct trace_iterator *iter = m->private;
bc0c38d1 1328 int i = (int)*pos;
4e3c3333 1329 void *ent;
bc0c38d1
SR
1330
1331 (*pos)++;
1332
1333 /* can't go backwards */
1334 if (iter->idx > i)
1335 return NULL;
1336
1337 if (iter->idx < 0)
1338 ent = find_next_entry_inc(iter);
1339 else
1340 ent = iter;
1341
1342 while (ent && iter->idx < i)
1343 ent = find_next_entry_inc(iter);
1344
1345 iter->pos = *pos;
1346
bc0c38d1
SR
1347 return ent;
1348}
1349
1350static void *s_start(struct seq_file *m, loff_t *pos)
1351{
1352 struct trace_iterator *iter = m->private;
1353 void *p = NULL;
1354 loff_t l = 0;
3928a8a2 1355 int cpu;
bc0c38d1
SR
1356
1357 mutex_lock(&trace_types_lock);
1358
d15f57f2
SR
1359 if (!current_trace || current_trace != iter->trace) {
1360 mutex_unlock(&trace_types_lock);
bc0c38d1 1361 return NULL;
d15f57f2 1362 }
bc0c38d1
SR
1363
1364 atomic_inc(&trace_record_cmdline_disabled);
1365
bc0c38d1
SR
1366 if (*pos != iter->pos) {
1367 iter->ent = NULL;
1368 iter->cpu = 0;
1369 iter->idx = -1;
1370
d769041f
SR
1371 ftrace_disable_cpu();
1372
3928a8a2
SR
1373 for_each_tracing_cpu(cpu) {
1374 ring_buffer_iter_reset(iter->buffer_iter[cpu]);
4c11d7ae 1375 }
bc0c38d1 1376
d769041f
SR
1377 ftrace_enable_cpu();
1378
bc0c38d1
SR
1379 for (p = iter; p && l < *pos; p = s_next(m, p, &l))
1380 ;
1381
1382 } else {
4c11d7ae 1383 l = *pos - 1;
bc0c38d1
SR
1384 p = s_next(m, p, &l);
1385 }
1386
1387 return p;
1388}
1389
1390static void s_stop(struct seq_file *m, void *p)
1391{
bc0c38d1 1392 atomic_dec(&trace_record_cmdline_disabled);
bc0c38d1
SR
1393 mutex_unlock(&trace_types_lock);
1394}
1395
76094a2c 1396#ifdef CONFIG_KRETPROBES
b3aa5577 1397static inline const char *kretprobed(const char *name)
76094a2c 1398{
b3aa5577
SR
1399 static const char tramp_name[] = "kretprobe_trampoline";
1400 int size = sizeof(tramp_name);
1401
1402 if (strncmp(tramp_name, name, size) == 0)
1403 return "[unknown/kretprobe'd]";
1404 return name;
76094a2c
AS
1405}
1406#else
b3aa5577 1407static inline const char *kretprobed(const char *name)
76094a2c 1408{
b3aa5577 1409 return name;
76094a2c
AS
1410}
1411#endif /* CONFIG_KRETPROBES */
1412
b3806b43 1413static int
214023c3 1414seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
bc0c38d1
SR
1415{
1416#ifdef CONFIG_KALLSYMS
1417 char str[KSYM_SYMBOL_LEN];
b3aa5577 1418 const char *name;
bc0c38d1
SR
1419
1420 kallsyms_lookup(address, NULL, NULL, NULL, str);
1421
b3aa5577
SR
1422 name = kretprobed(str);
1423
1424 return trace_seq_printf(s, fmt, name);
bc0c38d1 1425#endif
b3806b43 1426 return 1;
bc0c38d1
SR
1427}
1428
b3806b43 1429static int
214023c3
SR
1430seq_print_sym_offset(struct trace_seq *s, const char *fmt,
1431 unsigned long address)
bc0c38d1
SR
1432{
1433#ifdef CONFIG_KALLSYMS
1434 char str[KSYM_SYMBOL_LEN];
b3aa5577 1435 const char *name;
bc0c38d1
SR
1436
1437 sprint_symbol(str, address);
b3aa5577
SR
1438 name = kretprobed(str);
1439
1440 return trace_seq_printf(s, fmt, name);
bc0c38d1 1441#endif
b3806b43 1442 return 1;
bc0c38d1
SR
1443}
1444
1445#ifndef CONFIG_64BIT
1446# define IP_FMT "%08lx"
1447#else
1448# define IP_FMT "%016lx"
1449#endif
1450
15e6cb36 1451int
214023c3 1452seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
bc0c38d1 1453{
b3806b43
SR
1454 int ret;
1455
1456 if (!ip)
1457 return trace_seq_printf(s, "0");
bc0c38d1
SR
1458
1459 if (sym_flags & TRACE_ITER_SYM_OFFSET)
b3806b43 1460 ret = seq_print_sym_offset(s, "%s", ip);
bc0c38d1 1461 else
b3806b43
SR
1462 ret = seq_print_sym_short(s, "%s", ip);
1463
1464 if (!ret)
1465 return 0;
bc0c38d1
SR
1466
1467 if (sym_flags & TRACE_ITER_SYM_ADDR)
b3806b43
SR
1468 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
1469 return ret;
bc0c38d1
SR
1470}
1471
b54d3de9
TE
1472static inline int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
1473 unsigned long ip, unsigned long sym_flags)
1474{
1475 struct file *file = NULL;
1476 unsigned long vmstart = 0;
1477 int ret = 1;
1478
1479 if (mm) {
cffa10ae
TE
1480 const struct vm_area_struct *vma;
1481
1482 down_read(&mm->mmap_sem);
1483 vma = find_vma(mm, ip);
b54d3de9
TE
1484 if (vma) {
1485 file = vma->vm_file;
1486 vmstart = vma->vm_start;
1487 }
e38da592
TE
1488 if (file) {
1489 ret = trace_seq_path(s, &file->f_path);
1490 if (ret)
1491 ret = trace_seq_printf(s, "[+0x%lx]", ip - vmstart);
1492 }
cffa10ae 1493 up_read(&mm->mmap_sem);
b54d3de9 1494 }
b54d3de9
TE
1495 if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
1496 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
1497 return ret;
1498}
1499
02b67518
TE
1500static int
1501seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s,
b54d3de9 1502 unsigned long sym_flags)
02b67518 1503{
b54d3de9 1504 struct mm_struct *mm = NULL;
02b67518 1505 int ret = 1;
8d7c6a96 1506 unsigned int i;
02b67518 1507
b54d3de9
TE
1508 if (trace_flags & TRACE_ITER_SYM_USEROBJ) {
1509 struct task_struct *task;
1510 /*
1511 * we do the lookup on the thread group leader,
1512 * since individual threads might have already quit!
1513 */
1514 rcu_read_lock();
1515 task = find_task_by_vpid(entry->ent.tgid);
b54d3de9
TE
1516 if (task)
1517 mm = get_task_mm(task);
cffa10ae 1518 rcu_read_unlock();
b54d3de9
TE
1519 }
1520
02b67518
TE
1521 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
1522 unsigned long ip = entry->caller[i];
1523
1524 if (ip == ULONG_MAX || !ret)
1525 break;
b54d3de9 1526 if (i && ret)
02b67518
TE
1527 ret = trace_seq_puts(s, " <- ");
1528 if (!ip) {
b54d3de9
TE
1529 if (ret)
1530 ret = trace_seq_puts(s, "??");
02b67518
TE
1531 continue;
1532 }
b54d3de9
TE
1533 if (!ret)
1534 break;
1535 if (ret)
1536 ret = seq_print_user_ip(s, mm, ip, sym_flags);
02b67518
TE
1537 }
1538
b54d3de9
TE
1539 if (mm)
1540 mmput(mm);
02b67518
TE
1541 return ret;
1542}
1543
e309b41d 1544static void print_lat_help_header(struct seq_file *m)
bc0c38d1 1545{
a6168353
ME
1546 seq_puts(m, "# _------=> CPU# \n");
1547 seq_puts(m, "# / _-----=> irqs-off \n");
1548 seq_puts(m, "# | / _----=> need-resched \n");
1549 seq_puts(m, "# || / _---=> hardirq/softirq \n");
1550 seq_puts(m, "# ||| / _--=> preempt-depth \n");
1551 seq_puts(m, "# |||| / \n");
1552 seq_puts(m, "# ||||| delay \n");
1553 seq_puts(m, "# cmd pid ||||| time | caller \n");
1554 seq_puts(m, "# \\ / ||||| \\ | / \n");
bc0c38d1
SR
1555}
1556
e309b41d 1557static void print_func_help_header(struct seq_file *m)
bc0c38d1 1558{
a6168353
ME
1559 seq_puts(m, "# TASK-PID CPU# TIMESTAMP FUNCTION\n");
1560 seq_puts(m, "# | | | | |\n");
bc0c38d1
SR
1561}
1562
1563
e309b41d 1564static void
bc0c38d1
SR
1565print_trace_header(struct seq_file *m, struct trace_iterator *iter)
1566{
1567 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
1568 struct trace_array *tr = iter->tr;
1569 struct trace_array_cpu *data = tr->data[tr->cpu];
1570 struct tracer *type = current_trace;
3928a8a2
SR
1571 unsigned long total;
1572 unsigned long entries;
bc0c38d1
SR
1573 const char *name = "preemption";
1574
1575 if (type)
1576 name = type->name;
1577
3928a8a2
SR
1578 entries = ring_buffer_entries(iter->tr->buffer);
1579 total = entries +
1580 ring_buffer_overruns(iter->tr->buffer);
bc0c38d1
SR
1581
1582 seq_printf(m, "%s latency trace v1.1.5 on %s\n",
1583 name, UTS_RELEASE);
1584 seq_puts(m, "-----------------------------------"
1585 "---------------------------------\n");
1586 seq_printf(m, " latency: %lu us, #%lu/%lu, CPU#%d |"
1587 " (M:%s VP:%d, KP:%d, SP:%d HP:%d",
57f50be1 1588 nsecs_to_usecs(data->saved_latency),
bc0c38d1 1589 entries,
4c11d7ae 1590 total,
bc0c38d1
SR
1591 tr->cpu,
1592#if defined(CONFIG_PREEMPT_NONE)
1593 "server",
1594#elif defined(CONFIG_PREEMPT_VOLUNTARY)
1595 "desktop",
b5c21b45 1596#elif defined(CONFIG_PREEMPT)
bc0c38d1
SR
1597 "preempt",
1598#else
1599 "unknown",
1600#endif
1601 /* These are reserved for later use */
1602 0, 0, 0, 0);
1603#ifdef CONFIG_SMP
1604 seq_printf(m, " #P:%d)\n", num_online_cpus());
1605#else
1606 seq_puts(m, ")\n");
1607#endif
1608 seq_puts(m, " -----------------\n");
1609 seq_printf(m, " | task: %.16s-%d "
1610 "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n",
1611 data->comm, data->pid, data->uid, data->nice,
1612 data->policy, data->rt_priority);
1613 seq_puts(m, " -----------------\n");
1614
1615 if (data->critical_start) {
1616 seq_puts(m, " => started at: ");
214023c3
SR
1617 seq_print_ip_sym(&iter->seq, data->critical_start, sym_flags);
1618 trace_print_seq(m, &iter->seq);
bc0c38d1 1619 seq_puts(m, "\n => ended at: ");
214023c3
SR
1620 seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags);
1621 trace_print_seq(m, &iter->seq);
bc0c38d1
SR
1622 seq_puts(m, "\n");
1623 }
1624
1625 seq_puts(m, "\n");
1626}
1627
e309b41d 1628static void
214023c3 1629lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
bc0c38d1
SR
1630{
1631 int hardirq, softirq;
1632 char *comm;
1633
777e208d 1634 comm = trace_find_cmdline(entry->pid);
bc0c38d1 1635
777e208d 1636 trace_seq_printf(s, "%8.8s-%-5d ", comm, entry->pid);
a6168353 1637 trace_seq_printf(s, "%3d", cpu);
214023c3 1638 trace_seq_printf(s, "%c%c",
9244489a
SR
1639 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
1640 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' : '.',
777e208d 1641 ((entry->flags & TRACE_FLAG_NEED_RESCHED) ? 'N' : '.'));
bc0c38d1 1642
777e208d
SR
1643 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
1644 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
afc2abc0 1645 if (hardirq && softirq) {
214023c3 1646 trace_seq_putc(s, 'H');
afc2abc0
IM
1647 } else {
1648 if (hardirq) {
214023c3 1649 trace_seq_putc(s, 'h');
afc2abc0 1650 } else {
bc0c38d1 1651 if (softirq)
214023c3 1652 trace_seq_putc(s, 's');
bc0c38d1 1653 else
214023c3 1654 trace_seq_putc(s, '.');
bc0c38d1
SR
1655 }
1656 }
1657
777e208d
SR
1658 if (entry->preempt_count)
1659 trace_seq_printf(s, "%x", entry->preempt_count);
bc0c38d1 1660 else
214023c3 1661 trace_seq_puts(s, ".");
bc0c38d1
SR
1662}
1663
1664unsigned long preempt_mark_thresh = 100;
1665
e309b41d 1666static void
3928a8a2 1667lat_print_timestamp(struct trace_seq *s, u64 abs_usecs,
bc0c38d1
SR
1668 unsigned long rel_usecs)
1669{
214023c3 1670 trace_seq_printf(s, " %4lldus", abs_usecs);
bc0c38d1 1671 if (rel_usecs > preempt_mark_thresh)
214023c3 1672 trace_seq_puts(s, "!: ");
bc0c38d1 1673 else if (rel_usecs > 1)
214023c3 1674 trace_seq_puts(s, "+: ");
bc0c38d1 1675 else
214023c3 1676 trace_seq_puts(s, " : ");
bc0c38d1
SR
1677}
1678
1679static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
1680
fc5e27ae
PP
1681/*
1682 * The message is supposed to contain an ending newline.
1683 * If the printing stops prematurely, try to add a newline of our own.
1684 */
1685void trace_seq_print_cont(struct trace_seq *s, struct trace_iterator *iter)
dd0e545f 1686{
dd0e545f 1687 struct trace_entry *ent;
777e208d 1688 struct trace_field_cont *cont;
fc5e27ae 1689 bool ok = true;
dd0e545f 1690
3928a8a2 1691 ent = peek_next_entry(iter, iter->cpu, NULL);
dd0e545f
SR
1692 if (!ent || ent->type != TRACE_CONT) {
1693 trace_seq_putc(s, '\n');
1694 return;
1695 }
1696
1697 do {
777e208d 1698 cont = (struct trace_field_cont *)ent;
fc5e27ae 1699 if (ok)
777e208d 1700 ok = (trace_seq_printf(s, "%s", cont->buf) > 0);
d769041f
SR
1701
1702 ftrace_disable_cpu();
1703
1704 if (iter->buffer_iter[iter->cpu])
1705 ring_buffer_read(iter->buffer_iter[iter->cpu], NULL);
1706 else
1707 ring_buffer_consume(iter->tr->buffer, iter->cpu, NULL);
1708
1709 ftrace_enable_cpu();
1710
3928a8a2 1711 ent = peek_next_entry(iter, iter->cpu, NULL);
dd0e545f 1712 } while (ent && ent->type == TRACE_CONT);
fc5e27ae
PP
1713
1714 if (!ok)
1715 trace_seq_putc(s, '\n');
dd0e545f
SR
1716}
1717
a309720c
SR
1718static void test_cpu_buff_start(struct trace_iterator *iter)
1719{
1720 struct trace_seq *s = &iter->seq;
1721
12ef7d44
SR
1722 if (!(trace_flags & TRACE_ITER_ANNOTATE))
1723 return;
1724
1725 if (!(iter->iter_flags & TRACE_FILE_ANNOTATE))
1726 return;
1727
a309720c
SR
1728 if (cpu_isset(iter->cpu, iter->started))
1729 return;
1730
1731 cpu_set(iter->cpu, iter->started);
1732 trace_seq_printf(s, "##### CPU %u buffer started ####\n", iter->cpu);
1733}
1734
2c4f035f 1735static enum print_line_t
214023c3 1736print_lat_fmt(struct trace_iterator *iter, unsigned int trace_idx, int cpu)
bc0c38d1 1737{
214023c3 1738 struct trace_seq *s = &iter->seq;
bc0c38d1 1739 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
3928a8a2 1740 struct trace_entry *next_entry;
bc0c38d1
SR
1741 unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
1742 struct trace_entry *entry = iter->ent;
1743 unsigned long abs_usecs;
1744 unsigned long rel_usecs;
3928a8a2 1745 u64 next_ts;
bc0c38d1 1746 char *comm;
bac524d3 1747 int S, T;
86387f7e 1748 int i;
d17d9691 1749 unsigned state;
bc0c38d1 1750
dd0e545f 1751 if (entry->type == TRACE_CONT)
2c4f035f 1752 return TRACE_TYPE_HANDLED;
dd0e545f 1753
a309720c
SR
1754 test_cpu_buff_start(iter);
1755
3928a8a2
SR
1756 next_entry = find_next_entry(iter, NULL, &next_ts);
1757 if (!next_entry)
1758 next_ts = iter->ts;
1759 rel_usecs = ns2usecs(next_ts - iter->ts);
1760 abs_usecs = ns2usecs(iter->ts - iter->tr->time_start);
bc0c38d1
SR
1761
1762 if (verbose) {
777e208d 1763 comm = trace_find_cmdline(entry->pid);
a6168353 1764 trace_seq_printf(s, "%16s %5d %3d %d %08x %08x [%08lx]"
214023c3
SR
1765 " %ld.%03ldms (+%ld.%03ldms): ",
1766 comm,
777e208d
SR
1767 entry->pid, cpu, entry->flags,
1768 entry->preempt_count, trace_idx,
3928a8a2 1769 ns2usecs(iter->ts),
214023c3
SR
1770 abs_usecs/1000,
1771 abs_usecs % 1000, rel_usecs/1000,
1772 rel_usecs % 1000);
bc0c38d1 1773 } else {
f29c73fe
IM
1774 lat_print_generic(s, entry, cpu);
1775 lat_print_timestamp(s, abs_usecs, rel_usecs);
bc0c38d1
SR
1776 }
1777 switch (entry->type) {
777e208d 1778 case TRACE_FN: {
7104f300
SR
1779 struct ftrace_entry *field;
1780
1781 trace_assign_type(field, entry);
777e208d
SR
1782
1783 seq_print_ip_sym(s, field->ip, sym_flags);
214023c3 1784 trace_seq_puts(s, " (");
b3aa5577 1785 seq_print_ip_sym(s, field->parent_ip, sym_flags);
214023c3 1786 trace_seq_puts(s, ")\n");
bc0c38d1 1787 break;
777e208d 1788 }
bc0c38d1 1789 case TRACE_CTX:
777e208d 1790 case TRACE_WAKE: {
7104f300
SR
1791 struct ctx_switch_entry *field;
1792
1793 trace_assign_type(field, entry);
777e208d
SR
1794
1795 T = field->next_state < sizeof(state_to_char) ?
1796 state_to_char[field->next_state] : 'X';
bac524d3 1797
777e208d
SR
1798 state = field->prev_state ?
1799 __ffs(field->prev_state) + 1 : 0;
d17d9691 1800 S = state < sizeof(state_to_char) - 1 ? state_to_char[state] : 'X';
777e208d 1801 comm = trace_find_cmdline(field->next_pid);
80b5e940 1802 trace_seq_printf(s, " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
777e208d
SR
1803 field->prev_pid,
1804 field->prev_prio,
57422797 1805 S, entry->type == TRACE_CTX ? "==>" : " +",
777e208d
SR
1806 field->next_cpu,
1807 field->next_pid,
1808 field->next_prio,
bac524d3 1809 T, comm);
bc0c38d1 1810 break;
777e208d
SR
1811 }
1812 case TRACE_SPECIAL: {
7104f300
SR
1813 struct special_entry *field;
1814
1815 trace_assign_type(field, entry);
777e208d 1816
88a4216c 1817 trace_seq_printf(s, "# %ld %ld %ld\n",
777e208d
SR
1818 field->arg1,
1819 field->arg2,
1820 field->arg3);
f0a920d5 1821 break;
777e208d
SR
1822 }
1823 case TRACE_STACK: {
7104f300
SR
1824 struct stack_entry *field;
1825
1826 trace_assign_type(field, entry);
777e208d 1827
86387f7e
IM
1828 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
1829 if (i)
1830 trace_seq_puts(s, " <= ");
777e208d 1831 seq_print_ip_sym(s, field->caller[i], sym_flags);
86387f7e
IM
1832 }
1833 trace_seq_puts(s, "\n");
1834 break;
777e208d
SR
1835 }
1836 case TRACE_PRINT: {
7104f300
SR
1837 struct print_entry *field;
1838
1839 trace_assign_type(field, entry);
777e208d
SR
1840
1841 seq_print_ip_sym(s, field->ip, sym_flags);
1842 trace_seq_printf(s, ": %s", field->buf);
1843 if (entry->flags & TRACE_FLAG_CONT)
dd0e545f
SR
1844 trace_seq_print_cont(s, iter);
1845 break;
777e208d 1846 }
9f029e83
SR
1847 case TRACE_BRANCH: {
1848 struct trace_branch *field;
52f232cb
SR
1849
1850 trace_assign_type(field, entry);
1851
1852 trace_seq_printf(s, "[%s] %s:%s:%d\n",
68d119f0 1853 field->correct ? " ok " : " MISS ",
52f232cb
SR
1854 field->func,
1855 field->file,
1856 field->line);
1857 break;
1858 }
02b67518
TE
1859 case TRACE_USER_STACK: {
1860 struct userstack_entry *field;
1861
1862 trace_assign_type(field, entry);
1863
1864 seq_print_userip_objs(field, s, sym_flags);
b54d3de9 1865 trace_seq_putc(s, '\n');
02b67518
TE
1866 break;
1867 }
89b2f978 1868 default:
214023c3 1869 trace_seq_printf(s, "Unknown type %d\n", entry->type);
bc0c38d1 1870 }
2c4f035f 1871 return TRACE_TYPE_HANDLED;
bc0c38d1
SR
1872}
1873
2c4f035f 1874static enum print_line_t print_trace_fmt(struct trace_iterator *iter)
bc0c38d1 1875{
214023c3 1876 struct trace_seq *s = &iter->seq;
bc0c38d1 1877 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
4e3c3333 1878 struct trace_entry *entry;
bc0c38d1
SR
1879 unsigned long usec_rem;
1880 unsigned long long t;
1881 unsigned long secs;
1882 char *comm;
b3806b43 1883 int ret;
bac524d3 1884 int S, T;
86387f7e 1885 int i;
bc0c38d1 1886
4e3c3333 1887 entry = iter->ent;
dd0e545f
SR
1888
1889 if (entry->type == TRACE_CONT)
2c4f035f 1890 return TRACE_TYPE_HANDLED;
dd0e545f 1891
a309720c
SR
1892 test_cpu_buff_start(iter);
1893
777e208d 1894 comm = trace_find_cmdline(iter->ent->pid);
bc0c38d1 1895
3928a8a2 1896 t = ns2usecs(iter->ts);
bc0c38d1
SR
1897 usec_rem = do_div(t, 1000000ULL);
1898 secs = (unsigned long)t;
1899
777e208d 1900 ret = trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid);
f29c73fe 1901 if (!ret)
2c4f035f 1902 return TRACE_TYPE_PARTIAL_LINE;
a6168353 1903 ret = trace_seq_printf(s, "[%03d] ", iter->cpu);
f29c73fe 1904 if (!ret)
2c4f035f 1905 return TRACE_TYPE_PARTIAL_LINE;
f29c73fe
IM
1906 ret = trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem);
1907 if (!ret)
2c4f035f 1908 return TRACE_TYPE_PARTIAL_LINE;
bc0c38d1
SR
1909
1910 switch (entry->type) {
777e208d 1911 case TRACE_FN: {
7104f300
SR
1912 struct ftrace_entry *field;
1913
1914 trace_assign_type(field, entry);
777e208d
SR
1915
1916 ret = seq_print_ip_sym(s, field->ip, sym_flags);
b3806b43 1917 if (!ret)
2c4f035f 1918 return TRACE_TYPE_PARTIAL_LINE;
bc0c38d1 1919 if ((sym_flags & TRACE_ITER_PRINT_PARENT) &&
777e208d 1920 field->parent_ip) {
b3806b43
SR
1921 ret = trace_seq_printf(s, " <-");
1922 if (!ret)
2c4f035f 1923 return TRACE_TYPE_PARTIAL_LINE;
b3aa5577
SR
1924 ret = seq_print_ip_sym(s,
1925 field->parent_ip,
1926 sym_flags);
b3806b43 1927 if (!ret)
2c4f035f 1928 return TRACE_TYPE_PARTIAL_LINE;
bc0c38d1 1929 }
b3806b43
SR
1930 ret = trace_seq_printf(s, "\n");
1931 if (!ret)
2c4f035f 1932 return TRACE_TYPE_PARTIAL_LINE;
bc0c38d1 1933 break;
777e208d 1934 }
bc0c38d1 1935 case TRACE_CTX:
777e208d 1936 case TRACE_WAKE: {
7104f300
SR
1937 struct ctx_switch_entry *field;
1938
1939 trace_assign_type(field, entry);
777e208d
SR
1940
1941 S = field->prev_state < sizeof(state_to_char) ?
1942 state_to_char[field->prev_state] : 'X';
1943 T = field->next_state < sizeof(state_to_char) ?
1944 state_to_char[field->next_state] : 'X';
80b5e940 1945 ret = trace_seq_printf(s, " %5d:%3d:%c %s [%03d] %5d:%3d:%c\n",
777e208d
SR
1946 field->prev_pid,
1947 field->prev_prio,
b3806b43 1948 S,
57422797 1949 entry->type == TRACE_CTX ? "==>" : " +",
777e208d
SR
1950 field->next_cpu,
1951 field->next_pid,
1952 field->next_prio,
bac524d3 1953 T);
b3806b43 1954 if (!ret)
2c4f035f 1955 return TRACE_TYPE_PARTIAL_LINE;
bc0c38d1 1956 break;
777e208d
SR
1957 }
1958 case TRACE_SPECIAL: {
7104f300
SR
1959 struct special_entry *field;
1960
1961 trace_assign_type(field, entry);
777e208d 1962
88a4216c 1963 ret = trace_seq_printf(s, "# %ld %ld %ld\n",
777e208d
SR
1964 field->arg1,
1965 field->arg2,
1966 field->arg3);
f0a920d5 1967 if (!ret)
2c4f035f 1968 return TRACE_TYPE_PARTIAL_LINE;
f0a920d5 1969 break;
777e208d
SR
1970 }
1971 case TRACE_STACK: {
7104f300
SR
1972 struct stack_entry *field;
1973
1974 trace_assign_type(field, entry);
777e208d 1975
86387f7e
IM
1976 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
1977 if (i) {
1978 ret = trace_seq_puts(s, " <= ");
1979 if (!ret)
2c4f035f 1980 return TRACE_TYPE_PARTIAL_LINE;
86387f7e 1981 }
777e208d 1982 ret = seq_print_ip_sym(s, field->caller[i],
86387f7e
IM
1983 sym_flags);
1984 if (!ret)
2c4f035f 1985 return TRACE_TYPE_PARTIAL_LINE;
86387f7e
IM
1986 }
1987 ret = trace_seq_puts(s, "\n");
1988 if (!ret)
2c4f035f 1989 return TRACE_TYPE_PARTIAL_LINE;
86387f7e 1990 break;
777e208d
SR
1991 }
1992 case TRACE_PRINT: {
7104f300
SR
1993 struct print_entry *field;
1994
1995 trace_assign_type(field, entry);
777e208d
SR
1996
1997 seq_print_ip_sym(s, field->ip, sym_flags);
1998 trace_seq_printf(s, ": %s", field->buf);
1999 if (entry->flags & TRACE_FLAG_CONT)
dd0e545f
SR
2000 trace_seq_print_cont(s, iter);
2001 break;
bc0c38d1 2002 }
15e6cb36
FW
2003 case TRACE_FN_RET: {
2004 return print_return_function(iter);
2005 break;
2006 }
9f029e83
SR
2007 case TRACE_BRANCH: {
2008 struct trace_branch *field;
52f232cb
SR
2009
2010 trace_assign_type(field, entry);
2011
2012 trace_seq_printf(s, "[%s] %s:%s:%d\n",
68d119f0 2013 field->correct ? " ok " : " MISS ",
52f232cb
SR
2014 field->func,
2015 field->file,
2016 field->line);
2017 break;
2018 }
02b67518
TE
2019 case TRACE_USER_STACK: {
2020 struct userstack_entry *field;
2021
2022 trace_assign_type(field, entry);
2023
2024 ret = seq_print_userip_objs(field, s, sym_flags);
2025 if (!ret)
2026 return TRACE_TYPE_PARTIAL_LINE;
2027 ret = trace_seq_putc(s, '\n');
2028 if (!ret)
2029 return TRACE_TYPE_PARTIAL_LINE;
2030 break;
2031 }
777e208d 2032 }
2c4f035f 2033 return TRACE_TYPE_HANDLED;
bc0c38d1
SR
2034}
2035
2c4f035f 2036static enum print_line_t print_raw_fmt(struct trace_iterator *iter)
f9896bf3
IM
2037{
2038 struct trace_seq *s = &iter->seq;
2039 struct trace_entry *entry;
2040 int ret;
bac524d3 2041 int S, T;
f9896bf3
IM
2042
2043 entry = iter->ent;
dd0e545f
SR
2044
2045 if (entry->type == TRACE_CONT)
2c4f035f 2046 return TRACE_TYPE_HANDLED;
dd0e545f 2047
f9896bf3 2048 ret = trace_seq_printf(s, "%d %d %llu ",
777e208d 2049 entry->pid, iter->cpu, iter->ts);
f9896bf3 2050 if (!ret)
2c4f035f 2051 return TRACE_TYPE_PARTIAL_LINE;
f9896bf3
IM
2052
2053 switch (entry->type) {
777e208d 2054 case TRACE_FN: {
7104f300
SR
2055 struct ftrace_entry *field;
2056
2057 trace_assign_type(field, entry);
777e208d 2058
f9896bf3 2059 ret = trace_seq_printf(s, "%x %x\n",
777e208d
SR
2060 field->ip,
2061 field->parent_ip);
f9896bf3 2062 if (!ret)
2c4f035f 2063 return TRACE_TYPE_PARTIAL_LINE;
f9896bf3 2064 break;
777e208d 2065 }
f9896bf3 2066 case TRACE_CTX:
777e208d 2067 case TRACE_WAKE: {
7104f300
SR
2068 struct ctx_switch_entry *field;
2069
2070 trace_assign_type(field, entry);
777e208d
SR
2071
2072 S = field->prev_state < sizeof(state_to_char) ?
2073 state_to_char[field->prev_state] : 'X';
2074 T = field->next_state < sizeof(state_to_char) ?
2075 state_to_char[field->next_state] : 'X';
57422797
IM
2076 if (entry->type == TRACE_WAKE)
2077 S = '+';
80b5e940 2078 ret = trace_seq_printf(s, "%d %d %c %d %d %d %c\n",
777e208d
SR
2079 field->prev_pid,
2080 field->prev_prio,
f9896bf3 2081 S,
777e208d
SR
2082 field->next_cpu,
2083 field->next_pid,
2084 field->next_prio,
bac524d3 2085 T);
f9896bf3 2086 if (!ret)
2c4f035f 2087 return TRACE_TYPE_PARTIAL_LINE;
f9896bf3 2088 break;
777e208d 2089 }
f0a920d5 2090 case TRACE_SPECIAL:
02b67518 2091 case TRACE_USER_STACK:
777e208d 2092 case TRACE_STACK: {
7104f300
SR
2093 struct special_entry *field;
2094
2095 trace_assign_type(field, entry);
777e208d 2096
88a4216c 2097 ret = trace_seq_printf(s, "# %ld %ld %ld\n",
777e208d
SR
2098 field->arg1,
2099 field->arg2,
2100 field->arg3);
f0a920d5 2101 if (!ret)
2c4f035f 2102 return TRACE_TYPE_PARTIAL_LINE;
f0a920d5 2103 break;
777e208d
SR
2104 }
2105 case TRACE_PRINT: {
7104f300
SR
2106 struct print_entry *field;
2107
2108 trace_assign_type(field, entry);
777e208d
SR
2109
2110 trace_seq_printf(s, "# %lx %s", field->ip, field->buf);
2111 if (entry->flags & TRACE_FLAG_CONT)
dd0e545f
SR
2112 trace_seq_print_cont(s, iter);
2113 break;
f9896bf3 2114 }
777e208d 2115 }
2c4f035f 2116 return TRACE_TYPE_HANDLED;
f9896bf3
IM
2117}
2118
cb0f12aa
IM
2119#define SEQ_PUT_FIELD_RET(s, x) \
2120do { \
2121 if (!trace_seq_putmem(s, &(x), sizeof(x))) \
2122 return 0; \
2123} while (0)
2124
5e3ca0ec
IM
2125#define SEQ_PUT_HEX_FIELD_RET(s, x) \
2126do { \
ad0a3b68 2127 BUILD_BUG_ON(sizeof(x) > MAX_MEMHEX_BYTES); \
5e3ca0ec
IM
2128 if (!trace_seq_putmem_hex(s, &(x), sizeof(x))) \
2129 return 0; \
2130} while (0)
2131
2c4f035f 2132static enum print_line_t print_hex_fmt(struct trace_iterator *iter)
5e3ca0ec
IM
2133{
2134 struct trace_seq *s = &iter->seq;
2135 unsigned char newline = '\n';
2136 struct trace_entry *entry;
bac524d3 2137 int S, T;
5e3ca0ec
IM
2138
2139 entry = iter->ent;
dd0e545f
SR
2140
2141 if (entry->type == TRACE_CONT)
2c4f035f 2142 return TRACE_TYPE_HANDLED;
dd0e545f 2143
777e208d 2144 SEQ_PUT_HEX_FIELD_RET(s, entry->pid);
5e3ca0ec 2145 SEQ_PUT_HEX_FIELD_RET(s, iter->cpu);
3928a8a2 2146 SEQ_PUT_HEX_FIELD_RET(s, iter->ts);
5e3ca0ec
IM
2147
2148 switch (entry->type) {
777e208d 2149 case TRACE_FN: {
7104f300
SR
2150 struct ftrace_entry *field;
2151
2152 trace_assign_type(field, entry);
777e208d
SR
2153
2154 SEQ_PUT_HEX_FIELD_RET(s, field->ip);
2155 SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip);
5e3ca0ec 2156 break;
777e208d 2157 }
5e3ca0ec 2158 case TRACE_CTX:
777e208d 2159 case TRACE_WAKE: {
7104f300
SR
2160 struct ctx_switch_entry *field;
2161
2162 trace_assign_type(field, entry);
777e208d
SR
2163
2164 S = field->prev_state < sizeof(state_to_char) ?
2165 state_to_char[field->prev_state] : 'X';
2166 T = field->next_state < sizeof(state_to_char) ?
2167 state_to_char[field->next_state] : 'X';
57422797
IM
2168 if (entry->type == TRACE_WAKE)
2169 S = '+';
777e208d
SR
2170 SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid);
2171 SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio);
5e3ca0ec 2172 SEQ_PUT_HEX_FIELD_RET(s, S);
777e208d
SR
2173 SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu);
2174 SEQ_PUT_HEX_FIELD_RET(s, field->next_pid);
2175 SEQ_PUT_HEX_FIELD_RET(s, field->next_prio);
bac524d3 2176 SEQ_PUT_HEX_FIELD_RET(s, T);
5e3ca0ec 2177 break;
777e208d 2178 }
5e3ca0ec 2179 case TRACE_SPECIAL:
02b67518 2180 case TRACE_USER_STACK:
777e208d 2181 case TRACE_STACK: {
7104f300
SR
2182 struct special_entry *field;
2183
2184 trace_assign_type(field, entry);
777e208d
SR
2185
2186 SEQ_PUT_HEX_FIELD_RET(s, field->arg1);
2187 SEQ_PUT_HEX_FIELD_RET(s, field->arg2);
2188 SEQ_PUT_HEX_FIELD_RET(s, field->arg3);
5e3ca0ec
IM
2189 break;
2190 }
777e208d 2191 }
5e3ca0ec
IM
2192 SEQ_PUT_FIELD_RET(s, newline);
2193
2c4f035f 2194 return TRACE_TYPE_HANDLED;
5e3ca0ec
IM
2195}
2196
2c4f035f 2197static enum print_line_t print_bin_fmt(struct trace_iterator *iter)
cb0f12aa
IM
2198{
2199 struct trace_seq *s = &iter->seq;
2200 struct trace_entry *entry;
2201
2202 entry = iter->ent;
dd0e545f
SR
2203
2204 if (entry->type == TRACE_CONT)
2c4f035f 2205 return TRACE_TYPE_HANDLED;
dd0e545f 2206
777e208d 2207 SEQ_PUT_FIELD_RET(s, entry->pid);
072ba498 2208 SEQ_PUT_FIELD_RET(s, entry->cpu);
3928a8a2 2209 SEQ_PUT_FIELD_RET(s, iter->ts);
cb0f12aa
IM
2210
2211 switch (entry->type) {
777e208d 2212 case TRACE_FN: {
7104f300
SR
2213 struct ftrace_entry *field;
2214
2215 trace_assign_type(field, entry);
777e208d
SR
2216
2217 SEQ_PUT_FIELD_RET(s, field->ip);
2218 SEQ_PUT_FIELD_RET(s, field->parent_ip);
cb0f12aa 2219 break;
777e208d
SR
2220 }
2221 case TRACE_CTX: {
7104f300
SR
2222 struct ctx_switch_entry *field;
2223
2224 trace_assign_type(field, entry);
777e208d
SR
2225
2226 SEQ_PUT_FIELD_RET(s, field->prev_pid);
2227 SEQ_PUT_FIELD_RET(s, field->prev_prio);
2228 SEQ_PUT_FIELD_RET(s, field->prev_state);
2229 SEQ_PUT_FIELD_RET(s, field->next_pid);
2230 SEQ_PUT_FIELD_RET(s, field->next_prio);
2231 SEQ_PUT_FIELD_RET(s, field->next_state);
cb0f12aa 2232 break;
777e208d 2233 }
f0a920d5 2234 case TRACE_SPECIAL:
02b67518 2235 case TRACE_USER_STACK:
777e208d 2236 case TRACE_STACK: {
7104f300
SR
2237 struct special_entry *field;
2238
2239 trace_assign_type(field, entry);
777e208d
SR
2240
2241 SEQ_PUT_FIELD_RET(s, field->arg1);
2242 SEQ_PUT_FIELD_RET(s, field->arg2);
2243 SEQ_PUT_FIELD_RET(s, field->arg3);
f0a920d5 2244 break;
cb0f12aa 2245 }
777e208d 2246 }
cb0f12aa
IM
2247 return 1;
2248}
2249
bc0c38d1
SR
2250static int trace_empty(struct trace_iterator *iter)
2251{
bc0c38d1
SR
2252 int cpu;
2253
ab46428c 2254 for_each_tracing_cpu(cpu) {
d769041f
SR
2255 if (iter->buffer_iter[cpu]) {
2256 if (!ring_buffer_iter_empty(iter->buffer_iter[cpu]))
2257 return 0;
2258 } else {
2259 if (!ring_buffer_empty_cpu(iter->tr->buffer, cpu))
2260 return 0;
2261 }
bc0c38d1 2262 }
d769041f 2263
797d3712 2264 return 1;
bc0c38d1
SR
2265}
2266
2c4f035f 2267static enum print_line_t print_trace_line(struct trace_iterator *iter)
f9896bf3 2268{
2c4f035f
FW
2269 enum print_line_t ret;
2270
2271 if (iter->trace && iter->trace->print_line) {
2272 ret = iter->trace->print_line(iter);
2273 if (ret != TRACE_TYPE_UNHANDLED)
2274 return ret;
2275 }
72829bc3 2276
cb0f12aa
IM
2277 if (trace_flags & TRACE_ITER_BIN)
2278 return print_bin_fmt(iter);
2279
5e3ca0ec
IM
2280 if (trace_flags & TRACE_ITER_HEX)
2281 return print_hex_fmt(iter);
2282
f9896bf3
IM
2283 if (trace_flags & TRACE_ITER_RAW)
2284 return print_raw_fmt(iter);
2285
2286 if (iter->iter_flags & TRACE_FILE_LAT_FMT)
2287 return print_lat_fmt(iter, iter->idx, iter->cpu);
2288
2289 return print_trace_fmt(iter);
2290}
2291
bc0c38d1
SR
2292static int s_show(struct seq_file *m, void *v)
2293{
2294 struct trace_iterator *iter = v;
2295
2296 if (iter->ent == NULL) {
2297 if (iter->tr) {
2298 seq_printf(m, "# tracer: %s\n", iter->trace->name);
2299 seq_puts(m, "#\n");
2300 }
2301 if (iter->iter_flags & TRACE_FILE_LAT_FMT) {
2302 /* print nothing if the buffers are empty */
2303 if (trace_empty(iter))
2304 return 0;
2305 print_trace_header(m, iter);
2306 if (!(trace_flags & TRACE_ITER_VERBOSE))
2307 print_lat_help_header(m);
2308 } else {
2309 if (!(trace_flags & TRACE_ITER_VERBOSE))
2310 print_func_help_header(m);
2311 }
2312 } else {
f9896bf3 2313 print_trace_line(iter);
214023c3 2314 trace_print_seq(m, &iter->seq);
bc0c38d1
SR
2315 }
2316
2317 return 0;
2318}
2319
2320static struct seq_operations tracer_seq_ops = {
4bf39a94
IM
2321 .start = s_start,
2322 .next = s_next,
2323 .stop = s_stop,
2324 .show = s_show,
bc0c38d1
SR
2325};
2326
e309b41d 2327static struct trace_iterator *
bc0c38d1
SR
2328__tracing_open(struct inode *inode, struct file *file, int *ret)
2329{
2330 struct trace_iterator *iter;
3928a8a2
SR
2331 struct seq_file *m;
2332 int cpu;
bc0c38d1 2333
60a11774
SR
2334 if (tracing_disabled) {
2335 *ret = -ENODEV;
2336 return NULL;
2337 }
2338
bc0c38d1
SR
2339 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
2340 if (!iter) {
2341 *ret = -ENOMEM;
2342 goto out;
2343 }
2344
2345 mutex_lock(&trace_types_lock);
2346 if (current_trace && current_trace->print_max)
2347 iter->tr = &max_tr;
2348 else
2349 iter->tr = inode->i_private;
2350 iter->trace = current_trace;
2351 iter->pos = -1;
2352
12ef7d44
SR
2353 /* Annotate start of buffers if we had overruns */
2354 if (ring_buffer_overruns(iter->tr->buffer))
2355 iter->iter_flags |= TRACE_FILE_ANNOTATE;
2356
2357
3928a8a2 2358 for_each_tracing_cpu(cpu) {
d769041f 2359
3928a8a2
SR
2360 iter->buffer_iter[cpu] =
2361 ring_buffer_read_start(iter->tr->buffer, cpu);
d769041f 2362
3928a8a2
SR
2363 if (!iter->buffer_iter[cpu])
2364 goto fail_buffer;
2365 }
2366
bc0c38d1
SR
2367 /* TODO stop tracer */
2368 *ret = seq_open(file, &tracer_seq_ops);
3928a8a2
SR
2369 if (*ret)
2370 goto fail_buffer;
bc0c38d1 2371
3928a8a2
SR
2372 m = file->private_data;
2373 m->private = iter;
bc0c38d1 2374
3928a8a2 2375 /* stop the trace while dumping */
9036990d 2376 tracing_stop();
3928a8a2
SR
2377
2378 if (iter->trace && iter->trace->open)
2379 iter->trace->open(iter);
2380
bc0c38d1
SR
2381 mutex_unlock(&trace_types_lock);
2382
2383 out:
2384 return iter;
3928a8a2
SR
2385
2386 fail_buffer:
2387 for_each_tracing_cpu(cpu) {
2388 if (iter->buffer_iter[cpu])
2389 ring_buffer_read_finish(iter->buffer_iter[cpu]);
2390 }
2391 mutex_unlock(&trace_types_lock);
0bb943c7 2392 kfree(iter);
3928a8a2
SR
2393
2394 return ERR_PTR(-ENOMEM);
bc0c38d1
SR
2395}
2396
2397int tracing_open_generic(struct inode *inode, struct file *filp)
2398{
60a11774
SR
2399 if (tracing_disabled)
2400 return -ENODEV;
2401
bc0c38d1
SR
2402 filp->private_data = inode->i_private;
2403 return 0;
2404}
2405
2406int tracing_release(struct inode *inode, struct file *file)
2407{
2408 struct seq_file *m = (struct seq_file *)file->private_data;
2409 struct trace_iterator *iter = m->private;
3928a8a2 2410 int cpu;
bc0c38d1
SR
2411
2412 mutex_lock(&trace_types_lock);
3928a8a2
SR
2413 for_each_tracing_cpu(cpu) {
2414 if (iter->buffer_iter[cpu])
2415 ring_buffer_read_finish(iter->buffer_iter[cpu]);
2416 }
2417
bc0c38d1
SR
2418 if (iter->trace && iter->trace->close)
2419 iter->trace->close(iter);
2420
2421 /* reenable tracing if it was previously enabled */
9036990d 2422 tracing_start();
bc0c38d1
SR
2423 mutex_unlock(&trace_types_lock);
2424
2425 seq_release(inode, file);
2426 kfree(iter);
2427 return 0;
2428}
2429
2430static int tracing_open(struct inode *inode, struct file *file)
2431{
2432 int ret;
2433
2434 __tracing_open(inode, file, &ret);
2435
2436 return ret;
2437}
2438
2439static int tracing_lt_open(struct inode *inode, struct file *file)
2440{
2441 struct trace_iterator *iter;
2442 int ret;
2443
2444 iter = __tracing_open(inode, file, &ret);
2445
2446 if (!ret)
2447 iter->iter_flags |= TRACE_FILE_LAT_FMT;
2448
2449 return ret;
2450}
2451
2452
e309b41d 2453static void *
bc0c38d1
SR
2454t_next(struct seq_file *m, void *v, loff_t *pos)
2455{
2456 struct tracer *t = m->private;
2457
2458 (*pos)++;
2459
2460 if (t)
2461 t = t->next;
2462
2463 m->private = t;
2464
2465 return t;
2466}
2467
2468static void *t_start(struct seq_file *m, loff_t *pos)
2469{
2470 struct tracer *t = m->private;
2471 loff_t l = 0;
2472
2473 mutex_lock(&trace_types_lock);
2474 for (; t && l < *pos; t = t_next(m, t, &l))
2475 ;
2476
2477 return t;
2478}
2479
2480static void t_stop(struct seq_file *m, void *p)
2481{
2482 mutex_unlock(&trace_types_lock);
2483}
2484
2485static int t_show(struct seq_file *m, void *v)
2486{
2487 struct tracer *t = v;
2488
2489 if (!t)
2490 return 0;
2491
2492 seq_printf(m, "%s", t->name);
2493 if (t->next)
2494 seq_putc(m, ' ');
2495 else
2496 seq_putc(m, '\n');
2497
2498 return 0;
2499}
2500
2501static struct seq_operations show_traces_seq_ops = {
4bf39a94
IM
2502 .start = t_start,
2503 .next = t_next,
2504 .stop = t_stop,
2505 .show = t_show,
bc0c38d1
SR
2506};
2507
2508static int show_traces_open(struct inode *inode, struct file *file)
2509{
2510 int ret;
2511
60a11774
SR
2512 if (tracing_disabled)
2513 return -ENODEV;
2514
bc0c38d1
SR
2515 ret = seq_open(file, &show_traces_seq_ops);
2516 if (!ret) {
2517 struct seq_file *m = file->private_data;
2518 m->private = trace_types;
2519 }
2520
2521 return ret;
2522}
2523
2524static struct file_operations tracing_fops = {
4bf39a94
IM
2525 .open = tracing_open,
2526 .read = seq_read,
2527 .llseek = seq_lseek,
2528 .release = tracing_release,
bc0c38d1
SR
2529};
2530
2531static struct file_operations tracing_lt_fops = {
4bf39a94
IM
2532 .open = tracing_lt_open,
2533 .read = seq_read,
2534 .llseek = seq_lseek,
2535 .release = tracing_release,
bc0c38d1
SR
2536};
2537
2538static struct file_operations show_traces_fops = {
c7078de1
IM
2539 .open = show_traces_open,
2540 .read = seq_read,
2541 .release = seq_release,
2542};
2543
36dfe925
IM
2544/*
2545 * Only trace on a CPU if the bitmask is set:
2546 */
2547static cpumask_t tracing_cpumask = CPU_MASK_ALL;
2548
2549/*
2550 * When tracing/tracing_cpu_mask is modified then this holds
2551 * the new bitmask we are about to install:
2552 */
2553static cpumask_t tracing_cpumask_new;
2554
2555/*
2556 * The tracer itself will not take this lock, but still we want
2557 * to provide a consistent cpumask to user-space:
2558 */
2559static DEFINE_MUTEX(tracing_cpumask_update_lock);
2560
2561/*
2562 * Temporary storage for the character representation of the
2563 * CPU bitmask (and one more byte for the newline):
2564 */
2565static char mask_str[NR_CPUS + 1];
2566
c7078de1
IM
2567static ssize_t
2568tracing_cpumask_read(struct file *filp, char __user *ubuf,
2569 size_t count, loff_t *ppos)
2570{
36dfe925 2571 int len;
c7078de1
IM
2572
2573 mutex_lock(&tracing_cpumask_update_lock);
36dfe925
IM
2574
2575 len = cpumask_scnprintf(mask_str, count, tracing_cpumask);
2576 if (count - len < 2) {
2577 count = -EINVAL;
2578 goto out_err;
2579 }
2580 len += sprintf(mask_str + len, "\n");
2581 count = simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+1);
2582
2583out_err:
c7078de1
IM
2584 mutex_unlock(&tracing_cpumask_update_lock);
2585
2586 return count;
2587}
2588
2589static ssize_t
2590tracing_cpumask_write(struct file *filp, const char __user *ubuf,
2591 size_t count, loff_t *ppos)
2592{
36dfe925 2593 int err, cpu;
c7078de1
IM
2594
2595 mutex_lock(&tracing_cpumask_update_lock);
36dfe925 2596 err = cpumask_parse_user(ubuf, count, tracing_cpumask_new);
c7078de1 2597 if (err)
36dfe925
IM
2598 goto err_unlock;
2599
92205c23
SR
2600 raw_local_irq_disable();
2601 __raw_spin_lock(&ftrace_max_lock);
ab46428c 2602 for_each_tracing_cpu(cpu) {
36dfe925
IM
2603 /*
2604 * Increase/decrease the disabled counter if we are
2605 * about to flip a bit in the cpumask:
2606 */
2607 if (cpu_isset(cpu, tracing_cpumask) &&
2608 !cpu_isset(cpu, tracing_cpumask_new)) {
2609 atomic_inc(&global_trace.data[cpu]->disabled);
2610 }
2611 if (!cpu_isset(cpu, tracing_cpumask) &&
2612 cpu_isset(cpu, tracing_cpumask_new)) {
2613 atomic_dec(&global_trace.data[cpu]->disabled);
2614 }
2615 }
92205c23
SR
2616 __raw_spin_unlock(&ftrace_max_lock);
2617 raw_local_irq_enable();
36dfe925
IM
2618
2619 tracing_cpumask = tracing_cpumask_new;
2620
2621 mutex_unlock(&tracing_cpumask_update_lock);
c7078de1
IM
2622
2623 return count;
36dfe925
IM
2624
2625err_unlock:
2626 mutex_unlock(&tracing_cpumask_update_lock);
2627
2628 return err;
c7078de1
IM
2629}
2630
2631static struct file_operations tracing_cpumask_fops = {
2632 .open = tracing_open_generic,
2633 .read = tracing_cpumask_read,
2634 .write = tracing_cpumask_write,
bc0c38d1
SR
2635};
2636
2637static ssize_t
ee6bce52 2638tracing_trace_options_read(struct file *filp, char __user *ubuf,
bc0c38d1
SR
2639 size_t cnt, loff_t *ppos)
2640{
adf9f195 2641 int i;
bc0c38d1
SR
2642 char *buf;
2643 int r = 0;
2644 int len = 0;
adf9f195
FW
2645 u32 tracer_flags = current_trace->flags->val;
2646 struct tracer_opt *trace_opts = current_trace->flags->opts;
2647
bc0c38d1
SR
2648
2649 /* calulate max size */
2650 for (i = 0; trace_options[i]; i++) {
2651 len += strlen(trace_options[i]);
2652 len += 3; /* "no" and space */
2653 }
2654
adf9f195
FW
2655 /*
2656 * Increase the size with names of options specific
2657 * of the current tracer.
2658 */
2659 for (i = 0; trace_opts[i].name; i++) {
2660 len += strlen(trace_opts[i].name);
2661 len += 3; /* "no" and space */
2662 }
2663
bc0c38d1
SR
2664 /* +2 for \n and \0 */
2665 buf = kmalloc(len + 2, GFP_KERNEL);
2666 if (!buf)
2667 return -ENOMEM;
2668
2669 for (i = 0; trace_options[i]; i++) {
2670 if (trace_flags & (1 << i))
2671 r += sprintf(buf + r, "%s ", trace_options[i]);
2672 else
2673 r += sprintf(buf + r, "no%s ", trace_options[i]);
2674 }
2675
adf9f195
FW
2676 for (i = 0; trace_opts[i].name; i++) {
2677 if (tracer_flags & trace_opts[i].bit)
2678 r += sprintf(buf + r, "%s ",
2679 trace_opts[i].name);
2680 else
2681 r += sprintf(buf + r, "no%s ",
2682 trace_opts[i].name);
2683 }
2684
bc0c38d1
SR
2685 r += sprintf(buf + r, "\n");
2686 WARN_ON(r >= len + 2);
2687
36dfe925 2688 r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
bc0c38d1
SR
2689
2690 kfree(buf);
2691
2692 return r;
2693}
2694
adf9f195
FW
2695/* Try to assign a tracer specific option */
2696static int set_tracer_option(struct tracer *trace, char *cmp, int neg)
2697{
2698 struct tracer_flags *trace_flags = trace->flags;
2699 struct tracer_opt *opts = NULL;
2700 int ret = 0, i = 0;
2701 int len;
2702
2703 for (i = 0; trace_flags->opts[i].name; i++) {
2704 opts = &trace_flags->opts[i];
2705 len = strlen(opts->name);
2706
2707 if (strncmp(cmp, opts->name, len) == 0) {
2708 ret = trace->set_flag(trace_flags->val,
2709 opts->bit, !neg);
2710 break;
2711 }
2712 }
2713 /* Not found */
2714 if (!trace_flags->opts[i].name)
2715 return -EINVAL;
2716
2717 /* Refused to handle */
2718 if (ret)
2719 return ret;
2720
2721 if (neg)
2722 trace_flags->val &= ~opts->bit;
2723 else
2724 trace_flags->val |= opts->bit;
2725
2726 return 0;
2727}
2728
bc0c38d1 2729static ssize_t
ee6bce52 2730tracing_trace_options_write(struct file *filp, const char __user *ubuf,
bc0c38d1
SR
2731 size_t cnt, loff_t *ppos)
2732{
2733 char buf[64];
2734 char *cmp = buf;
2735 int neg = 0;
adf9f195 2736 int ret;
bc0c38d1
SR
2737 int i;
2738
cffae437
SR
2739 if (cnt >= sizeof(buf))
2740 return -EINVAL;
bc0c38d1
SR
2741
2742 if (copy_from_user(&buf, ubuf, cnt))
2743 return -EFAULT;
2744
2745 buf[cnt] = 0;
2746
2747 if (strncmp(buf, "no", 2) == 0) {
2748 neg = 1;
2749 cmp += 2;
2750 }
2751
2752 for (i = 0; trace_options[i]; i++) {
2753 int len = strlen(trace_options[i]);
2754
2755 if (strncmp(cmp, trace_options[i], len) == 0) {
2756 if (neg)
2757 trace_flags &= ~(1 << i);
2758 else
2759 trace_flags |= (1 << i);
2760 break;
2761 }
2762 }
adf9f195
FW
2763
2764 /* If no option could be set, test the specific tracer options */
2765 if (!trace_options[i]) {
2766 ret = set_tracer_option(current_trace, cmp, neg);
2767 if (ret)
2768 return ret;
2769 }
bc0c38d1
SR
2770
2771 filp->f_pos += cnt;
2772
2773 return cnt;
2774}
2775
2776static struct file_operations tracing_iter_fops = {
c7078de1 2777 .open = tracing_open_generic,
ee6bce52
SR
2778 .read = tracing_trace_options_read,
2779 .write = tracing_trace_options_write,
bc0c38d1
SR
2780};
2781
7bd2f24c
IM
2782static const char readme_msg[] =
2783 "tracing mini-HOWTO:\n\n"
2784 "# mkdir /debug\n"
2785 "# mount -t debugfs nodev /debug\n\n"
2786 "# cat /debug/tracing/available_tracers\n"
2787 "wakeup preemptirqsoff preemptoff irqsoff ftrace sched_switch none\n\n"
2788 "# cat /debug/tracing/current_tracer\n"
2789 "none\n"
2790 "# echo sched_switch > /debug/tracing/current_tracer\n"
2791 "# cat /debug/tracing/current_tracer\n"
2792 "sched_switch\n"
ee6bce52 2793 "# cat /debug/tracing/trace_options\n"
7bd2f24c 2794 "noprint-parent nosym-offset nosym-addr noverbose\n"
ee6bce52 2795 "# echo print-parent > /debug/tracing/trace_options\n"
7bd2f24c
IM
2796 "# echo 1 > /debug/tracing/tracing_enabled\n"
2797 "# cat /debug/tracing/trace > /tmp/trace.txt\n"
2798 "echo 0 > /debug/tracing/tracing_enabled\n"
2799;
2800
2801static ssize_t
2802tracing_readme_read(struct file *filp, char __user *ubuf,
2803 size_t cnt, loff_t *ppos)
2804{
2805 return simple_read_from_buffer(ubuf, cnt, ppos,
2806 readme_msg, strlen(readme_msg));
2807}
2808
2809static struct file_operations tracing_readme_fops = {
c7078de1
IM
2810 .open = tracing_open_generic,
2811 .read = tracing_readme_read,
7bd2f24c
IM
2812};
2813
bc0c38d1
SR
2814static ssize_t
2815tracing_ctrl_read(struct file *filp, char __user *ubuf,
2816 size_t cnt, loff_t *ppos)
2817{
bc0c38d1
SR
2818 char buf[64];
2819 int r;
2820
9036990d 2821 r = sprintf(buf, "%u\n", tracer_enabled);
4e3c3333 2822 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
bc0c38d1
SR
2823}
2824
2825static ssize_t
2826tracing_ctrl_write(struct file *filp, const char __user *ubuf,
2827 size_t cnt, loff_t *ppos)
2828{
2829 struct trace_array *tr = filp->private_data;
bc0c38d1 2830 char buf[64];
c6caeeb1
SR
2831 long val;
2832 int ret;
bc0c38d1 2833
cffae437
SR
2834 if (cnt >= sizeof(buf))
2835 return -EINVAL;
bc0c38d1
SR
2836
2837 if (copy_from_user(&buf, ubuf, cnt))
2838 return -EFAULT;
2839
2840 buf[cnt] = 0;
2841
c6caeeb1
SR
2842 ret = strict_strtoul(buf, 10, &val);
2843 if (ret < 0)
2844 return ret;
bc0c38d1
SR
2845
2846 val = !!val;
2847
2848 mutex_lock(&trace_types_lock);
9036990d
SR
2849 if (tracer_enabled ^ val) {
2850 if (val) {
bc0c38d1 2851 tracer_enabled = 1;
9036990d
SR
2852 if (current_trace->start)
2853 current_trace->start(tr);
2854 tracing_start();
2855 } else {
bc0c38d1 2856 tracer_enabled = 0;
9036990d
SR
2857 tracing_stop();
2858 if (current_trace->stop)
2859 current_trace->stop(tr);
2860 }
bc0c38d1
SR
2861 }
2862 mutex_unlock(&trace_types_lock);
2863
2864 filp->f_pos += cnt;
2865
2866 return cnt;
2867}
2868
2869static ssize_t
2870tracing_set_trace_read(struct file *filp, char __user *ubuf,
2871 size_t cnt, loff_t *ppos)
2872{
2873 char buf[max_tracer_type_len+2];
2874 int r;
2875
2876 mutex_lock(&trace_types_lock);
2877 if (current_trace)
2878 r = sprintf(buf, "%s\n", current_trace->name);
2879 else
2880 r = sprintf(buf, "\n");
2881 mutex_unlock(&trace_types_lock);
2882
4bf39a94 2883 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
bc0c38d1
SR
2884}
2885
d9e54076 2886static int tracing_set_tracer(char *buf)
bc0c38d1
SR
2887{
2888 struct trace_array *tr = &global_trace;
2889 struct tracer *t;
d9e54076 2890 int ret = 0;
bc0c38d1
SR
2891
2892 mutex_lock(&trace_types_lock);
2893 for (t = trace_types; t; t = t->next) {
2894 if (strcmp(t->name, buf) == 0)
2895 break;
2896 }
c2931e05
FW
2897 if (!t) {
2898 ret = -EINVAL;
2899 goto out;
2900 }
2901 if (t == current_trace)
bc0c38d1
SR
2902 goto out;
2903
9f029e83 2904 trace_branch_disable();
bc0c38d1
SR
2905 if (current_trace && current_trace->reset)
2906 current_trace->reset(tr);
2907
2908 current_trace = t;
1c80025a
FW
2909 if (t->init) {
2910 ret = t->init(tr);
2911 if (ret)
2912 goto out;
2913 }
bc0c38d1 2914
9f029e83 2915 trace_branch_enable(tr);
bc0c38d1
SR
2916 out:
2917 mutex_unlock(&trace_types_lock);
2918
d9e54076
PZ
2919 return ret;
2920}
2921
2922static ssize_t
2923tracing_set_trace_write(struct file *filp, const char __user *ubuf,
2924 size_t cnt, loff_t *ppos)
2925{
2926 char buf[max_tracer_type_len+1];
2927 int i;
2928 size_t ret;
e6e7a65a
FW
2929 int err;
2930
2931 ret = cnt;
d9e54076
PZ
2932
2933 if (cnt > max_tracer_type_len)
2934 cnt = max_tracer_type_len;
2935
2936 if (copy_from_user(&buf, ubuf, cnt))
2937 return -EFAULT;
2938
2939 buf[cnt] = 0;
2940
2941 /* strip ending whitespace. */
2942 for (i = cnt - 1; i > 0 && isspace(buf[i]); i--)
2943 buf[i] = 0;
2944
e6e7a65a
FW
2945 err = tracing_set_tracer(buf);
2946 if (err)
2947 return err;
d9e54076 2948
e6e7a65a 2949 filp->f_pos += ret;
bc0c38d1 2950
c2931e05 2951 return ret;
bc0c38d1
SR
2952}
2953
2954static ssize_t
2955tracing_max_lat_read(struct file *filp, char __user *ubuf,
2956 size_t cnt, loff_t *ppos)
2957{
2958 unsigned long *ptr = filp->private_data;
2959 char buf[64];
2960 int r;
2961
cffae437 2962 r = snprintf(buf, sizeof(buf), "%ld\n",
bc0c38d1 2963 *ptr == (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr));
cffae437
SR
2964 if (r > sizeof(buf))
2965 r = sizeof(buf);
4bf39a94 2966 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
bc0c38d1
SR
2967}
2968
2969static ssize_t
2970tracing_max_lat_write(struct file *filp, const char __user *ubuf,
2971 size_t cnt, loff_t *ppos)
2972{
2973 long *ptr = filp->private_data;
bc0c38d1 2974 char buf[64];
c6caeeb1
SR
2975 long val;
2976 int ret;
bc0c38d1 2977
cffae437
SR
2978 if (cnt >= sizeof(buf))
2979 return -EINVAL;
bc0c38d1
SR
2980
2981 if (copy_from_user(&buf, ubuf, cnt))
2982 return -EFAULT;
2983
2984 buf[cnt] = 0;
2985
c6caeeb1
SR
2986 ret = strict_strtoul(buf, 10, &val);
2987 if (ret < 0)
2988 return ret;
bc0c38d1
SR
2989
2990 *ptr = val * 1000;
2991
2992 return cnt;
2993}
2994
b3806b43
SR
2995static atomic_t tracing_reader;
2996
2997static int tracing_open_pipe(struct inode *inode, struct file *filp)
2998{
2999 struct trace_iterator *iter;
3000
3001 if (tracing_disabled)
3002 return -ENODEV;
3003
3004 /* We only allow for reader of the pipe */
3005 if (atomic_inc_return(&tracing_reader) != 1) {
3006 atomic_dec(&tracing_reader);
3007 return -EBUSY;
3008 }
3009
3010 /* create a buffer to store the information to pass to userspace */
3011 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
3012 if (!iter)
3013 return -ENOMEM;
3014
107bad8b 3015 mutex_lock(&trace_types_lock);
a309720c
SR
3016
3017 /* trace pipe does not show start of buffer */
3018 cpus_setall(iter->started);
3019
b3806b43 3020 iter->tr = &global_trace;
72829bc3 3021 iter->trace = current_trace;
b3806b43
SR
3022 filp->private_data = iter;
3023
107bad8b
SR
3024 if (iter->trace->pipe_open)
3025 iter->trace->pipe_open(iter);
3026 mutex_unlock(&trace_types_lock);
3027
b3806b43
SR
3028 return 0;
3029}
3030
3031static int tracing_release_pipe(struct inode *inode, struct file *file)
3032{
3033 struct trace_iterator *iter = file->private_data;
3034
3035 kfree(iter);
3036 atomic_dec(&tracing_reader);
3037
3038 return 0;
3039}
3040
2a2cc8f7
SSP
3041static unsigned int
3042tracing_poll_pipe(struct file *filp, poll_table *poll_table)
3043{
3044 struct trace_iterator *iter = filp->private_data;
3045
3046 if (trace_flags & TRACE_ITER_BLOCK) {
3047 /*
3048 * Always select as readable when in blocking mode
3049 */
3050 return POLLIN | POLLRDNORM;
afc2abc0 3051 } else {
2a2cc8f7
SSP
3052 if (!trace_empty(iter))
3053 return POLLIN | POLLRDNORM;
3054 poll_wait(filp, &trace_wait, poll_table);
3055 if (!trace_empty(iter))
3056 return POLLIN | POLLRDNORM;
3057
3058 return 0;
3059 }
3060}
3061
b3806b43
SR
3062/*
3063 * Consumer reader.
3064 */
3065static ssize_t
3066tracing_read_pipe(struct file *filp, char __user *ubuf,
3067 size_t cnt, loff_t *ppos)
3068{
3069 struct trace_iterator *iter = filp->private_data;
6c6c2796 3070 ssize_t sret;
b3806b43
SR
3071
3072 /* return any leftover data */
6c6c2796
PP
3073 sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
3074 if (sret != -EBUSY)
3075 return sret;
b3806b43 3076
6c6c2796 3077 trace_seq_reset(&iter->seq);
b3806b43 3078
107bad8b
SR
3079 mutex_lock(&trace_types_lock);
3080 if (iter->trace->read) {
6c6c2796
PP
3081 sret = iter->trace->read(iter, filp, ubuf, cnt, ppos);
3082 if (sret)
107bad8b 3083 goto out;
107bad8b
SR
3084 }
3085
9ff4b974
PP
3086waitagain:
3087 sret = 0;
b3806b43 3088 while (trace_empty(iter)) {
2dc8f095 3089
107bad8b 3090 if ((filp->f_flags & O_NONBLOCK)) {
6c6c2796 3091 sret = -EAGAIN;
107bad8b
SR
3092 goto out;
3093 }
2dc8f095 3094
b3806b43
SR
3095 /*
3096 * This is a make-shift waitqueue. The reason we don't use
3097 * an actual wait queue is because:
3098 * 1) we only ever have one waiter
3099 * 2) the tracing, traces all functions, we don't want
3100 * the overhead of calling wake_up and friends
3101 * (and tracing them too)
3102 * Anyway, this is really very primitive wakeup.
3103 */
3104 set_current_state(TASK_INTERRUPTIBLE);
3105 iter->tr->waiter = current;
3106
107bad8b
SR
3107 mutex_unlock(&trace_types_lock);
3108
9fe068e9
IM
3109 /* sleep for 100 msecs, and try again. */
3110 schedule_timeout(HZ/10);
b3806b43 3111
107bad8b
SR
3112 mutex_lock(&trace_types_lock);
3113
b3806b43
SR
3114 iter->tr->waiter = NULL;
3115
107bad8b 3116 if (signal_pending(current)) {
6c6c2796 3117 sret = -EINTR;
107bad8b
SR
3118 goto out;
3119 }
b3806b43 3120
84527997 3121 if (iter->trace != current_trace)
107bad8b 3122 goto out;
84527997 3123
b3806b43
SR
3124 /*
3125 * We block until we read something and tracing is disabled.
3126 * We still block if tracing is disabled, but we have never
3127 * read anything. This allows a user to cat this file, and
3128 * then enable tracing. But after we have read something,
3129 * we give an EOF when tracing is again disabled.
3130 *
3131 * iter->pos will be 0 if we haven't read anything.
3132 */
3133 if (!tracer_enabled && iter->pos)
3134 break;
3135
3136 continue;
3137 }
3138
3139 /* stop when tracing is finished */
3140 if (trace_empty(iter))
107bad8b 3141 goto out;
b3806b43
SR
3142
3143 if (cnt >= PAGE_SIZE)
3144 cnt = PAGE_SIZE - 1;
3145
53d0aa77 3146 /* reset all but tr, trace, and overruns */
53d0aa77
SR
3147 memset(&iter->seq, 0,
3148 sizeof(struct trace_iterator) -
3149 offsetof(struct trace_iterator, seq));
4823ed7e 3150 iter->pos = -1;
b3806b43 3151
088b1e42 3152 while (find_next_entry_inc(iter) != NULL) {
2c4f035f 3153 enum print_line_t ret;
088b1e42
SR
3154 int len = iter->seq.len;
3155
f9896bf3 3156 ret = print_trace_line(iter);
2c4f035f 3157 if (ret == TRACE_TYPE_PARTIAL_LINE) {
088b1e42
SR
3158 /* don't print partial lines */
3159 iter->seq.len = len;
b3806b43 3160 break;
088b1e42 3161 }
b3806b43
SR
3162
3163 trace_consume(iter);
3164
3165 if (iter->seq.len >= cnt)
3166 break;
b3806b43
SR
3167 }
3168
b3806b43 3169 /* Now copy what we have to the user */
6c6c2796
PP
3170 sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
3171 if (iter->seq.readpos >= iter->seq.len)
b3806b43 3172 trace_seq_reset(&iter->seq);
9ff4b974
PP
3173
3174 /*
3175 * If there was nothing to send to user, inspite of consuming trace
3176 * entries, go back to wait for more entries.
3177 */
6c6c2796 3178 if (sret == -EBUSY)
9ff4b974 3179 goto waitagain;
b3806b43 3180
107bad8b
SR
3181out:
3182 mutex_unlock(&trace_types_lock);
3183
6c6c2796 3184 return sret;
b3806b43
SR
3185}
3186
a98a3c3f
SR
3187static ssize_t
3188tracing_entries_read(struct file *filp, char __user *ubuf,
3189 size_t cnt, loff_t *ppos)
3190{
3191 struct trace_array *tr = filp->private_data;
3192 char buf[64];
3193 int r;
3194
1696b2b0 3195 r = sprintf(buf, "%lu\n", tr->entries >> 10);
a98a3c3f
SR
3196 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
3197}
3198
3199static ssize_t
3200tracing_entries_write(struct file *filp, const char __user *ubuf,
3201 size_t cnt, loff_t *ppos)
3202{
3203 unsigned long val;
3204 char buf[64];
bf5e6519 3205 int ret, cpu;
a98a3c3f 3206
cffae437
SR
3207 if (cnt >= sizeof(buf))
3208 return -EINVAL;
a98a3c3f
SR
3209
3210 if (copy_from_user(&buf, ubuf, cnt))
3211 return -EFAULT;
3212
3213 buf[cnt] = 0;
3214
c6caeeb1
SR
3215 ret = strict_strtoul(buf, 10, &val);
3216 if (ret < 0)
3217 return ret;
a98a3c3f
SR
3218
3219 /* must have at least 1 entry */
3220 if (!val)
3221 return -EINVAL;
3222
3223 mutex_lock(&trace_types_lock);
3224
c76f0694 3225 tracing_stop();
a98a3c3f 3226
bf5e6519
SR
3227 /* disable all cpu buffers */
3228 for_each_tracing_cpu(cpu) {
3229 if (global_trace.data[cpu])
3230 atomic_inc(&global_trace.data[cpu]->disabled);
3231 if (max_tr.data[cpu])
3232 atomic_inc(&max_tr.data[cpu]->disabled);
3233 }
3234
1696b2b0
SR
3235 /* value is in KB */
3236 val <<= 10;
3237
3928a8a2
SR
3238 if (val != global_trace.entries) {
3239 ret = ring_buffer_resize(global_trace.buffer, val);
3240 if (ret < 0) {
3241 cnt = ret;
3eefae99
SR
3242 goto out;
3243 }
3244
3928a8a2
SR
3245 ret = ring_buffer_resize(max_tr.buffer, val);
3246 if (ret < 0) {
3247 int r;
3248 cnt = ret;
3249 r = ring_buffer_resize(global_trace.buffer,
3250 global_trace.entries);
3251 if (r < 0) {
3252 /* AARGH! We are left with different
3253 * size max buffer!!!! */
3254 WARN_ON(1);
3255 tracing_disabled = 1;
a98a3c3f 3256 }
3928a8a2 3257 goto out;
a98a3c3f 3258 }
3eefae99 3259
3928a8a2 3260 global_trace.entries = val;
a98a3c3f
SR
3261 }
3262
3263 filp->f_pos += cnt;
3264
19384c03
SR
3265 /* If check pages failed, return ENOMEM */
3266 if (tracing_disabled)
3267 cnt = -ENOMEM;
a98a3c3f 3268 out:
bf5e6519
SR
3269 for_each_tracing_cpu(cpu) {
3270 if (global_trace.data[cpu])
3271 atomic_dec(&global_trace.data[cpu]->disabled);
3272 if (max_tr.data[cpu])
3273 atomic_dec(&max_tr.data[cpu]->disabled);
3274 }
3275
c76f0694 3276 tracing_start();
a98a3c3f
SR
3277 max_tr.entries = global_trace.entries;
3278 mutex_unlock(&trace_types_lock);
3279
3280 return cnt;
3281}
3282
5bf9a1ee
PP
3283static int mark_printk(const char *fmt, ...)
3284{
3285 int ret;
3286 va_list args;
3287 va_start(args, fmt);
3288 ret = trace_vprintk(0, fmt, args);
3289 va_end(args);
3290 return ret;
3291}
3292
3293static ssize_t
3294tracing_mark_write(struct file *filp, const char __user *ubuf,
3295 size_t cnt, loff_t *fpos)
3296{
3297 char *buf;
3298 char *end;
5bf9a1ee 3299
c76f0694 3300 if (tracing_disabled)
5bf9a1ee
PP
3301 return -EINVAL;
3302
3303 if (cnt > TRACE_BUF_SIZE)
3304 cnt = TRACE_BUF_SIZE;
3305
3306 buf = kmalloc(cnt + 1, GFP_KERNEL);
3307 if (buf == NULL)
3308 return -ENOMEM;
3309
3310 if (copy_from_user(buf, ubuf, cnt)) {
3311 kfree(buf);
3312 return -EFAULT;
3313 }
3314
3315 /* Cut from the first nil or newline. */
3316 buf[cnt] = '\0';
3317 end = strchr(buf, '\n');
3318 if (end)
3319 *end = '\0';
3320
3321 cnt = mark_printk("%s\n", buf);
3322 kfree(buf);
3323 *fpos += cnt;
3324
3325 return cnt;
3326}
3327
bc0c38d1 3328static struct file_operations tracing_max_lat_fops = {
4bf39a94
IM
3329 .open = tracing_open_generic,
3330 .read = tracing_max_lat_read,
3331 .write = tracing_max_lat_write,
bc0c38d1
SR
3332};
3333
3334static struct file_operations tracing_ctrl_fops = {
4bf39a94
IM
3335 .open = tracing_open_generic,
3336 .read = tracing_ctrl_read,
3337 .write = tracing_ctrl_write,
bc0c38d1
SR
3338};
3339
3340static struct file_operations set_tracer_fops = {
4bf39a94
IM
3341 .open = tracing_open_generic,
3342 .read = tracing_set_trace_read,
3343 .write = tracing_set_trace_write,
bc0c38d1
SR
3344};
3345
b3806b43 3346static struct file_operations tracing_pipe_fops = {
4bf39a94 3347 .open = tracing_open_pipe,
2a2cc8f7 3348 .poll = tracing_poll_pipe,
4bf39a94
IM
3349 .read = tracing_read_pipe,
3350 .release = tracing_release_pipe,
b3806b43
SR
3351};
3352
a98a3c3f
SR
3353static struct file_operations tracing_entries_fops = {
3354 .open = tracing_open_generic,
3355 .read = tracing_entries_read,
3356 .write = tracing_entries_write,
3357};
3358
5bf9a1ee 3359static struct file_operations tracing_mark_fops = {
43a15386 3360 .open = tracing_open_generic,
5bf9a1ee
PP
3361 .write = tracing_mark_write,
3362};
3363
bc0c38d1
SR
3364#ifdef CONFIG_DYNAMIC_FTRACE
3365
b807c3d0
SR
3366int __weak ftrace_arch_read_dyn_info(char *buf, int size)
3367{
3368 return 0;
3369}
3370
bc0c38d1 3371static ssize_t
b807c3d0 3372tracing_read_dyn_info(struct file *filp, char __user *ubuf,
bc0c38d1
SR
3373 size_t cnt, loff_t *ppos)
3374{
a26a2a27
SR
3375 static char ftrace_dyn_info_buffer[1024];
3376 static DEFINE_MUTEX(dyn_info_mutex);
bc0c38d1 3377 unsigned long *p = filp->private_data;
b807c3d0 3378 char *buf = ftrace_dyn_info_buffer;
a26a2a27 3379 int size = ARRAY_SIZE(ftrace_dyn_info_buffer);
bc0c38d1
SR
3380 int r;
3381
b807c3d0
SR
3382 mutex_lock(&dyn_info_mutex);
3383 r = sprintf(buf, "%ld ", *p);
4bf39a94 3384
a26a2a27 3385 r += ftrace_arch_read_dyn_info(buf+r, (size-1)-r);
b807c3d0
SR
3386 buf[r++] = '\n';
3387
3388 r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
3389
3390 mutex_unlock(&dyn_info_mutex);
3391
3392 return r;
bc0c38d1
SR
3393}
3394
b807c3d0 3395static struct file_operations tracing_dyn_info_fops = {
4bf39a94 3396 .open = tracing_open_generic,
b807c3d0 3397 .read = tracing_read_dyn_info,
bc0c38d1
SR
3398};
3399#endif
3400
3401static struct dentry *d_tracer;
3402
3403struct dentry *tracing_init_dentry(void)
3404{
3405 static int once;
3406
3407 if (d_tracer)
3408 return d_tracer;
3409
3410 d_tracer = debugfs_create_dir("tracing", NULL);
3411
3412 if (!d_tracer && !once) {
3413 once = 1;
3414 pr_warning("Could not create debugfs directory 'tracing'\n");
3415 return NULL;
3416 }
3417
3418 return d_tracer;
3419}
3420
60a11774
SR
3421#ifdef CONFIG_FTRACE_SELFTEST
3422/* Let selftest have access to static functions in this file */
3423#include "trace_selftest.c"
3424#endif
3425
b5ad384e 3426static __init int tracer_init_debugfs(void)
bc0c38d1
SR
3427{
3428 struct dentry *d_tracer;
3429 struct dentry *entry;
3430
3431 d_tracer = tracing_init_dentry();
3432
3433 entry = debugfs_create_file("tracing_enabled", 0644, d_tracer,
3434 &global_trace, &tracing_ctrl_fops);
3435 if (!entry)
3436 pr_warning("Could not create debugfs 'tracing_enabled' entry\n");
3437
ee6bce52 3438 entry = debugfs_create_file("trace_options", 0644, d_tracer,
bc0c38d1
SR
3439 NULL, &tracing_iter_fops);
3440 if (!entry)
ee6bce52 3441 pr_warning("Could not create debugfs 'trace_options' entry\n");
bc0c38d1 3442
c7078de1
IM
3443 entry = debugfs_create_file("tracing_cpumask", 0644, d_tracer,
3444 NULL, &tracing_cpumask_fops);
3445 if (!entry)
3446 pr_warning("Could not create debugfs 'tracing_cpumask' entry\n");
3447
bc0c38d1
SR
3448 entry = debugfs_create_file("latency_trace", 0444, d_tracer,
3449 &global_trace, &tracing_lt_fops);
3450 if (!entry)
3451 pr_warning("Could not create debugfs 'latency_trace' entry\n");
3452
3453 entry = debugfs_create_file("trace", 0444, d_tracer,
3454 &global_trace, &tracing_fops);
3455 if (!entry)
3456 pr_warning("Could not create debugfs 'trace' entry\n");
3457
3458 entry = debugfs_create_file("available_tracers", 0444, d_tracer,
3459 &global_trace, &show_traces_fops);
3460 if (!entry)
98a983aa 3461 pr_warning("Could not create debugfs 'available_tracers' entry\n");
bc0c38d1
SR
3462
3463 entry = debugfs_create_file("current_tracer", 0444, d_tracer,
3464 &global_trace, &set_tracer_fops);
3465 if (!entry)
98a983aa 3466 pr_warning("Could not create debugfs 'current_tracer' entry\n");
bc0c38d1
SR
3467
3468 entry = debugfs_create_file("tracing_max_latency", 0644, d_tracer,
3469 &tracing_max_latency,
3470 &tracing_max_lat_fops);
3471 if (!entry)
3472 pr_warning("Could not create debugfs "
3473 "'tracing_max_latency' entry\n");
3474
3475 entry = debugfs_create_file("tracing_thresh", 0644, d_tracer,
3476 &tracing_thresh, &tracing_max_lat_fops);
3477 if (!entry)
3478 pr_warning("Could not create debugfs "
98a983aa 3479 "'tracing_thresh' entry\n");
7bd2f24c
IM
3480 entry = debugfs_create_file("README", 0644, d_tracer,
3481 NULL, &tracing_readme_fops);
3482 if (!entry)
3483 pr_warning("Could not create debugfs 'README' entry\n");
3484
b3806b43
SR
3485 entry = debugfs_create_file("trace_pipe", 0644, d_tracer,
3486 NULL, &tracing_pipe_fops);
3487 if (!entry)
3488 pr_warning("Could not create debugfs "
98a983aa 3489 "'trace_pipe' entry\n");
bc0c38d1 3490
a94c80e7 3491 entry = debugfs_create_file("buffer_size_kb", 0644, d_tracer,
a98a3c3f
SR
3492 &global_trace, &tracing_entries_fops);
3493 if (!entry)
3494 pr_warning("Could not create debugfs "
a94c80e7 3495 "'buffer_size_kb' entry\n");
a98a3c3f 3496
5bf9a1ee
PP
3497 entry = debugfs_create_file("trace_marker", 0220, d_tracer,
3498 NULL, &tracing_mark_fops);
3499 if (!entry)
3500 pr_warning("Could not create debugfs "
3501 "'trace_marker' entry\n");
3502
bc0c38d1
SR
3503#ifdef CONFIG_DYNAMIC_FTRACE
3504 entry = debugfs_create_file("dyn_ftrace_total_info", 0444, d_tracer,
3505 &ftrace_update_tot_cnt,
b807c3d0 3506 &tracing_dyn_info_fops);
bc0c38d1
SR
3507 if (!entry)
3508 pr_warning("Could not create debugfs "
3509 "'dyn_ftrace_total_info' entry\n");
3510#endif
d618b3e6
IM
3511#ifdef CONFIG_SYSPROF_TRACER
3512 init_tracer_sysprof_debugfs(d_tracer);
3513#endif
b5ad384e 3514 return 0;
bc0c38d1
SR
3515}
3516
801fe400 3517int trace_vprintk(unsigned long ip, const char *fmt, va_list args)
dd0e545f 3518{
dd0e545f
SR
3519 static DEFINE_SPINLOCK(trace_buf_lock);
3520 static char trace_buf[TRACE_BUF_SIZE];
f09ce573 3521
3928a8a2 3522 struct ring_buffer_event *event;
f09ce573 3523 struct trace_array *tr = &global_trace;
dd0e545f 3524 struct trace_array_cpu *data;
777e208d 3525 struct print_entry *entry;
3928a8a2 3526 unsigned long flags, irq_flags;
38697053 3527 int cpu, len = 0, size, pc;
dd0e545f 3528
c76f0694 3529 if (tracing_disabled)
dd0e545f
SR
3530 return 0;
3531
38697053
SR
3532 pc = preempt_count();
3533 preempt_disable_notrace();
dd0e545f
SR
3534 cpu = raw_smp_processor_id();
3535 data = tr->data[cpu];
dd0e545f 3536
3ea2e6d7 3537 if (unlikely(atomic_read(&data->disabled)))
dd0e545f
SR
3538 goto out;
3539
38697053 3540 spin_lock_irqsave(&trace_buf_lock, flags);
801fe400 3541 len = vsnprintf(trace_buf, TRACE_BUF_SIZE, fmt, args);
dd0e545f
SR
3542
3543 len = min(len, TRACE_BUF_SIZE-1);
3544 trace_buf[len] = 0;
3545
777e208d
SR
3546 size = sizeof(*entry) + len + 1;
3547 event = ring_buffer_lock_reserve(tr->buffer, size, &irq_flags);
3928a8a2
SR
3548 if (!event)
3549 goto out_unlock;
777e208d 3550 entry = ring_buffer_event_data(event);
38697053 3551 tracing_generic_entry_update(&entry->ent, flags, pc);
777e208d
SR
3552 entry->ent.type = TRACE_PRINT;
3553 entry->ip = ip;
dd0e545f 3554
777e208d
SR
3555 memcpy(&entry->buf, trace_buf, len);
3556 entry->buf[len] = 0;
3928a8a2 3557 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
dd0e545f 3558
3928a8a2 3559 out_unlock:
38697053 3560 spin_unlock_irqrestore(&trace_buf_lock, flags);
dd0e545f
SR
3561
3562 out:
38697053 3563 preempt_enable_notrace();
dd0e545f
SR
3564
3565 return len;
3566}
801fe400
PP
3567EXPORT_SYMBOL_GPL(trace_vprintk);
3568
3569int __ftrace_printk(unsigned long ip, const char *fmt, ...)
3570{
3571 int ret;
3572 va_list ap;
3573
3574 if (!(trace_flags & TRACE_ITER_PRINTK))
3575 return 0;
3576
3577 va_start(ap, fmt);
3578 ret = trace_vprintk(ip, fmt, ap);
3579 va_end(ap);
3580 return ret;
3581}
dd0e545f
SR
3582EXPORT_SYMBOL_GPL(__ftrace_printk);
3583
3f5a54e3
SR
3584static int trace_panic_handler(struct notifier_block *this,
3585 unsigned long event, void *unused)
3586{
944ac425
SR
3587 if (ftrace_dump_on_oops)
3588 ftrace_dump();
3f5a54e3
SR
3589 return NOTIFY_OK;
3590}
3591
3592static struct notifier_block trace_panic_notifier = {
3593 .notifier_call = trace_panic_handler,
3594 .next = NULL,
3595 .priority = 150 /* priority: INT_MAX >= x >= 0 */
3596};
3597
3598static int trace_die_handler(struct notifier_block *self,
3599 unsigned long val,
3600 void *data)
3601{
3602 switch (val) {
3603 case DIE_OOPS:
944ac425
SR
3604 if (ftrace_dump_on_oops)
3605 ftrace_dump();
3f5a54e3
SR
3606 break;
3607 default:
3608 break;
3609 }
3610 return NOTIFY_OK;
3611}
3612
3613static struct notifier_block trace_die_notifier = {
3614 .notifier_call = trace_die_handler,
3615 .priority = 200
3616};
3617
3618/*
3619 * printk is set to max of 1024, we really don't need it that big.
3620 * Nothing should be printing 1000 characters anyway.
3621 */
3622#define TRACE_MAX_PRINT 1000
3623
3624/*
3625 * Define here KERN_TRACE so that we have one place to modify
3626 * it if we decide to change what log level the ftrace dump
3627 * should be at.
3628 */
3629#define KERN_TRACE KERN_INFO
3630
3631static void
3632trace_printk_seq(struct trace_seq *s)
3633{
3634 /* Probably should print a warning here. */
3635 if (s->len >= 1000)
3636 s->len = 1000;
3637
3638 /* should be zero ended, but we are paranoid. */
3639 s->buffer[s->len] = 0;
3640
3641 printk(KERN_TRACE "%s", s->buffer);
3642
3643 trace_seq_reset(s);
3644}
3645
3f5a54e3
SR
3646void ftrace_dump(void)
3647{
3648 static DEFINE_SPINLOCK(ftrace_dump_lock);
3649 /* use static because iter can be a bit big for the stack */
3650 static struct trace_iterator iter;
3f5a54e3
SR
3651 static cpumask_t mask;
3652 static int dump_ran;
d769041f
SR
3653 unsigned long flags;
3654 int cnt = 0, cpu;
3f5a54e3
SR
3655
3656 /* only one dump */
3657 spin_lock_irqsave(&ftrace_dump_lock, flags);
3658 if (dump_ran)
3659 goto out;
3660
3661 dump_ran = 1;
3662
3663 /* No turning back! */
81adbdc0 3664 ftrace_kill();
3f5a54e3 3665
d769041f
SR
3666 for_each_tracing_cpu(cpu) {
3667 atomic_inc(&global_trace.data[cpu]->disabled);
3668 }
3669
b54d3de9
TE
3670 /* don't look at user memory in panic mode */
3671 trace_flags &= ~TRACE_ITER_SYM_USEROBJ;
3672
3f5a54e3
SR
3673 printk(KERN_TRACE "Dumping ftrace buffer:\n");
3674
3675 iter.tr = &global_trace;
3676 iter.trace = current_trace;
3677
3678 /*
3679 * We need to stop all tracing on all CPUS to read the
3680 * the next buffer. This is a bit expensive, but is
3681 * not done often. We fill all what we can read,
3682 * and then release the locks again.
3683 */
3684
3685 cpus_clear(mask);
3686
3f5a54e3
SR
3687 while (!trace_empty(&iter)) {
3688
3689 if (!cnt)
3690 printk(KERN_TRACE "---------------------------------\n");
3691
3692 cnt++;
3693
3694 /* reset all but tr, trace, and overruns */
3695 memset(&iter.seq, 0,
3696 sizeof(struct trace_iterator) -
3697 offsetof(struct trace_iterator, seq));
3698 iter.iter_flags |= TRACE_FILE_LAT_FMT;
3699 iter.pos = -1;
3700
3701 if (find_next_entry_inc(&iter) != NULL) {
3702 print_trace_line(&iter);
3703 trace_consume(&iter);
3704 }
3705
3706 trace_printk_seq(&iter.seq);
3707 }
3708
3709 if (!cnt)
3710 printk(KERN_TRACE " (ftrace buffer empty)\n");
3711 else
3712 printk(KERN_TRACE "---------------------------------\n");
3713
3f5a54e3
SR
3714 out:
3715 spin_unlock_irqrestore(&ftrace_dump_lock, flags);
3716}
3717
3928a8a2 3718__init static int tracer_alloc_buffers(void)
bc0c38d1 3719{
4c11d7ae 3720 struct trace_array_cpu *data;
4c11d7ae
SR
3721 int i;
3722
3928a8a2
SR
3723 /* TODO: make the number of buffers hot pluggable with CPUS */
3724 tracing_buffer_mask = cpu_possible_map;
4c11d7ae 3725
3928a8a2
SR
3726 global_trace.buffer = ring_buffer_alloc(trace_buf_size,
3727 TRACE_BUFFER_FLAGS);
3728 if (!global_trace.buffer) {
3729 printk(KERN_ERR "tracer: failed to allocate ring buffer!\n");
3730 WARN_ON(1);
3731 return 0;
4c11d7ae 3732 }
3928a8a2 3733 global_trace.entries = ring_buffer_size(global_trace.buffer);
4c11d7ae
SR
3734
3735#ifdef CONFIG_TRACER_MAX_TRACE
3928a8a2
SR
3736 max_tr.buffer = ring_buffer_alloc(trace_buf_size,
3737 TRACE_BUFFER_FLAGS);
3738 if (!max_tr.buffer) {
3739 printk(KERN_ERR "tracer: failed to allocate max ring buffer!\n");
3740 WARN_ON(1);
3741 ring_buffer_free(global_trace.buffer);
3742 return 0;
4c11d7ae 3743 }
3928a8a2
SR
3744 max_tr.entries = ring_buffer_size(max_tr.buffer);
3745 WARN_ON(max_tr.entries != global_trace.entries);
a98a3c3f 3746#endif
ab46428c 3747
4c11d7ae 3748 /* Allocate the first page for all buffers */
ab46428c 3749 for_each_tracing_cpu(i) {
4c11d7ae 3750 data = global_trace.data[i] = &per_cpu(global_trace_cpu, i);
bc0c38d1 3751 max_tr.data[i] = &per_cpu(max_data, i);
4c11d7ae 3752 }
bc0c38d1 3753
bc0c38d1
SR
3754 trace_init_cmdlines();
3755
43a15386 3756 register_tracer(&nop_trace);
b5ad384e
FW
3757#ifdef CONFIG_BOOT_TRACER
3758 register_tracer(&boot_tracer);
3759 current_trace = &boot_tracer;
3760 current_trace->init(&global_trace);
3761#else
43a15386 3762 current_trace = &nop_trace;
b5ad384e 3763#endif
bc0c38d1 3764
60a11774
SR
3765 /* All seems OK, enable tracing */
3766 tracing_disabled = 0;
3928a8a2 3767
3f5a54e3
SR
3768 atomic_notifier_chain_register(&panic_notifier_list,
3769 &trace_panic_notifier);
3770
3771 register_die_notifier(&trace_die_notifier);
3772
bc0c38d1 3773 return 0;
bc0c38d1 3774}
b5ad384e
FW
3775early_initcall(tracer_alloc_buffers);
3776fs_initcall(tracer_init_debugfs);
This page took 0.534655 seconds and 5 git commands to generate.