From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Paolo Bonzini <pbonzini@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PULL 4/4] tests-aio-multithread: use atomic_read properly
Date: Mon, 27 Feb 2017 16:34:47 +0000 [thread overview]
Message-ID: <20170227163447.20428-5-stefanha@redhat.com> (raw)
In-Reply-To: <20170227163447.20428-1-stefanha@redhat.com>
From: Paolo Bonzini <pbonzini@redhat.com>
nodes[id].next is written by other threads. If atomic_read is not used
(matching atomic_set in mcs_mutex_lock!) the compiler can optimize the
whole "if" away!
Reported-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Tested-by: Greg Kurz <groug@kaod.org>
Message-id: 20170227111726.9237-1-pbonzini@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
tests/test-aio-multithread.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/test-aio-multithread.c b/tests/test-aio-multithread.c
index f11e990..8b0b40e 100644
--- a/tests/test-aio-multithread.c
+++ b/tests/test-aio-multithread.c
@@ -309,7 +309,7 @@ static void mcs_mutex_lock(void)
static void mcs_mutex_unlock(void)
{
int next;
- if (nodes[id].next == -1) {
+ if (atomic_read(&nodes[id].next) == -1) {
if (atomic_read(&mutex_head) == id &&
atomic_cmpxchg(&mutex_head, id, -1) == id) {
/* Last item in the list, exit. */
@@ -323,7 +323,7 @@ static void mcs_mutex_unlock(void)
}
/* Wake up the next in line. */
- next = nodes[id].next;
+ next = atomic_read(&nodes[id].next);
nodes[next].locked = 0;
qemu_futex_wake(&nodes[next].locked, 1);
}
--
2.9.3
next prev parent reply other threads:[~2017-02-27 16:35 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-27 16:34 [Qemu-devel] [PULL 0/4] Block patches Stefan Hajnoczi
2017-02-27 16:34 ` [Qemu-devel] [PULL 1/4] curl: do not use aio_context_acquire/release Stefan Hajnoczi
2017-05-03 14:54 ` Richard W.M. Jones
2017-05-03 14:59 ` Paolo Bonzini
2017-05-03 15:31 ` Richard W.M. Jones
2017-05-03 15:34 ` Richard W.M. Jones
2017-05-03 15:46 ` Paolo Bonzini
2017-05-03 15:55 ` Richard W.M. Jones
2017-05-03 16:08 ` Paolo Bonzini
2017-02-27 16:34 ` [Qemu-devel] [PULL 2/4] nfs: " Stefan Hajnoczi
2017-02-27 16:34 ` [Qemu-devel] [PULL 3/4] iscsi: " Stefan Hajnoczi
2017-02-27 16:34 ` Stefan Hajnoczi [this message]
2017-02-28 10:38 ` [Qemu-devel] [PULL 0/4] Block patches Peter Maydell
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=20170227163447.20428-5-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=pbonzini@redhat.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 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).