blob: 1003a4d5eb2522053ab54770477f01581b7087ef [file] [log] [blame]
Steven Rostedt60a11772008-05-12 21:20:44 +02001/* Include in trace.c */
2
Steven Rostedt9cc26a22009-03-09 16:00:22 -04003#include <linux/stringify.h>
Steven Rostedt60a11772008-05-12 21:20:44 +02004#include <linux/kthread.h>
Ingo Molnarc7aafc52008-05-12 21:20:45 +02005#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09006#include <linux/slab.h>
Steven Rostedt60a11772008-05-12 21:20:44 +02007
Ingo Molnare309b412008-05-12 21:20:51 +02008static inline int trace_valid_entry(struct trace_entry *entry)
Steven Rostedt60a11772008-05-12 21:20:44 +02009{
10 switch (entry->type) {
11 case TRACE_FN:
12 case TRACE_CTX:
Ingo Molnar57422792008-05-12 21:20:51 +020013 case TRACE_WAKE:
Steven Rostedt06fa75a2008-05-12 21:20:54 +020014 case TRACE_STACK:
Steven Rostedtdd0e5452008-08-01 12:26:41 -040015 case TRACE_PRINT:
Steven Rostedt80e5ea42008-11-12 15:24:24 -050016 case TRACE_BRANCH:
Frederic Weisbecker7447dce2009-02-07 21:33:57 +010017 case TRACE_GRAPH_ENT:
18 case TRACE_GRAPH_RET:
Steven Rostedt60a11772008-05-12 21:20:44 +020019 return 1;
20 }
21 return 0;
22}
23
Steven Rostedt3928a8a2008-09-29 23:02:41 -040024static int trace_test_buffer_cpu(struct trace_array *tr, int cpu)
Steven Rostedt60a11772008-05-12 21:20:44 +020025{
Steven Rostedt3928a8a2008-09-29 23:02:41 -040026 struct ring_buffer_event *event;
27 struct trace_entry *entry;
Steven Rostedt4b3e3d22009-02-18 22:50:01 -050028 unsigned int loops = 0;
Steven Rostedt60a11772008-05-12 21:20:44 +020029
Steven Rostedt66a8cb92010-03-31 13:21:56 -040030 while ((event = ring_buffer_consume(tr->buffer, cpu, NULL, NULL))) {
Steven Rostedt3928a8a2008-09-29 23:02:41 -040031 entry = ring_buffer_event_data(event);
Steven Rostedt60a11772008-05-12 21:20:44 +020032
Steven Rostedt4b3e3d22009-02-18 22:50:01 -050033 /*
34 * The ring buffer is a size of trace_buf_size, if
35 * we loop more than the size, there's something wrong
36 * with the ring buffer.
37 */
38 if (loops++ > trace_buf_size) {
39 printk(KERN_CONT ".. bad ring buffer ");
40 goto failed;
41 }
Steven Rostedt3928a8a2008-09-29 23:02:41 -040042 if (!trace_valid_entry(entry)) {
Ingo Molnarc7aafc52008-05-12 21:20:45 +020043 printk(KERN_CONT ".. invalid entry %d ",
Steven Rostedt3928a8a2008-09-29 23:02:41 -040044 entry->type);
Steven Rostedt60a11772008-05-12 21:20:44 +020045 goto failed;
46 }
Steven Rostedt60a11772008-05-12 21:20:44 +020047 }
Steven Rostedt60a11772008-05-12 21:20:44 +020048 return 0;
49
50 failed:
Steven Rostedt08bafa02008-05-12 21:20:45 +020051 /* disable tracing */
52 tracing_disabled = 1;
Steven Rostedt60a11772008-05-12 21:20:44 +020053 printk(KERN_CONT ".. corrupted trace buffer .. ");
54 return -1;
55}
56
57/*
58 * Test the trace buffer to see if all the elements
59 * are still sane.
60 */
61static int trace_test_buffer(struct trace_array *tr, unsigned long *count)
62{
Steven Rostedt30afdcb2008-05-12 21:20:56 +020063 unsigned long flags, cnt = 0;
64 int cpu, ret = 0;
Steven Rostedt60a11772008-05-12 21:20:44 +020065
Steven Rostedt30afdcb2008-05-12 21:20:56 +020066 /* Don't allow flipping of max traces now */
Steven Rostedtd51ad7a2008-11-15 15:48:29 -050067 local_irq_save(flags);
Thomas Gleixner0199c4e2009-12-02 20:01:25 +010068 arch_spin_lock(&ftrace_max_lock);
Steven Rostedt3928a8a2008-09-29 23:02:41 -040069
70 cnt = ring_buffer_entries(tr->buffer);
71
Steven Rostedt0c5119c2009-02-18 18:33:57 -050072 /*
73 * The trace_test_buffer_cpu runs a while loop to consume all data.
74 * If the calling tracer is broken, and is constantly filling
75 * the buffer, this will run forever, and hard lock the box.
76 * We disable the ring buffer while we do this test to prevent
77 * a hard lock up.
78 */
79 tracing_off();
Steven Rostedt60a11772008-05-12 21:20:44 +020080 for_each_possible_cpu(cpu) {
Steven Rostedt3928a8a2008-09-29 23:02:41 -040081 ret = trace_test_buffer_cpu(tr, cpu);
Steven Rostedt60a11772008-05-12 21:20:44 +020082 if (ret)
83 break;
84 }
Steven Rostedt0c5119c2009-02-18 18:33:57 -050085 tracing_on();
Thomas Gleixner0199c4e2009-12-02 20:01:25 +010086 arch_spin_unlock(&ftrace_max_lock);
Steven Rostedtd51ad7a2008-11-15 15:48:29 -050087 local_irq_restore(flags);
Steven Rostedt60a11772008-05-12 21:20:44 +020088
89 if (count)
90 *count = cnt;
91
92 return ret;
93}
94
Frederic Weisbecker1c800252008-11-16 05:57:26 +010095static inline void warn_failed_init_tracer(struct tracer *trace, int init_ret)
96{
97 printk(KERN_WARNING "Failed to init %s tracer, init returned %d\n",
98 trace->name, init_ret);
99}
Steven Rostedt606576c2008-10-06 19:06:12 -0400100#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedt77a2b372008-05-12 21:20:45 +0200101
102#ifdef CONFIG_DYNAMIC_FTRACE
103
Steven Rostedt95950c22011-05-06 00:08:51 -0400104static int trace_selftest_test_probe1_cnt;
105static void trace_selftest_test_probe1_func(unsigned long ip,
Steven Rostedt2f5f6ad2011-08-08 16:57:47 -0400106 unsigned long pip,
Steven Rostedta1e2e312011-08-09 12:50:46 -0400107 struct ftrace_ops *op,
108 struct pt_regs *pt_regs)
Steven Rostedt95950c22011-05-06 00:08:51 -0400109{
110 trace_selftest_test_probe1_cnt++;
111}
112
113static int trace_selftest_test_probe2_cnt;
114static void trace_selftest_test_probe2_func(unsigned long ip,
Steven Rostedt2f5f6ad2011-08-08 16:57:47 -0400115 unsigned long pip,
Steven Rostedta1e2e312011-08-09 12:50:46 -0400116 struct ftrace_ops *op,
117 struct pt_regs *pt_regs)
Steven Rostedt95950c22011-05-06 00:08:51 -0400118{
119 trace_selftest_test_probe2_cnt++;
120}
121
122static int trace_selftest_test_probe3_cnt;
123static void trace_selftest_test_probe3_func(unsigned long ip,
Steven Rostedt2f5f6ad2011-08-08 16:57:47 -0400124 unsigned long pip,
Steven Rostedta1e2e312011-08-09 12:50:46 -0400125 struct ftrace_ops *op,
126 struct pt_regs *pt_regs)
Steven Rostedt95950c22011-05-06 00:08:51 -0400127{
128 trace_selftest_test_probe3_cnt++;
129}
130
131static int trace_selftest_test_global_cnt;
132static void trace_selftest_test_global_func(unsigned long ip,
Steven Rostedt2f5f6ad2011-08-08 16:57:47 -0400133 unsigned long pip,
Steven Rostedta1e2e312011-08-09 12:50:46 -0400134 struct ftrace_ops *op,
135 struct pt_regs *pt_regs)
Steven Rostedt95950c22011-05-06 00:08:51 -0400136{
137 trace_selftest_test_global_cnt++;
138}
139
140static int trace_selftest_test_dyn_cnt;
141static void trace_selftest_test_dyn_func(unsigned long ip,
Steven Rostedt2f5f6ad2011-08-08 16:57:47 -0400142 unsigned long pip,
Steven Rostedta1e2e312011-08-09 12:50:46 -0400143 struct ftrace_ops *op,
144 struct pt_regs *pt_regs)
Steven Rostedt95950c22011-05-06 00:08:51 -0400145{
146 trace_selftest_test_dyn_cnt++;
147}
148
149static struct ftrace_ops test_probe1 = {
150 .func = trace_selftest_test_probe1_func,
Steven Rostedt47409742012-07-20 11:04:44 -0400151 .flags = FTRACE_OPS_FL_RECURSION_SAFE,
Steven Rostedt95950c22011-05-06 00:08:51 -0400152};
153
154static struct ftrace_ops test_probe2 = {
155 .func = trace_selftest_test_probe2_func,
Steven Rostedt47409742012-07-20 11:04:44 -0400156 .flags = FTRACE_OPS_FL_RECURSION_SAFE,
Steven Rostedt95950c22011-05-06 00:08:51 -0400157};
158
159static struct ftrace_ops test_probe3 = {
160 .func = trace_selftest_test_probe3_func,
Steven Rostedt47409742012-07-20 11:04:44 -0400161 .flags = FTRACE_OPS_FL_RECURSION_SAFE,
Steven Rostedt95950c22011-05-06 00:08:51 -0400162};
163
164static struct ftrace_ops test_global = {
Steven Rostedt47409742012-07-20 11:04:44 -0400165 .func = trace_selftest_test_global_func,
166 .flags = FTRACE_OPS_FL_GLOBAL | FTRACE_OPS_FL_RECURSION_SAFE,
Steven Rostedt95950c22011-05-06 00:08:51 -0400167};
168
169static void print_counts(void)
170{
171 printk("(%d %d %d %d %d) ",
172 trace_selftest_test_probe1_cnt,
173 trace_selftest_test_probe2_cnt,
174 trace_selftest_test_probe3_cnt,
175 trace_selftest_test_global_cnt,
176 trace_selftest_test_dyn_cnt);
177}
178
179static void reset_counts(void)
180{
181 trace_selftest_test_probe1_cnt = 0;
182 trace_selftest_test_probe2_cnt = 0;
183 trace_selftest_test_probe3_cnt = 0;
184 trace_selftest_test_global_cnt = 0;
185 trace_selftest_test_dyn_cnt = 0;
186}
187
188static int trace_selftest_ops(int cnt)
189{
190 int save_ftrace_enabled = ftrace_enabled;
191 struct ftrace_ops *dyn_ops;
192 char *func1_name;
193 char *func2_name;
194 int len1;
195 int len2;
196 int ret = -1;
197
198 printk(KERN_CONT "PASSED\n");
199 pr_info("Testing dynamic ftrace ops #%d: ", cnt);
200
201 ftrace_enabled = 1;
202 reset_counts();
203
204 /* Handle PPC64 '.' name */
205 func1_name = "*" __stringify(DYN_FTRACE_TEST_NAME);
206 func2_name = "*" __stringify(DYN_FTRACE_TEST_NAME2);
207 len1 = strlen(func1_name);
208 len2 = strlen(func2_name);
209
210 /*
211 * Probe 1 will trace function 1.
212 * Probe 2 will trace function 2.
213 * Probe 3 will trace functions 1 and 2.
214 */
215 ftrace_set_filter(&test_probe1, func1_name, len1, 1);
216 ftrace_set_filter(&test_probe2, func2_name, len2, 1);
217 ftrace_set_filter(&test_probe3, func1_name, len1, 1);
218 ftrace_set_filter(&test_probe3, func2_name, len2, 0);
219
220 register_ftrace_function(&test_probe1);
221 register_ftrace_function(&test_probe2);
222 register_ftrace_function(&test_probe3);
223 register_ftrace_function(&test_global);
224
225 DYN_FTRACE_TEST_NAME();
226
227 print_counts();
228
229 if (trace_selftest_test_probe1_cnt != 1)
230 goto out;
231 if (trace_selftest_test_probe2_cnt != 0)
232 goto out;
233 if (trace_selftest_test_probe3_cnt != 1)
234 goto out;
235 if (trace_selftest_test_global_cnt == 0)
236 goto out;
237
238 DYN_FTRACE_TEST_NAME2();
239
240 print_counts();
241
242 if (trace_selftest_test_probe1_cnt != 1)
243 goto out;
244 if (trace_selftest_test_probe2_cnt != 1)
245 goto out;
246 if (trace_selftest_test_probe3_cnt != 2)
247 goto out;
248
249 /* Add a dynamic probe */
250 dyn_ops = kzalloc(sizeof(*dyn_ops), GFP_KERNEL);
251 if (!dyn_ops) {
252 printk("MEMORY ERROR ");
253 goto out;
254 }
255
256 dyn_ops->func = trace_selftest_test_dyn_func;
257
258 register_ftrace_function(dyn_ops);
259
260 trace_selftest_test_global_cnt = 0;
261
262 DYN_FTRACE_TEST_NAME();
263
264 print_counts();
265
266 if (trace_selftest_test_probe1_cnt != 2)
267 goto out_free;
268 if (trace_selftest_test_probe2_cnt != 1)
269 goto out_free;
270 if (trace_selftest_test_probe3_cnt != 3)
271 goto out_free;
272 if (trace_selftest_test_global_cnt == 0)
273 goto out;
274 if (trace_selftest_test_dyn_cnt == 0)
275 goto out_free;
276
277 DYN_FTRACE_TEST_NAME2();
278
279 print_counts();
280
281 if (trace_selftest_test_probe1_cnt != 2)
282 goto out_free;
283 if (trace_selftest_test_probe2_cnt != 2)
284 goto out_free;
285 if (trace_selftest_test_probe3_cnt != 4)
286 goto out_free;
287
288 ret = 0;
289 out_free:
290 unregister_ftrace_function(dyn_ops);
291 kfree(dyn_ops);
292
293 out:
294 /* Purposely unregister in the same order */
295 unregister_ftrace_function(&test_probe1);
296 unregister_ftrace_function(&test_probe2);
297 unregister_ftrace_function(&test_probe3);
298 unregister_ftrace_function(&test_global);
299
300 /* Make sure everything is off */
301 reset_counts();
302 DYN_FTRACE_TEST_NAME();
303 DYN_FTRACE_TEST_NAME();
304
305 if (trace_selftest_test_probe1_cnt ||
306 trace_selftest_test_probe2_cnt ||
307 trace_selftest_test_probe3_cnt ||
308 trace_selftest_test_global_cnt ||
309 trace_selftest_test_dyn_cnt)
310 ret = -1;
311
312 ftrace_enabled = save_ftrace_enabled;
313
314 return ret;
315}
316
Steven Rostedt77a2b372008-05-12 21:20:45 +0200317/* Test dynamic code modification and ftrace filters */
318int trace_selftest_startup_dynamic_tracing(struct tracer *trace,
319 struct trace_array *tr,
320 int (*func)(void))
321{
Steven Rostedt77a2b372008-05-12 21:20:45 +0200322 int save_ftrace_enabled = ftrace_enabled;
323 int save_tracer_enabled = tracer_enabled;
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400324 unsigned long count;
Steven Rostedt4e491d12008-05-14 23:49:44 -0400325 char *func_name;
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400326 int ret;
Steven Rostedt77a2b372008-05-12 21:20:45 +0200327
328 /* The ftrace test PASSED */
329 printk(KERN_CONT "PASSED\n");
330 pr_info("Testing dynamic ftrace: ");
331
332 /* enable tracing, and record the filter function */
333 ftrace_enabled = 1;
334 tracer_enabled = 1;
335
336 /* passed in by parameter to fool gcc from optimizing */
337 func();
338
Steven Rostedt4e491d12008-05-14 23:49:44 -0400339 /*
Wenji Huang73d8b8b2009-02-17 01:10:02 -0500340 * Some archs *cough*PowerPC*cough* add characters to the
Steven Rostedt4e491d12008-05-14 23:49:44 -0400341 * start of the function names. We simply put a '*' to
Wenji Huang73d8b8b2009-02-17 01:10:02 -0500342 * accommodate them.
Steven Rostedt4e491d12008-05-14 23:49:44 -0400343 */
Steven Rostedt9cc26a22009-03-09 16:00:22 -0400344 func_name = "*" __stringify(DYN_FTRACE_TEST_NAME);
Steven Rostedt4e491d12008-05-14 23:49:44 -0400345
Steven Rostedt77a2b372008-05-12 21:20:45 +0200346 /* filter only on our function */
Steven Rostedt936e0742011-05-05 22:54:01 -0400347 ftrace_set_global_filter(func_name, strlen(func_name), 1);
Steven Rostedt77a2b372008-05-12 21:20:45 +0200348
349 /* enable tracing */
Arnaldo Carvalho de Melob6f11df2009-02-05 18:02:00 -0200350 ret = tracer_init(trace, tr);
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100351 if (ret) {
352 warn_failed_init_tracer(trace, ret);
353 goto out;
354 }
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400355
Steven Rostedt77a2b372008-05-12 21:20:45 +0200356 /* Sleep for a 1/10 of a second */
357 msleep(100);
358
359 /* we should have nothing in the buffer */
360 ret = trace_test_buffer(tr, &count);
361 if (ret)
362 goto out;
363
364 if (count) {
365 ret = -1;
366 printk(KERN_CONT ".. filter did not filter .. ");
367 goto out;
368 }
369
370 /* call our function again */
371 func();
372
373 /* sleep again */
374 msleep(100);
375
376 /* stop the tracing. */
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500377 tracing_stop();
Steven Rostedt77a2b372008-05-12 21:20:45 +0200378 ftrace_enabled = 0;
379
380 /* check the trace buffer */
381 ret = trace_test_buffer(tr, &count);
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500382 tracing_start();
Steven Rostedt77a2b372008-05-12 21:20:45 +0200383
384 /* we should only have one item */
385 if (!ret && count != 1) {
Steven Rostedt95950c22011-05-06 00:08:51 -0400386 trace->reset(tr);
Steven Rostedt06fa75a2008-05-12 21:20:54 +0200387 printk(KERN_CONT ".. filter failed count=%ld ..", count);
Steven Rostedt77a2b372008-05-12 21:20:45 +0200388 ret = -1;
389 goto out;
390 }
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500391
Steven Rostedt95950c22011-05-06 00:08:51 -0400392 /* Test the ops with global tracing running */
393 ret = trace_selftest_ops(1);
394 trace->reset(tr);
395
Steven Rostedt77a2b372008-05-12 21:20:45 +0200396 out:
397 ftrace_enabled = save_ftrace_enabled;
398 tracer_enabled = save_tracer_enabled;
399
400 /* Enable tracing on all functions again */
Steven Rostedt936e0742011-05-05 22:54:01 -0400401 ftrace_set_global_filter(NULL, 0, 1);
Steven Rostedt77a2b372008-05-12 21:20:45 +0200402
Steven Rostedt95950c22011-05-06 00:08:51 -0400403 /* Test the ops with global tracing off */
404 if (!ret)
405 ret = trace_selftest_ops(2);
406
Steven Rostedt77a2b372008-05-12 21:20:45 +0200407 return ret;
408}
Steven Rostedtea701f12012-07-20 13:08:05 -0400409
410static int trace_selftest_recursion_cnt;
411static void trace_selftest_test_recursion_func(unsigned long ip,
412 unsigned long pip,
413 struct ftrace_ops *op,
414 struct pt_regs *pt_regs)
415{
416 /*
417 * This function is registered without the recursion safe flag.
418 * The ftrace infrastructure should provide the recursion
419 * protection. If not, this will crash the kernel!
420 */
421 trace_selftest_recursion_cnt++;
422 DYN_FTRACE_TEST_NAME();
423}
424
425static void trace_selftest_test_recursion_safe_func(unsigned long ip,
426 unsigned long pip,
427 struct ftrace_ops *op,
428 struct pt_regs *pt_regs)
429{
430 /*
431 * We said we would provide our own recursion. By calling
432 * this function again, we should recurse back into this function
433 * and count again. But this only happens if the arch supports
434 * all of ftrace features and nothing else is using the function
435 * tracing utility.
436 */
437 if (trace_selftest_recursion_cnt++)
438 return;
439 DYN_FTRACE_TEST_NAME();
440}
441
442static struct ftrace_ops test_rec_probe = {
443 .func = trace_selftest_test_recursion_func,
444};
445
446static struct ftrace_ops test_recsafe_probe = {
447 .func = trace_selftest_test_recursion_safe_func,
448 .flags = FTRACE_OPS_FL_RECURSION_SAFE,
449};
450
451static int
452trace_selftest_function_recursion(void)
453{
454 int save_ftrace_enabled = ftrace_enabled;
455 int save_tracer_enabled = tracer_enabled;
456 char *func_name;
457 int len;
458 int ret;
459 int cnt;
460
461 /* The previous test PASSED */
462 pr_cont("PASSED\n");
463 pr_info("Testing ftrace recursion: ");
464
465
466 /* enable tracing, and record the filter function */
467 ftrace_enabled = 1;
468 tracer_enabled = 1;
469
470 /* Handle PPC64 '.' name */
471 func_name = "*" __stringify(DYN_FTRACE_TEST_NAME);
472 len = strlen(func_name);
473
474 ret = ftrace_set_filter(&test_rec_probe, func_name, len, 1);
475 if (ret) {
476 pr_cont("*Could not set filter* ");
477 goto out;
478 }
479
480 ret = register_ftrace_function(&test_rec_probe);
481 if (ret) {
482 pr_cont("*could not register callback* ");
483 goto out;
484 }
485
486 DYN_FTRACE_TEST_NAME();
487
488 unregister_ftrace_function(&test_rec_probe);
489
490 ret = -1;
491 if (trace_selftest_recursion_cnt != 1) {
492 pr_cont("*callback not called once (%d)* ",
493 trace_selftest_recursion_cnt);
494 goto out;
495 }
496
497 trace_selftest_recursion_cnt = 1;
498
499 pr_cont("PASSED\n");
500 pr_info("Testing ftrace recursion safe: ");
501
502 ret = ftrace_set_filter(&test_recsafe_probe, func_name, len, 1);
503 if (ret) {
504 pr_cont("*Could not set filter* ");
505 goto out;
506 }
507
508 ret = register_ftrace_function(&test_recsafe_probe);
509 if (ret) {
510 pr_cont("*could not register callback* ");
511 goto out;
512 }
513
514 DYN_FTRACE_TEST_NAME();
515
516 unregister_ftrace_function(&test_recsafe_probe);
517
518 /*
519 * If arch supports all ftrace features, and no other task
520 * was on the list, we should be fine.
521 */
522 if (!ftrace_nr_registered_ops() && !FTRACE_FORCE_LIST_FUNC)
523 cnt = 2; /* Should have recursed */
524 else
525 cnt = 1;
526
527 ret = -1;
528 if (trace_selftest_recursion_cnt != cnt) {
529 pr_cont("*callback not called expected %d times (%d)* ",
530 cnt, trace_selftest_recursion_cnt);
531 goto out;
532 }
533
534 ret = 0;
535out:
536 ftrace_enabled = save_ftrace_enabled;
537 tracer_enabled = save_tracer_enabled;
538
539 return ret;
540}
Steven Rostedt77a2b372008-05-12 21:20:45 +0200541#else
542# define trace_selftest_startup_dynamic_tracing(trace, tr, func) ({ 0; })
Steven Rostedtea701f12012-07-20 13:08:05 -0400543# define trace_selftest_function_recursion() ({ 0; })
Steven Rostedt77a2b372008-05-12 21:20:45 +0200544#endif /* CONFIG_DYNAMIC_FTRACE */
Ingo Molnare9a22d12009-03-13 11:54:40 +0100545
Steven Rostedtad977722012-07-20 13:45:59 -0400546static enum {
547 TRACE_SELFTEST_REGS_START,
548 TRACE_SELFTEST_REGS_FOUND,
549 TRACE_SELFTEST_REGS_NOT_FOUND,
550} trace_selftest_regs_stat;
551
552static void trace_selftest_test_regs_func(unsigned long ip,
553 unsigned long pip,
554 struct ftrace_ops *op,
555 struct pt_regs *pt_regs)
556{
557 if (pt_regs)
558 trace_selftest_regs_stat = TRACE_SELFTEST_REGS_FOUND;
559 else
560 trace_selftest_regs_stat = TRACE_SELFTEST_REGS_NOT_FOUND;
561}
562
563static struct ftrace_ops test_regs_probe = {
564 .func = trace_selftest_test_regs_func,
565 .flags = FTRACE_OPS_FL_RECURSION_SAFE | FTRACE_OPS_FL_SAVE_REGS,
566};
567
568static int
569trace_selftest_function_regs(void)
570{
571 int save_ftrace_enabled = ftrace_enabled;
572 int save_tracer_enabled = tracer_enabled;
573 char *func_name;
574 int len;
575 int ret;
576 int supported = 0;
577
578#ifdef ARCH_SUPPORTS_FTRACE_SAVE_REGS
579 supported = 1;
580#endif
581
582 /* The previous test PASSED */
583 pr_cont("PASSED\n");
584 pr_info("Testing ftrace regs%s: ",
585 !supported ? "(no arch support)" : "");
586
587 /* enable tracing, and record the filter function */
588 ftrace_enabled = 1;
589 tracer_enabled = 1;
590
591 /* Handle PPC64 '.' name */
592 func_name = "*" __stringify(DYN_FTRACE_TEST_NAME);
593 len = strlen(func_name);
594
595 ret = ftrace_set_filter(&test_regs_probe, func_name, len, 1);
596 /*
597 * If DYNAMIC_FTRACE is not set, then we just trace all functions.
598 * This test really doesn't care.
599 */
600 if (ret && ret != -ENODEV) {
601 pr_cont("*Could not set filter* ");
602 goto out;
603 }
604
605 ret = register_ftrace_function(&test_regs_probe);
606 /*
607 * Now if the arch does not support passing regs, then this should
608 * have failed.
609 */
610 if (!supported) {
611 if (!ret) {
612 pr_cont("*registered save-regs without arch support* ");
613 goto out;
614 }
615 test_regs_probe.flags |= FTRACE_OPS_FL_SAVE_REGS_IF_SUPPORTED;
616 ret = register_ftrace_function(&test_regs_probe);
617 }
618 if (ret) {
619 pr_cont("*could not register callback* ");
620 goto out;
621 }
622
623
624 DYN_FTRACE_TEST_NAME();
625
626 unregister_ftrace_function(&test_regs_probe);
627
628 ret = -1;
629
630 switch (trace_selftest_regs_stat) {
631 case TRACE_SELFTEST_REGS_START:
632 pr_cont("*callback never called* ");
633 goto out;
634
635 case TRACE_SELFTEST_REGS_FOUND:
636 if (supported)
637 break;
638 pr_cont("*callback received regs without arch support* ");
639 goto out;
640
641 case TRACE_SELFTEST_REGS_NOT_FOUND:
642 if (!supported)
643 break;
644 pr_cont("*callback received NULL regs* ");
645 goto out;
646 }
647
648 ret = 0;
649out:
650 ftrace_enabled = save_ftrace_enabled;
651 tracer_enabled = save_tracer_enabled;
652
653 return ret;
654}
655
Steven Rostedt60a11772008-05-12 21:20:44 +0200656/*
657 * Simple verification test of ftrace function tracer.
658 * Enable ftrace, sleep 1/10 second, and then read the trace
659 * buffer to see if all is in order.
660 */
661int
662trace_selftest_startup_function(struct tracer *trace, struct trace_array *tr)
663{
Steven Rostedt77a2b372008-05-12 21:20:45 +0200664 int save_ftrace_enabled = ftrace_enabled;
665 int save_tracer_enabled = tracer_enabled;
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400666 unsigned long count;
667 int ret;
Steven Rostedt60a11772008-05-12 21:20:44 +0200668
Steven Rostedt77a2b372008-05-12 21:20:45 +0200669 /* make sure msleep has been recorded */
670 msleep(1);
671
Steven Rostedt60a11772008-05-12 21:20:44 +0200672 /* start the tracing */
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200673 ftrace_enabled = 1;
Steven Rostedt77a2b372008-05-12 21:20:45 +0200674 tracer_enabled = 1;
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200675
Arnaldo Carvalho de Melob6f11df2009-02-05 18:02:00 -0200676 ret = tracer_init(trace, tr);
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100677 if (ret) {
678 warn_failed_init_tracer(trace, ret);
679 goto out;
680 }
681
Steven Rostedt60a11772008-05-12 21:20:44 +0200682 /* Sleep for a 1/10 of a second */
683 msleep(100);
684 /* stop the tracing. */
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500685 tracing_stop();
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200686 ftrace_enabled = 0;
687
Steven Rostedt60a11772008-05-12 21:20:44 +0200688 /* check the trace buffer */
689 ret = trace_test_buffer(tr, &count);
690 trace->reset(tr);
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500691 tracing_start();
Steven Rostedt60a11772008-05-12 21:20:44 +0200692
693 if (!ret && !count) {
694 printk(KERN_CONT ".. no entries found ..");
695 ret = -1;
Steven Rostedt77a2b372008-05-12 21:20:45 +0200696 goto out;
Steven Rostedt60a11772008-05-12 21:20:44 +0200697 }
698
Steven Rostedt77a2b372008-05-12 21:20:45 +0200699 ret = trace_selftest_startup_dynamic_tracing(trace, tr,
700 DYN_FTRACE_TEST_NAME);
Steven Rostedtea701f12012-07-20 13:08:05 -0400701 if (ret)
702 goto out;
Steven Rostedt77a2b372008-05-12 21:20:45 +0200703
Steven Rostedtea701f12012-07-20 13:08:05 -0400704 ret = trace_selftest_function_recursion();
Steven Rostedtad977722012-07-20 13:45:59 -0400705 if (ret)
706 goto out;
707
708 ret = trace_selftest_function_regs();
Steven Rostedt77a2b372008-05-12 21:20:45 +0200709 out:
710 ftrace_enabled = save_ftrace_enabled;
711 tracer_enabled = save_tracer_enabled;
712
Steven Rostedt4eebcc82008-05-12 21:20:48 +0200713 /* kill ftrace totally if we failed */
714 if (ret)
715 ftrace_kill();
716
Steven Rostedt60a11772008-05-12 21:20:44 +0200717 return ret;
718}
Steven Rostedt606576c2008-10-06 19:06:12 -0400719#endif /* CONFIG_FUNCTION_TRACER */
Steven Rostedt60a11772008-05-12 21:20:44 +0200720
Frederic Weisbecker7447dce2009-02-07 21:33:57 +0100721
722#ifdef CONFIG_FUNCTION_GRAPH_TRACER
Frederic Weisbeckercf586b62009-03-22 05:04:35 +0100723
724/* Maximum number of functions to trace before diagnosing a hang */
725#define GRAPH_MAX_FUNC_TEST 100000000
726
Frederic Weisbeckercecbca92010-04-18 19:08:41 +0200727static void
728__ftrace_dump(bool disable_tracing, enum ftrace_dump_mode oops_dump_mode);
Frederic Weisbeckercf586b62009-03-22 05:04:35 +0100729static unsigned int graph_hang_thresh;
730
731/* Wrap the real function entry probe to avoid possible hanging */
732static int trace_graph_entry_watchdog(struct ftrace_graph_ent *trace)
733{
734 /* This is harmlessly racy, we want to approximately detect a hang */
735 if (unlikely(++graph_hang_thresh > GRAPH_MAX_FUNC_TEST)) {
736 ftrace_graph_stop();
737 printk(KERN_WARNING "BUG: Function graph tracer hang!\n");
738 if (ftrace_dump_on_oops)
Frederic Weisbeckercecbca92010-04-18 19:08:41 +0200739 __ftrace_dump(false, DUMP_ALL);
Frederic Weisbeckercf586b62009-03-22 05:04:35 +0100740 return 0;
741 }
742
743 return trace_graph_entry(trace);
744}
745
Frederic Weisbecker7447dce2009-02-07 21:33:57 +0100746/*
747 * Pretty much the same than for the function tracer from which the selftest
748 * has been borrowed.
749 */
750int
751trace_selftest_startup_function_graph(struct tracer *trace,
752 struct trace_array *tr)
753{
754 int ret;
755 unsigned long count;
756
Frederic Weisbeckercf586b62009-03-22 05:04:35 +0100757 /*
758 * Simulate the init() callback but we attach a watchdog callback
759 * to detect and recover from possible hangs
760 */
761 tracing_reset_online_cpus(tr);
Frederic Weisbecker1a0799a2009-07-29 18:59:58 +0200762 set_graph_array(tr);
Frederic Weisbeckercf586b62009-03-22 05:04:35 +0100763 ret = register_ftrace_graph(&trace_graph_return,
764 &trace_graph_entry_watchdog);
Frederic Weisbecker7447dce2009-02-07 21:33:57 +0100765 if (ret) {
766 warn_failed_init_tracer(trace, ret);
767 goto out;
768 }
Frederic Weisbeckercf586b62009-03-22 05:04:35 +0100769 tracing_start_cmdline_record();
Frederic Weisbecker7447dce2009-02-07 21:33:57 +0100770
771 /* Sleep for a 1/10 of a second */
772 msleep(100);
773
Frederic Weisbeckercf586b62009-03-22 05:04:35 +0100774 /* Have we just recovered from a hang? */
775 if (graph_hang_thresh > GRAPH_MAX_FUNC_TEST) {
Frederic Weisbecker0cf53ff2009-03-22 15:13:07 +0100776 tracing_selftest_disabled = true;
Frederic Weisbeckercf586b62009-03-22 05:04:35 +0100777 ret = -1;
778 goto out;
779 }
780
Frederic Weisbecker7447dce2009-02-07 21:33:57 +0100781 tracing_stop();
782
783 /* check the trace buffer */
784 ret = trace_test_buffer(tr, &count);
785
786 trace->reset(tr);
787 tracing_start();
788
789 if (!ret && !count) {
790 printk(KERN_CONT ".. no entries found ..");
791 ret = -1;
792 goto out;
793 }
794
795 /* Don't test dynamic tracing, the function tracer already did */
796
797out:
798 /* Stop it if we failed */
799 if (ret)
800 ftrace_graph_stop();
801
802 return ret;
803}
804#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
805
806
Steven Rostedt60a11772008-05-12 21:20:44 +0200807#ifdef CONFIG_IRQSOFF_TRACER
808int
809trace_selftest_startup_irqsoff(struct tracer *trace, struct trace_array *tr)
810{
811 unsigned long save_max = tracing_max_latency;
812 unsigned long count;
813 int ret;
814
815 /* start the tracing */
Arnaldo Carvalho de Melob6f11df2009-02-05 18:02:00 -0200816 ret = tracer_init(trace, tr);
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100817 if (ret) {
818 warn_failed_init_tracer(trace, ret);
819 return ret;
820 }
821
Steven Rostedt60a11772008-05-12 21:20:44 +0200822 /* reset the max latency */
823 tracing_max_latency = 0;
824 /* disable interrupts for a bit */
825 local_irq_disable();
826 udelay(100);
827 local_irq_enable();
Frederic Weisbecker49036202009-03-17 22:38:58 +0100828
829 /*
830 * Stop the tracer to avoid a warning subsequent
831 * to buffer flipping failure because tracing_stop()
832 * disables the tr and max buffers, making flipping impossible
833 * in case of parallels max irqs off latencies.
834 */
835 trace->stop(tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200836 /* stop the tracing. */
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500837 tracing_stop();
Steven Rostedt60a11772008-05-12 21:20:44 +0200838 /* check both trace buffers */
839 ret = trace_test_buffer(tr, NULL);
840 if (!ret)
841 ret = trace_test_buffer(&max_tr, &count);
842 trace->reset(tr);
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500843 tracing_start();
Steven Rostedt60a11772008-05-12 21:20:44 +0200844
845 if (!ret && !count) {
846 printk(KERN_CONT ".. no entries found ..");
847 ret = -1;
848 }
849
850 tracing_max_latency = save_max;
851
852 return ret;
853}
854#endif /* CONFIG_IRQSOFF_TRACER */
855
856#ifdef CONFIG_PREEMPT_TRACER
857int
858trace_selftest_startup_preemptoff(struct tracer *trace, struct trace_array *tr)
859{
860 unsigned long save_max = tracing_max_latency;
861 unsigned long count;
862 int ret;
863
Steven Rostedt769c48e2008-11-07 22:36:02 -0500864 /*
865 * Now that the big kernel lock is no longer preemptable,
866 * and this is called with the BKL held, it will always
867 * fail. If preemption is already disabled, simply
868 * pass the test. When the BKL is removed, or becomes
869 * preemptible again, we will once again test this,
870 * so keep it in.
871 */
872 if (preempt_count()) {
873 printk(KERN_CONT "can not test ... force ");
874 return 0;
875 }
876
Steven Rostedt60a11772008-05-12 21:20:44 +0200877 /* start the tracing */
Arnaldo Carvalho de Melob6f11df2009-02-05 18:02:00 -0200878 ret = tracer_init(trace, tr);
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100879 if (ret) {
880 warn_failed_init_tracer(trace, ret);
881 return ret;
882 }
883
Steven Rostedt60a11772008-05-12 21:20:44 +0200884 /* reset the max latency */
885 tracing_max_latency = 0;
886 /* disable preemption for a bit */
887 preempt_disable();
888 udelay(100);
889 preempt_enable();
Frederic Weisbecker49036202009-03-17 22:38:58 +0100890
891 /*
892 * Stop the tracer to avoid a warning subsequent
893 * to buffer flipping failure because tracing_stop()
894 * disables the tr and max buffers, making flipping impossible
895 * in case of parallels max preempt off latencies.
896 */
897 trace->stop(tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200898 /* stop the tracing. */
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500899 tracing_stop();
Steven Rostedt60a11772008-05-12 21:20:44 +0200900 /* check both trace buffers */
901 ret = trace_test_buffer(tr, NULL);
902 if (!ret)
903 ret = trace_test_buffer(&max_tr, &count);
904 trace->reset(tr);
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500905 tracing_start();
Steven Rostedt60a11772008-05-12 21:20:44 +0200906
907 if (!ret && !count) {
908 printk(KERN_CONT ".. no entries found ..");
909 ret = -1;
910 }
911
912 tracing_max_latency = save_max;
913
914 return ret;
915}
916#endif /* CONFIG_PREEMPT_TRACER */
917
918#if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
919int
920trace_selftest_startup_preemptirqsoff(struct tracer *trace, struct trace_array *tr)
921{
922 unsigned long save_max = tracing_max_latency;
923 unsigned long count;
924 int ret;
925
Steven Rostedt769c48e2008-11-07 22:36:02 -0500926 /*
927 * Now that the big kernel lock is no longer preemptable,
928 * and this is called with the BKL held, it will always
929 * fail. If preemption is already disabled, simply
930 * pass the test. When the BKL is removed, or becomes
931 * preemptible again, we will once again test this,
932 * so keep it in.
933 */
934 if (preempt_count()) {
935 printk(KERN_CONT "can not test ... force ");
936 return 0;
937 }
938
Steven Rostedt60a11772008-05-12 21:20:44 +0200939 /* start the tracing */
Arnaldo Carvalho de Melob6f11df2009-02-05 18:02:00 -0200940 ret = tracer_init(trace, tr);
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100941 if (ret) {
942 warn_failed_init_tracer(trace, ret);
Frederic Weisbeckerac1d52d2009-03-16 00:32:41 +0100943 goto out_no_start;
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100944 }
Steven Rostedt60a11772008-05-12 21:20:44 +0200945
946 /* reset the max latency */
947 tracing_max_latency = 0;
948
949 /* disable preemption and interrupts for a bit */
950 preempt_disable();
951 local_irq_disable();
952 udelay(100);
953 preempt_enable();
954 /* reverse the order of preempt vs irqs */
955 local_irq_enable();
956
Frederic Weisbecker49036202009-03-17 22:38:58 +0100957 /*
958 * Stop the tracer to avoid a warning subsequent
959 * to buffer flipping failure because tracing_stop()
960 * disables the tr and max buffers, making flipping impossible
961 * in case of parallels max irqs/preempt off latencies.
962 */
963 trace->stop(tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200964 /* stop the tracing. */
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500965 tracing_stop();
Steven Rostedt60a11772008-05-12 21:20:44 +0200966 /* check both trace buffers */
967 ret = trace_test_buffer(tr, NULL);
Frederic Weisbeckerac1d52d2009-03-16 00:32:41 +0100968 if (ret)
Steven Rostedt60a11772008-05-12 21:20:44 +0200969 goto out;
970
971 ret = trace_test_buffer(&max_tr, &count);
Frederic Weisbeckerac1d52d2009-03-16 00:32:41 +0100972 if (ret)
Steven Rostedt60a11772008-05-12 21:20:44 +0200973 goto out;
974
975 if (!ret && !count) {
976 printk(KERN_CONT ".. no entries found ..");
977 ret = -1;
978 goto out;
979 }
980
981 /* do the test by disabling interrupts first this time */
982 tracing_max_latency = 0;
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500983 tracing_start();
Frederic Weisbecker49036202009-03-17 22:38:58 +0100984 trace->start(tr);
985
Steven Rostedt60a11772008-05-12 21:20:44 +0200986 preempt_disable();
987 local_irq_disable();
988 udelay(100);
989 preempt_enable();
990 /* reverse the order of preempt vs irqs */
991 local_irq_enable();
992
Frederic Weisbecker49036202009-03-17 22:38:58 +0100993 trace->stop(tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200994 /* stop the tracing. */
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500995 tracing_stop();
Steven Rostedt60a11772008-05-12 21:20:44 +0200996 /* check both trace buffers */
997 ret = trace_test_buffer(tr, NULL);
998 if (ret)
999 goto out;
1000
1001 ret = trace_test_buffer(&max_tr, &count);
1002
1003 if (!ret && !count) {
1004 printk(KERN_CONT ".. no entries found ..");
1005 ret = -1;
1006 goto out;
1007 }
1008
Frederic Weisbeckerac1d52d2009-03-16 00:32:41 +01001009out:
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -05001010 tracing_start();
Frederic Weisbeckerac1d52d2009-03-16 00:32:41 +01001011out_no_start:
1012 trace->reset(tr);
Steven Rostedt60a11772008-05-12 21:20:44 +02001013 tracing_max_latency = save_max;
1014
1015 return ret;
1016}
1017#endif /* CONFIG_IRQSOFF_TRACER && CONFIG_PREEMPT_TRACER */
1018
Steven Noonanfb1b6d82008-09-19 03:06:43 -07001019#ifdef CONFIG_NOP_TRACER
1020int
1021trace_selftest_startup_nop(struct tracer *trace, struct trace_array *tr)
1022{
1023 /* What could possibly go wrong? */
1024 return 0;
1025}
1026#endif
1027
Steven Rostedt60a11772008-05-12 21:20:44 +02001028#ifdef CONFIG_SCHED_TRACER
1029static int trace_wakeup_test_thread(void *data)
1030{
Steven Rostedt05bd68c2008-05-12 21:20:59 +02001031 /* Make this a RT thread, doesn't need to be too high */
Peter Zijlstrac9b5f502011-01-07 13:41:40 +01001032 static const struct sched_param param = { .sched_priority = 5 };
Steven Rostedt60a11772008-05-12 21:20:44 +02001033 struct completion *x = data;
1034
Steven Rostedt05bd68c2008-05-12 21:20:59 +02001035 sched_setscheduler(current, SCHED_FIFO, &param);
Steven Rostedt60a11772008-05-12 21:20:44 +02001036
1037 /* Make it know we have a new prio */
1038 complete(x);
1039
1040 /* now go to sleep and let the test wake us up */
1041 set_current_state(TASK_INTERRUPTIBLE);
1042 schedule();
1043
1044 /* we are awake, now wait to disappear */
1045 while (!kthread_should_stop()) {
1046 /*
1047 * This is an RT task, do short sleeps to let
1048 * others run.
1049 */
1050 msleep(100);
1051 }
1052
1053 return 0;
1054}
1055
1056int
1057trace_selftest_startup_wakeup(struct tracer *trace, struct trace_array *tr)
1058{
1059 unsigned long save_max = tracing_max_latency;
1060 struct task_struct *p;
1061 struct completion isrt;
1062 unsigned long count;
1063 int ret;
1064
1065 init_completion(&isrt);
1066
1067 /* create a high prio thread */
1068 p = kthread_run(trace_wakeup_test_thread, &isrt, "ftrace-test");
Ingo Molnarc7aafc52008-05-12 21:20:45 +02001069 if (IS_ERR(p)) {
Steven Rostedt60a11772008-05-12 21:20:44 +02001070 printk(KERN_CONT "Failed to create ftrace wakeup test thread ");
1071 return -1;
1072 }
1073
1074 /* make sure the thread is running at an RT prio */
1075 wait_for_completion(&isrt);
1076
1077 /* start the tracing */
Arnaldo Carvalho de Melob6f11df2009-02-05 18:02:00 -02001078 ret = tracer_init(trace, tr);
Frederic Weisbecker1c800252008-11-16 05:57:26 +01001079 if (ret) {
1080 warn_failed_init_tracer(trace, ret);
1081 return ret;
1082 }
1083
Steven Rostedt60a11772008-05-12 21:20:44 +02001084 /* reset the max latency */
1085 tracing_max_latency = 0;
1086
1087 /* sleep to let the RT thread sleep too */
1088 msleep(100);
1089
1090 /*
1091 * Yes this is slightly racy. It is possible that for some
1092 * strange reason that the RT thread we created, did not
1093 * call schedule for 100ms after doing the completion,
1094 * and we do a wakeup on a task that already is awake.
1095 * But that is extremely unlikely, and the worst thing that
1096 * happens in such a case, is that we disable tracing.
1097 * Honestly, if this race does happen something is horrible
1098 * wrong with the system.
1099 */
1100
1101 wake_up_process(p);
1102
Steven Rostedt5aa60c62008-09-29 23:02:37 -04001103 /* give a little time to let the thread wake up */
1104 msleep(100);
1105
Steven Rostedt60a11772008-05-12 21:20:44 +02001106 /* stop the tracing. */
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -05001107 tracing_stop();
Steven Rostedt60a11772008-05-12 21:20:44 +02001108 /* check both trace buffers */
1109 ret = trace_test_buffer(tr, NULL);
1110 if (!ret)
1111 ret = trace_test_buffer(&max_tr, &count);
1112
1113
1114 trace->reset(tr);
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -05001115 tracing_start();
Steven Rostedt60a11772008-05-12 21:20:44 +02001116
1117 tracing_max_latency = save_max;
1118
1119 /* kill the thread */
1120 kthread_stop(p);
1121
1122 if (!ret && !count) {
1123 printk(KERN_CONT ".. no entries found ..");
1124 ret = -1;
1125 }
1126
1127 return ret;
1128}
1129#endif /* CONFIG_SCHED_TRACER */
1130
1131#ifdef CONFIG_CONTEXT_SWITCH_TRACER
1132int
1133trace_selftest_startup_sched_switch(struct tracer *trace, struct trace_array *tr)
1134{
1135 unsigned long count;
1136 int ret;
1137
1138 /* start the tracing */
Arnaldo Carvalho de Melob6f11df2009-02-05 18:02:00 -02001139 ret = tracer_init(trace, tr);
Frederic Weisbecker1c800252008-11-16 05:57:26 +01001140 if (ret) {
1141 warn_failed_init_tracer(trace, ret);
1142 return ret;
1143 }
1144
Steven Rostedt60a11772008-05-12 21:20:44 +02001145 /* Sleep for a 1/10 of a second */
1146 msleep(100);
1147 /* stop the tracing. */
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -05001148 tracing_stop();
Steven Rostedt60a11772008-05-12 21:20:44 +02001149 /* check the trace buffer */
1150 ret = trace_test_buffer(tr, &count);
1151 trace->reset(tr);
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -05001152 tracing_start();
Steven Rostedt60a11772008-05-12 21:20:44 +02001153
1154 if (!ret && !count) {
1155 printk(KERN_CONT ".. no entries found ..");
1156 ret = -1;
1157 }
1158
1159 return ret;
1160}
1161#endif /* CONFIG_CONTEXT_SWITCH_TRACER */
Ingo Molnara6dd24f2008-05-12 21:20:47 +02001162
Steven Rostedt80e5ea42008-11-12 15:24:24 -05001163#ifdef CONFIG_BRANCH_TRACER
1164int
1165trace_selftest_startup_branch(struct tracer *trace, struct trace_array *tr)
1166{
1167 unsigned long count;
1168 int ret;
1169
1170 /* start the tracing */
Arnaldo Carvalho de Melob6f11df2009-02-05 18:02:00 -02001171 ret = tracer_init(trace, tr);
Frederic Weisbecker1c800252008-11-16 05:57:26 +01001172 if (ret) {
1173 warn_failed_init_tracer(trace, ret);
1174 return ret;
1175 }
1176
Steven Rostedt80e5ea42008-11-12 15:24:24 -05001177 /* Sleep for a 1/10 of a second */
1178 msleep(100);
1179 /* stop the tracing. */
1180 tracing_stop();
1181 /* check the trace buffer */
1182 ret = trace_test_buffer(tr, &count);
1183 trace->reset(tr);
1184 tracing_start();
1185
Wenji Huangd2ef7c22009-02-17 01:09:47 -05001186 if (!ret && !count) {
1187 printk(KERN_CONT ".. no entries found ..");
1188 ret = -1;
1189 }
1190
Steven Rostedt80e5ea42008-11-12 15:24:24 -05001191 return ret;
1192}
1193#endif /* CONFIG_BRANCH_TRACER */
Markus Metzger321bb5e2009-03-13 10:50:27 +01001194