From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Cy9qA-0000DU-Dp for qemu-devel@nongnu.org; Mon, 07 Feb 2005 09:26:14 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Cy9o9-0007ig-2l for qemu-devel@nongnu.org; Mon, 07 Feb 2005 09:24:09 -0500 Received: from [129.104.30.34] (helo=mx1.polytechnique.org) by monty-python.gnu.org with esmtp (Exim 4.34) id 1Cy9Dj-0007Eh-Qi for qemu-devel@nongnu.org; Mon, 07 Feb 2005 08:46:32 -0500 Received: from [84.99.204.237] (237.204.99-84.rev.gaoland.net [84.99.204.237]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ssl.polytechnique.org (Postfix) with ESMTP id E417D331E3 for ; Mon, 7 Feb 2005 14:46:29 +0100 (CET) Message-ID: <42077171.6030308@bellard.org> Date: Mon, 07 Feb 2005 14:47:29 +0100 From: Fabrice Bellard MIME-Version: 1.0 Subject: Re: [Qemu-devel] testandset asm fix References: <200502061443.38384.paul@codesourcery.com> In-Reply-To: <200502061443.38384.paul@codesourcery.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org OK. Anyway, the locking in QEMU is mostly boggus. If SMP is implemented someday with host threads, then it will be the right time to correct it ! Fabrice. Paul Brook wrote: > The inline assembly used for the x86/x86-64 host testandset routine is bogus. > The operand constraints are wrong (Fails to compile at -O0). > Also the return value is incorrect. It should return 0 if the lock was > successfully acquired. > > Patch below fixes it. The additional sete test is unnecessary, we can just use > the comparison/writeback value. > > Paul > > Index: exec-all.h > =================================================================== > RCS file: /cvsroot/qemu/qemu/exec-all.h,v > retrieving revision 1.26 > diff -u -p -r1.26 exec-all.h > --- exec-all.h 10 Jan 2005 23:23:48 -0000 1.26 > +++ exec-all.h 6 Feb 2005 14:35:43 -0000 > @@ -392,28 +392,24 @@ static inline int testandset (int *p) > #ifdef __i386__ > static inline int testandset (int *p) > { > - char ret; > - long int readval; > - > - __asm__ __volatile__ ("lock; cmpxchgl %3, %1; sete %0" > - : "=q" (ret), "=m" (*p), "=a" (readval) > - : "r" (1), "m" (*p), "a" (0) > - : "memory"); > - return ret; > + long int readval = 0; > + > + __asm__ __volatile__ ("lock; cmpxchgl %2, %0" > + : "+m" (*p), "+a" (readval) > + : "r" (1)); > + return readval; > } > #endif > > #ifdef __x86_64__ > static inline int testandset (int *p) > { > - char ret; > - int readval; > - > - __asm__ __volatile__ ("lock; cmpxchgl %3, %1; sete %0" > - : "=q" (ret), "=m" (*p), "=a" (readval) > - : "r" (1), "m" (*p), "a" (0) > - : "memory"); > - return ret; > + long int readval = 0; > + > + __asm__ __volatile__ ("lock; cmpxchgl %2, %0" > + : "+m" (*p), "+a" (readval) > + : "r" (1)); > + return readval; > } > #endif > > > > _______________________________________________ > Qemu-devel mailing list > Qemu-devel@nongnu.org > http://lists.nongnu.org/mailman/listinfo/qemu-devel > >