timer.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. #include <linux/stringify.h>
  8. struct tvec_base;
  9. struct timer_list {
  10. struct list_head entry;
  11. unsigned long expires;
  12. void (*function)(unsigned long);
  13. unsigned long data;
  14. struct tvec_base *base;
  15. #ifdef CONFIG_TIMER_STATS
  16. void *start_site;
  17. char start_comm[16];
  18. int start_pid;
  19. #endif
  20. #ifdef CONFIG_LOCKDEP
  21. struct lockdep_map lockdep_map;
  22. #endif
  23. };
  24. extern struct tvec_base boot_tvec_bases;
  25. #ifdef CONFIG_LOCKDEP
  26. /*
  27. * NB: because we have to copy the lockdep_map, setting the lockdep_map key
  28. * (second argument) here is required, otherwise it could be initialised to
  29. * the copy of the lockdep_map later! We use the pointer to and the string
  30. * "<file>:<line>" as the key resp. the name of the lockdep_map.
  31. */
  32. #define __TIMER_LOCKDEP_MAP_INITIALIZER(_kn) \
  33. .lockdep_map = STATIC_LOCKDEP_MAP_INIT(_kn, &_kn),
  34. #else
  35. #define __TIMER_LOCKDEP_MAP_INITIALIZER(_kn)
  36. #endif
  37. #define TIMER_INITIALIZER(_function, _expires, _data) { \
  38. .entry = { .prev = TIMER_ENTRY_STATIC }, \
  39. .function = (_function), \
  40. .expires = (_expires), \
  41. .data = (_data), \
  42. .base = &boot_tvec_bases, \
  43. __TIMER_LOCKDEP_MAP_INITIALIZER( \
  44. __FILE__ ":" __stringify(__LINE__)) \
  45. }
  46. #define DEFINE_TIMER(_name, _function, _expires, _data) \
  47. struct timer_list _name = \
  48. TIMER_INITIALIZER(_function, _expires, _data)
  49. void init_timer_key(struct timer_list *timer,
  50. const char *name,
  51. struct lock_class_key *key);
  52. void init_timer_deferrable_key(struct timer_list *timer,
  53. const char *name,
  54. struct lock_class_key *key);
  55. #ifdef CONFIG_LOCKDEP
  56. #define init_timer(timer) \
  57. do { \
  58. static struct lock_class_key __key; \
  59. init_timer_key((timer), #timer, &__key); \
  60. } while (0)
  61. #define init_timer_deferrable(timer) \
  62. do { \
  63. static struct lock_class_key __key; \
  64. init_timer_deferrable_key((timer), #timer, &__key); \
  65. } while (0)
  66. #define init_timer_on_stack(timer) \
  67. do { \
  68. static struct lock_class_key __key; \
  69. init_timer_on_stack_key((timer), #timer, &__key); \
  70. } while (0)
  71. #define setup_timer(timer, fn, data) \
  72. do { \
  73. static struct lock_class_key __key; \
  74. setup_timer_key((timer), #timer, &__key, (fn), (data));\
  75. } while (0)
  76. #define setup_timer_on_stack(timer, fn, data) \
  77. do { \
  78. static struct lock_class_key __key; \
  79. setup_timer_on_stack_key((timer), #timer, &__key, \
  80. (fn), (data)); \
  81. } while (0)
  82. #else
  83. #define init_timer(timer)\
  84. init_timer_key((timer), NULL, NULL)
  85. #define init_timer_deferrable(timer)\
  86. init_timer_deferrable_key((timer), NULL, NULL)
  87. #define init_timer_on_stack(timer)\
  88. init_timer_on_stack_key((timer), NULL, NULL)
  89. #define setup_timer(timer, fn, data)\
  90. setup_timer_key((timer), NULL, NULL, (fn), (data))
  91. #define setup_timer_on_stack(timer, fn, data)\
  92. setup_timer_on_stack_key((timer), NULL, NULL, (fn), (data))
  93. #endif
  94. #ifdef CONFIG_DEBUG_OBJECTS_TIMERS
  95. extern void init_timer_on_stack_key(struct timer_list *timer,
  96. const char *name,
  97. struct lock_class_key *key);
  98. extern void destroy_timer_on_stack(struct timer_list *timer);
  99. #else
  100. static inline void destroy_timer_on_stack(struct timer_list *timer) { }
  101. static inline void init_timer_on_stack_key(struct timer_list *timer,
  102. const char *name,
  103. struct lock_class_key *key)
  104. {
  105. init_timer_key(timer, name, key);
  106. }
  107. #endif
  108. static inline void setup_timer_key(struct timer_list * timer,
  109. const char *name,
  110. struct lock_class_key *key,
  111. void (*function)(unsigned long),
  112. unsigned long data)
  113. {
  114. timer->function = function;
  115. timer->data = data;
  116. init_timer_key(timer, name, key);
  117. }
  118. static inline void setup_timer_on_stack_key(struct timer_list *timer,
  119. const char *name,
  120. struct lock_class_key *key,
  121. void (*function)(unsigned long),
  122. unsigned long data)
  123. {
  124. timer->function = function;
  125. timer->data = data;
  126. init_timer_on_stack_key(timer, name, key);
  127. }
  128. /**
  129. * timer_pending - is a timer pending?
  130. * @timer: the timer in question
  131. *
  132. * timer_pending will tell whether a given timer is currently pending,
  133. * or not. Callers must ensure serialization wrt. other operations done
  134. * to this timer, eg. interrupt contexts, or other CPUs on SMP.
  135. *
  136. * return value: 1 if the timer is pending, 0 if not.
  137. */
  138. static inline int timer_pending(const struct timer_list * timer)
  139. {
  140. return timer->entry.next != NULL;
  141. }
  142. extern void add_timer_on(struct timer_list *timer, int cpu);
  143. extern int del_timer(struct timer_list * timer);
  144. extern int mod_timer(struct timer_list *timer, unsigned long expires);
  145. extern int mod_timer_pending(struct timer_list *timer, unsigned long expires);
  146. /*
  147. * The jiffies value which is added to now, when there is no timer
  148. * in the timer wheel:
  149. */
  150. #define NEXT_TIMER_MAX_DELTA ((1UL << 30) - 1)
  151. /*
  152. * Return when the next timer-wheel timeout occurs (in absolute jiffies),
  153. * locks the timer base:
  154. */
  155. extern unsigned long next_timer_interrupt(void);
  156. /*
  157. * Return when the next timer-wheel timeout occurs (in absolute jiffies),
  158. * locks the timer base and does the comparison against the given
  159. * jiffie.
  160. */
  161. extern unsigned long get_next_timer_interrupt(unsigned long now);
  162. /*
  163. * Timer-statistics info:
  164. */
  165. #ifdef CONFIG_TIMER_STATS
  166. #define TIMER_STATS_FLAG_DEFERRABLE 0x1
  167. extern void init_timer_stats(void);
  168. extern void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
  169. void *timerf, char *comm,
  170. unsigned int timer_flag);
  171. extern void __timer_stats_timer_set_start_info(struct timer_list *timer,
  172. void *addr);
  173. static inline void timer_stats_timer_set_start_info(struct timer_list *timer)
  174. {
  175. __timer_stats_timer_set_start_info(timer, __builtin_return_address(0));
  176. }
  177. static inline void timer_stats_timer_clear_start_info(struct timer_list *timer)
  178. {
  179. timer->start_site = NULL;
  180. }
  181. #else
  182. static inline void init_timer_stats(void)
  183. {
  184. }
  185. static inline void timer_stats_timer_set_start_info(struct timer_list *timer)
  186. {
  187. }
  188. static inline void timer_stats_timer_clear_start_info(struct timer_list *timer)
  189. {
  190. }
  191. #endif
  192. extern void add_timer(struct timer_list *timer);
  193. #ifdef CONFIG_SMP
  194. extern int try_to_del_timer_sync(struct timer_list *timer);
  195. extern int del_timer_sync(struct timer_list *timer);
  196. #else
  197. # define try_to_del_timer_sync(t) del_timer(t)
  198. # define del_timer_sync(t) del_timer(t)
  199. #endif
  200. #define del_singleshot_timer_sync(t) del_timer_sync(t)
  201. extern void init_timers(void);
  202. extern void run_local_timers(void);
  203. struct hrtimer;
  204. extern enum hrtimer_restart it_real_fn(struct hrtimer *);
  205. unsigned long __round_jiffies(unsigned long j, int cpu);
  206. unsigned long __round_jiffies_relative(unsigned long j, int cpu);
  207. unsigned long round_jiffies(unsigned long j);
  208. unsigned long round_jiffies_relative(unsigned long j);
  209. unsigned long __round_jiffies_up(unsigned long j, int cpu);
  210. unsigned long __round_jiffies_up_relative(unsigned long j, int cpu);
  211. unsigned long round_jiffies_up(unsigned long j);
  212. unsigned long round_jiffies_up_relative(unsigned long j);
  213. #endif