Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 1 | /* Include in trace.c */ |
| 2 | |
Steven Rostedt | 9cc26a2 | 2009-03-09 16:00:22 -0400 | [diff] [blame] | 3 | #include <linux/stringify.h> |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 4 | #include <linux/kthread.h> |
Ingo Molnar | c7aafc5 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 5 | #include <linux/delay.h> |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 6 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 7 | static inline int trace_valid_entry(struct trace_entry *entry) |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 8 | { |
| 9 | switch (entry->type) { |
| 10 | case TRACE_FN: |
| 11 | case TRACE_CTX: |
Ingo Molnar | 5742279 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 12 | case TRACE_WAKE: |
Steven Rostedt | 06fa75a | 2008-05-12 21:20:54 +0200 | [diff] [blame] | 13 | case TRACE_STACK: |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 14 | case TRACE_PRINT: |
Steven Rostedt | 06fa75a | 2008-05-12 21:20:54 +0200 | [diff] [blame] | 15 | case TRACE_SPECIAL: |
Steven Rostedt | 80e5ea4 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 16 | case TRACE_BRANCH: |
Frederic Weisbecker | 7447dce | 2009-02-07 21:33:57 +0100 | [diff] [blame] | 17 | case TRACE_GRAPH_ENT: |
| 18 | case TRACE_GRAPH_RET: |
Markus Metzger | 321bb5e | 2009-03-13 10:50:27 +0100 | [diff] [blame] | 19 | case TRACE_HW_BRANCHES: |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 20 | return 1; |
| 21 | } |
| 22 | return 0; |
| 23 | } |
| 24 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 25 | static int trace_test_buffer_cpu(struct trace_array *tr, int cpu) |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 26 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 27 | struct ring_buffer_event *event; |
| 28 | struct trace_entry *entry; |
Steven Rostedt | 4b3e3d2 | 2009-02-18 22:50:01 -0500 | [diff] [blame] | 29 | unsigned int loops = 0; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 30 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 31 | while ((event = ring_buffer_consume(tr->buffer, cpu, NULL))) { |
| 32 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 33 | |
Steven Rostedt | 4b3e3d2 | 2009-02-18 22:50:01 -0500 | [diff] [blame] | 34 | /* |
| 35 | * The ring buffer is a size of trace_buf_size, if |
| 36 | * we loop more than the size, there's something wrong |
| 37 | * with the ring buffer. |
| 38 | */ |
| 39 | if (loops++ > trace_buf_size) { |
| 40 | printk(KERN_CONT ".. bad ring buffer "); |
| 41 | goto failed; |
| 42 | } |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 43 | if (!trace_valid_entry(entry)) { |
Ingo Molnar | c7aafc5 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 44 | printk(KERN_CONT ".. invalid entry %d ", |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 45 | entry->type); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 46 | goto failed; |
| 47 | } |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 48 | } |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 49 | return 0; |
| 50 | |
| 51 | failed: |
Steven Rostedt | 08bafa0 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 52 | /* disable tracing */ |
| 53 | tracing_disabled = 1; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 54 | printk(KERN_CONT ".. corrupted trace buffer .. "); |
| 55 | return -1; |
| 56 | } |
| 57 | |
| 58 | /* |
| 59 | * Test the trace buffer to see if all the elements |
| 60 | * are still sane. |
| 61 | */ |
| 62 | static int trace_test_buffer(struct trace_array *tr, unsigned long *count) |
| 63 | { |
Steven Rostedt | 30afdcb | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 64 | unsigned long flags, cnt = 0; |
| 65 | int cpu, ret = 0; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 66 | |
Steven Rostedt | 30afdcb | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 67 | /* Don't allow flipping of max traces now */ |
Steven Rostedt | d51ad7a | 2008-11-15 15:48:29 -0500 | [diff] [blame] | 68 | local_irq_save(flags); |
Steven Rostedt | 30afdcb | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 69 | __raw_spin_lock(&ftrace_max_lock); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 70 | |
| 71 | cnt = ring_buffer_entries(tr->buffer); |
| 72 | |
Steven Rostedt | 0c5119c | 2009-02-18 18:33:57 -0500 | [diff] [blame] | 73 | /* |
| 74 | * The trace_test_buffer_cpu runs a while loop to consume all data. |
| 75 | * If the calling tracer is broken, and is constantly filling |
| 76 | * the buffer, this will run forever, and hard lock the box. |
| 77 | * We disable the ring buffer while we do this test to prevent |
| 78 | * a hard lock up. |
| 79 | */ |
| 80 | tracing_off(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 81 | for_each_possible_cpu(cpu) { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 82 | ret = trace_test_buffer_cpu(tr, cpu); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 83 | if (ret) |
| 84 | break; |
| 85 | } |
Steven Rostedt | 0c5119c | 2009-02-18 18:33:57 -0500 | [diff] [blame] | 86 | tracing_on(); |
Steven Rostedt | 30afdcb | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 87 | __raw_spin_unlock(&ftrace_max_lock); |
Steven Rostedt | d51ad7a | 2008-11-15 15:48:29 -0500 | [diff] [blame] | 88 | local_irq_restore(flags); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 89 | |
| 90 | if (count) |
| 91 | *count = cnt; |
| 92 | |
| 93 | return ret; |
| 94 | } |
| 95 | |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 96 | static inline void warn_failed_init_tracer(struct tracer *trace, int init_ret) |
| 97 | { |
| 98 | printk(KERN_WARNING "Failed to init %s tracer, init returned %d\n", |
| 99 | trace->name, init_ret); |
| 100 | } |
Steven Rostedt | 606576c | 2008-10-06 19:06:12 -0400 | [diff] [blame] | 101 | #ifdef CONFIG_FUNCTION_TRACER |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 102 | |
| 103 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 104 | |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 105 | /* Test dynamic code modification and ftrace filters */ |
| 106 | int trace_selftest_startup_dynamic_tracing(struct tracer *trace, |
| 107 | struct trace_array *tr, |
| 108 | int (*func)(void)) |
| 109 | { |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 110 | int save_ftrace_enabled = ftrace_enabled; |
| 111 | int save_tracer_enabled = tracer_enabled; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 112 | unsigned long count; |
Steven Rostedt | 4e491d1 | 2008-05-14 23:49:44 -0400 | [diff] [blame] | 113 | char *func_name; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 114 | int ret; |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 115 | |
| 116 | /* The ftrace test PASSED */ |
| 117 | printk(KERN_CONT "PASSED\n"); |
| 118 | pr_info("Testing dynamic ftrace: "); |
| 119 | |
| 120 | /* enable tracing, and record the filter function */ |
| 121 | ftrace_enabled = 1; |
| 122 | tracer_enabled = 1; |
| 123 | |
| 124 | /* passed in by parameter to fool gcc from optimizing */ |
| 125 | func(); |
| 126 | |
Steven Rostedt | 4e491d1 | 2008-05-14 23:49:44 -0400 | [diff] [blame] | 127 | /* |
Wenji Huang | 73d8b8b | 2009-02-17 01:10:02 -0500 | [diff] [blame] | 128 | * Some archs *cough*PowerPC*cough* add characters to the |
Steven Rostedt | 4e491d1 | 2008-05-14 23:49:44 -0400 | [diff] [blame] | 129 | * start of the function names. We simply put a '*' to |
Wenji Huang | 73d8b8b | 2009-02-17 01:10:02 -0500 | [diff] [blame] | 130 | * accommodate them. |
Steven Rostedt | 4e491d1 | 2008-05-14 23:49:44 -0400 | [diff] [blame] | 131 | */ |
Steven Rostedt | 9cc26a2 | 2009-03-09 16:00:22 -0400 | [diff] [blame] | 132 | func_name = "*" __stringify(DYN_FTRACE_TEST_NAME); |
Steven Rostedt | 4e491d1 | 2008-05-14 23:49:44 -0400 | [diff] [blame] | 133 | |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 134 | /* filter only on our function */ |
Steven Rostedt | 4e491d1 | 2008-05-14 23:49:44 -0400 | [diff] [blame] | 135 | ftrace_set_filter(func_name, strlen(func_name), 1); |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 136 | |
| 137 | /* enable tracing */ |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 138 | ret = tracer_init(trace, tr); |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 139 | if (ret) { |
| 140 | warn_failed_init_tracer(trace, ret); |
| 141 | goto out; |
| 142 | } |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 143 | |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 144 | /* Sleep for a 1/10 of a second */ |
| 145 | msleep(100); |
| 146 | |
| 147 | /* we should have nothing in the buffer */ |
| 148 | ret = trace_test_buffer(tr, &count); |
| 149 | if (ret) |
| 150 | goto out; |
| 151 | |
| 152 | if (count) { |
| 153 | ret = -1; |
| 154 | printk(KERN_CONT ".. filter did not filter .. "); |
| 155 | goto out; |
| 156 | } |
| 157 | |
| 158 | /* call our function again */ |
| 159 | func(); |
| 160 | |
| 161 | /* sleep again */ |
| 162 | msleep(100); |
| 163 | |
| 164 | /* stop the tracing. */ |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 165 | tracing_stop(); |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 166 | ftrace_enabled = 0; |
| 167 | |
| 168 | /* check the trace buffer */ |
| 169 | ret = trace_test_buffer(tr, &count); |
| 170 | trace->reset(tr); |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 171 | tracing_start(); |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 172 | |
| 173 | /* we should only have one item */ |
| 174 | if (!ret && count != 1) { |
Steven Rostedt | 06fa75a | 2008-05-12 21:20:54 +0200 | [diff] [blame] | 175 | printk(KERN_CONT ".. filter failed count=%ld ..", count); |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 176 | ret = -1; |
| 177 | goto out; |
| 178 | } |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 179 | |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 180 | out: |
| 181 | ftrace_enabled = save_ftrace_enabled; |
| 182 | tracer_enabled = save_tracer_enabled; |
| 183 | |
| 184 | /* Enable tracing on all functions again */ |
| 185 | ftrace_set_filter(NULL, 0, 1); |
| 186 | |
| 187 | return ret; |
| 188 | } |
| 189 | #else |
| 190 | # define trace_selftest_startup_dynamic_tracing(trace, tr, func) ({ 0; }) |
| 191 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
Ingo Molnar | e9a22d1 | 2009-03-13 11:54:40 +0100 | [diff] [blame^] | 192 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 193 | /* |
| 194 | * Simple verification test of ftrace function tracer. |
| 195 | * Enable ftrace, sleep 1/10 second, and then read the trace |
| 196 | * buffer to see if all is in order. |
| 197 | */ |
| 198 | int |
| 199 | trace_selftest_startup_function(struct tracer *trace, struct trace_array *tr) |
| 200 | { |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 201 | int save_ftrace_enabled = ftrace_enabled; |
| 202 | int save_tracer_enabled = tracer_enabled; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 203 | unsigned long count; |
| 204 | int ret; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 205 | |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 206 | /* make sure msleep has been recorded */ |
| 207 | msleep(1); |
| 208 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 209 | /* start the tracing */ |
Ingo Molnar | c7aafc5 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 210 | ftrace_enabled = 1; |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 211 | tracer_enabled = 1; |
Ingo Molnar | c7aafc5 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 212 | |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 213 | ret = tracer_init(trace, tr); |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 214 | if (ret) { |
| 215 | warn_failed_init_tracer(trace, ret); |
| 216 | goto out; |
| 217 | } |
| 218 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 219 | /* Sleep for a 1/10 of a second */ |
| 220 | msleep(100); |
| 221 | /* stop the tracing. */ |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 222 | tracing_stop(); |
Ingo Molnar | c7aafc5 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 223 | ftrace_enabled = 0; |
| 224 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 225 | /* check the trace buffer */ |
| 226 | ret = trace_test_buffer(tr, &count); |
| 227 | trace->reset(tr); |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 228 | tracing_start(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 229 | |
| 230 | if (!ret && !count) { |
| 231 | printk(KERN_CONT ".. no entries found .."); |
| 232 | ret = -1; |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 233 | goto out; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 234 | } |
| 235 | |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 236 | ret = trace_selftest_startup_dynamic_tracing(trace, tr, |
| 237 | DYN_FTRACE_TEST_NAME); |
| 238 | |
| 239 | out: |
| 240 | ftrace_enabled = save_ftrace_enabled; |
| 241 | tracer_enabled = save_tracer_enabled; |
| 242 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 243 | /* kill ftrace totally if we failed */ |
| 244 | if (ret) |
| 245 | ftrace_kill(); |
| 246 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 247 | return ret; |
| 248 | } |
Steven Rostedt | 606576c | 2008-10-06 19:06:12 -0400 | [diff] [blame] | 249 | #endif /* CONFIG_FUNCTION_TRACER */ |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 250 | |
Frederic Weisbecker | 7447dce | 2009-02-07 21:33:57 +0100 | [diff] [blame] | 251 | |
| 252 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 253 | /* |
| 254 | * Pretty much the same than for the function tracer from which the selftest |
| 255 | * has been borrowed. |
| 256 | */ |
| 257 | int |
| 258 | trace_selftest_startup_function_graph(struct tracer *trace, |
| 259 | struct trace_array *tr) |
| 260 | { |
| 261 | int ret; |
| 262 | unsigned long count; |
| 263 | |
| 264 | ret = tracer_init(trace, tr); |
| 265 | if (ret) { |
| 266 | warn_failed_init_tracer(trace, ret); |
| 267 | goto out; |
| 268 | } |
| 269 | |
| 270 | /* Sleep for a 1/10 of a second */ |
| 271 | msleep(100); |
| 272 | |
| 273 | tracing_stop(); |
| 274 | |
| 275 | /* check the trace buffer */ |
| 276 | ret = trace_test_buffer(tr, &count); |
| 277 | |
| 278 | trace->reset(tr); |
| 279 | tracing_start(); |
| 280 | |
| 281 | if (!ret && !count) { |
| 282 | printk(KERN_CONT ".. no entries found .."); |
| 283 | ret = -1; |
| 284 | goto out; |
| 285 | } |
| 286 | |
| 287 | /* Don't test dynamic tracing, the function tracer already did */ |
| 288 | |
| 289 | out: |
| 290 | /* Stop it if we failed */ |
| 291 | if (ret) |
| 292 | ftrace_graph_stop(); |
| 293 | |
| 294 | return ret; |
| 295 | } |
| 296 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ |
| 297 | |
| 298 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 299 | #ifdef CONFIG_IRQSOFF_TRACER |
| 300 | int |
| 301 | trace_selftest_startup_irqsoff(struct tracer *trace, struct trace_array *tr) |
| 302 | { |
| 303 | unsigned long save_max = tracing_max_latency; |
| 304 | unsigned long count; |
| 305 | int ret; |
| 306 | |
| 307 | /* start the tracing */ |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 308 | ret = tracer_init(trace, tr); |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 309 | if (ret) { |
| 310 | warn_failed_init_tracer(trace, ret); |
| 311 | return ret; |
| 312 | } |
| 313 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 314 | /* reset the max latency */ |
| 315 | tracing_max_latency = 0; |
| 316 | /* disable interrupts for a bit */ |
| 317 | local_irq_disable(); |
| 318 | udelay(100); |
| 319 | local_irq_enable(); |
| 320 | /* stop the tracing. */ |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 321 | tracing_stop(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 322 | /* check both trace buffers */ |
| 323 | ret = trace_test_buffer(tr, NULL); |
| 324 | if (!ret) |
| 325 | ret = trace_test_buffer(&max_tr, &count); |
| 326 | trace->reset(tr); |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 327 | tracing_start(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 328 | |
| 329 | if (!ret && !count) { |
| 330 | printk(KERN_CONT ".. no entries found .."); |
| 331 | ret = -1; |
| 332 | } |
| 333 | |
| 334 | tracing_max_latency = save_max; |
| 335 | |
| 336 | return ret; |
| 337 | } |
| 338 | #endif /* CONFIG_IRQSOFF_TRACER */ |
| 339 | |
| 340 | #ifdef CONFIG_PREEMPT_TRACER |
| 341 | int |
| 342 | trace_selftest_startup_preemptoff(struct tracer *trace, struct trace_array *tr) |
| 343 | { |
| 344 | unsigned long save_max = tracing_max_latency; |
| 345 | unsigned long count; |
| 346 | int ret; |
| 347 | |
Steven Rostedt | 769c48e | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 348 | /* |
| 349 | * Now that the big kernel lock is no longer preemptable, |
| 350 | * and this is called with the BKL held, it will always |
| 351 | * fail. If preemption is already disabled, simply |
| 352 | * pass the test. When the BKL is removed, or becomes |
| 353 | * preemptible again, we will once again test this, |
| 354 | * so keep it in. |
| 355 | */ |
| 356 | if (preempt_count()) { |
| 357 | printk(KERN_CONT "can not test ... force "); |
| 358 | return 0; |
| 359 | } |
| 360 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 361 | /* start the tracing */ |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 362 | ret = tracer_init(trace, tr); |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 363 | if (ret) { |
| 364 | warn_failed_init_tracer(trace, ret); |
| 365 | return ret; |
| 366 | } |
| 367 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 368 | /* reset the max latency */ |
| 369 | tracing_max_latency = 0; |
| 370 | /* disable preemption for a bit */ |
| 371 | preempt_disable(); |
| 372 | udelay(100); |
| 373 | preempt_enable(); |
| 374 | /* stop the tracing. */ |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 375 | tracing_stop(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 376 | /* check both trace buffers */ |
| 377 | ret = trace_test_buffer(tr, NULL); |
| 378 | if (!ret) |
| 379 | ret = trace_test_buffer(&max_tr, &count); |
| 380 | trace->reset(tr); |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 381 | tracing_start(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 382 | |
| 383 | if (!ret && !count) { |
| 384 | printk(KERN_CONT ".. no entries found .."); |
| 385 | ret = -1; |
| 386 | } |
| 387 | |
| 388 | tracing_max_latency = save_max; |
| 389 | |
| 390 | return ret; |
| 391 | } |
| 392 | #endif /* CONFIG_PREEMPT_TRACER */ |
| 393 | |
| 394 | #if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER) |
| 395 | int |
| 396 | trace_selftest_startup_preemptirqsoff(struct tracer *trace, struct trace_array *tr) |
| 397 | { |
| 398 | unsigned long save_max = tracing_max_latency; |
| 399 | unsigned long count; |
| 400 | int ret; |
| 401 | |
Steven Rostedt | 769c48e | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 402 | /* |
| 403 | * Now that the big kernel lock is no longer preemptable, |
| 404 | * and this is called with the BKL held, it will always |
| 405 | * fail. If preemption is already disabled, simply |
| 406 | * pass the test. When the BKL is removed, or becomes |
| 407 | * preemptible again, we will once again test this, |
| 408 | * so keep it in. |
| 409 | */ |
| 410 | if (preempt_count()) { |
| 411 | printk(KERN_CONT "can not test ... force "); |
| 412 | return 0; |
| 413 | } |
| 414 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 415 | /* start the tracing */ |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 416 | ret = tracer_init(trace, tr); |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 417 | if (ret) { |
| 418 | warn_failed_init_tracer(trace, ret); |
| 419 | goto out; |
| 420 | } |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 421 | |
| 422 | /* reset the max latency */ |
| 423 | tracing_max_latency = 0; |
| 424 | |
| 425 | /* disable preemption and interrupts for a bit */ |
| 426 | preempt_disable(); |
| 427 | local_irq_disable(); |
| 428 | udelay(100); |
| 429 | preempt_enable(); |
| 430 | /* reverse the order of preempt vs irqs */ |
| 431 | local_irq_enable(); |
| 432 | |
| 433 | /* stop the tracing. */ |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 434 | tracing_stop(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 435 | /* check both trace buffers */ |
| 436 | ret = trace_test_buffer(tr, NULL); |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 437 | if (ret) { |
| 438 | tracing_start(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 439 | goto out; |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 440 | } |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 441 | |
| 442 | ret = trace_test_buffer(&max_tr, &count); |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 443 | if (ret) { |
| 444 | tracing_start(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 445 | goto out; |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 446 | } |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 447 | |
| 448 | if (!ret && !count) { |
| 449 | printk(KERN_CONT ".. no entries found .."); |
| 450 | ret = -1; |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 451 | tracing_start(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 452 | goto out; |
| 453 | } |
| 454 | |
| 455 | /* do the test by disabling interrupts first this time */ |
| 456 | tracing_max_latency = 0; |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 457 | tracing_start(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 458 | preempt_disable(); |
| 459 | local_irq_disable(); |
| 460 | udelay(100); |
| 461 | preempt_enable(); |
| 462 | /* reverse the order of preempt vs irqs */ |
| 463 | local_irq_enable(); |
| 464 | |
| 465 | /* stop the tracing. */ |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 466 | tracing_stop(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 467 | /* check both trace buffers */ |
| 468 | ret = trace_test_buffer(tr, NULL); |
| 469 | if (ret) |
| 470 | goto out; |
| 471 | |
| 472 | ret = trace_test_buffer(&max_tr, &count); |
| 473 | |
| 474 | if (!ret && !count) { |
| 475 | printk(KERN_CONT ".. no entries found .."); |
| 476 | ret = -1; |
| 477 | goto out; |
| 478 | } |
| 479 | |
| 480 | out: |
| 481 | trace->reset(tr); |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 482 | tracing_start(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 483 | tracing_max_latency = save_max; |
| 484 | |
| 485 | return ret; |
| 486 | } |
| 487 | #endif /* CONFIG_IRQSOFF_TRACER && CONFIG_PREEMPT_TRACER */ |
| 488 | |
Steven Noonan | fb1b6d8 | 2008-09-19 03:06:43 -0700 | [diff] [blame] | 489 | #ifdef CONFIG_NOP_TRACER |
| 490 | int |
| 491 | trace_selftest_startup_nop(struct tracer *trace, struct trace_array *tr) |
| 492 | { |
| 493 | /* What could possibly go wrong? */ |
| 494 | return 0; |
| 495 | } |
| 496 | #endif |
| 497 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 498 | #ifdef CONFIG_SCHED_TRACER |
| 499 | static int trace_wakeup_test_thread(void *data) |
| 500 | { |
Steven Rostedt | 05bd68c | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 501 | /* Make this a RT thread, doesn't need to be too high */ |
| 502 | struct sched_param param = { .sched_priority = 5 }; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 503 | struct completion *x = data; |
| 504 | |
Steven Rostedt | 05bd68c | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 505 | sched_setscheduler(current, SCHED_FIFO, ¶m); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 506 | |
| 507 | /* Make it know we have a new prio */ |
| 508 | complete(x); |
| 509 | |
| 510 | /* now go to sleep and let the test wake us up */ |
| 511 | set_current_state(TASK_INTERRUPTIBLE); |
| 512 | schedule(); |
| 513 | |
| 514 | /* we are awake, now wait to disappear */ |
| 515 | while (!kthread_should_stop()) { |
| 516 | /* |
| 517 | * This is an RT task, do short sleeps to let |
| 518 | * others run. |
| 519 | */ |
| 520 | msleep(100); |
| 521 | } |
| 522 | |
| 523 | return 0; |
| 524 | } |
| 525 | |
| 526 | int |
| 527 | trace_selftest_startup_wakeup(struct tracer *trace, struct trace_array *tr) |
| 528 | { |
| 529 | unsigned long save_max = tracing_max_latency; |
| 530 | struct task_struct *p; |
| 531 | struct completion isrt; |
| 532 | unsigned long count; |
| 533 | int ret; |
| 534 | |
| 535 | init_completion(&isrt); |
| 536 | |
| 537 | /* create a high prio thread */ |
| 538 | p = kthread_run(trace_wakeup_test_thread, &isrt, "ftrace-test"); |
Ingo Molnar | c7aafc5 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 539 | if (IS_ERR(p)) { |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 540 | printk(KERN_CONT "Failed to create ftrace wakeup test thread "); |
| 541 | return -1; |
| 542 | } |
| 543 | |
| 544 | /* make sure the thread is running at an RT prio */ |
| 545 | wait_for_completion(&isrt); |
| 546 | |
| 547 | /* start the tracing */ |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 548 | ret = tracer_init(trace, tr); |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 549 | if (ret) { |
| 550 | warn_failed_init_tracer(trace, ret); |
| 551 | return ret; |
| 552 | } |
| 553 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 554 | /* reset the max latency */ |
| 555 | tracing_max_latency = 0; |
| 556 | |
| 557 | /* sleep to let the RT thread sleep too */ |
| 558 | msleep(100); |
| 559 | |
| 560 | /* |
| 561 | * Yes this is slightly racy. It is possible that for some |
| 562 | * strange reason that the RT thread we created, did not |
| 563 | * call schedule for 100ms after doing the completion, |
| 564 | * and we do a wakeup on a task that already is awake. |
| 565 | * But that is extremely unlikely, and the worst thing that |
| 566 | * happens in such a case, is that we disable tracing. |
| 567 | * Honestly, if this race does happen something is horrible |
| 568 | * wrong with the system. |
| 569 | */ |
| 570 | |
| 571 | wake_up_process(p); |
| 572 | |
Steven Rostedt | 5aa60c6 | 2008-09-29 23:02:37 -0400 | [diff] [blame] | 573 | /* give a little time to let the thread wake up */ |
| 574 | msleep(100); |
| 575 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 576 | /* stop the tracing. */ |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 577 | tracing_stop(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 578 | /* check both trace buffers */ |
| 579 | ret = trace_test_buffer(tr, NULL); |
| 580 | if (!ret) |
| 581 | ret = trace_test_buffer(&max_tr, &count); |
| 582 | |
| 583 | |
| 584 | trace->reset(tr); |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 585 | tracing_start(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 586 | |
| 587 | tracing_max_latency = save_max; |
| 588 | |
| 589 | /* kill the thread */ |
| 590 | kthread_stop(p); |
| 591 | |
| 592 | if (!ret && !count) { |
| 593 | printk(KERN_CONT ".. no entries found .."); |
| 594 | ret = -1; |
| 595 | } |
| 596 | |
| 597 | return ret; |
| 598 | } |
| 599 | #endif /* CONFIG_SCHED_TRACER */ |
| 600 | |
| 601 | #ifdef CONFIG_CONTEXT_SWITCH_TRACER |
| 602 | int |
| 603 | trace_selftest_startup_sched_switch(struct tracer *trace, struct trace_array *tr) |
| 604 | { |
| 605 | unsigned long count; |
| 606 | int ret; |
| 607 | |
| 608 | /* start the tracing */ |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 609 | ret = tracer_init(trace, tr); |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 610 | if (ret) { |
| 611 | warn_failed_init_tracer(trace, ret); |
| 612 | return ret; |
| 613 | } |
| 614 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 615 | /* Sleep for a 1/10 of a second */ |
| 616 | msleep(100); |
| 617 | /* stop the tracing. */ |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 618 | tracing_stop(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 619 | /* check the trace buffer */ |
| 620 | ret = trace_test_buffer(tr, &count); |
| 621 | trace->reset(tr); |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 622 | tracing_start(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 623 | |
| 624 | if (!ret && !count) { |
| 625 | printk(KERN_CONT ".. no entries found .."); |
| 626 | ret = -1; |
| 627 | } |
| 628 | |
| 629 | return ret; |
| 630 | } |
| 631 | #endif /* CONFIG_CONTEXT_SWITCH_TRACER */ |
Ingo Molnar | a6dd24f | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 632 | |
| 633 | #ifdef CONFIG_SYSPROF_TRACER |
| 634 | int |
| 635 | trace_selftest_startup_sysprof(struct tracer *trace, struct trace_array *tr) |
| 636 | { |
| 637 | unsigned long count; |
| 638 | int ret; |
| 639 | |
| 640 | /* start the tracing */ |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 641 | ret = tracer_init(trace, tr); |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 642 | if (ret) { |
| 643 | warn_failed_init_tracer(trace, ret); |
Wenji Huang | d2ef7c2 | 2009-02-17 01:09:47 -0500 | [diff] [blame] | 644 | return ret; |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 645 | } |
| 646 | |
Ingo Molnar | a6dd24f | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 647 | /* Sleep for a 1/10 of a second */ |
| 648 | msleep(100); |
| 649 | /* stop the tracing. */ |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 650 | tracing_stop(); |
Ingo Molnar | a6dd24f | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 651 | /* check the trace buffer */ |
| 652 | ret = trace_test_buffer(tr, &count); |
| 653 | trace->reset(tr); |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 654 | tracing_start(); |
Ingo Molnar | a6dd24f | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 655 | |
Wenji Huang | d2ef7c2 | 2009-02-17 01:09:47 -0500 | [diff] [blame] | 656 | if (!ret && !count) { |
| 657 | printk(KERN_CONT ".. no entries found .."); |
| 658 | ret = -1; |
| 659 | } |
| 660 | |
Ingo Molnar | a6dd24f | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 661 | return ret; |
| 662 | } |
| 663 | #endif /* CONFIG_SYSPROF_TRACER */ |
Steven Rostedt | 80e5ea4 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 664 | |
| 665 | #ifdef CONFIG_BRANCH_TRACER |
| 666 | int |
| 667 | trace_selftest_startup_branch(struct tracer *trace, struct trace_array *tr) |
| 668 | { |
| 669 | unsigned long count; |
| 670 | int ret; |
| 671 | |
| 672 | /* start the tracing */ |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 673 | ret = tracer_init(trace, tr); |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 674 | if (ret) { |
| 675 | warn_failed_init_tracer(trace, ret); |
| 676 | return ret; |
| 677 | } |
| 678 | |
Steven Rostedt | 80e5ea4 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 679 | /* Sleep for a 1/10 of a second */ |
| 680 | msleep(100); |
| 681 | /* stop the tracing. */ |
| 682 | tracing_stop(); |
| 683 | /* check the trace buffer */ |
| 684 | ret = trace_test_buffer(tr, &count); |
| 685 | trace->reset(tr); |
| 686 | tracing_start(); |
| 687 | |
Wenji Huang | d2ef7c2 | 2009-02-17 01:09:47 -0500 | [diff] [blame] | 688 | if (!ret && !count) { |
| 689 | printk(KERN_CONT ".. no entries found .."); |
| 690 | ret = -1; |
| 691 | } |
| 692 | |
Steven Rostedt | 80e5ea4 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 693 | return ret; |
| 694 | } |
| 695 | #endif /* CONFIG_BRANCH_TRACER */ |
Markus Metzger | 321bb5e | 2009-03-13 10:50:27 +0100 | [diff] [blame] | 696 | |
| 697 | #ifdef CONFIG_HW_BRANCH_TRACER |
| 698 | int |
| 699 | trace_selftest_startup_hw_branches(struct tracer *trace, |
| 700 | struct trace_array *tr) |
| 701 | { |
Markus Metzger | 321bb5e | 2009-03-13 10:50:27 +0100 | [diff] [blame] | 702 | struct trace_iterator iter; |
| 703 | struct tracer tracer; |
Ingo Molnar | e9a22d1 | 2009-03-13 11:54:40 +0100 | [diff] [blame^] | 704 | unsigned long count; |
| 705 | int ret; |
Markus Metzger | 321bb5e | 2009-03-13 10:50:27 +0100 | [diff] [blame] | 706 | |
| 707 | if (!trace->open) { |
| 708 | printk(KERN_CONT "missing open function..."); |
| 709 | return -1; |
| 710 | } |
| 711 | |
| 712 | ret = tracer_init(trace, tr); |
| 713 | if (ret) { |
| 714 | warn_failed_init_tracer(trace, ret); |
| 715 | return ret; |
| 716 | } |
| 717 | |
| 718 | /* |
| 719 | * The hw-branch tracer needs to collect the trace from the various |
| 720 | * cpu trace buffers - before tracing is stopped. |
| 721 | */ |
| 722 | memset(&iter, 0, sizeof(iter)); |
| 723 | memcpy(&tracer, trace, sizeof(tracer)); |
| 724 | |
| 725 | iter.trace = &tracer; |
| 726 | iter.tr = tr; |
| 727 | iter.pos = -1; |
| 728 | mutex_init(&iter.mutex); |
| 729 | |
| 730 | trace->open(&iter); |
| 731 | |
| 732 | mutex_destroy(&iter.mutex); |
| 733 | |
| 734 | tracing_stop(); |
| 735 | |
| 736 | ret = trace_test_buffer(tr, &count); |
| 737 | trace->reset(tr); |
| 738 | tracing_start(); |
| 739 | |
| 740 | if (!ret && !count) { |
| 741 | printk(KERN_CONT "no entries found.."); |
| 742 | ret = -1; |
| 743 | } |
| 744 | |
| 745 | return ret; |
| 746 | } |
| 747 | #endif /* CONFIG_HW_BRANCH_TRACER */ |