From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53427) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5unK-0004xo-EC for qemu-devel@nongnu.org; Thu, 26 May 2016 08:53:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b5unF-0006e9-Fz for qemu-devel@nongnu.org; Thu, 26 May 2016 08:53:46 -0400 Received: from mail-lf0-x244.google.com ([2a00:1450:4010:c07::244]:35281) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5unE-0006dU-Uv for qemu-devel@nongnu.org; Thu, 26 May 2016 08:53:41 -0400 Received: by mail-lf0-x244.google.com with SMTP id p10so5953671lfb.2 for ; Thu, 26 May 2016 05:53:40 -0700 (PDT) References: <5746D31C.3070500@gmail.com> <91b3837f-f61c-a7d4-5266-964e8e27a839@redhat.com> From: Sergey Fedorov Message-ID: <5746F1D2.30606@gmail.com> Date: Thu, 26 May 2016 15:53:38 +0300 MIME-Version: 1.0 In-Reply-To: <91b3837f-f61c-a7d4-5266-964e8e27a839@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] qemu-arm-static, multiprocess, atomic List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , Jeff Epler , qemu-devel@nongnu.org, =?UTF-8?Q?Alex_Benn=c3=a9e?= , Richard Henderson , Riku Voipio , Blue Swirl On 26/05/16 14:21, Paolo Bonzini wrote: > > On 26/05/2016 12:42, Sergey Fedorov wrote: >> I'm afraid even our recent efforts in >> multi-threaded TCG won't change the situation. The problem is that it >> would require to translate somehow ARM's exclusive access monitor to x86 >> model. >> > The cmpxchg-based variant would work. It doesn't implement LL/SC > exactly, but it works fine if the program is written against GCC atomic > builtins. I'm afraid, GCC can still generate ldrex/strex pair for __atomic_compare_exchange(): $ cat a.c #define atomic_cmpxchg(ptr, old, new) \ ({ \ typeof(*ptr) _old = (old), _new = (new); \ __atomic_compare_exchange(ptr, &_old, &_new, 0, \ __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); \ _old; \ }) int cmpexchg(int *ptr, int old, int new) { return atomic_cmpxchg(ptr, old, new); } $ arm-linux-gnueabi-gcc -march=armv7-a -O2 -c a.c $ arm-linux-gnueabi-objdump -d a.o a.o: file format elf32-littlearm Disassembly of section .text: 00000000 : 0: e24dd008 sub sp, sp, #8 4: e58d1004 str r1, [sp, #4] 8: f57ff05f dmb sy c: e1903f9f ldrex r3, [r0] 10: e1530001 cmp r3, r1 14: 1a000002 bne 24 18: e180cf92 strex ip, r2, [r0] 1c: e35c0000 cmp ip, #0 20: 1afffff9 bne c 24: f57ff05f dmb sy 28: e1a00003 mov r0, r3 2c: e28dd008 add sp, sp, #8 30: e12fff1e bx lr Kind regards, Sergey