Source-Changes-HG archive

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

[src/trunk]: src/sys Split subr_cpu.c out of kern_cpu.c, to contain routines ...



details:   https://anonhg.NetBSD.org/src/rev/f1ad5dde69d3
branches:  trunk
changeset: 967751:f1ad5dde69d3
user:      ad <ad%NetBSD.org@localhost>
date:      Fri Dec 20 21:20:09 2019 +0000

description:
Split subr_cpu.c out of kern_cpu.c, to contain routines shared with rump.

diffstat:

 sys/kern/files.kern                         |    3 +-
 sys/kern/kern_cpu.c                         |  388 +-----------------------
 sys/kern/subr_cpu.c                         |  446 ++++++++++++++++++++++++++++
 sys/rump/librump/rumpkern/Makefile.rumpkern |    4 +-
 4 files changed, 457 insertions(+), 384 deletions(-)

diffs (truncated from 929 to 300 lines):

diff -r 6dd4ec7de2d2 -r f1ad5dde69d3 sys/kern/files.kern
--- a/sys/kern/files.kern       Fri Dec 20 21:13:48 2019 +0000
+++ b/sys/kern/files.kern       Fri Dec 20 21:20:09 2019 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.kern,v 1.39 2019/12/12 22:55:20 pgoyette Exp $
+#      $NetBSD: files.kern,v 1.40 2019/12/20 21:20:09 ad Exp $
 
 #
 # kernel sources
@@ -104,6 +104,7 @@
 file   kern/subr_bufq.c                kern
 file   kern/subr_callback.c            kern
 file   kern/subr_cprng.c               kern
+file   kern/subr_cpu.c                 kern
 file   kern/subr_cpufreq.c             kern
 file   kern/subr_copy.c                kern
 file   kern/subr_csan.c                kcsan
diff -r 6dd4ec7de2d2 -r f1ad5dde69d3 sys/kern/kern_cpu.c
--- a/sys/kern/kern_cpu.c       Fri Dec 20 21:13:48 2019 +0000
+++ b/sys/kern/kern_cpu.c       Fri Dec 20 21:20:09 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_cpu.c,v 1.87 2019/12/20 21:05:34 ad Exp $ */
+/*     $NetBSD: kern_cpu.c,v 1.88 2019/12/20 21:20:09 ad Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008, 2009, 2010, 2012, 2019 The NetBSD Foundation, Inc.
@@ -55,8 +55,12 @@
  * SUCH DAMAGE.
  */
 
+/*
+ * CPU related routines not shared with rump.
+ */
+
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.87 2019/12/20 21:05:34 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.88 2019/12/20 21:20:09 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_cpu_ucode.h"
@@ -91,7 +95,6 @@
  * verify that the claim is true. This will prevent them from getting out
  * of sync.
  */
-#ifndef _RUMPKERNEL /* XXX temporary */
 #ifdef __HAVE_CPU_DATA_FIRST
 CTASSERT(offsetof(struct cpu_info, ci_data) == 0);
 #else
@@ -117,43 +120,7 @@
        .d_discard = nodiscard,
        .d_flag = D_OTHER | D_MPSAFE
 };
-#endif /* ifndef _RUMPKERNEL XXX */
 
-kmutex_t       cpu_lock                __cacheline_aligned;
-int            ncpu                    __read_mostly;
-int            ncpuonline              __read_mostly;
-bool           mp_online               __read_mostly;
-static bool    cpu_topology_present    __read_mostly;
-int64_t                cpu_counts[CPU_COUNT_MAX];
-
-/* An array of CPUs.  There are ncpu entries. */
-struct cpu_info **cpu_infos            __read_mostly;
-
-/* Note: set on mi_cpu_attach() and idle_loop(). */
-kcpuset_t *    kcpuset_attached        __read_mostly   = NULL;
-kcpuset_t *    kcpuset_running         __read_mostly   = NULL;
-
-int (*compat_cpuctl_ioctl)(struct lwp *, u_long, void *) = (void *)enosys;
-
-static char cpu_model[128];
-
-/*
- * mi_cpu_init: early initialisation of MI CPU related structures.
- *
- * Note: may not block and memory allocator is not yet available.
- */
-void
-mi_cpu_init(void)
-{
-
-       mutex_init(&cpu_lock, MUTEX_DEFAULT, IPL_NONE);
-
-       kcpuset_create(&kcpuset_attached, true);
-       kcpuset_create(&kcpuset_running, true);
-       kcpuset_set(kcpuset_running, 0);
-}
-
-#ifndef _RUMPKERNEL /* XXX temporary */
 int
 mi_cpu_attach(struct cpu_info *ci)
 {
@@ -475,27 +442,8 @@
        spc->spc_lastmod = time_second;
        return 0;
 }
-#endif /* ifndef _RUMPKERNEL XXX */
 
-int
-cpu_setmodel(const char *fmt, ...)
-{
-       int len;
-       va_list ap;
-
-       va_start(ap, fmt);
-       len = vsnprintf(cpu_model, sizeof(cpu_model), fmt, ap);
-       va_end(ap);
-       return len;
-}
-
-const char *
-cpu_getmodel(void)
-{
-       return cpu_model;
-}
-
-#if defined(__HAVE_INTR_CONTROL) && !defined(_RUMPKERNEL) /* XXX */
+#if defined(__HAVE_INTR_CONTROL)
 static void
 cpu_xc_intr(struct cpu_info *ci, void *unused)
 {
@@ -588,245 +536,6 @@
 }
 #endif /* __HAVE_INTR_CONTROL */
 
-bool
-cpu_softintr_p(void)
-{
-
-       return (curlwp->l_pflag & LP_INTR) != 0;
-}
-
-/*
- * Collect CPU topology information as each CPU is attached.  This can be
- * called early during boot, so we need to be careful what we do.
- */
-void
-cpu_topology_set(struct cpu_info *ci, u_int package_id, u_int core_id,
-    u_int smt_id, u_int numa_id)
-{
-       enum cpu_rel rel;
-
-       cpu_topology_present = true;
-       ci->ci_package_id = package_id;
-       ci->ci_core_id = core_id;
-       ci->ci_smt_id = smt_id;
-       ci->ci_numa_id = numa_id;
-       for (rel = 0; rel < __arraycount(ci->ci_sibling); rel++) {
-               ci->ci_sibling[rel] = ci;
-               ci->ci_nsibling[rel] = 1;
-       }
-}
-
-/*
- * Link a CPU into the given circular list.
- */
-static void
-cpu_topology_link(struct cpu_info *ci, struct cpu_info *ci2, enum cpu_rel rel)
-{
-       struct cpu_info *ci3;
-
-       /* Walk to the end of the existing circular list and append. */
-       for (ci3 = ci2;; ci3 = ci3->ci_sibling[rel]) {
-               ci3->ci_nsibling[rel]++;
-               if (ci3->ci_sibling[rel] == ci2) {
-                       break;
-               }
-       }
-       ci->ci_sibling[rel] = ci2;
-       ci3->ci_sibling[rel] = ci;
-       ci->ci_nsibling[rel] = ci3->ci_nsibling[rel];
-}
-
-/*
- * Print out the topology lists.
- */
-static void
-cpu_topology_dump(void)
-{
-#if DEBUG 
-       CPU_INFO_ITERATOR cii;
-       struct cpu_info *ci, *ci2;
-       const char *names[] = { "core", "package", "peer", "smt" };
-       enum cpu_rel rel;
-       int i;
-
-       for (CPU_INFO_FOREACH(cii, ci)) {
-               for (rel = 0; rel < __arraycount(ci->ci_sibling); rel++) {
-                       printf("%s has %d %s siblings:", cpu_name(ci),
-                           ci->ci_nsibling[rel], names[rel]);
-                       ci2 = ci->ci_sibling[rel];
-                       i = 0;
-                       do {
-                               printf(" %s", cpu_name(ci2));
-                               ci2 = ci2->ci_sibling[rel];
-                       } while (++i < 64 && ci2 != ci->ci_sibling[rel]);
-                       if (i == 64) {
-                               printf(" GAVE UP");
-                       }
-                       printf("\n");
-               }
-       }
-#endif /* DEBUG */
-}
-
-/*
- * Fake up topology info if we have none, or if what we got was bogus.
- * Don't override ci_package_id, etc, if cpu_topology_present is set.
- * MD code also uses these.
- */
-static void
-cpu_topology_fake(void)
-{
-       CPU_INFO_ITERATOR cii;
-       struct cpu_info *ci;
-       enum cpu_rel rel;
-
-       for (CPU_INFO_FOREACH(cii, ci)) {
-               for (rel = 0; rel < __arraycount(ci->ci_sibling); rel++) {
-                       ci->ci_sibling[rel] = ci;
-                       ci->ci_nsibling[rel] = 1;
-               }
-               if (!cpu_topology_present) {
-                       ci->ci_package_id = cpu_index(ci);
-               }
-               ci->ci_smt_primary = ci;
-               ci->ci_schedstate.spc_flags |= SPCF_SMTPRIMARY;
-       }
-       cpu_topology_dump();
-}
-
-/*
- * Fix up basic CPU topology info.  Right now that means attach each CPU to
- * circular lists of its siblings in the same core, and in the same package. 
- */
-void
-cpu_topology_init(void)
-{
-       CPU_INFO_ITERATOR cii, cii2;
-       struct cpu_info *ci, *ci2, *ci3;
-       u_int ncore, npackage, npeer, minsmt;
-       bool symmetric;
-
-       if (!cpu_topology_present) {
-               cpu_topology_fake();
-               return;
-       }
-
-       /* Find siblings in same core and package. */
-       for (CPU_INFO_FOREACH(cii, ci)) {
-               for (CPU_INFO_FOREACH(cii2, ci2)) {
-                       /* Avoid bad things happening. */
-                       if (ci2->ci_package_id == ci->ci_package_id &&
-                           ci2->ci_core_id == ci->ci_core_id &&
-                           ci2->ci_smt_id == ci->ci_smt_id &&
-                           ci2 != ci) {
-                               printf("cpu_topology_init: info bogus, "
-                                   "faking it\n");
-                               cpu_topology_fake();
-                               return;
-                       }
-                       if (ci2 == ci ||
-                           ci2->ci_package_id != ci->ci_package_id) {
-                               continue;
-                       }
-                       /* Find CPUs in the same core. */
-                       if (ci->ci_nsibling[CPUREL_CORE] == 1 &&
-                           ci->ci_core_id == ci2->ci_core_id) {
-                               cpu_topology_link(ci, ci2, CPUREL_CORE);
-                       }
-                       /* Find CPUs in the same package. */
-                       if (ci->ci_nsibling[CPUREL_PACKAGE] == 1) {
-                               cpu_topology_link(ci, ci2, CPUREL_PACKAGE);
-                       }
-                       if (ci->ci_nsibling[CPUREL_CORE] > 1 &&
-                           ci->ci_nsibling[CPUREL_PACKAGE] > 1) {
-                               break;
-                       }
-               }
-       }
-
-       /* Find peers in other packages, and peer SMTs in same package. */
-       for (CPU_INFO_FOREACH(cii, ci)) {
-               if (ci->ci_nsibling[CPUREL_PEER] <= 1) {
-                       for (CPU_INFO_FOREACH(cii2, ci2)) {
-                               if (ci != ci2 &&
-                                   ci->ci_package_id != ci2->ci_package_id &&
-                                   ci->ci_core_id == ci2->ci_core_id &&
-                                   ci->ci_smt_id == ci2->ci_smt_id) {
-                                       cpu_topology_link(ci, ci2,
-                                           CPUREL_PEER);
-                                       break;
-                               }
-                       }
-               }
-               if (ci->ci_nsibling[CPUREL_SMT] <= 1) {
-                       for (CPU_INFO_FOREACH(cii2, ci2)) {
-                               if (ci != ci2 &&
-                                   ci->ci_package_id == ci2->ci_package_id &&
-                                   ci->ci_core_id != ci2->ci_core_id &&



Home | Main Index | Thread Index | Old Index