Module Name: src
Committed By: thorpej
Date: Tue Mar 5 14:39:30 UTC 2024
Modified Files:
src/sys/kern: init_main.c subr_cpu.c
src/sys/sys: cpu.h
Log Message:
Early in main(), assert that curcpu() evaluates as the primary CPU and
stash away a pointer to it as the boot CPU for quick reference later.
To generate a diff of this commit:
cvs rdiff -u -r1.547 -r1.548 src/sys/kern/init_main.c
cvs rdiff -u -r1.20 -r1.21 src/sys/kern/subr_cpu.c
cvs rdiff -u -r1.52 -r1.53 src/sys/sys/cpu.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/kern/init_main.c
diff -u src/sys/kern/init_main.c:1.547 src/sys/kern/init_main.c:1.548
--- src/sys/kern/init_main.c:1.547 Wed Jan 17 10:18:41 2024
+++ src/sys/kern/init_main.c Tue Mar 5 14:39:29 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: init_main.c,v 1.547 2024/01/17 10:18:41 hannken Exp $ */
+/* $NetBSD: init_main.c,v 1.548 2024/03/05 14:39:29 thorpej Exp $ */
/*-
* Copyright (c) 2008, 2009, 2019, 2023 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.547 2024/01/17 10:18:41 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.548 2024/03/05 14:39:29 thorpej Exp $");
#include "opt_cnmagic.h"
#include "opt_ddb.h"
@@ -275,7 +275,8 @@ main(void)
#ifdef DIAGNOSTIC
/*
* Verify that CPU_INFO_FOREACH() knows about the boot CPU
- * and only the boot CPU at this point.
+ * and only the boot CPU at this point. The boot CPU should
+ * also be marked PRIMARY.
*/
int cpucount = 0;
for (CPU_INFO_FOREACH(cii, ci)) {
@@ -283,8 +284,12 @@ main(void)
cpucount++;
}
KASSERT(cpucount == 1);
+ KASSERT(CPU_IS_PRIMARY(curcpu()));
#endif
+ /* Stash a pointer to the boot CPU for quick reference wheen needed. */
+ boot_cpu = curcpu();
+
l = &lwp0;
#ifndef LWP0_CPU_INFO
l->l_cpu = curcpu();
Index: src/sys/kern/subr_cpu.c
diff -u src/sys/kern/subr_cpu.c:1.20 src/sys/kern/subr_cpu.c:1.21
--- src/sys/kern/subr_cpu.c:1.20 Thu Jan 4 11:18:19 2024
+++ src/sys/kern/subr_cpu.c Tue Mar 5 14:39:29 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_cpu.c,v 1.20 2024/01/04 11:18:19 mlelstv Exp $ */
+/* $NetBSD: subr_cpu.c,v 1.21 2024/03/05 14:39:29 thorpej Exp $ */
/*-
* Copyright (c) 2007, 2008, 2009, 2010, 2012, 2019, 2020
@@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_cpu.c,v 1.20 2024/01/04 11:18:19 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_cpu.c,v 1.21 2024/03/05 14:39:29 thorpej Exp $");
#include <sys/param.h>
#include <sys/atomic.h>
@@ -86,6 +86,9 @@ int64_t cpu_counts[CPU_COUNT_MAX];
/* An array of CPUs. There are ncpu entries. */
struct cpu_info **cpu_infos __read_mostly;
+/* A pointer to the boot CPU, for quick reference when needed. */
+struct cpu_info *boot_cpu __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;
Index: src/sys/sys/cpu.h
diff -u src/sys/sys/cpu.h:1.52 src/sys/sys/cpu.h:1.53
--- src/sys/sys/cpu.h:1.52 Sat Jul 8 13:59:05 2023
+++ src/sys/sys/cpu.h Tue Mar 5 14:39:29 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.52 2023/07/08 13:59:05 riastradh Exp $ */
+/* $NetBSD: cpu.h,v 1.53 2024/03/05 14:39:29 thorpej Exp $ */
/*-
* Copyright (c) 2007 YAMAMOTO Takashi,
@@ -100,6 +100,7 @@ void cpu_topology_init(void);
extern kmutex_t cpu_lock;
extern u_int maxcpus;
extern struct cpu_info **cpu_infos;
+extern struct cpu_info *boot_cpu;
extern kcpuset_t *kcpuset_attached;
extern kcpuset_t *kcpuset_running;