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 Enable MONITOR/MWAIT idle on AMD chips, exc...



details:   https://anonhg.NetBSD.org/src/rev/8a9a666d3494
branches:  trunk
changeset: 970802:8a9a666d3494
user:      ad <ad%NetBSD.org@localhost>
date:      Sat Apr 04 14:49:35 2020 +0000

description:
Enable MONITOR/MWAIT idle on AMD chips, except some buggy Ryzens.

diffstat:

 sys/arch/x86/x86/identcpu.c    |  39 +++++++++++++++++++++++++++++++--------
 sys/arch/x86/x86/x86_machdep.c |   7 +++----
 2 files changed, 34 insertions(+), 12 deletions(-)

diffs (105 lines):

diff -r 4d4b4d026ffe -r 8a9a666d3494 sys/arch/x86/x86/identcpu.c
--- a/sys/arch/x86/x86/identcpu.c       Sat Apr 04 14:45:37 2020 +0000
+++ b/sys/arch/x86/x86/identcpu.c       Sat Apr 04 14:49:35 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: identcpu.c,v 1.101 2020/04/03 22:45:30 ad Exp $        */
+/*     $NetBSD: identcpu.c,v 1.102 2020/04/04 14:49:35 ad 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.101 2020/04/03 22:45:30 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.102 2020/04/04 14:49:35 ad Exp $");
 
 #include "opt_xen.h"
 
@@ -362,19 +362,17 @@
 }
 
 static void
-cpu_probe_amd(struct cpu_info *ci)
+cpu_probe_amd_errata(struct cpu_info *ci)
 {
+       u_int model;
        uint64_t val;
        int flag;
 
-       if (cpu_vendor != CPUVENDOR_AMD)
-               return;
-       if (CPUID_TO_FAMILY(ci->ci_signature) < 5)
-               return;
+       model = CPUID_TO_MODEL(ci->ci_signature);
 
        switch (CPUID_TO_FAMILY(ci->ci_signature)) {
        case 0x05: /* K5 */
-               if (CPUID_TO_MODEL(ci->ci_signature) == 0) {
+               if (model == 0) {
                        /*
                         * According to the AMD Processor Recognition App Note,
                         * the AMD-K5 Model 0 uses the wrong bit to indicate
@@ -402,9 +400,34 @@
                        wrmsr(MSR_BU_CFG2, val);
                }
                break;
+
+       case 0x17:
+               /*
+                * "Revision Guide for AMD Family 17h Models 00h-0Fh
+                * Processors" revision 1.12:
+                *
+                * 1057 MWAIT or MWAITX Instructions May Fail to Correctly
+                * Exit From the Monitor Event Pending State
+                *
+                * 1109 MWAIT Instruction May Hang a Thread
+                */
+               if (model == 0x01) {
+                       cpu_feature[1] &= ~CPUID2_MONITOR;
+                       ci->ci_feat_val[1] &= ~CPUID2_MONITOR;
+               }
+               break;
        }
+}
+
+static void
+cpu_probe_amd(struct cpu_info *ci)
+{
+
+       if (cpu_vendor != CPUVENDOR_AMD)
+               return;
 
        cpu_probe_amd_cache(ci);
+       cpu_probe_amd_errata(ci);
 }
 
 static inline uint8_t
diff -r 4d4b4d026ffe -r 8a9a666d3494 sys/arch/x86/x86/x86_machdep.c
--- a/sys/arch/x86/x86/x86_machdep.c    Sat Apr 04 14:45:37 2020 +0000
+++ b/sys/arch/x86/x86/x86_machdep.c    Sat Apr 04 14:49:35 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: x86_machdep.c,v 1.135 2020/01/29 01:54:34 manu Exp $   */
+/*     $NetBSD: x86_machdep.c,v 1.136 2020/04/04 14:49:35 ad Exp $     */
 
 /*-
  * Copyright (c) 2002, 2006, 2007 YAMAMOTO Takashi,
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.135 2020/01/29 01:54:34 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.136 2020/04/04 14:49:35 ad Exp $");
 
 #include "opt_modular.h"
 #include "opt_physmem.h"
@@ -458,8 +458,7 @@
 {
 
 #ifndef XENPV
-       if ((cpu_feature[1] & CPUID2_MONITOR) == 0 ||
-           cpu_vendor == CPUVENDOR_AMD)
+       if ((cpu_feature[1] & CPUID2_MONITOR) == 0)
                x86_cpu_idle_set(x86_cpu_idle_halt, "halt", true);
        else
                x86_cpu_idle_set(x86_cpu_idle_mwait, "mwait", false);



Home | Main Index | Thread Index | Old Index