1 // SPDX-License-Identifier: GPL-2.0
3 * Preempt / IRQ disable delay thread to test latency tracers
5 * Copyright (C) 2018 Joel Fernandes (Google) <joel@joelfernandes.org>
8 #include <linux/trace_clock.h>
9 #include <linux/delay.h>
10 #include <linux/interrupt.h>
11 #include <linux/irq.h>
12 #include <linux/kernel.h>
13 #include <linux/kthread.h>
14 #include <linux/module.h>
15 #include <linux/printk.h>
16 #include <linux/string.h>
18 static ulong delay
= 100;
19 static char test_mode
[10] = "irq";
21 module_param_named(delay
, delay
, ulong
, S_IRUGO
);
22 module_param_string(test_mode
, test_mode
, 10, S_IRUGO
);
23 MODULE_PARM_DESC(delay
, "Period in microseconds (100 uS default)");
24 MODULE_PARM_DESC(test_mode
, "Mode of the test such as preempt or irq (default irq)");
26 static void busy_wait(ulong time
)
29 start
= trace_clock_local();
31 end
= trace_clock_local();
32 if (kthread_should_stop())
34 } while ((end
- start
) < (time
* 1000));
37 static int preemptirq_delay_run(void *data
)
41 if (!strcmp(test_mode
, "irq")) {
42 local_irq_save(flags
);
44 local_irq_restore(flags
);
45 } else if (!strcmp(test_mode
, "preempt")) {
54 static int __init
preemptirq_delay_init(void)
57 struct task_struct
*test_task
;
59 snprintf(task_name
, sizeof(task_name
), "%s_test", test_mode
);
61 test_task
= kthread_run(preemptirq_delay_run
, NULL
, task_name
);
62 return PTR_ERR_OR_ZERO(test_task
);
65 static void __exit
preemptirq_delay_exit(void)
70 module_init(preemptirq_delay_init
)
71 module_exit(preemptirq_delay_exit
)
72 MODULE_LICENSE("GPL v2");