1 #ifndef __MLP_RUNTIME__
2 #define __MLP_RUNTIME__
7 #include "psemaphore.h"
32 #define PARENTCOARSE 5
42 #define H_MASK (NUMBINS<<4)-1
53 #define OBJPTRPTR_2_OBJTYPE( opp ) ((int*)(*(opp)))[0]
54 #define OBJPTRPTR_2_OBJOID( opp ) ((int*)(*(opp)))[1]
58 // these fields are common to any SESE, and casting the
59 // generated SESE record to this can be used, because
60 // the common structure is always the first item in a
61 // customized SESE record
62 typedef struct SESEcommon_t {
64 // the identifier for the class of sese's that
65 // are instances of one particular static code block
66 // IMPORTANT: the class ID must be the first field of
67 // the task record so task dispatch works correctly!
70 // a parent waits on this semaphore when stalling on
71 // this child, the child gives it at its SESE exit
75 // the lock guards the following data SESE's
76 // use to coordinate with one another
79 struct Queue* forwardList;
80 volatile int unresolvedDependencies;
82 pthread_cond_t doneCond;
85 pthread_cond_t runningChildrenCond;
86 int numRunningChildren;
88 struct SESEcommon_t* parent;
90 psemaphore parentStallSem;
91 pthread_cond_t stallDone;
95 int unresolvedRentryIdx;
96 struct MemoryQueue_t** memoryQueueArray;
97 struct REntry_t* rentryArray[NUMRENTRY];
98 struct REntry_t* unresolvedRentryArray[NUMRENTRY];
100 int numDependentSESErecords;
101 int offsetToDepSESErecords;
103 // for determining when task records can be returned
104 // to the parent record's memory pool
105 MemPool* taskRecordMemPool;
106 volatile int refCount;
111 // a thread-local var refers to the currently
113 extern __thread SESEcommon* runningSESE;
117 typedef struct REntry_t{
118 int type; // fine read:0, fine write:1, parent read:2, parent write:3 coarse: 4, parent coarse:5, scc: 6
119 struct Hashtable_t* hashtable;
120 struct BinItem_t* binitem;
121 struct Vector_t* vector;
123 struct MemoryQueue_t* queue;
124 psemaphore parentStallSem;
130 typedef struct MemoryQueueItem_t {
131 int type; // hashtable:0, vector:1, singleitem:2
132 int total; //total non-retired
133 int status; //NOTREADY, READY
134 struct MemoryQueueItem_t *next;
137 typedef struct MemoryQueue_t {
138 MemoryQueueItem * head;
139 MemoryQueueItem * tail;
140 REntry * binbuf[NUMBINS];
141 REntry * buf[NUMRENTRY];
145 typedef struct BinItem_t {
147 int status; //NOTREADY, READY
148 int type; //READBIN:0, WRITEBIN:1
149 struct BinItem_t * next;
152 typedef struct Hashtable_t {
153 MemoryQueueItem item;
154 struct BinElement_t* array[NUMBINS];
155 struct Queue* unresolvedQueue;
158 typedef struct BinElement_t {
163 typedef struct WriteBinItem_t {
168 typedef struct ReadBinItem_t {
170 REntry * array[NUMREAD];
174 typedef struct Vector_t {
175 MemoryQueueItem item;
176 REntry * array[NUMITEMS];
180 typedef struct SCC_t {
181 MemoryQueueItem item;
185 int ADDRENTRY(MemoryQueue* q, REntry * r);
186 void RETIRERENTRY(MemoryQueue* Q, REntry * r);
190 // simple mechanical allocation and
191 // deallocation of SESE records
192 void* mlpAllocSESErecord( int size );
193 void mlpFreeSESErecord( SESEcommon* seseRecord );
195 MemoryQueue** mlpCreateMemoryQueueArray(int numMemoryQueue);
196 REntry* mlpCreateFineREntry(int type, SESEcommon* seseToIssue, void* dynID);
197 REntry* mlpCreateREntry (int type, SESEcommon* seseToIssue);
198 MemoryQueue* createMemoryQueue();
199 void rehashMemoryQueue(SESEcommon* seseParent);
202 static inline void ADD_REFERENCE_TO( SESEcommon* seseRec ) {
203 #ifndef OOO_DISABLE_TASKMEMPOOL
204 atomic_inc( &(seseRec->refCount) );
208 static inline void RELEASE_REFERENCE_TO( SESEcommon* seseRec ) {
209 #ifndef OOO_DISABLE_TASKMEMPOOL
210 if( atomic_sub_and_test( 1, &(seseRec->refCount) ) ) {
211 poolfreeinto( seseRec->parent->taskRecordMemPool, seseRec );
217 #endif /* __MLP_RUNTIME__ */