Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp904874rdb; Fri, 1 Dec 2023 01:28:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IGcDYhUNDp0raE0w77feTkYDJJiPNbC7OI2/Hp1CLvHVUI+KI/cSBtwUfT1yi5C9Uy7G3Ch X-Received: by 2002:a17:902:7c91:b0:1cf:f53d:5bc9 with SMTP id y17-20020a1709027c9100b001cff53d5bc9mr10499106pll.41.1701422933683; Fri, 01 Dec 2023 01:28:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701422933; cv=none; d=google.com; s=arc-20160816; b=VHFXQso/UwoDnhrs0WDaVH+T0ZbD0EKylfRuNEjkbguUhIILtOiVVZPGAUA5t3NDF6 HuV/9ypLN1Xgo34hSV++CKNfABt2ZavdzSIAB4iZUtSt7PHmXBQCTaIz7D2/ruEKh7kC 4FIbZoieF30qGDL3QO43npV0iWZYxOwxZ4/4rtDN5k0yISCdCj6BCQ3ELsamWEosh/Lj vSQtAXY6rFL3SPcyEZewjkc0EoGyaz4M3CVN/VJSQZ4zWGI/1LKZtFO13eMvQE2WuMQV vZp3oo1eRLtkxHvrXbz/lemaqNWWxFLBx7xypf5v1uiPm67wOszelwkk5JSHzk83u3Zy o5Ow== 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=Uvz4yBwpNSi6fkT+oXIwoWMRBUwA4W1/FjhD6j61hx8=; fh=PG6uS4TiiUSDyl8D/joYkWbwCgDm4ug0ir2h7tHBJXQ=; b=Obn6yJqIXLOdb7ejf5tbrCbCMtO2rxqfDGANUcyzkO55PY7i926uYknJ6u+CXwAZax xKDnJGlHe9M2fmGC1xVE4PafKyclZwcCh2RyXrwTpShOcrUL9/dPLMm1ELtnD9u9DfZ7 JpNRjOyoXUPOD5m+C1y3l7GWTrtbbO1kzZSqCdDzGggixSWVBUH/F0RZPNy8ZpBHSzId O0sjp3MSDNN4AxB9jApPMU0+Pv4AC0BcYGeIcMgRxp2i8FL640A7b4An+wljKCFwAxFL oufK16QvZK2hRPlCKQMCs63usY54dcCZcFvwXkPJcebfJhmt8iljwBNWAJGg+bfyWCJS PFiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qMsRwsr+; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=L2MRucXc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id w6-20020a1709027b8600b001cfb4a3adb1si1130798pll.623.2023.12.01.01.28.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 01:28:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qMsRwsr+; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=L2MRucXc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 8BCF280FA84D; Fri, 1 Dec 2023 01:28:52 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378181AbjLAJ2i (ORCPT + 99 others); Fri, 1 Dec 2023 04:28:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378025AbjLAJ2I (ORCPT ); Fri, 1 Dec 2023 04:28:08 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 530B51BE2 for ; Fri, 1 Dec 2023 01:27:25 -0800 (PST) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1701422843; 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=Uvz4yBwpNSi6fkT+oXIwoWMRBUwA4W1/FjhD6j61hx8=; b=qMsRwsr+tm2NABELd3xGyoIvs9Q3nKC7dA+P1bwnlmoDT+38yK2pUvPofS2GsHFXVt1295 HLaoAEa2mvXXxrwoBYDdvGli/++GZR+ZlkxXl6ewYb2ZbP77HoKfsEkiSiERJVGHfPUfkc sIvtIy0a3bwOVEnQVH/GBNHgGNiouQ70U2o+efM9AwjPrNKIXSnFQaQEn2QGhVLg+OwriT 86PuSupt2sL8tiDwd/TwQjJlybwK5x5Ya1ZGxjsBN4mZucPh9YxFI+GIi1FKFGgieAXDMv BAx2JlsD2U8C5nD8a1aLR8JCCNgq+5CP2wfh9Thj/lLlvXL2ISNL4GV0Go+zKw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1701422843; 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=Uvz4yBwpNSi6fkT+oXIwoWMRBUwA4W1/FjhD6j61hx8=; b=L2MRucXc33ide4+3K4Tl8jxU6vJKiCjEajaGrRk0LYhWnwHLfvl45rw41XC9DgrZmjhbtH ODBBm8bO2hjr5RAg== 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 24/32] timers: Split out "get next timer interrupt" functionality Date: Fri, 1 Dec 2023 10:26:46 +0100 Message-Id: <20231201092654.34614-25-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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Fri, 01 Dec 2023 01:28:52 -0800 (PST) The functionality for getting the next timer interrupt in get_next_timer_interrupt() is split into a separate function fetch_next_timer_interrupt() to be usable by other call sites. This is preparatory work for the conversion of the NOHZ timer placement to a pull at expiry time model. No functional change. Signed-off-by: Anna-Maria Behnsen Reviewed-by: Frederic Weisbecker --- v9: Update was required (change of preceding patches) v6: s/splitted/split v5: Update commit message v4: Fix typo in comment --- kernel/time/timer.c | 64 +++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 0d53d853ae22..fc376e06980e 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1985,30 +1985,13 @@ static unsigned long next_timer_interrupt(struct timer_base *base, return base->next_expiry; } -static inline u64 __get_next_timer_interrupt(unsigned long basej, u64 basem, - bool *idle) +static unsigned long fetch_next_timer_interrupt(unsigned long basej, u64 basem, + struct timer_base *base_local, + struct timer_base *base_global, + struct timer_events *tevt) { - struct timer_events tevt = { .local = KTIME_MAX, .global = KTIME_MAX }; unsigned long nextevt, nextevt_local, nextevt_global; - struct timer_base *base_local, *base_global; bool local_first; - u64 expires; - - /* - * Pretend that there is no timer pending if the cpu is offline. - * Possible pending timers will be migrated later to an active cpu. - */ - if (cpu_is_offline(smp_processor_id())) { - if (idle) - *idle = true; - return tevt.local; - } - - base_local = this_cpu_ptr(&timer_bases[BASE_LOCAL]); - base_global = this_cpu_ptr(&timer_bases[BASE_GLOBAL]); - - raw_spin_lock(&base_local->lock); - raw_spin_lock_nested(&base_global->lock, SINGLE_DEPTH_NESTING); nextevt_local = next_timer_interrupt(base_local, basej); nextevt_global = next_timer_interrupt(base_global, basej); @@ -2037,8 +2020,8 @@ static inline u64 __get_next_timer_interrupt(unsigned long basej, u64 basem, /* If we missed a tick already, force 0 delta */ if (time_before(nextevt, basej)) nextevt = basej; - tevt.local = basem + (u64)(nextevt - basej) * TICK_NSEC; - goto unlock; + tevt->local = basem + (u64)(nextevt - basej) * TICK_NSEC; + return nextevt; } /* @@ -2048,10 +2031,40 @@ static inline u64 __get_next_timer_interrupt(unsigned long basej, u64 basem, * ignored. If the global queue is empty, nothing to do either. */ if (!local_first && base_global->timers_pending) - tevt.global = basem + (u64)(nextevt_global - basej) * TICK_NSEC; + tevt->global = basem + (u64)(nextevt_global - basej) * TICK_NSEC; if (base_local->timers_pending) - tevt.local = basem + (u64)(nextevt_local - basej) * TICK_NSEC; + tevt->local = basem + (u64)(nextevt_local - basej) * TICK_NSEC; + + return nextevt; +} + +static inline u64 __get_next_timer_interrupt(unsigned long basej, u64 basem, + bool *idle) +{ + struct timer_events tevt = { .local = KTIME_MAX, .global = KTIME_MAX }; + struct timer_base *base_local, *base_global; + unsigned long nextevt; + u64 expires; + + /* + * Pretend that there is no timer pending if the cpu is offline. + * Possible pending timers will be migrated later to an active cpu. + */ + if (cpu_is_offline(smp_processor_id())) { + if (idle) + *idle = true; + return tevt.local; + } + + base_local = this_cpu_ptr(&timer_bases[BASE_LOCAL]); + base_global = this_cpu_ptr(&timer_bases[BASE_GLOBAL]); + + raw_spin_lock(&base_local->lock); + raw_spin_lock_nested(&base_global->lock, SINGLE_DEPTH_NESTING); + + nextevt = fetch_next_timer_interrupt(basej, basem, base_local, + base_global, &tevt); /* * We have a fresh next event. Check whether we can forward the @@ -2082,7 +2095,6 @@ static inline u64 __get_next_timer_interrupt(unsigned long basej, u64 basem, trace_timer_base_idle(base_local->is_idle, base_local->cpu); } -unlock: raw_spin_unlock(&base_global->lock); raw_spin_unlock(&base_local->lock); -- 2.39.2