qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v5 07/18] qemu-thread: add simple test-and-set s


From: Paolo Bonzini
Subject: Re: [Qemu-devel] [PATCH v5 07/18] qemu-thread: add simple test-and-set spinlock
Date: Wed, 18 May 2016 17:09:48 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.0


On 18/05/2016 17:05, Sergey Fedorov wrote:
> Please look at this:
> 
> $ cat >a.c <<EOF
> int atomic_exchange(int *x, int v)
> {
>     return __atomic_exchange_n(x, v, __ATOMIC_ACQUIRE);
> }
> 
> int sync_lock_test_and_set(int *x, int v)
> {
>     __sync_lock_test_and_set(x, v);
> }
> EOF
> 
> Disassembly of section .text:
> 
> 00000000 <atomic_exchange>:
>    0:    e1902f9f     ldrex    r2, [r0]
>    4:    e1803f91     strex    r3, r1, [r0]
>    8:    e3530000     cmp    r3, #0
>    c:    1afffffb     bne    0 <atomic_exchange>
>   10:    ee070fba     mcr    15, 0, r0, cr7, cr10, {5}
>   14:    e1a00002     mov    r0, r2
>   18:    e12fff1e     bx    lr
> 
> 00000078 <sync_lock_test_and_set>:
>   78:    e1902f9f     ldrex    r2, [r0]
>   7c:    e1803f91     strex    r3, r1, [r0]
>   80:    e3530000     cmp    r3, #0
>   84:    1afffffb     bne    78 <sync_lock_test_and_set>
>   88:    ee070fba     mcr    15, 0, r0, cr7, cr10, {5}
>   8c:    e12fff1e     bx    lr
> 
> 
> atomic_compare_exchange() looks pretty good, doesn't it? Could we use it
> to implement qemu_spin_lock()?

I guess you mean atomic_exchange?  That one looks good, indeed it's
equivalent to __sync_lock_test_and_set.

But honestly I think it would be even better to just use
__sync_lock_test_and_set in the spinlock implementation and not add this
to atomics.h.  There's already enough issues with the current subset of
atomics, I am not really happy to add non-SC read-modify-write
operations to the mix.

Thanks,

Paolo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]