timer.h 5.1 KB

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