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 Me@42: #define __USE_GNU Me@42: Me@42: #include "VMS_primitive_data_types.h" Me@42: #include "Queue_impl/BlockingQueue.h" Me@42: #include "Histogram/Histogram.h" Me@42: #include Me@42: Me@42: //When DEBUG is defined, VMS does sequential exe in the main thread Me@42: // It still does co-routines and all the mechanisms are the same, it just Me@42: // has only a single thread and animates VPs one at a time Me@42: #define SEQUENTIAL Me@42: Me@42: //when MEAS__TAKE_SUSP_TSC is defined, causes code to be inserted and Me@42: // compiled-in that saves the low part of the time stamp count just before Me@42: // suspending a processor and just after resuming that processor. It is Me@42: // saved into a field added to VirtProcr. Have to sanity-check for Me@42: // rollover of low portion into high portion. Me@42: #define MEAS__TIME_STAMP_SUSP Me@42: #define MEAS__TIME_MASTER Me@42: #define MEAS__NUM_TIMES_TO_RUN 100000 Me@42: Me@42: //This value is the number of hardware threads in the shared memory Me@42: // machine Me@42: #define NUM_CORES 4 Me@42: Me@42: // make double-num-cores scheduling slots, plus extra for master Me@42: //#define NUM_SCHED_SLOTS (2 * NUM_CORES + 1) Me@42: #define NUM_SCHED_SLOTS 3 Me@42: Me@42: #define READYTOANIMATE_RETRIES 10000 Me@42: Me@42: // stack Me@42: #define VIRT_PROCR_STACK_SIZE 0x10000 Me@42: Me@42: //256M of total memory for VMS__malloc Me@42: #define MASSIVE_MALLOC_SIZE 0x10000000 Me@42: Me@42: #define NUM_PREPEND_BYTES sizeof(FreeListElem) + sizeof(ownerElem); Me@42: Me@42: #define SUCCESS 0 Me@42: Me@42: #define writeVMSQ writeCASQ Me@42: #define readVMSQ readCASQ Me@42: #define makeVMSQ makeCASQ Me@42: #define VMSQueueStruc CASQueueStruc Me@42: Me@42: //#define thdAttrs NULL //For PThreads Me@42: Me@42: typedef struct _SchedSlot SchedSlot; Me@42: typedef struct _VMSReqst VMSReqst; Me@42: typedef struct _VirtProcr VirtProcr; 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@42: Me@42: typedef struct Me@42: { Me@42: void *endThdPt; Me@42: unsigned int coreNum; Me@42: } Me@42: ThdParams; Me@42: Me@42: 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@42: enum ReqstType Me@42: { Me@42: semantic = 1, Me@42: dissipate, Me@42: regCreated, Me@42: IO Me@42: }; Me@42: Me@42: struct _VMSReqst Me@42: { Me@42: // VirtProcr *virtProcrFrom; Me@42: enum ReqstType reqType;//used for dissipate and in future for IO requests Me@42: void *semReqData; Me@42: Me@42: VMSReqst *nextReqst; Me@42: }; Me@42: //VMSReqst Me@42: 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: Me@42: void *semanticData; Me@42: Me@42: //============================= MEASUREMENT STUFF ======================== Me@42: #ifdef MEAS__TIME_STAMP_SUSP Me@42: unsigned int preSuspTSCLow; Me@42: unsigned int postSuspTSCLow; Me@42: #endif Me@42: #ifdef MEAS__TIME_MASTER Me@42: unsigned int startMasterTSCLow; Me@42: unsigned int endMasterTSCLow; Me@42: #endif Me@42: //======================================================================== Me@42: }; Me@42: //VirtProcr Me@42: Me@42: Me@42: Me@42: typedef struct Me@42: { Me@42: SlaveScheduler slaveScheduler; Me@42: RequestHandler requestHandler; Me@42: Me@42: SchedSlot ***allSchedSlots; Me@42: SRSWQueueStruc **readyToAnimateQs; Me@42: VirtProcr **masterVPs; Me@42: Me@42: void *semanticEnv; Me@42: void *OSEventStruc; //for future, when add I/O to BLIS Me@42: Me@42: void *coreLoopStartPt;//addr to jump to to re-enter coreLoop Me@42: void *coreLoopEndPt; //addr to jump to to shut down a coreLoop Me@42: Me@42: int setupComplete; Me@42: int masterLock; Me@42: Me@42: } Me@42: MasterEnv; Me@42: Me@42: Me@42: //========================================================== Me@42: Me@42: void * coreLoop( void *paramsIn ); //standard PThreads fn prototype Me@42: void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype Me@42: void masterLoop( void *initData, VirtProcr *masterPr ); Me@42: Me@42: Me@42: //===================== Global Vars =================== Me@42: 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@42: volatile MasterEnv *_VMSMasterEnv; Me@42: Me@42: //========================== 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: Me@42: VirtProcr * Me@42: VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData ); Me@42: Me@42: VirtProcr * Me@42: VMS__create_the_shutdown_procr(); Me@42: Me@42: //========================== Me@42: inline void Me@42: VMS__add_sem_request( void *semReqData, VirtProcr *callingPr ); Me@42: Me@42: void Me@42: VMS__send_req_to_register_new_procr( VirtProcr *newPrToRegister, Me@42: VirtProcr *reqstingPr ); Me@42: Me@42: void Me@42: VMS__free_request( VMSReqst *req ); Me@42: Me@42: void Me@42: VMS__remove_and_free_top_request( VirtProcr *reqstingPr ); Me@42: Me@42: VMSReqst * Me@42: VMS__take_top_request_from( VirtProcr *reqstingPr ); Me@42: Me@42: VMSReqst * Me@42: VMS__free_top_and_give_next_request_from( VirtProcr *procrWithReq ); Me@42: Me@42: inline void * Me@42: VMS__take_sem_reqst_from( VMSReqst *req ); Me@42: Me@42: inline int Me@42: VMS__isSemanticReqst( VMSReqst *req ); Me@42: Me@42: inline int Me@42: VMS__isDissipateReqst( VMSReqst *req ); Me@42: Me@42: inline int Me@42: VMS__isCreateReqst( VMSReqst *req ); Me@42: Me@42: //========================== Me@42: Me@42: void Me@42: VMS__suspend_procr( VirtProcr *callingPr ); Me@42: Me@42: void Me@42: VMS__dissipate_procr( VirtProcr *prToDissipate ); Me@42: Me@42: void Me@42: VMS__handle_dissipate_reqst( VirtProcr *procrToDissipate ); Me@42: Me@42: void Me@42: VMS__cleanup_after_shutdown(); Me@42: Me@42: //============================= Statistics ================================== Me@42: Me@42: typedef unsigned long long TSCount; Me@42: Me@42: //Frequency of TS counts Me@42: //TODO: change freq for each machine Me@42: #define TSCOUNT_FREQ 3180000000 Me@42: Me@42: #define saveTimeStampCountInto(low, high) \ Me@42: asm volatile("RDTSC; \ Me@42: movl %%eax, %0; \ Me@42: movl %%edx, %1;" \ Me@42: /* outputs */ : "=m" (low), "=m" (high)\ Me@42: /* inputs */ : \ Me@42: /* clobber */ : "%eax", "%edx" \ Me@42: ); Me@42: Me@42: #define saveLowTimeStampCountInto(low) \ Me@42: asm volatile("RDTSC; \ Me@42: movl %%eax, %0;" \ Me@42: /* outputs */ : "=m" (low) \ Me@42: /* inputs */ : \ Me@42: /* clobber */ : "%eax", "%edx" \ Me@42: ); Me@42: Me@42: inline TSCount getTSCount(); Me@42: Me@42: //===================== Debug ========================== Me@42: int numProcrsCreated; Me@42: Me@42: Me@42: #endif /* _VMS_H */ Me@42: