From patchwork Wed Aug 24 20:44:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pranith Kumar X-Patchwork-Id: 9298321 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5E7DE607F0 for ; Wed, 24 Aug 2016 20:47:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50BBC2911C for ; Wed, 24 Aug 2016 20:47:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 452AC2911E; Wed, 24 Aug 2016 20:47:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id E3A0F2911C for ; Wed, 24 Aug 2016 20:46:59 +0000 (UTC) Received: from localhost ([::1]:53299 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcf4d-0003MU-3S for patchwork-qemu-devel@patchwork.kernel.org; Wed, 24 Aug 2016 16:46:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcf2L-00021l-Pu for qemu-devel@nongnu.org; Wed, 24 Aug 2016 16:44:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bcf2K-0004TO-Qo for qemu-devel@nongnu.org; Wed, 24 Aug 2016 16:44:37 -0400 Received: from mail-yw0-x244.google.com ([2607:f8b0:4002:c05::244]:36492) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcf2K-0004TI-MO for qemu-devel@nongnu.org; Wed, 24 Aug 2016 16:44:36 -0400 Received: by mail-yw0-x244.google.com with SMTP id u134so1410868ywg.3 for ; Wed, 24 Aug 2016 13:44:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:in-reply-to:references; bh=lBF3HyrXtQntKdxx93ROJ2IInmnbdbkWeMO3F1HFUr0=; b=jCkex2UlATsFpavARpuqOHhTcA7SnfM7Mhi378ugVOnsQZDIPLuNSTR/SP6xMeu5L0 Wt6qVTuhuKZdmFAmfj0AxbQ7DweOdBSSJOjt7IF63KTSVKk1H/WDSh7kQBe4yuQlFNbJ xdFxroBZHFQRicVrmF29DnlEKB8LucpHkdkscRk1m1aXumR1m2G0ZFSrwfm8SYpB5N6z GHqvEHBsmZrCXjI28rxIHThX9kHtfdJNpymieziXTa/NA+gJJO1XmXnou+OjajvSyZFY 9f5BdZ6/5fjF2JHMGUX8t3couh9Xtd2I50mr6o21KiuQ4LS9O5upnze/aJ19zM0wVWIp 3XIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=lBF3HyrXtQntKdxx93ROJ2IInmnbdbkWeMO3F1HFUr0=; b=l9KWe4EbKwTXNYuOipXGPlIWPYbUKvUcDr7jwqF8oddQ1ePiVbZlB+sP+eYCs9o5/V 3HPhxg4fZEdta1L7zfHso3E62JtAYq3R+2I91XFQc4f8PwN4J8H8BNoaLREOaad94uWy Rt+8WZS0/1LS3puQUA07QCGzv7J7LUEh6HFNXDiWgkf+CX1ivH1KQaBtP3C84ZxAqP9o kI3pFNB82nd/3XA4b2HHhvOHCEQuQoDELZVYUY7h8459+h+qVctXQ2GUNXjSMRfJzdVg vwAOiVqd144/OH8TXzlxljczs+NkjofXJrUqBg5J+X4FSqGep1XQ5CH/p5LOx6UmelSv Dl1Q== X-Gm-Message-State: AE9vXwPoxCNtLgKDAbj3SFcBPQfiJQBpG4FJ9FOJYd1DPnLrsMe0UNBfhgAz/GnbEMT18A== X-Received: by 10.129.152.142 with SMTP id p136mr4282919ywg.207.1472071476097; Wed, 24 Aug 2016 13:44:36 -0700 (PDT) Received: from evgadesktop.attlocal.net (108-232-152-155.lightspeed.tukrga.sbcglobal.net. [108.232.152.155]) by smtp.gmail.com with ESMTPSA id l81sm6276520ywb.56.2016.08.24.13.44.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 24 Aug 2016 13:44:33 -0700 (PDT) From: Pranith Kumar To: qemu-devel@nongnu.org, Paolo Bonzini , "Emilio G. Cota" , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Peter Maydell , Richard Henderson Date: Wed, 24 Aug 2016 16:44:22 -0400 Message-Id: <20160824204424.14041-2-bobby.prani@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20160824204424.14041-1-bobby.prani@gmail.com> References: <20160824204424.14041-1-bobby.prani@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4002:c05::244 Subject: [Qemu-devel] [PATCH 2/3] atomics: Use __atomic_*_n() variant primitives 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: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Use the __atomic_*_n() primitives which take the value as argument. It is not necessary to store the value locally before calling the primitive, hence saving us a stack store and load. Signed-off-by: Pranith Kumar --- include/qemu/atomic.h | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/include/qemu/atomic.h b/include/qemu/atomic.h index d313e6b..fc2309f 100644 --- a/include/qemu/atomic.h +++ b/include/qemu/atomic.h @@ -103,8 +103,7 @@ #define atomic_set(ptr, i) do { \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ - typeof(*ptr) _val = (i); \ - __atomic_store(ptr, &_val, __ATOMIC_RELAXED); \ + __atomic_store_n(ptr, i, __ATOMIC_RELAXED); \ } while(0) /* See above: most compilers currently treat consume and acquire the @@ -129,8 +128,7 @@ #define atomic_rcu_set(ptr, i) do { \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ - typeof(*ptr) _val = (i); \ - __atomic_store(ptr, &_val, __ATOMIC_RELEASE); \ + __atomic_store_n(ptr, i, __ATOMIC_RELEASE); \ } while(0) /* atomic_mb_read/set semantics map Java volatile variables. They are @@ -153,9 +151,8 @@ #define atomic_mb_set(ptr, i) do { \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ - typeof(*ptr) _val = (i); \ smp_wmb(); \ - __atomic_store(ptr, &_val, __ATOMIC_RELAXED); \ + __atomic_store_n(ptr, i, __ATOMIC_RELAXED); \ smp_mb(); \ } while(0) #else @@ -169,8 +166,7 @@ #define atomic_mb_set(ptr, i) do { \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ - typeof(*ptr) _val = (i); \ - __atomic_store(ptr, &_val, __ATOMIC_SEQ_CST); \ + __atomic_store_n(ptr, i, __ATOMIC_SEQ_CST); \ } while(0) #endif @@ -179,9 +175,7 @@ #define atomic_xchg(ptr, i) ({ \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ - typeof_strip_qual(*ptr) _new = (i), _old; \ - __atomic_exchange(ptr, &_new, &_old, __ATOMIC_SEQ_CST); \ - _old; \ + __atomic_exchange_n(ptr, i, __ATOMIC_SEQ_CST); \ }) /* Returns the eventual value, failed or not */