diff options
author | Viresh Kumar <viresh.kumar@linaro.org> | 2013-01-25 12:06:01 +0530 |
---|---|---|
committer | Viresh Kumar <viresh.kumar@linaro.org> | 2013-01-28 10:55:29 +0530 |
commit | f554b54072c83dc218c5aab45779907c509d581d (patch) | |
tree | fae309f7b12e1b2918c78d805c6de0174a00f10d | |
parent | f555d61e4d5b19a4b81c8a56e66cafaee0ede45e (diff) |
Add mdelay failure test
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
-rw-r--r-- | mdelay-workqueue.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/mdelay-workqueue.c b/mdelay-workqueue.c new file mode 100644 index 0000000..4094831 --- /dev/null +++ b/mdelay-workqueue.c @@ -0,0 +1,64 @@ +#include <linux/completion.h> +#include <linux/delay.h> +#include <linux/timer.h> +#include <linux/module.h> +#include <linux/printk.h> +#include <linux/workqueue.h> + +#define TIMER_DELAY 1 +static struct workqueue_struct *gwq; +static struct work_struct gwork; + +struct timer_list timer; +static int total_works = 1000, total_works_finished = 1; + +DECLARE_COMPLETION(wq_complete); + +void timer_fn(unsigned long data) +{ + queue_work_on(0, gwq, &gwork); +} + +static void wq_handler(struct work_struct *_work) +{ + if (total_works_finished++ == total_works) { + complete(&wq_complete); + return; + } + + mdelay(90); + + timer.expires = jiffies + TIMER_DELAY; + add_timer_on(&timer, 0); +} + +static int __init wq_module_init(void) +{ + gwq = alloc_workqueue("wq-test", 0, 0); + if (!gwq) { + pr_err("Failed to allocate workqueue\n"); + return 0; + } + + INIT_WORK(&gwork, wq_handler); + + init_timer(&timer); + timer.expires = jiffies + TIMER_DELAY; + timer.function = timer_fn; + + add_timer_on(&timer, 0); + + wait_for_completion_interruptible(&wq_complete); + return 0; +} +module_init(wq_module_init); + +static void __exit wq_module_exit(void) +{ + destroy_workqueue(gwq); +} +module_exit(wq_module_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Viresh Kumar <viresh.kumar@linaro.org>"); +MODULE_DESCRIPTION("Workqueue Analyser"); |