1 /* Include in trace.c */
3 #include <linux/stringify.h>
4 #include <linux/kthread.h>
5 #include <linux/delay.h>
6 #include <linux/slab.h>
8 static inline int trace_valid_entry(struct trace_entry
*entry
)
10 switch (entry
->type
) {
24 static int trace_test_buffer_cpu(struct trace_array
*tr
, int cpu
)
26 struct ring_buffer_event
*event
;
27 struct trace_entry
*entry
;
28 unsigned int loops
= 0;
30 while ((event
= ring_buffer_consume(tr
->buffer
, cpu
, NULL
, NULL
))) {
31 entry
= ring_buffer_event_data(event
);
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.
38 if (loops
++ > trace_buf_size
) {
39 printk(KERN_CONT
".. bad ring buffer ");
42 if (!trace_valid_entry(entry
)) {
43 printk(KERN_CONT
".. invalid entry %d ",
53 printk(KERN_CONT
".. corrupted trace buffer .. ");
58 * Test the trace buffer to see if all the elements
61 static int trace_test_buffer(struct trace_array
*tr
, unsigned long *count
)
63 unsigned long flags
, cnt
= 0;
66 /* Don't allow flipping of max traces now */
67 local_irq_save(flags
);
68 arch_spin_lock(&ftrace_max_lock
);
70 cnt
= ring_buffer_entries(tr
->buffer
);
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
80 for_each_possible_cpu(cpu
) {
81 ret
= trace_test_buffer_cpu(tr
, cpu
);
86 arch_spin_unlock(&ftrace_max_lock
);
87 local_irq_restore(flags
);
95 static inline void warn_failed_init_tracer(struct tracer
*trace
, int init_ret
)
97 printk(KERN_WARNING
"Failed to init %s tracer, init returned %d\n",
98 trace
->name
, init_ret
);
100 #ifdef CONFIG_FUNCTION_TRACER
102 #ifdef CONFIG_DYNAMIC_FTRACE
104 static int trace_selftest_test_probe1_cnt
;
105 static void trace_selftest_test_probe1_func(unsigned long ip
,
107 struct ftrace_ops
*op
,
108 struct pt_regs
*pt_regs
)
110 trace_selftest_test_probe1_cnt
++;
113 static int trace_selftest_test_probe2_cnt
;
114 static void trace_selftest_test_probe2_func(unsigned long ip
,
116 struct ftrace_ops
*op
,
117 struct pt_regs
*pt_regs
)
119 trace_selftest_test_probe2_cnt
++;
122 static int trace_selftest_test_probe3_cnt
;
123 static void trace_selftest_test_probe3_func(unsigned long ip
,
125 struct ftrace_ops
*op
,
126 struct pt_regs
*pt_regs
)
128 trace_selftest_test_probe3_cnt
++;
131 static int trace_selftest_test_global_cnt
;
132 static void trace_selftest_test_global_func(unsigned long ip
,
134 struct ftrace_ops
*op
,
135 struct pt_regs
*pt_regs
)
137 trace_selftest_test_global_cnt
++;
140 static int trace_selftest_test_dyn_cnt
;
141 static void trace_selftest_test_dyn_func(unsigned long ip
,
143 struct ftrace_ops
*op
,
144 struct pt_regs
*pt_regs
)
146 trace_selftest_test_dyn_cnt
++;
149 static struct ftrace_ops test_probe1
= {
150 .func
= trace_selftest_test_probe1_func
,
151 .flags
= FTRACE_OPS_FL_RECURSION_SAFE
,
154 static struct ftrace_ops test_probe2
= {
155 .func
= trace_selftest_test_probe2_func
,
156 .flags
= FTRACE_OPS_FL_RECURSION_SAFE
,
159 static struct ftrace_ops test_probe3
= {
160 .func
= trace_selftest_test_probe3_func
,
161 .flags
= FTRACE_OPS_FL_RECURSION_SAFE
,
164 static struct ftrace_ops test_global
= {
165 .func
= trace_selftest_test_global_func
,
166 .flags
= FTRACE_OPS_FL_GLOBAL
| FTRACE_OPS_FL_RECURSION_SAFE
,
169 static void print_counts(void)
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
);
179 static void reset_counts(void)
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;
188 static int trace_selftest_ops(int cnt
)
190 int save_ftrace_enabled
= ftrace_enabled
;
191 struct ftrace_ops
*dyn_ops
;
198 printk(KERN_CONT
"PASSED\n");
199 pr_info("Testing dynamic ftrace ops #%d: ", cnt
);
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
);
211 * Probe 1 will trace function 1.
212 * Probe 2 will trace function 2.
213 * Probe 3 will trace functions 1 and 2.
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);
220 register_ftrace_function(&test_probe1
);
221 register_ftrace_function(&test_probe2
);
222 register_ftrace_function(&test_probe3
);
223 register_ftrace_function(&test_global
);
225 DYN_FTRACE_TEST_NAME();
229 if (trace_selftest_test_probe1_cnt
!= 1)
231 if (trace_selftest_test_probe2_cnt
!= 0)
233 if (trace_selftest_test_probe3_cnt
!= 1)
235 if (trace_selftest_test_global_cnt
== 0)
238 DYN_FTRACE_TEST_NAME2();
242 if (trace_selftest_test_probe1_cnt
!= 1)
244 if (trace_selftest_test_probe2_cnt
!= 1)
246 if (trace_selftest_test_probe3_cnt
!= 2)
249 /* Add a dynamic probe */
250 dyn_ops
= kzalloc(sizeof(*dyn_ops
), GFP_KERNEL
);
252 printk("MEMORY ERROR ");
256 dyn_ops
->func
= trace_selftest_test_dyn_func
;
258 register_ftrace_function(dyn_ops
);
260 trace_selftest_test_global_cnt
= 0;
262 DYN_FTRACE_TEST_NAME();
266 if (trace_selftest_test_probe1_cnt
!= 2)
268 if (trace_selftest_test_probe2_cnt
!= 1)
270 if (trace_selftest_test_probe3_cnt
!= 3)
272 if (trace_selftest_test_global_cnt
== 0)
274 if (trace_selftest_test_dyn_cnt
== 0)
277 DYN_FTRACE_TEST_NAME2();
281 if (trace_selftest_test_probe1_cnt
!= 2)
283 if (trace_selftest_test_probe2_cnt
!= 2)
285 if (trace_selftest_test_probe3_cnt
!= 4)
290 unregister_ftrace_function(dyn_ops
);
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
);
300 /* Make sure everything is off */
302 DYN_FTRACE_TEST_NAME();
303 DYN_FTRACE_TEST_NAME();
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
)
312 ftrace_enabled
= save_ftrace_enabled
;
317 /* Test dynamic code modification and ftrace filters */
318 int trace_selftest_startup_dynamic_tracing(struct tracer
*trace
,
319 struct trace_array
*tr
,
322 int save_ftrace_enabled
= ftrace_enabled
;
323 int save_tracer_enabled
= tracer_enabled
;
328 /* The ftrace test PASSED */
329 printk(KERN_CONT
"PASSED\n");
330 pr_info("Testing dynamic ftrace: ");
332 /* enable tracing, and record the filter function */
336 /* passed in by parameter to fool gcc from optimizing */
340 * Some archs *cough*PowerPC*cough* add characters to the
341 * start of the function names. We simply put a '*' to
344 func_name
= "*" __stringify(DYN_FTRACE_TEST_NAME
);
346 /* filter only on our function */
347 ftrace_set_global_filter(func_name
, strlen(func_name
), 1);
350 ret
= tracer_init(trace
, tr
);
352 warn_failed_init_tracer(trace
, ret
);
356 /* Sleep for a 1/10 of a second */
359 /* we should have nothing in the buffer */
360 ret
= trace_test_buffer(tr
, &count
);
366 printk(KERN_CONT
".. filter did not filter .. ");
370 /* call our function again */
376 /* stop the tracing. */
380 /* check the trace buffer */
381 ret
= trace_test_buffer(tr
, &count
);
384 /* we should only have one item */
385 if (!ret
&& count
!= 1) {
387 printk(KERN_CONT
".. filter failed count=%ld ..", count
);
392 /* Test the ops with global tracing running */
393 ret
= trace_selftest_ops(1);
397 ftrace_enabled
= save_ftrace_enabled
;
398 tracer_enabled
= save_tracer_enabled
;
400 /* Enable tracing on all functions again */
401 ftrace_set_global_filter(NULL
, 0, 1);
403 /* Test the ops with global tracing off */
405 ret
= trace_selftest_ops(2);
410 static int trace_selftest_recursion_cnt
;
411 static void trace_selftest_test_recursion_func(unsigned long ip
,
413 struct ftrace_ops
*op
,
414 struct pt_regs
*pt_regs
)
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!
421 trace_selftest_recursion_cnt
++;
422 DYN_FTRACE_TEST_NAME();
425 static void trace_selftest_test_recursion_safe_func(unsigned long ip
,
427 struct ftrace_ops
*op
,
428 struct pt_regs
*pt_regs
)
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
437 if (trace_selftest_recursion_cnt
++)
439 DYN_FTRACE_TEST_NAME();
442 static struct ftrace_ops test_rec_probe
= {
443 .func
= trace_selftest_test_recursion_func
,
446 static struct ftrace_ops test_recsafe_probe
= {
447 .func
= trace_selftest_test_recursion_safe_func
,
448 .flags
= FTRACE_OPS_FL_RECURSION_SAFE
,
452 trace_selftest_function_recursion(void)
454 int save_ftrace_enabled
= ftrace_enabled
;
455 int save_tracer_enabled
= tracer_enabled
;
461 /* The previous test PASSED */
463 pr_info("Testing ftrace recursion: ");
466 /* enable tracing, and record the filter function */
470 /* Handle PPC64 '.' name */
471 func_name
= "*" __stringify(DYN_FTRACE_TEST_NAME
);
472 len
= strlen(func_name
);
474 ret
= ftrace_set_filter(&test_rec_probe
, func_name
, len
, 1);
476 pr_cont("*Could not set filter* ");
480 ret
= register_ftrace_function(&test_rec_probe
);
482 pr_cont("*could not register callback* ");
486 DYN_FTRACE_TEST_NAME();
488 unregister_ftrace_function(&test_rec_probe
);
491 if (trace_selftest_recursion_cnt
!= 1) {
492 pr_cont("*callback not called once (%d)* ",
493 trace_selftest_recursion_cnt
);
497 trace_selftest_recursion_cnt
= 1;
500 pr_info("Testing ftrace recursion safe: ");
502 ret
= ftrace_set_filter(&test_recsafe_probe
, func_name
, len
, 1);
504 pr_cont("*Could not set filter* ");
508 ret
= register_ftrace_function(&test_recsafe_probe
);
510 pr_cont("*could not register callback* ");
514 DYN_FTRACE_TEST_NAME();
516 unregister_ftrace_function(&test_recsafe_probe
);
519 * If arch supports all ftrace features, and no other task
520 * was on the list, we should be fine.
522 if (!ftrace_nr_registered_ops() && !FTRACE_FORCE_LIST_FUNC
)
523 cnt
= 2; /* Should have recursed */
528 if (trace_selftest_recursion_cnt
!= cnt
) {
529 pr_cont("*callback not called expected %d times (%d)* ",
530 cnt
, trace_selftest_recursion_cnt
);
536 ftrace_enabled
= save_ftrace_enabled
;
537 tracer_enabled
= save_tracer_enabled
;
542 # define trace_selftest_startup_dynamic_tracing(trace, tr, func) ({ 0; })
543 # define trace_selftest_function_recursion() ({ 0; })
544 #endif /* CONFIG_DYNAMIC_FTRACE */
547 TRACE_SELFTEST_REGS_START
,
548 TRACE_SELFTEST_REGS_FOUND
,
549 TRACE_SELFTEST_REGS_NOT_FOUND
,
550 } trace_selftest_regs_stat
;
552 static void trace_selftest_test_regs_func(unsigned long ip
,
554 struct ftrace_ops
*op
,
555 struct pt_regs
*pt_regs
)
558 trace_selftest_regs_stat
= TRACE_SELFTEST_REGS_FOUND
;
560 trace_selftest_regs_stat
= TRACE_SELFTEST_REGS_NOT_FOUND
;
563 static 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
,
569 trace_selftest_function_regs(void)
571 int save_ftrace_enabled
= ftrace_enabled
;
572 int save_tracer_enabled
= tracer_enabled
;
578 #ifdef ARCH_SUPPORTS_FTRACE_SAVE_REGS
582 /* The previous test PASSED */
584 pr_info("Testing ftrace regs%s: ",
585 !supported
? "(no arch support)" : "");
587 /* enable tracing, and record the filter function */
591 /* Handle PPC64 '.' name */
592 func_name
= "*" __stringify(DYN_FTRACE_TEST_NAME
);
593 len
= strlen(func_name
);
595 ret
= ftrace_set_filter(&test_regs_probe
, func_name
, len
, 1);
597 * If DYNAMIC_FTRACE is not set, then we just trace all functions.
598 * This test really doesn't care.
600 if (ret
&& ret
!= -ENODEV
) {
601 pr_cont("*Could not set filter* ");
605 ret
= register_ftrace_function(&test_regs_probe
);
607 * Now if the arch does not support passing regs, then this should
612 pr_cont("*registered save-regs without arch support* ");
615 test_regs_probe
.flags
|= FTRACE_OPS_FL_SAVE_REGS_IF_SUPPORTED
;
616 ret
= register_ftrace_function(&test_regs_probe
);
619 pr_cont("*could not register callback* ");
624 DYN_FTRACE_TEST_NAME();
626 unregister_ftrace_function(&test_regs_probe
);
630 switch (trace_selftest_regs_stat
) {
631 case TRACE_SELFTEST_REGS_START
:
632 pr_cont("*callback never called* ");
635 case TRACE_SELFTEST_REGS_FOUND
:
638 pr_cont("*callback received regs without arch support* ");
641 case TRACE_SELFTEST_REGS_NOT_FOUND
:
644 pr_cont("*callback received NULL regs* ");
650 ftrace_enabled
= save_ftrace_enabled
;
651 tracer_enabled
= save_tracer_enabled
;
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.
662 trace_selftest_startup_function(struct tracer
*trace
, struct trace_array
*tr
)
664 int save_ftrace_enabled
= ftrace_enabled
;
665 int save_tracer_enabled
= tracer_enabled
;
669 /* make sure msleep has been recorded */
672 /* start the tracing */
676 ret
= tracer_init(trace
, tr
);
678 warn_failed_init_tracer(trace
, ret
);
682 /* Sleep for a 1/10 of a second */
684 /* stop the tracing. */
688 /* check the trace buffer */
689 ret
= trace_test_buffer(tr
, &count
);
693 if (!ret
&& !count
) {
694 printk(KERN_CONT
".. no entries found ..");
699 ret
= trace_selftest_startup_dynamic_tracing(trace
, tr
,
700 DYN_FTRACE_TEST_NAME
);
704 ret
= trace_selftest_function_recursion();
708 ret
= trace_selftest_function_regs();
710 ftrace_enabled
= save_ftrace_enabled
;
711 tracer_enabled
= save_tracer_enabled
;
713 /* kill ftrace totally if we failed */
719 #endif /* CONFIG_FUNCTION_TRACER */
722 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
724 /* Maximum number of functions to trace before diagnosing a hang */
725 #define GRAPH_MAX_FUNC_TEST 100000000
728 __ftrace_dump(bool disable_tracing
, enum ftrace_dump_mode oops_dump_mode
);
729 static unsigned int graph_hang_thresh
;
731 /* Wrap the real function entry probe to avoid possible hanging */
732 static int trace_graph_entry_watchdog(struct ftrace_graph_ent
*trace
)
734 /* This is harmlessly racy, we want to approximately detect a hang */
735 if (unlikely(++graph_hang_thresh
> GRAPH_MAX_FUNC_TEST
)) {
737 printk(KERN_WARNING
"BUG: Function graph tracer hang!\n");
738 if (ftrace_dump_on_oops
)
739 __ftrace_dump(false, DUMP_ALL
);
743 return trace_graph_entry(trace
);
747 * Pretty much the same than for the function tracer from which the selftest
751 trace_selftest_startup_function_graph(struct tracer
*trace
,
752 struct trace_array
*tr
)
758 * Simulate the init() callback but we attach a watchdog callback
759 * to detect and recover from possible hangs
761 tracing_reset_online_cpus(tr
);
763 ret
= register_ftrace_graph(&trace_graph_return
,
764 &trace_graph_entry_watchdog
);
766 warn_failed_init_tracer(trace
, ret
);
769 tracing_start_cmdline_record();
771 /* Sleep for a 1/10 of a second */
774 /* Have we just recovered from a hang? */
775 if (graph_hang_thresh
> GRAPH_MAX_FUNC_TEST
) {
776 tracing_selftest_disabled
= true;
783 /* check the trace buffer */
784 ret
= trace_test_buffer(tr
, &count
);
789 if (!ret
&& !count
) {
790 printk(KERN_CONT
".. no entries found ..");
795 /* Don't test dynamic tracing, the function tracer already did */
798 /* Stop it if we failed */
804 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
807 #ifdef CONFIG_IRQSOFF_TRACER
809 trace_selftest_startup_irqsoff(struct tracer
*trace
, struct trace_array
*tr
)
811 unsigned long save_max
= tracing_max_latency
;
815 /* start the tracing */
816 ret
= tracer_init(trace
, tr
);
818 warn_failed_init_tracer(trace
, ret
);
822 /* reset the max latency */
823 tracing_max_latency
= 0;
824 /* disable interrupts for a bit */
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.
836 /* stop the tracing. */
838 /* check both trace buffers */
839 ret
= trace_test_buffer(tr
, NULL
);
841 ret
= trace_test_buffer(&max_tr
, &count
);
845 if (!ret
&& !count
) {
846 printk(KERN_CONT
".. no entries found ..");
850 tracing_max_latency
= save_max
;
854 #endif /* CONFIG_IRQSOFF_TRACER */
856 #ifdef CONFIG_PREEMPT_TRACER
858 trace_selftest_startup_preemptoff(struct tracer
*trace
, struct trace_array
*tr
)
860 unsigned long save_max
= tracing_max_latency
;
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,
872 if (preempt_count()) {
873 printk(KERN_CONT
"can not test ... force ");
877 /* start the tracing */
878 ret
= tracer_init(trace
, tr
);
880 warn_failed_init_tracer(trace
, ret
);
884 /* reset the max latency */
885 tracing_max_latency
= 0;
886 /* disable preemption for a bit */
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.
898 /* stop the tracing. */
900 /* check both trace buffers */
901 ret
= trace_test_buffer(tr
, NULL
);
903 ret
= trace_test_buffer(&max_tr
, &count
);
907 if (!ret
&& !count
) {
908 printk(KERN_CONT
".. no entries found ..");
912 tracing_max_latency
= save_max
;
916 #endif /* CONFIG_PREEMPT_TRACER */
918 #if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
920 trace_selftest_startup_preemptirqsoff(struct tracer
*trace
, struct trace_array
*tr
)
922 unsigned long save_max
= tracing_max_latency
;
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,
934 if (preempt_count()) {
935 printk(KERN_CONT
"can not test ... force ");
939 /* start the tracing */
940 ret
= tracer_init(trace
, tr
);
942 warn_failed_init_tracer(trace
, ret
);
946 /* reset the max latency */
947 tracing_max_latency
= 0;
949 /* disable preemption and interrupts for a bit */
954 /* reverse the order of preempt vs irqs */
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.
964 /* stop the tracing. */
966 /* check both trace buffers */
967 ret
= trace_test_buffer(tr
, NULL
);
971 ret
= trace_test_buffer(&max_tr
, &count
);
975 if (!ret
&& !count
) {
976 printk(KERN_CONT
".. no entries found ..");
981 /* do the test by disabling interrupts first this time */
982 tracing_max_latency
= 0;
990 /* reverse the order of preempt vs irqs */
994 /* stop the tracing. */
996 /* check both trace buffers */
997 ret
= trace_test_buffer(tr
, NULL
);
1001 ret
= trace_test_buffer(&max_tr
, &count
);
1003 if (!ret
&& !count
) {
1004 printk(KERN_CONT
".. no entries found ..");
1013 tracing_max_latency
= save_max
;
1017 #endif /* CONFIG_IRQSOFF_TRACER && CONFIG_PREEMPT_TRACER */
1019 #ifdef CONFIG_NOP_TRACER
1021 trace_selftest_startup_nop(struct tracer
*trace
, struct trace_array
*tr
)
1023 /* What could possibly go wrong? */
1028 #ifdef CONFIG_SCHED_TRACER
1029 static int trace_wakeup_test_thread(void *data
)
1031 /* Make this a RT thread, doesn't need to be too high */
1032 static const struct sched_param param
= { .sched_priority
= 5 };
1033 struct completion
*x
= data
;
1035 sched_setscheduler(current
, SCHED_FIFO
, ¶m
);
1037 /* Make it know we have a new prio */
1040 /* now go to sleep and let the test wake us up */
1041 set_current_state(TASK_INTERRUPTIBLE
);
1046 /* we are awake, now wait to disappear */
1047 while (!kthread_should_stop()) {
1049 * This is an RT task, do short sleeps to let
1059 trace_selftest_startup_wakeup(struct tracer
*trace
, struct trace_array
*tr
)
1061 unsigned long save_max
= tracing_max_latency
;
1062 struct task_struct
*p
;
1063 struct completion isrt
;
1064 unsigned long count
;
1067 init_completion(&isrt
);
1069 /* create a high prio thread */
1070 p
= kthread_run(trace_wakeup_test_thread
, &isrt
, "ftrace-test");
1072 printk(KERN_CONT
"Failed to create ftrace wakeup test thread ");
1076 /* make sure the thread is running at an RT prio */
1077 wait_for_completion(&isrt
);
1079 /* start the tracing */
1080 ret
= tracer_init(trace
, tr
);
1082 warn_failed_init_tracer(trace
, ret
);
1086 /* reset the max latency */
1087 tracing_max_latency
= 0;
1091 * Sleep to make sure the RT thread is asleep too.
1092 * On virtual machines we can't rely on timings,
1093 * but we want to make sure this test still works.
1098 init_completion(&isrt
);
1102 /* Wait for the task to wake up */
1103 wait_for_completion(&isrt
);
1105 /* stop the tracing. */
1107 /* check both trace buffers */
1108 ret
= trace_test_buffer(tr
, NULL
);
1110 ret
= trace_test_buffer(&max_tr
, &count
);
1116 tracing_max_latency
= save_max
;
1118 /* kill the thread */
1121 if (!ret
&& !count
) {
1122 printk(KERN_CONT
".. no entries found ..");
1128 #endif /* CONFIG_SCHED_TRACER */
1130 #ifdef CONFIG_CONTEXT_SWITCH_TRACER
1132 trace_selftest_startup_sched_switch(struct tracer
*trace
, struct trace_array
*tr
)
1134 unsigned long count
;
1137 /* start the tracing */
1138 ret
= tracer_init(trace
, tr
);
1140 warn_failed_init_tracer(trace
, ret
);
1144 /* Sleep for a 1/10 of a second */
1146 /* stop the tracing. */
1148 /* check the trace buffer */
1149 ret
= trace_test_buffer(tr
, &count
);
1153 if (!ret
&& !count
) {
1154 printk(KERN_CONT
".. no entries found ..");
1160 #endif /* CONFIG_CONTEXT_SWITCH_TRACER */
1162 #ifdef CONFIG_BRANCH_TRACER
1164 trace_selftest_startup_branch(struct tracer
*trace
, struct trace_array
*tr
)
1166 unsigned long count
;
1169 /* start the tracing */
1170 ret
= tracer_init(trace
, tr
);
1172 warn_failed_init_tracer(trace
, ret
);
1176 /* Sleep for a 1/10 of a second */
1178 /* stop the tracing. */
1180 /* check the trace buffer */
1181 ret
= trace_test_buffer(tr
, &count
);
1185 if (!ret
&& !count
) {
1186 printk(KERN_CONT
".. no entries found ..");
1192 #endif /* CONFIG_BRANCH_TRACER */