#include <linux/trace_clock.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/kthread.h>
#include <linux/module.h>
#include <linux/printk.h>
#include <linux/string.h>
static ulong delay = 100;
static char test_mode[10] = "irq";
module_param_named(delay, delay, ulong, S_IRUGO);
module_param_string(test_mode, test_mode, 10, S_IRUGO);
MODULE_PARM_DESC(delay, "Period in microseconds (100 uS default)");
MODULE_PARM_DESC(test_mode, "Mode of the test such as preempt or irq (default irq)");
static void busy_wait(ulong time)
start = trace_clock_local();
end = trace_clock_local();
if (kthread_should_stop())
} while ((end - start) < (time * 1000));
static int preemptirq_delay_run(void *data)
if (!strcmp(test_mode, "irq")) {
local_irq_restore(flags);
} else if (!strcmp(test_mode, "preempt")) {
static int __init preemptirq_delay_init(void)
struct task_struct *test_task;
snprintf(task_name, sizeof(task_name), "%s_test", test_mode);
test_task = kthread_run(preemptirq_delay_run, NULL, task_name);
return PTR_ERR_OR_ZERO(test_task);