drivers/misc/Kconfig | 11 ++++++ drivers/misc/Makefile | 1 + drivers/misc/timer-test.c | 80 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 0 deletions(-) create mode 100644 drivers/misc/timer-test.c diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index a726f3b..7ebdcfc 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -475,4 +475,15 @@ config SGI_GRU_DEBUG This option enables addition debugging code for the SGI GRU driver. If you are unsure, say N. +config TIMER_TEST + tristate "timer stress test" + default n + select INPUT + ---help--- + This is some code for stress testing the timer code. It is purely for + debugging purposes and should generally be disabled. If built as a + module, the module will be called timer-test. + + If you are unsure, say N. + endif # MISC_DEVICES diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index c6c13f6..ffffd78 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -30,3 +30,4 @@ obj-$(CONFIG_KGDB_TESTS) += kgdbts.o obj-$(CONFIG_SGI_XP) += sgi-xp/ obj-$(CONFIG_SGI_GRU) += sgi-gru/ obj-$(CONFIG_HP_ILO) += hpilo.o +obj-$(CONFIG_TIMER_TEST) += timer-test.o diff --git a/drivers/misc/timer-test.c b/drivers/misc/timer-test.c new file mode 100644 index 0000000..a58adcf --- /dev/null +++ b/drivers/misc/timer-test.c @@ -0,0 +1,80 @@ +#include +#include +#include +#include +#include +#include + +#define TSTM_FREQ 50 + +static struct timer_list tstm_timer; +static struct input_dev *tstm_idev; +static int key_state = 0; + +static void tstm_input_update(unsigned long data) +{ + key_state ^= 1; + input_report_key(tstm_idev, BTN_0, key_state); + input_sync(tstm_idev); + mod_timer(&tstm_timer, jiffies + HZ/TSTM_FREQ); +} + +static int tstm_dev_open(struct input_dev *dev) +{ + mod_timer(&tstm_timer, jiffies + HZ/TSTM_FREQ); + return 0; +} + +static void tstm_dev_close(struct input_dev *dev) +{ + del_timer_sync(&tstm_timer); +} + +static int __init tstm_init(void) +{ + int ret; + + tstm_idev = input_allocate_device(); + if (!tstm_idev) { + ret = -ENOMEM; + goto out; + } + + /* initialise the input device */ + tstm_idev->name = "Timer stress test data"; + tstm_idev->phys = "tstm/input0"; + tstm_idev->id.bustype = BUS_HOST; + tstm_idev->evbit[0] = BIT(EV_KEY); + tstm_idev->keybit[BIT_WORD(BTN_0)] = BIT_MASK(BTN_0); + tstm_idev->open = tstm_dev_open; + tstm_idev->close = tstm_dev_close; + + ret = input_register_device(tstm_idev); + if (ret) + goto out_idev; + + init_timer(&tstm_timer); + tstm_timer.function = tstm_input_update; + + printk(KERN_INFO "timer-test: module successfully loaded.\n"); + return 0; + +out_idev: + input_free_device(tstm_idev); +out: + printk(KERN_WARNING "timer-test: module init failed (ret=%d)!\n", ret); + return ret; +} + +static void __exit tstm_exit(void) +{ + input_unregister_device(tstm_idev); + printk(KERN_INFO "tstm: module unloaded.\n"); +} + +module_init(tstm_init); +module_exit(tstm_exit); + +MODULE_AUTHOR("Elias Oltmanns"); +MODULE_DESCRIPTION("Timer stress test module"); +MODULE_LICENSE("GPL v2");