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