diff MasterLoop.c @ 169:d1dd9e6ee72c

VMS preprocessor definitions moved to VMS_defs.h and changes to measurement
author Merten Sach <msach@mailbox.tu-berlin.de>
date Fri, 16 Dec 2011 20:00:21 +0100
parents fe5ec83f1baf
children c3f458403cd6
line diff
     1.1 --- a/MasterLoop.c	Thu Oct 06 16:25:59 2011 +0200
     1.2 +++ b/MasterLoop.c	Fri Dec 16 20:00:21 2011 +0100
     1.3 @@ -16,7 +16,7 @@
     1.4  //===========================================================================
     1.5  void inline
     1.6  stealWorkInto( SchedSlot *currSlot, VMSQueueStruc *readyToAnimateQ,
     1.7 -               VirtProcr *masterPr );
     1.8 +               VirtProcr *masterVP );
     1.9  
    1.10  //===========================================================================
    1.11  
    1.12 @@ -84,44 +84,34 @@
    1.13     void           *semanticEnv;
    1.14  
    1.15     int32           thisCoresIdx;
    1.16 -   VirtProcr      *masterPr;
    1.17 -   volatile        VirtProcr *volatileMasterPr;
    1.18 +   VirtProcr      *masterVP;
    1.19 +   volatile        VirtProcr *volatilemasterVP;
    1.20     
    1.21 -   volatileMasterPr = animatingPr;
    1.22 -   masterPr         = (VirtProcr*)volatileMasterPr; //used to force re-define after jmp
    1.23 -
    1.24 -      //First animation of each MasterVP will in turn animate this part
    1.25 -      // of setup code.. (VP creator sets up the stack as if this function
    1.26 -      // was called normally, but actually get here by jmp)
    1.27 -      //So, setup values about stack ptr, jmp pt and all that
    1.28 -   //masterPr->nextInstrPt = &&masterLoopStartPt;
    1.29 -
    1.30 -
    1.31 -      //Note, got rid of writing the stack and frame ptr up here, because
    1.32 -      // only one
    1.33 -      // core can ever animate a given MasterVP, so don't need to communicate
    1.34 -      // new frame and stack ptr to the MasterVP storage before a second
    1.35 -      // version of that MasterVP can get animated on a different core.
    1.36 -      //Also got rid of the busy-wait.
    1.37 -
    1.38 +   volatilemasterVP = animatingPr;
    1.39 +   masterVP         = (VirtProcr*)volatilemasterVP; //used to force re-define after jmp
    1.40 +   
    1.41 +      //======================  Measurement  =====================
    1.42 +       TSCountLowHigh endMaster;
    1.43 +       uint64 numCycles;
    1.44 +      //==========================================================
    1.45     
    1.46     //masterLoopStartPt:
    1.47 -   while(1){
    1.48 +   while(1){    //switch to core_loop and back to here is at end of loop
    1.49         
    1.50 -   //============================= MEASUREMENT STUFF ========================
    1.51 -   #ifdef MEAS__TIME_MASTER
    1.52 -      //Total Master time includes one coreloop time -- just assume the core
    1.53 -      // loop time is same for Master as for AppVPs, even though it may be
    1.54 -      // smaller due to higher predictability of the fixed jmp.
    1.55 -   saveLowTimeStampCountInto( masterPr->startMasterTSCLow );
    1.56 -   #endif
    1.57 -   //========================================================================
    1.58 +       //============================= MEASUREMENT STUFF =======================
    1.59 +       #ifdef MEAS__TIME_MASTER
    1.60 +          //Total Master time includes one coreloop time -- just assume the core
    1.61 +          // loop time is same for Master as for AppVPs, even though it may be
    1.62 +          // smaller due to higher predictability of the fixed jmp.
    1.63 +       saveLowTimeStampCountInto( masterVP->startMasterTSCLow );
    1.64 +       #endif
    1.65 +       //=======================================================================
    1.66  
    1.67     masterEnv        = (MasterEnv*)_VMSMasterEnv;
    1.68     
    1.69        //GCC may optimize so doesn't always re-define from frame-storage
    1.70 -   masterPr         = (VirtProcr*)volatileMasterPr;  //just to make sure after jmp
    1.71 -   thisCoresIdx     = masterPr->coreAnimatedBy;
    1.72 +   masterVP         = (VirtProcr*)volatilemasterVP;  //just to make sure after jmp
    1.73 +   thisCoresIdx     = masterVP->coreAnimatedBy;
    1.74     readyToAnimateQ  = masterEnv->readyToAnimateQs[thisCoresIdx];
    1.75     schedSlots       = masterEnv->allSchedSlots[thisCoresIdx];
    1.76  
    1.77 @@ -132,6 +122,7 @@
    1.78  
    1.79        //Poll each slot's Done flag
    1.80     numSlotsFilled = 0;
    1.81 +         Meas_startMasterLoop
    1.82     for( slotIdx = 0; slotIdx < NUM_SCHED_SLOTS; slotIdx++)
    1.83      {
    1.84        currSlot = schedSlots[ slotIdx ];
    1.85 @@ -142,22 +133,9 @@
    1.86           currSlot->needsProcrAssigned = TRUE;
    1.87  
    1.88              //process requests from slave to master
    1.89 -               //====================== MEASUREMENT STUFF ===================
    1.90 -               #ifdef MEAS__TIME_PLUGIN
    1.91 -               int32 startStamp1, endStamp1;
    1.92 -               saveLowTimeStampCountInto( startStamp1 );
    1.93 -               #endif
    1.94 -               //============================================================
    1.95 +               Meas_startReqHdlr
    1.96           (*requestHandler)( currSlot->procrAssignedToSlot, semanticEnv );
    1.97 -               //====================== MEASUREMENT STUFF ===================
    1.98 -               #ifdef MEAS__TIME_PLUGIN
    1.99 -               saveLowTimeStampCountInto( endStamp1 );
   1.100 -               addIntervalToHist( startStamp1, endStamp1,
   1.101 -                                        _VMSMasterEnv->reqHdlrLowTimeHist );
   1.102 -               addIntervalToHist( startStamp1, endStamp1,
   1.103 -                                        _VMSMasterEnv->reqHdlrHighTimeHist );
   1.104 -               #endif
   1.105 -               //============================================================
   1.106 +               Meas_endReqHdlr
   1.107         }
   1.108        if( currSlot->needsProcrAssigned )
   1.109         {    //give slot a new virt procr
   1.110 @@ -174,25 +152,36 @@
   1.111            }
   1.112         }
   1.113      }
   1.114 -
   1.115 +         Meas_endMasterLoop
   1.116     
   1.117     #ifdef USE_WORK_STEALING
   1.118        //If no slots filled, means no more work, look for work to steal.
   1.119     if( numSlotsFilled == 0 )
   1.120 -    { gateProtected_stealWorkInto( currSlot, readyToAnimateQ, masterPr );
   1.121 +    { gateProtected_stealWorkInto( currSlot, readyToAnimateQ, masterVP );
   1.122      }
   1.123     #endif
   1.124  
   1.125     
   1.126 -   #ifdef MEAS__TIME_MASTER
   1.127 -   saveLowTimeStampCountInto( masterPr->endMasterTSCLow );
   1.128 -   #endif
   1.129  
   1.130 -   masterSwitchToCoreLoop(animatingPr);
   1.131 +          //===================  Meas  =======================
   1.132 +          #ifdef MEAS__TIME_MASTER
   1.133 +          saveLowTimeStampCountInto( masterVP->endMasterTSCLow );
   1.134 +          #endif
   1.135 +          #ifdef MEAS__TIME_2011_SYS
   1.136 +         //Take meas here, to get cycles since entered Master
   1.137 +          saveTSCLowHigh(endMaster);
   1.138 +          numCycles = endMaster.longVal - _VMSMasterEnv->startMaster.longVal;
   1.139 +          
   1.140 +          if( numCycles < 200000 ) //sanity check against swap thd out)
   1.141 +           { masterEnv->totalMasterCycles += numCycles;
   1.142 +             masterEnv->numMasterAnimations++;
   1.143 +           }
   1.144 +          #endif
   1.145 +          //==================================================
   1.146 +   masterSwitchToCoreLoop(animatingPr); //"finishes" when switch back to Master
   1.147     flushRegisters();
   1.148     }//MasterLoop
   1.149  
   1.150 -
   1.151   }
   1.152  
   1.153  
   1.154 @@ -202,14 +191,14 @@
   1.155   */
   1.156  void inline
   1.157  stealWorkInto( SchedSlot *currSlot, VMSQueueStruc *readyToAnimateQ,
   1.158 -               VirtProcr *masterPr )
   1.159 +               VirtProcr *masterVP )
   1.160   { 
   1.161     VirtProcr   *stolenPr;
   1.162     int32        coreIdx, i;
   1.163     VMSQueueStruc *currQ;
   1.164  
   1.165     stolenPr = NULL;
   1.166 -   coreIdx = masterPr->coreAnimatedBy;
   1.167 +   coreIdx = masterVP->coreAnimatedBy;
   1.168     for( i = 0; i < NUM_CORES -1; i++ )
   1.169      {
   1.170        if( coreIdx >= NUM_CORES -1 )
   1.171 @@ -306,7 +295,7 @@
   1.172  void inline
   1.173  gateProtected_stealWorkInto( SchedSlot *currSlot,
   1.174                               VMSQueueStruc *myReadyToAnimateQ,
   1.175 -                             VirtProcr *masterPr )
   1.176 +                             VirtProcr *masterVP )
   1.177   {
   1.178     VirtProcr     *stolenPr;
   1.179     int32          coreIdx, i, haveAVictim, gotLock;
   1.180 @@ -319,7 +308,7 @@
   1.181  
   1.182        //see if any other cores have work available to steal
   1.183     haveAVictim = FALSE;
   1.184 -   coreIdx = masterPr->coreAnimatedBy;
   1.185 +   coreIdx = masterVP->coreAnimatedBy;
   1.186     for( i = 0; i < NUM_CORES -1; i++ )
   1.187      {
   1.188        if( coreIdx >= NUM_CORES -1 )