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