diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-10-01 13:45:16 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-10-01 13:45:16 -0400 |
| commit | 2fff56641be96acd938c8bd8f5f4f6d04795436f (patch) | |
| tree | 656454f704f7ece2177bafaa7f6107409cd9a2f0 | |
| parent | 0b981cb94bc63a2d0e5eccccdca75fe57643ffce (diff) | |
| parent | c5f66e99b7cb091e3d51ae8e8156892e8feb7fa3 (diff) | |
Merge branch 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull timer changes from Ingo Molnar:
"Timer enhancements, generalizations and cleanups from Tejun Heo, in
preparation for workqueue facility enhancements."
* 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
timer: Implement TIMER_IRQSAFE
timer: Clean up timer initializers
timer: Relocate declarations of init_timer_on_stack_key()
timer: Generalize timer->base flags handling
| -rw-r--r-- | include/linux/timer.h | 165 | ||||
| -rw-r--r-- | kernel/timer.c | 108 |
2 files changed, 114 insertions, 159 deletions
diff --git a/include/linux/timer.h b/include/linux/timer.h index 6abd9138beda..8c5a197e1587 100644 --- a/include/linux/timer.h +++ b/include/linux/timer.h | |||
| @@ -49,147 +49,112 @@ extern struct tvec_base boot_tvec_bases; | |||
| 49 | #endif | 49 | #endif |
| 50 | 50 | ||
| 51 | /* | 51 | /* |
| 52 | * Note that all tvec_bases are 2 byte aligned and lower bit of | 52 | * Note that all tvec_bases are at least 4 byte aligned and lower two bits |
| 53 | * base in timer_list is guaranteed to be zero. Use the LSB to | 53 | * of base in timer_list is guaranteed to be zero. Use them for flags. |
| 54 | * indicate whether the timer is deferrable. | ||
| 55 | * | 54 | * |
| 56 | * A deferrable timer will work normally when the system is busy, but | 55 | * A deferrable timer will work normally when the system is busy, but |
| 57 | * will not cause a CPU to come out of idle just to service it; instead, | 56 | * will not cause a CPU to come out of idle just to service it; instead, |
| 58 | * the timer will be serviced when the CPU eventually wakes up with a | 57 | * the timer will be serviced when the CPU eventually wakes up with a |
| 59 | * subsequent non-deferrable timer. | 58 | * 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! | ||
| 60 | */ | 67 | */ |
| 61 | #define TBASE_DEFERRABLE_FLAG (0x1) | 68 | #define TIMER_DEFERRABLE 0x1LU |
| 69 | #define TIMER_IRQSAFE 0x2LU | ||
| 62 | 70 | ||
| 63 | #define TIMER_INITIALIZER(_function, _expires, _data) { \ | 71 | #define TIMER_FLAG_MASK 0x3LU |
| 72 | |||
| 73 | #define __TIMER_INITIALIZER(_function, _expires, _data, _flags) { \ | ||
| 64 | .entry = { .prev = TIMER_ENTRY_STATIC }, \ | 74 | .entry = { .prev = TIMER_ENTRY_STATIC }, \ |
| 65 | .function = (_function), \ | 75 | .function = (_function), \ |
| 66 | .expires = (_expires), \ | 76 | .expires = (_expires), \ |
| 67 | .data = (_data), \ | 77 | .data = (_data), \ |
| 68 | .base = &boot_tvec_bases, \ | 78 | .base = (void *)((unsigned long)&boot_tvec_bases + (_flags)), \ |
| 69 | .slack = -1, \ | 79 | .slack = -1, \ |
| 70 | __TIMER_LOCKDEP_MAP_INITIALIZER( \ | 80 | __TIMER_LOCKDEP_MAP_INITIALIZER( \ |
| 71 | __FILE__ ":" __stringify(__LINE__)) \ | 81 | __FILE__ ":" __stringify(__LINE__)) \ |
| 72 | } | 82 | } |
| 73 | 83 | ||
| 74 | #define TBASE_MAKE_DEFERRED(ptr) ((struct tvec_base *) \ | 84 | #define TIMER_INITIALIZER(_function, _expires, _data) \ |
| 75 | ((unsigned char *)(ptr) + TBASE_DEFERRABLE_FLAG)) | 85 | __TIMER_INITIALIZER((_function), (_expires), (_data), 0) |
| 76 | 86 | ||
| 77 | #define TIMER_DEFERRED_INITIALIZER(_function, _expires, _data) {\ | 87 | #define TIMER_DEFERRED_INITIALIZER(_function, _expires, _data) \ |
| 78 | .entry = { .prev = TIMER_ENTRY_STATIC }, \ | 88 | __TIMER_INITIALIZER((_function), (_expires), (_data), TIMER_DEFERRABLE) |
| 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 | } | ||
| 86 | 89 | ||
| 87 | #define DEFINE_TIMER(_name, _function, _expires, _data) \ | 90 | #define DEFINE_TIMER(_name, _function, _expires, _data) \ |
| 88 | struct timer_list _name = \ | 91 | struct timer_list _name = \ |
| 89 | TIMER_INITIALIZER(_function, _expires, _data) | 92 | TIMER_INITIALIZER(_function, _expires, _data) |
| 90 | 93 | ||
| 91 | void init_timer_key(struct timer_list *timer, | 94 | void init_timer_key(struct timer_list *timer, unsigned int flags, |
| 92 | const char *name, | 95 | const char *name, struct lock_class_key *key); |
| 93 | struct lock_class_key *key); | 96 | |
| 94 | void init_timer_deferrable_key(struct timer_list *timer, | 97 | #ifdef CONFIG_DEBUG_OBJECTS_TIMERS |
| 95 | const char *name, | 98 | extern void init_timer_on_stack_key(struct timer_list *timer, |
| 96 | struct lock_class_key *key); | 99 | unsigned int flags, const char *name, |
| 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 | ||
| 97 | 111 | ||
| 98 | #ifdef CONFIG_LOCKDEP | 112 | #ifdef CONFIG_LOCKDEP |
| 99 | #define init_timer(timer) \ | 113 | #define __init_timer(_timer, _flags) \ |
| 100 | do { \ | 114 | do { \ |
| 101 | static struct lock_class_key __key; \ | 115 | static struct lock_class_key __key; \ |
| 102 | init_timer_key((timer), #timer, &__key); \ | 116 | init_timer_key((_timer), (_flags), #_timer, &__key); \ |
| 103 | } while (0) | 117 | } while (0) |
| 104 | 118 | ||
| 105 | #define init_timer_deferrable(timer) \ | 119 | #define __init_timer_on_stack(_timer, _flags) \ |
| 106 | do { \ | 120 | do { \ |
| 107 | static struct lock_class_key __key; \ | 121 | static struct lock_class_key __key; \ |
| 108 | init_timer_deferrable_key((timer), #timer, &__key); \ | 122 | init_timer_on_stack_key((_timer), (_flags), #_timer, &__key); \ |
| 109 | } while (0) | 123 | } 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 | ||
| 110 | 130 | ||
| 131 | #define init_timer(timer) \ | ||
| 132 | __init_timer((timer), 0) | ||
| 133 | #define init_timer_deferrable(timer) \ | ||
| 134 | __init_timer((timer), TIMER_DEFERRABLE) | ||
| 111 | #define init_timer_on_stack(timer) \ | 135 | #define init_timer_on_stack(timer) \ |
| 136 | __init_timer_on_stack((timer), 0) | ||
| 137 | |||
| 138 | #define __setup_timer(_timer, _fn, _data, _flags) \ | ||
| 112 | do { \ | 139 | do { \ |
| 113 | static struct lock_class_key __key; \ | 140 | __init_timer((_timer), (_flags)); \ |
| 114 | init_timer_on_stack_key((timer), #timer, &__key); \ | 141 | (_timer)->function = (_fn); \ |
| 142 | (_timer)->data = (_data); \ | ||
| 115 | } while (0) | 143 | } while (0) |
| 116 | 144 | ||
| 117 | #define setup_timer(timer, fn, data) \ | 145 | #define __setup_timer_on_stack(_timer, _fn, _data, _flags) \ |
| 118 | do { \ | 146 | do { \ |
| 119 | static struct lock_class_key __key; \ | 147 | __init_timer_on_stack((_timer), (_flags)); \ |
| 120 | setup_timer_key((timer), #timer, &__key, (fn), (data));\ | 148 | (_timer)->function = (_fn); \ |
| 149 | (_timer)->data = (_data); \ | ||
| 121 | } while (0) | 150 | } while (0) |
| 122 | 151 | ||
| 152 | #define setup_timer(timer, fn, data) \ | ||
| 153 | __setup_timer((timer), (fn), (data), 0) | ||
| 123 | #define setup_timer_on_stack(timer, fn, data) \ | 154 | #define setup_timer_on_stack(timer, fn, data) \ |
| 124 | do { \ | 155 | __setup_timer_on_stack((timer), (fn), (data), 0) |
| 125 | static struct lock_class_key __key; \ | ||
| 126 | setup_timer_on_stack_key((timer), #timer, &__key, \ | ||
| 127 | (fn), (data)); \ | ||
| 128 | } while (0) | ||
| 129 | #define setup_deferrable_timer_on_stack(timer, fn, data) \ | 156 | #define setup_deferrable_timer_on_stack(timer, fn, data) \ |
| 130 | do { \ | 157 | __setup_timer_on_stack((timer), (fn), (data), TIMER_DEFERRABLE) |
| 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); | ||
| 193 | 158 | ||
| 194 | /** | 159 | /** |
| 195 | * timer_pending - is a timer pending? | 160 | * timer_pending - is a timer pending? |
diff --git a/kernel/timer.c b/kernel/timer.c index 8c5e7b908c68..d5de1b2292aa 100644 --- a/kernel/timer.c +++ b/kernel/timer.c | |||
| @@ -92,24 +92,25 @@ static DEFINE_PER_CPU(struct tvec_base *, tvec_bases) = &boot_tvec_bases; | |||
| 92 | /* Functions below help us manage 'deferrable' flag */ | 92 | /* Functions below help us manage 'deferrable' flag */ |
| 93 | static inline unsigned int tbase_get_deferrable(struct tvec_base *base) | 93 | static inline unsigned int tbase_get_deferrable(struct tvec_base *base) |
| 94 | { | 94 | { |
| 95 | return ((unsigned int)(unsigned long)base & TBASE_DEFERRABLE_FLAG); | 95 | return ((unsigned int)(unsigned long)base & TIMER_DEFERRABLE); |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | static inline struct tvec_base *tbase_get_base(struct tvec_base *base) | 98 | static inline unsigned int tbase_get_irqsafe(struct tvec_base *base) |
| 99 | { | 99 | { |
| 100 | return ((struct tvec_base *)((unsigned long)base & ~TBASE_DEFERRABLE_FLAG)); | 100 | return ((unsigned int)(unsigned long)base & TIMER_IRQSAFE); |
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | static inline void timer_set_deferrable(struct timer_list *timer) | 103 | static inline struct tvec_base *tbase_get_base(struct tvec_base *base) |
| 104 | { | 104 | { |
| 105 | timer->base = TBASE_MAKE_DEFERRED(timer->base); | 105 | return ((struct tvec_base *)((unsigned long)base & ~TIMER_FLAG_MASK)); |
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | static inline void | 108 | static inline void |
| 109 | timer_set_base(struct timer_list *timer, struct tvec_base *new_base) | 109 | timer_set_base(struct timer_list *timer, struct tvec_base *new_base) |
| 110 | { | 110 | { |
| 111 | timer->base = (struct tvec_base *)((unsigned long)(new_base) | | 111 | unsigned long flags = (unsigned long)timer->base & TIMER_FLAG_MASK; |
| 112 | tbase_get_deferrable(timer->base)); | 112 | |
| 113 | timer->base = (struct tvec_base *)((unsigned long)(new_base) | flags); | ||
| 113 | } | 114 | } |
| 114 | 115 | ||
| 115 | static unsigned long round_jiffies_common(unsigned long j, int cpu, | 116 | static unsigned long round_jiffies_common(unsigned long j, int cpu, |
| @@ -563,16 +564,14 @@ static inline void debug_timer_assert_init(struct timer_list *timer) | |||
| 563 | debug_object_assert_init(timer, &timer_debug_descr); | 564 | debug_object_assert_init(timer, &timer_debug_descr); |
| 564 | } | 565 | } |
| 565 | 566 | ||
| 566 | static void __init_timer(struct timer_list *timer, | 567 | static void do_init_timer(struct timer_list *timer, unsigned int flags, |
| 567 | const char *name, | 568 | const char *name, struct lock_class_key *key); |
| 568 | struct lock_class_key *key); | ||
| 569 | 569 | ||
| 570 | void init_timer_on_stack_key(struct timer_list *timer, | 570 | void init_timer_on_stack_key(struct timer_list *timer, unsigned int flags, |
| 571 | const char *name, | 571 | const char *name, struct lock_class_key *key) |
| 572 | struct lock_class_key *key) | ||
| 573 | { | 572 | { |
| 574 | debug_object_init_on_stack(timer, &timer_debug_descr); | 573 | debug_object_init_on_stack(timer, &timer_debug_descr); |
| 575 | __init_timer(timer, name, key); | 574 | do_init_timer(timer, flags, name, key); |
| 576 | } | 575 | } |
| 577 | EXPORT_SYMBOL_GPL(init_timer_on_stack_key); | 576 | EXPORT_SYMBOL_GPL(init_timer_on_stack_key); |
| 578 | 577 | ||
| @@ -613,12 +612,13 @@ static inline void debug_assert_init(struct timer_list *timer) | |||
| 613 | debug_timer_assert_init(timer); | 612 | debug_timer_assert_init(timer); |
| 614 | } | 613 | } |
| 615 | 614 | ||
| 616 | static void __init_timer(struct timer_list *timer, | 615 | static void do_init_timer(struct timer_list *timer, unsigned int flags, |
| 617 | const char *name, | 616 | const char *name, struct lock_class_key *key) |
| 618 | struct lock_class_key *key) | ||
| 619 | { | 617 | { |
| 618 | struct tvec_base *base = __raw_get_cpu_var(tvec_bases); | ||
| 619 | |||
| 620 | timer->entry.next = NULL; | 620 | timer->entry.next = NULL; |
| 621 | timer->base = __raw_get_cpu_var(tvec_bases); | 621 | timer->base = (void *)((unsigned long)base | flags); |
| 622 | timer->slack = -1; | 622 | timer->slack = -1; |
| 623 | #ifdef CONFIG_TIMER_STATS | 623 | #ifdef CONFIG_TIMER_STATS |
| 624 | timer->start_site = NULL; | 624 | timer->start_site = NULL; |
| @@ -628,22 +628,10 @@ static void __init_timer(struct timer_list *timer, | |||
| 628 | lockdep_init_map(&timer->lockdep_map, name, key, 0); | 628 | lockdep_init_map(&timer->lockdep_map, name, key, 0); |
| 629 | } | 629 | } |
| 630 | 630 | ||
| 631 | void setup_deferrable_timer_on_stack_key(struct timer_list *timer, | ||
| 632 | const char *name, | ||
| 633 | struct lock_class_key *key, | ||
| 634 | void (*function)(unsigned long), | ||
| 635 | unsigned long data) | ||
| 636 | { | ||
| 637 | timer->function = function; | ||
| 638 | timer->data = data; | ||
| 639 | init_timer_on_stack_key(timer, name, key); | ||
| 640 | timer_set_deferrable(timer); | ||
| 641 | } | ||
| 642 | EXPORT_SYMBOL_GPL(setup_deferrable_timer_on_stack_key); | ||
| 643 | |||
| 644 | /** | 631 | /** |
| 645 | * init_timer_key - initialize a timer | 632 | * init_timer_key - initialize a timer |
| 646 | * @timer: the timer to be initialized | 633 | * @timer: the timer to be initialized |
| 634 | * @flags: timer flags | ||
| 647 | * @name: name of the timer | 635 | * @name: name of the timer |
| 648 | * @key: lockdep class key of the fake lock used for tracking timer | 636 | * @key: lockdep class key of the fake lock used for tracking timer |
| 649 | * sync lock dependencies | 637 | * sync lock dependencies |
| @@ -651,24 +639,14 @@ EXPORT_SYMBOL_GPL(setup_deferrable_timer_on_stack_key); | |||
| 651 | * init_timer_key() must be done to a timer prior calling *any* of the | 639 | * init_timer_key() must be done to a timer prior calling *any* of the |
| 652 | * other timer functions. | 640 | * other timer functions. |
| 653 | */ | 641 | */ |
| 654 | void init_timer_key(struct timer_list *timer, | 642 | void init_timer_key(struct timer_list *timer, unsigned int flags, |
| 655 | const char *name, | 643 | const char *name, struct lock_class_key *key) |
| 656 | struct lock_class_key *key) | ||
| 657 | { | 644 | { |
| 658 | debug_init(timer); | 645 | debug_init(timer); |
| 659 | __init_timer(timer, name, key); | 646 | do_init_timer(timer, flags, name, key); |
| 660 | } | 647 | } |
| 661 | EXPORT_SYMBOL(init_timer_key); | 648 | EXPORT_SYMBOL(init_timer_key); |
| 662 | 649 | ||
| 663 | void init_timer_deferrable_key(struct timer_list *timer, | ||
| 664 | const char *name, | ||
| 665 | struct lock_class_key *key) | ||
| 666 | { | ||
| 667 | init_timer_key(timer, name, key); | ||
| 668 | timer_set_deferrable(timer); | ||
| 669 | } | ||
| 670 | EXPORT_SYMBOL(init_timer_deferrable_key); | ||
| 671 | |||
| 672 | static inline void detach_timer(struct timer_list *timer, bool clear_pending) | 650 | static inline void detach_timer(struct timer_list *timer, bool clear_pending) |
| 673 | { | 651 | { |
| 674 | struct list_head *entry = &timer->entry; | 652 | struct list_head *entry = &timer->entry; |
| @@ -686,7 +664,7 @@ detach_expired_timer(struct timer_list *timer, struct tvec_base *base) | |||
| 686 | { | 664 | { |
| 687 | detach_timer(timer, true); | 665 | detach_timer(timer, true); |
| 688 | if (!tbase_get_deferrable(timer->base)) | 666 | if (!tbase_get_deferrable(timer->base)) |
| 689 | timer->base->active_timers--; | 667 | base->active_timers--; |
| 690 | } | 668 | } |
| 691 | 669 | ||
| 692 | static int detach_if_pending(struct timer_list *timer, struct tvec_base *base, | 670 | static int detach_if_pending(struct timer_list *timer, struct tvec_base *base, |
| @@ -697,7 +675,7 @@ static int detach_if_pending(struct timer_list *timer, struct tvec_base *base, | |||
| 697 | 675 | ||
| 698 | detach_timer(timer, clear_pending); | 676 | detach_timer(timer, clear_pending); |
| 699 | if (!tbase_get_deferrable(timer->base)) { | 677 | if (!tbase_get_deferrable(timer->base)) { |
| 700 | timer->base->active_timers--; | 678 | base->active_timers--; |
| 701 | if (timer->expires == base->next_timer) | 679 | if (timer->expires == base->next_timer) |
| 702 | base->next_timer = base->timer_jiffies; | 680 | base->next_timer = base->timer_jiffies; |
| 703 | } | 681 | } |
| @@ -1029,14 +1007,14 @@ EXPORT_SYMBOL(try_to_del_timer_sync); | |||
| 1029 | * | 1007 | * |
| 1030 | * Synchronization rules: Callers must prevent restarting of the timer, | 1008 | * Synchronization rules: Callers must prevent restarting of the timer, |
| 1031 | * otherwise this function is meaningless. It must not be called from | 1009 | * otherwise this function is meaningless. It must not be called from |
| 1032 | * interrupt contexts. The caller must not hold locks which would prevent | 1010 | * interrupt contexts unless the timer is an irqsafe one. The caller must |
| 1033 | * completion of the timer's handler. The timer's handler must not call | 1011 | * not hold locks which would prevent completion of the timer's |
| 1034 | * add_timer_on(). Upon exit the timer is not queued and the handler is | 1012 | * handler. The timer's handler must not call add_timer_on(). Upon exit the |
| 1035 | * not running on any CPU. | 1013 | * timer is not queued and the handler is not running on any CPU. |
| 1036 | * | 1014 | * |
| 1037 | * Note: You must not hold locks that are held in interrupt context | 1015 | * Note: For !irqsafe timers, you must not hold locks that are held in |
| 1038 | * while calling this function. Even if the lock has nothing to do | 1016 | * interrupt context while calling this function. Even if the lock has |
| 1039 | * with the timer in question. Here's why: | 1017 | * nothing to do with the timer in question. Here's why: |
| 1040 | * | 1018 | * |
| 1041 | * CPU0 CPU1 | 1019 | * CPU0 CPU1 |
| 1042 | * ---- ---- | 1020 | * ---- ---- |
| @@ -1073,7 +1051,7 @@ int del_timer_sync(struct timer_list *timer) | |||
| 1073 | * don't use it in hardirq context, because it | 1051 | * don't use it in hardirq context, because it |
| 1074 | * could lead to deadlock. | 1052 | * could lead to deadlock. |
| 1075 | */ | 1053 | */ |
| 1076 | WARN_ON(in_irq()); | 1054 | WARN_ON(in_irq() && !tbase_get_irqsafe(timer->base)); |
| 1077 | for (;;) { | 1055 | for (;;) { |
| 1078 | int ret = try_to_del_timer_sync(timer); | 1056 | int ret = try_to_del_timer_sync(timer); |
| 1079 | if (ret >= 0) | 1057 | if (ret >= 0) |
| @@ -1180,19 +1158,27 @@ static inline void __run_timers(struct tvec_base *base) | |||
| 1180 | while (!list_empty(head)) { | 1158 | while (!list_empty(head)) { |
| 1181 | void (*fn)(unsigned long); | 1159 | void (*fn)(unsigned long); |
| 1182 | unsigned long data; | 1160 | unsigned long data; |
| 1161 | bool irqsafe; | ||
| 1183 | 1162 | ||
| 1184 | timer = list_first_entry(head, struct timer_list,entry); | 1163 | timer = list_first_entry(head, struct timer_list,entry); |
| 1185 | fn = timer->function; | 1164 | fn = timer->function; |
| 1186 | data = timer->data; | 1165 | data = timer->data; |
| 1166 | irqsafe = tbase_get_irqsafe(timer->base); | ||
| 1187 | 1167 | ||
| 1188 | timer_stats_account_timer(timer); | 1168 | timer_stats_account_timer(timer); |
| 1189 | 1169 | ||
| 1190 | base->running_timer = timer; | 1170 | base->running_timer = timer; |
| 1191 | detach_expired_timer(timer, base); | 1171 | detach_expired_timer(timer, base); |
| 1192 | 1172 | ||
| 1193 | spin_unlock_irq(&base->lock); | 1173 | if (irqsafe) { |
| 1194 | call_timer_fn(timer, fn, data); | 1174 | spin_unlock(&base->lock); |
| 1195 | spin_lock_irq(&base->lock); | 1175 | call_timer_fn(timer, fn, data); |
| 1176 | spin_lock(&base->lock); | ||
| 1177 | } else { | ||
| 1178 | spin_unlock_irq(&base->lock); | ||
| 1179 | call_timer_fn(timer, fn, data); | ||
| 1180 | spin_lock_irq(&base->lock); | ||
| 1181 | } | ||
| 1196 | } | 1182 | } |
| 1197 | } | 1183 | } |
| 1198 | base->running_timer = NULL; | 1184 | base->running_timer = NULL; |
| @@ -1791,9 +1777,13 @@ static struct notifier_block __cpuinitdata timers_nb = { | |||
| 1791 | 1777 | ||
| 1792 | void __init init_timers(void) | 1778 | void __init init_timers(void) |
| 1793 | { | 1779 | { |
| 1794 | int err = timer_cpu_notify(&timers_nb, (unsigned long)CPU_UP_PREPARE, | 1780 | int err; |
| 1795 | (void *)(long)smp_processor_id()); | 1781 | |
| 1782 | /* ensure there are enough low bits for flags in timer->base pointer */ | ||
| 1783 | BUILD_BUG_ON(__alignof__(struct tvec_base) & TIMER_FLAG_MASK); | ||
| 1796 | 1784 | ||
| 1785 | err = timer_cpu_notify(&timers_nb, (unsigned long)CPU_UP_PREPARE, | ||
| 1786 | (void *)(long)smp_processor_id()); | ||
| 1797 | init_timer_stats(); | 1787 | init_timer_stats(); |
| 1798 | 1788 | ||
| 1799 | BUG_ON(err != NOTIFY_OK); | 1789 | BUG_ON(err != NOTIFY_OK); |
