From: Paolo Bonzini <pbonzini@redhat.com>
To: Alvise Rigo <a.rigo@virtualopensystems.com>,
qemu-devel@nongnu.org, mttcg@greensocs.com
Cc: alex.bennee@linaro.org, jani.kokkonen@huawei.com,
tech@virtualopensystems.com, claudio.fontana@huawei.com,
"Emilio G. Cota" <cota@braap.org>
Subject: Re: [Qemu-devel] [RFC v5 0/6] Slow-path for atomic instruction translation
Date: Wed, 30 Sep 2015 06:44:32 +0200 [thread overview]
Message-ID: <560B68B0.1080702@redhat.com> (raw)
In-Reply-To: <1443083566-10994-1-git-send-email-a.rigo@virtualopensystems.com>
On 24/09/2015 10:32, Alvise Rigo wrote:
> The implementation heavily uses the software TLB together with a new
> bitmap that has been added to the ram_list structure which flags, on a
> per-CPU basis, all the memory pages that are in the middle of a LoadLink
> (LL), StoreConditional (SC) operation. Since all these pages can be
> accessed directly through the fast-path and alter a vCPU's linked value,
> the new bitmap has been coupled with a new TLB flag for the TLB virtual
> address which forces the slow-path execution for all the accesses to a
> page containing a linked address.
Alvise, Emilio,
I have a doubt about your patches for ll/sc emulation, that I hope you
can clarify.
>From 10000ft, both approaches rely on checking a flag during stores.
This is split between the TLB and the CPUState for Alvise's patches (in
order to exploit the existing fast-path checks), and entirely in the
radix tree for Emilio's. However, the idea is the same.
Now, the patch are okay for serial emulation, but I am not sure if it's
possible to do lock-free ll/sc emulation, because there is a race.
If we check the flag before the store, the race is as follows:
CPU0 CPU1
-------------------------------------------------------
check flag
load locked:
set flag
load value (normal load on CPU)
store
store conditional (normal store on CPU)
where the sc doesn't fail. For completeness, if we check it afterwards
(which would be possible with Emilio's approach, though not for the
TLB-based one):
CPU0 CPU1
------------------------------------------------------
load locked
set bit
load value (normal load on CPU)
store
store conditional (normal store on CPU)
check flag
and again the sc doesn't fail.
Most solutions I can think of are impractical:
- hardware ll/sc in CPU1. x86 doesn't have it.
- hardware transactional memory in CPU0, checking the bit after the
store and abort the transaction (I think). HTM just doesn't exist.
- some kind of store-in-progress (SIP) flag that ll can test and force
failure of the corresponding sc. For example, each CPU could store a
(last_store_address, last_store_value) tuple. If the value that LL loads
disagrees with any CPU, the LL would direct the SC to fail. A store
would look like:
store value to last_store_value
smp_wmb()
store address to last_store_address
smp_mb()
load TLB or radix tree
The memory barrier orders the store to the SIP flag and the load from
the TLB, and is probably too expensive. :(
- some array of atomic global generation counts, incremented
unconditionally on every store and checked between ll and sc. Cacheline
bounce fiesta, hence extremely slow. :(
Tell me I'm wrong. :)
If I'm right, we can still keep the opcodes and implement them with a
simple cmpxchg. It would provide a nice generic tool to implement
atomic operations, and it will work correctly if the target has ll/sc.
However, ll/sc-on-cmpxchg (e.g., ARM-on-x86) would be susceptible to the
ABA problem.
Paolo
next prev parent reply other threads:[~2015-09-30 4:44 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-24 8:32 [Qemu-devel] [RFC v5 0/6] Slow-path for atomic instruction translation Alvise Rigo
2015-09-24 8:32 ` [Qemu-devel] [RFC v5 1/6] exec.c: Add new exclusive bitmap to ram_list Alvise Rigo
2015-09-26 17:15 ` Richard Henderson
2015-09-28 7:28 ` alvise rigo
2015-09-24 8:32 ` [Qemu-devel] [RFC v5 2/6] softmmu: Add new TLB_EXCL flag Alvise Rigo
2015-09-30 3:34 ` Richard Henderson
2015-09-30 9:24 ` alvise rigo
2015-09-30 11:09 ` Peter Maydell
2015-09-30 12:44 ` alvise rigo
2015-09-30 20:37 ` Richard Henderson
2015-09-24 8:32 ` [Qemu-devel] [RFC v5 3/6] softmmu: Add helpers for a new slowpath Alvise Rigo
2015-09-30 3:58 ` Richard Henderson
2015-09-30 9:46 ` alvise rigo
2015-09-30 20:42 ` Richard Henderson
2015-10-01 8:05 ` alvise rigo
2015-10-01 19:34 ` Richard Henderson
2015-09-24 8:32 ` [Qemu-devel] [RFC v5 4/6] target-arm: Create new runtime helpers for excl accesses Alvise Rigo
2015-09-30 4:03 ` Richard Henderson
2015-09-30 10:16 ` alvise rigo
2015-09-24 8:32 ` [Qemu-devel] [RFC v5 5/6] configure: Use slow-path for atomic only when the softmmu is enabled Alvise Rigo
2015-09-30 4:05 ` Richard Henderson
2015-09-30 9:51 ` alvise rigo
2015-09-24 8:32 ` [Qemu-devel] [RFC v5 6/6] target-arm: translate: Use ld/st excl for atomic insns Alvise Rigo
2015-09-30 4:44 ` Paolo Bonzini [this message]
2015-09-30 8:14 ` [Qemu-devel] [RFC v5 0/6] Slow-path for atomic instruction translation alvise rigo
2015-09-30 13:20 ` Paolo Bonzini
2015-10-01 19:32 ` 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=560B68B0.1080702@redhat.com \
--to=pbonzini@redhat.com \
--cc=a.rigo@virtualopensystems.com \
--cc=alex.bennee@linaro.org \
--cc=claudio.fontana@huawei.com \
--cc=cota@braap.org \
--cc=jani.kokkonen@huawei.com \
--cc=mttcg@greensocs.com \
--cc=qemu-devel@nongnu.org \
--cc=tech@virtualopensystems.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).