Polish multicore code
[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 int msglength;
14 volatile bool msgdatafull;
15 int outmsgdata[BAMBOO_OUT_BUF_LENGTH];
16 int outmsgindex;
17 int outmsglast;
18 int outmsgleft;
19 volatile bool isMsgHanging;
20
21 #define MSG_INDEXINC_I() \
22   msgdataindex = (msgdataindex + 1) & (BAMBOO_MSG_BUF_MASK) 
23
24 #define MSG_LASTINDEXINC_I() \
25   msgdatalast = (msgdatalast + 1) & (BAMBOO_MSG_BUF_MASK)
26
27 #define MSG_CACHE_I(n) \
28   msgdata[msgdatalast] = (n); \
29   MSG_LASTINDEXINC_I()
30
31 // NOTE: if msgdataindex == msgdatalast, it always means that the buffer if
32 //       full. In the case that the buffer is empty, should never call this
33 //       MACRO
34 #define MSG_REMAINSIZE_I(s) \
35   if(msgdataindex < msgdatalast) { \
36     (*(int*)s) = msgdatalast - msgdataindex; \
37   } else if((msgdataindex == msgdatalast) && (!msgdatafull)) { \
38     (*(int*)s) = 0; \
39   } else { \
40     (*(int*)s) = (BAMBOO_MSG_BUF_LENGTH) - msgdataindex + msgdatalast; \
41   }
42
43 #define OUTMSG_INDEXINC() \
44   outmsgindex = (outmsgindex + 1) & (BAMBOO_OUT_BUF_MASK)
45
46 #define OUTMSG_LASTINDEXINC() \
47   outmsglast = (outmsglast + 1) & (BAMBOO_OUT_BUF_MASK); \
48   if(outmsglast == outmsgindex) { \
49     BAMBOO_EXIT(0xd101); \
50   }
51
52 #define OUTMSG_CACHE(n) \
53   outmsgdata[outmsglast] = (n); \
54   OUTMSG_LASTINDEXINC();
55
56 /* Message format:
57  *      type + Msgbody
58  * type: 1 -- transfer object
59  *       2 -- transfer stall msg
60  *       3 -- lock request
61  *       4 -- lock grount
62  *       5 -- lock deny
63  *       6 -- lock release
64  *       // add for profile info
65  *       7 -- transfer profile output msg
66  *       8 -- transfer profile output finish msg
67  *       // add for alias lock strategy
68  *       9 -- redirect lock request
69  *       a -- lock grant with redirect info
70  *       b -- lock deny with redirect info
71  *       c -- lock release with redirect info
72  *       d -- status confirm request
73  *       e -- status report msg
74  *       f -- terminate
75  *      10 -- requiring for new memory
76  *      11 -- response for new memory request
77  *      12 -- GC init phase start
78  *      13 -- GC start
79  *      14 -- compact phase start
80  *      15 -- flush phase start
81  *      16 -- init phase finish
82  *      17 -- mark phase finish
83  *      18 -- compact phase finish
84  *      19 -- flush phase finish
85  *      1a -- GC finish
86  *      1b -- marked phase finish confirm request
87  *      1c -- marked phase finish confirm response
88  *      1d -- markedObj msg
89  *      1e -- start moving objs msg
90  *      1f -- ask for mapping info of a markedObj
91  *      20 -- mapping info of a markedObj
92  *      21 -- large objs info request
93  *      22 -- large objs info response
94  *      23 -- large objs mapping info
95  *
96  * ObjMsg: 1 + size of msg + obj's address + (task index + param index)+
97  * StallMsg: 2 + corenum + sendobjs + receiveobjs
98  *             (size is always 4 * sizeof(int))
99  * LockMsg: 3 + lock type + obj pointer + lock + request core
100  *            (size is always 5 * sizeof(int))
101  *          4/5/6 + lock type + obj pointer + lock
102  *            (size is always 4 * sizeof(int))
103  *          9 + lock type + obj pointer +  redirect lock + root request core
104  *            + request core
105  *            (size is always 6 * sizeof(int))
106  *          a/b + lock type + obj pointer + redirect lock
107  *              (size is always 4 * sizeof(int))
108  *          c + lock type + lock + redirect lock
109  *            (size is always 4 * sizeof(int))
110  *          lock type: 0 -- read; 1 -- write
111  * ProfileMsg: 7 + totalexetime
112  *               (size is always 2 * sizeof(int))
113  *             8 + corenum
114  *               (size is always 2 * sizeof(int))
115  * StatusMsg: d (size is always 1 * sizeof(int))
116  *            e + status + corenum + sendobjs + receiveobjs
117  *              (size is always 5 * sizeof(int))
118  *            status: 0 -- stall; 1 -- busy
119  * TerminateMsg: f (size is always 1 * sizeof(int)
120  * MemoryMsg: 10 + size + corenum
121  *              (size is always 3 * sizeof(int))
122  *           11 + base_va + size
123  *              (size is always 3 * sizeof(int))
124  * GCMsg: 12/13 (size is always 1 * sizeof(int))
125  *        14 + size of msg + (num of objs to move + (start address
126  *           + end address + dst core + start dst)+)?
127  *           + (num of incoming objs + (start dst + orig core)+)?
128  *           + (num of large obj lists + (start address + lenght
129  *           + start dst)+)?
130  *        15 (size is always 1 * sizeof(int))
131  *        16 + corenum
132  *           (size is always 2 * sizeof(int))
133  *        17 + corenum + gcsendobjs + gcreceiveobjs
134  *           (size if always 4 * sizeof(int))
135  *        18 + corenum + fulfilled blocks num + (finish compact(1) + current
136  *           heap top)/(need mem(0) + mem need)
137  *           size is always 5 * sizeof(int))
138  *        19 + corenum
139  *              (size is always 2 * sizeof(int))
140  *        1a (size is always 1 * sizeof(int))
141  *        1b (size if always 1 * sizeof(int))
142  *        1c + size of msg + corenum + gcsendobjs + gcreceiveobjs
143  *           (size is always 5 * sizeof(int))
144  *        1d + obj's address + request core
145  *           (size is always 3 * sizeof(int))
146  *        1e + corenum + start addr + end addr
147  *           (size if always 4 * sizeof(int))
148  *        1f + obj's address + corenum
149  *           (size is always 3 * sizeof(int))
150  *        20 + obj's address + dst address
151  *           (size if always 3 * sizeof(int))
152  *        21 (size is always 1 * sizeof(int))
153  *        22 + size of msg + corenum + current heap size
154  *           + (num of large obj lists + (start address + length)+)?
155  *        23 + orig large obj ptr + new large obj ptr
156  *            (size is always 3 * sizeof(int))
157  */
158 typedef enum {
159   MSGSTART = 0xD0,       // 0xD0
160   TRANSOBJ,              // 0xD1
161   TRANSTALL,             // 0xD2
162   LOCKREQUEST,           // 0xD3
163   LOCKGROUNT,            // 0xD4
164   LOCKDENY,              // 0xD5
165   LOCKRELEASE,           // 0xD6
166   PROFILEOUTPUT,         // 0xD7
167   PROFILEFINISH,         // 0xD8
168   REDIRECTLOCK,          // 0xD9
169   REDIRECTGROUNT,        // 0xDa
170   REDIRECTDENY,          // 0xDb
171   REDIRECTRELEASE,       // 0xDc
172   STATUSCONFIRM,         // 0xDd
173   STATUSREPORT,          // 0xDe
174   TERMINATE,             // 0xDf
175   MEMREQUEST,            // 0xE0
176   MEMRESPONSE,           // 0xE1
177 #ifdef MULTICORE_GC
178   GCSTARTPRE,            // 0xE2
179   GCSTARTINIT,           // 0xE3
180   GCSTART,               // 0xE4
181   GCSTARTCOMPACT,        // 0xE5
182   GCSTARTFLUSH,          // 0xE6
183   GCFINISHPRE,           // 0xE7
184   GCFINISHINIT,          // 0xE8
185   GCFINISHMARK,          // 0xE9
186   GCFINISHCOMPACT,       // 0xEa
187   GCFINISHFLUSH,         // 0xEb
188   GCFINISH,              // 0xEc
189   GCMARKCONFIRM,         // 0xEd
190   GCMARKREPORT,          // 0xEe
191   GCMARKEDOBJ,           // 0xEf
192   GCMOVESTART,           // 0xF0
193   GCLOBJREQUEST,         // 0xF1   
194   GCLOBJINFO,            // 0xF2
195 #ifdef GC_PROFILE
196   GCPROFILES,            // 0xF3
197 #endif // GC_PROFILE
198 #ifdef GC_CACHE_ADAPT
199   GCSTARTPOSTINIT,       // 0xF4
200   GCSTARTPREF,           // 0xF5
201   GCFINISHPOSTINIT,      // 0xF6
202   GCFINISHPREF,          // 0xF7
203 #endif // GC_CACHE_ADAPT
204 #endif // MULTICORE_GC
205   MSGEND
206 } MSGTYPE;
207
208 // msg related functions
209 INLINE void send_hanging_msg(bool isInterrupt);
210 INLINE void send_msg_1(int targetcore,
211                        unsigned long n0,
212                        bool isInterrupt);
213 INLINE void send_msg_2(int targetcore,
214                        unsigned long n0,
215                        unsigned long n1,
216                        bool isInterrupt);
217 INLINE void send_msg_3(int targetcore,
218                        unsigned long n0,
219                        unsigned long n1,
220                        unsigned long n2,
221                        bool isInterrupt);
222 INLINE void send_msg_4(int targetcore,
223                        unsigned long n0,
224                        unsigned long n1,
225                        unsigned long n2,
226                        unsigned long n3,
227                        bool isInterrupt);
228 INLINE void send_msg_5(int targetcore,
229                        unsigned long n0,
230                        unsigned long n1,
231                        unsigned long n2,
232                        unsigned long n3,
233                        unsigned long n4,
234                        bool isInterrupt);
235 INLINE void send_msg_6(int targetcore,
236                        unsigned long n0,
237                        unsigned long n1,
238                        unsigned long n2,
239                        unsigned long n3,
240                        unsigned long n4,
241                        unsigned long n5,
242                        bool isInterrupt);
243 INLINE void cache_msg_1(int targetcore,
244                         unsigned long n0);
245 INLINE void cache_msg_2(int targetcore,
246                         unsigned long n0,
247                         unsigned long n1);
248 INLINE void cache_msg_3(int targetcore,
249                         unsigned long n0,
250                         unsigned long n1,
251                         unsigned long n2);
252 INLINE void cache_msg_4(int targetcore,
253                         unsigned long n0,
254                         unsigned long n1,
255                         unsigned long n2,
256                         unsigned long n3);
257 INLINE void cache_msg_5(int targetcore,
258                         unsigned long n0,
259                         unsigned long n1,
260                         unsigned long n2,
261                         unsigned long n3,
262                         unsigned long n4);
263 INLINE void cache_msg_6(int targetcore,
264                         unsigned long n0,
265                         unsigned long n1,
266                         unsigned long n2,
267                         unsigned long n3,
268                         unsigned long n4,
269                         unsigned long n5);
270 INLINE int receiveMsg(unsigned int send_port_pending);
271 #ifdef TASK
272 INLINE void transferObject(struct transObjInfo * transObj);
273 #endif
274
275 #ifdef MULTICORE_GC
276 INLINE void transferMarkResults();
277 #endif 
278
279 #endif // MULTICORE
280 #endif // BAMBOO_MULTICORE_MSG_H