From nobody Thu Apr 9 12:33:09 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44F4BC4332F for ; Fri, 4 Nov 2022 14:58:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231956AbiKDO6X (ORCPT ); Fri, 4 Nov 2022 10:58:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231814AbiKDO55 (ORCPT ); Fri, 4 Nov 2022 10:57:57 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AB4E303C4 for ; Fri, 4 Nov 2022 07:57:56 -0700 (PDT) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667573874; 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=FruOUvpKeK+X7swaFNp01mmQJvyOWTcwLkHl8M9RVAo=; b=WHasScklTX2l+M94cuiAXTiHWhyYQZKUYPXN+0WrU04i3B2wIeHRAL7p5P2Vd0qKsdWBmJ NTXHiGgqYviBgWE/hJeIxrxiUxrEBTxr6ji/Cc9zINbCyDMl7QTV71eU7yob/aLskz2qJk pSg+OMtjNkwgInWSfJsvF8kywdnPzkpjbhy7dqwNc5RR5d3Uldy3cSDaR9TIuBYT0xvhDN HK1IuK6I6a1qeJcc8OrKZ9ESrEiUuavv2PjdjyX+g/KcBf4A3Pwv4GKupUFUe69rK0F3Zy Lsr0HrkqYijt+h6onL8LKHZ1AmbwfzpMVdHxezK1nGyujGqAnyP5zKKEdgkkpw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667573874; 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=FruOUvpKeK+X7swaFNp01mmQJvyOWTcwLkHl8M9RVAo=; b=2wS8GEB4PEbBXo6txsaCfHEF1g+vJEVKaQl6R3/fMHiP+lPDtKGvgPQJ+ghQetYhnuWU5z QFpqJjEwwkTYl8Dw== 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 , Anna-Maria Behnsen , Frederic Weisbecker Subject: [PATCH v4 04/16] timer: Rework idle logic Date: Fri, 4 Nov 2022 15:57:25 +0100 Message-Id: <20221104145737.71236-5-anna-maria@linutronix.de> In-Reply-To: <20221104145737.71236-1-anna-maria@linutronix.de> References: <20221104145737.71236-1-anna-maria@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner To improve readability of the code, split base->idle calculation and expires calculation into separate parts. 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 --- v4: Change condition to force 0 delta and update commit message (Frederic) --- kernel/time/timer.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 4547d2efcb86..0e9f609f5a38 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1727,21 +1727,20 @@ u64 get_next_timer_interrupt(unsigned long basej, u= 64 basem) base->clk =3D nextevt; } =20 - if (time_before_eq(nextevt, basej)) { - expires =3D basem; - base->is_idle =3D false; - } else { - if (base->timers_pending) - expires =3D 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 =3D true; + /* + * Base is idle if the next event is more than a tick away. 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). + */ + base->is_idle =3D time_after(nextevt, basej + 1); + + if (base->timers_pending) { + /* If we missed a tick already, force 0 delta */ + if (time_before(nextevt, basej)) + nextevt =3D basej; + expires =3D basem + (u64)(nextevt - basej) * TICK_NSEC; } raw_spin_unlock(&base->lock); =20 --=20 2.30.2