Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2573566rdb; Wed, 4 Oct 2023 05:36:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGk9pc4WY7UW5xNhvx1XWvnhOwk0UeqFfZWwtgPBR9iMTgeH/Iza3jCSLTTsoPxZtCHyIYy X-Received: by 2002:a17:903:32c2:b0:1c3:b0c7:38bf with SMTP id i2-20020a17090332c200b001c3b0c738bfmr8356535plr.12.1696423013280; Wed, 04 Oct 2023 05:36:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696423013; cv=none; d=google.com; s=arc-20160816; b=O2FZY3ZlrpX7HvX/qOOBfXuGPVSZEjzDHyB5AaHXC5+v8OkV5ssKAELH/xegHGr1kY 0R5HMFXVthqb3JP5V2vo6q9Q4PEXL8DERQezPwNc05YT3lgEbhsfwDH1hvWPHm1F6Hrz sBltK3OuYaJCbrkIF1ENtFKS3d/Xg4hufxb6YBMHdiRuQqeYUhfKJ9KF1CFL2E6R6sAv FhJ9iIg+kFsIHGe/HSNFy/LPDa2CkzlW4WwkYmpbf0uwJr8zo88OH7/LItkWSK2XHvZr 512BXSMb/hPgnkusFlzx84pIixwWBqQOHxPacDGCdX7qFlCR/+QaFNFVEfy3diLcTYCn qkrQ== 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=UbU5bSuCcQVQPyYupy8izkqKsaMYBNty7tW6QmE8iKw=; fh=H6hHKnScvHhKAB7z8Wb75LBNJxB0aNyPhv3ZCgyEYhY=; b=SlwsX3jTeBRRN9/pxVesP2UFGM1nAzigMZf+IYPBARNZJR2nIzs+cIvlqY3Vw7aSAv Yzq/rGqroarp4URLqae8eVRf9/Q5kFNHSCq1UDoBdk3z07TVDOZyrWQwSP0po4bAtJz0 8VZcoR0vtqTp91iOUl81uzvjCU2OMGvoUKa/Ta09wzoUnISkIkRHCUjzjDkuipn9QJsh /PiDCHixUhTNsTwaSAYo7u90WQm2iFznyMwxiyewn/TZbV+kJadqwhMFRH29rgPWhcx2 0/ryHV0CSJYm/GBOdmpPMOt/PEZ6lDPgWLq6fgWw8H58BJF8cAqb5QRmqtRfVZ4p9qP9 HYUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Vm18mK0h; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id e21-20020a637455000000b00573fe48c908si3193465pgn.128.2023.10.04.05.36.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 05:36:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Vm18mK0h; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 420D582164D8; Wed, 4 Oct 2023 05:36:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242555AbjJDMg0 (ORCPT + 99 others); Wed, 4 Oct 2023 08:36:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242423AbjJDMfp (ORCPT ); Wed, 4 Oct 2023 08:35:45 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7BC010E for ; Wed, 4 Oct 2023 05:35:38 -0700 (PDT) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1696422937; 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=UbU5bSuCcQVQPyYupy8izkqKsaMYBNty7tW6QmE8iKw=; b=Vm18mK0h624IkxPC+RuwP1V5JUc3VQxNiMyNVnyWmF7zg92JWgzSsrKwhS+/JmbfHIDAdg F+nuWN+TKYm3T/e4dQpp7sKaBFJ6RXyHIaFHf32rP0IBdXKrt3sdEDjT1t5rOzC/Qmaz2t MQbjt5MxG12Y7wyWvbkktmndl0iI1Eg8y6TsQPrd3TrkMXt5B4E+D5DfkwA2NfB2rJJV1R WGIQM8cSMqDOwtvIWo10dmDlNUm4ZQBkSDAP9JRzkbr4OMFpAz8FY0INfmde/y/xemHCVJ C0WNgXJUn5g+qksiopfRhaN4tKbaP7ThMFoqJv/mozSR75kq0Jyyda42ErQQuQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1696422937; 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=UbU5bSuCcQVQPyYupy8izkqKsaMYBNty7tW6QmE8iKw=; b=RIpnPbrFOlsf3zuhbSOlZCumUoG2m+tm3EaT2AMfmQpLFX+dltm9Ely/xBzr20jO9yYwmM BLOavtfRUQCHILCg== 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 , "Richard Cochran (linutronix GmbH)" , Anna-Maria Behnsen Subject: [PATCH v8 20/25] timer: Restructure internal locking Date: Wed, 4 Oct 2023 14:34:49 +0200 Message-Id: <20231004123454.15691-21-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: 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,URIBL_BLOCKED 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]); Wed, 04 Oct 2023 05:36:34 -0700 (PDT) From: "Richard Cochran (linutronix GmbH)" Move the locking out from __run_timers() to the call sites, so the protected section can be extended at the call site. Preparatory patch for changing the NOHZ timer placement to a pull at expiry time model. No functional change. Signed-off-by: Richard Cochran (linutronix GmbH) Signed-off-by: Anna-Maria Behnsen --- kernel/time/timer.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/kernel/time/timer.c b/kernel/time/timer.c index ae4b6f62b082..8893f5dd1d66 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -2230,11 +2230,7 @@ static inline void __run_timers(struct timer_base *base) struct hlist_head heads[LVL_DEPTH]; int levels; - if (time_before(jiffies, base->next_expiry)) - return; - - timer_base_lock_expiry(base); - raw_spin_lock_irq(&base->lock); + lockdep_assert_held(&base->lock); while (time_after_eq(jiffies, base->clk) && time_after_eq(jiffies, base->next_expiry)) { @@ -2254,21 +2250,36 @@ static inline void __run_timers(struct timer_base *base) while (levels--) expire_timers(base, heads + levels); } +} + +static void __run_timer_base(struct timer_base *base) +{ + if (time_before(jiffies, base->next_expiry)) + return; + + timer_base_lock_expiry(base); + raw_spin_lock_irq(&base->lock); + __run_timers(base); raw_spin_unlock_irq(&base->lock); timer_base_unlock_expiry(base); } +static void run_timer_base(int index) +{ + struct timer_base *base = this_cpu_ptr(&timer_bases[index]); + + __run_timer_base(base); +} + /* * This function runs timers and the timer-tq in bottom half context. */ static __latent_entropy void run_timer_softirq(struct softirq_action *h) { - struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_LOCAL]); - - __run_timers(base); + run_timer_base(BASE_LOCAL); if (IS_ENABLED(CONFIG_NO_HZ_COMMON)) { - __run_timers(this_cpu_ptr(&timer_bases[BASE_GLOBAL])); - __run_timers(this_cpu_ptr(&timer_bases[BASE_DEF])); + run_timer_base(BASE_GLOBAL); + run_timer_base(BASE_DEF); } } -- 2.39.2