From nobody Tue Feb 10 01:15:11 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 64EF4C77B7A for ; Wed, 24 May 2023 07:07:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239880AbjEXHHY (ORCPT ); Wed, 24 May 2023 03:07:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239793AbjEXHHC (ORCPT ); Wed, 24 May 2023 03:07:02 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FC47E6 for ; Wed, 24 May 2023 00:07:00 -0700 (PDT) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1684912018; 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=3nPoc4ex9ONP2BmQpTyzqK0BECnFowWD2Bg10S9sUhQ=; b=ygmvl73RIKtg2CvGUhk/vWDDvl4mJ296sHFwke/NlcFYGUeimMzJVFINJlSkfCGe9tiExJ djEqcpnCw8xR0lTyXMg3hlI9V4Mo3Idol2TFcDFpgwnSjVHcMoB/LrG5IQPL+jbbrzbRyT IAiOZuEWqLH26XKLgRDNcYc7rSPGK/QJobgGL/co7LsFVcqY3M46RTYIC85fp8My1OB+4y 3PN4dydZktD7gqvWs2ubcK5VK4tMRC16SLC07VXXjzLxfHSMBlsagGS2T5IEFQjTFBtaVp cJeqU6NRotBD0Z9Ry/UTaVYStzAwHHgyG+lqelGd3wFZooDCP0hZjnuedx6guQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1684912018; 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=3nPoc4ex9ONP2BmQpTyzqK0BECnFowWD2Bg10S9sUhQ=; b=nyt4KIqCFq0Er9OWDgdt9jN0tYGg+h+0Ojga3OXErmHJ3T8wH27jM7FPc9tt//rkAMhiMx Yd9vKAN+xKRWpVBg== 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" , Anna-Maria Behnsen , Frederic Weisbecker Subject: [PATCH v7 06/21] timer: Rework idle logic Date: Wed, 24 May 2023 09:06:14 +0200 Message-Id: <20230524070629.6377-7-anna-maria@linutronix.de> In-Reply-To: <20230524070629.6377-1-anna-maria@linutronix.de> References: <20230524070629.6377-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 1a61977f9efa..1522fb81887e 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1957,21 +1957,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