From patchwork Sat Jun 18 04:03:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pranith Kumar X-Patchwork-Id: 9185391 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 A22E2601C0 for ; Sat, 18 Jun 2016 04:05:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FE6427E33 for ; Sat, 18 Jun 2016 04:05:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 724E92835D; Sat, 18 Jun 2016 04:05:57 +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 5876E27E33 for ; Sat, 18 Jun 2016 04:05:56 +0000 (UTC) Received: from localhost ([::1]:32962 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bE7W7-0003cJ-GV for patchwork-qemu-devel@patchwork.kernel.org; Sat, 18 Jun 2016 00:05:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46291) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bE7Vd-0003cD-NE for qemu-devel@nongnu.org; Sat, 18 Jun 2016 00:05:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bE7Va-0005Jl-Do for qemu-devel@nongnu.org; Sat, 18 Jun 2016 00:05:25 -0400 Received: from mail-yw0-x243.google.com ([2607:f8b0:4002:c05::243]:35296) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bE7Va-0005Jh-89 for qemu-devel@nongnu.org; Sat, 18 Jun 2016 00:05:22 -0400 Received: by mail-yw0-x243.google.com with SMTP id z186so277128ywd.2 for ; Fri, 17 Jun 2016 21:05:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=s9UojQ2QJpIew95vcjLPkAqUyOFUdQniHq/L8uVTyO4=; b=L3ZuVgaE6g6CrMeRENNWiA/evocgLka0JmN5NTnAlrDx6B2zq0aj6qs36zgWiTMXw8 8v4YvOl/t+wnIWrjJHrVi8VOPreL9lL3Q5XzG+3assGE5M/rb8Jz/ufdzhoJeTSWuoA1 gaWLd++gUBNyUSWyAV4nfFG99c9rTdHYEC/T6G9lm/xyExOu+vZaKeMZel0VTt+Bcdt2 96jy7iqBkO8/J++KwSqWBQ1qbxV8HE/ckl/QA6uILZ0pOS45gi2Cg2K2ydhb/OEHi0fF aqnfD2GagqHVjP8nGXZOJ6YnOHcLagOes1/Ukdz275PDSzCtFlqHqnPNvPhisa28YA0r pfxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=s9UojQ2QJpIew95vcjLPkAqUyOFUdQniHq/L8uVTyO4=; b=fYmBOI79sWJutMdT7ga7hg8kAHPQzaIoIAtbdPcdnIIkLzFdn9L/zkwhRsFuDTIbMN wf1GjAzERk4T8QGtnUvKvAdTr7kdWVIrn1C/N6clMNlODjnckkq7VKIOd1ModQ3vv+fS EBf92bqh7cPWQih/BWH27Y867II+mSN4yexC5p59157ly4C+49etFHv8nSbnPypb5pn4 KhRhqka+TYbPZ/j0XsG3+KSUyNef1edidmEF06kp/sDAofjbSedMLL7DYnsmUP7YLNBr AXulvEVms8GQamiVT0Jk9mUIccTDAhVIw3MU9lc4lRwk8TBI4AjGHLaf1QxFkrOe6ezZ 0Vhw== X-Gm-Message-State: ALyK8tLOvB808b2Nexh663lNWMBwnOSPkyu+nv1FBjYsXg6r6yBlB1QViLPP2dCf1igoIA== X-Received: by 10.129.94.193 with SMTP id s184mr3340767ywb.71.1466222721371; Fri, 17 Jun 2016 21:05:21 -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 q7sm19517992ywg.16.2016.06.17.21.05.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 17 Jun 2016 21:05:20 -0700 (PDT) From: Pranith Kumar To: Richard Henderson , qemu-devel@nongnu.org (open list:All patches CC here) Date: Sat, 18 Jun 2016 00:03:30 -0400 Message-Id: <20160618040343.19517-2-bobby.prani@gmail.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160618040343.19517-1-bobby.prani@gmail.com> References: <20160618040343.19517-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::243 Subject: [Qemu-devel] [RFC v3 PATCH 01/14] Introduce TCGOpcode for memory barrier 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: serge.fdrv@gmail.com, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This commit introduces the TCGOpcode for memory barrier instruction. This opcode takes an argument which is the type of memory barrier which should be generated. Signed-off-by: Pranith Kumar Signed-off-by: Richard Henderson --- tcg/README | 17 +++++++++++++++++ tcg/tcg-op.c | 11 +++++++++++ tcg/tcg-op.h | 2 ++ tcg/tcg-opc.h | 2 ++ tcg/tcg.h | 14 ++++++++++++++ 5 files changed, 46 insertions(+) diff --git a/tcg/README b/tcg/README index ce8beba..1d48aa9 100644 --- a/tcg/README +++ b/tcg/README @@ -402,6 +402,23 @@ double-word product T0. The later is returned in two single-word outputs. Similar to mulu2, except the two inputs T1 and T2 are signed. +********* Memory Barrier support + +* mb <$arg> + +Generate a target memory barrier instruction to ensure memory ordering as being +enforced by a corresponding guest memory barrier instruction. The ordering +enforced by the backend may be stricter than the ordering required by the guest. +It cannot be weaker. This opcode takes a constant argument which is required to +generate the appropriate barrier instruction. The backend should take care to +emit the target barrier instruction only when necessary i.e., for SMP guests and +when MTTCG is enabled. + +The guest translators should generate this opcode for all guest instructions +which have ordering side effects. + +Please see docs/atomics.txt for more information on memory barriers. + ********* 64-bit guest on 32-bit host support The following opcodes are internal to TCG. Thus they are to be implemented by diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c index 54c0277..08f7858 100644 --- a/tcg/tcg-op.c +++ b/tcg/tcg-op.c @@ -39,6 +39,8 @@ extern TCGv_i32 TCGV_HIGH_link_error(TCGv_i64); #define TCGV_HIGH TCGV_HIGH_link_error #endif +extern int smp_cpus; + /* Note that this is optimized for sequential allocation during translate. Up to and including filling in the forward link immediately. We'll do proper termination of the end of the list after we finish translation. */ @@ -146,6 +148,15 @@ void tcg_gen_op6(TCGContext *ctx, TCGOpcode opc, TCGArg a1, TCGArg a2, tcg_emit_op(ctx, opc, pi); } +void tcg_gen_mb(TCGArg mb_type) +{ +#ifndef CONFIG_USER_ONLY + if (qemu_tcg_mttcg_enabled() && smp_cpus > 1) { + tcg_gen_op1(&tcg_ctx, INDEX_op_mb, mb_type); + } +#endif +} + /* 32 bit ops */ void tcg_gen_addi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2) diff --git a/tcg/tcg-op.h b/tcg/tcg-op.h index f217e80..41890cc 100644 --- a/tcg/tcg-op.h +++ b/tcg/tcg-op.h @@ -261,6 +261,8 @@ static inline void tcg_gen_br(TCGLabel *l) tcg_gen_op1(&tcg_ctx, INDEX_op_br, label_arg(l)); } +void tcg_gen_mb(TCGArg a); + /* Helper calls. */ /* 32 bit ops */ diff --git a/tcg/tcg-opc.h b/tcg/tcg-opc.h index 6d0410c..45528d2 100644 --- a/tcg/tcg-opc.h +++ b/tcg/tcg-opc.h @@ -42,6 +42,8 @@ DEF(br, 0, 0, 1, TCG_OPF_BB_END) # define IMPL64 TCG_OPF_64BIT #endif +DEF(mb, 0, 0, 1, 0) + DEF(mov_i32, 1, 1, 0, TCG_OPF_NOT_PRESENT) DEF(movi_i32, 1, 0, 1, TCG_OPF_NOT_PRESENT) DEF(setcond_i32, 1, 2, 1, 0) diff --git a/tcg/tcg.h b/tcg/tcg.h index db6a062..36feca9 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -408,6 +408,20 @@ static inline intptr_t QEMU_ARTIFICIAL GET_TCGV_PTR(TCGv_ptr t) #define TCG_CALL_DUMMY_TCGV MAKE_TCGV_I32(-1) #define TCG_CALL_DUMMY_ARG ((TCGArg)(-1)) +typedef enum { + TCG_MO_LD_LD = 1, + TCG_MO_ST_LD = 2, + TCG_MO_LD_ST = 4, + TCG_MO_ST_ST = 8, + TCG_MO_ALL = 0xF, // OR of all above +} TCGOrder; + +typedef enum { + TCG_BAR_ACQ = 32, + TCG_BAR_REL = 64, + TCG_BAR_SC = 128, +} TCGBar; + /* Conditions. Note that these are laid out for easy manipulation by the functions below: bit 0 is used for inverting;