From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753962AbbFSNYE (ORCPT ); Fri, 19 Jun 2015 09:24:04 -0400 Received: from terminus.zytor.com ([198.137.202.10]:45984 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753551AbbFSNXt (ORCPT ); Fri, 19 Jun 2015 09:23:49 -0400 Date: Fri, 19 Jun 2015 06:22:24 -0700 From: tip-bot for Thomas Gleixner Message-ID: Cc: linux-kernel@vger.kernel.org, john.stultz@linaro.org, joonwoop@codeaurora.org, fweisbec@gmail.com, edumazet@google.com, wenbo.wang@memblaze.com, hpa@zytor.com, peterz@infradead.org, tglx@linutronix.de, viresh.kumar@linaro.org, mingo@kernel.org, paulmck@linux.vnet.ibm.com Reply-To: paulmck@linux.vnet.ibm.com, mingo@kernel.org, peterz@infradead.org, tglx@linutronix.de, viresh.kumar@linaro.org, wenbo.wang@memblaze.com, edumazet@google.com, hpa@zytor.com, fweisbec@gmail.com, joonwoop@codeaurora.org, linux-kernel@vger.kernel.org, john.stultz@linaro.org In-Reply-To: <20150526224511.662994644@linutronix.de> References: <20150526224511.662994644@linutronix.de> To: linux-tip-commits@vger.kernel.org Subject: [tip:timers/core] timers: Sanitize catchup_timer_jiffies() usage Git-Commit-ID: 3bb475a3446facd0425d3f2fe7e85bf03c5c6c05 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 3bb475a3446facd0425d3f2fe7e85bf03c5c6c05 Gitweb: http://git.kernel.org/tip/3bb475a3446facd0425d3f2fe7e85bf03c5c6c05 Author: Thomas Gleixner AuthorDate: Tue, 26 May 2015 22:50:24 +0000 Committer: Thomas Gleixner CommitDate: Fri, 19 Jun 2015 15:18:27 +0200 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 Cc: Peter Zijlstra Cc: Paul McKenney Cc: Frederic Weisbecker Cc: Eric Dumazet Cc: Viresh Kumar Cc: John Stultz Cc: Joonwoo Park Cc: Wenbo Wang Link: http://lkml.kernel.org/r/20150526224511.662994644@linutronix.de Signed-off-by: Thomas Gleixner --- kernel/time/timer.c | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 7775d45..d5e0179 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) } EXPORT_SYMBOL_GPL(set_timer_slack); -/* - * If the list is empty, catch up ->timer_jiffies to the current time. - * The caller must hold the tvec_base lock. Returns true if the list - * was empty and therefore ->timer_jiffies was updated. - */ -static bool catchup_timer_jiffies(struct tvec_base *base) -{ - if (!base->all_timers) { - base->timer_jiffies = jiffies; - return true; - } - return false; -} - static void __internal_add_timer(struct tvec_base *base, struct timer_list *timer) { @@ -411,7 +397,10 @@ __internal_add_timer(struct tvec_base *base, struct timer_list *timer) static void internal_add_timer(struct tvec_base *base, struct timer_list *timer) { - (void)catchup_timer_jiffies(base); + /* Advance base->jiffies, if the base is empty */ + if (!base->all_timers++) + base->timer_jiffies = jiffies; + __internal_add_timer(base, timer); /* * 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) time_before(timer->expires, base->next_timer)) base->next_timer = timer->expires; } - base->all_timers++; /* * 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) if (!tbase_get_deferrable(timer->base)) base->active_timers--; base->all_timers--; - (void)catchup_timer_jiffies(base); } 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, if (timer->expires == base->next_timer) base->next_timer = base->timer_jiffies; } - base->all_timers--; - (void)catchup_timer_jiffies(base); + /* If this was the last timer, advance base->jiffies */ + if (!--base->all_timers) + base->timer_jiffies = jiffies; return 1; } @@ -1184,14 +1172,18 @@ static inline void __run_timers(struct tvec_base *base) struct timer_list *timer; spin_lock_irq(&base->lock); - if (catchup_timer_jiffies(base)) { - spin_unlock_irq(&base->lock); - return; - } + while (time_after_eq(jiffies, base->timer_jiffies)) { struct list_head work_list; struct list_head *head = &work_list; - int index = base->timer_jiffies & TVR_MASK; + int index; + + if (!base->all_timers) { + base->timer_jiffies = jiffies; + break; + } + + index = base->timer_jiffies & TVR_MASK; /* * Cascade timers: -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in Please read the FAQ at http://www.tux.org/lkml/