Source-Changes-HG archive

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

[src/netbsd-8]: src/sys/arch/x86/x86 Pull up following revision(s) (requested...



details:   https://anonhg.NetBSD.org/src/rev/dc5243edebf6
branches:  netbsd-8
changeset: 434863:dc5243edebf6
user:      martin <martin%NetBSD.org@localhost>
date:      Mon Apr 09 18:12:50 2018 +0000

description:
Pull up following revision(s) (requested by msaitoh in ticket #717):

        sys/arch/x86/x86/cpu_topology.c: revision 1.11-1.13

Check for undefined behaviour when doing right-shift.

CPUID tells the ApicIdCoreIdSize in bits.

Compute Core/SMT-IDs for AMD family 17h (Ryzen).

diffstat:

 sys/arch/x86/x86/cpu_topology.c |  24 +++++++++++++++++++-----
 1 files changed, 19 insertions(+), 5 deletions(-)

diffs (61 lines):

diff -r 78004b2a3f77 -r dc5243edebf6 sys/arch/x86/x86/cpu_topology.c
--- a/sys/arch/x86/x86/cpu_topology.c   Mon Apr 09 18:10:49 2018 +0000
+++ b/sys/arch/x86/x86/cpu_topology.c   Mon Apr 09 18:12:50 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu_topology.c,v 1.9.22.1 2017/11/21 15:03:20 martin Exp $     */
+/*     $NetBSD: cpu_topology.c,v 1.9.22.2 2018/04/09 18:12:50 martin Exp $     */
 
 /*-
  * Copyright (c) 2009 Mindaugas Rasiukevicius <rmind at NetBSD org>,
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu_topology.c,v 1.9.22.1 2017/11/21 15:03:20 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_topology.c,v 1.9.22.2 2018/04/09 18:12:50 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/bitops.h>
@@ -108,6 +108,7 @@
                        core_max = lp_max;
                        break;
                }
+
                /* Number of Cores (NC) per package (ecx[7:0]). */
                x86_cpuid(0x80000008, descs);
                core_max = (descs[2] & 0xff) + 1;
@@ -116,9 +117,9 @@
                if (n != 0) {
                        /*
                         * Extended Method.
-                        * core_bits = 2 ^ n (power of two)
+                        * core_max = 2 ^ n (power of two)
                         */
-                       core_bits = 1 << n;
+                       core_bits = n;
                }
                break;
        default:
@@ -150,8 +151,21 @@
                }
        }
 
+       /* Family 0x17 supports SMT */
+       if (cpu_vendor == CPUVENDOR_AMD && cpu_family == 0x17) { /* XXX */
+               x86_cpuid(0x8000001e, descs);
+               const u_int threads = ((descs[1] >> 8) & 0xff) + 1;
+
+               KASSERT(smt_bits == 0 && smt_bits <= core_bits);
+               smt_bits = ilog2(threads);
+               core_bits -= smt_bits;
+       }
+
        if (smt_bits + core_bits) {
-               ci->ci_package_id = apic_id >> (smt_bits + core_bits);
+               if (smt_bits + core_bits < sizeof(apic_id) * NBBY)
+                       ci->ci_package_id = apic_id >> (smt_bits + core_bits);
+               else
+                       ci->ci_package_id = 0;
        }
        if (core_bits) {
                u_int core_mask = __BITS(smt_bits, smt_bits + core_bits - 1);



Home | Main Index | Thread Index | Old Index