From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 729F74690 for ; Wed, 18 Dec 2024 16:29:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734539384; cv=none; b=k9mk0+G3SSW7ZIx7KBGLLAAtZp2SLSQMJV1w8TlMKWuRG1d01BNye+6jr2VeZ/QfLeVDe1TI6UINBcnJjhrexUqRSZPw7UxKnRA7PU0tFhdmXFyeVdXpQh4Xl2hq07TodA4k9rvA+hN+IVjEd5UXy/bOfUlApKTBN9i+G7jQQtk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734539384; c=relaxed/simple; bh=zqe/Tc5yCtt2Rzwg9en4Gvm5L9g065W+tfUdus9yujQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RKFdnODRf5k6vPL/xO30zC5mYNMG43uvxBY6DkBHO5HxmpXbZuP7yAYFmTuw/asf0sNLpgljUzTzTIVQ3DlTrjORZP/xOH5xBw71BugOdTBkW8t41HnfFcLlvXR0N7cXZmEXXfCRy7+OjLRHcmlkUtxW13JVs5QcWBsk+EOxJXQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=d/J9D5nX; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="d/J9D5nX" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=AxIW8ppvu13/U7Qn+yp6XSMddHFxpS2/A34A8W/DzsE=; b=d/J9D5nXRAlCEDmNimv68t2BRO 0/nlTdIB6kuXLt+cKkA4dAWCeBH9RfBv3Ym7agegU+9vZPTZF8MsK5aDqfvVs3VHcGeLkXJuPUg+S /K++EbT/bNjkbpE40cKQGqSd/w+lYR25QQELtdPPTURJwqKqtehIpSyTtsq1I18TxbutH41R+hzhv e/8/oedIGoI+Mn4aP8hzng+6l8FABBM9ydgjC3GQW+iKgU+ePuoLFuAAuxl0Jz2KGzvimOkkeM+JV vXjFhmEfeeYaJUPuoQ8QzN8qmISYT0NpmEKoqPbP2DMIZpA2JiE1BZiAZO/fehSsnqZknV6ENFHPN QM+qjYEQ==; Received: from 77-249-17-89.cable.dynamic.v4.ziggo.nl ([77.249.17.89] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tNwvW-00000000GsH-1rKc; Wed, 18 Dec 2024 16:29:35 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 6C88E30040C; Wed, 18 Dec 2024 17:29:34 +0100 (CET) Date: Wed, 18 Dec 2024 17:29:34 +0100 From: Peter Zijlstra To: "Paul E. McKenney" 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: <20241218162934.GJ12500@noisy.programming.kicks-ass.net> References: <0eaea03ecc9df536649763cfecda356fc38b6938.1734477414.git.dxu@dxuuu.xyz> <20241218103000.GK11133@noisy.programming.kicks-ass.net> <20241218162325.GH2354@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: <20241218162325.GH2354@noisy.programming.kicks-ass.net> 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. 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.