From: "Emilio G. Cota" <cota@braap.org>
To: Richard Henderson <rth@twiddle.net>
Cc: qemu-devel@nongnu.org, alex.bennee@linaro.org,
pbonzini@redhat.com, peter.maydell@linaro.org,
serge.fdrv@gmail.com
Subject: Re: [Qemu-devel] [PATCH v2 11/27] target-i386: emulate LOCK'ed cmpxchg using cmpxchg helpers
Date: Thu, 7 Jul 2016 23:19:29 -0400 [thread overview]
Message-ID: <20160708031929.GA4925@flamenco> (raw)
In-Reply-To: <20160708030817.GC28765@flamenco>
On Thu, Jul 07, 2016 at 23:08:17 -0400, Emilio G. Cota wrote:
> On Fri, Jul 01, 2016 at 10:04:37 -0700, Richard Henderson wrote:
> > From: "Emilio G. Cota" <cota@braap.org>
> >
> > The diff here is uglier than necessary. All this does is to turn
> >
> > FOO
> >
> > into:
> >
> > if (s->prefix & PREFIX_LOCK) {
> > BAR
> > } else {
> > FOO
> > }
> >
> > where FOO is the original implementation of an unlocked cmpxchg.
> >
> > [rth: Adjust unlocked cmpxchg to use movcond instead of branches.
> > Adjust helpers to use atomic helpers.]
> >
> > Signed-off-by: Emilio G. Cota <cota@braap.org>
> > Message-Id: <1467054136-10430-6-git-send-email-cota@braap.org>
> > Signed-off-by: Richard Henderson <rth@twiddle.net>
> > ---
> > target-i386/mem_helper.c | 96 ++++++++++++++++++++++++++++++++++++++----------
> > target-i386/translate.c | 87 +++++++++++++++++++++----------------------
> > 2 files changed, 120 insertions(+), 63 deletions(-)
> >
> > diff --git a/target-i386/mem_helper.c b/target-i386/mem_helper.c
> > index c2f4769..5c0558f 100644
> > --- a/target-i386/mem_helper.c
> > +++ b/target-i386/mem_helper.c
> > @@ -22,6 +22,8 @@
> > #include "exec/helper-proto.h"
> > #include "exec/exec-all.h"
> > #include "exec/cpu_ldst.h"
> > +#include "qemu/int128.h"
> > +#include "tcg.h"
> >
> > /* broken thread support */
> >
> > @@ -58,20 +60,39 @@ void helper_lock_init(void)
> >
> > void helper_cmpxchg8b(CPUX86State *env, target_ulong a0)
> > {
> > - uint64_t d;
> > + uintptr_t ra = GETPC();
> > + uint64_t oldv, cmpv, newv;
> > int eflags;
> >
> > eflags = cpu_cc_compute_all(env, CC_OP);
> > - d = cpu_ldq_data_ra(env, a0, GETPC());
> > - if (d == (((uint64_t)env->regs[R_EDX] << 32) | (uint32_t)env->regs[R_EAX])) {
> > - cpu_stq_data_ra(env, a0, ((uint64_t)env->regs[R_ECX] << 32)
> > - | (uint32_t)env->regs[R_EBX], GETPC());
> > - eflags |= CC_Z;
> > +
> > + cmpv = deposit64(env->regs[R_EAX], 32, 32, env->regs[R_EDX]);
> > + newv = deposit64(env->regs[R_EBX], 32, 32, env->regs[R_ECX]);
> > +
> > + if (parallel_cpus) {
>
> I think here we mean 'if (prefix_locked)', although prefix_locked isn't
> here. This is why in my original patch I defined two helpers ('locked'
> and 'unlocked'), otherwise we'll emulate cmpxchg atomically even when
> the LOCK prefix wasn't there. Not a big deal, but could hide bugs.
Correction to myself: we'd still need if (prefix_locked) for the whole
stop-the-world-and-do-non-atomically thing to work.
The concern that we might hide bugs by emulating non-locked cmpxchg
atomically persists. [ I wonder why one would ever use a non-locked
cmpxchg, though ]
E.
next prev parent reply other threads:[~2016-07-08 3:19 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-01 17:04 [Qemu-devel] [PATCH v2 00/27] cmpxchg-based emulation of atomics Richard Henderson
2016-07-01 17:04 ` [Qemu-devel] [PATCH v2 01/27] atomics: add atomic_xor Richard Henderson
2016-08-11 17:19 ` Alex Bennée
2016-07-01 17:04 ` [Qemu-devel] [PATCH v2 02/27] atomics: add atomic_op_fetch variants Richard Henderson
2016-08-11 17:20 ` Alex Bennée
2016-07-01 17:04 ` [Qemu-devel] [PATCH v2 03/27] exec: Avoid direct references to Int128 parts Richard Henderson
2016-07-01 17:04 ` [Qemu-devel] [PATCH v2 04/27] int128: Use __int128 if available Richard Henderson
2016-08-11 10:45 ` Alex Bennée
2016-08-25 19:09 ` [Qemu-devel] [PATCH] fixup! " Alex Bennée
2016-08-26 12:48 ` no-reply
2016-07-01 17:04 ` [Qemu-devel] [PATCH v2 06/27] int128: Use complex numbers if advisable Richard Henderson
2016-07-04 11:51 ` Paolo Bonzini
2016-07-04 12:07 ` Peter Maydell
2016-07-01 17:04 ` [Qemu-devel] [PATCH v2 07/27] tcg: Add EXCP_ATOMIC Richard Henderson
2016-09-08 8:38 ` Alex Bennée
2016-09-08 16:26 ` Richard Henderson
2016-07-01 17:04 ` [Qemu-devel] [PATCH v2 08/27] HACK: Always enable parallel_cpus Richard Henderson
2016-09-08 8:39 ` Alex Bennée
2016-09-08 16:22 ` Richard Henderson
2016-07-01 17:04 ` [Qemu-devel] [PATCH v2 09/27] tcg: Add atomic helpers Richard Henderson
2016-09-08 13:43 ` Alex Bennée
2016-09-08 16:08 ` Richard Henderson
2016-07-01 17:04 ` [Qemu-devel] [PATCH v2 10/27] tcg: Add atomic128 helpers Richard Henderson
2016-07-08 3:00 ` Emilio G. Cota
2016-07-08 5:26 ` Richard Henderson
2016-08-11 10:02 ` Alex Bennée
2016-07-01 17:04 ` [Qemu-devel] [PATCH v2 11/27] target-i386: emulate LOCK'ed cmpxchg using cmpxchg helpers Richard Henderson
2016-07-08 3:08 ` Emilio G. Cota
2016-07-08 3:19 ` Emilio G. Cota [this message]
2016-07-01 17:04 ` [Qemu-devel] [PATCH v2 12/27] target-i386: emulate LOCK'ed OP instructions using atomic helpers Richard Henderson
2016-07-01 17:04 ` [Qemu-devel] [PATCH v2 13/27] target-i386: emulate LOCK'ed INC using atomic helper Richard Henderson
2016-07-01 17:04 ` [Qemu-devel] [PATCH v2 14/27] target-i386: emulate LOCK'ed NOT " Richard Henderson
2016-07-01 17:04 ` [Qemu-devel] [PATCH v2 15/27] target-i386: emulate LOCK'ed NEG using cmpxchg helper Richard Henderson
2016-07-01 17:04 ` [Qemu-devel] [PATCH v2 16/27] target-i386: emulate LOCK'ed XADD using atomic helper Richard Henderson
2016-07-01 17:04 ` [Qemu-devel] [PATCH v2 17/27] target-i386: emulate LOCK'ed BTX ops using atomic helpers Richard Henderson
2016-07-01 17:04 ` [Qemu-devel] [PATCH v2 18/27] target-i386: emulate XCHG using atomic helper Richard Henderson
2016-07-01 17:04 ` [Qemu-devel] [PATCH v2 19/27] target-i386: remove helper_lock() Richard Henderson
2016-07-01 17:04 ` [Qemu-devel] [PATCH v2 20/27] tests: add atomic_add-bench Richard Henderson
2016-07-01 17:04 ` [Qemu-devel] [PATCH v2 21/27] target-arm: Rearrange aa32 load and store functions Richard Henderson
2016-07-01 17:04 ` [Qemu-devel] [PATCH v2 22/27] target-arm: emulate LL/SC using cmpxchg helpers Richard Henderson
2016-07-01 17:04 ` [Qemu-devel] [PATCH v2 23/27] target-arm: emulate SWP with atomic_xchg helper Richard Henderson
2016-07-01 17:04 ` [Qemu-devel] [PATCH v2 24/27] target-arm: emulate aarch64's LL/SC using cmpxchg helpers Richard Henderson
2016-07-08 3:34 ` Emilio G. Cota
2016-07-01 17:04 ` [Qemu-devel] [PATCH v2 25/27] linux-user: remove handling of ARM's EXCP_STREX Richard Henderson
2016-07-01 17:04 ` [Qemu-devel] [PATCH v2 26/27] linux-user: remove handling of aarch64's EXCP_STREX Richard Henderson
2016-07-01 17:04 ` [Qemu-devel] [PATCH v2 27/27] target-arm: remove EXCP_STREX + cpu_exclusive_{test, info} Richard Henderson
2016-07-01 17:23 ` [Qemu-devel] [PATCH v2 00/27] cmpxchg-based emulation of atomics Richard Henderson
2016-07-08 2:53 ` Emilio G. Cota
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=20160708031929.GA4925@flamenco \
--to=cota@braap.org \
--cc=alex.bennee@linaro.org \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--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).