Source-Changes-HG archive

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

[src/trunk]: src/sys Take the basic CPU topology information we already colle...



details:   https://anonhg.NetBSD.org/src/rev/15ac5ab41cfc
branches:  trunk
changeset: 846848:15ac5ab41cfc
user:      ad <ad%NetBSD.org@localhost>
date:      Mon Dec 02 23:22:43 2019 +0000

description:
Take the basic CPU topology information we already collect, and use it
to make circular lists of CPU siblings in the same core, and in the
same package.  Nothing fancy, just enough to have a bit of fun in the
scheduler trying out different tactics.

diffstat:

 sys/arch/aarch64/aarch64/cpufunc.c |   19 +++--
 sys/arch/arm/arm32/arm32_boot.c    |   17 +++--
 sys/arch/arm/arm32/cpu.c           |   17 +++--
 sys/arch/mips/mips/cpu_subr.c      |    9 +-
 sys/arch/x86/x86/cpu_topology.c    |   31 +++++---
 sys/kern/init_main.c               |    7 +-
 sys/kern/kern_cpu.c                |  118 ++++++++++++++++++++++++++++++++++++-
 sys/sys/cpu.h                      |    4 +-
 sys/sys/cpu_data.h                 |   19 ++++-
 9 files changed, 192 insertions(+), 49 deletions(-)

diffs (truncated from 484 to 300 lines):

diff -r 85a98c0df7e4 -r 15ac5ab41cfc sys/arch/aarch64/aarch64/cpufunc.c
--- a/sys/arch/aarch64/aarch64/cpufunc.c        Mon Dec 02 22:14:21 2019 +0000
+++ b/sys/arch/aarch64/aarch64/cpufunc.c        Mon Dec 02 23:22:43 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpufunc.c,v 1.8 2019/11/22 05:21:19 mlelstv Exp $      */
+/*     $NetBSD: cpufunc.c,v 1.9 2019/12/02 23:22:43 ad Exp $   */
 
 /*
  * Copyright (c) 2017 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -29,13 +29,13 @@
 #include "opt_multiprocessor.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpufunc.c,v 1.8 2019/11/22 05:21:19 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufunc.c,v 1.9 2019/12/02 23:22:43 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
 #include <sys/kmem.h>
+#include <sys/cpu.h>
 
-#include <aarch64/cpu.h>
 #include <aarch64/cpufunc.h>
 
 u_int cputype;                 /* compat arm */
@@ -93,12 +93,15 @@
 {
 
        if (mpidr & MPIDR_MT) {
-               ci->ci_smt_id = __SHIFTOUT(mpidr, MPIDR_AFF0);
-               ci->ci_core_id = __SHIFTOUT(mpidr, MPIDR_AFF1);
-               ci->ci_package_id = __SHIFTOUT(mpidr, MPIDR_AFF2);
+               cpu_topology_set(ci,
+                   __SHIFTOUT(mpidr, MPIDR_AFF2),
+                   __SHIFTOUT(mpidr, MPIDR_AFF1),
+                   __SHIFTOUT(mpidr, MPIDR_AFF0));
        } else {
-               ci->ci_core_id = __SHIFTOUT(mpidr, MPIDR_AFF0);
-               ci->ci_package_id = __SHIFTOUT(mpidr, MPIDR_AFF1);
+               cpu_topology_set(ci,
+                   __SHIFTOUT(mpidr, MPIDR_AFF1),
+                   __SHIFTOUT(mpidr, MPIDR_AFF0),
+                   0);
        }
 }
 
diff -r 85a98c0df7e4 -r 15ac5ab41cfc sys/arch/arm/arm32/arm32_boot.c
--- a/sys/arch/arm/arm32/arm32_boot.c   Mon Dec 02 22:14:21 2019 +0000
+++ b/sys/arch/arm/arm32/arm32_boot.c   Mon Dec 02 23:22:43 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arm32_boot.c,v 1.33 2019/03/16 10:05:40 skrll Exp $    */
+/*     $NetBSD: arm32_boot.c,v 1.34 2019/12/02 23:22:43 ad Exp $       */
 
 /*
  * Copyright (c) 2002, 2003, 2005  Genetec Corporation.  All rights reserved.
@@ -122,7 +122,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: arm32_boot.c,v 1.33 2019/03/16 10:05:40 skrll Exp $");
+__KERNEL_RCSID(1, "$NetBSD: arm32_boot.c,v 1.34 2019/12/02 23:22:43 ad Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_cputypes.h"
@@ -358,12 +358,15 @@
        uint32_t mpidr = armreg_mpidr_read();
        ci->ci_mpidr = mpidr;
        if (mpidr & MPIDR_MT) {
-               ci->ci_smt_id = __SHIFTOUT(mpidr, MPIDR_AFF0);
-               ci->ci_core_id = __SHIFTOUT(mpidr, MPIDR_AFF1);
-               ci->ci_package_id = __SHIFTOUT(mpidr, MPIDR_AFF2);
+               cpu_topology_set(ci,
+                   __SHIFTOUT(mpidr, MPIDR_AFF2),
+                   __SHIFTOUT(mpidr, MPIDR_AFF1),
+                   __SHIFTOUT(mpidr, MPIDR_AFF0));
        } else {
-               ci->ci_core_id = __SHIFTOUT(mpidr, MPIDR_AFF0);
-               ci->ci_package_id = __SHIFTOUT(mpidr, MPIDR_AFF1);
+               cpu_topology_set(ci,
+                   __SHIFTOUT(mpidr, MPIDR_AFF1),
+                   __SHIFTOUT(mpidr, MPIDR_AFF0),
+                   0);
        }
 
        ci->ci_arm_cpuid = cpu_idnum();
diff -r 85a98c0df7e4 -r 15ac5ab41cfc sys/arch/arm/arm32/cpu.c
--- a/sys/arch/arm/arm32/cpu.c  Mon Dec 02 22:14:21 2019 +0000
+++ b/sys/arch/arm/arm32/cpu.c  Mon Dec 02 23:22:43 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu.c,v 1.134 2019/10/20 14:25:14 jmcneill Exp $       */
+/*     $NetBSD: cpu.c,v 1.135 2019/12/02 23:22:43 ad Exp $     */
 
 /*
  * Copyright (c) 1995 Mark Brinicombe.
@@ -46,7 +46,7 @@
 #include "opt_multiprocessor.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.134 2019/10/20 14:25:14 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.135 2019/12/02 23:22:43 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -111,12 +111,15 @@
                ci->ci_mpidr = mpidr;
 
                if (mpidr & MPIDR_MT) {
-                       ci->ci_smt_id = __SHIFTOUT(mpidr, MPIDR_AFF0);
-                       ci->ci_core_id = __SHIFTOUT(mpidr, MPIDR_AFF1);
-                       ci->ci_package_id = __SHIFTOUT(mpidr, MPIDR_AFF2);
+                       cpu_topology_set(ci,
+                           __SHIFTOUT(mpidr, MPIDR_AFF2),
+                           __SHIFTOUT(mpidr, MPIDR_AFF1),
+                           __SHIFTOUT(mpidr, MPIDR_AFF0));
                } else {
-                       ci->ci_core_id = __SHIFTOUT(mpidr, MPIDR_AFF0);
-                       ci->ci_package_id = __SHIFTOUT(mpidr, MPIDR_AFF1);
+                       cpu_topology_set(ci,
+                           __SHIFTOUT(mpidr, MPIDR_AFF1),
+                           __SHIFTOUT(mpidr, MPIDR_AFF0),
+                           0);
                }
 #endif
        } else {
diff -r 85a98c0df7e4 -r 15ac5ab41cfc sys/arch/mips/mips/cpu_subr.c
--- a/sys/arch/mips/mips/cpu_subr.c     Mon Dec 02 22:14:21 2019 +0000
+++ b/sys/arch/mips/mips/cpu_subr.c     Mon Dec 02 23:22:43 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu_subr.c,v 1.38 2019/12/01 14:52:13 ad Exp $ */
+/*     $NetBSD: cpu_subr.c,v 1.39 2019/12/02 23:22:43 ad Exp $ */
 
 /*-
  * Copyright (c) 2010, 2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu_subr.c,v 1.38 2019/12/01 14:52:13 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_subr.c,v 1.39 2019/12/02 23:22:43 ad Exp $");
 
 #include "opt_cputype.h"
 #include "opt_ddb.h"
@@ -182,9 +182,6 @@
        KASSERT(cpu_id != 0);
        ci->ci_cpuid = cpu_id;
        ci->ci_pmap_kern_segtab = &pmap_kern_segtab,
-       ci->ci_package_id = cpu_package_id;
-       ci->ci_core_id = cpu_core_id;
-       ci->ci_smt_id = cpu_smt_id;
        ci->ci_cpu_freq = cpu_info_store.ci_cpu_freq;
        ci->ci_cctr_freq = cpu_info_store.ci_cctr_freq;
        ci->ci_cycles_per_hz = cpu_info_store.ci_cycles_per_hz;
@@ -192,6 +189,8 @@
        ci->ci_divisor_recip = cpu_info_store.ci_divisor_recip;
        ci->ci_cpuwatch_count = cpu_info_store.ci_cpuwatch_count;
 
+       cpu_topology_set(ci, cpu_package_id, cpu_core_id, cpu_smt_id);
+
        pmap_md_alloc_ephemeral_address_space(ci);
 
        mi_cpu_attach(ci);
diff -r 85a98c0df7e4 -r 15ac5ab41cfc sys/arch/x86/x86/cpu_topology.c
--- a/sys/arch/x86/x86/cpu_topology.c   Mon Dec 02 22:14:21 2019 +0000
+++ b/sys/arch/x86/x86/cpu_topology.c   Mon Dec 02 23:22:43 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu_topology.c,v 1.14 2018/11/21 10:34:53 msaitoh Exp $        */
+/*     $NetBSD: cpu_topology.c,v 1.15 2019/12/02 23:22:43 ad Exp $     */
 
 /*-
  * Copyright (c) 2009 Mindaugas Rasiukevicius <rmind at NetBSD org>,
@@ -36,13 +36,13 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu_topology.c,v 1.14 2018/11/21 10:34:53 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_topology.c,v 1.15 2019/12/02 23:22:43 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/bitops.h>
+#include <sys/cpu.h>
 
 #include <machine/specialreg.h>
-#include <machine/cpu.h>
 
 #include <x86/cpufunc.h>
 #include <x86/cputypes.h>
@@ -55,23 +55,28 @@
        u_int core_max;         /* Core per package */
        int n, cpu_family, apic_id, smt_bits, core_bits = 0;
        uint32_t descs[4];
+       int package_id, core_id, smt_id;
 
        apic_id = ci->ci_initapicid;
        cpu_family = CPUID_TO_FAMILY(ci->ci_signature);
 
        /* Initial values. */
-       ci->ci_package_id = apic_id;
-       ci->ci_core_id = 0;
-       ci->ci_smt_id = 0;
+       package_id = apic_id;
+       core_id = 0;
+       smt_id = 0;
 
        switch (cpu_vendor) {
        case CPUVENDOR_INTEL:
-               if (cpu_family < 6)
+               if (cpu_family < 6) {
+                       cpu_topology_set(ci, package_id, core_id, smt_id);
                        return;
+               }
                break;
        case CPUVENDOR_AMD:
-               if (cpu_family < 0xf)
+               if (cpu_family < 0xf) {
+                       cpu_topology_set(ci, package_id, core_id, smt_id);
                        return;
+               }
                break;
        default:
                return;
@@ -164,16 +169,18 @@
 
        if (smt_bits + core_bits) {
                if (smt_bits + core_bits < sizeof(apic_id) * NBBY)
-                       ci->ci_package_id = apic_id >> (smt_bits + core_bits);
+                       package_id = apic_id >> (smt_bits + core_bits);
                else
-                       ci->ci_package_id = 0;
+                       package_id = 0;
        }
        if (core_bits) {
                u_int core_mask = __BITS(smt_bits, smt_bits + core_bits - 1);
-               ci->ci_core_id = __SHIFTOUT(apic_id, core_mask);
+               core_id = __SHIFTOUT(apic_id, core_mask);
        }
        if (smt_bits) {
                u_int smt_mask = __BITS(0, smt_bits - 1);
-               ci->ci_smt_id = __SHIFTOUT(apic_id, smt_mask);
+               smt_id = __SHIFTOUT(apic_id, smt_mask);
        }
+
+       cpu_topology_set(ci, package_id, core_id, smt_id);
 }
diff -r 85a98c0df7e4 -r 15ac5ab41cfc sys/kern/init_main.c
--- a/sys/kern/init_main.c      Mon Dec 02 22:14:21 2019 +0000
+++ b/sys/kern/init_main.c      Mon Dec 02 23:22:43 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init_main.c,v 1.507 2019/12/01 17:08:31 ad Exp $       */
+/*     $NetBSD: init_main.c,v 1.508 2019/12/02 23:22:43 ad Exp $       */
 
 /*-
  * Copyright (c) 2008, 2009, 2019 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.507 2019/12/01 17:08:31 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.508 2019/12/02 23:22:43 ad Exp $");
 
 #include "opt_ddb.h"
 #include "opt_inet.h"
@@ -788,6 +788,9 @@
        struct cpu_info *ci;
        int s;
 
+       /* Fix up CPU topology info, which has all been collected by now. */
+       cpu_topology_init();
+
        /*
         * Now that we've found all the hardware, start the real time
         * and statistics clocks.
diff -r 85a98c0df7e4 -r 15ac5ab41cfc sys/kern/kern_cpu.c
--- a/sys/kern/kern_cpu.c       Mon Dec 02 22:14:21 2019 +0000
+++ b/sys/kern/kern_cpu.c       Mon Dec 02 23:22:43 2019 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: kern_cpu.c,v 1.78 2019/12/01 15:34:46 ad Exp $ */
+/*     $NetBSD: kern_cpu.c,v 1.79 2019/12/02 23:22:43 ad Exp $ */
 
 /*-
- * Copyright (c) 2007, 2008, 2009, 2010, 2012 The NetBSD Foundation, Inc.
+ * Copyright (c) 2007, 2008, 2009, 2010, 2012, 2019 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -56,7 +56,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.78 2019/12/01 15:34:46 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.79 2019/12/02 23:22:43 ad Exp $");
 
 #include "opt_cpu_ucode.h"
 
@@ -119,6 +119,7 @@
 int            ncpu                    __read_mostly;
 int            ncpuonline              __read_mostly;
 bool           mp_online               __read_mostly;
+static bool    cpu_topology_present    __read_mostly;
 
 /* An array of CPUs.  There are ncpu entries. */



Home | Main Index | Thread Index | Old Index