Me@42: /* Me@42: * Copyright 2009 OpenSourceStewardshipFoundation.org Me@42: * Licensed under GNU General Public License version 2 Me@42: * Me@42: * Author: seanhalle@yahoo.com Me@42: * Me@42: */ Me@42: Me@42: #ifndef _VMS_H Me@42: #define _VMS_H msach@76: #define _GNU_SOURCE Me@42: Me@42: #include "VMS_primitive_data_types.h" msach@201: #include "C_Libraries/Queue_impl/PrivateQueue.h" msach@201: #include "C_Libraries/Histogram/Histogram.h" msach@201: #include "C_Libraries/DynArray/DynArray.h" msach@201: #include "C_Libraries/Hash_impl/PrivateHash.h" Me@50: #include "vmalloc.h" Me@50: Me@42: #include Me@50: #include Me@42: msach@169: //============= #defines =========== Me@55: // msach@169: #include "VMS_defs.h" Me@42: Me@42: Me@50: Me@50: //=========================================================================== Me@50: typedef unsigned long long TSCount; msach@169: typedef union msach@169: { uint32 lowHigh[2]; msach@169: uint64 longVal; msach@169: } msach@169: TSCountLowHigh; Me@50: Me@50: typedef struct _SchedSlot SchedSlot; Me@50: typedef struct _VMSReqst VMSReqst; Me@50: typedef struct _VirtProcr VirtProcr; Me@50: typedef struct _IntervalProbe IntervalProbe; Me@55: typedef struct _GateStruc GateStruc; Me@55: Me@42: Me@42: typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx Me@42: typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv Me@42: typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr Me@42: typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr Me@50: typedef void (*ResumePrFnPtr) ( VirtProcr *, void * ); Me@50: Me@50: Me@50: //============= Requests =========== Me@50: // Me@50: Me@50: enum VMSReqstType //avoid starting enums at 0, for debug reasons Me@50: { Me@50: semantic = 1, Me@50: createReq, Me@50: dissipate, Me@50: VMSSemantic //goes with VMSSemReqst below Me@50: }; Me@50: Me@50: struct _VMSReqst Me@50: { Me@50: enum VMSReqstType reqType;//used for dissipate and in future for IO requests Me@50: void *semReqData; Me@50: Me@50: VMSReqst *nextReqst; Me@50: }; Me@50: //VMSReqst Me@50: Me@50: enum VMSSemReqstType //These are equivalent to semantic requests, but for Me@50: { // VMS's services available directly to app, like OS Me@50: createProbe = 1, // and probe services -- like a VMS-wide built-in lang Me@50: openFile, Me@50: otherIO Me@50: }; Me@42: Me@42: typedef struct Me@50: { enum VMSSemReqstType reqType; Me@50: VirtProcr *requestingPr; Me@50: char *nameStr; //for create probe Me@42: } Me@50: VMSSemReq; Me@42: Me@42: Me@50: //==================== Core data structures =================== Me@50: Me@42: struct _SchedSlot Me@42: { Me@42: int workIsDone; Me@42: int needsProcrAssigned; Me@42: VirtProcr *procrAssignedToSlot; Me@42: }; Me@42: //SchedSlot Me@42: Me@62: /*WARNING: re-arranging this data structure could cause VP switching Me@64: * assembly code to fail -- hard-codes offsets of fields Me@62: */ Me@42: struct _VirtProcr Me@42: { int procrID; //for debugging -- count up each time create Me@42: int coreAnimatedBy; Me@42: void *startOfStack; Me@42: void *stackPtr; Me@42: void *framePtr; Me@42: void *nextInstrPt; Me@42: Me@42: void *coreLoopStartPt; //allows proto-runtime to be linked later Me@42: void *coreLoopFramePtr; //restore before jmp back to core loop Me@42: void *coreLoopStackPtr; //restore before jmp back to core loop Me@42: Me@42: void *initialData; Me@42: Me@42: SchedSlot *schedSlot; Me@42: VMSReqst *requests; Me@42: msach@76: void *semanticData; //this livesUSE_GNU here for the life of VP Me@53: void *dataRetFromReq;//values returned from plugin to VP go here Me@42: Me@50: //=========== MEASUREMENT STUFF ========== msach@169: #ifdef MEAS__TIME_STAMP_SUSP msach@169: uint32 preSuspTSCLow; msach@169: uint32 postSuspTSCLow; msach@169: #endif msach@169: #ifdef MEAS__TIME_MASTER /* in VirtProcr because multiple masterVPs*/ msach@169: uint32 startMasterTSCLow;USE_GNU msach@169: uint32 endMasterTSCLow; msach@169: #endif msach@169: #ifdef MEAS__TIME_2011_SYS msach@169: TSCountLowHigh startSusp; msach@169: uint64 totalSuspCycles; msach@169: uint32 numGoodSusp; msach@169: #endif Me@65: //======================================== Me@50: Me@50: float64 createPtInSecs; //have space but don't use on some configs Me@42: }; Me@42: //VirtProcr Me@42: Me@42: Me@62: /*WARNING: re-arranging this data structure could cause VP-switching Me@62: * assembly code to fail -- hard-codes offsets of fields Me@62: * (because -O3 messes with things otherwise) Me@62: */ Me@42: typedef struct Me@42: { msach@173: union{ //added padding, because this variable is written a lot by different cores msach@173: //thus invalidating a lot of the stucture msach@173: volatile int32 masterLock; msach@173: char padding[256]; msach@173: } masterLockUnion; Me@42: SlaveScheduler slaveScheduler; Me@42: RequestHandler requestHandler; Me@42: Me@42: SchedSlot ***allSchedSlots; Me@55: VMSQueueStruc **readyToAnimateQs; Me@42: VirtProcr **masterVPs; Me@42: Me@42: void *semanticEnv; Me@42: void *OSEventStruc; //for future, when add I/O to BLIS msach@101: MallocArrays *freeLists; Me@50: int32 amtOfOutstandingMem; //total currently allocated Me@42: msach@73: void *coreLoopReturnPt;//addr to jump to to re-enter coreLoop Me@42: Me@50: int32 setupComplete; msach@173: //int32 numMasterInARow[NUM_CORES];//detect back-to-back masterVP Me@59: GateStruc *workStealingGates[ NUM_CORES ]; //concurrent work-steal Me@55: int32 workStealingLock; Me@55: Me@50: int32 numProcrsCreated; //gives ordering to processor creation Me@50: Me@50: //=========== MEASUREMENT STUFF ============= msach@169: IntervalProbe **intervalProbes; msach@169: PrivDynArrayInfo *dynIntervalProbesInfo; msach@169: HashTable *probeNameHashTbl; msach@169: int32 masterCreateProbeID; msach@169: float64 createPtInSecs; msach@169: Histogram **measHists; msach@169: PrivDynArrayInfo *measHistsInfo; msach@169: #ifdef MEAS__TIME_PLUGIN msach@169: Histogram *reqHdlrLowTimeHist; msach@169: Histogram *reqHdlrHighTimeHist; msach@169: #endif msach@169: #ifdef MEAS__TIME_MALLOC msach@169: Histogram *mallocTimeHist; msach@169: Histogram *freeTimeHist; msach@169: #endif msach@169: #ifdef MEAS__TIME_MASTER_LOCK msach@169: Histogram *masterLockLowTimeHist; msach@169: Histogram *masterLockHighTimeHist; msach@169: #endif msach@169: #ifdef MEAS__TIME_2011_SYS msach@169: TSCountLowHigh startMaster; msach@169: uint64 totalMasterCycles; msach@169: uint32 numMasterAnimations; msach@169: TSCountLowHigh startReqHdlr; msach@169: uint64 totalPluginCycles; msach@169: uint32 numPluginAnimations; msach@169: uint64 cyclesTillStartMasterLoop; msach@169: TSCountLowHigh endMasterLoop; msach@169: #endif msach@169: //========================================== Me@42: } Me@42: MasterEnv; Me@42: Me@55: //========================= Extra Stuff Data Strucs ======================= Me@54: typedef struct Me@54: { Me@42: Me@54: } Me@54: VMSExcp; Me@50: Me@55: struct _GateStruc Me@55: { Me@55: int32 gateClosed; Me@55: int32 preGateProgress; Me@55: int32 waitProgress; Me@55: int32 exitProgress; Me@55: }; Me@55: //GateStruc Me@50: Me@50: //======================= OS Thread related =============================== Me@42: Me@42: void * coreLoop( void *paramsIn ); //standard PThreads fn prototype Me@42: void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype msach@169: void masterLoop( void *initData, VirtProcr *masterVP ); Me@42: Me@42: Me@50: typedef struct Me@50: { Me@50: void *endThdPt; Me@50: unsigned int coreNum; Me@50: } Me@50: ThdParams; Me@42: Me@42: pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state Me@42: ThdParams *coreLoopThdParams [ NUM_CORES ]; Me@42: pthread_mutex_t suspendLock; Me@42: pthread_cond_t suspend_cond; Me@42: Me@50: Me@50: Me@50: //===================== Global Vars =================== Me@50: msach@171: volatile MasterEnv *_VMSMasterEnv __align_to_cacheline__; Me@42: Me@50: Me@50: Me@50: Me@50: //=========================== Function Prototypes ========================= Me@50: Me@53: Me@53: //========== Setup and shutdown ========== Me@42: void Me@42: VMS__init(); Me@42: Me@42: void Me@42: VMS__init_Seq(); Me@42: Me@42: void Me@42: VMS__start_the_work_then_wait_until_done(); Me@42: Me@42: void Me@42: VMS__start_the_work_then_wait_until_done_Seq(); Me@42: msach@76: inline VirtProcr * Me@42: VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData ); Me@42: Me@53: void Me@53: VMS__dissipate_procr( VirtProcr *procrToDissipate ); Me@53: Me@50: //Use this to create processor inside entry point & other places outside Me@50: // the VMS system boundary (IE, not run in slave nor Master) Me@50: VirtProcr * Me@50: VMS_ext__create_procr( VirtProcrFnPtr fnPtr, void *initialData ); Me@50: Me@53: void Me@53: VMS_ext__dissipate_procr( VirtProcr *procrToDissipate ); Me@42: Me@50: void Me@54: VMS__throw_exception( char *msgStr, VirtProcr *reqstPr, VMSExcp *excpData ); Me@54: Me@54: void Me@53: VMS__shutdown(); Me@53: Me@53: void Me@53: VMS__cleanup_at_end_of_shutdown(); Me@50: Me@64: void * Me@64: VMS__give_sem_env_for( VirtProcr *animPr ); Me@64: Me@50: Me@50: //============== Request Related =============== Me@50: Me@50: void Me@50: VMS__suspend_procr( VirtProcr *callingPr ); Me@50: Me@42: inline void Me@53: VMS__add_sem_request_in_mallocd_VMSReqst( void *semReqData, VirtProcr *callingPr ); Me@53: Me@53: inline void Me@53: VMS__send_sem_request( void *semReqData, VirtProcr *callingPr ); Me@42: Me@42: void Me@50: VMS__send_create_procr_req( void *semReqData, VirtProcr *reqstingPr ); Me@42: Me@53: void inline Me@53: VMS__send_dissipate_req( VirtProcr *prToDissipate ); Me@53: Me@52: inline void Me@52: VMS__send_VMSSem_request( void *semReqData, VirtProcr *callingPr ); Me@52: Me@42: VMSReqst * Me@50: VMS__take_next_request_out_of( VirtProcr *procrWithReq ); Me@42: Me@42: inline void * Me@42: VMS__take_sem_reqst_from( VMSReqst *req ); Me@42: msach@78: void inline msach@78: VMS__handle_VMSSemReq( VMSReqst *req, VirtProcr *requestingPr, void *semEnv, msach@78: ResumePrFnPtr resumePrFnPtr ); msach@78: msach@169: //======================== MEASUREMENT ====================== msach@169: uint64 msach@169: VMS__give_num_plugin_cycles(); msach@169: uint32 msach@169: VMS__give_num_plugin_animations(); Me@42: Me@42: Me@42: msach@77: #include "ProcrContext.h" Me@50: #include "probes.h" Me@65: #include "vutilities.h" msach@201: #include "VMS_Implementations/Vthread_impl/VMS_lang_specific_defines.h" Me@42: #endif /* _VMS_H */ Me@42: