Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/x86/x86 Always use x86_fpu_save, clearer.



details:   https://anonhg.NetBSD.org/src/rev/bac9e4d17f75
branches:  trunk
changeset: 827508:bac9e4d17f75
user:      maxv <maxv%NetBSD.org@localhost>
date:      Tue Oct 31 11:37:05 2017 +0000

description:
Always use x86_fpu_save, clearer.

diffstat:

 sys/arch/x86/x86/fpu.c      |  43 +++++++++++++++++++++++++++----------------
 sys/arch/x86/x86/identcpu.c |  11 +++++++----
 2 files changed, 34 insertions(+), 20 deletions(-)

diffs (133 lines):

diff -r 6190ff3a57f1 -r bac9e4d17f75 sys/arch/x86/x86/fpu.c
--- a/sys/arch/x86/x86/fpu.c    Tue Oct 31 10:46:47 2017 +0000
+++ b/sys/arch/x86/x86/fpu.c    Tue Oct 31 11:37:05 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fpu.c,v 1.15 2017/10/31 10:35:58 maxv Exp $    */
+/*     $NetBSD: fpu.c,v 1.16 2017/10/31 11:37:05 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.15 2017/10/31 10:35:58 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.16 2017/10/31 11:37:05 maxv Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -368,10 +368,12 @@
        ci->ci_fpcurlwp = l;
        pcb->pcb_fpcpu = ci;
 
-       if (i386_use_fxsave) {
-               if (x86_xsave_features != 0) {
-                       xrstor(&pcb->pcb_savefpu, x86_xsave_features);
-               } else {
+       switch (x86_fpu_save) {
+               case FPU_SAVE_FSAVE:
+                       frstor(&pcb->pcb_savefpu);
+                       break;
+
+               case FPU_SAVE_FXSAVE:
                        /*
                         * AMD FPU's do not restore FIP, FDP, and FOP on
                         * fxrstor, leaking other process's execution history.
@@ -384,11 +386,13 @@
                        if (fngetsw() & 0x80)
                                fnclex();
                        fldummy();
+                       fxrstor(&pcb->pcb_savefpu);
+                       break;
 
-                       fxrstor(&pcb->pcb_savefpu);
-               }
-       } else {
-               frstor(&pcb->pcb_savefpu);
+               case FPU_SAVE_XSAVE:
+               case FPU_SAVE_XSAVEOPT:
+                       xrstor(&pcb->pcb_savefpu, x86_xsave_features);
+                       break;
        }
 
        KASSERT(ci == curcpu());
@@ -416,13 +420,20 @@
 
        if (save) {
                clts();
-               if (i386_use_fxsave) {
-                       if (x86_xsave_features != 0)
+
+               switch (x86_fpu_save) {
+                       case FPU_SAVE_FSAVE:
+                               fnsave(&pcb->pcb_savefpu);
+                               break;
+
+                       case FPU_SAVE_FXSAVE:
+                               fxsave(&pcb->pcb_savefpu);
+                               break;
+
+                       case FPU_SAVE_XSAVE:
+                       case FPU_SAVE_XSAVEOPT:
                                xsave(&pcb->pcb_savefpu, x86_xsave_features);
-                       else
-                               fxsave(&pcb->pcb_savefpu);
-               } else {
-                       fnsave(&pcb->pcb_savefpu);
+                               break;
                }
        }
 
diff -r 6190ff3a57f1 -r bac9e4d17f75 sys/arch/x86/x86/identcpu.c
--- a/sys/arch/x86/x86/identcpu.c       Tue Oct 31 10:46:47 2017 +0000
+++ b/sys/arch/x86/x86/identcpu.c       Tue Oct 31 11:37:05 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: identcpu.c,v 1.60 2017/10/09 17:49:28 maya Exp $       */
+/*     $NetBSD: identcpu.c,v 1.61 2017/10/31 11:37:05 maxv Exp $       */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.60 2017/10/09 17:49:28 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.61 2017/10/31 11:37:05 maxv Exp $");
 
 #include "opt_xen.h"
 
@@ -64,7 +64,7 @@
 int cpu_vendor;
 char cpu_brand_string[49];
 
-int x86_fpu_save __read_mostly = FPU_SAVE_FSAVE;
+int x86_fpu_save __read_mostly;
 unsigned int x86_fpu_save_size __read_mostly = 512;
 uint64_t x86_xsave_features __read_mostly = 0;
 
@@ -723,6 +723,8 @@
 {
        u_int descs[4];
 
+       x86_fpu_save = FPU_SAVE_FSAVE;
+
 #ifdef i386 /* amd64 always has fxsave, sse and sse2 */
        /* If we have FXSAVE/FXRESTOR, use them. */
        if ((ci->ci_feat_val[0] & CPUID_FXSR) == 0) {
@@ -750,7 +752,7 @@
 
        x86_fpu_save = FPU_SAVE_FXSAVE;
 
-       /* See if xsave (for AVX is supported) */
+       /* See if xsave (for AVX) is supported */
        if ((ci->ci_feat_val[1] & CPUID2_XSAVE) == 0)
                return;
 
@@ -768,6 +770,7 @@
 
 #ifdef XEN
        /* Don't use xsave, force fxsave with x86_xsave_features = 0. */
+       x86_fpu_save = FPU_SAVE_FXSAVE;
 #else
        x86_xsave_features = (uint64_t)descs[3] << 32 | descs[0];
 #endif



Home | Main Index | Thread Index | Old Index