diff VMS.c @ 55:3bac84e4e56e

Works with correct matrix mult Nov 4 -- switch animators macros, many updates Changed all queues back to VMSQ variants #defines correct, protected, work-stealing, with compiler switch in and out
author Me
date Thu, 04 Nov 2010 18:13:18 -0700
parents f8508572f3de
children 26d53313a8f2
line diff
     1.1 --- a/VMS.c	Tue Nov 02 16:43:01 2010 -0700
     1.2 +++ b/VMS.c	Thu Nov 04 18:13:18 2010 -0700
     1.3 @@ -87,7 +87,7 @@
     1.4  void
     1.5  create_masterEnv()
     1.6   { MasterEnv       *masterEnv;
     1.7 -   SRSWQueueStruc **readyToAnimateQs;
     1.8 +   VMSQueueStruc **readyToAnimateQs;
     1.9     int              coreIdx;
    1.10     VirtProcr      **masterVPs;
    1.11     SchedSlot     ***allSchedSlots; //ptr to array of ptrs
    1.12 @@ -105,7 +105,7 @@
    1.13     masterEnv     = _VMSMasterEnv;
    1.14     
    1.15        //Make a readyToAnimateQ for each core loop
    1.16 -   readyToAnimateQs = VMS__malloc( NUM_CORES * sizeof(SRSWQueueStruc *) );
    1.17 +   readyToAnimateQs = VMS__malloc( NUM_CORES * sizeof(VMSQueueStruc *) );
    1.18     masterVPs        = VMS__malloc( NUM_CORES * sizeof(VirtProcr *) );
    1.19  
    1.20        //One array for each core, 3 in array, core's masterVP scheds all
    1.21 @@ -114,18 +114,20 @@
    1.22     _VMSMasterEnv->numProcrsCreated = 0;  //used by create procr
    1.23     for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
    1.24      {    
    1.25 -      readyToAnimateQs[ coreIdx ] = makeSRSWQ();
    1.26 +      readyToAnimateQs[ coreIdx ] = makeVMSQ();
    1.27        
    1.28           //Q: should give masterVP core-specific info as its init data?
    1.29        masterVPs[ coreIdx ] = VMS__create_procr( &masterLoop, masterEnv );
    1.30        masterVPs[ coreIdx ]->coreAnimatedBy = coreIdx;
    1.31        allSchedSlots[ coreIdx ] = create_sched_slots(); //makes for one core
    1.32        _VMSMasterEnv->numMasterInARow[ coreIdx ] = 0;
    1.33 +      _VMSMasterEnv->workStealingGates[ coreIdx ] = NULL;
    1.34      }
    1.35     _VMSMasterEnv->readyToAnimateQs = readyToAnimateQs;
    1.36     _VMSMasterEnv->masterVPs        = masterVPs;
    1.37     _VMSMasterEnv->masterLock       = UNLOCKED;
    1.38     _VMSMasterEnv->allSchedSlots    = allSchedSlots;
    1.39 +   _VMSMasterEnv->workStealingLock = UNLOCKED;
    1.40  
    1.41  
    1.42        //Aug 19, 2010:  no longer need to place initial masterVP into queue
    1.43 @@ -338,8 +340,7 @@
    1.44   */
    1.45  void
    1.46  VMS__suspend_procr( VirtProcr *animatingPr )
    1.47 - { void *jmpPt, *stackPtrAddr, *framePtrAddr, *coreLoopStackPtr;
    1.48 -   void *coreLoopFramePtr;
    1.49 + { 
    1.50  
    1.51        //The request to master will cause this suspended virt procr to get
    1.52        // scheduled again at some future point -- to resume, core loop jumps
    1.53 @@ -350,23 +351,6 @@
    1.54        //return ownership of the virt procr and sched slot to Master virt pr
    1.55     animatingPr->schedSlot->workIsDone = TRUE;
    1.56  
    1.57 -   stackPtrAddr      = &(animatingPr->stackPtr);
    1.58 -   framePtrAddr      = &(animatingPr->framePtr);
    1.59 -
    1.60 -   jmpPt             = _VMSMasterEnv->coreLoopStartPt;
    1.61 -   coreLoopFramePtr  = animatingPr->coreLoopFramePtr;//need this only
    1.62 -   coreLoopStackPtr  = animatingPr->coreLoopStackPtr;//safety
    1.63 -
    1.64 -      //Save the virt procr's stack and frame ptrs,
    1.65 -   asm volatile("movl %0,     %%eax;  \
    1.66 -                 movl %%esp, (%%eax); \
    1.67 -                 movl %1,     %%eax;  \
    1.68 -                 movl %%ebp, (%%eax) "\
    1.69 -   /* outputs */ : "=g" (stackPtrAddr), "=g" (framePtrAddr) \
    1.70 -   /* inputs  */ :        \
    1.71 -   /* clobber */ : "%eax" \
    1.72 -                );
    1.73 -
    1.74     //===========================  Measurement stuff ========================
    1.75     #ifdef MEAS__TIME_STAMP_SUSP
    1.76        //record time stamp: compare to time-stamp recorded below
    1.77 @@ -374,20 +358,10 @@
    1.78     #endif
    1.79     //=======================================================================
    1.80  
    1.81 -      //restore coreloop's frame ptr, then jump back to "start" of core loop
    1.82 -      //Note, GCC compiles to assembly that saves esp and ebp in the stack
    1.83 -      // frame -- so have to explicitly do assembly that saves to memory
    1.84 -   asm volatile("movl %0, %%eax;      \
    1.85 -                 movl %1, %%esp;      \
    1.86 -                 movl %2, %%ebp;      \
    1.87 -                 jmp  %%eax    "      \
    1.88 -   /* outputs */ :                    \
    1.89 -   /* inputs  */ : "m" (jmpPt), "m"(coreLoopStackPtr), "m"(coreLoopFramePtr)\
    1.90 -   /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi","%esi"  \
    1.91 -                ); //list everything as clobbered to force GCC to save all
    1.92 -                   // live vars that are in regs on stack before this
    1.93 -                   // assembly, so that stack pointer is correct, before jmp
    1.94  
    1.95 +   SwitchToCoreLoop( animatingPr )
    1.96 +
    1.97 +   //=======================================================================
    1.98  ResumePt:
    1.99     #ifdef MEAS__TIME_STAMP_SUSP
   1.100        //NOTE: only take low part of count -- do sanity check when take diff
   1.101 @@ -673,7 +647,7 @@
   1.102     for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ )
   1.103      {    //Note, this is running in the master
   1.104        shutDownPr = VMS__create_procr( &endOSThreadFn, NULL );
   1.105 -      writeSRSWQ( shutDownPr, _VMSMasterEnv->readyToAnimateQs[coreIdx] );
   1.106 +      writeVMSQ( shutDownPr, _VMSMasterEnv->readyToAnimateQs[coreIdx] );
   1.107      }
   1.108  
   1.109   }
   1.110 @@ -717,7 +691,7 @@
   1.111  void
   1.112  VMS__cleanup_at_end_of_shutdown()
   1.113   { 
   1.114 -   SRSWQueueStruc **readyToAnimateQs;
   1.115 +   VMSQueueStruc **readyToAnimateQs;
   1.116     int              coreIdx;
   1.117     VirtProcr      **masterVPs;
   1.118     SchedSlot     ***allSchedSlots; //ptr to array of ptrs
   1.119 @@ -731,7 +705,7 @@
   1.120     
   1.121     for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
   1.122      {
   1.123 -      freeSRSWQ( readyToAnimateQs[ coreIdx ] );
   1.124 +      freeVMSQ( readyToAnimateQs[ coreIdx ] );
   1.125           //master VPs were created external to VMS, so use external free
   1.126        VMS__dissipate_procr( masterVPs[ coreIdx ] );
   1.127