Module Name: src Committed By: rmind Date: Thu Apr 30 00:07:23 UTC 2009
Modified Files: src/sys/arch/x86/conf: files.x86 src/sys/arch/x86/include: cpu.h src/sys/arch/x86/x86: identcpu.c Added Files: src/sys/arch/x86/x86: cpu_topology.c Log Message: Move x86 CPU topology detection code into the separate file (as it was originally). OK by <yamt>. To generate a diff of this commit: cvs rdiff -u -r1.51 -r1.52 src/sys/arch/x86/conf/files.x86 cvs rdiff -u -r1.16 -r1.17 src/sys/arch/x86/include/cpu.h cvs rdiff -u -r0 -r1.1 src/sys/arch/x86/x86/cpu_topology.c cvs rdiff -u -r1.15 -r1.16 src/sys/arch/x86/x86/identcpu.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/conf/files.x86 diff -u src/sys/arch/x86/conf/files.x86:1.51 src/sys/arch/x86/conf/files.x86:1.52 --- src/sys/arch/x86/conf/files.x86:1.51 Fri Apr 17 21:07:58 2009 +++ src/sys/arch/x86/conf/files.x86 Thu Apr 30 00:07:23 2009 @@ -1,4 +1,4 @@ -# $NetBSD: files.x86,v 1.51 2009/04/17 21:07:58 dyoung Exp $ +# $NetBSD: files.x86,v 1.52 2009/04/30 00:07:23 rmind Exp $ # options for MP configuration through the MP spec defflag opt_mpbios.h MPBIOS MPVERBOSE MPDEBUG MPBIOS_SCANPCI @@ -49,6 +49,7 @@ file arch/x86/x86/bus_space.c file arch/x86/x86/consinit.c file arch/x86/x86/core_machdep.c coredump +file arch/x86/x86/cpu_topology.c file arch/x86/x86/errata.c file arch/x86/x86/genfb_machdep.c file arch/x86/x86/identcpu.c Index: src/sys/arch/x86/include/cpu.h diff -u src/sys/arch/x86/include/cpu.h:1.16 src/sys/arch/x86/include/cpu.h:1.17 --- src/sys/arch/x86/include/cpu.h:1.16 Sun Apr 19 14:11:37 2009 +++ src/sys/arch/x86/include/cpu.h Thu Apr 30 00:07:23 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: cpu.h,v 1.16 2009/04/19 14:11:37 ad Exp $ */ +/* $NetBSD: cpu.h,v 1.17 2009/04/30 00:07:23 rmind Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -353,6 +353,9 @@ void cpu_probe(struct cpu_info *); void cpu_identify(struct cpu_info *); +/* cpu_topology.c */ +void x86_cpu_toplogy(struct cpu_info *); + /* vm_machdep.c */ void cpu_proc_fork(struct proc *, struct proc *); Index: src/sys/arch/x86/x86/identcpu.c diff -u src/sys/arch/x86/x86/identcpu.c:1.15 src/sys/arch/x86/x86/identcpu.c:1.16 --- src/sys/arch/x86/x86/identcpu.c:1.15 Wed Apr 1 03:56:54 2009 +++ src/sys/arch/x86/x86/identcpu.c Thu Apr 30 00:07:23 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: identcpu.c,v 1.15 2009/04/01 03:56:54 tls Exp $ */ +/* $NetBSD: identcpu.c,v 1.16 2009/04/30 00:07:23 rmind Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -29,34 +29,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -/*- - * Copyright (c)2008 YAMAMOTO Takashi, - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.15 2009/04/01 03:56:54 tls Exp $"); +__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.16 2009/04/30 00:07:23 rmind Exp $"); #include "opt_enhanced_speedstep.h" #include "opt_intel_odcm.h" @@ -70,7 +44,6 @@ #include <sys/param.h> #include <sys/systm.h> #include <sys/device.h> -#include <sys/bitops.h> #include <uvm/uvm_extern.h> @@ -131,55 +104,6 @@ return (NULL); } -static void -cpu_probe_p6(struct cpu_info *ci) -{ - u_int lp_max = 1; /* logical processors per package */ - u_int smt_max; /* smt per core */ - u_int core_max = 1; /* core per package */ - int smt_bits, core_bits; - uint32_t descs[4]; - - if (cpu_vendor != CPUVENDOR_INTEL || - CPUID2FAMILY(ci->ci_signature) < 6) - return; - - /* Determine the extended feature flags. */ - x86_cpuid(0x80000000, descs); - if (descs[0] >= 0x80000001) { - x86_cpuid(0x80000001, descs); - ci->ci_feature3_flags |= descs[3]; /* %edx */ - } - - /* Determine topology. 253668.pdf 7.10.2. */ - ci->ci_packageid = ci->ci_initapicid; - ci->ci_coreid = 0; - ci->ci_smtid = 0; - if ((ci->ci_feature_flags & CPUID_HTT) != 0) { - x86_cpuid(1, descs); - lp_max = (descs[1] >> 16) & 0xff; - } - x86_cpuid(0, descs); - if (descs[0] >= 4) { - x86_cpuid2(4, 0, descs); - core_max = (descs[0] >> 26) + 1; - } - KASSERT(lp_max >= core_max); - smt_max = lp_max / core_max; - smt_bits = ilog2(smt_max - 1) + 1; - core_bits = ilog2(core_max - 1) + 1; - if (smt_bits + core_bits) { - ci->ci_packageid = ci->ci_initapicid >> (smt_bits + core_bits); - } - if (core_bits) { - u_int core_mask = __BITS(smt_bits, smt_bits + core_bits - 1); - ci->ci_coreid = __SHIFTOUT(ci->ci_initapicid, core_mask); - } - if (smt_bits) { - u_int smt_mask = __BITS(0, smt_bits - 1); - ci->ci_smtid = __SHIFTOUT(ci->ci_initapicid, smt_mask); - } -} static void cpu_probe_amd_cache(struct cpu_info *ci) @@ -720,7 +644,6 @@ } } - cpu_probe_p6(ci); cpu_probe_k5(ci); cpu_probe_k678(ci); cpu_probe_cyrix(ci); @@ -728,6 +651,8 @@ cpu_probe_c3(ci); cpu_probe_geode(ci); + x86_cpu_toplogy(ci); + if (cpu_vendor != CPUVENDOR_AMD && (ci->ci_feature_flags & CPUID_TM) && (rdmsr(MSR_MISC_ENABLE) & (1 << 3)) == 0) { /* Enable thermal monitor 1. */ Added files: Index: src/sys/arch/x86/x86/cpu_topology.c diff -u /dev/null src/sys/arch/x86/x86/cpu_topology.c:1.1 --- /dev/null Thu Apr 30 00:07:23 2009 +++ src/sys/arch/x86/x86/cpu_topology.c Thu Apr 30 00:07:23 2009 @@ -0,0 +1,90 @@ +/* $NetBSD: cpu_topology.c,v 1.1 2009/04/30 00:07:23 rmind Exp $ */ + +/*- + * Copyright (c)2008 YAMAMOTO Takashi, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: cpu_topology.c,v 1.1 2009/04/30 00:07:23 rmind Exp $"); + +#include <sys/param.h> +#include <sys/bitops.h> + +#include <machine/specialreg.h> +#include <machine/cpu.h> + +#include <x86/cpufunc.h> +#include <x86/cputypes.h> +#include <x86/cpuvar.h> + +void +x86_cpu_toplogy(struct cpu_info *ci) +{ + u_int lp_max = 1; /* logical processors per package */ + u_int smt_max; /* smt per core */ + u_int core_max = 1; /* core per package */ + int smt_bits, core_bits; + uint32_t descs[4]; + + if (cpu_vendor != CPUVENDOR_INTEL || + CPUID2FAMILY(ci->ci_signature) < 6) + return; + + /* Determine the extended feature flags. */ + x86_cpuid(0x80000000, descs); + if (descs[0] >= 0x80000001) { + x86_cpuid(0x80000001, descs); + ci->ci_feature3_flags |= descs[3]; /* %edx */ + } + + /* Determine topology. 253668.pdf 7.10.2. */ + ci->ci_packageid = ci->ci_initapicid; + ci->ci_coreid = 0; + ci->ci_smtid = 0; + if ((ci->ci_feature_flags & CPUID_HTT) != 0) { + x86_cpuid(1, descs); + lp_max = (descs[1] >> 16) & 0xff; + } + x86_cpuid(0, descs); + if (descs[0] >= 4) { + x86_cpuid2(4, 0, descs); + core_max = (descs[0] >> 26) + 1; + } + KASSERT(lp_max >= core_max); + smt_max = lp_max / core_max; + smt_bits = ilog2(smt_max - 1) + 1; + core_bits = ilog2(core_max - 1) + 1; + if (smt_bits + core_bits) { + ci->ci_packageid = ci->ci_initapicid >> (smt_bits + core_bits); + } + if (core_bits) { + u_int core_mask = __BITS(smt_bits, smt_bits + core_bits - 1); + ci->ci_coreid = __SHIFTOUT(ci->ci_initapicid, core_mask); + } + if (smt_bits) { + u_int smt_mask = __BITS(0, smt_bits - 1); + ci->ci_smtid = __SHIFTOUT(ci->ci_initapicid, smt_mask); + } +}