From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LhRjL-0001V0-0y for qemu-devel@nongnu.org; Wed, 11 Mar 2009 12:56:31 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LhRjJ-0001UO-3n for qemu-devel@nongnu.org; Wed, 11 Mar 2009 12:56:30 -0400 Received: from [199.232.76.173] (port=49856 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LhRjI-0001UL-PA for qemu-devel@nongnu.org; Wed, 11 Mar 2009 12:56:28 -0400 Received: from e6.ny.us.ibm.com ([32.97.182.146]:59984) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LhRjI-0007uT-CG for qemu-devel@nongnu.org; Wed, 11 Mar 2009 12:56:28 -0400 Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com [9.56.227.236]) by e6.ny.us.ibm.com (8.13.1/8.13.1) with ESMTP id n2BGvbcP014182 for ; Wed, 11 Mar 2009 12:57:37 -0400 Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by d01relay04.pok.ibm.com (8.13.8/8.13.8/NCO v9.2) with ESMTP id n2BGuPx1195422 for ; Wed, 11 Mar 2009 12:56:25 -0400 Received: from d01av02.pok.ibm.com (loopback [127.0.0.1]) by d01av02.pok.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id n2BGt2A4003844 for ; Wed, 11 Mar 2009 12:55:03 -0400 Message-ID: <49B7ED35.5050704@us.ibm.com> Date: Wed, 11 Mar 2009 11:56:21 -0500 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [patch 1/2] qemu: sem/thread helpers References: <20090311161645.344003675@localhost.localdomain> <20090311161942.482576079@localhost.localdomain> <200903111648.02530.paul@codesourcery.com> In-Reply-To: <200903111648.02530.paul@codesourcery.com> Content-Type: text/plain; charset=ISO-8859-1; 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: Paul Brook Cc: Marcelo Tosatti , qemu-devel@nongnu.org Paul Brook wrote: >> +QemuSem qemu_sem; >> > > It's entirely unclear what is actually protected by the semaphore. > > What exactly does the IO thread do? AFAICS device MMIO is still run from > within the CPU thread. Device code is not threadsafe (and probably never will > be), so you can't run any of the device callbacks in the IO thread either. > Doesn't seem like there's a lot left for it to do... > The goal is to drop qemu_mutex while the VCPU is running to allow the device model to run while the VCPU executes. This is not currently safe with TCG but it is safe when using KVM. There are a couple reasons to drop qemu_mutex while running the VCPU. When using KVM's in-kernel APIC, hlt emulation occurs within the kernel. This means that the KVM_RUN ioctl blocks indefinitely. We currently don't use in-kernel APIC emulation in upstream QEMU's KVM support as this set of patches is a pre-requisite for that. This also enables true SMP support in KVM. You can allow multiple VCPUs to run concurrently once you're dropping qemu_mutex during VCPU execution. The VCPU threads have to acquire qemu_mutex once they drop back to QEMU (to handle MMIO, for instance), but this only happens during IO. From an infrastructure perspective, this is a feature for KVM but also a step in a better direction for TCG too. If TCG can be made to allow qemu_mutex to be dropped (perhaps for x86->x86 translation, as a start), then the same infrastructure can be used for true SMP support with TCG. Once we have this, we can start making some of the device model code thread safe too... Regards, Anthony Liguori Regards, Anthony Liguori > Paul >