From patchwork Mon Jan 15 14:37:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anna-Maria Behnsen X-Patchwork-Id: 188189 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp1744319dyc; Mon, 15 Jan 2024 06:41:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IGaEaMM68cFomwSSrlzae6/Q0/OrwDI4O46vOGAvHHlqRt7hob0kZxOARVK8TxtXRN1BBrp X-Received: by 2002:a17:906:88a:b0:a28:b71d:6801 with SMTP id n10-20020a170906088a00b00a28b71d6801mr2604580eje.149.1705329704963; Mon, 15 Jan 2024 06:41:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705329704; cv=none; d=google.com; s=arc-20160816; b=o/IuYCcESOy81xKKrRZWjlnjlgWJDFpku+8kvPUzZjzFJqM2FDHJDlVDrg+2tf5dW2 FwDRXjCHyI2qS1hnkF86kf5ifGQFcF+o+Op+I7qzLwm5Gu9mZrTaqGT8zQdmxYj1Wvt7 mevZkzRu+LT4Kq3g7OkfYdJGJ+1Qh1wW6WayAFBMzZeqAuyY4d+b7jeNImXeIfqrcpZ1 lP2/jzQ621m/3I7T5JWln+4lplq8Y2xqJLPYnewMQbAKLLSNjRUJnj/dxbwtcmODwrMG REVWazcpuGw0LAKTmEGCTOW0s7qRNBEloX5IocVkIS+j3qv2CnW9jz4C++5fyXkSfhIP CI5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=L0MYhdyqdCnNF2sikCCC+B6J3YzfhlbKGb8NzRYHY1Q=; fh=PG6uS4TiiUSDyl8D/joYkWbwCgDm4ug0ir2h7tHBJXQ=; b=IOHjSyOwltD0udpe+roSlOtBz+6kyMSOhxWQP44dd9WEgmdsL59anWbzjU/jrjxU9n ufSSxqtu1BSK5/JQXK48LTKxwr3orXZYCMtFR9PSSSePNHH2vUU3+15fKVofk2NaOkZn nM0syucbbRy928EWqyeL37yVq6Uj247qJkCevd/nza4G4gB+TH2uoLxUuuLPWSdHpO7h IX67aqkmabXp3PXUx1yug9Obksv7rPU3Bb0c7hbvHBypMi1wiCGi4t2d436nJ3m6tf6h j8sVPHpMBsKpyYqWloyG9lLWy2qm4ClOpX3sW8o6WhqpEOSKmD2sv5M+Spb6MnyFfoCF p3Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=XoTSyhcG; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=g08rqGsE; spf=pass (google.com: domain of linux-kernel+bounces-26108-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26108-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id jx24-20020a170906ca5800b00a2cfe9dd275si2444276ejb.440.2024.01.15.06.41.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 06:41:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26108-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=XoTSyhcG; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=g08rqGsE; spf=pass (google.com: domain of linux-kernel+bounces-26108-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26108-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 9084E1F2292A for ; Mon, 15 Jan 2024 14:41:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8252C1947F; Mon, 15 Jan 2024 14:38:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="XoTSyhcG"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="g08rqGsE" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B36C1805E for ; Mon, 15 Jan 2024 14:38:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1705329489; 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=L0MYhdyqdCnNF2sikCCC+B6J3YzfhlbKGb8NzRYHY1Q=; b=XoTSyhcGXL3jewDT8HeyR35QvUNIwwU5TQmxnt8IqAsASAAa7s6QlLsGaP9rjri5CVBtkh bt2NmkVvbHCYMfA/RffmV+1YNGNRkBrsVc8Pm1XOJ4FM119w8CHQ3bwbGy6alkxKGxwEw8 9MlVF1ZGDuTkS2bItWoFLKsJR+dy+cww2ThJvEhGlXJO1u0C1qubSvBFZrXxEONbwbtvBR 8ywQDFqZhlpTf/T0yPXCkLgffWz0kGEOVoQMQtSgNiYlbbRJULMChJ1BZDTWgEGiVSx3U9 NnCB2ToDM1XZaJR/KjNCRSuto1povy5FzB1hQlCt9pMumKbyKmYBkjYvH+AJ0Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1705329489; 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=L0MYhdyqdCnNF2sikCCC+B6J3YzfhlbKGb8NzRYHY1Q=; b=g08rqGsEbLNBGwipTVvkMSon7N5/imR58bml+pm9R18WMYCyhxI3JHagKL/BjtMNScic1Z jMV806HMjOLAOZDA== 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 v10 12/20] timers: Split out "get next timer interrupt" functionality Date: Mon, 15 Jan 2024 15:37:35 +0100 Message-Id: <20240115143743.27827-13-anna-maria@linutronix.de> In-Reply-To: <20240115143743.27827-1-anna-maria@linutronix.de> References: <20240115143743.27827-1-anna-maria@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788167800447462430 X-GMAIL-MSGID: 1788167800447462430 functionality 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 --- v10: Update was required (change of preceding patches) 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 f119b44e44e0..9fa759dd80f5 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1988,30 +1988,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); @@ -2029,8 +2012,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 forward; + tevt->local = basem + (u64)(nextevt - basej) * TICK_NSEC; + return nextevt; } /* @@ -2040,12 +2023,41 @@ 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); -forward: /* * We have a fresh next event. Check whether we can forward the * base.