Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch Rename fpu_eagerswitch to fpu_switch, and add fpu_x...



details:   https://anonhg.NetBSD.org/src/rev/294a439511ee
branches:  trunk
changeset: 455006:294a439511ee
user:      maxv <maxv%NetBSD.org@localhost>
date:      Fri Oct 04 11:47:07 2019 +0000

description:
Rename fpu_eagerswitch to fpu_switch, and add fpu_xstate_reload to
simplify.

diffstat:

 sys/arch/amd64/amd64/locore.S |   4 +-
 sys/arch/i386/i386/locore.S   |   6 ++--
 sys/arch/x86/include/fpu.h    |   4 +--
 sys/arch/x86/x86/fpu.c        |  57 +++++++++++++++---------------------------
 4 files changed, 27 insertions(+), 44 deletions(-)

diffs (178 lines):

diff -r afab38868b06 -r 294a439511ee sys/arch/amd64/amd64/locore.S
--- a/sys/arch/amd64/amd64/locore.S     Fri Oct 04 11:43:07 2019 +0000
+++ b/sys/arch/amd64/amd64/locore.S     Fri Oct 04 11:47:07 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore.S,v 1.187 2019/10/03 05:06:29 maxv Exp $        */
+/*     $NetBSD: locore.S,v 1.188 2019/10/04 11:47:07 maxv Exp $        */
 
 /*
  * Copyright-o-rama!
@@ -1150,7 +1150,7 @@
        /* Switch the FPU. */
        movq    %r13,%rdi
        movq    %r12,%rsi
-       callq   _C_LABEL(fpu_eagerswitch)
+       callq   _C_LABEL(fpu_switch)
 
        /* Don't bother with the rest if switching to a system process. */
        testl   $LW_SYSTEM,L_FLAG(%r12)
diff -r afab38868b06 -r 294a439511ee sys/arch/i386/i386/locore.S
--- a/sys/arch/i386/i386/locore.S       Fri Oct 04 11:43:07 2019 +0000
+++ b/sys/arch/i386/i386/locore.S       Fri Oct 04 11:47:07 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore.S,v 1.169 2019/10/03 05:06:29 maxv Exp $        */
+/*     $NetBSD: locore.S,v 1.170 2019/10/04 11:47:07 maxv Exp $        */
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.169 2019/10/03 05:06:29 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.170 2019/10/04 11:47:07 maxv Exp $");
 
 #include "opt_copy_symtab.h"
 #include "opt_ddb.h"
@@ -1141,7 +1141,7 @@
        pushl   %edx
        pushl   %edi
        pushl   %esi
-       call    _C_LABEL(fpu_eagerswitch)
+       call    _C_LABEL(fpu_switch)
        addl    $8,%esp
        popl    %edx
 
diff -r afab38868b06 -r 294a439511ee sys/arch/x86/include/fpu.h
--- a/sys/arch/x86/include/fpu.h        Fri Oct 04 11:43:07 2019 +0000
+++ b/sys/arch/x86/include/fpu.h        Fri Oct 04 11:47:07 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fpu.h,v 1.17 2019/06/26 12:30:13 mgorny Exp $  */
+/*     $NetBSD: fpu.h,v 1.18 2019/10/04 11:47:08 maxv Exp $    */
 
 #ifndef        _X86_FPU_H_
 #define        _X86_FPU_H_
@@ -20,8 +20,6 @@
 void fpusave_lwp(struct lwp *, bool);
 void fpusave_cpu(bool);
 
-void fpu_eagerswitch(struct lwp *, struct lwp *);
-
 void fpu_set_default_cw(struct lwp *, unsigned int);
 
 void fputrap(struct trapframe *);
diff -r afab38868b06 -r 294a439511ee sys/arch/x86/x86/fpu.c
--- a/sys/arch/x86/x86/fpu.c    Fri Oct 04 11:43:07 2019 +0000
+++ b/sys/arch/x86/x86/fpu.c    Fri Oct 04 11:47:07 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fpu.c,v 1.56 2019/10/03 05:06:29 maxv Exp $    */
+/*     $NetBSD: fpu.c,v 1.57 2019/10/04 11:47:08 maxv Exp $    */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.  All
@@ -96,7 +96,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.56 2019/10/03 05:06:29 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.57 2019/10/04 11:47:08 maxv Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -267,8 +267,10 @@
        fpu_area_restore(&pcb->pcb_savefpu, x86_xsave_features);
 }
 
+void fpu_switch(struct lwp *, struct lwp *);
+
 void
-fpu_eagerswitch(struct lwp *oldlwp, struct lwp *newlwp)
+fpu_switch(struct lwp *oldlwp, struct lwp *newlwp)
 {
        int s;
 
@@ -536,6 +538,17 @@
        }
 }
 
+static inline void
+fpu_xstate_reload(union savefpu *fpu_save, uint64_t xstate)
+{
+       /*
+        * Force a reload of the given xstate during the next XRSTOR.
+        */
+       if (x86_fpu_save >= FPU_SAVE_XSAVE) {
+               fpu_save->sv_xsave_hdr.xsh_xstate_bv |= xstate;
+       }
+}
+
 void
 fpu_set_default_cw(struct lwp *l, unsigned int x87_cw)
 {
@@ -544,13 +557,8 @@
 
        if (i386_use_fxsave) {
                fpu_save->sv_xmm.fx_cw = x87_cw;
-
-               /* Force a reload of CW */
-               if ((x87_cw != __INITIAL_NPXCW__) &&
-                   (x86_fpu_save == FPU_SAVE_XSAVE ||
-                   x86_fpu_save == FPU_SAVE_XSAVEOPT)) {
-                       fpu_save->sv_xsave_hdr.xsh_xstate_bv |=
-                           XCR0_X87;
+               if (x87_cw != __INITIAL_NPXCW__) {
+                       fpu_xstate_reload(fpu_save, XCR0_X87);
                }
        } else {
                fpu_save->sv_87.s87_cw = x87_cw;
@@ -594,14 +602,8 @@
                fpu_save->sv_xmm.fx_mxcsr = __INITIAL_MXCSR__;
                fpu_save->sv_xmm.fx_mxcsr_mask = x86_fpu_mxcsr_mask;
                fpu_save->sv_xmm.fx_cw = x87_cw;
-
-               /*
-                * Force a reload of CW if we're using the non-default
-                * value.
-                */
                if (__predict_false(x87_cw != __INITIAL_NPXCW__)) {
-                       fpu_save->sv_xsave_hdr.xsh_xstate_bv |=
-                           XCR0_X87;
+                       fpu_xstate_reload(fpu_save, XCR0_X87);
                }
                break;
        }
@@ -781,15 +783,7 @@
                fpu_save->sv_xmm.fx_mxcsr_mask &= x86_fpu_mxcsr_mask;
                fpu_save->sv_xmm.fx_mxcsr &= fpu_save->sv_xmm.fx_mxcsr_mask;
 
-               /*
-                * Make sure the x87 and SSE bits are set in xstate_bv.
-                * Otherwise xrstor will not restore them.
-                */
-               if (x86_fpu_save == FPU_SAVE_XSAVE ||
-                   x86_fpu_save == FPU_SAVE_XSAVEOPT) {
-                       fpu_save->sv_xsave_hdr.xsh_xstate_bv |=
-                           (XCR0_X87 | XCR0_SSE);
-               }
+               fpu_xstate_reload(fpu_save, XCR0_X87 | XCR0_SSE);
        } else {
                process_xmm_to_s87(fpregs, &fpu_save->sv_87);
        }
@@ -805,16 +799,7 @@
                fpusave_lwp(l, true);
                fpu_save = lwp_fpuarea(l);
                process_s87_to_xmm(fpregs, &fpu_save->sv_xmm);
-
-               /*
-                * Make sure the x87 and SSE bits are set in xstate_bv.
-                * Otherwise xrstor will not restore them.
-                */
-               if (x86_fpu_save == FPU_SAVE_XSAVE ||
-                   x86_fpu_save == FPU_SAVE_XSAVEOPT) {
-                       fpu_save->sv_xsave_hdr.xsh_xstate_bv |=
-                           (XCR0_X87 | XCR0_SSE);
-               }
+               fpu_xstate_reload(fpu_save, XCR0_X87 | XCR0_SSE);
        } else {
                fpusave_lwp(l, false);
                fpu_save = lwp_fpuarea(l);



Home | Main Index | Thread Index | Old Index