From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47161) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpZqb-0001jp-0I for qemu-devel@nongnu.org; Thu, 20 Jun 2013 04:04:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UpZqZ-0000ow-O5 for qemu-devel@nongnu.org; Thu, 20 Jun 2013 04:04:00 -0400 Received: from mail-qc0-x22c.google.com ([2607:f8b0:400d:c01::22c]:55927) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpZqZ-0000or-KJ for qemu-devel@nongnu.org; Thu, 20 Jun 2013 04:03:59 -0400 Received: by mail-qc0-f172.google.com with SMTP id j10so3604586qcx.3 for ; Thu, 20 Jun 2013 01:03:59 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <51C2B766.70308@redhat.com> Date: Thu, 20 Jun 2013 10:03:50 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1371675569-6516-1-git-send-email-pingfank@linux.vnet.ibm.com> <1371675569-6516-2-git-send-email-pingfank@linux.vnet.ibm.com> <1371674394.16968.26000.camel@triegel.csb> <51C2183D.7050605@twiddle.net> In-Reply-To: <51C2183D.7050605@twiddle.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v3 1/2] add a header file for atomic operations List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Richard Henderson Cc: Kevin Wolf , "Paul E. McKenney" , Stefan Hajnoczi , Andrew Haley , Liu Ping Fan , qemu-devel@nongnu.org, Anthony Liguori , Torvald Riegel Il 19/06/2013 22:44, Richard Henderson ha scritto: >>> >> + /* Data must be read atomically. We don't really need barrier semantics >>> >> + * but it's easier to use atomic_* than roll our own. */ >>> >> + log = atomic_xchg(from, 0); >> > >> > If you really don't need any ordering guarantees / barriers here, then >> > using a relaxed load should be fine. But my gut feeling tells me you >> > probably do need some barriers; either you are "re-using" another >> > barrier (and then the comment should probably point out which), or it >> > must be a case where it's either fine to read any value someone (else) >> > wrote or there's no concurrent store after all. >> > > There is a store here, before and after. Read the value, store zero. > > I suppose what the comment is saying is that the atomic operation doesn't need > to be ordered with respect to the rest of the surrounding code, as the object > being synchronized is just that one integer. Exactly. The items of the array can be read independently. Paolo