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@0: Me@0: #include "VMS_primitive_data_types.h" Me@0: #include "Queue_impl/BlockingQueue.h" Me@7: #include Me@13: #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@23: #define NUM_SCHED_SLOTS (2 * NUM_CORES + 1) Me@23: Me@23: //128K stack.. compromise, want 10K virtPr Me@23: #define VIRT_PROCR_STACK_SIZE 0x100000 Me@0: Me@0: #define SUCCESS 0 Me@0: Me@13: //#define thdAttrs NULL //For PThreads Me@0: Me@16: typedef struct _SchedSlot SchedSlot; Me@23: typedef struct _SlaveReqst 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@23: IO Me@23: }; Me@5: Me@16: struct _SlaveReqst Me@16: { Me@23: // VirtProcr *virtProcrFrom; Me@23: 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@16: //SlaveReqst 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@5: SlaveScheduler slaveScheduler; Me@5: RequestHandler requestHandler; Me@0: Me@5: SchedSlot **schedSlots; Me@5: SchedSlot **filledSlots; Me@5: int numFilled; Me@5: Me@0: int stillRunning; Me@0: Me@5: VirtProcr *masterVirtPr; Me@0: void *semanticEnv; Me@5: void *OSEventStruc; //for future, when add I/O to BLIS Me@16: Me@16: void *coreLoopShutDownPt; //addr to jump to to shut down a coreLoop Me@0: } Me@0: MasterEnv; Me@0: Me@0: Me@16: //========================================================== Me@0: Me@7: DWORD WINAPI coreLoop( LPVOID paramsIn ); Me@7: //void * coreLoop( 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@13: HANDLE coreLoopThdHandles[ NUM_CORES ]; //windows handle to thread Me@13: ThdParams *coreLoopThdParams[ NUM_CORES ]; Me@13: DWORD coreLoopThdIds[ NUM_CORES ]; Me@0: Me@13: //TODO: Debug: figure out if need to be volatile or not 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@5: // need to save any regs used by core loop (will see if this really works) Me@13: volatile CASQueueStruc *_VMSWorkQ; Me@0: Me@7: //========================== Me@7: void Me@7: VMS__init(); Me@7: Me@7: void Me@7: VMS__start(); Me@7: 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@7: inline void Me@7: VMS__send_sem_request( void *semReqData, VirtProcr *callingPr ); Me@7: Me@7: void Me@23: VMS__send_dissipate_request( VirtProcr *procrToDissipate ); Me@23: Me@23: void Me@23: VMS__remove_and_free_top_request( VirtProcr *reqstingPr ); Me@23: 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@23: VMS__shutdown(); Me@7: Me@13: //============================= Statistics ================================== Me@13: Me@13: typedef unsigned long long TSCount; Me@13: 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: