summaryrefslogtreecommitdiff
path: root/sys/src/9/port/devcons.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2015-11-30 14:56:00 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2015-11-30 14:56:00 +0100
commit7f3659e78f83a59badebeae6414b9b3cd89d7a58 (patch)
treef7d3b4c1efbc4e8ecc14ee6201563db3152012a2 /sys/src/9/port/devcons.c
parent254031cf7020f1b185c6d0af89c653a271e0ed01 (diff)
kernel: cleanup exit()/shutdown()/reboot() code
introduce cpushutdown() function that does the common operation of initiating shutdown, returning once all cpu's got the message and are about to shutdown. this avoids duplicated code which isnt really machine specific. automatic reboot on panic only when *debug= is not set and the machine is a cpu server or has no display, otherwise just hang.
Diffstat (limited to 'sys/src/9/port/devcons.c')
-rw-r--r--sys/src/9/port/devcons.c35
1 files changed, 32 insertions, 3 deletions
diff --git a/sys/src/9/port/devcons.c b/sys/src/9/port/devcons.c
index dc761f493..78f56afd1 100644
--- a/sys/src/9/port/devcons.c
+++ b/sys/src/9/port/devcons.c
@@ -260,9 +260,15 @@ panic(char *fmt, ...)
splx(s);
prflush();
dumpstack();
- if(!cpuserver)
- for(;;);
- exit(1);
+
+ /* reboot cpu servers and headless machines when not debugging */
+ if(getconf("*debug") == nil)
+ if(cpuserver || !conf.monitor)
+ exit(1);
+
+ /* otherwise, just hang */
+ while(islo()) idlehands();
+ for(;;);
}
/* libmp at least contains a few calls to sysfatal; simulate with panic */
@@ -1038,3 +1044,26 @@ writebintime(char *buf, int n)
}
return n;
}
+
+void
+cpushutdown(void)
+{
+ int ms, once;
+
+ lock(&active);
+ once = active.machs & (1<<m->machno);
+ active.machs &= ~(1<<m->machno);
+ active.exiting = 1;
+ unlock(&active);
+
+ if(once)
+ iprint("cpu%d: exiting\n", m->machno);
+
+ /* wait for any other processors to shutdown */
+ spllo();
+ for(ms = 5*1000; ms > 0; ms -= TK2MS(2)){
+ delay(TK2MS(2));
+ if(active.machs == 0 && consactive() == 0)
+ break;
+ }
+}