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