From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42602) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uxg8u-0003JW-5z for qemu-devel@nongnu.org; Fri, 12 Jul 2013 12:24:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uxg8r-0003lF-Ow for qemu-devel@nongnu.org; Fri, 12 Jul 2013 12:24:24 -0400 Received: from mail-qc0-x22e.google.com ([2607:f8b0:400d:c01::22e]:59204) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uxg8r-0003l7-Lw for qemu-devel@nongnu.org; Fri, 12 Jul 2013 12:24:21 -0400 Received: by mail-qc0-f174.google.com with SMTP id m15so5046723qcq.19 for ; Fri, 12 Jul 2013 09:24:20 -0700 (PDT) Sender: Richard Henderson Message-ID: <51E02DAE.3040204@twiddle.net> Date: Fri, 12 Jul 2013 09:24:14 -0700 From: Richard Henderson MIME-Version: 1.0 References: <1373610771-11819-1-git-send-email-pingfank@linux.vnet.ibm.com> In-Reply-To: <1373610771-11819-1-git-send-email-pingfank@linux.vnet.ibm.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] atomic: using memory_order_relaxed for refcnt inc/dec ops List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Liu Ping Fan Cc: Paolo Bonzini , qemu-devel@nongnu.org On 07/11/2013 11:32 PM, Liu Ping Fan wrote: > Refcnt's atomic inc/dec ops are frequent and its idiom need no seq_cst > order. So to get better performance, it worth to adopt _relaxed > other than _seq_cst memory model on them. You'd need to update the documentation then. As it stands, what you've written looks like a bug. > +#ifndef _GLIBCXX_ATOMIC_BUILTINS This will never be defined. It's private to the libstdc++ implementation. See how we've defined things using __atomic elsewhere in the file, looking at one of the __ATOMIC defines. And in either case, it's better form to use positive tests than negative ones. I.e. #ifdef rather than #ifndef > #define atomic_fetch_inc(ptr) __sync_fetch_and_add(ptr, 1) > #define atomic_fetch_dec(ptr) __sync_fetch_and_add(ptr, -1) I'd prefer atomic_fetch_inc_relaxed, as that's more self-documenting. But I'll re-iterate the necessity of documentation in this area. r~