diff options
Diffstat (limited to 'include/linux/timer.h')
| -rw-r--r-- | include/linux/timer.h | 165 |
1 files changed, 100 insertions, 65 deletions
diff --git a/include/linux/timer.h b/include/linux/timer.h index 8c5a197e158..6abd9138bed 100644 --- a/include/linux/timer.h +++ b/include/linux/timer.h | |||
| @@ -49,112 +49,147 @@ extern struct tvec_base boot_tvec_bases; | |||
| 49 | #endif | 49 | #endif |
| 50 | 50 | ||
| 51 | /* | 51 | /* |
| 52 | * Note that all tvec_bases are at least 4 byte aligned and lower two bits | 52 | * Note that all tvec_bases are 2 byte aligned and lower bit of |
| 53 | * of base in timer_list is guaranteed to be zero. Use them for flags. | 53 | * base in timer_list is guaranteed to be zero. Use the LSB to |
| 54 | * indicate whether the timer is deferrable. | ||
| 54 | * | 55 | * |
| 55 | * A deferrable timer will work normally when the system is busy, but | 56 | * A deferrable timer will work normally when the system is busy, but |
| 56 | * will not cause a CPU to come out of idle just to service it; instead, | 57 | * will not cause a CPU to come out of idle just to service it; instead, |
| 57 | * the timer will be serviced when the CPU eventually wakes up with a | 58 | * the timer will be serviced when the CPU eventually wakes up with a |
| 58 | * subsequent non-deferrable timer. | 59 | * subsequent non-deferrable timer. |
| 59 | * | ||
| 60 | * An irqsafe timer is executed with IRQ disabled and it's safe to wait for | ||
| 61 | * the completion of the running instance from IRQ handlers, for example, | ||
| 62 | * by calling del_timer_sync(). | ||
| 63 | * | ||
| 64 | * Note: The irq disabled callback execution is a special case for | ||
| 65 | * workqueue locking issues. It's not meant for executing random crap | ||
| 66 | * with interrupts disabled. Abuse is monitored! | ||
| 67 | */ | 60 | */ |
| 68 | #define TIMER_DEFERRABLE 0x1LU | 61 | #define TBASE_DEFERRABLE_FLAG (0x1) |
| 69 | #define TIMER_IRQSAFE 0x2LU | ||
| 70 | 62 | ||
| 71 | #define TIMER_FLAG_MASK 0x3LU | 63 | #define TIMER_INITIALIZER(_function, _expires, _data) { \ |
| 72 | |||
| 73 | #define __TIMER_INITIALIZER(_function, _expires, _data, _flags) { \ | ||
| 74 | .entry = { .prev = TIMER_ENTRY_STATIC }, \ | 64 | .entry = { .prev = TIMER_ENTRY_STATIC }, \ |
| 75 | .function = (_function), \ | 65 | .function = (_function), \ |
| 76 | .expires = (_expires), \ | 66 | .expires = (_expires), \ |
| 77 | .data = (_data), \ | 67 | .data = (_data), \ |
| 78 | .base = (void *)((unsigned long)&boot_tvec_bases + (_flags)), \ | 68 | .base = &boot_tvec_bases, \ |
| 79 | .slack = -1, \ | 69 | .slack = -1, \ |
| 80 | __TIMER_LOCKDEP_MAP_INITIALIZER( \ | 70 | __TIMER_LOCKDEP_MAP_INITIALIZER( \ |
| 81 | __FILE__ ":" __stringify(__LINE__)) \ | 71 | __FILE__ ":" __stringify(__LINE__)) \ |
| 82 | } | 72 | } |
| 83 | 73 | ||
| 84 | #define TIMER_INITIALIZER(_function, _expires, _data) \ | 74 | #define TBASE_MAKE_DEFERRED(ptr) ((struct tvec_base *) \ |
| 85 | __TIMER_INITIALIZER((_function), (_expires), (_data), 0) | 75 | ((unsigned char *)(ptr) + TBASE_DEFERRABLE_FLAG)) |
| 86 | 76 | ||
| 87 | #define TIMER_DEFERRED_INITIALIZER(_function, _expires, _data) \ | 77 | #define TIMER_DEFERRED_INITIALIZER(_function, _expires, _data) {\ |
| 88 | __TIMER_INITIALIZER((_function), (_expires), (_data), TIMER_DEFERRABLE) | 78 | .entry = { .prev = TIMER_ENTRY_STATIC }, \ |
| 79 | .function = (_function), \ | ||
| 80 | .expires = (_expires), \ | ||
| 81 | .data = (_data), \ | ||
| 82 | .base = TBASE_MAKE_DEFERRED(&boot_tvec_bases), \ | ||
| 83 | __TIMER_LOCKDEP_MAP_INITIALIZER( \ | ||
| 84 | __FILE__ ":" __stringify(__LINE__)) \ | ||
| 85 | } | ||
| 89 | 86 | ||
| 90 | #define DEFINE_TIMER(_name, _function, _expires, _data) \ | 87 | #define DEFINE_TIMER(_name, _function, _expires, _data) \ |
| 91 | struct timer_list _name = \ | 88 | struct timer_list _name = \ |
| 92 | TIMER_INITIALIZER(_function, _expires, _data) | 89 | TIMER_INITIALIZER(_function, _expires, _data) |
| 93 | 90 | ||
| 94 | void init_timer_key(struct timer_list *timer, unsigned int flags, | 91 | void init_timer_key(struct timer_list *timer, |
| 95 | const char *name, struct lock_class_key *key); | 92 | const char *name, |
| 96 | 93 | struct lock_class_key *key); | |
| 97 | #ifdef CONFIG_DEBUG_OBJECTS_TIMERS | 94 | void init_timer_deferrable_key(struct timer_list *timer, |
| 98 | extern void init_timer_on_stack_key(struct timer_list *timer, | 95 | const char *name, |
| 99 | unsigned int flags, const char *name, | 96 | struct lock_class_key *key); |
| 100 | struct lock_class_key *key); | ||
| 101 | extern void destroy_timer_on_stack(struct timer_list *timer); | ||
| 102 | #else | ||
| 103 | static inline void destroy_timer_on_stack(struct timer_list *timer) { } | ||
| 104 | static inline void init_timer_on_stack_key(struct timer_list *timer, | ||
| 105 | unsigned int flags, const char *name, | ||
| 106 | struct lock_class_key *key) | ||
| 107 | { | ||
| 108 | init_timer_key(timer, flags, name, key); | ||
| 109 | } | ||
| 110 | #endif | ||
| 111 | 97 | ||
| 112 | #ifdef CONFIG_LOCKDEP | 98 | #ifdef CONFIG_LOCKDEP |
| 113 | #define __init_timer(_timer, _flags) \ | 99 | #define init_timer(timer) \ |
| 114 | do { \ | 100 | do { \ |
| 115 | static struct lock_class_key __key; \ | 101 | static struct lock_class_key __key; \ |
| 116 | init_timer_key((_timer), (_flags), #_timer, &__key); \ | 102 | init_timer_key((timer), #timer, &__key); \ |
| 117 | } while (0) | 103 | } while (0) |
| 118 | 104 | ||
| 119 | #define __init_timer_on_stack(_timer, _flags) \ | 105 | #define init_timer_deferrable(timer) \ |
| 120 | do { \ | 106 | do { \ |
| 121 | static struct lock_class_key __key; \ | 107 | static struct lock_class_key __key; \ |
| 122 | init_timer_on_stack_key((_timer), (_flags), #_timer, &__key); \ | 108 | init_timer_deferrable_key((timer), #timer, &__key); \ |
| 123 | } while (0) | 109 | } while (0) |
| 124 | #else | ||
| 125 | #define __init_timer(_timer, _flags) \ | ||
| 126 | init_timer_key((_timer), (_flags), NULL, NULL) | ||
| 127 | #define __init_timer_on_stack(_timer, _flags) \ | ||
| 128 | init_timer_on_stack_key((_timer), (_flags), NULL, NULL) | ||
| 129 | #endif | ||
| 130 | 110 | ||
| 131 | #define init_timer(timer) \ | ||
| 132 | __init_timer((timer), 0) | ||
| 133 | #define init_timer_deferrable(timer) \ | ||
| 134 | __init_timer((timer), TIMER_DEFERRABLE) | ||
| 135 | #define init_timer_on_stack(timer) \ | 111 | #define init_timer_on_stack(timer) \ |
| 136 | __init_timer_on_stack((timer), 0) | ||
| 137 | |||
| 138 | #define __setup_timer(_timer, _fn, _data, _flags) \ | ||
| 139 | do { \ | 112 | do { \ |
| 140 | __init_timer((_timer), (_flags)); \ | 113 | static struct lock_class_key __key; \ |
| 141 | (_timer)->function = (_fn); \ | 114 | init_timer_on_stack_key((timer), #timer, &__key); \ |
| 142 | (_timer)->data = (_data); \ | ||
| 143 | } while (0) | 115 | } while (0) |
| 144 | 116 | ||
| 145 | #define __setup_timer_on_stack(_timer, _fn, _data, _flags) \ | 117 | #define setup_timer(timer, fn, data) \ |
| 146 | do { \ | 118 | do { \ |
| 147 | __init_timer_on_stack((_timer), (_flags)); \ | 119 | static struct lock_class_key __key; \ |
| 148 | (_timer)->function = (_fn); \ | 120 | setup_timer_key((timer), #timer, &__key, (fn), (data));\ |
| 149 | (_timer)->data = (_data); \ | ||
| 150 | } while (0) | 121 | } while (0) |
| 151 | 122 | ||
| 152 | #define setup_timer(timer, fn, data) \ | ||
| 153 | __setup_timer((timer), (fn), (data), 0) | ||
| 154 | #define setup_timer_on_stack(timer, fn, data) \ | 123 | #define setup_timer_on_stack(timer, fn, data) \ |
| 155 | __setup_timer_on_stack((timer), (fn), (data), 0) | 124 | do { \ |
| 125 | static struct lock_class_key __key; \ | ||
| 126 | setup_timer_on_stack_key((timer), #timer, &__key, \ | ||
| 127 | (fn), (data)); \ | ||
| 128 | } while (0) | ||
| 156 | #define setup_deferrable_timer_on_stack(timer, fn, data) \ | 129 | #define setup_deferrable_timer_on_stack(timer, fn, data) \ |
| 157 | __setup_timer_on_stack((timer), (fn), (data), TIMER_DEFERRABLE) | 130 | do { \ |
| 131 | static struct lock_class_key __key; \ | ||
| 132 | setup_deferrable_timer_on_stack_key((timer), #timer, \ | ||
| 133 | &__key, (fn), \ | ||
| 134 | (data)); \ | ||
| 135 | } while (0) | ||
| 136 | #else | ||
| 137 | #define init_timer(timer)\ | ||
| 138 | init_timer_key((timer), NULL, NULL) | ||
| 139 | #define init_timer_deferrable(timer)\ | ||
| 140 | init_timer_deferrable_key((timer), NULL, NULL) | ||
| 141 | #define init_timer_on_stack(timer)\ | ||
| 142 | init_timer_on_stack_key((timer), NULL, NULL) | ||
| 143 | #define setup_timer(timer, fn, data)\ | ||
| 144 | setup_timer_key((timer), NULL, NULL, (fn), (data)) | ||
| 145 | #define setup_timer_on_stack(timer, fn, data)\ | ||
| 146 | setup_timer_on_stack_key((timer), NULL, NULL, (fn), (data)) | ||
| 147 | #define setup_deferrable_timer_on_stack(timer, fn, data)\ | ||
| 148 | setup_deferrable_timer_on_stack_key((timer), NULL, NULL, (fn), (data)) | ||
| 149 | #endif | ||
| 150 | |||
| 151 | #ifdef CONFIG_DEBUG_OBJECTS_TIMERS | ||
| 152 | extern void init_timer_on_stack_key(struct timer_list *timer, | ||
| 153 | const char *name, | ||
| 154 | struct lock_class_key *key); | ||
| 155 | extern void destroy_timer_on_stack(struct timer_list *timer); | ||
| 156 | #else | ||
| 157 | static inline void destroy_timer_on_stack(struct timer_list *timer) { } | ||
| 158 | static inline void init_timer_on_stack_key(struct timer_list *timer, | ||
| 159 | const char *name, | ||
| 160 | struct lock_class_key *key) | ||
| 161 | { | ||
| 162 | init_timer_key(timer, name, key); | ||
| 163 | } | ||
| 164 | #endif | ||
| 165 | |||
| 166 | static inline void setup_timer_key(struct timer_list * timer, | ||
| 167 | const char *name, | ||
| 168 | struct lock_class_key *key, | ||
| 169 | void (*function)(unsigned long), | ||
| 170 | unsigned long data) | ||
| 171 | { | ||
| 172 | timer->function = function; | ||
| 173 | timer->data = data; | ||
| 174 | init_timer_key(timer, name, key); | ||
| 175 | } | ||
| 176 | |||
| 177 | static inline void setup_timer_on_stack_key(struct timer_list *timer, | ||
| 178 | const char *name, | ||
| 179 | struct lock_class_key *key, | ||
| 180 | void (*function)(unsigned long), | ||
| 181 | unsigned long data) | ||
| 182 | { | ||
| 183 | timer->function = function; | ||
| 184 | timer->data = data; | ||
| 185 | init_timer_on_stack_key(timer, name, key); | ||
| 186 | } | ||
| 187 | |||
| 188 | extern void setup_deferrable_timer_on_stack_key(struct timer_list *timer, | ||
| 189 | const char *name, | ||
| 190 | struct lock_class_key *key, | ||
| 191 | void (*function)(unsigned long), | ||
| 192 | unsigned long data); | ||
| 158 | 193 | ||
| 159 | /** | 194 | /** |
| 160 | * timer_pending - is a timer pending? | 195 | * timer_pending - is a timer pending? |
