diff options
author | Thomas Gleixner <tglx@linutronix.de> | 2015-05-26 18:50:24 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2015-06-19 09:18:27 -0400 |
commit | 3bb475a3446facd0425d3f2fe7e85bf03c5c6c05 (patch) | |
tree | 0b7af9596cdac5bb89bd2f3ad70e0f26a615b706 /kernel/time/timer.c | |
parent | 887d9dc989eb0154492e41e7c07492edbb088ba1 (diff) |
timers: Sanitize catchup_timer_jiffies() usage
catchup_timer_jiffies() has been applied blindly to several functions
without looking for possible better ways to do it.
1) internal_add_timer()
Move the update to base->all_timers before we actually insert the
timer into the wheel.
2) detach_if_pending()
Again the update to base->all_timers allows us to explicitely do
the timer_jiffies update in place, if this was the last timer which
got removed.
3) __run_timers()
We only check on entry, which is silly, because base->timer_jiffies
can be behind - especially on NOHZ kernels - and if there is a
single deferrable timer somewhere between base->timer_jiffies and
jiffies we expire it and then loop until base->timer_jiffies ==
jiffies.
Move it into the loop.
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>
Link: http://lkml.kernel.org/r/20150526224511.662994644@linutronix.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'kernel/time/timer.c')
-rw-r--r-- | kernel/time/timer.c | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 7775d454a204..d5e017970ac7 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c | |||
@@ -351,20 +351,6 @@ void set_timer_slack(struct timer_list *timer, int slack_hz) | |||
351 | } | 351 | } |
352 | EXPORT_SYMBOL_GPL(set_timer_slack); | 352 | EXPORT_SYMBOL_GPL(set_timer_slack); |
353 | 353 | ||
354 | /* | ||
355 | * If the list is empty, catch up ->timer_jiffies to the current time. | ||
356 | * The caller must hold the tvec_base lock. Returns true if the list | ||
357 | * was empty and therefore ->timer_jiffies was updated. | ||
358 | */ | ||
359 | static bool catchup_timer_jiffies(struct tvec_base *base) | ||
360 | { | ||
361 | if (!base->all_timers) { | ||
362 | base->timer_jiffies = jiffies; | ||
363 | return true; | ||
364 | } | ||
365 | return false; | ||
366 | } | ||
367 | |||
368 | static void | 354 | static void |
369 | __internal_add_timer(struct tvec_base *base, struct timer_list *timer) | 355 | __internal_add_timer(struct tvec_base *base, struct timer_list *timer) |
370 | { | 356 | { |
@@ -411,7 +397,10 @@ __internal_add_timer(struct tvec_base *base, struct timer_list *timer) | |||
411 | 397 | ||
412 | static void internal_add_timer(struct tvec_base *base, struct timer_list *timer) | 398 | static void internal_add_timer(struct tvec_base *base, struct timer_list *timer) |
413 | { | 399 | { |
414 | (void)catchup_timer_jiffies(base); | 400 | /* Advance base->jiffies, if the base is empty */ |
401 | if (!base->all_timers++) | ||
402 | base->timer_jiffies = jiffies; | ||
403 | |||
415 | __internal_add_timer(base, timer); | 404 | __internal_add_timer(base, timer); |
416 | /* | 405 | /* |
417 | * Update base->active_timers and base->next_timer | 406 | * Update base->active_timers and base->next_timer |
@@ -421,7 +410,6 @@ static void internal_add_timer(struct tvec_base *base, struct timer_list *timer) | |||
421 | time_before(timer->expires, base->next_timer)) | 410 | time_before(timer->expires, base->next_timer)) |
422 | base->next_timer = timer->expires; | 411 | base->next_timer = timer->expires; |
423 | } | 412 | } |
424 | base->all_timers++; | ||
425 | 413 | ||
426 | /* | 414 | /* |
427 | * Check whether the other CPU is in dynticks mode and needs | 415 | * Check whether the other CPU is in dynticks mode and needs |
@@ -718,7 +706,6 @@ detach_expired_timer(struct timer_list *timer, struct tvec_base *base) | |||
718 | if (!tbase_get_deferrable(timer->base)) | 706 | if (!tbase_get_deferrable(timer->base)) |
719 | base->active_timers--; | 707 | base->active_timers--; |
720 | base->all_timers--; | 708 | base->all_timers--; |
721 | (void)catchup_timer_jiffies(base); | ||
722 | } | 709 | } |
723 | 710 | ||
724 | static int detach_if_pending(struct timer_list *timer, struct tvec_base *base, | 711 | static int detach_if_pending(struct timer_list *timer, struct tvec_base *base, |
@@ -733,8 +720,9 @@ static int detach_if_pending(struct timer_list *timer, struct tvec_base *base, | |||
733 | if (timer->expires == base->next_timer) | 720 | if (timer->expires == base->next_timer) |
734 | base->next_timer = base->timer_jiffies; | 721 | base->next_timer = base->timer_jiffies; |
735 | } | 722 | } |
736 | base->all_timers--; | 723 | /* If this was the last timer, advance base->jiffies */ |
737 | (void)catchup_timer_jiffies(base); | 724 | if (!--base->all_timers) |
725 | base->timer_jiffies = jiffies; | ||
738 | return 1; | 726 | return 1; |
739 | } | 727 | } |
740 | 728 | ||
@@ -1184,14 +1172,18 @@ static inline void __run_timers(struct tvec_base *base) | |||
1184 | struct timer_list *timer; | 1172 | struct timer_list *timer; |
1185 | 1173 | ||
1186 | spin_lock_irq(&base->lock); | 1174 | spin_lock_irq(&base->lock); |
1187 | if (catchup_timer_jiffies(base)) { | 1175 | |
1188 | spin_unlock_irq(&base->lock); | ||
1189 | return; | ||
1190 | } | ||
1191 | while (time_after_eq(jiffies, base->timer_jiffies)) { | 1176 | while (time_after_eq(jiffies, base->timer_jiffies)) { |
1192 | struct list_head work_list; | 1177 | struct list_head work_list; |
1193 | struct list_head *head = &work_list; | 1178 | struct list_head *head = &work_list; |
1194 | int index = base->timer_jiffies & TVR_MASK; | 1179 | int index; |
1180 | |||
1181 | if (!base->all_timers) { | ||
1182 | base->timer_jiffies = jiffies; | ||
1183 | break; | ||
1184 | } | ||
1185 | |||
1186 | index = base->timer_jiffies & TVR_MASK; | ||
1195 | 1187 | ||
1196 | /* | 1188 | /* |
1197 | * Cascade timers: | 1189 | * Cascade timers: |