Advertisement
Guest User

dmh

a guest
Dec 20th, 2010
597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. #include <linux/init.h>
  2. #include <linux/module.h>
  3. #include <linux/sched.h>
  4. #include <linux/time.h>
  5. #include <linux/timer.h>
  6.  
  7. #define TIMER_DELAY_SECS 5
  8. #define TIMER_CHAIN 3
  9.  
  10. struct timer_list my_timer;
  11. static struct timeval timestamp;
  12. static int timer_count;
  13. unsigned long timer_params;
  14.  
  15. static void timer_func(unsigned long timer_params);
  16.  
  17. void create_my_timer()
  18. {
  19. init_timer(&my_timer);
  20. my_timer.expires = jiffies + TIMER_DELAY_SECS * HZ;
  21. my_timer.data = timer_params;
  22. my_timer.function = timer_func;
  23. add_timer(&my_timer);
  24. }
  25.  
  26. static void timer_func(unsigned long timer_params)
  27. {
  28. do_gettimeofday(&timestamp);
  29. printk(KERN_DEBUG "timer_test: timer fired (count = %d). timestamp:%d\n", timer_count,0
  30. cpu_to_le32(timestamp.tv_sec));
  31. printk(KERN_DEBUG "timer_test: current process = %s (pid %i)\n", current->comm, current->pid);
  32. if (timer_count < TIMER_CHAIN)
  33. {
  34. create_my_timer();
  35. timer_count++;
  36. }
  37. else
  38. printk(KERN_DEBUG "timer_test: reached max timer chains\n");
  39. }
  40.  
  41. static int __init timertest_init(void)
  42. {
  43. printk(KERN_DEBUG "timer_test: init\n");
  44. timer_count = 0;
  45. create_my_timer();
  46. return 0;
  47. }
  48.  
  49. static void __exit timertest_exit(void)
  50. {
  51. printk(KERN_DEBUG "timer_test: exit\n");
  52. if(timer_pending(&my_timer))
  53. {
  54. printk(KERN_DEBUG "timer_test: timer pending, deleting before exit\n");
  55. del_timer(&my_timer);
  56. }
  57. }
  58.  
  59. module_init(timertest_init);
  60. module_exit(timertest_exit);
  61. MODULE_LICENSE("GPL");
  62. MODULE_AUTHOR("Dexter Haslem < dexter.haslem@gmail.com >");
  63. MODULE_DESCRIPTION("timer test module");
  64. MODULE_VERSION("1");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement