Module Name: src
Committed By: thorpej
Date: Wed Jan 1 22:57:17 UTC 2020
Modified Files:
src/sys/arch/arm/sunxi: sunxi_thermal.c
src/sys/arch/sparc64/dev: sbus.c
src/sys/compat/common: kern_xxx_12.c
src/sys/ddb: db_command.c
src/sys/dev/sysmon: swwdog.c sysmon_power.c
src/sys/external/bsd/drm2/include/linux: reboot.h
src/sys/kern: init_main.c kern_reboot.c kern_subr.c subr_prf.c
src/sys/sys: kernel.h reboot.h
Log Message:
- Introduce a new global kernel variable "shutting_down" to indicate that
the system is shutting down or rebooting.
- Set this global in a new function called kern_reboot(), which is currently
just a basic wrapper around cpu_reboot().
- Call kern_reboot() instead of cpu_reboot() almost everywhere; a few
places remain where it's still called directly, but those are in early
pre-main() machdep locations.
Eventually, all of the various cpu_reboot() functions should be re-factored
and common functionality moved to kern_reboot(), but that's for another day.
To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/arm/sunxi/sunxi_thermal.c
cvs rdiff -u -r1.97 -r1.98 src/sys/arch/sparc64/dev/sbus.c
cvs rdiff -u -r1.16 -r1.17 src/sys/compat/common/kern_xxx_12.c
cvs rdiff -u -r1.166 -r1.167 src/sys/ddb/db_command.c
cvs rdiff -u -r1.20 -r1.21 src/sys/dev/sysmon/swwdog.c
cvs rdiff -u -r1.61 -r1.62 src/sys/dev/sysmon/sysmon_power.c
cvs rdiff -u -r1.5 -r1.6 src/sys/external/bsd/drm2/include/linux/reboot.h
cvs rdiff -u -r1.515 -r1.516 src/sys/kern/init_main.c
cvs rdiff -u -r1.1 -r1.2 src/sys/kern/kern_reboot.c
cvs rdiff -u -r1.227 -r1.228 src/sys/kern/kern_subr.c
cvs rdiff -u -r1.181 -r1.182 src/sys/kern/subr_prf.c
cvs rdiff -u -r1.30 -r1.31 src/sys/sys/kernel.h
cvs rdiff -u -r1.25 -r1.26 src/sys/sys/reboot.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/arch/arm/sunxi/sunxi_thermal.c
diff -u src/sys/arch/arm/sunxi/sunxi_thermal.c:1.7 src/sys/arch/arm/sunxi/sunxi_thermal.c:1.8
--- src/sys/arch/arm/sunxi/sunxi_thermal.c:1.7 Wed Jan 2 19:32:41 2019
+++ src/sys/arch/arm/sunxi/sunxi_thermal.c Wed Jan 1 22:57:16 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_thermal.c,v 1.7 2019/01/02 19:32:41 jmcneill Exp $ */
+/* $NetBSD: sunxi_thermal.c,v 1.8 2020/01/01 22:57:16 thorpej Exp $ */
/*-
* Copyright (c) 2016-2017 Jared McNeill <[email protected]>
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sunxi_thermal.c,v 1.7 2019/01/02 19:32:41 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_thermal.c,v 1.8 2020/01/01 22:57:16 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -445,7 +445,7 @@ sunxi_thermal_task_shut(void *arg)
device_printf(sc->dev,
"WARNING - current temperature exceeds safe limits\n");
- cpu_reboot(RB_POWERDOWN, NULL);
+ kern_reboot(RB_POWERDOWN, NULL);
}
static void
Index: src/sys/arch/sparc64/dev/sbus.c
diff -u src/sys/arch/sparc64/dev/sbus.c:1.97 src/sys/arch/sparc64/dev/sbus.c:1.98
--- src/sys/arch/sparc64/dev/sbus.c:1.97 Sun Nov 10 21:16:33 2019
+++ src/sys/arch/sparc64/dev/sbus.c Wed Jan 1 22:57:16 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: sbus.c,v 1.97 2019/11/10 21:16:33 chs Exp $ */
+/* $NetBSD: sbus.c,v 1.98 2020/01/01 22:57:16 thorpej Exp $ */
/*
* Copyright (c) 1999-2002 Eduardo Horvath
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sbus.c,v 1.97 2019/11/10 21:16:33 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sbus.c,v 1.98 2020/01/01 22:57:16 thorpej Exp $");
#include "opt_ddb.h"
@@ -426,7 +426,7 @@ sbus_overtemp(void *arg)
/* Should try a clean shutdown first */
printf("DANGER: OVER TEMPERATURE detected\nShutting down...\n");
delay(20);
- cpu_reboot(RB_POWERDOWN|RB_HALT, NULL);
+ kern_reboot(RB_POWERDOWN|RB_HALT, NULL);
}
/*
Index: src/sys/compat/common/kern_xxx_12.c
diff -u src/sys/compat/common/kern_xxx_12.c:1.16 src/sys/compat/common/kern_xxx_12.c:1.17
--- src/sys/compat/common/kern_xxx_12.c:1.16 Sun Jan 27 02:08:39 2019
+++ src/sys/compat/common/kern_xxx_12.c Wed Jan 1 22:57:17 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_xxx_12.c,v 1.16 2019/01/27 02:08:39 pgoyette Exp $ */
+/* $NetBSD: kern_xxx_12.c,v 1.17 2020/01/01 22:57:17 thorpej Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993
@@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_xxx_12.c,v 1.16 2019/01/27 02:08:39 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_xxx_12.c,v 1.17 2020/01/01 22:57:17 thorpej Exp $");
#if defined(_KERNEL_OPT)
#include "opt_compat_netbsd.h"
@@ -69,7 +69,7 @@ compat_12_sys_reboot(struct lwp *l,
KAUTH_SYSTEM_REBOOT, 0, NULL, NULL, NULL)) != 0)
return (error);
KERNEL_LOCK(1, NULL);
- cpu_reboot(SCARG(uap, opt), NULL);
+ kern_reboot(SCARG(uap, opt), NULL);
KERNEL_UNLOCK_ONE(NULL);
return (0);
}
Index: src/sys/ddb/db_command.c
diff -u src/sys/ddb/db_command.c:1.166 src/sys/ddb/db_command.c:1.167
--- src/sys/ddb/db_command.c:1.166 Fri Dec 27 12:51:56 2019
+++ src/sys/ddb/db_command.c Wed Jan 1 22:57:17 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: db_command.c,v 1.166 2019/12/27 12:51:56 ad Exp $ */
+/* $NetBSD: db_command.c,v 1.167 2020/01/01 22:57:17 thorpej Exp $ */
/*
* Copyright (c) 1996, 1997, 1998, 1999, 2002, 2009, 2019
@@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.166 2019/12/27 12:51:56 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.167 2020/01/01 22:57:17 thorpej Exp $");
#ifdef _KERNEL_OPT
#include "opt_aio.h"
@@ -1397,7 +1397,7 @@ db_reboot_cmd(db_expr_t addr, bool have_
panicstr = "reboot forced via kernel debugger";
/* Make it possible to break into the debugger again */
spl0();
- cpu_reboot((int)bootflags, NULL);
+ kern_reboot((int)bootflags, NULL);
#else /* _KERNEL */
db_printf("This command can only be used in-kernel.\n");
#endif /* _KERNEL */
@@ -1464,7 +1464,7 @@ db_sync_cmd(db_expr_t addr, bool have_ad
*/
db_recover = 0;
panicstr = "dump forced via kernel debugger";
- cpu_reboot(RB_DUMP, NULL);
+ kern_reboot(RB_DUMP, NULL);
#else /* _KERNEL */
db_printf("This command can only be used in-kernel.\n");
#endif /* _KERNEL */
Index: src/sys/dev/sysmon/swwdog.c
diff -u src/sys/dev/sysmon/swwdog.c:1.20 src/sys/dev/sysmon/swwdog.c:1.21
--- src/sys/dev/sysmon/swwdog.c:1.20 Wed Mar 27 09:52:16 2019
+++ src/sys/dev/sysmon/swwdog.c Wed Jan 1 22:57:17 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: swwdog.c,v 1.20 2019/03/27 09:52:16 pgoyette Exp $ */
+/* $NetBSD: swwdog.c,v 1.21 2020/01/01 22:57:17 thorpej Exp $ */
/*
* Copyright (c) 2004, 2005 Steven M. Bellovin
@@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: swwdog.c,v 1.20 2019/03/27 09:52:16 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: swwdog.c,v 1.21 2020/01/01 22:57:17 thorpej Exp $");
/*
*
@@ -107,7 +107,7 @@ static void
doreboot(struct work *wrkwrkwrk, void *p)
{
- cpu_reboot(0, NULL);
+ kern_reboot(0, NULL);
}
int
Index: src/sys/dev/sysmon/sysmon_power.c
diff -u src/sys/dev/sysmon/sysmon_power.c:1.61 src/sys/dev/sysmon/sysmon_power.c:1.62
--- src/sys/dev/sysmon/sysmon_power.c:1.61 Tue Aug 20 18:43:57 2019
+++ src/sys/dev/sysmon/sysmon_power.c Wed Jan 1 22:57:17 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_power.c,v 1.61 2019/08/20 18:43:57 maxv Exp $ */
+/* $NetBSD: sysmon_power.c,v 1.62 2020/01/01 22:57:17 thorpej Exp $ */
/*-
* Copyright (c) 2007 Juan Romero Pardines.
@@ -69,7 +69,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysmon_power.c,v 1.61 2019/08/20 18:43:57 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_power.c,v 1.62 2020/01/01 22:57:17 thorpej Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
@@ -864,7 +864,7 @@ sysmon_penvsys_event(struct penvsys_stat
switch (event) {
case PENVSYS_EVENT_LOW_POWER:
printf("sysmon: LOW POWER! SHUTTING DOWN.\n");
- cpu_reboot(RB_POWERDOWN, NULL);
+ kern_reboot(RB_POWERDOWN, NULL);
break;
case PENVSYS_EVENT_STATE_CHANGED:
printf("%s: state changed on '%s' to '%s'\n",
@@ -1031,7 +1031,7 @@ sysmon_pswitch_event(struct sysmon_pswit
*/
printf("%s: power button pressed, shutting down!\n",
smpsw->smpsw_name);
- cpu_reboot(RB_POWERDOWN, NULL);
+ kern_reboot(RB_POWERDOWN, NULL);
break;
case PSWITCH_TYPE_RESET:
@@ -1046,7 +1046,7 @@ sysmon_pswitch_event(struct sysmon_pswit
*/
printf("%s: reset button pressed, rebooting!\n",
smpsw->smpsw_name);
- cpu_reboot(0, NULL);
+ kern_reboot(0, NULL);
break;
case PSWITCH_TYPE_SLEEP:
Index: src/sys/external/bsd/drm2/include/linux/reboot.h
diff -u src/sys/external/bsd/drm2/include/linux/reboot.h:1.5 src/sys/external/bsd/drm2/include/linux/reboot.h:1.6
--- src/sys/external/bsd/drm2/include/linux/reboot.h:1.5 Mon Aug 27 13:41:24 2018
+++ src/sys/external/bsd/drm2/include/linux/reboot.h Wed Jan 1 22:57:17 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: reboot.h,v 1.5 2018/08/27 13:41:24 riastradh Exp $ */
+/* $NetBSD: reboot.h,v 1.6 2020/01/01 22:57:17 thorpej Exp $ */
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -44,7 +44,7 @@ static inline int
orderly_poweroff(bool force __unused)
{
- cpu_reboot(RB_POWERDOWN, NULL);
+ kern_reboot(RB_POWERDOWN, NULL);
return 0;
}
Index: src/sys/kern/init_main.c
diff -u src/sys/kern/init_main.c:1.515 src/sys/kern/init_main.c:1.516
--- src/sys/kern/init_main.c:1.515 Wed Jan 1 21:09:11 2020
+++ src/sys/kern/init_main.c Wed Jan 1 22:57:17 2020
@@ -1,7 +1,7 @@
-/* $NetBSD: init_main.c,v 1.515 2020/01/01 21:09:11 thorpej Exp $ */
+/* $NetBSD: init_main.c,v 1.516 2020/01/01 22:57:17 thorpej Exp $ */
/*-
- * Copyright (c) 2008, 2009, 2019, The NetBSD Foundation, Inc.
+ * Copyright (c) 2008, 2009, 2019 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -97,7 +97,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.515 2020/01/01 21:09:11 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.516 2020/01/01 22:57:17 thorpej Exp $");
#include "opt_ddb.h"
#include "opt_inet.h"
@@ -241,6 +241,7 @@ struct proc *initproc;
struct vnode *rootvp, *swapdev_vp;
int boothowto;
int cold __read_mostly = 1; /* still working on startup */
+int shutting_down __read_mostly; /* system is shutting down */
struct timespec boottime; /* time at system startup - will only follow settime deltas */
int start_init_exec; /* semaphore for start_init() */
@@ -1015,9 +1016,9 @@ start_init(void *arg)
printf(": ");
len = cngetsn(ipath, sizeof(ipath)-1);
if (len == 4 && strcmp(ipath, "halt") == 0) {
- cpu_reboot(RB_HALT, NULL);
+ kern_reboot(RB_HALT, NULL);
} else if (len == 6 && strcmp(ipath, "reboot") == 0) {
- cpu_reboot(0, NULL);
+ kern_reboot(0, NULL);
#if defined(DDB)
} else if (len == 3 && strcmp(ipath, "ddb") == 0) {
console_debugger();
Index: src/sys/kern/kern_reboot.c
diff -u src/sys/kern/kern_reboot.c:1.1 src/sys/kern/kern_reboot.c:1.2
--- src/sys/kern/kern_reboot.c:1.1 Fri Sep 14 01:55:19 2018
+++ src/sys/kern/kern_reboot.c Wed Jan 1 22:57:17 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_reboot.c,v 1.1 2018/09/14 01:55:19 mrg Exp $ */
+/* $NetBSD: kern_reboot.c,v 1.2 2020/01/01 22:57:17 thorpej Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993
@@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_reboot.c,v 1.1 2018/09/14 01:55:19 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_reboot.c,v 1.2 2020/01/01 22:57:17 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -41,8 +41,26 @@ __KERNEL_RCSID(0, "$NetBSD: kern_reboot.
#include <sys/reboot.h>
#include <sys/syscall.h>
#include <sys/syscallargs.h>
+#include <sys/kernel.h>
#include <sys/kauth.h>
+/*
+ * Reboot / shutdown the system.
+ */
+void
+kern_reboot(int howto, char *bootstr)
+{
+
+ shutting_down = 1;
+
+ /*
+ * XXX We should re-factor out all of the common stuff
+ * that each and every cpu_reboot() does and put it here.
+ */
+
+ cpu_reboot(howto, bootstr);
+}
+
/* ARGSUSED */
int
sys_reboot(struct lwp *l, const struct sys_reboot_args *uap, register_t *retval)
@@ -70,7 +88,7 @@ sys_reboot(struct lwp *l, const struct s
* Not all ports use the bootstr currently.
*/
KERNEL_LOCK(1, NULL);
- cpu_reboot(SCARG(uap, opt), bootstr);
+ kern_reboot(SCARG(uap, opt), bootstr);
KERNEL_UNLOCK_ONE(NULL);
return (0);
}
Index: src/sys/kern/kern_subr.c
diff -u src/sys/kern/kern_subr.c:1.227 src/sys/kern/kern_subr.c:1.228
--- src/sys/kern/kern_subr.c:1.227 Mon Sep 16 00:01:16 2019
+++ src/sys/kern/kern_subr.c Wed Jan 1 22:57:17 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_subr.c,v 1.227 2019/09/16 00:01:16 manu Exp $ */
+/* $NetBSD: kern_subr.c,v 1.228 2020/01/01 22:57:17 thorpej Exp $ */
/*-
* Copyright (c) 1997, 1998, 1999, 2002, 2007, 2008 The NetBSD Foundation, Inc.
@@ -79,7 +79,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_subr.c,v 1.227 2019/09/16 00:01:16 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_subr.c,v 1.228 2020/01/01 22:57:17 thorpej Exp $");
#include "opt_ddb.h"
#include "opt_md.h"
@@ -405,9 +405,9 @@ setroot_ask(device_t bootdv, int bootpar
break;
}
if (len == 4 && strcmp(buf, "halt") == 0)
- cpu_reboot(RB_HALT, NULL);
+ kern_reboot(RB_HALT, NULL);
else if (len == 6 && strcmp(buf, "reboot") == 0)
- cpu_reboot(0, NULL);
+ kern_reboot(0, NULL);
#if defined(DDB)
else if (len == 3 && strcmp(buf, "ddb") == 0) {
console_debugger();
@@ -654,9 +654,9 @@ getdisk(const char *str, int len, int de
deviter_t di;
if (len == 4 && strcmp(str, "halt") == 0)
- cpu_reboot(RB_HALT, NULL);
+ kern_reboot(RB_HALT, NULL);
else if (len == 6 && strcmp(str, "reboot") == 0)
- cpu_reboot(0, NULL);
+ kern_reboot(0, NULL);
#if defined(DDB)
else if (len == 3 && strcmp(str, "ddb") == 0) {
console_debugger();
Index: src/sys/kern/subr_prf.c
diff -u src/sys/kern/subr_prf.c:1.181 src/sys/kern/subr_prf.c:1.182
--- src/sys/kern/subr_prf.c:1.181 Tue May 21 04:57:02 2019
+++ src/sys/kern/subr_prf.c Wed Jan 1 22:57:17 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_prf.c,v 1.181 2019/05/21 04:57:02 christos Exp $ */
+/* $NetBSD: subr_prf.c,v 1.182 2020/01/01 22:57:17 thorpej Exp $ */
/*-
* Copyright (c) 1986, 1988, 1991, 1993
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v 1.181 2019/05/21 04:57:02 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v 1.182 2020/01/01 22:57:17 thorpej Exp $");
#ifdef _KERNEL_OPT
#include "opt_ddb.h"
@@ -333,7 +333,7 @@ vpanic(const char *fmt, va_list ap)
#ifdef DDB
db_panic();
#endif
- cpu_reboot(bootopt, NULL);
+ kern_reboot(bootopt, NULL);
}
/*
Index: src/sys/sys/kernel.h
diff -u src/sys/sys/kernel.h:1.30 src/sys/sys/kernel.h:1.31
--- src/sys/sys/kernel.h:1.30 Sat Jun 2 22:25:30 2018
+++ src/sys/sys/kernel.h Wed Jan 1 22:57:17 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: kernel.h,v 1.30 2018/06/02 22:25:30 christos Exp $ */
+/* $NetBSD: kernel.h,v 1.31 2020/01/01 22:57:17 thorpej Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -55,6 +55,7 @@ extern struct timespec boottime;
extern int rtc_offset; /* offset of rtc from UTC in minutes */
extern int cold; /* still working on startup */
+extern int shutting_down; /* system is shutting down */
extern int tick; /* usec per tick (1000000 / hz) */
extern int tickadj; /* "standard" clock skew, us./tick */
extern int hardclock_ticks; /* # of hardclock ticks */
Index: src/sys/sys/reboot.h
diff -u src/sys/sys/reboot.h:1.25 src/sys/sys/reboot.h:1.26
--- src/sys/sys/reboot.h:1.25 Tue Dec 25 18:33:48 2007
+++ src/sys/sys/reboot.h Wed Jan 1 22:57:17 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: reboot.h,v 1.25 2007/12/25 18:33:48 perry Exp $ */
+/* $NetBSD: reboot.h,v 1.26 2020/01/01 22:57:17 thorpej Exp $ */
/*
* Copyright (c) 1982, 1986, 1988, 1993, 1994
@@ -114,8 +114,8 @@
__BEGIN_DECLS
-void cpu_reboot(int, char *)
- __dead;
+void kern_reboot(int, char *) __dead;
+void cpu_reboot(int, char *) __dead;
__END_DECLS