From patchwork Wed Oct 4 12:34:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anna-Maria Behnsen X-Patchwork-Id: 148272 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:254a:b0:403:3b70:6f57 with SMTP id hf10csp98797vqb; Wed, 4 Oct 2023 05:36:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEjkHSrPTn2cGMpyuhB9XeubHOWe7YM4dhyE0VUp4g0edMeg/IDIqgUK+3jla/gRu+D88Ya X-Received: by 2002:a17:902:d491:b0:1c7:2e8f:c3b5 with SMTP id c17-20020a170902d49100b001c72e8fc3b5mr3347677plg.20.1696423013505; 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=W0jz85us85rCujzqIlb0NVk5QA/cMXQyVLXADguv+RkfJBx6eXbaqASlp6kqmBmne5 NeOm9mQXzlhhQr4exugEfpZthsRSgNenwZFTJC8xj+0qHrJSl2mGIwnpAQ3QBNXJJDpt s2UY4DioL5U9QPq51HdHJ/XPH/TFXkqdJOPTfbWvyoPIkvDR61uPhMueALw64x1mBJc7 wTKO77BHSApwGPcTOZRpsNizxoahd4kdAaekRWOnukERjDY7rGkijC8WPMt+77wqgyUA i6CynfSOwxHk3nrXHthgqsNUwSHdls/BZM/qjJd9bEpzNyEShqQB41GgrjnvMzeJnnIj SWDA== 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 header.b=RIpnPbrF; 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id r2-20020a170902c60200b001c72476ca30si3359865plr.281.2023.10.04.05.36.53 (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 header.b=RIpnPbrF; 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 351528031C50; 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 S242556AbjJDMg0 (ORCPT + 18 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 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:35 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778828458051728650 X-GMAIL-MSGID: 1778828458051728650 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); } }