# HG changeset patch # User Merten Sach # Date 1316434537 -7200 # Node ID 99343ffe1918508ceef38f7fb35444a14048955f # Parent f1374d5dbb9895c2c9cc10d6aad74611e7812278 The shutdown now uses inter master requests diff -r f1374d5dbb98 -r 99343ffe1918 CoreLoop.c --- a/CoreLoop.c Fri Sep 16 20:13:33 2011 +0200 +++ b/CoreLoop.c Mon Sep 19 14:15:37 2011 +0200 @@ -160,16 +160,11 @@ void * terminateCoreLoop(VirtProcr *currPr){ - //first free the shutdown VP that jumped here -- it first restores the - // coreloop's stack, so addr of currPr in stack frame is still correct - VMS__dissipate_procr( currPr ); - pthread_exit( NULL ); + pthread_exit( NULL ); } -#ifdef SEQUENTIAL - //=========================================================================== /*This sequential version is exact same as threaded, except doesn't do the * pin-threads part, nor the wait until setup complete part. @@ -188,7 +183,7 @@ thisCoresIdx = 0; //Save the return address in the SwitchVP function - saveCoreLoopReturnAddr(&(_VMSMasterEnv->coreLoopReturnPt)); + saveCoreLoopReturnAddr((void**)&(_VMSMasterEnv->coreLoopReturnPt)); while(1){ @@ -212,4 +207,3 @@ flushRegisters(); } } -#endif diff -r f1374d5dbb98 -r 99343ffe1918 MasterLoop.c --- a/MasterLoop.c Fri Sep 16 20:13:33 2011 +0200 +++ b/MasterLoop.c Mon Sep 19 14:15:37 2011 +0200 @@ -238,12 +238,17 @@ void inline handleInterVMSCoreReq( InterVMSCoreReqst *currReq, VirtProcr *masterPr ) { - switch( currReq->reqType ) + switch( currReq->secondReqType ) { case transfer_free_ptr: handleTransferFree( currReq, masterPr ); currReq->obsolete = 1; //now the sender can free the structure break; + case shutdownVP: + currReq->obsolete = 1; + handleShutdown(currReq, masterPr); + //The Execution of the MasterLoop ends here + break; default: break; } diff -r f1374d5dbb98 -r 99343ffe1918 ProcrContext.h --- a/ProcrContext.h Fri Sep 16 20:13:33 2011 +0200 +++ b/ProcrContext.h Mon Sep 19 14:15:37 2011 +0200 @@ -65,7 +65,9 @@ void startVirtProcrFn(); -void *asmTerminateCoreLoop(VirtProcr *currPr); +void asmTerminateCoreLoop(VirtProcr *currPr); + +void asmTerminateCoreLoopSeq(VirtProcr *currPr); #define flushRegisters() \ asm volatile ("":::"%rbx", "%r12", "%r13","%r14","%r15"); diff -r f1374d5dbb98 -r 99343ffe1918 VMS.c --- a/VMS.c Fri Sep 16 20:13:33 2011 +0200 +++ b/VMS.c Mon Sep 19 14:15:37 2011 +0200 @@ -619,13 +619,9 @@ // itself //Note, should not stack-allocate initial data -- no guarantee, in // general that creating processor will outlive ones it creates. - - - /* - * call the core specific version, because the creating master can already be dead - */ - //VMS__free_in_lib( animatingPr->startOfStack, animatingPr ); - //VMS__free_in_lib( animatingPr, animatingPr); + + VMS__free( animatingPr->startOfStack); + VMS__free( animatingPr); } @@ -664,14 +660,12 @@ void VMS__shutdown() { int coreIdx; - VirtProcr *shutDownPr; - - //create the shutdown processors, one for each core loop -- put them - // directly into the Q -- each core will die when gets one + //Send a shutdown Request to all MasterLoops. for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ) { //Note, this is running in the master - shutDownPr = VMS__create_procr( &endOSThreadFn, NULL ); - writeVMSQ( shutDownPr, _VMSMasterEnv->readyToAnimateQs[coreIdx] ); + InterVMSCoreReqst *shutdownReqst = VMS__malloc(sizeof(InterVMSCoreReqst)); + shutdownReqst->secondReqType = shutdownVP; + sendInterMasterReqst(coreIdx, (InterMasterReqst*)shutdownReqst); } } @@ -690,6 +684,7 @@ * to core loop function -- note that this slices out a level of virtual * processors). */ +/* void endOSThreadFn( void *initData, VirtProcr *animatingPr ) { @@ -699,6 +694,7 @@ asmTerminateCoreLoop(animatingPr); #endif } + */ /*This is called from the startup & shutdown diff -r f1374d5dbb98 -r 99343ffe1918 VMS.h --- a/VMS.h Fri Sep 16 20:13:33 2011 +0200 +++ b/VMS.h Mon Sep 19 14:15:37 2011 +0200 @@ -49,9 +49,9 @@ #define DEBUG2( bool, msg, p1, p2) \ // if(bool) {printf(msg, p1, p2); fflush(stdin);} -#define ERROR(msg) printf(msg); -#define ERROR1(msg, param) printf(msg, param); -#define ERROR2(msg, p1, p2) printf(msg, p1, p2); +#define ERROR(msg) printf(msg) +#define ERROR1(msg, param) printf(msg, param); +#define ERROR2(msg, p1, p2) printf(msg, p1, p2) //=========================== STATS ======================= diff -r f1374d5dbb98 -r 99343ffe1918 contextSwitch.s --- a/contextSwitch.s Fri Sep 16 20:13:33 2011 +0200 +++ b/contextSwitch.s Mon Sep 19 14:15:37 2011 +0200 @@ -94,6 +94,9 @@ #VirtProcr in %rdi movq 0x38(%rdi), %rsp #restore stack pointer movq 0x30(%rdi), %rbp #restore frame pointer + movq $_VMSMasterEnv, %rcx + movq (%rcx) , %rcx + movl $0x0 , 0x44(%rcx) #release lock movq $terminateCoreLoop, %rax jmp *%rax #jmp to CoreLoop @@ -108,7 +111,6 @@ movq 0x38(%rdi), %rsp #restore stack pointer movq 0x30(%rdi), %rbp #restore frame pointer #argument is in %rdi - call VMS__dissipate_procr movq %rbp , %rsp #goto the coreLoops stack pop %rbp #restore the old framepointer ret #return from core loop diff -r f1374d5dbb98 -r 99343ffe1918 inter_VMS_requests.h --- a/inter_VMS_requests.h Fri Sep 16 20:13:33 2011 +0200 +++ b/inter_VMS_requests.h Mon Sep 19 14:15:37 2011 +0200 @@ -34,7 +34,8 @@ //This ones for requests between internals of VMS-core.. such as malloc enum InterVMSCoreReqType { - transfer_free_ptr = 1 //avoid starting enums at 0, for debug reasons + transfer_free_ptr = 1, //avoid starting enums at 0, for debug reasons + shutdownVP }; //Doing a trick to save space & time -- allocate space diff -r f1374d5dbb98 -r 99343ffe1918 inter_VMS_requests_handler.c --- a/inter_VMS_requests_handler.c Fri Sep 16 20:13:33 2011 +0200 +++ b/inter_VMS_requests_handler.c Mon Sep 19 14:15:37 2011 +0200 @@ -7,6 +7,7 @@ #include #include +#include "VMS.h" #include "ProcrContext.h" #include "inter_VMS_requests.h" #include "vmalloc.h" @@ -24,3 +25,17 @@ VMS__free( masterReq->freePtr ); } + +/* + * The starts the shutdown procedure. + */ +inline void +handleShutdown( InterVMSCoreReqst *masterReq, VirtProcr *masterPr ) +{ +#ifdef SEQUENTIAL + asmTerminateCoreLoopSeq(masterPr); +#else + asmTerminateCoreLoop(masterPr); +#endif +} + diff -r f1374d5dbb98 -r 99343ffe1918 inter_VMS_requests_handler.h --- a/inter_VMS_requests_handler.h Fri Sep 16 20:13:33 2011 +0200 +++ b/inter_VMS_requests_handler.h Mon Sep 19 14:15:37 2011 +0200 @@ -18,6 +18,9 @@ inline void handleTransferFree( InterVMSCoreReqst *masterReq, VirtProcr *masterPr ); +inline void +handleShutdown( InterVMSCoreReqst *masterReq, VirtProcr *masterPr ); + #endif /* _MASTER_REQ_HANDLER_H */ diff -r f1374d5dbb98 -r 99343ffe1918 vmalloc.c --- a/vmalloc.c Fri Sep 16 20:13:33 2011 +0200 +++ b/vmalloc.c Mon Sep 19 14:15:37 2011 +0200 @@ -103,7 +103,7 @@ } if( foundElem == NULL ) - { ERROR("\nmalloc failed\n") + { ERROR1("\nMalloc failed, requested size: %d\n", sizeRequested); return (void *)NULL; //indicates malloc failed } //Using a kludge to identify the element that is the top chunk in the