From patchwork Tue Apr 18 11:11:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 9685805 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 37EB6602C2 for ; Tue, 18 Apr 2017 16:42:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29A8928490 for ; Tue, 18 Apr 2017 16:42:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E26D28495; Tue, 18 Apr 2017 16:42:14 +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 B99E328490 for ; Tue, 18 Apr 2017 16:42:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757105AbdDRQmM (ORCPT ); Tue, 18 Apr 2017 12:42:12 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:52265 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757097AbdDRQmM (ORCPT ); Tue, 18 Apr 2017 12:42:12 -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 1d0WBO-00082L-6u; Tue, 18 Apr 2017 18:40:52 +0200 Message-Id: <20170418111400.589271247@linutronix.de> User-Agent: quilt/0.63-1 Date: Tue, 18 Apr 2017 13:11:05 +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 Subject: [patch V2 03/10] timers: Rework idle logic References: <20170418111102.490432548@linutronix.de> MIME-Version: 1.0 Content-Disposition: inline; filename=timers--Rework-idle-logic.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 Storing next event and determining whether the base is idle can be done in __next_timer_interrupt(). Preparatory patch for new call sites which need this information as well. Signed-off-by: Thomas Gleixner --- kernel/time/timer.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1358,8 +1358,11 @@ static int next_pending_bucket(struct ti /* * Search the first expiring timer in the various clock levels. Caller must * hold base->lock. + * + * Stores the next expiry time in base. The return value indicates whether + * the base is empty or not. */ -static unsigned long __next_timer_interrupt(struct timer_base *base) +static bool __next_timer_interrupt(struct timer_base *base) { unsigned long clk, next, adj; unsigned lvl, offset = 0; @@ -1416,7 +1419,10 @@ static unsigned long __next_timer_interr clk >>= LVL_CLK_SHIFT; clk += adj; } - return next; + /* Store the next event in the base */ + base->next_expiry = next; + /* Return whether the base is empty or not */ + return next == base->clk + NEXT_TIMER_MAX_DELTA; } /* @@ -1465,7 +1471,7 @@ u64 get_next_timer_interrupt(unsigned lo struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]); u64 expires = KTIME_MAX; unsigned long nextevt; - bool is_max_delta; + bool is_empty; /* * Pretend that there is no timer pending if the cpu is offline. @@ -1475,9 +1481,8 @@ u64 get_next_timer_interrupt(unsigned lo return expires; spin_lock(&base->lock); - nextevt = __next_timer_interrupt(base); - is_max_delta = (nextevt == base->clk + NEXT_TIMER_MAX_DELTA); - base->next_expiry = nextevt; + is_empty = __next_timer_interrupt(base); + nextevt = base->next_expiry; /* * We have a fresh next event. Check whether we can forward the * base. We can only do that when @basej is past base->clk @@ -1490,20 +1495,17 @@ u64 get_next_timer_interrupt(unsigned lo base->clk = nextevt; } - if (time_before_eq(nextevt, basej)) { - expires = basem; - base->is_idle = false; - } else { - if (!is_max_delta) - expires = basem + (nextevt - basej) * TICK_NSEC; - /* - * If we expect to sleep more than a tick, mark the base idle: - */ - if ((expires - basem) > TICK_NSEC) - base->is_idle = true; - } + /* Base is idle if the next event is more than a tick away. */ + base->is_idle = time_after(nextevt, basej + 1); spin_unlock(&base->lock); + if (!is_empty) { + /* If we missed a tick already, force 0 delta */ + if (time_before_eq(nextevt, basej)) + nextevt = basej; + expires = basem + (nextevt - basej) * TICK_NSEC; + } + return cmp_next_hrtimer_event(basem, expires); } @@ -1534,7 +1536,10 @@ static int collect_expired_timers(struct * the next expiring timer. */ if ((long)(jiffies - base->clk) > 2) { - unsigned long next = __next_timer_interrupt(base); + unsigned long next; + + __next_timer_interrupt(base); + next = base->next_expiry; /* * If the next timer is ahead of time forward to current