Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame^] | 1 | #ifndef _LINUX_TIMER_H |
| 2 | #define _LINUX_TIMER_H |
| 3 | |
| 4 | #include <linux/list.h> |
| 5 | #include <linux/ktime.h> |
| 6 | #include <linux/stddef.h> |
| 7 | #include <linux/debugobjects.h> |
| 8 | #include <linux/stringify.h> |
| 9 | |
| 10 | struct tvec_base; |
| 11 | |
| 12 | struct timer_list { |
| 13 | struct list_head entry; |
| 14 | unsigned long expires; |
| 15 | struct tvec_base *base; |
| 16 | |
| 17 | void (*function)(unsigned long); |
| 18 | unsigned long data; |
| 19 | |
| 20 | int slack; |
| 21 | |
| 22 | #ifdef CONFIG_TIMER_STATS |
| 23 | int start_pid; |
| 24 | void *start_site; |
| 25 | char start_comm[16]; |
| 26 | #endif |
| 27 | #ifdef CONFIG_LOCKDEP |
| 28 | struct lockdep_map lockdep_map; |
| 29 | #endif |
| 30 | }; |
| 31 | |
| 32 | extern struct tvec_base boot_tvec_bases; |
| 33 | |
| 34 | #ifdef CONFIG_LOCKDEP |
| 35 | #define __TIMER_LOCKDEP_MAP_INITIALIZER(_kn) \ |
| 36 | .lockdep_map = STATIC_LOCKDEP_MAP_INIT(_kn, &_kn), |
| 37 | #else |
| 38 | #define __TIMER_LOCKDEP_MAP_INITIALIZER(_kn) |
| 39 | #endif |
| 40 | |
| 41 | #define TBASE_DEFERRABLE_FLAG (0x1) |
| 42 | |
| 43 | #define TIMER_INITIALIZER(_function, _expires, _data) { \ |
| 44 | .entry = { .prev = TIMER_ENTRY_STATIC }, \ |
| 45 | .function = (_function), \ |
| 46 | .expires = (_expires), \ |
| 47 | .data = (_data), \ |
| 48 | .base = &boot_tvec_bases, \ |
| 49 | .slack = -1, \ |
| 50 | __TIMER_LOCKDEP_MAP_INITIALIZER( \ |
| 51 | __FILE__ ":" __stringify(__LINE__)) \ |
| 52 | } |
| 53 | |
| 54 | #define TBASE_MAKE_DEFERRED(ptr) ((struct tvec_base *) \ |
| 55 | ((unsigned char *)(ptr) + TBASE_DEFERRABLE_FLAG)) |
| 56 | |
| 57 | #define TIMER_DEFERRED_INITIALIZER(_function, _expires, _data) {\ |
| 58 | .entry = { .prev = TIMER_ENTRY_STATIC }, \ |
| 59 | .function = (_function), \ |
| 60 | .expires = (_expires), \ |
| 61 | .data = (_data), \ |
| 62 | .base = TBASE_MAKE_DEFERRED(&boot_tvec_bases), \ |
| 63 | __TIMER_LOCKDEP_MAP_INITIALIZER( \ |
| 64 | __FILE__ ":" __stringify(__LINE__)) \ |
| 65 | } |
| 66 | |
| 67 | #define DEFINE_TIMER(_name, _function, _expires, _data) \ |
| 68 | struct timer_list _name = \ |
| 69 | TIMER_INITIALIZER(_function, _expires, _data) |
| 70 | |
| 71 | void init_timer_key(struct timer_list *timer, |
| 72 | const char *name, |
| 73 | struct lock_class_key *key); |
| 74 | void init_timer_deferrable_key(struct timer_list *timer, |
| 75 | const char *name, |
| 76 | struct lock_class_key *key); |
| 77 | |
| 78 | #ifdef CONFIG_LOCKDEP |
| 79 | #define init_timer(timer) \ |
| 80 | do { \ |
| 81 | static struct lock_class_key __key; \ |
| 82 | init_timer_key((timer), #timer, &__key); \ |
| 83 | } while (0) |
| 84 | |
| 85 | #define init_timer_deferrable(timer) \ |
| 86 | do { \ |
| 87 | static struct lock_class_key __key; \ |
| 88 | init_timer_deferrable_key((timer), #timer, &__key); \ |
| 89 | } while (0) |
| 90 | |
| 91 | #define init_timer_on_stack(timer) \ |
| 92 | do { \ |
| 93 | static struct lock_class_key __key; \ |
| 94 | init_timer_on_stack_key((timer), #timer, &__key); \ |
| 95 | } while (0) |
| 96 | |
| 97 | #define setup_timer(timer, fn, data) \ |
| 98 | do { \ |
| 99 | static struct lock_class_key __key; \ |
| 100 | setup_timer_key((timer), #timer, &__key, (fn), (data));\ |
| 101 | } while (0) |
| 102 | |
| 103 | #define setup_timer_on_stack(timer, fn, data) \ |
| 104 | do { \ |
| 105 | static struct lock_class_key __key; \ |
| 106 | setup_timer_on_stack_key((timer), #timer, &__key, \ |
| 107 | (fn), (data)); \ |
| 108 | } while (0) |
| 109 | #define setup_deferrable_timer_on_stack(timer, fn, data) \ |
| 110 | do { \ |
| 111 | static struct lock_class_key __key; \ |
| 112 | setup_deferrable_timer_on_stack_key((timer), #timer, \ |
| 113 | &__key, (fn), \ |
| 114 | (data)); \ |
| 115 | } while (0) |
| 116 | #else |
| 117 | #define init_timer(timer)\ |
| 118 | init_timer_key((timer), NULL, NULL) |
| 119 | #define init_timer_deferrable(timer)\ |
| 120 | init_timer_deferrable_key((timer), NULL, NULL) |
| 121 | #define init_timer_on_stack(timer)\ |
| 122 | init_timer_on_stack_key((timer), NULL, NULL) |
| 123 | #define setup_timer(timer, fn, data)\ |
| 124 | setup_timer_key((timer), NULL, NULL, (fn), (data)) |
| 125 | #define setup_timer_on_stack(timer, fn, data)\ |
| 126 | setup_timer_on_stack_key((timer), NULL, NULL, (fn), (data)) |
| 127 | #define setup_deferrable_timer_on_stack(timer, fn, data)\ |
| 128 | setup_deferrable_timer_on_stack_key((timer), NULL, NULL, (fn), (data)) |
| 129 | #endif |
| 130 | |
| 131 | #ifdef CONFIG_DEBUG_OBJECTS_TIMERS |
| 132 | extern void init_timer_on_stack_key(struct timer_list *timer, |
| 133 | const char *name, |
| 134 | struct lock_class_key *key); |
| 135 | extern void destroy_timer_on_stack(struct timer_list *timer); |
| 136 | #else |
| 137 | static inline void destroy_timer_on_stack(struct timer_list *timer) { } |
| 138 | static inline void init_timer_on_stack_key(struct timer_list *timer, |
| 139 | const char *name, |
| 140 | struct lock_class_key *key) |
| 141 | { |
| 142 | init_timer_key(timer, name, key); |
| 143 | } |
| 144 | #endif |
| 145 | |
| 146 | static inline void setup_timer_key(struct timer_list * timer, |
| 147 | const char *name, |
| 148 | struct lock_class_key *key, |
| 149 | void (*function)(unsigned long), |
| 150 | unsigned long data) |
| 151 | { |
| 152 | timer->function = function; |
| 153 | timer->data = data; |
| 154 | init_timer_key(timer, name, key); |
| 155 | } |
| 156 | |
| 157 | static inline void setup_timer_on_stack_key(struct timer_list *timer, |
| 158 | const char *name, |
| 159 | struct lock_class_key *key, |
| 160 | void (*function)(unsigned long), |
| 161 | unsigned long data) |
| 162 | { |
| 163 | timer->function = function; |
| 164 | timer->data = data; |
| 165 | init_timer_on_stack_key(timer, name, key); |
| 166 | } |
| 167 | |
| 168 | extern void setup_deferrable_timer_on_stack_key(struct timer_list *timer, |
| 169 | const char *name, |
| 170 | struct lock_class_key *key, |
| 171 | void (*function)(unsigned long), |
| 172 | unsigned long data); |
| 173 | |
| 174 | static inline int timer_pending(const struct timer_list * timer) |
| 175 | { |
| 176 | return timer->entry.next != NULL; |
| 177 | } |
| 178 | |
| 179 | extern void add_timer_on(struct timer_list *timer, int cpu); |
| 180 | extern int del_timer(struct timer_list * timer); |
| 181 | extern int mod_timer(struct timer_list *timer, unsigned long expires); |
| 182 | extern int mod_timer_pending(struct timer_list *timer, unsigned long expires); |
| 183 | extern int mod_timer_pinned(struct timer_list *timer, unsigned long expires); |
| 184 | |
| 185 | extern void set_timer_slack(struct timer_list *time, int slack_hz); |
| 186 | |
| 187 | #define TIMER_NOT_PINNED 0 |
| 188 | #define TIMER_PINNED 1 |
| 189 | #define NEXT_TIMER_MAX_DELTA ((1UL << 30) - 1) |
| 190 | |
| 191 | extern unsigned long get_next_timer_interrupt(unsigned long now); |
| 192 | |
| 193 | #ifdef CONFIG_TIMER_STATS |
| 194 | |
| 195 | extern int timer_stats_active; |
| 196 | |
| 197 | #define TIMER_STATS_FLAG_DEFERRABLE 0x1 |
| 198 | |
| 199 | extern void init_timer_stats(void); |
| 200 | |
| 201 | extern void timer_stats_update_stats(void *timer, pid_t pid, void *startf, |
| 202 | void *timerf, char *comm, |
| 203 | unsigned int timer_flag); |
| 204 | |
| 205 | extern void __timer_stats_timer_set_start_info(struct timer_list *timer, |
| 206 | void *addr); |
| 207 | |
| 208 | static inline void timer_stats_timer_set_start_info(struct timer_list *timer) |
| 209 | { |
| 210 | if (likely(!timer_stats_active)) |
| 211 | return; |
| 212 | __timer_stats_timer_set_start_info(timer, __builtin_return_address(0)); |
| 213 | } |
| 214 | |
| 215 | static inline void timer_stats_timer_clear_start_info(struct timer_list *timer) |
| 216 | { |
| 217 | timer->start_site = NULL; |
| 218 | } |
| 219 | #else |
| 220 | static inline void init_timer_stats(void) |
| 221 | { |
| 222 | } |
| 223 | |
| 224 | static inline void timer_stats_timer_set_start_info(struct timer_list *timer) |
| 225 | { |
| 226 | } |
| 227 | |
| 228 | static inline void timer_stats_timer_clear_start_info(struct timer_list *timer) |
| 229 | { |
| 230 | } |
| 231 | #endif |
| 232 | |
| 233 | extern void add_timer(struct timer_list *timer); |
| 234 | |
| 235 | extern int try_to_del_timer_sync(struct timer_list *timer); |
| 236 | |
| 237 | #ifdef CONFIG_SMP |
| 238 | extern int del_timer_sync(struct timer_list *timer); |
| 239 | #else |
| 240 | # define del_timer_sync(t) del_timer(t) |
| 241 | #endif |
| 242 | |
| 243 | #define del_singleshot_timer_sync(t) del_timer_sync(t) |
| 244 | |
| 245 | extern void init_timers(void); |
| 246 | extern void run_local_timers(void); |
| 247 | struct hrtimer; |
| 248 | extern enum hrtimer_restart it_real_fn(struct hrtimer *); |
| 249 | |
| 250 | unsigned long __round_jiffies(unsigned long j, int cpu); |
| 251 | unsigned long __round_jiffies_relative(unsigned long j, int cpu); |
| 252 | unsigned long round_jiffies(unsigned long j); |
| 253 | unsigned long round_jiffies_relative(unsigned long j); |
| 254 | |
| 255 | unsigned long __round_jiffies_up(unsigned long j, int cpu); |
| 256 | unsigned long __round_jiffies_up_relative(unsigned long j, int cpu); |
| 257 | unsigned long round_jiffies_up(unsigned long j); |
| 258 | unsigned long round_jiffies_up_relative(unsigned long j); |
| 259 | |
| 260 | #endif |