From: "Jan Beulich" Subject: [PATCH] passthrough: streamline _hvm_dirq_assist() Date: Thu, 11 Sep 2014 14:14:43 +0100 Message-ID: <5411BC630200007800033E1A@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartDEEB9653.0__=" Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XS4D0-0005Ss-B2 for xen-devel@lists.xenproject.org; Thu, 11 Sep 2014 13:14:46 +0000 List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartDEEB9653.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline The loop inside this function was calling two functions with loop- invariable arguments which clearly don't need calling more than once: send_guest_pirq() and __msi_pirq_eoi(). After moving these out of the loop it further became apparent that folding the hvm_pci_msi_assert() helper into the main function can further help readability. In the course of this I noticed that __hvm_dpci_eoi() called hvm_pci_intx_deassert() unconditionally, whereas hvm_pci_intx_assert() (correctly) got called only when !hvm_domain_use_pirq(), so the former is being made conditional now too. Signed-off-by: Jan Beulich --- a/xen/drivers/passthrough/io.c +++ b/xen/drivers/passthrough/io.c @@ -513,45 +513,39 @@ void hvm_dpci_msi_eoi(struct domain *d,=20 spin_unlock(&d->event_lock); } =20 -static void hvm_pci_msi_assert( - struct domain *d, struct hvm_pirq_dpci *pirq_dpci) -{ - struct pirq *pirq =3D dpci_pirq(pirq_dpci); - - if ( hvm_domain_use_pirq(d, pirq) ) - send_guest_pirq(d, pirq); - else - vmsi_deliver_pirq(d, pirq_dpci); -} - static int _hvm_dirq_assist(struct domain *d, struct hvm_pirq_dpci = *pirq_dpci, void *arg) { if ( test_and_clear_bool(pirq_dpci->masked) ) { + struct pirq *pirq =3D dpci_pirq(pirq_dpci); const struct dev_intx_gsi_link *digl; =20 + if ( hvm_domain_use_pirq(d, pirq) ) + { + send_guest_pirq(d, pirq); + + if ( pirq_dpci->flags & HVM_IRQ_DPCI_GUEST_MSI ) + return 0; + } + if ( pirq_dpci->flags & HVM_IRQ_DPCI_GUEST_MSI ) { - hvm_pci_msi_assert(d, pirq_dpci); + vmsi_deliver_pirq(d, pirq_dpci); return 0; } =20 list_for_each_entry ( digl, &pirq_dpci->digl_list, list ) { - struct pirq *info =3D dpci_pirq(pirq_dpci); - - if ( hvm_domain_use_pirq(d, info) ) - send_guest_pirq(d, info); - else - hvm_pci_intx_assert(d, digl->device, digl->intx); + hvm_pci_intx_assert(d, digl->device, digl->intx); pirq_dpci->pending++; + } =20 - if ( pirq_dpci->flags & HVM_IRQ_DPCI_TRANSLATE ) - { - /* for translated MSI to INTx interrupt, eoi as early as = possible */ - __msi_pirq_eoi(pirq_dpci); - } + if ( pirq_dpci->flags & HVM_IRQ_DPCI_TRANSLATE ) + { + /* for translated MSI to INTx interrupt, eoi as early as = possible */ + __msi_pirq_eoi(pirq_dpci); + return 0; } =20 /* @@ -561,8 +555,8 @@ static int _hvm_dirq_assist(struct domai * guest will never deal with the irq, then the physical = interrupt line * will never be deasserted. */ - if ( pt_irq_need_timer(pirq_dpci->flags) ) - set_timer(&pirq_dpci->timer, NOW() + PT_IRQ_TIME_OUT); + ASSERT(pt_irq_need_timer(pirq_dpci->flags)); + set_timer(&pirq_dpci->timer, NOW() + PT_IRQ_TIME_OUT); } =20 return 0; @@ -583,12 +577,12 @@ static void __hvm_dpci_eoi(struct domain const struct hvm_girq_dpci_mapping *girq, const union vioapic_redir_entry *ent) { - struct pirq *pirq; + struct pirq *pirq =3D pirq_info(d, girq->machine_gsi); struct hvm_pirq_dpci *pirq_dpci; =20 - hvm_pci_intx_deassert(d, girq->device, girq->intx); + if ( !hvm_domain_use_pirq(d, pirq) ) + hvm_pci_intx_deassert(d, girq->device, girq->intx); =20 - pirq =3D pirq_info(d, girq->machine_gsi); pirq_dpci =3D pirq_dpci(pirq); =20 /* --=__PartDEEB9653.0__= Content-Type: text/plain; name="pt-dirq-assist.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="pt-dirq-assist.patch" passthrough: streamline _hvm_dirq_assist()=0A=0AThe loop inside this = function was calling two functions with loop-=0Ainvariable arguments which = clearly don't need calling more than once:=0Asend_guest_pirq() and = __msi_pirq_eoi(). After moving these out of the=0Aloop it further became = apparent that folding the hvm_pci_msi_assert()=0Ahelper into the main = function can further help readability.=0A=0AIn the course of this I = noticed that __hvm_dpci_eoi() called=0Ahvm_pci_intx_deassert() unconditiona= lly, whereas hvm_pci_intx_assert()=0A(correctly) got called only when = !hvm_domain_use_pirq(), so the former=0Ais being made conditional now = too.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- = a/xen/drivers/passthrough/io.c=0A+++ b/xen/drivers/passthrough/io.c=0A@@ = -513,45 +513,39 @@ void hvm_dpci_msi_eoi(struct domain *d, =0A = spin_unlock(&d->event_lock);=0A }=0A =0A-static void hvm_pci_msi_assert(=0A= - struct domain *d, struct hvm_pirq_dpci *pirq_dpci)=0A-{=0A- struct = pirq *pirq =3D dpci_pirq(pirq_dpci);=0A-=0A- if ( hvm_domain_use_pirq(d,= pirq) )=0A- send_guest_pirq(d, pirq);=0A- else=0A- = vmsi_deliver_pirq(d, pirq_dpci);=0A-}=0A-=0A static int _hvm_dirq_assist(st= ruct domain *d, struct hvm_pirq_dpci *pirq_dpci,=0A = void *arg)=0A {=0A if ( test_and_clear_bool(pirq_dpci->masked) = )=0A {=0A+ struct pirq *pirq =3D dpci_pirq(pirq_dpci);=0A = const struct dev_intx_gsi_link *digl;=0A =0A+ if ( hvm_domain_use_= pirq(d, pirq) )=0A+ {=0A+ send_guest_pirq(d, pirq);=0A+= =0A+ if ( pirq_dpci->flags & HVM_IRQ_DPCI_GUEST_MSI )=0A+ = return 0;=0A+ }=0A+=0A if ( pirq_dpci->flags & = HVM_IRQ_DPCI_GUEST_MSI )=0A {=0A- hvm_pci_msi_assert(d, = pirq_dpci);=0A+ vmsi_deliver_pirq(d, pirq_dpci);=0A = return 0;=0A }=0A =0A list_for_each_entry ( digl, = &pirq_dpci->digl_list, list )=0A {=0A- struct pirq = *info =3D dpci_pirq(pirq_dpci);=0A-=0A- if ( hvm_domain_use_pirq= (d, info) )=0A- send_guest_pirq(d, info);=0A- = else=0A- hvm_pci_intx_assert(d, digl->device, digl->intx);= =0A+ hvm_pci_intx_assert(d, digl->device, digl->intx);=0A = pirq_dpci->pending++;=0A+ }=0A =0A- if ( pirq_dpci-= >flags & HVM_IRQ_DPCI_TRANSLATE )=0A- {=0A- /* = for translated MSI to INTx interrupt, eoi as early as possible */=0A- = __msi_pirq_eoi(pirq_dpci);=0A- }=0A+ if ( = pirq_dpci->flags & HVM_IRQ_DPCI_TRANSLATE )=0A+ {=0A+ /* = for translated MSI to INTx interrupt, eoi as early as possible */=0A+ = __msi_pirq_eoi(pirq_dpci);=0A+ return 0;=0A }=0A = =0A /*=0A@@ -561,8 +555,8 @@ static int _hvm_dirq_assist(struct = domai=0A * guest will never deal with the irq, then the physical = interrupt line=0A * will never be deasserted.=0A */=0A- = if ( pt_irq_need_timer(pirq_dpci->flags) )=0A- set_timer(&= pirq_dpci->timer, NOW() + PT_IRQ_TIME_OUT);=0A+ ASSERT(pt_irq_need_t= imer(pirq_dpci->flags));=0A+ set_timer(&pirq_dpci->timer, NOW() + = PT_IRQ_TIME_OUT);=0A }=0A =0A return 0;=0A@@ -583,12 +577,12 @@ = static void __hvm_dpci_eoi(struct domain=0A = const struct hvm_girq_dpci_mapping *girq,=0A = const union vioapic_redir_entry *ent)=0A {=0A- struct pirq *pirq;=0A+ = struct pirq *pirq =3D pirq_info(d, girq->machine_gsi);=0A struct = hvm_pirq_dpci *pirq_dpci;=0A =0A- hvm_pci_intx_deassert(d, girq->device,= girq->intx);=0A+ if ( !hvm_domain_use_pirq(d, pirq) )=0A+ = hvm_pci_intx_deassert(d, girq->device, girq->intx);=0A =0A- pirq =3D = pirq_info(d, girq->machine_gsi);=0A pirq_dpci =3D pirq_dpci(pirq);=0A = =0A /*=0A --=__PartDEEB9653.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__PartDEEB9653.0__=--