From: Paolo Bonzini <pbonzini@redhat.com>
To: "Alex Bennée" <alex.bennee@linaro.org>
Cc: mttcg@greensocs.com, peter.maydell@linaro.org,
mark.burton@greensocs.com, a.rigo@virtualopensystems.com,
qemu-devel@nongnu.org, fred.konrad@greensocs.com
Subject: Re: [Qemu-devel] [RFC PATCH 3/4] include/qemu/atomic.h: default to __atomic functions
Date: Mon, 25 Jan 2016 23:02:59 +0100 [thread overview]
Message-ID: <56A69B93.4030500@redhat.com> (raw)
In-Reply-To: <87twm1o6w1.fsf@linaro.org>
On 25/01/2016 19:23, Alex Bennée wrote:
>>> + })
>>> +
>>> +#define atomic_mb_set(ptr, i) ((void)atomic_xchg(ptr, i))
>>> +#define atomic_mb_read(ptr) \
>>> + ({ \
>>> + typeof(*ptr) _val; \
>>> + __atomic_load(ptr, &_val, __ATOMIC_ACQUIRE); \
>>> + _val; \
>>> + })
>>
>> Please leave these defined in terms of relaxed accesses and memory
>> barriers.
>
> May I ask why? Doesn't the __ATOMIC_ACQUIRE ensure the load barrier is
> in place? Or should it be a fill CST barrier?
First, because they are defined like this in docs/atomics.txt. :)
Second, because the right definition would be
__atomic_load(__ATOMIC_SEQ_CST) and __atomic_store(__ATOMIC_SEQ_CST).
These produce even better code than the memory barriers on x86 but,
unfortunately, on POWER they are implemented in such a way that make
things very slow.
Basically, instead of
mb_read -> load; rmb()
mb_set -> wmb(); store(); mb()
POWER uses this:
mb_read -> load; mb()
mb_set -> wmb(); store(); mb()
There are reasons for these, and they are proved in
http://www.cl.cam.ac.uk/~pes20/cppppc/popl079-batty.pdf (I'm not
pretending I understand this paper except inasmuch as it was necessary
to write docs/atomics.txt). However, the cases that actually matter
basically never arise. Again, this is documented in docs/atomics.txt
around line 90.
As an alternative to explicit memory barriers, you can use this on POWER:
mb_read -> load-acquire
mb_set -> store-release + mb()
and seq-cst load/store everywhere else.
Paolo
next prev parent reply other threads:[~2016-01-25 22:03 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-25 16:49 [Qemu-devel] [RFC PATCH 0/4] ThreadSanitizer support Alex Bennée
2016-01-25 16:49 ` [Qemu-devel] [RFC PATCH 1/4] configure: move EXTRA_CFLAGS append to the end Alex Bennée
2016-01-25 17:04 ` Peter Maydell
2016-01-25 17:37 ` Peter Maydell
2016-01-25 16:49 ` [Qemu-devel] [RFC PATCH 2/4] configure: introduce --extra-libs Alex Bennée
2016-01-25 17:08 ` Peter Maydell
2016-01-25 17:25 ` Alex Bennée
2016-01-25 17:36 ` Peter Maydell
2016-01-25 17:58 ` Paolo Bonzini
2016-01-25 18:15 ` Alex Bennée
2016-01-25 22:10 ` Paolo Bonzini
2016-01-26 8:43 ` Alex Bennée
2016-01-25 16:49 ` [Qemu-devel] [RFC PATCH 3/4] include/qemu/atomic.h: default to __atomic functions Alex Bennée
2016-01-25 18:04 ` Paolo Bonzini
2016-01-25 18:23 ` Alex Bennée
2016-01-25 22:02 ` Paolo Bonzini [this message]
2016-01-25 16:49 ` [Qemu-devel] [RFC PATCH 4/4] tsan: various fixes for make check Alex Bennée
2016-01-25 18:09 ` Paolo Bonzini
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=56A69B93.4030500@redhat.com \
--to=pbonzini@redhat.com \
--cc=a.rigo@virtualopensystems.com \
--cc=alex.bennee@linaro.org \
--cc=fred.konrad@greensocs.com \
--cc=mark.burton@greensocs.com \
--cc=mttcg@greensocs.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.