From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: Re: [Qemu-devel] [PATCH] kvm: First step to push iothread lock out of inner run loop Date: Thu, 28 Jun 2012 22:45:04 -0300 Message-ID: <20120629014504.GC12611@amt.cnet> References: <4FE4F56D.1020201@web.de> <4FE4F7F5.7030400@web.de> <20120626193420.GA19852@amt.cnet> <4FEC65DF.20504@codemonkey.ws> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Jan Kiszka , Liu Ping Fan , kvm , qemu-devel , Alexander Graf , Avi Kivity To: Anthony Liguori Return-path: Received: from mx1.redhat.com ([209.132.183.28]:60634 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754992Ab2F2Bp6 (ORCPT ); Thu, 28 Jun 2012 21:45:58 -0400 Content-Disposition: inline In-Reply-To: <4FEC65DF.20504@codemonkey.ws> Sender: kvm-owner@vger.kernel.org List-ID: On Thu, Jun 28, 2012 at 09:10:39AM -0500, Anthony Liguori wrote: > > > >1. read_lock(memmap_lock) > >2. MemoryRegionSection mrs = lookup(addr) > >3. qom_ref(mrs.mr->dev) > >4. read_unlock(memmap_lock) > > > >5. mutex_lock(dev->lock) > >6. dispatch(&mrs, addr, data, size) > >7. mutex_unlock(dev->lock) > > Just a detail, I don't think we should acquire a device specific > lock in global code. Rather, I think we should acquire the global > lock before dispatch unless a MemoryRegion is marked as being > unlocked. "The basic plan is introduce granular locking starting at the KVM dispatch level until we can get to MemoryRegion dispatch. We'll then have some way to indicate that a MemoryRegion's callbacks should be invoked without holding the qemu global mutex." Before that is possible, the callback must not make use of data structures currently protected by qemu_global_mutex, such as timers, interrupts (that is, you would have to split locks for each individual service invoked from inside callbacks, which is a recipe for disaster). With lock_device() below you can have mutex_lock(dev->lock) device specific work mutex_lock(qemu_global_mutex) raise irq, send packet, etc mutex_unlock(qemu_global_mutex) mutex_unlock(dev->lock) and iothread doing the select() pseudocode in the previous email.