From 6149350c481a3289e855aea11695b880aa722102 Mon Sep 17 00:00:00 2001 From: skrll Date: Sat, 15 Feb 2020 07:20:40 +0000 Subject: [PATCH] Remove the 'slow' argument from cpu_topology_set and create a new function cpu_topology_setspeed which sets the relative speed of the cpu. This allows cpu_topology_set is be used at cpu hatch time. The relative speed is only known once all cpus have hatched/attached OK ad@ --- sys/arch/arm/arm/arm_cpu_topology.c | 13 ++++++------- sys/arch/macppc/macppc/cpu.c | 6 +++--- sys/arch/mips/mips/cpu_subr.c | 6 +++--- sys/arch/x86/x86/cpu_topology.c | 10 +++++----- sys/kern/subr_cpu.c | 20 +++++++++++++++----- sys/sys/cpu.h | 5 +++-- 6 files changed, 35 insertions(+), 25 deletions(-) diff --git a/sys/arch/arm/arm/arm_cpu_topology.c b/sys/arch/arm/arm/arm_cpu_topology.c index 3de8c88907f9..112458acbf1a 100644 --- a/sys/arch/arm/arm/arm_cpu_topology.c +++ b/sys/arch/arm/arm/arm_cpu_topology.c @@ -1,4 +1,4 @@ -/* $NetBSD: arm_cpu_topology.c,v 1.2 2020/01/16 06:34:24 mrg Exp $ */ +/* $NetBSD: arm_cpu_topology.c,v 1.3 2020/02/15 07:20:41 skrll Exp $ */ /* * Copyright (c) 2020 Matthew R. Green @@ -33,7 +33,7 @@ #include "opt_multiprocessor.h" #include -__KERNEL_RCSID(0, "$NetBSD: arm_cpu_topology.c,v 1.2 2020/01/16 06:34:24 mrg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: arm_cpu_topology.c,v 1.3 2020/02/15 07:20:41 skrll Exp $"); #include #include @@ -61,7 +61,7 @@ arm_cpu_topology_set(struct cpu_info * const ci, uint64_t mpidr, bool slow) coreid = __SHIFTOUT(mpidr, MPIDR_AFF0); smtid = 0; } - cpu_topology_set(ci, pkgid, coreid, smtid, numaid, slow); + cpu_topology_set(ci, pkgid, coreid, smtid, numaid); #endif /* MULTIPROCESSOR */ } @@ -88,8 +88,7 @@ arm_cpu_do_topology(struct cpu_info *const newci) * mi_cpu_attach() is called and ncpu is bumped, so call it * directly here. This also handles the not-MP case. */ - arm_cpu_topology_set(newci, arm_cpu_mpidr(newci), - newci->ci_capacity_dmips_mhz < best_cap); + cpu_topology_setspeed(newci, newci->ci_capacity_dmips_mhz < best_cap); /* * Using saved largest capacity, refresh previous topology info. @@ -98,8 +97,8 @@ arm_cpu_do_topology(struct cpu_info *const newci) for (CPU_INFO_FOREACH(cii, ci)) { if (ci == newci) continue; - arm_cpu_topology_set(ci, arm_cpu_mpidr(ci), - ci->ci_capacity_dmips_mhz < best_cap); + cpu_topology_setspeed(newci, + newci->ci_capacity_dmips_mhz < best_cap); } #endif /* MULTIPROCESSOR */ } diff --git a/sys/arch/macppc/macppc/cpu.c b/sys/arch/macppc/macppc/cpu.c index 3f7ec7f2e7b9..1ff39d91bed2 100644 --- a/sys/arch/macppc/macppc/cpu.c +++ b/sys/arch/macppc/macppc/cpu.c @@ -1,4 +1,4 @@ -/* $NetBSD: cpu.c,v 1.71 2020/02/09 09:30:37 skrll Exp $ */ +/* $NetBSD: cpu.c,v 1.72 2020/02/15 07:20:41 skrll Exp $ */ /*- * Copyright (c) 2001 Tsubai Masanari. @@ -33,7 +33,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.71 2020/02/09 09:30:37 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.72 2020/02/15 07:20:41 skrll Exp $"); #include "opt_ppcparam.h" #include "opt_multiprocessor.h" @@ -175,7 +175,7 @@ cpuattach(device_t parent, device_t self, void *aux) core = package & 1; package >>= 1; } - cpu_topology_set(ci, package, core, 0, 0, false); + cpu_topology_set(ci, package, core, 0, 0); if (ci->ci_khz == 0) { cpu_OFgetspeed(self, ci); diff --git a/sys/arch/mips/mips/cpu_subr.c b/sys/arch/mips/mips/cpu_subr.c index 1c474d47ff72..9d06842a28bc 100644 --- a/sys/arch/mips/mips/cpu_subr.c +++ b/sys/arch/mips/mips/cpu_subr.c @@ -1,4 +1,4 @@ -/* $NetBSD: cpu_subr.c,v 1.45 2020/01/09 16:35:03 ad Exp $ */ +/* $NetBSD: cpu_subr.c,v 1.46 2020/02/15 07:20:41 skrll Exp $ */ /*- * Copyright (c) 2010, 2019 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cpu_subr.c,v 1.45 2020/01/09 16:35:03 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cpu_subr.c,v 1.46 2020/02/15 07:20:41 skrll Exp $"); #include "opt_cputype.h" #include "opt_ddb.h" @@ -189,7 +189,7 @@ cpu_info_alloc(struct pmap_tlb_info *ti, cpuid_t cpu_id, cpuid_t cpu_package_id, 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, 0, false); + cpu_topology_set(ci, cpu_package_id, cpu_core_id, cpu_smt_id, 0); pmap_md_alloc_ephemeral_address_space(ci); diff --git a/sys/arch/x86/x86/cpu_topology.c b/sys/arch/x86/x86/cpu_topology.c index f73b7f65052c..4c3cf75af6a1 100644 --- a/sys/arch/x86/x86/cpu_topology.c +++ b/sys/arch/x86/x86/cpu_topology.c @@ -1,4 +1,4 @@ -/* $NetBSD: cpu_topology.c,v 1.18 2020/01/20 06:50:34 mlelstv Exp $ */ +/* $NetBSD: cpu_topology.c,v 1.19 2020/02/15 07:20:41 skrll Exp $ */ /*- * Copyright (c) 2009 Mindaugas Rasiukevicius , @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cpu_topology.c,v 1.18 2020/01/20 06:50:34 mlelstv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cpu_topology.c,v 1.19 2020/02/15 07:20:41 skrll Exp $"); #include "acpica.h" @@ -95,14 +95,14 @@ x86_cpu_topology(struct cpu_info *ci) case CPUVENDOR_INTEL: if (cpu_family < 6) { cpu_topology_set(ci, package_id, core_id, smt_id, - numa_id, false); + numa_id); return; } break; case CPUVENDOR_AMD: if (cpu_family < 0xf) { cpu_topology_set(ci, package_id, core_id, smt_id, - numa_id, false); + numa_id); return; } break; @@ -211,5 +211,5 @@ x86_cpu_topology(struct cpu_info *ci) smt_id = __SHIFTOUT(apic_id, smt_mask); } - cpu_topology_set(ci, package_id, core_id, smt_id, numa_id, false); + cpu_topology_set(ci, package_id, core_id, smt_id, numa_id); } diff --git a/sys/kern/subr_cpu.c b/sys/kern/subr_cpu.c index 24ed29c0a27d..e6ceeb325474 100644 --- a/sys/kern/subr_cpu.c +++ b/sys/kern/subr_cpu.c @@ -1,4 +1,4 @@ -/* $NetBSD: subr_cpu.c,v 1.12 2020/02/09 09:30:22 skrll Exp $ */ +/* $NetBSD: subr_cpu.c,v 1.13 2020/02/15 07:20:40 skrll Exp $ */ /*- * Copyright (c) 2007, 2008, 2009, 2010, 2012, 2019, 2020 @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_cpu.c,v 1.12 2020/02/09 09:30:22 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_cpu.c,v 1.13 2020/02/15 07:20:40 skrll Exp $"); #include #include @@ -142,23 +142,33 @@ cpu_softintr_p(void) */ void cpu_topology_set(struct cpu_info *ci, u_int package_id, u_int core_id, - u_int smt_id, u_int numa_id, bool slow) + u_int smt_id, u_int numa_id) { enum cpu_rel rel; cpu_topology_present = true; - cpu_topology_haveslow |= slow; ci->ci_package_id = package_id; ci->ci_core_id = core_id; ci->ci_smt_id = smt_id; ci->ci_numa_id = numa_id; - ci->ci_is_slow = slow; + ci->ci_is_slow = false; for (rel = 0; rel < __arraycount(ci->ci_sibling); rel++) { ci->ci_sibling[rel] = ci; ci->ci_nsibling[rel] = 1; } } +/* + * Collect CPU relative speed + */ +void +cpu_topology_setspeed(struct cpu_info *ci, bool slow) +{ + + cpu_topology_haveslow |= slow; + ci->ci_is_slow = slow; +} + /* * Link a CPU into the given circular list. */ diff --git a/sys/sys/cpu.h b/sys/sys/cpu.h index bcd28724b4a0..ed3332138646 100644 --- a/sys/sys/cpu.h +++ b/sys/sys/cpu.h @@ -1,4 +1,4 @@ -/* $NetBSD: cpu.h,v 1.49 2020/02/09 09:29:50 skrll Exp $ */ +/* $NetBSD: cpu.h,v 1.50 2020/02/15 07:20:40 skrll Exp $ */ /*- * Copyright (c) 2007 YAMAMOTO Takashi, @@ -90,7 +90,8 @@ bool cpu_kpreempt_disabled(void); int cpu_lwp_setprivate(struct lwp *, void *); void cpu_intr_redistribute(void); u_int cpu_intr_count(struct cpu_info *); -void cpu_topology_set(struct cpu_info *, u_int, u_int, u_int, u_int, bool); +void cpu_topology_set(struct cpu_info *, u_int, u_int, u_int, u_int); +void cpu_topology_setspeed(struct cpu_info *, bool); void cpu_topology_init(void); #endif