Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MjFSF-0004Q2-6G for qemu-devel@nongnu.org; Thu, 03 Sep 2009 12:46:35 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MjFSA-0004KE-RH for qemu-devel@nongnu.org; Thu, 03 Sep 2009 12:46:34 -0400 Received: from [199.232.76.173] (port=51438 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MjFSA-0004K2-Ho for qemu-devel@nongnu.org; Thu, 03 Sep 2009 12:46:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:12541) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MjFSA-0000TH-1k for qemu-devel@nongnu.org; Thu, 03 Sep 2009 12:46:30 -0400 Date: Thu, 3 Sep 2009 13:46:09 -0300 From: Glauber Costa Subject: Re: [Qemu-devel] [RFC] queue_work proposal Message-ID: <20090903164609.GR30340@mothafucka.localdomain> References: <1251939158-17153-1-git-send-email-glommer@redhat.com> <4A9F8230.80101@redhat.com> <20090903111505.GO30340@mothafucka.localdomain> <4A9FA95D.60404@redhat.com> <20090903121135.GQ30340@mothafucka.localdomain> <4A9FC7FF.8010602@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4A9FC7FF.8010602@redhat.com> List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Avi Kivity Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org On Thu, Sep 03, 2009 at 04:43:27PM +0300, Avi Kivity wrote: > On 09/03/2009 03:11 PM, Glauber Costa wrote: >> On Thu, Sep 03, 2009 at 02:32:45PM +0300, Avi Kivity wrote: >> >>> On 09/03/2009 02:15 PM, Glauber Costa wrote: >>> >>>> >>>>> on_vcpu() and queue_work() are fundamentally different (yes, I see the >>>>> wait parameter, and I think there should be two separate functions for >>>>> such different behaviours). >>>>> >>>>> >>>> Therefore, the name change. The exact on_vcpu behaviour, however, can be >>>> implemented ontop of queue_work(). >>>> >>> Will there be any use for asynchronous queue_work()? >>> >>> It's a dangerous API. >>> >> Initially, I thought we could use it for batching, if we forced a flush in the end of >> a sequence of operations. This can makes things faster if we are doing a bunch of calls >> in a row, from the wrong thread. >> > > It's a lot easier and safer to write a function that does your batch job > and on_vcpu() it. agree. > >>> I think it's reasonable to demand that whoever calls kvm_vcpu_ioctl() >>> know what they are doing (and they'll get surprising results if it >>> switches threads implicitly). >>> >> I respectfully disagree. Not that I want people not to know what they are doing, but I >> believe that, forcing something that can only run in a specific thread to be run there, >> provides us with a much saner interface, that will make code a lot more readable and >> maintainable. >> > > Example: > > kvm_vcpu_ioctl(get_regs) > regs->rflags |= some_flag > kvm_vcpu_ioctl(set_regs) > > This looks totally sane but is racy if kvm_vcpu_ioctl() does an implicit > on_vcpu(). Not at all. If we do queue_work once, it will execute whatever function you ask for in the correct thread, and for there on, everything will be local. So even if you nest functions that call queue_work themselves, only the first will involve synchronization at all. >> I will assume you meant "the other is assynchronous". It does not need to be. >> I though about including the assynchronous version in this RFC to let doors >> open for performance improvements *if* we needed them. But again: the absolute >> majority of the calls will be local. So it is not that important. >> > > Then there's even less reason to include the async version. I am pretty much convinced by now. > >>> on_vcpu() is a subset of queue_work(). I meant, why to we need the >>> extra functionality? >>> >> As I said, if you oppose it hardly, we don't really need to. >> > > I do oppose it, but the reason for not including it should be the > reasons I cited, not that I oppose it. For a masked vigilante like you, I thought it was clear enough that "fierce opposition" automatically meant you got strong reasons, and were actually right.