From nobody Wed Sep 10 02:01:40 2025 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 587CAE7B601 for ; Wed, 4 Oct 2023 12:35:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242480AbjJDMgA (ORCPT ); Wed, 4 Oct 2023 08:36:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242376AbjJDMff (ORCPT ); Wed, 4 Oct 2023 08:35:35 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 695AFC6 for ; Wed, 4 Oct 2023 05:35:32 -0700 (PDT) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1696422931; 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=JvV/GTzIlX0Cx+6nbNdm3uB0dglqhwMGFjF0Qs3Csts=; b=anbpNzaF4gSVJYCje1CvoII4DNAP+K00Xko6363w/r9C54Ss9u48ITN+CsVTms4TpahdsJ tqXY+v2mOpyUmHytzorE+MN5OXdzM1pMN55anRLPCyT8+XviZTOU2ABl6PossHk6ybWaRi 18beY7ITHPVkMfQ5dXhnFBQClLLxWmuu4vWZF29jMC1vajgVmiwOBZwVEFwgJX2iazzGJa Z5plhNpKRuTYIZv4vceHtVZQRxrYEb2Ee8FwqOLhcfeA4r6IqBuMtqK4n7upOmqPG+plgJ +q9c86bL7B+EFiGxEkzNi0Jkn1b4K1/aCdDFIm3rhIk6f6ByVGj0fi193VtoTw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1696422931; 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=JvV/GTzIlX0Cx+6nbNdm3uB0dglqhwMGFjF0Qs3Csts=; b=N6cePmuxnggtkUWqTVBUfH7Yjf0o6ukWOKrXHR0Pj/o5cOdJIlIgadV9XxYYQdHtONDg3i +QqgcHp36b0UjsAg== 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 v8 09/25] timer: Split out get next timer functionality Date: Wed, 4 Oct 2023 14:34:38 +0200 Message-Id: <20231004123454.15691-10-anna-maria@linutronix.de> In-Reply-To: <20231004123454.15691-1-anna-maria@linutronix.de> References: <20231004123454.15691-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" Split out get next timer functionality to make it reusable in other places. Thereby the order of getting the next expiry, forwarding the base clock and mark timer bases as idle, is changed. This change of order shouldn't have any impact, as nothing inside the function relies on the idle value or the updated timer base clock. Signed-off-by: Anna-Maria Behnsen --- kernel/time/timer.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 18f8aac9b19a..f443aa807fbc 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1911,6 +1911,24 @@ static u64 cmp_next_hrtimer_event(u64 basem, u64 exp= ires) return DIV_ROUND_UP_ULL(nextevt, TICK_NSEC) * TICK_NSEC; } =20 +static inline unsigned long __get_next_timer_interrupt(unsigned long basej, + struct timer_base *base) +{ + unsigned long nextevt; + + if (base->next_expiry_recalc) + next_expiry_recalc(base); + nextevt =3D base->next_expiry; + + if (base->timers_pending) { + /* If we missed a tick already, force 0 delta */ + if (time_before(nextevt, basej)) + nextevt =3D basej; + } + + return nextevt; +} + /** * get_next_timer_interrupt - return the time (clock mono) of the next tim= er * @basej: base time jiffies @@ -1933,9 +1951,7 @@ u64 get_next_timer_interrupt(unsigned long basej, u64= basem) return expires; =20 raw_spin_lock(&base->lock); - if (base->next_expiry_recalc) - next_expiry_recalc(base); - nextevt =3D base->next_expiry; + nextevt =3D __get_next_timer_interrupt(basej, base); =20 /* * We have a fresh next event. Check whether we can forward the @@ -1952,14 +1968,10 @@ u64 get_next_timer_interrupt(unsigned long basej, u= 64 basem) */ base->is_idle =3D time_after(nextevt, basej + 1); =20 - 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 + expires =3D basem + (u64)(nextevt - basej) * TICK_NSEC; + return cmp_next_hrtimer_event(basem, expires); } =20 --=20 2.39.2