qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] tests-aio-multithread: use atomic_read properly
@ 2017-02-27 11:17 Paolo Bonzini
  2017-02-27 12:01 ` Greg Kurz
  2017-02-27 14:01 ` Stefan Hajnoczi
  0 siblings, 2 replies; 4+ messages in thread
From: Paolo Bonzini @ 2017-02-27 11:17 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

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>
---
 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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] tests-aio-multithread: use atomic_read properly
  2017-02-27 11:17 [Qemu-devel] [PATCH] tests-aio-multithread: use atomic_read properly Paolo Bonzini
@ 2017-02-27 12:01 ` Greg Kurz
  2017-02-27 13:39   ` Peter Maydell
  2017-02-27 14:01 ` Stefan Hajnoczi
  1 sibling, 1 reply; 4+ messages in thread
From: Greg Kurz @ 2017-02-27 12:01 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel, stefanha

[-- Attachment #1: Type: text/plain, Size: 1379 bytes --]

On Mon, 27 Feb 2017 12:17:26 +0100
Paolo Bonzini <pbonzini@redhat.com> wrote:

> 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>
> ---

Cool ! I can use travis again :)

Tested-by: Greg Kurz <groug@kaod.org>

>  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);
>  }


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] tests-aio-multithread: use atomic_read properly
  2017-02-27 12:01 ` Greg Kurz
@ 2017-02-27 13:39   ` Peter Maydell
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2017-02-27 13:39 UTC (permalink / raw)
  To: Greg Kurz; +Cc: Paolo Bonzini, QEMU Developers, Stefan Hajnoczi

On 27 February 2017 at 12:01, Greg Kurz <groug@kaod.org> wrote:
> On Mon, 27 Feb 2017 12:17:26 +0100
> Paolo Bonzini <pbonzini@redhat.com> wrote:
>
>> 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>
>> ---
>
> Cool ! I can use travis again :)
>
> Tested-by: Greg Kurz <groug@kaod.org>
>

Thanks; applied to master as a build fix.

-- PMM

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] tests-aio-multithread: use atomic_read properly
  2017-02-27 11:17 [Qemu-devel] [PATCH] tests-aio-multithread: use atomic_read properly Paolo Bonzini
  2017-02-27 12:01 ` Greg Kurz
@ 2017-02-27 14:01 ` Stefan Hajnoczi
  1 sibling, 0 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2017-02-27 14:01 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel, stefanha

[-- Attachment #1: Type: text/plain, Size: 540 bytes --]

On Mon, Feb 27, 2017 at 12:17:26PM +0100, Paolo Bonzini wrote:
> 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>
> ---
>  tests/test-aio-multithread.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-02-27 14:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-27 11:17 [Qemu-devel] [PATCH] tests-aio-multithread: use atomic_read properly Paolo Bonzini
2017-02-27 12:01 ` Greg Kurz
2017-02-27 13:39   ` Peter Maydell
2017-02-27 14:01 ` Stefan Hajnoczi

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).