changeset 193:20358f56e498 perf_counters

fix coreloop recording bug and eliminate race condition on measurement-collecting list
author Nina Engelhardt <nengel@mailbox.tu-berlin.de>
date Thu, 09 Feb 2012 15:40:11 +0100
parents fe5ad5726e36
children 0072a555f59c
files CoreLoop.c MasterLoop.c ProcrContext.c VMS.c VMS.h
diffstat 5 files changed, 42 insertions(+), 21 deletions(-) [+]
line diff
     1.1 --- a/CoreLoop.c	Fri Feb 03 17:32:48 2012 +0100
     1.2 +++ b/CoreLoop.c	Thu Feb 09 15:40:11 2012 +0100
     1.3 @@ -79,6 +79,7 @@
     1.4     if(errorCode){ printf("\nset affinity failure\n"); exit(0); }
     1.5  #ifdef MEAS__PERF_COUNTERS
     1.6     CounterHandler counterHandler = _VMSMasterEnv->counterHandler;
     1.7 +   VirtProcr      *lastVPBeforeMaster = NULL;
     1.8  #endif
     1.9     
    1.10     //Save the return address in the SwitchVP function
    1.11 @@ -91,7 +92,7 @@
    1.12         if(currPr){
    1.13                 uint64 cycles,instrs;
    1.14                 saveCyclesAndInstrs(thisCoresIdx,cycles, instrs);
    1.15 -               (*counterHandler)(CoreLoop_afterWork,currPr,cycles,instrs);
    1.16 +               (*counterHandler)(Work_end,currPr->procrID,currPr->numTimesScheduled,currPr,cycles,instrs);
    1.17         }
    1.18     #endif
    1.19        //Get virtual processor from queue
    1.20 @@ -119,7 +120,11 @@
    1.21     currPr = (VirtProcr *) readVMSQ( readyToAnimateQ );
    1.22     #endif
    1.23  
    1.24 -   if( currPr != NULL ) _VMSMasterEnv->numMasterInARow[thisCoresIdx] = 0;
    1.25 +   if( currPr != NULL ){ 
    1.26 +       _VMSMasterEnv->numMasterInARow[thisCoresIdx] = 0; 
    1.27 +       //save last VP here
    1.28 +       lastVPBeforeMaster = currPr;
    1.29 +   }
    1.30     else
    1.31      {
    1.32        //============================= MEASUREMENT STUFF =====================
    1.33 @@ -127,8 +132,17 @@
    1.34        int32 startStamp, endStamp;
    1.35        saveLowTimeStampCountInto( startStamp );
    1.36        #endif
    1.37 +      #ifdef MEAS__PERF_COUNTERS
    1.38 +      if(lastVPBeforeMaster){
    1.39 +        uint64 cycles,instrs;
    1.40 +        saveCyclesAndInstrs(thisCoresIdx,cycles, instrs);
    1.41 +        (*counterHandler)(AppResponderInvocation_start,lastVPBeforeMaster->procrID,lastVPBeforeMaster->numTimesScheduled,lastVPBeforeMaster,cycles,instrs);
    1.42 +        lastVPBeforeMaster = NULL;
    1.43 +      }
    1.44 +      #endif
    1.45        //=====================================================================
    1.46        int tries = 0; int gotLock = 0;
    1.47 +      //TODO: startinvocation time here
    1.48        while( currPr == NULL ) //if queue was empty, enter get masterLock loop
    1.49         {    //queue was empty, so get master lock
    1.50  
    1.51 @@ -165,7 +179,7 @@
    1.52     if(currPr){
    1.53          uint64 cycles,instrs;
    1.54          saveCyclesAndInstrs(thisCoresIdx,cycles, instrs);
    1.55 -        (*counterHandler)(CoreLoop_beforeWork,currPr,cycles,instrs);
    1.56 +        (*counterHandler)(Work_start,currPr->procrID,currPr->numTimesScheduled,currPr,cycles,instrs);
    1.57     }
    1.58     #endif
    1.59     switchToVP(currPr); //The VPs return in here
     2.1 --- a/MasterLoop.c	Fri Feb 03 17:32:48 2012 +0100
     2.2 +++ b/MasterLoop.c	Thu Feb 09 15:40:11 2012 +0100
     2.3 @@ -133,7 +133,7 @@
     2.4     #ifdef MEAS__PERF_COUNTERS
     2.5     CounterHandler counterHandler = masterEnv->counterHandler;             
     2.6     #endif
     2.7 -
     2.8 +        //
     2.9        //Poll each slot's Done flag
    2.10     numSlotsFilled = 0;
    2.11     for( slotIdx = 0; slotIdx < NUM_SCHED_SLOTS; slotIdx++)
    2.12 @@ -152,10 +152,11 @@
    2.13                 saveLowTimeStampCountInto( startStamp1 );
    2.14                 #endif
    2.15                 #ifdef MEAS__PERF_COUNTERS
    2.16 -               VirtProcr p_sav = *(currSlot->procrAssignedToSlot);
    2.17 +               int vpid = currSlot->procrAssignedToSlot->procrID;
    2.18 +               int task = currSlot->procrAssignedToSlot->numTimesScheduled;
    2.19                 uint64 cycles, instrs;
    2.20                 saveCyclesAndInstrs(thisCoresIdx,cycles, instrs);
    2.21 -               (*counterHandler)(MasterLoop_beforeReqHdlr,&p_sav,cycles,instrs);
    2.22 +               (*counterHandler)(AppResponder_start,vpid,task,currSlot->procrAssignedToSlot,cycles,instrs);
    2.23                 #endif
    2.24                 //============================================================
    2.25           (*requestHandler)( currSlot->procrAssignedToSlot, semanticEnv );
    2.26 @@ -171,7 +172,7 @@
    2.27                 //done with constraints check
    2.28                 uint64 cycles2,instrs2;
    2.29                 saveCyclesAndInstrs(thisCoresIdx,cycles2, instrs2);
    2.30 -               (*counterHandler)(MasterLoop_afterReqHdlr,&p_sav,cycles2,instrs2);
    2.31 +               (*counterHandler)(AppResponder_end,vpid,task,currSlot->procrAssignedToSlot,cycles2,instrs2);
    2.32                 #endif
    2.33                 //============================================================
    2.34         }
    2.35 @@ -200,8 +201,8 @@
    2.36                 uint64 cycles;
    2.37                 uint64 instrs;
    2.38                 saveCyclesAndInstrs(thisCoresIdx,cycles,instrs);
    2.39 -               (*counterHandler)(MasterLoop_beforeAssign,schedVirtPr,tmp_cycles,tmp_instrs);
    2.40 -               (*counterHandler)(MasterLoop_afterAssign,schedVirtPr,cycles,instrs);
    2.41 +               (*counterHandler)(Assigner_start,schedVirtPr->procrID,schedVirtPr->numTimesScheduled,schedVirtPr,tmp_cycles,tmp_instrs);
    2.42 +               (*counterHandler)(Assigner_end,schedVirtPr->procrID,schedVirtPr->numTimesScheduled,schedVirtPr,cycles,instrs);
    2.43                 #endif
    2.44            }
    2.45         }
     3.1 --- a/ProcrContext.c	Fri Feb 03 17:32:48 2012 +0100
     3.2 +++ b/ProcrContext.c	Thu Feb 09 15:40:11 2012 +0100
     3.3 @@ -27,7 +27,8 @@
     3.4     newPr->initialData  = initialData;
     3.5     newPr->requests     = NULL;
     3.6     newPr->schedSlot    = NULL;
     3.7 -
     3.8 +   newPr->isMasterVP = FALSE;
     3.9 +   newPr->isShutdownVP = FALSE;
    3.10     /*
    3.11      * Hardware dependent part           
    3.12      */
     4.1 --- a/VMS.c	Fri Feb 03 17:32:48 2012 +0100
     4.2 +++ b/VMS.c	Thu Feb 09 15:40:11 2012 +0100
     4.3 @@ -149,6 +149,7 @@
     4.4           //Q: should give masterVP core-specific info as its init data?
     4.5        masterVPs[ coreIdx ] = VMS__create_procr( (VirtProcrFnPtr)&masterLoop, (void*)masterEnv );
     4.6        masterVPs[ coreIdx ]->coreAnimatedBy = coreIdx;
     4.7 +      masterVPs[ coreIdx ]->isMasterVP = TRUE;
     4.8        allSchedSlots[ coreIdx ] = create_sched_slots(); //makes for one core
     4.9        _VMSMasterEnv->numMasterInARow[ coreIdx ] = 0;
    4.10        _VMSMasterEnv->workStealingGates[ coreIdx ] = NULL;
    4.11 @@ -440,7 +441,7 @@
    4.12          //start work
    4.13     uint64 cycles,instrs;
    4.14     saveCyclesAndInstrs(animatingPr->coreAnimatedBy,cycles, instrs);
    4.15 -   (*(_VMSMasterEnv->counterHandler))(Procr_suspend,animatingPr,cycles,instrs); 
    4.16 +   (*(_VMSMasterEnv->counterHandler))(HwResponderInvocation_start,animatingPr->procrID,animatingPr->numTimesScheduled,animatingPr,cycles,instrs); 
    4.17     #endif     
    4.18     //=======================================================================
    4.19  
    4.20 @@ -730,6 +731,7 @@
    4.21     for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ )
    4.22      {    //Note, this is running in the master
    4.23        shutDownPr = VMS__create_procr( &endOSThreadFn, NULL );
    4.24 +      shutDownPr->isShutdownVP = TRUE;
    4.25        writeVMSQ( shutDownPr, _VMSMasterEnv->readyToAnimateQs[coreIdx] );
    4.26      }
    4.27  #ifdef MEAS__PERF_COUNTERS 
     5.1 --- a/VMS.h	Fri Feb 03 17:32:48 2012 +0100
     5.2 +++ b/VMS.h	Thu Feb 09 15:40:11 2012 +0100
     5.3 @@ -86,7 +86,7 @@
     5.4  
     5.5     // tradeoff amortizing master fixed overhead vs imbalance potential
     5.6     // when work-stealing, can make bigger, at risk of losing cache affinity
     5.7 -#define NUM_SCHED_SLOTS  1
     5.8 +#define NUM_SCHED_SLOTS  5
     5.9  
    5.10  #define MIN_WORK_UNIT_CYCLES 20000
    5.11  
    5.12 @@ -129,7 +129,7 @@
    5.13  typedef void  (*VirtProcrFnPtr)  ( void *, VirtProcr * ); //initData, animPr
    5.14  typedef void    VirtProcrFn      ( void *, VirtProcr * ); //initData, animPr
    5.15  typedef void  (*ResumePrFnPtr)   ( VirtProcr *, void * );
    5.16 -typedef void (*CounterHandler) (int,VirtProcr*,uint64,uint64);
    5.17 +typedef void (*CounterHandler) (int,int,int,VirtProcr*,uint64,uint64);
    5.18  
    5.19  //============= Requests ===========
    5.20  //
    5.21 @@ -212,6 +212,8 @@
    5.22     //CounterRecord** counter_history;
    5.23     //PrivDynArrayInfo* counter_history_array_info;
    5.24     #endif
    5.25 +   int isMasterVP;
    5.26 +   int isShutdownVP;
    5.27        //========================================
    5.28     
    5.29     float64      createPtInSecs;  //have space but don't use on some configs
    5.30 @@ -443,14 +445,15 @@
    5.31  } while (0) 
    5.32  
    5.33  enum eventType {
    5.34 -    MasterLoop_beforeReqHdlr = 1,
    5.35 -    MasterLoop_afterReqHdlr,
    5.36 -    MasterLoop_beforeAssign,
    5.37 -    MasterLoop_afterAssign,
    5.38 -    CoreLoop_afterWork,
    5.39 -    CoreLoop_beforeWork,
    5.40 -    Procr_suspend,
    5.41 -    MasterLoop_beforeNextAssign
    5.42 +    DebugEvt = 0,
    5.43 +    AppResponderInvocation_start,
    5.44 +    AppResponder_start,
    5.45 +    AppResponder_end,
    5.46 +    Assigner_start,
    5.47 +    Assigner_end,
    5.48 +    Work_start,
    5.49 +    Work_end,
    5.50 +    HwResponderInvocation_start
    5.51  };
    5.52  
    5.53  #define getReturnAddressBeforeLibraryCall(vp_ptr, res_ptr) do{     \