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_buffer
*buf
, int cpu
)
26 struct ring_buffer_event
*event
;
27 struct trace_entry
*entry
;
28 unsigned int loops
= 0;
30 while ((event
= ring_buffer_consume(buf
->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_buffer
*buf
, 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(&buf
->tr
->max_lock
);
70 cnt
= ring_buffer_entries(buf
->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(buf
, cpu
);
86 arch_spin_unlock(&buf
->tr
->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 void print_counts(void)
166 printk("(%d %d %d %d %d) ",
167 trace_selftest_test_probe1_cnt
,
168 trace_selftest_test_probe2_cnt
,
169 trace_selftest_test_probe3_cnt
,
170 trace_selftest_test_global_cnt
,
171 trace_selftest_test_dyn_cnt
);
174 static void reset_counts(void)
176 trace_selftest_test_probe1_cnt
= 0;
177 trace_selftest_test_probe2_cnt
= 0;
178 trace_selftest_test_probe3_cnt
= 0;
179 trace_selftest_test_global_cnt
= 0;
180 trace_selftest_test_dyn_cnt
= 0;
183 static int trace_selftest_ops(struct trace_array
*tr
, int cnt
)
185 int save_ftrace_enabled
= ftrace_enabled
;
186 struct ftrace_ops
*dyn_ops
;
193 printk(KERN_CONT
"PASSED\n");
194 pr_info("Testing dynamic ftrace ops #%d: ", cnt
);
199 /* Handle PPC64 '.' name */
200 func1_name
= "*" __stringify(DYN_FTRACE_TEST_NAME
);
201 func2_name
= "*" __stringify(DYN_FTRACE_TEST_NAME2
);
202 len1
= strlen(func1_name
);
203 len2
= strlen(func2_name
);
206 * Probe 1 will trace function 1.
207 * Probe 2 will trace function 2.
208 * Probe 3 will trace functions 1 and 2.
210 ftrace_set_filter(&test_probe1
, func1_name
, len1
, 1);
211 ftrace_set_filter(&test_probe2
, func2_name
, len2
, 1);
212 ftrace_set_filter(&test_probe3
, func1_name
, len1
, 1);
213 ftrace_set_filter(&test_probe3
, func2_name
, len2
, 0);
215 register_ftrace_function(&test_probe1
);
216 register_ftrace_function(&test_probe2
);
217 register_ftrace_function(&test_probe3
);
218 /* First time we are running with main function */
220 ftrace_init_array_ops(tr
, trace_selftest_test_global_func
);
221 register_ftrace_function(tr
->ops
);
224 DYN_FTRACE_TEST_NAME();
228 if (trace_selftest_test_probe1_cnt
!= 1)
230 if (trace_selftest_test_probe2_cnt
!= 0)
232 if (trace_selftest_test_probe3_cnt
!= 1)
235 if (trace_selftest_test_global_cnt
== 0)
239 DYN_FTRACE_TEST_NAME2();
243 if (trace_selftest_test_probe1_cnt
!= 1)
245 if (trace_selftest_test_probe2_cnt
!= 1)
247 if (trace_selftest_test_probe3_cnt
!= 2)
250 /* Add a dynamic probe */
251 dyn_ops
= kzalloc(sizeof(*dyn_ops
), GFP_KERNEL
);
253 printk("MEMORY ERROR ");
257 dyn_ops
->func
= trace_selftest_test_dyn_func
;
259 register_ftrace_function(dyn_ops
);
261 trace_selftest_test_global_cnt
= 0;
263 DYN_FTRACE_TEST_NAME();
267 if (trace_selftest_test_probe1_cnt
!= 2)
269 if (trace_selftest_test_probe2_cnt
!= 1)
271 if (trace_selftest_test_probe3_cnt
!= 3)
274 if (trace_selftest_test_global_cnt
== 0)
277 if (trace_selftest_test_dyn_cnt
== 0)
280 DYN_FTRACE_TEST_NAME2();
284 if (trace_selftest_test_probe1_cnt
!= 2)
286 if (trace_selftest_test_probe2_cnt
!= 2)
288 if (trace_selftest_test_probe3_cnt
!= 4)
293 unregister_ftrace_function(dyn_ops
);
297 /* Purposely unregister in the same order */
298 unregister_ftrace_function(&test_probe1
);
299 unregister_ftrace_function(&test_probe2
);
300 unregister_ftrace_function(&test_probe3
);
302 unregister_ftrace_function(tr
->ops
);
303 ftrace_reset_array_ops(tr
);
305 /* Make sure everything is off */
307 DYN_FTRACE_TEST_NAME();
308 DYN_FTRACE_TEST_NAME();
310 if (trace_selftest_test_probe1_cnt
||
311 trace_selftest_test_probe2_cnt
||
312 trace_selftest_test_probe3_cnt
||
313 trace_selftest_test_global_cnt
||
314 trace_selftest_test_dyn_cnt
)
317 ftrace_enabled
= save_ftrace_enabled
;
322 /* Test dynamic code modification and ftrace filters */
323 static int trace_selftest_startup_dynamic_tracing(struct tracer
*trace
,
324 struct trace_array
*tr
,
327 int save_ftrace_enabled
= ftrace_enabled
;
332 /* The ftrace test PASSED */
333 printk(KERN_CONT
"PASSED\n");
334 pr_info("Testing dynamic ftrace: ");
336 /* enable tracing, and record the filter function */
339 /* passed in by parameter to fool gcc from optimizing */
343 * Some archs *cough*PowerPC*cough* add characters to the
344 * start of the function names. We simply put a '*' to
347 func_name
= "*" __stringify(DYN_FTRACE_TEST_NAME
);
349 /* filter only on our function */
350 ftrace_set_global_filter(func_name
, strlen(func_name
), 1);
353 ret
= tracer_init(trace
, tr
);
355 warn_failed_init_tracer(trace
, ret
);
359 /* Sleep for a 1/10 of a second */
362 /* we should have nothing in the buffer */
363 ret
= trace_test_buffer(&tr
->trace_buffer
, &count
);
369 printk(KERN_CONT
".. filter did not filter .. ");
373 /* call our function again */
379 /* stop the tracing. */
383 /* check the trace buffer */
384 ret
= trace_test_buffer(&tr
->trace_buffer
, &count
);
387 /* we should only have one item */
388 if (!ret
&& count
!= 1) {
390 printk(KERN_CONT
".. filter failed count=%ld ..", count
);
395 /* Test the ops with global tracing running */
396 ret
= trace_selftest_ops(tr
, 1);
400 ftrace_enabled
= save_ftrace_enabled
;
402 /* Enable tracing on all functions again */
403 ftrace_set_global_filter(NULL
, 0, 1);
405 /* Test the ops with global tracing off */
407 ret
= trace_selftest_ops(tr
, 2);
412 static int trace_selftest_recursion_cnt
;
413 static void trace_selftest_test_recursion_func(unsigned long ip
,
415 struct ftrace_ops
*op
,
416 struct pt_regs
*pt_regs
)
419 * This function is registered without the recursion safe flag.
420 * The ftrace infrastructure should provide the recursion
421 * protection. If not, this will crash the kernel!
423 if (trace_selftest_recursion_cnt
++ > 10)
425 DYN_FTRACE_TEST_NAME();
428 static void trace_selftest_test_recursion_safe_func(unsigned long ip
,
430 struct ftrace_ops
*op
,
431 struct pt_regs
*pt_regs
)
434 * We said we would provide our own recursion. By calling
435 * this function again, we should recurse back into this function
436 * and count again. But this only happens if the arch supports
437 * all of ftrace features and nothing else is using the function
440 if (trace_selftest_recursion_cnt
++)
442 DYN_FTRACE_TEST_NAME();
445 static struct ftrace_ops test_rec_probe
= {
446 .func
= trace_selftest_test_recursion_func
,
449 static struct ftrace_ops test_recsafe_probe
= {
450 .func
= trace_selftest_test_recursion_safe_func
,
451 .flags
= FTRACE_OPS_FL_RECURSION_SAFE
,
455 trace_selftest_function_recursion(void)
457 int save_ftrace_enabled
= ftrace_enabled
;
462 /* The previous test PASSED */
464 pr_info("Testing ftrace recursion: ");
467 /* 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 (trace_selftest_recursion_cnt
!= 2) {
520 pr_cont("*callback not called expected 2 times (%d)* ",
521 trace_selftest_recursion_cnt
);
527 ftrace_enabled
= save_ftrace_enabled
;
532 # define trace_selftest_startup_dynamic_tracing(trace, tr, func) ({ 0; })
533 # define trace_selftest_function_recursion() ({ 0; })
534 #endif /* CONFIG_DYNAMIC_FTRACE */
537 TRACE_SELFTEST_REGS_START
,
538 TRACE_SELFTEST_REGS_FOUND
,
539 TRACE_SELFTEST_REGS_NOT_FOUND
,
540 } trace_selftest_regs_stat
;
542 static void trace_selftest_test_regs_func(unsigned long ip
,
544 struct ftrace_ops
*op
,
545 struct pt_regs
*pt_regs
)
548 trace_selftest_regs_stat
= TRACE_SELFTEST_REGS_FOUND
;
550 trace_selftest_regs_stat
= TRACE_SELFTEST_REGS_NOT_FOUND
;
553 static struct ftrace_ops test_regs_probe
= {
554 .func
= trace_selftest_test_regs_func
,
555 .flags
= FTRACE_OPS_FL_RECURSION_SAFE
| FTRACE_OPS_FL_SAVE_REGS
,
559 trace_selftest_function_regs(void)
561 int save_ftrace_enabled
= ftrace_enabled
;
567 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
571 /* The previous test PASSED */
573 pr_info("Testing ftrace regs%s: ",
574 !supported
? "(no arch support)" : "");
576 /* enable tracing, and record the filter function */
579 /* Handle PPC64 '.' name */
580 func_name
= "*" __stringify(DYN_FTRACE_TEST_NAME
);
581 len
= strlen(func_name
);
583 ret
= ftrace_set_filter(&test_regs_probe
, func_name
, len
, 1);
585 * If DYNAMIC_FTRACE is not set, then we just trace all functions.
586 * This test really doesn't care.
588 if (ret
&& ret
!= -ENODEV
) {
589 pr_cont("*Could not set filter* ");
593 ret
= register_ftrace_function(&test_regs_probe
);
595 * Now if the arch does not support passing regs, then this should
600 pr_cont("*registered save-regs without arch support* ");
603 test_regs_probe
.flags
|= FTRACE_OPS_FL_SAVE_REGS_IF_SUPPORTED
;
604 ret
= register_ftrace_function(&test_regs_probe
);
607 pr_cont("*could not register callback* ");
612 DYN_FTRACE_TEST_NAME();
614 unregister_ftrace_function(&test_regs_probe
);
618 switch (trace_selftest_regs_stat
) {
619 case TRACE_SELFTEST_REGS_START
:
620 pr_cont("*callback never called* ");
623 case TRACE_SELFTEST_REGS_FOUND
:
626 pr_cont("*callback received regs without arch support* ");
629 case TRACE_SELFTEST_REGS_NOT_FOUND
:
632 pr_cont("*callback received NULL regs* ");
638 ftrace_enabled
= save_ftrace_enabled
;
644 * Simple verification test of ftrace function tracer.
645 * Enable ftrace, sleep 1/10 second, and then read the trace
646 * buffer to see if all is in order.
649 trace_selftest_startup_function(struct tracer
*trace
, struct trace_array
*tr
)
651 int save_ftrace_enabled
= ftrace_enabled
;
655 #ifdef CONFIG_DYNAMIC_FTRACE
656 if (ftrace_filter_param
) {
657 printk(KERN_CONT
" ... kernel command line filter set: force PASS ... ");
662 /* make sure msleep has been recorded */
665 /* start the tracing */
668 ret
= tracer_init(trace
, tr
);
670 warn_failed_init_tracer(trace
, ret
);
674 /* Sleep for a 1/10 of a second */
676 /* stop the tracing. */
680 /* check the trace buffer */
681 ret
= trace_test_buffer(&tr
->trace_buffer
, &count
);
685 if (!ret
&& !count
) {
686 printk(KERN_CONT
".. no entries found ..");
691 ret
= trace_selftest_startup_dynamic_tracing(trace
, tr
,
692 DYN_FTRACE_TEST_NAME
);
696 ret
= trace_selftest_function_recursion();
700 ret
= trace_selftest_function_regs();
702 ftrace_enabled
= save_ftrace_enabled
;
704 /* kill ftrace totally if we failed */
710 #endif /* CONFIG_FUNCTION_TRACER */
713 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
715 /* Maximum number of functions to trace before diagnosing a hang */
716 #define GRAPH_MAX_FUNC_TEST 100000000
718 static unsigned int graph_hang_thresh
;
720 /* Wrap the real function entry probe to avoid possible hanging */
721 static int trace_graph_entry_watchdog(struct ftrace_graph_ent
*trace
)
723 /* This is harmlessly racy, we want to approximately detect a hang */
724 if (unlikely(++graph_hang_thresh
> GRAPH_MAX_FUNC_TEST
)) {
726 printk(KERN_WARNING
"BUG: Function graph tracer hang!\n");
727 if (ftrace_dump_on_oops
) {
728 ftrace_dump(DUMP_ALL
);
729 /* ftrace_dump() disables tracing */
735 return trace_graph_entry(trace
);
739 * Pretty much the same than for the function tracer from which the selftest
743 trace_selftest_startup_function_graph(struct tracer
*trace
,
744 struct trace_array
*tr
)
749 #ifdef CONFIG_DYNAMIC_FTRACE
750 if (ftrace_filter_param
) {
751 printk(KERN_CONT
" ... kernel command line filter set: force PASS ... ");
757 * Simulate the init() callback but we attach a watchdog callback
758 * to detect and recover from possible hangs
760 tracing_reset_online_cpus(&tr
->trace_buffer
);
762 ret
= register_ftrace_graph(&trace_graph_return
,
763 &trace_graph_entry_watchdog
);
765 warn_failed_init_tracer(trace
, ret
);
768 tracing_start_cmdline_record();
770 /* Sleep for a 1/10 of a second */
773 /* Have we just recovered from a hang? */
774 if (graph_hang_thresh
> GRAPH_MAX_FUNC_TEST
) {
775 tracing_selftest_disabled
= true;
782 /* check the trace buffer */
783 ret
= trace_test_buffer(&tr
->trace_buffer
, &count
);
788 if (!ret
&& !count
) {
789 printk(KERN_CONT
".. no entries found ..");
794 /* Don't test dynamic tracing, the function tracer already did */
797 /* Stop it if we failed */
803 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
806 #ifdef CONFIG_IRQSOFF_TRACER
808 trace_selftest_startup_irqsoff(struct tracer
*trace
, struct trace_array
*tr
)
810 unsigned long save_max
= tr
->max_latency
;
814 /* start the tracing */
815 ret
= tracer_init(trace
, tr
);
817 warn_failed_init_tracer(trace
, ret
);
821 /* reset the max latency */
823 /* disable interrupts for a bit */
829 * Stop the tracer to avoid a warning subsequent
830 * to buffer flipping failure because tracing_stop()
831 * disables the tr and max buffers, making flipping impossible
832 * in case of parallels max irqs off latencies.
835 /* stop the tracing. */
837 /* check both trace buffers */
838 ret
= trace_test_buffer(&tr
->trace_buffer
, NULL
);
840 ret
= trace_test_buffer(&tr
->max_buffer
, &count
);
844 if (!ret
&& !count
) {
845 printk(KERN_CONT
".. no entries found ..");
849 tr
->max_latency
= save_max
;
853 #endif /* CONFIG_IRQSOFF_TRACER */
855 #ifdef CONFIG_PREEMPT_TRACER
857 trace_selftest_startup_preemptoff(struct tracer
*trace
, struct trace_array
*tr
)
859 unsigned long save_max
= tr
->max_latency
;
864 * Now that the big kernel lock is no longer preemptable,
865 * and this is called with the BKL held, it will always
866 * fail. If preemption is already disabled, simply
867 * pass the test. When the BKL is removed, or becomes
868 * preemptible again, we will once again test this,
871 if (preempt_count()) {
872 printk(KERN_CONT
"can not test ... force ");
876 /* start the tracing */
877 ret
= tracer_init(trace
, tr
);
879 warn_failed_init_tracer(trace
, ret
);
883 /* reset the max latency */
885 /* disable preemption for a bit */
891 * Stop the tracer to avoid a warning subsequent
892 * to buffer flipping failure because tracing_stop()
893 * disables the tr and max buffers, making flipping impossible
894 * in case of parallels max preempt off latencies.
897 /* stop the tracing. */
899 /* check both trace buffers */
900 ret
= trace_test_buffer(&tr
->trace_buffer
, NULL
);
902 ret
= trace_test_buffer(&tr
->max_buffer
, &count
);
906 if (!ret
&& !count
) {
907 printk(KERN_CONT
".. no entries found ..");
911 tr
->max_latency
= save_max
;
915 #endif /* CONFIG_PREEMPT_TRACER */
917 #if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
919 trace_selftest_startup_preemptirqsoff(struct tracer
*trace
, struct trace_array
*tr
)
921 unsigned long save_max
= tr
->max_latency
;
926 * Now that the big kernel lock is no longer preemptable,
927 * and this is called with the BKL held, it will always
928 * fail. If preemption is already disabled, simply
929 * pass the test. When the BKL is removed, or becomes
930 * preemptible again, we will once again test this,
933 if (preempt_count()) {
934 printk(KERN_CONT
"can not test ... force ");
938 /* start the tracing */
939 ret
= tracer_init(trace
, tr
);
941 warn_failed_init_tracer(trace
, ret
);
945 /* reset the max latency */
948 /* disable preemption and interrupts for a bit */
953 /* reverse the order of preempt vs irqs */
957 * Stop the tracer to avoid a warning subsequent
958 * to buffer flipping failure because tracing_stop()
959 * disables the tr and max buffers, making flipping impossible
960 * in case of parallels max irqs/preempt off latencies.
963 /* stop the tracing. */
965 /* check both trace buffers */
966 ret
= trace_test_buffer(&tr
->trace_buffer
, NULL
);
970 ret
= trace_test_buffer(&tr
->max_buffer
, &count
);
974 if (!ret
&& !count
) {
975 printk(KERN_CONT
".. no entries found ..");
980 /* do the test by disabling interrupts first this time */
989 /* reverse the order of preempt vs irqs */
993 /* stop the tracing. */
995 /* check both trace buffers */
996 ret
= trace_test_buffer(&tr
->trace_buffer
, NULL
);
1000 ret
= trace_test_buffer(&tr
->max_buffer
, &count
);
1002 if (!ret
&& !count
) {
1003 printk(KERN_CONT
".. no entries found ..");
1012 tr
->max_latency
= save_max
;
1016 #endif /* CONFIG_IRQSOFF_TRACER && CONFIG_PREEMPT_TRACER */
1018 #ifdef CONFIG_NOP_TRACER
1020 trace_selftest_startup_nop(struct tracer
*trace
, struct trace_array
*tr
)
1022 /* What could possibly go wrong? */
1027 #ifdef CONFIG_SCHED_TRACER
1028 static int trace_wakeup_test_thread(void *data
)
1030 /* Make this a -deadline thread */
1031 static const struct sched_attr attr
= {
1032 .sched_policy
= SCHED_DEADLINE
,
1033 .sched_runtime
= 100000ULL,
1034 .sched_deadline
= 10000000ULL,
1035 .sched_period
= 10000000ULL
1037 struct completion
*x
= data
;
1039 sched_setattr(current
, &attr
);
1041 /* Make it know we have a new prio */
1044 /* now go to sleep and let the test wake us up */
1045 set_current_state(TASK_INTERRUPTIBLE
);
1050 /* we are awake, now wait to disappear */
1051 while (!kthread_should_stop()) {
1053 * This will likely be the system top priority
1054 * task, do short sleeps to let others run.
1063 trace_selftest_startup_wakeup(struct tracer
*trace
, struct trace_array
*tr
)
1065 unsigned long save_max
= tr
->max_latency
;
1066 struct task_struct
*p
;
1067 struct completion is_ready
;
1068 unsigned long count
;
1071 init_completion(&is_ready
);
1073 /* create a -deadline thread */
1074 p
= kthread_run(trace_wakeup_test_thread
, &is_ready
, "ftrace-test");
1076 printk(KERN_CONT
"Failed to create ftrace wakeup test thread ");
1080 /* make sure the thread is running at -deadline policy */
1081 wait_for_completion(&is_ready
);
1083 /* start the tracing */
1084 ret
= tracer_init(trace
, tr
);
1086 warn_failed_init_tracer(trace
, ret
);
1090 /* reset the max latency */
1091 tr
->max_latency
= 0;
1095 * Sleep to make sure the -deadline thread is asleep too.
1096 * On virtual machines we can't rely on timings,
1097 * but we want to make sure this test still works.
1102 init_completion(&is_ready
);
1106 /* Wait for the task to wake up */
1107 wait_for_completion(&is_ready
);
1109 /* stop the tracing. */
1111 /* check both trace buffers */
1112 ret
= trace_test_buffer(&tr
->trace_buffer
, NULL
);
1113 printk("ret = %d\n", ret
);
1115 ret
= trace_test_buffer(&tr
->max_buffer
, &count
);
1121 tr
->max_latency
= save_max
;
1123 /* kill the thread */
1126 if (!ret
&& !count
) {
1127 printk(KERN_CONT
".. no entries found ..");
1133 #endif /* CONFIG_SCHED_TRACER */
1135 #ifdef CONFIG_CONTEXT_SWITCH_TRACER
1137 trace_selftest_startup_sched_switch(struct tracer
*trace
, struct trace_array
*tr
)
1139 unsigned long count
;
1142 /* start the tracing */
1143 ret
= tracer_init(trace
, tr
);
1145 warn_failed_init_tracer(trace
, ret
);
1149 /* Sleep for a 1/10 of a second */
1151 /* stop the tracing. */
1153 /* check the trace buffer */
1154 ret
= trace_test_buffer(&tr
->trace_buffer
, &count
);
1158 if (!ret
&& !count
) {
1159 printk(KERN_CONT
".. no entries found ..");
1165 #endif /* CONFIG_CONTEXT_SWITCH_TRACER */
1167 #ifdef CONFIG_BRANCH_TRACER
1169 trace_selftest_startup_branch(struct tracer
*trace
, struct trace_array
*tr
)
1171 unsigned long count
;
1174 /* start the tracing */
1175 ret
= tracer_init(trace
, tr
);
1177 warn_failed_init_tracer(trace
, ret
);
1181 /* Sleep for a 1/10 of a second */
1183 /* stop the tracing. */
1185 /* check the trace buffer */
1186 ret
= trace_test_buffer(&tr
->trace_buffer
, &count
);
1190 if (!ret
&& !count
) {
1191 printk(KERN_CONT
".. no entries found ..");
1197 #endif /* CONFIG_BRANCH_TRACER */