kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kvm/fpu: Enable fully eager restore kvm FPU
@ 2012-08-16  5:14 Xudong Hao
  2012-08-16  9:08 ` Avi Kivity
  0 siblings, 1 reply; 13+ messages in thread
From: Xudong Hao @ 2012-08-16  5:14 UTC (permalink / raw)
  To: avi; +Cc: kvm, xiantao.zhang, Xudong Hao

Enable KVM FPU fully eager restore, if there is other FPU state which isn't tracked by
CR0.TS bit.

Tested with these cases:
1) SpecCPU2000 workload( 1 VM, 2 VMs)
2) Program for floating point caculate

Signed-off-by: Xudong Hao <xudong.hao@intel.com>
---
 arch/x86/include/asm/kvm.h |    4 ++++
 arch/x86/kvm/x86.c         |   13 ++++++++++++-
 2 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/arch/x86/include/asm/kvm.h b/arch/x86/include/asm/kvm.h
index 246617e..91aa1cd 100644
--- a/arch/x86/include/asm/kvm.h
+++ b/arch/x86/include/asm/kvm.h
@@ -8,6 +8,8 @@
 
 #include <linux/types.h>
 #include <linux/ioctl.h>
+#include <asm/user.h>
+#include <asm/xsave.h>
 
 /* Select x86 specific features in <linux/kvm.h> */
 #define __KVM_HAVE_PIT
@@ -29,6 +31,8 @@
 /* Architectural interrupt line count. */
 #define KVM_NR_INTERRUPTS 256
 
+#define KVM_XSTATE_LAZY	(XSTATE_FP | XSTATE_SSE | XSTATE_YMM)
+
 struct kvm_memory_alias {
 	__u32 slot;  /* this has a different namespace than memory slots */
 	__u32 flags;
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index b6379e5..2e628e5 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -5966,7 +5966,18 @@ void kvm_put_guest_fpu(struct kvm_vcpu *vcpu)
 	vcpu->guest_fpu_loaded = 0;
 	fpu_save_init(&vcpu->arch.guest_fpu);
 	++vcpu->stat.fpu_reload;
-	kvm_make_request(KVM_REQ_DEACTIVATE_FPU, vcpu);
+	/*
+	 * Currently KVM trigger FPU restore by #NM (via CR0.TS),
+	 * till now only XCR0.bit0, XCR0.bit1, XCR0.bit2 is tracked
+	 * by TS bit, there might be other FPU state is not tracked
+	 * by TS bit. Here it only make FPU deactivate request and do 
+	 * FPU lazy restore for these cases: 1)xsave isn't enabled 
+	 * in guest, 2)all guest FPU states can be tracked by TS bit.
+	 * For others, doing fully FPU eager restore.
+	 */
+	if (!kvm_read_cr4_bits(vcpu, X86_CR4_OSXSAVE) ||
+		!(vcpu->arch.xcr0 & ~KVM_XSTATE_LAZY))
+		kvm_make_request(KVM_REQ_DEACTIVATE_FPU, vcpu);
 	trace_kvm_fpu(0);
 }
 
-- 
1.5.5


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2012-09-05  1:10 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-16  5:14 [PATCH] kvm/fpu: Enable fully eager restore kvm FPU Xudong Hao
2012-08-16  9:08 ` Avi Kivity
2012-08-16  9:48   ` Hao, Xudong
2012-08-16 10:59     ` Avi Kivity
2012-08-16 11:50       ` Hao, Xudong
2012-08-20  9:24       ` Roedel, Joerg
2012-08-20 10:08         ` Avi Kivity
2012-08-20 10:14           ` Roedel, Joerg
2012-08-20 10:43             ` Avi Kivity
2012-08-20 10:53               ` Roedel, Joerg
2012-08-23  8:51               ` Hao, Xudong
2012-09-03  9:23                 ` Avi Kivity
2012-09-05  1:10                   ` Hao, Xudong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).