From patchwork Sat May 14 03:34:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 9094541 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CF9369F1C3 for ; Sat, 14 May 2016 03:38:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2582020148 for ; Sat, 14 May 2016 03:38:59 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 725D120114 for ; Sat, 14 May 2016 03:38:58 +0000 (UTC) Received: from localhost ([::1]:36562 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1QPp-0002N5-NO for patchwork-qemu-devel@patchwork.kernel.org; Fri, 13 May 2016 23:38:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46903) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1QM4-0002um-Bo for qemu-devel@nongnu.org; Fri, 13 May 2016 23:35:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b1QLy-0005Ki-VG for qemu-devel@nongnu.org; Fri, 13 May 2016 23:35:04 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:39542) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1QLw-0005JW-N7 for qemu-devel@nongnu.org; Fri, 13 May 2016 23:34:58 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id C496D20B88 for ; Fri, 13 May 2016 23:34:41 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Fri, 13 May 2016 23:34:41 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-sasl-enc:x-sasl-enc; s=mesmtp; bh=nhd03tHOPOUTILchaocjMNwf3ps =; b=2mWHJEgi3acR/49QchWNJ793KtszY/lmP6yLOUXh8pEqoNK1LolW2K1ECKK iLmKPD/Nc7486PTS5LHsjQR3YnbyqfDwc8P6rA8mCX5PSn1zL5BPukI3+i1XWdjH J5XmYnNNY5/MY2oRfEhPiMaHcKyUf3O91MHMSY/sIsuznido= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=nhd0 3tHOPOUTILchaocjMNwf3ps=; b=OV5kp1JV+uTnZ31G2dvCorIhRdZtctpmpSCA 04/AwgrQS2Mai6hSGdLHai5k4wkFt7zdzga25w8jNEUIownWXdw/acaP3mA2ePCm eiGI8tCt+h+lAS/dNk8EXmyG1dKGFc/MJ2p5WlLCISooJo1hiKqhMykUdiNhbCSx bldoeYk= X-Sasl-enc: xecwyg1qwqWF5YsY6m0cUF4QSI6zcjWW7aJERW0rkPAx 1463196881 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 766F66800EA; Fri, 13 May 2016 23:34:41 -0400 (EDT) From: "Emilio G. Cota" To: QEMU Developers , MTTCG Devel Date: Fri, 13 May 2016 23:34:21 -0400 Message-Id: <1463196873-17737-7-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1463196873-17737-1-git-send-email-cota@braap.org> References: <1463196873-17737-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.29 Subject: [Qemu-devel] [PATCH v5 06/18] atomics: add atomic_read_acquire and atomic_set_release X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Sergey Fedorov , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Peter Crosthwaite Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When __atomic is not available, we use full memory barriers instead of smp/wmb, since acquire/release barriers apply to all memory operations and not just to loads/stores, respectively. Signed-off-by: Emilio G. Cota Reviewed-by: Pranith Kumar --- include/qemu/atomic.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/include/qemu/atomic.h b/include/qemu/atomic.h index 6061a46..1766c22 100644 --- a/include/qemu/atomic.h +++ b/include/qemu/atomic.h @@ -56,6 +56,21 @@ __atomic_store(ptr, &_val, __ATOMIC_RELAXED); \ } while(0) +/* atomic read/set with acquire/release barrier */ +#define atomic_read_acquire(ptr) \ + ({ \ + QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ + typeof(*ptr) _val; \ + __atomic_load(ptr, &_val, __ATOMIC_ACQUIRE); \ + _val; \ + }) + +#define atomic_set_release(ptr, i) do { \ + QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ + typeof(*ptr) _val = (i); \ + __atomic_store(ptr, &_val, __ATOMIC_RELEASE); \ +} while(0) + /* Atomic RCU operations imply weak memory barriers */ #define atomic_rcu_read(ptr) \ @@ -243,6 +258,18 @@ #define atomic_read(ptr) (*(__typeof__(*ptr) volatile*) (ptr)) #define atomic_set(ptr, i) ((*(__typeof__(*ptr) volatile*) (ptr)) = (i)) +/* atomic read/set with acquire/release barrier */ +#define atomic_read_acquire(ptr) ({ \ + typeof(*ptr) _val = atomic_read(ptr); \ + smp_mb(); \ + _val; \ +}) + +#define atomic_set_release(ptr, i) do { \ + smp_mb(); \ + atomic_set(ptr, i); \ +} while (0) + /** * atomic_rcu_read - reads a RCU-protected pointer to a local variable * into a RCU read-side critical section. The pointer can later be safely