X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=Robust%2Fsrc%2FRuntime%2Fmlp_runtime.h;h=4e351a50974a73fac14bffc48908328d3cf24d58;hb=c623d47ba5d7f26bd9f57a9082a8b29128c2912c;hp=16adef36cc09a13d4987a2b744d8ab4216cabca0;hpb=e800e30ed229bcbf7553a1b4b7863f78100e5542;p=IRC.git diff --git a/Robust/src/Runtime/mlp_runtime.h b/Robust/src/Runtime/mlp_runtime.h index 16adef36..4e351a50 100644 --- a/Robust/src/Runtime/mlp_runtime.h +++ b/Robust/src/Runtime/mlp_runtime.h @@ -5,7 +5,41 @@ #include #include "Queue.h" #include "psemaphore.h" +#include "mlp_lock.h" +#include "memPool.h" +#ifndef FALSE +#define FALSE 0 +#endif + +#ifndef TRUE +#define TRUE 1 +#endif + +#define NUMBINS 64 +#define NUMREAD 64 +#define NUMITEMS 64 +#define NUMRENTRY 256 + +#define READY 1 +#define NOTREADY 0 + +#define READ 0 +#define WRITE 1 +#define PARENTREAD 2 +#define PARENTWRITE 3 +#define COARSE 4 +#define PARENTCOARSE 5 +#define SCCITEM 6 + +#define HASHTABLE 0 +#define VECTOR 1 +#define SINGLEITEM 2 + +#define READBIN 0 +#define WRITEBIN 1 + +#define H_MASK (NUMBINS<<4)-1 #ifndef FALSE #define FALSE 0 @@ -15,14 +49,11 @@ #define TRUE 1 #endif -// each allocation site nees the following -typedef struct AllocSite_t{ - long id; - struct Queue* waitingQueue; -} AllocSite; -// forward declaration of pointer type -typedef struct SESEcommon_t* SESEcommon_p; +#define OBJPTRPTR_2_OBJTYPE( opp ) ((int*)(*(opp)))[0] +#define OBJPTRPTR_2_OBJOID( opp ) ((int*)(*(opp)))[1] + + // these fields are common to any SESE, and casting the // generated SESE record to this can be used, because @@ -32,6 +63,8 @@ typedef struct SESEcommon_t { // the identifier for the class of sese's that // are instances of one particular static code block + // IMPORTANT: the class ID must be the first field of + // the task record so task dispatch works correctly! int classID; // a parent waits on this semaphore when stalling on @@ -44,7 +77,7 @@ typedef struct SESEcommon_t { pthread_mutex_t lock; struct Queue* forwardList; - int unresolvedDependencies; + volatile int unresolvedDependencies; pthread_cond_t doneCond; int doneExecuting; @@ -52,31 +85,133 @@ typedef struct SESEcommon_t { pthread_cond_t runningChildrenCond; int numRunningChildren; - SESEcommon_p parent; + struct SESEcommon_t* parent; + + psemaphore parentStallSem; + pthread_cond_t stallDone; + + int numMemoryQueue; + int rentryIdx; + int unresolvedRentryIdx; + struct MemoryQueue_t** memoryQueueArray; + struct REntry_t* rentryArray[NUMRENTRY]; + struct REntry_t* unresolvedRentryArray[NUMRENTRY]; + + int numDependentSESErecords; + int offsetToDepSESErecords; - AllocSite* allocSiteArray; - int numRelatedAllocSites; - psemaphore memoryStallSiteSem; + // for determining when task records can be returned + // to the parent record's memory pool + MemPool* taskRecordMemPool; + volatile int refCount; } SESEcommon; -// a thread-local stack of SESEs and function to -// ensure it is initialized once per thread -/* -extern __thread struct Queue* seseCallStack; -extern __thread pthread_once_t mlpOnceObj; -void mlpInitOncePerThread(); -*/ -extern __thread SESEcommon_p seseCaller; +// a thread-local var refers to the currently +// running task +extern __thread SESEcommon* runningSESE; + + + +typedef struct REntry_t{ + int type; // fine read:0, fine write:1, parent read:2, parent write:3 coarse: 4, parent coarse:5, scc: 6 + struct Hashtable_t* hashtable; + struct BinItem_t* binitem; + struct Vector_t* vector; + struct SCC_t* scc; + struct MemoryQueue_t* queue; + psemaphore parentStallSem; + SESEcommon* seseRec; + INTPTR* pointer; + int isBufMode; +} REntry; + +typedef struct MemoryQueueItem_t { + int type; // hashtable:0, vector:1, singleitem:2 + int total; //total non-retired + int status; //NOTREADY, READY + struct MemoryQueueItem_t *next; +} MemoryQueueItem; + +typedef struct MemoryQueue_t { + MemoryQueueItem * head; + MemoryQueueItem * tail; + REntry * binbuf[NUMBINS]; + REntry * buf[NUMRENTRY]; + int bufcount; +} MemoryQueue; + +typedef struct BinItem_t { + int total; + int status; //NOTREADY, READY + int type; //READBIN:0, WRITEBIN:1 + struct BinItem_t * next; +} BinItem; + +typedef struct Hashtable_t { + MemoryQueueItem item; + struct BinElement_t* array[NUMBINS]; + struct Queue* unresolvedQueue; +} Hashtable; + +typedef struct BinElement_t { + BinItem * head; + BinItem * tail; +} BinElement; + +typedef struct WriteBinItem_t { + BinItem item; + REntry * val; +} WriteBinItem; + +typedef struct ReadBinItem_t { + BinItem item; + REntry * array[NUMREAD]; + int index; +} ReadBinItem; + +typedef struct Vector_t { + MemoryQueueItem item; + REntry * array[NUMITEMS]; + int index; +} Vector; + +typedef struct SCC_t { + MemoryQueueItem item; + REntry * val; +} SCC; + +int ADDRENTRY(MemoryQueue* q, REntry * r); +void RETIRERENTRY(MemoryQueue* Q, REntry * r); + // simple mechanical allocation and // deallocation of SESE records -void* mlpCreateSESErecord( int size ); -void mlpDestroySESErecord( void* seseRecord ); +void* mlpAllocSESErecord( int size ); +void mlpFreeSESErecord( SESEcommon* seseRecord ); + +MemoryQueue** mlpCreateMemoryQueueArray(int numMemoryQueue); +REntry* mlpCreateFineREntry(int type, SESEcommon* seseToIssue, void* dynID); +REntry* mlpCreateREntry (int type, SESEcommon* seseToIssue); +MemoryQueue* createMemoryQueue(); +void rehashMemoryQueue(SESEcommon* seseParent); + -AllocSite* mlpCreateAllocSiteArray(int numAllocSites); +static inline void ADD_REFERENCE_TO( SESEcommon* seseRec ) { +#ifndef OOO_DISABLE_TASKMEMPOOL + atomic_inc( &(seseRec->refCount) ); +#endif +} + +static inline void RELEASE_REFERENCE_TO( SESEcommon* seseRec ) { +#ifndef OOO_DISABLE_TASKMEMPOOL + if( atomic_sub_and_test( 1, &(seseRec->refCount) ) ) { + poolfreeinto( seseRec->parent->taskRecordMemPool, seseRec ); + } +#endif +} #endif /* __MLP_RUNTIME__ */