1 /* Include in trace.c */
3 #include <linux/kthread.h>
4 #include <linux/delay.h>
6 static inline int trace_valid_entry(struct trace_entry
*entry
)
21 static int trace_test_buffer_cpu(struct trace_array
*tr
, int cpu
)
23 struct ring_buffer_event
*event
;
24 struct trace_entry
*entry
;
26 while ((event
= ring_buffer_consume(tr
->buffer
, cpu
, NULL
))) {
27 entry
= ring_buffer_event_data(event
);
29 if (!trace_valid_entry(entry
)) {
30 printk(KERN_CONT
".. invalid entry %d ",
40 printk(KERN_CONT
".. corrupted trace buffer .. ");
45 * Test the trace buffer to see if all the elements
48 static int trace_test_buffer(struct trace_array
*tr
, unsigned long *count
)
50 unsigned long flags
, cnt
= 0;
53 /* Don't allow flipping of max traces now */
54 local_irq_save(flags
);
55 __raw_spin_lock(&ftrace_max_lock
);
57 cnt
= ring_buffer_entries(tr
->buffer
);
59 for_each_possible_cpu(cpu
) {
60 ret
= trace_test_buffer_cpu(tr
, cpu
);
64 __raw_spin_unlock(&ftrace_max_lock
);
65 local_irq_restore(flags
);
73 static inline void warn_failed_init_tracer(struct tracer
*trace
, int init_ret
)
75 printk(KERN_WARNING
"Failed to init %s tracer, init returned %d\n",
76 trace
->name
, init_ret
);
78 #ifdef CONFIG_FUNCTION_TRACER
80 #ifdef CONFIG_DYNAMIC_FTRACE
83 #define STR(x) __STR(x)
85 /* Test dynamic code modification and ftrace filters */
86 int trace_selftest_startup_dynamic_tracing(struct tracer
*trace
,
87 struct trace_array
*tr
,
90 int save_ftrace_enabled
= ftrace_enabled
;
91 int save_tracer_enabled
= tracer_enabled
;
96 /* The ftrace test PASSED */
97 printk(KERN_CONT
"PASSED\n");
98 pr_info("Testing dynamic ftrace: ");
100 /* enable tracing, and record the filter function */
104 /* passed in by parameter to fool gcc from optimizing */
108 * Some archs *cough*PowerPC*cough* add charachters to the
109 * start of the function names. We simply put a '*' to
112 func_name
= "*" STR(DYN_FTRACE_TEST_NAME
);
114 /* filter only on our function */
115 ftrace_set_filter(func_name
, strlen(func_name
), 1);
118 ret
= trace
->init(tr
);
120 warn_failed_init_tracer(trace
, ret
);
124 /* Sleep for a 1/10 of a second */
127 /* we should have nothing in the buffer */
128 ret
= trace_test_buffer(tr
, &count
);
134 printk(KERN_CONT
".. filter did not filter .. ");
138 /* call our function again */
144 /* stop the tracing. */
148 /* check the trace buffer */
149 ret
= trace_test_buffer(tr
, &count
);
153 /* we should only have one item */
154 if (!ret
&& count
!= 1) {
155 printk(KERN_CONT
".. filter failed count=%ld ..", count
);
161 ftrace_enabled
= save_ftrace_enabled
;
162 tracer_enabled
= save_tracer_enabled
;
164 /* Enable tracing on all functions again */
165 ftrace_set_filter(NULL
, 0, 1);
170 # define trace_selftest_startup_dynamic_tracing(trace, tr, func) ({ 0; })
171 #endif /* CONFIG_DYNAMIC_FTRACE */
173 * Simple verification test of ftrace function tracer.
174 * Enable ftrace, sleep 1/10 second, and then read the trace
175 * buffer to see if all is in order.
178 trace_selftest_startup_function(struct tracer
*trace
, struct trace_array
*tr
)
180 int save_ftrace_enabled
= ftrace_enabled
;
181 int save_tracer_enabled
= tracer_enabled
;
185 /* make sure msleep has been recorded */
188 /* start the tracing */
192 ret
= trace
->init(tr
);
194 warn_failed_init_tracer(trace
, ret
);
198 /* Sleep for a 1/10 of a second */
200 /* stop the tracing. */
204 /* check the trace buffer */
205 ret
= trace_test_buffer(tr
, &count
);
209 if (!ret
&& !count
) {
210 printk(KERN_CONT
".. no entries found ..");
215 ret
= trace_selftest_startup_dynamic_tracing(trace
, tr
,
216 DYN_FTRACE_TEST_NAME
);
219 ftrace_enabled
= save_ftrace_enabled
;
220 tracer_enabled
= save_tracer_enabled
;
222 /* kill ftrace totally if we failed */
228 #endif /* CONFIG_FUNCTION_TRACER */
230 #ifdef CONFIG_IRQSOFF_TRACER
232 trace_selftest_startup_irqsoff(struct tracer
*trace
, struct trace_array
*tr
)
234 unsigned long save_max
= tracing_max_latency
;
238 /* start the tracing */
239 ret
= trace
->init(tr
);
241 warn_failed_init_tracer(trace
, ret
);
245 /* reset the max latency */
246 tracing_max_latency
= 0;
247 /* disable interrupts for a bit */
251 /* stop the tracing. */
253 /* check both trace buffers */
254 ret
= trace_test_buffer(tr
, NULL
);
256 ret
= trace_test_buffer(&max_tr
, &count
);
260 if (!ret
&& !count
) {
261 printk(KERN_CONT
".. no entries found ..");
265 tracing_max_latency
= save_max
;
269 #endif /* CONFIG_IRQSOFF_TRACER */
271 #ifdef CONFIG_PREEMPT_TRACER
273 trace_selftest_startup_preemptoff(struct tracer
*trace
, struct trace_array
*tr
)
275 unsigned long save_max
= tracing_max_latency
;
280 * Now that the big kernel lock is no longer preemptable,
281 * and this is called with the BKL held, it will always
282 * fail. If preemption is already disabled, simply
283 * pass the test. When the BKL is removed, or becomes
284 * preemptible again, we will once again test this,
287 if (preempt_count()) {
288 printk(KERN_CONT
"can not test ... force ");
292 /* start the tracing */
293 ret
= trace
->init(tr
);
295 warn_failed_init_tracer(trace
, ret
);
299 /* reset the max latency */
300 tracing_max_latency
= 0;
301 /* disable preemption for a bit */
305 /* stop the tracing. */
307 /* check both trace buffers */
308 ret
= trace_test_buffer(tr
, NULL
);
310 ret
= trace_test_buffer(&max_tr
, &count
);
314 if (!ret
&& !count
) {
315 printk(KERN_CONT
".. no entries found ..");
319 tracing_max_latency
= save_max
;
323 #endif /* CONFIG_PREEMPT_TRACER */
325 #if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
327 trace_selftest_startup_preemptirqsoff(struct tracer
*trace
, struct trace_array
*tr
)
329 unsigned long save_max
= tracing_max_latency
;
334 * Now that the big kernel lock is no longer preemptable,
335 * and this is called with the BKL held, it will always
336 * fail. If preemption is already disabled, simply
337 * pass the test. When the BKL is removed, or becomes
338 * preemptible again, we will once again test this,
341 if (preempt_count()) {
342 printk(KERN_CONT
"can not test ... force ");
346 /* start the tracing */
347 ret
= trace
->init(tr
);
349 warn_failed_init_tracer(trace
, ret
);
353 /* reset the max latency */
354 tracing_max_latency
= 0;
356 /* disable preemption and interrupts for a bit */
361 /* reverse the order of preempt vs irqs */
364 /* stop the tracing. */
366 /* check both trace buffers */
367 ret
= trace_test_buffer(tr
, NULL
);
373 ret
= trace_test_buffer(&max_tr
, &count
);
379 if (!ret
&& !count
) {
380 printk(KERN_CONT
".. no entries found ..");
386 /* do the test by disabling interrupts first this time */
387 tracing_max_latency
= 0;
393 /* reverse the order of preempt vs irqs */
396 /* stop the tracing. */
398 /* check both trace buffers */
399 ret
= trace_test_buffer(tr
, NULL
);
403 ret
= trace_test_buffer(&max_tr
, &count
);
405 if (!ret
&& !count
) {
406 printk(KERN_CONT
".. no entries found ..");
414 tracing_max_latency
= save_max
;
418 #endif /* CONFIG_IRQSOFF_TRACER && CONFIG_PREEMPT_TRACER */
420 #ifdef CONFIG_NOP_TRACER
422 trace_selftest_startup_nop(struct tracer
*trace
, struct trace_array
*tr
)
424 /* What could possibly go wrong? */
429 #ifdef CONFIG_SCHED_TRACER
430 static int trace_wakeup_test_thread(void *data
)
432 /* Make this a RT thread, doesn't need to be too high */
433 struct sched_param param
= { .sched_priority
= 5 };
434 struct completion
*x
= data
;
436 sched_setscheduler(current
, SCHED_FIFO
, ¶m
);
438 /* Make it know we have a new prio */
441 /* now go to sleep and let the test wake us up */
442 set_current_state(TASK_INTERRUPTIBLE
);
445 /* we are awake, now wait to disappear */
446 while (!kthread_should_stop()) {
448 * This is an RT task, do short sleeps to let
458 trace_selftest_startup_wakeup(struct tracer
*trace
, struct trace_array
*tr
)
460 unsigned long save_max
= tracing_max_latency
;
461 struct task_struct
*p
;
462 struct completion isrt
;
466 init_completion(&isrt
);
468 /* create a high prio thread */
469 p
= kthread_run(trace_wakeup_test_thread
, &isrt
, "ftrace-test");
471 printk(KERN_CONT
"Failed to create ftrace wakeup test thread ");
475 /* make sure the thread is running at an RT prio */
476 wait_for_completion(&isrt
);
478 /* start the tracing */
479 ret
= trace
->init(tr
);
481 warn_failed_init_tracer(trace
, ret
);
485 /* reset the max latency */
486 tracing_max_latency
= 0;
488 /* sleep to let the RT thread sleep too */
492 * Yes this is slightly racy. It is possible that for some
493 * strange reason that the RT thread we created, did not
494 * call schedule for 100ms after doing the completion,
495 * and we do a wakeup on a task that already is awake.
496 * But that is extremely unlikely, and the worst thing that
497 * happens in such a case, is that we disable tracing.
498 * Honestly, if this race does happen something is horrible
499 * wrong with the system.
504 /* give a little time to let the thread wake up */
507 /* stop the tracing. */
509 /* check both trace buffers */
510 ret
= trace_test_buffer(tr
, NULL
);
512 ret
= trace_test_buffer(&max_tr
, &count
);
518 tracing_max_latency
= save_max
;
520 /* kill the thread */
523 if (!ret
&& !count
) {
524 printk(KERN_CONT
".. no entries found ..");
530 #endif /* CONFIG_SCHED_TRACER */
532 #ifdef CONFIG_CONTEXT_SWITCH_TRACER
534 trace_selftest_startup_sched_switch(struct tracer
*trace
, struct trace_array
*tr
)
539 /* start the tracing */
540 ret
= trace
->init(tr
);
542 warn_failed_init_tracer(trace
, ret
);
546 /* Sleep for a 1/10 of a second */
548 /* stop the tracing. */
550 /* check the trace buffer */
551 ret
= trace_test_buffer(tr
, &count
);
555 if (!ret
&& !count
) {
556 printk(KERN_CONT
".. no entries found ..");
562 #endif /* CONFIG_CONTEXT_SWITCH_TRACER */
564 #ifdef CONFIG_SYSPROF_TRACER
566 trace_selftest_startup_sysprof(struct tracer
*trace
, struct trace_array
*tr
)
571 /* start the tracing */
572 ret
= trace
->init(tr
);
574 warn_failed_init_tracer(trace
, ret
);
578 /* Sleep for a 1/10 of a second */
580 /* stop the tracing. */
582 /* check the trace buffer */
583 ret
= trace_test_buffer(tr
, &count
);
589 #endif /* CONFIG_SYSPROF_TRACER */
591 #ifdef CONFIG_BRANCH_TRACER
593 trace_selftest_startup_branch(struct tracer
*trace
, struct trace_array
*tr
)
598 /* start the tracing */
599 ret
= trace
->init(tr
);
601 warn_failed_init_tracer(trace
, ret
);
605 /* Sleep for a 1/10 of a second */
607 /* stop the tracing. */
609 /* check the trace buffer */
610 ret
= trace_test_buffer(tr
, &count
);
616 #endif /* CONFIG_BRANCH_TRACER */
This page took 0.093488 seconds and 6 git commands to generate.