aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoel Fernandes (Google) <joel@joelfernandes.org>2018-07-12 17:36:11 -0400
committerSteven Rostedt (VMware) <rostedt@goodmis.org>2018-07-26 10:50:17 -0400
commitf96e8577da1026c344e49c75111303888d225389 (patch)
tree006ef00ce81df3e1c0bb25632a3ff61c07a31cac
parent2b27ece6c50c7f0a1db372786731be1a17c5b606 (diff)
lib: Add module for testing preemptoff/irqsoff latency tracers
Here we introduce a test module for introducing a long preempt or irq disable delay in the kernel which the preemptoff or irqsoff tracers can detect. This module is to be used only for test purposes and is default disabled. Following is the expected output (only briefly shown) that can be parsed to verify that the tracers are working correctly. We will use this from the kselftests in future patches. For the preemptoff tracer: echo preemptoff > /d/tracing/current_tracer sleep 1 insmod ./preemptirq_delay_test.ko test_mode=preempt delay=500000 sleep 1 bash-4.3# cat /d/tracing/trace preempt -1066 2...2 0us@: preemptirq_delay_run <-preemptirq_delay_run preempt -1066 2...2 500002us : preemptirq_delay_run <-preemptirq_delay_run preempt -1066 2...2 500004us : tracer_preempt_on <-preemptirq_delay_run preempt -1066 2...2 500012us : <stack trace> => kthread => ret_from_fork For the irqsoff tracer: echo irqsoff > /d/tracing/current_tracer sleep 1 insmod ./preemptirq_delay_test.ko test_mode=irq delay=500000 sleep 1 bash-4.3# cat /d/tracing/trace irq dis -1069 1d..1 0us@: preemptirq_delay_run irq dis -1069 1d..1 500001us : preemptirq_delay_run irq dis -1069 1d..1 500002us : tracer_hardirqs_on <-preemptirq_delay_run irq dis -1069 1d..1 500005us : <stack trace> => ret_from_fork Link: http://lkml.kernel.org/r/20180712213611.GA8743@joelaf.mtv.corp.google.com Cc: Boqun Feng <boqun.feng@gmail.com> Cc: Byungchul Park <byungchul.park@lge.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Julia Cartwright <julia@ni.com> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Paul McKenney <paulmck@linux.vnet.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Shuah Khan <shuah@kernel.org> Cc: Thomas Glexiner <tglx@linutronix.de> Cc: Todd Kjos <tkjos@google.com> Cc: Tom Zanussi <tom.zanussi@linux.intel.com> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> [ Erick is a co-developer of this commit ] Signed-off-by: Erick Reyes <erickreyes@google.com> Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
-rw-r--r--kernel/trace/Kconfig15
-rw-r--r--kernel/trace/Makefile1
-rw-r--r--kernel/trace/preemptirq_delay_test.c72
3 files changed, 88 insertions, 0 deletions
diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig
index dcc0166d1997..e15fadbe5dfb 100644
--- a/kernel/trace/Kconfig
+++ b/kernel/trace/Kconfig
@@ -687,6 +687,21 @@ config RING_BUFFER_STARTUP_TEST
687 687
688 If unsure, say N 688 If unsure, say N
689 689
690config PREEMPTIRQ_DELAY_TEST
691 tristate "Preempt / IRQ disable delay thread to test latency tracers"
692 depends on m
693 help
694 Select this option to build a test module that can help test latency
695 tracers by executing a preempt or irq disable section with a user
696 configurable delay. The module busy waits for the duration of the
697 critical section.
698
699 For example, the following invocation forces a one-time irq-disabled
700 critical section for 500us:
701 modprobe preemptirq_delay_test test_mode=irq delay=500000
702
703 If unsure, say N
704
690config TRACE_EVAL_MAP_FILE 705config TRACE_EVAL_MAP_FILE
691 bool "Show eval mappings for trace events" 706 bool "Show eval mappings for trace events"
692 depends on TRACING 707 depends on TRACING
diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile
index e2538c7638d4..31c6b524c260 100644
--- a/kernel/trace/Makefile
+++ b/kernel/trace/Makefile
@@ -33,6 +33,7 @@ obj-$(CONFIG_TRACING) += trace_seq.o
33obj-$(CONFIG_TRACING) += trace_stat.o 33obj-$(CONFIG_TRACING) += trace_stat.o
34obj-$(CONFIG_TRACING) += trace_printk.o 34obj-$(CONFIG_TRACING) += trace_printk.o
35obj-$(CONFIG_TRACING_MAP) += tracing_map.o 35obj-$(CONFIG_TRACING_MAP) += tracing_map.o
36obj-$(CONFIG_PREEMPTIRQ_DELAY_TEST) += preemptirq_delay_test.o
36obj-$(CONFIG_CONTEXT_SWITCH_TRACER) += trace_sched_switch.o 37obj-$(CONFIG_CONTEXT_SWITCH_TRACER) += trace_sched_switch.o
37obj-$(CONFIG_FUNCTION_TRACER) += trace_functions.o 38obj-$(CONFIG_FUNCTION_TRACER) += trace_functions.o
38obj-$(CONFIG_PREEMPTIRQ_EVENTS) += trace_irqsoff.o 39obj-$(CONFIG_PREEMPTIRQ_EVENTS) += trace_irqsoff.o
diff --git a/kernel/trace/preemptirq_delay_test.c b/kernel/trace/preemptirq_delay_test.c
new file mode 100644
index 000000000000..c97a026c0720
--- /dev/null
+++ b/kernel/trace/preemptirq_delay_test.c
@@ -0,0 +1,72 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Preempt / IRQ disable delay thread to test latency tracers
4 *
5 * Copyright (C) 2018 Joel Fernandes (Google) <joel@joelfernandes.org>
6 */
7
8#include <linux/delay.h>
9#include <linux/interrupt.h>
10#include <linux/irq.h>
11#include <linux/kernel.h>
12#include <linux/kthread.h>
13#include <linux/ktime.h>
14#include <linux/module.h>
15#include <linux/printk.h>
16#include <linux/string.h>
17
18static ulong delay = 100;
19static char test_mode[10] = "irq";
20
21module_param_named(delay, delay, ulong, S_IRUGO);
22module_param_string(test_mode, test_mode, 10, S_IRUGO);
23MODULE_PARM_DESC(delay, "Period in microseconds (100 uS default)");
24MODULE_PARM_DESC(test_mode, "Mode of the test such as preempt or irq (default irq)");
25
26static void busy_wait(ulong time)
27{
28 ktime_t start, end;
29 start = ktime_get();
30 do {
31 end = ktime_get();
32 if (kthread_should_stop())
33 break;
34 } while (ktime_to_ns(ktime_sub(end, start)) < (time * 1000));
35}
36
37int preemptirq_delay_run(void *data)
38{
39 unsigned long flags;
40
41 if (!strcmp(test_mode, "irq")) {
42 local_irq_save(flags);
43 busy_wait(delay);
44 local_irq_restore(flags);
45 } else if (!strcmp(test_mode, "preempt")) {
46 preempt_disable();
47 busy_wait(delay);
48 preempt_enable();
49 }
50
51 return 0;
52}
53
54static int __init preemptirq_delay_init(void)
55{
56 char task_name[50];
57 struct task_struct *test_task;
58
59 snprintf(task_name, sizeof(task_name), "%s_test", test_mode);
60
61 test_task = kthread_run(preemptirq_delay_run, NULL, task_name);
62 return PTR_ERR_OR_ZERO(test_task);
63}
64
65static void __exit preemptirq_delay_exit(void)
66{
67 return;
68}
69
70module_init(preemptirq_delay_init)
71module_exit(preemptirq_delay_exit)
72MODULE_LICENSE("GPL v2");