diff options
author | Avi Kivity <avi@redhat.com> | 2009-06-16 05:33:56 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2009-09-10 01:32:57 -0400 |
commit | d3edefc0035669e8817d1d5c32ef03e882477323 (patch) | |
tree | 7fde2dfa8f43e1619e0d31549e54fef4d19a374d /arch/x86/kvm/vmx.c | |
parent | 681405bfc73a2717ae9b03b2bad465b009106f31 (diff) |
KVM: VMX: Only reload guest cr2 if different from host cr2
cr2 changes only rarely, and writing it is expensive. Avoid the costly cr2
writes by checking if it does not already hold the desired value.
Shaves 70 cycles off the vmexit latency.
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86/kvm/vmx.c')
-rw-r--r-- | arch/x86/kvm/vmx.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index fc8d49c6bc51..1a84ca191cd1 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c | |||
@@ -3651,11 +3651,16 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) | |||
3651 | "mov %%"R"sp, %c[host_rsp](%0) \n\t" | 3651 | "mov %%"R"sp, %c[host_rsp](%0) \n\t" |
3652 | __ex(ASM_VMX_VMWRITE_RSP_RDX) "\n\t" | 3652 | __ex(ASM_VMX_VMWRITE_RSP_RDX) "\n\t" |
3653 | "1: \n\t" | 3653 | "1: \n\t" |
3654 | /* Reload cr2 if changed */ | ||
3655 | "mov %c[cr2](%0), %%"R"ax \n\t" | ||
3656 | "mov %%cr2, %%"R"dx \n\t" | ||
3657 | "cmp %%"R"ax, %%"R"dx \n\t" | ||
3658 | "je 2f \n\t" | ||
3659 | "mov %%"R"ax, %%cr2 \n\t" | ||
3660 | "2: \n\t" | ||
3654 | /* Check if vmlaunch of vmresume is needed */ | 3661 | /* Check if vmlaunch of vmresume is needed */ |
3655 | "cmpl $0, %c[launched](%0) \n\t" | 3662 | "cmpl $0, %c[launched](%0) \n\t" |
3656 | /* Load guest registers. Don't clobber flags. */ | 3663 | /* Load guest registers. Don't clobber flags. */ |
3657 | "mov %c[cr2](%0), %%"R"ax \n\t" | ||
3658 | "mov %%"R"ax, %%cr2 \n\t" | ||
3659 | "mov %c[rax](%0), %%"R"ax \n\t" | 3664 | "mov %c[rax](%0), %%"R"ax \n\t" |
3660 | "mov %c[rbx](%0), %%"R"bx \n\t" | 3665 | "mov %c[rbx](%0), %%"R"bx \n\t" |
3661 | "mov %c[rdx](%0), %%"R"dx \n\t" | 3666 | "mov %c[rdx](%0), %%"R"dx \n\t" |