| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_TIMER_H | 
|  | 2 | #define _LINUX_TIMER_H | 
|  | 3 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | #include <linux/list.h> | 
| Ingo Molnar | 82f67cd | 2007-02-16 01:28:13 -0800 | [diff] [blame] | 5 | #include <linux/ktime.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <linux/stddef.h> | 
| Thomas Gleixner | c6f3a97 | 2008-04-30 00:55:03 -0700 | [diff] [blame] | 7 | #include <linux/debugobjects.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 |  | 
| Pavel Machek | a6fa8e5 | 2008-01-30 13:30:00 +0100 | [diff] [blame] | 9 | struct tvec_base; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 |  | 
|  | 11 | struct timer_list { | 
|  | 12 | struct list_head entry; | 
|  | 13 | unsigned long expires; | 
|  | 14 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | void (*function)(unsigned long); | 
|  | 16 | unsigned long data; | 
|  | 17 |  | 
| Pavel Machek | a6fa8e5 | 2008-01-30 13:30:00 +0100 | [diff] [blame] | 18 | struct tvec_base *base; | 
| Ingo Molnar | 82f67cd | 2007-02-16 01:28:13 -0800 | [diff] [blame] | 19 | #ifdef CONFIG_TIMER_STATS | 
|  | 20 | void *start_site; | 
|  | 21 | char start_comm[16]; | 
|  | 22 | int start_pid; | 
|  | 23 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | }; | 
|  | 25 |  | 
| Pavel Machek | a6fa8e5 | 2008-01-30 13:30:00 +0100 | [diff] [blame] | 26 | extern struct tvec_base boot_tvec_bases; | 
| Oleg Nesterov | 55c888d | 2005-06-23 00:08:56 -0700 | [diff] [blame] | 27 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #define TIMER_INITIALIZER(_function, _expires, _data) {		\ | 
| Thomas Gleixner | c6f3a97 | 2008-04-30 00:55:03 -0700 | [diff] [blame] | 29 | .entry = { .prev = TIMER_ENTRY_STATIC },	\ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | .function = (_function),			\ | 
|  | 31 | .expires = (_expires),				\ | 
|  | 32 | .data = (_data),				\ | 
| Oleg Nesterov | 3691c51 | 2006-03-31 02:30:30 -0800 | [diff] [blame] | 33 | .base = &boot_tvec_bases,			\ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | } | 
|  | 35 |  | 
| Ingo Molnar | 8d06afa | 2005-09-09 13:10:40 -0700 | [diff] [blame] | 36 | #define DEFINE_TIMER(_name, _function, _expires, _data)		\ | 
|  | 37 | struct timer_list _name =				\ | 
|  | 38 | TIMER_INITIALIZER(_function, _expires, _data) | 
|  | 39 |  | 
| Harvey Harrison | ec70158 | 2008-02-08 04:19:55 -0800 | [diff] [blame] | 40 | void init_timer(struct timer_list *timer); | 
|  | 41 | void init_timer_deferrable(struct timer_list *timer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 |  | 
| Thomas Gleixner | c6f3a97 | 2008-04-30 00:55:03 -0700 | [diff] [blame] | 43 | #ifdef CONFIG_DEBUG_OBJECTS_TIMERS | 
|  | 44 | extern void init_timer_on_stack(struct timer_list *timer); | 
|  | 45 | extern void destroy_timer_on_stack(struct timer_list *timer); | 
|  | 46 | #else | 
|  | 47 | static inline void destroy_timer_on_stack(struct timer_list *timer) { } | 
|  | 48 | static inline void init_timer_on_stack(struct timer_list *timer) | 
|  | 49 | { | 
|  | 50 | init_timer(timer); | 
|  | 51 | } | 
|  | 52 | #endif | 
|  | 53 |  | 
| Oleg Nesterov | a8db2db | 2005-10-30 15:01:38 -0800 | [diff] [blame] | 54 | static inline void setup_timer(struct timer_list * timer, | 
|  | 55 | void (*function)(unsigned long), | 
|  | 56 | unsigned long data) | 
|  | 57 | { | 
|  | 58 | timer->function = function; | 
|  | 59 | timer->data = data; | 
|  | 60 | init_timer(timer); | 
|  | 61 | } | 
|  | 62 |  | 
| Thomas Gleixner | c6f3a97 | 2008-04-30 00:55:03 -0700 | [diff] [blame] | 63 | static inline void setup_timer_on_stack(struct timer_list *timer, | 
|  | 64 | void (*function)(unsigned long), | 
|  | 65 | unsigned long data) | 
|  | 66 | { | 
|  | 67 | timer->function = function; | 
|  | 68 | timer->data = data; | 
|  | 69 | init_timer_on_stack(timer); | 
|  | 70 | } | 
|  | 71 |  | 
| Robert P. J. Day | 45f8bde | 2007-01-26 00:57:09 -0800 | [diff] [blame] | 72 | /** | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | * timer_pending - is a timer pending? | 
|  | 74 | * @timer: the timer in question | 
|  | 75 | * | 
|  | 76 | * timer_pending will tell whether a given timer is currently pending, | 
|  | 77 | * or not. Callers must ensure serialization wrt. other operations done | 
|  | 78 | * to this timer, eg. interrupt contexts, or other CPUs on SMP. | 
|  | 79 | * | 
|  | 80 | * return value: 1 if the timer is pending, 0 if not. | 
|  | 81 | */ | 
|  | 82 | static inline int timer_pending(const struct timer_list * timer) | 
|  | 83 | { | 
| Oleg Nesterov | 55c888d | 2005-06-23 00:08:56 -0700 | [diff] [blame] | 84 | return timer->entry.next != NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | } | 
|  | 86 |  | 
|  | 87 | extern void add_timer_on(struct timer_list *timer, int cpu); | 
|  | 88 | extern int del_timer(struct timer_list * timer); | 
|  | 89 | extern int __mod_timer(struct timer_list *timer, unsigned long expires); | 
|  | 90 | extern int mod_timer(struct timer_list *timer, unsigned long expires); | 
|  | 91 |  | 
| Thomas Gleixner | fd064b9 | 2007-02-16 01:27:47 -0800 | [diff] [blame] | 92 | /* | 
| Thomas Gleixner | eaad084 | 2007-05-29 23:47:39 +0200 | [diff] [blame] | 93 | * The jiffies value which is added to now, when there is no timer | 
|  | 94 | * in the timer wheel: | 
|  | 95 | */ | 
|  | 96 | #define NEXT_TIMER_MAX_DELTA	((1UL << 30) - 1) | 
|  | 97 |  | 
|  | 98 | /* | 
| Thomas Gleixner | fd064b9 | 2007-02-16 01:27:47 -0800 | [diff] [blame] | 99 | * Return when the next timer-wheel timeout occurs (in absolute jiffies), | 
|  | 100 | * locks the timer base: | 
|  | 101 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | extern unsigned long next_timer_interrupt(void); | 
| Thomas Gleixner | fd064b9 | 2007-02-16 01:27:47 -0800 | [diff] [blame] | 103 | /* | 
|  | 104 | * Return when the next timer-wheel timeout occurs (in absolute jiffies), | 
|  | 105 | * locks the timer base and does the comparison against the given | 
|  | 106 | * jiffie. | 
|  | 107 | */ | 
|  | 108 | extern unsigned long get_next_timer_interrupt(unsigned long now); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 |  | 
| Ingo Molnar | 82f67cd | 2007-02-16 01:28:13 -0800 | [diff] [blame] | 110 | /* | 
|  | 111 | * Timer-statistics info: | 
|  | 112 | */ | 
|  | 113 | #ifdef CONFIG_TIMER_STATS | 
|  | 114 |  | 
| Venki Pallipadi | c5c061b8 | 2007-07-15 23:40:30 -0700 | [diff] [blame] | 115 | #define TIMER_STATS_FLAG_DEFERRABLE	0x1 | 
|  | 116 |  | 
| Ingo Molnar | 82f67cd | 2007-02-16 01:28:13 -0800 | [diff] [blame] | 117 | extern void init_timer_stats(void); | 
|  | 118 |  | 
|  | 119 | extern void timer_stats_update_stats(void *timer, pid_t pid, void *startf, | 
| Venki Pallipadi | c5c061b8 | 2007-07-15 23:40:30 -0700 | [diff] [blame] | 120 | void *timerf, char *comm, | 
|  | 121 | unsigned int timer_flag); | 
| Ingo Molnar | 82f67cd | 2007-02-16 01:28:13 -0800 | [diff] [blame] | 122 |  | 
|  | 123 | extern void __timer_stats_timer_set_start_info(struct timer_list *timer, | 
|  | 124 | void *addr); | 
|  | 125 |  | 
|  | 126 | static inline void timer_stats_timer_set_start_info(struct timer_list *timer) | 
|  | 127 | { | 
|  | 128 | __timer_stats_timer_set_start_info(timer, __builtin_return_address(0)); | 
|  | 129 | } | 
|  | 130 |  | 
|  | 131 | static inline void timer_stats_timer_clear_start_info(struct timer_list *timer) | 
|  | 132 | { | 
|  | 133 | timer->start_site = NULL; | 
|  | 134 | } | 
|  | 135 | #else | 
|  | 136 | static inline void init_timer_stats(void) | 
|  | 137 | { | 
|  | 138 | } | 
|  | 139 |  | 
| Ingo Molnar | 82f67cd | 2007-02-16 01:28:13 -0800 | [diff] [blame] | 140 | static inline void timer_stats_timer_set_start_info(struct timer_list *timer) | 
|  | 141 | { | 
|  | 142 | } | 
|  | 143 |  | 
|  | 144 | static inline void timer_stats_timer_clear_start_info(struct timer_list *timer) | 
|  | 145 | { | 
|  | 146 | } | 
|  | 147 | #endif | 
|  | 148 |  | 
| Robert P. J. Day | 45f8bde | 2007-01-26 00:57:09 -0800 | [diff] [blame] | 149 | /** | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | * add_timer - start a timer | 
|  | 151 | * @timer: the timer to be added | 
|  | 152 | * | 
|  | 153 | * The kernel will do a ->function(->data) callback from the | 
| Andrzej Zaborowski | 13fce80 | 2006-03-24 18:13:37 +0100 | [diff] [blame] | 154 | * timer interrupt at the ->expires point in the future. The | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | * current time is 'jiffies'. | 
|  | 156 | * | 
| Andrzej Zaborowski | 13fce80 | 2006-03-24 18:13:37 +0100 | [diff] [blame] | 157 | * The timer's ->expires, ->function (and if the handler uses it, ->data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | * fields must be set prior calling this function. | 
|  | 159 | * | 
| Andrzej Zaborowski | 13fce80 | 2006-03-24 18:13:37 +0100 | [diff] [blame] | 160 | * Timers with an ->expires field in the past will be executed in the next | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | * timer tick. | 
|  | 162 | */ | 
| Andrew Morton | 15d2bac | 2005-10-30 15:02:24 -0800 | [diff] [blame] | 163 | static inline void add_timer(struct timer_list *timer) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | { | 
| Andrew Morton | 15d2bac | 2005-10-30 15:02:24 -0800 | [diff] [blame] | 165 | BUG_ON(timer_pending(timer)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | __mod_timer(timer, timer->expires); | 
|  | 167 | } | 
|  | 168 |  | 
|  | 169 | #ifdef CONFIG_SMP | 
| Oleg Nesterov | fd450b7 | 2005-06-23 00:08:59 -0700 | [diff] [blame] | 170 | extern int try_to_del_timer_sync(struct timer_list *timer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | extern int del_timer_sync(struct timer_list *timer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | #else | 
| Oleg Nesterov | fd450b7 | 2005-06-23 00:08:59 -0700 | [diff] [blame] | 173 | # define try_to_del_timer_sync(t)	del_timer(t) | 
|  | 174 | # define del_timer_sync(t)		del_timer(t) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | #endif | 
|  | 176 |  | 
| Oleg Nesterov | 55c888d | 2005-06-23 00:08:56 -0700 | [diff] [blame] | 177 | #define del_singleshot_timer_sync(t) del_timer_sync(t) | 
|  | 178 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | extern void init_timers(void); | 
|  | 180 | extern void run_local_timers(void); | 
| Roman Zippel | 05cfb61 | 2006-03-26 01:38:12 -0800 | [diff] [blame] | 181 | struct hrtimer; | 
| Thomas Gleixner | c9cb2e3 | 2007-02-16 01:27:49 -0800 | [diff] [blame] | 182 | extern enum hrtimer_restart it_real_fn(struct hrtimer *); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 |  | 
| Arjan van de Ven | 4c36a5d | 2006-12-10 02:21:24 -0800 | [diff] [blame] | 184 | unsigned long __round_jiffies(unsigned long j, int cpu); | 
|  | 185 | unsigned long __round_jiffies_relative(unsigned long j, int cpu); | 
|  | 186 | unsigned long round_jiffies(unsigned long j); | 
|  | 187 | unsigned long round_jiffies_relative(unsigned long j); | 
|  | 188 |  | 
| Alan Stern | 9c133c4 | 2008-11-06 08:42:48 +0100 | [diff] [blame] | 189 | unsigned long __round_jiffies_up(unsigned long j, int cpu); | 
|  | 190 | unsigned long __round_jiffies_up_relative(unsigned long j, int cpu); | 
|  | 191 | unsigned long round_jiffies_up(unsigned long j); | 
|  | 192 | unsigned long round_jiffies_up_relative(unsigned long j); | 
|  | 193 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | #endif |