]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - kernel/trace/trace.c
ftrace: add UNINTERRUPTIBLE state for kftraced on disable
[mirror_ubuntu-zesty-kernel.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>
17#include <linux/debugfs.h>
4c11d7ae 18#include <linux/pagemap.h>
bc0c38d1
SR
19#include <linux/hardirq.h>
20#include <linux/linkage.h>
21#include <linux/uaccess.h>
22#include <linux/ftrace.h>
23#include <linux/module.h>
24#include <linux/percpu.h>
25#include <linux/ctype.h>
26#include <linux/init.h>
2a2cc8f7 27#include <linux/poll.h>
bc0c38d1
SR
28#include <linux/gfp.h>
29#include <linux/fs.h>
30
86387f7e
IM
31#include <linux/stacktrace.h>
32
bc0c38d1
SR
33#include "trace.h"
34
35unsigned long __read_mostly tracing_max_latency = (cycle_t)ULONG_MAX;
36unsigned long __read_mostly tracing_thresh;
37
60a11774
SR
38static int tracing_disabled = 1;
39
e309b41d 40static long
bc0c38d1
SR
41ns2usecs(cycle_t nsec)
42{
43 nsec += 500;
44 do_div(nsec, 1000);
45 return nsec;
46}
47
e309b41d 48cycle_t ftrace_now(int cpu)
750ed1a4 49{
0fd9e0da 50 return cpu_clock(cpu);
750ed1a4
IM
51}
52
bc0c38d1
SR
53static struct trace_array global_trace;
54
55static DEFINE_PER_CPU(struct trace_array_cpu, global_trace_cpu);
56
57static struct trace_array max_tr;
58
59static DEFINE_PER_CPU(struct trace_array_cpu, max_data);
60
26994ead 61static int tracer_enabled = 1;
57422797 62static unsigned long trace_nr_entries = 65536UL;
bc0c38d1
SR
63
64static struct tracer *trace_types __read_mostly;
65static struct tracer *current_trace __read_mostly;
66static int max_tracer_type_len;
67
68static DEFINE_MUTEX(trace_types_lock);
4e655519
IM
69static DECLARE_WAIT_QUEUE_HEAD(trace_wait);
70
71unsigned long trace_flags = TRACE_ITER_PRINT_PARENT;
72
4e655519
IM
73void trace_wake_up(void)
74{
017730c1
IM
75 /*
76 * The runqueue_is_locked() can fail, but this is the best we
77 * have for now:
78 */
79 if (!(trace_flags & TRACE_ITER_BLOCK) && !runqueue_is_locked())
4e655519
IM
80 wake_up(&trace_wait);
81}
bc0c38d1 82
4c11d7ae
SR
83#define ENTRIES_PER_PAGE (PAGE_SIZE / sizeof(struct trace_entry))
84
bc0c38d1
SR
85static int __init set_nr_entries(char *str)
86{
87 if (!str)
88 return 0;
89 trace_nr_entries = simple_strtoul(str, &str, 0);
90 return 1;
91}
92__setup("trace_entries=", set_nr_entries);
93
57f50be1
SR
94unsigned long nsecs_to_usecs(unsigned long nsecs)
95{
96 return nsecs / 1000;
97}
98
bc0c38d1
SR
99enum trace_type {
100 __TRACE_FIRST_TYPE = 0,
101
102 TRACE_FN,
103 TRACE_CTX,
57422797 104 TRACE_WAKE,
86387f7e 105 TRACE_STACK,
f0a920d5 106 TRACE_SPECIAL,
bc0c38d1
SR
107
108 __TRACE_LAST_TYPE
109};
110
111enum trace_flag_type {
112 TRACE_FLAG_IRQS_OFF = 0x01,
113 TRACE_FLAG_NEED_RESCHED = 0x02,
114 TRACE_FLAG_HARDIRQ = 0x04,
115 TRACE_FLAG_SOFTIRQ = 0x08,
116};
117
bc0c38d1
SR
118#define TRACE_ITER_SYM_MASK \
119 (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
120
121/* These must match the bit postions above */
122static const char *trace_options[] = {
123 "print-parent",
124 "sym-offset",
125 "sym-addr",
126 "verbose",
f9896bf3 127 "raw",
5e3ca0ec 128 "hex",
cb0f12aa 129 "bin",
2a2cc8f7 130 "block",
86387f7e 131 "stacktrace",
4ac3ba41 132 "sched-tree",
bc0c38d1
SR
133 NULL
134};
135
92205c23
SR
136static raw_spinlock_t ftrace_max_lock =
137 (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED;
bc0c38d1
SR
138
139/*
140 * Copy the new maximum trace into the separate maximum-trace
141 * structure. (this way the maximum trace is permanently saved,
142 * for later retrieval via /debugfs/tracing/latency_trace)
143 */
e309b41d 144static void
bc0c38d1
SR
145__update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
146{
147 struct trace_array_cpu *data = tr->data[cpu];
148
149 max_tr.cpu = cpu;
150 max_tr.time_start = data->preempt_timestamp;
151
152 data = max_tr.data[cpu];
153 data->saved_latency = tracing_max_latency;
154
155 memcpy(data->comm, tsk->comm, TASK_COMM_LEN);
156 data->pid = tsk->pid;
157 data->uid = tsk->uid;
158 data->nice = tsk->static_prio - 20 - MAX_RT_PRIO;
159 data->policy = tsk->policy;
160 data->rt_priority = tsk->rt_priority;
161
162 /* record this tasks comm */
163 tracing_record_cmdline(current);
164}
165
c7aafc54
IM
166void check_pages(struct trace_array_cpu *data)
167{
168 struct page *page, *tmp;
169
170 BUG_ON(data->trace_pages.next->prev != &data->trace_pages);
171 BUG_ON(data->trace_pages.prev->next != &data->trace_pages);
172
173 list_for_each_entry_safe(page, tmp, &data->trace_pages, lru) {
174 BUG_ON(page->lru.next->prev != &page->lru);
175 BUG_ON(page->lru.prev->next != &page->lru);
176 }
177}
178
179void *head_page(struct trace_array_cpu *data)
180{
181 struct page *page;
182
183 check_pages(data);
184 if (list_empty(&data->trace_pages))
185 return NULL;
186
187 page = list_entry(data->trace_pages.next, struct page, lru);
188 BUG_ON(&page->lru == &data->trace_pages);
189
190 return page_address(page);
191}
192
e309b41d 193static int
214023c3
SR
194trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
195{
196 int len = (PAGE_SIZE - 1) - s->len;
197 va_list ap;
b3806b43 198 int ret;
214023c3
SR
199
200 if (!len)
201 return 0;
202
203 va_start(ap, fmt);
b3806b43 204 ret = vsnprintf(s->buffer + s->len, len, fmt, ap);
214023c3
SR
205 va_end(ap);
206
b3806b43
SR
207 /* If we can't write it all, don't bother writing anything */
208 if (ret > len)
209 return 0;
210
211 s->len += ret;
214023c3
SR
212
213 return len;
214}
215
e309b41d 216static int
214023c3
SR
217trace_seq_puts(struct trace_seq *s, const char *str)
218{
219 int len = strlen(str);
220
221 if (len > ((PAGE_SIZE - 1) - s->len))
b3806b43 222 return 0;
214023c3
SR
223
224 memcpy(s->buffer + s->len, str, len);
225 s->len += len;
226
227 return len;
228}
229
e309b41d 230static int
214023c3
SR
231trace_seq_putc(struct trace_seq *s, unsigned char c)
232{
233 if (s->len >= (PAGE_SIZE - 1))
234 return 0;
235
236 s->buffer[s->len++] = c;
237
238 return 1;
239}
240
e309b41d 241static int
cb0f12aa
IM
242trace_seq_putmem(struct trace_seq *s, void *mem, size_t len)
243{
244 if (len > ((PAGE_SIZE - 1) - s->len))
245 return 0;
246
247 memcpy(s->buffer + s->len, mem, len);
248 s->len += len;
249
250 return len;
251}
252
5e3ca0ec
IM
253#define HEX_CHARS 17
254
e309b41d 255static int
5e3ca0ec
IM
256trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len)
257{
258 unsigned char hex[HEX_CHARS];
259 unsigned char *data;
260 unsigned char byte;
261 int i, j;
262
263 BUG_ON(len >= HEX_CHARS);
264
265 data = mem;
266
267#ifdef __BIG_ENDIAN
268 for (i = 0, j = 0; i < len; i++) {
269#else
270 for (i = len-1, j = 0; i >= 0; i--) {
271#endif
272 byte = data[i];
273
274 hex[j] = byte & 0x0f;
275 if (hex[j] >= 10)
276 hex[j] += 'a' - 10;
277 else
278 hex[j] += '0';
279 j++;
280
281 hex[j] = byte >> 4;
282 if (hex[j] >= 10)
283 hex[j] += 'a' - 10;
284 else
285 hex[j] += '0';
286 j++;
287 }
288 hex[j] = ' ';
289 j++;
290
291 return trace_seq_putmem(s, hex, j);
292}
293
e309b41d 294static void
214023c3
SR
295trace_seq_reset(struct trace_seq *s)
296{
297 s->len = 0;
298}
299
e309b41d 300static void
214023c3
SR
301trace_print_seq(struct seq_file *m, struct trace_seq *s)
302{
303 int len = s->len >= PAGE_SIZE ? PAGE_SIZE - 1 : s->len;
304
305 s->buffer[len] = 0;
306 seq_puts(m, s->buffer);
307
308 trace_seq_reset(s);
309}
310
e309b41d 311static void
c7aafc54
IM
312flip_trace(struct trace_array_cpu *tr1, struct trace_array_cpu *tr2)
313{
314 struct list_head flip_pages;
315
316 INIT_LIST_HEAD(&flip_pages);
317
93a588f4 318 memcpy(&tr1->trace_head_idx, &tr2->trace_head_idx,
c7aafc54 319 sizeof(struct trace_array_cpu) -
93a588f4 320 offsetof(struct trace_array_cpu, trace_head_idx));
c7aafc54
IM
321
322 check_pages(tr1);
323 check_pages(tr2);
324 list_splice_init(&tr1->trace_pages, &flip_pages);
325 list_splice_init(&tr2->trace_pages, &tr1->trace_pages);
326 list_splice_init(&flip_pages, &tr2->trace_pages);
327 BUG_ON(!list_empty(&flip_pages));
328 check_pages(tr1);
329 check_pages(tr2);
330}
331
e309b41d 332void
bc0c38d1
SR
333update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
334{
335 struct trace_array_cpu *data;
bc0c38d1
SR
336 int i;
337
4c11d7ae 338 WARN_ON_ONCE(!irqs_disabled());
92205c23 339 __raw_spin_lock(&ftrace_max_lock);
bc0c38d1
SR
340 /* clear out all the previous traces */
341 for_each_possible_cpu(i) {
342 data = tr->data[i];
c7aafc54 343 flip_trace(max_tr.data[i], data);
89b2f978 344 tracing_reset(data);
bc0c38d1
SR
345 }
346
347 __update_max_tr(tr, tsk, cpu);
92205c23 348 __raw_spin_unlock(&ftrace_max_lock);
bc0c38d1
SR
349}
350
351/**
352 * update_max_tr_single - only copy one trace over, and reset the rest
353 * @tr - tracer
354 * @tsk - task with the latency
355 * @cpu - the cpu of the buffer to copy.
356 */
e309b41d 357void
bc0c38d1
SR
358update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu)
359{
360 struct trace_array_cpu *data = tr->data[cpu];
bc0c38d1
SR
361 int i;
362
4c11d7ae 363 WARN_ON_ONCE(!irqs_disabled());
92205c23 364 __raw_spin_lock(&ftrace_max_lock);
bc0c38d1
SR
365 for_each_possible_cpu(i)
366 tracing_reset(max_tr.data[i]);
367
c7aafc54 368 flip_trace(max_tr.data[cpu], data);
89b2f978 369 tracing_reset(data);
bc0c38d1
SR
370
371 __update_max_tr(tr, tsk, cpu);
92205c23 372 __raw_spin_unlock(&ftrace_max_lock);
bc0c38d1
SR
373}
374
375int register_tracer(struct tracer *type)
376{
377 struct tracer *t;
378 int len;
379 int ret = 0;
380
381 if (!type->name) {
382 pr_info("Tracer must have a name\n");
383 return -1;
384 }
385
386 mutex_lock(&trace_types_lock);
387 for (t = trace_types; t; t = t->next) {
388 if (strcmp(type->name, t->name) == 0) {
389 /* already found */
390 pr_info("Trace %s already registered\n",
391 type->name);
392 ret = -1;
393 goto out;
394 }
395 }
396
60a11774
SR
397#ifdef CONFIG_FTRACE_STARTUP_TEST
398 if (type->selftest) {
399 struct tracer *saved_tracer = current_trace;
400 struct trace_array_cpu *data;
401 struct trace_array *tr = &global_trace;
402 int saved_ctrl = tr->ctrl;
403 int i;
404 /*
405 * Run a selftest on this tracer.
406 * Here we reset the trace buffer, and set the current
407 * tracer to be this tracer. The tracer can then run some
408 * internal tracing to verify that everything is in order.
409 * If we fail, we do not register this tracer.
410 */
411 for_each_possible_cpu(i) {
60a11774 412 data = tr->data[i];
c7aafc54
IM
413 if (!head_page(data))
414 continue;
60a11774
SR
415 tracing_reset(data);
416 }
417 current_trace = type;
418 tr->ctrl = 0;
419 /* the test is responsible for initializing and enabling */
420 pr_info("Testing tracer %s: ", type->name);
421 ret = type->selftest(type, tr);
422 /* the test is responsible for resetting too */
423 current_trace = saved_tracer;
424 tr->ctrl = saved_ctrl;
425 if (ret) {
426 printk(KERN_CONT "FAILED!\n");
427 goto out;
428 }
1d4db00a
SR
429 /* Only reset on passing, to avoid touching corrupted buffers */
430 for_each_possible_cpu(i) {
431 data = tr->data[i];
432 if (!head_page(data))
433 continue;
434 tracing_reset(data);
435 }
60a11774
SR
436 printk(KERN_CONT "PASSED\n");
437 }
438#endif
439
bc0c38d1
SR
440 type->next = trace_types;
441 trace_types = type;
442 len = strlen(type->name);
443 if (len > max_tracer_type_len)
444 max_tracer_type_len = len;
60a11774 445
bc0c38d1
SR
446 out:
447 mutex_unlock(&trace_types_lock);
448
449 return ret;
450}
451
452void unregister_tracer(struct tracer *type)
453{
454 struct tracer **t;
455 int len;
456
457 mutex_lock(&trace_types_lock);
458 for (t = &trace_types; *t; t = &(*t)->next) {
459 if (*t == type)
460 goto found;
461 }
462 pr_info("Trace %s not registered\n", type->name);
463 goto out;
464
465 found:
466 *t = (*t)->next;
467 if (strlen(type->name) != max_tracer_type_len)
468 goto out;
469
470 max_tracer_type_len = 0;
471 for (t = &trace_types; *t; t = &(*t)->next) {
472 len = strlen((*t)->name);
473 if (len > max_tracer_type_len)
474 max_tracer_type_len = len;
475 }
476 out:
477 mutex_unlock(&trace_types_lock);
478}
479
e309b41d 480void tracing_reset(struct trace_array_cpu *data)
bc0c38d1
SR
481{
482 data->trace_idx = 0;
93a588f4
SR
483 data->trace_head = data->trace_tail = head_page(data);
484 data->trace_head_idx = 0;
485 data->trace_tail_idx = 0;
bc0c38d1
SR
486}
487
bc0c38d1
SR
488#define SAVED_CMDLINES 128
489static unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
490static unsigned map_cmdline_to_pid[SAVED_CMDLINES];
491static char saved_cmdlines[SAVED_CMDLINES][TASK_COMM_LEN];
492static int cmdline_idx;
493static DEFINE_SPINLOCK(trace_cmdline_lock);
494atomic_t trace_record_cmdline_disabled;
495
496static void trace_init_cmdlines(void)
497{
498 memset(&map_pid_to_cmdline, -1, sizeof(map_pid_to_cmdline));
499 memset(&map_cmdline_to_pid, -1, sizeof(map_cmdline_to_pid));
500 cmdline_idx = 0;
501}
502
e309b41d 503void trace_stop_cmdline_recording(void);
bc0c38d1 504
e309b41d 505static void trace_save_cmdline(struct task_struct *tsk)
bc0c38d1
SR
506{
507 unsigned map;
508 unsigned idx;
509
510 if (!tsk->pid || unlikely(tsk->pid > PID_MAX_DEFAULT))
511 return;
512
513 /*
514 * It's not the end of the world if we don't get
515 * the lock, but we also don't want to spin
516 * nor do we want to disable interrupts,
517 * so if we miss here, then better luck next time.
518 */
519 if (!spin_trylock(&trace_cmdline_lock))
520 return;
521
522 idx = map_pid_to_cmdline[tsk->pid];
523 if (idx >= SAVED_CMDLINES) {
524 idx = (cmdline_idx + 1) % SAVED_CMDLINES;
525
526 map = map_cmdline_to_pid[idx];
527 if (map <= PID_MAX_DEFAULT)
528 map_pid_to_cmdline[map] = (unsigned)-1;
529
530 map_pid_to_cmdline[tsk->pid] = idx;
531
532 cmdline_idx = idx;
533 }
534
535 memcpy(&saved_cmdlines[idx], tsk->comm, TASK_COMM_LEN);
536
537 spin_unlock(&trace_cmdline_lock);
538}
539
e309b41d 540static char *trace_find_cmdline(int pid)
bc0c38d1
SR
541{
542 char *cmdline = "<...>";
543 unsigned map;
544
545 if (!pid)
546 return "<idle>";
547
548 if (pid > PID_MAX_DEFAULT)
549 goto out;
550
551 map = map_pid_to_cmdline[pid];
552 if (map >= SAVED_CMDLINES)
553 goto out;
554
555 cmdline = saved_cmdlines[map];
556
557 out:
558 return cmdline;
559}
560
e309b41d 561void tracing_record_cmdline(struct task_struct *tsk)
bc0c38d1
SR
562{
563 if (atomic_read(&trace_record_cmdline_disabled))
564 return;
565
566 trace_save_cmdline(tsk);
567}
568
e309b41d 569static inline struct list_head *
93a588f4
SR
570trace_next_list(struct trace_array_cpu *data, struct list_head *next)
571{
572 /*
573 * Roundrobin - but skip the head (which is not a real page):
574 */
575 next = next->next;
576 if (unlikely(next == &data->trace_pages))
577 next = next->next;
578 BUG_ON(next == &data->trace_pages);
579
580 return next;
581}
582
e309b41d 583static inline void *
93a588f4
SR
584trace_next_page(struct trace_array_cpu *data, void *addr)
585{
586 struct list_head *next;
587 struct page *page;
588
589 page = virt_to_page(addr);
590
591 next = trace_next_list(data, &page->lru);
592 page = list_entry(next, struct page, lru);
593
594 return page_address(page);
595}
596
e309b41d 597static inline struct trace_entry *
c7aafc54 598tracing_get_trace_entry(struct trace_array *tr, struct trace_array_cpu *data)
bc0c38d1
SR
599{
600 unsigned long idx, idx_next;
601 struct trace_entry *entry;
602
4c11d7ae 603 data->trace_idx++;
93a588f4 604 idx = data->trace_head_idx;
bc0c38d1
SR
605 idx_next = idx + 1;
606
c7aafc54
IM
607 BUG_ON(idx * TRACE_ENTRY_SIZE >= PAGE_SIZE);
608
93a588f4 609 entry = data->trace_head + idx * TRACE_ENTRY_SIZE;
4c11d7ae
SR
610
611 if (unlikely(idx_next >= ENTRIES_PER_PAGE)) {
93a588f4 612 data->trace_head = trace_next_page(data, data->trace_head);
bc0c38d1
SR
613 idx_next = 0;
614 }
615
93a588f4
SR
616 if (data->trace_head == data->trace_tail &&
617 idx_next == data->trace_tail_idx) {
618 /* overrun */
619 data->trace_tail_idx++;
620 if (data->trace_tail_idx >= ENTRIES_PER_PAGE) {
621 data->trace_tail =
622 trace_next_page(data, data->trace_tail);
623 data->trace_tail_idx = 0;
624 }
625 }
626
627 data->trace_head_idx = idx_next;
bc0c38d1
SR
628
629 return entry;
630}
631
e309b41d 632static inline void
c7aafc54 633tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags)
bc0c38d1
SR
634{
635 struct task_struct *tsk = current;
636 unsigned long pc;
637
638 pc = preempt_count();
639
c7aafc54
IM
640 entry->preempt_count = pc & 0xff;
641 entry->pid = tsk->pid;
750ed1a4 642 entry->t = ftrace_now(raw_smp_processor_id());
bc0c38d1
SR
643 entry->flags = (irqs_disabled_flags(flags) ? TRACE_FLAG_IRQS_OFF : 0) |
644 ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) |
645 ((pc & SOFTIRQ_MASK) ? TRACE_FLAG_SOFTIRQ : 0) |
646 (need_resched() ? TRACE_FLAG_NEED_RESCHED : 0);
647}
648
e309b41d 649void
6fb44b71
SR
650trace_function(struct trace_array *tr, struct trace_array_cpu *data,
651 unsigned long ip, unsigned long parent_ip, unsigned long flags)
bc0c38d1
SR
652{
653 struct trace_entry *entry;
dcb6308f 654 unsigned long irq_flags;
bc0c38d1 655
92205c23
SR
656 raw_local_irq_save(irq_flags);
657 __raw_spin_lock(&data->lock);
c7aafc54 658 entry = tracing_get_trace_entry(tr, data);
bc0c38d1 659 tracing_generic_entry_update(entry, flags);
c7aafc54
IM
660 entry->type = TRACE_FN;
661 entry->fn.ip = ip;
662 entry->fn.parent_ip = parent_ip;
92205c23
SR
663 __raw_spin_unlock(&data->lock);
664 raw_local_irq_restore(irq_flags);
bc0c38d1
SR
665}
666
e309b41d 667void
2e0f5761
IM
668ftrace(struct trace_array *tr, struct trace_array_cpu *data,
669 unsigned long ip, unsigned long parent_ip, unsigned long flags)
670{
671 if (likely(!atomic_read(&data->disabled)))
6fb44b71 672 trace_function(tr, data, ip, parent_ip, flags);
2e0f5761
IM
673}
674
e309b41d 675void
4e655519
IM
676__trace_special(void *__tr, void *__data,
677 unsigned long arg1, unsigned long arg2, unsigned long arg3)
f0a920d5 678{
4e655519
IM
679 struct trace_array_cpu *data = __data;
680 struct trace_array *tr = __tr;
f0a920d5 681 struct trace_entry *entry;
dcb6308f 682 unsigned long irq_flags;
f0a920d5 683
92205c23
SR
684 raw_local_irq_save(irq_flags);
685 __raw_spin_lock(&data->lock);
f0a920d5
IM
686 entry = tracing_get_trace_entry(tr, data);
687 tracing_generic_entry_update(entry, 0);
688 entry->type = TRACE_SPECIAL;
689 entry->special.arg1 = arg1;
690 entry->special.arg2 = arg2;
691 entry->special.arg3 = arg3;
92205c23
SR
692 __raw_spin_unlock(&data->lock);
693 raw_local_irq_restore(irq_flags);
017730c1
IM
694
695 trace_wake_up();
86387f7e
IM
696}
697
698void __trace_stack(struct trace_array *tr,
699 struct trace_array_cpu *data,
700 unsigned long flags,
701 int skip)
702{
703 struct trace_entry *entry;
704 struct stack_trace trace;
705
706 if (!(trace_flags & TRACE_ITER_STACKTRACE))
707 return;
708
709 entry = tracing_get_trace_entry(tr, data);
710 tracing_generic_entry_update(entry, flags);
711 entry->type = TRACE_STACK;
712
713 memset(&entry->stack, 0, sizeof(entry->stack));
714
715 trace.nr_entries = 0;
716 trace.max_entries = FTRACE_STACK_ENTRIES;
717 trace.skip = skip;
718 trace.entries = entry->stack.caller;
719
720 save_stack_trace(&trace);
f0a920d5
IM
721}
722
e309b41d 723void
bc0c38d1
SR
724tracing_sched_switch_trace(struct trace_array *tr,
725 struct trace_array_cpu *data,
86387f7e
IM
726 struct task_struct *prev,
727 struct task_struct *next,
bc0c38d1
SR
728 unsigned long flags)
729{
730 struct trace_entry *entry;
dcb6308f 731 unsigned long irq_flags;
bc0c38d1 732
92205c23
SR
733 raw_local_irq_save(irq_flags);
734 __raw_spin_lock(&data->lock);
c7aafc54 735 entry = tracing_get_trace_entry(tr, data);
bc0c38d1
SR
736 tracing_generic_entry_update(entry, flags);
737 entry->type = TRACE_CTX;
738 entry->ctx.prev_pid = prev->pid;
739 entry->ctx.prev_prio = prev->prio;
740 entry->ctx.prev_state = prev->state;
741 entry->ctx.next_pid = next->pid;
742 entry->ctx.next_prio = next->prio;
bac524d3 743 entry->ctx.next_state = next->state;
86387f7e 744 __trace_stack(tr, data, flags, 4);
92205c23
SR
745 __raw_spin_unlock(&data->lock);
746 raw_local_irq_restore(irq_flags);
bc0c38d1
SR
747}
748
57422797
IM
749void
750tracing_sched_wakeup_trace(struct trace_array *tr,
751 struct trace_array_cpu *data,
86387f7e
IM
752 struct task_struct *wakee,
753 struct task_struct *curr,
57422797
IM
754 unsigned long flags)
755{
756 struct trace_entry *entry;
757 unsigned long irq_flags;
758
92205c23
SR
759 raw_local_irq_save(irq_flags);
760 __raw_spin_lock(&data->lock);
57422797
IM
761 entry = tracing_get_trace_entry(tr, data);
762 tracing_generic_entry_update(entry, flags);
763 entry->type = TRACE_WAKE;
764 entry->ctx.prev_pid = curr->pid;
765 entry->ctx.prev_prio = curr->prio;
766 entry->ctx.prev_state = curr->state;
767 entry->ctx.next_pid = wakee->pid;
768 entry->ctx.next_prio = wakee->prio;
bac524d3 769 entry->ctx.next_state = wakee->state;
86387f7e 770 __trace_stack(tr, data, flags, 5);
92205c23
SR
771 __raw_spin_unlock(&data->lock);
772 raw_local_irq_restore(irq_flags);
017730c1
IM
773
774 trace_wake_up();
57422797
IM
775}
776
2e0f5761 777#ifdef CONFIG_FTRACE
e309b41d 778static void
2e0f5761
IM
779function_trace_call(unsigned long ip, unsigned long parent_ip)
780{
781 struct trace_array *tr = &global_trace;
782 struct trace_array_cpu *data;
783 unsigned long flags;
784 long disabled;
785 int cpu;
786
787 if (unlikely(!tracer_enabled))
788 return;
789
790 local_irq_save(flags);
791 cpu = raw_smp_processor_id();
792 data = tr->data[cpu];
793 disabled = atomic_inc_return(&data->disabled);
794
795 if (likely(disabled == 1))
6fb44b71 796 trace_function(tr, data, ip, parent_ip, flags);
2e0f5761
IM
797
798 atomic_dec(&data->disabled);
799 local_irq_restore(flags);
800}
801
802static struct ftrace_ops trace_ops __read_mostly =
803{
804 .func = function_trace_call,
805};
806
e309b41d 807void tracing_start_function_trace(void)
2e0f5761
IM
808{
809 register_ftrace_function(&trace_ops);
810}
811
e309b41d 812void tracing_stop_function_trace(void)
2e0f5761
IM
813{
814 unregister_ftrace_function(&trace_ops);
815}
816#endif
817
bc0c38d1
SR
818enum trace_file_type {
819 TRACE_FILE_LAT_FMT = 1,
820};
821
822static struct trace_entry *
4c11d7ae
SR
823trace_entry_idx(struct trace_array *tr, struct trace_array_cpu *data,
824 struct trace_iterator *iter, int cpu)
bc0c38d1 825{
4c11d7ae
SR
826 struct page *page;
827 struct trace_entry *array;
bc0c38d1 828
4c11d7ae 829 if (iter->next_idx[cpu] >= tr->entries ||
b3806b43
SR
830 iter->next_idx[cpu] >= data->trace_idx ||
831 (data->trace_head == data->trace_tail &&
832 data->trace_head_idx == data->trace_tail_idx))
bc0c38d1
SR
833 return NULL;
834
4c11d7ae 835 if (!iter->next_page[cpu]) {
93a588f4
SR
836 /* Initialize the iterator for this cpu trace buffer */
837 WARN_ON(!data->trace_tail);
838 page = virt_to_page(data->trace_tail);
839 iter->next_page[cpu] = &page->lru;
840 iter->next_page_idx[cpu] = data->trace_tail_idx;
4c11d7ae 841 }
bc0c38d1 842
4c11d7ae 843 page = list_entry(iter->next_page[cpu], struct page, lru);
c7aafc54
IM
844 BUG_ON(&data->trace_pages == &page->lru);
845
4c11d7ae
SR
846 array = page_address(page);
847
93a588f4 848 WARN_ON(iter->next_page_idx[cpu] >= ENTRIES_PER_PAGE);
4c11d7ae 849 return &array[iter->next_page_idx[cpu]];
bc0c38d1
SR
850}
851
e309b41d 852static struct trace_entry *
bc0c38d1
SR
853find_next_entry(struct trace_iterator *iter, int *ent_cpu)
854{
855 struct trace_array *tr = iter->tr;
856 struct trace_entry *ent, *next = NULL;
857 int next_cpu = -1;
858 int cpu;
859
860 for_each_possible_cpu(cpu) {
c7aafc54 861 if (!head_page(tr->data[cpu]))
bc0c38d1 862 continue;
4c11d7ae 863 ent = trace_entry_idx(tr, tr->data[cpu], iter, cpu);
cdd31cd2
IM
864 /*
865 * Pick the entry with the smallest timestamp:
866 */
867 if (ent && (!next || ent->t < next->t)) {
bc0c38d1
SR
868 next = ent;
869 next_cpu = cpu;
870 }
871 }
872
873 if (ent_cpu)
874 *ent_cpu = next_cpu;
875
876 return next;
877}
878
e309b41d 879static void trace_iterator_increment(struct trace_iterator *iter)
bc0c38d1 880{
b3806b43
SR
881 iter->idx++;
882 iter->next_idx[iter->cpu]++;
883 iter->next_page_idx[iter->cpu]++;
8c523a9d 884
b3806b43
SR
885 if (iter->next_page_idx[iter->cpu] >= ENTRIES_PER_PAGE) {
886 struct trace_array_cpu *data = iter->tr->data[iter->cpu];
bc0c38d1 887
b3806b43
SR
888 iter->next_page_idx[iter->cpu] = 0;
889 iter->next_page[iter->cpu] =
890 trace_next_list(data, iter->next_page[iter->cpu]);
891 }
892}
bc0c38d1 893
e309b41d 894static void trace_consume(struct trace_iterator *iter)
b3806b43
SR
895{
896 struct trace_array_cpu *data = iter->tr->data[iter->cpu];
897
898 data->trace_tail_idx++;
899 if (data->trace_tail_idx >= ENTRIES_PER_PAGE) {
900 data->trace_tail = trace_next_page(data, data->trace_tail);
901 data->trace_tail_idx = 0;
902 }
4e3c3333 903
b3806b43
SR
904 /* Check if we empty it, then reset the index */
905 if (data->trace_head == data->trace_tail &&
906 data->trace_head_idx == data->trace_tail_idx)
907 data->trace_idx = 0;
b3806b43
SR
908}
909
e309b41d 910static void *find_next_entry_inc(struct trace_iterator *iter)
b3806b43
SR
911{
912 struct trace_entry *next;
913 int next_cpu = -1;
914
915 next = find_next_entry(iter, &next_cpu);
93a588f4 916
4e3c3333
IM
917 iter->prev_ent = iter->ent;
918 iter->prev_cpu = iter->cpu;
919
bc0c38d1
SR
920 iter->ent = next;
921 iter->cpu = next_cpu;
922
b3806b43
SR
923 if (next)
924 trace_iterator_increment(iter);
925
bc0c38d1
SR
926 return next ? iter : NULL;
927}
928
e309b41d 929static void *s_next(struct seq_file *m, void *v, loff_t *pos)
bc0c38d1
SR
930{
931 struct trace_iterator *iter = m->private;
bc0c38d1
SR
932 void *last_ent = iter->ent;
933 int i = (int)*pos;
4e3c3333 934 void *ent;
bc0c38d1
SR
935
936 (*pos)++;
937
938 /* can't go backwards */
939 if (iter->idx > i)
940 return NULL;
941
942 if (iter->idx < 0)
943 ent = find_next_entry_inc(iter);
944 else
945 ent = iter;
946
947 while (ent && iter->idx < i)
948 ent = find_next_entry_inc(iter);
949
950 iter->pos = *pos;
951
952 if (last_ent && !ent)
953 seq_puts(m, "\n\nvim:ft=help\n");
954
955 return ent;
956}
957
958static void *s_start(struct seq_file *m, loff_t *pos)
959{
960 struct trace_iterator *iter = m->private;
961 void *p = NULL;
962 loff_t l = 0;
963 int i;
964
965 mutex_lock(&trace_types_lock);
966
967 if (!current_trace || current_trace != iter->trace)
968 return NULL;
969
970 atomic_inc(&trace_record_cmdline_disabled);
971
972 /* let the tracer grab locks here if needed */
973 if (current_trace->start)
974 current_trace->start(iter);
975
976 if (*pos != iter->pos) {
977 iter->ent = NULL;
978 iter->cpu = 0;
979 iter->idx = -1;
4e3c3333
IM
980 iter->prev_ent = NULL;
981 iter->prev_cpu = -1;
bc0c38d1 982
4c11d7ae 983 for_each_possible_cpu(i) {
bc0c38d1 984 iter->next_idx[i] = 0;
4c11d7ae
SR
985 iter->next_page[i] = NULL;
986 }
bc0c38d1
SR
987
988 for (p = iter; p && l < *pos; p = s_next(m, p, &l))
989 ;
990
991 } else {
4c11d7ae 992 l = *pos - 1;
bc0c38d1
SR
993 p = s_next(m, p, &l);
994 }
995
996 return p;
997}
998
999static void s_stop(struct seq_file *m, void *p)
1000{
1001 struct trace_iterator *iter = m->private;
1002
1003 atomic_dec(&trace_record_cmdline_disabled);
1004
1005 /* let the tracer release locks here if needed */
1006 if (current_trace && current_trace == iter->trace && iter->trace->stop)
1007 iter->trace->stop(iter);
1008
1009 mutex_unlock(&trace_types_lock);
1010}
1011
b3806b43 1012static int
214023c3 1013seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
bc0c38d1
SR
1014{
1015#ifdef CONFIG_KALLSYMS
1016 char str[KSYM_SYMBOL_LEN];
1017
1018 kallsyms_lookup(address, NULL, NULL, NULL, str);
1019
b3806b43 1020 return trace_seq_printf(s, fmt, str);
bc0c38d1 1021#endif
b3806b43 1022 return 1;
bc0c38d1
SR
1023}
1024
b3806b43 1025static int
214023c3
SR
1026seq_print_sym_offset(struct trace_seq *s, const char *fmt,
1027 unsigned long address)
bc0c38d1
SR
1028{
1029#ifdef CONFIG_KALLSYMS
1030 char str[KSYM_SYMBOL_LEN];
1031
1032 sprint_symbol(str, address);
b3806b43 1033 return trace_seq_printf(s, fmt, str);
bc0c38d1 1034#endif
b3806b43 1035 return 1;
bc0c38d1
SR
1036}
1037
1038#ifndef CONFIG_64BIT
1039# define IP_FMT "%08lx"
1040#else
1041# define IP_FMT "%016lx"
1042#endif
1043
e309b41d 1044static int
214023c3 1045seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
bc0c38d1 1046{
b3806b43
SR
1047 int ret;
1048
1049 if (!ip)
1050 return trace_seq_printf(s, "0");
bc0c38d1
SR
1051
1052 if (sym_flags & TRACE_ITER_SYM_OFFSET)
b3806b43 1053 ret = seq_print_sym_offset(s, "%s", ip);
bc0c38d1 1054 else
b3806b43
SR
1055 ret = seq_print_sym_short(s, "%s", ip);
1056
1057 if (!ret)
1058 return 0;
bc0c38d1
SR
1059
1060 if (sym_flags & TRACE_ITER_SYM_ADDR)
b3806b43
SR
1061 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
1062 return ret;
bc0c38d1
SR
1063}
1064
e309b41d 1065static void print_lat_help_header(struct seq_file *m)
bc0c38d1
SR
1066{
1067 seq_puts(m, "# _------=> CPU# \n");
1068 seq_puts(m, "# / _-----=> irqs-off \n");
1069 seq_puts(m, "# | / _----=> need-resched \n");
1070 seq_puts(m, "# || / _---=> hardirq/softirq \n");
1071 seq_puts(m, "# ||| / _--=> preempt-depth \n");
1072 seq_puts(m, "# |||| / \n");
1073 seq_puts(m, "# ||||| delay \n");
1074 seq_puts(m, "# cmd pid ||||| time | caller \n");
1075 seq_puts(m, "# \\ / ||||| \\ | / \n");
1076}
1077
e309b41d 1078static void print_func_help_header(struct seq_file *m)
bc0c38d1
SR
1079{
1080 seq_puts(m, "# TASK-PID CPU# TIMESTAMP FUNCTION\n");
1081 seq_puts(m, "# | | | | |\n");
1082}
1083
1084
e309b41d 1085static void
bc0c38d1
SR
1086print_trace_header(struct seq_file *m, struct trace_iterator *iter)
1087{
1088 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
1089 struct trace_array *tr = iter->tr;
1090 struct trace_array_cpu *data = tr->data[tr->cpu];
1091 struct tracer *type = current_trace;
4c11d7ae
SR
1092 unsigned long total = 0;
1093 unsigned long entries = 0;
bc0c38d1
SR
1094 int cpu;
1095 const char *name = "preemption";
1096
1097 if (type)
1098 name = type->name;
1099
1100 for_each_possible_cpu(cpu) {
c7aafc54 1101 if (head_page(tr->data[cpu])) {
4c11d7ae
SR
1102 total += tr->data[cpu]->trace_idx;
1103 if (tr->data[cpu]->trace_idx > tr->entries)
bc0c38d1 1104 entries += tr->entries;
4c11d7ae 1105 else
bc0c38d1
SR
1106 entries += tr->data[cpu]->trace_idx;
1107 }
1108 }
1109
1110 seq_printf(m, "%s latency trace v1.1.5 on %s\n",
1111 name, UTS_RELEASE);
1112 seq_puts(m, "-----------------------------------"
1113 "---------------------------------\n");
1114 seq_printf(m, " latency: %lu us, #%lu/%lu, CPU#%d |"
1115 " (M:%s VP:%d, KP:%d, SP:%d HP:%d",
57f50be1 1116 nsecs_to_usecs(data->saved_latency),
bc0c38d1 1117 entries,
4c11d7ae 1118 total,
bc0c38d1
SR
1119 tr->cpu,
1120#if defined(CONFIG_PREEMPT_NONE)
1121 "server",
1122#elif defined(CONFIG_PREEMPT_VOLUNTARY)
1123 "desktop",
1124#elif defined(CONFIG_PREEMPT_DESKTOP)
1125 "preempt",
1126#else
1127 "unknown",
1128#endif
1129 /* These are reserved for later use */
1130 0, 0, 0, 0);
1131#ifdef CONFIG_SMP
1132 seq_printf(m, " #P:%d)\n", num_online_cpus());
1133#else
1134 seq_puts(m, ")\n");
1135#endif
1136 seq_puts(m, " -----------------\n");
1137 seq_printf(m, " | task: %.16s-%d "
1138 "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n",
1139 data->comm, data->pid, data->uid, data->nice,
1140 data->policy, data->rt_priority);
1141 seq_puts(m, " -----------------\n");
1142
1143 if (data->critical_start) {
1144 seq_puts(m, " => started at: ");
214023c3
SR
1145 seq_print_ip_sym(&iter->seq, data->critical_start, sym_flags);
1146 trace_print_seq(m, &iter->seq);
bc0c38d1 1147 seq_puts(m, "\n => ended at: ");
214023c3
SR
1148 seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags);
1149 trace_print_seq(m, &iter->seq);
bc0c38d1
SR
1150 seq_puts(m, "\n");
1151 }
1152
1153 seq_puts(m, "\n");
1154}
1155
e309b41d 1156static void
214023c3 1157lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
bc0c38d1
SR
1158{
1159 int hardirq, softirq;
1160 char *comm;
1161
1162 comm = trace_find_cmdline(entry->pid);
1163
214023c3
SR
1164 trace_seq_printf(s, "%8.8s-%-5d ", comm, entry->pid);
1165 trace_seq_printf(s, "%d", cpu);
1166 trace_seq_printf(s, "%c%c",
1167 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' : '.',
1168 ((entry->flags & TRACE_FLAG_NEED_RESCHED) ? 'N' : '.'));
bc0c38d1
SR
1169
1170 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
1171 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
1172 if (hardirq && softirq)
214023c3 1173 trace_seq_putc(s, 'H');
bc0c38d1
SR
1174 else {
1175 if (hardirq)
214023c3 1176 trace_seq_putc(s, 'h');
bc0c38d1
SR
1177 else {
1178 if (softirq)
214023c3 1179 trace_seq_putc(s, 's');
bc0c38d1 1180 else
214023c3 1181 trace_seq_putc(s, '.');
bc0c38d1
SR
1182 }
1183 }
1184
1185 if (entry->preempt_count)
214023c3 1186 trace_seq_printf(s, "%x", entry->preempt_count);
bc0c38d1 1187 else
214023c3 1188 trace_seq_puts(s, ".");
bc0c38d1
SR
1189}
1190
1191unsigned long preempt_mark_thresh = 100;
1192
e309b41d 1193static void
214023c3 1194lat_print_timestamp(struct trace_seq *s, unsigned long long abs_usecs,
bc0c38d1
SR
1195 unsigned long rel_usecs)
1196{
214023c3 1197 trace_seq_printf(s, " %4lldus", abs_usecs);
bc0c38d1 1198 if (rel_usecs > preempt_mark_thresh)
214023c3 1199 trace_seq_puts(s, "!: ");
bc0c38d1 1200 else if (rel_usecs > 1)
214023c3 1201 trace_seq_puts(s, "+: ");
bc0c38d1 1202 else
214023c3 1203 trace_seq_puts(s, " : ");
bc0c38d1
SR
1204}
1205
1206static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
1207
e309b41d 1208static int
214023c3 1209print_lat_fmt(struct trace_iterator *iter, unsigned int trace_idx, int cpu)
bc0c38d1 1210{
214023c3 1211 struct trace_seq *s = &iter->seq;
bc0c38d1
SR
1212 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
1213 struct trace_entry *next_entry = find_next_entry(iter, NULL);
1214 unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
1215 struct trace_entry *entry = iter->ent;
1216 unsigned long abs_usecs;
1217 unsigned long rel_usecs;
1218 char *comm;
bac524d3 1219 int S, T;
86387f7e 1220 int i;
bc0c38d1
SR
1221
1222 if (!next_entry)
1223 next_entry = entry;
1224 rel_usecs = ns2usecs(next_entry->t - entry->t);
1225 abs_usecs = ns2usecs(entry->t - iter->tr->time_start);
1226
1227 if (verbose) {
1228 comm = trace_find_cmdline(entry->pid);
214023c3
SR
1229 trace_seq_printf(s, "%16s %5d %d %d %08x %08x [%08lx]"
1230 " %ld.%03ldms (+%ld.%03ldms): ",
1231 comm,
1232 entry->pid, cpu, entry->flags,
1233 entry->preempt_count, trace_idx,
1234 ns2usecs(entry->t),
1235 abs_usecs/1000,
1236 abs_usecs % 1000, rel_usecs/1000,
1237 rel_usecs % 1000);
bc0c38d1 1238 } else {
f29c73fe
IM
1239 lat_print_generic(s, entry, cpu);
1240 lat_print_timestamp(s, abs_usecs, rel_usecs);
bc0c38d1
SR
1241 }
1242 switch (entry->type) {
1243 case TRACE_FN:
214023c3
SR
1244 seq_print_ip_sym(s, entry->fn.ip, sym_flags);
1245 trace_seq_puts(s, " (");
1246 seq_print_ip_sym(s, entry->fn.parent_ip, sym_flags);
1247 trace_seq_puts(s, ")\n");
bc0c38d1
SR
1248 break;
1249 case TRACE_CTX:
57422797 1250 case TRACE_WAKE:
bc0c38d1
SR
1251 S = entry->ctx.prev_state < sizeof(state_to_char) ?
1252 state_to_char[entry->ctx.prev_state] : 'X';
bac524d3
PZ
1253 T = entry->ctx.next_state < sizeof(state_to_char) ?
1254 state_to_char[entry->ctx.next_state] : 'X';
1255
bc0c38d1 1256 comm = trace_find_cmdline(entry->ctx.next_pid);
bac524d3 1257 trace_seq_printf(s, " %5d:%3d:%c %s %5d:%3d:%c %s\n",
214023c3
SR
1258 entry->ctx.prev_pid,
1259 entry->ctx.prev_prio,
57422797 1260 S, entry->type == TRACE_CTX ? "==>" : " +",
214023c3
SR
1261 entry->ctx.next_pid,
1262 entry->ctx.next_prio,
bac524d3 1263 T, comm);
bc0c38d1 1264 break;
f0a920d5 1265 case TRACE_SPECIAL:
88a4216c 1266 trace_seq_printf(s, "# %ld %ld %ld\n",
f0a920d5
IM
1267 entry->special.arg1,
1268 entry->special.arg2,
1269 entry->special.arg3);
1270 break;
86387f7e
IM
1271 case TRACE_STACK:
1272 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
1273 if (i)
1274 trace_seq_puts(s, " <= ");
1275 seq_print_ip_sym(s, entry->stack.caller[i], sym_flags);
1276 }
1277 trace_seq_puts(s, "\n");
1278 break;
89b2f978 1279 default:
214023c3 1280 trace_seq_printf(s, "Unknown type %d\n", entry->type);
bc0c38d1 1281 }
f9896bf3 1282 return 1;
bc0c38d1
SR
1283}
1284
e309b41d 1285static int print_trace_fmt(struct trace_iterator *iter)
bc0c38d1 1286{
214023c3 1287 struct trace_seq *s = &iter->seq;
bc0c38d1 1288 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
4e3c3333 1289 struct trace_entry *entry;
bc0c38d1
SR
1290 unsigned long usec_rem;
1291 unsigned long long t;
1292 unsigned long secs;
1293 char *comm;
b3806b43 1294 int ret;
bac524d3 1295 int S, T;
86387f7e 1296 int i;
bc0c38d1 1297
4e3c3333
IM
1298 entry = iter->ent;
1299
bc0c38d1
SR
1300 comm = trace_find_cmdline(iter->ent->pid);
1301
cdd31cd2 1302 t = ns2usecs(entry->t);
bc0c38d1
SR
1303 usec_rem = do_div(t, 1000000ULL);
1304 secs = (unsigned long)t;
1305
f29c73fe
IM
1306 ret = trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid);
1307 if (!ret)
1308 return 0;
1309 ret = trace_seq_printf(s, "[%02d] ", iter->cpu);
1310 if (!ret)
1311 return 0;
1312 ret = trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem);
1313 if (!ret)
1314 return 0;
bc0c38d1
SR
1315
1316 switch (entry->type) {
1317 case TRACE_FN:
b3806b43
SR
1318 ret = seq_print_ip_sym(s, entry->fn.ip, sym_flags);
1319 if (!ret)
1320 return 0;
bc0c38d1
SR
1321 if ((sym_flags & TRACE_ITER_PRINT_PARENT) &&
1322 entry->fn.parent_ip) {
b3806b43
SR
1323 ret = trace_seq_printf(s, " <-");
1324 if (!ret)
1325 return 0;
1326 ret = seq_print_ip_sym(s, entry->fn.parent_ip,
1327 sym_flags);
1328 if (!ret)
1329 return 0;
bc0c38d1 1330 }
b3806b43
SR
1331 ret = trace_seq_printf(s, "\n");
1332 if (!ret)
1333 return 0;
bc0c38d1
SR
1334 break;
1335 case TRACE_CTX:
57422797 1336 case TRACE_WAKE:
bc0c38d1
SR
1337 S = entry->ctx.prev_state < sizeof(state_to_char) ?
1338 state_to_char[entry->ctx.prev_state] : 'X';
bac524d3
PZ
1339 T = entry->ctx.next_state < sizeof(state_to_char) ?
1340 state_to_char[entry->ctx.next_state] : 'X';
1341 ret = trace_seq_printf(s, " %5d:%3d:%c %s %5d:%3d:%c\n",
b3806b43
SR
1342 entry->ctx.prev_pid,
1343 entry->ctx.prev_prio,
1344 S,
57422797 1345 entry->type == TRACE_CTX ? "==>" : " +",
b3806b43 1346 entry->ctx.next_pid,
bac524d3
PZ
1347 entry->ctx.next_prio,
1348 T);
b3806b43
SR
1349 if (!ret)
1350 return 0;
bc0c38d1 1351 break;
f0a920d5 1352 case TRACE_SPECIAL:
88a4216c 1353 ret = trace_seq_printf(s, "# %ld %ld %ld\n",
f0a920d5
IM
1354 entry->special.arg1,
1355 entry->special.arg2,
1356 entry->special.arg3);
1357 if (!ret)
1358 return 0;
1359 break;
86387f7e
IM
1360 case TRACE_STACK:
1361 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
1362 if (i) {
1363 ret = trace_seq_puts(s, " <= ");
1364 if (!ret)
1365 return 0;
1366 }
1367 ret = seq_print_ip_sym(s, entry->stack.caller[i],
1368 sym_flags);
1369 if (!ret)
1370 return 0;
1371 }
1372 ret = trace_seq_puts(s, "\n");
1373 if (!ret)
1374 return 0;
1375 break;
bc0c38d1 1376 }
b3806b43 1377 return 1;
bc0c38d1
SR
1378}
1379
e309b41d 1380static int print_raw_fmt(struct trace_iterator *iter)
f9896bf3
IM
1381{
1382 struct trace_seq *s = &iter->seq;
1383 struct trace_entry *entry;
1384 int ret;
bac524d3 1385 int S, T;
f9896bf3
IM
1386
1387 entry = iter->ent;
1388
1389 ret = trace_seq_printf(s, "%d %d %llu ",
1390 entry->pid, iter->cpu, entry->t);
1391 if (!ret)
1392 return 0;
1393
1394 switch (entry->type) {
1395 case TRACE_FN:
1396 ret = trace_seq_printf(s, "%x %x\n",
1397 entry->fn.ip, entry->fn.parent_ip);
1398 if (!ret)
1399 return 0;
1400 break;
1401 case TRACE_CTX:
57422797 1402 case TRACE_WAKE:
f9896bf3
IM
1403 S = entry->ctx.prev_state < sizeof(state_to_char) ?
1404 state_to_char[entry->ctx.prev_state] : 'X';
bac524d3
PZ
1405 T = entry->ctx.next_state < sizeof(state_to_char) ?
1406 state_to_char[entry->ctx.next_state] : 'X';
57422797
IM
1407 if (entry->type == TRACE_WAKE)
1408 S = '+';
bac524d3 1409 ret = trace_seq_printf(s, "%d %d %c %d %d %c\n",
f9896bf3
IM
1410 entry->ctx.prev_pid,
1411 entry->ctx.prev_prio,
1412 S,
1413 entry->ctx.next_pid,
bac524d3
PZ
1414 entry->ctx.next_prio,
1415 T);
f9896bf3
IM
1416 if (!ret)
1417 return 0;
1418 break;
f0a920d5 1419 case TRACE_SPECIAL:
86387f7e 1420 case TRACE_STACK:
88a4216c 1421 ret = trace_seq_printf(s, "# %ld %ld %ld\n",
f0a920d5
IM
1422 entry->special.arg1,
1423 entry->special.arg2,
1424 entry->special.arg3);
1425 if (!ret)
1426 return 0;
1427 break;
f9896bf3
IM
1428 }
1429 return 1;
1430}
1431
cb0f12aa
IM
1432#define SEQ_PUT_FIELD_RET(s, x) \
1433do { \
1434 if (!trace_seq_putmem(s, &(x), sizeof(x))) \
1435 return 0; \
1436} while (0)
1437
5e3ca0ec
IM
1438#define SEQ_PUT_HEX_FIELD_RET(s, x) \
1439do { \
1440 if (!trace_seq_putmem_hex(s, &(x), sizeof(x))) \
1441 return 0; \
1442} while (0)
1443
e309b41d 1444static int print_hex_fmt(struct trace_iterator *iter)
5e3ca0ec
IM
1445{
1446 struct trace_seq *s = &iter->seq;
1447 unsigned char newline = '\n';
1448 struct trace_entry *entry;
bac524d3 1449 int S, T;
5e3ca0ec
IM
1450
1451 entry = iter->ent;
1452
1453 SEQ_PUT_HEX_FIELD_RET(s, entry->pid);
1454 SEQ_PUT_HEX_FIELD_RET(s, iter->cpu);
1455 SEQ_PUT_HEX_FIELD_RET(s, entry->t);
1456
1457 switch (entry->type) {
1458 case TRACE_FN:
1459 SEQ_PUT_HEX_FIELD_RET(s, entry->fn.ip);
1460 SEQ_PUT_HEX_FIELD_RET(s, entry->fn.parent_ip);
1461 break;
1462 case TRACE_CTX:
57422797 1463 case TRACE_WAKE:
5e3ca0ec
IM
1464 S = entry->ctx.prev_state < sizeof(state_to_char) ?
1465 state_to_char[entry->ctx.prev_state] : 'X';
bac524d3
PZ
1466 T = entry->ctx.next_state < sizeof(state_to_char) ?
1467 state_to_char[entry->ctx.next_state] : 'X';
57422797
IM
1468 if (entry->type == TRACE_WAKE)
1469 S = '+';
5e3ca0ec
IM
1470 SEQ_PUT_HEX_FIELD_RET(s, entry->ctx.prev_pid);
1471 SEQ_PUT_HEX_FIELD_RET(s, entry->ctx.prev_prio);
1472 SEQ_PUT_HEX_FIELD_RET(s, S);
1473 SEQ_PUT_HEX_FIELD_RET(s, entry->ctx.next_pid);
1474 SEQ_PUT_HEX_FIELD_RET(s, entry->ctx.next_prio);
1475 SEQ_PUT_HEX_FIELD_RET(s, entry->fn.parent_ip);
bac524d3 1476 SEQ_PUT_HEX_FIELD_RET(s, T);
5e3ca0ec
IM
1477 break;
1478 case TRACE_SPECIAL:
86387f7e 1479 case TRACE_STACK:
5e3ca0ec
IM
1480 SEQ_PUT_HEX_FIELD_RET(s, entry->special.arg1);
1481 SEQ_PUT_HEX_FIELD_RET(s, entry->special.arg2);
1482 SEQ_PUT_HEX_FIELD_RET(s, entry->special.arg3);
1483 break;
1484 }
1485 SEQ_PUT_FIELD_RET(s, newline);
1486
1487 return 1;
1488}
1489
e309b41d 1490static int print_bin_fmt(struct trace_iterator *iter)
cb0f12aa
IM
1491{
1492 struct trace_seq *s = &iter->seq;
1493 struct trace_entry *entry;
1494
1495 entry = iter->ent;
1496
1497 SEQ_PUT_FIELD_RET(s, entry->pid);
1498 SEQ_PUT_FIELD_RET(s, entry->cpu);
1499 SEQ_PUT_FIELD_RET(s, entry->t);
1500
1501 switch (entry->type) {
1502 case TRACE_FN:
1503 SEQ_PUT_FIELD_RET(s, entry->fn.ip);
1504 SEQ_PUT_FIELD_RET(s, entry->fn.parent_ip);
1505 break;
1506 case TRACE_CTX:
1507 SEQ_PUT_FIELD_RET(s, entry->ctx.prev_pid);
1508 SEQ_PUT_FIELD_RET(s, entry->ctx.prev_prio);
1509 SEQ_PUT_FIELD_RET(s, entry->ctx.prev_state);
1510 SEQ_PUT_FIELD_RET(s, entry->ctx.next_pid);
1511 SEQ_PUT_FIELD_RET(s, entry->ctx.next_prio);
bac524d3 1512 SEQ_PUT_FIELD_RET(s, entry->ctx.next_state);
cb0f12aa 1513 break;
f0a920d5 1514 case TRACE_SPECIAL:
86387f7e 1515 case TRACE_STACK:
f0a920d5
IM
1516 SEQ_PUT_FIELD_RET(s, entry->special.arg1);
1517 SEQ_PUT_FIELD_RET(s, entry->special.arg2);
1518 SEQ_PUT_FIELD_RET(s, entry->special.arg3);
1519 break;
cb0f12aa
IM
1520 }
1521 return 1;
1522}
1523
bc0c38d1
SR
1524static int trace_empty(struct trace_iterator *iter)
1525{
1526 struct trace_array_cpu *data;
1527 int cpu;
1528
1529 for_each_possible_cpu(cpu) {
1530 data = iter->tr->data[cpu];
1531
b3806b43
SR
1532 if (head_page(data) && data->trace_idx &&
1533 (data->trace_tail != data->trace_head ||
1534 data->trace_tail_idx != data->trace_head_idx))
bc0c38d1
SR
1535 return 0;
1536 }
1537 return 1;
1538}
1539
f9896bf3
IM
1540static int print_trace_line(struct trace_iterator *iter)
1541{
cb0f12aa
IM
1542 if (trace_flags & TRACE_ITER_BIN)
1543 return print_bin_fmt(iter);
1544
5e3ca0ec
IM
1545 if (trace_flags & TRACE_ITER_HEX)
1546 return print_hex_fmt(iter);
1547
f9896bf3
IM
1548 if (trace_flags & TRACE_ITER_RAW)
1549 return print_raw_fmt(iter);
1550
1551 if (iter->iter_flags & TRACE_FILE_LAT_FMT)
1552 return print_lat_fmt(iter, iter->idx, iter->cpu);
1553
1554 return print_trace_fmt(iter);
1555}
1556
bc0c38d1
SR
1557static int s_show(struct seq_file *m, void *v)
1558{
1559 struct trace_iterator *iter = v;
1560
1561 if (iter->ent == NULL) {
1562 if (iter->tr) {
1563 seq_printf(m, "# tracer: %s\n", iter->trace->name);
1564 seq_puts(m, "#\n");
1565 }
1566 if (iter->iter_flags & TRACE_FILE_LAT_FMT) {
1567 /* print nothing if the buffers are empty */
1568 if (trace_empty(iter))
1569 return 0;
1570 print_trace_header(m, iter);
1571 if (!(trace_flags & TRACE_ITER_VERBOSE))
1572 print_lat_help_header(m);
1573 } else {
1574 if (!(trace_flags & TRACE_ITER_VERBOSE))
1575 print_func_help_header(m);
1576 }
1577 } else {
f9896bf3 1578 print_trace_line(iter);
214023c3 1579 trace_print_seq(m, &iter->seq);
bc0c38d1
SR
1580 }
1581
1582 return 0;
1583}
1584
1585static struct seq_operations tracer_seq_ops = {
4bf39a94
IM
1586 .start = s_start,
1587 .next = s_next,
1588 .stop = s_stop,
1589 .show = s_show,
bc0c38d1
SR
1590};
1591
e309b41d 1592static struct trace_iterator *
bc0c38d1
SR
1593__tracing_open(struct inode *inode, struct file *file, int *ret)
1594{
1595 struct trace_iterator *iter;
1596
60a11774
SR
1597 if (tracing_disabled) {
1598 *ret = -ENODEV;
1599 return NULL;
1600 }
1601
bc0c38d1
SR
1602 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
1603 if (!iter) {
1604 *ret = -ENOMEM;
1605 goto out;
1606 }
1607
1608 mutex_lock(&trace_types_lock);
1609 if (current_trace && current_trace->print_max)
1610 iter->tr = &max_tr;
1611 else
1612 iter->tr = inode->i_private;
1613 iter->trace = current_trace;
1614 iter->pos = -1;
1615
1616 /* TODO stop tracer */
1617 *ret = seq_open(file, &tracer_seq_ops);
1618 if (!*ret) {
1619 struct seq_file *m = file->private_data;
1620 m->private = iter;
1621
1622 /* stop the trace while dumping */
1623 if (iter->tr->ctrl)
1624 tracer_enabled = 0;
1625
1626 if (iter->trace && iter->trace->open)
1627 iter->trace->open(iter);
1628 } else {
1629 kfree(iter);
1630 iter = NULL;
1631 }
1632 mutex_unlock(&trace_types_lock);
1633
1634 out:
1635 return iter;
1636}
1637
1638int tracing_open_generic(struct inode *inode, struct file *filp)
1639{
60a11774
SR
1640 if (tracing_disabled)
1641 return -ENODEV;
1642
bc0c38d1
SR
1643 filp->private_data = inode->i_private;
1644 return 0;
1645}
1646
1647int tracing_release(struct inode *inode, struct file *file)
1648{
1649 struct seq_file *m = (struct seq_file *)file->private_data;
1650 struct trace_iterator *iter = m->private;
1651
1652 mutex_lock(&trace_types_lock);
1653 if (iter->trace && iter->trace->close)
1654 iter->trace->close(iter);
1655
1656 /* reenable tracing if it was previously enabled */
1657 if (iter->tr->ctrl)
1658 tracer_enabled = 1;
1659 mutex_unlock(&trace_types_lock);
1660
1661 seq_release(inode, file);
1662 kfree(iter);
1663 return 0;
1664}
1665
1666static int tracing_open(struct inode *inode, struct file *file)
1667{
1668 int ret;
1669
1670 __tracing_open(inode, file, &ret);
1671
1672 return ret;
1673}
1674
1675static int tracing_lt_open(struct inode *inode, struct file *file)
1676{
1677 struct trace_iterator *iter;
1678 int ret;
1679
1680 iter = __tracing_open(inode, file, &ret);
1681
1682 if (!ret)
1683 iter->iter_flags |= TRACE_FILE_LAT_FMT;
1684
1685 return ret;
1686}
1687
1688
e309b41d 1689static void *
bc0c38d1
SR
1690t_next(struct seq_file *m, void *v, loff_t *pos)
1691{
1692 struct tracer *t = m->private;
1693
1694 (*pos)++;
1695
1696 if (t)
1697 t = t->next;
1698
1699 m->private = t;
1700
1701 return t;
1702}
1703
1704static void *t_start(struct seq_file *m, loff_t *pos)
1705{
1706 struct tracer *t = m->private;
1707 loff_t l = 0;
1708
1709 mutex_lock(&trace_types_lock);
1710 for (; t && l < *pos; t = t_next(m, t, &l))
1711 ;
1712
1713 return t;
1714}
1715
1716static void t_stop(struct seq_file *m, void *p)
1717{
1718 mutex_unlock(&trace_types_lock);
1719}
1720
1721static int t_show(struct seq_file *m, void *v)
1722{
1723 struct tracer *t = v;
1724
1725 if (!t)
1726 return 0;
1727
1728 seq_printf(m, "%s", t->name);
1729 if (t->next)
1730 seq_putc(m, ' ');
1731 else
1732 seq_putc(m, '\n');
1733
1734 return 0;
1735}
1736
1737static struct seq_operations show_traces_seq_ops = {
4bf39a94
IM
1738 .start = t_start,
1739 .next = t_next,
1740 .stop = t_stop,
1741 .show = t_show,
bc0c38d1
SR
1742};
1743
1744static int show_traces_open(struct inode *inode, struct file *file)
1745{
1746 int ret;
1747
60a11774
SR
1748 if (tracing_disabled)
1749 return -ENODEV;
1750
bc0c38d1
SR
1751 ret = seq_open(file, &show_traces_seq_ops);
1752 if (!ret) {
1753 struct seq_file *m = file->private_data;
1754 m->private = trace_types;
1755 }
1756
1757 return ret;
1758}
1759
1760static struct file_operations tracing_fops = {
4bf39a94
IM
1761 .open = tracing_open,
1762 .read = seq_read,
1763 .llseek = seq_lseek,
1764 .release = tracing_release,
bc0c38d1
SR
1765};
1766
1767static struct file_operations tracing_lt_fops = {
4bf39a94
IM
1768 .open = tracing_lt_open,
1769 .read = seq_read,
1770 .llseek = seq_lseek,
1771 .release = tracing_release,
bc0c38d1
SR
1772};
1773
1774static struct file_operations show_traces_fops = {
c7078de1
IM
1775 .open = show_traces_open,
1776 .read = seq_read,
1777 .release = seq_release,
1778};
1779
36dfe925
IM
1780/*
1781 * Only trace on a CPU if the bitmask is set:
1782 */
1783static cpumask_t tracing_cpumask = CPU_MASK_ALL;
1784
1785/*
1786 * When tracing/tracing_cpu_mask is modified then this holds
1787 * the new bitmask we are about to install:
1788 */
1789static cpumask_t tracing_cpumask_new;
1790
1791/*
1792 * The tracer itself will not take this lock, but still we want
1793 * to provide a consistent cpumask to user-space:
1794 */
1795static DEFINE_MUTEX(tracing_cpumask_update_lock);
1796
1797/*
1798 * Temporary storage for the character representation of the
1799 * CPU bitmask (and one more byte for the newline):
1800 */
1801static char mask_str[NR_CPUS + 1];
1802
c7078de1
IM
1803static ssize_t
1804tracing_cpumask_read(struct file *filp, char __user *ubuf,
1805 size_t count, loff_t *ppos)
1806{
36dfe925 1807 int len;
c7078de1
IM
1808
1809 mutex_lock(&tracing_cpumask_update_lock);
36dfe925
IM
1810
1811 len = cpumask_scnprintf(mask_str, count, tracing_cpumask);
1812 if (count - len < 2) {
1813 count = -EINVAL;
1814 goto out_err;
1815 }
1816 len += sprintf(mask_str + len, "\n");
1817 count = simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+1);
1818
1819out_err:
c7078de1
IM
1820 mutex_unlock(&tracing_cpumask_update_lock);
1821
1822 return count;
1823}
1824
1825static ssize_t
1826tracing_cpumask_write(struct file *filp, const char __user *ubuf,
1827 size_t count, loff_t *ppos)
1828{
36dfe925 1829 int err, cpu;
c7078de1
IM
1830
1831 mutex_lock(&tracing_cpumask_update_lock);
36dfe925 1832 err = cpumask_parse_user(ubuf, count, tracing_cpumask_new);
c7078de1 1833 if (err)
36dfe925
IM
1834 goto err_unlock;
1835
92205c23
SR
1836 raw_local_irq_disable();
1837 __raw_spin_lock(&ftrace_max_lock);
36dfe925
IM
1838 for_each_possible_cpu(cpu) {
1839 /*
1840 * Increase/decrease the disabled counter if we are
1841 * about to flip a bit in the cpumask:
1842 */
1843 if (cpu_isset(cpu, tracing_cpumask) &&
1844 !cpu_isset(cpu, tracing_cpumask_new)) {
1845 atomic_inc(&global_trace.data[cpu]->disabled);
1846 }
1847 if (!cpu_isset(cpu, tracing_cpumask) &&
1848 cpu_isset(cpu, tracing_cpumask_new)) {
1849 atomic_dec(&global_trace.data[cpu]->disabled);
1850 }
1851 }
92205c23
SR
1852 __raw_spin_unlock(&ftrace_max_lock);
1853 raw_local_irq_enable();
36dfe925
IM
1854
1855 tracing_cpumask = tracing_cpumask_new;
1856
1857 mutex_unlock(&tracing_cpumask_update_lock);
c7078de1
IM
1858
1859 return count;
36dfe925
IM
1860
1861err_unlock:
1862 mutex_unlock(&tracing_cpumask_update_lock);
1863
1864 return err;
c7078de1
IM
1865}
1866
1867static struct file_operations tracing_cpumask_fops = {
1868 .open = tracing_open_generic,
1869 .read = tracing_cpumask_read,
1870 .write = tracing_cpumask_write,
bc0c38d1
SR
1871};
1872
1873static ssize_t
1874tracing_iter_ctrl_read(struct file *filp, char __user *ubuf,
1875 size_t cnt, loff_t *ppos)
1876{
1877 char *buf;
1878 int r = 0;
1879 int len = 0;
1880 int i;
1881
1882 /* calulate max size */
1883 for (i = 0; trace_options[i]; i++) {
1884 len += strlen(trace_options[i]);
1885 len += 3; /* "no" and space */
1886 }
1887
1888 /* +2 for \n and \0 */
1889 buf = kmalloc(len + 2, GFP_KERNEL);
1890 if (!buf)
1891 return -ENOMEM;
1892
1893 for (i = 0; trace_options[i]; i++) {
1894 if (trace_flags & (1 << i))
1895 r += sprintf(buf + r, "%s ", trace_options[i]);
1896 else
1897 r += sprintf(buf + r, "no%s ", trace_options[i]);
1898 }
1899
1900 r += sprintf(buf + r, "\n");
1901 WARN_ON(r >= len + 2);
1902
36dfe925 1903 r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
bc0c38d1
SR
1904
1905 kfree(buf);
1906
1907 return r;
1908}
1909
1910static ssize_t
1911tracing_iter_ctrl_write(struct file *filp, const char __user *ubuf,
1912 size_t cnt, loff_t *ppos)
1913{
1914 char buf[64];
1915 char *cmp = buf;
1916 int neg = 0;
1917 int i;
1918
1919 if (cnt > 63)
1920 cnt = 63;
1921
1922 if (copy_from_user(&buf, ubuf, cnt))
1923 return -EFAULT;
1924
1925 buf[cnt] = 0;
1926
1927 if (strncmp(buf, "no", 2) == 0) {
1928 neg = 1;
1929 cmp += 2;
1930 }
1931
1932 for (i = 0; trace_options[i]; i++) {
1933 int len = strlen(trace_options[i]);
1934
1935 if (strncmp(cmp, trace_options[i], len) == 0) {
1936 if (neg)
1937 trace_flags &= ~(1 << i);
1938 else
1939 trace_flags |= (1 << i);
1940 break;
1941 }
1942 }
442e544c
IM
1943 /*
1944 * If no option could be set, return an error:
1945 */
1946 if (!trace_options[i])
1947 return -EINVAL;
bc0c38d1
SR
1948
1949 filp->f_pos += cnt;
1950
1951 return cnt;
1952}
1953
1954static struct file_operations tracing_iter_fops = {
c7078de1
IM
1955 .open = tracing_open_generic,
1956 .read = tracing_iter_ctrl_read,
1957 .write = tracing_iter_ctrl_write,
bc0c38d1
SR
1958};
1959
7bd2f24c
IM
1960static const char readme_msg[] =
1961 "tracing mini-HOWTO:\n\n"
1962 "# mkdir /debug\n"
1963 "# mount -t debugfs nodev /debug\n\n"
1964 "# cat /debug/tracing/available_tracers\n"
1965 "wakeup preemptirqsoff preemptoff irqsoff ftrace sched_switch none\n\n"
1966 "# cat /debug/tracing/current_tracer\n"
1967 "none\n"
1968 "# echo sched_switch > /debug/tracing/current_tracer\n"
1969 "# cat /debug/tracing/current_tracer\n"
1970 "sched_switch\n"
1971 "# cat /debug/tracing/iter_ctrl\n"
1972 "noprint-parent nosym-offset nosym-addr noverbose\n"
1973 "# echo print-parent > /debug/tracing/iter_ctrl\n"
1974 "# echo 1 > /debug/tracing/tracing_enabled\n"
1975 "# cat /debug/tracing/trace > /tmp/trace.txt\n"
1976 "echo 0 > /debug/tracing/tracing_enabled\n"
1977;
1978
1979static ssize_t
1980tracing_readme_read(struct file *filp, char __user *ubuf,
1981 size_t cnt, loff_t *ppos)
1982{
1983 return simple_read_from_buffer(ubuf, cnt, ppos,
1984 readme_msg, strlen(readme_msg));
1985}
1986
1987static struct file_operations tracing_readme_fops = {
c7078de1
IM
1988 .open = tracing_open_generic,
1989 .read = tracing_readme_read,
7bd2f24c
IM
1990};
1991
bc0c38d1
SR
1992static ssize_t
1993tracing_ctrl_read(struct file *filp, char __user *ubuf,
1994 size_t cnt, loff_t *ppos)
1995{
1996 struct trace_array *tr = filp->private_data;
1997 char buf[64];
1998 int r;
1999
2000 r = sprintf(buf, "%ld\n", tr->ctrl);
4e3c3333 2001 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
bc0c38d1
SR
2002}
2003
2004static ssize_t
2005tracing_ctrl_write(struct file *filp, const char __user *ubuf,
2006 size_t cnt, loff_t *ppos)
2007{
2008 struct trace_array *tr = filp->private_data;
2009 long val;
2010 char buf[64];
2011
2012 if (cnt > 63)
2013 cnt = 63;
2014
2015 if (copy_from_user(&buf, ubuf, cnt))
2016 return -EFAULT;
2017
2018 buf[cnt] = 0;
2019
2020 val = simple_strtoul(buf, NULL, 10);
2021
2022 val = !!val;
2023
2024 mutex_lock(&trace_types_lock);
2025 if (tr->ctrl ^ val) {
2026 if (val)
2027 tracer_enabled = 1;
2028 else
2029 tracer_enabled = 0;
2030
2031 tr->ctrl = val;
2032
2033 if (current_trace && current_trace->ctrl_update)
2034 current_trace->ctrl_update(tr);
2035 }
2036 mutex_unlock(&trace_types_lock);
2037
2038 filp->f_pos += cnt;
2039
2040 return cnt;
2041}
2042
2043static ssize_t
2044tracing_set_trace_read(struct file *filp, char __user *ubuf,
2045 size_t cnt, loff_t *ppos)
2046{
2047 char buf[max_tracer_type_len+2];
2048 int r;
2049
2050 mutex_lock(&trace_types_lock);
2051 if (current_trace)
2052 r = sprintf(buf, "%s\n", current_trace->name);
2053 else
2054 r = sprintf(buf, "\n");
2055 mutex_unlock(&trace_types_lock);
2056
4bf39a94 2057 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
bc0c38d1
SR
2058}
2059
2060static ssize_t
2061tracing_set_trace_write(struct file *filp, const char __user *ubuf,
2062 size_t cnt, loff_t *ppos)
2063{
2064 struct trace_array *tr = &global_trace;
2065 struct tracer *t;
2066 char buf[max_tracer_type_len+1];
2067 int i;
2068
2069 if (cnt > max_tracer_type_len)
2070 cnt = max_tracer_type_len;
2071
2072 if (copy_from_user(&buf, ubuf, cnt))
2073 return -EFAULT;
2074
2075 buf[cnt] = 0;
2076
2077 /* strip ending whitespace. */
2078 for (i = cnt - 1; i > 0 && isspace(buf[i]); i--)
2079 buf[i] = 0;
2080
2081 mutex_lock(&trace_types_lock);
2082 for (t = trace_types; t; t = t->next) {
2083 if (strcmp(t->name, buf) == 0)
2084 break;
2085 }
2086 if (!t || t == current_trace)
2087 goto out;
2088
2089 if (current_trace && current_trace->reset)
2090 current_trace->reset(tr);
2091
2092 current_trace = t;
2093 if (t->init)
2094 t->init(tr);
2095
2096 out:
2097 mutex_unlock(&trace_types_lock);
2098
2099 filp->f_pos += cnt;
2100
2101 return cnt;
2102}
2103
2104static ssize_t
2105tracing_max_lat_read(struct file *filp, char __user *ubuf,
2106 size_t cnt, loff_t *ppos)
2107{
2108 unsigned long *ptr = filp->private_data;
2109 char buf[64];
2110 int r;
2111
2112 r = snprintf(buf, 64, "%ld\n",
2113 *ptr == (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr));
2114 if (r > 64)
2115 r = 64;
4bf39a94 2116 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
bc0c38d1
SR
2117}
2118
2119static ssize_t
2120tracing_max_lat_write(struct file *filp, const char __user *ubuf,
2121 size_t cnt, loff_t *ppos)
2122{
2123 long *ptr = filp->private_data;
2124 long val;
2125 char buf[64];
2126
2127 if (cnt > 63)
2128 cnt = 63;
2129
2130 if (copy_from_user(&buf, ubuf, cnt))
2131 return -EFAULT;
2132
2133 buf[cnt] = 0;
2134
2135 val = simple_strtoul(buf, NULL, 10);
2136
2137 *ptr = val * 1000;
2138
2139 return cnt;
2140}
2141
b3806b43
SR
2142static atomic_t tracing_reader;
2143
2144static int tracing_open_pipe(struct inode *inode, struct file *filp)
2145{
2146 struct trace_iterator *iter;
2147
2148 if (tracing_disabled)
2149 return -ENODEV;
2150
2151 /* We only allow for reader of the pipe */
2152 if (atomic_inc_return(&tracing_reader) != 1) {
2153 atomic_dec(&tracing_reader);
2154 return -EBUSY;
2155 }
2156
2157 /* create a buffer to store the information to pass to userspace */
2158 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
2159 if (!iter)
2160 return -ENOMEM;
2161
2162 iter->tr = &global_trace;
2163
2164 filp->private_data = iter;
2165
2166 return 0;
2167}
2168
2169static int tracing_release_pipe(struct inode *inode, struct file *file)
2170{
2171 struct trace_iterator *iter = file->private_data;
2172
2173 kfree(iter);
2174 atomic_dec(&tracing_reader);
2175
2176 return 0;
2177}
2178
2a2cc8f7
SSP
2179static unsigned int
2180tracing_poll_pipe(struct file *filp, poll_table *poll_table)
2181{
2182 struct trace_iterator *iter = filp->private_data;
2183
2184 if (trace_flags & TRACE_ITER_BLOCK) {
2185 /*
2186 * Always select as readable when in blocking mode
2187 */
2188 return POLLIN | POLLRDNORM;
2189 }
2190 else {
2191 if (!trace_empty(iter))
2192 return POLLIN | POLLRDNORM;
2193 poll_wait(filp, &trace_wait, poll_table);
2194 if (!trace_empty(iter))
2195 return POLLIN | POLLRDNORM;
2196
2197 return 0;
2198 }
2199}
2200
b3806b43
SR
2201/*
2202 * Consumer reader.
2203 */
2204static ssize_t
2205tracing_read_pipe(struct file *filp, char __user *ubuf,
2206 size_t cnt, loff_t *ppos)
2207{
2208 struct trace_iterator *iter = filp->private_data;
2209 struct trace_array_cpu *data;
2210 static cpumask_t mask;
b3806b43
SR
2211 static int start;
2212 unsigned long flags;
25770467 2213#ifdef CONFIG_FTRACE
2e0f5761 2214 int ftrace_save;
25770467 2215#endif
b3806b43
SR
2216 int read = 0;
2217 int cpu;
2218 int len;
2219 int ret;
2220
2221 /* return any leftover data */
2222 if (iter->seq.len > start) {
2223 len = iter->seq.len - start;
2224 if (cnt > len)
2225 cnt = len;
2226 ret = copy_to_user(ubuf, iter->seq.buffer + start, cnt);
2227 if (ret)
2228 cnt = -EFAULT;
2229
2230 start += len;
2231
2232 return cnt;
2233 }
2234
2235 trace_seq_reset(&iter->seq);
2236 start = 0;
2237
2238 while (trace_empty(iter)) {
2a2cc8f7
SSP
2239 if (!(trace_flags & TRACE_ITER_BLOCK))
2240 return -EWOULDBLOCK;
b3806b43
SR
2241 /*
2242 * This is a make-shift waitqueue. The reason we don't use
2243 * an actual wait queue is because:
2244 * 1) we only ever have one waiter
2245 * 2) the tracing, traces all functions, we don't want
2246 * the overhead of calling wake_up and friends
2247 * (and tracing them too)
2248 * Anyway, this is really very primitive wakeup.
2249 */
2250 set_current_state(TASK_INTERRUPTIBLE);
2251 iter->tr->waiter = current;
2252
2253 /* sleep for one second, and try again. */
2254 schedule_timeout(HZ);
2255
2256 iter->tr->waiter = NULL;
2257
2258 if (signal_pending(current))
2259 return -EINTR;
2260
2261 /*
2262 * We block until we read something and tracing is disabled.
2263 * We still block if tracing is disabled, but we have never
2264 * read anything. This allows a user to cat this file, and
2265 * then enable tracing. But after we have read something,
2266 * we give an EOF when tracing is again disabled.
2267 *
2268 * iter->pos will be 0 if we haven't read anything.
2269 */
2270 if (!tracer_enabled && iter->pos)
2271 break;
2272
2273 continue;
2274 }
2275
2276 /* stop when tracing is finished */
2277 if (trace_empty(iter))
2278 return 0;
2279
2280 if (cnt >= PAGE_SIZE)
2281 cnt = PAGE_SIZE - 1;
2282
2283 memset(iter, 0, sizeof(*iter));
2284 iter->tr = &global_trace;
2285 iter->pos = -1;
2286
2287 /*
2288 * We need to stop all tracing on all CPUS to read the
2289 * the next buffer. This is a bit expensive, but is
2290 * not done often. We fill all what we can read,
2291 * and then release the locks again.
2292 */
2293
2294 cpus_clear(mask);
2295 local_irq_save(flags);
25770467 2296#ifdef CONFIG_FTRACE
2e0f5761
IM
2297 ftrace_save = ftrace_enabled;
2298 ftrace_enabled = 0;
25770467 2299#endif
2e0f5761 2300 smp_wmb();
b3806b43
SR
2301 for_each_possible_cpu(cpu) {
2302 data = iter->tr->data[cpu];
2303
2304 if (!head_page(data) || !data->trace_idx)
2305 continue;
2306
2307 atomic_inc(&data->disabled);
b3806b43
SR
2308 cpu_set(cpu, mask);
2309 }
2310
2e0f5761
IM
2311 for_each_cpu_mask(cpu, mask) {
2312 data = iter->tr->data[cpu];
92205c23 2313 __raw_spin_lock(&data->lock);
2e0f5761
IM
2314 }
2315
088b1e42
SR
2316 while (find_next_entry_inc(iter) != NULL) {
2317 int len = iter->seq.len;
2318
f9896bf3 2319 ret = print_trace_line(iter);
088b1e42
SR
2320 if (!ret) {
2321 /* don't print partial lines */
2322 iter->seq.len = len;
b3806b43 2323 break;
088b1e42 2324 }
b3806b43
SR
2325
2326 trace_consume(iter);
2327
2328 if (iter->seq.len >= cnt)
2329 break;
b3806b43
SR
2330 }
2331
d4c5a2f5 2332 for_each_cpu_mask(cpu, mask) {
b3806b43 2333 data = iter->tr->data[cpu];
92205c23 2334 __raw_spin_unlock(&data->lock);
2e0f5761
IM
2335 }
2336
2337 for_each_cpu_mask(cpu, mask) {
2338 data = iter->tr->data[cpu];
b3806b43
SR
2339 atomic_dec(&data->disabled);
2340 }
25770467 2341#ifdef CONFIG_FTRACE
2e0f5761 2342 ftrace_enabled = ftrace_save;
25770467 2343#endif
b3806b43
SR
2344 local_irq_restore(flags);
2345
2346 /* Now copy what we have to the user */
2347 read = iter->seq.len;
2348 if (read > cnt)
2349 read = cnt;
2350
2351 ret = copy_to_user(ubuf, iter->seq.buffer, read);
2352
2353 if (read < iter->seq.len)
2354 start = read;
2355 else
2356 trace_seq_reset(&iter->seq);
2357
2358 if (ret)
2359 read = -EFAULT;
2360
2361 return read;
2362}
2363
bc0c38d1 2364static struct file_operations tracing_max_lat_fops = {
4bf39a94
IM
2365 .open = tracing_open_generic,
2366 .read = tracing_max_lat_read,
2367 .write = tracing_max_lat_write,
bc0c38d1
SR
2368};
2369
2370static struct file_operations tracing_ctrl_fops = {
4bf39a94
IM
2371 .open = tracing_open_generic,
2372 .read = tracing_ctrl_read,
2373 .write = tracing_ctrl_write,
bc0c38d1
SR
2374};
2375
2376static struct file_operations set_tracer_fops = {
4bf39a94
IM
2377 .open = tracing_open_generic,
2378 .read = tracing_set_trace_read,
2379 .write = tracing_set_trace_write,
bc0c38d1
SR
2380};
2381
b3806b43 2382static struct file_operations tracing_pipe_fops = {
4bf39a94 2383 .open = tracing_open_pipe,
2a2cc8f7 2384 .poll = tracing_poll_pipe,
4bf39a94
IM
2385 .read = tracing_read_pipe,
2386 .release = tracing_release_pipe,
b3806b43
SR
2387};
2388
bc0c38d1
SR
2389#ifdef CONFIG_DYNAMIC_FTRACE
2390
2391static ssize_t
2392tracing_read_long(struct file *filp, char __user *ubuf,
2393 size_t cnt, loff_t *ppos)
2394{
2395 unsigned long *p = filp->private_data;
2396 char buf[64];
2397 int r;
2398
2399 r = sprintf(buf, "%ld\n", *p);
4bf39a94
IM
2400
2401 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
bc0c38d1
SR
2402}
2403
2404static struct file_operations tracing_read_long_fops = {
4bf39a94
IM
2405 .open = tracing_open_generic,
2406 .read = tracing_read_long,
bc0c38d1
SR
2407};
2408#endif
2409
2410static struct dentry *d_tracer;
2411
2412struct dentry *tracing_init_dentry(void)
2413{
2414 static int once;
2415
2416 if (d_tracer)
2417 return d_tracer;
2418
2419 d_tracer = debugfs_create_dir("tracing", NULL);
2420
2421 if (!d_tracer && !once) {
2422 once = 1;
2423 pr_warning("Could not create debugfs directory 'tracing'\n");
2424 return NULL;
2425 }
2426
2427 return d_tracer;
2428}
2429
60a11774
SR
2430#ifdef CONFIG_FTRACE_SELFTEST
2431/* Let selftest have access to static functions in this file */
2432#include "trace_selftest.c"
2433#endif
2434
bc0c38d1
SR
2435static __init void tracer_init_debugfs(void)
2436{
2437 struct dentry *d_tracer;
2438 struct dentry *entry;
2439
2440 d_tracer = tracing_init_dentry();
2441
2442 entry = debugfs_create_file("tracing_enabled", 0644, d_tracer,
2443 &global_trace, &tracing_ctrl_fops);
2444 if (!entry)
2445 pr_warning("Could not create debugfs 'tracing_enabled' entry\n");
2446
2447 entry = debugfs_create_file("iter_ctrl", 0644, d_tracer,
2448 NULL, &tracing_iter_fops);
2449 if (!entry)
2450 pr_warning("Could not create debugfs 'iter_ctrl' entry\n");
2451
c7078de1
IM
2452 entry = debugfs_create_file("tracing_cpumask", 0644, d_tracer,
2453 NULL, &tracing_cpumask_fops);
2454 if (!entry)
2455 pr_warning("Could not create debugfs 'tracing_cpumask' entry\n");
2456
bc0c38d1
SR
2457 entry = debugfs_create_file("latency_trace", 0444, d_tracer,
2458 &global_trace, &tracing_lt_fops);
2459 if (!entry)
2460 pr_warning("Could not create debugfs 'latency_trace' entry\n");
2461
2462 entry = debugfs_create_file("trace", 0444, d_tracer,
2463 &global_trace, &tracing_fops);
2464 if (!entry)
2465 pr_warning("Could not create debugfs 'trace' entry\n");
2466
2467 entry = debugfs_create_file("available_tracers", 0444, d_tracer,
2468 &global_trace, &show_traces_fops);
2469 if (!entry)
2470 pr_warning("Could not create debugfs 'trace' entry\n");
2471
2472 entry = debugfs_create_file("current_tracer", 0444, d_tracer,
2473 &global_trace, &set_tracer_fops);
2474 if (!entry)
2475 pr_warning("Could not create debugfs 'trace' entry\n");
2476
2477 entry = debugfs_create_file("tracing_max_latency", 0644, d_tracer,
2478 &tracing_max_latency,
2479 &tracing_max_lat_fops);
2480 if (!entry)
2481 pr_warning("Could not create debugfs "
2482 "'tracing_max_latency' entry\n");
2483
2484 entry = debugfs_create_file("tracing_thresh", 0644, d_tracer,
2485 &tracing_thresh, &tracing_max_lat_fops);
2486 if (!entry)
2487 pr_warning("Could not create debugfs "
2488 "'tracing_threash' entry\n");
7bd2f24c
IM
2489 entry = debugfs_create_file("README", 0644, d_tracer,
2490 NULL, &tracing_readme_fops);
2491 if (!entry)
2492 pr_warning("Could not create debugfs 'README' entry\n");
2493
b3806b43
SR
2494 entry = debugfs_create_file("trace_pipe", 0644, d_tracer,
2495 NULL, &tracing_pipe_fops);
2496 if (!entry)
2497 pr_warning("Could not create debugfs "
2498 "'tracing_threash' entry\n");
bc0c38d1
SR
2499
2500#ifdef CONFIG_DYNAMIC_FTRACE
2501 entry = debugfs_create_file("dyn_ftrace_total_info", 0444, d_tracer,
2502 &ftrace_update_tot_cnt,
2503 &tracing_read_long_fops);
2504 if (!entry)
2505 pr_warning("Could not create debugfs "
2506 "'dyn_ftrace_total_info' entry\n");
2507#endif
2508}
2509
2510/* dummy trace to disable tracing */
2511static struct tracer no_tracer __read_mostly =
2512{
4bf39a94 2513 .name = "none",
bc0c38d1
SR
2514};
2515
4c11d7ae 2516static int trace_alloc_page(void)
bc0c38d1 2517{
4c11d7ae 2518 struct trace_array_cpu *data;
4c11d7ae
SR
2519 struct page *page, *tmp;
2520 LIST_HEAD(pages);
c7aafc54 2521 void *array;
4c11d7ae
SR
2522 int i;
2523
2524 /* first allocate a page for each CPU */
2525 for_each_possible_cpu(i) {
2526 array = (void *)__get_free_page(GFP_KERNEL);
2527 if (array == NULL) {
2528 printk(KERN_ERR "tracer: failed to allocate page"
2529 "for trace buffer!\n");
2530 goto free_pages;
2531 }
2532
2533 page = virt_to_page(array);
2534 list_add(&page->lru, &pages);
2535
2536/* Only allocate if we are actually using the max trace */
2537#ifdef CONFIG_TRACER_MAX_TRACE
2538 array = (void *)__get_free_page(GFP_KERNEL);
2539 if (array == NULL) {
2540 printk(KERN_ERR "tracer: failed to allocate page"
2541 "for trace buffer!\n");
2542 goto free_pages;
2543 }
2544 page = virt_to_page(array);
2545 list_add(&page->lru, &pages);
2546#endif
2547 }
2548
2549 /* Now that we successfully allocate a page per CPU, add them */
2550 for_each_possible_cpu(i) {
2551 data = global_trace.data[i];
92205c23 2552 data->lock = (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED;
4c11d7ae 2553 page = list_entry(pages.next, struct page, lru);
c7aafc54 2554 list_del_init(&page->lru);
4c11d7ae
SR
2555 list_add_tail(&page->lru, &data->trace_pages);
2556 ClearPageLRU(page);
2557
2558#ifdef CONFIG_TRACER_MAX_TRACE
2559 data = max_tr.data[i];
92205c23 2560 data->lock = (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED;
4c11d7ae 2561 page = list_entry(pages.next, struct page, lru);
c7aafc54 2562 list_del_init(&page->lru);
4c11d7ae
SR
2563 list_add_tail(&page->lru, &data->trace_pages);
2564 SetPageLRU(page);
2565#endif
2566 }
2567 global_trace.entries += ENTRIES_PER_PAGE;
2568
2569 return 0;
2570
2571 free_pages:
2572 list_for_each_entry_safe(page, tmp, &pages, lru) {
c7aafc54 2573 list_del_init(&page->lru);
4c11d7ae
SR
2574 __free_page(page);
2575 }
2576 return -ENOMEM;
bc0c38d1
SR
2577}
2578
2579__init static int tracer_alloc_buffers(void)
2580{
4c11d7ae
SR
2581 struct trace_array_cpu *data;
2582 void *array;
2583 struct page *page;
2584 int pages = 0;
60a11774 2585 int ret = -ENOMEM;
bc0c38d1
SR
2586 int i;
2587
26994ead
SR
2588 global_trace.ctrl = tracer_enabled;
2589
4c11d7ae 2590 /* Allocate the first page for all buffers */
bc0c38d1 2591 for_each_possible_cpu(i) {
4c11d7ae 2592 data = global_trace.data[i] = &per_cpu(global_trace_cpu, i);
bc0c38d1
SR
2593 max_tr.data[i] = &per_cpu(max_data, i);
2594
4c11d7ae 2595 array = (void *)__get_free_page(GFP_KERNEL);
bc0c38d1 2596 if (array == NULL) {
4c11d7ae
SR
2597 printk(KERN_ERR "tracer: failed to allocate page"
2598 "for trace buffer!\n");
bc0c38d1
SR
2599 goto free_buffers;
2600 }
4c11d7ae
SR
2601
2602 /* set the array to the list */
2603 INIT_LIST_HEAD(&data->trace_pages);
2604 page = virt_to_page(array);
2605 list_add(&page->lru, &data->trace_pages);
2606 /* use the LRU flag to differentiate the two buffers */
2607 ClearPageLRU(page);
bc0c38d1
SR
2608
2609/* Only allocate if we are actually using the max trace */
2610#ifdef CONFIG_TRACER_MAX_TRACE
4c11d7ae 2611 array = (void *)__get_free_page(GFP_KERNEL);
bc0c38d1 2612 if (array == NULL) {
4c11d7ae
SR
2613 printk(KERN_ERR "tracer: failed to allocate page"
2614 "for trace buffer!\n");
bc0c38d1
SR
2615 goto free_buffers;
2616 }
4c11d7ae
SR
2617
2618 INIT_LIST_HEAD(&max_tr.data[i]->trace_pages);
2619 page = virt_to_page(array);
2620 list_add(&page->lru, &max_tr.data[i]->trace_pages);
2621 SetPageLRU(page);
bc0c38d1
SR
2622#endif
2623 }
2624
2625 /*
2626 * Since we allocate by orders of pages, we may be able to
2627 * round up a bit.
2628 */
4c11d7ae 2629 global_trace.entries = ENTRIES_PER_PAGE;
4c11d7ae
SR
2630 pages++;
2631
2632 while (global_trace.entries < trace_nr_entries) {
2633 if (trace_alloc_page())
2634 break;
2635 pages++;
2636 }
89b2f978 2637 max_tr.entries = global_trace.entries;
bc0c38d1 2638
4c11d7ae
SR
2639 pr_info("tracer: %d pages allocated for %ld",
2640 pages, trace_nr_entries);
bc0c38d1
SR
2641 pr_info(" entries of %ld bytes\n", (long)TRACE_ENTRY_SIZE);
2642 pr_info(" actual entries %ld\n", global_trace.entries);
2643
2644 tracer_init_debugfs();
2645
2646 trace_init_cmdlines();
2647
2648 register_tracer(&no_tracer);
2649 current_trace = &no_tracer;
2650
60a11774
SR
2651 /* All seems OK, enable tracing */
2652 tracing_disabled = 0;
2653
bc0c38d1
SR
2654 return 0;
2655
2656 free_buffers:
2657 for (i-- ; i >= 0; i--) {
4c11d7ae 2658 struct page *page, *tmp;
bc0c38d1
SR
2659 struct trace_array_cpu *data = global_trace.data[i];
2660
c7aafc54 2661 if (data) {
4c11d7ae
SR
2662 list_for_each_entry_safe(page, tmp,
2663 &data->trace_pages, lru) {
c7aafc54 2664 list_del_init(&page->lru);
4c11d7ae
SR
2665 __free_page(page);
2666 }
bc0c38d1
SR
2667 }
2668
2669#ifdef CONFIG_TRACER_MAX_TRACE
2670 data = max_tr.data[i];
c7aafc54 2671 if (data) {
4c11d7ae
SR
2672 list_for_each_entry_safe(page, tmp,
2673 &data->trace_pages, lru) {
c7aafc54 2674 list_del_init(&page->lru);
4c11d7ae
SR
2675 __free_page(page);
2676 }
bc0c38d1
SR
2677 }
2678#endif
2679 }
60a11774 2680 return ret;
bc0c38d1 2681}
60a11774 2682fs_initcall(tracer_alloc_buffers);