This patch address a couple of long-standing issues revolving around kernel panics and use of rdb. Previously, rdb simply did not work on mp systems, as it assumed a splhi was sufficient to lock system resources. On an mp system, unless the uart ISR happened to be wired to the same CPU that has dropped into rdb, I/O will be stolen from the getc poll rdb relies on to communicate with the remote debugger. To fix this behavior, rdb must lock out other machs to avoid sharing resources. panic is similarly afflicted. A splhi is issued which is typically not enough, often resulting in corrupted dumpstack output from prints on other machs. Another interesting side-effect is that procs will continue to run on machs not participating in the panic. These changes made panic a first class citizen rather than a variant of shutdown. To handle both cases, panic (and each arch) have been updated to stall out other machs on the next clock interrupt. This is somewhat similiar to the exiting mechanism. The difference is that this allows the system to pre-emptively shutdown machs apart from exit, which happens too late. A nice side-effect of this change is that not only does this correct rdb behavior, but it also handles the corrupted dumpstack and racing procs issues nicely. A final change introduced a new plan9.ini conf variable, consdebug which enables ^T^Td at boot, which permits use of rdb early in the boot process. Reference: /n/sources/patch/maybe/panic-rdb Date: Sat Sep 15 22:58:55 CES 2012 Signed-off-by: sstallion@gmail.com --- /sys/src/9/alphapc/dat.h Sat Sep 15 22:18:43 2012 +++ /sys/src/9/alphapc/dat.h Sat Sep 15 22:18:41 2012 @@ -186,7 +186,7 @@ Lock; short machs; short exiting; - short ispanic; + short panicking; }active; /* --- /sys/src/9/alphapc/faultalpha.c Sat Sep 15 22:18:47 2012 +++ /sys/src/9/alphapc/faultalpha.c Sat Sep 15 22:18:45 2012 @@ -46,7 +46,7 @@ mmudump(); dumpregs(ur); _dumpstack(ur); - exit(1); + exit(); } /* --- /sys/src/9/alphapc/kbd.c Sat Sep 15 22:18:51 2012 +++ /sys/src/9/alphapc/kbd.c Sat Sep 15 22:18:49 2012 @@ -322,7 +322,7 @@ if(!(c & (Spec|KF))){ if(ctl){ if(alt && c == Del) - exit(0); + exit(); c &= 0x1f; } if(!collecting){ --- /sys/src/9/alphapc/main.c Sat Sep 15 22:18:56 2012 +++ /sys/src/9/alphapc/main.c Sat Sep 15 22:18:53 2012 @@ -156,8 +156,9 @@ memset(m, 0, sizeof(Mach)); m->machno = n; - active.exiting = 0; active.machs = 1; + active.exiting = 0; + active.panicking = 0; cpu = (Hwcpu*) ((ulong)hwrpb + hwrpb->cpuoff + n*hwrpb->cpulen); cpu->state &= ~Cpubootinprog; @@ -306,15 +307,11 @@ /* from ../pc */ static void -shutdown(int ispanic) +shutdown(void) { int ms, once; lock(&active); - if(ispanic) - active.ispanic = ispanic; - else if(m->machno == 0 && (active.machs & (1<machno)) == 0) - active.ispanic = 0; once = active.machs & (1<machno); active.machs &= ~(1<machno); active.exiting = 1; @@ -322,21 +319,22 @@ if(once) print("cpu%d: exiting\n", m->machno); - spllo(); - for(ms = 5*1000; ms > 0; ms -= TK2MS(2)){ - delay(TK2MS(2)); - if(active.machs == 0 && consactive() == 0) - break; - } - if(active.ispanic && m->machno == 0) { + if(active.panicking){ if(cpuserver) delay(10000); else for (;;) continue; - } else + }else{ + spllo(); + for(ms = 5*1000; ms > 0; ms -= TK2MS(2)){ + delay(TK2MS(2)); + if(active.machs == 0 && consactive() == 0) + break; + } delay(1000); + } } /* from ../pc: */ @@ -344,7 +342,7 @@ reboot(void *entry, void *code, ulong size) { // writeconf(); // pass kernel environment to next kernel - shutdown(0); + shutdown(); /* * should be the only processor running now @@ -387,11 +385,11 @@ } #endif setupboot(0); // reboot, don't halt - exit(0); + exit(); } void -exit(int ispanic) +exit(void) { canlock(&active); active.machs &= ~(1<machno); @@ -406,10 +404,8 @@ splhi(); delay(1000); /* give serial fifo time to finish flushing */ - if (getconf("*debug") != nil) { - USED(ispanic); + if (getconf("*debug") != nil) delay(60*1000); /* give us time to read the screen */ - } if(arch->coredetach) arch->coredetach(); setupboot(1); // set up to halt @@ -418,7 +414,7 @@ // on PC is just: //if (0) { - // shutdown(ispanic); + // shutdown(); // arch->reset(); //} } --- /sys/src/9/alphapc/trap.c Sat Sep 15 22:19:02 2012 +++ /sys/src/9/alphapc/trap.c Sat Sep 15 22:18:58 2012 @@ -388,7 +388,7 @@ dumpstack(); if(m->machno == 0) spllo(); - exit(1); + exit(); } void @@ -411,7 +411,7 @@ l.sp = ur->sp; l.pc = ur->pc; dumpstack(); - exit(1); + exit(); } void --- /sys/src/9/bitsy/dat.h Sat Sep 15 22:19:06 2012 +++ /sys/src/9/bitsy/dat.h Sat Sep 15 22:19:04 2012 @@ -183,7 +183,7 @@ Lock; int machs; /* bitmap of active CPUs */ int exiting; /* shutdown */ - int ispanic; /* shutdown in response to a panic */ + int panicking; /* panic */ }active; #define MACHP(n) ((Mach *)(MACHADDR+(n)*BY2PG)) --- /sys/src/9/bitsy/main.c Sat Sep 15 22:19:11 2012 +++ /sys/src/9/bitsy/main.c Sat Sep 15 22:19:08 2012 @@ -56,7 +56,7 @@ void reboot(void*, void*, ulong) { - exit(0); + exit(); } @@ -64,11 +64,10 @@ * exit kernel either on a panic or user request */ void -exit(int ispanic) +exit(void) { void (*f)(void); - USED(ispanic); delay(1000); iprint("it's a wonderful day to die\n"); --- /sys/src/9/kw/dat.h Sat Sep 15 22:19:15 2012 +++ /sys/src/9/kw/dat.h Sat Sep 15 22:19:13 2012 @@ -195,7 +195,7 @@ Lock; int machs; /* bitmap of active CPUs */ int exiting; /* shutdown */ - int ispanic; /* shutdown in response to a panic */ + int panicking; /* panic */ }active; enum { --- /sys/src/9/kw/main.c Sat Sep 15 22:19:20 2012 +++ /sys/src/9/kw/main.c Sat Sep 15 22:19:18 2012 @@ -361,20 +361,17 @@ active.machs = 1; active.exiting = 0; + active.panicking = 0; up = nil; } static void -shutdown(int ispanic) +shutdown(void) { int ms, once; lock(&active); - if(ispanic) - active.ispanic = ispanic; - else if(m->machno == 0 && (active.machs & (1<machno)) == 0) - active.ispanic = 0; once = active.machs & (1<machno); active.machs &= ~(1<machno); active.exiting = 1; @@ -382,11 +379,14 @@ if(once) iprint("cpu%d: exiting\n", m->machno); - spllo(); - for(ms = 5*1000; ms > 0; ms -= TK2MS(2)){ - delay(TK2MS(2)); - if(active.machs == 0 && consactive() == 0) - break; + + if(!active.panicking){ + spllo(); + for(ms = 5*1000; ms > 0; ms -= TK2MS(2)){ + delay(TK2MS(2)); + if(active.machs == 0 && consactive() == 0) + break; + } } delay(1000); } @@ -395,9 +395,9 @@ * exit kernel either on a panic or user request */ void -exit(int code) +exit(void) { - shutdown(code); + shutdown(); splhi(); archreboot(); } @@ -414,7 +414,7 @@ iprint("starting reboot..."); writeconf(); - shutdown(0); + shutdown(); /* * should be the only processor running now @@ -644,7 +644,7 @@ */ if(nelem(sheevamem) > nelem(conf.mem)){ iprint("memory configuration botch\n"); - exit(1); + exit(); } if((p = getconf("*maxmem")) != nil) { memsize = strtoul(p, 0, 0) - PHYSDRAM; --- /sys/src/9/mtx/dat.h Sat Sep 15 22:19:25 2012 +++ /sys/src/9/mtx/dat.h Sat Sep 15 22:19:23 2012 @@ -186,7 +186,7 @@ Lock; short machs; short exiting; - short ispanic; + short panicking; }active; /* --- /sys/src/9/mtx/kbd.c Sat Sep 15 22:19:30 2012 +++ /sys/src/9/mtx/kbd.c Sat Sep 15 22:19:27 2012 @@ -322,7 +322,7 @@ if(!(c & (Spec|KF))){ if(ctl){ if(alt && c == Del) - exit(0); + exit(); c &= 0x1f; } if(!collecting){ --- /sys/src/9/mtx/main.c Sat Sep 15 22:19:36 2012 +++ /sys/src/9/mtx/main.c Sat Sep 15 22:19:33 2012 @@ -62,6 +62,7 @@ active.machs = 1; active.exiting = 0; + active.panicking = 0; } void @@ -212,19 +213,15 @@ void reboot(void*, void*, ulong) { - exit(0); + exit(); } void -exit(int ispanic) +exit(void) { int ms, once; lock(&active); - if(ispanic) - active.ispanic = ispanic; - else if(m->machno == 0 && (active.machs & (1<machno)) == 0) - active.ispanic = 0; once = active.machs & (1<machno); active.machs &= ~(1<machno); active.exiting = 1; @@ -232,21 +229,21 @@ if(once) print("cpu%d: exiting\n", m->machno); - spllo(); - for(ms = 5*1000; ms > 0; ms -= TK2MS(2)){ - delay(TK2MS(2)); - if(active.machs == 0 && consactive() == 0) - break; - } - if(active.ispanic && m->machno == 0){ + if(active.panicking){ if(cpuserver) delay(10000); else if(conf.monitor) for(;;); - } - else + }else{ + spllo(); + for(ms = 5*1000; ms > 0; ms -= TK2MS(2)){ + delay(TK2MS(2)); + if(active.machs == 0 && consactive() == 0) + break; + } delay(1000); + } watchreset(); } --- /sys/src/9/omap/dat.h Sat Sep 15 22:19:41 2012 +++ /sys/src/9/omap/dat.h Sat Sep 15 22:19:39 2012 @@ -217,7 +217,7 @@ Lock; int machs; /* bitmap of active CPUs */ int exiting; /* shutdown */ - int ispanic; /* shutdown in response to a panic */ + int panicking; /* panic */ }active; extern register Mach* m; /* R10 */ --- /sys/src/9/omap/devcons.c Sat Sep 15 22:19:46 2012 +++ /sys/src/9/omap/devcons.c Sat Sep 15 22:19:43 2012 @@ -17,8 +17,6 @@ ulong kprintinuse; /* test and set whether /dev/kprint is open */ int iprintscreenputs = 1; -int panicking; - static struct { QLock; @@ -281,18 +279,18 @@ void panic(char *fmt, ...) { - int n, s; + int n; va_list arg; char buf[PRINTSIZE]; kprintoq = nil; /* don't try to write to /dev/kprint */ - if(panicking) + splhi(); + if(active.panicking) for(;;); - panicking = 1; + active.panicking = 1; delay(20); - s = splhi(); strcpy(buf, "panic: "); va_start(arg, fmt); n = vseprint(buf+strlen(buf), buf+sizeof(buf), fmt, arg) - buf; @@ -300,13 +298,12 @@ iprint("%s\n", buf); if(consdebug) (*consdebug)(); - splx(s); prflush(); buf[n] = '\n'; // putstrn(buf, n+1); // dumpstack(); - exit(1); + exit(); } /* libmp at least contains a few calls to sysfatal; simulate with panic */ @@ -472,7 +469,7 @@ case 'D': if(consdebug == nil) consdebug = rdb; - consdebug(); + panic("consdebug"); return; case 'p': x = spllo(); @@ -486,7 +483,7 @@ killbig("^t ^t k"); return; case 'r': - exit(0); + exit(); return; } } @@ -668,6 +665,10 @@ static void consinit(void) { + char *s; + + if((s = getconf("consdebug")) != nil && strcmp(s, "0") != 0) + consdebug = rdb; todinit(); randominit(); /* --- /sys/src/9/omap/kbd.c Sat Sep 15 22:19:51 2012 +++ /sys/src/9/omap/kbd.c Sat Sep 15 22:19:49 2012 @@ -268,7 +268,7 @@ if(!(c & (Spec|KF))){ if(kbscan->ctl) if(kbscan->alt && c == Del) - exit(0); + exit(); if(!kbscan->collecting){ kbdputc(kbdq, c); return; --- /sys/src/9/omap/main.c Sat Sep 15 22:19:57 2012 +++ /sys/src/9/omap/main.c Sat Sep 15 22:19:54 2012 @@ -297,20 +297,17 @@ active.machs = 1; active.exiting = 0; + active.panicking = 0; up = nil; } static void -shutdown(int ispanic) +shutdown(void) { int ms, once; lock(&active); - if(ispanic) - active.ispanic = ispanic; - else if(m->machno == 0 && (active.machs & (1<machno)) == 0) - active.ispanic = 0; once = active.machs & (1<machno); active.machs &= ~(1<machno); active.exiting = 1; @@ -318,11 +315,14 @@ if(once) iprint("cpu%d: exiting\n", m->machno); - spllo(); - for(ms = 5*1000; ms > 0; ms -= TK2MS(2)){ - delay(TK2MS(2)); - if(active.machs == 0 && consactive() == 0) - break; + + if(!active.panicking){ + spllo(); + for(ms = 5*1000; ms > 0; ms -= TK2MS(2)){ + delay(TK2MS(2)); + if(active.machs == 0 && consactive() == 0) + break; + } } delay(1000); } @@ -331,9 +331,9 @@ * exit kernel either on a panic or user request */ void -exit(int code) +exit(void) { - shutdown(code); + shutdown(); splhi(); archreboot(); } @@ -382,7 +382,7 @@ print("starting reboot..."); writeconf(); - shutdown(0); + shutdown(); /* * should be the only processor running now @@ -613,7 +613,7 @@ */ if(nelem(omapmem) > nelem(conf.mem)){ iprint("memory configuration botch\n"); - exit(1); + exit(); } if((p = getconf("*maxmem")) != nil) { memsize = strtoul(p, 0, 0) - PHYSDRAM; --- /sys/src/9/pc/dat.h Sat Sep 15 22:20:03 2012 +++ /sys/src/9/pc/dat.h Sat Sep 15 22:20:00 2012 @@ -277,7 +277,7 @@ Lock; int machs; /* bitmap of active CPUs */ int exiting; /* shutdown */ - int ispanic; /* shutdown in response to a panic */ + int panicking; /* panic */ int thunderbirdsarego; /* lets the added processors continue to schedinit */ int rebooting; /* just idle cpus > 0 */ }active; --- /sys/src/9/pc/kbd.c Sat Sep 15 22:20:09 2012 +++ /sys/src/9/pc/kbd.c Sat Sep 15 22:20:06 2012 @@ -469,7 +469,7 @@ if(!(c & (Spec|KF))){ if(kbscan->ctl) if(kbscan->alt && c == Del) - exit(0); + exit(); if(!kbscan->collecting){ kbdputc(kbdq, c); return; --- /sys/src/9/pc/main.c Sat Sep 15 22:20:16 2012 +++ /sys/src/9/pc/main.c Sat Sep 15 22:20:13 2012 @@ -144,6 +144,7 @@ active.machs = 1; active.exiting = 0; + active.panicking = 0; } void @@ -712,22 +713,18 @@ } static void -shutdown(int ispanic) +shutdown(void) { int ms, once; lock(&active); - if(ispanic) - active.ispanic = ispanic; - else if(m->machno == 0 && (active.machs & (1<machno)) == 0) - active.ispanic = 0; once = active.machs & (1<machno); /* - * setting exiting will make hzclock() on each processor call exit(0), - * which calls shutdown(0) and arch->reset(), which on mp systems is + * setting exiting will make hzclock() on each processor call exit(), + * which calls shutdown() and arch->reset(), which on mp systems is * mpshutdown, which idles non-bootstrap cpus and returns on bootstrap * processors (to permit a reboot). clearing our bit in machs avoids - * calling exit(0) from hzclock() on this processor. + * calling exit() from hzclock() on this processor. */ active.machs &= ~(1<machno); active.exiting = 1; @@ -736,15 +733,7 @@ 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; - } - - if(active.ispanic){ + if(active.panicking){ if(!cpuserver) for(;;) halt(); @@ -752,8 +741,16 @@ delay(5*60*1000); else delay(10000); - }else + }else{ + /* 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; + } delay(1000); + } } void @@ -784,7 +781,7 @@ lock(&active); active.rebooting = 1; unlock(&active); - shutdown(0); + shutdown(); if(arch->resetothers) arch->resetothers(); delay(20); @@ -830,9 +827,9 @@ void -exit(int ispanic) +exit(void) { - shutdown(ispanic); + shutdown(); arch->reset(); } --- /sys/src/9/pcboot/dat.h Sat Sep 15 22:20:22 2012 +++ /sys/src/9/pcboot/dat.h Sat Sep 15 22:20:20 2012 @@ -279,7 +279,7 @@ Lock; int machs; /* bitmap of active CPUs */ int exiting; /* shutdown */ - int ispanic; /* shutdown in response to a panic */ + int panicking; /* panic */ int thunderbirdsarego; /* lets the added processors continue to schedinit */ int rebooting; /* just idle cpus > 0 */ }active; --- /sys/src/9/pcboot/main.c Sat Sep 15 22:20:29 2012 +++ /sys/src/9/pcboot/main.c Sat Sep 15 22:20:26 2012 @@ -227,6 +227,7 @@ active.machs = 1; active.exiting = 0; + active.panicking = 0; } void @@ -498,22 +499,18 @@ } static void -shutdown(int ispanic) +shutdown(void) { int ms, once; lock(&active); - if(ispanic) - active.ispanic = ispanic; - else if(m->machno == 0 && (active.machs & (1<machno)) == 0) - active.ispanic = 0; once = active.machs & (1<machno); /* - * setting exiting will make hzclock() on each processor call exit(0), - * which calls shutdown(0) and arch->reset(), which on mp systems is + * setting exiting will make hzclock() on each processor call exit(), + * which calls shutdown() and arch->reset(), which on mp systems is * mpshutdown, which idles non-bootstrap cpus and returns on bootstrap * processors (to permit a reboot). clearing our bit in machs avoids - * calling exit(0) from hzclock() on this processor. + * calling exit() from hzclock() on this processor. */ active.machs &= ~(1<machno); active.exiting = 1; @@ -522,15 +519,7 @@ 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; - } - - if(active.ispanic){ + if(active.panicking){ if(!cpuserver) for(;;) halt(); @@ -538,8 +527,16 @@ delay(5*60*1000); else delay(10000); - }else + }else{ + /* 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; + } delay(1000); + } } void @@ -572,7 +569,7 @@ lock(&active); active.rebooting = 1; unlock(&active); - shutdown(0); + shutdown(); if(arch->resetothers) arch->resetothers(); delay(20); @@ -619,10 +616,9 @@ void -exit(int ispanic) +exit(void) { - shutdown(ispanic); - spllo(); + shutdown(); arch->reset(); } --- /sys/src/9/pcboot/warp64.c Sat Sep 15 22:20:32 2012 +++ /sys/src/9/pcboot/warp64.c Sat Sep 15 22:20:30 2012 @@ -49,7 +49,7 @@ if(!havelongmode()) { print("can't run 64-bit kernel on 32-bit cpu\n"); delay(5000); - exit(0); + exit(); } if(v_flag) print("mkmultiboot\n"); --- /sys/src/9/port/allocb.c Sat Sep 15 22:20:36 2012 +++ /sys/src/9/port/allocb.c Sat Sep 15 22:20:34 2012 @@ -84,7 +84,7 @@ if((m1++%10000)==0){ if(mp++ > 1000){ active.exiting = 1; - exit(0); + exit(); } iprint("iallocb: limited %lud/%lud\n", ialloc.bytes, conf.ialloc); @@ -96,7 +96,7 @@ if((m2++%10000)==0){ if(mp++ > 1000){ active.exiting = 1; - exit(0); + exit(); } iprint("iallocb: no memory %lud/%lud\n", ialloc.bytes, conf.ialloc); --- /sys/src/9/port/devcons.c Sat Sep 15 22:20:41 2012 +++ /sys/src/9/port/devcons.c Sat Sep 15 22:20:38 2012 @@ -18,8 +18,6 @@ ulong kprintinuse; /* test and set whether /dev/kprint is open */ int iprintscreenputs = 1; -int panicking; - static struct { QLock; @@ -272,17 +270,17 @@ void panic(char *fmt, ...) { - int n, s; + int n; va_list arg; char buf[PRINTSIZE]; kprintoq = nil; /* don't try to write to /dev/kprint */ - if(panicking) + splhi(); + if(active.panicking) for(;;); - panicking = 1; + active.panicking = 1; - s = splhi(); strcpy(buf, "panic: "); va_start(arg, fmt); n = vseprint(buf+strlen(buf), buf+sizeof(buf), fmt, arg) - buf; @@ -290,13 +288,12 @@ iprint("%s\n", buf); if(consdebug) (*consdebug)(); - splx(s); prflush(); buf[n] = '\n'; putstrn(buf, n+1); dumpstack(); - exit(1); + exit(); } /* libmp at least contains a few calls to sysfatal; simulate with panic */ @@ -462,7 +459,7 @@ case 'D': if(consdebug == nil) consdebug = rdb; - consdebug(); + panic("consdebug"); return; case 'p': x = spllo(); @@ -476,7 +473,7 @@ killbig("^t ^t k"); return; case 'r': - exit(0); + exit(); return; } } @@ -660,6 +657,10 @@ static void consinit(void) { + char *s; + + if((s = getconf("consdebug")) != nil && strcmp(s, "0") != 0) + consdebug = rdb; todinit(); randominit(); /* --- /sys/src/9/port/edf.c Sat Sep 15 22:20:46 2012 +++ /sys/src/9/port/edf.c Sat Sep 15 22:20:43 2012 @@ -134,11 +134,10 @@ deadlineintr(Ureg*, Timer *t) { /* Proc reached deadline */ - extern int panicking; Proc *p; void (*pt)(Proc*, int, vlong); - if(panicking || active.exiting) + if(active.exiting || active.panicking) return; p = t->ta; @@ -210,10 +209,9 @@ releaseintr(Ureg*, Timer *t) { Proc *p; - extern int panicking; Schedq *rq; - if(panicking || active.exiting) + if(active.exiting || active.panicking) return; p = t->ta; --- /sys/src/9/port/portclock.c Sat Sep 15 22:20:49 2012 +++ /sys/src/9/port/portclock.c Sat Sep 15 22:20:47 2012 @@ -156,8 +156,10 @@ if(active.exiting) { print("someone's exiting\n"); - exit(0); + exit(); } + if(active.panicking) + for(;;); checkalarms(); --- /sys/src/9/port/portfns.h Sat Sep 15 22:20:54 2012 +++ /sys/src/9/port/portfns.h Sat Sep 15 22:20:51 2012 @@ -100,7 +100,7 @@ void error(char*); long execregs(ulong, ulong, ulong); void exhausted(char*); -void exit(int); +void exit(void); uvlong fastticks(uvlong*); uvlong fastticks2ns(uvlong); uvlong fastticks2us(uvlong); --- /sys/src/9/port/rebootcmd.c Sat Sep 15 22:20:57 2012 +++ /sys/src/9/port/rebootcmd.c Sat Sep 15 22:20:55 2012 @@ -59,7 +59,7 @@ uchar *p; if(argc == 0) - exit(0); + exit(); c = namec(argv[0], Aopen, OEXEC, 0); if(waserror()){ --- /sys/src/9/port/ucallocb.c Sat Sep 15 22:21:01 2012 +++ /sys/src/9/port/ucallocb.c Sat Sep 15 22:20:59 2012 @@ -84,7 +84,7 @@ if((m1++%10000)==0){ if(mp++ > 1000){ active.exiting = 1; - exit(0); + exit(); } iprint("uciallocb: limited %lud/%lud\n", ucialloc.bytes, conf.ialloc); @@ -96,7 +96,7 @@ if(0 && (m2++%10000)==0){ if(mp++ > 1000){ active.exiting = 1; - exit(0); + exit(); } iprint("uciallocb: no memory %lud/%lud\n", ucialloc.bytes, conf.ialloc); --- /sys/src/9/ppc/dat.h Sat Sep 15 22:21:07 2012 +++ /sys/src/9/ppc/dat.h Sat Sep 15 22:21:05 2012 @@ -191,7 +191,7 @@ Lock; short machs; short exiting; - short ispanic; + short panicking; }active; /* --- /sys/src/9/ppc/main.c Sat Sep 15 22:21:13 2012 +++ /sys/src/9/ppc/main.c Sat Sep 15 22:21:11 2012 @@ -243,15 +243,11 @@ } void -exit(int ispanic) +exit(void) { int ms, once; lock(&active); - if(ispanic) - active.ispanic = ispanic; - else if(m->machno == 0 && (active.machs & (1<machno)) == 0) - active.ispanic = 0; once = active.machs & (1<machno); active.machs &= ~(1<machno); active.exiting = 1; @@ -259,22 +255,21 @@ if(once) print("cpu%d: exiting\n", m->machno); - spllo(); - for(ms = 5*1000; ms > 0; ms -= TK2MS(2)){ - delay(TK2MS(2)); - if(active.machs == 0 && consactive() == 0) - break; - } - if(active.ispanic && m->machno == 0){ + if(active.panicking){ if(cpuserver) delay(10000); else if(conf.monitor) for(;;); - } - else + }else{ + spllo(); + for(ms = 5*1000; ms > 0; ms -= TK2MS(2)){ + delay(TK2MS(2)); + if(active.machs == 0 && consactive() == 0) + break; + } delay(1000); - + } } /* --- /sys/src/9/ppc/msaturn.c Sat Sep 15 22:21:17 2012 +++ /sys/src/9/ppc/msaturn.c Sat Sep 15 22:21:15 2012 @@ -142,6 +142,7 @@ active.machs = 1; active.exiting = 0; + active.panicking = 0; putmsr(getmsr() | MSR_ME); --- /sys/src/9/teg2/dat.h Sat Sep 15 22:21:24 2012 +++ /sys/src/9/teg2/dat.h Sat Sep 15 22:21:21 2012 @@ -249,7 +249,7 @@ int wfi; /* bitmap of CPUs in WFI state */ int stopped; /* bitmap of CPUs stopped */ int exiting; /* shutdown */ - int ispanic; /* shutdown in response to a panic */ + int panicking; /* panic */ int thunderbirdsarego; /* lets the added processors continue to schedinit */ }active; --- /sys/src/9/teg2/devcons.c Sat Sep 15 22:21:30 2012 +++ /sys/src/9/teg2/devcons.c Sat Sep 15 22:21:26 2012 @@ -18,8 +18,6 @@ ulong kprintinuse; /* test and set whether /dev/kprint is open */ int iprintscreenputs = 1; -int panicking; - static struct { QLock; @@ -282,17 +280,17 @@ void panic(char *fmt, ...) { - int n, s; + int n; va_list arg; char buf[PRINTSIZE]; kprintoq = nil; /* don't try to write to /dev/kprint */ - if(panicking) + splhi(); + if(active.panicking) for(;;); - panicking = 1; + active.panicking = 1; - s = splhi(); delay(2000); strcpy(buf, "\npanic: "); va_start(arg, fmt); @@ -301,7 +299,6 @@ iprint("%s\n", buf); if(consdebug) (*consdebug)(); - splx(s); prflush(); USED(n); // buf[n] = '\n'; @@ -309,7 +306,7 @@ // dumpstack(); delay(2000); - exit(1); + exit(); } /* libmp at least contains a few calls to sysfatal; simulate with panic */ @@ -475,7 +472,7 @@ case 'D': if(consdebug == nil) consdebug = rdb; - consdebug(); + panic("consdebug"); return; case 'p': x = spllo(); @@ -489,7 +486,7 @@ killbig("^t ^t k"); return; case 'r': - exit(0); + exit(); return; } } @@ -673,6 +670,10 @@ static void consinit(void) { + char *s; + + if((s = getconf("consdebug")) != nil && strcmp(s, "0") != 0) + consdebug = rdb; todinit(); randominit(); /* --- /sys/src/9/teg2/kbd.c Sat Sep 15 22:21:36 2012 +++ /sys/src/9/teg2/kbd.c Sat Sep 15 22:21:33 2012 @@ -268,7 +268,7 @@ if(!(c & (Spec|KF))){ if(kbscan->ctl) if(kbscan->alt && c == Del) - exit(0); + exit(); if(!kbscan->collecting){ kbdputc(kbdq, c); return; --- /sys/src/9/teg2/main.c Sat Sep 15 22:21:44 2012 +++ /sys/src/9/teg2/main.c Sat Sep 15 22:21:40 2012 @@ -291,6 +291,7 @@ machinit(); active.exiting = 0; + active.panicking = 0; l1cache->wbse(&active, sizeof active); up = nil; } @@ -482,21 +483,17 @@ } static void -shutdown(int ispanic) +shutdown(void) { int ms, once; lock(&active); - if(ispanic) - active.ispanic = ispanic; - else if(m->machno == 0 && (active.machs & (1<machno)) == 0) - active.ispanic = 0; once = active.machs & (1<machno); /* - * setting exiting will make hzclock() on each processor call exit(0), - * which calls shutdown(0) and idles non-bootstrap cpus and returns + * setting exiting will make hzclock() on each processor call exit(), + * which calls shutdown() and idles non-bootstrap cpus and returns * on bootstrap processors (to permit a reboot). clearing our bit - * in machs avoids calling exit(0) from hzclock() on this processor. + * in machs avoids calling exit() from hzclock() on this processor. */ active.machs &= ~(1<machno); active.exiting = 1; @@ -506,15 +503,18 @@ delay(m->machno*1000); /* stagger them */ iprint("cpu%d: exiting\n", m->machno); } - spllo(); - if (m->machno == 0) - ms = 5*1000; - else - ms = 2*1000; - for(; ms > 0; ms -= TK2MS(2)){ - delay(TK2MS(2)); - if(active.machs == 0 && consactive() == 0) - break; + + if(!active.panicking){ + spllo(); + if (m->machno == 0) + ms = 5*1000; + else + ms = 2*1000; + for(; ms > 0; ms -= TK2MS(2)){ + delay(TK2MS(2)); + if(active.machs == 0 && consactive() == 0) + break; + } } delay(500); } @@ -523,9 +523,9 @@ * exit kernel either on a panic or user request */ void -exit(int code) +exit(void) { - shutdown(code); + shutdown(); splhi(); if (m->machno == 0) archreboot(); @@ -602,7 +602,7 @@ for (want = 0, cpu = 1; cpu < navailcpus; cpu++) want |= 1 << cpu; active.stopped = 0; - shutdown(0); + shutdown(); for (ms = 15*1000; ms > 0 && active.stopped != want; ms -= 10) delay(10); delay(20); @@ -842,7 +842,7 @@ */ if(nelem(tsmem) > nelem(conf.mem)){ iprint("memory configuration botch\n"); - exit(1); + exit(); } if(0 && (p = getconf("*maxmem")) != nil) { memsize = strtoul(p, 0, 0) - PHYSDRAM;