timer.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. struct tvec_base;
  7. struct timer_list {
  8. struct list_head entry;
  9. unsigned long expires;
  10. void (*function)(unsigned long);
  11. unsigned long data;
  12. struct tvec_base *base;
  13. #ifdef CONFIG_TIMER_STATS
  14. void *start_site;
  15. char start_comm[16];
  16. int start_pid;
  17. #endif
  18. };
  19. extern struct tvec_base boot_tvec_bases;
  20. #define TIMER_INITIALIZER(_function, _expires, _data) { \
  21. .function = (_function), \
  22. .expires = (_expires), \
  23. .data = (_data), \
  24. .base = &boot_tvec_bases, \
  25. }
  26. #define DEFINE_TIMER(_name, _function, _expires, _data) \
  27. struct timer_list _name = \
  28. TIMER_INITIALIZER(_function, _expires, _data)
  29. void init_timer(struct timer_list *timer);
  30. void init_timer_deferrable(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. * The jiffies value which is added to now, when there is no timer
  59. * in the timer wheel:
  60. */
  61. #define NEXT_TIMER_MAX_DELTA ((1UL << 30) - 1)
  62. /*
  63. * Return when the next timer-wheel timeout occurs (in absolute jiffies),
  64. * locks the timer base:
  65. */
  66. extern unsigned long next_timer_interrupt(void);
  67. /*
  68. * Return when the next timer-wheel timeout occurs (in absolute jiffies),
  69. * locks the timer base and does the comparison against the given
  70. * jiffie.
  71. */
  72. extern unsigned long get_next_timer_interrupt(unsigned long now);
  73. /*
  74. * Timer-statistics info:
  75. */
  76. #ifdef CONFIG_TIMER_STATS
  77. #define TIMER_STATS_FLAG_DEFERRABLE 0x1
  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. unsigned int timer_flag);
  82. extern void __timer_stats_timer_set_start_info(struct timer_list *timer,
  83. void *addr);
  84. static inline void timer_stats_timer_set_start_info(struct timer_list *timer)
  85. {
  86. __timer_stats_timer_set_start_info(timer, __builtin_return_address(0));
  87. }
  88. static inline void timer_stats_timer_clear_start_info(struct timer_list *timer)
  89. {
  90. timer->start_site = NULL;
  91. }
  92. #else
  93. static inline void init_timer_stats(void)
  94. {
  95. }
  96. static inline void timer_stats_timer_set_start_info(struct timer_list *timer)
  97. {
  98. }
  99. static inline void timer_stats_timer_clear_start_info(struct timer_list *timer)
  100. {
  101. }
  102. #endif
  103. /**
  104. * add_timer - start a timer
  105. * @timer: the timer to be added
  106. *
  107. * The kernel will do a ->function(->data) callback from the
  108. * timer interrupt at the ->expires point in the future. The
  109. * current time is 'jiffies'.
  110. *
  111. * The timer's ->expires, ->function (and if the handler uses it, ->data)
  112. * fields must be set prior calling this function.
  113. *
  114. * Timers with an ->expires field in the past will be executed in the next
  115. * timer tick.
  116. */
  117. static inline void add_timer(struct timer_list *timer)
  118. {
  119. BUG_ON(timer_pending(timer));
  120. __mod_timer(timer, timer->expires);
  121. }
  122. #ifdef CONFIG_SMP
  123. extern int try_to_del_timer_sync(struct timer_list *timer);
  124. extern int del_timer_sync(struct timer_list *timer);
  125. #else
  126. # define try_to_del_timer_sync(t) del_timer(t)
  127. # define del_timer_sync(t) del_timer(t)
  128. #endif
  129. #define del_singleshot_timer_sync(t) del_timer_sync(t)
  130. extern void init_timers(void);
  131. extern void run_local_timers(void);
  132. struct hrtimer;
  133. extern enum hrtimer_restart it_real_fn(struct hrtimer *);
  134. unsigned long __round_jiffies(unsigned long j, int cpu);
  135. unsigned long __round_jiffies_relative(unsigned long j, int cpu);
  136. unsigned long round_jiffies(unsigned long j);
  137. unsigned long round_jiffies_relative(unsigned long j);
  138. #endif