Return interrupt acknoledge info to userspace
RFC PATCH 1/1 Return interrupt acknoledge info to userspace
User space device emulation for timers might be inaccurate and cause coalescing of several irq into one. It happens when the load on the host is high and the guest did not manage to ack the previous irq. By get/set request irq commands the device won't issue another irq before the previous one has been acknowledged.
Userspace will request information about acking certain irq vectors. Every vcpu will update this information in its vcpu_run structure, it is in/out variable.
Note that if there is pending irq that didn't manage to be injected, it is being cleared.
--- arch/x86/kvm/svm.c | 1 + arch/x86/kvm/vmx.c | 1 + arch/x86/kvm/x86.c | 20 ++++++++++++++++++-- include/asm-x86/kvm_host.h | 2 ++ include/linux/kvm.h | 5 +++++ 5 files changed, 27 insertions(+), 2 deletions(-)
arch/x86/kvm/svm.c +1 -0
@@ -1501,6 +1501,7 @@ static void svm_intr_assist(struct kvm_vcpu *vcpu) intr_vector =kvm_cpu_get_interrupt (vcpu);svm_inject_irq (svm, intr_vector);kvm_timer_intr_post (vcpu, intr_vector); +clear_bit (intr_vector, vcpu->arch.irq_ack_requests); }static void kvm_reput_irq (struct vcpu_svm *svm)
arch/x86/kvm/vmx.c +1 -0
@@ -2369,6 +2369,7 @@ static void vmx_intr_assist(struct kvm_vcpu *vcpu) vector =kvm_cpu_get_interrupt (vcpu);vmx_inject_irq (vcpu, vector);kvm_timer_intr_post (vcpu, vector); +clear_bit (vector, vcpu->arch.irq_ack_requests); }else enable_irq_window (vcpu); }
arch/x86/kvm/x86.c +0 -0
@@ -2689,8 +2689,21 @@ static void post_kvm_run_save(struct kvm_vcpu
*vcpu,
kvm_run->if_flag = (kvm_x86_ops->get_rflags(vcpu) &
X86_EFLAGS_IF) != 0;
kvm_run->cr8 = kvm_get_cr8(vcpu);
kvm_run->apic_base = kvm_get_apic_base(vcpu);- if (irqchip_in_kernel(vcpu->kvm))
+ if (irqchip_in_kernel(vcpu->kvm)) {
+ int pending_vec;
+
kvm_run->ready_for_interrupt_injection = 1;
+ /*
+ * Sync userspace the acknoledge irqs that were
requested,
+ * remove irqs that were not yet injected (pending)
+ */
+ pending_vec = kvm_x86_ops->get_irq(vcpu);
+ if (pending_vec != -1 &&
+ test_bit(pending_vec, kvm_run->irq_acked))
+ set_bit(pending_vec,vcpu->arch.irq_ack_requests);
+ memcpy(kvm_run->irq_acked, vcpu->arch.irq_ack_requests,
+ sizeof(vcpu->arch.irq_ack_requests));
+ }
else
kvm_run->ready_for_interrupt_injection =(vcpu->arch.interrupt_window_open &&
@@ -2891,9 +2904,12 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
if (vcpu->sigset_active)
sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved);- /* re-sync apic's tpr */
if (!irqchip_in_kernel(vcpu->kvm))
+ /* re-sync apic's tpr */
kvm_set_cr8(vcpu, kvm_run->cr8);+ else
+ memcpy(vcpu->arch.irq_ack_requests, kvm_run->irq_acked,
+ sizeof(vcpu->arch.irq_ack_requests));
if (vcpu->arch.pio.cur_count) {
r = complete_pio(vcpu);include/asm-x86/kvm_host.h +0 -0
@@ -213,6 +213,8 @@ struct kvm_vcpu_arch {int interrupt_window_open;unsigned long irq_summary;/* bit vector: 1 per word in
irq_pending */
DECLARE_BITMAP(irq_pending, KVM_NR_INTERRUPTS);
+ DECLARE_BITMAP(irq_ack_requests, KVM_NR_INTERRUPTS);
+
unsigned long regs[NR_VCPU_REGS]; /* for rsp:vcpu_load_rsp_rip() */
unsigned long rip; /* needs vcpu_load_rsp_rip() */
include/linux/kvm.h +5 -0
@@ -141,6 +141,11 @@ struct kvm_run {/* Fix the size of the union. */ char padding[256 ]; }; + +/* Max architectural interrupt line count. */ +#define MAX_KVM_NR_INTERRUPTS 256 +/* in (pre_kvm_run), out (post_kvm_run) */ +__u64 irq_acked[(MAX_KVM_NR_INTERRUPTS +63 ) /64 ]; };/* for KVM_TRANSLATE */
Signature · 1 line
1.5.4.1
Quoted 1 line
From
c76378355d5478f89971b2fa8053a1891a503af6Mon Sep 17 00:00:00 2001
From: Dor Laor <[email protected]>
Date: Sun, 23 Mar 2008 15:20:49 +0200
Subject: [PATCH] [KVM] Return interrupt acknoledge info to userspace
User space device emulation for timers might be inaccurate and ause coalescing of several irq into one. It happens when the load on the host is high and the guest did not manage to ack the previous irq. By get/set request irq commands the device won't issue another irq before the previous one has been acknoledged.
Userspace will request information about acking certain irq vectors. Every vcpu will update this information in its vcpu_run structure, it is in/out variable.
Note that if there is pending irq that didn't manage to be injected, it is being cleared.
--- arch/x86/kvm/svm.c | 1 + arch/x86/kvm/vmx.c | 1 + arch/x86/kvm/x86.c | 20 ++++++++++++++++++-- include/asm-x86/kvm_host.h | 2 ++ include/linux/kvm.h | 5 +++++ 5 files changed, 27 insertions(+), 2 deletions(-)
arch/x86/kvm/svm.c +1 -0
@@ -1501,6 +1501,7 @@ static void svm_intr_assist(struct kvm_vcpu *vcpu) intr_vector =kvm_cpu_get_interrupt (vcpu);svm_inject_irq (svm, intr_vector);kvm_timer_intr_post (vcpu, intr_vector); +clear_bit (intr_vector, vcpu->arch.irq_ack_requests); }static void kvm_reput_irq (struct vcpu_svm *svm)
arch/x86/kvm/vmx.c +1 -0
@@ -2369,6 +2369,7 @@ static void vmx_intr_assist(struct kvm_vcpu *vcpu) vector =kvm_cpu_get_interrupt (vcpu);vmx_inject_irq (vcpu, vector);kvm_timer_intr_post (vcpu, vector); +clear_bit (vector, vcpu->arch.irq_ack_requests); }else enable_irq_window (vcpu); }
arch/x86/kvm/x86.c +18 -2
@@ -2689,8 +2689,21 @@ static void post_kvm_run_save(struct kvm_vcpu *vcpu, kvm_run->if_flag = (kvm_x86_ops->get_rflags (vcpu) &X86_EFLAGS_IF ) !=0 ; kvm_run->cr8 =kvm_get_cr8 (vcpu); kvm_run->apic_base =kvm_get_apic_base (vcpu); -if (irqchip_in_kernel (vcpu->kvm)) +if (irqchip_in_kernel (vcpu->kvm)) { +int pending_vec; + kvm_run->ready_for_interrupt_injection =1 ; +/* +* Sync userspace the acknoledge irqs that were requested, +* remove irqs that were not yet injected (pending) +*/ + pending_vec = kvm_x86_ops->get_irq (vcpu); +if (pending_vec !=-1 && +test_bit (pending_vec, kvm_run->irq_acked)) +set_bit (pending_vec, vcpu->arch.irq_ack_requests); +memcpy (kvm_run->irq_acked, vcpu->arch.irq_ack_requests, +sizeof (vcpu->arch.irq_ack_requests)); + }else kvm_run->ready_for_interrupt_injection = (vcpu->arch.interrupt_window_open &&
@@ -2891,9 +2904,12 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)if (vcpu->sigset_active)sigprocmask (SIG_SETMASK , &vcpu->sigset, &sigsaved); -/* re-sync apic's tpr */ if (!irqchip_in_kernel (vcpu->kvm)) +/* re-sync apic's tpr */ kvm_set_cr8 (vcpu, kvm_run->cr8); +else +memcpy (vcpu->arch.irq_ack_requests, kvm_run->irq_acked, +sizeof (vcpu->arch.irq_ack_requests));if (vcpu->arch.pio.cur_count) { r =complete_pio (vcpu);
include/asm-x86/kvm_host.h +2 -0
@@ -213,6 +213,8 @@ struct kvm_vcpu_arch {int interrupt_window_open;unsigned long irq_summary;/* bit vector: 1 per word in irq_pending */ DECLARE_BITMAP (irq_pending,KVM_NR_INTERRUPTS ); +DECLARE_BITMAP (irq_ack_requests,KVM_NR_INTERRUPTS ); +unsigned long regs[NR_VCPU_REGS ];/* for rsp: vcpu_load_rsp_rip() */ unsigned long rip;/* needs vcpu_load_rsp_rip() */
include/linux/kvm.h +5 -0
@@ -141,6 +141,11 @@ struct kvm_run {/* Fix the size of the union. */ char padding[256 ]; }; + +/* Max architectural interrupt line count. */ +#define MAX_KVM_NR_INTERRUPTS 256 +/* in (pre_kvm_run), out (post_kvm_run) */ +__u64 irq_acked[(MAX_KVM_NR_INTERRUPTS +63 ) /64 ]; };/* for KVM_TRANSLATE */
Signature · 1 line
1.5.4.1
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
kvm-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel