changeset 70:f9b60012fd74

working ucontext version
author Merten Sach <msach@mailbox.tu-berlin.de>
date Fri, 27 May 2011 12:35:40 +0200
parents 11bfe9d136ed
children 556f58db1531 efb55f1b5fb9
files CoreLoop.c MasterLoop.c VMS.c VMS.h
diffstat 4 files changed, 118 insertions(+), 165 deletions(-) [+]
line diff
     1.1 --- a/CoreLoop.c	Wed May 11 16:13:24 2011 +0200
     1.2 +++ b/CoreLoop.c	Fri May 27 12:35:40 2011 +0200
     1.3 @@ -27,7 +27,7 @@
     1.4   *This cycle then repeats, until a special shutdown virtual processor is
     1.5   * animated, which jumps to the end point at the bottom of core loop.
     1.6   */
     1.7 -void *
     1.8 +void 
     1.9  coreLoop( void *paramsIn )
    1.10   { 
    1.11     ThdParams      *coreLoopThdParams;
    1.12 @@ -36,8 +36,9 @@
    1.13     VMSQueueStruc *readyToAnimateQ;
    1.14     unsigned long   coreMask;  //has 1 in bit positions of allowed cores
    1.15     int             errorCode;
    1.16 +   ucontext_t coreLoopContext;
    1.17  
    1.18 -      //work-stealing struc on stack to prevent false-sharing in cache-line
    1.19 +   //work-stealing struc on stack to prevent false-sharing in cache-line
    1.20     volatile GateStruc gate;
    1.21     //preGateProgress, waitProgress, exitProgress, gateClosed;
    1.22  
    1.23 @@ -78,8 +79,8 @@
    1.24        //To get label addr in non-gcc compiler, can trick it by making a call
    1.25        // to a fn that does asm that pulls the "return"
    1.26        // addr off the stack and stores it in a pointed-to location.
    1.27 -   _VMSMasterEnv->coreLoopEndPt   = &&CoreLoopEndPt;
    1.28 -   _VMSMasterEnv->coreLoopStartPt = &&CoreLoopStartPt;
    1.29 +      //VMSMasterEnv->coreLoopEndPt   = &&CoreLoopEndPt;
    1.30 +      //VMSMasterEnv->coreLoopStartPt = &&CoreLoopStartPt;
    1.31     
    1.32        //Core loop has no values live upon CoreLoopStartPt except
    1.33        // _VMSMasterEnv
    1.34 @@ -90,7 +91,7 @@
    1.35        // Get to work!  --  virt procr jumps back here when suspends
    1.36        //Note, have to restore the frame-pointer before jump to here, to get
    1.37        // this code to work right (readyToAnimateQ and so forth are frame-ptr relative)
    1.38 -CoreLoopStartPt:
    1.39 +   while(1){
    1.40     
    1.41        //Get virtual processor from queue
    1.42        //The Q must be a global, static volatile var, so not kept in reg,
    1.43 @@ -117,7 +118,8 @@
    1.44     currPr = (VirtProcr *) readVMSQ( readyToAnimateQ );
    1.45     #endif
    1.46  
    1.47 -   if( currPr != NULL ) _VMSMasterEnv->numMasterInARow[thisCoresIdx] = 0;
    1.48 +   if( currPr != NULL )
    1.49 +       _VMSMasterEnv->numMasterInARow[thisCoresIdx] = 0;
    1.50     else
    1.51      {
    1.52        //============================= MEASUREMENT STUFF =====================
    1.53 @@ -127,7 +129,7 @@
    1.54        #endif
    1.55        //=====================================================================
    1.56        int tries = 0; int gotLock = 0;
    1.57 -      while( currPr == NULL ) //if queue was empty, enter get masterLock loop
    1.58 +      while( currPr == NULL ) //if queue was empty, enter loop to get MasterLock
    1.59         {    //queue was empty, so get master lock
    1.60  
    1.61           gotLock = __sync_bool_compare_and_swap(&(_VMSMasterEnv->masterLock),
    1.62 @@ -158,21 +160,33 @@
    1.63  
    1.64      }
    1.65  
    1.66 +   //SwitchToVP( currPr )
    1.67 +   //Swap to current VProc
    1.68 +   currPr->savedCoreLoopStatus = &coreLoopContext;
    1.69 +   coreLoopContext.uc_link=NULL;
    1.70 +   swapcontext(&coreLoopContext,currPr->savedVPStatus);
    1.71 +   }
    1.72 +
    1.73     
    1.74 -   SwitchToVP( currPr )
    1.75 -
    1.76 -
    1.77     //=========== jmp to here when want to shut down the VMS system ==========
    1.78 -   CoreLoopEndPt:
    1.79 -      //first free shutdown VP that jumped here -- it first restores the
    1.80 -      // coreloop's stack, so addr of currPr in stack frame is still correct
    1.81 +   //first free shutdown VP that jumped here -- it first restores the
    1.82 +   // coreloop's stack, so addr of currPr in stack frame is still correct
    1.83     VMS__dissipate_procr( currPr );
    1.84     pthread_exit( NULL );
    1.85   }
    1.86  
    1.87 +void terminateCoreLoop(VirtProcr *currPr)
    1.88 +{
    1.89 +  //=========== jmp to here when want to shut down the VMS system ==========
    1.90 +   //first free shutdown VP that jumped here -- it first restores the
    1.91 +   // coreloop's stack, so addr of currPr in stack frame is still correct
    1.92 +   VMS__dissipate_procr( currPr );
    1.93 +   pthread_exit( NULL );  
    1.94 +}
    1.95  
    1.96  
    1.97  
    1.98 +#ifdef SEQUENTIAL
    1.99  //===========================================================================
   1.100  /*This sequential version is exact same as threaded, except doesn't do the
   1.101   * pin-threads part, nor the wait until setup complete part.
   1.102 @@ -237,3 +251,4 @@
   1.103     VMS__dissipate_procr( currPr ); //free shutdown pr, that jmpd here
   1.104     return;
   1.105   }
   1.106 +#endif
     2.1 --- a/MasterLoop.c	Wed May 11 16:13:24 2011 +0200
     2.2 +++ b/MasterLoop.c	Fri May 27 12:35:40 2011 +0200
     2.3 @@ -20,7 +20,6 @@
     2.4  //===========================================================================
     2.5  
     2.6  
     2.7 -
     2.8  /*This code is animated by the virtual Master processor.
     2.9   *
    2.10   *Polls each sched slot exactly once, hands any requests made by a newly
    2.11 @@ -84,16 +83,12 @@
    2.12  
    2.13     int32           thisCoresIdx;
    2.14     VirtProcr      *masterPr;
    2.15 -   volatile        VirtProcr *volatileMasterPr;
    2.16 -   
    2.17 -   volatileMasterPr = animatingPr;
    2.18 -   masterPr         = (VirtProcr*)volatileMasterPr; //used to force re-define after jmp
    2.19  
    2.20        //First animation of each MasterVP will in turn animate this part
    2.21        // of setup code.. (VP creator sets up the stack as if this function
    2.22        // was called normally, but actually get here by jmp)
    2.23        //So, setup values about stack ptr, jmp pt and all that
    2.24 -   masterPr->nextInstrPt = &&masterLoopStartPt;
    2.25 +   masterPr         = animatingPr;  //just to make sure after jmp
    2.26  
    2.27  
    2.28        //Note, got rid of writing the stack and frame ptr up here, because
    2.29 @@ -102,9 +97,21 @@
    2.30        // new frame and stack ptr to the MasterVP storage before a second
    2.31        // version of that MasterVP can get animated on a different core.
    2.32        //Also got rid of the busy-wait.
    2.33 +   
    2.34 +   masterEnv        = (MasterEnv*)_VMSMasterEnv;
    2.35 +   
    2.36 +   thisCoresIdx     = masterPr->coreAnimatedBy;
    2.37 +   readyToAnimateQ  = masterEnv->readyToAnimateQs[thisCoresIdx];
    2.38 +   schedSlots       = masterEnv->allSchedSlots[thisCoresIdx];
    2.39 +
    2.40 +   requestHandler   = masterEnv->requestHandler;
    2.41 +   slaveScheduler   = masterEnv->slaveScheduler;
    2.42 +   semanticEnv      = masterEnv->semanticEnv;
    2.43 +
    2.44  
    2.45     
    2.46 -   masterLoopStartPt:
    2.47 +   while(1){
    2.48 +   
    2.49     //============================= MEASUREMENT STUFF ========================
    2.50     #ifdef MEAS__TIME_MASTER
    2.51        //Total Master time includes one coreloop time -- just assume the core
    2.52 @@ -114,20 +121,7 @@
    2.53     #endif
    2.54     //========================================================================
    2.55  
    2.56 -   masterEnv        = (MasterEnv*)_VMSMasterEnv;
    2.57 -   
    2.58 -      //GCC may optimize so doesn't always re-define from frame-storage
    2.59 -   masterPr         = (VirtProcr*)volatileMasterPr;  //just to make sure after jmp
    2.60 -   thisCoresIdx     = masterPr->coreAnimatedBy;
    2.61 -   readyToAnimateQ  = masterEnv->readyToAnimateQs[thisCoresIdx];
    2.62 -   schedSlots       = masterEnv->allSchedSlots[thisCoresIdx];
    2.63 -
    2.64 -   requestHandler   = masterEnv->requestHandler;
    2.65 -   slaveScheduler   = masterEnv->slaveScheduler;
    2.66 -   semanticEnv      = masterEnv->semanticEnv;
    2.67 -
    2.68 -
    2.69 -      //Poll each slot's Done flag
    2.70 +   //Poll each slot's Done flag
    2.71     numSlotsFilled = 0;
    2.72     for( slotIdx = 0; slotIdx < NUM_SCHED_SLOTS; slotIdx++)
    2.73      {
    2.74 @@ -185,39 +179,16 @@
    2.75     saveLowTimeStampCountInto( masterPr->endMasterTSCLow );
    2.76     #endif
    2.77  
    2.78 -
    2.79 -
    2.80 -/* VirtProcr  offsets:
    2.81 - * 0xc  stackPtr
    2.82 - * 0x10 framePtr
    2.83 - * 0x14 nextInstrPt
    2.84 - * 0x1c coreLoopFramePtr
    2.85 - * 0x20 coreLoopStackPtr
    2.86 - *
    2.87 - * _VMSMasterEnv  offsets:
    2.88 - * 0x24 coreLoopStartPt
    2.89 - * 0x28 coreLoopEndPt
    2.90 - * 0x30 masterLock
    2.91 - */
    2.92 -//   masterSwitchToCoreLoop( masterPr )
    2.93 -   asm volatile("movl         %0,       %%ebx;  \
    2.94 -                 movl         %1,       %%ecx;  \
    2.95 -                 movl      %%esp,  0x0c(%%ecx); \
    2.96 -                 movl      %%ebp,  0x10(%%ecx); \
    2.97 -                 movl 0x24(%%ebx),      %%eax;  \
    2.98 -                 movl 0x20(%%ecx),      %%esp;  \
    2.99 -                 movl 0x1c(%%ecx),      %%ebp;  \
   2.100 -                 movl $0x0,        0x30(%%ebx); \
   2.101 -                 jmp                    %%eax"  \
   2.102 -   /* outputs */ :                              \
   2.103 -   /* inputs  */ : "g"(_VMSMasterEnv), "g"(masterPr)                        \
   2.104 -   /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \
   2.105 -                );
   2.106 +   //Clear lock
   2.107 +   _VMSMasterEnv->masterLock = 0;
   2.108 +   
   2.109 +   //Swap to coreLoop
   2.110 +   swapcontext(masterPr->savedVPStatus,masterPr->savedCoreLoopStatus);
   2.111 +   }
   2.112  
   2.113   }
   2.114  
   2.115  
   2.116 -
   2.117  /*This has a race condition -- the coreloops are accessing their own queues
   2.118   * at the same time that this work-stealer on a different core is trying to
   2.119   */
     3.1 --- a/VMS.c	Wed May 11 16:13:24 2011 +0200
     3.2 +++ b/VMS.c	Fri May 27 12:35:40 2011 +0200
     3.3 @@ -261,6 +261,7 @@
     3.4        // the Master env and rest of VMS locations
     3.5   }
     3.6  
     3.7 +#ifdef SEQUENTIAL
     3.8  /*Only difference between version with an OS thread pinned to each core and
     3.9   * the sequential version of VMS is VMS__init_Seq, this, and coreLoop_Seq.
    3.10   */
    3.11 @@ -272,6 +273,7 @@
    3.12        coreLoop_Seq( NULL );
    3.13  
    3.14   }
    3.15 +#endif
    3.16  
    3.17  
    3.18  
    3.19 @@ -287,28 +289,30 @@
    3.20   */
    3.21  inline VirtProcr *
    3.22  create_procr_helper( VirtProcr *newPr,       VirtProcrFnPtr  fnPtr,
    3.23 -                     void      *initialData, char           *stackLocs )
    3.24 +                     void      *initialData, char           *stackLocs,
    3.25 +                     ucontext_t *contextBuf)
    3.26   {
    3.27 -   char  *stackPtr;
    3.28 -
    3.29 +   char  *stackPtr = ( (char *)stackLocs + VIRT_PROCR_STACK_SIZE - 0x4);
    3.30 +    
    3.31 +   getcontext(contextBuf);
    3.32 +   contextBuf->uc_stack.ss_sp=stackLocs;
    3.33 +   contextBuf->uc_stack.ss_size=VIRT_PROCR_STACK_SIZE;   
    3.34 +   contextBuf->uc_stack.ss_flags=0;
    3.35 +   makecontext(contextBuf, fnPtr, 2, initialData, newPr);
    3.36 +   contextBuf->uc_link=NULL;
    3.37 +   
    3.38 +   newPr->procrID      = _VMSMasterEnv->numProcrsCreated++;
    3.39 +   newPr->savedVPStatus  = contextBuf;
    3.40 +   newPr->initialData  = initialData;
    3.41     newPr->startOfStack = stackLocs;
    3.42 -   newPr->procrID      = _VMSMasterEnv->numProcrsCreated++;
    3.43 -   newPr->nextInstrPt  = fnPtr;
    3.44 -   newPr->initialData  = initialData;
    3.45     newPr->requests     = NULL;
    3.46     newPr->schedSlot    = NULL;
    3.47 -
    3.48 -      //fnPtr takes two params -- void *initData & void *animProcr
    3.49 -      //alloc stack locations, make stackPtr be the highest addr minus room
    3.50 -      // for 2 params + return addr.  Return addr (NULL) is in loc pointed to
    3.51 -      // by stackPtr, initData at stackPtr + 4 bytes, animatingPr just above
    3.52 -   stackPtr = ( (char *)stackLocs + VIRT_PROCR_STACK_SIZE - 0x10 );
    3.53     
    3.54        //setup __cdecl on stack -- coreloop will switch to stackPtr before jmp
    3.55 -   *( (int *)stackPtr + 2 ) = (int) newPr; //rightmost param -- 32bit pointer
    3.56 -   *( (int *)stackPtr + 1 ) = (int) initialData;  //next  param to left
    3.57 -   newPr->stackPtr = stackPtr; //core loop will switch to this, then
    3.58 -   newPr->framePtr = stackPtr; //suspend loop will save new stack & frame ptr
    3.59 +   //*( (int *)stackPtr + 2 ) = (int) newPr; //rightmost param -- 32bit pointer
    3.60 +   //*( (int *)stackPtr + 1 ) = (int) initialData;  //next  param to left
    3.61 +   //newPr->stackPtr = stackPtr; //core loop will switch to this, then
    3.62 +   //newPr->framePtr = stackPtr; //suspend loop will save new stack & frame ptr
    3.63  
    3.64     //============================= MEASUREMENT STUFF ========================
    3.65     #ifdef STATS__TURN_ON_PROBES
    3.66 @@ -326,13 +330,16 @@
    3.67  VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData )
    3.68   { VirtProcr *newPr;
    3.69     char      *stackLocs;
    3.70 +   ucontext_t *contextBuffer;
    3.71  
    3.72     newPr      = VMS__malloc( sizeof(VirtProcr) );
    3.73     stackLocs  = VMS__malloc( VIRT_PROCR_STACK_SIZE );
    3.74 +   contextBuffer  = VMS__malloc(sizeof(ucontext_t));
    3.75 +   
    3.76     if( stackLocs == 0 )
    3.77      { perror("VMS__malloc stack"); exit(1); }
    3.78  
    3.79 -   return create_procr_helper( newPr, fnPtr, initialData, stackLocs );
    3.80 +   return create_procr_helper( newPr, fnPtr, initialData, stackLocs, contextBuffer );
    3.81   }
    3.82  
    3.83  /* "ext" designates that it's for use outside the VMS system -- should only
    3.84 @@ -343,13 +350,16 @@
    3.85  VMS_ext__create_procr( VirtProcrFnPtr fnPtr, void *initialData )
    3.86   { VirtProcr *newPr;
    3.87     char      *stackLocs;
    3.88 +   ucontext_t *contextBuffer;
    3.89  
    3.90     newPr      = malloc( sizeof(VirtProcr) );
    3.91     stackLocs  = malloc( VIRT_PROCR_STACK_SIZE );
    3.92 +   contextBuffer  = VMS__malloc(sizeof(ucontext_t));
    3.93 +   
    3.94     if( stackLocs == 0 )
    3.95      { perror("malloc stack"); exit(1); }
    3.96  
    3.97 -   return create_procr_helper( newPr, fnPtr, initialData, stackLocs );
    3.98 +   return create_procr_helper( newPr, fnPtr, initialData, stackLocs, contextBuffer );
    3.99   }
   3.100  
   3.101  
   3.102 @@ -373,14 +383,7 @@
   3.103  void
   3.104  VMS__suspend_procr( VirtProcr *animatingPr )
   3.105   { 
   3.106 -
   3.107 -      //The request to master will cause this suspended virt procr to get
   3.108 -      // scheduled again at some future point -- to resume, core loop jumps
   3.109 -      // to the resume point (below), which causes restore of saved regs and
   3.110 -      // "return" from this call.
   3.111 -   animatingPr->nextInstrPt = &&ResumePt;
   3.112 -
   3.113 -      //return ownership of the virt procr and sched slot to Master virt pr
   3.114 +    //return ownership of the virt procr and sched slot to Master virt pr
   3.115     animatingPr->schedSlot->workIsDone = TRUE;
   3.116  
   3.117     //===========================  Measurement stuff ========================
   3.118 @@ -389,57 +392,14 @@
   3.119     saveLowTimeStampCountInto( animatingPr->preSuspTSCLow );
   3.120     #endif
   3.121     //=======================================================================
   3.122 -
   3.123 -/* VirtProcr  offsets:
   3.124 - * 0xc  stackPtr
   3.125 - * 0x10 framePtr
   3.126 - * 0x14 nextInstrPt
   3.127 - * 0x1c coreLoopFramePtr
   3.128 - * 0x20 coreLoopStackPtr
   3.129 - *
   3.130 - * _VMSMasterEnv  offsets:
   3.131 - * 0x24 coreLoopStartPt
   3.132 - * 0x28 coreLoopEndPt
   3.133 - * 0x30 masterLock
   3.134 - */
   3.135 -//   SwitchToCoreLoop( animatingPr )
   3.136 -   asm volatile("movl         %0,       %%ebx;  \
   3.137 -                 movl         %1,       %%ecx;  \
   3.138 -                 movl      %%esp,  0x0c(%%ecx); \
   3.139 -                 movl      %%ebp,  0x10(%%ecx); \
   3.140 -                 movl 0x24(%%ebx),      %%eax;  \
   3.141 -                 movl 0x20(%%ecx),      %%esp;  \
   3.142 -                 movl 0x1c(%%ecx),      %%ebp;  \
   3.143 -                 jmp                    %%eax"  \
   3.144 -   /* outputs */ :                              \
   3.145 -   /* inputs  */ : "g"(_VMSMasterEnv), "g"(animatingPr)                     \
   3.146 -   /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \
   3.147 -                );
   3.148 -
   3.149 -//  asm volatile("mov  %0,%%ebx;       \
   3.150 -                 mov  %%ebx, %%eax;   \
   3.151 -                 add  $0xc,  %%eax;   \
   3.152 -                 movl %%esp, (%%eax); \
   3.153 -                 mov  %%ebx, %%eax;   \
   3.154 -                 add  $0x10, %%eax;   \
   3.155 -                 movl %%ebp, (%%eax); \
   3.156 -                 movl %1, %%eax;      \
   3.157 -                 movl %2, %%esp;      \
   3.158 -                 movl %3, %%ebp;      \
   3.159 -                 jmp  %%eax"          \
   3.160 -   /* outputs */ :                    \
   3.161 -   /* inputs  */ : "g"(animatingPr), "g" (jmpPt), "g" (coreLoopStackPtr), \
   3.162 -                   "g" (coreLoopFramePtr) \
   3.163 -   /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \
   3.164 -                );
   3.165 +   
   3.166 +   swapcontext(animatingPr->savedVPStatus,animatingPr->savedCoreLoopStatus);
   3.167  
   3.168     //=======================================================================
   3.169 -ResumePt:
   3.170     #ifdef MEAS__TIME_STAMP_SUSP
   3.171        //NOTE: only take low part of count -- do sanity check when take diff
   3.172     saveLowTimeStampCountInto( animatingPr->postSuspTSCLow );
   3.173     #endif
   3.174 -
   3.175     return;
   3.176   }
   3.177  
   3.178 @@ -739,21 +699,15 @@
   3.179  void
   3.180  endOSThreadFn( void *initData, VirtProcr *animatingPr )
   3.181   { void *jmpPt, *coreLoopStackPtr, *coreLoopFramePtr;
   3.182 -
   3.183 -   jmpPt             = _VMSMasterEnv->coreLoopEndPt;
   3.184 -   coreLoopStackPtr  = animatingPr->coreLoopStackPtr;
   3.185 -   coreLoopFramePtr  = animatingPr->coreLoopFramePtr;
   3.186 -
   3.187 -
   3.188 -   asm volatile("movl %0, %%eax;      \
   3.189 -                 movl %1, %%esp;      \
   3.190 -                 movl %2, %%ebp;      \
   3.191 -                 jmp  %%eax    "      \
   3.192 -   /* outputs */ :                    \
   3.193 -   /* inputs  */ : "m" (jmpPt), "m"(coreLoopStackPtr), "m"(coreLoopFramePtr)\
   3.194 -   /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi","%esi"  \
   3.195 -                );
   3.196 - }
   3.197 + ucontext_t* contextBuf = animatingPr->savedCoreLoopStatus;
   3.198 + void *stackPtr = contextBuf->uc_mcontext.gregs[REG_ESP];
   3.199 + 
   3.200 + getcontext(contextBuf);
   3.201 + contextBuf->uc_stack.ss_sp=stackPtr;
   3.202 + makecontext(contextBuf,&terminateCoreLoop,1,animatingPr);
   3.203 + contextBuf->uc_link=NULL;
   3.204 + swapcontext(animatingPr->savedVPStatus,contextBuf);
   3.205 +}
   3.206  
   3.207  
   3.208  /*This is called from the startup & shutdown
     4.1 --- a/VMS.h	Wed May 11 16:13:24 2011 +0200
     4.2 +++ b/VMS.h	Fri May 27 12:35:40 2011 +0200
     4.3 @@ -17,9 +17,9 @@
     4.4  #include "Hash_impl/PrivateHash.h"
     4.5  #include "vmalloc.h"
     4.6  
     4.7 -//#include <stdio.h>
     4.8  #include <pthread.h>
     4.9  #include <sys/time.h>
    4.10 +#include <ucontext.h>
    4.11  
    4.12  
    4.13  //===============================  Debug  ===================================
    4.14 @@ -51,9 +51,9 @@
    4.15  #define DEBUG2( bool, msg, p1, p2) \
    4.16  //   if(bool) {printf(msg, p1, p2); fflush(stdin);}
    4.17  
    4.18 -#define ERROR(msg) printf(msg); //fflush(stdin);
    4.19 -#define ERROR1(msg, param) printf(msg, param); fflush(stdin);
    4.20 -#define ERROR2(msg, p1, p2) printf(msg, p1, p2); fflush(stdin);
    4.21 +#define ERROR(msg) printf(msg);
    4.22 +#define ERROR1(msg, param) printf(msg, param);
    4.23 +#define ERROR2(msg, p1, p2) printf(msg, p1, p2);
    4.24  
    4.25  //===========================  STATS =======================
    4.26  
    4.27 @@ -175,13 +175,15 @@
    4.28   { int         procrID;  //for debugging -- count up each time create
    4.29     int         coreAnimatedBy;
    4.30     void       *startOfStack;
    4.31 -   void       *stackPtr;
    4.32 -   void       *framePtr;
    4.33 -   void       *nextInstrPt;
    4.34 +   //void       *stackPtr;
    4.35 +   //void       *framePtr;
    4.36 +   //void       *nextInstrPt;
    4.37 +   ucontext_t    *savedVPStatus;
    4.38     
    4.39 -   void       *coreLoopStartPt;  //allows proto-runtime to be linked later
    4.40 -   void       *coreLoopFramePtr; //restore before jmp back to core loop
    4.41 -   void       *coreLoopStackPtr; //restore before jmp back to core loop
    4.42 +   //void       *coreLoopStartPt;  //allows proto-runtime to be linked later
    4.43 +   //void       *coreLoopFramePtr; //restore before jmp back to core loop
    4.44 +   //void       *coreLoopStackPtr; //restore before jmp back to core loop
    4.45 +   ucontext_t  *savedCoreLoopStatus;
    4.46  
    4.47     void       *initialData;
    4.48  
    4.49 @@ -225,11 +227,11 @@
    4.50     MallocProlog    *freeListHead;
    4.51     int32            amtOfOutstandingMem; //total currently allocated
    4.52  
    4.53 -   void            *coreLoopStartPt;//addr to jump to to re-enter coreLoop
    4.54 -   void            *coreLoopEndPt;  //addr to jump to to shut down a coreLoop
    4.55 +   //void            *coreLoopStartPt;//addr to jump to to re-enter coreLoop
    4.56 +   //void            *coreLoopEndPt;  //addr to jump to to shut down a coreLoop
    4.57  
    4.58     int32            setupComplete;
    4.59 -   int32            masterLock;
    4.60 +   volatile int32            masterLock;
    4.61  
    4.62     int32            numMasterInARow[NUM_CORES];//detect back-to-back masterVP
    4.63     GateStruc       *workStealingGates[ NUM_CORES ]; //concurrent work-steal
    4.64 @@ -278,11 +280,11 @@
    4.65  
    4.66  //=======================  OS Thread related  ===============================
    4.67  
    4.68 -void * coreLoop( void *paramsIn );  //standard PThreads fn prototype
    4.69 +void coreLoop( void *paramsIn );  //standard PThreads fn prototype
    4.70  void * coreLoop_Seq( void *paramsIn );  //standard PThreads fn prototype
    4.71 +void terminateCoreLoop(VirtProcr *currPr);
    4.72  void masterLoop( void *initData, VirtProcr *masterPr );
    4.73  
    4.74 -
    4.75  typedef struct
    4.76   {
    4.77     void           *endThdPt;
    4.78 @@ -296,7 +298,6 @@
    4.79  pthread_cond_t  suspend_cond;
    4.80  
    4.81  
    4.82 -
    4.83  //=====================  Global Vars ===================
    4.84  
    4.85  volatile MasterEnv      *_VMSMasterEnv;
    4.86 @@ -548,6 +549,18 @@
    4.87  
    4.88  //=====
    4.89  
    4.90 +//======= Utilities ======
    4.91 +/*
    4.92 + * This Macro makes the gcc reload all variables from Stack after this function.
    4.93 + * This is necessary because we jmp into the masterLoop and the variables are
    4.94 + * kept in Registers for optimization.
    4.95 + */
    4.96 +#define flushRegisters() \
    4.97 +         asm volatile ("" /*no instr needed*/  \  
    4.98 +                        ::: /*no output and input*/ \
    4.99 +                        "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi")
   4.100 +//========
   4.101 +
   4.102  #include "SwitchAnimators.h"
   4.103  #include "probes.h"
   4.104  #include "vutilities.h"