timer.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #ifndef _LINUX_TIMER_H
  2. #define _LINUX_TIMER_H
  3. #include <linux/list.h>
  4. #include <linux/ktime.h>
  5. #include <linux/spinlock.h>
  6. #include <linux/stddef.h>
  7. struct tvec_t_base_s;
  8. struct timer_list {
  9. struct list_head entry;
  10. unsigned long expires;
  11. void (*function)(unsigned long);
  12. unsigned long data;
  13. struct tvec_t_base_s *base;
  14. #ifdef CONFIG_TIMER_STATS
  15. void *start_site;
  16. char start_comm[16];
  17. int start_pid;
  18. #endif
  19. };
  20. extern struct tvec_t_base_s boot_tvec_bases;
  21. #define TIMER_INITIALIZER(_function, _expires, _data) { \
  22. .function = (_function), \
  23. .expires = (_expires), \
  24. .data = (_data), \
  25. .base = &boot_tvec_bases, \
  26. }
  27. #define DEFINE_TIMER(_name, _function, _expires, _data) \
  28. struct timer_list _name = \
  29. TIMER_INITIALIZER(_function, _expires, _data)
  30. void fastcall init_timer(struct timer_list * timer);
  31. static inline void setup_timer(struct timer_list * timer,
  32. void (*function)(unsigned long),
  33. unsigned long data)
  34. {
  35. timer->function = function;
  36. timer->data = data;
  37. init_timer(timer);
  38. }
  39. /**
  40. * timer_pending - is a timer pending?
  41. * @timer: the timer in question
  42. *
  43. * timer_pending will tell whether a given timer is currently pending,
  44. * or not. Callers must ensure serialization wrt. other operations done
  45. * to this timer, eg. interrupt contexts, or other CPUs on SMP.
  46. *
  47. * return value: 1 if the timer is pending, 0 if not.
  48. */
  49. static inline int timer_pending(const struct timer_list * timer)
  50. {
  51. return timer->entry.next != NULL;
  52. }
  53. extern void add_timer_on(struct timer_list *timer, int cpu);
  54. extern int del_timer(struct timer_list * timer);
  55. extern int __mod_timer(struct timer_list *timer, unsigned long expires);
  56. extern int mod_timer(struct timer_list *timer, unsigned long expires);
  57. /*
  58. * Return when the next timer-wheel timeout occurs (in absolute jiffies),
  59. * locks the timer base:
  60. */
  61. extern unsigned long next_timer_interrupt(void);
  62. /*
  63. * Return when the next timer-wheel timeout occurs (in absolute jiffies),
  64. * locks the timer base and does the comparison against the given
  65. * jiffie.
  66. */
  67. extern unsigned long get_next_timer_interrupt(unsigned long now);
  68. /*
  69. * Timer-statistics info:
  70. */
  71. #ifdef CONFIG_TIMER_STATS
  72. extern void init_timer_stats(void);
  73. extern void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
  74. void *timerf, char * comm);
  75. static inline void timer_stats_account_timer(struct timer_list *timer)
  76. {
  77. timer_stats_update_stats(timer, timer->start_pid, timer->start_site,
  78. timer->function, timer->start_comm);
  79. }
  80. extern void __timer_stats_timer_set_start_info(struct timer_list *timer,
  81. void *addr);
  82. static inline void timer_stats_timer_set_start_info(struct timer_list *timer)
  83. {
  84. __timer_stats_timer_set_start_info(timer, __builtin_return_address(0));
  85. }
  86. static inline void timer_stats_timer_clear_start_info(struct timer_list *timer)
  87. {
  88. timer->start_site = NULL;
  89. }
  90. #else
  91. static inline void init_timer_stats(void)
  92. {
  93. }
  94. static inline void timer_stats_account_timer(struct timer_list *timer)
  95. {
  96. }
  97. static inline void timer_stats_timer_set_start_info(struct timer_list *timer)
  98. {
  99. }
  100. static inline void timer_stats_timer_clear_start_info(struct timer_list *timer)
  101. {
  102. }
  103. #endif
  104. extern void delayed_work_timer_fn(unsigned long __data);
  105. /**
  106. * add_timer - start a timer
  107. * @timer: the timer to be added
  108. *
  109. * The kernel will do a ->function(->data) callback from the
  110. * timer interrupt at the ->expires point in the future. The
  111. * current time is 'jiffies'.
  112. *
  113. * The timer's ->expires, ->function (and if the handler uses it, ->data)
  114. * fields must be set prior calling this function.
  115. *
  116. * Timers with an ->expires field in the past will be executed in the next
  117. * timer tick.
  118. */
  119. static inline void add_timer(struct timer_list *timer)
  120. {
  121. BUG_ON(timer_pending(timer));
  122. __mod_timer(timer, timer->expires);
  123. }
  124. #ifdef CONFIG_SMP
  125. extern int try_to_del_timer_sync(struct timer_list *timer);
  126. extern int del_timer_sync(struct timer_list *timer);
  127. #else
  128. # define try_to_del_timer_sync(t) del_timer(t)
  129. # define del_timer_sync(t) del_timer(t)
  130. #endif
  131. #define del_singleshot_timer_sync(t) del_timer_sync(t)
  132. extern void init_timers(void);
  133. extern void run_local_timers(void);
  134. struct hrtimer;
  135. extern enum hrtimer_restart it_real_fn(struct hrtimer *);
  136. unsigned long __round_jiffies(unsigned long j, int cpu);
  137. unsigned long __round_jiffies_relative(unsigned long j, int cpu);
  138. unsigned long round_jiffies(unsigned long j);
  139. unsigned long round_jiffies_relative(unsigned long j);
  140. #endif