Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp625603ybt; Mon, 6 Jul 2020 18:34:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+8boCZtEOtgb+5oIvdrlQm6ppU7ljZ2thTWtTPGccDxJ2iTSjIMKurTb2zbHknCQzWYPJ X-Received: by 2002:a17:906:2b12:: with SMTP id a18mr44848090ejg.186.1594085699521; Mon, 06 Jul 2020 18:34:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594085699; cv=none; d=google.com; s=arc-20160816; b=OlT7uNFtjgBEcuuAZaWemgaQibsJ45YT5GcMxVwv2STsaP0E9xjJbcjPMk1/AymlKW bzX/UqPLDVqdwUVTUDJu9RxQwcVlCSaROdRlWTvmx0geXlF7L0RarBYWQYMt6iP1ZKXx yC5yajeG4YFQjUV3GCg/Fp37nL+OctrDqY5Opq2rBdj4QTfM9dePSKBSEuSWhgsZt1Mh yVja2A8PCMLhHeO3gUdhOyN0jniiXYO9BYYx3pSY59Y6CdET6F0RrZXqhC2sLKvLBmOl h2Sbg66oiyzXl7nf75WyCROF4DaEAk7KOTwUNbSLrIP9LWUvIckPW3TNWi0uSfRwlIsJ 131g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yVjm8Hz/sQ3C0l1YgUQYv8JY3SiyUHZQoRqadfUSwCU=; b=z9/K0YzR8TSFuuzkIaql7sUdcL9NAAk4Yy39kQJXvHX/u3WkOF9aYCOpiWhDuF7baw L5miHTbnXjLOzL00K6noZ4rrjaxer5YwhyXA+Z+mybvZcACz0ZgAGLg76ftnrv5TT3MW NKXMnFl8yiATga7lPCQbGqcpVr4QWTIjSIl4PONDOJP3rDd2AvlvA4fRd/72QkQy4fRV fjr5sIGqcqoTQ/1zQoqXucLLiKRSZ/fg2LMWeNz6UFpg4JcRmaEucqirgaU98alF4aAO fsKwkFFLgenWjjCUcqi8wUqdG8YLkkBVsD1F+K99cQh+NpJ4tnVIt76d1So1mtZTc0AQ szCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lH7Vp+2U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e12si15202712edy.476.2020.07.06.18.34.36; Mon, 06 Jul 2020 18:34:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lH7Vp+2U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728001AbgGGBdR (ORCPT + 99 others); Mon, 6 Jul 2020 21:33:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:38622 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727064AbgGGBdL (ORCPT ); Mon, 6 Jul 2020 21:33:11 -0400 Received: from lenoir.home (lfbn-ncy-1-317-216.w83-196.abo.wanadoo.fr [83.196.152.216]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C00FA20722; Tue, 7 Jul 2020 01:33:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594085590; bh=PChPmPgkPRJyChaEB5cLP+xdU+gHVw+vY9UEWW59FAA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lH7Vp+2UyHxRJ0kohuoLWZpMy6dWQNnFhOhLCpcBsqYj27mn/kkDc+xo62ZIIaXR8 qw1h79iU/o3/Dlg34WtMwC4Bxu46GTQZAP4b3+2dZuBmYruYbhb7Va7KcqkWfGd0eN c4dRcmprFbC0YEMh6VpmhDVyz4Hp5oycVbHjL4qE= From: Frederic Weisbecker To: Thomas Gleixner Cc: LKML , Frederic Weisbecker , Anna-Maria Gleixner , Peter Zijlstra , Juri Lelli Subject: [PATCH 3/9] timer: Optimize _next_timer_interrupt() level iteration Date: Tue, 7 Jul 2020 03:32:47 +0200 Message-Id: <20200707013253.26770-4-frederic@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707013253.26770-1-frederic@kernel.org> References: <20200707013253.26770-1-frederic@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If a level has a timer that expires before we reach the next level, there is no need to iterate further. The next level is reached when the 3 lower bits of the current level are cleared. If the next event happens before/during that, the next levels won't give us an earlier expiration. Signed-off-by: Frederic Weisbecker Cc: Peter Zijlstra Cc: Anna-Maria Gleixner Cc: Juri Lelli --- kernel/time/timer.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/kernel/time/timer.c b/kernel/time/timer.c index ae1259f67486..acf7cb8c09f8 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1523,6 +1523,7 @@ static unsigned long __next_timer_interrupt(struct timer_base *base) clk = base->clk; for (lvl = 0; lvl < LVL_DEPTH; lvl++, offset += LVL_SIZE) { int pos = next_pending_bucket(base, offset, clk & LVL_MASK); + unsigned long lvl_clk = clk & LVL_CLK_MASK; if (pos >= 0) { unsigned long tmp = clk + (unsigned long) pos; @@ -1530,6 +1531,13 @@ static unsigned long __next_timer_interrupt(struct timer_base *base) tmp <<= LVL_SHIFT(lvl); if (time_before(tmp, next)) next = tmp; + + /* + * If the next expiration happens before we reach + * the next level, no need to check further. + */ + if (pos <= ((LVL_CLK_DIV - lvl_clk) & LVL_CLK_MASK)) + break; } /* * Clock for the next level. If the current level clock lower @@ -1567,7 +1575,7 @@ static unsigned long __next_timer_interrupt(struct timer_base *base) * So the simple check whether the lower bits of the current * level are 0 or not is sufficient for all cases. */ - adj = clk & LVL_CLK_MASK ? 1 : 0; + adj = lvl_clk ? 1 : 0; clk >>= LVL_CLK_SHIFT; clk += adj; } -- 2.26.2