[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] x86/fpu: create lazy and non-lazy FPU restore functions
# HG changeset patch # User Wei Huang <wei.huang2@xxxxxxx> # Date 1304937563 -3600 # Node ID 103f89fef2942fc44887a777064532aaa9a1f90d # Parent 631bdf00a81f2099233ca3146c8c7383511aba0f x86/fpu: create lazy and non-lazy FPU restore functions Currently Xen relies on #NM (via CR0.TS) to trigger FPU context restore. But not all FPU state is tracked by TS bit. This function creates two FPU restore functions: vcpu_restore_fpu_lazy() and vcpu_restore_fpu_eager(). vcpu_restore_fpu_lazy() is still used when #NM is triggered. vcpu_restore_fpu_eager(), as a comparision, is called for vcpu which is being scheduled in on every context switch. To minimize restore overhead, it creates a flag, nonlazy_xstate_used, to control non-lazy restore. Signed-off-by: Wei Huang <wei.huang2@xxxxxxx> --- diff -r 631bdf00a81f -r 103f89fef294 xen/arch/x86/domain.c --- a/xen/arch/x86/domain.c Mon May 09 11:38:55 2011 +0100 +++ b/xen/arch/x86/domain.c Mon May 09 11:39:23 2011 +0100 @@ -1566,6 +1566,7 @@ memcpy(stack_regs, &n->arch.user_regs, CTXT_SWITCH_STACK_BYTES); if ( xsave_enabled(n) && n->arch.xcr0 != get_xcr0() ) set_xcr0(n->arch.xcr0); + vcpu_restore_fpu_eager(n); n->arch.ctxt_switch_to(n); } diff -r 631bdf00a81f -r 103f89fef294 xen/arch/x86/hvm/svm/svm.c --- a/xen/arch/x86/hvm/svm/svm.c Mon May 09 11:38:55 2011 +0100 +++ b/xen/arch/x86/hvm/svm/svm.c Mon May 09 11:39:23 2011 +0100 @@ -348,7 +348,7 @@ { struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb; - vcpu_restore_fpu(v); + vcpu_restore_fpu_lazy(v); vmcb_set_exception_intercepts( vmcb, vmcb_get_exception_intercepts(vmcb) & ~(1U << TRAP_no_device)); } diff -r 631bdf00a81f -r 103f89fef294 xen/arch/x86/hvm/vmx/vmx.c --- a/xen/arch/x86/hvm/vmx/vmx.c Mon May 09 11:38:55 2011 +0100 +++ b/xen/arch/x86/hvm/vmx/vmx.c Mon May 09 11:39:23 2011 +0100 @@ -612,7 +612,7 @@ static void vmx_fpu_enter(struct vcpu *v) { - vcpu_restore_fpu(v); + vcpu_restore_fpu_lazy(v); v->arch.hvm_vmx.exception_bitmap &= ~(1u << TRAP_no_device); vmx_update_exception_bitmap(v); v->arch.hvm_vmx.host_cr0 &= ~X86_CR0_TS; diff -r 631bdf00a81f -r 103f89fef294 xen/arch/x86/i387.c --- a/xen/arch/x86/i387.c Mon May 09 11:38:55 2011 +0100 +++ b/xen/arch/x86/i387.c Mon May 09 11:39:23 2011 +0100 @@ -98,13 +98,13 @@ /* FPU Save Functions */ /*******************************/ /* Save x87 extended state */ -static inline void fpu_xsave(struct vcpu *v, uint64_t mask) +static inline void fpu_xsave(struct vcpu *v) { /* XCR0 normally represents what guest OS set. In case of Xen itself, * we set all accumulated feature mask before doing save/restore. */ set_xcr0(v->arch.xcr0_accum); - xsave(v, mask); + xsave(v, v->arch.nonlazy_xstate_used ? XSTATE_ALL : XSTATE_LAZY); set_xcr0(v->arch.xcr0); } @@ -160,10 +160,25 @@ /*******************************/ /* VCPU FPU Functions */ /*******************************/ +/* Restore FPU state whenever VCPU is schduled in. */ +void vcpu_restore_fpu_eager(struct vcpu *v) +{ + ASSERT(!is_idle_vcpu(v)); + + /* save the nonlazy extended state which is not tracked by CR0.TS bit */ + if ( v->arch.nonlazy_xstate_used ) + { + /* Avoid recursion */ + clts(); + fpu_xrstor(v, XSTATE_NONLAZY); + stts(); + } +} + /* * Restore FPU state when #NM is triggered. */ -void vcpu_restore_fpu(struct vcpu *v) +void vcpu_restore_fpu_lazy(struct vcpu *v) { ASSERT(!is_idle_vcpu(v)); @@ -174,7 +189,7 @@ return; if ( xsave_enabled(v) ) - fpu_xrstor(v, XSTATE_ALL); + fpu_xrstor(v, XSTATE_LAZY); else if ( v->fpu_initialised ) { if ( cpu_has_fxsr ) @@ -204,7 +219,7 @@ clts(); if ( xsave_enabled(v) ) - fpu_xsave(v, XSTATE_ALL); + fpu_xsave(v); else if ( cpu_has_fxsr ) fpu_fxsave(v); else diff -r 631bdf00a81f -r 103f89fef294 xen/arch/x86/traps.c --- a/xen/arch/x86/traps.c Mon May 09 11:38:55 2011 +0100 +++ b/xen/arch/x86/traps.c Mon May 09 11:39:23 2011 +0100 @@ -3198,7 +3198,7 @@ BUG_ON(!guest_mode(regs)); - vcpu_restore_fpu(curr); + vcpu_restore_fpu_lazy(curr); if ( curr->arch.pv_vcpu.ctrlreg[0] & X86_CR0_TS ) { diff -r 631bdf00a81f -r 103f89fef294 xen/include/asm-x86/domain.h --- a/xen/include/asm-x86/domain.h Mon May 09 11:38:55 2011 +0100 +++ b/xen/include/asm-x86/domain.h Mon May 09 11:39:23 2011 +0100 @@ -492,7 +492,10 @@ * it explicitly enables it via xcr0. */ uint64_t xcr0_accum; - + /* This variable determines whether nonlazy extended state has been used, + * and thus should be saved/restored. */ + bool_t nonlazy_xstate_used; + struct paging_vcpu paging; #ifdef CONFIG_X86_32 diff -r 631bdf00a81f -r 103f89fef294 xen/include/asm-x86/i387.h --- a/xen/include/asm-x86/i387.h Mon May 09 11:38:55 2011 +0100 +++ b/xen/include/asm-x86/i387.h Mon May 09 11:39:23 2011 +0100 @@ -14,7 +14,8 @@ #include <xen/types.h> #include <xen/percpu.h> -void vcpu_restore_fpu(struct vcpu *v); +void vcpu_restore_fpu_eager(struct vcpu *v); +void vcpu_restore_fpu_lazy(struct vcpu *v); void vcpu_save_fpu(struct vcpu *v); int vcpu_init_fpu(struct vcpu *v); _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |