aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/trace/trace.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/trace/trace.c')
-rw-r--r--kernel/trace/trace.c2633
1 files changed, 1371 insertions, 1262 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 17bb88d86ac2..e5b56199e5e0 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -11,32 +11,33 @@
11 * Copyright (C) 2004-2006 Ingo Molnar 11 * Copyright (C) 2004-2006 Ingo Molnar
12 * Copyright (C) 2004 William Lee Irwin III 12 * Copyright (C) 2004 William Lee Irwin III
13 */ 13 */
14#include <linux/ring_buffer.h>
14#include <linux/utsrelease.h> 15#include <linux/utsrelease.h>
16#include <linux/stacktrace.h>
17#include <linux/writeback.h>
15#include <linux/kallsyms.h> 18#include <linux/kallsyms.h>
16#include <linux/seq_file.h> 19#include <linux/seq_file.h>
17#include <linux/notifier.h> 20#include <linux/notifier.h>
21#include <linux/irqflags.h>
18#include <linux/debugfs.h> 22#include <linux/debugfs.h>
19#include <linux/pagemap.h> 23#include <linux/pagemap.h>
20#include <linux/hardirq.h> 24#include <linux/hardirq.h>
21#include <linux/linkage.h> 25#include <linux/linkage.h>
22#include <linux/uaccess.h> 26#include <linux/uaccess.h>
27#include <linux/kprobes.h>
23#include <linux/ftrace.h> 28#include <linux/ftrace.h>
24#include <linux/module.h> 29#include <linux/module.h>
25#include <linux/percpu.h> 30#include <linux/percpu.h>
31#include <linux/splice.h>
26#include <linux/kdebug.h> 32#include <linux/kdebug.h>
27#include <linux/ctype.h> 33#include <linux/ctype.h>
28#include <linux/init.h> 34#include <linux/init.h>
29#include <linux/poll.h> 35#include <linux/poll.h>
30#include <linux/gfp.h> 36#include <linux/gfp.h>
31#include <linux/fs.h> 37#include <linux/fs.h>
32#include <linux/kprobes.h>
33#include <linux/writeback.h>
34
35#include <linux/stacktrace.h>
36#include <linux/ring_buffer.h>
37#include <linux/irqflags.h>
38 38
39#include "trace.h" 39#include "trace.h"
40#include "trace_output.h"
40 41
41#define TRACE_BUFFER_FLAGS (RB_FL_OVERWRITE) 42#define TRACE_BUFFER_FLAGS (RB_FL_OVERWRITE)
42 43
@@ -47,11 +48,16 @@ unsigned long __read_mostly tracing_thresh;
47 * We need to change this state when a selftest is running. 48 * We need to change this state when a selftest is running.
48 * A selftest will lurk into the ring-buffer to count the 49 * A selftest will lurk into the ring-buffer to count the
49 * entries inserted during the selftest although some concurrent 50 * entries inserted during the selftest although some concurrent
50 * insertions into the ring-buffer such as ftrace_printk could occurred 51 * insertions into the ring-buffer such as trace_printk could occurred
51 * at the same time, giving false positive or negative results. 52 * at the same time, giving false positive or negative results.
52 */ 53 */
53static bool __read_mostly tracing_selftest_running; 54static bool __read_mostly tracing_selftest_running;
54 55
56/*
57 * If a tracer is running, we do not want to run SELFTEST.
58 */
59static bool __read_mostly tracing_selftest_disabled;
60
55/* For tracers that don't implement custom flags */ 61/* For tracers that don't implement custom flags */
56static struct tracer_opt dummy_tracer_opt[] = { 62static struct tracer_opt dummy_tracer_opt[] = {
57 { } 63 { }
@@ -73,7 +79,7 @@ static int dummy_set_flag(u32 old_flags, u32 bit, int set)
73 * of the tracer is successful. But that is the only place that sets 79 * of the tracer is successful. But that is the only place that sets
74 * this back to zero. 80 * this back to zero.
75 */ 81 */
76int tracing_disabled = 1; 82static int tracing_disabled = 1;
77 83
78static DEFINE_PER_CPU(local_t, ftrace_cpu_disabled); 84static DEFINE_PER_CPU(local_t, ftrace_cpu_disabled);
79 85
@@ -91,6 +97,9 @@ static inline void ftrace_enable_cpu(void)
91 97
92static cpumask_var_t __read_mostly tracing_buffer_mask; 98static cpumask_var_t __read_mostly tracing_buffer_mask;
93 99
100/* Define which cpu buffers are currently read in trace_pipe */
101static cpumask_var_t tracing_reader_cpumask;
102
94#define for_each_tracing_cpu(cpu) \ 103#define for_each_tracing_cpu(cpu) \
95 for_each_cpu(cpu, tracing_buffer_mask) 104 for_each_cpu(cpu, tracing_buffer_mask)
96 105
@@ -109,14 +118,19 @@ static cpumask_var_t __read_mostly tracing_buffer_mask;
109 */ 118 */
110int ftrace_dump_on_oops; 119int ftrace_dump_on_oops;
111 120
112static int tracing_set_tracer(char *buf); 121static int tracing_set_tracer(const char *buf);
122
123#define BOOTUP_TRACER_SIZE 100
124static char bootup_tracer_buf[BOOTUP_TRACER_SIZE] __initdata;
125static char *default_bootup_tracer;
113 126
114static int __init set_ftrace(char *str) 127static int __init set_ftrace(char *str)
115{ 128{
116 tracing_set_tracer(str); 129 strncpy(bootup_tracer_buf, str, BOOTUP_TRACER_SIZE);
130 default_bootup_tracer = bootup_tracer_buf;
117 return 1; 131 return 1;
118} 132}
119__setup("ftrace", set_ftrace); 133__setup("ftrace=", set_ftrace);
120 134
121static int __init set_ftrace_dump_on_oops(char *str) 135static int __init set_ftrace_dump_on_oops(char *str)
122{ 136{
@@ -186,9 +200,6 @@ int tracing_is_enabled(void)
186 return tracer_enabled; 200 return tracer_enabled;
187} 201}
188 202
189/* function tracing enabled */
190int ftrace_function_enabled;
191
192/* 203/*
193 * trace_buf_size is the size in bytes that is allocated 204 * trace_buf_size is the size in bytes that is allocated
194 * for a buffer. Note, the number of bytes is always rounded 205 * for a buffer. Note, the number of bytes is always rounded
@@ -229,7 +240,7 @@ static DECLARE_WAIT_QUEUE_HEAD(trace_wait);
229 240
230/* trace_flags holds trace_options default values */ 241/* trace_flags holds trace_options default values */
231unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK | 242unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |
232 TRACE_ITER_ANNOTATE; 243 TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO;
233 244
234/** 245/**
235 * trace_wake_up - wake up tasks waiting for trace input 246 * trace_wake_up - wake up tasks waiting for trace input
@@ -280,13 +291,15 @@ static const char *trace_options[] = {
280 "block", 291 "block",
281 "stacktrace", 292 "stacktrace",
282 "sched-tree", 293 "sched-tree",
283 "ftrace_printk", 294 "trace_printk",
284 "ftrace_preempt", 295 "ftrace_preempt",
285 "branch", 296 "branch",
286 "annotate", 297 "annotate",
287 "userstacktrace", 298 "userstacktrace",
288 "sym-userobj", 299 "sym-userobj",
289 "printk-msg-only", 300 "printk-msg-only",
301 "context-info",
302 "latency-format",
290 NULL 303 NULL
291}; 304};
292 305
@@ -326,146 +339,37 @@ __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
326 data->rt_priority = tsk->rt_priority; 339 data->rt_priority = tsk->rt_priority;
327 340
328 /* record this tasks comm */ 341 /* record this tasks comm */
329 tracing_record_cmdline(current); 342 tracing_record_cmdline(tsk);
330} 343}
331 344
332/** 345ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt)
333 * trace_seq_printf - sequence printing of trace information
334 * @s: trace sequence descriptor
335 * @fmt: printf format string
336 *
337 * The tracer may use either sequence operations or its own
338 * copy to user routines. To simplify formating of a trace
339 * trace_seq_printf is used to store strings into a special
340 * buffer (@s). Then the output may be either used by
341 * the sequencer or pulled into another buffer.
342 */
343int
344trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
345{ 346{
346 int len = (PAGE_SIZE - 1) - s->len; 347 int len;
347 va_list ap;
348 int ret; 348 int ret;
349 349
350 if (!len) 350 if (!cnt)
351 return 0;
352
353 va_start(ap, fmt);
354 ret = vsnprintf(s->buffer + s->len, len, fmt, ap);
355 va_end(ap);
356
357 /* If we can't write it all, don't bother writing anything */
358 if (ret >= len)
359 return 0;
360
361 s->len += ret;
362
363 return len;
364}
365
366/**
367 * trace_seq_puts - trace sequence printing of simple string
368 * @s: trace sequence descriptor
369 * @str: simple string to record
370 *
371 * The tracer may use either the sequence operations or its own
372 * copy to user routines. This function records a simple string
373 * into a special buffer (@s) for later retrieval by a sequencer
374 * or other mechanism.
375 */
376static int
377trace_seq_puts(struct trace_seq *s, const char *str)
378{
379 int len = strlen(str);
380
381 if (len > ((PAGE_SIZE - 1) - s->len))
382 return 0;
383
384 memcpy(s->buffer + s->len, str, len);
385 s->len += len;
386
387 return len;
388}
389
390static int
391trace_seq_putc(struct trace_seq *s, unsigned char c)
392{
393 if (s->len >= (PAGE_SIZE - 1))
394 return 0;
395
396 s->buffer[s->len++] = c;
397
398 return 1;
399}
400
401static int
402trace_seq_putmem(struct trace_seq *s, void *mem, size_t len)
403{
404 if (len > ((PAGE_SIZE - 1) - s->len))
405 return 0; 351 return 0;
406 352
407 memcpy(s->buffer + s->len, mem, len); 353 if (s->len <= s->readpos)
408 s->len += len; 354 return -EBUSY;
409
410 return len;
411}
412
413#define MAX_MEMHEX_BYTES 8
414#define HEX_CHARS (MAX_MEMHEX_BYTES*2 + 1)
415
416static int
417trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len)
418{
419 unsigned char hex[HEX_CHARS];
420 unsigned char *data = mem;
421 int i, j;
422
423#ifdef __BIG_ENDIAN
424 for (i = 0, j = 0; i < len; i++) {
425#else
426 for (i = len-1, j = 0; i >= 0; i--) {
427#endif
428 hex[j++] = hex_asc_hi(data[i]);
429 hex[j++] = hex_asc_lo(data[i]);
430 }
431 hex[j++] = ' ';
432
433 return trace_seq_putmem(s, hex, j);
434}
435
436static int
437trace_seq_path(struct trace_seq *s, struct path *path)
438{
439 unsigned char *p;
440 355
441 if (s->len >= (PAGE_SIZE - 1)) 356 len = s->len - s->readpos;
442 return 0; 357 if (cnt > len)
443 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len); 358 cnt = len;
444 if (!IS_ERR(p)) { 359 ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt);
445 p = mangle_path(s->buffer + s->len, p, "\n"); 360 if (ret == cnt)
446 if (p) { 361 return -EFAULT;
447 s->len = p - s->buffer;
448 return 1;
449 }
450 } else {
451 s->buffer[s->len++] = '?';
452 return 1;
453 }
454 362
455 return 0; 363 cnt -= ret;
456}
457 364
458static void 365 s->readpos += cnt;
459trace_seq_reset(struct trace_seq *s) 366 return cnt;
460{
461 s->len = 0;
462 s->readpos = 0;
463} 367}
464 368
465ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt) 369ssize_t trace_seq_to_buffer(struct trace_seq *s, void *buf, size_t cnt)
466{ 370{
467 int len; 371 int len;
468 int ret; 372 void *ret;
469 373
470 if (s->len <= s->readpos) 374 if (s->len <= s->readpos)
471 return -EBUSY; 375 return -EBUSY;
@@ -473,11 +377,11 @@ ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt)
473 len = s->len - s->readpos; 377 len = s->len - s->readpos;
474 if (cnt > len) 378 if (cnt > len)
475 cnt = len; 379 cnt = len;
476 ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt); 380 ret = memcpy(buf, s->buffer + s->readpos, cnt);
477 if (ret) 381 if (!ret)
478 return -EFAULT; 382 return -EFAULT;
479 383
480 s->readpos += len; 384 s->readpos += cnt;
481 return cnt; 385 return cnt;
482} 386}
483 387
@@ -489,7 +393,7 @@ trace_print_seq(struct seq_file *m, struct trace_seq *s)
489 s->buffer[len] = 0; 393 s->buffer[len] = 0;
490 seq_puts(m, s->buffer); 394 seq_puts(m, s->buffer);
491 395
492 trace_seq_reset(s); 396 trace_seq_init(s);
493} 397}
494 398
495/** 399/**
@@ -543,7 +447,7 @@ update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu)
543 447
544 ftrace_enable_cpu(); 448 ftrace_enable_cpu();
545 449
546 WARN_ON_ONCE(ret); 450 WARN_ON_ONCE(ret && ret != -EAGAIN);
547 451
548 __update_max_tr(tr, tsk, cpu); 452 __update_max_tr(tr, tsk, cpu);
549 __raw_spin_unlock(&ftrace_max_lock); 453 __raw_spin_unlock(&ftrace_max_lock);
@@ -556,6 +460,8 @@ update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu)
556 * Register a new plugin tracer. 460 * Register a new plugin tracer.
557 */ 461 */
558int register_tracer(struct tracer *type) 462int register_tracer(struct tracer *type)
463__releases(kernel_lock)
464__acquires(kernel_lock)
559{ 465{
560 struct tracer *t; 466 struct tracer *t;
561 int len; 467 int len;
@@ -594,9 +500,12 @@ int register_tracer(struct tracer *type)
594 else 500 else
595 if (!type->flags->opts) 501 if (!type->flags->opts)
596 type->flags->opts = dummy_tracer_opt; 502 type->flags->opts = dummy_tracer_opt;
503 if (!type->wait_pipe)
504 type->wait_pipe = default_wait_pipe;
505
597 506
598#ifdef CONFIG_FTRACE_STARTUP_TEST 507#ifdef CONFIG_FTRACE_STARTUP_TEST
599 if (type->selftest) { 508 if (type->selftest && !tracing_selftest_disabled) {
600 struct tracer *saved_tracer = current_trace; 509 struct tracer *saved_tracer = current_trace;
601 struct trace_array *tr = &global_trace; 510 struct trace_array *tr = &global_trace;
602 int i; 511 int i;
@@ -638,8 +547,26 @@ int register_tracer(struct tracer *type)
638 out: 547 out:
639 tracing_selftest_running = false; 548 tracing_selftest_running = false;
640 mutex_unlock(&trace_types_lock); 549 mutex_unlock(&trace_types_lock);
641 lock_kernel();
642 550
551 if (ret || !default_bootup_tracer)
552 goto out_unlock;
553
554 if (strncmp(default_bootup_tracer, type->name, BOOTUP_TRACER_SIZE))
555 goto out_unlock;
556
557 printk(KERN_INFO "Starting tracer '%s'\n", type->name);
558 /* Do we want this tracer to start on bootup? */
559 tracing_set_tracer(type->name);
560 default_bootup_tracer = NULL;
561 /* disable other selftests, since this will break it. */
562 tracing_selftest_disabled = 1;
563#ifdef CONFIG_FTRACE_STARTUP_TEST
564 printk(KERN_INFO "Disabling FTRACE selftests due to running tracer '%s'\n",
565 type->name);
566#endif
567
568 out_unlock:
569 lock_kernel();
643 return ret; 570 return ret;
644} 571}
645 572
@@ -658,6 +585,15 @@ void unregister_tracer(struct tracer *type)
658 585
659 found: 586 found:
660 *t = (*t)->next; 587 *t = (*t)->next;
588
589 if (type == current_trace && tracer_enabled) {
590 tracer_enabled = 0;
591 tracing_stop();
592 if (current_trace->stop)
593 current_trace->stop(&global_trace);
594 current_trace = &nop_trace;
595 }
596
661 if (strlen(type->name) != max_tracer_type_len) 597 if (strlen(type->name) != max_tracer_type_len)
662 goto out; 598 goto out;
663 599
@@ -693,10 +629,10 @@ static unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
693static unsigned map_cmdline_to_pid[SAVED_CMDLINES]; 629static unsigned map_cmdline_to_pid[SAVED_CMDLINES];
694static char saved_cmdlines[SAVED_CMDLINES][TASK_COMM_LEN]; 630static char saved_cmdlines[SAVED_CMDLINES][TASK_COMM_LEN];
695static int cmdline_idx; 631static int cmdline_idx;
696static DEFINE_SPINLOCK(trace_cmdline_lock); 632static raw_spinlock_t trace_cmdline_lock = __RAW_SPIN_LOCK_UNLOCKED;
697 633
698/* temporary disable recording */ 634/* temporary disable recording */
699atomic_t trace_record_cmdline_disabled __read_mostly; 635static atomic_t trace_record_cmdline_disabled __read_mostly;
700 636
701static void trace_init_cmdlines(void) 637static void trace_init_cmdlines(void)
702{ 638{
@@ -738,13 +674,12 @@ void tracing_start(void)
738 return; 674 return;
739 675
740 spin_lock_irqsave(&tracing_start_lock, flags); 676 spin_lock_irqsave(&tracing_start_lock, flags);
741 if (--trace_stop_count) 677 if (--trace_stop_count) {
742 goto out; 678 if (trace_stop_count < 0) {
743 679 /* Someone screwed up their debugging */
744 if (trace_stop_count < 0) { 680 WARN_ON_ONCE(1);
745 /* Someone screwed up their debugging */ 681 trace_stop_count = 0;
746 WARN_ON_ONCE(1); 682 }
747 trace_stop_count = 0;
748 goto out; 683 goto out;
749 } 684 }
750 685
@@ -806,7 +741,7 @@ static void trace_save_cmdline(struct task_struct *tsk)
806 * nor do we want to disable interrupts, 741 * nor do we want to disable interrupts,
807 * so if we miss here, then better luck next time. 742 * so if we miss here, then better luck next time.
808 */ 743 */
809 if (!spin_trylock(&trace_cmdline_lock)) 744 if (!__raw_spin_trylock(&trace_cmdline_lock))
810 return; 745 return;
811 746
812 idx = map_pid_to_cmdline[tsk->pid]; 747 idx = map_pid_to_cmdline[tsk->pid];
@@ -824,7 +759,7 @@ static void trace_save_cmdline(struct task_struct *tsk)
824 759
825 memcpy(&saved_cmdlines[idx], tsk->comm, TASK_COMM_LEN); 760 memcpy(&saved_cmdlines[idx], tsk->comm, TASK_COMM_LEN);
826 761
827 spin_unlock(&trace_cmdline_lock); 762 __raw_spin_unlock(&trace_cmdline_lock);
828} 763}
829 764
830char *trace_find_cmdline(int pid) 765char *trace_find_cmdline(int pid)
@@ -876,78 +811,114 @@ tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags,
876 (need_resched() ? TRACE_FLAG_NEED_RESCHED : 0); 811 (need_resched() ? TRACE_FLAG_NEED_RESCHED : 0);
877} 812}
878 813
814struct ring_buffer_event *trace_buffer_lock_reserve(struct trace_array *tr,
815 unsigned char type,
816 unsigned long len,
817 unsigned long flags, int pc)
818{
819 struct ring_buffer_event *event;
820
821 event = ring_buffer_lock_reserve(tr->buffer, len);
822 if (event != NULL) {
823 struct trace_entry *ent = ring_buffer_event_data(event);
824
825 tracing_generic_entry_update(ent, flags, pc);
826 ent->type = type;
827 }
828
829 return event;
830}
831static void ftrace_trace_stack(struct trace_array *tr,
832 unsigned long flags, int skip, int pc);
833static void ftrace_trace_userstack(struct trace_array *tr,
834 unsigned long flags, int pc);
835
836void trace_buffer_unlock_commit(struct trace_array *tr,
837 struct ring_buffer_event *event,
838 unsigned long flags, int pc)
839{
840 ring_buffer_unlock_commit(tr->buffer, event);
841
842 ftrace_trace_stack(tr, flags, 6, pc);
843 ftrace_trace_userstack(tr, flags, pc);
844 trace_wake_up();
845}
846
847struct ring_buffer_event *
848trace_current_buffer_lock_reserve(unsigned char type, unsigned long len,
849 unsigned long flags, int pc)
850{
851 return trace_buffer_lock_reserve(&global_trace,
852 type, len, flags, pc);
853}
854
855void trace_current_buffer_unlock_commit(struct ring_buffer_event *event,
856 unsigned long flags, int pc)
857{
858 return trace_buffer_unlock_commit(&global_trace, event, flags, pc);
859}
860
879void 861void
880trace_function(struct trace_array *tr, struct trace_array_cpu *data, 862trace_function(struct trace_array *tr,
881 unsigned long ip, unsigned long parent_ip, unsigned long flags, 863 unsigned long ip, unsigned long parent_ip, unsigned long flags,
882 int pc) 864 int pc)
883{ 865{
884 struct ring_buffer_event *event; 866 struct ring_buffer_event *event;
885 struct ftrace_entry *entry; 867 struct ftrace_entry *entry;
886 unsigned long irq_flags;
887 868
888 /* If we are reading the ring buffer, don't trace */ 869 /* If we are reading the ring buffer, don't trace */
889 if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled)))) 870 if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled))))
890 return; 871 return;
891 872
892 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry), 873 event = trace_buffer_lock_reserve(tr, TRACE_FN, sizeof(*entry),
893 &irq_flags); 874 flags, pc);
894 if (!event) 875 if (!event)
895 return; 876 return;
896 entry = ring_buffer_event_data(event); 877 entry = ring_buffer_event_data(event);
897 tracing_generic_entry_update(&entry->ent, flags, pc);
898 entry->ent.type = TRACE_FN;
899 entry->ip = ip; 878 entry->ip = ip;
900 entry->parent_ip = parent_ip; 879 entry->parent_ip = parent_ip;
901 ring_buffer_unlock_commit(tr->buffer, event, irq_flags); 880 ring_buffer_unlock_commit(tr->buffer, event);
902} 881}
903 882
904#ifdef CONFIG_FUNCTION_GRAPH_TRACER 883#ifdef CONFIG_FUNCTION_GRAPH_TRACER
905static void __trace_graph_entry(struct trace_array *tr, 884static void __trace_graph_entry(struct trace_array *tr,
906 struct trace_array_cpu *data,
907 struct ftrace_graph_ent *trace, 885 struct ftrace_graph_ent *trace,
908 unsigned long flags, 886 unsigned long flags,
909 int pc) 887 int pc)
910{ 888{
911 struct ring_buffer_event *event; 889 struct ring_buffer_event *event;
912 struct ftrace_graph_ent_entry *entry; 890 struct ftrace_graph_ent_entry *entry;
913 unsigned long irq_flags;
914 891
915 if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled)))) 892 if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled))))
916 return; 893 return;
917 894
918 event = ring_buffer_lock_reserve(global_trace.buffer, sizeof(*entry), 895 event = trace_buffer_lock_reserve(&global_trace, TRACE_GRAPH_ENT,
919 &irq_flags); 896 sizeof(*entry), flags, pc);
920 if (!event) 897 if (!event)
921 return; 898 return;
922 entry = ring_buffer_event_data(event); 899 entry = ring_buffer_event_data(event);
923 tracing_generic_entry_update(&entry->ent, flags, pc);
924 entry->ent.type = TRACE_GRAPH_ENT;
925 entry->graph_ent = *trace; 900 entry->graph_ent = *trace;
926 ring_buffer_unlock_commit(global_trace.buffer, event, irq_flags); 901 ring_buffer_unlock_commit(global_trace.buffer, event);
927} 902}
928 903
929static void __trace_graph_return(struct trace_array *tr, 904static void __trace_graph_return(struct trace_array *tr,
930 struct trace_array_cpu *data,
931 struct ftrace_graph_ret *trace, 905 struct ftrace_graph_ret *trace,
932 unsigned long flags, 906 unsigned long flags,
933 int pc) 907 int pc)
934{ 908{
935 struct ring_buffer_event *event; 909 struct ring_buffer_event *event;
936 struct ftrace_graph_ret_entry *entry; 910 struct ftrace_graph_ret_entry *entry;
937 unsigned long irq_flags;
938 911
939 if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled)))) 912 if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled))))
940 return; 913 return;
941 914
942 event = ring_buffer_lock_reserve(global_trace.buffer, sizeof(*entry), 915 event = trace_buffer_lock_reserve(&global_trace, TRACE_GRAPH_RET,
943 &irq_flags); 916 sizeof(*entry), flags, pc);
944 if (!event) 917 if (!event)
945 return; 918 return;
946 entry = ring_buffer_event_data(event); 919 entry = ring_buffer_event_data(event);
947 tracing_generic_entry_update(&entry->ent, flags, pc);
948 entry->ent.type = TRACE_GRAPH_RET;
949 entry->ret = *trace; 920 entry->ret = *trace;
950 ring_buffer_unlock_commit(global_trace.buffer, event, irq_flags); 921 ring_buffer_unlock_commit(global_trace.buffer, event);
951} 922}
952#endif 923#endif
953 924
@@ -957,31 +928,23 @@ ftrace(struct trace_array *tr, struct trace_array_cpu *data,
957 int pc) 928 int pc)
958{ 929{
959 if (likely(!atomic_read(&data->disabled))) 930 if (likely(!atomic_read(&data->disabled)))
960 trace_function(tr, data, ip, parent_ip, flags, pc); 931 trace_function(tr, ip, parent_ip, flags, pc);
961} 932}
962 933
963static void ftrace_trace_stack(struct trace_array *tr, 934static void __ftrace_trace_stack(struct trace_array *tr,
964 struct trace_array_cpu *data, 935 unsigned long flags,
965 unsigned long flags, 936 int skip, int pc)
966 int skip, int pc)
967{ 937{
968#ifdef CONFIG_STACKTRACE 938#ifdef CONFIG_STACKTRACE
969 struct ring_buffer_event *event; 939 struct ring_buffer_event *event;
970 struct stack_entry *entry; 940 struct stack_entry *entry;
971 struct stack_trace trace; 941 struct stack_trace trace;
972 unsigned long irq_flags;
973 942
974 if (!(trace_flags & TRACE_ITER_STACKTRACE)) 943 event = trace_buffer_lock_reserve(tr, TRACE_STACK,
975 return; 944 sizeof(*entry), flags, pc);
976
977 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
978 &irq_flags);
979 if (!event) 945 if (!event)
980 return; 946 return;
981 entry = ring_buffer_event_data(event); 947 entry = ring_buffer_event_data(event);
982 tracing_generic_entry_update(&entry->ent, flags, pc);
983 entry->ent.type = TRACE_STACK;
984
985 memset(&entry->caller, 0, sizeof(entry->caller)); 948 memset(&entry->caller, 0, sizeof(entry->caller));
986 949
987 trace.nr_entries = 0; 950 trace.nr_entries = 0;
@@ -990,38 +953,43 @@ static void ftrace_trace_stack(struct trace_array *tr,
990 trace.entries = entry->caller; 953 trace.entries = entry->caller;
991 954
992 save_stack_trace(&trace); 955 save_stack_trace(&trace);
993 ring_buffer_unlock_commit(tr->buffer, event, irq_flags); 956 ring_buffer_unlock_commit(tr->buffer, event);
994#endif 957#endif
995} 958}
996 959
960static void ftrace_trace_stack(struct trace_array *tr,
961 unsigned long flags,
962 int skip, int pc)
963{
964 if (!(trace_flags & TRACE_ITER_STACKTRACE))
965 return;
966
967 __ftrace_trace_stack(tr, flags, skip, pc);
968}
969
997void __trace_stack(struct trace_array *tr, 970void __trace_stack(struct trace_array *tr,
998 struct trace_array_cpu *data,
999 unsigned long flags, 971 unsigned long flags,
1000 int skip) 972 int skip, int pc)
1001{ 973{
1002 ftrace_trace_stack(tr, data, flags, skip, preempt_count()); 974 __ftrace_trace_stack(tr, flags, skip, pc);
1003} 975}
1004 976
1005static void ftrace_trace_userstack(struct trace_array *tr, 977static void ftrace_trace_userstack(struct trace_array *tr,
1006 struct trace_array_cpu *data, 978 unsigned long flags, int pc)
1007 unsigned long flags, int pc)
1008{ 979{
1009#ifdef CONFIG_STACKTRACE 980#ifdef CONFIG_STACKTRACE
1010 struct ring_buffer_event *event; 981 struct ring_buffer_event *event;
1011 struct userstack_entry *entry; 982 struct userstack_entry *entry;
1012 struct stack_trace trace; 983 struct stack_trace trace;
1013 unsigned long irq_flags;
1014 984
1015 if (!(trace_flags & TRACE_ITER_USERSTACKTRACE)) 985 if (!(trace_flags & TRACE_ITER_USERSTACKTRACE))
1016 return; 986 return;
1017 987
1018 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry), 988 event = trace_buffer_lock_reserve(tr, TRACE_USER_STACK,
1019 &irq_flags); 989 sizeof(*entry), flags, pc);
1020 if (!event) 990 if (!event)
1021 return; 991 return;
1022 entry = ring_buffer_event_data(event); 992 entry = ring_buffer_event_data(event);
1023 tracing_generic_entry_update(&entry->ent, flags, pc);
1024 entry->ent.type = TRACE_USER_STACK;
1025 993
1026 memset(&entry->caller, 0, sizeof(entry->caller)); 994 memset(&entry->caller, 0, sizeof(entry->caller));
1027 995
@@ -1031,70 +999,58 @@ static void ftrace_trace_userstack(struct trace_array *tr,
1031 trace.entries = entry->caller; 999 trace.entries = entry->caller;
1032 1000
1033 save_stack_trace_user(&trace); 1001 save_stack_trace_user(&trace);
1034 ring_buffer_unlock_commit(tr->buffer, event, irq_flags); 1002 ring_buffer_unlock_commit(tr->buffer, event);
1035#endif 1003#endif
1036} 1004}
1037 1005
1038void __trace_userstack(struct trace_array *tr, 1006#ifdef UNUSED
1039 struct trace_array_cpu *data, 1007static void __trace_userstack(struct trace_array *tr, unsigned long flags)
1040 unsigned long flags)
1041{ 1008{
1042 ftrace_trace_userstack(tr, data, flags, preempt_count()); 1009 ftrace_trace_userstack(tr, flags, preempt_count());
1043} 1010}
1011#endif /* UNUSED */
1044 1012
1045static void 1013static void
1046ftrace_trace_special(void *__tr, void *__data, 1014ftrace_trace_special(void *__tr,
1047 unsigned long arg1, unsigned long arg2, unsigned long arg3, 1015 unsigned long arg1, unsigned long arg2, unsigned long arg3,
1048 int pc) 1016 int pc)
1049{ 1017{
1050 struct ring_buffer_event *event; 1018 struct ring_buffer_event *event;
1051 struct trace_array_cpu *data = __data;
1052 struct trace_array *tr = __tr; 1019 struct trace_array *tr = __tr;
1053 struct special_entry *entry; 1020 struct special_entry *entry;
1054 unsigned long irq_flags;
1055 1021
1056 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry), 1022 event = trace_buffer_lock_reserve(tr, TRACE_SPECIAL,
1057 &irq_flags); 1023 sizeof(*entry), 0, pc);
1058 if (!event) 1024 if (!event)
1059 return; 1025 return;
1060 entry = ring_buffer_event_data(event); 1026 entry = ring_buffer_event_data(event);
1061 tracing_generic_entry_update(&entry->ent, 0, pc);
1062 entry->ent.type = TRACE_SPECIAL;
1063 entry->arg1 = arg1; 1027 entry->arg1 = arg1;
1064 entry->arg2 = arg2; 1028 entry->arg2 = arg2;
1065 entry->arg3 = arg3; 1029 entry->arg3 = arg3;
1066 ring_buffer_unlock_commit(tr->buffer, event, irq_flags); 1030 trace_buffer_unlock_commit(tr, event, 0, pc);
1067 ftrace_trace_stack(tr, data, irq_flags, 4, pc);
1068 ftrace_trace_userstack(tr, data, irq_flags, pc);
1069
1070 trace_wake_up();
1071} 1031}
1072 1032
1073void 1033void
1074__trace_special(void *__tr, void *__data, 1034__trace_special(void *__tr, void *__data,
1075 unsigned long arg1, unsigned long arg2, unsigned long arg3) 1035 unsigned long arg1, unsigned long arg2, unsigned long arg3)
1076{ 1036{
1077 ftrace_trace_special(__tr, __data, arg1, arg2, arg3, preempt_count()); 1037 ftrace_trace_special(__tr, arg1, arg2, arg3, preempt_count());
1078} 1038}
1079 1039
1080void 1040void
1081tracing_sched_switch_trace(struct trace_array *tr, 1041tracing_sched_switch_trace(struct trace_array *tr,
1082 struct trace_array_cpu *data,
1083 struct task_struct *prev, 1042 struct task_struct *prev,
1084 struct task_struct *next, 1043 struct task_struct *next,
1085 unsigned long flags, int pc) 1044 unsigned long flags, int pc)
1086{ 1045{
1087 struct ring_buffer_event *event; 1046 struct ring_buffer_event *event;
1088 struct ctx_switch_entry *entry; 1047 struct ctx_switch_entry *entry;
1089 unsigned long irq_flags;
1090 1048
1091 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry), 1049 event = trace_buffer_lock_reserve(tr, TRACE_CTX,
1092 &irq_flags); 1050 sizeof(*entry), flags, pc);
1093 if (!event) 1051 if (!event)
1094 return; 1052 return;
1095 entry = ring_buffer_event_data(event); 1053 entry = ring_buffer_event_data(event);
1096 tracing_generic_entry_update(&entry->ent, flags, pc);
1097 entry->ent.type = TRACE_CTX;
1098 entry->prev_pid = prev->pid; 1054 entry->prev_pid = prev->pid;
1099 entry->prev_prio = prev->prio; 1055 entry->prev_prio = prev->prio;
1100 entry->prev_state = prev->state; 1056 entry->prev_state = prev->state;
@@ -1102,29 +1058,23 @@ tracing_sched_switch_trace(struct trace_array *tr,
1102 entry->next_prio = next->prio; 1058 entry->next_prio = next->prio;
1103 entry->next_state = next->state; 1059 entry->next_state = next->state;
1104 entry->next_cpu = task_cpu(next); 1060 entry->next_cpu = task_cpu(next);
1105 ring_buffer_unlock_commit(tr->buffer, event, irq_flags); 1061 trace_buffer_unlock_commit(tr, event, flags, pc);
1106 ftrace_trace_stack(tr, data, flags, 5, pc);
1107 ftrace_trace_userstack(tr, data, flags, pc);
1108} 1062}
1109 1063
1110void 1064void
1111tracing_sched_wakeup_trace(struct trace_array *tr, 1065tracing_sched_wakeup_trace(struct trace_array *tr,
1112 struct trace_array_cpu *data,
1113 struct task_struct *wakee, 1066 struct task_struct *wakee,
1114 struct task_struct *curr, 1067 struct task_struct *curr,
1115 unsigned long flags, int pc) 1068 unsigned long flags, int pc)
1116{ 1069{
1117 struct ring_buffer_event *event; 1070 struct ring_buffer_event *event;
1118 struct ctx_switch_entry *entry; 1071 struct ctx_switch_entry *entry;
1119 unsigned long irq_flags;
1120 1072
1121 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry), 1073 event = trace_buffer_lock_reserve(tr, TRACE_WAKE,
1122 &irq_flags); 1074 sizeof(*entry), flags, pc);
1123 if (!event) 1075 if (!event)
1124 return; 1076 return;
1125 entry = ring_buffer_event_data(event); 1077 entry = ring_buffer_event_data(event);
1126 tracing_generic_entry_update(&entry->ent, flags, pc);
1127 entry->ent.type = TRACE_WAKE;
1128 entry->prev_pid = curr->pid; 1078 entry->prev_pid = curr->pid;
1129 entry->prev_prio = curr->prio; 1079 entry->prev_prio = curr->prio;
1130 entry->prev_state = curr->state; 1080 entry->prev_state = curr->state;
@@ -1132,11 +1082,10 @@ tracing_sched_wakeup_trace(struct trace_array *tr,
1132 entry->next_prio = wakee->prio; 1082 entry->next_prio = wakee->prio;
1133 entry->next_state = wakee->state; 1083 entry->next_state = wakee->state;
1134 entry->next_cpu = task_cpu(wakee); 1084 entry->next_cpu = task_cpu(wakee);
1135 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
1136 ftrace_trace_stack(tr, data, flags, 6, pc);
1137 ftrace_trace_userstack(tr, data, flags, pc);
1138 1085
1139 trace_wake_up(); 1086 ring_buffer_unlock_commit(tr->buffer, event);
1087 ftrace_trace_stack(tr, flags, 6, pc);
1088 ftrace_trace_userstack(tr, flags, pc);
1140} 1089}
1141 1090
1142void 1091void
@@ -1157,66 +1106,7 @@ ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3)
1157 data = tr->data[cpu]; 1106 data = tr->data[cpu];
1158 1107
1159 if (likely(atomic_inc_return(&data->disabled) == 1)) 1108 if (likely(atomic_inc_return(&data->disabled) == 1))
1160 ftrace_trace_special(tr, data, arg1, arg2, arg3, pc); 1109 ftrace_trace_special(tr, arg1, arg2, arg3, pc);
1161
1162 atomic_dec(&data->disabled);
1163 local_irq_restore(flags);
1164}
1165
1166#ifdef CONFIG_FUNCTION_TRACER
1167static void
1168function_trace_call_preempt_only(unsigned long ip, unsigned long parent_ip)
1169{
1170 struct trace_array *tr = &global_trace;
1171 struct trace_array_cpu *data;
1172 unsigned long flags;
1173 long disabled;
1174 int cpu, resched;
1175 int pc;
1176
1177 if (unlikely(!ftrace_function_enabled))
1178 return;
1179
1180 pc = preempt_count();
1181 resched = ftrace_preempt_disable();
1182 local_save_flags(flags);
1183 cpu = raw_smp_processor_id();
1184 data = tr->data[cpu];
1185 disabled = atomic_inc_return(&data->disabled);
1186
1187 if (likely(disabled == 1))
1188 trace_function(tr, data, ip, parent_ip, flags, pc);
1189
1190 atomic_dec(&data->disabled);
1191 ftrace_preempt_enable(resched);
1192}
1193
1194static void
1195function_trace_call(unsigned long ip, unsigned long parent_ip)
1196{
1197 struct trace_array *tr = &global_trace;
1198 struct trace_array_cpu *data;
1199 unsigned long flags;
1200 long disabled;
1201 int cpu;
1202 int pc;
1203
1204 if (unlikely(!ftrace_function_enabled))
1205 return;
1206
1207 /*
1208 * Need to use raw, since this must be called before the
1209 * recursive protection is performed.
1210 */
1211 local_irq_save(flags);
1212 cpu = raw_smp_processor_id();
1213 data = tr->data[cpu];
1214 disabled = atomic_inc_return(&data->disabled);
1215
1216 if (likely(disabled == 1)) {
1217 pc = preempt_count();
1218 trace_function(tr, data, ip, parent_ip, flags, pc);
1219 }
1220 1110
1221 atomic_dec(&data->disabled); 1111 atomic_dec(&data->disabled);
1222 local_irq_restore(flags); 1112 local_irq_restore(flags);
@@ -1244,7 +1134,7 @@ int trace_graph_entry(struct ftrace_graph_ent *trace)
1244 disabled = atomic_inc_return(&data->disabled); 1134 disabled = atomic_inc_return(&data->disabled);
1245 if (likely(disabled == 1)) { 1135 if (likely(disabled == 1)) {
1246 pc = preempt_count(); 1136 pc = preempt_count();
1247 __trace_graph_entry(tr, data, trace, flags, pc); 1137 __trace_graph_entry(tr, trace, flags, pc);
1248 } 1138 }
1249 /* Only do the atomic if it is not already set */ 1139 /* Only do the atomic if it is not already set */
1250 if (!test_tsk_trace_graph(current)) 1140 if (!test_tsk_trace_graph(current))
@@ -1270,7 +1160,7 @@ void trace_graph_return(struct ftrace_graph_ret *trace)
1270 disabled = atomic_inc_return(&data->disabled); 1160 disabled = atomic_inc_return(&data->disabled);
1271 if (likely(disabled == 1)) { 1161 if (likely(disabled == 1)) {
1272 pc = preempt_count(); 1162 pc = preempt_count();
1273 __trace_graph_return(tr, data, trace, flags, pc); 1163 __trace_graph_return(tr, trace, flags, pc);
1274 } 1164 }
1275 if (!trace->depth) 1165 if (!trace->depth)
1276 clear_tsk_trace_graph(current); 1166 clear_tsk_trace_graph(current);
@@ -1279,30 +1169,66 @@ void trace_graph_return(struct ftrace_graph_ret *trace)
1279} 1169}
1280#endif /* CONFIG_FUNCTION_GRAPH_TRACER */ 1170#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
1281 1171
1282static struct ftrace_ops trace_ops __read_mostly =
1283{
1284 .func = function_trace_call,
1285};
1286 1172
1287void tracing_start_function_trace(void) 1173/**
1174 * trace_vprintk - write binary msg to tracing buffer
1175 *
1176 */
1177int trace_vprintk(unsigned long ip, int depth, const char *fmt, va_list args)
1288{ 1178{
1289 ftrace_function_enabled = 0; 1179 static DEFINE_SPINLOCK(trace_buf_lock);
1180 static u32 trace_buf[TRACE_BUF_SIZE];
1290 1181
1291 if (trace_flags & TRACE_ITER_PREEMPTONLY) 1182 struct ring_buffer_event *event;
1292 trace_ops.func = function_trace_call_preempt_only; 1183 struct trace_array *tr = &global_trace;
1293 else 1184 struct trace_array_cpu *data;
1294 trace_ops.func = function_trace_call; 1185 struct print_entry *entry;
1186 unsigned long flags;
1187 int resched;
1188 int cpu, len = 0, size, pc;
1295 1189
1296 register_ftrace_function(&trace_ops); 1190 if (unlikely(tracing_selftest_running || tracing_disabled))
1297 ftrace_function_enabled = 1; 1191 return 0;
1298}
1299 1192
1300void tracing_stop_function_trace(void) 1193 /* Don't pollute graph traces with trace_vprintk internals */
1301{ 1194 pause_graph_tracing();
1302 ftrace_function_enabled = 0; 1195
1303 unregister_ftrace_function(&trace_ops); 1196 pc = preempt_count();
1197 resched = ftrace_preempt_disable();
1198 cpu = raw_smp_processor_id();
1199 data = tr->data[cpu];
1200
1201 if (unlikely(atomic_read(&data->disabled)))
1202 goto out;
1203
1204 spin_lock_irqsave(&trace_buf_lock, flags);
1205 len = vbin_printf(trace_buf, TRACE_BUF_SIZE, fmt, args);
1206
1207 if (len > TRACE_BUF_SIZE || len < 0)
1208 goto out_unlock;
1209
1210 size = sizeof(*entry) + sizeof(u32) * len;
1211 event = trace_buffer_lock_reserve(tr, TRACE_PRINT, size, flags, pc);
1212 if (!event)
1213 goto out_unlock;
1214 entry = ring_buffer_event_data(event);
1215 entry->ip = ip;
1216 entry->depth = depth;
1217 entry->fmt = fmt;
1218
1219 memcpy(entry->buf, trace_buf, sizeof(u32) * len);
1220 ring_buffer_unlock_commit(tr->buffer, event);
1221
1222out_unlock:
1223 spin_unlock_irqrestore(&trace_buf_lock, flags);
1224
1225out:
1226 ftrace_preempt_enable(resched);
1227 unpause_graph_tracing();
1228
1229 return len;
1304} 1230}
1305#endif 1231EXPORT_SYMBOL_GPL(trace_vprintk);
1306 1232
1307enum trace_file_type { 1233enum trace_file_type {
1308 TRACE_FILE_LAT_FMT = 1, 1234 TRACE_FILE_LAT_FMT = 1,
@@ -1345,10 +1271,25 @@ __find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts)
1345{ 1271{
1346 struct ring_buffer *buffer = iter->tr->buffer; 1272 struct ring_buffer *buffer = iter->tr->buffer;
1347 struct trace_entry *ent, *next = NULL; 1273 struct trace_entry *ent, *next = NULL;
1274 int cpu_file = iter->cpu_file;
1348 u64 next_ts = 0, ts; 1275 u64 next_ts = 0, ts;
1349 int next_cpu = -1; 1276 int next_cpu = -1;
1350 int cpu; 1277 int cpu;
1351 1278
1279 /*
1280 * If we are in a per_cpu trace file, don't bother by iterating over
1281 * all cpu and peek directly.
1282 */
1283 if (cpu_file > TRACE_PIPE_ALL_CPU) {
1284 if (ring_buffer_empty_cpu(buffer, cpu_file))
1285 return NULL;
1286 ent = peek_next_entry(iter, cpu_file, ent_ts);
1287 if (ent_cpu)
1288 *ent_cpu = cpu_file;
1289
1290 return ent;
1291 }
1292
1352 for_each_tracing_cpu(cpu) { 1293 for_each_tracing_cpu(cpu) {
1353 1294
1354 if (ring_buffer_empty_cpu(buffer, cpu)) 1295 if (ring_buffer_empty_cpu(buffer, cpu))
@@ -1376,8 +1317,8 @@ __find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts)
1376} 1317}
1377 1318
1378/* Find the next real entry, without updating the iterator itself */ 1319/* Find the next real entry, without updating the iterator itself */
1379static struct trace_entry * 1320struct trace_entry *trace_find_next_entry(struct trace_iterator *iter,
1380find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts) 1321 int *ent_cpu, u64 *ent_ts)
1381{ 1322{
1382 return __find_next_entry(iter, ent_cpu, ent_ts); 1323 return __find_next_entry(iter, ent_cpu, ent_ts);
1383} 1324}
@@ -1426,19 +1367,32 @@ static void *s_next(struct seq_file *m, void *v, loff_t *pos)
1426 return ent; 1367 return ent;
1427} 1368}
1428 1369
1370/*
1371 * No necessary locking here. The worst thing which can
1372 * happen is loosing events consumed at the same time
1373 * by a trace_pipe reader.
1374 * Other than that, we don't risk to crash the ring buffer
1375 * because it serializes the readers.
1376 *
1377 * The current tracer is copied to avoid a global locking
1378 * all around.
1379 */
1429static void *s_start(struct seq_file *m, loff_t *pos) 1380static void *s_start(struct seq_file *m, loff_t *pos)
1430{ 1381{
1431 struct trace_iterator *iter = m->private; 1382 struct trace_iterator *iter = m->private;
1383 static struct tracer *old_tracer;
1384 int cpu_file = iter->cpu_file;
1432 void *p = NULL; 1385 void *p = NULL;
1433 loff_t l = 0; 1386 loff_t l = 0;
1434 int cpu; 1387 int cpu;
1435 1388
1389 /* copy the tracer to avoid using a global lock all around */
1436 mutex_lock(&trace_types_lock); 1390 mutex_lock(&trace_types_lock);
1437 1391 if (unlikely(old_tracer != current_trace && current_trace)) {
1438 if (!current_trace || current_trace != iter->trace) { 1392 old_tracer = current_trace;
1439 mutex_unlock(&trace_types_lock); 1393 *iter->trace = *current_trace;
1440 return NULL;
1441 } 1394 }
1395 mutex_unlock(&trace_types_lock);
1442 1396
1443 atomic_inc(&trace_record_cmdline_disabled); 1397 atomic_inc(&trace_record_cmdline_disabled);
1444 1398
@@ -1449,9 +1403,12 @@ static void *s_start(struct seq_file *m, loff_t *pos)
1449 1403
1450 ftrace_disable_cpu(); 1404 ftrace_disable_cpu();
1451 1405
1452 for_each_tracing_cpu(cpu) { 1406 if (cpu_file == TRACE_PIPE_ALL_CPU) {
1453 ring_buffer_iter_reset(iter->buffer_iter[cpu]); 1407 for_each_tracing_cpu(cpu)
1454 } 1408 ring_buffer_iter_reset(iter->buffer_iter[cpu]);
1409 } else
1410 ring_buffer_iter_reset(iter->buffer_iter[cpu_file]);
1411
1455 1412
1456 ftrace_enable_cpu(); 1413 ftrace_enable_cpu();
1457 1414
@@ -1469,155 +1426,6 @@ static void *s_start(struct seq_file *m, loff_t *pos)
1469static void s_stop(struct seq_file *m, void *p) 1426static void s_stop(struct seq_file *m, void *p)
1470{ 1427{
1471 atomic_dec(&trace_record_cmdline_disabled); 1428 atomic_dec(&trace_record_cmdline_disabled);
1472 mutex_unlock(&trace_types_lock);
1473}
1474
1475#ifdef CONFIG_KRETPROBES
1476static inline const char *kretprobed(const char *name)
1477{
1478 static const char tramp_name[] = "kretprobe_trampoline";
1479 int size = sizeof(tramp_name);
1480
1481 if (strncmp(tramp_name, name, size) == 0)
1482 return "[unknown/kretprobe'd]";
1483 return name;
1484}
1485#else
1486static inline const char *kretprobed(const char *name)
1487{
1488 return name;
1489}
1490#endif /* CONFIG_KRETPROBES */
1491
1492static int
1493seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
1494{
1495#ifdef CONFIG_KALLSYMS
1496 char str[KSYM_SYMBOL_LEN];
1497 const char *name;
1498
1499 kallsyms_lookup(address, NULL, NULL, NULL, str);
1500
1501 name = kretprobed(str);
1502
1503 return trace_seq_printf(s, fmt, name);
1504#endif
1505 return 1;
1506}
1507
1508static int
1509seq_print_sym_offset(struct trace_seq *s, const char *fmt,
1510 unsigned long address)
1511{
1512#ifdef CONFIG_KALLSYMS
1513 char str[KSYM_SYMBOL_LEN];
1514 const char *name;
1515
1516 sprint_symbol(str, address);
1517 name = kretprobed(str);
1518
1519 return trace_seq_printf(s, fmt, name);
1520#endif
1521 return 1;
1522}
1523
1524#ifndef CONFIG_64BIT
1525# define IP_FMT "%08lx"
1526#else
1527# define IP_FMT "%016lx"
1528#endif
1529
1530int
1531seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
1532{
1533 int ret;
1534
1535 if (!ip)
1536 return trace_seq_printf(s, "0");
1537
1538 if (sym_flags & TRACE_ITER_SYM_OFFSET)
1539 ret = seq_print_sym_offset(s, "%s", ip);
1540 else
1541 ret = seq_print_sym_short(s, "%s", ip);
1542
1543 if (!ret)
1544 return 0;
1545
1546 if (sym_flags & TRACE_ITER_SYM_ADDR)
1547 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
1548 return ret;
1549}
1550
1551static inline int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
1552 unsigned long ip, unsigned long sym_flags)
1553{
1554 struct file *file = NULL;
1555 unsigned long vmstart = 0;
1556 int ret = 1;
1557
1558 if (mm) {
1559 const struct vm_area_struct *vma;
1560
1561 down_read(&mm->mmap_sem);
1562 vma = find_vma(mm, ip);
1563 if (vma) {
1564 file = vma->vm_file;
1565 vmstart = vma->vm_start;
1566 }
1567 if (file) {
1568 ret = trace_seq_path(s, &file->f_path);
1569 if (ret)
1570 ret = trace_seq_printf(s, "[+0x%lx]", ip - vmstart);
1571 }
1572 up_read(&mm->mmap_sem);
1573 }
1574 if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
1575 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
1576 return ret;
1577}
1578
1579static int
1580seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s,
1581 unsigned long sym_flags)
1582{
1583 struct mm_struct *mm = NULL;
1584 int ret = 1;
1585 unsigned int i;
1586
1587 if (trace_flags & TRACE_ITER_SYM_USEROBJ) {
1588 struct task_struct *task;
1589 /*
1590 * we do the lookup on the thread group leader,
1591 * since individual threads might have already quit!
1592 */
1593 rcu_read_lock();
1594 task = find_task_by_vpid(entry->ent.tgid);
1595 if (task)
1596 mm = get_task_mm(task);
1597 rcu_read_unlock();
1598 }
1599
1600 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
1601 unsigned long ip = entry->caller[i];
1602
1603 if (ip == ULONG_MAX || !ret)
1604 break;
1605 if (i && ret)
1606 ret = trace_seq_puts(s, " <- ");
1607 if (!ip) {
1608 if (ret)
1609 ret = trace_seq_puts(s, "??");
1610 continue;
1611 }
1612 if (!ret)
1613 break;
1614 if (ret)
1615 ret = seq_print_user_ip(s, mm, ip, sym_flags);
1616 }
1617
1618 if (mm)
1619 mmput(mm);
1620 return ret;
1621} 1429}
1622 1430
1623static void print_lat_help_header(struct seq_file *m) 1431static void print_lat_help_header(struct seq_file *m)
@@ -1658,11 +1466,11 @@ print_trace_header(struct seq_file *m, struct trace_iterator *iter)
1658 total = entries + 1466 total = entries +
1659 ring_buffer_overruns(iter->tr->buffer); 1467 ring_buffer_overruns(iter->tr->buffer);
1660 1468
1661 seq_printf(m, "%s latency trace v1.1.5 on %s\n", 1469 seq_printf(m, "# %s latency trace v1.1.5 on %s\n",
1662 name, UTS_RELEASE); 1470 name, UTS_RELEASE);
1663 seq_puts(m, "-----------------------------------" 1471 seq_puts(m, "# -----------------------------------"
1664 "---------------------------------\n"); 1472 "---------------------------------\n");
1665 seq_printf(m, " latency: %lu us, #%lu/%lu, CPU#%d |" 1473 seq_printf(m, "# latency: %lu us, #%lu/%lu, CPU#%d |"
1666 " (M:%s VP:%d, KP:%d, SP:%d HP:%d", 1474 " (M:%s VP:%d, KP:%d, SP:%d HP:%d",
1667 nsecs_to_usecs(data->saved_latency), 1475 nsecs_to_usecs(data->saved_latency),
1668 entries, 1476 entries,
@@ -1684,121 +1492,24 @@ print_trace_header(struct seq_file *m, struct trace_iterator *iter)
1684#else 1492#else
1685 seq_puts(m, ")\n"); 1493 seq_puts(m, ")\n");
1686#endif 1494#endif
1687 seq_puts(m, " -----------------\n"); 1495 seq_puts(m, "# -----------------\n");
1688 seq_printf(m, " | task: %.16s-%d " 1496 seq_printf(m, "# | task: %.16s-%d "
1689 "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n", 1497 "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n",
1690 data->comm, data->pid, data->uid, data->nice, 1498 data->comm, data->pid, data->uid, data->nice,
1691 data->policy, data->rt_priority); 1499 data->policy, data->rt_priority);
1692 seq_puts(m, " -----------------\n"); 1500 seq_puts(m, "# -----------------\n");
1693 1501
1694 if (data->critical_start) { 1502 if (data->critical_start) {
1695 seq_puts(m, " => started at: "); 1503 seq_puts(m, "# => started at: ");
1696 seq_print_ip_sym(&iter->seq, data->critical_start, sym_flags); 1504 seq_print_ip_sym(&iter->seq, data->critical_start, sym_flags);
1697 trace_print_seq(m, &iter->seq); 1505 trace_print_seq(m, &iter->seq);
1698 seq_puts(m, "\n => ended at: "); 1506 seq_puts(m, "\n# => ended at: ");
1699 seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags); 1507 seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags);
1700 trace_print_seq(m, &iter->seq); 1508 trace_print_seq(m, &iter->seq);
1701 seq_puts(m, "\n"); 1509 seq_puts(m, "#\n");
1702 }
1703
1704 seq_puts(m, "\n");
1705}
1706
1707static void
1708lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
1709{
1710 int hardirq, softirq;
1711 char *comm;
1712
1713 comm = trace_find_cmdline(entry->pid);
1714
1715 trace_seq_printf(s, "%8.8s-%-5d ", comm, entry->pid);
1716 trace_seq_printf(s, "%3d", cpu);
1717 trace_seq_printf(s, "%c%c",
1718 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
1719 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' : '.',
1720 ((entry->flags & TRACE_FLAG_NEED_RESCHED) ? 'N' : '.'));
1721
1722 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
1723 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
1724 if (hardirq && softirq) {
1725 trace_seq_putc(s, 'H');
1726 } else {
1727 if (hardirq) {
1728 trace_seq_putc(s, 'h');
1729 } else {
1730 if (softirq)
1731 trace_seq_putc(s, 's');
1732 else
1733 trace_seq_putc(s, '.');
1734 }
1735 } 1510 }
1736 1511
1737 if (entry->preempt_count) 1512 seq_puts(m, "#\n");
1738 trace_seq_printf(s, "%x", entry->preempt_count);
1739 else
1740 trace_seq_puts(s, ".");
1741}
1742
1743unsigned long preempt_mark_thresh = 100;
1744
1745static void
1746lat_print_timestamp(struct trace_seq *s, u64 abs_usecs,
1747 unsigned long rel_usecs)
1748{
1749 trace_seq_printf(s, " %4lldus", abs_usecs);
1750 if (rel_usecs > preempt_mark_thresh)
1751 trace_seq_puts(s, "!: ");
1752 else if (rel_usecs > 1)
1753 trace_seq_puts(s, "+: ");
1754 else
1755 trace_seq_puts(s, " : ");
1756}
1757
1758static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
1759
1760static int task_state_char(unsigned long state)
1761{
1762 int bit = state ? __ffs(state) + 1 : 0;
1763
1764 return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
1765}
1766
1767/*
1768 * The message is supposed to contain an ending newline.
1769 * If the printing stops prematurely, try to add a newline of our own.
1770 */
1771void trace_seq_print_cont(struct trace_seq *s, struct trace_iterator *iter)
1772{
1773 struct trace_entry *ent;
1774 struct trace_field_cont *cont;
1775 bool ok = true;
1776
1777 ent = peek_next_entry(iter, iter->cpu, NULL);
1778 if (!ent || ent->type != TRACE_CONT) {
1779 trace_seq_putc(s, '\n');
1780 return;
1781 }
1782
1783 do {
1784 cont = (struct trace_field_cont *)ent;
1785 if (ok)
1786 ok = (trace_seq_printf(s, "%s", cont->buf) > 0);
1787
1788 ftrace_disable_cpu();
1789
1790 if (iter->buffer_iter[iter->cpu])
1791 ring_buffer_read(iter->buffer_iter[iter->cpu], NULL);
1792 else
1793 ring_buffer_consume(iter->tr->buffer, iter->cpu, NULL);
1794
1795 ftrace_enable_cpu();
1796
1797 ent = peek_next_entry(iter, iter->cpu, NULL);
1798 } while (ent && ent->type == TRACE_CONT);
1799
1800 if (!ok)
1801 trace_seq_putc(s, '\n');
1802} 1513}
1803 1514
1804static void test_cpu_buff_start(struct trace_iterator *iter) 1515static void test_cpu_buff_start(struct trace_iterator *iter)
@@ -1818,452 +1529,88 @@ static void test_cpu_buff_start(struct trace_iterator *iter)
1818 trace_seq_printf(s, "##### CPU %u buffer started ####\n", iter->cpu); 1529 trace_seq_printf(s, "##### CPU %u buffer started ####\n", iter->cpu);
1819} 1530}
1820 1531
1821static enum print_line_t
1822print_lat_fmt(struct trace_iterator *iter, unsigned int trace_idx, int cpu)
1823{
1824 struct trace_seq *s = &iter->seq;
1825 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
1826 struct trace_entry *next_entry;
1827 unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
1828 struct trace_entry *entry = iter->ent;
1829 unsigned long abs_usecs;
1830 unsigned long rel_usecs;
1831 u64 next_ts;
1832 char *comm;
1833 int S, T;
1834 int i;
1835
1836 if (entry->type == TRACE_CONT)
1837 return TRACE_TYPE_HANDLED;
1838
1839 test_cpu_buff_start(iter);
1840
1841 next_entry = find_next_entry(iter, NULL, &next_ts);
1842 if (!next_entry)
1843 next_ts = iter->ts;
1844 rel_usecs = ns2usecs(next_ts - iter->ts);
1845 abs_usecs = ns2usecs(iter->ts - iter->tr->time_start);
1846
1847 if (verbose) {
1848 comm = trace_find_cmdline(entry->pid);
1849 trace_seq_printf(s, "%16s %5d %3d %d %08x %08x [%08lx]"
1850 " %ld.%03ldms (+%ld.%03ldms): ",
1851 comm,
1852 entry->pid, cpu, entry->flags,
1853 entry->preempt_count, trace_idx,
1854 ns2usecs(iter->ts),
1855 abs_usecs/1000,
1856 abs_usecs % 1000, rel_usecs/1000,
1857 rel_usecs % 1000);
1858 } else {
1859 lat_print_generic(s, entry, cpu);
1860 lat_print_timestamp(s, abs_usecs, rel_usecs);
1861 }
1862 switch (entry->type) {
1863 case TRACE_FN: {
1864 struct ftrace_entry *field;
1865
1866 trace_assign_type(field, entry);
1867
1868 seq_print_ip_sym(s, field->ip, sym_flags);
1869 trace_seq_puts(s, " (");
1870 seq_print_ip_sym(s, field->parent_ip, sym_flags);
1871 trace_seq_puts(s, ")\n");
1872 break;
1873 }
1874 case TRACE_CTX:
1875 case TRACE_WAKE: {
1876 struct ctx_switch_entry *field;
1877
1878 trace_assign_type(field, entry);
1879
1880 T = task_state_char(field->next_state);
1881 S = task_state_char(field->prev_state);
1882 comm = trace_find_cmdline(field->next_pid);
1883 trace_seq_printf(s, " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
1884 field->prev_pid,
1885 field->prev_prio,
1886 S, entry->type == TRACE_CTX ? "==>" : " +",
1887 field->next_cpu,
1888 field->next_pid,
1889 field->next_prio,
1890 T, comm);
1891 break;
1892 }
1893 case TRACE_SPECIAL: {
1894 struct special_entry *field;
1895
1896 trace_assign_type(field, entry);
1897
1898 trace_seq_printf(s, "# %ld %ld %ld\n",
1899 field->arg1,
1900 field->arg2,
1901 field->arg3);
1902 break;
1903 }
1904 case TRACE_STACK: {
1905 struct stack_entry *field;
1906
1907 trace_assign_type(field, entry);
1908
1909 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
1910 if (i)
1911 trace_seq_puts(s, " <= ");
1912 seq_print_ip_sym(s, field->caller[i], sym_flags);
1913 }
1914 trace_seq_puts(s, "\n");
1915 break;
1916 }
1917 case TRACE_PRINT: {
1918 struct print_entry *field;
1919
1920 trace_assign_type(field, entry);
1921
1922 seq_print_ip_sym(s, field->ip, sym_flags);
1923 trace_seq_printf(s, ": %s", field->buf);
1924 if (entry->flags & TRACE_FLAG_CONT)
1925 trace_seq_print_cont(s, iter);
1926 break;
1927 }
1928 case TRACE_BRANCH: {
1929 struct trace_branch *field;
1930
1931 trace_assign_type(field, entry);
1932
1933 trace_seq_printf(s, "[%s] %s:%s:%d\n",
1934 field->correct ? " ok " : " MISS ",
1935 field->func,
1936 field->file,
1937 field->line);
1938 break;
1939 }
1940 case TRACE_USER_STACK: {
1941 struct userstack_entry *field;
1942
1943 trace_assign_type(field, entry);
1944
1945 seq_print_userip_objs(field, s, sym_flags);
1946 trace_seq_putc(s, '\n');
1947 break;
1948 }
1949 default:
1950 trace_seq_printf(s, "Unknown type %d\n", entry->type);
1951 }
1952 return TRACE_TYPE_HANDLED;
1953}
1954
1955static enum print_line_t print_trace_fmt(struct trace_iterator *iter) 1532static enum print_line_t print_trace_fmt(struct trace_iterator *iter)
1956{ 1533{
1957 struct trace_seq *s = &iter->seq; 1534 struct trace_seq *s = &iter->seq;
1958 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); 1535 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
1959 struct trace_entry *entry; 1536 struct trace_entry *entry;
1960 unsigned long usec_rem; 1537 struct trace_event *event;
1961 unsigned long long t;
1962 unsigned long secs;
1963 char *comm;
1964 int ret;
1965 int S, T;
1966 int i;
1967 1538
1968 entry = iter->ent; 1539 entry = iter->ent;
1969 1540
1970 if (entry->type == TRACE_CONT)
1971 return TRACE_TYPE_HANDLED;
1972
1973 test_cpu_buff_start(iter); 1541 test_cpu_buff_start(iter);
1974 1542
1975 comm = trace_find_cmdline(iter->ent->pid); 1543 event = ftrace_find_event(entry->type);
1976
1977 t = ns2usecs(iter->ts);
1978 usec_rem = do_div(t, 1000000ULL);
1979 secs = (unsigned long)t;
1980
1981 ret = trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid);
1982 if (!ret)
1983 return TRACE_TYPE_PARTIAL_LINE;
1984 ret = trace_seq_printf(s, "[%03d] ", iter->cpu);
1985 if (!ret)
1986 return TRACE_TYPE_PARTIAL_LINE;
1987 ret = trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem);
1988 if (!ret)
1989 return TRACE_TYPE_PARTIAL_LINE;
1990
1991 switch (entry->type) {
1992 case TRACE_FN: {
1993 struct ftrace_entry *field;
1994
1995 trace_assign_type(field, entry);
1996
1997 ret = seq_print_ip_sym(s, field->ip, sym_flags);
1998 if (!ret)
1999 return TRACE_TYPE_PARTIAL_LINE;
2000 if ((sym_flags & TRACE_ITER_PRINT_PARENT) &&
2001 field->parent_ip) {
2002 ret = trace_seq_printf(s, " <-");
2003 if (!ret)
2004 return TRACE_TYPE_PARTIAL_LINE;
2005 ret = seq_print_ip_sym(s,
2006 field->parent_ip,
2007 sym_flags);
2008 if (!ret)
2009 return TRACE_TYPE_PARTIAL_LINE;
2010 }
2011 ret = trace_seq_printf(s, "\n");
2012 if (!ret)
2013 return TRACE_TYPE_PARTIAL_LINE;
2014 break;
2015 }
2016 case TRACE_CTX:
2017 case TRACE_WAKE: {
2018 struct ctx_switch_entry *field;
2019
2020 trace_assign_type(field, entry);
2021
2022 T = task_state_char(field->next_state);
2023 S = task_state_char(field->prev_state);
2024 ret = trace_seq_printf(s, " %5d:%3d:%c %s [%03d] %5d:%3d:%c\n",
2025 field->prev_pid,
2026 field->prev_prio,
2027 S,
2028 entry->type == TRACE_CTX ? "==>" : " +",
2029 field->next_cpu,
2030 field->next_pid,
2031 field->next_prio,
2032 T);
2033 if (!ret)
2034 return TRACE_TYPE_PARTIAL_LINE;
2035 break;
2036 }
2037 case TRACE_SPECIAL: {
2038 struct special_entry *field;
2039
2040 trace_assign_type(field, entry);
2041
2042 ret = trace_seq_printf(s, "# %ld %ld %ld\n",
2043 field->arg1,
2044 field->arg2,
2045 field->arg3);
2046 if (!ret)
2047 return TRACE_TYPE_PARTIAL_LINE;
2048 break;
2049 }
2050 case TRACE_STACK: {
2051 struct stack_entry *field;
2052 1544
2053 trace_assign_type(field, entry); 1545 if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
2054 1546 if (iter->iter_flags & TRACE_FILE_LAT_FMT) {
2055 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) { 1547 if (!trace_print_lat_context(iter))
2056 if (i) { 1548 goto partial;
2057 ret = trace_seq_puts(s, " <= "); 1549 } else {
2058 if (!ret) 1550 if (!trace_print_context(iter))
2059 return TRACE_TYPE_PARTIAL_LINE; 1551 goto partial;
2060 }
2061 ret = seq_print_ip_sym(s, field->caller[i],
2062 sym_flags);
2063 if (!ret)
2064 return TRACE_TYPE_PARTIAL_LINE;
2065 } 1552 }
2066 ret = trace_seq_puts(s, "\n");
2067 if (!ret)
2068 return TRACE_TYPE_PARTIAL_LINE;
2069 break;
2070 } 1553 }
2071 case TRACE_PRINT: {
2072 struct print_entry *field;
2073 1554
2074 trace_assign_type(field, entry); 1555 if (event)
1556 return event->trace(iter, sym_flags);
2075 1557
2076 seq_print_ip_sym(s, field->ip, sym_flags); 1558 if (!trace_seq_printf(s, "Unknown type %d\n", entry->type))
2077 trace_seq_printf(s, ": %s", field->buf); 1559 goto partial;
2078 if (entry->flags & TRACE_FLAG_CONT)
2079 trace_seq_print_cont(s, iter);
2080 break;
2081 }
2082 case TRACE_GRAPH_RET: {
2083 return print_graph_function(iter);
2084 }
2085 case TRACE_GRAPH_ENT: {
2086 return print_graph_function(iter);
2087 }
2088 case TRACE_BRANCH: {
2089 struct trace_branch *field;
2090
2091 trace_assign_type(field, entry);
2092 1560
2093 trace_seq_printf(s, "[%s] %s:%s:%d\n",
2094 field->correct ? " ok " : " MISS ",
2095 field->func,
2096 field->file,
2097 field->line);
2098 break;
2099 }
2100 case TRACE_USER_STACK: {
2101 struct userstack_entry *field;
2102
2103 trace_assign_type(field, entry);
2104
2105 ret = seq_print_userip_objs(field, s, sym_flags);
2106 if (!ret)
2107 return TRACE_TYPE_PARTIAL_LINE;
2108 ret = trace_seq_putc(s, '\n');
2109 if (!ret)
2110 return TRACE_TYPE_PARTIAL_LINE;
2111 break;
2112 }
2113 }
2114 return TRACE_TYPE_HANDLED; 1561 return TRACE_TYPE_HANDLED;
1562partial:
1563 return TRACE_TYPE_PARTIAL_LINE;
2115} 1564}
2116 1565
2117static enum print_line_t print_raw_fmt(struct trace_iterator *iter) 1566static enum print_line_t print_raw_fmt(struct trace_iterator *iter)
2118{ 1567{
2119 struct trace_seq *s = &iter->seq; 1568 struct trace_seq *s = &iter->seq;
2120 struct trace_entry *entry; 1569 struct trace_entry *entry;
2121 int ret; 1570 struct trace_event *event;
2122 int S, T;
2123 1571
2124 entry = iter->ent; 1572 entry = iter->ent;
2125 1573
2126 if (entry->type == TRACE_CONT) 1574 if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
2127 return TRACE_TYPE_HANDLED; 1575 if (!trace_seq_printf(s, "%d %d %llu ",
2128 1576 entry->pid, iter->cpu, iter->ts))
2129 ret = trace_seq_printf(s, "%d %d %llu ", 1577 goto partial;
2130 entry->pid, iter->cpu, iter->ts);
2131 if (!ret)
2132 return TRACE_TYPE_PARTIAL_LINE;
2133
2134 switch (entry->type) {
2135 case TRACE_FN: {
2136 struct ftrace_entry *field;
2137
2138 trace_assign_type(field, entry);
2139
2140 ret = trace_seq_printf(s, "%x %x\n",
2141 field->ip,
2142 field->parent_ip);
2143 if (!ret)
2144 return TRACE_TYPE_PARTIAL_LINE;
2145 break;
2146 } 1578 }
2147 case TRACE_CTX:
2148 case TRACE_WAKE: {
2149 struct ctx_switch_entry *field;
2150
2151 trace_assign_type(field, entry);
2152
2153 T = task_state_char(field->next_state);
2154 S = entry->type == TRACE_WAKE ? '+' :
2155 task_state_char(field->prev_state);
2156 ret = trace_seq_printf(s, "%d %d %c %d %d %d %c\n",
2157 field->prev_pid,
2158 field->prev_prio,
2159 S,
2160 field->next_cpu,
2161 field->next_pid,
2162 field->next_prio,
2163 T);
2164 if (!ret)
2165 return TRACE_TYPE_PARTIAL_LINE;
2166 break;
2167 }
2168 case TRACE_SPECIAL:
2169 case TRACE_USER_STACK:
2170 case TRACE_STACK: {
2171 struct special_entry *field;
2172 1579
2173 trace_assign_type(field, entry); 1580 event = ftrace_find_event(entry->type);
1581 if (event)
1582 return event->raw(iter, 0);
2174 1583
2175 ret = trace_seq_printf(s, "# %ld %ld %ld\n", 1584 if (!trace_seq_printf(s, "%d ?\n", entry->type))
2176 field->arg1, 1585 goto partial;
2177 field->arg2,
2178 field->arg3);
2179 if (!ret)
2180 return TRACE_TYPE_PARTIAL_LINE;
2181 break;
2182 }
2183 case TRACE_PRINT: {
2184 struct print_entry *field;
2185 1586
2186 trace_assign_type(field, entry);
2187
2188 trace_seq_printf(s, "# %lx %s", field->ip, field->buf);
2189 if (entry->flags & TRACE_FLAG_CONT)
2190 trace_seq_print_cont(s, iter);
2191 break;
2192 }
2193 }
2194 return TRACE_TYPE_HANDLED; 1587 return TRACE_TYPE_HANDLED;
1588partial:
1589 return TRACE_TYPE_PARTIAL_LINE;
2195} 1590}
2196 1591
2197#define SEQ_PUT_FIELD_RET(s, x) \
2198do { \
2199 if (!trace_seq_putmem(s, &(x), sizeof(x))) \
2200 return 0; \
2201} while (0)
2202
2203#define SEQ_PUT_HEX_FIELD_RET(s, x) \
2204do { \
2205 BUILD_BUG_ON(sizeof(x) > MAX_MEMHEX_BYTES); \
2206 if (!trace_seq_putmem_hex(s, &(x), sizeof(x))) \
2207 return 0; \
2208} while (0)
2209
2210static enum print_line_t print_hex_fmt(struct trace_iterator *iter) 1592static enum print_line_t print_hex_fmt(struct trace_iterator *iter)
2211{ 1593{
2212 struct trace_seq *s = &iter->seq; 1594 struct trace_seq *s = &iter->seq;
2213 unsigned char newline = '\n'; 1595 unsigned char newline = '\n';
2214 struct trace_entry *entry; 1596 struct trace_entry *entry;
2215 int S, T; 1597 struct trace_event *event;
2216 1598
2217 entry = iter->ent; 1599 entry = iter->ent;
2218 1600
2219 if (entry->type == TRACE_CONT) 1601 if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
2220 return TRACE_TYPE_HANDLED; 1602 SEQ_PUT_HEX_FIELD_RET(s, entry->pid);
2221 1603 SEQ_PUT_HEX_FIELD_RET(s, iter->cpu);
2222 SEQ_PUT_HEX_FIELD_RET(s, entry->pid); 1604 SEQ_PUT_HEX_FIELD_RET(s, iter->ts);
2223 SEQ_PUT_HEX_FIELD_RET(s, iter->cpu);
2224 SEQ_PUT_HEX_FIELD_RET(s, iter->ts);
2225
2226 switch (entry->type) {
2227 case TRACE_FN: {
2228 struct ftrace_entry *field;
2229
2230 trace_assign_type(field, entry);
2231
2232 SEQ_PUT_HEX_FIELD_RET(s, field->ip);
2233 SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip);
2234 break;
2235 }
2236 case TRACE_CTX:
2237 case TRACE_WAKE: {
2238 struct ctx_switch_entry *field;
2239
2240 trace_assign_type(field, entry);
2241
2242 T = task_state_char(field->next_state);
2243 S = entry->type == TRACE_WAKE ? '+' :
2244 task_state_char(field->prev_state);
2245 SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid);
2246 SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio);
2247 SEQ_PUT_HEX_FIELD_RET(s, S);
2248 SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu);
2249 SEQ_PUT_HEX_FIELD_RET(s, field->next_pid);
2250 SEQ_PUT_HEX_FIELD_RET(s, field->next_prio);
2251 SEQ_PUT_HEX_FIELD_RET(s, T);
2252 break;
2253 } 1605 }
2254 case TRACE_SPECIAL:
2255 case TRACE_USER_STACK:
2256 case TRACE_STACK: {
2257 struct special_entry *field;
2258 1606
2259 trace_assign_type(field, entry); 1607 event = ftrace_find_event(entry->type);
2260 1608 if (event) {
2261 SEQ_PUT_HEX_FIELD_RET(s, field->arg1); 1609 enum print_line_t ret = event->hex(iter, 0);
2262 SEQ_PUT_HEX_FIELD_RET(s, field->arg2); 1610 if (ret != TRACE_TYPE_HANDLED)
2263 SEQ_PUT_HEX_FIELD_RET(s, field->arg3); 1611 return ret;
2264 break;
2265 }
2266 } 1612 }
1613
2267 SEQ_PUT_FIELD_RET(s, newline); 1614 SEQ_PUT_FIELD_RET(s, newline);
2268 1615
2269 return TRACE_TYPE_HANDLED; 1616 return TRACE_TYPE_HANDLED;
@@ -2278,13 +1625,10 @@ static enum print_line_t print_printk_msg_only(struct trace_iterator *iter)
2278 1625
2279 trace_assign_type(field, entry); 1626 trace_assign_type(field, entry);
2280 1627
2281 ret = trace_seq_printf(s, field->buf); 1628 ret = trace_seq_bprintf(s, field->fmt, field->buf);
2282 if (!ret) 1629 if (!ret)
2283 return TRACE_TYPE_PARTIAL_LINE; 1630 return TRACE_TYPE_PARTIAL_LINE;
2284 1631
2285 if (entry->flags & TRACE_FLAG_CONT)
2286 trace_seq_print_cont(s, iter);
2287
2288 return TRACE_TYPE_HANDLED; 1632 return TRACE_TYPE_HANDLED;
2289} 1633}
2290 1634
@@ -2292,53 +1636,18 @@ static enum print_line_t print_bin_fmt(struct trace_iterator *iter)
2292{ 1636{
2293 struct trace_seq *s = &iter->seq; 1637 struct trace_seq *s = &iter->seq;
2294 struct trace_entry *entry; 1638 struct trace_entry *entry;
1639 struct trace_event *event;
2295 1640
2296 entry = iter->ent; 1641 entry = iter->ent;
2297 1642
2298 if (entry->type == TRACE_CONT) 1643 if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
2299 return TRACE_TYPE_HANDLED; 1644 SEQ_PUT_FIELD_RET(s, entry->pid);
2300 1645 SEQ_PUT_FIELD_RET(s, iter->cpu);
2301 SEQ_PUT_FIELD_RET(s, entry->pid); 1646 SEQ_PUT_FIELD_RET(s, iter->ts);
2302 SEQ_PUT_FIELD_RET(s, entry->cpu);
2303 SEQ_PUT_FIELD_RET(s, iter->ts);
2304
2305 switch (entry->type) {
2306 case TRACE_FN: {
2307 struct ftrace_entry *field;
2308
2309 trace_assign_type(field, entry);
2310
2311 SEQ_PUT_FIELD_RET(s, field->ip);
2312 SEQ_PUT_FIELD_RET(s, field->parent_ip);
2313 break;
2314 } 1647 }
2315 case TRACE_CTX: {
2316 struct ctx_switch_entry *field;
2317
2318 trace_assign_type(field, entry);
2319 1648
2320 SEQ_PUT_FIELD_RET(s, field->prev_pid); 1649 event = ftrace_find_event(entry->type);
2321 SEQ_PUT_FIELD_RET(s, field->prev_prio); 1650 return event ? event->binary(iter, 0) : TRACE_TYPE_HANDLED;
2322 SEQ_PUT_FIELD_RET(s, field->prev_state);
2323 SEQ_PUT_FIELD_RET(s, field->next_pid);
2324 SEQ_PUT_FIELD_RET(s, field->next_prio);
2325 SEQ_PUT_FIELD_RET(s, field->next_state);
2326 break;
2327 }
2328 case TRACE_SPECIAL:
2329 case TRACE_USER_STACK:
2330 case TRACE_STACK: {
2331 struct special_entry *field;
2332
2333 trace_assign_type(field, entry);
2334
2335 SEQ_PUT_FIELD_RET(s, field->arg1);
2336 SEQ_PUT_FIELD_RET(s, field->arg2);
2337 SEQ_PUT_FIELD_RET(s, field->arg3);
2338 break;
2339 }
2340 }
2341 return 1;
2342} 1651}
2343 1652
2344static int trace_empty(struct trace_iterator *iter) 1653static int trace_empty(struct trace_iterator *iter)
@@ -2382,9 +1691,6 @@ static enum print_line_t print_trace_line(struct trace_iterator *iter)
2382 if (trace_flags & TRACE_ITER_RAW) 1691 if (trace_flags & TRACE_ITER_RAW)
2383 return print_raw_fmt(iter); 1692 return print_raw_fmt(iter);
2384 1693
2385 if (iter->iter_flags & TRACE_FILE_LAT_FMT)
2386 return print_lat_fmt(iter, iter->idx, iter->cpu);
2387
2388 return print_trace_fmt(iter); 1694 return print_trace_fmt(iter);
2389} 1695}
2390 1696
@@ -2426,30 +1732,40 @@ static struct seq_operations tracer_seq_ops = {
2426}; 1732};
2427 1733
2428static struct trace_iterator * 1734static struct trace_iterator *
2429__tracing_open(struct inode *inode, struct file *file, int *ret) 1735__tracing_open(struct inode *inode, struct file *file)
2430{ 1736{
1737 long cpu_file = (long) inode->i_private;
1738 void *fail_ret = ERR_PTR(-ENOMEM);
2431 struct trace_iterator *iter; 1739 struct trace_iterator *iter;
2432 struct seq_file *m; 1740 struct seq_file *m;
2433 int cpu; 1741 int cpu, ret;
2434 1742
2435 if (tracing_disabled) { 1743 if (tracing_disabled)
2436 *ret = -ENODEV; 1744 return ERR_PTR(-ENODEV);
2437 return NULL;
2438 }
2439 1745
2440 iter = kzalloc(sizeof(*iter), GFP_KERNEL); 1746 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
2441 if (!iter) { 1747 if (!iter)
2442 *ret = -ENOMEM; 1748 return ERR_PTR(-ENOMEM);
2443 goto out;
2444 }
2445 1749
1750 /*
1751 * We make a copy of the current tracer to avoid concurrent
1752 * changes on it while we are reading.
1753 */
2446 mutex_lock(&trace_types_lock); 1754 mutex_lock(&trace_types_lock);
1755 iter->trace = kzalloc(sizeof(*iter->trace), GFP_KERNEL);
1756 if (!iter->trace)
1757 goto fail;
1758
1759 if (current_trace)
1760 *iter->trace = *current_trace;
1761
2447 if (current_trace && current_trace->print_max) 1762 if (current_trace && current_trace->print_max)
2448 iter->tr = &max_tr; 1763 iter->tr = &max_tr;
2449 else 1764 else
2450 iter->tr = inode->i_private; 1765 iter->tr = &global_trace;
2451 iter->trace = current_trace;
2452 iter->pos = -1; 1766 iter->pos = -1;
1767 mutex_init(&iter->mutex);
1768 iter->cpu_file = cpu_file;
2453 1769
2454 /* Notify the tracer early; before we stop tracing. */ 1770 /* Notify the tracer early; before we stop tracing. */
2455 if (iter->trace && iter->trace->open) 1771 if (iter->trace && iter->trace->open)
@@ -2459,20 +1775,30 @@ __tracing_open(struct inode *inode, struct file *file, int *ret)
2459 if (ring_buffer_overruns(iter->tr->buffer)) 1775 if (ring_buffer_overruns(iter->tr->buffer))
2460 iter->iter_flags |= TRACE_FILE_ANNOTATE; 1776 iter->iter_flags |= TRACE_FILE_ANNOTATE;
2461 1777
1778 if (iter->cpu_file == TRACE_PIPE_ALL_CPU) {
1779 for_each_tracing_cpu(cpu) {
2462 1780
2463 for_each_tracing_cpu(cpu) { 1781 iter->buffer_iter[cpu] =
1782 ring_buffer_read_start(iter->tr->buffer, cpu);
2464 1783
1784 if (!iter->buffer_iter[cpu])
1785 goto fail_buffer;
1786 }
1787 } else {
1788 cpu = iter->cpu_file;
2465 iter->buffer_iter[cpu] = 1789 iter->buffer_iter[cpu] =
2466 ring_buffer_read_start(iter->tr->buffer, cpu); 1790 ring_buffer_read_start(iter->tr->buffer, cpu);
2467 1791
2468 if (!iter->buffer_iter[cpu]) 1792 if (!iter->buffer_iter[cpu])
2469 goto fail_buffer; 1793 goto fail;
2470 } 1794 }
2471 1795
2472 /* TODO stop tracer */ 1796 /* TODO stop tracer */
2473 *ret = seq_open(file, &tracer_seq_ops); 1797 ret = seq_open(file, &tracer_seq_ops);
2474 if (*ret) 1798 if (ret < 0) {
1799 fail_ret = ERR_PTR(ret);
2475 goto fail_buffer; 1800 goto fail_buffer;
1801 }
2476 1802
2477 m = file->private_data; 1803 m = file->private_data;
2478 m->private = iter; 1804 m->private = iter;
@@ -2482,7 +1808,6 @@ __tracing_open(struct inode *inode, struct file *file, int *ret)
2482 1808
2483 mutex_unlock(&trace_types_lock); 1809 mutex_unlock(&trace_types_lock);
2484 1810
2485 out:
2486 return iter; 1811 return iter;
2487 1812
2488 fail_buffer: 1813 fail_buffer:
@@ -2490,10 +1815,12 @@ __tracing_open(struct inode *inode, struct file *file, int *ret)
2490 if (iter->buffer_iter[cpu]) 1815 if (iter->buffer_iter[cpu])
2491 ring_buffer_read_finish(iter->buffer_iter[cpu]); 1816 ring_buffer_read_finish(iter->buffer_iter[cpu]);
2492 } 1817 }
1818 fail:
2493 mutex_unlock(&trace_types_lock); 1819 mutex_unlock(&trace_types_lock);
1820 kfree(iter->trace);
2494 kfree(iter); 1821 kfree(iter);
2495 1822
2496 return ERR_PTR(-ENOMEM); 1823 return fail_ret;
2497} 1824}
2498 1825
2499int tracing_open_generic(struct inode *inode, struct file *filp) 1826int tracing_open_generic(struct inode *inode, struct file *filp)
@@ -2505,7 +1832,7 @@ int tracing_open_generic(struct inode *inode, struct file *filp)
2505 return 0; 1832 return 0;
2506} 1833}
2507 1834
2508int tracing_release(struct inode *inode, struct file *file) 1835static int tracing_release(struct inode *inode, struct file *file)
2509{ 1836{
2510 struct seq_file *m = (struct seq_file *)file->private_data; 1837 struct seq_file *m = (struct seq_file *)file->private_data;
2511 struct trace_iterator *iter = m->private; 1838 struct trace_iterator *iter = m->private;
@@ -2525,33 +1852,26 @@ int tracing_release(struct inode *inode, struct file *file)
2525 mutex_unlock(&trace_types_lock); 1852 mutex_unlock(&trace_types_lock);
2526 1853
2527 seq_release(inode, file); 1854 seq_release(inode, file);
1855 mutex_destroy(&iter->mutex);
1856 kfree(iter->trace);
2528 kfree(iter); 1857 kfree(iter);
2529 return 0; 1858 return 0;
2530} 1859}
2531 1860
2532static int tracing_open(struct inode *inode, struct file *file) 1861static int tracing_open(struct inode *inode, struct file *file)
2533{ 1862{
2534 int ret;
2535
2536 __tracing_open(inode, file, &ret);
2537
2538 return ret;
2539}
2540
2541static int tracing_lt_open(struct inode *inode, struct file *file)
2542{
2543 struct trace_iterator *iter; 1863 struct trace_iterator *iter;
2544 int ret; 1864 int ret = 0;
2545
2546 iter = __tracing_open(inode, file, &ret);
2547 1865
2548 if (!ret) 1866 iter = __tracing_open(inode, file);
1867 if (IS_ERR(iter))
1868 ret = PTR_ERR(iter);
1869 else if (trace_flags & TRACE_ITER_LATENCY_FMT)
2549 iter->iter_flags |= TRACE_FILE_LAT_FMT; 1870 iter->iter_flags |= TRACE_FILE_LAT_FMT;
2550 1871
2551 return ret; 1872 return ret;
2552} 1873}
2553 1874
2554
2555static void * 1875static void *
2556t_next(struct seq_file *m, void *v, loff_t *pos) 1876t_next(struct seq_file *m, void *v, loff_t *pos)
2557{ 1877{
@@ -2623,21 +1943,14 @@ static int show_traces_open(struct inode *inode, struct file *file)
2623 return ret; 1943 return ret;
2624} 1944}
2625 1945
2626static struct file_operations tracing_fops = { 1946static const struct file_operations tracing_fops = {
2627 .open = tracing_open, 1947 .open = tracing_open,
2628 .read = seq_read, 1948 .read = seq_read,
2629 .llseek = seq_lseek, 1949 .llseek = seq_lseek,
2630 .release = tracing_release, 1950 .release = tracing_release,
2631}; 1951};
2632 1952
2633static struct file_operations tracing_lt_fops = { 1953static const struct file_operations show_traces_fops = {
2634 .open = tracing_lt_open,
2635 .read = seq_read,
2636 .llseek = seq_lseek,
2637 .release = tracing_release,
2638};
2639
2640static struct file_operations show_traces_fops = {
2641 .open = show_traces_open, 1954 .open = show_traces_open,
2642 .read = seq_read, 1955 .read = seq_read,
2643 .release = seq_release, 1956 .release = seq_release,
@@ -2730,7 +2043,7 @@ err_unlock:
2730 return err; 2043 return err;
2731} 2044}
2732 2045
2733static struct file_operations tracing_cpumask_fops = { 2046static const struct file_operations tracing_cpumask_fops = {
2734 .open = tracing_open_generic, 2047 .open = tracing_open_generic,
2735 .read = tracing_cpumask_read, 2048 .read = tracing_cpumask_read,
2736 .write = tracing_cpumask_write, 2049 .write = tracing_cpumask_write,
@@ -2740,57 +2053,62 @@ static ssize_t
2740tracing_trace_options_read(struct file *filp, char __user *ubuf, 2053tracing_trace_options_read(struct file *filp, char __user *ubuf,
2741 size_t cnt, loff_t *ppos) 2054 size_t cnt, loff_t *ppos)
2742{ 2055{
2743 int i; 2056 struct tracer_opt *trace_opts;
2057 u32 tracer_flags;
2058 int len = 0;
2744 char *buf; 2059 char *buf;
2745 int r = 0; 2060 int r = 0;
2746 int len = 0; 2061 int i;
2747 u32 tracer_flags = current_trace->flags->val;
2748 struct tracer_opt *trace_opts = current_trace->flags->opts;
2749 2062
2750 2063
2751 /* calulate max size */ 2064 /* calculate max size */
2752 for (i = 0; trace_options[i]; i++) { 2065 for (i = 0; trace_options[i]; i++) {
2753 len += strlen(trace_options[i]); 2066 len += strlen(trace_options[i]);
2754 len += 3; /* "no" and space */ 2067 len += 3; /* "no" and newline */
2755 } 2068 }
2756 2069
2070 mutex_lock(&trace_types_lock);
2071 tracer_flags = current_trace->flags->val;
2072 trace_opts = current_trace->flags->opts;
2073
2757 /* 2074 /*
2758 * Increase the size with names of options specific 2075 * Increase the size with names of options specific
2759 * of the current tracer. 2076 * of the current tracer.
2760 */ 2077 */
2761 for (i = 0; trace_opts[i].name; i++) { 2078 for (i = 0; trace_opts[i].name; i++) {
2762 len += strlen(trace_opts[i].name); 2079 len += strlen(trace_opts[i].name);
2763 len += 3; /* "no" and space */ 2080 len += 3; /* "no" and newline */
2764 } 2081 }
2765 2082
2766 /* +2 for \n and \0 */ 2083 /* +2 for \n and \0 */
2767 buf = kmalloc(len + 2, GFP_KERNEL); 2084 buf = kmalloc(len + 2, GFP_KERNEL);
2768 if (!buf) 2085 if (!buf) {
2086 mutex_unlock(&trace_types_lock);
2769 return -ENOMEM; 2087 return -ENOMEM;
2088 }
2770 2089
2771 for (i = 0; trace_options[i]; i++) { 2090 for (i = 0; trace_options[i]; i++) {
2772 if (trace_flags & (1 << i)) 2091 if (trace_flags & (1 << i))
2773 r += sprintf(buf + r, "%s ", trace_options[i]); 2092 r += sprintf(buf + r, "%s\n", trace_options[i]);
2774 else 2093 else
2775 r += sprintf(buf + r, "no%s ", trace_options[i]); 2094 r += sprintf(buf + r, "no%s\n", trace_options[i]);
2776 } 2095 }
2777 2096
2778 for (i = 0; trace_opts[i].name; i++) { 2097 for (i = 0; trace_opts[i].name; i++) {
2779 if (tracer_flags & trace_opts[i].bit) 2098 if (tracer_flags & trace_opts[i].bit)
2780 r += sprintf(buf + r, "%s ", 2099 r += sprintf(buf + r, "%s\n",
2781 trace_opts[i].name); 2100 trace_opts[i].name);
2782 else 2101 else
2783 r += sprintf(buf + r, "no%s ", 2102 r += sprintf(buf + r, "no%s\n",
2784 trace_opts[i].name); 2103 trace_opts[i].name);
2785 } 2104 }
2105 mutex_unlock(&trace_types_lock);
2786 2106
2787 r += sprintf(buf + r, "\n");
2788 WARN_ON(r >= len + 2); 2107 WARN_ON(r >= len + 2);
2789 2108
2790 r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); 2109 r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
2791 2110
2792 kfree(buf); 2111 kfree(buf);
2793
2794 return r; 2112 return r;
2795} 2113}
2796 2114
@@ -2865,7 +2183,9 @@ tracing_trace_options_write(struct file *filp, const char __user *ubuf,
2865 2183
2866 /* If no option could be set, test the specific tracer options */ 2184 /* If no option could be set, test the specific tracer options */
2867 if (!trace_options[i]) { 2185 if (!trace_options[i]) {
2186 mutex_lock(&trace_types_lock);
2868 ret = set_tracer_option(current_trace, cmp, neg); 2187 ret = set_tracer_option(current_trace, cmp, neg);
2188 mutex_unlock(&trace_types_lock);
2869 if (ret) 2189 if (ret)
2870 return ret; 2190 return ret;
2871 } 2191 }
@@ -2875,7 +2195,7 @@ tracing_trace_options_write(struct file *filp, const char __user *ubuf,
2875 return cnt; 2195 return cnt;
2876} 2196}
2877 2197
2878static struct file_operations tracing_iter_fops = { 2198static const struct file_operations tracing_iter_fops = {
2879 .open = tracing_open_generic, 2199 .open = tracing_open_generic,
2880 .read = tracing_trace_options_read, 2200 .read = tracing_trace_options_read,
2881 .write = tracing_trace_options_write, 2201 .write = tracing_trace_options_write,
@@ -2908,7 +2228,7 @@ tracing_readme_read(struct file *filp, char __user *ubuf,
2908 readme_msg, strlen(readme_msg)); 2228 readme_msg, strlen(readme_msg));
2909} 2229}
2910 2230
2911static struct file_operations tracing_readme_fops = { 2231static const struct file_operations tracing_readme_fops = {
2912 .open = tracing_open_generic, 2232 .open = tracing_open_generic,
2913 .read = tracing_readme_read, 2233 .read = tracing_readme_read,
2914}; 2234};
@@ -2930,7 +2250,7 @@ tracing_ctrl_write(struct file *filp, const char __user *ubuf,
2930{ 2250{
2931 struct trace_array *tr = filp->private_data; 2251 struct trace_array *tr = filp->private_data;
2932 char buf[64]; 2252 char buf[64];
2933 long val; 2253 unsigned long val;
2934 int ret; 2254 int ret;
2935 2255
2936 if (cnt >= sizeof(buf)) 2256 if (cnt >= sizeof(buf))
@@ -2985,8 +2305,23 @@ tracing_set_trace_read(struct file *filp, char __user *ubuf,
2985 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); 2305 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
2986} 2306}
2987 2307
2988static int tracing_set_tracer(char *buf) 2308int tracer_init(struct tracer *t, struct trace_array *tr)
2309{
2310 tracing_reset_online_cpus(tr);
2311 return t->init(tr);
2312}
2313
2314struct trace_option_dentry;
2315
2316static struct trace_option_dentry *
2317create_trace_option_files(struct tracer *tracer);
2318
2319static void
2320destroy_trace_option_files(struct trace_option_dentry *topts);
2321
2322static int tracing_set_tracer(const char *buf)
2989{ 2323{
2324 static struct trace_option_dentry *topts;
2990 struct trace_array *tr = &global_trace; 2325 struct trace_array *tr = &global_trace;
2991 struct tracer *t; 2326 struct tracer *t;
2992 int ret = 0; 2327 int ret = 0;
@@ -3007,9 +2342,14 @@ static int tracing_set_tracer(char *buf)
3007 if (current_trace && current_trace->reset) 2342 if (current_trace && current_trace->reset)
3008 current_trace->reset(tr); 2343 current_trace->reset(tr);
3009 2344
2345 destroy_trace_option_files(topts);
2346
3010 current_trace = t; 2347 current_trace = t;
2348
2349 topts = create_trace_option_files(current_trace);
2350
3011 if (t->init) { 2351 if (t->init) {
3012 ret = t->init(tr); 2352 ret = tracer_init(t, tr);
3013 if (ret) 2353 if (ret)
3014 goto out; 2354 goto out;
3015 } 2355 }
@@ -3072,9 +2412,9 @@ static ssize_t
3072tracing_max_lat_write(struct file *filp, const char __user *ubuf, 2412tracing_max_lat_write(struct file *filp, const char __user *ubuf,
3073 size_t cnt, loff_t *ppos) 2413 size_t cnt, loff_t *ppos)
3074{ 2414{
3075 long *ptr = filp->private_data; 2415 unsigned long *ptr = filp->private_data;
3076 char buf[64]; 2416 char buf[64];
3077 long val; 2417 unsigned long val;
3078 int ret; 2418 int ret;
3079 2419
3080 if (cnt >= sizeof(buf)) 2420 if (cnt >= sizeof(buf))
@@ -3094,54 +2434,96 @@ tracing_max_lat_write(struct file *filp, const char __user *ubuf,
3094 return cnt; 2434 return cnt;
3095} 2435}
3096 2436
3097static atomic_t tracing_reader;
3098
3099static int tracing_open_pipe(struct inode *inode, struct file *filp) 2437static int tracing_open_pipe(struct inode *inode, struct file *filp)
3100{ 2438{
2439 long cpu_file = (long) inode->i_private;
3101 struct trace_iterator *iter; 2440 struct trace_iterator *iter;
2441 int ret = 0;
3102 2442
3103 if (tracing_disabled) 2443 if (tracing_disabled)
3104 return -ENODEV; 2444 return -ENODEV;
3105 2445
3106 /* We only allow for reader of the pipe */ 2446 mutex_lock(&trace_types_lock);
3107 if (atomic_inc_return(&tracing_reader) != 1) { 2447
3108 atomic_dec(&tracing_reader); 2448 /* We only allow one reader per cpu */
3109 return -EBUSY; 2449 if (cpu_file == TRACE_PIPE_ALL_CPU) {
2450 if (!cpumask_empty(tracing_reader_cpumask)) {
2451 ret = -EBUSY;
2452 goto out;
2453 }
2454 cpumask_setall(tracing_reader_cpumask);
2455 } else {
2456 if (!cpumask_test_cpu(cpu_file, tracing_reader_cpumask))
2457 cpumask_set_cpu(cpu_file, tracing_reader_cpumask);
2458 else {
2459 ret = -EBUSY;
2460 goto out;
2461 }
3110 } 2462 }
3111 2463
3112 /* create a buffer to store the information to pass to userspace */ 2464 /* create a buffer to store the information to pass to userspace */
3113 iter = kzalloc(sizeof(*iter), GFP_KERNEL); 2465 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
3114 if (!iter) 2466 if (!iter) {
3115 return -ENOMEM; 2467 ret = -ENOMEM;
2468 goto out;
2469 }
3116 2470
3117 if (!alloc_cpumask_var(&iter->started, GFP_KERNEL)) { 2471 /*
3118 kfree(iter); 2472 * We make a copy of the current tracer to avoid concurrent
3119 return -ENOMEM; 2473 * changes on it while we are reading.
2474 */
2475 iter->trace = kmalloc(sizeof(*iter->trace), GFP_KERNEL);
2476 if (!iter->trace) {
2477 ret = -ENOMEM;
2478 goto fail;
3120 } 2479 }
2480 if (current_trace)
2481 *iter->trace = *current_trace;
3121 2482
3122 mutex_lock(&trace_types_lock); 2483 if (!alloc_cpumask_var(&iter->started, GFP_KERNEL)) {
2484 ret = -ENOMEM;
2485 goto fail;
2486 }
3123 2487
3124 /* trace pipe does not show start of buffer */ 2488 /* trace pipe does not show start of buffer */
3125 cpumask_setall(iter->started); 2489 cpumask_setall(iter->started);
3126 2490
2491 iter->cpu_file = cpu_file;
3127 iter->tr = &global_trace; 2492 iter->tr = &global_trace;
3128 iter->trace = current_trace; 2493 mutex_init(&iter->mutex);
3129 filp->private_data = iter; 2494 filp->private_data = iter;
3130 2495
3131 if (iter->trace->pipe_open) 2496 if (iter->trace->pipe_open)
3132 iter->trace->pipe_open(iter); 2497 iter->trace->pipe_open(iter);
2498
2499out:
3133 mutex_unlock(&trace_types_lock); 2500 mutex_unlock(&trace_types_lock);
2501 return ret;
3134 2502
3135 return 0; 2503fail:
2504 kfree(iter->trace);
2505 kfree(iter);
2506 mutex_unlock(&trace_types_lock);
2507 return ret;
3136} 2508}
3137 2509
3138static int tracing_release_pipe(struct inode *inode, struct file *file) 2510static int tracing_release_pipe(struct inode *inode, struct file *file)
3139{ 2511{
3140 struct trace_iterator *iter = file->private_data; 2512 struct trace_iterator *iter = file->private_data;
3141 2513
2514 mutex_lock(&trace_types_lock);
2515
2516 if (iter->cpu_file == TRACE_PIPE_ALL_CPU)
2517 cpumask_clear(tracing_reader_cpumask);
2518 else
2519 cpumask_clear_cpu(iter->cpu_file, tracing_reader_cpumask);
2520
2521 mutex_unlock(&trace_types_lock);
2522
3142 free_cpumask_var(iter->started); 2523 free_cpumask_var(iter->started);
2524 mutex_destroy(&iter->mutex);
2525 kfree(iter->trace);
3143 kfree(iter); 2526 kfree(iter);
3144 atomic_dec(&tracing_reader);
3145 2527
3146 return 0; 2528 return 0;
3147} 2529}
@@ -3167,67 +2549,57 @@ tracing_poll_pipe(struct file *filp, poll_table *poll_table)
3167 } 2549 }
3168} 2550}
3169 2551
3170/* 2552
3171 * Consumer reader. 2553void default_wait_pipe(struct trace_iterator *iter)
3172 */
3173static ssize_t
3174tracing_read_pipe(struct file *filp, char __user *ubuf,
3175 size_t cnt, loff_t *ppos)
3176{ 2554{
3177 struct trace_iterator *iter = filp->private_data; 2555 DEFINE_WAIT(wait);
3178 ssize_t sret;
3179 2556
3180 /* return any leftover data */ 2557 prepare_to_wait(&trace_wait, &wait, TASK_INTERRUPTIBLE);
3181 sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
3182 if (sret != -EBUSY)
3183 return sret;
3184 2558
3185 trace_seq_reset(&iter->seq); 2559 if (trace_empty(iter))
2560 schedule();
3186 2561
3187 mutex_lock(&trace_types_lock); 2562 finish_wait(&trace_wait, &wait);
3188 if (iter->trace->read) { 2563}
3189 sret = iter->trace->read(iter, filp, ubuf, cnt, ppos); 2564
3190 if (sret) 2565/*
3191 goto out; 2566 * This is a make-shift waitqueue.
3192 } 2567 * A tracer might use this callback on some rare cases:
2568 *
2569 * 1) the current tracer might hold the runqueue lock when it wakes up
2570 * a reader, hence a deadlock (sched, function, and function graph tracers)
2571 * 2) the function tracers, trace all functions, we don't want
2572 * the overhead of calling wake_up and friends
2573 * (and tracing them too)
2574 *
2575 * Anyway, this is really very primitive wakeup.
2576 */
2577void poll_wait_pipe(struct trace_iterator *iter)
2578{
2579 set_current_state(TASK_INTERRUPTIBLE);
2580 /* sleep for 100 msecs, and try again. */
2581 schedule_timeout(HZ / 10);
2582}
2583
2584/* Must be called with trace_types_lock mutex held. */
2585static int tracing_wait_pipe(struct file *filp)
2586{
2587 struct trace_iterator *iter = filp->private_data;
3193 2588
3194waitagain:
3195 sret = 0;
3196 while (trace_empty(iter)) { 2589 while (trace_empty(iter)) {
3197 2590
3198 if ((filp->f_flags & O_NONBLOCK)) { 2591 if ((filp->f_flags & O_NONBLOCK)) {
3199 sret = -EAGAIN; 2592 return -EAGAIN;
3200 goto out;
3201 } 2593 }
3202 2594
3203 /* 2595 mutex_unlock(&iter->mutex);
3204 * This is a make-shift waitqueue. The reason we don't use
3205 * an actual wait queue is because:
3206 * 1) we only ever have one waiter
3207 * 2) the tracing, traces all functions, we don't want
3208 * the overhead of calling wake_up and friends
3209 * (and tracing them too)
3210 * Anyway, this is really very primitive wakeup.
3211 */
3212 set_current_state(TASK_INTERRUPTIBLE);
3213 iter->tr->waiter = current;
3214
3215 mutex_unlock(&trace_types_lock);
3216 2596
3217 /* sleep for 100 msecs, and try again. */ 2597 iter->trace->wait_pipe(iter);
3218 schedule_timeout(HZ/10);
3219 2598
3220 mutex_lock(&trace_types_lock); 2599 mutex_lock(&iter->mutex);
3221 2600
3222 iter->tr->waiter = NULL; 2601 if (signal_pending(current))
3223 2602 return -EINTR;
3224 if (signal_pending(current)) {
3225 sret = -EINTR;
3226 goto out;
3227 }
3228
3229 if (iter->trace != current_trace)
3230 goto out;
3231 2603
3232 /* 2604 /*
3233 * We block until we read something and tracing is disabled. 2605 * We block until we read something and tracing is disabled.
@@ -3240,13 +2612,59 @@ waitagain:
3240 */ 2612 */
3241 if (!tracer_enabled && iter->pos) 2613 if (!tracer_enabled && iter->pos)
3242 break; 2614 break;
2615 }
2616
2617 return 1;
2618}
2619
2620/*
2621 * Consumer reader.
2622 */
2623static ssize_t
2624tracing_read_pipe(struct file *filp, char __user *ubuf,
2625 size_t cnt, loff_t *ppos)
2626{
2627 struct trace_iterator *iter = filp->private_data;
2628 static struct tracer *old_tracer;
2629 ssize_t sret;
2630
2631 /* return any leftover data */
2632 sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
2633 if (sret != -EBUSY)
2634 return sret;
2635
2636 trace_seq_init(&iter->seq);
3243 2637
3244 continue; 2638 /* copy the tracer to avoid using a global lock all around */
2639 mutex_lock(&trace_types_lock);
2640 if (unlikely(old_tracer != current_trace && current_trace)) {
2641 old_tracer = current_trace;
2642 *iter->trace = *current_trace;
3245 } 2643 }
2644 mutex_unlock(&trace_types_lock);
2645
2646 /*
2647 * Avoid more than one consumer on a single file descriptor
2648 * This is just a matter of traces coherency, the ring buffer itself
2649 * is protected.
2650 */
2651 mutex_lock(&iter->mutex);
2652 if (iter->trace->read) {
2653 sret = iter->trace->read(iter, filp, ubuf, cnt, ppos);
2654 if (sret)
2655 goto out;
2656 }
2657
2658waitagain:
2659 sret = tracing_wait_pipe(filp);
2660 if (sret <= 0)
2661 goto out;
3246 2662
3247 /* stop when tracing is finished */ 2663 /* stop when tracing is finished */
3248 if (trace_empty(iter)) 2664 if (trace_empty(iter)) {
2665 sret = 0;
3249 goto out; 2666 goto out;
2667 }
3250 2668
3251 if (cnt >= PAGE_SIZE) 2669 if (cnt >= PAGE_SIZE)
3252 cnt = PAGE_SIZE - 1; 2670 cnt = PAGE_SIZE - 1;
@@ -3267,8 +2685,8 @@ waitagain:
3267 iter->seq.len = len; 2685 iter->seq.len = len;
3268 break; 2686 break;
3269 } 2687 }
3270 2688 if (ret != TRACE_TYPE_NO_CONSUME)
3271 trace_consume(iter); 2689 trace_consume(iter);
3272 2690
3273 if (iter->seq.len >= cnt) 2691 if (iter->seq.len >= cnt)
3274 break; 2692 break;
@@ -3277,7 +2695,7 @@ waitagain:
3277 /* Now copy what we have to the user */ 2695 /* Now copy what we have to the user */
3278 sret = trace_seq_to_user(&iter->seq, ubuf, cnt); 2696 sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
3279 if (iter->seq.readpos >= iter->seq.len) 2697 if (iter->seq.readpos >= iter->seq.len)
3280 trace_seq_reset(&iter->seq); 2698 trace_seq_init(&iter->seq);
3281 2699
3282 /* 2700 /*
3283 * If there was nothing to send to user, inspite of consuming trace 2701 * If there was nothing to send to user, inspite of consuming trace
@@ -3287,11 +2705,148 @@ waitagain:
3287 goto waitagain; 2705 goto waitagain;
3288 2706
3289out: 2707out:
3290 mutex_unlock(&trace_types_lock); 2708 mutex_unlock(&iter->mutex);
3291 2709
3292 return sret; 2710 return sret;
3293} 2711}
3294 2712
2713static void tracing_pipe_buf_release(struct pipe_inode_info *pipe,
2714 struct pipe_buffer *buf)
2715{
2716 __free_page(buf->page);
2717}
2718
2719static void tracing_spd_release_pipe(struct splice_pipe_desc *spd,
2720 unsigned int idx)
2721{
2722 __free_page(spd->pages[idx]);
2723}
2724
2725static struct pipe_buf_operations tracing_pipe_buf_ops = {
2726 .can_merge = 0,
2727 .map = generic_pipe_buf_map,
2728 .unmap = generic_pipe_buf_unmap,
2729 .confirm = generic_pipe_buf_confirm,
2730 .release = tracing_pipe_buf_release,
2731 .steal = generic_pipe_buf_steal,
2732 .get = generic_pipe_buf_get,
2733};
2734
2735static size_t
2736tracing_fill_pipe_page(size_t rem, struct trace_iterator *iter)
2737{
2738 size_t count;
2739 int ret;
2740
2741 /* Seq buffer is page-sized, exactly what we need. */
2742 for (;;) {
2743 count = iter->seq.len;
2744 ret = print_trace_line(iter);
2745 count = iter->seq.len - count;
2746 if (rem < count) {
2747 rem = 0;
2748 iter->seq.len -= count;
2749 break;
2750 }
2751 if (ret == TRACE_TYPE_PARTIAL_LINE) {
2752 iter->seq.len -= count;
2753 break;
2754 }
2755
2756 trace_consume(iter);
2757 rem -= count;
2758 if (!find_next_entry_inc(iter)) {
2759 rem = 0;
2760 iter->ent = NULL;
2761 break;
2762 }
2763 }
2764
2765 return rem;
2766}
2767
2768static ssize_t tracing_splice_read_pipe(struct file *filp,
2769 loff_t *ppos,
2770 struct pipe_inode_info *pipe,
2771 size_t len,
2772 unsigned int flags)
2773{
2774 struct page *pages[PIPE_BUFFERS];
2775 struct partial_page partial[PIPE_BUFFERS];
2776 struct trace_iterator *iter = filp->private_data;
2777 struct splice_pipe_desc spd = {
2778 .pages = pages,
2779 .partial = partial,
2780 .nr_pages = 0, /* This gets updated below. */
2781 .flags = flags,
2782 .ops = &tracing_pipe_buf_ops,
2783 .spd_release = tracing_spd_release_pipe,
2784 };
2785 static struct tracer *old_tracer;
2786 ssize_t ret;
2787 size_t rem;
2788 unsigned int i;
2789
2790 /* copy the tracer to avoid using a global lock all around */
2791 mutex_lock(&trace_types_lock);
2792 if (unlikely(old_tracer != current_trace && current_trace)) {
2793 old_tracer = current_trace;
2794 *iter->trace = *current_trace;
2795 }
2796 mutex_unlock(&trace_types_lock);
2797
2798 mutex_lock(&iter->mutex);
2799
2800 if (iter->trace->splice_read) {
2801 ret = iter->trace->splice_read(iter, filp,
2802 ppos, pipe, len, flags);
2803 if (ret)
2804 goto out_err;
2805 }
2806
2807 ret = tracing_wait_pipe(filp);
2808 if (ret <= 0)
2809 goto out_err;
2810
2811 if (!iter->ent && !find_next_entry_inc(iter)) {
2812 ret = -EFAULT;
2813 goto out_err;
2814 }
2815
2816 /* Fill as many pages as possible. */
2817 for (i = 0, rem = len; i < PIPE_BUFFERS && rem; i++) {
2818 pages[i] = alloc_page(GFP_KERNEL);
2819 if (!pages[i])
2820 break;
2821
2822 rem = tracing_fill_pipe_page(rem, iter);
2823
2824 /* Copy the data into the page, so we can start over. */
2825 ret = trace_seq_to_buffer(&iter->seq,
2826 page_address(pages[i]),
2827 iter->seq.len);
2828 if (ret < 0) {
2829 __free_page(pages[i]);
2830 break;
2831 }
2832 partial[i].offset = 0;
2833 partial[i].len = iter->seq.len;
2834
2835 trace_seq_init(&iter->seq);
2836 }
2837
2838 mutex_unlock(&iter->mutex);
2839
2840 spd.nr_pages = i;
2841
2842 return splice_to_pipe(pipe, &spd);
2843
2844out_err:
2845 mutex_unlock(&iter->mutex);
2846
2847 return ret;
2848}
2849
3295static ssize_t 2850static ssize_t
3296tracing_entries_read(struct file *filp, char __user *ubuf, 2851tracing_entries_read(struct file *filp, char __user *ubuf,
3297 size_t cnt, loff_t *ppos) 2852 size_t cnt, loff_t *ppos)
@@ -3433,42 +2988,288 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,
3433 return cnt; 2988 return cnt;
3434} 2989}
3435 2990
3436static struct file_operations tracing_max_lat_fops = { 2991static const struct file_operations tracing_max_lat_fops = {
3437 .open = tracing_open_generic, 2992 .open = tracing_open_generic,
3438 .read = tracing_max_lat_read, 2993 .read = tracing_max_lat_read,
3439 .write = tracing_max_lat_write, 2994 .write = tracing_max_lat_write,
3440}; 2995};
3441 2996
3442static struct file_operations tracing_ctrl_fops = { 2997static const struct file_operations tracing_ctrl_fops = {
3443 .open = tracing_open_generic, 2998 .open = tracing_open_generic,
3444 .read = tracing_ctrl_read, 2999 .read = tracing_ctrl_read,
3445 .write = tracing_ctrl_write, 3000 .write = tracing_ctrl_write,
3446}; 3001};
3447 3002
3448static struct file_operations set_tracer_fops = { 3003static const struct file_operations set_tracer_fops = {
3449 .open = tracing_open_generic, 3004 .open = tracing_open_generic,
3450 .read = tracing_set_trace_read, 3005 .read = tracing_set_trace_read,
3451 .write = tracing_set_trace_write, 3006 .write = tracing_set_trace_write,
3452}; 3007};
3453 3008
3454static struct file_operations tracing_pipe_fops = { 3009static const struct file_operations tracing_pipe_fops = {
3455 .open = tracing_open_pipe, 3010 .open = tracing_open_pipe,
3456 .poll = tracing_poll_pipe, 3011 .poll = tracing_poll_pipe,
3457 .read = tracing_read_pipe, 3012 .read = tracing_read_pipe,
3013 .splice_read = tracing_splice_read_pipe,
3458 .release = tracing_release_pipe, 3014 .release = tracing_release_pipe,
3459}; 3015};
3460 3016
3461static struct file_operations tracing_entries_fops = { 3017static const struct file_operations tracing_entries_fops = {
3462 .open = tracing_open_generic, 3018 .open = tracing_open_generic,
3463 .read = tracing_entries_read, 3019 .read = tracing_entries_read,
3464 .write = tracing_entries_write, 3020 .write = tracing_entries_write,
3465}; 3021};
3466 3022
3467static struct file_operations tracing_mark_fops = { 3023static const struct file_operations tracing_mark_fops = {
3468 .open = tracing_open_generic, 3024 .open = tracing_open_generic,
3469 .write = tracing_mark_write, 3025 .write = tracing_mark_write,
3470}; 3026};
3471 3027
3028struct ftrace_buffer_info {
3029 struct trace_array *tr;
3030 void *spare;
3031 int cpu;
3032 unsigned int read;
3033};
3034
3035static int tracing_buffers_open(struct inode *inode, struct file *filp)
3036{
3037 int cpu = (int)(long)inode->i_private;
3038 struct ftrace_buffer_info *info;
3039
3040 if (tracing_disabled)
3041 return -ENODEV;
3042
3043 info = kzalloc(sizeof(*info), GFP_KERNEL);
3044 if (!info)
3045 return -ENOMEM;
3046
3047 info->tr = &global_trace;
3048 info->cpu = cpu;
3049 info->spare = ring_buffer_alloc_read_page(info->tr->buffer);
3050 /* Force reading ring buffer for first read */
3051 info->read = (unsigned int)-1;
3052 if (!info->spare)
3053 goto out;
3054
3055 filp->private_data = info;
3056
3057 return 0;
3058
3059 out:
3060 kfree(info);
3061 return -ENOMEM;
3062}
3063
3064static ssize_t
3065tracing_buffers_read(struct file *filp, char __user *ubuf,
3066 size_t count, loff_t *ppos)
3067{
3068 struct ftrace_buffer_info *info = filp->private_data;
3069 unsigned int pos;
3070 ssize_t ret;
3071 size_t size;
3072
3073 if (!count)
3074 return 0;
3075
3076 /* Do we have previous read data to read? */
3077 if (info->read < PAGE_SIZE)
3078 goto read;
3079
3080 info->read = 0;
3081
3082 ret = ring_buffer_read_page(info->tr->buffer,
3083 &info->spare,
3084 count,
3085 info->cpu, 0);
3086 if (ret < 0)
3087 return 0;
3088
3089 pos = ring_buffer_page_len(info->spare);
3090
3091 if (pos < PAGE_SIZE)
3092 memset(info->spare + pos, 0, PAGE_SIZE - pos);
3093
3094read:
3095 size = PAGE_SIZE - info->read;
3096 if (size > count)
3097 size = count;
3098
3099 ret = copy_to_user(ubuf, info->spare + info->read, size);
3100 if (ret == size)
3101 return -EFAULT;
3102 size -= ret;
3103
3104 *ppos += size;
3105 info->read += size;
3106
3107 return size;
3108}
3109
3110static int tracing_buffers_release(struct inode *inode, struct file *file)
3111{
3112 struct ftrace_buffer_info *info = file->private_data;
3113
3114 ring_buffer_free_read_page(info->tr->buffer, info->spare);
3115 kfree(info);
3116
3117 return 0;
3118}
3119
3120struct buffer_ref {
3121 struct ring_buffer *buffer;
3122 void *page;
3123 int ref;
3124};
3125
3126static void buffer_pipe_buf_release(struct pipe_inode_info *pipe,
3127 struct pipe_buffer *buf)
3128{
3129 struct buffer_ref *ref = (struct buffer_ref *)buf->private;
3130
3131 if (--ref->ref)
3132 return;
3133
3134 ring_buffer_free_read_page(ref->buffer, ref->page);
3135 kfree(ref);
3136 buf->private = 0;
3137}
3138
3139static int buffer_pipe_buf_steal(struct pipe_inode_info *pipe,
3140 struct pipe_buffer *buf)
3141{
3142 return 1;
3143}
3144
3145static void buffer_pipe_buf_get(struct pipe_inode_info *pipe,
3146 struct pipe_buffer *buf)
3147{
3148 struct buffer_ref *ref = (struct buffer_ref *)buf->private;
3149
3150 ref->ref++;
3151}
3152
3153/* Pipe buffer operations for a buffer. */
3154static struct pipe_buf_operations buffer_pipe_buf_ops = {
3155 .can_merge = 0,
3156 .map = generic_pipe_buf_map,
3157 .unmap = generic_pipe_buf_unmap,
3158 .confirm = generic_pipe_buf_confirm,
3159 .release = buffer_pipe_buf_release,
3160 .steal = buffer_pipe_buf_steal,
3161 .get = buffer_pipe_buf_get,
3162};
3163
3164/*
3165 * Callback from splice_to_pipe(), if we need to release some pages
3166 * at the end of the spd in case we error'ed out in filling the pipe.
3167 */
3168static void buffer_spd_release(struct splice_pipe_desc *spd, unsigned int i)
3169{
3170 struct buffer_ref *ref =
3171 (struct buffer_ref *)spd->partial[i].private;
3172
3173 if (--ref->ref)
3174 return;
3175
3176 ring_buffer_free_read_page(ref->buffer, ref->page);
3177 kfree(ref);
3178 spd->partial[i].private = 0;
3179}
3180
3181static ssize_t
3182tracing_buffers_splice_read(struct file *file, loff_t *ppos,
3183 struct pipe_inode_info *pipe, size_t len,
3184 unsigned int flags)
3185{
3186 struct ftrace_buffer_info *info = file->private_data;
3187 struct partial_page partial[PIPE_BUFFERS];
3188 struct page *pages[PIPE_BUFFERS];
3189 struct splice_pipe_desc spd = {
3190 .pages = pages,
3191 .partial = partial,
3192 .flags = flags,
3193 .ops = &buffer_pipe_buf_ops,
3194 .spd_release = buffer_spd_release,
3195 };
3196 struct buffer_ref *ref;
3197 int size, i;
3198 size_t ret;
3199
3200 /*
3201 * We can't seek on a buffer input
3202 */
3203 if (unlikely(*ppos))
3204 return -ESPIPE;
3205
3206
3207 for (i = 0; i < PIPE_BUFFERS && len; i++, len -= size) {
3208 struct page *page;
3209 int r;
3210
3211 ref = kzalloc(sizeof(*ref), GFP_KERNEL);
3212 if (!ref)
3213 break;
3214
3215 ref->buffer = info->tr->buffer;
3216 ref->page = ring_buffer_alloc_read_page(ref->buffer);
3217 if (!ref->page) {
3218 kfree(ref);
3219 break;
3220 }
3221
3222 r = ring_buffer_read_page(ref->buffer, &ref->page,
3223 len, info->cpu, 0);
3224 if (r < 0) {
3225 ring_buffer_free_read_page(ref->buffer,
3226 ref->page);
3227 kfree(ref);
3228 break;
3229 }
3230
3231 /*
3232 * zero out any left over data, this is going to
3233 * user land.
3234 */
3235 size = ring_buffer_page_len(ref->page);
3236 if (size < PAGE_SIZE)
3237 memset(ref->page + size, 0, PAGE_SIZE - size);
3238
3239 page = virt_to_page(ref->page);
3240
3241 spd.pages[i] = page;
3242 spd.partial[i].len = PAGE_SIZE;
3243 spd.partial[i].offset = 0;
3244 spd.partial[i].private = (unsigned long)ref;
3245 spd.nr_pages++;
3246 }
3247
3248 spd.nr_pages = i;
3249
3250 /* did we read anything? */
3251 if (!spd.nr_pages) {
3252 if (flags & SPLICE_F_NONBLOCK)
3253 ret = -EAGAIN;
3254 else
3255 ret = 0;
3256 /* TODO: block */
3257 return ret;
3258 }
3259
3260 ret = splice_to_pipe(pipe, &spd);
3261
3262 return ret;
3263}
3264
3265static const struct file_operations tracing_buffers_fops = {
3266 .open = tracing_buffers_open,
3267 .read = tracing_buffers_read,
3268 .release = tracing_buffers_release,
3269 .splice_read = tracing_buffers_splice_read,
3270 .llseek = no_llseek,
3271};
3272
3472#ifdef CONFIG_DYNAMIC_FTRACE 3273#ifdef CONFIG_DYNAMIC_FTRACE
3473 3274
3474int __weak ftrace_arch_read_dyn_info(char *buf, int size) 3275int __weak ftrace_arch_read_dyn_info(char *buf, int size)
@@ -3500,7 +3301,7 @@ tracing_read_dyn_info(struct file *filp, char __user *ubuf,
3500 return r; 3301 return r;
3501} 3302}
3502 3303
3503static struct file_operations tracing_dyn_info_fops = { 3304static const struct file_operations tracing_dyn_info_fops = {
3504 .open = tracing_open_generic, 3305 .open = tracing_open_generic,
3505 .read = tracing_read_dyn_info, 3306 .read = tracing_read_dyn_info,
3506}; 3307};
@@ -3526,15 +3327,346 @@ struct dentry *tracing_init_dentry(void)
3526 return d_tracer; 3327 return d_tracer;
3527} 3328}
3528 3329
3330static struct dentry *d_percpu;
3331
3332struct dentry *tracing_dentry_percpu(void)
3333{
3334 static int once;
3335 struct dentry *d_tracer;
3336
3337 if (d_percpu)
3338 return d_percpu;
3339
3340 d_tracer = tracing_init_dentry();
3341
3342 if (!d_tracer)
3343 return NULL;
3344
3345 d_percpu = debugfs_create_dir("per_cpu", d_tracer);
3346
3347 if (!d_percpu && !once) {
3348 once = 1;
3349 pr_warning("Could not create debugfs directory 'per_cpu'\n");
3350 return NULL;
3351 }
3352
3353 return d_percpu;
3354}
3355
3356static void tracing_init_debugfs_percpu(long cpu)
3357{
3358 struct dentry *d_percpu = tracing_dentry_percpu();
3359 struct dentry *entry, *d_cpu;
3360 /* strlen(cpu) + MAX(log10(cpu)) + '\0' */
3361 char cpu_dir[7];
3362
3363 if (cpu > 999 || cpu < 0)
3364 return;
3365
3366 sprintf(cpu_dir, "cpu%ld", cpu);
3367 d_cpu = debugfs_create_dir(cpu_dir, d_percpu);
3368 if (!d_cpu) {
3369 pr_warning("Could not create debugfs '%s' entry\n", cpu_dir);
3370 return;
3371 }
3372
3373 /* per cpu trace_pipe */
3374 entry = debugfs_create_file("trace_pipe", 0444, d_cpu,
3375 (void *) cpu, &tracing_pipe_fops);
3376 if (!entry)
3377 pr_warning("Could not create debugfs 'trace_pipe' entry\n");
3378
3379 /* per cpu trace */
3380 entry = debugfs_create_file("trace", 0444, d_cpu,
3381 (void *) cpu, &tracing_fops);
3382 if (!entry)
3383 pr_warning("Could not create debugfs 'trace' entry\n");
3384}
3385
3529#ifdef CONFIG_FTRACE_SELFTEST 3386#ifdef CONFIG_FTRACE_SELFTEST
3530/* Let selftest have access to static functions in this file */ 3387/* Let selftest have access to static functions in this file */
3531#include "trace_selftest.c" 3388#include "trace_selftest.c"
3532#endif 3389#endif
3533 3390
3391struct trace_option_dentry {
3392 struct tracer_opt *opt;
3393 struct tracer_flags *flags;
3394 struct dentry *entry;
3395};
3396
3397static ssize_t
3398trace_options_read(struct file *filp, char __user *ubuf, size_t cnt,
3399 loff_t *ppos)
3400{
3401 struct trace_option_dentry *topt = filp->private_data;
3402 char *buf;
3403
3404 if (topt->flags->val & topt->opt->bit)
3405 buf = "1\n";
3406 else
3407 buf = "0\n";
3408
3409 return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2);
3410}
3411
3412static ssize_t
3413trace_options_write(struct file *filp, const char __user *ubuf, size_t cnt,
3414 loff_t *ppos)
3415{
3416 struct trace_option_dentry *topt = filp->private_data;
3417 unsigned long val;
3418 char buf[64];
3419 int ret;
3420
3421 if (cnt >= sizeof(buf))
3422 return -EINVAL;
3423
3424 if (copy_from_user(&buf, ubuf, cnt))
3425 return -EFAULT;
3426
3427 buf[cnt] = 0;
3428
3429 ret = strict_strtoul(buf, 10, &val);
3430 if (ret < 0)
3431 return ret;
3432
3433 ret = 0;
3434 switch (val) {
3435 case 0:
3436 /* do nothing if already cleared */
3437 if (!(topt->flags->val & topt->opt->bit))
3438 break;
3439
3440 mutex_lock(&trace_types_lock);
3441 if (current_trace->set_flag)
3442 ret = current_trace->set_flag(topt->flags->val,
3443 topt->opt->bit, 0);
3444 mutex_unlock(&trace_types_lock);
3445 if (ret)
3446 return ret;
3447 topt->flags->val &= ~topt->opt->bit;
3448 break;
3449 case 1:
3450 /* do nothing if already set */
3451 if (topt->flags->val & topt->opt->bit)
3452 break;
3453
3454 mutex_lock(&trace_types_lock);
3455 if (current_trace->set_flag)
3456 ret = current_trace->set_flag(topt->flags->val,
3457 topt->opt->bit, 1);
3458 mutex_unlock(&trace_types_lock);
3459 if (ret)
3460 return ret;
3461 topt->flags->val |= topt->opt->bit;
3462 break;
3463
3464 default:
3465 return -EINVAL;
3466 }
3467
3468 *ppos += cnt;
3469
3470 return cnt;
3471}
3472
3473
3474static const struct file_operations trace_options_fops = {
3475 .open = tracing_open_generic,
3476 .read = trace_options_read,
3477 .write = trace_options_write,
3478};
3479
3480static ssize_t
3481trace_options_core_read(struct file *filp, char __user *ubuf, size_t cnt,
3482 loff_t *ppos)
3483{
3484 long index = (long)filp->private_data;
3485 char *buf;
3486
3487 if (trace_flags & (1 << index))
3488 buf = "1\n";
3489 else
3490 buf = "0\n";
3491
3492 return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2);
3493}
3494
3495static ssize_t
3496trace_options_core_write(struct file *filp, const char __user *ubuf, size_t cnt,
3497 loff_t *ppos)
3498{
3499 long index = (long)filp->private_data;
3500 char buf[64];
3501 unsigned long val;
3502 int ret;
3503
3504 if (cnt >= sizeof(buf))
3505 return -EINVAL;
3506
3507 if (copy_from_user(&buf, ubuf, cnt))
3508 return -EFAULT;
3509
3510 buf[cnt] = 0;
3511
3512 ret = strict_strtoul(buf, 10, &val);
3513 if (ret < 0)
3514 return ret;
3515
3516 switch (val) {
3517 case 0:
3518 trace_flags &= ~(1 << index);
3519 break;
3520 case 1:
3521 trace_flags |= 1 << index;
3522 break;
3523
3524 default:
3525 return -EINVAL;
3526 }
3527
3528 *ppos += cnt;
3529
3530 return cnt;
3531}
3532
3533static const struct file_operations trace_options_core_fops = {
3534 .open = tracing_open_generic,
3535 .read = trace_options_core_read,
3536 .write = trace_options_core_write,
3537};
3538
3539static struct dentry *trace_options_init_dentry(void)
3540{
3541 struct dentry *d_tracer;
3542 static struct dentry *t_options;
3543
3544 if (t_options)
3545 return t_options;
3546
3547 d_tracer = tracing_init_dentry();
3548 if (!d_tracer)
3549 return NULL;
3550
3551 t_options = debugfs_create_dir("options", d_tracer);
3552 if (!t_options) {
3553 pr_warning("Could not create debugfs directory 'options'\n");
3554 return NULL;
3555 }
3556
3557 return t_options;
3558}
3559
3560static void
3561create_trace_option_file(struct trace_option_dentry *topt,
3562 struct tracer_flags *flags,
3563 struct tracer_opt *opt)
3564{
3565 struct dentry *t_options;
3566 struct dentry *entry;
3567
3568 t_options = trace_options_init_dentry();
3569 if (!t_options)
3570 return;
3571
3572 topt->flags = flags;
3573 topt->opt = opt;
3574
3575 entry = debugfs_create_file(opt->name, 0644, t_options, topt,
3576 &trace_options_fops);
3577
3578 topt->entry = entry;
3579
3580}
3581
3582static struct trace_option_dentry *
3583create_trace_option_files(struct tracer *tracer)
3584{
3585 struct trace_option_dentry *topts;
3586 struct tracer_flags *flags;
3587 struct tracer_opt *opts;
3588 int cnt;
3589
3590 if (!tracer)
3591 return NULL;
3592
3593 flags = tracer->flags;
3594
3595 if (!flags || !flags->opts)
3596 return NULL;
3597
3598 opts = flags->opts;
3599
3600 for (cnt = 0; opts[cnt].name; cnt++)
3601 ;
3602
3603 topts = kcalloc(cnt + 1, sizeof(*topts), GFP_KERNEL);
3604 if (!topts)
3605 return NULL;
3606
3607 for (cnt = 0; opts[cnt].name; cnt++)
3608 create_trace_option_file(&topts[cnt], flags,
3609 &opts[cnt]);
3610
3611 return topts;
3612}
3613
3614static void
3615destroy_trace_option_files(struct trace_option_dentry *topts)
3616{
3617 int cnt;
3618
3619 if (!topts)
3620 return;
3621
3622 for (cnt = 0; topts[cnt].opt; cnt++) {
3623 if (topts[cnt].entry)
3624 debugfs_remove(topts[cnt].entry);
3625 }
3626
3627 kfree(topts);
3628}
3629
3630static struct dentry *
3631create_trace_option_core_file(const char *option, long index)
3632{
3633 struct dentry *t_options;
3634 struct dentry *entry;
3635
3636 t_options = trace_options_init_dentry();
3637 if (!t_options)
3638 return NULL;
3639
3640 entry = debugfs_create_file(option, 0644, t_options, (void *)index,
3641 &trace_options_core_fops);
3642
3643 return entry;
3644}
3645
3646static __init void create_trace_options_dir(void)
3647{
3648 struct dentry *t_options;
3649 struct dentry *entry;
3650 int i;
3651
3652 t_options = trace_options_init_dentry();
3653 if (!t_options)
3654 return;
3655
3656 for (i = 0; trace_options[i]; i++) {
3657 entry = create_trace_option_core_file(trace_options[i], i);
3658 if (!entry)
3659 pr_warning("Could not create debugfs %s entry\n",
3660 trace_options[i]);
3661 }
3662}
3663
3534static __init int tracer_init_debugfs(void) 3664static __init int tracer_init_debugfs(void)
3535{ 3665{
3536 struct dentry *d_tracer; 3666 struct dentry *d_tracer;
3667 struct dentry *buffers;
3537 struct dentry *entry; 3668 struct dentry *entry;
3669 int cpu;
3538 3670
3539 d_tracer = tracing_init_dentry(); 3671 d_tracer = tracing_init_dentry();
3540 3672
@@ -3548,18 +3680,15 @@ static __init int tracer_init_debugfs(void)
3548 if (!entry) 3680 if (!entry)
3549 pr_warning("Could not create debugfs 'trace_options' entry\n"); 3681 pr_warning("Could not create debugfs 'trace_options' entry\n");
3550 3682
3683 create_trace_options_dir();
3684
3551 entry = debugfs_create_file("tracing_cpumask", 0644, d_tracer, 3685 entry = debugfs_create_file("tracing_cpumask", 0644, d_tracer,
3552 NULL, &tracing_cpumask_fops); 3686 NULL, &tracing_cpumask_fops);
3553 if (!entry) 3687 if (!entry)
3554 pr_warning("Could not create debugfs 'tracing_cpumask' entry\n"); 3688 pr_warning("Could not create debugfs 'tracing_cpumask' entry\n");
3555 3689
3556 entry = debugfs_create_file("latency_trace", 0444, d_tracer,
3557 &global_trace, &tracing_lt_fops);
3558 if (!entry)
3559 pr_warning("Could not create debugfs 'latency_trace' entry\n");
3560
3561 entry = debugfs_create_file("trace", 0444, d_tracer, 3690 entry = debugfs_create_file("trace", 0444, d_tracer,
3562 &global_trace, &tracing_fops); 3691 (void *) TRACE_PIPE_ALL_CPU, &tracing_fops);
3563 if (!entry) 3692 if (!entry)
3564 pr_warning("Could not create debugfs 'trace' entry\n"); 3693 pr_warning("Could not create debugfs 'trace' entry\n");
3565 3694
@@ -3590,8 +3719,8 @@ static __init int tracer_init_debugfs(void)
3590 if (!entry) 3719 if (!entry)
3591 pr_warning("Could not create debugfs 'README' entry\n"); 3720 pr_warning("Could not create debugfs 'README' entry\n");
3592 3721
3593 entry = debugfs_create_file("trace_pipe", 0644, d_tracer, 3722 entry = debugfs_create_file("trace_pipe", 0444, d_tracer,
3594 NULL, &tracing_pipe_fops); 3723 (void *) TRACE_PIPE_ALL_CPU, &tracing_pipe_fops);
3595 if (!entry) 3724 if (!entry)
3596 pr_warning("Could not create debugfs " 3725 pr_warning("Could not create debugfs "
3597 "'trace_pipe' entry\n"); 3726 "'trace_pipe' entry\n");
@@ -3608,6 +3737,26 @@ static __init int tracer_init_debugfs(void)
3608 pr_warning("Could not create debugfs " 3737 pr_warning("Could not create debugfs "
3609 "'trace_marker' entry\n"); 3738 "'trace_marker' entry\n");
3610 3739
3740 buffers = debugfs_create_dir("binary_buffers", d_tracer);
3741
3742 if (!buffers)
3743 pr_warning("Could not create buffers directory\n");
3744 else {
3745 int cpu;
3746 char buf[64];
3747
3748 for_each_tracing_cpu(cpu) {
3749 sprintf(buf, "%d", cpu);
3750
3751 entry = debugfs_create_file(buf, 0444, buffers,
3752 (void *)(long)cpu,
3753 &tracing_buffers_fops);
3754 if (!entry)
3755 pr_warning("Could not create debugfs buffers "
3756 "'%s' entry\n", buf);
3757 }
3758 }
3759
3611#ifdef CONFIG_DYNAMIC_FTRACE 3760#ifdef CONFIG_DYNAMIC_FTRACE
3612 entry = debugfs_create_file("dyn_ftrace_total_info", 0444, d_tracer, 3761 entry = debugfs_create_file("dyn_ftrace_total_info", 0444, d_tracer,
3613 &ftrace_update_tot_cnt, 3762 &ftrace_update_tot_cnt,
@@ -3619,77 +3768,12 @@ static __init int tracer_init_debugfs(void)
3619#ifdef CONFIG_SYSPROF_TRACER 3768#ifdef CONFIG_SYSPROF_TRACER
3620 init_tracer_sysprof_debugfs(d_tracer); 3769 init_tracer_sysprof_debugfs(d_tracer);
3621#endif 3770#endif
3622 return 0;
3623}
3624
3625int trace_vprintk(unsigned long ip, int depth, const char *fmt, va_list args)
3626{
3627 static DEFINE_SPINLOCK(trace_buf_lock);
3628 static char trace_buf[TRACE_BUF_SIZE];
3629
3630 struct ring_buffer_event *event;
3631 struct trace_array *tr = &global_trace;
3632 struct trace_array_cpu *data;
3633 int cpu, len = 0, size, pc;
3634 struct print_entry *entry;
3635 unsigned long irq_flags;
3636 3771
3637 if (tracing_disabled || tracing_selftest_running) 3772 for_each_tracing_cpu(cpu)
3638 return 0; 3773 tracing_init_debugfs_percpu(cpu);
3639 3774
3640 pc = preempt_count(); 3775 return 0;
3641 preempt_disable_notrace();
3642 cpu = raw_smp_processor_id();
3643 data = tr->data[cpu];
3644
3645 if (unlikely(atomic_read(&data->disabled)))
3646 goto out;
3647
3648 pause_graph_tracing();
3649 spin_lock_irqsave(&trace_buf_lock, irq_flags);
3650 len = vsnprintf(trace_buf, TRACE_BUF_SIZE, fmt, args);
3651
3652 len = min(len, TRACE_BUF_SIZE-1);
3653 trace_buf[len] = 0;
3654
3655 size = sizeof(*entry) + len + 1;
3656 event = ring_buffer_lock_reserve(tr->buffer, size, &irq_flags);
3657 if (!event)
3658 goto out_unlock;
3659 entry = ring_buffer_event_data(event);
3660 tracing_generic_entry_update(&entry->ent, irq_flags, pc);
3661 entry->ent.type = TRACE_PRINT;
3662 entry->ip = ip;
3663 entry->depth = depth;
3664
3665 memcpy(&entry->buf, trace_buf, len);
3666 entry->buf[len] = 0;
3667 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
3668
3669 out_unlock:
3670 spin_unlock_irqrestore(&trace_buf_lock, irq_flags);
3671 unpause_graph_tracing();
3672 out:
3673 preempt_enable_notrace();
3674
3675 return len;
3676}
3677EXPORT_SYMBOL_GPL(trace_vprintk);
3678
3679int __ftrace_printk(unsigned long ip, const char *fmt, ...)
3680{
3681 int ret;
3682 va_list ap;
3683
3684 if (!(trace_flags & TRACE_ITER_PRINTK))
3685 return 0;
3686
3687 va_start(ap, fmt);
3688 ret = trace_vprintk(ip, task_curr_ret_stack(current), fmt, ap);
3689 va_end(ap);
3690 return ret;
3691} 3776}
3692EXPORT_SYMBOL_GPL(__ftrace_printk);
3693 3777
3694static int trace_panic_handler(struct notifier_block *this, 3778static int trace_panic_handler(struct notifier_block *this,
3695 unsigned long event, void *unused) 3779 unsigned long event, void *unused)
@@ -3750,7 +3834,7 @@ trace_printk_seq(struct trace_seq *s)
3750 3834
3751 printk(KERN_TRACE "%s", s->buffer); 3835 printk(KERN_TRACE "%s", s->buffer);
3752 3836
3753 trace_seq_reset(s); 3837 trace_seq_init(s);
3754} 3838}
3755 3839
3756void ftrace_dump(void) 3840void ftrace_dump(void)
@@ -3782,8 +3866,10 @@ void ftrace_dump(void)
3782 3866
3783 printk(KERN_TRACE "Dumping ftrace buffer:\n"); 3867 printk(KERN_TRACE "Dumping ftrace buffer:\n");
3784 3868
3869 /* Simulate the iterator */
3785 iter.tr = &global_trace; 3870 iter.tr = &global_trace;
3786 iter.trace = current_trace; 3871 iter.trace = current_trace;
3872 iter.cpu_file = TRACE_PIPE_ALL_CPU;
3787 3873
3788 /* 3874 /*
3789 * We need to stop all tracing on all CPUS to read the 3875 * We need to stop all tracing on all CPUS to read the
@@ -3835,8 +3921,12 @@ __init static int tracer_alloc_buffers(void)
3835 if (!alloc_cpumask_var(&tracing_cpumask, GFP_KERNEL)) 3921 if (!alloc_cpumask_var(&tracing_cpumask, GFP_KERNEL))
3836 goto out_free_buffer_mask; 3922 goto out_free_buffer_mask;
3837 3923
3924 if (!alloc_cpumask_var(&tracing_reader_cpumask, GFP_KERNEL))
3925 goto out_free_tracing_cpumask;
3926
3838 cpumask_copy(tracing_buffer_mask, cpu_possible_mask); 3927 cpumask_copy(tracing_buffer_mask, cpu_possible_mask);
3839 cpumask_copy(tracing_cpumask, cpu_all_mask); 3928 cpumask_copy(tracing_cpumask, cpu_all_mask);
3929 cpumask_clear(tracing_reader_cpumask);
3840 3930
3841 /* TODO: make the number of buffers hot pluggable with CPUS */ 3931 /* TODO: make the number of buffers hot pluggable with CPUS */
3842 global_trace.buffer = ring_buffer_alloc(trace_buf_size, 3932 global_trace.buffer = ring_buffer_alloc(trace_buf_size,
@@ -3871,14 +3961,10 @@ __init static int tracer_alloc_buffers(void)
3871 trace_init_cmdlines(); 3961 trace_init_cmdlines();
3872 3962
3873 register_tracer(&nop_trace); 3963 register_tracer(&nop_trace);
3964 current_trace = &nop_trace;
3874#ifdef CONFIG_BOOT_TRACER 3965#ifdef CONFIG_BOOT_TRACER
3875 register_tracer(&boot_tracer); 3966 register_tracer(&boot_tracer);
3876 current_trace = &boot_tracer;
3877 current_trace->init(&global_trace);
3878#else
3879 current_trace = &nop_trace;
3880#endif 3967#endif
3881
3882 /* All seems OK, enable tracing */ 3968 /* All seems OK, enable tracing */
3883 tracing_disabled = 0; 3969 tracing_disabled = 0;
3884 3970
@@ -3889,11 +3975,34 @@ __init static int tracer_alloc_buffers(void)
3889 ret = 0; 3975 ret = 0;
3890 3976
3891out_free_cpumask: 3977out_free_cpumask:
3978 free_cpumask_var(tracing_reader_cpumask);
3979out_free_tracing_cpumask:
3892 free_cpumask_var(tracing_cpumask); 3980 free_cpumask_var(tracing_cpumask);
3893out_free_buffer_mask: 3981out_free_buffer_mask:
3894 free_cpumask_var(tracing_buffer_mask); 3982 free_cpumask_var(tracing_buffer_mask);
3895out: 3983out:
3896 return ret; 3984 return ret;
3897} 3985}
3986
3987__init static int clear_boot_tracer(void)
3988{
3989 /*
3990 * The default tracer at boot buffer is an init section.
3991 * This function is called in lateinit. If we did not
3992 * find the boot tracer, then clear it out, to prevent
3993 * later registration from accessing the buffer that is
3994 * about to be freed.
3995 */
3996 if (!default_bootup_tracer)
3997 return 0;
3998
3999 printk(KERN_INFO "ftrace bootup tracer '%s' not registered.\n",
4000 default_bootup_tracer);
4001 default_bootup_tracer = NULL;
4002
4003 return 0;
4004}
4005
3898early_initcall(tracer_alloc_buffers); 4006early_initcall(tracer_alloc_buffers);
3899fs_initcall(tracer_init_debugfs); 4007fs_initcall(tracer_init_debugfs);
4008late_initcall(clear_boot_tracer);