Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp68320rdf; Mon, 20 Nov 2023 16:38:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IEm2OSMLoxchNJ8fOBP2KhAJtyfPGBWhXLefGYpIbZ4Zq2Tbj5P08YMuxVXJ8HQ+yhD929x X-Received: by 2002:a05:6870:96a4:b0:1f5:ccc6:36 with SMTP id o36-20020a05687096a400b001f5ccc60036mr11532962oaq.36.1700527106774; Mon, 20 Nov 2023 16:38:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700527106; cv=none; d=google.com; s=arc-20160816; b=0GZyfOqOACNRB7eiwFt14gDusDYcylBTC93Su6qgNUXksjlCXObLg2AxYJc5b44T3A wLPCLn0n8aH8FMEwYk6KpVL86Q1RLxKmE5RL3Wbqf46FM5+uTSK2HBfJ8Z+YlJOuJdFg CC44zu3BMmWrtdeL/OSbt0zMV2PTU2SDjKuRdG5Qu+Vt5KDwu3WuOph3BGIgjmVy6M0E GqO1blLInCj8vzXI762yRzxocYWXHFPqmJugegyk54z+E9tWPSuz1RRglLxYOSgdkaX1 9gHWIRJ1n8dwDY4KYjZze9Rw43xNL7r427enAdYyZm2RvovJ/3uKntQFR5siCdXTCzro rh3Q== 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=m3+mV4D9cHsYIpdu5rD5+dCdp87Lbcn/lIoF5cFH4mg=; fh=z9W4oVdUQnH5bSFRNqkjhmWrzFDbzja8FeSnD4u1LKM=; b=zh2Vsvld/oyqr4I5oXJ/SqD28ZCO9vW5t80pYAABeIhgqhMHic9pMp4FGoWDEzePvH qnjd8Sha2Zo8QwKRUeeBT4Df2ed09XamCEHHR+h9TsfrSJzIgbphhgDRdPB5ryOL6sSl u3rik8QzqtmxjqAQan+NYO7MvDBleRK2eZiKDaiSjZUBN9ExSLrLRXMMG3OWbklvkJEE KzqyT37fsS5adY70VvHflUHfGWHtSEsmsEiQPxBYSz/iW2lTVhfHydJmbUuj8hdAdyhA Imy1noyXVoRk9AJtXuwpaQC0y/jsAx9Pm3EY8FiXkLuoikHc1iGuIuSGXrds6i37UtsO u4wA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NEAPL1v4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id 36-20020a631464000000b005859c255ce8si9324505pgu.819.2023.11.20.16.38.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 16:38:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NEAPL1v4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id CA16A8078C9A; Mon, 20 Nov 2023 16:38:23 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229853AbjKUAiP (ORCPT + 99 others); Mon, 20 Nov 2023 19:38:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229490AbjKUAiO (ORCPT ); Mon, 20 Nov 2023 19:38:14 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72C1CBB for ; Mon, 20 Nov 2023 16:38:11 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D90E3C433C8; Tue, 21 Nov 2023 00:38:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700527090; bh=YaadEINN+MJ2ly7Vsrgyw8WtUuyHp41LyZ7pnHSZI7I=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=NEAPL1v4B1fGEyzm8CG5AD4iy/ZOD+hVeCbdkf6bmBFbows0o2JfcguPGkxq2XmbM xa87Px1CI28arzhCoGmlzLXrYU3yu056Ey6CBNEyNS7u80d29qycuiwrq9WOCBVkD9 RvhbZhkt4jqpOw5rztsyAmrHhpKYYfvf3xM8LWutEdQDzOQdZQ06QyDM/TddnfHx6F +yX9ZnHVLcx8FayNLGuIvJ1hELFL4ilgQdyinsueEhXLpyat4C5P7mC7YTGM7S615x tDDfWvMW054oKg63e9QiETGJ7UKrBC3oYW0Y2gUEE1I1on4TOIELxtcE+TFGOPGyDU SeTDogLBJfz1A== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 787C7CE1390; Mon, 20 Nov 2023 16:38:10 -0800 (PST) Date: Mon, 20 Nov 2023 16:38:10 -0800 From: "Paul E. McKenney" To: Ankur Arora Cc: linux-kernel@vger.kernel.org, tglx@linutronix.de, peterz@infradead.org, torvalds@linux-foundation.org, linux-mm@kvack.org, x86@kernel.org, akpm@linux-foundation.org, luto@kernel.org, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, willy@infradead.org, mgorman@suse.de, jon.grimm@amd.com, bharata@amd.com, raghavendra.kt@amd.com, boris.ostrovsky@oracle.com, konrad.wilk@oracle.com, jgross@suse.com, andrew.cooper3@citrix.com, mingo@kernel.org, bristot@kernel.org, mathieu.desnoyers@efficios.com, geert@linux-m68k.org, glaubitz@physik.fu-berlin.de, anton.ivanov@cambridgegreys.com, mattst88@gmail.com, krypton@ulrich-teichert.org, rostedt@goodmis.org, David.Laight@aculab.com, richard@nod.at, mjguzik@gmail.com Subject: Re: [RFC PATCH 48/86] rcu: handle quiescent states for PREEMPT_RCU=n Message-ID: <2027da00-273d-41cf-b9e7-460776181083@paulmck-laptop> Reply-To: paulmck@kernel.org References: <20231107215742.363031-1-ankur.a.arora@oracle.com> <20231107215742.363031-49-ankur.a.arora@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231107215742.363031-49-ankur.a.arora@oracle.com> 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,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 groat.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 (groat.vger.email [0.0.0.0]); Mon, 20 Nov 2023 16:38:24 -0800 (PST) On Tue, Nov 07, 2023 at 01:57:34PM -0800, Ankur Arora wrote: > cond_resched() is used to provide urgent quiescent states for > read-side critical sections on PREEMPT_RCU=n configurations. > This was necessary because lacking preempt_count, there was no > way for the tick handler to know if we were executing in RCU > read-side critical section or not. > > An always-on CONFIG_PREEMPT_COUNT, however, allows the tick to > reliably report quiescent states. > > Accordingly, evaluate preempt_count() based quiescence in > rcu_flavor_sched_clock_irq(). > > Suggested-by: Paul E. McKenney > Signed-off-by: Ankur Arora > --- > kernel/rcu/tree_plugin.h | 3 ++- > kernel/sched/core.c | 15 +-------------- > 2 files changed, 3 insertions(+), 15 deletions(-) > > diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h > index f87191e008ff..618f055f8028 100644 > --- a/kernel/rcu/tree_plugin.h > +++ b/kernel/rcu/tree_plugin.h > @@ -963,7 +963,8 @@ static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp) > */ > static void rcu_flavor_sched_clock_irq(int user) > { > - if (user || rcu_is_cpu_rrupt_from_idle()) { > + if (user || rcu_is_cpu_rrupt_from_idle() || > + !(preempt_count() & (PREEMPT_MASK | SOFTIRQ_MASK))) { This looks good. > /* > * Get here if this CPU took its interrupt from user > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index bf5df2b866df..15db5fb7acc7 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -8588,20 +8588,7 @@ int __sched _cond_resched(void) > preempt_schedule_common(); > return 1; > } > - /* > - * In preemptible kernels, ->rcu_read_lock_nesting tells the tick > - * whether the current CPU is in an RCU read-side critical section, > - * so the tick can report quiescent states even for CPUs looping > - * in kernel context. In contrast, in non-preemptible kernels, > - * RCU readers leave no in-memory hints, which means that CPU-bound > - * processes executing in kernel context might never report an > - * RCU quiescent state. Therefore, the following code causes > - * cond_resched() to report a quiescent state, but only when RCU > - * is in urgent need of one. > - */ > -#ifndef CONFIG_PREEMPT_RCU > - rcu_all_qs(); > -#endif But... Suppose we have a long-running loop in the kernel that regularly enables preemption, but only momentarily. Then the added rcu_flavor_sched_clock_irq() check would almost always fail, making for extremely long grace periods. Or did I miss a change that causes preempt_enable() to help RCU out? Thanx, Paul > return 0; > } > EXPORT_SYMBOL(_cond_resched); > -- > 2.31.1 >