From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCHv2 RFC] kvm: deliver msix interrupts from irq handler Date: Mon, 11 Jun 2012 14:53:23 +0300 Message-ID: <4FD5DC33.3060709@redhat.com> References: <20120608160120.GA2959@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org To: "Michael S. Tsirkin" Return-path: Received: from mx1.redhat.com ([209.132.183.28]:32742 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751494Ab2FKLxZ (ORCPT ); Mon, 11 Jun 2012 07:53:25 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q5BBrPHS010477 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 11 Jun 2012 07:53:25 -0400 In-Reply-To: <20120608160120.GA2959@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On 06/08/2012 07:01 PM, Michael S. Tsirkin wrote: > We can deliver certain interrupts, notably MSIX, > from atomic context. Add a new API kvm_set_irq_inatomic, > that does exactly that, and use it to implement > an irq handler for msi. > > This reduces the pressure on scheduler in case > where host and guest irq share a host cpu. > Looks nice. > > +/* > + * Deliver an IRQ in an atomic context if we can, or return a failure, > + * user can retry in a process context. > + * Return value: > + * -EWOULDBLOCK - Can't deliver in atomic context: retry in a process context. > + * Other values - No need to retry. > + */ > +int kvm_set_irq_inatomic(struct kvm *kvm, int irq_source_id, u32 irq, int level) > +{ > + struct kvm_kernel_irq_routing_entry *e; > + int ret = -EINVAL; > + struct kvm_irq_routing_table *irq_rt; > + struct hlist_node *n; > + > + trace_kvm_set_irq(irq, level, irq_source_id); > + > + /* > + * We know MSI are safe in interrupt context. They are also > + * easy as there's a single routing entry for these GSIs. > + * So only handle MSI in an atomic context, for now. > + * > + * This shares some code with kvm_set_irq: this > + * version is optimized for a single entry MSI only case. > + */ > + rcu_read_lock(); > + irq_rt = rcu_dereference(kvm->irq_routing); > + if (irq < irq_rt->nr_rt_entries) > + hlist_for_each_entry(e, n, &irq_rt->map[irq], link) { > + if (likely(e->type == KVM_IRQ_ROUTING_MSI)) > + ret = kvm_set_msi(e, kvm, irq_source_id, level); > + else > + ret = -EWOULDBLOCK; > + break; > + } > + rcu_read_unlock(); > + return ret; > +} > + kvm_set_msi() contains a loop over all vcpus to match the APIC ID (or to broadcast). I'd rather see a cache that contains the vcpu pointer and vector number (assumes delivery mode of fixed and not the other junk), if the cache is filled fire away, otherwise slow path to a thread and fill the cache if possible. -- error compiling committee.c: too many arguments to function