From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 10F27CCF9F6 for ; Wed, 29 Oct 2025 14:53:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=RgXYHGlIIx4Ip/v38wL2u4J4q7Wcy2XsHbcZK/IxQbM=; b=tX+gigdpPTi3Wt fux2R4kBzgbU0SirVs7nTlGPMy1CvQiekw67FK4bTdkGfOSxxa+E6m9XVgm0what0fWNyI7fPFXMP S6TBE4sTVCjuuWOefiBgxVJc4dhXvU4Lrmn4lVlEI7bT4QqDNEazY8OvBhK2+h4fYExW0QHDTiHJY 6/GCKzDpfi8QFrXMHR4Gjn6JiB0Ywx3ouODw1dTjvtX9SAbUkuwtwq9r2oFd568mK8//7FH+XffUf lEYkXSEm3naOn5Bo0PX8WrJm5L+rIr2LuuZMVpStQkeCBaevvGTYLOkjuFon1Oh56g6f7L1qtjE94 2xnmCpaReT4iK9LXEosg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vE7Xu-00000001fZR-2IvX; Wed, 29 Oct 2025 14:53:06 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vE7Xr-00000001fXX-1H9F; Wed, 29 Oct 2025 14:53:04 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 12E3741728; Wed, 29 Oct 2025 14:53:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39C64C19423; Wed, 29 Oct 2025 14:53:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1761749581; bh=DycaBBkGuqgEIP5677gSgx8QDJGofxkMNPMcP3M730o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=NbRDLF5bQ+u4J4hiySQAVpBuc86Gn1rrbceqZEKYNWpKF9yoAhVdLiG/Nu9SRzin5 ddwOS2DAvBL0w6K59co5lqXWGrpHXdyA3+e94n4XKlatrRRprHxYDEy/DFtpqcJYjz jGBmveuocLom0Tr99M8s/YfJisMETw3u7WfPV8VPmObP73KGTMrcXJF2ZKhuh5kL4K FNZiQ5jjE+Qy5WcINDDA3sOHLfgNQyF9ljeM8CBlvKWvkNPOMLvSsJkY31UBeqPnRr epdow2onJrow0Coha3Tk5/8X8R1mpOEWDHWRuB0t8h2sykd3/evOgK+UEPDUs1Kui5 FM7cF5Ys9ZgFA== Date: Wed, 29 Oct 2025 15:52:58 +0100 From: Frederic Weisbecker To: Valentin Schneider Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, rcu@vger.kernel.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, linux-riscv@lists.infradead.org, linux-arch@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Nicolas Saenz Julienne , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Arnaldo Carvalho de Melo , Josh Poimboeuf , Paolo Bonzini , Arnd Bergmann , "Paul E. McKenney" , Jason Baron , Steven Rostedt , Ard Biesheuvel , Sami Tolvanen , "David S. Miller" , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Mathieu Desnoyers , Mel Gorman , Andrew Morton , Masahiro Yamada , Han Shen , Rik van Riel , Jann Horn , Dan Carpenter , Oleg Nesterov , Juri Lelli , Clark Williams , Yair Podemsky , Marcelo Tosatti , Daniel Wagner , Petr Tesarik Subject: Re: [PATCH v6 23/29] context-tracking: Introduce work deferral infrastructure Message-ID: References: <20251010153839.151763-1-vschneid@redhat.com> <20251010153839.151763-24-vschneid@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251029_075303_381542_B1B3DD11 X-CRM114-Status: GOOD ( 26.87 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Le Wed, Oct 29, 2025 at 11:09:50AM +0100, Valentin Schneider a =E9crit : > On 28/10/25 15:00, Frederic Weisbecker wrote: > > Le Fri, Oct 10, 2025 at 05:38:33PM +0200, Valentin Schneider a =E9crit : > >> + old =3D atomic_read(&ct->state); > >> + > >> + /* > >> + * The work bit must only be set if the target CPU is not executing > >> + * in kernelspace. > >> + * CT_RCU_WATCHING is used as a proxy for that - if the bit is set, = we > >> + * know for sure the CPU is executing in the kernel whether that be = in > >> + * NMI, IRQ or process context. > >> + * Set CT_RCU_WATCHING here and let the cmpxchg do the check for us; > >> + * the state could change between the atomic_read() and the cmpxchg(= ). > >> + */ > >> + old |=3D CT_RCU_WATCHING; > > > > Most of the time, the task should be either idle or in userspace. I'm s= till not > > sure why you start with a bet that the CPU is in the kernel with RCU wa= tching. > > > = > Right I think I got that the wrong way around when I switched to using > CT_RCU_WATCHING vs CT_STATE_KERNEL. That wants to be > = > old &=3D ~CT_RCU_WATCHING; > = > i.e. bet the CPU is NOHZ-idle, if it's not the cmpxchg fails and we don't > store the work bit. Right. > = > >> + /* > >> + * Try setting the work until either > >> + * - the target CPU has entered kernelspace > >> + * - the work has been set > >> + */ > >> + do { > >> + ret =3D atomic_try_cmpxchg(&ct->state, &old, old | (work << CT_WORK= _START)); > >> + } while (!ret && !(old & CT_RCU_WATCHING)); > > > > So this applies blindly to idle as well, right? It should work but note= that > > idle entry code before RCU watches is also fragile. > > > = > Yeah I remember losing some hair trying to grok the idle entry situation; > we could keep this purely NOHZ_FULL and have the deferral condition be: > = > (ct->state & CT_STATE_USER) && !(ct->state & CT_RCU_WATCHING) Well, after all what works for NOHZ_FULL should also work for idle. It's preceded by entry code as well (or rather __cpuidle). Thanks. -- = Frederic Weisbecker SUSE Labs _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv