From patchwork Mon Aug 29 17:17:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pranith Kumar X-Patchwork-Id: 9304177 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 87E866077C for ; Mon, 29 Aug 2016 17:17:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7674728789 for ; Mon, 29 Aug 2016 17:17:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6AE60287A0; Mon, 29 Aug 2016 17:17:28 +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 E45A628789 for ; Mon, 29 Aug 2016 17:17:27 +0000 (UTC) Received: from localhost ([::1]:44948 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beQBZ-0002mE-SV for patchwork-qemu-devel@patchwork.kernel.org; Mon, 29 Aug 2016 13:17:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42316) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beQBI-0002m8-IN for qemu-devel@nongnu.org; Mon, 29 Aug 2016 13:17:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1beQBE-0000s5-BP for qemu-devel@nongnu.org; Mon, 29 Aug 2016 13:17:07 -0400 Received: from mail-yb0-x244.google.com ([2607:f8b0:4002:c09::244]:34733) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beQBE-0000s0-2G for qemu-devel@nongnu.org; Mon, 29 Aug 2016 13:17:04 -0400 Received: by mail-yb0-x244.google.com with SMTP id g67so3639603ybi.1 for ; Mon, 29 Aug 2016 10:17:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=ctnBpOEjIzNXOudQh4uP54bqOKAoAFSbKF2DaSBWrF0=; b=lHVItueuhOOhdhFlgKGDpjRmTXOn75Z7sM2TR8CJgv699VYg+ec1SqtUmC2UeLA6qF mWJxzTQF6HNlZzdr4PA94vwaHaEt7ICtdezVIY2A6K/iU2xmFGTKekCwbNKQ0uLult8Z BZYyVxF0FBbJ+s4C7zKQm00PmKc3GlSvIjJo06PUQNN/tw/FZ5i5LI+vs5LmnBiNvHGN eONvvgPhvuF72OMZiUAlQaxKPeT1QmswthJGRcddImC/OiJHsiDUe4ChwU++XZ4ts/Q5 vaelvynhYNzFaW/ff2Jiex+xFY3aR1yhAXYDPh4DRcx+YVT3K/O7kFtD9Xc2yffqibHA 4I6w== 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; bh=ctnBpOEjIzNXOudQh4uP54bqOKAoAFSbKF2DaSBWrF0=; b=KOjofsylXizs1nbzeSI6aWvQ8F+utIvblRyPie4S0qtQGTBEZVO+WoEXnWDqVQMhPU iQX21CfESeEs9QFJPtCx7ZiwavAKvAHCZIEpoxlzIEgtOxQ2f6cgHh1+TmuYe3erGpBW fT0O9TVCbJ3FMFWqRuabdcczslTT6kk6DRSBKC9ArGz8FvBJHq9DGeqbdLq91io3uhiZ qA0K+stz8jzMQyWSe5alan8ve+OTzFJax24xW2sXlFPKApPLgwOb4Pskam5OMxOot3vR +QarJ+ciVuQurqIDCNMxTDMdLFRLj4pYxfv2uByVk7O9vFow+V5Usl3xgobbaNvfnoTX sXUQ== X-Gm-Message-State: AE9vXwPQnCCLtLqqvnB4bL0zEkYgpABW/sxu9mLJCvJ/hC3lVT4dx2WYgmI7Vfy2mQpGxA== X-Received: by 10.37.111.197 with SMTP id k188mr15669334ybc.122.1472491023366; Mon, 29 Aug 2016 10:17:03 -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 j189sm16894829ywc.32.2016.08.29.10.17.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 29 Aug 2016 10:17:02 -0700 (PDT) From: Pranith Kumar To: Paolo Bonzini , "Emilio G. Cota" , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , qemu-devel@nongnu.org (open list:All patches CC here) Date: Mon, 29 Aug 2016 13:17:01 -0400 Message-Id: <20160829171701.14025-1-bobby.prani@gmail.com> X-Mailer: git-send-email 2.9.3 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4002:c09::244 Subject: [Qemu-devel] [PATCH v2] 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 | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) v2: - convert atomic_load() and atomic_compare_exchange() diff --git a/include/qemu/atomic.h b/include/qemu/atomic.h index 43b0645..9bb991e 100644 --- a/include/qemu/atomic.h +++ b/include/qemu/atomic.h @@ -96,15 +96,12 @@ #define atomic_read(ptr) \ ({ \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ - typeof_strip_qual(*ptr) _val; \ - __atomic_load(ptr, &_val, __ATOMIC_RELAXED); \ - _val; \ + __atomic_load_n(ptr, __ATOMIC_RELAXED); \ }) #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 +126,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 +149,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 +164,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,17 +173,15 @@ #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 */ #define atomic_cmpxchg(ptr, old, new) \ ({ \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ - typeof_strip_qual(*ptr) _old = (old), _new = (new); \ - __atomic_compare_exchange(ptr, &_old, &_new, false, \ + typeof_strip_qual(*ptr) _old = (old); \ + __atomic_compare_exchange_n(ptr, &_old, new, false, \ __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); \ _old; \ })