From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LOb07-0000Gy-T5 for qemu-devel@nongnu.org; Sun, 18 Jan 2009 11:59:55 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LOb02-000074-Fp for qemu-devel@nongnu.org; Sun, 18 Jan 2009 11:59:54 -0500 Received: from [199.232.76.173] (port=38108 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LOb02-00006h-85 for qemu-devel@nongnu.org; Sun, 18 Jan 2009 11:59:50 -0500 Received: from soufre.accelance.net ([213.162.48.15]:64175) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LOb01-0004Xs-N6 for qemu-devel@nongnu.org; Sun, 18 Jan 2009 11:59:49 -0500 Received: from [192.168.0.3] (potipota.net [88.168.176.51]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by soufre.accelance.net (Postfix) with ESMTP id C5CC945014 for ; Sun, 18 Jan 2009 17:59:46 +0100 (CET) From: Lionel Landwerlin Content-Type: text/plain; charset=UTF-8 Date: Sun, 18 Jan 2009 17:59:45 +0100 Message-Id: <1232297985.10124.23.camel@cocoduo.atr> Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH] Add support for atomic operations on sh user emulation 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 Hi all, I've got some problem with threads and sh4 user emulation. Let's take a little example : ------------------------------------------------------ #include #include #include static pthread_mutex_t mutex; static void * thread_task (int id) { while (1) { pthread_mutex_lock (&mutex); printf ("%i Got it !\n", id); pthread_mutex_unlock (&mutex); } } int main (int argc, char *argv[]) { int i, n =3D 42; pthread_t th; pthread_mutex_init (&mutex, NULL); for (i =3D 0 ; i < n ; i++) { pthread_create (&th, NULL, thread_task, (void *) i); } =20 thread_task (n); return EXIT_SUCCESS; } ------------------------------------------------------ For those who would like to test, here is a stripped rootfs http://djdeath.atr.free.fr/rootfs_sh4.tar.gz (from stlinux.com) with everything to execute this like test (you will find the previous example compiled in /tmp). So when starting this program with the current qemu, you will probably got an assertion (after a random amonth of time) from the libc : mutex->__data.__owner =3D=3D 0 The problem is that on SH4 (and probably others) uniprocessor architectures, there is no atomic instructions (or very few). Atomic operations related to locking etc... are provided by a kernel emulation (gUSA). In user mode emulation qemu has to provide this emulation instead of the kernel that is unaware of the state of the emulated program (register, stack, etc...) and is probably everytime from a different architecture. The following patch provide a way to emulate gUSA, maybe not the best. This patch is a rewrite of the previous patch I sent on tas.b atomic operation. Regards, --=20 =EF=BB=BFLione Landwerlin =20 =EF=BB=BF O p e n W i d e 14, rue Gaillon 75002 Paris