From patchwork Wed Mar 1 14:17:39 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: 62917 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp3658537wrd; Wed, 1 Mar 2023 06:22:53 -0800 (PST) X-Google-Smtp-Source: AK7set+rThver9mwxeF3k17g/Zj4LxjEN5FpYkFhtPiajtrFHbiXRXw0TMBBqJl1nXKNsnynVAqa X-Received: by 2002:a17:906:c2c3:b0:878:42af:aa76 with SMTP id ch3-20020a170906c2c300b0087842afaa76mr7806925ejb.54.1677680573751; Wed, 01 Mar 2023 06:22:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677680573; cv=none; d=google.com; s=arc-20160816; b=ciYt1hSEEy9kzA88BLrQ2SfN+UwHb5iyVFBXm7yJSDXEMtFHgr8RlEVSh/UPpn1w6a tx6Fv3dsnF27+DAZwEj4Df8J3dO/61hgCvnNhqQlzVCbyqtdwyU7TtTPmExphTS+/W2o Z6iOcXmTUokuC4PoQ69xQd7xGDssfFTOnFGMeZDrs7GoKdeWfSuf7+OnBdyl8WTDufou ZC87GhiToh6+2zcGca7FWNgYNIaghPqJbhFJZ01VNDVOhwT0nKaMKi2Ak4eaerTtdxRx 5KYQyzbmbV1KKVbxMGoUU4T82nW6B9PF0xCiYPIL0JEulFNNpgUsCG0/xEn3OTE0UWst A4Yw== 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=hYkRaj7fFuHhhF0p5MKMIEGo5VHWJduanTtTi0xnzx4=; b=cEs72Pgn3eFOog2T1U7HnjMuquDmjO+h8+Yj5ILlZHRao+QMOS3IRdbncsCEgG18i1 1teYSC8ehJYdwULVmgDq0PjTIdUC8B5lx/D01hJPi7Jj11b4fL5uvPv6DSaoMbdbp5Dy 4jFNVio5+mc4654bkEDl235A4hYQme9mNZyMJE/2frxI/baZGIOmr46CG9ufnR4zb1pa pPf2X8+YTsQNDjxLEcfLphoydeZsTy+Nnkt+SlJXNQcXyPs1NKmFJiyLj2Gd5Se/GzzE qbPf4E/xF08GMRRssINOufcCdPCZ+AbrbG2OT76uq9t+xILc6XuWwVWqNhK75hmULmD6 EjbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mVDzJUVS; 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 g8-20020a1709065d0800b008dcca98e6edsi6450483ejt.29.2023.03.01.06.22.31; Wed, 01 Mar 2023 06:22:53 -0800 (PST) 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=mVDzJUVS; 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 S229934AbjCAOT0 (ORCPT + 99 others); Wed, 1 Mar 2023 09:19:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230064AbjCAOSM (ORCPT ); Wed, 1 Mar 2023 09:18:12 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC735302AB for ; Wed, 1 Mar 2023 06:18:09 -0800 (PST) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1677680288; 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=hYkRaj7fFuHhhF0p5MKMIEGo5VHWJduanTtTi0xnzx4=; b=mVDzJUVSL8YbK+9WDuug7CP+lk9mwKhlGxGqYBLWtRQSlXkhIBWl4oBxypRJGdqj+TUatt VExTVmNdLsACHM/tNqpr80K/MOPP9k4If66+GlQJgP0/m/jekcPdlSBuaFeVCvKkMIhvfU saLM+xNjbyzEH5tLcJbm51/1SQS5qpe3IiXo7BQgQCZHtgwIt4VWluS3RZqDtCjOG5PMUI 7MhBnPA0pTWsRHK/BPjCprpdFLZwBb8ASGDnXzkWn5DNGzeDjErUjTANfpLYAaho1qjKoJ emM45ZMQBHGv+aHZODTbLTZXEAsaFpM5kechy4w0V/0wRoJlsaVkV3E2KpqDLA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1677680288; 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=hYkRaj7fFuHhhF0p5MKMIEGo5VHWJduanTtTi0xnzx4=; b=Dxk2RIhDpMLPxR2d11a/L4F5Oxuy6YM3yRzV2H/snMQzjS/yU651n5EfrTTDPrSORm0i4N y175wT56vIlHjNCw== 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 v5 13/18] timer: Restructure internal locking Date: Wed, 1 Mar 2023 15:17:39 +0100 Message-Id: <20230301141744.16063-14-anna-maria@linutronix.de> In-Reply-To: <20230301141744.16063-1-anna-maria@linutronix.de> References: <20230301141744.16063-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?1759175585198659533?= X-GMAIL-MSGID: =?utf-8?q?1759175585198659533?= 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 9daaef5d2f6f..be085e94afcc 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -2142,11 +2142,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)) { @@ -2166,21 +2162,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); } }