1 #ifndef __MLP_RUNTIME__
2 #define __MLP_RUNTIME__
7 #include "psemaphore.h"
32 #define PARENTCOARSE 5
42 #define H_MASK (NUMBINS)-1
53 // these are useful for interpreting an INTPTR to an
54 // Object at runtime to retrieve the object's type
55 // or object id (OID), 64-bit safe
56 #define OBJPTRPTR_2_OBJTYPE( opp ) ((int*)(*(opp)))[0]
57 #define OBJPTRPTR_2_OBJOID( opp ) ((int*)(*(opp)))[1]
61 // forwarding list elements is a linked
62 // structure of arrays, should help task
63 // dispatch because the first element is
64 // an embedded member of the task record,
65 // only have to do memory allocation if
66 // a lot of items are on the list
67 #define FLIST_ITEMS_PER_ELEMENT 30
68 typedef struct ForwardingListElement_t {
70 struct ForwardingListElement_t* nextElement;
71 INTPTR items[FLIST_ITEMS_PER_ELEMENT];
72 } ForwardingListElement;
76 // these fields are common to any SESE, and casting the
77 // generated SESE record to this can be used, because
78 // the common structure is always the first item in a
79 // customized SESE record
80 typedef struct SESEcommon_t {
82 // the identifier for the class of sese's that
83 // are instances of one particular static code block
84 // IMPORTANT: the class ID must be the first field of
85 // the task record so task dispatch works correctly!
88 // a parent waits on this semaphore when stalling on
89 // this child, the child gives it at its SESE exit
93 // the lock guards the following data SESE's
94 // use to coordinate with one another
97 // NOTE: first element is embedded in the task
98 // record, so don't free it!
99 //ForwardingListElement forwardList;
100 struct Queue* forwardList;
103 volatile int unresolvedDependencies;
105 pthread_cond_t doneCond;
108 pthread_cond_t runningChildrenCond;
109 int numRunningChildren;
111 struct SESEcommon_t* parent;
113 //psemaphore parentStallSem;
114 //pthread_cond_t stallDone;
118 int unresolvedRentryIdx;
119 struct MemoryQueue_t** memoryQueueArray;
120 struct REntry_t* rentryArray[NUMRENTRY];
121 struct REntry_t* unresolvedRentryArray[NUMRENTRY];
123 int numDependentSESErecords;
124 int offsetToDepSESErecords;
126 int offsetToParamRecords;
129 // for determining when task records can be returned
130 // to the parent record's memory pool
131 MemPool* taskRecordMemPool;
132 volatile int refCount;
137 // a thread-local var refers to the currently
139 extern __thread SESEcommon* runningSESE;
143 typedef struct REntry_t{
144 // fine read:0, fine write:1, parent read:2,
145 // parent write:3 coarse: 4, parent coarse:5, scc: 6
147 struct Hashtable_t* hashtable;
148 struct BinItem_t* binitem;
149 struct Vector_t* vector;
151 struct MemoryQueue_t* queue;
152 psemaphore parentStallSem;
158 typedef struct MemoryQueueItem_t {
159 int type; // hashtable:0, vector:1, singleitem:2
160 int total; //total non-retired
161 int status; //NOTREADY, READY
162 struct MemoryQueueItem_t *next;
165 typedef struct MemoryQueue_t {
166 MemoryQueueItem * head;
167 MemoryQueueItem * tail;
168 REntry * binbuf[NUMBINS];
169 REntry * buf[NUMRENTRY];
173 typedef struct BinItem_t {
175 int status; //NOTREADY, READY
176 int type; //READBIN:0, WRITEBIN:1
177 struct BinItem_t * next;
180 typedef struct Hashtable_t {
181 MemoryQueueItem item;
182 struct BinElement_t* array[NUMBINS];
183 struct Queue* unresolvedQueue;
186 typedef struct BinElement_t {
191 typedef struct WriteBinItem_t {
196 typedef struct ReadBinItem_t {
198 REntry * array[NUMREAD];
202 typedef struct Vector_t {
203 MemoryQueueItem item;
204 REntry * array[NUMITEMS];
208 typedef struct SCC_t {
209 MemoryQueueItem item;
213 int ADDRENTRY(MemoryQueue* q, REntry * r);
214 void RETIRERENTRY(MemoryQueue* Q, REntry * r);
219 static inline void ADD_FORWARD_ITEM( ForwardingListElement* e,
221 //atomic_inc( &(s->refCount) );
227 // simple mechanical allocation and
228 // deallocation of SESE records
229 void* mlpAllocSESErecord( int size );
230 void mlpFreeSESErecord( SESEcommon* seseRecord );
232 MemoryQueue** mlpCreateMemoryQueueArray(int numMemoryQueue);
233 REntry* mlpCreateFineREntry(int type, SESEcommon* seseToIssue, void* dynID);
234 REntry* mlpCreateREntry (int type, SESEcommon* seseToIssue);
235 MemoryQueue* createMemoryQueue();
236 void rehashMemoryQueue(SESEcommon* seseParent);
239 static inline void ADD_REFERENCE_TO( SESEcommon* seseRec ) {
240 atomic_inc( &(seseRec->refCount) );
243 static inline void RELEASE_REFERENCE_TO( SESEcommon* seseRec ) {
244 if( atomic_sub_and_test( 1, &(seseRec->refCount) ) ) {
245 poolfreeinto( seseRec->parent->taskRecordMemPool, seseRec );
250 #endif /* __MLP_RUNTIME__ */