From patchwork Wed May 24 07:06:24 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: 98337 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2651097vqo; Wed, 24 May 2023 00:11:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6D7OB14/BxqPwGMsP3hMd/2/G6TyX9tZDrYtvHWr6SjFxgLjuyxJzFNR85e3LGOgoK8Kj+ X-Received: by 2002:a17:90a:ee8c:b0:24d:e296:659b with SMTP id i12-20020a17090aee8c00b0024de296659bmr17493211pjz.22.1684912265351; Wed, 24 May 2023 00:11:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684912265; cv=none; d=google.com; s=arc-20160816; b=r3uoyGTtgS4iakcjR1XjQQVgGEGgZWFvV+csXKamtDLXoBFcQH8y3KdriiKAPdoK1t 7U2/75v+4NlvtdhnPx82G1RGfELJoeAnbnoH7nG1txAFlK4zDpmSz5V86nMyS3hiZQoe WoaB2KVvua/phJgsl5vfjhL2i5FqGzMaUtRV2MAzBo9BUKN0tiNU4bKG7rHtYL7eQOlK uyUXQhigOv7S+AcI43Mr0BEfhBTqRPnv7SNgQlOK9Dsjg3du5uzxv4FFZsIkY/Y52KjK fH+5AIGGKVvcZ3K3Rbg2uK4ix/HhXIRfDVdD4H5hpWXvjUNwsIhSlSzS/diITb7MLkbs VOVg== 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=5Rgz0XMpFHBcgryFLb9u8XHoyQkZQCERFRJm4RJQ5aM=; b=uYQ33Q+G04VBJT2q8KD46yKu8dMBqIfAvV9Ga8aIYMDAlmjVxiiePPV/pwF/4Y8A8F e5uriafC3RIHOLxQQy8oRoGyk0xMm1ZA+bIIiVdo38dJvNP4qO18H1Az0MPi5kMAe3jb wFsh2oFI5xz7ORwM0z6aJH4mfXk8kNC90wAMUmNbYZIrgpx/95Yk/xhk2jzqKUqcJEOq i49j/9GQ2sZhclvc+BiSkw7JTddeG5wXt1CmRackP4jhsFAKoCJPu6kM4PeceLVETZXn VTS2XbU7QBIxooLyZWOQqc9rfJs7+zI3wEgMNcjyOc8rEAufqLb4uxJGodVcjenQrZ2r mXiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="ZA/565hY"; 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 k70-20020a638449000000b0051b423d966csi1234300pgd.280.2023.05.24.00.10.52; Wed, 24 May 2023 00:11:05 -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="ZA/565hY"; 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 S239737AbjEXHIT (ORCPT + 99 others); Wed, 24 May 2023 03:08:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239908AbjEXHHj (ORCPT ); Wed, 24 May 2023 03:07:39 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50C431B4 for ; Wed, 24 May 2023 00:07:06 -0700 (PDT) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1684912024; 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=5Rgz0XMpFHBcgryFLb9u8XHoyQkZQCERFRJm4RJQ5aM=; b=ZA/565hYULTzhp4Plywb8Bb+rNQozqthRlQ6lyBZEoVflXtTSl3KMZujNEkfx0dSNcU5/7 trLT0/nXE2rKYK6Cizc0bIhdbBXM44Qg9RlA3fFF0fgq6Vg2HKXAKhkbjZqkf0kruE5vZO nieSIsftVRLVWSu9ja7vlz+8Lbz13x96ybGfJQ4LhtyKs8McVBIfgEj34JufyUpUZ3n3/Q 8Gq8jjCogehMm6wwEdK3YSpTVigv7G4MRAwOBI97dFp9GDoRQvYuylShzLYDRBvp1Lanrf 3NFUmpc85EyY6G9KcUr2YW+U4rnL4i9lHp9GGV0Uqf6oTE9SLjYjbhw44w04iQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1684912024; 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=5Rgz0XMpFHBcgryFLb9u8XHoyQkZQCERFRJm4RJQ5aM=; b=B10AAADYkHpwVbWkLSNQvdrPRmrH7RAgbM7qllpRuQNJyuypUowUeOG9RoOUqqsfBCeaUt k5vfawz1UXqFJcCA== 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" , "Richard Cochran (linutronix GmbH)" , Anna-Maria Behnsen Subject: [PATCH v7 16/21] timer: Restructure internal locking Date: Wed, 24 May 2023 09:06:24 +0200 Message-Id: <20230524070629.6377-17-anna-maria@linutronix.de> In-Reply-To: <20230524070629.6377-1-anna-maria@linutronix.de> References: <20230524070629.6377-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,T_SCC_BODY_TEXT_LINE 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?1766758563727744826?= X-GMAIL-MSGID: =?utf-8?q?1766758563727744826?= 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 564001b98098..20106dad531a 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -2202,11 +2202,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)) { @@ -2226,21 +2222,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); } }