From: "Alex Bennée" <alex.bennee@linaro.org>
To: Pranith Kumar <bobby.prani@gmail.com>
Cc: Richard Henderson <rth@twiddle.net>,
"open list:All patches CC here" <qemu-devel@nongnu.org>,
serge.fdrv@gmail.com
Subject: Re: [Qemu-devel] [RFC v3 PATCH 01/14] Introduce TCGOpcode for memory barrier
Date: Tue, 21 Jun 2016 19:04:15 +0100 [thread overview]
Message-ID: <87wpliquzk.fsf@linaro.org> (raw)
In-Reply-To: <20160618040343.19517-2-bobby.prani@gmail.com>
Pranith Kumar <bobby.prani@gmail.com> writes:
> 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 <bobby.prani@gmail.com>
> Signed-off-by: Richard Henderson <rth@twiddle.net>
> ---
> 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
> +}
> +
This introduces a dependency on MTTCG which maybe is best handled in
that patch series. I get the feeling we might be able to merge this
series before MTTCG as barriers are still required for user-mode. Maybe
something like this makes more sense to keep the patch series
independent for now:
void tcg_gen_mb(TCGArg mb_type)
{
#ifdef CONFIG_USER_ONLY
const bool emit_barriers = true;
#else
/* TODO: When MTTCG is available for system mode
* we will enable when qemu_tcg_mttcg_enabled() && smp_cpus > 1
*/
bool emit_barriers = false;
#endif
if (emit_barriers) {
tcg_gen_op1(&tcg_ctx, INDEX_op_mb, mb_type);
}
}
Maybe it is time to look at the user-mode memory model testers like:
http://diy.inria.fr/
Rich,
What do you think? Do you think the memory barrier stuff should be kept
independent so it can be merged once ready?
> /* 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;
I mentioned my confusing in another email about having separate enums here.
> +
> /* Conditions. Note that these are laid out for easy manipulation by
> the functions below:
> bit 0 is used for inverting;
--
Alex Bennée
next prev parent reply other threads:[~2016-06-21 18:04 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20160618040343.19517-1-bobby.prani@gmail.com>
2016-06-18 4:03 ` [Qemu-devel] [RFC v3 PATCH 01/14] Introduce TCGOpcode for memory barrier Pranith Kumar
2016-06-20 21:21 ` Sergey Fedorov
2016-06-21 14:52 ` Pranith Kumar
2016-06-21 15:09 ` Alex Bennée
2016-06-21 18:06 ` Pranith Kumar
2016-06-22 15:50 ` Sergey Fedorov
2016-06-21 7:30 ` Paolo Bonzini
2016-06-21 18:04 ` Alex Bennée [this message]
2016-06-21 18:09 ` Pranith Kumar
2016-06-21 18:23 ` Alex Bennée
2016-06-21 19:40 ` Richard Henderson
2016-06-18 4:03 ` [Qemu-devel] [RFC v3 PATCH 02/14] tcg/i386: Add support for fence Pranith Kumar
2016-06-21 7:24 ` Paolo Bonzini
2016-06-22 16:25 ` Alex Bennée
2016-06-22 16:49 ` Richard Henderson
2016-06-22 18:18 ` Alex Bennée
2016-06-18 4:03 ` [Qemu-devel] [RFC v3 PATCH 03/14] tcg/aarch64: " Pranith Kumar
2016-06-23 16:18 ` Alex Bennée
2016-06-23 16:50 ` Richard Henderson
2016-06-23 19:58 ` Alex Bennée
2016-06-18 4:03 ` [Qemu-devel] [RFC v3 PATCH 04/14] tcg/arm: " Pranith Kumar
2016-06-23 16:30 ` Alex Bennée
2016-06-23 16:49 ` Richard Henderson
2016-06-18 4:03 ` [Qemu-devel] [RFC v3 PATCH 05/14] tcg/ia64: " Pranith Kumar
2016-06-18 4:03 ` [Qemu-devel] [RFC v3 PATCH 06/14] tcg/mips: " Pranith Kumar
2016-06-18 4:03 ` [Qemu-devel] [RFC v3 PATCH 07/14] tcg/ppc: " Pranith Kumar
2016-06-22 19:50 ` Sergey Fedorov
2016-06-22 20:21 ` Richard Henderson
2016-06-22 20:27 ` Sergey Fedorov
2016-06-23 14:42 ` Sergey Fedorov
2016-06-18 4:03 ` [Qemu-devel] [RFC v3 PATCH 08/14] tcg/s390: " Pranith Kumar
2016-06-21 7:26 ` Paolo Bonzini
2016-06-18 4:03 ` [Qemu-devel] [RFC v3 PATCH 09/14] tcg/sparc: " Pranith Kumar
2016-06-22 19:56 ` Sergey Fedorov
2016-06-18 4:03 ` [Qemu-devel] [RFC v3 PATCH 10/14] tcg/tci: " Pranith Kumar
2016-06-22 19:57 ` Sergey Fedorov
2016-06-22 20:25 ` Richard Henderson
2016-06-22 20:28 ` Sergey Fedorov
2016-06-18 4:03 ` [Qemu-devel] [RFC v3 PATCH 11/14] target-arm: Generate fences in ARMv7 frontend Pranith Kumar
2016-06-18 4:03 ` [Qemu-devel] [RFC v3 PATCH 12/14] target-alpha: Generate fence op Pranith Kumar
2016-06-18 4:03 ` [Qemu-devel] [RFC v3 PATCH 13/14] aarch64: Generate fences for aarch64 Pranith Kumar
2016-06-24 16:17 ` Alex Bennée
2016-06-18 4:03 ` [Qemu-devel] [RFC v3 PATCH 14/14] target-i386: Generate fences for x86 Pranith Kumar
2016-06-18 5:48 ` Richard Henderson
2016-06-20 15:05 ` Pranith Kumar
2016-06-21 7:28 ` Paolo Bonzini
2016-06-21 15:57 ` Richard Henderson
2016-06-21 16:12 ` Paolo Bonzini
2016-06-21 16:23 ` Richard Henderson
2016-06-21 16:33 ` Paolo Bonzini
2016-06-21 17:28 ` Pranith Kumar
2016-06-21 17:54 ` Peter Maydell
2016-06-21 18:03 ` Pranith Kumar
2016-06-21 18:25 ` Alex Bennée
2016-06-22 11:18 ` Sergey Fedorov
2016-06-18 4:08 ` [Qemu-devel] [RFC v3 PATCH 00/14] tcg: Add fence gen support Pranith Kumar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wpliquzk.fsf@linaro.org \
--to=alex.bennee@linaro.org \
--cc=bobby.prani@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
--cc=serge.fdrv@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).