diff MasterLoop.c @ 119:ac11b50220bd

Added inter-master requests
author Me@portablequad
date Tue, 30 Aug 2011 21:55:04 -0700
parents efb55f1b5fb9
children d4c881c7f03a 7cff4e13d5c4
line diff
     1.1 --- a/MasterLoop.c	Tue Jul 26 16:28:47 2011 +0200
     1.2 +++ b/MasterLoop.c	Tue Aug 30 21:55:04 2011 -0700
     1.3 @@ -11,7 +11,7 @@
     1.4  
     1.5  #include "VMS.h"
     1.6  #include "ProcrContext.h"
     1.7 -
     1.8 +#include "Master_Request_Handlers.h"
     1.9  
    1.10  //===========================================================================
    1.11  void inline
    1.12 @@ -106,6 +106,8 @@
    1.13  
    1.14     
    1.15     //masterLoopStartPt:
    1.16 +   //The animating materVP suspends at end of this loop, then later resumes and
    1.17 +   // comes back here 
    1.18     while(1){
    1.19         
    1.20     //============================= MEASUREMENT STUFF ========================
    1.21 @@ -120,7 +122,7 @@
    1.22     masterEnv        = (MasterEnv*)_VMSMasterEnv;
    1.23     
    1.24        //GCC may optimize so doesn't always re-define from frame-storage
    1.25 -   masterPr         = (VirtProcr*)volatileMasterPr;  //just to make sure after jmp
    1.26 +   masterPr         = (VirtProcr*)volatileMasterPr; //on stack, to be sure after jmp
    1.27     thisCoresIdx     = masterPr->coreAnimatedBy;
    1.28     readyToAnimateQ  = masterEnv->readyToAnimateQs[thisCoresIdx];
    1.29     schedSlots       = masterEnv->allSchedSlots[thisCoresIdx];
    1.30 @@ -129,8 +131,16 @@
    1.31     slaveScheduler   = masterEnv->slaveScheduler;
    1.32     semanticEnv      = masterEnv->semanticEnv;
    1.33  
    1.34 -
    1.35 -      //Poll each slot's Done flag
    1.36 +      //First, check for requests from other MasterVPs, and handle them
    1.37 +   if( masterEnv->requestsWaitingFor[thisCoresIdx] )
    1.38 +    { masterReqQ = masterEnv->masterReqQs[thisCoresIdx];
    1.39 +	  while( currReq = readVMSQ(masterReqQ) )
    1.40 +       { handleMasterReq( currReq, semanticEnv, masterPr );
    1.41 +       }	   
    1.42 +	}
    1.43 +      //Now, take care of the SlaveVPs
    1.44 +	  //Go through the slots -- if Slave there newly suspended, handle its request
    1.45 +	  // then, either way, ask assigner to fill each slot
    1.46     numSlotsFilled = 0;
    1.47     for( slotIdx = 0; slotIdx < NUM_SCHED_SLOTS; slotIdx++)
    1.48      {
    1.49 @@ -190,15 +200,44 @@
    1.50  
    1.51     masterSwitchToCoreLoop(animatingPr);
    1.52     flushRegisters();
    1.53 -   }//MasterLoop
    1.54 -
    1.55 -
    1.56 +   }//while(1)   MasterLoop
    1.57   }
    1.58  
    1.59 +/*This is for inter-master communication.  Either the master itself or
    1.60 + * the plugin sends one of these requests.  Some are handled here, by the
    1.61 + * master_loop, others are handed off to the plugin.
    1.62 + */
    1.63 +void inline
    1.64 +handleMasterReq( MasterReq *currReq, void *_semEnv, VirtProcr *masterPr )
    1.65 + {
    1.66 +   switch( currReq->reqType )
    1.67 +    { case interVMSReq:
    1.68 +            handleInterVMSReq(     (InterVMSCoreReq *)currReq, masterPr);
    1.69 +         break;
    1.70 +      case interPluginReq:
    1.71 +	       (*interPluginReqHdlr)(  (InterPluginReq  *)currReq, _semEnv );
    1.72 +         break;
    1.73 +      default:
    1.74 +         break;
    1.75 +    }
    1.76 + }
    1.77  
    1.78 +void inline
    1.79 +handleInterVMSReq( InterVMSCoreReq *currReq, VirtProcr *masterPr )
    1.80 + { 
    1.81 +   switch( currReq->reqType )
    1.82 +    {
    1.83 +      case transfer_free:        handleTransferFree( currReq, masterPr );
    1.84 +         break;
    1.85 +    }
    1.86 + }
    1.87 + 
    1.88  
    1.89 -/*This has a race condition -- the coreloops are accessing their own queues
    1.90 - * at the same time that this work-stealer on a different core is trying to
    1.91 +/*Work Stealing Alg -- racy one
    1.92 + *This algorithm has a race condition -- the coreloops are accessing their
    1.93 + * own queues at the same time that this work-stealer on a different core
    1.94 + * is trying to.
    1.95 + *The second stealing alg, below, protects against this.
    1.96   */
    1.97  void inline
    1.98  stealWorkInto( SchedSlot *currSlot, VMSQueueStruc *readyToAnimateQ,
    1.99 @@ -234,7 +273,8 @@
   1.100      }
   1.101   }
   1.102  
   1.103 -/*This algorithm makes the common case fast.  Make the coreloop passive,
   1.104 +/*Work Stealing alg -- protected one
   1.105 + *This algorithm makes the common case fast.  Make the coreloop passive,
   1.106   * and show its progress.  Make the stealer control a gate that coreloop
   1.107   * has to pass.
   1.108   *To avoid interference, only one stealer at a time.  Use a global
   1.109 @@ -360,7 +400,7 @@
   1.110     //======= End Gate-protection  =======
   1.111  
   1.112  
   1.113 -   if( stolenPr != NULL )  //victim could have been in protected and taken
   1.114 +   if( stolenPr != NULL )  //victim could have been in protected and took it
   1.115      { currSlot->procrAssignedToSlot = stolenPr;
   1.116        stolenPr->schedSlot           = currSlot;
   1.117        currSlot->needsProcrAssigned  = FALSE;