From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Maydell Subject: Re: [Qemu-devel] [PATCH 01/15] atomic: introduce atomic operations Date: Wed, 8 Aug 2012 10:21:41 +0100 Message-ID: References: <1344407156-25562-1-git-send-email-qemulist@gmail.com> <1344407156-25562-2-git-send-email-qemulist@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Stefan Hajnoczi , Marcelo Tosatti , Blue Swirl , Avi Kivity , Anthony Liguori , Jan Kiszka , Paolo Bonzini , =?UTF-8?Q?Andreas_F=C3=A4rber?= To: Liu Ping Fan Return-path: Received: from mail-gg0-f174.google.com ([209.85.161.174]:52595 "EHLO mail-gg0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752505Ab2HHJVm (ORCPT ); Wed, 8 Aug 2012 05:21:42 -0400 Received: by ggnl2 with SMTP id l2so514908ggn.19 for ; Wed, 08 Aug 2012 02:21:41 -0700 (PDT) In-Reply-To: <1344407156-25562-2-git-send-email-qemulist@gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: On 8 August 2012 07:25, Liu Ping Fan wrote: > +static inline void atomic_sub(int i, Atomic *v) > +{ > + asm volatile("lock; subl %1,%0" > + : "+m" (v->counter) > + : "ir" (i)); > +} NAK. We don't want random inline assembly implementations of locking primitives in QEMU, they are way too hard to keep working with all the possible host architectures we support. I spent some time a while back getting rid of the (variously busted) versions we had previously. If you absolutely must use atomic ops, use the gcc builtins. For preference, stick to higher level and less error-prone abstractions. -- PMM From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:55662) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sz2SY-0005O9-BS for qemu-devel@nongnu.org; Wed, 08 Aug 2012 05:21:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sz2SU-0004v9-82 for qemu-devel@nongnu.org; Wed, 08 Aug 2012 05:21:46 -0400 Received: from mail-yx0-f173.google.com ([209.85.213.173]:63080) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sz2SU-0004v3-4I for qemu-devel@nongnu.org; Wed, 08 Aug 2012 05:21:42 -0400 Received: by yenm4 with SMTP id m4so505295yen.4 for ; Wed, 08 Aug 2012 02:21:41 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <1344407156-25562-2-git-send-email-qemulist@gmail.com> References: <1344407156-25562-1-git-send-email-qemulist@gmail.com> <1344407156-25562-2-git-send-email-qemulist@gmail.com> Date: Wed, 8 Aug 2012 10:21:41 +0100 Message-ID: From: Peter Maydell Content-Type: text/plain; charset=UTF-8 Subject: Re: [Qemu-devel] [PATCH 01/15] atomic: introduce atomic operations List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Liu Ping Fan Cc: kvm@vger.kernel.org, Stefan Hajnoczi , Marcelo Tosatti , qemu-devel@nongnu.org, Blue Swirl , Avi Kivity , Anthony Liguori , Jan Kiszka , Paolo Bonzini , =?UTF-8?Q?Andreas_F=C3=A4rber?= On 8 August 2012 07:25, Liu Ping Fan wrote: > +static inline void atomic_sub(int i, Atomic *v) > +{ > + asm volatile("lock; subl %1,%0" > + : "+m" (v->counter) > + : "ir" (i)); > +} NAK. We don't want random inline assembly implementations of locking primitives in QEMU, they are way too hard to keep working with all the possible host architectures we support. I spent some time a while back getting rid of the (variously busted) versions we had previously. If you absolutely must use atomic ops, use the gcc builtins. For preference, stick to higher level and less error-prone abstractions. -- PMM