From patchwork Tue Apr 18 11:11:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 9685827 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7881B602C2 for ; Tue, 18 Apr 2017 16:44:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6AE0C28497 for ; Tue, 18 Apr 2017 16:44:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5FC0A2849A; Tue, 18 Apr 2017 16:44:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=2.0 tests=BAYES_00, DATE_IN_PAST_03_06, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D16FB28497 for ; Tue, 18 Apr 2017 16:44:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754601AbdDRQoE (ORCPT ); Tue, 18 Apr 2017 12:44:04 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:52294 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932565AbdDRQoB (ORCPT ); Tue, 18 Apr 2017 12:44:01 -0400 Received: from localhost ([127.0.0.1] helo=[127.0.1.1]) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1d0WDA-00089L-Hl; Tue, 18 Apr 2017 18:42:46 +0200 Message-Id: <20170418111400.856441536@linutronix.de> User-Agent: quilt/0.63-1 Date: Tue, 18 Apr 2017 13:11:08 +0200 From: Thomas Gleixner To: LKML Cc: Peter Zijlstra , John Stultz , Eric Dumazet , Anna-Maria Gleixner , "Rafael J. Wysocki" , linux-pm@vger.kernel.org, Arjan van de Ven , "Paul E. McKenney" , Frederic Weisbecker , Rik van Riel , Richard Cochran Subject: [patch V2 06/10] timer: Restructure internal locking References: <20170418111102.490432548@linutronix.de> MIME-Version: 1.0 Content-Disposition: inline; filename=timer_Restructure_internal_locking.patch Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move the locking out from __run_timers() to the call sites, so the protected section can be extended at the call site. Preparatory patch for changing the NOHZ timer placement to a pull at expiry time model. No functional change. Signed-off-by: Richard Cochran Signed-off-by: Anna-Maria Gleixner Signed-off-by: Thomas Gleixner --- kernel/time/timer.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1651,17 +1651,14 @@ void update_process_times(int user_tick) /** * __run_timers - run all expired timers (if any) on this CPU. * @base: the timer vector to be processed. + * + * Caller must hold the base lock. */ static inline void __run_timers(struct timer_base *base) { struct hlist_head heads[LVL_DEPTH]; int levels; - if (!time_after_eq(jiffies, base->clk)) - return; - - spin_lock_irq(&base->lock); - while (time_after_eq(jiffies, base->clk)) { levels = collect_expired_timers(base, heads); @@ -1671,7 +1668,20 @@ static inline void __run_timers(struct t expire_timers(base, heads + levels); } base->running_timer = NULL; - spin_unlock_irq(&base->lock); +} + +static void run_timer_base(int index, bool check_nohz) +{ + struct timer_base *base = this_cpu_ptr(&timer_bases[index]); + + if (check_nohz && !base->nohz_active) + return; + + if (time_after_eq(jiffies, base->clk)) { + spin_lock_irq(&base->lock); + __run_timers(base); + spin_unlock_irq(&base->lock); + } } /* @@ -1679,16 +1689,11 @@ static inline void __run_timers(struct t */ static __latent_entropy void run_timer_softirq(struct softirq_action *h) { - struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_LOCAL]); + run_timer_base(BASE_LOCAL, false); - __run_timers(base); if (IS_ENABLED(CONFIG_NO_HZ_COMMON)) { - base = this_cpu_ptr(&timer_bases[BASE_GLOBAL]); - __run_timers(base); - - base = this_cpu_ptr(&timer_bases[BASE_DEF]); - if (base->nohz_active) - __run_timers(base); + run_timer_base(BASE_GLOBAL, false); + run_timer_base(BASE_DEF, true); } }