From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40809) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YBiC7-0004Ct-0P for qemu-devel@nongnu.org; Thu, 15 Jan 2015 06:02:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YBiC2-0001Q0-0d for qemu-devel@nongnu.org; Thu, 15 Jan 2015 06:02:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55368) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YBhv3-0004S5-Ld for qemu-devel@nongnu.org; Thu, 15 Jan 2015 05:44:53 -0500 Message-ID: <54B79A1B.40409@redhat.com> Date: Thu, 15 Jan 2015 11:44:43 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <54B7958D.2040108@greensocs.com> In-Reply-To: <54B7958D.2040108@greensocs.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] global_mutex and multithread. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Frederic Konrad , mttcg@greensocs.com, qemu-devel Cc: Peter Maydell , Alexander Graf On 15/01/2015 11:25, Frederic Konrad wrote: > Hi everybody, > > In case of multithread TCG what is the best way to handle > qemu_global_mutex? > We though to have one mutex per vcpu and then synchronize vcpu threads when > they exit (eg: in tcg_exec_all). The basic ideas from Jan's patch in http://article.gmane.org/gmane.comp.emulators.qemu/118807 still apply. RAM block reordering doesn't exist anymore, having been replaced with mru_block. The patch reacquired the lock when entering MMIO or PIO emulation. That's enough while there is only one VCPU thread. Once you have >1 VCPU thread you'll need the RCU work that I am slowly polishing and sending out. That's because one device can change the memory map, and that will cause a tlb_flush for all CPUs in tcg_commit, and that's not thread-safe. And later on, once devices start being converted to run outside the BQL, that can be changed to use new functions address_space_rw_unlocked / io_mem_read_unlocked / io_mem_write_unlocked. Something like that is already visible at https://github.com/bonzini/qemu/commits/rcu (ignore patches after "kvm: Switch to unlocked MMIO"). Paolo