1 #ifndef MULTICORE_RUNTIME
2 #define MULTICORE_RUNTIME
5 #define INLINE inline __attribute__((always_inline))
8 ////////////////////////////////////////////////////////////////
10 ///////////////////////////////////////////////////////////////
12 // data structures for msgs
13 #define BAMBOO_OUT_BUF_LENGTH 300
14 #define BAMBOO_MSG_BUF_LENGTH 30
15 int msgdata[BAMBOO_MSG_BUF_LENGTH];
19 int outmsgdata[BAMBOO_OUT_BUF_LENGTH];
24 volatile bool isMsgSending;
26 #define OUTMSG_INDEXINC() \
27 outmsgindex = (outmsgindex + 1) % (BAMBOO_OUT_BUF_LENGTH)
29 #define OUTMSG_LASTINDEXINC() \
30 outmsglast = (outmsglast + 1) % (BAMBOO_OUT_BUF_LENGTH); \
31 if(outmsglast == outmsgindex) { \
32 BAMBOO_EXIT(0xd001); \
35 #define OUTMSG_CACHE(n) \
36 outmsgdata[outmsglast] = (n); \
37 OUTMSG_LASTINDEXINC();
41 * type: 0 -- transfer object
42 * 1 -- transfer stall msg
47 * // add for profile info
48 * 6 -- transfer profile output msg
49 * 7 -- transfer profile output finish msg
50 * // add for alias lock strategy
51 * 8 -- redirect lock request
52 * 9 -- lock grant with redirect info
53 * a -- lock deny with redirect info
54 * b -- lock release with redirect info
55 * c -- status confirm request
56 * d -- status report msg
58 * f -- requiring for new memory
59 * 10 -- response for new memory request
60 * 11 -- GC init phase start
62 * 13 -- compact phase start
63 * 14 -- flush phase start
64 * 15 -- init phase finish
65 * 16 -- mark phase finish
66 * 17 -- compact phase finish
67 * 18 -- flush phase finish
69 * 1a -- marked phase finish confirm request
70 * 1b -- marked phase finish confirm response
72 * 1d -- start moving objs msg
73 * 1e -- ask for mapping info of a markedObj
74 * 1f -- mapping info of a markedObj
75 * 20 -- large objs info request
76 * 21 -- large objs info response
77 * 22 -- large objs mapping info
79 * ObjMsg: 0 + size of msg + obj's address + (task index + param index)+
80 * StallMsg: 1 + corenum + sendobjs + receiveobjs
81 * (size is always 4 * sizeof(int))
82 * LockMsg: 2 + lock type + obj pointer + lock + request core
83 * (size is always 5 * sizeof(int))
84 * 3/4/5 + lock type + obj pointer + lock
85 * (size is always 4 * sizeof(int))
86 * 8 + lock type + obj pointer + redirect lock + root request core
88 * (size is always 6 * sizeof(int))
89 * 9/a + lock type + obj pointer + redirect lock
90 * (size is always 4 * sizeof(int))
91 * b + lock type + lock + redirect lock
92 * (size is always 4 * sizeof(int))
93 * lock type: 0 -- read; 1 -- write
94 * ProfileMsg: 6 + totalexetime
95 * (size is always 2 * sizeof(int))
97 * (size is always 2 * sizeof(int))
98 * StatusMsg: c (size is always 1 * sizeof(int))
99 * d + status + corenum + sendobjs + receiveobjs
100 * (size is always 5 * sizeof(int))
101 * status: 0 -- stall; 1 -- busy
102 * TerminateMsg: e (size is always 1 * sizeof(int)
103 * MemoryMsg: f + size + corenum
104 * (size is always 3 * sizeof(int))
105 * 10 + base_va + size
106 * (size is always 3 * sizeof(int))
107 * GCMsg: 11/12 (size is always 1 * sizeof(int))
108 * 13 + size of msg + (num of objs to move + (start address
109 * + end address + dst core + start dst)+)?
110 * + (num of incoming objs + (start dst + orig core)+)?
111 * + (num of large obj lists + (start address + lenght
113 * 14 (size is always 1 * sizeof(int))
115 * (size is always 2 * sizeof(int))
116 * 16 + corenum + gcsendobjs + gcreceiveobjs
117 * (size if always 4 * sizeof(int))
118 * 17 + corenum + fulfilled blocks num + (finish compact(1) + current
119 * heap top)/(need mem(0) + mem need)
120 * size is always 5 * sizeof(int))
122 * (size is always 2 * sizeof(int))
123 * 19 (size is always 1 * sizeof(int))
124 * 1a (size if always 1 * sizeof(int))
125 * 1b + size of msg + corenum + gcsendobjs + gcreceiveobjs
126 * (size is always 5 * sizeof(int))
128 * (size is always 2 * sizeof(int))
129 * 1d + corenum + start addr + end addr
130 * (size if always 4 * sizeof(int))
131 * 1e + obj's address + corenum
132 * (size is always 3 * sizeof(int))
133 * 1f + obj's address + dst address
134 * (size if always 3 * sizeof(int))
135 * 20 (size is always 1 * sizeof(int))
136 * 21 + size of msg + corenum + current heap size
137 * + (num of large obj lists + (start address + length)+)?
138 * 22 + orig large obj ptr + new large obj ptr
139 * (size is always 3 * sizeof(int))
142 TRANSOBJ = 0x0, // 0x0
148 PROFILEOUTPUT, // 0x6
149 PROFILEFINISH, // 0x7
151 REDIRECTGROUNT, // 0x9
153 REDIRECTRELEASE, // 0xb
154 STATUSCONFIRM, // 0xc
162 GCSTARTCOMPACT, // 0x13
163 GCSTARTFLUSH, // 0x14
164 GCFINISHINIT, // 0x15
165 GCFINISHMARK, // 0x16
166 GCFINISHCOMPACT, // 0x17
167 GCFINISHFLUSH, // 0x18
169 GCMARKCONFIRM, // 0x1a
170 GCMARKREPORT, // 0x1b
173 GCMAPREQUEST, // 0x1e
175 GCLOBJREQUEST, // 0x20
177 GCLOBJMAPPING, // 0x22
182 // data structures of status for termination
183 int corestatus[NUMCORES]; // records status of each core
186 int numsendobjs[NUMCORES]; // records how many objects a core has sent out
187 int numreceiveobjs[NUMCORES]; // records how many objects a core has received
188 volatile int numconfirm;
189 volatile bool waitconfirm;
191 int self_numsendobjs;
192 int self_numreceiveobjs;
194 // get rid of lock msgs for GC version
196 // data structures for locking
197 struct RuntimeHash locktable;
198 static struct RuntimeHash* locktbl = &locktable;
199 struct RuntimeHash * lockRedirectTbl;
200 struct RuntimeHash * objRedirectLockTbl;
211 // data structures for waiting objs
212 struct Queue objqueue;
213 struct Queue * totransobjqueue; // queue to hold objs to be transferred
214 // should be cleared whenever enter a task
216 // data structures for shared memory allocation
217 #define BAMBOO_BASE_VA 0xd000000
219 #include "structdefs.h"
220 #define BAMBOO_NUM_PAGES (NUMCORES*(2+1)+3)
221 #define BAMBOO_PAGE_SIZE (64 * 64)
222 #define BAMBOO_SMEM_SIZE (BAMBOO_PAGE_SIZE)
224 #define BAMBOO_NUM_PAGES (1024 * 512 * 4)
225 #define BAMBOO_PAGE_SIZE (4096)
226 #define BAMBOO_SMEM_SIZE (16 * BAMBOO_PAGE_SIZE)
228 #define BAMBOO_SHARED_MEM_SIZE (BAMBOO_PAGE_SIZE * BAMBOO_NUM_PAGES)
231 #include "multicoregarbage.h"
234 SMEMLOCAL = 0x0, // 0x0, using local mem only
235 SMEMFIXED, // 0x1, use local mem in lower address space(1 block only)
236 // and global mem in higher address space
237 SMEMMIXED, // 0x2, like FIXED mode but use a threshold to control
238 SMEMGLOBAL, // 0x3, using global mem only
242 SMEMSTRATEGY bamboo_smem_mode; //-DSMEML: LOCAL; -DSMEMF: FIXED;
243 //-DSMEMM: MIXED; -DSMEMG: GLOBAL;
250 struct freeMemItem * next;
254 struct freeMemItem * head;
255 struct freeMemItem * tail;
258 struct freeMemList * bamboo_free_mem_list;
260 volatile mspace bamboo_free_msp;
262 volatile bool smemflag;
263 volatile INTPTR bamboo_cur_msp;
264 volatile int bamboo_smem_size;
269 // data structures for profile mode
272 #define TASKINFOLENGTH 30000
273 //#define INTERRUPTINFOLENGTH 500
279 typedef struct task_info {
281 unsigned long long startTime;
282 unsigned long long endTime;
283 unsigned long long exitIndex;
284 struct Queue * newObjs;
287 /*typedef struct interrupt_info {
292 TaskInfo * taskInfoArray[TASKINFOLENGTH];
294 bool taskInfoOverflow;
295 /*InterruptInfo * interruptInfoArray[INTERRUPTINFOLENGTH];
296 int interruptInfoIndex;
297 bool interruptInfoOverflow;*/
298 int profilestatus[NUMCORES]; // records status of each core
301 #endif // #ifdef PROFILE
306 /////////////////////////////////////////////////////////////
308 ////////////////////////////////////////////////////////////
309 // these are functions should be implemented in //
310 // multicore runtime for any multicore processors //
311 ////////////////////////////////////////////////////////////
314 INLINE void initialization(void);
315 INLINE void initCommunication(void);
316 INLINE void fakeExecution(void);
317 INLINE void terminate(void);
318 INLINE void initlock(struct ___Object___ * v);
320 // lock related functions
321 bool getreadlock(void* ptr);
322 void releasereadlock(void* ptr);
323 bool getwritelock(void* ptr);
324 void releasewritelock(void* ptr);
325 bool getwritelock_I(void* ptr);
326 void releasewritelock_I(void * ptr);
328 void releasewritelock_r(void * lock, void * redirectlock);
330 /* this function is to process lock requests.
331 * can only be invoked in receiveObject() */
332 // if return -1: the lock request is redirected
333 // 0: the lock request is approved
334 // 1: the lock request is denied
335 INLINE int processlockrequest(int locktype,
341 INLINE void processlockrelease(int locktype,
346 // msg related functions
347 INLINE void send_hanging_msg();
348 INLINE void send_msg_1(int targetcore,
350 INLINE void send_msg_2(int targetcore,
353 INLINE void send_msg_3(int targetcore,
357 INLINE void send_msg_4(int targetcore,
362 INLINE void send_msg_5(int targetcore,
368 INLINE void send_msg_6(int targetcore,
375 INLINE void cache_msg_2(int targetcore,
378 INLINE void cache_msg_3(int targetcore,
382 INLINE void cache_msg_4(int targetcore,
387 INLINE void cache_msg_5(int targetcore,
393 INLINE void cache_msg_6(int targetcore,
400 INLINE void transferObject(struct transObjInfo * transObj);
401 INLINE int receiveMsg(void);
404 INLINE void transferMarkResults();
408 INLINE void profileTaskStart(char * taskname);
409 INLINE void profileTaskEnd(void);
410 void outputProfileData();
411 #endif // #ifdef PROFILE
412 ///////////////////////////////////////////////////////////
414 /////////////////////////////////////////////////////////////////////////////
415 // For each version of BAMBOO runtime, there should be a header file named //
416 // runtim_arch.h defining following MARCOS: //
417 // BAMBOO_TOTALCORE: the total # of cores available in the processor //
418 // BAMBOO_NUM_OF_CORE: the # of current residing core //
419 // BAMBOO_GET_NUM_OF_CORE(): compute the # of current residing core //
420 // BAMBOO_DEBUGPRINT(x): print out integer x //
421 // BAMBOO_DEBUGPRINT_REG(x): print out value of variable x //
422 // BAMBOO_LOCAL_MEM_CALLOC(x, y): allocate an array of x elements each of //
423 // whose size in bytes is y on local memory //
424 // BAMBOO_LOCAL_MEM_FREE(x): free space with ptr x on local memory //
425 // BAMBOO_SHARE_MEM_CALLOC(x, y): allocate an array of x elements each of //
426 // whose size in bytes is y on shared memory//
427 // BAMBOO_START_CRITICAL_SECTION_OBJ_QUEUE() //
428 // BAMBOO_CLOSE_CRITICAL_SECTION_OBJ_QUEUE(): locks for global data //
429 // structures related to obj //
431 // BAMBOO_START_CRITICAL_SECTION_STATUS() //
432 // BAMBOO_CLOSE_CRITICAL_SECTION_STATUS(): locks for global data structures//
433 // related to status data //
434 // BAMBOO_START_CRITICAL_SECTION_MSG() //
435 // BAMBOO_CLOSE_CRITICAL_SECTION_MSG(): locks for global data structures //
436 // related to msg data //
437 // BAMBOO_START_CRITICAL_SECTION_LOCK() //
438 // BAMBOO_CLOSE_CRITICAL_SECTION_LOCK(): locks for global data structures //
439 // related to lock table //
440 // BAMBOO_START_CRITICAL_SECTION_MEM() //
441 // BAMBOO_CLOSE_CRITICAL_SECTION_MEM(): locks for allocating memory //
442 // BAMBOO_START_CRITICAL_SECTION() //
443 // BAMBOO_CLOSE_CRITICAL_SECTION(): locks for all global data structures //
444 // BAMBOO_WAITING_FOR_LOCK(): routine executed while waiting for lock //
445 // request response //
446 // BAMBOO_CACHE_LINE_SIZE: the cache line size //
447 // BAMBOO_CACHE_LINE_MASK: mask for a cache line //
448 // BAMBOO_CACHE_FLUSH_RANGE(x, y): flush cache lines started at x with //
450 // BAMBOO_CACHE_FLUSH_ALL(): flush the whole cache of a core if necessary //
451 // BAMBOO_EXIT(x): exit routine //
452 // BAMBOO_MSG_AVAIL(): checking if there are msgs coming in //
453 // BAMBOO_GCMSG_AVAIL(): checking if there are gcmsgs coming in //
454 // BAMBOO_GET_EXE_TIME(): rountine to get current clock cycle number //
455 /////////////////////////////////////////////////////////////////////////////
457 #endif // #ifdef MULTICORE
458 #endif // #ifdef TASK
459 #endif // #ifndef MULTICORE_RUNTIME