]> err.no Git - linux-2.6/commitdiff
KVM: round robin for APIC lowest priority delivery mode
authorHe, Qing <qing.he@intel.com>
Mon, 3 Sep 2007 14:01:36 +0000 (17:01 +0300)
committerAvi Kivity <avi@qumranet.com>
Sat, 13 Oct 2007 08:18:26 +0000 (10:18 +0200)
Signed-off-by: Qing He <qing.he@intel.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
drivers/kvm/kvm.h
drivers/kvm/lapic.c

index f8fe87d3ddbddae9b68e6bb2a2d95c5b0ae44910..dbb929d8a31e602001c526102862a59f417f5d94 100644 (file)
@@ -413,6 +413,7 @@ struct kvm {
        struct kvm_io_bus pio_bus;
        struct kvm_pic *vpic;
        struct kvm_ioapic *vioapic;
+       int round_robin_prev_vcpu;
 };
 
 static inline struct kvm_pic *pic_irqchip(struct kvm *kvm)
index 01e769672dccf7d0908a0d869fb8f07bfca58a8e..ca1db3852ace0a4759de0a57a44a3badda4f2570 100644 (file)
@@ -371,12 +371,35 @@ struct kvm_lapic *kvm_apic_round_robin(struct kvm *kvm, u8 vector,
                                       unsigned long bitmap)
 {
        int vcpu_id;
+       int last;
+       int next;
+       struct kvm_lapic *apic;
+
+       last = kvm->round_robin_prev_vcpu;
+       next = last;
+
+       do {
+               if (++next == KVM_MAX_VCPUS)
+                       next = 0;
+               if (kvm->vcpus[next] == NULL || !test_bit(next, &bitmap))
+                       continue;
+               apic = kvm->vcpus[next]->apic;
+               if (apic && apic_enabled(apic))
+                       break;
+               apic = NULL;
+       } while (next != last);
+       kvm->round_robin_prev_vcpu = next;
+
+       if (!apic) {
+               vcpu_id = ffs(bitmap) - 1;
+               if (vcpu_id < 0) {
+                       vcpu_id = 0;
+                       printk(KERN_DEBUG "vcpu not ready for apic_round_robin\n");
+               }
+               apic = kvm->vcpus[vcpu_id]->apic;
+       }
 
-       /* TODO for real round robin */
-       vcpu_id = fls(bitmap) - 1;
-       if (vcpu_id < 0)
-               printk(KERN_DEBUG "vcpu not ready for apic_round_robin\n");
-       return kvm->vcpus[vcpu_id]->apic;
+       return apic;
 }
 
 static void apic_set_eoi(struct kvm_lapic *apic)