Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp905224rdb; Fri, 1 Dec 2023 01:29:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IFVxhkIS7lAp3quI5yEANzKikVdp/Kp66/DMd+Tk+RGiDOf1uHq0l0zoNpoGqBYuNFTrmD+ X-Received: by 2002:a05:6871:70a:b0:1fa:f463:c509 with SMTP id f10-20020a056871070a00b001faf463c509mr490826oap.47.1701422982107; Fri, 01 Dec 2023 01:29:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701422982; cv=none; d=google.com; s=arc-20160816; b=rfsc5vxd8mOkHaE4xmsiYD9lRMQ6cJ3bwSjmqpuvp+a+YOxwfe1TzJxK6kRRiz2RTo RYCt08bXo05ul09DwKpJ6KwrMcsKkvXAVqjwlZ9KWp1dwDWmOPGtIZGBuo5WMQx4v64y 7/ppKJufF0N2CNeee4A3xj1lx1biSavvu/tTQu99HPc9QxvprUfv5SQQg0OHbcOaQ+tF VumP06VCkU1KlmB64lQWXYouwP8nAzRYTIkTcuKFrQNYDbsuuR5D7/dULpkYO12jh06a V5WOcByhz/JVPSWfk+QNKPbbEVyZTRa8GtpgRqHfHNjRL6KCi0RUbQQoVcSoj1seqwDR c8XQ== 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=j1C4FMe7pCnDmgmGqNMXsgIVbPWX+pQUl8aT2cvTpxE=; fh=PG6uS4TiiUSDyl8D/joYkWbwCgDm4ug0ir2h7tHBJXQ=; b=JGKlG66jHudN1S8o5Id1qY30OOwkKntJTxb7xVlBExkZKyb7IQfN+M9Qypc1WtvEf1 IYqRQ83dhgRZFyOQ2S0ir4Odu81qHSalG2lEM8Y0clyeoyJqkgav8p/tGyd08rBlrRxJ hYMkQ2AqOA9ozd64xus2/Vs6xTXdjFaubu2+iZ+xaTJB264Tbn0u0maJyysjUezW42YM V3oeFkVzPknvGD6cDI1aNj/rpFZ60IpIgENFGacVYSblcdiItXLyq1yOmbJtCQI80iAi ubLIkyX9EhbqVpzWS94eIPLdcgJolfi0z73Cpk1+uloVyaEYwWnJHqk5STjZNbTz7cpx WCpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=F20CyeVD; dkim=neutral (no key) header.i=@linutronix.de header.b=zimkCzW5; 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 q33-20020a635061000000b005bdbedcaf61si3032518pgl.674.2023.12.01.01.29.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 01:29:42 -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=F20CyeVD; dkim=neutral (no key) header.i=@linutronix.de header.b=zimkCzW5; 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 44408824633B; Fri, 1 Dec 2023 01:29:32 -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 S1378069AbjLAJ2X (ORCPT + 99 others); Fri, 1 Dec 2023 04:28:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378151AbjLAJ1y (ORCPT ); Fri, 1 Dec 2023 04:27:54 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E40561BC6 for ; Fri, 1 Dec 2023 01:27:22 -0800 (PST) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1701422841; 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=j1C4FMe7pCnDmgmGqNMXsgIVbPWX+pQUl8aT2cvTpxE=; b=F20CyeVDuw7jm58dTRpNRqAbUkr6ff/ZKa8JWcMJjS1xEGOEeyHQaEWSIyjb9dtKsJPOl7 J51VieHtILw3lrPjVx/SxFIrkBv3xVrmzu018wirkiPPuCMkentQlQjSk0LX9NJeQXsS2a wiXf9rUilA3GKSDN/as4IYPlBFlBhTLb1VnnECsJcr8VK398l1Si0a67e1JFxOfsB7gxRw HGSINAF+Bw0YFNzOQTmLcxncwk05bTQmawg21ZZ8DFGSw+gUqURM0GR5+jlOxTabKjFv1s mMLPgavKnCIkKjeowAwjCsW9Xe46YZ1AfAWpO/dpgDEj8y0jJyegvsvCsPTEgw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1701422841; 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=j1C4FMe7pCnDmgmGqNMXsgIVbPWX+pQUl8aT2cvTpxE=; b=zimkCzW5Hc5BNNqsTiWhrRNjS1Qz+YQP0rnArDywmOir6z0bmDO27jgmpr+TsxqqusG/PV rfRDRQ7UyL85FzDg== 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 21/32] timers: Split next timer interrupt logic Date: Fri, 1 Dec 2023 10:26:43 +0100 Message-Id: <20231201092654.34614-22-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:29:32 -0800 (PST) Logic for getting next timer interrupt (no matter of recalculated or already stored in base->next_expiry) is split into a separate function "next_timer_interrupt()" to make it available for new call sites. No functional change. Signed-off-by: Anna-Maria Behnsen --- v9: Adapt to the fix for empty timer bases. --- kernel/time/timer.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/kernel/time/timer.c b/kernel/time/timer.c index b14d84f1fe50..eda4972ca862 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1951,12 +1951,29 @@ static u64 cmp_next_hrtimer_event(u64 basem, u64 expires) return DIV_ROUND_UP_ULL(nextevt, TICK_NSEC) * TICK_NSEC; } +static unsigned long next_timer_interrupt(struct timer_base *base, + unsigned long basej) +{ + if (base->next_expiry_recalc) + next_expiry_recalc(base); + + /* + * Move next_expiry for the empty base into the future to prevent a + * unnecessary raise of the timer softirq when the next_expiry value + * will be reached even if there is no timer pending. + */ + if (!base->timers_pending) + base->next_expiry = basej + NEXT_TIMER_MAX_DELTA; + + return base->next_expiry; +} + static inline u64 __get_next_timer_interrupt(unsigned long basej, u64 basem, bool *idle) { struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]); - unsigned long nextevt = basej + NEXT_TIMER_MAX_DELTA; u64 expires = KTIME_MAX; + unsigned long nextevt; /* * Pretend that there is no timer pending if the cpu is offline. @@ -1969,24 +1986,13 @@ static inline u64 __get_next_timer_interrupt(unsigned long basej, u64 basem, } raw_spin_lock(&base->lock); - if (base->next_expiry_recalc) - next_expiry_recalc(base); + nextevt = next_timer_interrupt(base, basej); if (base->timers_pending) { - nextevt = base->next_expiry; - /* If we missed a tick already, force 0 delta */ if (time_before(nextevt, basej)) nextevt = basej; expires = basem + (u64)(nextevt - basej) * TICK_NSEC; - } else { - /* - * Move next_expiry for the empty base into the future to - * prevent a unnecessary raise of the timer softirq when the - * next_expiry value will be reached even if there is no timer - * pending. - */ - base->next_expiry = nextevt; } /* -- 2.39.2