timer.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. * Return when the next timer-wheel timeout occurs (in absolute jiffies),
  60. * locks the timer base:
  61. */
  62. extern unsigned long next_timer_interrupt(void);
  63. /*
  64. * Return when the next timer-wheel timeout occurs (in absolute jiffies),
  65. * locks the timer base and does the comparison against the given
  66. * jiffie.
  67. */
  68. extern unsigned long get_next_timer_interrupt(unsigned long now);
  69. /*
  70. * Timer-statistics info:
  71. */
  72. #ifdef CONFIG_TIMER_STATS
  73. extern void init_timer_stats(void);
  74. extern void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
  75. void *timerf, char * comm);
  76. static inline void timer_stats_account_timer(struct timer_list *timer)
  77. {
  78. timer_stats_update_stats(timer, timer->start_pid, timer->start_site,
  79. timer->function, timer->start_comm);
  80. }
  81. extern void __timer_stats_timer_set_start_info(struct timer_list *timer,
  82. void *addr);
  83. static inline void timer_stats_timer_set_start_info(struct timer_list *timer)
  84. {
  85. __timer_stats_timer_set_start_info(timer, __builtin_return_address(0));
  86. }
  87. static inline void timer_stats_timer_clear_start_info(struct timer_list *timer)
  88. {
  89. timer->start_site = NULL;
  90. }
  91. #else
  92. static inline void init_timer_stats(void)
  93. {
  94. }
  95. static inline void timer_stats_account_timer(struct timer_list *timer)
  96. {
  97. }
  98. static inline void timer_stats_timer_set_start_info(struct timer_list *timer)
  99. {
  100. }
  101. static inline void timer_stats_timer_clear_start_info(struct timer_list *timer)
  102. {
  103. }
  104. #endif
  105. extern void delayed_work_timer_fn(unsigned long __data);
  106. /**
  107. * add_timer - start a timer
  108. * @timer: the timer to be added
  109. *
  110. * The kernel will do a ->function(->data) callback from the
  111. * timer interrupt at the ->expires point in the future. The
  112. * current time is 'jiffies'.
  113. *
  114. * The timer's ->expires, ->function (and if the handler uses it, ->data)
  115. * fields must be set prior calling this function.
  116. *
  117. * Timers with an ->expires field in the past will be executed in the next
  118. * timer tick.
  119. */
  120. static inline void add_timer(struct timer_list *timer)
  121. {
  122. BUG_ON(timer_pending(timer));
  123. __mod_timer(timer, timer->expires);
  124. }
  125. #ifdef CONFIG_SMP
  126. extern int try_to_del_timer_sync(struct timer_list *timer);
  127. extern int del_timer_sync(struct timer_list *timer);
  128. #else
  129. # define try_to_del_timer_sync(t) del_timer(t)
  130. # define del_timer_sync(t) del_timer(t)
  131. #endif
  132. #define del_singleshot_timer_sync(t) del_timer_sync(t)
  133. extern void init_timers(void);
  134. extern void run_local_timers(void);
  135. struct hrtimer;
  136. extern enum hrtimer_restart it_real_fn(struct hrtimer *);
  137. unsigned long __round_jiffies(unsigned long j, int cpu);
  138. unsigned long __round_jiffies_relative(unsigned long j, int cpu);
  139. unsigned long round_jiffies(unsigned long j);
  140. unsigned long round_jiffies_relative(unsigned long j);
  141. #endif