1 #ifndef __MLP_RUNTIME__
2 #define __MLP_RUNTIME__
7 #include "psemaphore.h"
31 #define PARENTCOARSE 5
41 #define H_MASK (NUMBINS<<4)-1
51 typedef struct REntry_t{
52 int type; // fine read:0, fine write:1, parent read:2, parent write:3 coarse: 4, parent coarse:5, scc: 6
53 struct Hashtable_t* hashtable;
54 struct BinItem_t* binitem;
55 struct Vector_t* vector;
57 struct MemoryQueue_t* queue;
58 psemaphore parentStallSem;
64 typedef struct MemoryQueueItem_t {
65 int type; // hashtable:0, vector:1, singleitem:2
66 int total; //total non-retired
67 int status; //NOTREADY, READY
68 struct MemoryQueueItem_t *next;
71 typedef struct MemoryQueue_t {
72 MemoryQueueItem * head;
73 MemoryQueueItem * tail;
76 typedef struct BinItem_t {
78 int status; //NOTREADY, READY
79 int type; //READBIN:0, WRITEBIN:1
80 struct BinItem_t * next;
83 typedef struct Hashtable_t {
85 struct BinElement_t* array[NUMBINS];
86 struct Queue* unresolvedQueue;
89 typedef struct BinElement_t {
94 typedef struct WriteBinItem_t {
99 typedef struct ReadBinItem_t {
101 REntry * array[NUMREAD];
105 typedef struct Vector_t {
106 MemoryQueueItem item;
107 REntry * array[NUMITEMS];
111 typedef struct SCC_t {
112 MemoryQueueItem item;
116 int ADDRENTRY(MemoryQueue* q, REntry * r);
117 void RETIRERENTRY(MemoryQueue* Q, REntry * r);
120 // forward declaration of pointer type
121 typedef struct SESEcommon_t* SESEcommon_p;
123 // these fields are common to any SESE, and casting the
124 // generated SESE record to this can be used, because
125 // the common structure is always the first item in a
126 // customized SESE record
127 typedef struct SESEcommon_t {
129 // the identifier for the class of sese's that
130 // are instances of one particular static code block
133 // a parent waits on this semaphore when stalling on
134 // this child, the child gives it at its SESE exit
138 // the lock guards the following data SESE's
139 // use to coordinate with one another
140 pthread_mutex_t lock;
142 struct Queue* forwardList;
143 volatile int unresolvedDependencies;
145 pthread_cond_t doneCond;
148 pthread_cond_t runningChildrenCond;
149 int numRunningChildren;
153 psemaphore parentStallSem;
154 pthread_cond_t stallDone;
158 int unresolvedRentryIdx;
159 struct MemoryQueue_t** memoryQueueArray;
160 struct REntry_t* rentryArray[NUMRENTRY];
161 struct REntry_t* unresolvedRentryArray[NUMRENTRY];
165 // a thread-local stack of SESEs and function to
166 // ensure it is initialized once per thread
168 extern __thread struct Queue* seseCallStack;
169 extern __thread pthread_once_t mlpOnceObj;
170 void mlpInitOncePerThread();
172 extern __thread SESEcommon_p seseCaller;
175 // simple mechanical allocation and
176 // deallocation of SESE records
177 void* mlpCreateSESErecord( int size );
178 void mlpDestroySESErecord( void* seseRecord );
179 void* mlpAllocSESErecord( int size );
181 MemoryQueue** mlpCreateMemoryQueueArray(int numMemoryQueue);
182 REntry* mlpCreateFineREntry(int type, void* seseToIssue, void* dynID);
183 REntry* mlpCreateREntry(int type, void* seseToIssue);
184 MemoryQueue* createMemoryQueue();
185 void rehashMemoryQueue(SESEcommon_p seseParent);
187 #endif /* __MLP_RUNTIME__ */