From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50814) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b336q-0001WR-34 for qemu-devel@nongnu.org; Wed, 18 May 2016 11:10:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b336l-0005Hl-Ob for qemu-devel@nongnu.org; Wed, 18 May 2016 11:10:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46740) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b336l-0005Hd-IZ for qemu-devel@nongnu.org; Wed, 18 May 2016 11:09:59 -0400 References: <1463196873-17737-1-git-send-email-cota@braap.org> <1463196873-17737-8-git-send-email-cota@braap.org> <573B5134.8060104@gmail.com> <66d14198-dab0-c72e-fe17-d022cff3feff@twiddle.net> <20160517200415.GD30174@flamenco> <573B7CFB.30002@gmail.com> <20160518002814.GA25803@flamenco> <573C79CA.3010703@gmail.com> <573C807D.7050505@gmail.com> <0da2faf1-4d51-3bda-cc2b-81dfac485b80@redhat.com> <573C84A7.6000707@gmail.com> From: Paolo Bonzini Message-ID: Date: Wed, 18 May 2016 17:09:48 +0200 MIME-Version: 1.0 In-Reply-To: <573C84A7.6000707@gmail.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v5 07/18] qemu-thread: add simple test-and-set spinlock List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Sergey Fedorov , "Emilio G. Cota" Cc: Richard Henderson , QEMU Developers , MTTCG Devel , =?UTF-8?Q?Alex_Benn=c3=a9e?= , Peter Crosthwaite On 18/05/2016 17:05, Sergey Fedorov wrote: > Please look at this: > > $ cat >a.c < 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 : > 0: e1902f9f ldrex r2, [r0] > 4: e1803f91 strex r3, r1, [r0] > 8: e3530000 cmp r3, #0 > c: 1afffffb bne 0 > 10: ee070fba mcr 15, 0, r0, cr7, cr10, {5} > 14: e1a00002 mov r0, r2 > 18: e12fff1e bx lr > > 00000078 : > 78: e1902f9f ldrex r2, [r0] > 7c: e1803f91 strex r3, r1, [r0] > 80: e3530000 cmp r3, #0 > 84: 1afffffb bne 78 > 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