From: "Michael S. Tsirkin" <mst@redhat.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Avi Kivity <avi@redhat.com>, Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
x86@kernel.org, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH RFC 2/2] kvm: set affinity hint for assigned device msi
Date: Mon, 17 Oct 2011 19:04:40 +0200 [thread overview]
Message-ID: <20111017170440.GA8894@redhat.com> (raw)
In-Reply-To: <20111017160741.GA25476@amt.cnet>
On Mon, Oct 17, 2011 at 02:07:41PM -0200, Marcelo Tosatti wrote:
> > > Configurations to consider, all common ones used for assigned devices?
> >
> > I mean, besides round robin, any other modes that
> > have an issue? Interrupts can also be multicast,
> > I think, but we probably don't care what happens
> > to affinity then, as msi interrupts are probably never
> > broadcast ...
>
> There is also lowest priority, which can be used with MSI.
So the following will probably address that comment?
diff --git a/virt/kvm/assigned-dev.c b/virt/kvm/assigned-dev.c
index f89f138..b579777 100644
--- a/virt/kvm/assigned-dev.c
+++ b/virt/kvm/assigned-dev.c
@@ -142,9 +142,11 @@ static void deassign_host_irq(struct kvm *kvm,
for (i = 0; i < assigned_dev->entries_nr; i++)
disable_irq(assigned_dev->host_msix_entries[i].vector);
- for (i = 0; i < assigned_dev->entries_nr; i++)
- free_irq(assigned_dev->host_msix_entries[i].vector,
- (void *)assigned_dev);
+ for (i = 0; i < assigned_dev->entries_nr; i++) {
+ u32 vector = assigned_dev->host_msix_entries[i].vector;
+ irq_set_affinity_hint(vector, NULL);
+ free_irq(vector, (void *)assigned_dev);
+ }
assigned_dev->entries_nr = 0;
kfree(assigned_dev->host_msix_entries);
diff --git a/virt/kvm/irq_comm.c b/virt/kvm/irq_comm.c
index ac8b629..dabf89f 100644
--- a/virt/kvm/irq_comm.c
+++ b/virt/kvm/irq_comm.c
@@ -22,6 +22,7 @@
#include <linux/kvm_host.h>
#include <linux/slab.h>
+#include <linux/interrupt.h>
#include <trace/events/kvm.h>
#include <asm/msidef.h>
@@ -80,11 +81,23 @@ inline static bool kvm_is_dm_lowest_prio(struct kvm_lapic_irq *irq)
#endif
}
+static void kvm_vcpu_host_irq_hint(struct kvm_vcpu *vcpu, int host_irq)
+{
+ const struct cpumask *mask;
+ /* raw_smp_processor_id() is ok here: if we get preempted we can get a
+ * wrong value but we don't mind much. */
+ if (host_irq >= 0 && unlikely(vcpu->cpu != raw_smp_processor_id())) {
+ mask = get_cpu_mask(vcpu->cpu);
+ irq_set_affinity_hint(host_irq, mask);
+ }
+}
+
int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
struct kvm_lapic_irq *irq, int host_irq)
{
int i, r = -1;
- struct kvm_vcpu *vcpu, *lowest = NULL;
+ int matches = 0;
+ struct kvm_vcpu *vcpu, *lowest = NULL, *match;
if (irq->dest_mode == 0 && irq->dest_id == 0xff &&
kvm_is_dm_lowest_prio(irq))
@@ -98,10 +111,13 @@ int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
irq->dest_id, irq->dest_mode))
continue;
+ ++matches;
+
if (!kvm_is_dm_lowest_prio(irq)) {
if (r < 0)
r = 0;
r += kvm_apic_set_irq(vcpu, irq);
+ match = vcpu;
} else if (kvm_lapic_enabled(vcpu)) {
if (!lowest)
lowest = vcpu;
@@ -110,8 +126,13 @@ int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
}
}
- if (lowest)
+ if (lowest) {
r = kvm_apic_set_irq(lowest, irq);
+ match = lowest;
+ }
+
+ if (matches == 1)
+ kvm_vcpu_host_irq_hint(match, host_irq);
return r;
}
next prev parent reply other threads:[~2011-10-17 17:03 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-11 18:38 [PATCH RFC 0/2] kvm: set irq affinity for assigned devices Michael S. Tsirkin
2011-10-11 18:38 ` [PATCH RFC 1/2] kvm: pass host irq number to set irq calls Michael S. Tsirkin
2011-10-11 18:38 ` [PATCH RFC 2/2] kvm: set affinity hint for assigned device msi Michael S. Tsirkin
2011-10-13 14:54 ` Marcelo Tosatti
2011-10-16 13:12 ` Michael S. Tsirkin
2011-10-17 10:58 ` Marcelo Tosatti
2011-10-17 13:32 ` Michael S. Tsirkin
2011-10-17 16:07 ` Marcelo Tosatti
2011-10-17 16:14 ` Michael S. Tsirkin
2011-10-17 17:04 ` Michael S. Tsirkin [this message]
2012-01-11 16:10 ` Marcelo Tosatti
2011-10-17 11:09 ` Marcelo Tosatti
2011-10-17 13:35 ` Michael S. Tsirkin
2012-01-12 14:09 ` Avi Kivity
2012-01-15 13:24 ` Michael S. Tsirkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111017170440.GA8894@redhat.com \
--to=mst@redhat.com \
--cc=avi@redhat.com \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mtosatti@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox