KVM: introduce kvm_vcpu_on_spin
authorZhai, Edwin <edwin.zhai@intel.com>
Fri, 9 Oct 2009 10:03:20 +0000 (18:03 +0800)
committerAvi Kivity <avi@redhat.com>
Thu, 3 Dec 2009 07:32:17 +0000 (09:32 +0200)
Introduce kvm_vcpu_on_spin, to be used by VMX/SVM to yield processing
once the cpu detects pause-based looping.

Signed-off-by: "Zhai, Edwin" <edwin.zhai@intel.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
include/linux/kvm_host.h
virt/kvm/kvm_main.c

index b985a29d8175fcf4a8d6e823687b740e6ffb27a2..bd5a616d937318dffb2a88ee0465873aef44adc7 100644 (file)
@@ -286,6 +286,7 @@ int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn);
 void mark_page_dirty(struct kvm *kvm, gfn_t gfn);
 
 void kvm_vcpu_block(struct kvm_vcpu *vcpu);
+void kvm_vcpu_on_spin(struct kvm_vcpu *vcpu);
 void kvm_resched(struct kvm_vcpu *vcpu);
 void kvm_load_guest_fpu(struct kvm_vcpu *vcpu);
 void kvm_put_guest_fpu(struct kvm_vcpu *vcpu);
index 70c8cbea0a99ad986503846aaf043f0ec20ff41c..cac69c4415dfcf9bb9d3b00108145bbed57f9405 100644 (file)
@@ -1108,6 +1108,21 @@ void kvm_resched(struct kvm_vcpu *vcpu)
 }
 EXPORT_SYMBOL_GPL(kvm_resched);
 
+void kvm_vcpu_on_spin(struct kvm_vcpu *vcpu)
+{
+       ktime_t expires;
+       DEFINE_WAIT(wait);
+
+       prepare_to_wait(&vcpu->wq, &wait, TASK_INTERRUPTIBLE);
+
+       /* Sleep for 100 us, and hope lock-holder got scheduled */
+       expires = ktime_add_ns(ktime_get(), 100000UL);
+       schedule_hrtimeout(&expires, HRTIMER_MODE_ABS);
+
+       finish_wait(&vcpu->wq, &wait);
+}
+EXPORT_SYMBOL_GPL(kvm_vcpu_on_spin);
+
 static int kvm_vcpu_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
        struct kvm_vcpu *vcpu = vma->vm_file->private_data;