From patchwork Tue Oct 25 13:58:44 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: 10797 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1024273wru; Tue, 25 Oct 2022 07:02:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5qKWVEr/B8MUW06JafVtH2W/Sd5OY7P1nozhNtNKk7z1EgapeBzGo5q15VsKSr/kx2yOkp X-Received: by 2002:a05:6402:3588:b0:45d:7d14:baf2 with SMTP id y8-20020a056402358800b0045d7d14baf2mr35472497edc.1.1666706550413; Tue, 25 Oct 2022 07:02:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666706550; cv=none; d=google.com; s=arc-20160816; b=J4ms6l/3f+B4zy9M1TaFPENZyyWjlP2P4DczulkOmZD6vYuv5ybIgrCn1g3NL12B7C BMAbf+xqaZwxz+tOTL64kwQFyrv0QqdV+dggHT1y9cXfXWxEi3r0XCVY8Zxp0vkbmFo4 IeM+wr7lsZ39R091sOeG8z428k2MCEYkWwllF4zgna2+bT6ZpNYfvtZ7G2B6xkp44ot3 IVNP+6xfdg4HOlJ5RkOEPUs1Yk8xgzBZcS20mbAiEIU+ry80QmNzFUp2MuHVb+vDxn+J uWQ/yimQYZU4qRkSY28/zpiHsobmgTnndQnHuI5D5x9x8jxPx3tAf9fKcP5qBga/EO8/ +CEA== 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=CGHVsSTlrh42mtIuI9uwDJB0LFHl02eMk5Ez8/za1gE=; b=WgwahrSqDXCKq9wZcBZxD9ItuAusVWLspRF/PGKE4UgjtQPUuO2ySa2zgxIwQydypY pQuWsZqQYApG7v7Vye7rLD7+MH8mjCnEOOII7p2uR9vPb4jwPVzYkVNkWc+raOtPwR0U tGc5I2Dp3A4wKe7LAfD0Qgank2wlC449cOzxBWRCY2mFIYo6/aMyBFniu01g9d64Gx9W OgiuIHzqYElwPyPb+VVyd/XzoSiFfYF006ddrnAjwYiXu7JkjK3W6USRsZqVKIbXgy91 RaXpzE/NEuw+wdfFZB491h0heb5ke5bGYGglSpCizyhDCHHq04bmxZGxwIzwaMHnYFjs d+wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=psy71Xoy; 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::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 gt33-20020a1709072da100b00788361f96a2si887899ejc.776.2022.10.25.07.02.04; Tue, 25 Oct 2022 07:02:30 -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=psy71Xoy; 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::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 S232280AbiJYOAc (ORCPT + 99 others); Tue, 25 Oct 2022 10:00:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231917AbiJYN7d (ORCPT ); Tue, 25 Oct 2022 09:59:33 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B60C559B; Tue, 25 Oct 2022 06:59:28 -0700 (PDT) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666706367; 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=CGHVsSTlrh42mtIuI9uwDJB0LFHl02eMk5Ez8/za1gE=; b=psy71XoywLxpFRQtpsAzmGAtKp/n3Nkt57Eou0efsjHndu1b2cex56ZmmiWO/z5Ir+Jvln wStFFpbewui20Pxoz2OrdFzZdUjknLDe+y+h93ds4RSxKv0o3cKEHoYBoeq/18yELHDcv0 E3/FXpntETQtt2XKbhjzkEjzkWiQ2QxR//TCVgSMq6KH2V7PMJmBBCnt5IWpc3RW54gXC8 +z3YNawaC+b8+yJ4hK+g+fgBZvxTaJu5RgF5p/G8AlZ6A3yvb4QJQwgv26MUUDj/zbcbt3 xo+chAZ27SWHljI3LC0FS9lR0r6V2Fv96vK3AdJPsiO+KhSj+bIslofR4ilvaA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666706367; 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=CGHVsSTlrh42mtIuI9uwDJB0LFHl02eMk5Ez8/za1gE=; b=cDavS7ruVI86fuuZ0pIbMSDz0yM97jug9hFd7TT1eAn1P/NDH13s+F8kfvIDSwfEkg6gaD zqwM8KHh929+elBQ== To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , John Stultz , Eric Dumazet , Thomas Gleixner , "Rafael J. Wysocki" , linux-pm@vger.kernel.org, Arjan van de Ven , "Paul E. McKenney" , Frederic Weisbecker , Rik van Riel , "Richard Cochran (linutronix GmbH)" , Anna-Maria Behnsen Subject: [PATCH v3 11/17] timer: Restructure internal locking Date: Tue, 25 Oct 2022 15:58:44 +0200 Message-Id: <20221025135850.51044-12-anna-maria@linutronix.de> In-Reply-To: <20221025135850.51044-1-anna-maria@linutronix.de> References: <20221025135850.51044-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,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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747668487815825274?= X-GMAIL-MSGID: =?utf-8?q?1747668487815825274?= 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 54631e86763f..bce2f87d5e70 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1911,11 +1911,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)) { @@ -1935,21 +1931,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); } }