From: Paolo Bonzini <pbonzini@redhat.com>
To: Pranith Kumar <bobby.prani@gmail.com>
Cc: mttcg@greensocs.com, "Peter Maydell" <peter.maydell@linaro.org>,
"Mark Burton" <mark.burton@greensocs.com>,
"alvise rigo" <a.rigo@virtualopensystems.com>,
qemu-devel <qemu-devel@nongnu.org>,
stefanha@redhat.com, "Alex Bennée" <alex.bennee@linaro.org>,
"KONRAD Frédéric" <fred.konrad@greensocs.com>
Subject: Re: [Qemu-devel] [PATCH v1 3/5] include/qemu/atomic.h: default to __atomic functions
Date: Mon, 4 Apr 2016 19:03:48 +0200 [thread overview]
Message-ID: <57029E74.8070509@redhat.com> (raw)
In-Reply-To: <CAJhHMCA1NZiUvKaUpb5SSXOnLe+a507xmAf9Kuym3i7MVuKcHw@mail.gmail.com>
On 04/04/2016 18:26, Pranith Kumar wrote:
> Hi Paolo,
>
> On Mon, Apr 4, 2016 at 4:14 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>>
>> The issue is that atomic_thread_fence() only affects other atomic
>> operations, while smp_rmb() and smp_wmb() affect normal loads and stores
>> as well.
>
> That is different from what I understand what atomic_thread_fence()
> does. AFAIK, it should order all loads/stores and not only atomic
> operations.
>
> Quoting http://www.inf.pucrs.br/~flash/progeng2/cppreference/w/cpp/atomic/atomic_thread_fencehtml.html:
>
> "Establishes memory synchronization ordering of non-atomic and relaxed
> atomic accesses"
You can find some information at
https://bugzilla.redhat.com/show_bug.cgi?id=1142857 and
https://retrace.fedoraproject.org/faf/problems/670281/.
I've looked at private email from that time and I was pointed to this
sentence in GCC's manual, which says the opposite:
"Note that in the C++11 memory model, fences (e.g.,
‘__atomic_thread_fence’) take effect in combination with other
atomic operations on specific memory locations (e.g., atomic loads);
operations on specific memory locations do not necessarily affect
other operations in the same way."
Basically, the __atomic fences are essentially a way to break up a
non-relaxed atomic access into a relaxed atomic access and the
ordering-constraining fence. According to those emails, atomic
load-acquires and store-releases can provide synchronization for plain
loads and stores (not just for relaxed atomic loads and stores).
However, an atomic thread fence cannot do this.
>> In the GCC implementation, atomic operations (even relaxed ones) access
>> memory as if the pointer was volatile. By doing this, GCC can remove
>> the acquire and release fences altogether on TSO architectures. We
>> actually observed a case where the compiler subsequently inverted the
>> order of two writes around a smp_wmb().
>
> That is a GCC bug in that case. GCC should remove smp_wmb() only after
> the optimization passes have run in the codegen phase. Can you please
> point me to the mailing list thread/bug where this was discovered? Or
> is it easily reproducible with reverting that patch? In that case, the
> location of the bug will be helpful to analyse this further.
It depends on the compiler you're using. With some luck, reverting the
patch will cause accesses across smp_wmb() or smp_rmb() to get
reordered. In our case it was in thread-pool.c; Kevin Wolf did the
analysis.
>> In principle it could do the same on architectures that are sequentially
>> consistent; even if none exists in practice, keeping the barriers for
>> smp_mb() is consistent with the other barriers.
>
> I understand one barrier(), but having two on both sides seems
> unnecessary. I would prefer we clean up and have just one. Although, I
> think it is just an annoyance since performance wise there is no
> difference. Two consecutive barrier()'s should behave just like one.
Yes, this is okay to change.
Paolo
next prev parent reply other threads:[~2016-04-04 17:03 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-28 10:15 [Qemu-devel] [PATCH v1 0/5] ThreadSanitizer support Alex Bennée
2016-01-28 10:15 ` [Qemu-devel] [PATCH v1 1/5] configure: introduce --extra-libs Alex Bennée
2016-01-28 11:14 ` Paolo Bonzini
2016-01-28 11:38 ` Alex Bennée
2016-01-28 10:15 ` [Qemu-devel] [PATCH v1 2/5] configure: ensure ldflags propagated to config_host Alex Bennée
2016-01-28 11:10 ` Paolo Bonzini
2016-01-28 11:13 ` Paolo Bonzini
2016-01-29 15:26 ` Alex Bennée
2016-01-28 10:15 ` [Qemu-devel] [PATCH v1 3/5] include/qemu/atomic.h: default to __atomic functions Alex Bennée
2016-01-28 11:00 ` Paolo Bonzini
2016-01-29 16:06 ` Alex Bennée
2016-02-04 12:40 ` Paolo Bonzini
2016-02-04 13:00 ` Peter Maydell
2016-04-01 14:30 ` James Hogan
2016-04-01 14:51 ` Peter Maydell
2016-04-01 16:06 ` Alex Bennée
2016-04-01 20:35 ` Pranith Kumar
2016-04-04 8:14 ` Paolo Bonzini
2016-04-04 16:26 ` Pranith Kumar
2016-04-04 17:03 ` Paolo Bonzini [this message]
2016-04-04 20:15 ` Paolo Bonzini
2016-04-05 3:35 ` Pranith Kumar
2016-04-05 12:47 ` Paolo Bonzini
2016-01-28 10:15 ` [Qemu-devel] [PATCH v1 4/5] async.c: various atomic fixes for tsan Alex Bennée
2016-01-28 10:45 ` Paolo Bonzini
2016-01-28 10:15 ` [Qemu-devel] [PATCH v1 5/5] thread-pool: atomic fixes from tsan Alex Bennée
2016-01-28 10:44 ` 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=57029E74.8070509@redhat.com \
--to=pbonzini@redhat.com \
--cc=a.rigo@virtualopensystems.com \
--cc=alex.bennee@linaro.org \
--cc=bobby.prani@gmail.com \
--cc=fred.konrad@greensocs.com \
--cc=mark.burton@greensocs.com \
--cc=mttcg@greensocs.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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 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.