genirq/debugfs: No need to check return value of debugfs_create functions
[linux/fpc-iii.git] / kernel / trace / preemptirq_delay_test.c
blobd8765c952fab3a7dfdf091b210bc7725e781d11c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Preempt / IRQ disable delay thread to test latency tracers
5 * Copyright (C) 2018 Joel Fernandes (Google) <joel@joelfernandes.org>
6 */
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)
28 u64 start, end;
29 start = trace_clock_local();
30 do {
31 end = trace_clock_local();
32 if (kthread_should_stop())
33 break;
34 } while ((end - start) < (time * 1000));
37 static int preemptirq_delay_run(void *data)
39 unsigned long flags;
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();
51 return 0;
54 static int __init preemptirq_delay_init(void)
56 char task_name[50];
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)
67 return;
70 module_init(preemptirq_delay_init)
71 module_exit(preemptirq_delay_exit)
72 MODULE_LICENSE("GPL v2");