From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:60849) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TC4hu-0006jP-P7 for qemu-devel@nongnu.org; Thu, 13 Sep 2012 04:23:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TC4ht-0001qp-G8 for qemu-devel@nongnu.org; Thu, 13 Sep 2012 04:23:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31248) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TC4ht-0001qb-32 for qemu-devel@nongnu.org; Thu, 13 Sep 2012 04:23:29 -0400 Message-ID: <505197FA.1060502@redhat.com> Date: Thu, 13 Sep 2012 11:23:22 +0300 From: Avi Kivity MIME-Version: 1.0 References: <1347349912-15611-1-git-send-email-qemulist@gmail.com> <1347349912-15611-2-git-send-email-qemulist@gmail.com> <504EF077.9080107@redhat.com> <505195CF.8040002@redhat.com> <50519716.5030402@redhat.com> In-Reply-To: <50519716.5030402@redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: Jan Kiszka , Marcelo Tosatti , liu ping fan , Anthony Liguori , qemu-devel@nongnu.org On 09/13/2012 11:19 AM, Paolo Bonzini wrote: > Il 13/09/2012 10:14, Avi Kivity ha scritto: >>>>> >>> +static inline void atomic_set(Atomic *v, int i) >>>>> >>> +{ >>>>> >>> + v->counter = i; >>>>> >>> +} >>>>> >>> + >>>>> >>> +static inline int atomic_read(Atomic *v) >>>>> >>> +{ >>>>> >>> + return v->counter; >>>>> >>> +} >>>>> >>> >>>> >> >>>> >> So these two operations don't get mangled by the optimizer. >>>> >> >>> > Browsing linux code and reading lkml, find some similar material. But >>> > they have moved volatile from ->counter to function - atomic_read(). >>> > As to atomic_read(), I think it need to prevent optimizer from >>> > refetching issue, but as to atomic_set(), do we need ? >> I think so, to prevent reordering. > > Agreed. Alternatively, stick a barrier() before and after the > assignment and read. > > But I don't really see the point in wrapping atomically-accessed > variables in a struct. Preventing accidental naked access (to be reported in patch review as "wardrobe malfunction"). > Are we going to add a variant for long, a > variant for pointers, etc.? template ...; > I already proposed my version of this at > http://github.com/bonzini/qemu/commit/1b439343. Atomic operations are sufficiently rare and sufficiently important to warrant extra effort, so I prefer the explicitly typed variants. -- error compiling committee.c: too many arguments to function