[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations
From: |
liu ping fan |
Subject: |
Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations |
Date: |
Thu, 13 Sep 2012 16:45:48 +0800 |
On Thu, Sep 13, 2012 at 4:19 PM, Paolo Bonzini <address@hidden> wrote:
> Il 13/09/2012 10:14, Avi Kivity ha scritto:
>>>>> >>> +static inline void atomic_set(Atomic *v, int i)
>>>>> >>> +{
>>>>> >>> + v->counter = i;
>>>>> >>> +}
>>>>> >>> +
>>>>> >>> +static inline int atomic_read(Atomic *v)
>>>>> >>> +{
>>>>> >>> + return v->counter;
>>>>> >>> +}
>>>>> >>>
>>>> >>
>>>> >> So these two operations don't get mangled by the optimizer.
>>>> >>
>>> > Browsing linux code and reading lkml, find some similar material. But
>>> > they have moved volatile from ->counter to function - atomic_read().
>>> > As to atomic_read(), I think it need to prevent optimizer from
>>> > refetching issue, but as to atomic_set(), do we need ?
>> I think so, to prevent reordering.
>
> Agreed. Alternatively, stick a barrier() before and after the
> assignment and read.
>
Yes, the linux just leave this barrier() as caller's choice at the
exact point, not right in atomic_set(). And embed barrier() in
atomic_set() can easy the caller's job.
Thanks and regards,
pingfan
> But I don't really see the point in wrapping atomically-accessed
> variables in a struct. Are we going to add a variant for long, a
> variant for pointers, etc.?
>
> I already proposed my version of this at
> http://github.com/bonzini/qemu/commit/1b439343.
>
> Paolo
- [Qemu-devel] [PATCH V3 0/10] prepare unplug out of protection of global lock, Liu Ping Fan, 2012/09/11
- [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations, Liu Ping Fan, 2012/09/11
- Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations, Avi Kivity, 2012/09/11
- Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations, liu ping fan, 2012/09/13
- Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations, Avi Kivity, 2012/09/13
- Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations, Paolo Bonzini, 2012/09/13
- Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations, Avi Kivity, 2012/09/13
- Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations, Paolo Bonzini, 2012/09/13
- Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations,
liu ping fan <=
- Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations, Jamie Lokier, 2012/09/19
- Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations, Jamie Lokier, 2012/09/19
- Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations, Peter Maydell, 2012/09/19
- Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations, Jamie Lokier, 2012/09/19
Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations, Peter Maydell, 2012/09/11
[Qemu-devel] [PATCH V3 02/11] qom: apply atomic on object's refcount, Liu Ping Fan, 2012/09/11
[Qemu-devel] [PATCH V3 03/11] hotplug: introduce qdev_unplug_complete() to remove device from views, Liu Ping Fan, 2012/09/11
[Qemu-devel] [PATCH V3 04/11] pci: remove pci device from mem view when unplug, Liu Ping Fan, 2012/09/11
[Qemu-devel] [PATCH V3 05/11] memory: introduce ref, unref interface for MemoryRegionOps, Liu Ping Fan, 2012/09/11