]> git.lizzy.rs Git - plan9front.git/commitdiff
kernel: cleanup exit()/shutdown()/reboot() code
authorcinap_lenrek <cinap_lenrek@felloff.net>
Mon, 30 Nov 2015 13:56:00 +0000 (14:56 +0100)
committercinap_lenrek <cinap_lenrek@felloff.net>
Mon, 30 Nov 2015 13:56:00 +0000 (14:56 +0100)
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.

32 files changed:
sys/src/9/alphapc/dat.h
sys/src/9/alphapc/main.c
sys/src/9/bcm/dat.h
sys/src/9/bcm/main.c
sys/src/9/bitsy/dat.h
sys/src/9/bitsy/main.c
sys/src/9/kw/dat.h
sys/src/9/kw/main.c
sys/src/9/mtx/dat.h
sys/src/9/mtx/main.c
sys/src/9/omap/dat.h
sys/src/9/omap/main.c
sys/src/9/omap4/dat.h
sys/src/9/pc/dat.h
sys/src/9/pc/main.c
sys/src/9/pc/screen.c
sys/src/9/pc64/dat.h
sys/src/9/pc64/main.c
sys/src/9/port/allocb.c
sys/src/9/port/devcons.c
sys/src/9/port/portfns.h
sys/src/9/port/rebootcmd.c
sys/src/9/port/ucallocb.c
sys/src/9/ppc/dat.h
sys/src/9/ppc/main.c
sys/src/9/sgi/dat.h
sys/src/9/sgi/main.c
sys/src/9/teg2/dat.h
sys/src/9/teg2/main.c
sys/src/9/xen/main.c
sys/src/9/zynq/dat.h
sys/src/9/zynq/main.c

index 5257a291e12276d8c352a8f9b98e626a16f721c6..250d607e0a15df4d480d460929ee9e1f5aacbe23 100644 (file)
@@ -186,7 +186,6 @@ struct
        Lock;
        short   machs;
        short   exiting;
-       short   ispanic;
 }active;
 
 /*
index ac123ea9f8174dc4d02d5410354e397bf00263e7..9175c2627f01d83ad6421381c67facac7ad226bb 100644 (file)
@@ -308,123 +308,21 @@ setupboot(int halt)
        cpu->state |= (halt? Cpuhaltstayhalted: Cpuhaltwarmboot);
 }
 
-/* from ../pc */
-static void
-shutdown(int ispanic)
-{
-       int ms, once;
-
-       lock(&active);
-       if(ispanic)
-               active.ispanic = ispanic;
-       else if(m->machno == 0 && (active.machs & (1<<m->machno)) == 0)
-               active.ispanic = 0;
-       once = active.machs & (1<<m->machno);
-       active.machs &= ~(1<<m->machno);
-       active.exiting = 1;
-       unlock(&active);
-
-       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(cpuserver)
-                       delay(10000);
-               else
-                       for (;;)
-                               continue;
-       } else
-               delay(1000);
-}
-
-/* from ../pc: */
 void
-reboot(void *entry, void *code, ulong size)
+reboot(void *, void *, ulong)
 {
-       // writeconf();         // pass kernel environment to next kernel
-       shutdown(0);
-
-       /*
-        * should be the only processor running now
-        */
-       print("shutting down...\n");
-       delay(200);
-
-       splhi();
-
-       /* turn off buffered serial console */
-       serialoq = nil;
-
-       /* shutdown devices */
-       chandevshutdown();
-
-#ifdef FUTURE
-{
-       ulong *pdb;
-       /*
-        * Modify the machine page table to directly map the low 4MB of memory
-        * This allows the reboot code to turn off the page mapping
-        */
-       pdb = m->pdb;
-       pdb[PDX(0)] = pdb[PDX(KZERO)];
-       mmuflushtlb(PADDR(pdb));
-}
-       /* setup reboot trampoline function */
-{
-       void (*f)(ulong, ulong, ulong) = (void*)REBOOTADDR;
-
-       memmove(f, rebootcode, sizeof(rebootcode));
-#else
-       USED(entry, code, size);
-#endif
-
-       print("rebooting...\n");
-#ifdef FUTURE
-       /* off we go - never to return */
-       (*f)(PADDR(entry), PADDR(code), size);
-}
-#endif
-       setupboot(0);           // reboot, don't halt
-       exit(0);
 }
 
 void
-exit(int ispanic)
+exit(int)
 {
-       canlock(&active);
-       active.machs &= ~(1<<m->machno);
-       active.exiting = 1;
-       unlock(&active);
-
-       spllo();
-       print("cpu %d exiting\n", m->machno);
-       do
-               delay(100);
-       while(consactive());
-
+       cpushutdown();
        splhi();
-       delay(1000);    /* give serial fifo time to finish flushing */
-       if (getconf("*debug") != nil) {
-               USED(ispanic);
-               delay(60*1000);         /* give us time to read the screen */
-       }
        if(arch->coredetach)
                arch->coredetach();
        setupboot(1);                   // set up to halt
-       for (; ; )
+       for (;;)
                firmware();
-
-       // on PC is just:
-       //if (0) {
-       //      shutdown(ispanic);
-       //      arch->reset();
-       //}
 }
 
 void
index cb860a6fae7a5daad34b6ff3db0e031ca548944f..76d4012c35968c7edfd852b391f2bc1c0c97c5ff 100644 (file)
@@ -225,7 +225,6 @@ struct
        Lock;
        int     machs;                  /* bitmap of active CPUs */
        int     exiting;                /* shutdown */
-       int     ispanic;                /* shutdown in response to a panic */
 }active;
 
 extern register Mach* m;                       /* R10 */
index 1746a5279069afeb4288146652ddf2b7780e682e..a39637a217d8125ae1d8328fdc989f12c9f3a058 100644 (file)
@@ -522,39 +522,13 @@ confinit(void)
 
 }
 
-static void
-shutdown(int ispanic)
-{
-       int ms, once;
-
-       lock(&active);
-       if(ispanic)
-               active.ispanic = ispanic;
-       else if(m->machno == 0 && (active.machs & (1<<m->machno)) == 0)
-               active.ispanic = 0;
-       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);
-       spllo();
-       for(ms = 5*1000; ms > 0; ms -= TK2MS(2)){
-               delay(TK2MS(2));
-               if(active.machs == 0 && consactive() == 0)
-                       break;
-       }
-       delay(1000);
-}
-
 /*
  *  exit kernel either on a panic or user request
  */
 void
-exit(int code)
+exit(int)
 {
-       shutdown(code);
+       cpushutdown();
        splfhi();
        archreboot();
 }
@@ -579,17 +553,8 @@ reboot(void *entry, void *code, ulong size)
 {
        void (*f)(ulong, ulong, ulong);
 
-       print("starting reboot...");
        writeconf();
-       shutdown(0);
-
-       /*
-        * should be the only processor running now
-        */
-
-       print("reboot entry %#lux code %#lux size %ld\n",
-               PADDR(entry), PADDR(code), size);
-       delay(100);
+       cpushutdown();
 
        /* turn off buffered serial console */
        serialoq = nil;
@@ -612,10 +577,6 @@ reboot(void *entry, void *code, ulong size)
 
        /* off we go - never to return */
        (*f)(PADDR(entry), PADDR(code), size);
-
-       iprint("loaded kernel returned!\n");
-       delay(1000);
-       archreboot();
 }
 
 int
index a2e8b410a8000abec39d2ef273b29daf409cc59b..6b5d190a760bfc6debd7bcdd4bc2e33882292981 100644 (file)
@@ -180,7 +180,6 @@ struct
        Lock;
        int     machs;                  /* bitmap of active CPUs */
        int     exiting;                /* shutdown */
-       int     ispanic;                /* shutdown in response to a panic */
 }active;
 
 #define        MACHP(n)        ((Mach *)(MACHADDR+(n)*BY2PG))
index 03f496286e390b2d7ebf9d499d1ac69542ac5302..203428e738019c2ac20b62b820bca63668e9803f 100644 (file)
@@ -56,7 +56,6 @@ main(void)
 void
 reboot(void*, void*, ulong)
 {
-       exit(0);
 }
 
 
@@ -64,13 +63,12 @@ reboot(void*, void*, ulong)
  *  exit kernel either on a panic or user request
  */
 void
-exit(int ispanic)
+exit(int)
 {
        void (*f)(void);
 
-       USED(ispanic);
-       delay(1000);
-
+       cpushutdown();
+       splhi();
        iprint("it's a wonderful day to die\n");
        cacheflush();
        mmuinvalidate();
index f0327bb6a3e1667469d8172a3cb9446cc92ce7db..a6623abacf614b97dede93b300ba8af83fa04747 100644 (file)
@@ -196,7 +196,6 @@ struct
        Lock;
        int     machs;                  /* bitmap of active CPUs */
        int     exiting;                /* shutdown */
-       int     ispanic;                /* shutdown in response to a panic */
 }active;
 
 enum {
index 8b2080ef7258f11cfa4bce64cde58f3e09a28ec5..e938660b337b75e649f9f1dcc11ca8e9f8c722d9 100644 (file)
@@ -355,39 +355,13 @@ machinit(void)
        up = nil;
 }
 
-static void
-shutdown(int ispanic)
-{
-       int ms, once;
-
-       lock(&active);
-       if(ispanic)
-               active.ispanic = ispanic;
-       else if(m->machno == 0 && (active.machs & (1<<m->machno)) == 0)
-               active.ispanic = 0;
-       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);
-       spllo();
-       for(ms = 5*1000; ms > 0; ms -= TK2MS(2)){
-               delay(TK2MS(2));
-               if(active.machs == 0 && consactive() == 0)
-                       break;
-       }
-       delay(1000);
-}
-
 /*
  *  exit kernel either on a panic or user request
  */
 void
-exit(int code)
+exit(int)
 {
-       shutdown(code);
+       cpushutdown();
        splhi();
        archreboot();
 }
@@ -401,17 +375,8 @@ reboot(void *entry, void *code, ulong size)
 {
        void (*f)(ulong, ulong, ulong);
 
-       iprint("starting reboot...");
        writeconf();
-       
-       shutdown(0);
-
-       /*
-        * should be the only processor running now
-        */
-
-       print("shutting down...\n");
-       delay(200);
+       cpushutdown();
 
        /* turn off buffered serial console */
        serialoq = nil;
@@ -430,19 +395,10 @@ reboot(void *entry, void *code, ulong size)
        cacheuwbinv();
        l2cacheuwb();
 
-       print("rebooting...");
-       iprint("entry %#lux code %#lux size %ld\n",
-               PADDR(entry), PADDR(code), size);
-       delay(100);             /* wait for uart to quiesce */
-
        /* off we go - never to return */
        cacheuwbinv();
        l2cacheuwb();
        (*f)(PADDR(entry), PADDR(code), size);
-
-       iprint("loaded kernel returned!\n");
-       delay(1000);
-       archreboot();
 }
 
 /*
index 294bca8c5b8c953bc37c1cffeb4d274cbbf8be90..4e3c7414d3f5a631fbb0052fc4ae560ce28ac82a 100644 (file)
@@ -183,7 +183,6 @@ struct
        Lock;
        short   machs;
        short   exiting;
-       short   ispanic;
 }active;
 
 /*
index 491580101e79c2294558ee73a47c0d98f3af2195..f3c5a156884caf6250a78760375fc8ae08c6fc9e 100644 (file)
@@ -211,42 +211,12 @@ userinit(void)
 void
 reboot(void*, void*, ulong)
 {
-       exit(0);
 }
 
 void
-exit(int ispanic)
+exit(int)
 {
-       int ms, once;
-
-       lock(&active);
-       if(ispanic)
-               active.ispanic = ispanic;
-       else if(m->machno == 0 && (active.machs & (1<<m->machno)) == 0)
-               active.ispanic = 0;
-       once = active.machs & (1<<m->machno);
-       active.machs &= ~(1<<m->machno);
-       active.exiting = 1;
-       unlock(&active);
-
-       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(cpuserver)
-                       delay(10000);
-               else if(conf.monitor)
-                       for(;;);
-       }
-       else
-               delay(1000);
-
+       cpushutdown();
        watchreset();
 }
 
index 6ed388c155b43cc01fcf5b01878113dbfc588e3b..982e18b74f9845fe216b0720331373c464cb585a 100644 (file)
@@ -218,7 +218,6 @@ struct
        Lock;
        int     machs;                  /* bitmap of active CPUs */
        int     exiting;                /* shutdown */
-       int     ispanic;                /* shutdown in response to a panic */
 }active;
 
 extern register Mach* m;                       /* R10 */
index 818da7276936a7d1b185dc54939ad422f84c4c12..42ce8ba5a591c1a2bd7db7c8d4a85256385b6ff8 100644 (file)
@@ -301,39 +301,13 @@ machinit(void)
        up = nil;
 }
 
-static void
-shutdown(int ispanic)
-{
-       int ms, once;
-
-       lock(&active);
-       if(ispanic)
-               active.ispanic = ispanic;
-       else if(m->machno == 0 && (active.machs & (1<<m->machno)) == 0)
-               active.ispanic = 0;
-       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);
-       spllo();
-       for(ms = 5*1000; ms > 0; ms -= TK2MS(2)){
-               delay(TK2MS(2));
-               if(active.machs == 0 && consactive() == 0)
-                       break;
-       }
-       delay(1000);
-}
-
 /*
  *  exit kernel either on a panic or user request
  */
 void
-exit(int code)
+exit(int)
 {
-       shutdown(code);
+       cpushutdown();
        splhi();
        archreboot();
 }
@@ -380,17 +354,8 @@ reboot(void *entry, void *code, ulong size)
 {
        void (*f)(ulong, ulong, ulong);
 
-       print("starting reboot...");
        writeconf();
-       shutdown(0);
-
-       /*
-        * should be the only processor running now
-        */
-
-       print("reboot entry %#lux code %#lux size %ld\n",
-               PADDR(entry), PADDR(code), size);
-       delay(100);
+       cpushutdown();
 
        /* turn off buffered serial console */
        serialoq = nil;
@@ -414,10 +379,6 @@ reboot(void *entry, void *code, ulong size)
 
        /* off we go - never to return */
        (*f)(PADDR(entry), PADDR(code), size);
-
-       iprint("loaded kernel returned!\n");
-       delay(1000);
-       archreboot();
 }
 
 /*
index 31bf462f02d03a78fccae56aecb3764bc16beef8..658e639d7b37b28b64cb75834117ae914b8fefc6 100644 (file)
@@ -132,7 +132,6 @@ struct
        Lock;
        int     machs;                  /* bitmap of active CPUs */
        int     exiting;                /* shutdown */
-       int     ispanic;                /* shutdown in response to a panic */
 }active;
 
 extern Mach *m;
index 8bcc5053a098705a35c3afaae2fd7e1f9901f5c1..19b7dfae28a935fcadd1898e6f05d3b42b852a90 100644 (file)
@@ -272,7 +272,6 @@ struct
        Lock;
        int     machs;                  /* bitmap of active CPUs */
        int     exiting;                /* shutdown */
-       int     ispanic;                /* shutdown in response to a panic */
        int     thunderbirdsarego;      /* lets the added processors continue to schedinit */
 }active;
 
index 6672717c29e5afb52b2f8df62b55d37e0ed0fa2c..6d83419979d6425df462013c4a51abf79801e162 100644 (file)
@@ -163,7 +163,6 @@ main(void)
                pcimatch(0, 0, 0);
        }else
                links();
-       conf.monitor = 1;
        chandevreset();
        pageinit();
        swapinit();
@@ -890,50 +889,6 @@ procsave(Proc *p)
        mmuflushtlb(PADDR(m->pdb));
 }
 
-static void
-shutdown(int ispanic)
-{
-       int ms, once;
-
-       lock(&active);
-       if(ispanic)
-               active.ispanic = ispanic;
-       else if(m->machno == 0 && (active.machs & (1<<m->machno)) == 0)
-               active.ispanic = 0;
-       once = active.machs & (1<<m->machno);
-       /*
-        * setting exiting will make hzclock() on each processor call exit(0),
-        * which calls shutdown(0) and arch->reset(), which on mp systems calls
-        * mpshutdown(), from which there is no return: the processor is idled
-        * or initiates a reboot.  clearing our bit in machs avoids calling
-        * exit(0) from hzclock() on this processor.
-        */
-       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;
-       }
-
-       if(active.ispanic){
-               if(!cpuserver)
-                       for(;;)
-                               halt();
-               if(getconf("*debug"))
-                       delay(5*60*1000);
-               else
-                       delay(10000);
-       }
-}
-
 void
 reboot(void *entry, void *code, ulong size)
 {
@@ -952,10 +907,7 @@ reboot(void *entry, void *code, ulong size)
                procwired(up, 0);
                sched();
        }
-       shutdown(0);
-
-       iprint("shutting down...\n");
-       delay(200);
+       cpushutdown();
 
        splhi();
 
@@ -985,8 +937,8 @@ reboot(void *entry, void *code, ulong size)
 
 
 void
-exit(int ispanic)
+exit(int)
 {
-       shutdown(ispanic);
+       cpushutdown();
        arch->reset();
 }
index 4ff7a9485fcb6bbef384b3035f6914f1af94b08c..c74d2da71407c58fa798ca311396e7f390f1cd5e 100644 (file)
@@ -664,6 +664,8 @@ bootscreeninit(void)
        scr->cur = &swcursor;
        scr->cur->enable(scr);
        cursoron();
+
+       conf.monitor = 1;
 }
 
 /*
index 538a74da0218e09d088225297a3ac95bc146789d..5558f331a9aeeea1a872257e2ce111ce4c5607b8 100644 (file)
@@ -235,7 +235,6 @@ struct
        Lock;
        int     machs;                  /* bitmap of active CPUs */
        int     exiting;                /* shutdown */
-       int     ispanic;                /* shutdown in response to a panic */
        int     thunderbirdsarego;      /* lets the added processors continue to schedinit */
 }active;
 
index 8695b6ea312bd25db07391cbc707aded9f531897..4805bcc9e73bfd1f3fd24f267193da9c39f41de1 100644 (file)
@@ -512,7 +512,6 @@ main()
                pcimatch(0, 0, 0);
        }else
                links();
-       conf.monitor = 1;
        chandevreset();
        preallocpages();
        pageinit();
@@ -522,54 +521,10 @@ main()
        schedinit();
 }
 
-static void
-shutdown(int ispanic)
-{
-       int ms, once;
-
-       lock(&active);
-       if(ispanic)
-               active.ispanic = ispanic;
-       else if(m->machno == 0 && (active.machs & (1<<m->machno)) == 0)
-               active.ispanic = 0;
-       once = active.machs & (1<<m->machno);
-       /*
-        * setting exiting will make hzclock() on each processor call exit(0),
-        * which calls shutdown(0) and arch->reset(), which on mp systems calls
-        * mpshutdown(), from which there is no return: the processor is idled
-        * or initiates a reboot.  clearing our bit in machs avoids calling
-        * exit(0) from hzclock() on this processor.
-        */
-       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;
-       }
-
-       if(active.ispanic){
-               if(!cpuserver)
-                       for(;;)
-                               halt();
-               if(getconf("*debug"))
-                       delay(5*60*1000);
-               else
-                       delay(10000);
-       }
-}
-
 void
-exit(int ispanic)
+exit(int)
 {
-       shutdown(ispanic);
+       cpushutdown();
        arch->reset();
 }
 
@@ -590,10 +545,7 @@ reboot(void *entry, void *code, ulong size)
                procwired(up, 0);
                sched();
        }
-       shutdown(0);
-
-       iprint("shutting down...\n");
-       delay(200);
+       cpushutdown();
 
        splhi();
 
index 00af00e4d857edb0e3963e091f24f5dde598b317..3949680cc2d4252572c60fadcfe8b32ec93192a8 100644 (file)
@@ -86,10 +86,8 @@ iallocb(int size)
 
        if(ialloc.bytes > conf.ialloc){
                if((m1++%10000)==0){
-                       if(mp++ > 1000){
-                               active.exiting = 1;
-                               exit(0);
-                       }
+                       if(mp++ > 1000)
+                               panic("iallocb: out of memory");
                        iprint("iallocb: limited %lud/%lud\n",
                                ialloc.bytes, conf.ialloc);
                }
@@ -98,10 +96,8 @@ iallocb(int size)
 
        if((b = _allocb(size)) == nil){
                if((m2++%10000)==0){
-                       if(mp++ > 1000){
-                               active.exiting = 1;
-                               exit(0);
-                       }
+                       if(mp++ > 1000)
+                               panic("iallocb: out of memory");
                        iprint("iallocb: no memory %lud/%lud\n",
                                ialloc.bytes, conf.ialloc);
                }
index dc761f49343bc2b144eba16fbcb35405622adbc1..78f56afd115f082f1522474546dbabc7061a0ffd 100644 (file)
@@ -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;
+       }
+}
index 4944b928593d094d572acdff441f8053d4afe792..ffda16d230b515c5770ec16683c45927cccb0400 100644 (file)
@@ -41,6 +41,7 @@ int           cmount(Chan**, Chan*, int, char*);
 void           confinit(void);
 int            consactive(void);
 void           (*consdebug)(void);
+void           cpushutdown(void);
 void           copen(Chan*);
 void           cclunk(Chan*);
 Block*         concatblock(Block*);
index 537c4e7cfd138a2d09a36214e8eddaa45b719179..fc5186cf23c4a96ac94ece90a4cd8d986846e659 100644 (file)
@@ -103,6 +103,5 @@ rebootcmd(int argc, char *argv[])
        setbootcmd(argc-1, argv+1);
 
        reboot((void*)entry, p, size);
-
-       panic("return from reboot!");
+       error(Egreg);
 }
index 126733d9a341c782331da36c1da8f30d5ad3c255..410aa62e85647d245ffc1ebe87d8c938d6955253 100644 (file)
@@ -78,24 +78,10 @@ uciallocb(int size)
        Block *b;
        static int m1, m2, mp;
 
-       if(0 && ucialloc.bytes > conf.ialloc){
-               if((m1++%10000)==0){
-                       if(mp++ > 1000){
-                               active.exiting = 1;
-                               exit(0);
-                       }
-                       iprint("uciallocb: limited %lud/%lud\n",
-                               ucialloc.bytes, conf.ialloc);
-               }
-               return nil;
-       }
-
        if((b = _ucallocb(size)) == nil){
                if(0 && (m2++%10000)==0){
-                       if(mp++ > 1000){
-                               active.exiting = 1;
-                               exit(0);
-                       }
+                       if(mp++ > 1000)
+                               panic("uciallocb: out of memory");
                        iprint("uciallocb: no memory %lud/%lud\n",
                                ucialloc.bytes, conf.ialloc);
                }
index f92367764ba488944818a5fc2c66451820168b22..d10559f0178d8a6fbc4c97cf50ade843bc809d6e 100644 (file)
@@ -191,7 +191,6 @@ struct
        Lock;
        short   machs;
        short   exiting;
-       short   ispanic;
 }active;
 
 /*
index e0badeb5722a5c760897982785ece83ce4f81b83..5d2a1765bcd9ad45b423ba02c266fe3ec7ad089a 100644 (file)
@@ -243,38 +243,10 @@ userinit(void)
 }
 
 void
-exit(int ispanic)
+exit(int)
 {
-       int ms, once;
-
-       lock(&active);
-       if(ispanic)
-               active.ispanic = ispanic;
-       else if(m->machno == 0 && (active.machs & (1<<m->machno)) == 0)
-               active.ispanic = 0;
-       once = active.machs & (1<<m->machno);
-       active.machs &= ~(1<<m->machno);
-       active.exiting = 1;
-       unlock(&active);
-
-       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(cpuserver)
-                       delay(10000);
-               else if(conf.monitor)
-                       for(;;);
-       }
-       else
-               delay(1000);
-
+       cpushutdown();
+       for(;;) idlehands();
 }
 
 /*
@@ -424,8 +396,6 @@ confinit(void)
                 */
                imagmem->maxsize = kpages;
        }
-
-//     conf.monitor = 1;       /* BUG */
 }
 
 static int
index b0e47a6cb7d9f4d168ad8a277cd57acb08fc183f..771b755cee49c810f23e29ae6e9b97178f89c92d 100644 (file)
@@ -206,7 +206,6 @@ struct
        Lock;
        long    machs;          /* bitmap of processors */
        short   exiting;
-       int     ispanic;
 }active;
 
 extern register Mach   *m;
index 086ab4fb24024d844e562b86827f4df44010e43e..08c6c85b84e3608d88a1f822b3ca496bdd8f6ea7 100644 (file)
@@ -372,10 +372,10 @@ userinit(void)
 }
 
 void
-exit(int ispanic)
+exit(int)
 {
+       cpushutdown();
        splhi();
-       while(ispanic);
        arcs(0x18);     /* reboot */
 }
 
index 83420dfbd81ae0ce7bb27d484767ded3e3ceab2c..80068975c16069aea7dba7b1e06a5fe47093e24b 100644 (file)
@@ -250,7 +250,6 @@ struct
        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     thunderbirdsarego;      /* lets the added processors continue to schedinit */
 }active;
 
index f5feced0ac99b0ae169909e5ae93ef0ad3babe67..6847f3a9165ae561077339c85938d31758a73c49 100644 (file)
@@ -480,51 +480,13 @@ main(void)
        panic("cpu%d: schedinit returned", m->machno);
 }
 
-static void
-shutdown(int ispanic)
-{
-       int ms, once;
-
-       lock(&active);
-       if(ispanic)
-               active.ispanic = ispanic;
-       else if(m->machno == 0 && (active.machs & (1<<m->machno)) == 0)
-               active.ispanic = 0;
-       once = active.machs & (1<<m->machno);
-       /*
-        * setting exiting will make hzclock() on each processor call exit(0),
-        * which calls shutdown(0) 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.
-        */
-       active.machs &= ~(1<<m->machno);
-       active.exiting = 1;
-       unlock(&active);
-
-       if(once) {
-               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;
-       }
-       delay(500);
-}
-
 /*
  *  exit kernel either on a panic or user request
  */
 void
-exit(int code)
+exit(int)
 {
-       shutdown(code);
+       cpushutdown();
        splhi();
        if (m->machno == 0)
                archreboot();
@@ -576,10 +538,8 @@ isaconfig(char *class, int ctlrno, ISAConf *isa)
 void
 reboot(void *entry, void *code, ulong size)
 {
-       int cpu, nmach, want, ms;
        void (*f)(ulong, ulong, ulong);
 
-       nmach = conf.nmach;
        writeconf();
 
        /*
@@ -590,33 +550,12 @@ reboot(void *entry, void *code, ulong size)
                procwired(up, 0);
                sched();
        }
-       if (m->machno != 0)
-               print("on cpu%d (not 0)!\n", m->machno);
-
-       /*
-        * the other cpus could be holding locks that will never get
-        * released (e.g., in the print path) if we put them into
-        * reset now, so force them to shutdown gracefully first.
-        */
-       for (want = 0, cpu = 1; cpu < navailcpus; cpu++)
-               want |= 1 << cpu;
-       active.stopped = 0;
-       shutdown(0);
-       for (ms = 15*1000; ms > 0 && active.stopped != want; ms -= 10)
-               delay(10);
-       delay(20);
-       if (active.stopped != want) {
-               for (cpu = 1; cpu < nmach; cpu++)
-                       stopcpu(cpu);           /* make really sure */
-               delay(20);
-       }
+       cpushutdown();
 
        /*
         * should be the only processor running now
         */
        pcireset();
-//     print("reboot entry %#lux code %#lux size %ld\n",
-//             PADDR(entry), PADDR(code), size);
 
        /* turn off buffered serial console */
        serialoq = nil;
@@ -642,9 +581,6 @@ reboot(void *entry, void *code, ulong size)
 
        /* off we go - never to return */
        (*f)(PADDR(entry), PADDR(code), size);
-
-       iprint("loaded kernel returned!\n");
-       archreboot();
 }
 
 /*
index 9888af3ce4b7540731caded1e84a41d883042f62..33b80057931e2e23314980f83af487fed586e9f9 100644 (file)
@@ -644,58 +644,13 @@ procsave(Proc *p)
        mmuflushtlb(0);
 }
 
-static void
-shutdown(int ispanic)
-{
-       int ms, once;
-
-       lock(&active);
-       if(ispanic)
-               active.ispanic = ispanic;
-       else if(m->machno == 0 && (active.machs & (1<<m->machno)) == 0)
-               active.ispanic = 0;
-       once = active.machs & (1<<m->machno);
-       active.machs &= ~(1<<m->machno);
-       active.exiting = 1;
-       unlock(&active);
-
-       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(getconf("*debug"))
-               delay(5*60*1000);
-
-       if(active.ispanic){
-               if(!cpuserver)
-                       for(;;)
-                               halt();
-               delay(10000);
-       }else
-               delay(1000);
-}
-
 void
 reboot(void *entry, void *code, ulong size)
 {
        void (*f)(ulong, ulong, ulong);
-       //ulong *pdb;
 
        writeconf();
-
-       shutdown(0);
-
-       /*
-        * should be the only processor running now
-        */
-
-       print("shutting down...\n");
-       delay(200);
+       cpushutdown();
 
        splhi();
 
@@ -709,28 +664,19 @@ reboot(void *entry, void *code, ulong size)
        if(entry == 0)
                HYPERVISOR_shutdown(0);
 
-       /*
-        * Modify the machine page table to directly map the low 4MB of memory
-        * This allows the reboot code to turn off the page mapping
-        */
-       //pdb = m->pdb;
-       //pdb[PDX(0)] = pdb[PDX(KZERO)];
        mmuflushtlb(0);
 
        /* setup reboot trampoline function */
        f = (void*)REBOOTADDR;
        memmove(f, rebootcode, sizeof(rebootcode));
 
-       print("rebooting...\n");
-
        /* off we go - never to return */
        (*f)(PADDR(entry), PADDR(code), size);
 }
 
-
 void
-exit(int ispanic)
+exit(int)
 {
-       shutdown(ispanic);
+       cpushutdown();
        arch->reset();
 }
index 2d3e681a739ae46d5967f958ac748f567eedea8a..4172407b4fac54b15827dddf988c31c019412413 100644 (file)
@@ -177,7 +177,6 @@ struct
        Lock;
        int     machs;                  /* bitmap of active CPUs */
        int     exiting;                /* shutdown */
-       int     ispanic;                /* shutdown in response to a panic */
 }active;
 
 extern register Mach* m;                       /* R10 */
index 969bede818cd109cea4f311b2379acc79ef36369..91206e0a3e29996a97ca219bc22ea13342472057 100644 (file)
@@ -21,13 +21,13 @@ int nconf;
 void
 exit(int)
 {
-       NOPE
+       cpushutdown();
+       for(;;) idlehands();
 }
 
 void
 reboot(void *, void *, ulong)
 {
-       NOPE
 }
 
 void