Me@0: /* Me@0: * Copyright 2009 OpenSourceStewardshipFoundation.org Me@0: * Licensed under GNU General Public License version 2 Me@0: * Me@0: * Author: seanhalle@yahoo.com Me@0: * Me@0: */ Me@0: Me@0: #ifndef _VMS_H Me@0: #define _VMS_H Me@25: #define __USE_GNU Me@0: Me@0: #include "VMS_primitive_data_types.h" Me@0: #include "Queue_impl/BlockingQueue.h" Me@38: #include "Histogram/Histogram.h" Me@26: #include Me@0: Me@31: //When DEBUG is defined, VMS does sequential exe in the main thread Me@31: // It still does co-routines and all the mechanisms are the same, it just Me@31: // has only a single thread and animates VPs one at a time Me@38: #define SEQUENTIAL Me@38: Me@38: //when MEAS__TAKE_SUSP_TSC is defined, causes code to be inserted and Me@38: // compiled-in that saves the low part of the time stamp count just before Me@38: // suspending a processor and just after resuming that processor. It is Me@38: // saved into a field added to VirtProcr. Have to sanity-check for Me@38: // rollover of low portion into high portion. Me@38: #define MEAS__TIME_STAMP_SUSP Me@38: #define MEAS__TIME_MASTER Me@38: #define MEAS__NUM_TIMES_TO_RUN 100000 Me@31: Me@23: //This value is the number of hardware threads in the shared memory Me@23: // machine Me@23: #define NUM_CORES 4 Me@23: Me@23: // make double-num-cores scheduling slots, plus extra for master Me@29: //#define NUM_SCHED_SLOTS (2 * NUM_CORES + 1) Me@29: #define NUM_SCHED_SLOTS 3 Me@23: Me@31: #define READYTOANIMATE_RETRIES 10000 Me@31: Me@31: // stack Me@31: #define VIRT_PROCR_STACK_SIZE 0x10000 Me@30: Me@41: //256M of total memory for VMS__malloc Me@30: #define MASSIVE_MALLOC_SIZE 0x10000000 Me@30: Me@30: #define NUM_PREPEND_BYTES sizeof(FreeListElem) + sizeof(ownerElem); Me@0: Me@0: #define SUCCESS 0 Me@0: Me@30: #define writeVMSQ writeCASQ Me@30: #define readVMSQ readCASQ Me@30: #define makeVMSQ makeCASQ Me@30: #define VMSQueueStruc CASQueueStruc Me@26: Me@13: //#define thdAttrs NULL //For PThreads Me@0: Me@16: typedef struct _SchedSlot SchedSlot; Me@26: typedef struct _VMSReqst VMSReqst; Me@5: typedef struct _VirtProcr VirtProcr; Me@0: Me@31: typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx Me@23: typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv Me@23: typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr Me@23: typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr Me@16: Me@0: typedef struct Me@0: { Me@7: void *endThdPt; Me@7: unsigned int coreNum; Me@0: } Me@0: ThdParams; Me@0: Me@16: Me@5: struct _SchedSlot Me@5: { Me@5: int workIsDone; Me@5: int needsProcrAssigned; Me@5: VirtProcr *procrAssignedToSlot; Me@5: }; Me@16: //SchedSlot Me@16: Me@23: enum ReqstType Me@23: { Me@23: semantic = 1, Me@23: dissipate, Me@24: regCreated, Me@23: IO Me@23: }; Me@5: Me@24: struct _VMSReqst Me@16: { Me@23: // VirtProcr *virtProcrFrom; Me@24: enum ReqstType reqType;//used for dissipate and in future for IO requests Me@23: void *semReqData; Me@16: Me@23: VMSReqst *nextReqst; Me@16: }; Me@24: //VMSReqst Me@5: Me@5: struct _VirtProcr Me@13: { int procrID; //for debugging -- count up each time create Me@16: int coreAnimatedBy; Me@23: void *startOfStack; Me@5: void *stackPtr; Me@5: void *framePtr; Me@5: void *nextInstrPt; Me@16: Me@5: void *coreLoopStartPt; //allows proto-runtime to be linked later Me@16: void *coreLoopFramePtr; //restore before jmp back to core loop Me@16: void *coreLoopStackPtr; //restore before jmp back to core loop Me@5: Me@5: void *initialData; Me@5: Me@5: SchedSlot *schedSlot; Me@23: VMSReqst *requests; Me@5: Me@5: void *semanticData; Me@38: Me@38: //============================= MEASUREMENT STUFF ======================== Me@38: #ifdef MEAS__TIME_STAMP_SUSP Me@38: unsigned int preSuspTSCLow; Me@38: unsigned int postSuspTSCLow; Me@38: #endif Me@38: #ifdef MEAS__TIME_MASTER Me@38: unsigned int startMasterTSCLow; Me@38: unsigned int endMasterTSCLow; Me@38: #endif Me@38: //======================================================================== Me@5: }; Me@16: //VirtProcr Me@5: Me@5: Me@16: Me@0: typedef struct Me@0: { Me@31: SlaveScheduler slaveScheduler; Me@31: RequestHandler requestHandler; Me@0: Me@31: SchedSlot ***allSchedSlots; Me@31: SRSWQueueStruc **readyToAnimateQs; Me@31: VirtProcr **masterVPs; Me@25: Me@31: void *semanticEnv; Me@31: void *OSEventStruc; //for future, when add I/O to BLIS Me@16: Me@31: void *coreLoopStartPt;//addr to jump to to re-enter coreLoop Me@31: void *coreLoopEndPt; //addr to jump to to shut down a coreLoop Me@25: Me@31: int setupComplete; Me@31: int masterLock; Me@38: Me@0: } Me@0: MasterEnv; Me@0: Me@0: Me@16: //========================================================== Me@0: Me@25: void * coreLoop( void *paramsIn ); //standard PThreads fn prototype Me@28: void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype Me@7: void masterLoop( void *initData, VirtProcr *masterPr ); Me@0: Me@0: Me@0: //===================== Global Vars =================== Me@0: Me@5: Me@26: pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state Me@26: ThdParams *coreLoopThdParams [ NUM_CORES ]; Me@26: pthread_mutex_t suspendLock; Me@26: pthread_cond_t suspend_cond; Me@0: Me@13: volatile MasterEnv *_VMSMasterEnv; Me@5: Me@7: //========================== Me@7: void Me@7: VMS__init(); Me@7: Me@7: void Me@28: VMS__init_Seq(); Me@28: Me@28: void Me@24: VMS__start_the_work_then_wait_until_done(); Me@7: Me@28: void Me@28: VMS__start_the_work_then_wait_until_done_Seq(); Me@28: Me@7: VirtProcr * Me@7: VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData ); Me@7: Me@23: VirtProcr * Me@23: VMS__create_the_shutdown_procr(); Me@23: Me@24: //========================== Me@7: inline void Me@24: VMS__add_sem_request( void *semReqData, VirtProcr *callingPr ); Me@7: Me@7: void Me@38: VMS__send_req_to_register_new_procr( VirtProcr *newPrToRegister, Me@24: VirtProcr *reqstingPr ); Me@24: Me@24: void Me@24: VMS__free_request( VMSReqst *req ); Me@23: Me@23: void Me@23: VMS__remove_and_free_top_request( VirtProcr *reqstingPr ); Me@23: Me@24: VMSReqst * Me@24: VMS__take_top_request_from( VirtProcr *reqstingPr ); Me@24: Me@31: VMSReqst * Me@31: VMS__free_top_and_give_next_request_from( VirtProcr *procrWithReq ); Me@31: Me@24: inline void * Me@24: VMS__take_sem_reqst_from( VMSReqst *req ); Me@24: Me@24: inline int Me@24: VMS__isSemanticReqst( VMSReqst *req ); Me@24: Me@24: inline int Me@24: VMS__isDissipateReqst( VMSReqst *req ); Me@24: Me@24: inline int Me@24: VMS__isCreateReqst( VMSReqst *req ); Me@24: Me@24: //========================== Me@24: Me@23: void Me@23: VMS__suspend_procr( VirtProcr *callingPr ); Me@23: Me@23: void Me@23: VMS__dissipate_procr( VirtProcr *prToDissipate ); Me@23: Me@23: void Me@29: VMS__handle_dissipate_reqst( VirtProcr *procrToDissipate ); Me@29: Me@29: void Me@29: VMS__cleanup_after_shutdown(); Me@7: Me@13: //============================= Statistics ================================== Me@13: Me@13: typedef unsigned long long TSCount; Me@13: Me@25: //Frequency of TS counts Me@25: //TODO: change freq for each machine Me@25: #define TSCOUNT_FREQ 3180000000 Me@25: Me@13: #define saveTimeStampCountInto(low, high) \ Me@13: asm volatile("RDTSC; \ Me@13: movl %%eax, %0; \ Me@13: movl %%edx, %1;" \ Me@13: /* outputs */ : "=m" (low), "=m" (high)\ Me@13: /* inputs */ : \ Me@13: /* clobber */ : "%eax", "%edx" \ Me@13: ); Me@13: Me@38: #define saveLowTimeStampCountInto(low) \ Me@38: asm volatile("RDTSC; \ Me@38: movl %%eax, %0;" \ Me@38: /* outputs */ : "=m" (low) \ Me@38: /* inputs */ : \ Me@38: /* clobber */ : "%eax", "%edx" \ Me@38: ); Me@38: Me@13: inline TSCount getTSCount(); Me@13: Me@23: //===================== Debug ========================== Me@13: int numProcrsCreated; Me@0: Me@23: Me@0: #endif /* _VMS_H */ Me@0: