From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755801AbbFLTA3 (ORCPT ); Fri, 12 Jun 2015 15:00:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49729 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755739AbbFLTA0 (ORCPT ); Fri, 12 Jun 2015 15:00:26 -0400 Date: Fri, 12 Jun 2015 20:59:19 +0200 From: Oleg Nesterov To: "Paul E. McKenney" Cc: Peter Zijlstra , umgwanakikbuti@gmail.com, mingo@elte.hu, ktkhai@parallels.com, rostedt@goodmis.org, tglx@linutronix.de, juri.lelli@gmail.com, pang.xunlei@linaro.org, wanpeng.li@linux.intel.com, linux-kernel@vger.kernel.org, Al Viro , Linus Torvalds Subject: Re: [PATCH 11/18] seqcount: Introduce raw_write_seqcount_barrier() Message-ID: <20150612185919.GA11558@redhat.com> References: <20150611124636.448700267@infradead.org> <20150611124743.374180021@infradead.org> <20150611153341.GK3913@linux.vnet.ibm.com> <20150611214557.GA4249@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150611214557.GA4249@linux.vnet.ibm.com> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/11, Paul E. McKenney wrote: > > > > + * seqcount_t seq; > > > + * bool X = true, Y = false; > > > + * > > > + * void read(void) > > > + * { > > > + * bool x, y; > > > + * > > > + * do { > > > + * int s = read_seqcount_begin(&seq); > > > + * > > > + * x = X; y = Y; > > > + * > > > + * } while (read_seqcount_retry(&seq, s)); > > > + * > > > + * BUG_ON(!x && !y); > > > + * } > > > + * > > > + * void write(void) > > > + * { > > > + * Y = true; > > > + * > > > + * write_seqcount_begin(seq); > > > + * write_seqcount_end(seq); > > > + * > > > + * X = false; > > > + * } > > > > > +static inline void raw_write_seqcount_barrier(seqcount_t *s) > > > +{ > > > + s->sequence++; > > > + smp_wmb(); > > > + s->sequence++; > > > +} > > > + > > > /* > > > * raw_write_seqcount_latch - redirect readers to even/odd copy > > > * @s: pointer to seqcount_t > > > > Looks good otherwise. > > > > Reviewed-by: Paul E. McKenney > > Color me slow and stupid. Maybe due to reviewing a patch too early in > the morning, who knows? > > There is nothing above that prevents the compiler and the CPU from > reordering the assignments to X and Y with the increment of s->sequence++. Yes, but this doesn't matter, I think. The writer does Y = true; 1st_increment; wmb(); 2nd_increment; X = false; and we do not care about reordering before or after wmnb() at all. But we rely on the fact that 1st_increment can not be reordered with "X = false", and that "Y = true" can not be reordered with the 2nd_increment. And another simple "proof" is that seqcount_barrier() is equivalent to write_seqcount_begin() + + write_seqcount_end() and thus the code above is correct, or the ACQUIRE/RELEASE semantics of seqcount_t is broken ;) Oleg.