bug fixes
[IRC.git] / Robust / src / Runtime / bamboo / multicoremsg.h
1 #ifndef BAMBOO_MULTICORE_MSG_H
2 #define BAMBOO_MULTICORE_MSG_H
3 #include "multicore.h"
4 #ifdef MULTICORE
5 // data structures for msgs
6 #define BAMBOO_OUT_BUF_LENGTH 2048
7 #define BAMBOO_OUT_BUF_MASK (0x7FF)
8 #define BAMBOO_MSG_BUF_LENGTH 2048
9 #define BAMBOO_MSG_BUF_MASK (0x7FF)
10 int msgdata[BAMBOO_MSG_BUF_LENGTH];
11 volatile int msgdataindex;
12 volatile int msgdatalast;
13 volatile bool msgdatafull;
14 int outmsgdata[BAMBOO_OUT_BUF_LENGTH];
15 int outmsgindex;
16 int outmsglast;
17 int outmsgleft;
18 volatile bool isMsgHanging;
19 volatile bool startflag;
20 #define MSG_INDEXINC_I() \
21   msgdataindex = (msgdataindex + 1) & (BAMBOO_MSG_BUF_MASK) 
22
23 #define MSG_LASTINDEXINC_I() \
24   msgdatalast = (msgdatalast + 1) & (BAMBOO_MSG_BUF_MASK)
25
26 #define MSG_CACHE_I(n) \
27   msgdata[msgdatalast] = (n); \
28   MSG_LASTINDEXINC_I()
29
30 #define MSG_REMAINSIZE_I(s)                                    \
31   if(msgdataindex < msgdatalast) {                             \
32     s = msgdatalast - msgdataindex;                            \
33   } else if((msgdataindex == msgdatalast) && (!msgdatafull)) { \
34     s = 0;                                                     \
35   } else {                                                     \
36     s = (BAMBOO_MSG_BUF_LENGTH) - msgdataindex + msgdatalast;  \
37   }
38
39 #define OUTMSG_INDEXINC() \
40   outmsgindex = (outmsgindex + 1) & (BAMBOO_OUT_BUF_MASK)
41
42 #define OUTMSG_LASTINDEXINC() \
43   outmsglast = (outmsglast + 1) & (BAMBOO_OUT_BUF_MASK); \
44   if(outmsglast == outmsgindex) { \
45     BAMBOO_EXIT(); \
46   }
47
48 #define OUTMSG_CACHE(n) \
49   outmsgdata[outmsglast] = (n); \
50   OUTMSG_LASTINDEXINC();
51
52 /* Message format:
53  *      type + Msgbody
54  * type: 1 -- transfer object
55  *       2 -- transfer stall msg
56  *       3 -- lock request
57  *       4 -- lock grount
58  *       5 -- lock deny
59  *       6 -- lock release
60  *       // add for profile info
61  *       7 -- transfer profile output msg
62  *       8 -- transfer profile output finish msg
63  *       // add for alias lock strategy
64  *       9 -- redirect lock request
65  *       a -- lock grant with redirect info
66  *       b -- lock deny with redirect info
67  *       c -- lock release with redirect info
68  *       d -- status confirm request
69  *       e -- status report msg
70  *       f -- terminate
71  *      10 -- requiring for new memory
72  *      11 -- response for new memory request
73  *      12 -- GC init phase start
74  *      13 -- GC start
75  *      14 -- compact phase start
76  *      15 -- update phase start
77  *      16 -- init phase finish
78  *      17 -- mark phase finish
79  *      18 -- compact phase finish
80  *      19 -- update phase finish
81  *      1a -- GC finish
82  *      1b -- marked phase finish confirm request
83  *      1c -- marked phase finish confirm response
84  *      1d -- markedObj msg
85  *      1e -- start moving objs msg
86  *      1f -- ask for mapping info of a markedObj
87  *      20 -- mapping info of a markedObj
88  *      21 -- large objs info request
89  *      22 -- large objs info response
90  *      23 -- large objs mapping info
91  *
92  * ObjMsg: 1 + size of msg + obj's address + (task index + param index)+
93  * StallMsg: 2 + corenum + sendobjs + receiveobjs
94  *             (size is always 4 * sizeof(int))
95  * LockMsg: 3 + lock type + obj pointer + lock + request core
96  *            (size is always 5 * sizeof(int))
97  *          4/5/6 + lock type + obj pointer + lock
98  *            (size is always 4 * sizeof(int))
99  *          9 + lock type + obj pointer +  redirect lock + root request core
100  *            + request core
101  *            (size is always 6 * sizeof(int))
102  *          a/b + lock type + obj pointer + redirect lock
103  *              (size is always 4 * sizeof(int))
104  *          c + lock type + lock + redirect lock
105  *            (size is always 4 * sizeof(int))
106  *          lock type: 0 -- read; 1 -- write
107  * ProfileMsg: 7 + totalexetime
108  *               (size is always 2 * sizeof(int))
109  *             8 
110  *               (size is always sizeof(int))
111  * StatusMsg: d (size is always 1 * sizeof(int))
112  *            e + status + corenum + sendobjs + receiveobjs
113  *              (size is always 5 * sizeof(int))
114  *            status: 0 -- stall; 1 -- busy
115  * TerminateMsg: f (size is always 1 * sizeof(int)
116  * MemoryMsg: 10 + size + corenum
117  *              (size is always 3 * sizeof(int))
118  *           11 + base_va + size
119  *              (size is always 3 * sizeof(int))
120  * GCMsg: 12/13 (size is always 1 * sizeof(int))
121  *        14 + size of msg + (num of objs to move + (start address
122  *           + end address + dst core + start dst)+)?
123  *           + (num of incoming objs + (start dst + orig core)+)?
124  *           + (num of large obj lists + (start address + lenght
125  *           + start dst)+)?
126  *        15 (size is always 1 * sizeof(int))
127  *        16 + corenum
128  *           (size is always 2 * sizeof(int))
129  *        17 + corenum + gcsendobjs + gcreceiveobjs
130  *           (size if always 4 * sizeof(int))
131  *        18 + corenum + fulfilled blocks num + (finish compact(1) + current
132  *           heap top)/(need mem(0) + mem need)
133  *           size is always 5 * sizeof(int))
134  *        19 + corenum
135  *              (size is always 2 * sizeof(int))
136  *        1a (size is always 1 * sizeof(int))
137  *        1b (size if always 1 * sizeof(int))
138  *        1c + size of msg + corenum + gcsendobjs + gcreceiveobjs
139  *           (size is always 5 * sizeof(int))
140  *        1d + obj's address + request core
141  *           (size is always 3 * sizeof(int))
142  *        1e + corenum + start addr + end addr
143  *           (size if always 4 * sizeof(int))
144  *        1f + obj's address + corenum
145  *           (size is always 3 * sizeof(int))
146  *        20 + obj's address + dst address
147  *           (size if always 3 * sizeof(int))
148  *        21 (size is always 1 * sizeof(int))
149  *        22 + size of msg + corenum + current heap size
150  *           + (num of large obj lists + (start address + length)+)?
151  *        23 + orig large obj ptr + new large obj ptr
152  *            (size is always 3 * sizeof(int))
153  */
154 typedef enum {
155   MSGSTART = 0x0,        // 0xD0
156   REQNOTIFYSTART,
157   NOTIFYSTART,
158   TRANSOBJ,              // 0xD1
159   TRANSTALL,             // 0xD2
160   LOCKREQUEST,           // 0xD3
161   LOCKGROUNT,            // 0xD4
162   LOCKDENY,              // 0xD5
163   LOCKRELEASE,           // 0xD6
164   PROFILEOUTPUT,         // 0xD7
165   PROFILEFINISH,         // 0xD8
166   REDIRECTLOCK,          // 0xD9
167   REDIRECTGROUNT,        // 0xDa
168   REDIRECTDENY,          // 0xDb
169   REDIRECTRELEASE,       // 0xDc
170   STATUSCONFIRM,         // 0xDd
171   STATUSREPORT,          // 0xDe
172   TERMINATE,             // 0xDf
173   MEMREQUEST,            // 0xE0
174   MEMRESPONSE,           // 0xE1
175 #if defined(MULTICORE_GC)||defined(PMC_GC)
176   GCINVOKE,              // 0xE2
177   GCSTARTPRE,            // 0xE3
178 #endif
179 #ifdef MULTICORE_GC
180   GCSTARTINIT,           // 0xE4
181   GCSTART,               // 0xE5
182   GCSTARTCOMPACT,        // 0xE6
183   GCSTARTUPDATE,         // 0xE7
184   GCFINISHPRE,           // 0xE8
185   GCFINISHINIT,          // 0xE9
186   GCFINISHMARK,          // 0xEa
187   GCFINISHCOMPACT,       // 0xEb
188   GCRETURNMEM,
189   GCFINISHUPDATE,        // 0xEc
190   GCFINISH,              // 0xEd
191   GCMARKCONFIRM,         // 0xEe
192   GCMARKREPORT,          // 0xEf
193   GCMARKEDOBJ,           // 0xF0
194   GCMOVESTART,           // 0xF1
195   GCLOBJREQUEST,         // 0xF2   
196   GCREQBLOCK,              
197   GCGRANTBLOCK,  
198   GCLOBJINFO,            // 0xF2
199 #ifdef GC_PROFILE
200   GCPROFILES,            // 0xF3
201 #endif // GC_PROFILE
202 #ifdef GC_CACHE_ADAPT
203   GCSTARTCACHEPOLICY,    // 0xF4
204   GCFINISHCACHEPOLICY,   // 0xF5
205   GCSTARTPREF,           // 0xF6
206   GCFINISHPREF,          // 0xF7
207 #endif // GC_CACHE_ADAPT
208 #endif // MULTICORE_GC
209   MSGEND
210 } MSGTYPE;
211
212 // msg related functions
213 void send_msg_1(int targetcore,unsigned long n0);
214 void send_msg_2(int targetcore,unsigned long n0,unsigned long n1);
215 void send_msg_3(int targetcore,unsigned long n0,unsigned long n1,unsigned long n2);
216 void send_msg_4(int targetcore,unsigned long n0,unsigned long n1,unsigned long n2,unsigned long n3);
217 void send_msg_5(int targetcore,unsigned long n0,unsigned long n1,unsigned long n2,unsigned long n3,unsigned long n4);
218 void send_msg_6(int targetcore,unsigned long n0,unsigned long n1,unsigned long n2,unsigned long n3,unsigned long n4,unsigned long n5);
219 void send_msg_1_I(int targetcore,unsigned long n0);
220 void send_msg_2_I(int targetcore,unsigned long n0,unsigned long n1);
221 void send_msg_3_I(int targetcore,unsigned long n0,unsigned long n1,unsigned long n2);
222 void send_msg_4_I(int targetcore,unsigned long n0,unsigned long n1,unsigned long n2,unsigned long n3);
223 void send_msg_5_I(int targetcore,unsigned long n0,unsigned long n1,unsigned long n2,unsigned long n3,unsigned long n4);
224 void send_msg_6_I(int targetcore,unsigned long n0,unsigned long n1,unsigned long n2,unsigned long n3,unsigned long n4,unsigned long n5);
225 void cache_msg_1_I(int targetcore,unsigned long n0);
226 void cache_msg_2_I(int targetcore,unsigned long n0,unsigned long n1);
227 void cache_msg_3_I(int targetcore,unsigned long n0,unsigned long n1,unsigned long n2);
228 void cache_msg_4_I(int targetcore,unsigned long n0,unsigned long n1,unsigned long n2,unsigned long n3);
229 void cache_msg_5_I(int targetcore,unsigned long n0,unsigned long n1,unsigned long n2,unsigned long n3,unsigned long n4);
230 void cache_msg_6_I(int targetcore,unsigned long n0,unsigned long n1,unsigned long n2,unsigned long n3,unsigned long n4,unsigned long n5);
231 int receiveMsg_I();
232 #ifdef TASK
233 void transferObject(struct transObjInfo * transObj);
234 #endif
235
236
237 #ifdef MULTICORE_GC
238 void transferMarkResults();
239 void processmsg_gcstartinit_I();
240 void processmsg_gcstart_I();
241 void processmsg_gcstartcompact_I();
242 void processmsg_gcstartupdate_I();
243 void processmsg_gcfinishpre_I();
244 void processmsg_gcfinishinit_I();
245 void processmsg_memrequest_I();
246 void processmsg_memresponse_I();
247 void processmsg_reqblock_I();
248 void processmsg_grantblock_I();
249 void processmsg_gcfinishmark_I();
250 void processmsg_returnmem_I();
251 void * handlegcfinishcompact_I(int cnum, unsigned int bytesneeded, unsigned int maxbytesneeded);
252 void processmsg_gcfinishcompact_I();
253 void processmsg_gcfinishupdate_I();
254 void processmsg_gcfinish_I();
255 void processmsg_gcmarkconfirm_I();
256 void processmsg_gcmarkreport_I();
257 void processmsg_gcmarkedobj_I();
258 void processmsg_gcmovestart_I();
259 void processmsg_gclobjinfo_I(unsigned int msglength);
260 #else
261 void processmsg_lockrequest_I();
262 void processmsg_lockrequest_I();
263 void processmsg_lockgrount_I();
264 void processmsg_lockdeny_I();
265 void processmsg_lockrelease_I();
266 void processmsg_redirectlock_I();
267 void processmsg_redirectgrount_I();
268 void processmsg_redirectdeny_I();
269 void processmsg_redirectrelease_I();
270 #endif 
271
272 unsigned int checkMsgLength_I(unsigned int realtype);
273 void processmsg_transtall_I();
274 void processmsg_statusconfirm_I();
275 void processmsg_statusreport_I();
276 void processmsg_terminate_I();
277 void processmsg_req_notify_start();
278 void processmsg_notify_start();
279 int receiveObject_I();
280
281
282 #ifdef GC_PROFILE
283 void processmsg_gcprofiles_I();
284 #endif
285
286 #ifdef GC_CACHE_ADAPT
287 void processmsg_gcstartcachepolicy_I();
288 void processmsg_gcfinishcachepolicy_I();
289 void processmsg_gcstartpref_I();
290 void processmsg_gcfinishpref_I();
291 #endif
292
293 #ifdef PROFILE
294 void processmsg_profileoutput_I();
295 void processmsg_profilefinish_I();
296 #endif
297 #endif // MULTICORE
298 #endif // BAMBOO_MULTICORE_MSG_H