Some code clean and make the cache adapt version compile
[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
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     (*(int*)s) = msgdatalast - msgdataindex; \
33   } else if((msgdataindex == msgdatalast) && (!msgdatafull)) { \
34     (*(int*)s) = 0; \
35   } else { \
36     (*(int*)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 -- flush phase start
77  *      16 -- init phase finish
78  *      17 -- mark phase finish
79  *      18 -- compact phase finish
80  *      19 -- flush 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   TRANSOBJ,              // 0xD1
157   TRANSTALL,             // 0xD2
158   LOCKREQUEST,           // 0xD3
159   LOCKGROUNT,            // 0xD4
160   LOCKDENY,              // 0xD5
161   LOCKRELEASE,           // 0xD6
162   PROFILEOUTPUT,         // 0xD7
163   PROFILEFINISH,         // 0xD8
164   REDIRECTLOCK,          // 0xD9
165   REDIRECTGROUNT,        // 0xDa
166   REDIRECTDENY,          // 0xDb
167   REDIRECTRELEASE,       // 0xDc
168   STATUSCONFIRM,         // 0xDd
169   STATUSREPORT,          // 0xDe
170   TERMINATE,             // 0xDf
171   MEMREQUEST,            // 0xE0
172   MEMRESPONSE,           // 0xE1
173 #ifdef MULTICORE_GC
174   GCSTARTPRE,            // 0xE2
175   GCSTARTINIT,           // 0xE3
176   GCSTART,               // 0xE4
177   GCSTARTCOMPACT,        // 0xE5
178   GCSTARTFLUSH,          // 0xE6
179   GCFINISHPRE,           // 0xE7
180   GCFINISHINIT,          // 0xE8
181   GCFINISHMARK,          // 0xE9
182   GCFINISHCOMPACT,       // 0xEa
183   GCFINISHFLUSH,         // 0xEb
184   GCFINISH,              // 0xEc
185   GCMARKCONFIRM,         // 0xEd
186   GCMARKREPORT,          // 0xEe
187   GCMARKEDOBJ,           // 0xEf
188   GCMOVESTART,           // 0xF0
189   GCLOBJREQUEST,         // 0xF1   
190   GCLOBJINFO,            // 0xF2
191 #ifdef GC_PROFILE
192   GCPROFILES,            // 0xF3
193 #endif // GC_PROFILE
194 #ifdef GC_CACHE_ADAPT
195   GCSTARTPREF,           // 0xF4
196   GCFINISHPREF,          // 0xF5
197 #endif // GC_CACHE_ADAPT
198 #endif // MULTICORE_GC
199   MSGEND
200 } MSGTYPE;
201
202 // msg related functions
203 void send_msg_1(int targetcore,unsigned long n0);
204 void send_msg_2(int targetcore,unsigned long n0,unsigned long n1);
205 void send_msg_3(int targetcore,unsigned long n0,unsigned long n1,unsigned long n2);
206 void send_msg_4(int targetcore,unsigned long n0,unsigned long n1,unsigned long n2,unsigned long n3);
207 void send_msg_5(int targetcore,unsigned long n0,unsigned long n1,unsigned long n2,unsigned long n3,unsigned long n4);
208 void send_msg_6(int targetcore,unsigned long n0,unsigned long n1,unsigned long n2,unsigned long n3,unsigned long n4,unsigned long n5);
209 void send_msg_1_I(int targetcore,unsigned long n0);
210 void send_msg_2_I(int targetcore,unsigned long n0,unsigned long n1);
211 void send_msg_3_I(int targetcore,unsigned long n0,unsigned long n1,unsigned long n2);
212 void send_msg_4_I(int targetcore,unsigned long n0,unsigned long n1,unsigned long n2,unsigned long n3);
213 void send_msg_5_I(int targetcore,unsigned long n0,unsigned long n1,unsigned long n2,unsigned long n3,unsigned long n4);
214 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);
215 void cache_msg_1_I(int targetcore,unsigned long n0);
216 void cache_msg_2_I(int targetcore,unsigned long n0,unsigned long n1);
217 void cache_msg_3_I(int targetcore,unsigned long n0,unsigned long n1,unsigned long n2);
218 void cache_msg_4_I(int targetcore,unsigned long n0,unsigned long n1,unsigned long n2,unsigned long n3);
219 void cache_msg_5_I(int targetcore,unsigned long n0,unsigned long n1,unsigned long n2,unsigned long n3,unsigned long n4);
220 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);
221 int receiveMsg_I();
222 #ifdef TASK
223 void transferObject(struct transObjInfo * transObj);
224 #endif
225
226 #ifdef MULTICORE_GC
227 void transferMarkResults();
228 #endif 
229
230 #endif // MULTICORE
231 #endif // BAMBOO_MULTICORE_MSG_H