From patchwork Fri Dec 1 09:26:48 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: 172372 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp993232vqy; Fri, 1 Dec 2023 01:31:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IH5Z+Gu+FVg0f8yBxtZtGpOVBreKCNfZtPoM/CXUUXHCvfIm3Cyfo5+L7Q7MMbZOYWXfC7p X-Received: by 2002:a05:6a00:14c8:b0:68f:c078:b0c9 with SMTP id w8-20020a056a0014c800b0068fc078b0c9mr33578360pfu.11.1701423092553; Fri, 01 Dec 2023 01:31:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701423092; cv=none; d=google.com; s=arc-20160816; b=Olp7rjvgyNLGIXN0A7y4HVO5E4SObBDIq5cEn3iVvnOkttNU9jjsJq2krvQVqNMQsk fFDxRXarqj1o72K9EYwzOSVf0B1vMeDGRp/2pyRoAei9NsIV2BwxaTff9RDODSNk3kzW zmm1AmgvVfw/DflgA1OamieI/64Vs/2h2MFyyM6GXiR4wkGMc+CSr8+j/ipixgFXpgBZ ZaJDYeKYsfVoiJBaKiW6xKQNRSTkMk2DOIzUIrMAAopqe3akPeWL3SsDgns8chF6OMwQ kbcSEsc1baGryNgG7emZPcTcHpyFbOd5OOr2f0E+jA/1eAbkSn7xdmTLLAG1mSmDB1kB 1fTg== 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=bWHMK6r5kBUJ9iV8cP/TU68Vsy3sDvddkiKO4TwUZlc=; fh=H6hHKnScvHhKAB7z8Wb75LBNJxB0aNyPhv3ZCgyEYhY=; b=xfQtrpRx06GENA1+vLwDY10Idn7puI3XILwiq1uCw1ViYS5m8/VxMuQMojLJwWIHRH D7bklEsoJxGE76RRKJN3TZj5Mr3in4n+wA13PETckZrTw9zCeAxr4v8zZvbKF0ZOIa2K RO0gjSiR1G+A8d3HqWhm7q7i7N27D0mApV9VKkIK+pjsBhKdoWdvTvoUbKUSy/xeBJsC 9Or1bfx5gKbEfuQzv5q0LbRp8DJsOzy7h2lFrOQfUE5hOLkkGUgOMsP2yWSxlSPMn896 G84zTZ0STZB4pMqKtiMiv5OMnuxDxoh0sHlIkd3UEveVru9jdstfPIlEPExnA+9qOZn3 Q+OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=QMhs93p2; dkim=neutral (no key) header.i=@linutronix.de header.b=xZTklOBz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id d3-20020a63ed03000000b005a9fb6bf73esi3030608pgi.293.2023.12.01.01.31.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 01:31:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=QMhs93p2; dkim=neutral (no key) header.i=@linutronix.de header.b=xZTklOBz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id AE79E808BCB7; Fri, 1 Dec 2023 01:30:21 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378259AbjLAJ2w (ORCPT + 99 others); Fri, 1 Dec 2023 04:28:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378126AbjLAJ2K (ORCPT ); Fri, 1 Dec 2023 04:28:10 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC6641BFE for ; Fri, 1 Dec 2023 01:27:26 -0800 (PST) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1701422844; 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=bWHMK6r5kBUJ9iV8cP/TU68Vsy3sDvddkiKO4TwUZlc=; b=QMhs93p2ZCm6/MJxUMJdkxY/fBy9yYF7JUtsxSHtc9PYue8MZ0SoTHBdgGncOOxORk0ako vL2tnp0171mhN/4n/ReEYLl/a3R6Z/zdScU2QBslAWcu1KSe4vZ+h5iv0arm6+pF4t+FeB NjTheIExH1dDjaJXiRJsT4vg4FMpVT27Wiuihfby106yl2uG6MuiyJfHPXoRVnihspDN6Y SFZd19aQtV1uHqBTmaAUH80vC9KQsqfY6IqczyD0Sp+K85mgP6sQgx6Te5oltDezegw1H0 luV9XbDyrXLtx5BGc7S0R3jPEnug9EJnE2fhRH49c0HGea35EpV2UQ/Z1rlS9A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1701422844; 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=bWHMK6r5kBUJ9iV8cP/TU68Vsy3sDvddkiKO4TwUZlc=; b=xZTklOBzQvP69gCnFqvs8Dq2tLlMJcoPnlLizYK7DoNtiWj3CrGJ5Pba/DvLj/dMeYpxV6 VDw0ycerZCa3TDCQ== 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 v9 26/32] timers: Restructure internal locking Date: Fri, 1 Dec 2023 10:26:48 +0100 Message-Id: <20231201092654.34614-27-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 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email 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 (howler.vger.email [0.0.0.0]); Fri, 01 Dec 2023 01:30:21 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784071420815626448 X-GMAIL-MSGID: 1784071420815626448 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 2cff43c10329..b0fa8afe9059 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)) { @@ -2258,21 +2254,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); } }