aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2015-05-26 18:50:29 -0400
committerThomas Gleixner <tglx@linutronix.de>2015-06-19 09:18:27 -0400
commit0eeda71bc30d74f66f8231f45621d5ace3419186 (patch)
tree2024585f3e1478f91cdec943fe762b81eb1257ca
parent1dabbcec2c0a36fe43509d06499b9e512e70a028 (diff)
timer: Replace timer base by a cpu index
Instead of storing a pointer to the per cpu tvec_base we can simply cache a CPU index in the timer_list and use that to get hold of the correct per cpu tvec_base. This is only used in lock_timer_base() and the slightly larger code is peanuts versus the spinlock operation and the d-cache foot print of the timer wheel. Aside of that this allows to get rid of following nuisances: - boot_tvec_base That statically allocated 4k bss data is just kept around so the timer has a home when it gets statically initialized. It serves no other purpose. With the CPU index we assign the timer to CPU0 at static initialization time and therefor can avoid the whole boot_tvec_base dance. That also simplifies the init code, which just can use the per cpu base. Before: text data bss dec hex filename 17491 9201 4160 30852 7884 ../build/kernel/time/timer.o After: text data bss dec hex filename 17440 9193 0 26633 6809 ../build/kernel/time/timer.o - Overloading the base pointer with various flags The CPU index has enough space to hold the flags (deferrable, irqsafe) so we can get rid of the extra masking and bit fiddling with the base pointer. As a benefit we reduce the size of struct timer_list on 64 bit machines. 4 - 8 bytes, a size reduction up to 15% per struct timer_list, which is a real win as we have tons of them embedded in other structs. This changes also the newly added deferrable printout of the timer start trace point to capture and print all timer->flags, which allows us to decode the target cpu of the timer as well. We might have used bitfields for this, but that would change the static initializers and the init function for no value to accomodate big endian bitfields. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Paul McKenney <paulmck@linux.vnet.ibm.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Eric Dumazet <edumazet@google.com> Cc: Viresh Kumar <viresh.kumar@linaro.org> Cc: John Stultz <john.stultz@linaro.org> Cc: Joonwoo Park <joonwoop@codeaurora.org> Cc: Wenbo Wang <wenbo.wang@memblaze.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Badhri Jagan Sridharan <Badhri@google.com> Link: http://lkml.kernel.org/r/20150526224511.950084301@linutronix.de Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
-rw-r--r--include/linux/timer.h38
-rw-r--r--include/trace/events/timer.h13
-rw-r--r--kernel/time/timer.c127
3 files changed, 58 insertions, 120 deletions
diff --git a/include/linux/timer.h b/include/linux/timer.h
index 064ee24d3f38..4a0d52bc2073 100644
--- a/include/linux/timer.h
+++ b/include/linux/timer.h
@@ -14,27 +14,23 @@ struct timer_list {
14 * All fields that change during normal runtime grouped to the 14 * All fields that change during normal runtime grouped to the
15 * same cacheline 15 * same cacheline
16 */ 16 */
17 struct hlist_node entry; 17 struct hlist_node entry;
18 unsigned long expires; 18 unsigned long expires;
19 struct tvec_base *base; 19 void (*function)(unsigned long);
20 20 unsigned long data;
21 void (*function)(unsigned long); 21 u32 flags;
22 unsigned long data; 22 int slack;
23
24 int slack;
25 23
26#ifdef CONFIG_TIMER_STATS 24#ifdef CONFIG_TIMER_STATS
27 int start_pid; 25 int start_pid;
28 void *start_site; 26 void *start_site;
29 char start_comm[16]; 27 char start_comm[16];
30#endif 28#endif
31#ifdef CONFIG_LOCKDEP 29#ifdef CONFIG_LOCKDEP
32 struct lockdep_map lockdep_map; 30 struct lockdep_map lockdep_map;
33#endif 31#endif
34}; 32};
35 33
36extern struct tvec_base boot_tvec_bases;
37
38#ifdef CONFIG_LOCKDEP 34#ifdef CONFIG_LOCKDEP
39/* 35/*
40 * NB: because we have to copy the lockdep_map, setting the lockdep_map key 36 * NB: because we have to copy the lockdep_map, setting the lockdep_map key
@@ -49,9 +45,6 @@ extern struct tvec_base boot_tvec_bases;
49#endif 45#endif
50 46
51/* 47/*
52 * Note that all tvec_bases are at least 4 byte aligned and lower two bits
53 * of base in timer_list is guaranteed to be zero. Use them for flags.
54 *
55 * A deferrable timer will work normally when the system is busy, but 48 * 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, 49 * 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 50 * the timer will be serviced when the CPU eventually wakes up with a
@@ -65,17 +58,18 @@ extern struct tvec_base boot_tvec_bases;
65 * workqueue locking issues. It's not meant for executing random crap 58 * workqueue locking issues. It's not meant for executing random crap
66 * with interrupts disabled. Abuse is monitored! 59 * with interrupts disabled. Abuse is monitored!
67 */ 60 */
68#define TIMER_DEFERRABLE 0x1LU 61#define TIMER_CPUMASK 0x0007FFFF
69#define TIMER_IRQSAFE 0x2LU 62#define TIMER_MIGRATING 0x00080000
70 63#define TIMER_BASEMASK (TIMER_CPUMASK | TIMER_MIGRATING)
71#define TIMER_FLAG_MASK 0x3LU 64#define TIMER_DEFERRABLE 0x00100000
65#define TIMER_IRQSAFE 0x00200000
72 66
73#define __TIMER_INITIALIZER(_function, _expires, _data, _flags) { \ 67#define __TIMER_INITIALIZER(_function, _expires, _data, _flags) { \
74 .entry = { .next = TIMER_ENTRY_STATIC }, \ 68 .entry = { .next = TIMER_ENTRY_STATIC }, \
75 .function = (_function), \ 69 .function = (_function), \
76 .expires = (_expires), \ 70 .expires = (_expires), \
77 .data = (_data), \ 71 .data = (_data), \
78 .base = (void *)((unsigned long)&boot_tvec_bases + (_flags)), \ 72 .flags = (_flags), \
79 .slack = -1, \ 73 .slack = -1, \
80 __TIMER_LOCKDEP_MAP_INITIALIZER( \ 74 __TIMER_LOCKDEP_MAP_INITIALIZER( \
81 __FILE__ ":" __stringify(__LINE__)) \ 75 __FILE__ ":" __stringify(__LINE__)) \
diff --git a/include/trace/events/timer.h b/include/trace/events/timer.h
index d7abef1fe6e0..073b9ac245ba 100644
--- a/include/trace/events/timer.h
+++ b/include/trace/events/timer.h
@@ -45,16 +45,16 @@ TRACE_EVENT(timer_start,
45 45
46 TP_PROTO(struct timer_list *timer, 46 TP_PROTO(struct timer_list *timer,
47 unsigned long expires, 47 unsigned long expires,
48 unsigned int deferrable), 48 unsigned int flags),
49 49
50 TP_ARGS(timer, expires, deferrable), 50 TP_ARGS(timer, expires, flags),
51 51
52 TP_STRUCT__entry( 52 TP_STRUCT__entry(
53 __field( void *, timer ) 53 __field( void *, timer )
54 __field( void *, function ) 54 __field( void *, function )
55 __field( unsigned long, expires ) 55 __field( unsigned long, expires )
56 __field( unsigned long, now ) 56 __field( unsigned long, now )
57 __field( unsigned int, deferrable ) 57 __field( unsigned int, flags )
58 ), 58 ),
59 59
60 TP_fast_assign( 60 TP_fast_assign(
@@ -62,13 +62,12 @@ TRACE_EVENT(timer_start,
62 __entry->function = timer->function; 62 __entry->function = timer->function;
63 __entry->expires = expires; 63 __entry->expires = expires;
64 __entry->now = jiffies; 64 __entry->now = jiffies;
65 __entry->deferrable = deferrable; 65 __entry->flags = flags;
66 ), 66 ),
67 67
68 TP_printk("timer=%p function=%pf expires=%lu [timeout=%ld] defer=%c", 68 TP_printk("timer=%p function=%pf expires=%lu [timeout=%ld] flags=0x%08x",
69 __entry->timer, __entry->function, __entry->expires, 69 __entry->timer, __entry->function, __entry->expires,
70 (long)__entry->expires - __entry->now, 70 (long)__entry->expires - __entry->now, __entry->flags)
71 __entry->deferrable > 0 ? 'y':'n')
72); 71);
73 72
74/** 73/**
diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index 3a5e0c840884..1540af9f62eb 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -92,43 +92,8 @@ struct tvec_base {
92 struct tvec tv5; 92 struct tvec tv5;
93} ____cacheline_aligned; 93} ____cacheline_aligned;
94 94
95/*
96 * __TIMER_INITIALIZER() needs to set ->base to a valid pointer (because we've
97 * made NULL special, hint: lock_timer_base()) and we cannot get a compile time
98 * pointer to per-cpu entries because we don't know where we'll map the section,
99 * even for the boot cpu.
100 *
101 * And so we use boot_tvec_bases for boot CPU and per-cpu __tvec_bases for the
102 * rest of them.
103 */
104struct tvec_base boot_tvec_bases;
105EXPORT_SYMBOL(boot_tvec_bases);
106
107static DEFINE_PER_CPU(struct tvec_base *, tvec_bases) = &boot_tvec_bases;
108
109/* Functions below help us manage 'deferrable' flag */
110static inline unsigned int tbase_get_deferrable(struct tvec_base *base)
111{
112 return ((unsigned int)(unsigned long)base & TIMER_DEFERRABLE);
113}
114
115static inline unsigned int tbase_get_irqsafe(struct tvec_base *base)
116{
117 return ((unsigned int)(unsigned long)base & TIMER_IRQSAFE);
118}
119
120static inline struct tvec_base *tbase_get_base(struct tvec_base *base)
121{
122 return ((struct tvec_base *)((unsigned long)base & ~TIMER_FLAG_MASK));
123}
124
125static inline void
126timer_set_base(struct timer_list *timer, struct tvec_base *new_base)
127{
128 unsigned long flags = (unsigned long)timer->base & TIMER_FLAG_MASK;
129 95
130 timer->base = (struct tvec_base *)((unsigned long)(new_base) | flags); 96static DEFINE_PER_CPU(struct tvec_base, tvec_bases);
131}
132 97
133static unsigned long round_jiffies_common(unsigned long j, int cpu, 98static unsigned long round_jiffies_common(unsigned long j, int cpu,
134 bool force_up) 99 bool force_up)
@@ -403,7 +368,7 @@ static void internal_add_timer(struct tvec_base *base, struct timer_list *timer)
403 /* 368 /*
404 * Update base->active_timers and base->next_timer 369 * Update base->active_timers and base->next_timer
405 */ 370 */
406 if (!tbase_get_deferrable(timer->base)) { 371 if (!(timer->flags & TIMER_DEFERRABLE)) {
407 if (!base->active_timers++ || 372 if (!base->active_timers++ ||
408 time_before(timer->expires, base->next_timer)) 373 time_before(timer->expires, base->next_timer))
409 base->next_timer = timer->expires; 374 base->next_timer = timer->expires;
@@ -422,7 +387,7 @@ static void internal_add_timer(struct tvec_base *base, struct timer_list *timer)
422 * require special care against races with idle_cpu(), lets deal 387 * require special care against races with idle_cpu(), lets deal
423 * with that later. 388 * with that later.
424 */ 389 */
425 if (!tbase_get_deferrable(timer->base) || tick_nohz_full_cpu(base->cpu)) 390 if (!(timer->flags & TIMER_DEFERRABLE) || tick_nohz_full_cpu(base->cpu))
426 wake_up_nohz_cpu(base->cpu); 391 wake_up_nohz_cpu(base->cpu);
427} 392}
428 393
@@ -443,7 +408,7 @@ static void timer_stats_account_timer(struct timer_list *timer)
443 408
444 if (likely(!timer->start_site)) 409 if (likely(!timer->start_site))
445 return; 410 return;
446 if (unlikely(tbase_get_deferrable(timer->base))) 411 if (unlikely(timer->flags & TIMER_DEFERRABLE))
447 flag |= TIMER_STATS_FLAG_DEFERRABLE; 412 flag |= TIMER_STATS_FLAG_DEFERRABLE;
448 413
449 timer_stats_update_stats(timer, timer->start_pid, timer->start_site, 414 timer_stats_update_stats(timer, timer->start_pid, timer->start_site,
@@ -636,7 +601,7 @@ static inline void
636debug_activate(struct timer_list *timer, unsigned long expires) 601debug_activate(struct timer_list *timer, unsigned long expires)
637{ 602{
638 debug_timer_activate(timer); 603 debug_timer_activate(timer);
639 trace_timer_start(timer, expires, tbase_get_deferrable(timer->base)); 604 trace_timer_start(timer, expires, timer->flags);
640} 605}
641 606
642static inline void debug_deactivate(struct timer_list *timer) 607static inline void debug_deactivate(struct timer_list *timer)
@@ -653,10 +618,8 @@ static inline void debug_assert_init(struct timer_list *timer)
653static void do_init_timer(struct timer_list *timer, unsigned int flags, 618static void do_init_timer(struct timer_list *timer, unsigned int flags,
654 const char *name, struct lock_class_key *key) 619 const char *name, struct lock_class_key *key)
655{ 620{
656 struct tvec_base *base = raw_cpu_read(tvec_bases);
657
658 timer->entry.pprev = NULL; 621 timer->entry.pprev = NULL;
659 timer->base = (void *)((unsigned long)base | flags); 622 timer->flags = flags | raw_smp_processor_id();
660 timer->slack = -1; 623 timer->slack = -1;
661#ifdef CONFIG_TIMER_STATS 624#ifdef CONFIG_TIMER_STATS
662 timer->start_site = NULL; 625 timer->start_site = NULL;
@@ -701,7 +664,7 @@ static inline void
701detach_expired_timer(struct timer_list *timer, struct tvec_base *base) 664detach_expired_timer(struct timer_list *timer, struct tvec_base *base)
702{ 665{
703 detach_timer(timer, true); 666 detach_timer(timer, true);
704 if (!tbase_get_deferrable(timer->base)) 667 if (!(timer->flags & TIMER_DEFERRABLE))
705 base->active_timers--; 668 base->active_timers--;
706 base->all_timers--; 669 base->all_timers--;
707} 670}
@@ -713,7 +676,7 @@ static int detach_if_pending(struct timer_list *timer, struct tvec_base *base,
713 return 0; 676 return 0;
714 677
715 detach_timer(timer, clear_pending); 678 detach_timer(timer, clear_pending);
716 if (!tbase_get_deferrable(timer->base)) { 679 if (!(timer->flags & TIMER_DEFERRABLE)) {
717 base->active_timers--; 680 base->active_timers--;
718 if (timer->expires == base->next_timer) 681 if (timer->expires == base->next_timer)
719 base->next_timer = base->timer_jiffies; 682 base->next_timer = base->timer_jiffies;
@@ -732,24 +695,22 @@ static int detach_if_pending(struct timer_list *timer, struct tvec_base *base,
732 * So __run_timers/migrate_timers can safely modify all timers which could 695 * So __run_timers/migrate_timers can safely modify all timers which could
733 * be found on ->tvX lists. 696 * be found on ->tvX lists.
734 * 697 *
735 * When the timer's base is locked, and the timer removed from list, it is 698 * When the timer's base is locked and removed from the list, the
736 * possible to set timer->base = NULL and drop the lock: the timer remains 699 * TIMER_MIGRATING flag is set, FIXME
737 * locked.
738 */ 700 */
739static struct tvec_base *lock_timer_base(struct timer_list *timer, 701static struct tvec_base *lock_timer_base(struct timer_list *timer,
740 unsigned long *flags) 702 unsigned long *flags)
741 __acquires(timer->base->lock) 703 __acquires(timer->base->lock)
742{ 704{
743 struct tvec_base *base;
744
745 for (;;) { 705 for (;;) {
746 struct tvec_base *prelock_base = timer->base; 706 u32 tf = timer->flags;
747 base = tbase_get_base(prelock_base); 707 struct tvec_base *base;
748 if (likely(base != NULL)) { 708
709 if (!(tf & TIMER_MIGRATING)) {
710 base = per_cpu_ptr(&tvec_bases, tf & TIMER_CPUMASK);
749 spin_lock_irqsave(&base->lock, *flags); 711 spin_lock_irqsave(&base->lock, *flags);
750 if (likely(prelock_base == timer->base)) 712 if (timer->flags == tf)
751 return base; 713 return base;
752 /* The timer has migrated to another CPU */
753 spin_unlock_irqrestore(&base->lock, *flags); 714 spin_unlock_irqrestore(&base->lock, *flags);
754 } 715 }
755 cpu_relax(); 716 cpu_relax();
@@ -776,7 +737,7 @@ __mod_timer(struct timer_list *timer, unsigned long expires,
776 debug_activate(timer, expires); 737 debug_activate(timer, expires);
777 738
778 cpu = get_nohz_timer_target(pinned); 739 cpu = get_nohz_timer_target(pinned);
779 new_base = per_cpu(tvec_bases, cpu); 740 new_base = per_cpu_ptr(&tvec_bases, cpu);
780 741
781 if (base != new_base) { 742 if (base != new_base) {
782 /* 743 /*
@@ -788,11 +749,12 @@ __mod_timer(struct timer_list *timer, unsigned long expires,
788 */ 749 */
789 if (likely(base->running_timer != timer)) { 750 if (likely(base->running_timer != timer)) {
790 /* See the comment in lock_timer_base() */ 751 /* See the comment in lock_timer_base() */
791 timer_set_base(timer, NULL); 752 timer->flags |= TIMER_MIGRATING;
753
792 spin_unlock(&base->lock); 754 spin_unlock(&base->lock);
793 base = new_base; 755 base = new_base;
794 spin_lock(&base->lock); 756 spin_lock(&base->lock);
795 timer_set_base(timer, base); 757 timer->flags = (timer->flags & ~TIMER_BASEMASK) | cpu;
796 } 758 }
797 } 759 }
798 760
@@ -954,13 +916,13 @@ EXPORT_SYMBOL(add_timer);
954 */ 916 */
955void add_timer_on(struct timer_list *timer, int cpu) 917void add_timer_on(struct timer_list *timer, int cpu)
956{ 918{
957 struct tvec_base *base = per_cpu(tvec_bases, cpu); 919 struct tvec_base *base = per_cpu_ptr(&tvec_bases, cpu);
958 unsigned long flags; 920 unsigned long flags;
959 921
960 timer_stats_timer_set_start_info(timer); 922 timer_stats_timer_set_start_info(timer);
961 BUG_ON(timer_pending(timer) || !timer->function); 923 BUG_ON(timer_pending(timer) || !timer->function);
962 spin_lock_irqsave(&base->lock, flags); 924 spin_lock_irqsave(&base->lock, flags);
963 timer_set_base(timer, base); 925 timer->flags = (timer->flags & ~TIMER_BASEMASK) | cpu;
964 debug_activate(timer, timer->expires); 926 debug_activate(timer, timer->expires);
965 internal_add_timer(base, timer); 927 internal_add_timer(base, timer);
966 spin_unlock_irqrestore(&base->lock, flags); 928 spin_unlock_irqrestore(&base->lock, flags);
@@ -1025,8 +987,6 @@ int try_to_del_timer_sync(struct timer_list *timer)
1025EXPORT_SYMBOL(try_to_del_timer_sync); 987EXPORT_SYMBOL(try_to_del_timer_sync);
1026 988
1027#ifdef CONFIG_SMP 989#ifdef CONFIG_SMP
1028static DEFINE_PER_CPU(struct tvec_base, __tvec_bases);
1029
1030/** 990/**
1031 * del_timer_sync - deactivate a timer and wait for the handler to finish. 991 * del_timer_sync - deactivate a timer and wait for the handler to finish.
1032 * @timer: the timer to be deactivated 992 * @timer: the timer to be deactivated
@@ -1081,7 +1041,7 @@ int del_timer_sync(struct timer_list *timer)
1081 * don't use it in hardirq context, because it 1041 * don't use it in hardirq context, because it
1082 * could lead to deadlock. 1042 * could lead to deadlock.
1083 */ 1043 */
1084 WARN_ON(in_irq() && !tbase_get_irqsafe(timer->base)); 1044 WARN_ON(in_irq() && !(timer->flags & TIMER_IRQSAFE));
1085 for (;;) { 1045 for (;;) {
1086 int ret = try_to_del_timer_sync(timer); 1046 int ret = try_to_del_timer_sync(timer);
1087 if (ret >= 0) 1047 if (ret >= 0)
@@ -1106,7 +1066,6 @@ static int cascade(struct tvec_base *base, struct tvec *tv, int index)
1106 * don't have to detach them individually. 1066 * don't have to detach them individually.
1107 */ 1067 */
1108 hlist_for_each_entry_safe(timer, tmp, &tv_list, entry) { 1068 hlist_for_each_entry_safe(timer, tmp, &tv_list, entry) {
1109 BUG_ON(tbase_get_base(timer->base) != base);
1110 /* No accounting, while moving them */ 1069 /* No accounting, while moving them */
1111 __internal_add_timer(base, timer); 1070 __internal_add_timer(base, timer);
1112 } 1071 }
@@ -1202,7 +1161,7 @@ static inline void __run_timers(struct tvec_base *base)
1202 timer = hlist_entry(head->first, struct timer_list, entry); 1161 timer = hlist_entry(head->first, struct timer_list, entry);
1203 fn = timer->function; 1162 fn = timer->function;
1204 data = timer->data; 1163 data = timer->data;
1205 irqsafe = tbase_get_irqsafe(timer->base); 1164 irqsafe = timer->flags & TIMER_IRQSAFE;
1206 1165
1207 timer_stats_account_timer(timer); 1166 timer_stats_account_timer(timer);
1208 1167
@@ -1242,7 +1201,7 @@ static unsigned long __next_timer_interrupt(struct tvec_base *base)
1242 index = slot = timer_jiffies & TVR_MASK; 1201 index = slot = timer_jiffies & TVR_MASK;
1243 do { 1202 do {
1244 hlist_for_each_entry(nte, base->tv1.vec + slot, entry) { 1203 hlist_for_each_entry(nte, base->tv1.vec + slot, entry) {
1245 if (tbase_get_deferrable(nte->base)) 1204 if (nte->flags & TIMER_DEFERRABLE)
1246 continue; 1205 continue;
1247 1206
1248 found = 1; 1207 found = 1;
@@ -1273,7 +1232,7 @@ cascade:
1273 index = slot = timer_jiffies & TVN_MASK; 1232 index = slot = timer_jiffies & TVN_MASK;
1274 do { 1233 do {
1275 hlist_for_each_entry(nte, varp->vec + slot, entry) { 1234 hlist_for_each_entry(nte, varp->vec + slot, entry) {
1276 if (tbase_get_deferrable(nte->base)) 1235 if (nte->flags & TIMER_DEFERRABLE)
1277 continue; 1236 continue;
1278 1237
1279 found = 1; 1238 found = 1;
@@ -1343,7 +1302,7 @@ static u64 cmp_next_hrtimer_event(u64 basem, u64 expires)
1343 */ 1302 */
1344u64 get_next_timer_interrupt(unsigned long basej, u64 basem) 1303u64 get_next_timer_interrupt(unsigned long basej, u64 basem)
1345{ 1304{
1346 struct tvec_base *base = __this_cpu_read(tvec_bases); 1305 struct tvec_base *base = this_cpu_ptr(&tvec_bases);
1347 u64 expires = KTIME_MAX; 1306 u64 expires = KTIME_MAX;
1348 unsigned long nextevt; 1307 unsigned long nextevt;
1349 1308
@@ -1395,7 +1354,7 @@ void update_process_times(int user_tick)
1395 */ 1354 */
1396static void run_timer_softirq(struct softirq_action *h) 1355static void run_timer_softirq(struct softirq_action *h)
1397{ 1356{
1398 struct tvec_base *base = __this_cpu_read(tvec_bases); 1357 struct tvec_base *base = this_cpu_ptr(&tvec_bases);
1399 1358
1400 if (time_after_eq(jiffies, base->timer_jiffies)) 1359 if (time_after_eq(jiffies, base->timer_jiffies))
1401 __run_timers(base); 1360 __run_timers(base);
@@ -1534,12 +1493,13 @@ EXPORT_SYMBOL(schedule_timeout_uninterruptible);
1534static void migrate_timer_list(struct tvec_base *new_base, struct hlist_head *head) 1493static void migrate_timer_list(struct tvec_base *new_base, struct hlist_head *head)
1535{ 1494{
1536 struct timer_list *timer; 1495 struct timer_list *timer;
1496 int cpu = new_base->cpu;
1537 1497
1538 while (!hlist_empty(head)) { 1498 while (!hlist_empty(head)) {
1539 timer = hlist_entry(head->first, struct timer_list, entry); 1499 timer = hlist_entry(head->first, struct timer_list, entry);
1540 /* We ignore the accounting on the dying cpu */ 1500 /* We ignore the accounting on the dying cpu */
1541 detach_timer(timer, false); 1501 detach_timer(timer, false);
1542 timer_set_base(timer, new_base); 1502 timer->flags = (timer->flags & ~TIMER_BASEMASK) | cpu;
1543 internal_add_timer(new_base, timer); 1503 internal_add_timer(new_base, timer);
1544 } 1504 }
1545} 1505}
@@ -1551,8 +1511,8 @@ static void migrate_timers(int cpu)
1551 int i; 1511 int i;
1552 1512
1553 BUG_ON(cpu_online(cpu)); 1513 BUG_ON(cpu_online(cpu));
1554 old_base = per_cpu(tvec_bases, cpu); 1514 old_base = per_cpu_ptr(&tvec_bases, cpu);
1555 new_base = get_cpu_var(tvec_bases); 1515 new_base = this_cpu_ptr(&tvec_bases);
1556 /* 1516 /*
1557 * The caller is globally serialized and nobody else 1517 * The caller is globally serialized and nobody else
1558 * takes two locks at once, deadlock is not possible. 1518 * takes two locks at once, deadlock is not possible.
@@ -1576,7 +1536,6 @@ static void migrate_timers(int cpu)
1576 1536
1577 spin_unlock(&old_base->lock); 1537 spin_unlock(&old_base->lock);
1578 spin_unlock_irq(&new_base->lock); 1538 spin_unlock_irq(&new_base->lock);
1579 put_cpu_var(tvec_bases);
1580} 1539}
1581 1540
1582static int timer_cpu_notify(struct notifier_block *self, 1541static int timer_cpu_notify(struct notifier_block *self,
@@ -1602,12 +1561,11 @@ static inline void timer_register_cpu_notifier(void)
1602static inline void timer_register_cpu_notifier(void) { } 1561static inline void timer_register_cpu_notifier(void) { }
1603#endif /* CONFIG_HOTPLUG_CPU */ 1562#endif /* CONFIG_HOTPLUG_CPU */
1604 1563
1605static void __init init_timer_cpu(struct tvec_base *base, int cpu) 1564static void __init init_timer_cpu(int cpu)
1606{ 1565{
1607 BUG_ON(base != tbase_get_base(base)); 1566 struct tvec_base *base = per_cpu_ptr(&tvec_bases, cpu);
1608 1567
1609 base->cpu = cpu; 1568 base->cpu = cpu;
1610 per_cpu(tvec_bases, cpu) = base;
1611 spin_lock_init(&base->lock); 1569 spin_lock_init(&base->lock);
1612 1570
1613 base->timer_jiffies = jiffies; 1571 base->timer_jiffies = jiffies;
@@ -1616,27 +1574,14 @@ static void __init init_timer_cpu(struct tvec_base *base, int cpu)
1616 1574
1617static void __init init_timer_cpus(void) 1575static void __init init_timer_cpus(void)
1618{ 1576{
1619 struct tvec_base *base;
1620 int local_cpu = smp_processor_id();
1621 int cpu; 1577 int cpu;
1622 1578
1623 for_each_possible_cpu(cpu) { 1579 for_each_possible_cpu(cpu)
1624 if (cpu == local_cpu) 1580 init_timer_cpu(cpu);
1625 base = &boot_tvec_bases;
1626#ifdef CONFIG_SMP
1627 else
1628 base = per_cpu_ptr(&__tvec_bases, cpu);
1629#endif
1630
1631 init_timer_cpu(base, cpu);
1632 }
1633} 1581}
1634 1582
1635void __init init_timers(void) 1583void __init init_timers(void)
1636{ 1584{
1637 /* ensure there are enough low bits for flags in timer->base pointer */
1638 BUILD_BUG_ON(__alignof__(struct tvec_base) & TIMER_FLAG_MASK);
1639
1640 init_timer_cpus(); 1585 init_timer_cpus();
1641 init_timer_stats(); 1586 init_timer_stats();
1642 timer_register_cpu_notifier(); 1587 timer_register_cpu_notifier();