cleanup exit() which still allowed splhi'ing. that bit has been removed and we put the console into synchronous mode. this allows us to reboot without worring about interrupts calling sched again. if anyone sees nix double panic after this change, please post a note to this list. Reference: /n/atom/patch/applied2013/exitcleanup Date: Sun Dec 29 22:30:47 CET 2013 Signed-off-by: quanstro@quanstro.net --- /sys/src/nix/k10/main.c Sun Dec 29 22:27:19 2013 +++ /sys/src/nix/k10/main.c Sun Dec 29 22:27:19 2013 @@ -8,7 +8,6 @@ #include "io.h" #include "apic.h" -uintptr kseg0 = KZERO; Sys* sys; char dbgflg[256]; @@ -40,9 +39,6 @@ m->splpc = 0; m->online = 1; - /* - * CAUTION: no time sync done, etc. - */ DBG("Wait for the thunderbirds!\n"); while(!active.thunderbirdsarego) monmwait(&active.thunderbirdsarego, 0); @@ -62,16 +58,12 @@ ainc(&active.nonline); schedinit(); - panic("squidboy returns"); } /* - * Rendezvous with other cores. - * wait until they are initialized. - * Sync TSC with them. - * We assume other processors that could boot had time to - * set online to 1 by now. + * Wait for other cores to be initialized and sync tsc counters. + * Assume other cores have had time to set active.online=1. */ static void nixsquids(void) @@ -142,9 +134,7 @@ consputs = cgaconsputs; vsvminit(MACHSTKSZ); - sys->nmach = 1; - fmtinit(); print("\nnix\n"); @@ -164,20 +154,19 @@ mallocinit(); archpciinit(); - if(getconf("*maxmach") != nil) - maxmach = atoi(getconf("*maxmach")); - mpsinit(maxmach); /* acpi */ - - umeminit(); - trapinit(); - printinit(); - /* * This is necessary with GRUB and QEMU. Without it an interrupt can occur * at a weird vector, because the vector base is likely different, causing * havoc. Do it before any APIC initialisation. */ i8259init(32); + if(getconf("*maxmach") != nil) + maxmach = atoi(getconf("*maxmach")); + mpsinit(maxmach); /* acpi */ + + umeminit(); + trapinit(); + printinit(); procinit0(); lapiconline(); @@ -301,9 +290,7 @@ * Kernel Stack * * N.B. make sure there's enough space for syscall to check - * for valid args and - * space for gotolabel's return PC - * AMD64 stack must be quad-aligned. + * for valid args and space for gotolabel's return PC */ p->sched.pc = PTR2UINT(init0); p->sched.sp = PTR2UINT(p->kstack+KSTACK-sizeof(up->arg)-sizeof(uintptr)); @@ -342,43 +329,6 @@ ready(p); } -static void -shutdown(int ispanic) -{ - int ms, once; - - ilock(&active); - if(ispanic) - active.ispanic = ispanic; - else if(m->machno == 0 && m->online == 0) - active.ispanic = 0; - once = m->online; - m->online = 0; - adec(&active.nonline); - active.exiting = 1; - iunlock(&active); - - if(once) - iprint("cpu%d: exiting\n", m->machno); - - spllo(); - for(ms = 5*1000; ms > 0; ms -= TK2MS(2)){ - delay(TK2MS(2)); - if(active.nonline == 0 && consactive() == 0) - break; - } - - if(active.ispanic && m->machno == 0){ - if(cpuserver) - delay(30000); - else - for(;;) - halt(); - } - else - delay(1000); -} - void apshut(void *v) { @@ -386,8 +336,8 @@ i = (int)(uintptr)v; procwired(up, i); - sched(); splhi(); + m->online = 0; adec(&active.nonline); ndnr(); } @@ -402,7 +352,6 @@ // writeconf(); procwired(up, 0); - sched(); for(i = 1; i < active.nonline; i++) kproc("apshut", apshut, (void*)i); @@ -435,6 +384,23 @@ void exit(int ispanic) { - shutdown(ispanic); + synccons(); + + /* accounting */ + if(!m->online) + ndnr(); + m->online = 0; + iprint("cpu%d: exiting\n", m->machno); + adec(&active.nonline); + ainc(&active.exiting); + + /* wait (terminals wait forever) */ + if(ispanic && !cpuserver) + ndnr(); + for(int ms = 0; ms < 5000; ms += 1){ + if(active.nonline == 0) + break; + delay(1); + } archreset(); } --- /sys/src/nix/k10/dat.h Sun Dec 29 22:27:19 2013 +++ /sys/src/nix/k10/dat.h Sun Dec 29 22:27:19 2013 @@ -281,7 +281,6 @@ struct { - Lock; int nonline; /* # of active CPUs */ int nbooting; /* # of CPUs waiting for the bsp to go */ int exiting; /* shutdown */ @@ -298,11 +297,6 @@ extern register Mach* m; /* R15 */ extern register Proc* up; /* R14 */ - -extern uintptr kseg0; - -#pragma varargck type "R" u64int -#pragma varargck type "W" uintptr /* * Horrid.