Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <linux/init.h>
- #include <linux/module.h>
- #include <linux/sched.h>
- #include <linux/time.h>
- #include <linux/timer.h>
- #define TIMER_DELAY_SECS 5
- #define TIMER_CHAIN 3
- struct timer_list my_timer;
- static struct timeval timestamp;
- static int timer_count;
- unsigned long timer_params;
- static void timer_func(unsigned long timer_params);
- void create_my_timer()
- {
- init_timer(&my_timer);
- my_timer.expires = jiffies + TIMER_DELAY_SECS * HZ;
- my_timer.data = timer_params;
- my_timer.function = timer_func;
- add_timer(&my_timer);
- }
- static void timer_func(unsigned long timer_params)
- {
- do_gettimeofday(×tamp);
- printk(KERN_DEBUG "timer_test: timer fired (count = %d). timestamp:%d\n", timer_count,0
- cpu_to_le32(timestamp.tv_sec));
- printk(KERN_DEBUG "timer_test: current process = %s (pid %i)\n", current->comm, current->pid);
- if (timer_count < TIMER_CHAIN)
- {
- create_my_timer();
- timer_count++;
- }
- else
- printk(KERN_DEBUG "timer_test: reached max timer chains\n");
- }
- static int __init timertest_init(void)
- {
- printk(KERN_DEBUG "timer_test: init\n");
- timer_count = 0;
- create_my_timer();
- return 0;
- }
- static void __exit timertest_exit(void)
- {
- printk(KERN_DEBUG "timer_test: exit\n");
- if(timer_pending(&my_timer))
- {
- printk(KERN_DEBUG "timer_test: timer pending, deleting before exit\n");
- del_timer(&my_timer);
- }
- }
- module_init(timertest_init);
- module_exit(timertest_exit);
- MODULE_LICENSE("GPL");
- MODULE_AUTHOR("Dexter Haslem < dexter.haslem@gmail.com >");
- MODULE_DESCRIPTION("timer test module");
- MODULE_VERSION("1");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement