From patchwork Fri Nov 4 14:57:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anna-Maria Behnsen X-Patchwork-Id: 15623 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp456176wru; Fri, 4 Nov 2022 08:02:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Js3GEjfhu6FWlTj16R3P8t9MzHSF/nO2TYHY5skLSRN/AGSfIy4IByDjqQEm/PGC6Pyzj X-Received: by 2002:a05:6402:530d:b0:463:b0cb:50e5 with SMTP id eo13-20020a056402530d00b00463b0cb50e5mr20231522edb.45.1667574175306; Fri, 04 Nov 2022 08:02:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667574175; cv=none; d=google.com; s=arc-20160816; b=ez2YJoE+F02PiSF1XUW9VAOxLc/zcDXMquFVvRLEW8n3+2tjuV6ifF6pUYPQ1uNjdk vPS1hJ3blaI6Ov1HCo3a/V3kw9/m6k7/JNzqT1KpO0A91ZczPIsFlmC7geoGKb1wRDkc UzTE5Emi0q8QviMpOE6jzlfe9MzuDfGCxpG19p7DxnrpUw4fvlhzl5oSRiYFywVrkXWe 33N1zgYofKuBN8N+laMPZ0cNRo1NT2upvyTjzQzbeeiRZ/S22xvaofcVLN0h6gln474i aI2DKIjuDJsC1lxrbMm1QQgAN79CklH0Kfl82J7mtTnC+Vjbyb1Xu166GNlcAtvn15Oe tbyw== 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=bR/mftSP+c00ARZaKpp17SnhKoPd5BhUk3++d2T/vCA=; b=qgbEfnV5UBpj4wvzm+Cemd4e+vJq3rame12TFmyurOzMIXazMFh0kMaYNoH+2JrODl kbL5Juv3CkmeC9TgxZ/hDeXCELJ8lVrh/RFA3P3Uy3Kwz8et9oSaazZwngj7GgzJDmeM peR035ZndlckzAJdMqpgycmTVQKWIFiyqj9POMA5yJYUsPgT9qbUzeMH5nDCN4rO5UA8 t4YyjMPz98yCfowimsqTQQiu3dkKnzlxQ0hJuAZ3pFc5QPIxV54lsLf5WXucwHOCYcso GT8hMIQZdnOtoczafaFAN7X27qBqEcltv+18fI1gFmhoacnrxKJWtDNv9cZoqSU/Q+ck 88QQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=pfuMn0tB; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hv9-20020a17090760c900b007adc8d6b77esi6007936ejc.308.2022.11.04.08.02.31; Fri, 04 Nov 2022 08:02:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=pfuMn0tB; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232362AbiKDO7H (ORCPT + 99 others); Fri, 4 Nov 2022 10:59:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232248AbiKDO6F (ORCPT ); Fri, 4 Nov 2022 10:58:05 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBBA7317EF for ; Fri, 4 Nov 2022 07:57:59 -0700 (PDT) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667573878; 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=bR/mftSP+c00ARZaKpp17SnhKoPd5BhUk3++d2T/vCA=; b=pfuMn0tB4XvaXaxjLKLEA7eLNd19BHMNYFkZjtkLMrL7U7qZpJ83I0x0iTzN3ophyHF8sK Y32iIHbmCxJ1zUzVhUOSmjwBCkoQkZWAWRiWNtCNuFOwc87yYDPC9c2WKbRcJzCuQFAnDE bDvh8mrUjJh9ypeXTE4GI87WhQm4k3lDk4zoQ4Mt+O8HUmVeKOEhromVWuQgTZZLoJGX89 1xXA52iEzuMXsBI5QPEmLCYdaFgGwqxC5rAZzaZzSFFRIC6gsfsqq6zbzVZ37Gag5W2wgh 5r5qUzbw15jPZL5GYCRUHcSKzaRvb8FL7i5f0tlrmL82hM+/qv2bzMJc6L5k/Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667573878; 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=bR/mftSP+c00ARZaKpp17SnhKoPd5BhUk3++d2T/vCA=; b=9FEpIwyJCazovQUC5fZa2Ev4q0i98lV3OV5rm+y2sgZ/wTepYpgtZsSEbEaPEIZQvzmlHt O4Yo32UnlmCSnPBw== 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 , "Richard Cochran (linutronix GmbH)" , Anna-Maria Behnsen Subject: [PATCH v4 11/16] timer: Restructure internal locking Date: Fri, 4 Nov 2022 15:57:32 +0100 Message-Id: <20221104145737.71236-12-anna-maria@linutronix.de> In-Reply-To: <20221104145737.71236-1-anna-maria@linutronix.de> References: <20221104145737.71236-1-anna-maria@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748578258599385501?= X-GMAIL-MSGID: =?utf-8?q?1748578258599385501?= 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 1b82661f6172..641e7284f0d7 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1910,11 +1910,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)) { @@ -1934,21 +1930,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); } }