diff options
Diffstat (limited to 'kernel/trace/trace_functions.c')
| -rw-r--r-- | kernel/trace/trace_functions.c | 369 |
1 files changed, 353 insertions, 16 deletions
diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c index 9236d7e25a1..c9a0b7df44f 100644 --- a/kernel/trace/trace_functions.c +++ b/kernel/trace/trace_functions.c | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | * Copyright (C) 2004-2006 Ingo Molnar | 9 | * Copyright (C) 2004-2006 Ingo Molnar |
| 10 | * Copyright (C) 2004 William Lee Irwin III | 10 | * Copyright (C) 2004 William Lee Irwin III |
| 11 | */ | 11 | */ |
| 12 | #include <linux/ring_buffer.h> | ||
| 12 | #include <linux/debugfs.h> | 13 | #include <linux/debugfs.h> |
| 13 | #include <linux/uaccess.h> | 14 | #include <linux/uaccess.h> |
| 14 | #include <linux/ftrace.h> | 15 | #include <linux/ftrace.h> |
| @@ -16,52 +17,388 @@ | |||
| 16 | 17 | ||
| 17 | #include "trace.h" | 18 | #include "trace.h" |
| 18 | 19 | ||
| 19 | static void start_function_trace(struct trace_array *tr) | 20 | /* function tracing enabled */ |
| 21 | static int ftrace_function_enabled; | ||
| 22 | |||
| 23 | static struct trace_array *func_trace; | ||
| 24 | |||
| 25 | static void tracing_start_function_trace(void); | ||
| 26 | static void tracing_stop_function_trace(void); | ||
| 27 | |||
| 28 | static int function_trace_init(struct trace_array *tr) | ||
| 20 | { | 29 | { |
| 30 | func_trace = tr; | ||
| 21 | tr->cpu = get_cpu(); | 31 | tr->cpu = get_cpu(); |
| 22 | tracing_reset_online_cpus(tr); | ||
| 23 | put_cpu(); | 32 | put_cpu(); |
| 24 | 33 | ||
| 25 | tracing_start_cmdline_record(); | 34 | tracing_start_cmdline_record(); |
| 26 | tracing_start_function_trace(); | 35 | tracing_start_function_trace(); |
| 36 | return 0; | ||
| 27 | } | 37 | } |
| 28 | 38 | ||
| 29 | static void stop_function_trace(struct trace_array *tr) | 39 | static void function_trace_reset(struct trace_array *tr) |
| 30 | { | 40 | { |
| 31 | tracing_stop_function_trace(); | 41 | tracing_stop_function_trace(); |
| 32 | tracing_stop_cmdline_record(); | 42 | tracing_stop_cmdline_record(); |
| 33 | } | 43 | } |
| 34 | 44 | ||
| 35 | static int function_trace_init(struct trace_array *tr) | 45 | static void function_trace_start(struct trace_array *tr) |
| 36 | { | 46 | { |
| 37 | start_function_trace(tr); | 47 | tracing_reset_online_cpus(tr); |
| 38 | return 0; | ||
| 39 | } | 48 | } |
| 40 | 49 | ||
| 41 | static void function_trace_reset(struct trace_array *tr) | 50 | static void |
| 51 | function_trace_call_preempt_only(unsigned long ip, unsigned long parent_ip) | ||
| 52 | { | ||
| 53 | struct trace_array *tr = func_trace; | ||
| 54 | struct trace_array_cpu *data; | ||
| 55 | unsigned long flags; | ||
| 56 | long disabled; | ||
| 57 | int cpu, resched; | ||
| 58 | int pc; | ||
| 59 | |||
| 60 | if (unlikely(!ftrace_function_enabled)) | ||
| 61 | return; | ||
| 62 | |||
| 63 | pc = preempt_count(); | ||
| 64 | resched = ftrace_preempt_disable(); | ||
| 65 | local_save_flags(flags); | ||
| 66 | cpu = raw_smp_processor_id(); | ||
| 67 | data = tr->data[cpu]; | ||
| 68 | disabled = atomic_inc_return(&data->disabled); | ||
| 69 | |||
| 70 | if (likely(disabled == 1)) | ||
| 71 | trace_function(tr, ip, parent_ip, flags, pc); | ||
| 72 | |||
| 73 | atomic_dec(&data->disabled); | ||
| 74 | ftrace_preempt_enable(resched); | ||
| 75 | } | ||
| 76 | |||
| 77 | static void | ||
| 78 | function_trace_call(unsigned long ip, unsigned long parent_ip) | ||
| 42 | { | 79 | { |
| 43 | stop_function_trace(tr); | 80 | struct trace_array *tr = func_trace; |
| 81 | struct trace_array_cpu *data; | ||
| 82 | unsigned long flags; | ||
| 83 | long disabled; | ||
| 84 | int cpu; | ||
| 85 | int pc; | ||
| 86 | |||
| 87 | if (unlikely(!ftrace_function_enabled)) | ||
| 88 | return; | ||
| 89 | |||
| 90 | /* | ||
| 91 | * Need to use raw, since this must be called before the | ||
| 92 | * recursive protection is performed. | ||
| 93 | */ | ||
| 94 | local_irq_save(flags); | ||
| 95 | cpu = raw_smp_processor_id(); | ||
| 96 | data = tr->data[cpu]; | ||
| 97 | disabled = atomic_inc_return(&data->disabled); | ||
| 98 | |||
| 99 | if (likely(disabled == 1)) { | ||
| 100 | pc = preempt_count(); | ||
| 101 | trace_function(tr, ip, parent_ip, flags, pc); | ||
| 102 | } | ||
| 103 | |||
| 104 | atomic_dec(&data->disabled); | ||
| 105 | local_irq_restore(flags); | ||
| 44 | } | 106 | } |
| 45 | 107 | ||
| 46 | static void function_trace_start(struct trace_array *tr) | 108 | static void |
| 109 | function_stack_trace_call(unsigned long ip, unsigned long parent_ip) | ||
| 47 | { | 110 | { |
| 48 | tracing_reset_online_cpus(tr); | 111 | struct trace_array *tr = func_trace; |
| 112 | struct trace_array_cpu *data; | ||
| 113 | unsigned long flags; | ||
| 114 | long disabled; | ||
| 115 | int cpu; | ||
| 116 | int pc; | ||
| 117 | |||
| 118 | if (unlikely(!ftrace_function_enabled)) | ||
| 119 | return; | ||
| 120 | |||
| 121 | /* | ||
| 122 | * Need to use raw, since this must be called before the | ||
| 123 | * recursive protection is performed. | ||
| 124 | */ | ||
| 125 | local_irq_save(flags); | ||
| 126 | cpu = raw_smp_processor_id(); | ||
| 127 | data = tr->data[cpu]; | ||
| 128 | disabled = atomic_inc_return(&data->disabled); | ||
| 129 | |||
| 130 | if (likely(disabled == 1)) { | ||
| 131 | pc = preempt_count(); | ||
| 132 | trace_function(tr, ip, parent_ip, flags, pc); | ||
| 133 | /* | ||
| 134 | * skip over 5 funcs: | ||
| 135 | * __ftrace_trace_stack, | ||
| 136 | * __trace_stack, | ||
| 137 | * function_stack_trace_call | ||
| 138 | * ftrace_list_func | ||
| 139 | * ftrace_call | ||
| 140 | */ | ||
| 141 | __trace_stack(tr, flags, 5, pc); | ||
| 142 | } | ||
| 143 | |||
| 144 | atomic_dec(&data->disabled); | ||
| 145 | local_irq_restore(flags); | ||
| 146 | } | ||
| 147 | |||
| 148 | |||
| 149 | static struct ftrace_ops trace_ops __read_mostly = | ||
| 150 | { | ||
| 151 | .func = function_trace_call, | ||
| 152 | }; | ||
| 153 | |||
| 154 | static struct ftrace_ops trace_stack_ops __read_mostly = | ||
| 155 | { | ||
| 156 | .func = function_stack_trace_call, | ||
| 157 | }; | ||
| 158 | |||
| 159 | /* Our two options */ | ||
| 160 | enum { | ||
| 161 | TRACE_FUNC_OPT_STACK = 0x1, | ||
| 162 | }; | ||
| 163 | |||
| 164 | static struct tracer_opt func_opts[] = { | ||
| 165 | #ifdef CONFIG_STACKTRACE | ||
| 166 | { TRACER_OPT(func_stack_trace, TRACE_FUNC_OPT_STACK) }, | ||
| 167 | #endif | ||
| 168 | { } /* Always set a last empty entry */ | ||
| 169 | }; | ||
| 170 | |||
| 171 | static struct tracer_flags func_flags = { | ||
| 172 | .val = 0, /* By default: all flags disabled */ | ||
| 173 | .opts = func_opts | ||
| 174 | }; | ||
| 175 | |||
| 176 | static void tracing_start_function_trace(void) | ||
| 177 | { | ||
| 178 | ftrace_function_enabled = 0; | ||
| 179 | |||
| 180 | if (trace_flags & TRACE_ITER_PREEMPTONLY) | ||
| 181 | trace_ops.func = function_trace_call_preempt_only; | ||
| 182 | else | ||
| 183 | trace_ops.func = function_trace_call; | ||
| 184 | |||
| 185 | if (func_flags.val & TRACE_FUNC_OPT_STACK) | ||
| 186 | register_ftrace_function(&trace_stack_ops); | ||
| 187 | else | ||
| 188 | register_ftrace_function(&trace_ops); | ||
| 189 | |||
| 190 | ftrace_function_enabled = 1; | ||
| 191 | } | ||
| 192 | |||
| 193 | static void tracing_stop_function_trace(void) | ||
| 194 | { | ||
| 195 | ftrace_function_enabled = 0; | ||
| 196 | /* OK if they are not registere | ||
