Module Name: src Committed By: ad Date: Sat Apr 4 14:49:36 UTC 2020
Modified Files: src/sys/arch/x86/x86: identcpu.c x86_machdep.c Log Message: Enable MONITOR/MWAIT idle on AMD chips, except some buggy Ryzens. To generate a diff of this commit: cvs rdiff -u -r1.101 -r1.102 src/sys/arch/x86/x86/identcpu.c cvs rdiff -u -r1.135 -r1.136 src/sys/arch/x86/x86/x86_machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/x86/x86/identcpu.c diff -u src/sys/arch/x86/x86/identcpu.c:1.101 src/sys/arch/x86/x86/identcpu.c:1.102 --- src/sys/arch/x86/x86/identcpu.c:1.101 Fri Apr 3 22:45:30 2020 +++ src/sys/arch/x86/x86/identcpu.c Sat Apr 4 14:49:35 2020 @@ -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 @@ cpu_probe_amd_cache(struct cpu_info *ci) } 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 @@ cpu_probe_amd(struct cpu_info *ci) 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 Index: src/sys/arch/x86/x86/x86_machdep.c diff -u src/sys/arch/x86/x86/x86_machdep.c:1.135 src/sys/arch/x86/x86/x86_machdep.c:1.136 --- src/sys/arch/x86/x86/x86_machdep.c:1.135 Wed Jan 29 01:54:34 2020 +++ src/sys/arch/x86/x86/x86_machdep.c Sat Apr 4 14:49:35 2020 @@ -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 @@ x86_cpu_idle_init(void) { #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);