# HG changeset patch # User Some Random Person # Date 1331318796 28800 # Node ID 64737d3deeb4a0df26eb1afdcf40f444a4671cdb # Parent a18539c0bc37cf9d4a1f12b60b1272f67e79e3e1 Cleanup system measurement macros diff -r a18539c0bc37 -r 64737d3deeb4 CoreLoop.c --- a/CoreLoop.c Wed Mar 07 22:53:50 2012 -0800 +++ b/CoreLoop.c Fri Mar 09 10:46:36 2012 -0800 @@ -37,6 +37,7 @@ SchedSlot *currSlot, **schedSlots; cpu_set_t coreMask; //has 1 in bit positions of allowed cores int32 errorCode; + TSCountLowHigh endSusp; //work-stealing struc on stack to prevent false-sharing in cache-line volatile GateStruc gate; @@ -128,6 +129,9 @@ switchToSlv(currVP); //Slave suspend makes core "return" from this call flushRegisters(); + + MEAS__endCoreLoop_for_Sys; + }//CoreLoop } diff -r a18539c0bc37 -r 64737d3deeb4 Defines/VMS_defs__MEAS.h --- a/Defines/VMS_defs__MEAS.h Wed Mar 07 22:53:50 2012 -0800 +++ b/Defines/VMS_defs__MEAS.h Fri Mar 09 10:46:36 2012 -0800 @@ -195,27 +195,6 @@ #define MEAS__Print_Hists_for_Malloc_Meas #endif - -#ifdef MEAS__TURN_ON_SYSTEM_MEAS - #define MEAS__Insert_System_Meas_Fields_into_Slave \ - TSCountLowHigh startSusp; \ - uint64 totalSuspCycles; \ - uint32 numGoodSusp; - - #define MEAS__Insert_System_Meas_Fields_into_MasterEnv \ - TSCountLowHigh startMaster; \ - uint64 totalMasterCycles; \ - uint32 numMasterAnimations; \ - TSCountLowHigh startReqHdlr; \ - uint64 totalPluginCycles; \ - uint32 numPluginAnimations; \ - uint64 cyclesTillStartMasterLoop; \ - TSCountLowHigh endMasterLoop; - -#else - #define MEAS__Insert_System_Meas_Fields_into_Slave - #define MEAS__Insert_System_Meas_Fields_into_MasterEnv -#endif #ifdef MEAS__TURN_ON_PLUGIN_MEAS @@ -256,27 +235,60 @@ #endif - + #ifdef MEAS__TURN_ON_SYSTEM_MEAS - #define MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv + #define MEAS__Insert_System_Meas_Fields_into_Slave \ + TSCountLowHigh startSusp; \ + uint64 totalSuspCycles; \ + uint32 numGoodSusp; - #define MEAS__startMasterLoop \ + #define MEAS__Insert_System_Meas_Fields_into_MasterEnv \ + TSCountLowHigh startMaster; \ + uint64 totalMasterCycles; \ + uint32 numMasterAnimations; \ + TSCountLowHigh startReqHdlr; \ + uint64 totalPluginCycles; \ + uint32 numPluginAnimations; \ + uint64 cyclesTillStartMasterLoop; \ + TSCountLowHigh endMasterLoop; + + #define MEAS__startMasterLoop_forSys \ TSCountLowHigh startStamp1, endStamp1; \ saveTSCLowHigh( endStamp1 ); \ _VMSMasterEnv->cyclesTillStartMasterLoop = \ endStamp1.longVal - masterVP->startSusp.longVal; - #define MEAS__endMasterLoop \ + #define Meas_startReqHdlr_forSys \ + saveTSCLowHigh( startStamp1 ); \ + _VMSMasterEnv->startReqHdlr.longVal = startStamp1.longVal; + + #define MEAS__endMasterLoop_forSys \ saveTSCLowHigh( startStamp1 ); \ _VMSMasterEnv->endMasterLoop.longVal = startStamp1.longVal; + /*A TSC is stored in VP first thing inside wrapper-lib + * Now, measures cycles from there to here + * Master and Plugin will add this value to other trace-seg measures + */ + #define MEAS__capture_end_susp_in_CoreLoop_forSys\ + saveTSCLowHigh(endSusp); \ + numCycles = endSusp.longVal - currVP->startSusp.longVal; \ + /*sanity check (400K is about 20K iters)*/ \ + if( numCycles < 400000 ) \ + { currVP->totalSuspCycles += numCycles; \ + currVP->numGoodSusp++; \ + } \ + /*recorded every time, but only read if currVP == MasterVP*/ \ + _VMSMasterEnv->startMaster.longVal = endSusp.longVal; + #else - #define MEAS__Insert_System_Meas_Fields_into_MasterEnv + #define MEAS__Insert_System_Meas_Fields_into_Slave + #define MEAS__Insert_System_Meas_Fields_into_MasterEnv #define MEAS__Make_Meas_Hists_for_System_Meas #define MEAS__startMasterLoop_forSys + #define MEAS__startReqHdlr_forSys #define MEAS__endMasterLoop_forSys - #define MEAS__startReqHdlr_forSys - #define MEAS__endReqHdlr_forSys + #define MEAS__capture_end_susp_in_CoreLoop_forSys #define MEAS__Print_Hists_for_System_Meas #endif diff -r a18539c0bc37 -r 64737d3deeb4 VMS.h --- a/VMS.h Wed Mar 07 22:53:50 2012 -0800 +++ b/VMS.h Fri Mar 09 10:46:36 2012 -0800 @@ -219,6 +219,8 @@ volatile MasterEnv *_VMSMasterEnv __align_to_cacheline__; +pthread_mutex_t suspendLock = PTHREAD_MUTEX_INITIALIZER; +pthread_cond_t suspend_cond = PTHREAD_COND_INITIALIZER; //========================= Function Prototypes =========================== diff -r a18539c0bc37 -r 64737d3deeb4 VMS__startup_and_shutdown.c --- a/VMS__startup_and_shutdown.c Wed Mar 07 22:53:50 2012 -0800 +++ b/VMS__startup_and_shutdown.c Fri Mar 09 10:46:36 2012 -0800 @@ -35,8 +35,6 @@ void endOSThreadFn( void *initData, SlaveVP *animatingSlv ); -pthread_mutex_t suspendLock = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t suspend_cond = PTHREAD_COND_INITIALIZER; //=========================================================================== @@ -80,23 +78,127 @@ #endif } - VMS__start_VMS_running( ); +/*This structure holds all the information VMS needs to manage a program. VMS + * stores information about what percent of CPU time the program is getting, what + * language it uses, the request handlers to call for its slaves, and so on. + */ +typedef struct + { void *semEnv; + RequestHdlrFnPtr requestHandler; + SlaveAssignerFnPtr slaveAssigner; + int32 numSlavesLive; + void *resultToReturn; + + TopLevelFnPtr seedFnPtr; + void *dataForSeed; + bool32 executionIsComplete; + pthread_mutex_t doneLock; + pthread_cond_t doneCond; + } +VMSProcess; + + +void +VMS__start_VMS_running() + { + create_masterEnv(); - VMSProcessID matrixMultProcessID; + #ifdef DEBUG__TURN_ON_SEQUENTIAL_MODE + /*Nothing else to create for sequential mode*/ + #else + create_the_coreLoop_OS_threads(); + #endif + } + +/*A pointer to the startup-function for the language is given as the last + * argument to the call. Use this to initialize a program in the language. + * This creates a data structure that encapsulates the bookkeeping info + * VMS uses to track and schedule a program run. + */ +VMSProcess * +VMS__spawn_program_on_data_in_Lang( TopLevelFnPtr prog_seed_fn, void *data, + LangInitFnPtr langInitFnPtr ) + { VMSProcess *newProcess; + newProcess = malloc( sizeof(VMSProcess) ); + newProcess->doneLock = PTHREAD_MUTEX_INITIALIZER; + newProcess->doneCond = PTHREAD_COND_INITIALIZER; + newProcess->executionIsComplete = FALSE; + newProcess->numSlavesLive = 0; - matrixMultProcessID = + newProcess->dataForSeed = data; + newProcess->seedFnPtr = prog_seed_fn; + + /*The language's spawn-process function fills in the plugin function-ptrs in + * the VMSProcess struct, gives the struct to VMS, which then makes and + * queues the seed SlaveVP, which starts processors made from the code being + * animated. + */ + (*langInitFnPtr)( newProcess ); + + return newProcess; + } + +/*When all SlaveVPs owned by the program-run associated to the process have + * dissipated, then return from this call. There is no language to cleanup, + * and VMS does not shutdown.. but the process bookkeeping structure, + * which is used by VMS to track and schedule the program, is freed. + *The VMSProcess structure is kept until this call collects the results from it, + * then freed. If the process is not done yet when VMS gets this + * call, then this call waits.. the challenge here is that this call comes from + * a live OS thread that's outside VMS.. so, inside here, it waits on a + * condition.. then it's a VMS thread that signals this to wake up.. + *First checks whether the process is done, if yes, calls the clean-up fn then + * returns the result extracted from the VMSProcess struct. + *If process not done yet, then performs a wait (in a loop to be sure the + * wakeup is not spurious, which can happen). VMS registers the wait, and upon + * the process ending (last SlaveVP owned by it dissipates), then VMS signals + * this to wakeup. This then calls the cleanup fn and returns the result. + */ +void * +VMS__give_results_when_done_for( VMSProcess *process ) + { void *result; + + pthread_mutex_lock( process->doneLock ); + while( !(process->executionIsComplete) ) + { + pthread_cond_wait( process->doneCond, + process->doneLock ); + } + pthread_mutex_unlock( process->doneLock ); + + result = process->resultToReturn; + + VMS_int__cleanup_process_after_done( process ); + free( process ); //was malloc'd above, so free it here + + return result; + } + +/*Turns off the VMS system, and frees all data associated with it. Does this + * by creating shutdown SlaveVPs and inserting them into scheduling slots. + * Will probably have to wake up sleeping cores as part of this -- the fn that + * inserts the new SlaveVPs should handle the wakeup.. + */ +void +VMS__shutdown() + { + for( cores ) + { slave = VMS_int__create_new_SlaveVP( shutdownFN, NULL ); + VMS_int__insert_slave_onto_core( SlaveVP *slave, coreNum ); + } + } + +/* VMS__start_VMS_running(); + + VMSProcess matrixMultProcess; + + matrixMultProcess = VMS__spawn_program_on_data_in_Lang( &prog_seed_fn, data, Vthread_lang ); - resMatrix = VMS__give_results_when_done_for( matrixMultProcessID ); - -// Vthread__give_results_when_done_for( matrixMultProcessID ); - - //VMS__shutdown_lang( Vthread ); - - //Vthread__shutdown_lang(); + resMatrix = VMS__give_results_when_done_for( matrixMultProcess ); VMS__shutdown(); - + */ void create_masterEnv()