timer.h 4.6 KB

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