Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp711268rdb; Thu, 19 Oct 2023 17:49:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGhWgpbFCFKY3IkfTgqaW89JrOroKaasElksCqaTqjTbblBNTw+h6LoVfYPIDqRwS1eEFRo X-Received: by 2002:a17:90a:194:b0:27d:5946:5e2e with SMTP id 20-20020a17090a019400b0027d59465e2emr507300pjc.1.1697762955963; Thu, 19 Oct 2023 17:49:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697762955; cv=none; d=google.com; s=arc-20160816; b=TggM7rpGfxd3oDv/O/GNlpUv4biObeht2U4ycx4J2w050eHB1xIRJ5ixtwU1o1Xd7v EHsGbkQloC6fFZCSRgblZUKstpIW654RligKuW1jmvJSE84Iw4UwfoD6j0vGIt2o9NWF xYyEj6AR3jwl993mGXz3ZICCVaOLrcuzTrdwBUXPZFnTbwqvkBTinDklVSciGGVN69WB ARZelOUlXUJN2tiVMI32zSMQjWKAOF3sjWBAlcJY2VS03swasU7/v5jahwg8uJ79vh8d qsej3T8cioRuEkBiHogH4H8v2icbBjUnFkFItL3xZpg3nW7ULzjrMlz+SDtYy502Mh4v QyGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=bC8TXbHsfwAn9cRKKFW7p2E6F8Sko/3MA9Jk6oMFD84=; fh=42W0Ruxbtug8Q7zrU3JSMjODvfjeDuJ4gVbLxJ2lfjo=; b=P6pvSEAbzub9Q7UUPvqcy3PbuID49XQMMGNoqY+2OPMJrlNITskr186lVWdYxRDBZM DC8WNvv6+9mHgAUIwOJ33woZWIetnxWJf9JgQt3AqbkS69MM6WAQpbYncYnAG0fmfFnU Ck7IRyHQDdgRGsXGT2iwmXNhTiUcXALkC4GBT0WEjVxgax2pvQC8QOM8jZlD5L0dA3uJ I+cnKl41GLyCi5+lCr9n77opEafbdsbVyosXuoq40zGlBmeMil3hJ8gpjgZSBYoLSDPA Uqx1AnFERXIET9ZzPuym0AyPDcZLP9sbWgyJbJjn0NNYWlL+gcIgLvpa25eVD2vNrJPf hnJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BuQZ4T8W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id s1-20020a17090aad8100b0027d0c3507eesi3310710pjq.32.2023.10.19.17.49.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 17:49:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BuQZ4T8W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 95D5082CC46D; Thu, 19 Oct 2023 17:49:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346802AbjJTAtG (ORCPT + 99 others); Thu, 19 Oct 2023 20:49:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346767AbjJTAtF (ORCPT ); Thu, 19 Oct 2023 20:49:05 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD6EEFA; Thu, 19 Oct 2023 17:49:03 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7CEF9C433C9; Fri, 20 Oct 2023 00:49:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697762943; bh=9IPz2MmxCzAMUtqeAKQ6/4/VO68F8fYr09w07o8HlVk=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=BuQZ4T8WbnmiItxronuQk02qekF/N0iZ20hsL6StDD8S5qJITFUOPXkr2JVuJcsyU pSeB/+Yr4PPRLN/B2TptPn/KkPpvPBuby3Jn03xgvXEDLm2D4+yUM4fqvj3ekO2s/J /Y7F8xuI+qxA1UR7YXUl2jMLEgMzaXxPjBxCz3IGKf7PHuRfzwjmwfXSqrFHkCLagF HNDAinJkl4KYZPmQhaAwinHLX2JBfbl+fUWn+3f6+/AU+AH58ZVrJAFdtWy2pp7/WS mya3qaMHUiyq/o8UpWLf1Dax50kMAGJ8VG7cqldUPXYWwZxg0KNqPWIDX+zn7a3EMn fwTNQ3gxE8ANA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 1EA6BCE0DEA; Thu, 19 Oct 2023 17:49:03 -0700 (PDT) Date: Thu, 19 Oct 2023 17:49:03 -0700 From: "Paul E. McKenney" To: Frederic Weisbecker Cc: LKML , Boqun Feng , Joel Fernandes , Josh Triplett , Mathieu Desnoyers , Neeraj Upadhyay , Steven Rostedt , Uladzislau Rezki , rcu , Zqiang , Lai Jiangshan , "Liam R . Howlett" , Peter Zijlstra , Sebastian Siewior , Thomas Gleixner Subject: Re: [PATCH 3/4] rcu: Make tiny RCU use ksoftirqd to trigger a QS from idle Message-ID: Reply-To: paulmck@kernel.org References: <20231019233543.1243121-1-frederic@kernel.org> <20231019233543.1243121-4-frederic@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231019233543.1243121-4-frederic@kernel.org> X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Thu, 19 Oct 2023 17:49:13 -0700 (PDT) On Fri, Oct 20, 2023 at 01:35:42AM +0200, Frederic Weisbecker wrote: > The commit: > > cff9b2332ab7 ("kernel/sched: Modify initial boot task idle setup") > > fixed an issue where rcutiny would request a quiescent state with > setting TIF_NEED_RESCHED in early boot when init/0 has the PF_IDLE flag > set but interrupts aren't enabled yet. A subsequent call to > cond_resched() would then enable IRQs too early. > > When callbacks are enqueued in idle, RCU currently performs the > following: > > 1) Call resched_cpu() to trigger exit from idle and go through the > scheduler to call rcu_note_context_switch() -> rcu_qs() > > 2) rcu_qs() notes the quiescent state and raises RCU_SOFTIRQ if there > is a callback, waking up ksoftirqd since it isn't called from an > interrupt. > > However the call to resched_cpu() can opportunistically be replaced and > optimized with raising RCU_SOFTIRQ and forcing ksoftirqd wakeup instead. > > It's worth noting that RCU grace period polling while idle is then > suboptimized but such a usecase can be considered very rare or even > non-existent. > > The advantage of this optimization is that it also works if PF_IDLE is > set early because ksoftirqd is created way after IRQs are enabled on > boot and it can't be awaken before its creation. If > raise_ksoftirqd_irqoff() is called after the first scheduling point > but before kostfirqd is created, nearby voluntary schedule calls are > expected to provide the desired quiescent state and in the worst case > the first launch of ksoftirqd is close enough on the first initcalls. > > Fixes: cff9b2332ab7 ("kernel/sched: Modify initial boot task idle setup") > Cc: Liam R. Howlett > Cc: Peter Zijlstra (Intel) > Cc: Sebastian Siewior > Cc: Thomas Gleixner > Signed-off-by: Frederic Weisbecker Reviewed-by: Paul E. McKenney I did a touch-test of the series, and have started overnight testing. Thanx, Paul > --- > kernel/rcu/tiny.c | 21 ++++++++++++++++----- > 1 file changed, 16 insertions(+), 5 deletions(-) > > diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c > index fec804b79080..9460e4e9d84c 100644 > --- a/kernel/rcu/tiny.c > +++ b/kernel/rcu/tiny.c > @@ -190,12 +190,15 @@ void call_rcu(struct rcu_head *head, rcu_callback_t func) > local_irq_save(flags); > *rcu_ctrlblk.curtail = head; > rcu_ctrlblk.curtail = &head->next; > - local_irq_restore(flags); > > if (unlikely(is_idle_task(current))) { > - /* force scheduling for rcu_qs() */ > - resched_cpu(0); > + /* > + * Force resched to trigger a QS and handle callbacks right after. > + * This also takes care of avoiding too early rescheduling on boot. > + */ > + raise_ksoftirqd_irqoff(RCU_SOFTIRQ); > } > + local_irq_restore(flags); > } > EXPORT_SYMBOL_GPL(call_rcu); > > @@ -228,8 +231,16 @@ unsigned long start_poll_synchronize_rcu(void) > unsigned long gp_seq = get_state_synchronize_rcu(); > > if (unlikely(is_idle_task(current))) { > - /* force scheduling for rcu_qs() */ > - resched_cpu(0); > + unsigned long flags; > + > + /* > + * Force resched to trigger a QS. This also takes care of avoiding > + * too early rescheduling on boot. It's suboptimized but GP > + * polling on idle isn't expected much as a usecase. > + */ > + local_irq_save(flags); > + raise_ksoftirqd_irqoff(RCU_SOFTIRQ); > + local_irq_restore(flags); > } > return gp_seq; > } > -- > 2.34.1 >