From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42214) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZYyjq-0000WT-1b for qemu-devel@nongnu.org; Mon, 07 Sep 2015 11:53:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZYyjl-0002o4-MZ for qemu-devel@nongnu.org; Mon, 07 Sep 2015 11:53:45 -0400 Received: from mail-wi0-f169.google.com ([209.85.212.169]:37915) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZYyjl-0002nt-G2 for qemu-devel@nongnu.org; Mon, 07 Sep 2015 11:53:41 -0400 Received: by wiclk2 with SMTP id lk2so88390345wic.1 for ; Mon, 07 Sep 2015 08:53:41 -0700 (PDT) References: <1440375847-17603-1-git-send-email-cota@braap.org> <1440375847-17603-8-git-send-email-cota@braap.org> From: Alex =?utf-8?Q?Benn=C3=A9e?= In-reply-to: <1440375847-17603-8-git-send-email-cota@braap.org> Date: Mon, 07 Sep 2015 16:53:39 +0100 Message-ID: <87d1xu9qf0.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [RFC 07/38] seqlock: read sequence number atomically List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Emilio G. Cota" Cc: mttcg@listserver.greensocs.com, mark.burton@greensocs.com, a.rigo@virtualopensystems.com, qemu-devel@nongnu.org, guillaume.delbergue@greensocs.com, pbonzini@redhat.com, Frederic Konrad Emilio G. Cota writes: > With this change we make sure that the compiler will not > optimise the read of the sequence number in any way. What was it doing? Using atomic_read to work around a compiler bug seems a bit heavy handed if true atomicity isn't needed. > > Signed-off-by: Emilio G. Cota > --- > include/qemu/seqlock.h | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/include/qemu/seqlock.h b/include/qemu/seqlock.h > index f1256f5..70b01fd 100644 > --- a/include/qemu/seqlock.h > +++ b/include/qemu/seqlock.h > @@ -55,18 +55,18 @@ static inline void seqlock_write_unlock(QemuSeqLock *sl) > static inline unsigned seqlock_read_begin(QemuSeqLock *sl) > { > /* Always fail if a write is in progress. */ > - unsigned ret = sl->sequence & ~1; > + unsigned ret = atomic_read(&sl->sequence); > > /* Read sequence before reading other fields. */ > smp_rmb(); > - return ret; > + return ret & ~1; > } > > static inline int seqlock_read_retry(const QemuSeqLock *sl, unsigned start) > { > /* Read other fields before reading final sequence. */ > smp_rmb(); > - return unlikely(sl->sequence != start); > + return unlikely(atomic_read(&sl->sequence) != start); > } > > #endif -- Alex Bennée