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.c1480
1 files changed, 435 insertions, 1045 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 17bb88d86ac2..95f99a7abf2f 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -31,12 +31,14 @@
31#include <linux/fs.h> 31#include <linux/fs.h>
32#include <linux/kprobes.h> 32#include <linux/kprobes.h>
33#include <linux/writeback.h> 33#include <linux/writeback.h>
34#include <linux/splice.h>
34 35
35#include <linux/stacktrace.h> 36#include <linux/stacktrace.h>
36#include <linux/ring_buffer.h> 37#include <linux/ring_buffer.h>
37#include <linux/irqflags.h> 38#include <linux/irqflags.h>
38 39
39#include "trace.h" 40#include "trace.h"
41#include "trace_output.h"
40 42
41#define TRACE_BUFFER_FLAGS (RB_FL_OVERWRITE) 43#define TRACE_BUFFER_FLAGS (RB_FL_OVERWRITE)
42 44
@@ -52,6 +54,11 @@ unsigned long __read_mostly tracing_thresh;
52 */ 54 */
53static bool __read_mostly tracing_selftest_running; 55static bool __read_mostly tracing_selftest_running;
54 56
57/*
58 * If a tracer is running, we do not want to run SELFTEST.
59 */
60static bool __read_mostly tracing_selftest_disabled;
61
55/* For tracers that don't implement custom flags */ 62/* For tracers that don't implement custom flags */
56static struct tracer_opt dummy_tracer_opt[] = { 63static struct tracer_opt dummy_tracer_opt[] = {
57 { } 64 { }
@@ -73,7 +80,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 80 * of the tracer is successful. But that is the only place that sets
74 * this back to zero. 81 * this back to zero.
75 */ 82 */
76int tracing_disabled = 1; 83static int tracing_disabled = 1;
77 84
78static DEFINE_PER_CPU(local_t, ftrace_cpu_disabled); 85static DEFINE_PER_CPU(local_t, ftrace_cpu_disabled);
79 86
@@ -109,14 +116,19 @@ static cpumask_var_t __read_mostly tracing_buffer_mask;
109 */ 116 */
110int ftrace_dump_on_oops; 117int ftrace_dump_on_oops;
111 118
112static int tracing_set_tracer(char *buf); 119static int tracing_set_tracer(const char *buf);
120
121#define BOOTUP_TRACER_SIZE 100
122static char bootup_tracer_buf[BOOTUP_TRACER_SIZE] __initdata;
123static char *default_bootup_tracer;
113 124
114static int __init set_ftrace(char *str) 125static int __init set_ftrace(char *str)
115{ 126{
116 tracing_set_tracer(str); 127 strncpy(bootup_tracer_buf, str, BOOTUP_TRACER_SIZE);
128 default_bootup_tracer = bootup_tracer_buf;
117 return 1; 129 return 1;
118} 130}
119__setup("ftrace", set_ftrace); 131__setup("ftrace=", set_ftrace);
120 132
121static int __init set_ftrace_dump_on_oops(char *str) 133static int __init set_ftrace_dump_on_oops(char *str)
122{ 134{
@@ -186,9 +198,6 @@ int tracing_is_enabled(void)
186 return tracer_enabled; 198 return tracer_enabled;
187} 199}
188 200
189/* function tracing enabled */
190int ftrace_function_enabled;
191
192/* 201/*
193 * trace_buf_size is the size in bytes that is allocated 202 * trace_buf_size is the size in bytes that is allocated
194 * for a buffer. Note, the number of bytes is always rounded 203 * for a buffer. Note, the number of bytes is always rounded
@@ -229,7 +238,7 @@ static DECLARE_WAIT_QUEUE_HEAD(trace_wait);
229 238
230/* trace_flags holds trace_options default values */ 239/* trace_flags holds trace_options default values */
231unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK | 240unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |
232 TRACE_ITER_ANNOTATE; 241 TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO;
233 242
234/** 243/**
235 * trace_wake_up - wake up tasks waiting for trace input 244 * trace_wake_up - wake up tasks waiting for trace input
@@ -287,6 +296,7 @@ static const char *trace_options[] = {
287 "userstacktrace", 296 "userstacktrace",
288 "sym-userobj", 297 "sym-userobj",
289 "printk-msg-only", 298 "printk-msg-only",
299 "context-info",
290 NULL 300 NULL
291}; 301};
292 302
@@ -329,132 +339,6 @@ __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
329 tracing_record_cmdline(current); 339 tracing_record_cmdline(current);
330} 340}
331 341
332/**
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 int len = (PAGE_SIZE - 1) - s->len;
347 va_list ap;
348 int ret;
349
350 if (!len)
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;
406
407 memcpy(s->buffer + s->len, mem, len);
408 s->len += len;
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
441 if (s->len >= (PAGE_SIZE - 1))
442 return 0;
443 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
444 if (!IS_ERR(p)) {
445 p = mangle_path(s->buffer + s->len, p, "\n");
446 if (p) {
447 s->len = p - s->buffer;
448 return 1;
449 }
450 } else {
451 s->buffer[s->len++] = '?';
452 return 1;
453 }
454
455 return 0;
456}
457
458static void 342static void
459trace_seq_reset(struct trace_seq *s) 343trace_seq_reset(struct trace_seq *s)
460{ 344{
@@ -481,6 +365,25 @@ ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt)
481 return cnt; 365 return cnt;
482} 366}
483 367
368ssize_t trace_seq_to_buffer(struct trace_seq *s, void *buf, size_t cnt)
369{
370 int len;
371 void *ret;
372
373 if (s->len <= s->readpos)
374 return -EBUSY;
375
376 len = s->len - s->readpos;
377 if (cnt > len)
378 cnt = len;
379 ret = memcpy(buf, s->buffer + s->readpos, cnt);
380 if (!ret)
381 return -EFAULT;
382
383 s->readpos += len;
384 return cnt;
385}
386
484static void 387static void
485trace_print_seq(struct seq_file *m, struct trace_seq *s) 388trace_print_seq(struct seq_file *m, struct trace_seq *s)
486{ 389{
@@ -543,7 +446,7 @@ update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu)
543 446
544 ftrace_enable_cpu(); 447 ftrace_enable_cpu();
545 448
546 WARN_ON_ONCE(ret); 449 WARN_ON_ONCE(ret && ret != -EAGAIN);
547 450
548 __update_max_tr(tr, tsk, cpu); 451 __update_max_tr(tr, tsk, cpu);
549 __raw_spin_unlock(&ftrace_max_lock); 452 __raw_spin_unlock(&ftrace_max_lock);
@@ -556,6 +459,8 @@ update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu)
556 * Register a new plugin tracer. 459 * Register a new plugin tracer.
557 */ 460 */
558int register_tracer(struct tracer *type) 461int register_tracer(struct tracer *type)
462__releases(kernel_lock)
463__acquires(kernel_lock)
559{ 464{
560 struct tracer *t; 465 struct tracer *t;
561 int len; 466 int len;
@@ -596,7 +501,7 @@ int register_tracer(struct tracer *type)
596 type->flags->opts = dummy_tracer_opt; 501 type->flags->opts = dummy_tracer_opt;
597 502
598#ifdef CONFIG_FTRACE_STARTUP_TEST 503#ifdef CONFIG_FTRACE_STARTUP_TEST
599 if (type->selftest) { 504 if (type->selftest && !tracing_selftest_disabled) {
600 struct tracer *saved_tracer = current_trace; 505 struct tracer *saved_tracer = current_trace;
601 struct trace_array *tr = &global_trace; 506 struct trace_array *tr = &global_trace;
602 int i; 507 int i;
@@ -638,8 +543,26 @@ int register_tracer(struct tracer *type)
638 out: 543 out:
639 tracing_selftest_running = false; 544 tracing_selftest_running = false;
640 mutex_unlock(&trace_types_lock); 545 mutex_unlock(&trace_types_lock);
641 lock_kernel();
642 546
547 if (ret || !default_bootup_tracer)
548 goto out_unlock;
549
550 if (strncmp(default_bootup_tracer, type->name, BOOTUP_TRACER_SIZE))
551 goto out_unlock;
552
553 printk(KERN_INFO "Starting tracer '%s'\n", type->name);
554 /* Do we want this tracer to start on bootup? */
555 tracing_set_tracer(type->name);
556 default_bootup_tracer = NULL;
557 /* disable other selftests, since this will break it. */
558 tracing_selftest_disabled = 1;
559#ifdef CONFIG_FTRACE_STARTUP_TEST
560 printk(KERN_INFO "Disabling FTRACE selftests due to running tracer '%s'\n",
561 type->name);
562#endif
563
564 out_unlock:
565 lock_kernel();
643 return ret; 566 return ret;
644} 567}
645 568
@@ -658,6 +581,15 @@ void unregister_tracer(struct tracer *type)
658 581
659 found: 582 found:
660 *t = (*t)->next; 583 *t = (*t)->next;
584
585 if (type == current_trace && tracer_enabled) {
586 tracer_enabled = 0;
587 tracing_stop();
588 if (current_trace->stop)
589 current_trace->stop(&global_trace);
590 current_trace = &nop_trace;
591 }
592
661 if (strlen(type->name) != max_tracer_type_len) 593 if (strlen(type->name) != max_tracer_type_len)
662 goto out; 594 goto out;
663 595
@@ -696,7 +628,7 @@ static int cmdline_idx;
696static DEFINE_SPINLOCK(trace_cmdline_lock); 628static DEFINE_SPINLOCK(trace_cmdline_lock);
697 629
698/* temporary disable recording */ 630/* temporary disable recording */
699atomic_t trace_record_cmdline_disabled __read_mostly; 631static atomic_t trace_record_cmdline_disabled __read_mostly;
700 632
701static void trace_init_cmdlines(void) 633static void trace_init_cmdlines(void)
702{ 634{
@@ -738,13 +670,12 @@ void tracing_start(void)
738 return; 670 return;
739 671
740 spin_lock_irqsave(&tracing_start_lock, flags); 672 spin_lock_irqsave(&tracing_start_lock, flags);
741 if (--trace_stop_count) 673 if (--trace_stop_count) {
742 goto out; 674 if (trace_stop_count < 0) {
743 675 /* Someone screwed up their debugging */
744 if (trace_stop_count < 0) { 676 WARN_ON_ONCE(1);
745 /* Someone screwed up their debugging */ 677 trace_stop_count = 0;
746 WARN_ON_ONCE(1); 678 }
747 trace_stop_count = 0;
748 goto out; 679 goto out;
749 } 680 }
750 681
@@ -876,78 +807,100 @@ tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags,
876 (need_resched() ? TRACE_FLAG_NEED_RESCHED : 0); 807 (need_resched() ? TRACE_FLAG_NEED_RESCHED : 0);
877} 808}
878 809
810struct ring_buffer_event *trace_buffer_lock_reserve(struct trace_array *tr,
811 unsigned char type,
812 unsigned long len,
813 unsigned long flags, int pc)
814{
815 struct ring_buffer_event *event;
816
817 event = ring_buffer_lock_reserve(tr->buffer, len);
818 if (event != NULL) {
819 struct trace_entry *ent = ring_buffer_event_data(event);
820
821 tracing_generic_entry_update(ent, flags, pc);
822 ent->type = type;
823 }
824
825 return event;
826}
827static void ftrace_trace_stack(struct trace_array *tr,
828 unsigned long flags, int skip, int pc);
829static void ftrace_trace_userstack(struct trace_array *tr,
830 unsigned long flags, int pc);
831
832void trace_buffer_unlock_commit(struct trace_array *tr,
833 struct ring_buffer_event *event,
834 unsigned long flags, int pc)
835{
836 ring_buffer_unlock_commit(tr->buffer, event);
837
838 ftrace_trace_stack(tr, flags, 6, pc);
839 ftrace_trace_userstack(tr, flags, pc);
840 trace_wake_up();
841}
842
879void 843void
880trace_function(struct trace_array *tr, struct trace_array_cpu *data, 844trace_function(struct trace_array *tr,
881 unsigned long ip, unsigned long parent_ip, unsigned long flags, 845 unsigned long ip, unsigned long parent_ip, unsigned long flags,
882 int pc) 846 int pc)
883{ 847{
884 struct ring_buffer_event *event; 848 struct ring_buffer_event *event;
885 struct ftrace_entry *entry; 849 struct ftrace_entry *entry;
886 unsigned long irq_flags;
887 850
888 /* If we are reading the ring buffer, don't trace */ 851 /* If we are reading the ring buffer, don't trace */
889 if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled)))) 852 if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled))))
890 return; 853 return;
891 854
892 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry), 855 event = trace_buffer_lock_reserve(tr, TRACE_FN, sizeof(*entry),
893 &irq_flags); 856 flags, pc);
894 if (!event) 857 if (!event)
895 return; 858 return;
896 entry = ring_buffer_event_data(event); 859 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; 860 entry->ip = ip;
900 entry->parent_ip = parent_ip; 861 entry->parent_ip = parent_ip;
901 ring_buffer_unlock_commit(tr->buffer, event, irq_flags); 862 ring_buffer_unlock_commit(tr->buffer, event);
902} 863}
903 864
904#ifdef CONFIG_FUNCTION_GRAPH_TRACER 865#ifdef CONFIG_FUNCTION_GRAPH_TRACER
905static void __trace_graph_entry(struct trace_array *tr, 866static void __trace_graph_entry(struct trace_array *tr,
906 struct trace_array_cpu *data,
907 struct ftrace_graph_ent *trace, 867 struct ftrace_graph_ent *trace,
908 unsigned long flags, 868 unsigned long flags,
909 int pc) 869 int pc)
910{ 870{
911 struct ring_buffer_event *event; 871 struct ring_buffer_event *event;
912 struct ftrace_graph_ent_entry *entry; 872 struct ftrace_graph_ent_entry *entry;
913 unsigned long irq_flags;
914 873
915 if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled)))) 874 if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled))))
916 return; 875 return;
917 876
918 event = ring_buffer_lock_reserve(global_trace.buffer, sizeof(*entry), 877 event = trace_buffer_lock_reserve(&global_trace, TRACE_GRAPH_ENT,
919 &irq_flags); 878 sizeof(*entry), flags, pc);
920 if (!event) 879 if (!event)
921 return; 880 return;
922 entry = ring_buffer_event_data(event); 881 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; 882 entry->graph_ent = *trace;
926 ring_buffer_unlock_commit(global_trace.buffer, event, irq_flags); 883 ring_buffer_unlock_commit(global_trace.buffer, event);
927} 884}
928 885
929static void __trace_graph_return(struct trace_array *tr, 886static void __trace_graph_return(struct trace_array *tr,
930 struct trace_array_cpu *data,
931 struct ftrace_graph_ret *trace, 887 struct ftrace_graph_ret *trace,
932 unsigned long flags, 888 unsigned long flags,
933 int pc) 889 int pc)
934{ 890{
935 struct ring_buffer_event *event; 891 struct ring_buffer_event *event;
936 struct ftrace_graph_ret_entry *entry; 892 struct ftrace_graph_ret_entry *entry;
937 unsigned long irq_flags;
938 893
939 if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled)))) 894 if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled))))
940 return; 895 return;
941 896
942 event = ring_buffer_lock_reserve(global_trace.buffer, sizeof(*entry), 897 event = trace_buffer_lock_reserve(&global_trace, TRACE_GRAPH_RET,
943 &irq_flags); 898 sizeof(*entry), flags, pc);
944 if (!event) 899 if (!event)
945 return; 900 return;
946 entry = ring_buffer_event_data(event); 901 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; 902 entry->ret = *trace;
950 ring_buffer_unlock_commit(global_trace.buffer, event, irq_flags); 903 ring_buffer_unlock_commit(global_trace.buffer, event);
951} 904}
952#endif 905#endif
953 906
@@ -957,31 +910,23 @@ ftrace(struct trace_array *tr, struct trace_array_cpu *data,
957 int pc) 910 int pc)
958{ 911{
959 if (likely(!atomic_read(&data->disabled))) 912 if (likely(!atomic_read(&data->disabled)))
960 trace_function(tr, data, ip, parent_ip, flags, pc); 913 trace_function(tr, ip, parent_ip, flags, pc);
961} 914}
962 915
963static void ftrace_trace_stack(struct trace_array *tr, 916static void __ftrace_trace_stack(struct trace_array *tr,
964 struct trace_array_cpu *data, 917 unsigned long flags,
965 unsigned long flags, 918 int skip, int pc)
966 int skip, int pc)
967{ 919{
968#ifdef CONFIG_STACKTRACE 920#ifdef CONFIG_STACKTRACE
969 struct ring_buffer_event *event; 921 struct ring_buffer_event *event;
970 struct stack_entry *entry; 922 struct stack_entry *entry;
971 struct stack_trace trace; 923 struct stack_trace trace;
972 unsigned long irq_flags;
973 924
974 if (!(trace_flags & TRACE_ITER_STACKTRACE)) 925 event = trace_buffer_lock_reserve(tr, TRACE_STACK,
975 return; 926 sizeof(*entry), flags, pc);
976
977 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
978 &irq_flags);
979 if (!event) 927 if (!event)
980 return; 928 return;
981 entry = ring_buffer_event_data(event); 929 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)); 930 memset(&entry->caller, 0, sizeof(entry->caller));
986 931
987 trace.nr_entries = 0; 932 trace.nr_entries = 0;
@@ -990,38 +935,43 @@ static void ftrace_trace_stack(struct trace_array *tr,
990 trace.entries = entry->caller; 935 trace.entries = entry->caller;
991 936
992 save_stack_trace(&trace); 937 save_stack_trace(&trace);
993 ring_buffer_unlock_commit(tr->buffer, event, irq_flags); 938 ring_buffer_unlock_commit(tr->buffer, event);
994#endif 939#endif
995} 940}
996 941
942static void ftrace_trace_stack(struct trace_array *tr,
943 unsigned long flags,
944 int skip, int pc)
945{
946 if (!(trace_flags & TRACE_ITER_STACKTRACE))
947 return;
948
949 __ftrace_trace_stack(tr, flags, skip, pc);
950}
951
997void __trace_stack(struct trace_array *tr, 952void __trace_stack(struct trace_array *tr,
998 struct trace_array_cpu *data,
999 unsigned long flags, 953 unsigned long flags,
1000 int skip) 954 int skip, int pc)
1001{ 955{
1002 ftrace_trace_stack(tr, data, flags, skip, preempt_count()); 956 __ftrace_trace_stack(tr, flags, skip, pc);
1003} 957}
1004 958
1005static void ftrace_trace_userstack(struct trace_array *tr, 959static void ftrace_trace_userstack(struct trace_array *tr,
1006 struct trace_array_cpu *data, 960 unsigned long flags, int pc)
1007 unsigned long flags, int pc)
1008{ 961{
1009#ifdef CONFIG_STACKTRACE 962#ifdef CONFIG_STACKTRACE
1010 struct ring_buffer_event *event; 963 struct ring_buffer_event *event;
1011 struct userstack_entry *entry; 964 struct userstack_entry *entry;
1012 struct stack_trace trace; 965 struct stack_trace trace;
1013 unsigned long irq_flags;
1014 966
1015 if (!(trace_flags & TRACE_ITER_USERSTACKTRACE)) 967 if (!(trace_flags & TRACE_ITER_USERSTACKTRACE))
1016 return; 968 return;
1017 969
1018 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry), 970 event = trace_buffer_lock_reserve(tr, TRACE_USER_STACK,
1019 &irq_flags); 971 sizeof(*entry), flags, pc);
1020 if (!event) 972 if (!event)
1021 return; 973 return;
1022 entry = ring_buffer_event_data(event); 974 entry = ring_buffer_event_data(event);
1023 tracing_generic_entry_update(&entry->ent, flags, pc);
1024 entry->ent.type = TRACE_USER_STACK;
1025 975
1026 memset(&entry->caller, 0, sizeof(entry->caller)); 976 memset(&entry->caller, 0, sizeof(entry->caller));
1027 977
@@ -1031,70 +981,58 @@ static void ftrace_trace_userstack(struct trace_array *tr,
1031 trace.entries = entry->caller; 981 trace.entries = entry->caller;
1032 982
1033 save_stack_trace_user(&trace); 983 save_stack_trace_user(&trace);
1034 ring_buffer_unlock_commit(tr->buffer, event, irq_flags); 984 ring_buffer_unlock_commit(tr->buffer, event);
1035#endif 985#endif
1036} 986}
1037 987
1038void __trace_userstack(struct trace_array *tr, 988#ifdef UNUSED
1039 struct trace_array_cpu *data, 989static void __trace_userstack(struct trace_array *tr, unsigned long flags)
1040 unsigned long flags)
1041{ 990{
1042 ftrace_trace_userstack(tr, data, flags, preempt_count()); 991 ftrace_trace_userstack(tr, flags, preempt_count());
1043} 992}
993#endif /* UNUSED */
1044 994
1045static void 995static void
1046ftrace_trace_special(void *__tr, void *__data, 996ftrace_trace_special(void *__tr,
1047 unsigned long arg1, unsigned long arg2, unsigned long arg3, 997 unsigned long arg1, unsigned long arg2, unsigned long arg3,
1048 int pc) 998 int pc)
1049{ 999{
1050 struct ring_buffer_event *event; 1000 struct ring_buffer_event *event;
1051 struct trace_array_cpu *data = __data;
1052 struct trace_array *tr = __tr; 1001 struct trace_array *tr = __tr;
1053 struct special_entry *entry; 1002 struct special_entry *entry;
1054 unsigned long irq_flags;
1055 1003
1056 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry), 1004 event = trace_buffer_lock_reserve(tr, TRACE_SPECIAL,
1057 &irq_flags); 1005 sizeof(*entry), 0, pc);
1058 if (!event) 1006 if (!event)
1059 return; 1007 return;
1060 entry = ring_buffer_event_data(event); 1008 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; 1009 entry->arg1 = arg1;
1064 entry->arg2 = arg2; 1010 entry->arg2 = arg2;
1065 entry->arg3 = arg3; 1011 entry->arg3 = arg3;
1066 ring_buffer_unlock_commit(tr->buffer, event, irq_flags); 1012 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} 1013}
1072 1014
1073void 1015void
1074__trace_special(void *__tr, void *__data, 1016__trace_special(void *__tr, void *__data,
1075 unsigned long arg1, unsigned long arg2, unsigned long arg3) 1017 unsigned long arg1, unsigned long arg2, unsigned long arg3)
1076{ 1018{
1077 ftrace_trace_special(__tr, __data, arg1, arg2, arg3, preempt_count()); 1019 ftrace_trace_special(__tr, arg1, arg2, arg3, preempt_count());
1078} 1020}
1079 1021
1080void 1022void
1081tracing_sched_switch_trace(struct trace_array *tr, 1023tracing_sched_switch_trace(struct trace_array *tr,
1082 struct trace_array_cpu *data,
1083 struct task_struct *prev, 1024 struct task_struct *prev,
1084 struct task_struct *next, 1025 struct task_struct *next,
1085 unsigned long flags, int pc) 1026 unsigned long flags, int pc)
1086{ 1027{
1087 struct ring_buffer_event *event; 1028 struct ring_buffer_event *event;
1088 struct ctx_switch_entry *entry; 1029 struct ctx_switch_entry *entry;
1089 unsigned long irq_flags;
1090 1030
1091 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry), 1031 event = trace_buffer_lock_reserve(tr, TRACE_CTX,
1092 &irq_flags); 1032 sizeof(*entry), flags, pc);
1093 if (!event) 1033 if (!event)
1094 return; 1034 return;
1095 entry = ring_buffer_event_data(event); 1035 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; 1036 entry->prev_pid = prev->pid;
1099 entry->prev_prio = prev->prio; 1037 entry->prev_prio = prev->prio;
1100 entry->prev_state = prev->state; 1038 entry->prev_state = prev->state;
@@ -1102,29 +1040,23 @@ tracing_sched_switch_trace(struct trace_array *tr,
1102 entry->next_prio = next->prio; 1040 entry->next_prio = next->prio;
1103 entry->next_state = next->state; 1041 entry->next_state = next->state;
1104 entry->next_cpu = task_cpu(next); 1042 entry->next_cpu = task_cpu(next);
1105 ring_buffer_unlock_commit(tr->buffer, event, irq_flags); 1043 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} 1044}
1109 1045
1110void 1046void
1111tracing_sched_wakeup_trace(struct trace_array *tr, 1047tracing_sched_wakeup_trace(struct trace_array *tr,
1112 struct trace_array_cpu *data,
1113 struct task_struct *wakee, 1048 struct task_struct *wakee,
1114 struct task_struct *curr, 1049 struct task_struct *curr,
1115 unsigned long flags, int pc) 1050 unsigned long flags, int pc)
1116{ 1051{
1117 struct ring_buffer_event *event; 1052 struct ring_buffer_event *event;
1118 struct ctx_switch_entry *entry; 1053 struct ctx_switch_entry *entry;
1119 unsigned long irq_flags;
1120 1054
1121 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry), 1055 event = trace_buffer_lock_reserve(tr, TRACE_WAKE,
1122 &irq_flags); 1056 sizeof(*entry), flags, pc);
1123 if (!event) 1057 if (!event)
1124 return; 1058 return;
1125 entry = ring_buffer_event_data(event); 1059 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; 1060 entry->prev_pid = curr->pid;
1129 entry->prev_prio = curr->prio; 1061 entry->prev_prio = curr->prio;
1130 entry->prev_state = curr->state; 1062 entry->prev_state = curr->state;
@@ -1132,11 +1064,7 @@ tracing_sched_wakeup_trace(struct trace_array *tr,
1132 entry->next_prio = wakee->prio; 1064 entry->next_prio = wakee->prio;
1133 entry->next_state = wakee->state; 1065 entry->next_state = wakee->state;
1134 entry->next_cpu = task_cpu(wakee); 1066 entry->next_cpu = task_cpu(wakee);
1135 ring_buffer_unlock_commit(tr->buffer, event, irq_flags); 1067 trace_buffer_unlock_commit(tr, event, flags, pc);
1136 ftrace_trace_stack(tr, data, flags, 6, pc);
1137 ftrace_trace_userstack(tr, data, flags, pc);
1138
1139 trace_wake_up();
1140} 1068}
1141 1069
1142void 1070void
@@ -1157,66 +1085,7 @@ ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3)
1157 data = tr->data[cpu]; 1085 data = tr->data[cpu];
1158 1086
1159 if (likely(atomic_inc_return(&data->disabled) == 1)) 1087 if (likely(atomic_inc_return(&data->disabled) == 1))
1160 ftrace_trace_special(tr, data, arg1, arg2, arg3, pc); 1088 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 1089
1221 atomic_dec(&data->disabled); 1090 atomic_dec(&data->disabled);
1222 local_irq_restore(flags); 1091 local_irq_restore(flags);
@@ -1244,7 +1113,7 @@ int trace_graph_entry(struct ftrace_graph_ent *trace)
1244 disabled = atomic_inc_return(&data->disabled); 1113 disabled = atomic_inc_return(&data->disabled);
1245 if (likely(disabled == 1)) { 1114 if (likely(disabled == 1)) {
1246 pc = preempt_count(); 1115 pc = preempt_count();
1247 __trace_graph_entry(tr, data, trace, flags, pc); 1116 __trace_graph_entry(tr, trace, flags, pc);
1248 } 1117 }
1249 /* Only do the atomic if it is not already set */ 1118 /* Only do the atomic if it is not already set */
1250 if (!test_tsk_trace_graph(current)) 1119 if (!test_tsk_trace_graph(current))
@@ -1270,7 +1139,7 @@ void trace_graph_return(struct ftrace_graph_ret *trace)
1270 disabled = atomic_inc_return(&data->disabled); 1139 disabled = atomic_inc_return(&data->disabled);
1271 if (likely(disabled == 1)) { 1140 if (likely(disabled == 1)) {
1272 pc = preempt_count(); 1141 pc = preempt_count();
1273 __trace_graph_return(tr, data, trace, flags, pc); 1142 __trace_graph_return(tr, trace, flags, pc);
1274 } 1143 }
1275 if (!trace->depth) 1144 if (!trace->depth)
1276 clear_tsk_trace_graph(current); 1145 clear_tsk_trace_graph(current);
@@ -1279,31 +1148,6 @@ void trace_graph_return(struct ftrace_graph_ret *trace)
1279} 1148}
1280#endif /* CONFIG_FUNCTION_GRAPH_TRACER */ 1149#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
1281 1150
1282static struct ftrace_ops trace_ops __read_mostly =
1283{
1284 .func = function_trace_call,
1285};
1286
1287void tracing_start_function_trace(void)
1288{
1289 ftrace_function_enabled = 0;
1290
1291 if (trace_flags & TRACE_ITER_PREEMPTONLY)
1292 trace_ops.func = function_trace_call_preempt_only;
1293 else
1294 trace_ops.func = function_trace_call;
1295
1296 register_ftrace_function(&trace_ops);
1297 ftrace_function_enabled = 1;
1298}
1299
1300void tracing_stop_function_trace(void)
1301{
1302 ftrace_function_enabled = 0;
1303 unregister_ftrace_function(&trace_ops);
1304}
1305#endif
1306
1307enum trace_file_type { 1151enum trace_file_type {
1308 TRACE_FILE_LAT_FMT = 1, 1152 TRACE_FILE_LAT_FMT = 1,
1309 TRACE_FILE_ANNOTATE = 2, 1153 TRACE_FILE_ANNOTATE = 2,
@@ -1376,8 +1220,8 @@ __find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts)
1376} 1220}
1377 1221
1378/* Find the next real entry, without updating the iterator itself */ 1222/* Find the next real entry, without updating the iterator itself */
1379static struct trace_entry * 1223struct trace_entry *trace_find_next_entry(struct trace_iterator *iter,
1380find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts) 1224 int *ent_cpu, u64 *ent_ts)
1381{ 1225{
1382 return __find_next_entry(iter, ent_cpu, ent_ts); 1226 return __find_next_entry(iter, ent_cpu, ent_ts);
1383} 1227}
@@ -1472,154 +1316,6 @@ static void s_stop(struct seq_file *m, void *p)
1472 mutex_unlock(&trace_types_lock); 1316 mutex_unlock(&trace_types_lock);
1473} 1317}
1474 1318
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}
1622
1623static void print_lat_help_header(struct seq_file *m) 1319static void print_lat_help_header(struct seq_file *m)
1624{ 1320{
1625 seq_puts(m, "# _------=> CPU# \n"); 1321 seq_puts(m, "# _------=> CPU# \n");
@@ -1704,103 +1400,6 @@ print_trace_header(struct seq_file *m, struct trace_iterator *iter)
1704 seq_puts(m, "\n"); 1400 seq_puts(m, "\n");
1705} 1401}
1706 1402
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 }
1736
1737 if (entry->preempt_count)
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}
1803
1804static void test_cpu_buff_start(struct trace_iterator *iter) 1403static void test_cpu_buff_start(struct trace_iterator *iter)
1805{ 1404{
1806 struct trace_seq *s = &iter->seq; 1405 struct trace_seq *s = &iter->seq;
@@ -1818,138 +1417,31 @@ static void test_cpu_buff_start(struct trace_iterator *iter)
1818 trace_seq_printf(s, "##### CPU %u buffer started ####\n", iter->cpu); 1417 trace_seq_printf(s, "##### CPU %u buffer started ####\n", iter->cpu);
1819} 1418}
1820 1419
1821static enum print_line_t 1420static enum print_line_t print_lat_fmt(struct trace_iterator *iter)
1822print_lat_fmt(struct trace_iterator *iter, unsigned int trace_idx, int cpu)
1823{ 1421{
1824 struct trace_seq *s = &iter->seq; 1422 struct trace_seq *s = &iter->seq;
1825 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); 1423 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
1826 struct trace_entry *next_entry; 1424 struct trace_event *event;
1827 unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
1828 struct trace_entry *entry = iter->ent; 1425 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 1426
1839 test_cpu_buff_start(iter); 1427 test_cpu_buff_start(iter);
1840 1428
1841 next_entry = find_next_entry(iter, NULL, &next_ts); 1429 event = ftrace_find_event(entry->type);
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 1430
1922 seq_print_ip_sym(s, field->ip, sym_flags); 1431 if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
1923 trace_seq_printf(s, ": %s", field->buf); 1432 if (!trace_print_lat_context(iter))
1924 if (entry->flags & TRACE_FLAG_CONT) 1433 goto partial;
1925 trace_seq_print_cont(s, iter);
1926 break;
1927 } 1434 }
1928 case TRACE_BRANCH: {
1929 struct trace_branch *field;
1930 1435
1931 trace_assign_type(field, entry); 1436 if (event)
1437 return event->latency_trace(iter, sym_flags);
1932 1438
1933 trace_seq_printf(s, "[%s] %s:%s:%d\n", 1439 if (!trace_seq_printf(s, "Unknown type %d\n", entry->type))
1934 field->correct ? " ok " : " MISS ", 1440 goto partial;
1935 field->func,
1936 field->file,
1937 field->line);
1938 break;
1939 }
1940 case TRACE_USER_STACK: {
1941 struct userstack_entry *field;
1942 1441
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; 1442 return TRACE_TYPE_HANDLED;
1443partial:
1444 return TRACE_TYPE_PARTIAL_LINE;
1953} 1445}
1954 1446
1955static enum print_line_t print_trace_fmt(struct trace_iterator *iter) 1447static enum print_line_t print_trace_fmt(struct trace_iterator *iter)
@@ -1957,313 +1449,78 @@ static enum print_line_t print_trace_fmt(struct trace_iterator *iter)
1957 struct trace_seq *s = &iter->seq; 1449 struct trace_seq *s = &iter->seq;
1958 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); 1450 unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
1959 struct trace_entry *entry; 1451 struct trace_entry *entry;
1960 unsigned long usec_rem; 1452 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 1453
1968 entry = iter->ent; 1454 entry = iter->ent;
1969 1455
1970 if (entry->type == TRACE_CONT)
1971 return TRACE_TYPE_HANDLED;
1972
1973 test_cpu_buff_start(iter); 1456 test_cpu_buff_start(iter);
1974 1457
1975 comm = trace_find_cmdline(iter->ent->pid); 1458 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
2053 trace_assign_type(field, entry);
2054
2055 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
2056 if (i) {
2057 ret = trace_seq_puts(s, " <= ");
2058 if (!ret)
2059 return TRACE_TYPE_PARTIAL_LINE;
2060 }
2061 ret = seq_print_ip_sym(s, field->caller[i],
2062 sym_flags);
2063 if (!ret)
2064 return TRACE_TYPE_PARTIAL_LINE;
2065 }
2066 ret = trace_seq_puts(s, "\n");
2067 if (!ret)
2068 return TRACE_TYPE_PARTIAL_LINE;
2069 break;
2070 }
2071 case TRACE_PRINT: {
2072 struct print_entry *field;
2073
2074 trace_assign_type(field, entry);
2075 1459
2076 seq_print_ip_sym(s, field->ip, sym_flags); 1460 if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
2077 trace_seq_printf(s, ": %s", field->buf); 1461 if (!trace_print_context(iter))
2078 if (entry->flags & TRACE_FLAG_CONT) 1462 goto partial;
2079 trace_seq_print_cont(s, iter);
2080 break;
2081 }
2082 case TRACE_GRAPH_RET: {
2083 return print_graph_function(iter);
2084 } 1463 }
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 1464
2093 trace_seq_printf(s, "[%s] %s:%s:%d\n", 1465 if (event)
2094 field->correct ? " ok " : " MISS ", 1466 return event->trace(iter, sym_flags);
2095 field->func,
2096 field->file,
2097 field->line);
2098 break;
2099 }
2100 case TRACE_USER_STACK: {
2101 struct userstack_entry *field;
2102 1467
2103 trace_assign_type(field, entry); 1468 if (!trace_seq_printf(s, "Unknown type %d\n", entry->type))
1469 goto partial;
2104 1470
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; 1471 return TRACE_TYPE_HANDLED;
1472partial:
1473 return TRACE_TYPE_PARTIAL_LINE;
2115} 1474}
2116 1475
2117static enum print_line_t print_raw_fmt(struct trace_iterator *iter) 1476static enum print_line_t print_raw_fmt(struct trace_iterator *iter)
2118{ 1477{
2119 struct trace_seq *s = &iter->seq; 1478 struct trace_seq *s = &iter->seq;
2120 struct trace_entry *entry; 1479 struct trace_entry *entry;
2121 int ret; 1480 struct trace_event *event;
2122 int S, T;
2123 1481
2124 entry = iter->ent; 1482 entry = iter->ent;
2125 1483
2126 if (entry->type == TRACE_CONT) 1484 if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
2127 return TRACE_TYPE_HANDLED; 1485 if (!trace_seq_printf(s, "%d %d %llu ",
2128 1486 entry->pid, iter->cpu, iter->ts))
2129 ret = trace_seq_printf(s, "%d %d %llu ", 1487 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 }
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 } 1488 }
2168 case TRACE_SPECIAL:
2169 case TRACE_USER_STACK:
2170 case TRACE_STACK: {
2171 struct special_entry *field;
2172 1489
2173 trace_assign_type(field, entry); 1490 event = ftrace_find_event(entry->type);
1491 if (event)
1492 return event->raw(iter, 0);
2174 1493
2175 ret = trace_seq_printf(s, "# %ld %ld %ld\n", 1494 if (!trace_seq_printf(s, "%d ?\n", entry->type))
2176 field->arg1, 1495 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 1496
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; 1497 return TRACE_TYPE_HANDLED;
1498partial:
1499 return TRACE_TYPE_PARTIAL_LINE;
2195} 1500}
2196 1501
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) 1502static enum print_line_t print_hex_fmt(struct trace_iterator *iter)
2211{ 1503{
2212 struct trace_seq *s = &iter->seq; 1504 struct trace_seq *s = &iter->seq;
2213 unsigned char newline = '\n'; 1505 unsigned char newline = '\n';
2214 struct trace_entry *entry; 1506 struct trace_entry *entry;
2215 int S, T; 1507 struct trace_event *event;
2216 1508
2217 entry = iter->ent; 1509 entry = iter->ent;
2218 1510
2219 if (entry->type == TRACE_CONT) 1511 if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
2220 return TRACE_TYPE_HANDLED; 1512 SEQ_PUT_HEX_FIELD_RET(s, entry->pid);
2221 1513 SEQ_PUT_HEX_FIELD_RET(s, iter->cpu);
2222 SEQ_PUT_HEX_FIELD_RET(s, entry->pid); 1514 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 } 1515 }
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 }
2254 case TRACE_SPECIAL:
2255 case TRACE_USER_STACK:
2256 case TRACE_STACK: {
2257 struct special_entry *field;
2258
2259 trace_assign_type(field, entry);
2260 1516
2261 SEQ_PUT_HEX_FIELD_RET(s, field->arg1); 1517 event = ftrace_find_event(entry->type);
2262 SEQ_PUT_HEX_FIELD_RET(s, field->arg2); 1518 if (event) {
2263 SEQ_PUT_HEX_FIELD_RET(s, field->arg3); 1519 enum print_line_t ret = event->hex(iter, 0);
2264 break; 1520 if (ret != TRACE_TYPE_HANDLED)
2265 } 1521 return ret;
2266 } 1522 }
1523
2267 SEQ_PUT_FIELD_RET(s, newline); 1524 SEQ_PUT_FIELD_RET(s, newline);
2268 1525
2269 return TRACE_TYPE_HANDLED; 1526 return TRACE_TYPE_HANDLED;
@@ -2278,13 +1535,10 @@ static enum print_line_t print_printk_msg_only(struct trace_iterator *iter)
2278 1535
2279 trace_assign_type(field, entry); 1536 trace_assign_type(field, entry);
2280 1537
2281 ret = trace_seq_printf(s, field->buf); 1538 ret = trace_seq_printf(s, "%s", field->buf);
2282 if (!ret) 1539 if (!ret)
2283 return TRACE_TYPE_PARTIAL_LINE; 1540 return TRACE_TYPE_PARTIAL_LINE;
2284 1541
2285 if (entry->flags & TRACE_FLAG_CONT)
2286 trace_seq_print_cont(s, iter);
2287
2288 return TRACE_TYPE_HANDLED; 1542 return TRACE_TYPE_HANDLED;
2289} 1543}
2290 1544
@@ -2292,53 +1546,18 @@ static enum print_line_t print_bin_fmt(struct trace_iterator *iter)
2292{ 1546{
2293 struct trace_seq *s = &iter->seq; 1547 struct trace_seq *s = &iter->seq;
2294 struct trace_entry *entry; 1548 struct trace_entry *entry;
1549 struct trace_event *event;
2295 1550
2296 entry = iter->ent; 1551 entry = iter->ent;
2297 1552
2298 if (entry->type == TRACE_CONT) 1553 if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
2299 return TRACE_TYPE_HANDLED; 1554 SEQ_PUT_FIELD_RET(s, entry->pid);
2300 1555 SEQ_PUT_FIELD_RET(s, iter->cpu);
2301 SEQ_PUT_FIELD_RET(s, entry->pid); 1556 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 } 1557 }
2315 case TRACE_CTX: {
2316 struct ctx_switch_entry *field;
2317
2318 trace_assign_type(field, entry);
2319
2320 SEQ_PUT_FIELD_RET(s, field->prev_pid);
2321 SEQ_PUT_FIELD_RET(s, field->prev_prio);
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 1558
2335 SEQ_PUT_FIELD_RET(s, field->arg1); 1559 event = ftrace_find_event(entry->type);
2336 SEQ_PUT_FIELD_RET(s, field->arg2); 1560 return event ? event->binary(iter, 0) : TRACE_TYPE_HANDLED;
2337 SEQ_PUT_FIELD_RET(s, field->arg3);
2338 break;
2339 }
2340 }
2341 return 1;
2342} 1561}
2343 1562
2344static int trace_empty(struct trace_iterator *iter) 1563static int trace_empty(struct trace_iterator *iter)
@@ -2383,7 +1602,7 @@ static enum print_line_t print_trace_line(struct trace_iterator *iter)
2383 return print_raw_fmt(iter); 1602 return print_raw_fmt(iter);
2384 1603
2385 if (iter->iter_flags & TRACE_FILE_LAT_FMT) 1604 if (iter->iter_flags & TRACE_FILE_LAT_FMT)
2386 return print_lat_fmt(iter, iter->idx, iter->cpu); 1605 return print_lat_fmt(iter);
2387 1606
2388 return print_trace_fmt(iter); 1607 return print_trace_fmt(iter);
2389} 1608}
@@ -2505,7 +1724,7 @@ int tracing_open_generic(struct inode *inode, struct file *filp)
2505 return 0; 1724 return 0;
2506} 1725}
2507 1726
2508int tracing_release(struct inode *inode, struct file *file) 1727static int tracing_release(struct inode *inode, struct file *file)
2509{ 1728{
2510 struct seq_file *m = (struct seq_file *)file->private_data; 1729 struct seq_file *m = (struct seq_file *)file->private_data;
2511 struct trace_iterator *iter = m->private; 1730 struct trace_iterator *iter = m->private;
@@ -2748,7 +1967,7 @@ tracing_trace_options_read(struct file *filp, char __user *ubuf,
2748 struct tracer_opt *trace_opts = current_trace->flags->opts; 1967 struct tracer_opt *trace_opts = current_trace->flags->opts;
2749 1968
2750 1969
2751 /* calulate max size */ 1970 /* calculate max size */
2752 for (i = 0; trace_options[i]; i++) { 1971 for (i = 0; trace_options[i]; i++) {
2753 len += strlen(trace_options[i]); 1972 len += strlen(trace_options[i]);
2754 len += 3; /* "no" and space */ 1973 len += 3; /* "no" and space */
@@ -2930,7 +2149,7 @@ tracing_ctrl_write(struct file *filp, const char __user *ubuf,
2930{ 2149{
2931 struct trace_array *tr = filp->private_data; 2150 struct trace_array *tr = filp->private_data;
2932 char buf[64]; 2151 char buf[64];
2933 long val; 2152 unsigned long val;
2934 int ret; 2153 int ret;
2935 2154
2936 if (cnt >= sizeof(buf)) 2155 if (cnt >= sizeof(buf))
@@ -2985,7 +2204,13 @@ tracing_set_trace_read(struct file *filp, char __user *ubuf,
2985 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); 2204 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
2986} 2205}
2987 2206
2988static int tracing_set_tracer(char *buf) 2207int tracer_init(struct tracer *t, struct trace_array *tr)
2208{
2209 tracing_reset_online_cpus(tr);
2210 return t->init(tr);
2211}
2212
2213static int tracing_set_tracer(const char *buf)
2989{ 2214{
2990 struct trace_array *tr = &global_trace; 2215 struct trace_array *tr = &global_trace;
2991 struct tracer *t; 2216 struct tracer *t;
@@ -3009,7 +2234,7 @@ static int tracing_set_tracer(char *buf)
3009 2234
3010 current_trace = t; 2235 current_trace = t;
3011 if (t->init) { 2236 if (t->init) {
3012 ret = t->init(tr); 2237 ret = tracer_init(t, tr);
3013 if (ret) 2238 if (ret)
3014 goto out; 2239 goto out;
3015 } 2240 }
@@ -3072,9 +2297,9 @@ static ssize_t
3072tracing_max_lat_write(struct file *filp, const char __user *ubuf, 2297tracing_max_lat_write(struct file *filp, const char __user *ubuf,
3073 size_t cnt, loff_t *ppos) 2298 size_t cnt, loff_t *ppos)
3074{ 2299{
3075 long *ptr = filp->private_data; 2300 unsigned long *ptr = filp->private_data;
3076 char buf[64]; 2301 char buf[64];
3077 long val; 2302 unsigned long val;
3078 int ret; 2303 int ret;
3079 2304
3080 if (cnt >= sizeof(buf)) 2305 if (cnt >= sizeof(buf))
@@ -3167,37 +2392,15 @@ tracing_poll_pipe(struct file *filp, poll_table *poll_table)
3167 } 2392 }
3168} 2393}
3169 2394
3170/* 2395/* Must be called with trace_types_lock mutex held. */
3171 * Consumer reader. 2396static int tracing_wait_pipe(struct file *filp)
3172 */
3173static ssize_t
3174tracing_read_pipe(struct file *filp, char __user *ubuf,
3175 size_t cnt, loff_t *ppos)
3176{ 2397{
3177 struct trace_iterator *iter = filp->private_data; 2398 struct trace_iterator *iter = filp->private_data;
3178 ssize_t sret;
3179 2399
3180 /* return any leftover data */
3181 sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
3182 if (sret != -EBUSY)
3183 return sret;
3184
3185 trace_seq_reset(&iter->seq);
3186
3187 mutex_lock(&trace_types_lock);
3188 if (iter->trace->read) {
3189 sret = iter->trace->read(iter, filp, ubuf, cnt, ppos);
3190 if (sret)
3191 goto out;
3192 }
3193
3194waitagain:
3195 sret = 0;
3196 while (trace_empty(iter)) { 2400 while (trace_empty(iter)) {
3197 2401
3198 if ((filp->f_flags & O_NONBLOCK)) { 2402 if ((filp->f_flags & O_NONBLOCK)) {
3199 sret = -EAGAIN; 2403 return -EAGAIN;
3200 goto out;
3201 } 2404 }
3202 2405
3203 /* 2406 /*
@@ -3222,12 +2425,11 @@ waitagain:
3222 iter->tr->waiter = NULL; 2425 iter->tr->waiter = NULL;
3223 2426
3224 if (signal_pending(current)) { 2427 if (signal_pending(current)) {
3225 sret = -EINTR; 2428 return -EINTR;
3226 goto out;
3227 } 2429 }
3228 2430
3229 if (iter->trace != current_trace) 2431 if (iter->trace != current_trace)
3230 goto out; 2432 return 0;
3231 2433
3232 /* 2434 /*
3233 * We block until we read something and tracing is disabled. 2435 * We block until we read something and tracing is disabled.
@@ -3244,9 +2446,43 @@ waitagain:
3244 continue; 2446 continue;
3245 } 2447 }
3246 2448
2449 return 1;
2450}
2451
2452/*
2453 * Consumer reader.
2454 */
2455static ssize_t
2456tracing_read_pipe(struct file *filp, char __user *ubuf,
2457 size_t cnt, loff_t *ppos)
2458{
2459 struct trace_iterator *iter = filp->private_data;
2460 ssize_t sret;
2461
2462 /* return any leftover data */
2463 sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
2464 if (sret != -EBUSY)
2465 return sret;
2466
2467 trace_seq_reset(&iter->seq);
2468
2469 mutex_lock(&trace_types_lock);
2470 if (iter->trace->read) {
2471 sret = iter->trace->read(iter, filp, ubuf, cnt, ppos);
2472 if (sret)
2473 goto out;
2474 }
2475
2476waitagain:
2477 sret = tracing_wait_pipe(filp);
2478 if (sret <= 0)
2479 goto out;
2480
3247 /* stop when tracing is finished */ 2481 /* stop when tracing is finished */
3248 if (trace_empty(iter)) 2482 if (trace_empty(iter)) {
2483 sret = 0;
3249 goto out; 2484 goto out;
2485 }
3250 2486
3251 if (cnt >= PAGE_SIZE) 2487 if (cnt >= PAGE_SIZE)
3252 cnt = PAGE_SIZE - 1; 2488 cnt = PAGE_SIZE - 1;
@@ -3267,8 +2503,8 @@ waitagain:
3267 iter->seq.len = len; 2503 iter->seq.len = len;
3268 break; 2504 break;
3269 } 2505 }
3270 2506 if (ret != TRACE_TYPE_NO_CONSUME)
3271 trace_consume(iter); 2507 trace_consume(iter);
3272 2508
3273 if (iter->seq.len >= cnt) 2509 if (iter->seq.len >= cnt)
3274 break; 2510 break;
@@ -3292,6 +2528,135 @@ out:
3292 return sret; 2528 return sret;
3293} 2529}
3294 2530
2531static void tracing_pipe_buf_release(struct pipe_inode_info *pipe,
2532 struct pipe_buffer *buf)
2533{
2534 __free_page(buf->page);
2535}
2536
2537static void tracing_spd_release_pipe(struct splice_pipe_desc *spd,
2538 unsigned int idx)
2539{
2540 __free_page(spd->pages[idx]);
2541}
2542
2543static struct pipe_buf_operations tracing_pipe_buf_ops = {
2544 .can_merge = 0,
2545 .map = generic_pipe_buf_map,
2546 .unmap = generic_pipe_buf_unmap,
2547 .confirm = generic_pipe_buf_confirm,
2548 .release = tracing_pipe_buf_release,
2549 .steal = generic_pipe_buf_steal,
2550 .get = generic_pipe_buf_get,
2551};
2552
2553static size_t
2554tracing_fill_pipe_page(struct page *pages, size_t rem,
2555 struct trace_iterator *iter)
2556{
2557 size_t count;
2558 int ret;
2559
2560 /* Seq buffer is page-sized, exactly what we need. */
2561 for (;;) {
2562 count = iter->seq.len;
2563 ret = print_trace_line(iter);
2564 count = iter->seq.len - count;
2565 if (rem < count) {
2566 rem = 0;
2567 iter->seq.len -= count;
2568 break;
2569 }
2570 if (ret == TRACE_TYPE_PARTIAL_LINE) {
2571 iter->seq.len -= count;
2572 break;
2573 }
2574
2575 trace_consume(iter);
2576 rem -= count;
2577 if (!find_next_entry_inc(iter)) {
2578 rem = 0;
2579 iter->ent = NULL;
2580 break;
2581 }
2582 }
2583
2584 return rem;
2585}
2586
2587static ssize_t tracing_splice_read_pipe(struct file *filp,
2588 loff_t *ppos,
2589 struct pipe_inode_info *pipe,
2590 size_t len,
2591 unsigned int flags)
2592{
2593 struct page *pages[PIPE_BUFFERS];
2594 struct partial_page partial[PIPE_BUFFERS];
2595 struct trace_iterator *iter = filp->private_data;
2596 struct splice_pipe_desc spd = {
2597 .pages = pages,
2598 .partial = partial,
2599 .nr_pages = 0, /* This gets updated below. */
2600 .flags = flags,
2601 .ops = &tracing_pipe_buf_ops,
2602 .spd_release = tracing_spd_release_pipe,
2603 };
2604 ssize_t ret;
2605 size_t rem;
2606 unsigned int i;
2607
2608 mutex_lock(&trace_types_lock);
2609
2610 if (iter->trace->splice_read) {
2611 ret = iter->trace->splice_read(iter, filp,
2612 ppos, pipe, len, flags);
2613 if (ret)
2614 goto out_err;
2615 }
2616
2617 ret = tracing_wait_pipe(filp);
2618 if (ret <= 0)
2619 goto out_err;
2620
2621 if (!iter->ent && !find_next_entry_inc(iter)) {
2622 ret = -EFAULT;
2623 goto out_err;
2624 }
2625
2626 /* Fill as many pages as possible. */
2627 for (i = 0, rem = len; i < PIPE_BUFFERS && rem; i++) {
2628 pages[i] = alloc_page(GFP_KERNEL);
2629 if (!pages[i])
2630 break;
2631
2632 rem = tracing_fill_pipe_page(pages[i], rem, iter);
2633
2634 /* Copy the data into the page, so we can start over. */
2635 ret = trace_seq_to_buffer(&iter->seq,
2636 page_address(pages[i]),
2637 iter->seq.len);
2638 if (ret < 0) {
2639 __free_page(pages[i]);
2640 break;
2641 }
2642 partial[i].offset = 0;
2643 partial[i].len = iter->seq.len;
2644
2645 trace_seq_reset(&iter->seq);
2646 }
2647
2648 mutex_unlock(&trace_types_lock);
2649
2650 spd.nr_pages = i;
2651
2652 return splice_to_pipe(pipe, &spd);
2653
2654out_err:
2655 mutex_unlock(&trace_types_lock);
2656
2657 return ret;
2658}
2659
3295static ssize_t 2660static ssize_t
3296tracing_entries_read(struct file *filp, char __user *ubuf, 2661tracing_entries_read(struct file *filp, char __user *ubuf,
3297 size_t cnt, loff_t *ppos) 2662 size_t cnt, loff_t *ppos)
@@ -3455,6 +2820,7 @@ static struct file_operations tracing_pipe_fops = {
3455 .open = tracing_open_pipe, 2820 .open = tracing_open_pipe,
3456 .poll = tracing_poll_pipe, 2821 .poll = tracing_poll_pipe,
3457 .read = tracing_read_pipe, 2822 .read = tracing_read_pipe,
2823 .splice_read = tracing_splice_read_pipe,
3458 .release = tracing_release_pipe, 2824 .release = tracing_release_pipe,
3459}; 2825};
3460 2826
@@ -3653,18 +3019,16 @@ int trace_vprintk(unsigned long ip, int depth, const char *fmt, va_list args)
3653 trace_buf[len] = 0; 3019 trace_buf[len] = 0;
3654 3020
3655 size = sizeof(*entry) + len + 1; 3021 size = sizeof(*entry) + len + 1;
3656 event = ring_buffer_lock_reserve(tr->buffer, size, &irq_flags); 3022 event = trace_buffer_lock_reserve(tr, TRACE_PRINT, size, irq_flags, pc);
3657 if (!event) 3023 if (!event)
3658 goto out_unlock; 3024 goto out_unlock;
3659 entry = ring_buffer_event_data(event); 3025 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; 3026 entry->ip = ip;
3663 entry->depth = depth; 3027 entry->depth = depth;
3664 3028
3665 memcpy(&entry->buf, trace_buf, len); 3029 memcpy(&entry->buf, trace_buf, len);
3666 entry->buf[len] = 0; 3030 entry->buf[len] = 0;
3667 ring_buffer_unlock_commit(tr->buffer, event, irq_flags); 3031 ring_buffer_unlock_commit(tr->buffer, event);
3668 3032
3669 out_unlock: 3033 out_unlock:
3670 spin_unlock_irqrestore(&trace_buf_lock, irq_flags); 3034 spin_unlock_irqrestore(&trace_buf_lock, irq_flags);
@@ -3691,6 +3055,15 @@ int __ftrace_printk(unsigned long ip, const char *fmt, ...)
3691} 3055}
3692EXPORT_SYMBOL_GPL(__ftrace_printk); 3056EXPORT_SYMBOL_GPL(__ftrace_printk);
3693 3057
3058int __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap)
3059{
3060 if (!(trace_flags & TRACE_ITER_PRINTK))
3061 return 0;
3062
3063 return trace_vprintk(ip, task_curr_ret_stack(current), fmt, ap);
3064}
3065EXPORT_SYMBOL_GPL(__ftrace_vprintk);
3066
3694static int trace_panic_handler(struct notifier_block *this, 3067static int trace_panic_handler(struct notifier_block *this,
3695 unsigned long event, void *unused) 3068 unsigned long event, void *unused)
3696{ 3069{
@@ -3871,14 +3244,10 @@ __init static int tracer_alloc_buffers(void)
3871 trace_init_cmdlines(); 3244 trace_init_cmdlines();
3872 3245
3873 register_tracer(&nop_trace); 3246 register_tracer(&nop_trace);
3247 current_trace = &nop_trace;
3874#ifdef CONFIG_BOOT_TRACER 3248#ifdef CONFIG_BOOT_TRACER
3875 register_tracer(&boot_tracer); 3249 register_tracer(&boot_tracer);
3876 current_trace = &boot_tracer;
3877 current_trace->init(&global_trace);
3878#else
3879 current_trace = &nop_trace;
3880#endif 3250#endif
3881
3882 /* All seems OK, enable tracing */ 3251 /* All seems OK, enable tracing */
3883 tracing_disabled = 0; 3252 tracing_disabled = 0;
3884 3253
@@ -3895,5 +3264,26 @@ out_free_buffer_mask:
3895out: 3264out:
3896 return ret; 3265 return ret;
3897} 3266}
3267
3268__init static int clear_boot_tracer(void)
3269{
3270 /*
3271 * The default tracer at boot buffer is an init section.
3272 * This function is called in lateinit. If we did not
3273 * find the boot tracer, then clear it out, to prevent
3274 * later registration from accessing the buffer that is
3275 * about to be freed.
3276 */
3277 if (!default_bootup_tracer)
3278 return 0;
3279
3280 printk(KERN_INFO "ftrace bootup tracer '%s' not registered.\n",
3281 default_bootup_tracer);
3282 default_bootup_tracer = NULL;
3283
3284 return 0;
3285}
3286
3898early_initcall(tracer_alloc_buffers); 3287early_initcall(tracer_alloc_buffers);
3899fs_initcall(tracer_init_debugfs); 3288fs_initcall(tracer_init_debugfs);
3289late_initcall(clear_boot_tracer);