1 #ifndef MULTICORE_RUNTIME
2 #define MULTICORE_RUNTIME
4 ////////////////////////////////////////////////////////////////
6 ///////////////////////////////////////////////////////////////
8 // data structures for msgs
9 #define BAMBOO_OUT_BUF_LENGTH 300
14 int outmsgdata[BAMBOO_OUT_BUF_LENGTH];
19 volatile bool isMsgSending;
23 * type: 0 -- transfer object
24 * 1 -- transfer stall msg
29 * // add for profile info
30 * 6 -- transfer profile output msg
31 * 7 -- transfer profile output finish msg
32 * // add for alias lock strategy
33 * 8 -- redirect lock request
34 * 9 -- lock grant with redirect info
35 * a -- lock deny with redirect info
36 * b -- lock release with redirect info
37 * c -- status confirm request
38 * d -- status report msg
40 * f -- requiring for new memory
41 * 10 -- response for new memory request
43 * 12 -- compact phase start
44 * 13 -- flush phase start
45 * 14 -- mark phase finish
46 * 15 -- compact phase finish
47 * 16 -- flush phase finish
49 * 18 -- marked phase finish confirm request
50 * 19 -- marked phase finish confirm response
52 * 1b -- start moving objs msg
53 * 1c -- ask for mapping info of a markedObj
54 * 1d -- mapping info of a markedObj
55 * 1e -- large objs info request
56 * 1f -- large objs info response
58 * ObjMsg: 0 + size of msg + obj's address + (task index + param index)+
59 * StallMsg: 1 + corenum + sendobjs + receiveobjs (size is always 4 * sizeof(int))
60 * LockMsg: 2 + lock type + obj pointer + lock + request core (size is always 5 * sizeof(int))
61 * 3/4/5 + lock type + obj pointer + lock (size is always 4 * sizeof(int))
62 * 8 + lock type + obj pointer + redirect lock + root request core + request core (size is always 6 * sizeof(int))
63 * 9/a + lock type + obj pointer + redirect lock (size is always 4 * sizeof(int))
64 * b + lock type + lock + redirect lock (size is always 4 * sizeof(int))
65 * lock type: 0 -- read; 1 -- write
66 * ProfileMsg: 6 + totalexetime (size is always 2 * sizeof(int))
67 * 7 + corenum (size is always 2 * sizeof(int))
68 * StatusMsg: c (size is always 1 * sizeof(int))
69 * d + status + corenum (size is always 3 * sizeof(int))
70 * status: 0 -- stall; 1 -- busy
71 * TerminateMsg: e (size is always 1 * sizeof(int)
72 * MemoryMsg: f + size + corenum (size is always 3 * sizeof(int))
73 * 10 + base_va + size (size is always 3 * sizeof(int))
74 * GCMsg: 11 (size is always 1 * sizeof(int))
75 * 12 + size of msg + (num of objs to move + (start address + end address + dst core + start dst)+)? + (num of incoming objs + (start dst + orig core)+)? + (num of large obj lists + (start address + lenght + start dst)+)?
76 * 13 (size is always 1 * sizeof(int))
77 * 14 + corenum + gcsendobjs + gcreceiveobjs (size if always 4 * sizeof(int))
78 * 15/16 + corenum (size is always 2 * sizeof(int))
79 * 17 (size is always 1 * sizeof(int))
80 * 18 (size if always 1 * sizeof(int))
81 * 19 + size of msg + corenum + gcsendobjs + gcreceiveobjs (size is always 5 * sizeof(int))
82 * 1a + obj's address (size is always 2 * sizeof(int))
83 * 1b + corenum ( size is always 2 * sizeof(int))
84 * 1c + obj's address + corenum (size is always 3 * sizeof(int))
85 * 1d + obj's address + dst address (size if always 3 * sizeof(int))
86 * 1e (size is always 1 * sizeof(int))
87 * 1f + size of msg + corenum + (num of large obj lists + (start address + length)+)?
90 TRANSOBJ = 0x0, // 0x0
99 REDIRECTGROUNT, // 0x9
101 REDIRECTRELEASE, // 0xb
102 STATUSCONFIRM, // 0xc
109 GCSTARTCOMPACT, // 0x12
110 GCSTARTFLUSH, // 0x13
111 GCFINISHMARK, // 0x14
112 GCFINISHCOMPACT, // 0x15
113 GCFINISHFLUSH, // 0x16
115 GCMARKCONFIRM, // 0x18
116 GCMARKREPORT, // 0x19
119 GCMAPREQUEST, // 0x1c
121 GCLOBJREQUEST, // 0x1e
127 // data structures of status for termination
128 int corestatus[NUMCORES]; // records status of each core
131 int numsendobjs[NUMCORES]; // records how many objects a core has sent out
132 int numreceiveobjs[NUMCORES]; // records how many objects a core has received
136 int self_numsendobjs;
137 int self_numreceiveobjs;
139 // data structures for locking
140 struct RuntimeHash * objRedirectLockTbl;
146 // data structures for waiting objs
147 struct Queue objqueue;
149 // data structures for shared memory allocation
151 #include "multicoregarbage.h"
153 #define BAMBOO_NUM_PAGES 1024 * 512
154 #define BAMBOO_PAGE_SIZE 4096
155 #define BAMBOO_SHARED_MEM_SIZE BAMBOO_PAGE_SIZE * BAMBOO_PAGE_SIZE
156 #define BAMBOO_BASE_VA 0xd000000
157 #define BAMBOO_SMEM_SIZE 16 * BAMBOO_PAGE_SIZE
160 mspace bamboo_free_msp;
161 mspace bamboo_cur_msp;
162 int bamboo_smem_size;
168 // data structures for profile mode
171 #define TASKINFOLENGTH 30000
172 //#define INTERRUPTINFOLENGTH 500
178 typedef struct task_info {
180 unsigned long long startTime;
181 unsigned long long endTime;
182 unsigned long long exitIndex;
183 struct Queue * newObjs;
186 /*typedef struct interrupt_info {
191 TaskInfo * taskInfoArray[TASKINFOLENGTH];
193 bool taskInfoOverflow;
194 /*InterruptInfo * interruptInfoArray[INTERRUPTINFOLENGTH];
195 int interruptInfoIndex;
196 bool interruptInfoOverflow;*/
197 int profilestatus[NUMCORES]; // records status of each core
200 #endif // #ifdef PROFILE
205 /////////////////////////////////////////////////////////////
207 ////////////////////////////////////////////////////////////
208 // these are functions should be implemented in //
209 // multicore runtime for any multicore processors //
210 ////////////////////////////////////////////////////////////
213 inline void initialization(void) __attribute__((always_inline));
214 inline void initCommunication(void) __attribute__((always_inline));
215 inline void fakeExecution(void) __attribute__((always_inline));
216 inline void terminate(void) __attribute__((always_inline));
218 // lock related functions
219 bool getreadlock(void* ptr);
220 void releasereadlock(void* ptr);
221 bool getwritelock(void* ptr);
222 void releasewritelock(void* ptr);
223 bool getwritelock_I(void* ptr);
224 void releasewritelock_I(void * ptr);
225 /* this function is to process lock requests.
226 * can only be invoked in receiveObject() */
227 // if return -1: the lock request is redirected
228 // 0: the lock request is approved
229 // 1: the lock request is denied
230 inline int processlockrequest(int locktype, int lock, int obj, int requestcore, int rootrequestcore, bool cache) __attribute_((always_inline));
231 inline void processlockrelease(int locktype, int lock, int redirectlock, bool isredirect) __attribute_((always_inline));
233 // msg related functions
234 inline void send_msg_1(int targetcore, unsigned long n0) __attribute__((always_inline));
235 inline void send_msg_2(int targetcore, unsigned long n0, unsigned long n1) __attribute__((always_inline));
236 inline void send_msg_3(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2) __attribute__((always_inline));
237 inline void send_msg_4(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2, unsigned long n3) __attribute__((always_inline));
238 inline void send_msg_5(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2, unsigned long n3, unsigned long n4) __attribute__((always_inline));
239 inline void send_msg_6(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2, unsigned long n3, unsigned long n4, unsigned long n5) __attribute__((always_inline));
240 inline void cache_msg_2(int targetcore, unsigned long n0, unsigned long n1) __attribute__((always_inline));
241 inline void cache_msg_3(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2) __attribute__((always_inline));
242 inline void cache_msg_4(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2, unsigned long n3) __attribute__((always_inline));
243 inline void cache_msg_5(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2, unsigned long n3, unsigned long n4) __attribute__((always_inline));
244 inline void cache_msg_6(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2, unsigned long n3, unsigned long n4, unsigned long n5) __attribute__((always_inline));
245 inline void transferObject(struct transObjInfo * transObj);
246 inline int receiveMsg(void) __attribute__((always_inline));
247 inline int receiveGCMsg(void) __attribute__((always_inline));
250 inline void profileTaskStart(char * taskname) __attribute__((always_inline));
251 inline void profileTaskEnd(void) __attribute__((always_inline));
252 void outputProfileData();
253 #endif // #ifdef PROFILE
254 ///////////////////////////////////////////////////////////
256 //////////////////////////////////////////////////////////////////////////////////////
257 // For each version of BAMBOO runtime, there should be a header file named //
258 // runtim_arch.h defining following MARCOS: //
259 // BAMBOO_TOTALCORE: the total # of cores available in the processor //
260 // BAMBOO_NUM_OF_CORE: the # of current residing core //
261 // BAMBOO_GET_NUM_OF_CORE(): compute the # of current residing core //
262 // BAMBOO_DEBUGPRINT(x): print out integer x //
263 // BAMBOO_DEBUGPRINT_REG(x): print out value of variable x //
264 // BAMBOO_LOCAL_MEM_CALLOC(x, y): allocate an array of x elements each of whose //
265 // size in bytes is y on local memory //
266 // BAMBOO_LOCAL_MEM_FREE(x): free space with ptr x on local memory //
267 // BAMBOO_SHARE_MEM_CALLOC(x, y): allocate an array of x elements each of whose //
268 // size in bytes is y on shared memory //
269 // BAMBOO_START_CRITICAL_SECTION_OBJ_QUEUE() //
270 // BAMBOO_CLOSE_CRITICAL_SECTION_OBJ_QUEUE(): locks for global data structures //
271 // related to obj queue //
272 // BAMBOO_START_CRITICAL_SECTION_STATUS() //
273 // BAMBOO_CLOSE_CRITICAL_SECTION_STATUS(): locks for global data structures //
274 // related to status data //
275 // BAMBOO_START_CRITICAL_SECTION_MSG() //
276 // BAMBOO_CLOSE_CRITICAL_SECTION_MSG(): locks for global data structures related //
278 // BAMBOO_START_CRITICAL_SECTION_LOCK() //
279 // BAMBOO_CLOSE_CRITICAL_SECTION_LOCK(): locks for global data structures related //
281 // BAMBOO_START_CRITICAL_SECTION_MEM() //
282 // BAMBOO_CLOSE_CRITICAL_SECTION_MEM(): locks for allocating memory //
283 // BAMBOO_START_CRITICAL_SECTION() //
284 // BAMBOO_CLOSE_CRITICAL_SECTION(): locks for all global data structures //
285 // BAMBOO_WAITING_FOR_LOCK(): routine executed while waiting for lock request //
287 // BAMBOO_CACHE_LINE_SIZE: the cache line size //
288 // BAMBOO_CACHE_LINE_MASK: mask for a cache line //
289 // BAMBOO_CACHE_FLUSH_RANGE(x, y): flush cache lines started at x with length y //
290 // BAMBOO_CACHE_FLUSH_ALL(): flush the whole cache of a core if necessary //
291 // BAMBOO_EXIT(x): exit routine //
292 // BAMBOO_MSG_AVAIL(): checking if there are msgs coming in //
293 // BAMBOO_GCMSG_AVAIL(): checking if there are gcmsgs coming in //
294 // BAMBOO_GET_EXE_TIME(): rountine to get current clock cycle number //
295 /////////////////////////////////////////////////////////////////////////////////////
297 #endif // #ifdef MULTICORE
298 #endif // #ifdef TASK
299 #endif // #ifndef MULTICORE_RUNTIME