# HG changeset patch # User engelhardt@cray1 # Date 1311687384 -7200 # Node ID 3bc3b89630c79e72fb5feb7286e6eb652f585780 # Parent 388af85fe19097c985740fec813f5d6e9d7abd8e perf counters diff -r 388af85fe190 -r 3bc3b89630c7 CoreLoop.c --- a/CoreLoop.c Tue Jul 26 15:35:57 2011 +0200 +++ b/CoreLoop.c Tue Jul 26 15:36:24 2011 +0200 @@ -71,7 +71,7 @@ CPU_ZERO(&coreMask); CPU_SET(coreLoopThdParams->coreNum,&coreMask); //coreMask = 1L << coreLoopThdParams->coreNum; - + pthread_t selfThd = pthread_self(); errorCode = pthread_setaffinity_np( selfThd, sizeof(coreMask), &coreMask); @@ -151,8 +151,38 @@ } - + #ifdef MEAS__PERF_COUNTER + //start work + int lastRecordIdx = currPr->counter_history_array_info->numInArray -1; + CounterRecord* lastRecord = currPr->counter_history[lastRecordIdx]; + lastRecord->work_core = thisCoresIdx; + int cycles_fd = _VMSMasterEnv->cycles_counter_fd[thisCoresIdx]; + int instrs_fd = _VMSMasterEnv->instrs_counter_fd[thisCoresIdx]; + int nread; + + nread = read(cycles_fd,&(lastRecord->start_work_cycles),sizeof(lastRecord->start_work_cycles)); + if(nread<0){ + lastRecord->start_work_cycles = 0; + } + + nread = read(instrs_fd,&(lastRecord->start_work_instrs),sizeof(lastRecord->start_work_instrs)); + if(nread<0){ + lastRecord->start_work_instrs = 0; + } + #endif switchToVP(currPr); //The VPs return in here + #ifdef MEAS__PERF_COUNTER + //end work + nread = read(cycles_fd,&(lastRecord->start_work_cycles),sizeof(lastRecord->start_work_cycles)); + if(nread<0){ + lastRecord->start_work_cycles = 0; + } + + nread = read(instrs_fd,&(lastRecord->start_work_instrs),sizeof(lastRecord->start_work_instrs)); + if(nread<0){ + lastRecord->start_work_instrs = 0; + } + #endif flushRegisters(); }//CoreLoop } diff -r 388af85fe190 -r 3bc3b89630c7 MasterLoop.c --- a/MasterLoop.c Tue Jul 26 15:35:57 2011 +0200 +++ b/MasterLoop.c Tue Jul 26 15:36:24 2011 +0200 @@ -147,6 +147,32 @@ int32 startStamp1, endStamp1; saveLowTimeStampCountInto( startStamp1 ); #endif + #ifdef MEAS__PERF_COUNTER + int lastRecordIdx = currSlot->procrAssignedToSlot->counter_history_array_info->numInArray -1; + CounterRecord* lastRecord = currSlot->procrAssignedToSlot->counter_history[lastRecordIdx]; + lastRecord->req_core = thisCoresIdx; + int cycles_fd = masterEnv->cycles_counter_fd[thisCoresIdx]; + int instrs_fd = masterEnv->instrs_counter_fd[thisCoresIdx]; + int nread; + + nread = read(cycles_fd,&(lastRecord->req_cycles),sizeof(lastRecord->req_cycles)); + if(nread<0){ + lastRecord->req_cycles = 0; + } + + nread = read(instrs_fd,&(lastRecord->req_instrs),sizeof(lastRecord->req_instrs)); + if(nread<0){ + lastRecord->req_instrs = 0; + } + //End of task, start of next task + //print counters from last run + print_record(lastRecord); + //create new entry in record array here + CounterRecord* newRecord = VMS__malloc(sizeof(CounterRecord)); + newRecord->req_core = thisCoresIdx; + addToDynArray( (void*) newRecord, currSlot->procrAssignedToSlot->counter_history_array_info); + lastRecord = newRecord; + #endif //============================================================ (*requestHandler)( currSlot->procrAssignedToSlot, semanticEnv ); //====================== MEASUREMENT STUFF =================== @@ -157,13 +183,59 @@ addIntervalToHist( startStamp1, endStamp1, _VMSMasterEnv->reqHdlrHighTimeHist ); #endif + #ifdef MEAS__PERF_COUNTER + + nread = read(cycles_fd,&(lastRecord->sc_done_cycles),sizeof(lastRecord->sc_done_cycles)); + if(nread<0){ + lastRecord->sc_done_cycles = 0; + } + nread = read(instrs_fd,&(lastRecord->sc_done_instrs),sizeof(lastRecord->sc_done_instrs)); + if(nread<0){ + lastRecord->sc_done_instrs = 0; + } + #endif //============================================================ } if( currSlot->needsProcrAssigned ) { //give slot a new virt procr + #ifdef MEAS__PERF_COUNTER + //start assigner + int cycles_fd = masterEnv->cycles_counter_fd[thisCoresIdx]; + int instrs_fd = masterEnv->instrs_counter_fd[thisCoresIdx]; + uint64 tmp_cycles; + uint64 tmp_instrs; + int nread=0; + + nread = read(cycles_fd,&tmp_cycles,sizeof(uint64)); + if(nread<0){ + tmp_cycles = 0; + } + + nread = read(instrs_fd,&tmp_instrs,sizeof(uint64)); + if(nread<0){ + tmp_instrs = 0; + } + #endif schedVirtPr = (*slaveScheduler)( semanticEnv, thisCoresIdx ); - + #ifdef MEAS__PERF_COUNTER + //end assigner + int lastRecordIdx = currSlot->procrAssignedToSlot->counter_history_array_info->numInArray -1; + CounterRecord* lastRecord = currSlot->procrAssignedToSlot->counter_history[lastRecordIdx]; + lastRecord->assigning_core = thisCoresIdx; + lastRecord->start_assign_cycles = tmp_cycles; + lastRecord->start_assign_instrs = tmp_instrs; + + nread = read(cycles_fd,&(lastRecord->end_assign_cycles),sizeof(lastRecord->end_assign_cycles)); + if(nread<0){ + lastRecord->end_assign_cycles = 0; + } + + nread = read(instrs_fd,&(lastRecord->end_assign_instrs),sizeof(lastRecord->end_assign_instrs)); + if(nread<0){ + lastRecord->end_assign_instrs = 0; + } + #endif if( schedVirtPr != NULL ) { currSlot->procrAssignedToSlot = schedVirtPr; schedVirtPr->schedSlot = currSlot; diff -r 388af85fe190 -r 3bc3b89630c7 ProcrContext.c --- a/ProcrContext.c Tue Jul 26 15:35:57 2011 +0200 +++ b/ProcrContext.c Tue Jul 26 15:36:24 2011 +0200 @@ -59,6 +59,7 @@ //newPr->createPtInSecs = timeStamp.tv_sec +(timeStamp.tv_usec/1000000.0) - // _VMSMasterEnv->createPtInSecs; #endif + //======================================================================== return newPr; diff -r 388af85fe190 -r 3bc3b89630c7 VMS.c --- a/VMS.c Tue Jul 26 15:35:57 2011 +0200 +++ b/VMS.c Tue Jul 26 15:36:24 2011 +0200 @@ -16,6 +16,9 @@ #include "Queue_impl/BlockingQueue.h" #include "Histogram/Histogram.h" +#include +#include +#include #define thdAttrs NULL @@ -177,6 +180,43 @@ #endif MakeTheMeasHists(); + + #ifdef MEAS__PERF_COUNTER + printf("Creating HW counters..."); + struct perf_event_attr hw_event; + hw_event.type = PERF_TYPE_HARDWARE; + hw_event.size = sizeof(struct perf_event_attr); + hw_event.disabled = 1; + hw_event.inherit = 1; /* children inherit it */ + hw_event.pinned = 1; /* must always be on PMU */ + hw_event.exclusive = 0; /* only group on PMU */ + hw_event.exclude_user = 0; /* don't count user */ + hw_event.exclude_kernel = 1; /* ditto kernel */ + hw_event.exclude_hv = 1; /* ditto hypervisor */ + hw_event.exclude_idle = 0; /* don't count when idle */ + hw_event.mmap = 0; /* include mmap data */ + hw_event.comm = 0; /* include comm data */ + + for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ ) + { + hw_event.config = PERF_COUNT_HW_CPU_CYCLES; //cycles + _VMSMasterEnv->cycles_counter_fd[coreIdx] = syscall(__NR_perf_event_open, &hw_event, + 0,//pid_t pid, + coreIdx,//int cpu, + -1,//int group_fd, + 0//unsigned long flags + ); + hw_event.config = PERF_COUNT_HW_INSTRUCTIONS; //instrs + _VMSMasterEnv->instrs_counter_fd[coreIdx] = syscall(__NR_perf_event_open, &hw_event, + 0,//pid_t pid, + coreIdx,//int cpu, + -1,//int group_fd, + 0//unsigned long flags + ); + } + prctl(PR_TASK_PERF_EVENTS_ENABLE); + #endif + //======================================================================== } diff -r 388af85fe190 -r 3bc3b89630c7 VMS.h --- a/VMS.h Tue Jul 26 15:35:57 2011 +0200 +++ b/VMS.h Tue Jul 26 15:36:24 2011 +0200 @@ -16,6 +16,7 @@ #include "DynArray/DynArray.h" #include "Hash_impl/PrivateHash.h" #include "vmalloc.h" +#include "Counters/Counters.h" #include #include @@ -58,7 +59,7 @@ //when MEAS__TIME_STAMP_SUSP is defined, causes code to be inserted and // compiled-in that saves the low part of the time stamp count just before - // suspending a processor and just after resuming that processorsrc/VPThread_lib/VMS/VMS.h:322: warning: previous declaration of ‘VMS__create_procr’ was here. It is + // suspending a processor and just after resuming that processor. It is // saved into a field added to VirtProcr. Have to sanity-check for // rollover of low portion into high portion. //#define MEAS__TIME_STAMP_SUSP @@ -72,11 +73,12 @@ // different cores. #define NUM_TSC_ROUND_TRIPS 10 +#define MEAS__PERF_COUNTERS //========================= Hardware related Constants ===================== //This value is the number of hardware threads in the shared memory // machine -#define NUM_CORES 8 +#define NUM_CORES 2 // tradeoff amortizing master fixed overhead vs imbalance potential // when work-stealing, can make bigger, at risk of losing cache affinity @@ -202,6 +204,10 @@ unsigned int startMasterTSCLow;USE_GNU unsigned int endMasterTSCLow; #endif + #ifdef MEAS__PERF_COUNTERS // + CounterRecord** counter_history; + PrivDynArrayInfo* counter_history_array_info; + #endif //======================================== float64 createPtInSecs; //have space but don't use on some configs @@ -258,6 +264,10 @@ Histogram *masterLockLowTimeHist; Histogram *masterLockHighTimeHist; #endif + #ifdef MEAS__PERF_COUNTERS + int cycles_counter_fd[NUM_CORES]; + int instrs_counter_fd[NUM_CORES]; + #endif } MasterEnv;