Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp192795ybt; Tue, 30 Jun 2020 18:13:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqYIMGUGdanujjppwm8oyj6i7BTFaWmOtsJ6ZAC6oborWcK++M341+zJZh+WkuJLSx49xn X-Received: by 2002:a17:906:ca43:: with SMTP id jx3mr9843332ejb.208.1593565981190; Tue, 30 Jun 2020 18:13:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593565981; cv=none; d=google.com; s=arc-20160816; b=KkHlZcRjapiqGUiZEBY2t/Gs3CayzEjboqaLwzwCud1YJyfbfRXLemu7LDlzPe6C7i ZFi4K2cdm1w3+kFfK+b/++yM+TDNgR3xbJ/XasaIpID3wQLdpAaDxwBUK942CCV5T1JS DdAHH8AeEqQAUP99EjLs5Cso/lfdnLGpNdplAKRZE99LhHmXRDA9PW4NsGrJi94CH52o UwrP+NA0xeyxpyUgz+nCOxbSyVPeT7O94ZNpGd9POAV+qNMw/8vOyLDCJ2oDN+8QUzE3 7WCI3FiFHZWNisG6uPI29KecdHN8tKzJ8EB5Quv8OT4uFhqJgdU3YZVbHoytkQ6pEu9Y XRRg== 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=LQyS0UVHEVZLpnNr2XTmzOnjhOZSmlAAL4e7hjlHcb0=; b=H5ygQf9EFldDfG/Y1uVAp9ccAwmObYLmt2OtT7J2+7a4RileYscqvAnP41jRgaePza ipRaIIFBAQy9Kr2zpI/lREbqhDbbgjVyeyIo4uaGlna4ju/eR1G3KlfgdqxK2wgaXWOo D28R+eI/rcopwindk4Z1yQA+5l4nErE5f0B1gZ4BmhT6+iZ31tV+iqsf6TIYY+RWBOgy Yr6b2EBUa5fB7FwYu2eYF50sGHhU2zCsuRD8+7o0xeIzNrwj/8RzYxzCbSaUzY8MEUAQ XslMfSGuFt5ozLj0czV8PnWmWyuqSO34S+fyKNIiQZdGCg88Eyg3Fmuzu7AiwwLJsZcs JO8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wJZDTK6G; 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 dg12si2691152edb.81.2020.06.30.18.12.38; Tue, 30 Jun 2020 18:13:01 -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=wJZDTK6G; 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 S1726621AbgGABKp (ORCPT + 99 others); Tue, 30 Jun 2020 21:10:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:56972 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726555AbgGABKn (ORCPT ); Tue, 30 Jun 2020 21:10:43 -0400 Received: from lenoir.home (lfbn-ncy-1-996-218.w90-101.abo.wanadoo.fr [90.101.73.218]) (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 4516520780; Wed, 1 Jul 2020 01:10:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593565842; bh=mr+rQe0l8XSIekeEQFmG7I8vyIFw4b1KDVO2WDIE5lc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wJZDTK6GDUNZbV4QtJGgNeRrtwxFjmld8mukrjb6nZXFlYINfDhiIvYgoSwlFJCgh y12cc4o2EEvmteqk9Gvm6QRBh6fq7s67WzXfketN+hfnObaCPvtJmO+StBEH/+So88 E6jzhF6mJDuwDsgoE8EjPiDdXqZEAjj6h5MWBDSc= From: Frederic Weisbecker To: Thomas Gleixner Cc: LKML , Frederic Weisbecker , Anna-Maria Gleixner , Peter Zijlstra , Juri Lelli Subject: [RFC PATCH 04/10] timer: Optimize _next_timer_interrupt() level iteration Date: Wed, 1 Jul 2020 03:10:24 +0200 Message-Id: <20200701011030.14324-5-frederic@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200701011030.14324-1-frederic@kernel.org> References: <20200701011030.14324-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 b4838d63a016..4aa74aafdd33 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1515,6 +1515,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; @@ -1522,6 +1523,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 @@ -1559,7 +1567,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