From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B75CC1F8AD2 for ; Wed, 18 Dec 2024 16:59:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734541187; cv=none; b=DlqNdiSbRaECM7JUP6uQETrmHhrddUs+Zk5yqHdgWZZGlwBOHjy5EVt5/eNelNlGZBV5cXLgxLHk6zJsomljux7ohdNaFZ1R6qaF79mtO58vqxFpB9NIjEWRWqDPEMd3OENZX/0r2WkvmzfAg/LHxiF0JrrS0ZzRwfl2uJ2Zpm4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734541187; c=relaxed/simple; bh=BKkrJbSWtrMz0vRXAtkQeGH9f62w3Oq1XSGa84D9OgE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fuVnzV5lnuMtJIpPRDmRP7J0kE9U02y8oXF56HSowW7ylmLS+a0aM6hAlS82wzPXX1hY3strR4ZSYk4aluhr//x0dyv8yAO4tAEcM5BSpVrMS87UQqhY0ZW6Rn43jE3wty1kgpZUz2+rWnS0d/4S4Kjg1mUgPIe5rFLvyqcmgN8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bgR0l5xy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bgR0l5xy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81340C4CED0; Wed, 18 Dec 2024 16:59:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734541187; bh=BKkrJbSWtrMz0vRXAtkQeGH9f62w3Oq1XSGa84D9OgE=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=bgR0l5xy1Z1hBdeSMfCVmedWxxUhdsNHTiWBaj/UVF8EXqCwyLtZ8oobK1nrtBbnB on0GMxz3RmbGZUOI95cNsSElLe186m73RYcUYmIwnYkI9MEqOL5VrQXtvtXjaDp8Lr c6NY3pl7G6PNKrNUxoKKUlckwKWggm9wu3/wp+lPJRmAqaiOL6/frJhz9T14Ahu/qS HR6SAtS7EAKi6/kQwRvVET//tz5eU0QqXp2Bi9YixfoYMj0F03AZybou0kdaklMZ47 CiLwiCLAT4boNUJbJDtptfHX7ZKBa21pQnJqHhDh6eosTddvAatTWjaP/Xd690o54N 471XX8MjmLvVQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 24987CE0C3D; Wed, 18 Dec 2024 08:59:47 -0800 (PST) Date: Wed, 18 Dec 2024 08:59:47 -0800 From: "Paul E. McKenney" To: Peter Zijlstra Cc: Daniel Xu , mingo@redhat.com, will@kernel.org, longman@redhat.com, boqun.feng@gmail.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] seqlock: Use WRITE_ONCE() when updating sequence Message-ID: <9b6d585a-c17f-4dd1-9518-b28ac2dfd855@paulmck-laptop> Reply-To: paulmck@kernel.org References: <0eaea03ecc9df536649763cfecda356fc38b6938.1734477414.git.dxu@dxuuu.xyz> <20241218103000.GK11133@noisy.programming.kicks-ass.net> <20241218162325.GH2354@noisy.programming.kicks-ass.net> <20241218162934.GJ12500@noisy.programming.kicks-ass.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241218162934.GJ12500@noisy.programming.kicks-ass.net> On Wed, Dec 18, 2024 at 05:29:34PM +0100, Peter Zijlstra wrote: > On Wed, Dec 18, 2024 at 05:23:25PM +0100, Peter Zijlstra wrote: > > On Wed, Dec 18, 2024 at 07:43:41AM -0800, Paul E. McKenney wrote: > > > On Wed, Dec 18, 2024 at 11:30:00AM +0100, Peter Zijlstra wrote: > > > > On Tue, Dec 17, 2024 at 03:17:36PM -0800, Daniel Xu wrote: > > > > > > > > > @@ -405,7 +405,7 @@ do { \ > > > > > static inline void do_raw_write_seqcount_begin(seqcount_t *s) > > > > > { > > > > > kcsan_nestable_atomic_begin(); > > > > > - s->sequence++; > > > > > + WRITE_ONCE(s->sequence, READ_ONCE(s->sequence) + 1); > > > > > smp_wmb(); > > > > > } > > > > > > > > This results in significantly worse code-gen, it will change an inc to > > > > memory with a load,inc,store. > > > > > > Isn't that code-generation bug in the process of being fixed? > > > > Last time I looked the compiler wasn't allowed to touch it because of > > all the volatile going around. Did anything change? > > > > > And, either way, given the likely cache miss, should we really care? > > > > Yeah, extra register pressure too. OK, fair point. > Perhaps something like: (*(volatile unsigned int *)&s->sequence)++; ? > I'd have to check what the compiler makes of that. > > /me mucks about with godbolt for a bit... > > GCC doesn't optimize that, but Clang does. > > I would still very much refrain from making this change until both > compilers can generate sane code for it. Is GCC on track to do this, or do we need to encourage them? Just to make sure I understand, your proposal is to create an INC_ONCE() or similar, and add it once compiler support is there? Seems reasonable to me, just checking. Thanx, Paul