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@26: #include Me@0: 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@30: // 8K stack Me@30: #define VIRT_PROCR_STACK_SIZE 0x20000 Me@30: Me@30: //256M of total memory for VMS application to 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@23: typedef VirtProcr * (*SlaveScheduler) ( void * ); //semEnv 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@16: // void *framePtr; Me@16: // void *stackPtr; 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@5: }; Me@16: //VirtProcr Me@5: Me@5: Me@16: Me@0: typedef struct Me@0: { Me@30: SlaveScheduler slaveScheduler; Me@30: RequestHandler requestHandler; Me@0: Me@30: SchedSlot **schedSlots; Me@30: SchedSlot **filledSlots; Me@30: int numToPrecede; Me@5: Me@30: volatile int stillRunning; Me@0: Me@30: VirtProcr *masterVirtPr; Me@25: Me@30: void *semanticEnv; Me@30: void *OSEventStruc; //for future, when add I/O to BLIS Me@16: Me@30: void *coreLoopEndPt; //addr to jump to to shut down a coreLoop Me@25: Me@30: int setupComplete; Me@30: Me@30: void *mallocChunk; 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@5: //workQ is global, static, and volatile so that core loop has its location Me@5: // hard coded, and reloads every time through the loop -- that way don't Me@25: // need to save any regs used by core loop Me@26: volatile VMSQueueStruc *_VMSWorkQ; Me@0: 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@24: VMS__send_register_new_procr_request( 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@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@13: inline TSCount getTSCount(); Me@13: Me@23: //===================== Debug ========================== Me@13: int numProcrsCreated; Me@0: Me@23: Me@0: #endif /* _VMS_H */ Me@0: