From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51545) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2qTH-00079q-RW for qemu-devel@nongnu.org; Tue, 17 May 2016 21:40:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b2lBa-0006OB-1E for qemu-devel@nongnu.org; Tue, 17 May 2016 16:01:49 -0400 Received: from mail-lb0-x243.google.com ([2a00:1450:4010:c04::243]:34725) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2lBY-0006Nu-Uv for qemu-devel@nongnu.org; Tue, 17 May 2016 16:01:45 -0400 Received: by mail-lb0-x243.google.com with SMTP id bg8so1610072lbc.1 for ; Tue, 17 May 2016 13:01:44 -0700 (PDT) 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> <573B7793.9020109@gmail.com> From: Sergey Fedorov Message-ID: <573B78A6.6030009@gmail.com> Date: Tue, 17 May 2016 23:01:42 +0300 MIME-Version: 1.0 In-Reply-To: <573B7793.9020109@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: Richard Henderson , "Emilio G. Cota" , QEMU Developers , MTTCG Devel Cc: =?UTF-8?Q?Alex_Benn=c3=a9e?= , Paolo Bonzini , Peter Crosthwaite On 17/05/16 22:57, Sergey Fedorov wrote: > On 17/05/16 22:19, Richard Henderson wrote: >> On 05/17/2016 10:13 AM, Sergey Fedorov wrote: >>>>> +static inline void qemu_spin_lock(QemuSpin *spin) >>>>> +{ >>>>> + while (atomic_test_and_set_acquire(&spin->value)) { >>> >From gcc-4.8 info page, node "__atomic Builtins", description of >>> __atomic_test_and_set(): >>> >>> It should be only used for operands of type 'bool' or 'char'. >>> >> Hum. I thought I remembered all operand sizes there, but I've just re-checked >> and you're right about bool (and really only bool). >> >> Perhaps we should just stick with __sync_test_and_set then. I'm thinking here >> of e.g. armv6, a reasonable host, which can't operate on 1 byte atomic values. >> > > Sorry, I can't see reading ARMv6 ARM that 1-byte access can't be > atomic. What I've found: > > B2.4.1 Normal memory attribute > (snip) > Shared Normal memory > > (snip) > ... Reads to Shared Normal Memory that are aligned in memory > to the size of the access must be atomic. > > Actually, here's the sample code: #include struct foo { bool b; int i; }; int main(void) { struct foo f; __atomic_store_n(&f.b, 0, __ATOMIC_SEQ_CST); __atomic_store_n(&f.i, 0, __ATOMIC_SEQ_CST); return 0; } compiles with: arm-linux-gnueabi-gcc -march=armv6 -O2 -c a.c and disasm: 00000000
: 0: e24dd008 sub sp, sp, #8 4: ee070fba mcr 15, 0, r0, cr7, cr10, {5} 8: e3a03000 mov r3, #0 c: e5cd3000 strb r3, [sp] 10: ee070fba mcr 15, 0, r0, cr7, cr10, {5} 14: ee070fba mcr 15, 0, r0, cr7, cr10, {5} 18: e1a00003 mov r0, r3 1c: e58d3004 str r3, [sp, #4] 20: ee070fba mcr 15, 0, r0, cr7, cr10, {5} 24: e28dd008 add sp, sp, #8 28: e12fff1e bx lr Looks like GCC has no trouble generating __atomic_store_n() for 1-byte bool... Kind regards, Sergey