Received: from eggs.gnu.org ([208.118.235.92]:38935) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S30o8-0004TO-IR for qemu-devel@nongnu.org; Thu, 01 Mar 2012 02:52:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S30o4-0003QO-W4 for qemu-devel@nongnu.org; Thu, 01 Mar 2012 02:52:12 -0500 Received: from csmailer.cs.nctu.edu.tw ([140.113.235.130]:57605) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S30o4-0003LI-38 for qemu-devel@nongnu.org; Thu, 01 Mar 2012 02:52:08 -0500 Date: Thu, 1 Mar 2012 15:51:46 +0800 From: =?utf-8?B?6Zmz6Z+L5Lu7?= Message-ID: <20120301075146.GA2937@cs.nctu.edu.tw> References: <1330340818-4125-1-git-send-email-e.voevodin@samsung.com> <1330344787-14482-1-git-send-email-e.voevodin@samsung.com> <4F4C4643.2080007@samsung.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2] TCG: Convert global variables to be TLS. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , i.mitsyanko@samsung.com, Evgeny Voevodin , kyungmin.park@samsung.com, d.solodkiy@samsung.com, m.kozlov@samsung.com > If you're serious about multithreading TCG then I think the first > steps are: > * fix existing race conditions > * think very hard > * come up with an overall design for what you're proposing As COREMU [1] point out, current QEMU atomic instruction emulation appr= oach is problematic. For example, guest application might use x86 xchg instructio= n to implement spin lock/unlock (addr is a shared memory space). spin_unlock: spin_lock: =20 try: r10 =3D 1; xchg addr, r10; if (r10 =3D=3D 0) goto success; *addr =3D 0; fail: pause; if (*addr !=3D 0) goto fail; goto try; success: =20 After QEMU translation, guest xchg instruction becomes spin_unlock: spin_lock: helper_lock; *addr =3D 0; T0 =3D r10; T1 =3D *addr; *addr =3D T0; r10 =3D T1; helper_unlock; You can the see the atomicity on which spin lock/unlock rely is broken. "*addr =3D 0" can happened in the between of helper_lock/helper_unlock. COREMU solve this by using a lightway software transaction memory to emul= ate atomic instructions. I think this issue is quite important if we want to = make TCG multithreaded, right? Is there a better way to solve this? Regards, chenwj [1] http://citeseerx.ist.psu.edu/viewdoc/download?doi=3D10.1.1.187.6011&rep=3D= rep1&type=3Dpdf --=20 Wei-Ren Chen (=E9=99=B3=E9=9F=8B=E4=BB=BB) Computer Systems Lab, Institute of Information Science, Academia Sinica, Taiwan (R.O.C.) Tel:886-2-2788-3799 #1667 Homepage: http://people.cs.nctu.edu.tw/~chenwj