qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <rth@twiddle.net>
To: Torvald Riegel <triegel@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	Anthony Liguori <anthony@codemonkey.ws>,
	Andrew Haley <aph@redhat.com>, Liu Ping Fan <qemulist@gmail.com>,
	qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH v3 1/2] add a header file for atomic operations
Date: Wed, 19 Jun 2013 13:44:45 -0700	[thread overview]
Message-ID: <51C2183D.7050605@twiddle.net> (raw)
In-Reply-To: <1371674394.16968.26000.camel@triegel.csb>

On 06/19/2013 01:39 PM, Torvald Riegel wrote:
> On Thu, 2013-06-20 at 04:59 +0800, Liu Ping Fan wrote:
>> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
>> index fbabf99..28abe1e 100644
>> --- a/hw/virtio/vhost.c
>> +++ b/hw/virtio/vhost.c
>> @@ -16,6 +16,7 @@
>>  #include <sys/ioctl.h>
>>  #include "hw/virtio/vhost.h"
>>  #include "hw/hw.h"
>> +#include "qemu/atomic.h"
>>  #include "qemu/range.h"
>>  #include <linux/vhost.h>
>>  #include "exec/address-spaces.h"
>> @@ -47,11 +48,9 @@ static void vhost_dev_sync_region(struct vhost_dev *dev,
>>              addr += VHOST_LOG_CHUNK;
>>              continue;
>>          }
>> -        /* Data must be read atomically. We don't really
>> -         * need the barrier semantics of __sync
>> -         * builtins, but it's easier to use them than
>> -         * roll our own. */
>> -        log = __sync_fetch_and_and(from, 0);
>> +        /* Data must be read atomically. We don't really need barrier semantics
>> +         * but it's easier to use atomic_* than roll our own. */
>> +        log = atomic_xchg(from, 0);
> 
> If you really don't need any ordering guarantees / barriers here, then
> using a relaxed load should be fine.  But my gut feeling tells me you
> probably do need some barriers; either you are "re-using" another
> barrier (and then the comment should probably point out which), or it
> must be a case where it's either fine to read any value someone (else)
> wrote or there's no concurrent store after all.
> 

There is a store here, before and after.  Read the value, store zero.

I suppose what the comment is saying is that the atomic operation doesn't need
to be ordered with respect to the rest of the surrounding code, as the object
being synchronized is just that one integer.


r~

  reply	other threads:[~2013-06-19 20:45 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-19 20:59 [Qemu-devel] [PATCH v3 0/2] QEMUBH: make AioContext's bh re-entrant Liu Ping Fan
2013-06-19 20:59 ` [Qemu-devel] [PATCH v3 1/2] add a header file for atomic operations Liu Ping Fan
2013-06-19 16:37   ` Richard Henderson
2013-06-19 16:42     ` Paolo Bonzini
2013-06-19 20:39   ` Torvald Riegel
2013-06-19 20:44     ` Richard Henderson [this message]
2013-06-20  8:03       ` Paolo Bonzini
2013-06-19 20:59 ` [Qemu-devel] [PATCH v3 2/2] QEMUBH: make AioContext's bh re-entrant Liu Ping Fan
2013-06-20  7:39   ` Stefan Hajnoczi
2013-06-20  8:16     ` Paolo Bonzini
2013-06-20  9:12       ` liu ping fan
2013-06-20  9:19         ` Paolo Bonzini
2013-06-20  9:41       ` liu ping fan
2013-06-20  9:45         ` Paolo Bonzini
2013-06-21  4:35           ` liu ping fan

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=51C2183D.7050605@twiddle.net \
    --to=rth@twiddle.net \
    --cc=anthony@codemonkey.ws \
    --cc=aph@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemulist@gmail.com \
    --cc=stefanha@redhat.com \
    --cc=triegel@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 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).