Source-Changes-HG archive

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

[src/trunk]: src/sys CPU_INFO_FOREACH() must always iterate at least the boot...



details:   https://anonhg.NetBSD.org/src/rev/14ba4f419e28
branches:  trunk
changeset: 828475:14ba4f419e28
user:      mrg <mrg%NetBSD.org@localhost>
date:      Sat Dec 16 00:37:51 2017 +0000

description:
CPU_INFO_FOREACH() must always iterate at least the boot cpu.
document this in sys/cpu.h and fix the arm and mips versions
to check ncpu is non zero before using it as an iterator max.

this should fix the new assert in init_main.c.

diffstat:

 sys/arch/arm/include/cpu.h  |   4 ++--
 sys/arch/mips/include/cpu.h |   4 ++--
 sys/sys/cpu.h               |  10 +++++++++-
 3 files changed, 13 insertions(+), 5 deletions(-)

diffs (60 lines):

diff -r 3f57bdfb2798 -r 14ba4f419e28 sys/arch/arm/include/cpu.h
--- a/sys/arch/arm/include/cpu.h        Fri Dec 15 23:57:42 2017 +0000
+++ b/sys/arch/arm/include/cpu.h        Sat Dec 16 00:37:51 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu.h,v 1.93 2017/04/04 09:26:32 sevan Exp $   */
+/*     $NetBSD: cpu.h,v 1.94 2017/12/16 00:37:51 mrg Exp $     */
 
 /*
  * Copyright (c) 1994-1996 Mark Brinicombe.
@@ -235,7 +235,7 @@
 #define cpu_number()           (curcpu()->ci_index)
 #define CPU_IS_PRIMARY(ci)     ((ci)->ci_index == 0)
 #define CPU_INFO_FOREACH(cii, ci)                      \
-       cii = 0, ci = cpu_info[0]; cii < ncpu && (ci = cpu_info[cii]) != NULL; cii++
+       cii = 0, ci = cpu_info[0]; cii < (ncpu ? ncpu : 1) && (ci = cpu_info[cii]) != NULL; cii++
 #else
 #define cpu_number()            0
 
diff -r 3f57bdfb2798 -r 14ba4f419e28 sys/arch/mips/include/cpu.h
--- a/sys/arch/mips/include/cpu.h       Fri Dec 15 23:57:42 2017 +0000
+++ b/sys/arch/mips/include/cpu.h       Sat Dec 16 00:37:51 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu.h,v 1.121 2016/10/31 12:49:04 skrll Exp $  */
+/*     $NetBSD: cpu.h,v 1.122 2017/12/16 00:37:52 mrg Exp $    */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -160,7 +160,7 @@
 #ifdef MULTIPROCESSOR
 #define        CPU_INFO_ITERATOR               int
 #define        CPU_INFO_FOREACH(cii, ci)       \
-    cii = 0, ci = cpu_infos[0]; cii < ncpu && (ci = cpu_infos[cii]) != NULL; cii++
+    cii = 0, ci = cpu_infos[0]; cii < (ncpu ? ncpu : 1) && (ci = cpu_infos[cii]) != NULL; cii++
 #else
 #define        CPU_INFO_ITERATOR               int __unused
 #define        CPU_INFO_FOREACH(cii, ci)       \
diff -r 3f57bdfb2798 -r 14ba4f419e28 sys/sys/cpu.h
--- a/sys/sys/cpu.h     Fri Dec 15 23:57:42 2017 +0000
+++ b/sys/sys/cpu.h     Sat Dec 16 00:37:51 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu.h,v 1.41 2014/05/19 20:39:23 rmind Exp $   */
+/*     $NetBSD: cpu.h,v 1.42 2017/12/16 00:37:51 mrg Exp $     */
 
 /*-
  * Copyright (c) 2007 YAMAMOTO Takashi,
@@ -63,6 +63,14 @@
 #define        cpu_did_resched(l)      /* nothing */
 #endif
 
+/*
+ * CPU_INFO_ITERATOR() may be supplied by machine dependent code as it
+ * controls how the cpu_info structures are allocated.
+ * 
+ * This macro must always iterate just the boot-CPU when the system has
+ * not attached any cpus via mi_cpu_attach() yet, and the "ncpu" variable
+ * is zero.
+ */
 #ifndef CPU_INFO_ITERATOR
 #define        CPU_INFO_ITERATOR               int
 #define        CPU_INFO_FOREACH(cii, ci)       \



Home | Main Index | Thread Index | Old Index