aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/timer.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/timer.c')
-rw-r--r--kernel/timer.c42
1 files changed, 11 insertions, 31 deletions
diff --git a/kernel/timer.c b/kernel/timer.c
index 353b9227c2ec..d6459923d245 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -88,18 +88,6 @@ struct tvec_base boot_tvec_bases;
88EXPORT_SYMBOL(boot_tvec_bases); 88EXPORT_SYMBOL(boot_tvec_bases);
89static DEFINE_PER_CPU(struct tvec_base *, tvec_bases) = &boot_tvec_bases; 89static DEFINE_PER_CPU(struct tvec_base *, tvec_bases) = &boot_tvec_bases;
90 90
91/*
92 * Note that all tvec_bases are 2 byte aligned and lower bit of
93 * base in timer_list is guaranteed to be zero. Use the LSB to
94 * indicate whether the timer is deferrable.
95 *
96 * A deferrable timer will work normally when the system is busy, but
97 * will not cause a CPU to come out of idle just to service it; instead,
98 * the timer will be serviced when the CPU eventually wakes up with a
99 * subsequent non-deferrable timer.
100 */
101#define TBASE_DEFERRABLE_FLAG (0x1)
102
103/* Functions below help us manage 'deferrable' flag */ 91/* Functions below help us manage 'deferrable' flag */
104static inline unsigned int tbase_get_deferrable(struct tvec_base *base) 92static inline unsigned int tbase_get_deferrable(struct tvec_base *base)
105{ 93{
@@ -113,8 +101,7 @@ static inline struct tvec_base *tbase_get_base(struct tvec_base *base)
113 101
114static inline void timer_set_deferrable(struct timer_list *timer) 102static inline void timer_set_deferrable(struct timer_list *timer)
115{ 103{
116 timer->base = ((struct tvec_base *)((unsigned long)(timer->base) | 104 timer->base = TBASE_MAKE_DEFERRED(timer->base);
117 TBASE_DEFERRABLE_FLAG));
118} 105}
119 106
120static inline void 107static inline void
@@ -343,15 +330,6 @@ void set_timer_slack(struct timer_list *timer, int slack_hz)
343} 330}
344EXPORT_SYMBOL_GPL(set_timer_slack); 331EXPORT_SYMBOL_GPL(set_timer_slack);
345 332
346
347static inline void set_running_timer(struct tvec_base *base,
348 struct timer_list *timer)
349{
350#ifdef CONFIG_SMP
351 base->running_timer = timer;
352#endif
353}
354
355static void internal_add_timer(struct tvec_base *base, struct timer_list *timer) 333static void internal_add_timer(struct tvec_base *base, struct timer_list *timer)
356{ 334{
357 unsigned long expires = timer->expires; 335 unsigned long expires = timer->expires;
@@ -936,15 +914,12 @@ int del_timer(struct timer_list *timer)
936} 914}
937EXPORT_SYMBOL(del_timer); 915EXPORT_SYMBOL(del_timer);
938 916
939#ifdef CONFIG_SMP
940/** 917/**
941 * try_to_del_timer_sync - Try to deactivate a timer 918 * try_to_del_timer_sync - Try to deactivate a timer
942 * @timer: timer do del 919 * @timer: timer do del
943 * 920 *
944 * This function tries to deactivate a timer. Upon successful (ret >= 0) 921 * This function tries to deactivate a timer. Upon successful (ret >= 0)
945 * exit the timer is not queued and the handler is not running on any CPU. 922 * exit the timer is not queued and the handler is not running on any CPU.
946 *
947 * It must not be called from interrupt contexts.
948 */ 923 */
949int try_to_del_timer_sync(struct timer_list *timer) 924int try_to_del_timer_sync(struct timer_list *timer)
950{ 925{
@@ -973,6 +948,7 @@ out:
973} 948}
974EXPORT_SYMBOL(try_to_del_timer_sync); 949EXPORT_SYMBOL(try_to_del_timer_sync);
975 950
951#ifdef CONFIG_SMP
976/** 952/**
977 * del_timer_sync - deactivate a timer and wait for the handler to finish. 953 * del_timer_sync - deactivate a timer and wait for the handler to finish.
978 * @timer: the timer to be deactivated 954 * @timer: the timer to be deactivated
@@ -1000,7 +976,11 @@ int del_timer_sync(struct timer_list *timer)
1000 lock_map_release(&timer->lockdep_map); 976 lock_map_release(&timer->lockdep_map);
1001 local_irq_restore(flags); 977 local_irq_restore(flags);
1002#endif 978#endif
1003 979 /*
980 * don't use it in hardirq context, because it
981 * could lead to deadlock.
982 */
983 WARN_ON(in_irq());
1004 for (;;) { 984 for (;;) {
1005 int ret = try_to_del_timer_sync(timer); 985 int ret = try_to_del_timer_sync(timer);
1006 if (ret >= 0) 986 if (ret >= 0)
@@ -1111,7 +1091,7 @@ static inline void __run_timers(struct tvec_base *base)
1111 1091
1112 timer_stats_account_timer(timer); 1092 timer_stats_account_timer(timer);
1113 1093
1114 set_running_timer(base, timer); 1094 base->running_timer = timer;
1115 detach_timer(timer, 1); 1095 detach_timer(timer, 1);
1116 1096
1117 spin_unlock_irq(&base->lock); 1097 spin_unlock_irq(&base->lock);
@@ -1119,7 +1099,7 @@ static inline void __run_timers(struct tvec_base *base)
1119 spin_lock_irq(&base->lock); 1099 spin_lock_irq(&base->lock);
1120 } 1100 }
1121 } 1101 }
1122 set_running_timer(base, NULL); 1102 base->running_timer = NULL;
1123 spin_unlock_irq(&base->lock); 1103 spin_unlock_irq(&base->lock);
1124} 1104}
1125 1105
@@ -1249,7 +1229,7 @@ static unsigned long cmp_next_hrtimer_event(unsigned long now,
1249 */ 1229 */
1250unsigned long get_next_timer_interrupt(unsigned long now) 1230unsigned long get_next_timer_interrupt(unsigned long now)
1251{ 1231{
1252 struct tvec_base *base = __get_cpu_var(tvec_bases); 1232 struct tvec_base *base = __this_cpu_read(tvec_bases);
1253 unsigned long expires; 1233 unsigned long expires;
1254 1234
1255 /* 1235 /*
@@ -1298,7 +1278,7 @@ void update_process_times(int user_tick)
1298 */ 1278 */
1299static void run_timer_softirq(struct softirq_action *h) 1279static void run_timer_softirq(struct softirq_action *h)
1300{ 1280{
1301 struct tvec_base *base = __get_cpu_var(tvec_bases); 1281 struct tvec_base *base = __this_cpu_read(tvec_bases);
1302 1282
1303 hrtimer_run_pending(); 1283 hrtimer_run_pending();
1304 1284