Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp904613rdb; Fri, 1 Dec 2023 01:28:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IHHne5xKCL7kIxo6xnF7I2HvZRphnOgxD6r3aT1UwxGXNm+tr/nb+LRVuLU4oBvuyKC02mD X-Received: by 2002:a17:90b:3843:b0:285:ab8c:21db with SMTP id nl3-20020a17090b384300b00285ab8c21dbmr23954202pjb.32.1701422898750; Fri, 01 Dec 2023 01:28:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701422898; cv=none; d=google.com; s=arc-20160816; b=jo2KzHzYDmu1t98BoaNBJoyAX2splc3PKAp7/eyFaHGlSXJy0KSewiu0U0CutG78Hg Ka6k9UmSvggDUneyZYZYjCGfkI0WpDguqdgYVH6Yk3alJ6THXMCQagJqHY7cMObCUV2Q j7nx2agb62qneJMmFhMJOk2zvfOAIvMuoeMVX2RozyGAn3+fdXq7HVoBhr32ZkodB0PA NogOxKlQxwo+FpUCNT3EetTE8F0ZXoHp81v0l9jOmiqulYzvblWe3NCV9V+enLj/53f2 NhpLf74IuHw46g9oRzvbxkdOccPpcxBcnlbi3SXDMxdxu4HESgsejbaAvRt0S3EV8u0n jisQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=OjHpvhdurB+xA/Q5Qjg90zYVhHrCM9ixI3FXScsHyt8=; fh=PG6uS4TiiUSDyl8D/joYkWbwCgDm4ug0ir2h7tHBJXQ=; b=CahPC9GDSpvdRMkmBOSD/ld0Mt0f5Gy7CixOcBiRpWxu4OyIYBDq7l5S8z/NoNNPS3 L4OFpx3GVN3WDFSl6H0k4hkU0zBWaYTbWIUMI8wQ358J5z+/pBThlUxfVva8AaKqoPLU fZ/X2e+ebfNj60HqxsfUlpfQNw5u6FzJVo6CiJlMfoqNRIgqfb13yoS7FUJDt3x4tB6H Pa767ypAnmj9mlzGfXSgIEzXRjQUiwVs8aYcsPD36+REVFAwF5/U8dnajB3OpbflE8D7 q7A8m18ic+oMWoaVajJNUS5RYCU6u1ff6EpRyjvQTNX59h6ECfnQuxSD7bpfHc9QX+to HQCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=KKGSI58S; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id jb17-20020a170903259100b001d00a92b9d4si1245906plb.575.2023.12.01.01.28.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 01:28:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=KKGSI58S; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 516F4825F14A; Fri, 1 Dec 2023 01:28:11 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378122AbjLAJ1p (ORCPT + 99 others); Fri, 1 Dec 2023 04:27:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378050AbjLAJ1W (ORCPT ); Fri, 1 Dec 2023 04:27:22 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03BF8171C for ; Fri, 1 Dec 2023 01:27:14 -0800 (PST) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1701422833; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OjHpvhdurB+xA/Q5Qjg90zYVhHrCM9ixI3FXScsHyt8=; b=KKGSI58SUmBD5Umq/6Q4hIqdbuQjSnzca6zjvAccM2ulw1J6bMv4sXp813ZrMIM1hVtQVH MspT53qWCRzuqvVxUVkoZ04eH80zx/S7MKiw82z+OJKUhRBCi4XQI0/1WlXc2sqf13LW5W IliQXqnyGckto5IWaqLX7GyU0+RzB8zepKOF/AnVpcJ+6MNpR5HCo26arlDmQf94v6jG3J wUax+CBx48cBjE5Axx9p7sO19r8k8gYwRvLBrc5EXDJDpWBcX66pOL4Ys/OiTDUdjW/xc+ t8UrhivzaOHFUQCi/N8COFa/nSqBBhaGOO7CG3xoQe4tqPVGSUhVWd0rxerE7Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1701422833; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OjHpvhdurB+xA/Q5Qjg90zYVhHrCM9ixI3FXScsHyt8=; b=Aml3ir39NvV+AcjCiHTJCqqN6AvMpP5DwCTpdnC7/AHu45ZPNUabml56+ThbNpQsMZFpb2 eyfv64zM1EqeFwBg== To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , John Stultz , Thomas Gleixner , Eric Dumazet , "Rafael J . Wysocki" , Arjan van de Ven , "Paul E . McKenney" , Frederic Weisbecker , Rik van Riel , Steven Rostedt , Sebastian Siewior , Giovanni Gherdovich , Lukasz Luba , "Gautham R . Shenoy" , Srinivas Pandruvada , K Prateek Nayak , Anna-Maria Behnsen Subject: [PATCH v9 11/32] timers: Rework idle logic Date: Fri, 1 Dec 2023 10:26:33 +0100 Message-Id: <20231201092654.34614-12-anna-maria@linutronix.de> In-Reply-To: <20231201092654.34614-1-anna-maria@linutronix.de> References: <20231201092654.34614-1-anna-maria@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Fri, 01 Dec 2023 01:28:11 -0800 (PST) From: Thomas Gleixner To improve readability of the code, split base->idle calculation and expires calculation into separate parts. While at it, update the comment about timer base idle marking. Thereby the following subtle change happens if the next event is just one jiffy ahead and the tick was already stopped: Originally base->is_idle remains true in this situation. Now base->is_idle turns to false. This may spare an IPI if a timer is enqueued remotely to an idle CPU that is going to tick on the next jiffy. Signed-off-by: Thomas Gleixner Signed-off-by: Anna-Maria Behnsen Reviewed-by: Frederic Weisbecker --- v9: Re-ordering to not hurt the eyes and update comment v4: Change condition to force 0 delta and update commit message (Frederic) --- kernel/time/timer.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/kernel/time/timer.c b/kernel/time/timer.c index fee42dda8237..0826018d9873 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1943,22 +1943,23 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem) */ __forward_timer_base(base, basej); - if (time_before_eq(nextevt, basej)) { - expires = basem; - base->is_idle = false; - } else { - if (base->timers_pending) - expires = basem + (u64)(nextevt - basej) * TICK_NSEC; - /* - * If we expect to sleep more than a tick, mark the base idle. - * Also the tick is stopped so any added timer must forward - * the base clk itself to keep granularity small. This idle - * logic is only maintained for the BASE_STD base, deferrable - * timers may still see large granularity skew (by design). - */ - if ((expires - basem) > TICK_NSEC) - base->is_idle = true; + if (base->timers_pending) { + /* If we missed a tick already, force 0 delta */ + if (time_before(nextevt, basej)) + nextevt = basej; + expires = basem + (u64)(nextevt - basej) * TICK_NSEC; } + + /* + * Base is idle if the next event is more than a tick away. + * + * If the base is marked idle then any timer add operation must forward + * the base clk itself to keep granularity small. This idle logic is + * only maintained for the BASE_STD base, deferrable timers may still + * see large granularity skew (by design). + */ + base->is_idle = time_after(nextevt, basej + 1); + trace_timer_base_idle(base->is_idle, base->cpu); raw_spin_unlock(&base->lock); -- 2.39.2