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 + sendobjs + receiveobjs (size is always 5 * 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 + current heap size + (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 // get rid of lock msgs for GC version
141 // data structures for locking
142 struct RuntimeHash * objRedirectLockTbl;
149 // data structures for waiting objs
150 struct Queue objqueue;
152 // data structures for shared memory allocation
154 #include "multicoregarbage.h"
156 #define BAMBOO_NUM_PAGES 1024 * 512
157 #define BAMBOO_PAGE_SIZE 4096
158 #define BAMBOO_SHARED_MEM_SIZE BAMBOO_PAGE_SIZE * BAMBOO_PAGE_SIZE
159 #define BAMBOO_BASE_VA 0xd000000
160 #define BAMBOO_SMEM_SIZE 16 * BAMBOO_PAGE_SIZE
163 mspace bamboo_free_msp;
164 mspace bamboo_cur_msp;
165 int bamboo_smem_size;
171 // data structures for profile mode
174 #define TASKINFOLENGTH 30000
175 //#define INTERRUPTINFOLENGTH 500
181 typedef struct task_info {
183 unsigned long long startTime;
184 unsigned long long endTime;
185 unsigned long long exitIndex;
186 struct Queue * newObjs;
189 /*typedef struct interrupt_info {
194 TaskInfo * taskInfoArray[TASKINFOLENGTH];
196 bool taskInfoOverflow;
197 /*InterruptInfo * interruptInfoArray[INTERRUPTINFOLENGTH];
198 int interruptInfoIndex;
199 bool interruptInfoOverflow;*/
200 int profilestatus[NUMCORES]; // records status of each core
203 #endif // #ifdef PROFILE
208 /////////////////////////////////////////////////////////////
210 ////////////////////////////////////////////////////////////
211 // these are functions should be implemented in //
212 // multicore runtime for any multicore processors //
213 ////////////////////////////////////////////////////////////
216 inline void initialization(void) __attribute__((always_inline));
217 inline void initCommunication(void) __attribute__((always_inline));
218 inline void fakeExecution(void) __attribute__((always_inline));
219 inline void terminate(void) __attribute__((always_inline));
221 // lock related functions
222 bool getreadlock(void* ptr);
223 void releasereadlock(void* ptr);
224 bool getwritelock(void* ptr);
225 void releasewritelock(void* ptr);
226 bool getwritelock_I(void* ptr);
227 void releasewritelock_I(void * ptr);
228 /* this function is to process lock requests.
229 * can only be invoked in receiveObject() */
230 // if return -1: the lock request is redirected
231 // 0: the lock request is approved
232 // 1: the lock request is denied
233 inline int processlockrequest(int locktype, int lock, int obj, int requestcore, int rootrequestcore, bool cache) __attribute_((always_inline));
234 inline void processlockrelease(int locktype, int lock, int redirectlock, bool isredirect) __attribute_((always_inline));
236 // msg related functions
237 inline void send_msg_1(int targetcore, unsigned long n0) __attribute__((always_inline));
238 inline void send_msg_2(int targetcore, unsigned long n0, unsigned long n1) __attribute__((always_inline));
239 inline void send_msg_3(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2) __attribute__((always_inline));
240 inline void send_msg_4(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2, unsigned long n3) __attribute__((always_inline));
241 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));
242 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));
243 inline void cache_msg_2(int targetcore, unsigned long n0, unsigned long n1) __attribute__((always_inline));
244 inline void cache_msg_3(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2) __attribute__((always_inline));
245 inline void cache_msg_4(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2, unsigned long n3) __attribute__((always_inline));
246 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));
247 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));
248 inline void transferObject(struct transObjInfo * transObj);
249 inline int receiveMsg(void) __attribute__((always_inline));
252 inline void profileTaskStart(char * taskname) __attribute__((always_inline));
253 inline void profileTaskEnd(void) __attribute__((always_inline));
254 void outputProfileData();
255 #endif // #ifdef PROFILE
256 ///////////////////////////////////////////////////////////
258 //////////////////////////////////////////////////////////////////////////////////////
259 // For each version of BAMBOO runtime, there should be a header file named //
260 // runtim_arch.h defining following MARCOS: //
261 // BAMBOO_TOTALCORE: the total # of cores available in the processor //
262 // BAMBOO_NUM_OF_CORE: the # of current residing core //
263 // BAMBOO_GET_NUM_OF_CORE(): compute the # of current residing core //
264 // BAMBOO_DEBUGPRINT(x): print out integer x //
265 // BAMBOO_DEBUGPRINT_REG(x): print out value of variable x //
266 // BAMBOO_LOCAL_MEM_CALLOC(x, y): allocate an array of x elements each of whose //
267 // size in bytes is y on local memory //
268 // BAMBOO_LOCAL_MEM_FREE(x): free space with ptr x on local memory //
269 // BAMBOO_SHARE_MEM_CALLOC(x, y): allocate an array of x elements each of whose //
270 // size in bytes is y on shared memory //
271 // BAMBOO_START_CRITICAL_SECTION_OBJ_QUEUE() //
272 // BAMBOO_CLOSE_CRITICAL_SECTION_OBJ_QUEUE(): locks for global data structures //
273 // related to obj queue //
274 // BAMBOO_START_CRITICAL_SECTION_STATUS() //
275 // BAMBOO_CLOSE_CRITICAL_SECTION_STATUS(): locks for global data structures //
276 // related to status data //
277 // BAMBOO_START_CRITICAL_SECTION_MSG() //
278 // BAMBOO_CLOSE_CRITICAL_SECTION_MSG(): locks for global data structures related //
280 // BAMBOO_START_CRITICAL_SECTION_LOCK() //
281 // BAMBOO_CLOSE_CRITICAL_SECTION_LOCK(): locks for global data structures related //
283 // BAMBOO_START_CRITICAL_SECTION_MEM() //
284 // BAMBOO_CLOSE_CRITICAL_SECTION_MEM(): locks for allocating memory //
285 // BAMBOO_START_CRITICAL_SECTION() //
286 // BAMBOO_CLOSE_CRITICAL_SECTION(): locks for all global data structures //
287 // BAMBOO_WAITING_FOR_LOCK(): routine executed while waiting for lock request //
289 // BAMBOO_CACHE_LINE_SIZE: the cache line size //
290 // BAMBOO_CACHE_LINE_MASK: mask for a cache line //
291 // BAMBOO_CACHE_FLUSH_RANGE(x, y): flush cache lines started at x with length y //
292 // BAMBOO_CACHE_FLUSH_ALL(): flush the whole cache of a core if necessary //
293 // BAMBOO_EXIT(x): exit routine //
294 // BAMBOO_MSG_AVAIL(): checking if there are msgs coming in //
295 // BAMBOO_GCMSG_AVAIL(): checking if there are gcmsgs coming in //
296 // BAMBOO_GET_EXE_TIME(): rountine to get current clock cycle number //
297 /////////////////////////////////////////////////////////////////////////////////////
299 #endif // #ifdef MULTICORE
300 #endif // #ifdef TASK
301 #endif // #ifndef MULTICORE_RUNTIME