Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch port the arm64 cpu topology setup for big.little to...
details: https://anonhg.NetBSD.org/src/rev/b5a7ee0e53f2
branches: trunk
changeset: 467147:b5a7ee0e53f2
user: mrg <mrg%NetBSD.org@localhost>
date: Wed Jan 15 08:34:04 2020 +0000
description:
port the arm64 cpu topology setup for big.little to arm.
rename arm64 cpu_do_topology() to arm_cpu_do_topology() and
call it from both arm cpu_attach().
replace both aarch64_set_topology() inline code in arm
cpu_attach() with new arm_cpu_do_topology(), which is called
by the arm64 locore as well (possibly not needed, which would
allow it to become static.)
not yet tested on a real big.little armv7 system. tested
on rockpro64 and pinebook pro.
diffstat:
sys/arch/aarch64/aarch64/cpu.c | 45 +--------------
sys/arch/aarch64/aarch64/cpufunc.c | 25 +--------
sys/arch/aarch64/aarch64/locore.S | 6 +-
sys/arch/aarch64/conf/files.aarch64 | 3 +-
sys/arch/aarch64/include/cpu.h | 3 +-
sys/arch/aarch64/include/cpufunc.h | 3 +-
sys/arch/arm/arm/arm_cpu_topology.c | 102 ++++++++++++++++++++++++++++++++++++
sys/arch/arm/arm32/cpu.c | 21 +------
sys/arch/arm/conf/files.arm | 3 +-
sys/arch/arm/include/cpu.h | 4 +-
sys/arch/arm/include/cpu_topology.h | 59 ++++++++++++++++++++
11 files changed, 184 insertions(+), 90 deletions(-)
diffs (truncated from 464 to 300 lines):
diff -r 39c180559770 -r b5a7ee0e53f2 sys/arch/aarch64/aarch64/cpu.c
--- a/sys/arch/aarch64/aarch64/cpu.c Wed Jan 15 08:25:01 2020 +0000
+++ b/sys/arch/aarch64/aarch64/cpu.c Wed Jan 15 08:34:04 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.33 2020/01/12 09:29:18 mrg Exp $ */
+/* $NetBSD: cpu.c,v 1.34 2020/01/15 08:34:04 mrg Exp $ */
/*
* Copyright (c) 2017 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: cpu.c,v 1.33 2020/01/12 09:29:18 mrg Exp $");
+__KERNEL_RCSID(1, "$NetBSD: cpu.c,v 1.34 2020/01/15 08:34:04 mrg Exp $");
#include "locators.h"
#include "opt_arm_debug.h"
@@ -48,6 +48,7 @@
#include <aarch64/cpufunc.h>
#include <aarch64/machdep.h>
+#include <arm/cpu_topology.h>
#ifdef FDT
#include <arm/fdt/arm_fdtvar.h>
#endif
@@ -65,7 +66,6 @@
static void cpu_identify2(device_t self, struct cpu_info *);
static void cpu_setup_id(struct cpu_info *);
static void cpu_setup_sysctl(device_t, struct cpu_info *);
-static void cpu_do_topology(struct cpu_info *);
#ifdef MULTIPROCESSOR
uint64_t cpu_mpidr[MAXCPUS];
@@ -145,7 +145,7 @@
ci->ci_dev = dv;
dv->dv_private = ci;
- cpu_do_topology(ci);
+ arm_cpu_do_topology(ci);
cpu_identify(ci->ci_dev, ci);
#ifdef MULTIPROCESSOR
@@ -498,43 +498,6 @@
CTL_CREATE, CTL_EOL);
}
-static void
-cpu_do_topology(struct cpu_info *newci)
-{
- struct cpu_info *ci;
- CPU_INFO_ITERATOR cii;
- prop_dictionary_t dict;
- uint32_t capacity_dmips_mhz;
- static uint32_t best_cap = 0;
-
- dict = device_properties(newci->ci_dev);
- if (prop_dictionary_get_uint32(dict, "capacity_dmips_mhz",
- &capacity_dmips_mhz)) {
- newci->ci_capacity_dmips_mhz = capacity_dmips_mhz;
- } else {
- newci->ci_capacity_dmips_mhz = 0;
- }
-
- if (newci->ci_capacity_dmips_mhz > best_cap)
- best_cap = newci->ci_capacity_dmips_mhz;
-
- /*
- * CPU_INFO_FOREACH() doesn't work for this CPU until mi_cpu_attach()
- * is called and ncpu is bumped, so call it directly here.
- */
- aarch64_set_topology(newci, newci->ci_id.ac_mpidr,
- newci->ci_capacity_dmips_mhz < best_cap);
-
- /*
- * Using saved largest capacity, refresh previous topology info.
- * It's supposed to be OK to re-set topology.
- */
- for (CPU_INFO_FOREACH(cii, ci)) {
- aarch64_set_topology(ci, ci->ci_id.ac_mpidr,
- ci->ci_capacity_dmips_mhz < best_cap);
- }
-}
-
#ifdef MULTIPROCESSOR
void
cpu_boot_secondary_processors(void)
diff -r 39c180559770 -r b5a7ee0e53f2 sys/arch/aarch64/aarch64/cpufunc.c
--- a/sys/arch/aarch64/aarch64/cpufunc.c Wed Jan 15 08:25:01 2020 +0000
+++ b/sys/arch/aarch64/aarch64/cpufunc.c Wed Jan 15 08:34:04 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpufunc.c,v 1.14 2020/01/12 09:29:18 mrg Exp $ */
+/* $NetBSD: cpufunc.c,v 1.15 2020/01/15 08:34:04 mrg Exp $ */
/*
* Copyright (c) 2017 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -29,7 +29,7 @@
#include "opt_multiprocessor.h"
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpufunc.c,v 1.14 2020/01/12 09:29:18 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufunc.c,v 1.15 2020/01/15 08:34:04 mrg Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -89,27 +89,6 @@
}
void
-aarch64_set_topology(struct cpu_info * const ci, uint64_t mpidr, bool slow)
-{
-
- if (mpidr & MPIDR_MT) {
- cpu_topology_set(ci,
- __SHIFTOUT(mpidr, MPIDR_AFF2),
- __SHIFTOUT(mpidr, MPIDR_AFF1),
- __SHIFTOUT(mpidr, MPIDR_AFF0),
- 0,
- slow);
- } else {
- cpu_topology_set(ci,
- __SHIFTOUT(mpidr, MPIDR_AFF1),
- __SHIFTOUT(mpidr, MPIDR_AFF0),
- 0,
- 0,
- slow);
- }
-}
-
-void
aarch64_getcacheinfo(int unit)
{
struct cpu_info * const ci = curcpu();
diff -r 39c180559770 -r b5a7ee0e53f2 sys/arch/aarch64/aarch64/locore.S
--- a/sys/arch/aarch64/aarch64/locore.S Wed Jan 15 08:25:01 2020 +0000
+++ b/sys/arch/aarch64/aarch64/locore.S Wed Jan 15 08:34:04 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: locore.S,v 1.51 2020/01/12 09:29:18 mrg Exp $ */
+/* $NetBSD: locore.S,v 1.52 2020/01/15 08:34:04 mrg Exp $ */
/*
* Copyright (c) 2017 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -38,7 +38,7 @@
#include <aarch64/hypervisor.h>
#include "assym.h"
-RCSID("$NetBSD: locore.S,v 1.51 2020/01/12 09:29:18 mrg Exp $")
+RCSID("$NetBSD: locore.S,v 1.52 2020/01/15 08:34:04 mrg Exp $")
#ifdef AARCH64_DEVICE_MEM_STRONGLY_ORDERED
#define MAIR_DEVICE_MEM MAIR_DEVICE_nGnRnE
@@ -188,7 +188,7 @@
mrs x0, tpidr_el1 /* curcpu */
mrs x1, mpidr_el1
mov x2, #0
- bl aarch64_set_topology
+ bl arm_cpu_topology_set
mov x0, xzr
bl aarch64_getcacheinfo
diff -r 39c180559770 -r b5a7ee0e53f2 sys/arch/aarch64/conf/files.aarch64
--- a/sys/arch/aarch64/conf/files.aarch64 Wed Jan 15 08:25:01 2020 +0000
+++ b/sys/arch/aarch64/conf/files.aarch64 Wed Jan 15 08:34:04 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.aarch64,v 1.16 2019/12/28 17:19:43 jmcneill Exp $
+# $NetBSD: files.aarch64,v 1.17 2020/01/15 08:34:04 mrg Exp $
defflag opt_cpuoptions.h AARCH64_ALIGNMENT_CHECK
defflag opt_cpuoptions.h AARCH64_EL0_STACK_ALIGNMENT_CHECK
@@ -41,6 +41,7 @@
file arch/aarch64/aarch64/fpu.c
file arch/arm/arm/arm_generic_dma.c
+file arch/arm/arm/arm_cpu_topology.c
file arch/arm/arm32/bus_dma.c
device psci
diff -r 39c180559770 -r b5a7ee0e53f2 sys/arch/aarch64/include/cpu.h
--- a/sys/arch/aarch64/include/cpu.h Wed Jan 15 08:25:01 2020 +0000
+++ b/sys/arch/aarch64/include/cpu.h Wed Jan 15 08:34:04 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.18 2020/01/12 09:29:18 mrg Exp $ */
+/* $NetBSD: cpu.h,v 1.19 2020/01/15 08:34:04 mrg Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -104,6 +104,7 @@
uint64_t ci_acpiid; /* ACPI Processor Unique ID */
struct aarch64_sysctl_cpu_id ci_id;
+#define arm_cpu_mpidr(ci) ((ci)->ci_id.ac_mpidr)
struct aarch64_cache_info *ci_cacheinfo;
struct aarch64_cpufuncs ci_cpufuncs;
diff -r 39c180559770 -r b5a7ee0e53f2 sys/arch/aarch64/include/cpufunc.h
--- a/sys/arch/aarch64/include/cpufunc.h Wed Jan 15 08:25:01 2020 +0000
+++ b/sys/arch/aarch64/include/cpufunc.h Wed Jan 15 08:34:04 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpufunc.h,v 1.10 2020/01/12 09:29:18 mrg Exp $ */
+/* $NetBSD: cpufunc.h,v 1.11 2020/01/15 08:34:04 mrg Exp $ */
/*
* Copyright (c) 2017 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -69,7 +69,6 @@
extern u_int cputype; /* compat arm */
int set_cpufuncs(void);
-void aarch64_set_topology(struct cpu_info *, uint64_t, bool);
void aarch64_getcacheinfo(int);
void aarch64_printcacheinfo(device_t);
diff -r 39c180559770 -r b5a7ee0e53f2 sys/arch/arm/arm/arm_cpu_topology.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/arm/arm_cpu_topology.c Wed Jan 15 08:34:04 2020 +0000
@@ -0,0 +1,102 @@
+/* $NetBSD: arm_cpu_topology.c,v 1.1 2020/01/15 08:34:04 mrg Exp $ */
+
+/*
+ * Copyright (c) 2020 Matthew R. Green
+ * 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.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 "opt_multiprocessor.h"
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: arm_cpu_topology.c,v 1.1 2020/01/15 08:34:04 mrg Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/device.h>
+
+#include <arm/cpu.h>
+#include <arm/cpu_topology.h>
+
+#include <prop/proplib.h>
+
+void
+arm_cpu_topology_set(struct cpu_info * const ci, uint64_t mpidr, bool slow)
+{
+ uint pkgid, coreid, smtid, numaid = 0;
+
+ if (mpidr & MPIDR_MT) {
+ pkgid = __SHIFTOUT(mpidr, MPIDR_AFF2);
+ coreid = __SHIFTOUT(mpidr, MPIDR_AFF1);
+ smtid = __SHIFTOUT(mpidr, MPIDR_AFF0);
+ } else {
+ pkgid = __SHIFTOUT(mpidr, MPIDR_AFF1);
+ coreid = __SHIFTOUT(mpidr, MPIDR_AFF0);
+ smtid = 0;
+ }
+ cpu_topology_set(ci, pkgid, coreid, smtid, numaid, slow);
+}
+
+void
+arm_cpu_do_topology(struct cpu_info *const newci)
+{
+#ifdef MULTIPROCESSOR
+ struct cpu_info *ci;
+ CPU_INFO_ITERATOR cii;
+#endif /* MULTIPROCESSOR */
+ prop_dictionary_t dict;
+ uint32_t capacity_dmips_mhz = 0;
+ static uint32_t best_cap = 0;
+
+ dict = device_properties(newci->ci_dev);
+ if (prop_dictionary_get_uint32(dict, "capacity_dmips_mhz",
+ &capacity_dmips_mhz))
+ newci->ci_capacity_dmips_mhz = capacity_dmips_mhz;
+
+ if (newci->ci_capacity_dmips_mhz > best_cap)
+ best_cap = newci->ci_capacity_dmips_mhz;
+
+ /*
+ * CPU_INFO_FOREACH() doesn't always work for this CPU until
+ * mi_cpu_attach() is called and ncpu is bumped, so call it
+ * directly here. This also handles the not-MP case.
Home |
Main Index |
Thread Index |
Old Index