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> |
Johannes Berg | 6f2b9b9 | 2009-01-29 16:03:20 +0100 | [diff] [blame] | 8 | #include <linux/stringify.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
Pavel Machek | a6fa8e5 | 2008-01-30 13:30:00 +0100 | [diff] [blame] | 10 | struct tvec_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
| 12 | struct timer_list { |
| 13 | struct list_head entry; |
| 14 | unsigned long expires; |
| 15 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | void (*function)(unsigned long); |
| 17 | unsigned long data; |
| 18 | |
Pavel Machek | a6fa8e5 | 2008-01-30 13:30:00 +0100 | [diff] [blame] | 19 | struct tvec_base *base; |
Ingo Molnar | 82f67cd | 2007-02-16 01:28:13 -0800 | [diff] [blame] | 20 | #ifdef CONFIG_TIMER_STATS |
| 21 | void *start_site; |
| 22 | char start_comm[16]; |
| 23 | int start_pid; |
| 24 | #endif |
Johannes Berg | 6f2b9b9 | 2009-01-29 16:03:20 +0100 | [diff] [blame] | 25 | #ifdef CONFIG_LOCKDEP |
| 26 | struct lockdep_map lockdep_map; |
| 27 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | }; |
| 29 | |
Pavel Machek | a6fa8e5 | 2008-01-30 13:30:00 +0100 | [diff] [blame] | 30 | extern struct tvec_base boot_tvec_bases; |
Oleg Nesterov | 55c888d | 2005-06-23 00:08:56 -0700 | [diff] [blame] | 31 | |
Johannes Berg | 6f2b9b9 | 2009-01-29 16:03:20 +0100 | [diff] [blame] | 32 | #ifdef CONFIG_LOCKDEP |
| 33 | /* |
| 34 | * NB: because we have to copy the lockdep_map, setting the lockdep_map key |
| 35 | * (second argument) here is required, otherwise it could be initialised to |
| 36 | * the copy of the lockdep_map later! We use the pointer to and the string |
| 37 | * "<file>:<line>" as the key resp. the name of the lockdep_map. |
| 38 | */ |
| 39 | #define __TIMER_LOCKDEP_MAP_INITIALIZER(_kn) \ |
| 40 | .lockdep_map = STATIC_LOCKDEP_MAP_INIT(_kn, &_kn), |
| 41 | #else |
| 42 | #define __TIMER_LOCKDEP_MAP_INITIALIZER(_kn) |
| 43 | #endif |
| 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #define TIMER_INITIALIZER(_function, _expires, _data) { \ |
Thomas Gleixner | c6f3a97 | 2008-04-30 00:55:03 -0700 | [diff] [blame] | 46 | .entry = { .prev = TIMER_ENTRY_STATIC }, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | .function = (_function), \ |
| 48 | .expires = (_expires), \ |
| 49 | .data = (_data), \ |
Oleg Nesterov | 3691c51 | 2006-03-31 02:30:30 -0800 | [diff] [blame] | 50 | .base = &boot_tvec_bases, \ |
Johannes Berg | 6f2b9b9 | 2009-01-29 16:03:20 +0100 | [diff] [blame] | 51 | __TIMER_LOCKDEP_MAP_INITIALIZER( \ |
| 52 | __FILE__ ":" __stringify(__LINE__)) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Ingo Molnar | 8d06afa | 2005-09-09 13:10:40 -0700 | [diff] [blame] | 55 | #define DEFINE_TIMER(_name, _function, _expires, _data) \ |
| 56 | struct timer_list _name = \ |
| 57 | TIMER_INITIALIZER(_function, _expires, _data) |
| 58 | |
Johannes Berg | 6f2b9b9 | 2009-01-29 16:03:20 +0100 | [diff] [blame] | 59 | void init_timer_key(struct timer_list *timer, |
| 60 | const char *name, |
| 61 | struct lock_class_key *key); |
| 62 | void init_timer_deferrable_key(struct timer_list *timer, |
| 63 | const char *name, |
| 64 | struct lock_class_key *key); |
| 65 | |
| 66 | #ifdef CONFIG_LOCKDEP |
| 67 | #define init_timer(timer) \ |
| 68 | do { \ |
| 69 | static struct lock_class_key __key; \ |
| 70 | init_timer_key((timer), #timer, &__key); \ |
| 71 | } while (0) |
| 72 | |
| 73 | #define init_timer_deferrable(timer) \ |
| 74 | do { \ |
| 75 | static struct lock_class_key __key; \ |
| 76 | init_timer_deferrable_key((timer), #timer, &__key); \ |
| 77 | } while (0) |
| 78 | |
| 79 | #define init_timer_on_stack(timer) \ |
| 80 | do { \ |
| 81 | static struct lock_class_key __key; \ |
| 82 | init_timer_on_stack_key((timer), #timer, &__key); \ |
| 83 | } while (0) |
| 84 | |
| 85 | #define setup_timer(timer, fn, data) \ |
| 86 | do { \ |
| 87 | static struct lock_class_key __key; \ |
| 88 | setup_timer_key((timer), #timer, &__key, (fn), (data));\ |
| 89 | } while (0) |
| 90 | |
| 91 | #define setup_timer_on_stack(timer, fn, data) \ |
| 92 | do { \ |
| 93 | static struct lock_class_key __key; \ |
| 94 | setup_timer_on_stack_key((timer), #timer, &__key, \ |
| 95 | (fn), (data)); \ |
| 96 | } while (0) |
| 97 | #else |
| 98 | #define init_timer(timer)\ |
| 99 | init_timer_key((timer), NULL, NULL) |
| 100 | #define init_timer_deferrable(timer)\ |
| 101 | init_timer_deferrable_key((timer), NULL, NULL) |
| 102 | #define init_timer_on_stack(timer)\ |
| 103 | init_timer_on_stack_key((timer), NULL, NULL) |
| 104 | #define setup_timer(timer, fn, data)\ |
| 105 | setup_timer_key((timer), NULL, NULL, (fn), (data)) |
| 106 | #define setup_timer_on_stack(timer, fn, data)\ |
| 107 | setup_timer_on_stack_key((timer), NULL, NULL, (fn), (data)) |
| 108 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Thomas Gleixner | c6f3a97 | 2008-04-30 00:55:03 -0700 | [diff] [blame] | 110 | #ifdef CONFIG_DEBUG_OBJECTS_TIMERS |
Johannes Berg | 6f2b9b9 | 2009-01-29 16:03:20 +0100 | [diff] [blame] | 111 | extern void init_timer_on_stack_key(struct timer_list *timer, |
| 112 | const char *name, |
| 113 | struct lock_class_key *key); |
Thomas Gleixner | c6f3a97 | 2008-04-30 00:55:03 -0700 | [diff] [blame] | 114 | extern void destroy_timer_on_stack(struct timer_list *timer); |
| 115 | #else |
| 116 | static inline void destroy_timer_on_stack(struct timer_list *timer) { } |
Johannes Berg | 6f2b9b9 | 2009-01-29 16:03:20 +0100 | [diff] [blame] | 117 | static inline void init_timer_on_stack_key(struct timer_list *timer, |
| 118 | const char *name, |
| 119 | struct lock_class_key *key) |
Thomas Gleixner | c6f3a97 | 2008-04-30 00:55:03 -0700 | [diff] [blame] | 120 | { |
Johannes Berg | 6f2b9b9 | 2009-01-29 16:03:20 +0100 | [diff] [blame] | 121 | init_timer_key(timer, name, key); |
Thomas Gleixner | c6f3a97 | 2008-04-30 00:55:03 -0700 | [diff] [blame] | 122 | } |
| 123 | #endif |
| 124 | |
Johannes Berg | 6f2b9b9 | 2009-01-29 16:03:20 +0100 | [diff] [blame] | 125 | static inline void setup_timer_key(struct timer_list * timer, |
| 126 | const char *name, |
| 127 | struct lock_class_key *key, |
Oleg Nesterov | a8db2db | 2005-10-30 15:01:38 -0800 | [diff] [blame] | 128 | void (*function)(unsigned long), |
| 129 | unsigned long data) |
| 130 | { |
| 131 | timer->function = function; |
| 132 | timer->data = data; |
Johannes Berg | 6f2b9b9 | 2009-01-29 16:03:20 +0100 | [diff] [blame] | 133 | init_timer_key(timer, name, key); |
Oleg Nesterov | a8db2db | 2005-10-30 15:01:38 -0800 | [diff] [blame] | 134 | } |
| 135 | |
Johannes Berg | 6f2b9b9 | 2009-01-29 16:03:20 +0100 | [diff] [blame] | 136 | static inline void setup_timer_on_stack_key(struct timer_list *timer, |
| 137 | const char *name, |
| 138 | struct lock_class_key *key, |
Thomas Gleixner | c6f3a97 | 2008-04-30 00:55:03 -0700 | [diff] [blame] | 139 | void (*function)(unsigned long), |
| 140 | unsigned long data) |
| 141 | { |
| 142 | timer->function = function; |
| 143 | timer->data = data; |
Johannes Berg | 6f2b9b9 | 2009-01-29 16:03:20 +0100 | [diff] [blame] | 144 | init_timer_on_stack_key(timer, name, key); |
Thomas Gleixner | c6f3a97 | 2008-04-30 00:55:03 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Robert P. J. Day | 45f8bde | 2007-01-26 00:57:09 -0800 | [diff] [blame] | 147 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | * timer_pending - is a timer pending? |
| 149 | * @timer: the timer in question |
| 150 | * |
| 151 | * timer_pending will tell whether a given timer is currently pending, |
| 152 | * or not. Callers must ensure serialization wrt. other operations done |
| 153 | * to this timer, eg. interrupt contexts, or other CPUs on SMP. |
| 154 | * |
| 155 | * return value: 1 if the timer is pending, 0 if not. |
| 156 | */ |
| 157 | static inline int timer_pending(const struct timer_list * timer) |
| 158 | { |
Oleg Nesterov | 55c888d | 2005-06-23 00:08:56 -0700 | [diff] [blame] | 159 | return timer->entry.next != NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | extern void add_timer_on(struct timer_list *timer, int cpu); |
| 163 | extern int del_timer(struct timer_list * timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | extern int mod_timer(struct timer_list *timer, unsigned long expires); |
Ingo Molnar | 7401922 | 2009-02-18 12:23:29 +0100 | [diff] [blame] | 165 | extern int mod_timer_pending(struct timer_list *timer, unsigned long expires); |
Arun R Bharadwaj | 597d027 | 2009-04-16 12:13:26 +0530 | [diff] [blame] | 166 | extern int mod_timer_pinned(struct timer_list *timer, unsigned long expires); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
Arun R Bharadwaj | 597d027 | 2009-04-16 12:13:26 +0530 | [diff] [blame] | 168 | #define TIMER_NOT_PINNED 0 |
| 169 | #define TIMER_PINNED 1 |
Thomas Gleixner | fd064b9 | 2007-02-16 01:27:47 -0800 | [diff] [blame] | 170 | /* |
Thomas Gleixner | eaad084 | 2007-05-29 23:47:39 +0200 | [diff] [blame] | 171 | * The jiffies value which is added to now, when there is no timer |
| 172 | * in the timer wheel: |
| 173 | */ |
| 174 | #define NEXT_TIMER_MAX_DELTA ((1UL << 30) - 1) |
| 175 | |
| 176 | /* |
Thomas Gleixner | fd064b9 | 2007-02-16 01:27:47 -0800 | [diff] [blame] | 177 | * Return when the next timer-wheel timeout occurs (in absolute jiffies), |
Thomas Gleixner | fd064b9 | 2007-02-16 01:27:47 -0800 | [diff] [blame] | 178 | * locks the timer base and does the comparison against the given |
| 179 | * jiffie. |
| 180 | */ |
| 181 | extern unsigned long get_next_timer_interrupt(unsigned long now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
Ingo Molnar | 82f67cd | 2007-02-16 01:28:13 -0800 | [diff] [blame] | 183 | /* |
| 184 | * Timer-statistics info: |
| 185 | */ |
| 186 | #ifdef CONFIG_TIMER_STATS |
| 187 | |
Heiko Carstens | 507e123 | 2009-06-23 17:38:15 +0200 | [diff] [blame] | 188 | extern int timer_stats_active; |
| 189 | |
Venki Pallipadi | c5c061b8 | 2007-07-15 23:40:30 -0700 | [diff] [blame] | 190 | #define TIMER_STATS_FLAG_DEFERRABLE 0x1 |
| 191 | |
Ingo Molnar | 82f67cd | 2007-02-16 01:28:13 -0800 | [diff] [blame] | 192 | extern void init_timer_stats(void); |
| 193 | |
| 194 | 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] | 195 | void *timerf, char *comm, |
| 196 | unsigned int timer_flag); |
Ingo Molnar | 82f67cd | 2007-02-16 01:28:13 -0800 | [diff] [blame] | 197 | |
| 198 | extern void __timer_stats_timer_set_start_info(struct timer_list *timer, |
| 199 | void *addr); |
| 200 | |
| 201 | static inline void timer_stats_timer_set_start_info(struct timer_list *timer) |
| 202 | { |
Heiko Carstens | 507e123 | 2009-06-23 17:38:15 +0200 | [diff] [blame] | 203 | if (likely(!timer_stats_active)) |
| 204 | return; |
Ingo Molnar | 82f67cd | 2007-02-16 01:28:13 -0800 | [diff] [blame] | 205 | __timer_stats_timer_set_start_info(timer, __builtin_return_address(0)); |
| 206 | } |
| 207 | |
| 208 | static inline void timer_stats_timer_clear_start_info(struct timer_list *timer) |
| 209 | { |
| 210 | timer->start_site = NULL; |
| 211 | } |
| 212 | #else |
| 213 | static inline void init_timer_stats(void) |
| 214 | { |
| 215 | } |
| 216 | |
Ingo Molnar | 82f67cd | 2007-02-16 01:28:13 -0800 | [diff] [blame] | 217 | static inline void timer_stats_timer_set_start_info(struct timer_list *timer) |
| 218 | { |
| 219 | } |
| 220 | |
| 221 | static inline void timer_stats_timer_clear_start_info(struct timer_list *timer) |
| 222 | { |
| 223 | } |
| 224 | #endif |
| 225 | |
Ingo Molnar | 7401922 | 2009-02-18 12:23:29 +0100 | [diff] [blame] | 226 | extern void add_timer(struct timer_list *timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
| 228 | #ifdef CONFIG_SMP |
Oleg Nesterov | fd450b7 | 2005-06-23 00:08:59 -0700 | [diff] [blame] | 229 | extern int try_to_del_timer_sync(struct timer_list *timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | extern int del_timer_sync(struct timer_list *timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | #else |
Oleg Nesterov | fd450b7 | 2005-06-23 00:08:59 -0700 | [diff] [blame] | 232 | # define try_to_del_timer_sync(t) del_timer(t) |
| 233 | # define del_timer_sync(t) del_timer(t) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | #endif |
| 235 | |
Oleg Nesterov | 55c888d | 2005-06-23 00:08:56 -0700 | [diff] [blame] | 236 | #define del_singleshot_timer_sync(t) del_timer_sync(t) |
| 237 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | extern void init_timers(void); |
| 239 | extern void run_local_timers(void); |
Roman Zippel | 05cfb61 | 2006-03-26 01:38:12 -0800 | [diff] [blame] | 240 | struct hrtimer; |
Thomas Gleixner | c9cb2e3 | 2007-02-16 01:27:49 -0800 | [diff] [blame] | 241 | extern enum hrtimer_restart it_real_fn(struct hrtimer *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
Arjan van de Ven | 4c36a5d | 2006-12-10 02:21:24 -0800 | [diff] [blame] | 243 | unsigned long __round_jiffies(unsigned long j, int cpu); |
| 244 | unsigned long __round_jiffies_relative(unsigned long j, int cpu); |
| 245 | unsigned long round_jiffies(unsigned long j); |
| 246 | unsigned long round_jiffies_relative(unsigned long j); |
| 247 | |
Alan Stern | 9c133c4 | 2008-11-06 08:42:48 +0100 | [diff] [blame] | 248 | unsigned long __round_jiffies_up(unsigned long j, int cpu); |
| 249 | unsigned long __round_jiffies_up_relative(unsigned long j, int cpu); |
| 250 | unsigned long round_jiffies_up(unsigned long j); |
| 251 | unsigned long round_jiffies_up_relative(unsigned long j); |
| 252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | #endif |