Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 1 | /* Include in trace.c */ |
| 2 | |
| 3 | #include <linux/kthread.h> |
Ingo Molnar | c7aafc5 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 4 | #include <linux/delay.h> |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 5 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 6 | static inline int trace_valid_entry(struct trace_entry *entry) |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 7 | { |
| 8 | switch (entry->type) { |
| 9 | case TRACE_FN: |
| 10 | case TRACE_CTX: |
Ingo Molnar | 5742279 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 11 | case TRACE_WAKE: |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 12 | case TRACE_CONT: |
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 | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 16 | return 1; |
| 17 | } |
| 18 | return 0; |
| 19 | } |
| 20 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 21 | static int trace_test_buffer_cpu(struct trace_array *tr, int cpu) |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 22 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 23 | struct ring_buffer_event *event; |
| 24 | struct trace_entry *entry; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 25 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 26 | while ((event = ring_buffer_consume(tr->buffer, cpu, NULL))) { |
| 27 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 28 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 29 | if (!trace_valid_entry(entry)) { |
Ingo Molnar | c7aafc5 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 30 | printk(KERN_CONT ".. invalid entry %d ", |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 31 | entry->type); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 32 | goto failed; |
| 33 | } |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 34 | } |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 35 | return 0; |
| 36 | |
| 37 | failed: |
Steven Rostedt | 08bafa0 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 38 | /* disable tracing */ |
| 39 | tracing_disabled = 1; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 40 | printk(KERN_CONT ".. corrupted trace buffer .. "); |
| 41 | return -1; |
| 42 | } |
| 43 | |
| 44 | /* |
| 45 | * Test the trace buffer to see if all the elements |
| 46 | * are still sane. |
| 47 | */ |
| 48 | static int trace_test_buffer(struct trace_array *tr, unsigned long *count) |
| 49 | { |
Steven Rostedt | 30afdcb | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 50 | unsigned long flags, cnt = 0; |
| 51 | int cpu, ret = 0; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 52 | |
Steven Rostedt | 30afdcb | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 53 | /* Don't allow flipping of max traces now */ |
| 54 | raw_local_irq_save(flags); |
| 55 | __raw_spin_lock(&ftrace_max_lock); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 56 | |
| 57 | cnt = ring_buffer_entries(tr->buffer); |
| 58 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 59 | for_each_possible_cpu(cpu) { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 60 | ret = trace_test_buffer_cpu(tr, cpu); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 61 | if (ret) |
| 62 | break; |
| 63 | } |
Steven Rostedt | 30afdcb | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 64 | __raw_spin_unlock(&ftrace_max_lock); |
| 65 | raw_local_irq_restore(flags); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 66 | |
| 67 | if (count) |
| 68 | *count = cnt; |
| 69 | |
| 70 | return ret; |
| 71 | } |
| 72 | |
Steven Rostedt | 606576c | 2008-10-06 19:06:12 -0400 | [diff] [blame] | 73 | #ifdef CONFIG_FUNCTION_TRACER |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 74 | |
| 75 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 76 | |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 77 | #define __STR(x) #x |
| 78 | #define STR(x) __STR(x) |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 79 | |
| 80 | /* Test dynamic code modification and ftrace filters */ |
| 81 | int trace_selftest_startup_dynamic_tracing(struct tracer *trace, |
| 82 | struct trace_array *tr, |
| 83 | int (*func)(void)) |
| 84 | { |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 85 | int save_ftrace_enabled = ftrace_enabled; |
| 86 | int save_tracer_enabled = tracer_enabled; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 87 | unsigned long count; |
Steven Rostedt | 4e491d1 | 2008-05-14 23:49:44 -0400 | [diff] [blame] | 88 | char *func_name; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 89 | int ret; |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 90 | |
| 91 | /* The ftrace test PASSED */ |
| 92 | printk(KERN_CONT "PASSED\n"); |
| 93 | pr_info("Testing dynamic ftrace: "); |
| 94 | |
| 95 | /* enable tracing, and record the filter function */ |
| 96 | ftrace_enabled = 1; |
| 97 | tracer_enabled = 1; |
| 98 | |
| 99 | /* passed in by parameter to fool gcc from optimizing */ |
| 100 | func(); |
| 101 | |
Steven Rostedt | 4e491d1 | 2008-05-14 23:49:44 -0400 | [diff] [blame] | 102 | /* |
| 103 | * Some archs *cough*PowerPC*cough* add charachters to the |
| 104 | * start of the function names. We simply put a '*' to |
| 105 | * accomodate them. |
| 106 | */ |
| 107 | func_name = "*" STR(DYN_FTRACE_TEST_NAME); |
| 108 | |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 109 | /* filter only on our function */ |
Steven Rostedt | 4e491d1 | 2008-05-14 23:49:44 -0400 | [diff] [blame] | 110 | ftrace_set_filter(func_name, strlen(func_name), 1); |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 111 | |
| 112 | /* enable tracing */ |
| 113 | tr->ctrl = 1; |
| 114 | trace->init(tr); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 115 | |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 116 | /* Sleep for a 1/10 of a second */ |
| 117 | msleep(100); |
| 118 | |
| 119 | /* we should have nothing in the buffer */ |
| 120 | ret = trace_test_buffer(tr, &count); |
| 121 | if (ret) |
| 122 | goto out; |
| 123 | |
| 124 | if (count) { |
| 125 | ret = -1; |
| 126 | printk(KERN_CONT ".. filter did not filter .. "); |
| 127 | goto out; |
| 128 | } |
| 129 | |
| 130 | /* call our function again */ |
| 131 | func(); |
| 132 | |
| 133 | /* sleep again */ |
| 134 | msleep(100); |
| 135 | |
| 136 | /* stop the tracing. */ |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame^] | 137 | tracing_stop(); |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 138 | ftrace_enabled = 0; |
| 139 | |
| 140 | /* check the trace buffer */ |
| 141 | ret = trace_test_buffer(tr, &count); |
| 142 | trace->reset(tr); |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame^] | 143 | tracing_start(); |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 144 | |
| 145 | /* we should only have one item */ |
| 146 | if (!ret && count != 1) { |
Steven Rostedt | 06fa75a | 2008-05-12 21:20:54 +0200 | [diff] [blame] | 147 | printk(KERN_CONT ".. filter failed count=%ld ..", count); |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 148 | ret = -1; |
| 149 | goto out; |
| 150 | } |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame^] | 151 | |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 152 | out: |
| 153 | ftrace_enabled = save_ftrace_enabled; |
| 154 | tracer_enabled = save_tracer_enabled; |
| 155 | |
| 156 | /* Enable tracing on all functions again */ |
| 157 | ftrace_set_filter(NULL, 0, 1); |
| 158 | |
| 159 | return ret; |
| 160 | } |
| 161 | #else |
| 162 | # define trace_selftest_startup_dynamic_tracing(trace, tr, func) ({ 0; }) |
| 163 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 164 | /* |
| 165 | * Simple verification test of ftrace function tracer. |
| 166 | * Enable ftrace, sleep 1/10 second, and then read the trace |
| 167 | * buffer to see if all is in order. |
| 168 | */ |
| 169 | int |
| 170 | trace_selftest_startup_function(struct tracer *trace, struct trace_array *tr) |
| 171 | { |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 172 | int save_ftrace_enabled = ftrace_enabled; |
| 173 | int save_tracer_enabled = tracer_enabled; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 174 | unsigned long count; |
| 175 | int ret; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 176 | |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 177 | /* make sure msleep has been recorded */ |
| 178 | msleep(1); |
| 179 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 180 | /* start the tracing */ |
Ingo Molnar | c7aafc5 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 181 | ftrace_enabled = 1; |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 182 | tracer_enabled = 1; |
Ingo Molnar | c7aafc5 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 183 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 184 | tr->ctrl = 1; |
| 185 | trace->init(tr); |
| 186 | /* Sleep for a 1/10 of a second */ |
| 187 | msleep(100); |
| 188 | /* stop the tracing. */ |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame^] | 189 | tracing_stop(); |
Ingo Molnar | c7aafc5 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 190 | ftrace_enabled = 0; |
| 191 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 192 | /* check the trace buffer */ |
| 193 | ret = trace_test_buffer(tr, &count); |
| 194 | trace->reset(tr); |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame^] | 195 | tracing_start(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 196 | |
| 197 | if (!ret && !count) { |
| 198 | printk(KERN_CONT ".. no entries found .."); |
| 199 | ret = -1; |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 200 | goto out; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 201 | } |
| 202 | |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 203 | ret = trace_selftest_startup_dynamic_tracing(trace, tr, |
| 204 | DYN_FTRACE_TEST_NAME); |
| 205 | |
| 206 | out: |
| 207 | ftrace_enabled = save_ftrace_enabled; |
| 208 | tracer_enabled = save_tracer_enabled; |
| 209 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 210 | /* kill ftrace totally if we failed */ |
| 211 | if (ret) |
| 212 | ftrace_kill(); |
| 213 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 214 | return ret; |
| 215 | } |
Steven Rostedt | 606576c | 2008-10-06 19:06:12 -0400 | [diff] [blame] | 216 | #endif /* CONFIG_FUNCTION_TRACER */ |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 217 | |
| 218 | #ifdef CONFIG_IRQSOFF_TRACER |
| 219 | int |
| 220 | trace_selftest_startup_irqsoff(struct tracer *trace, struct trace_array *tr) |
| 221 | { |
| 222 | unsigned long save_max = tracing_max_latency; |
| 223 | unsigned long count; |
| 224 | int ret; |
| 225 | |
| 226 | /* start the tracing */ |
| 227 | tr->ctrl = 1; |
| 228 | trace->init(tr); |
| 229 | /* reset the max latency */ |
| 230 | tracing_max_latency = 0; |
| 231 | /* disable interrupts for a bit */ |
| 232 | local_irq_disable(); |
| 233 | udelay(100); |
| 234 | local_irq_enable(); |
| 235 | /* stop the tracing. */ |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame^] | 236 | tracing_stop(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 237 | /* check both trace buffers */ |
| 238 | ret = trace_test_buffer(tr, NULL); |
| 239 | if (!ret) |
| 240 | ret = trace_test_buffer(&max_tr, &count); |
| 241 | trace->reset(tr); |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame^] | 242 | tracing_start(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 243 | |
| 244 | if (!ret && !count) { |
| 245 | printk(KERN_CONT ".. no entries found .."); |
| 246 | ret = -1; |
| 247 | } |
| 248 | |
| 249 | tracing_max_latency = save_max; |
| 250 | |
| 251 | return ret; |
| 252 | } |
| 253 | #endif /* CONFIG_IRQSOFF_TRACER */ |
| 254 | |
| 255 | #ifdef CONFIG_PREEMPT_TRACER |
| 256 | int |
| 257 | trace_selftest_startup_preemptoff(struct tracer *trace, struct trace_array *tr) |
| 258 | { |
| 259 | unsigned long save_max = tracing_max_latency; |
| 260 | unsigned long count; |
| 261 | int ret; |
| 262 | |
| 263 | /* start the tracing */ |
| 264 | tr->ctrl = 1; |
| 265 | trace->init(tr); |
| 266 | /* reset the max latency */ |
| 267 | tracing_max_latency = 0; |
| 268 | /* disable preemption for a bit */ |
| 269 | preempt_disable(); |
| 270 | udelay(100); |
| 271 | preempt_enable(); |
| 272 | /* stop the tracing. */ |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame^] | 273 | tracing_stop(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 274 | /* check both trace buffers */ |
| 275 | ret = trace_test_buffer(tr, NULL); |
| 276 | if (!ret) |
| 277 | ret = trace_test_buffer(&max_tr, &count); |
| 278 | trace->reset(tr); |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame^] | 279 | tracing_start(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 280 | |
| 281 | if (!ret && !count) { |
| 282 | printk(KERN_CONT ".. no entries found .."); |
| 283 | ret = -1; |
| 284 | } |
| 285 | |
| 286 | tracing_max_latency = save_max; |
| 287 | |
| 288 | return ret; |
| 289 | } |
| 290 | #endif /* CONFIG_PREEMPT_TRACER */ |
| 291 | |
| 292 | #if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER) |
| 293 | int |
| 294 | trace_selftest_startup_preemptirqsoff(struct tracer *trace, struct trace_array *tr) |
| 295 | { |
| 296 | unsigned long save_max = tracing_max_latency; |
| 297 | unsigned long count; |
| 298 | int ret; |
| 299 | |
| 300 | /* start the tracing */ |
| 301 | tr->ctrl = 1; |
| 302 | trace->init(tr); |
| 303 | |
| 304 | /* reset the max latency */ |
| 305 | tracing_max_latency = 0; |
| 306 | |
| 307 | /* disable preemption and interrupts for a bit */ |
| 308 | preempt_disable(); |
| 309 | local_irq_disable(); |
| 310 | udelay(100); |
| 311 | preempt_enable(); |
| 312 | /* reverse the order of preempt vs irqs */ |
| 313 | local_irq_enable(); |
| 314 | |
| 315 | /* stop the tracing. */ |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame^] | 316 | tracing_stop(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 317 | /* check both trace buffers */ |
| 318 | ret = trace_test_buffer(tr, NULL); |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame^] | 319 | if (ret) { |
| 320 | tracing_start(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 321 | goto out; |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame^] | 322 | } |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 323 | |
| 324 | ret = trace_test_buffer(&max_tr, &count); |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame^] | 325 | if (ret) { |
| 326 | tracing_start(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 327 | goto out; |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame^] | 328 | } |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 329 | |
| 330 | if (!ret && !count) { |
| 331 | printk(KERN_CONT ".. no entries found .."); |
| 332 | ret = -1; |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame^] | 333 | tracing_start(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 334 | goto out; |
| 335 | } |
| 336 | |
| 337 | /* do the test by disabling interrupts first this time */ |
| 338 | tracing_max_latency = 0; |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame^] | 339 | tracing_start(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 340 | preempt_disable(); |
| 341 | local_irq_disable(); |
| 342 | udelay(100); |
| 343 | preempt_enable(); |
| 344 | /* reverse the order of preempt vs irqs */ |
| 345 | local_irq_enable(); |
| 346 | |
| 347 | /* stop the tracing. */ |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame^] | 348 | tracing_stop(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 349 | /* check both trace buffers */ |
| 350 | ret = trace_test_buffer(tr, NULL); |
| 351 | if (ret) |
| 352 | goto out; |
| 353 | |
| 354 | ret = trace_test_buffer(&max_tr, &count); |
| 355 | |
| 356 | if (!ret && !count) { |
| 357 | printk(KERN_CONT ".. no entries found .."); |
| 358 | ret = -1; |
| 359 | goto out; |
| 360 | } |
| 361 | |
| 362 | out: |
| 363 | trace->reset(tr); |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame^] | 364 | tracing_start(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 365 | tracing_max_latency = save_max; |
| 366 | |
| 367 | return ret; |
| 368 | } |
| 369 | #endif /* CONFIG_IRQSOFF_TRACER && CONFIG_PREEMPT_TRACER */ |
| 370 | |
Steven Noonan | fb1b6d8 | 2008-09-19 03:06:43 -0700 | [diff] [blame] | 371 | #ifdef CONFIG_NOP_TRACER |
| 372 | int |
| 373 | trace_selftest_startup_nop(struct tracer *trace, struct trace_array *tr) |
| 374 | { |
| 375 | /* What could possibly go wrong? */ |
| 376 | return 0; |
| 377 | } |
| 378 | #endif |
| 379 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 380 | #ifdef CONFIG_SCHED_TRACER |
| 381 | static int trace_wakeup_test_thread(void *data) |
| 382 | { |
Steven Rostedt | 05bd68c | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 383 | /* Make this a RT thread, doesn't need to be too high */ |
| 384 | struct sched_param param = { .sched_priority = 5 }; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 385 | struct completion *x = data; |
| 386 | |
Steven Rostedt | 05bd68c | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 387 | sched_setscheduler(current, SCHED_FIFO, ¶m); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 388 | |
| 389 | /* Make it know we have a new prio */ |
| 390 | complete(x); |
| 391 | |
| 392 | /* now go to sleep and let the test wake us up */ |
| 393 | set_current_state(TASK_INTERRUPTIBLE); |
| 394 | schedule(); |
| 395 | |
| 396 | /* we are awake, now wait to disappear */ |
| 397 | while (!kthread_should_stop()) { |
| 398 | /* |
| 399 | * This is an RT task, do short sleeps to let |
| 400 | * others run. |
| 401 | */ |
| 402 | msleep(100); |
| 403 | } |
| 404 | |
| 405 | return 0; |
| 406 | } |
| 407 | |
| 408 | int |
| 409 | trace_selftest_startup_wakeup(struct tracer *trace, struct trace_array *tr) |
| 410 | { |
| 411 | unsigned long save_max = tracing_max_latency; |
| 412 | struct task_struct *p; |
| 413 | struct completion isrt; |
| 414 | unsigned long count; |
| 415 | int ret; |
| 416 | |
| 417 | init_completion(&isrt); |
| 418 | |
| 419 | /* create a high prio thread */ |
| 420 | p = kthread_run(trace_wakeup_test_thread, &isrt, "ftrace-test"); |
Ingo Molnar | c7aafc5 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 421 | if (IS_ERR(p)) { |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 422 | printk(KERN_CONT "Failed to create ftrace wakeup test thread "); |
| 423 | return -1; |
| 424 | } |
| 425 | |
| 426 | /* make sure the thread is running at an RT prio */ |
| 427 | wait_for_completion(&isrt); |
| 428 | |
| 429 | /* start the tracing */ |
| 430 | tr->ctrl = 1; |
| 431 | trace->init(tr); |
| 432 | /* reset the max latency */ |
| 433 | tracing_max_latency = 0; |
| 434 | |
| 435 | /* sleep to let the RT thread sleep too */ |
| 436 | msleep(100); |
| 437 | |
| 438 | /* |
| 439 | * Yes this is slightly racy. It is possible that for some |
| 440 | * strange reason that the RT thread we created, did not |
| 441 | * call schedule for 100ms after doing the completion, |
| 442 | * and we do a wakeup on a task that already is awake. |
| 443 | * But that is extremely unlikely, and the worst thing that |
| 444 | * happens in such a case, is that we disable tracing. |
| 445 | * Honestly, if this race does happen something is horrible |
| 446 | * wrong with the system. |
| 447 | */ |
| 448 | |
| 449 | wake_up_process(p); |
| 450 | |
Steven Rostedt | 5aa60c6 | 2008-09-29 23:02:37 -0400 | [diff] [blame] | 451 | /* give a little time to let the thread wake up */ |
| 452 | msleep(100); |
| 453 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 454 | /* stop the tracing. */ |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame^] | 455 | tracing_stop(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 456 | /* check both trace buffers */ |
| 457 | ret = trace_test_buffer(tr, NULL); |
| 458 | if (!ret) |
| 459 | ret = trace_test_buffer(&max_tr, &count); |
| 460 | |
| 461 | |
| 462 | trace->reset(tr); |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame^] | 463 | tracing_start(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 464 | |
| 465 | tracing_max_latency = save_max; |
| 466 | |
| 467 | /* kill the thread */ |
| 468 | kthread_stop(p); |
| 469 | |
| 470 | if (!ret && !count) { |
| 471 | printk(KERN_CONT ".. no entries found .."); |
| 472 | ret = -1; |
| 473 | } |
| 474 | |
| 475 | return ret; |
| 476 | } |
| 477 | #endif /* CONFIG_SCHED_TRACER */ |
| 478 | |
| 479 | #ifdef CONFIG_CONTEXT_SWITCH_TRACER |
| 480 | int |
| 481 | trace_selftest_startup_sched_switch(struct tracer *trace, struct trace_array *tr) |
| 482 | { |
| 483 | unsigned long count; |
| 484 | int ret; |
| 485 | |
| 486 | /* start the tracing */ |
| 487 | tr->ctrl = 1; |
| 488 | trace->init(tr); |
| 489 | /* Sleep for a 1/10 of a second */ |
| 490 | msleep(100); |
| 491 | /* stop the tracing. */ |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame^] | 492 | tracing_stop(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 493 | /* check the trace buffer */ |
| 494 | ret = trace_test_buffer(tr, &count); |
| 495 | trace->reset(tr); |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame^] | 496 | tracing_start(); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 497 | |
| 498 | if (!ret && !count) { |
| 499 | printk(KERN_CONT ".. no entries found .."); |
| 500 | ret = -1; |
| 501 | } |
| 502 | |
| 503 | return ret; |
| 504 | } |
| 505 | #endif /* CONFIG_CONTEXT_SWITCH_TRACER */ |
Ingo Molnar | a6dd24f | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 506 | |
| 507 | #ifdef CONFIG_SYSPROF_TRACER |
| 508 | int |
| 509 | trace_selftest_startup_sysprof(struct tracer *trace, struct trace_array *tr) |
| 510 | { |
| 511 | unsigned long count; |
| 512 | int ret; |
| 513 | |
| 514 | /* start the tracing */ |
| 515 | tr->ctrl = 1; |
| 516 | trace->init(tr); |
| 517 | /* Sleep for a 1/10 of a second */ |
| 518 | msleep(100); |
| 519 | /* stop the tracing. */ |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame^] | 520 | tracing_stop(); |
Ingo Molnar | a6dd24f | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 521 | /* check the trace buffer */ |
| 522 | ret = trace_test_buffer(tr, &count); |
| 523 | trace->reset(tr); |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame^] | 524 | tracing_start(); |
Ingo Molnar | a6dd24f | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 525 | |
Ingo Molnar | a6dd24f | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 526 | return ret; |
| 527 | } |
| 528 | #endif /* CONFIG_SYSPROF_TRACER */ |