aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2012-05-25 18:08:58 -0400
committerThomas Gleixner <tglx@linutronix.de>2012-06-06 07:49:01 -0400
commit99d5f3aac674fe081ffddd2dbb8946ccbc14c410 (patch)
treed4a6cb5f0d4906f2ce983d2db8b4046b96706f53
parentfacbb4a7efbd658046bf615f03cd97a1504785d8 (diff)
timers: Add accounting of non deferrable timers
The code in get_next_timer_interrupt() is suboptimal as it has to run through the cascade to find the next expiring timer. On a completely idle core we should only do that when there is an active timer enqueued and base->next_timer does not give us a fast answer. Add accounting of the active timers to the now consolidated attach/detach code. I deliberately avoided sanity checks because the code is fully symetric and any fiddling with timers w/o using the API functions will lead to cute explosions anyway. ulong is big enough even on 32bit and if we really run into the situation to have more than 1<<32 timers enqueued there, then we are definitely not in a state to go idle and run through that code. This allows us to fix another shortcoming of get_next_timer_interrupt(). Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Gilad Ben-Yossef <gilad@benyossef.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Link: http://lkml.kernel.org/r/20120525214819.236377028@linutronix.de
-rw-r--r--kernel/timer.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/kernel/timer.c b/kernel/timer.c
index 7207690b535..7fada698bd1 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -77,6 +77,7 @@ struct tvec_base {
77 struct timer_list *running_timer; 77 struct timer_list *running_timer;
78 unsigned long timer_jiffies; 78 unsigned long timer_jiffies;
79 unsigned long next_timer; 79 unsigned long next_timer;
80 unsigned long active_timers;
80 struct tvec_root tv1; 81 struct tvec_root tv1;
81 struct tvec tv2; 82 struct tvec tv2;
82 struct tvec tv3; 83 struct tvec tv3;
@@ -377,11 +378,13 @@ static void internal_add_timer(struct tvec_base *base, struct timer_list *timer)
377{ 378{
378 __internal_add_timer(base, timer); 379 __internal_add_timer(base, timer);
379 /* 380 /*
380 * Update base->next_timer if this is the earliest one. 381 * Update base->active_timers and base->next_timer
381 */ 382 */
382 if (time_before(timer->expires, base->next_timer) && 383 if (!tbase_get_deferrable(timer->base)) {
383 !tbase_get_deferrable(timer->base)) 384 if (time_before(timer->expires, base->next_timer))
384 base->next_timer = timer->expires; 385 base->next_timer = timer->expires;
386 base->active_timers++;
387 }
385} 388}
386 389
387#ifdef CONFIG_TIMER_STATS 390#ifdef CONFIG_TIMER_STATS
@@ -678,6 +681,14 @@ static inline void detach_timer(struct timer_list *timer, bool clear_pending)
678 entry->prev = LIST_POISON2; 681 entry->prev = LIST_POISON2;
679} 682}
680 683
684static inline void
685detach_expired_timer(struct timer_list *timer, struct tvec_base *base)
686{
687 detach_timer(timer, true);
688 if (!tbase_get_deferrable(timer->base))
689 timer->base->active_timers--;
690}
691
681static int detach_if_pending(struct timer_list *timer, struct tvec_base *base, 692static int detach_if_pending(struct timer_list *timer, struct tvec_base *base,
682 bool clear_pending) 693 bool clear_pending)
683{ 694{
@@ -685,9 +696,11 @@ static int detach_if_pending(struct timer_list *timer, struct tvec_base *base,
685 return 0; 696 return 0;
686 697
687 detach_timer(timer, clear_pending); 698 detach_timer(timer, clear_pending);
688 if (timer->expires == base->next_timer && 699 if (!tbase_get_deferrable(timer->base)) {
689 !tbase_get_deferrable(timer->base)) 700 timer->base->active_timers--;
690 base->next_timer = base->timer_jiffies; 701 if (timer->expires == base->next_timer)
702 base->next_timer = base->timer_jiffies;
703 }
691 return 1; 704 return 1;
692} 705}
693 706
@@ -1175,7 +1188,7 @@ static inline void __run_timers(struct tvec_base *base)
1175 timer_stats_account_timer(timer); 1188 timer_stats_account_timer(timer);
1176 1189
1177 base->running_timer = timer; 1190 base->running_timer = timer;
1178 detach_timer(timer, true); 1191 detach_expired_timer(timer, base);
1179 1192
1180 spin_unlock_irq(&base->lock); 1193 spin_unlock_irq(&base->lock);
1181 call_timer_fn(timer, fn, data); 1194 call_timer_fn(timer, fn, data);
@@ -1701,6 +1714,7 @@ static int __cpuinit init_timers_cpu(int cpu)
1701 1714
1702 base->timer_jiffies = jiffies; 1715 base->timer_jiffies = jiffies;
1703 base->next_timer = base->timer_jiffies; 1716 base->next_timer = base->timer_jiffies;
1717 base->active_timers = 0;
1704 return 0; 1718 return 0;
1705} 1719}
1706 1720
@@ -1711,6 +1725,7 @@ static void migrate_timer_list(struct tvec_base *new_base, struct list_head *hea
1711 1725
1712 while (!list_empty(head)) { 1726 while (!list_empty(head)) {
1713 timer = list_first_entry(head, struct timer_list, entry); 1727 timer = list_first_entry(head, struct timer_list, entry);
1728 /* We ignore the accounting on the dying cpu */
1714 detach_timer(timer, false); 1729 detach_timer(timer, false);
1715 timer_set_base(timer, new_base); 1730 timer_set_base(timer, new_base);
1716 internal_add_timer(new_base, timer); 1731 internal_add_timer(new_base, timer);