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 /kernel | |
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
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/timer.c | 108 |
1 files changed, 49 insertions, 59 deletions
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); |