Skip to content

Commit

Permalink
KVM: x86: optimize delivery of TSC deadline timer interrupt
Browse files Browse the repository at this point in the history
The newly-added tracepoint shows the following results on
the tscdeadline_latency test:

        qemu-kvm-8387  [002]  6425.558974: kvm_vcpu_wakeup:      poll time 10407 ns
        qemu-kvm-8387  [002]  6425.558984: kvm_vcpu_wakeup:      poll time 0 ns
        qemu-kvm-8387  [002]  6425.561242: kvm_vcpu_wakeup:      poll time 10477 ns
        qemu-kvm-8387  [002]  6425.561251: kvm_vcpu_wakeup:      poll time 0 ns

and so on.  This is because we need to go through kvm_vcpu_block again
after the timer IRQ is injected.  Avoid it by polling once before
entering kvm_vcpu_block.

On my machine (Xeon E5 Sandy Bridge) this removes about 500 cycles (7%)
from the latency of the TSC deadline timer.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
Paolo Bonzini committed Apr 8, 2015
1 parent 362c698 commit 9c8fd1b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions arch/x86/kvm/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -6406,12 +6406,13 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)

static inline int vcpu_block(struct kvm *kvm, struct kvm_vcpu *vcpu)
{
srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx);
kvm_vcpu_block(vcpu);
vcpu->srcu_idx = srcu_read_lock(&kvm->srcu);

if (!kvm_check_request(KVM_REQ_UNHALT, vcpu))
return 1;
if (!kvm_arch_vcpu_runnable(vcpu)) {
srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx);
kvm_vcpu_block(vcpu);
vcpu->srcu_idx = srcu_read_lock(&kvm->srcu);
if (!kvm_check_request(KVM_REQ_UNHALT, vcpu))
return 1;
}

kvm_apic_accept_events(vcpu);
switch(vcpu->arch.mp_state) {
Expand Down

0 comments on commit 9c8fd1b

Please sign in to comment.