3 #include "multicoreruntime.h"
4 #include "runtime_arch.h"
5 #include "GenericHashtable.h"
8 #define INLINE inline __attribute__((always_inline))
9 #endif // #ifndef INLINE
11 // data structures for task invocation
12 struct genhashtable * activetasks;
13 struct taskparamdescriptor * currtpd;
14 struct LockValue runtime_locks[MAXTASKPARAMS];
17 // specific functions used inside critical sections
18 void enqueueObject_I(void * ptr,
19 struct parameterwrapper ** queues,
21 int enqueuetasks_I(struct parameterwrapper *parameter,
22 struct parameterwrapper *prevptr,
23 struct ___Object___ *ptr,
29 #define NUM_CORES2TEST 5
31 int core2test[1][NUM_CORES2TEST] = {
35 int core2test[56][NUM_CORES2TEST] = {
36 { 0, -1, 7, -1, 1}, { 1, -1, 8, 0, 2}, { 2, -1, 9, 1, 3},
37 { 3, -1, 10, 2, 4}, { 4, -1, 11, 3, 5}, { 5, -1, 12, 4, 6},
38 { 6, -1, 13, 5, -1}, { 7, 0, 14, -1, 8}, { 8, 1, 15, 7, 9},
39 { 9, 2, 16, 8, 10}, {10, 3, 17, 9, 11}, {11, 4, 18, 10, 12},
40 {12, 5, 19, 11, 13}, {13, 6, 20, 12, -1}, {14, 7, 21, -1, 15},
41 {15, 8, 22, 14, 16}, {16, 9, 23, 15, 17}, {17, 10, 24, 16, 18},
42 {18, 11, 25, 17, 19}, {19, 12, 26, 18, 20}, {20, 13, 27, 19, -1},
43 {21, 14, 28, -1, 22}, {22, 15, 29, 21, 23}, {23, 16, 30, 22, 24},
44 {24, 17, 31, 23, 25}, {25, 18, 32, 24, 26}, {26, 19, 33, 25, 27},
45 {27, 20, 34, 26, -1}, {28, 21, 35, -1, 29}, {29, 22, 36, 28, 30},
46 {30, 23, 37, 29, 31}, {31, 24, 38, 30, 32}, {32, 25, 39, 31, 33},
47 {33, 26, 40, 32, 34}, {34, 27, 41, 33, -1}, {35, 28, 42, -1, 36},
48 {36, 29, 43, 35, 37}, {37, 30, 44, 36, 38}, {38, 31, 45, 37, 39},
49 {39, 32, 46, 38, 40}, {40, 33, 47, 39, 41}, {41, 34, 48, 40, -1},
50 {42, 35, 49, -1, 43}, {43, 36, 50, 42, 44}, {44, 37, 51, 43, 45},
51 {45, 38, 52, 44, 46}, {46, 39, 53, 45, 47}, {47, 40, 54, 46, 48},
52 {48, 41, 55, 47, -1}, {49, 42, -1, -1, 50}, {50, 43, -1, 49, 51},
53 {51, 44, -1, 50, 52}, {52, 45, -1, 51, 53}, {53, 46, -1, 52, 54},
54 {54, 47, -1, 53, 55}, {55, 48, -1, 54, -1}
57 int core2test[62][NUM_CORES2TEST] = {
58 { 0, -1, 6, -1, 1}, { 1, -1, 7, 0, 2}, { 2, -1, 8, 1, 3},
59 { 3, -1, 9, 2, 4}, { 4, -1, 10, 3, 5}, { 5, -1, 11, 4, -1},
60 { 6, 0, 14, -1, 7}, { 7, 1, 15, 6, 8}, { 8, 2, 16, 7, 9},
61 { 9, 3, 17, 8, 10}, {10, 4, 18, 9, 11}, {11, 5, 19, 10, 12},
62 {12, -1, 20, 11, 13}, {13, -1, 21, 12, -1}, {14, 6, 22, -1, 15},
63 {15, 7, 23, 14, 16}, {16, 8, 24, 15, 17}, {17, 9, 25, 16, 18},
64 {18, 10, 26, 17, 19}, {19, 11, 27, 18, 20}, {20, 12, 28, 19, 21},
65 {21, 13, 29, 28, -1}, {22, 14, 30, -1, 23}, {23, 15, 31, 22, 24},
66 {24, 16, 32, 23, 25}, {25, 17, 33, 24, 26}, {26, 18, 34, 25, 27},
67 {27, 19, 35, 26, 28}, {28, 20, 36, 27, 29}, {29, 21, 37, 28, -1},
68 {30, 22, 38, -1, 31}, {31, 23, 39, 30, 32}, {32, 24, 40, 31, 33},
69 {33, 25, 41, 32, 34}, {34, 26, 42, 33, 35}, {35, 27, 43, 34, 36},
70 {36, 28, 44, 35, 37}, {37, 29, 45, 36, -1}, {38, 30, 46, -1, 39},
71 {39, 31, 47, 38, 40}, {40, 32, 48, 39, 41}, {41, 33, 49, 40, 42},
72 {42, 34, 50, 41, 43}, {43, 35, 51, 42, 44}, {44, 36, 52, 43, 45},
73 {45, 37, 53, 44, -1}, {46, 38, 54, -1, 47}, {47, 39, 55, 46, 48},
74 {48, 40, 56, 47, 49}, {49, 41, 57, 48, 50}, {50, 42, 58, 49, 51},
75 {51, 43, 59, 50, 52}, {52, 44, 60, 51, 53}, {53, 45, 61, 52, -1},
76 {54, 46, -1, -1, 55}, {55, 47, -1, 54, 56}, {56, 48, -1, 55, 57},
77 {57, 49, -1, 56, 59}, {58, 50, -1, 57, 59}, {59, 51, -1, 58, 60},
78 {60, 52, -1, 59, 61}, {61, 53, -1, 60, -1}
82 unsigned int gcmem_mixed_threshold = 0;
83 unsigned int gcmem_mixed_usedmem = 0;
84 #define NUM_CORES2TEST 9
86 int core2test[1][NUM_CORES2TEST] = {
87 {0, -1, -1, -1, -1, -1, -1, -1, -1}
90 int core2test[56][NUM_CORES2TEST] = {
91 { 0, -1, 7, -1, 1, -1, 14, -1, 2},
92 { 1, -1, 8, 0, 2, -1, 15, -1, 3},
93 { 2, -1, 9, 1, 3, -1, 16, 0, 4},
94 { 3, -1, 10, 2, 4, -1, 17, 1, 5},
95 { 4, -1, 11, 3, 5, -1, 18, 2, 6},
96 { 5, -1, 12, 4, 6, -1, 19, 3, -1},
97 { 6, -1, 13, 5, -1, -1, 20, 4, -1},
98 { 7, 0, 14, -1, 8, -1, 21, -1, 9},
99 { 8, 1, 15, 7, 9, -1, 22, -1, 10},
100 { 9, 2, 16, 8, 10, -1, 23, 7, 11},
101 {10, 3, 17, 9, 11, -1, 24, 8, 12},
102 {11, 4, 18, 10, 12, -1, 25, 9, 13},
103 {12, 5, 19, 11, 13, -1, 26, 10, -1},
104 {13, 6, 20, 12, -1, -1, 27, 11, -1},
105 {14, 7, 21, -1, 15, 0, 28, -1, 16},
106 {15, 8, 22, 14, 16, 1, 29, -1, 17},
107 {16, 9, 23, 15, 17, 2, 30, 14, 18},
108 {17, 10, 24, 16, 18, 3, 31, 15, 19},
109 {18, 11, 25, 17, 19, 4, 32, 16, 20},
110 {19, 12, 26, 18, 20, 5, 33, 17, -1},
111 {20, 13, 27, 19, -1, 6, 34, 18, -1},
112 {21, 14, 28, -1, 22, 7, 35, -1, 23},
113 {22, 15, 29, 21, 23, 8, 36, -1, 24},
114 {23, 16, 30, 22, 24, 9, 37, 21, 25},
115 {24, 17, 31, 23, 25, 10, 38, 22, 26},
116 {25, 18, 32, 24, 26, 11, 39, 23, 27},
117 {26, 19, 33, 25, 27, 12, 40, 24, -1},
118 {27, 20, 34, 26, -1, 13, 41, 25, -1},
119 {28, 21, 35, -1, 29, 14, 42, -1, 30},
120 {29, 22, 36, 28, 30, 15, 43, -1, 31},
121 {30, 23, 37, 29, 31, 16, 44, 28, 32},
122 {31, 24, 38, 30, 32, 17, 45, 29, 33},
123 {32, 25, 39, 31, 33, 18, 46, 30, 34},
124 {33, 26, 40, 32, 34, 19, 47, 31, -1},
125 {34, 27, 41, 33, -1, 20, 48, 32, -1},
126 {35, 28, 42, -1, 36, 21, 49, -1, 37},
127 {36, 29, 43, 35, 37, 22, 50, -1, 38},
128 {37, 30, 44, 36, 38, 23, 51, 35, 39},
129 {38, 31, 45, 37, 39, 24, 52, 36, 40},
130 {39, 32, 46, 38, 40, 25, 53, 37, 41},
131 {40, 33, 47, 39, 41, 26, 54, 38, -1},
132 {41, 34, 48, 40, -1, 27, 55, 39, -1},
133 {42, 35, 49, -1, 43, 28, -1, -1, 44},
134 {43, 36, 50, 42, 44, 29, -1, -1, 45},
135 {44, 37, 51, 43, 45, 30, -1, 42, 46},
136 {45, 38, 52, 44, 46, 31, -1, 43, 47},
137 {46, 39, 53, 45, 47, 32, -1, 44, 48},
138 {47, 40, 54, 46, 48, 33, -1, 45, -1},
139 {48, 41, 55, 47, -1, 34, -1, 46, -1},
140 {49, 42, -1, -1, 50, 35, -1, -1, 51},
141 {50, 43, -1, 49, 51, 36, -1, -1, 52},
142 {51, 44, -1, 50, 52, 37, -1, 49, 53},
143 {52, 45, -1, 51, 53, 38, -1, 50, 54},
144 {53, 46, -1, 52, 54, 39, -1, 51, 55},
145 {54, 47, -1, 53, 55, 40, -1, 52, -1},
146 {55, 48, -1, 54, -1, 41, -1, 53, -1}
149 int core2test[62][NUM_CORES2TEST] = {
150 { 0, -1, 6, -1, 1, -1, 14, -1, 2},
151 { 1, -1, 7, 0, 2, -1, 15, -1, 3},
152 { 2, -1, 8, 1, 3, -1, 16, 0, 4},
153 { 3, -1, 9, 2, 4, -1, 17, 1, 5},
154 { 4, -1, 10, 3, 5, -1, 18, 2, -1},
155 { 5, -1, 11, 4, -1, -1, 19, 3, -1},
156 { 6, 0, 14, -1, 7, -1, 22, -1, 8},
157 { 7, 1, 15, 6, 8, -1, 23, -1, 9},
158 { 8, 2, 16, 7, 9, -1, 24, 6, 10},
159 { 9, 3, 17, 8, 10, -1, 25, 7, 11},
160 {10, 4, 18, 9, 11, -1, 26, 8, 12},
161 {11, 5, 19, 10, 12, -1, 27, 9, 13},
162 {12, -1, 20, 11, 13, -1, 28, 10, -1},
163 {13, -1, 21, 12, -1, -1, 29, 11, -1},
164 {14, 6, 22, -1, 15, 0, 30, -1, 16},
165 {15, 7, 23, 14, 16, 1, 31, -1, 17},
166 {16, 8, 24, 15, 17, 2, 32, 14, 18},
167 {17, 9, 25, 16, 18, 3, 33, 15, 19},
168 {18, 10, 26, 17, 19, 4, 34, 16, 20},
169 {19, 11, 27, 18, 20, 5, 35, 17, 21},
170 {20, 12, 28, 19, 21, -1, 36, 18, -1},
171 {21, 13, 29, 28, -1, -1, 37, 19, -1},
172 {22, 14, 30, -1, 23, 6, 38, -1, 24},
173 {23, 15, 31, 22, 24, 7, 39, -1, 25},
174 {24, 16, 32, 23, 25, 8, 40, 22, 26},
175 {25, 17, 33, 24, 26, 9, 41, 23, 27},
176 {26, 18, 34, 25, 27, 10, 42, 24, 28},
177 {27, 19, 35, 26, 28, 11, 43, 25, 29},
178 {28, 20, 36, 27, 29, 12, 44, 26, -1},
179 {29, 21, 37, 28, -1, 13, 45, 27, -1},
180 {30, 22, 38, -1, 31, 22, 46, -1, 32},
181 {31, 23, 39, 30, 32, 15, 47, -1, 33},
182 {32, 24, 40, 31, 33, 16, 48, 30, 34},
183 {33, 25, 41, 32, 34, 17, 49, 31, 35},
184 {34, 26, 42, 33, 35, 18, 50, 32, 36},
185 {35, 27, 43, 34, 36, 19, 51, 33, 37},
186 {36, 28, 44, 35, 37, 20, 52, 34, -1},
187 {37, 29, 45, 36, -1, 21, 53, 35, -1},
188 {38, 30, 46, -1, 39, 22, 54, -1, 40},
189 {39, 31, 47, 38, 40, 23, 55, -1, 41},
190 {40, 32, 48, 39, 41, 24, 56, 38, 42},
191 {41, 33, 49, 40, 42, 25, 57, 39, 43},
192 {42, 34, 50, 41, 43, 26, 58, 40, 44},
193 {43, 35, 51, 42, 44, 27, 59, 41, 45},
194 {44, 36, 52, 43, 45, 28, 60, 42, -1},
195 {45, 37, 53, 44, -1, 29, 61, 43, -1},
196 {46, 38, 54, -1, 47, 30, -1, -1, 48},
197 {47, 39, 55, 46, 48, 31, -1, -1, 49},
198 {48, 40, 56, 47, 49, 32, -1, 46, 50},
199 {49, 41, 57, 48, 50, 33, -1, 47, 51},
200 {50, 42, 58, 49, 51, 34, -1, 48, 52},
201 {51, 43, 59, 50, 52, 35, -1, 49, 53},
202 {52, 44, 60, 51, 53, 36, -1, 50, -1},
203 {53, 45, 61, 52, -1, 37, -1, 51, -1},
204 {54, 46, -1, -1, 55, 38, -1, -1, 56},
205 {55, 47, -1, 54, 56, 39, -1, -1, 57},
206 {56, 48, -1, 55, 57, 40, -1, 54, 58},
207 {57, 49, -1, 56, 59, 41, -1, 55, 59},
208 {58, 50, -1, 57, 59, 42, -1, 56, 60},
209 {59, 51, -1, 58, 60, 43, -1, 57, 61},
210 {60, 52, -1, 59, 61, 44, -1, 58, -1},
211 {61, 53, -1, 60, -1, 45, -1, 59, -1}
216 inline __attribute__((always_inline))
217 void setupsmemmode(void) {
219 // Only allocate local mem chunks to each core.
220 // If a core has used up its local shared memory, start gc.
221 bamboo_smem_mode = SMEMLOCAL;
223 // Allocate the local shared memory to each core with the highest priority,
224 // if a core has used up its local shared memory, try to allocate the
225 // shared memory that belong to its neighbours, if also failed, start gc.
226 bamboo_smem_mode = SMEMFIXED;
228 // Allocate the local shared memory to each core with the highest priority,
229 // if a core has used up its local shared memory, try to allocate the
230 // shared memory that belong to its neighbours first, if failed, check
231 // current memory allocation rate, if it has already reached the threshold,
232 // start gc, otherwise, allocate the shared memory globally. If all the
233 // shared memory has been used up, start gc.
234 bamboo_smem_mode = SMEMMIXED;
236 // Allocate all the memory chunks globally, do not consider the host cores
237 // When all the shared memory are used up, start gc.
238 bamboo_smem_mode = SMEMGLOBAL;
240 // defaultly using local mode
241 bamboo_smem_mode = SMEMLOCAL;
242 //bamboo_smem_mode = SMEMGLOBAL;
243 //bamboo_smem_mode = SMEMFIXED;
245 } // void setupsmemmode(void)
248 inline __attribute__((always_inline))
249 void initruntimedata() {
251 // initialize the arrays
252 if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
253 // startup core to initialize corestatus[]
254 for(i = 0; i < NUMCORESACTIVE; ++i) {
257 numreceiveobjs[i] = 0;
259 // initialize the profile data arrays
260 profilestatus[i] = 1;
264 gcnumsendobjs[0][i] = gcnumsendobjs[1][i] = 0;
265 gcnumreceiveobjs[0][i] = gcnumreceiveobjs[1][i] = 0;
267 } // for(i = 0; i < NUMCORESACTIVE; ++i)
269 for(i = 0; i < NUMCORES4GC; ++i) {
271 gcrequiredmems[i] = 0;
273 gcfilledblocks[i] = 0;
274 } // for(i = 0; i < NUMCORES4GC; ++i)
277 gc_infoOverflow = false;
278 gc_num_livespace = 0;
279 gc_num_freespace = 0;
290 self_numsendobjs = 0;
291 self_numreceiveobjs = 0;
293 for(i = 0; i < BAMBOO_MSG_BUF_LENGTH; ++i) {
298 msglength = BAMBOO_MSG_BUF_LENGTH;
300 for(i = 0; i < BAMBOO_OUT_BUF_LENGTH; ++i) {
306 isMsgHanging = false;
307 //isMsgSending = false;
310 bamboo_cur_msp = NULL;
311 bamboo_smem_size = 0;
312 totransobjqueue = createQueue_I();
315 bamboo_smem_zero_top = NULL;
317 gcprocessing = false;
318 gcphase = FINISHPHASE;
322 gcself_numsendobjs = 0;
323 gcself_numreceiveobjs = 0;
324 gcmarkedptrbound = 0;
325 #ifdef LOCALHASHTBL_TEST
326 gcpointertbl = allocateRuntimeHash_I(20);
328 gcpointertbl = mgchashCreate_I(2000, 0.75);
330 //gcpointertbl = allocateMGCHash_I(20);
331 gcforwardobjtbl = allocateMGCHash_I(20, 3);
334 //gcismapped = false;
343 gcsbstarttbl = BAMBOO_BASE_VA;
344 bamboo_smemtbl = (void *)gcsbstarttbl
345 + (BAMBOO_SHARED_MEM_SIZE/BAMBOO_SMEM_SIZE)*sizeof(INTPTR);
346 if(BAMBOO_NUM_OF_CORE < NUMCORES4GC) {
347 int t_size = ((BAMBOO_RMSP_SIZE)-sizeof(mgcsharedhashtbl_t)*2
348 -128*sizeof(size_t))/sizeof(mgcsharedhashlistnode_t)-2;
350 unsigned int tmp_k = 1 << (sizeof(int)*8 -1);
351 while(((t_size & tmp_k) == 0) && (kk < sizeof(int)*8)) {
352 t_size = t_size << 1;
355 t_size = tmp_k >> kk;
356 gcsharedptbl = mgcsharedhashCreate_I(t_size,0.30);//allocateGCSharedHash_I(20);
360 BAMBOO_MEMSET_WH(gcrpointertbls, 0,
361 sizeof(mgcsharedhashtbl_t *)*NUMCORES4GC);
362 //sizeof(struct RuntimeHash *)*NUMCORES4GC);
364 gcmem_mixed_threshold = (unsigned int)((BAMBOO_SHARED_MEM_SIZE
365 -bamboo_reserved_smem*BAMBOO_SMEM_SIZE)*0.8);
366 gcmem_mixed_usedmem = 0;
371 gc_num_forwardobj = 0;
372 gc_num_profiles = NUMCORESACTIVE - 1;
375 gc_num_flush_dtlb = 0;
377 gc_localheap_s = false;
378 #ifdef GC_CACHE_ADAPT
379 gccachestage = false;
380 // enable the timer interrupt
381 bamboo_tile_timer_set_next_event(500000000); // TODO
382 bamboo_unmask_timer_intr();
383 bamboo_dtlb_sampling_process();
384 #endif // GC_CACHE_ADAPT
386 // create the lock table, lockresult table and obj queue
389 (struct RuntimeNode **) RUNMALLOC_I(sizeof(struct RuntimeNode *)*20);
390 /* Set allocation blocks*/
391 locktable.listhead=NULL;
392 locktable.listtail=NULL;
394 locktable.numelements = 0;
399 lockRedirectTbl = allocateRuntimeHash_I(20);
400 objRedirectLockTbl = allocateRuntimeHash_I(20);
405 objqueue.head = NULL;
406 objqueue.tail = NULL;
412 //isInterrupt = true;
416 taskInfoOverflow = false;
417 #ifdef PROFILE_INTERRUPT
418 interruptInfoIndex = 0;
419 interruptInfoOverflow = false;
420 #endif // PROFILE_INTERRUPT
423 for(i = 0; i < MAXTASKPARAMS; i++) {
424 runtime_locks[i].redirectlock = 0;
425 runtime_locks[i].value = 0;
430 inline __attribute__((always_inline))
431 void disruntimedata() {
433 #ifdef LOCALHASHTBL_TEST
434 freeRuntimeHash(gcpointertbl);
436 mgchashDelete(gcpointertbl);
438 //freeMGCHash(gcpointertbl);
439 freeMGCHash(gcforwardobjtbl);
440 // for mapping info structures
441 //freeRuntimeHash(gcrcoretbl);
443 freeRuntimeHash(lockRedirectTbl);
444 freeRuntimeHash(objRedirectLockTbl);
445 RUNFREE(locktable.bucket);
447 if(activetasks != NULL) {
448 genfreehashtable(activetasks);
450 if(currtpd != NULL) {
451 RUNFREE(currtpd->parameterArray);
455 BAMBOO_LOCAL_MEM_CLOSE();
456 BAMBOO_SHARE_MEM_CLOSE();
459 inline __attribute__((always_inline))
460 bool checkObjQueue() {
462 struct transObjInfo * objInfo = NULL;
466 #ifdef ACCURATEPROFILE
467 bool isChecking = false;
468 if(!isEmpty(&objqueue)) {
469 profileTaskStart("objqueue checking");
471 } // if(!isEmpty(&objqueue))
475 while(!isEmpty(&objqueue)) {
477 BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
479 BAMBOO_DEBUGPRINT(0xf001);
482 //isInterrupt = false;
485 BAMBOO_DEBUGPRINT(0xeee1);
488 objInfo = (struct transObjInfo *)getItem(&objqueue);
489 obj = objInfo->objptr;
491 BAMBOO_DEBUGPRINT_REG((int)obj);
493 // grab lock and flush the obj
497 BAMBOO_WAITING_FOR_LOCK(0);
498 } // while(!lockflag)
501 BAMBOO_DEBUGPRINT_REG(grount);
516 BAMBOO_CACHE_FLUSH_RANGE((int)obj,sizeof(int));
517 BAMBOO_CACHE_FLUSH_RANGE((int)obj,
518 classsize[((struct ___Object___ *)obj)->type]);
520 // enqueue the object
521 for(k = 0; k < objInfo->length; ++k) {
522 int taskindex = objInfo->queues[2 * k];
523 int paramindex = objInfo->queues[2 * k + 1];
524 struct parameterwrapper ** queues =
525 &(paramqueues[BAMBOO_NUM_OF_CORE][taskindex][paramindex]);
527 BAMBOO_DEBUGPRINT_REG(taskindex);
528 BAMBOO_DEBUGPRINT_REG(paramindex);
529 struct ___Object___ * tmpptr = (struct ___Object___ *)obj;
530 tprintf("Process %x(%d): receive obj %x(%lld), ptrflag %x\n",
531 BAMBOO_NUM_OF_CORE, BAMBOO_NUM_OF_CORE, (int)obj,
532 (long)obj, tmpptr->flag);
534 enqueueObject_I(obj, queues, 1);
536 BAMBOO_DEBUGPRINT_REG(hashsize(activetasks));
538 } // for(k = 0; k < objInfo->length; ++k)
539 releasewritelock_I(obj);
540 RUNFREE(objInfo->queues);
544 // put it at the end of the queue if no update version in the queue
545 struct QueueItem * qitem = getHead(&objqueue);
546 struct QueueItem * prev = NULL;
547 while(qitem != NULL) {
548 struct transObjInfo * tmpinfo =
549 (struct transObjInfo *)(qitem->objectptr);
550 if(tmpinfo->objptr == obj) {
551 // the same object in the queue, which should be enqueued
552 // recently. Current one is outdate, do not re-enqueue it
553 RUNFREE(objInfo->queues);
558 } // if(tmpinfo->objptr == obj)
559 qitem = getNextQueueItem(prev);
560 } // while(qitem != NULL)
561 // try to execute active tasks already enqueued first
562 addNewItem_I(&objqueue, objInfo);
564 //isInterrupt = true;
567 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
569 BAMBOO_DEBUGPRINT(0xf000);
573 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
575 BAMBOO_DEBUGPRINT(0xf000);
577 } // while(!isEmpty(&objqueue))
580 #ifdef ACCURATEPROFILE
588 BAMBOO_DEBUGPRINT(0xee02);
593 inline __attribute__((always_inline))
594 void checkCoreStatus() {
595 bool allStall = false;
599 (waitconfirm && (numconfirm == 0))) {
601 BAMBOO_DEBUGPRINT(0xee04);
602 BAMBOO_DEBUGPRINT_REG(waitconfirm);
604 BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
606 BAMBOO_DEBUGPRINT(0xf001);
608 corestatus[BAMBOO_NUM_OF_CORE] = 0;
609 numsendobjs[BAMBOO_NUM_OF_CORE] = self_numsendobjs;
610 numreceiveobjs[BAMBOO_NUM_OF_CORE] = self_numreceiveobjs;
611 // check the status of all cores
614 BAMBOO_DEBUGPRINT_REG(NUMCORESACTIVE);
616 for(i = 0; i < NUMCORESACTIVE; ++i) {
618 BAMBOO_DEBUGPRINT(0xe000 + corestatus[i]);
620 if(corestatus[i] != 0) {
624 } // for(i = 0; i < NUMCORESACTIVE; ++i)
626 // check if the sum of send objs and receive obj are the same
627 // yes->check if the info is the latest; no->go on executing
629 for(i = 0; i < NUMCORESACTIVE; ++i) {
630 sumsendobj += numsendobjs[i];
632 BAMBOO_DEBUGPRINT(0xf000 + numsendobjs[i]);
634 } // for(i = 0; i < NUMCORESACTIVE; ++i)
635 for(i = 0; i < NUMCORESACTIVE; ++i) {
636 sumsendobj -= numreceiveobjs[i];
638 BAMBOO_DEBUGPRINT(0xf000 + numreceiveobjs[i]);
640 } // for(i = 0; i < NUMCORESACTIVE; ++i)
641 if(0 == sumsendobj) {
643 // the first time found all cores stall
644 // send out status confirm msg to all other cores
645 // reset the corestatus array too
647 BAMBOO_DEBUGPRINT(0xee05);
649 corestatus[BAMBOO_NUM_OF_CORE] = 1;
651 numconfirm = NUMCORESACTIVE - 1;
652 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
653 for(i = 1; i < NUMCORESACTIVE; ++i) {
655 // send status confirm msg to core i
656 send_msg_1(i, STATUSCONFIRM, false);
657 } // for(i = 1; i < NUMCORESACTIVE; ++i)
660 // all the core status info are the latest
661 // terminate; for profiling mode, send request to all
662 // other cores to pour out profiling data
664 BAMBOO_DEBUGPRINT(0xee06);
668 totalexetime = BAMBOO_GET_EXE_TIME() - bamboo_start_time;
671 //BAMBOO_DEBUGPRINT_REG(interrupttime);
674 BAMBOO_DEBUGPRINT(BAMBOO_GET_EXE_TIME() - bamboo_start_time);
675 //BAMBOO_DEBUGPRINT_REG(total_num_t6); // TODO for test
677 BAMBOO_DEBUGPRINT_REG(gc_num_flush_dtlb);
679 #ifndef BAMBOO_MEMPROF
680 BAMBOO_DEBUGPRINT(0xbbbbbbbb);
683 // profile mode, send msgs to other cores to request pouring
684 // out progiling data
686 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
688 BAMBOO_DEBUGPRINT(0xf000);
690 for(i = 1; i < NUMCORESACTIVE; ++i) {
691 // send profile request msg to core i
692 send_msg_2(i, PROFILEOUTPUT, totalexetime, false);
693 } // for(i = 1; i < NUMCORESACTIVE; ++i)
695 // pour profiling data on startup core
699 BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
701 BAMBOO_DEBUGPRINT(0xf001);
703 profilestatus[BAMBOO_NUM_OF_CORE] = 0;
704 // check the status of all cores
707 BAMBOO_DEBUGPRINT_REG(NUMCORESACTIVE);
709 for(i = 0; i < NUMCORESACTIVE; ++i) {
711 BAMBOO_DEBUGPRINT(0xe000 + profilestatus[i]);
713 if(profilestatus[i] != 0) {
717 } // for(i = 0; i < NUMCORESACTIVE; ++i)
720 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
722 BAMBOO_DEBUGPRINT(0xf000);
727 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
733 // gc_profile mode, output gc prfiling data
735 #ifdef GC_CACHE_ADAPT
736 bamboo_mask_timer_intr(); // disable the TILE_TIMER interrupt
737 #endif // GC_CACHE_ADAPT
739 gc_outputProfileData();
740 #endif // #ifdef GC_PROFILE
741 #endif // #ifdef MULTICORE_GC
743 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
744 terminate(); // All done.
745 } // if(!waitconfirm)
747 // still some objects on the fly on the network
748 // reset the waitconfirm and numconfirm
750 BAMBOO_DEBUGPRINT(0xee07);
754 } // if(0 == sumsendobj)
756 // not all cores are stall, keep on waiting
758 BAMBOO_DEBUGPRINT(0xee08);
763 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
765 BAMBOO_DEBUGPRINT(0xf000);
767 } // if((!waitconfirm) ||
770 // main function for each core
771 inline void run(void * arg) {
775 bool sendStall = false;
777 bool tocontinue = false;
779 corenum = BAMBOO_GET_NUM_OF_CORE();
781 BAMBOO_DEBUGPRINT(0xeeee);
782 BAMBOO_DEBUGPRINT_REG(corenum);
783 BAMBOO_DEBUGPRINT(STARTUPCORE);
785 //BAMBOO_DEBUGPRINT(BAMBOO_GET_EXE_TIME()); // TODO
787 // initialize runtime data structures
790 // other architecture related initialization
794 initializeexithandler();
796 // main process of the execution module
797 if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) {
798 // non-executing cores, only processing communications
801 //isInterrupt = false;
805 /* Create queue of active tasks */
807 genallocatehashtable((unsigned int (*)(void *)) &hashCodetpd,
808 (int (*)(void *,void *)) &comparetpd);
810 /* Process task information */
813 if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
814 /* Create startup object */
815 createstartupobject(argc, argv);
819 BAMBOO_DEBUGPRINT(0xee00);
825 // check if need to do GC
829 #endif // MULTICORE_GC
831 // check if there are new active tasks can be executed
838 while(receiveObject() != -1) {
843 BAMBOO_DEBUGPRINT(0xee01);
846 // check if there are some pending objects,
847 // if yes, enqueue them and executetasks again
848 tocontinue = checkObjQueue();
852 if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
855 BAMBOO_DEBUGPRINT(0xee03);
863 BAMBOO_DEBUGPRINT(0xee09);
869 // wait for some time
872 BAMBOO_DEBUGPRINT(0xee0a);
878 // send StallMsg to startup core
880 BAMBOO_DEBUGPRINT(0xee0b);
883 send_msg_4(STARTUPCORE, TRANSTALL, BAMBOO_NUM_OF_CORE,
884 self_numsendobjs, self_numreceiveobjs, false);
896 BAMBOO_DEBUGPRINT(0xee0c);
899 } // if(STARTUPCORE == BAMBOO_NUM_OF_CORE)
902 } // if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1)
906 struct ___createstartupobject____I_locals {
909 struct ___StartupObject___ * ___startupobject___;
910 struct ArrayObject * ___stringarray___;
911 }; // struct ___createstartupobject____I_locals
913 void createstartupobject(int argc,
917 /* Allocate startup object */
919 struct ___createstartupobject____I_locals ___locals___ =
920 {2, NULL, NULL, NULL};
921 struct ___StartupObject___ *startupobject=
922 (struct ___StartupObject___*) allocate_new(&___locals___, STARTUPTYPE);
923 ___locals___.___startupobject___ = startupobject;
924 struct ArrayObject * stringarray=
925 allocate_newarray(&___locals___, STRINGARRAYTYPE, argc-1);
926 ___locals___.___stringarray___ = stringarray;
928 struct ___StartupObject___ *startupobject=
929 (struct ___StartupObject___*) allocate_new(STARTUPTYPE);
930 struct ArrayObject * stringarray=
931 allocate_newarray(STRINGARRAYTYPE, argc-1);
933 /* Build array of strings */
934 startupobject->___parameters___=stringarray;
935 for(i=1; i<argc; i++) {
936 int length=strlen(argv[i]);
938 struct ___String___ *newstring=NewString(&___locals___, argv[i],length);
940 struct ___String___ *newstring=NewString(argv[i],length);
942 ((void **)(((char *)&stringarray->___length___)+sizeof(int)))[i-1]=
946 startupobject->version = 0;
947 startupobject->lock = NULL;
949 /* Set initialized flag for startup object */
950 flagorandinit(startupobject,1,0xFFFFFFFF);
951 enqueueObject(startupobject, NULL, 0);
953 BAMBOO_CACHE_FLUSH_ALL();
957 int hashCodetpd(struct taskparamdescriptor *ftd) {
958 int hash=(int)ftd->task;
960 for(i=0; i<ftd->numParameters; i++) {
961 hash^=(int)ftd->parameterArray[i];
966 int comparetpd(struct taskparamdescriptor *ftd1,
967 struct taskparamdescriptor *ftd2) {
969 if (ftd1->task!=ftd2->task)
971 for(i=0; i<ftd1->numParameters; i++)
972 if(ftd1->parameterArray[i]!=ftd2->parameterArray[i])
977 /* This function sets a tag. */
979 void tagset(void *ptr,
980 struct ___Object___ * obj,
981 struct ___TagDescriptor___ * tagd) {
983 void tagset(struct ___Object___ * obj,
984 struct ___TagDescriptor___ * tagd) {
986 struct ArrayObject * ao=NULL;
987 struct ___Object___ * tagptr=obj->___tags___;
989 obj->___tags___=(struct ___Object___ *)tagd;
991 /* Have to check if it is already set */
992 if (tagptr->type==TAGTYPE) {
993 struct ___TagDescriptor___ * td=(struct ___TagDescriptor___ *) tagptr;
998 int ptrarray[]={2, (int) ptr, (int) obj, (int)tagd};
999 struct ArrayObject * ao=
1000 allocate_newarray(&ptrarray,TAGARRAYTYPE,TAGARRAYINTERVAL);
1001 obj=(struct ___Object___ *)ptrarray[2];
1002 tagd=(struct ___TagDescriptor___ *)ptrarray[3];
1003 td=(struct ___TagDescriptor___ *) obj->___tags___;
1005 ao=allocate_newarray(TAGARRAYTYPE,TAGARRAYINTERVAL);
1008 ARRAYSET(ao, struct ___TagDescriptor___ *, 0, td);
1009 ARRAYSET(ao, struct ___TagDescriptor___ *, 1, tagd);
1010 obj->___tags___=(struct ___Object___ *) ao;
1011 ao->___cachedCode___=2;
1015 struct ArrayObject *ao=(struct ArrayObject *) tagptr;
1016 for(i=0; i<ao->___cachedCode___; i++) {
1017 struct ___TagDescriptor___ * td=
1018 ARRAYGET(ao, struct ___TagDescriptor___*, i);
1023 if (ao->___cachedCode___<ao->___length___) {
1024 ARRAYSET(ao, struct ___TagDescriptor___ *,ao->___cachedCode___,tagd);
1025 ao->___cachedCode___++;
1028 int ptrarray[]={2,(int) ptr, (int) obj, (int) tagd};
1029 struct ArrayObject * aonew=
1030 allocate_newarray(&ptrarray,TAGARRAYTYPE,
1031 TAGARRAYINTERVAL+ao->___length___);
1032 obj=(struct ___Object___ *)ptrarray[2];
1033 tagd=(struct ___TagDescriptor___ *) ptrarray[3];
1034 ao=(struct ArrayObject *)obj->___tags___;
1036 struct ArrayObject * aonew=
1037 allocate_newarray(TAGARRAYTYPE,TAGARRAYINTERVAL+ao->___length___);
1040 aonew->___cachedCode___=ao->___length___+1;
1041 for(i=0; i<ao->___length___; i++) {
1042 ARRAYSET(aonew, struct ___TagDescriptor___*, i,
1043 ARRAYGET(ao, struct ___TagDescriptor___*, i));
1045 ARRAYSET(aonew, struct ___TagDescriptor___ *, ao->___length___,tagd);
1051 struct ___Object___ * tagset=tagd->flagptr;
1054 } else if (tagset->type!=OBJECTARRAYTYPE) {
1056 int ptrarray[]={2, (int) ptr, (int) obj, (int)tagd};
1057 struct ArrayObject * ao=
1058 allocate_newarray(&ptrarray,OBJECTARRAYTYPE,OBJECTARRAYINTERVAL);
1059 obj=(struct ___Object___ *)ptrarray[2];
1060 tagd=(struct ___TagDescriptor___ *)ptrarray[3];
1062 struct ArrayObject * ao=
1063 allocate_newarray(OBJECTARRAYTYPE,OBJECTARRAYINTERVAL);
1065 ARRAYSET(ao, struct ___Object___ *, 0, tagd->flagptr);
1066 ARRAYSET(ao, struct ___Object___ *, 1, obj);
1067 ao->___cachedCode___=2;
1068 tagd->flagptr=(struct ___Object___ *)ao;
1070 struct ArrayObject *ao=(struct ArrayObject *) tagset;
1071 if (ao->___cachedCode___<ao->___length___) {
1072 ARRAYSET(ao, struct ___Object___*, ao->___cachedCode___++, obj);
1076 int ptrarray[]={2, (int) ptr, (int) obj, (int)tagd};
1077 struct ArrayObject * aonew=
1078 allocate_newarray(&ptrarray,OBJECTARRAYTYPE,
1079 OBJECTARRAYINTERVAL+ao->___length___);
1080 obj=(struct ___Object___ *)ptrarray[2];
1081 tagd=(struct ___TagDescriptor___ *)ptrarray[3];
1082 ao=(struct ArrayObject *)tagd->flagptr;
1084 struct ArrayObject * aonew=allocate_newarray(OBJECTARRAYTYPE,
1085 OBJECTARRAYINTERVAL+ao->___length___);
1087 aonew->___cachedCode___=ao->___cachedCode___+1;
1088 for(i=0; i<ao->___length___; i++) {
1089 ARRAYSET(aonew, struct ___Object___*, i,
1090 ARRAYGET(ao, struct ___Object___*, i));
1092 ARRAYSET(aonew, struct ___Object___ *, ao->___cachedCode___, obj);
1093 tagd->flagptr=(struct ___Object___ *) aonew;
1099 /* This function clears a tag. */
1101 void tagclear(void *ptr,
1102 struct ___Object___ * obj,
1103 struct ___TagDescriptor___ * tagd) {
1105 void tagclear(struct ___Object___ * obj,
1106 struct ___TagDescriptor___ * tagd) {
1108 /* We'll assume that tag is alway there.
1109 Need to statically check for this of course. */
1110 struct ___Object___ * tagptr=obj->___tags___;
1112 if (tagptr->type==TAGTYPE) {
1113 if ((struct ___TagDescriptor___ *)tagptr==tagd)
1114 obj->___tags___=NULL;
1116 struct ArrayObject *ao=(struct ArrayObject *) tagptr;
1118 for(i=0; i<ao->___cachedCode___; i++) {
1119 struct ___TagDescriptor___ * td=
1120 ARRAYGET(ao, struct ___TagDescriptor___ *, i);
1122 ao->___cachedCode___--;
1123 if (i<ao->___cachedCode___)
1124 ARRAYSET(ao, struct ___TagDescriptor___ *, i,
1125 ARRAYGET(ao,struct ___TagDescriptor___*,ao->___cachedCode___));
1126 ARRAYSET(ao,struct ___TagDescriptor___ *,ao->___cachedCode___, NULL);
1127 if (ao->___cachedCode___==0)
1128 obj->___tags___=NULL;
1135 struct ___Object___ *tagset=tagd->flagptr;
1136 if (tagset->type!=OBJECTARRAYTYPE) {
1140 struct ArrayObject *ao=(struct ArrayObject *) tagset;
1142 for(i=0; i<ao->___cachedCode___; i++) {
1143 struct ___Object___ * tobj=ARRAYGET(ao, struct ___Object___ *, i);
1145 ao->___cachedCode___--;
1146 if (i<ao->___cachedCode___)
1147 ARRAYSET(ao, struct ___Object___ *, i,
1148 ARRAYGET(ao, struct ___Object___ *, ao->___cachedCode___));
1149 ARRAYSET(ao, struct ___Object___ *, ao->___cachedCode___, NULL);
1150 if (ao->___cachedCode___==0)
1161 /* This function allocates a new tag. */
1163 struct ___TagDescriptor___ * allocate_tag(void *ptr,
1165 struct ___TagDescriptor___ * v=
1166 (struct ___TagDescriptor___ *) FREEMALLOC((struct garbagelist *) ptr,
1167 classsize[TAGTYPE]);
1169 struct ___TagDescriptor___ * allocate_tag(int index) {
1170 struct ___TagDescriptor___ * v=FREEMALLOC(classsize[TAGTYPE]);
1179 /* This function updates the flag for object ptr. It or's the flag
1180 with the or mask and and's it with the andmask. */
1182 void flagbody(struct ___Object___ *ptr,
1184 struct parameterwrapper ** queues,
1188 int flagcomp(const int *val1, const int *val2) {
1189 return (*val1)-(*val2);
1192 void flagorand(void * ptr,
1195 struct parameterwrapper ** queues,
1198 int oldflag=((int *)ptr)[1];
1199 int flag=ormask|oldflag;
1201 flagbody(ptr, flag, queues, length, false);
1205 bool intflagorand(void * ptr,
1209 int oldflag=((int *)ptr)[1];
1210 int flag=ormask|oldflag;
1212 if (flag==oldflag) /* Don't do anything */
1215 flagbody(ptr, flag, NULL, 0, false);
1221 void flagorandinit(void * ptr,
1224 int oldflag=((int *)ptr)[1];
1225 int flag=ormask|oldflag;
1227 flagbody(ptr,flag,NULL,0,true);
1230 void flagbody(struct ___Object___ *ptr,
1232 struct parameterwrapper ** vqueues,
1235 struct parameterwrapper * flagptr = NULL;
1237 struct parameterwrapper ** queues = vqueues;
1238 int length = vlength;
1240 int UNUSED, UNUSED2;
1241 int * enterflags = NULL;
1242 if((!isnew) && (queues == NULL)) {
1243 if(BAMBOO_NUM_OF_CORE < NUMCORESACTIVE) {
1244 queues = objectqueues[BAMBOO_NUM_OF_CORE][ptr->type];
1245 length = numqueues[BAMBOO_NUM_OF_CORE][ptr->type];
1252 /*Remove object from all queues */
1253 for(i = 0; i < length; ++i) {
1254 flagptr = queues[i];
1255 ObjectHashget(flagptr->objectset, (int) ptr, (int *) &next,
1256 (int *) &enterflags, &UNUSED, &UNUSED2);
1257 ObjectHashremove(flagptr->objectset, (int)ptr);
1258 if (enterflags!=NULL)
1259 RUNFREE(enterflags);
1263 void enqueueObject(void * vptr,
1264 struct parameterwrapper ** vqueues,
1266 struct ___Object___ *ptr = (struct ___Object___ *)vptr;
1269 //struct QueueItem *tmpptr;
1270 struct parameterwrapper * parameter=NULL;
1273 struct parameterwrapper * prevptr=NULL;
1274 struct ___Object___ *tagptr=NULL;
1275 struct parameterwrapper ** queues = vqueues;
1276 int length = vlength;
1277 if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) {
1280 if(queues == NULL) {
1281 queues = objectqueues[BAMBOO_NUM_OF_CORE][ptr->type];
1282 length = numqueues[BAMBOO_NUM_OF_CORE][ptr->type];
1284 tagptr=ptr->___tags___;
1286 /* Outer loop iterates through all parameter queues an object of
1287 this type could be in. */
1288 for(j = 0; j < length; ++j) {
1289 parameter = queues[j];
1291 if (parameter->numbertags>0) {
1293 goto nextloop; //that means the object has no tag
1294 //but that param needs tag
1295 else if(tagptr->type==TAGTYPE) { //one tag
1296 //struct ___TagDescriptor___ * tag=
1297 //(struct ___TagDescriptor___*) tagptr;
1298 for(i=0; i<parameter->numbertags; i++) {
1299 //slotid is parameter->tagarray[2*i];
1300 int tagid=parameter->tagarray[2*i+1];
1301 if (tagid!=tagptr->flag)
1302 goto nextloop; /*We don't have this tag */
1304 } else { //multiple tags
1305 struct ArrayObject * ao=(struct ArrayObject *) tagptr;
1306 for(i=0; i<parameter->numbertags; i++) {
1307 //slotid is parameter->tagarray[2*i];
1308 int tagid=parameter->tagarray[2*i+1];
1310 for(j=0; j<ao->___cachedCode___; j++) {
1311 if (tagid==ARRAYGET(ao, struct ___TagDescriptor___*, j)->flag)
1322 for(i=0; i<parameter->numberofterms; i++) {
1323 int andmask=parameter->intarray[i*2];
1324 int checkmask=parameter->intarray[i*2+1];
1325 if ((ptr->flag&andmask)==checkmask) {
1326 enqueuetasks(parameter, prevptr, ptr, NULL, 0);
1337 void enqueueObject_I(void * vptr,
1338 struct parameterwrapper ** vqueues,
1340 struct ___Object___ *ptr = (struct ___Object___ *)vptr;
1343 //struct QueueItem *tmpptr;
1344 struct parameterwrapper * parameter=NULL;
1347 struct parameterwrapper * prevptr=NULL;
1348 struct ___Object___ *tagptr=NULL;
1349 struct parameterwrapper ** queues = vqueues;
1350 int length = vlength;
1351 if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) {
1354 if(queues == NULL) {
1355 queues = objectqueues[BAMBOO_NUM_OF_CORE][ptr->type];
1356 length = numqueues[BAMBOO_NUM_OF_CORE][ptr->type];
1358 tagptr=ptr->___tags___;
1360 /* Outer loop iterates through all parameter queues an object of
1361 this type could be in. */
1362 for(j = 0; j < length; ++j) {
1363 parameter = queues[j];
1365 if (parameter->numbertags>0) {
1367 goto nextloop; //that means the object has no tag
1368 //but that param needs tag
1369 else if(tagptr->type==TAGTYPE) { //one tag
1370 //struct ___TagDescriptor___*tag=(struct ___TagDescriptor___*)tagptr;
1371 for(i=0; i<parameter->numbertags; i++) {
1372 //slotid is parameter->tagarray[2*i];
1373 int tagid=parameter->tagarray[2*i+1];
1374 if (tagid!=tagptr->flag)
1375 goto nextloop; /*We don't have this tag */
1377 } else { //multiple tags
1378 struct ArrayObject * ao=(struct ArrayObject *) tagptr;
1379 for(i=0; i<parameter->numbertags; i++) {
1380 //slotid is parameter->tagarray[2*i];
1381 int tagid=parameter->tagarray[2*i+1];
1383 for(j=0; j<ao->___cachedCode___; j++) {
1384 if (tagid==ARRAYGET(ao, struct ___TagDescriptor___*, j)->flag)
1395 for(i=0; i<parameter->numberofterms; i++) {
1396 int andmask=parameter->intarray[i*2];
1397 int checkmask=parameter->intarray[i*2+1];
1398 if ((ptr->flag&andmask)==checkmask) {
1399 enqueuetasks_I(parameter, prevptr, ptr, NULL, 0);
1411 int * getAliasLock(void ** ptrs,
1413 struct RuntimeHash * tbl) {
1415 return (int*)(RUNMALLOC(sizeof(int)));
1420 bool redirect = false;
1421 int redirectlock = 0;
1422 for(; i < length; i++) {
1423 struct ___Object___ * ptr = (struct ___Object___ *)(ptrs[i]);
1426 if(ptr->lock == NULL) {
1429 lock = (int)(ptr->lock);
1432 if(lock != redirectlock) {
1433 RuntimeHashadd(tbl, lock, redirectlock);
1436 if(RuntimeHashcontainskey(tbl, lock)) {
1437 // already redirected
1439 RuntimeHashget(tbl, lock, &redirectlock);
1440 for(; j < locklen; j++) {
1441 if(locks[j] != redirectlock) {
1442 RuntimeHashadd(tbl, locks[j], redirectlock);
1447 for(j = 0; j < locklen; j++) {
1448 if(locks[j] == lock) {
1451 } else if(locks[j] > lock) {
1458 locks[h] = locks[h-1];
1467 return (int *)redirectlock;
1469 return (int *)(locks[0]);
1474 void addAliasLock(void * ptr,
1476 struct ___Object___ * obj = (struct ___Object___ *)ptr;
1477 if(((int)ptr != lock) && (obj->lock != (int*)lock)) {
1478 // originally no alias lock associated or have a different alias lock
1479 // flush it as the new one
1480 obj->lock = (int *)lock;
1485 inline void setTaskExitIndex(int index) {
1486 taskInfoArray[taskInfoIndex]->exitIndex = index;
1489 inline void addNewObjInfo(void * nobj) {
1490 if(taskInfoArray[taskInfoIndex]->newObjs == NULL) {
1491 taskInfoArray[taskInfoIndex]->newObjs = createQueue();
1493 addNewItem(taskInfoArray[taskInfoIndex]->newObjs, nobj);
1498 // Only allocate local mem chunks to each core.
1499 // If a core has used up its local shared memory, start gc.
1500 void * localmalloc_I(int coren,
1504 int gccorenum = (coren < NUMCORES4GC) ? (coren) : (coren % NUMCORES4GC);
1507 int tofindb = gc_core2block[2*gccorenum+i]+(NUMCORES4GC*2)*j;
1508 int totest = tofindb;
1509 int bound = BAMBOO_SMEM_SIZE_L;
1513 bound = (totest < NUMCORES4GC) ? BAMBOO_SMEM_SIZE_L : BAMBOO_SMEM_SIZE;
1514 int nsize = bamboo_smemtbl[totest];
1515 bool islocal = true;
1517 bool tocheck = true;
1518 // have some space in the block
1519 if(totest == tofindb) {
1520 // the first partition
1521 size = bound - nsize;
1522 } else if(nsize == 0) {
1523 // an empty partition, can be appended
1526 // not an empty partition, can not be appended
1527 // the last continuous block is not big enough, go to check the next
1531 } // if(totest == tofindb) else if(nsize == 0) else ...
1534 // have enough space in the block, malloc
1538 // no enough space yet, try to append next continuous block
1540 } // if(size > isize) else ...
1542 } // if(nsize < bound)
1544 // no space in the block, go to check the next block
1550 tofindb = totest = gc_core2block[2*gccorenum+i]+(NUMCORES4GC*2)*j;
1553 } // if(islocal) else ...
1554 if(totest > gcnumblock-1-bamboo_reserved_smem) {
1555 // no more local mem, do not find suitable block
1558 } // if(totest > gcnumblock-1-bamboo_reserved_smem) ...
1561 if(foundsmem == 1) {
1562 // find suitable block
1563 mem = gcbaseva+bamboo_smemtbl[tofindb]+((tofindb<NUMCORES4GC) ?
1564 (BAMBOO_SMEM_SIZE_L*tofindb) : (BAMBOO_LARGE_SMEM_BOUND+
1565 (tofindb-NUMCORES4GC)*BAMBOO_SMEM_SIZE));
1567 // set bamboo_smemtbl
1568 for(i = tofindb; i <= totest; i++) {
1569 bamboo_smemtbl[i]=(i<NUMCORES4GC)?BAMBOO_SMEM_SIZE_L:BAMBOO_SMEM_SIZE;
1571 } else if(foundsmem == 2) {
1572 // no suitable block
1577 } // void * localmalloc_I(int, int, int *)
1580 // Allocate the local shared memory to each core with the highest priority,
1581 // if a core has used up its local shared memory, try to allocate the
1582 // shared memory that belong to its neighbours, if also failed, start gc.
1583 void * fixedmalloc_I(int coren,
1590 int gccorenum = (coren < NUMCORES4GC) ? (coren) : (coren % NUMCORES4GC);
1591 int coords_x = bamboo_cpu2coords[gccorenum*2];
1592 int coords_y = bamboo_cpu2coords[gccorenum*2+1];
1594 int tofindb = gc_core2block[2*core2test[gccorenum][k]+i]+(NUMCORES4GC*2)*j;
1595 int totest = tofindb;
1596 int bound = BAMBOO_SMEM_SIZE_L;
1600 bound = (totest < NUMCORES4GC) ? BAMBOO_SMEM_SIZE_L : BAMBOO_SMEM_SIZE;
1601 int nsize = bamboo_smemtbl[totest];
1602 bool islocal = true;
1604 bool tocheck = true;
1605 // have some space in the block
1606 if(totest == tofindb) {
1607 // the first partition
1608 size = bound - nsize;
1609 } else if(nsize == 0) {
1610 // an empty partition, can be appended
1613 // not an empty partition, can not be appended
1614 // the last continuous block is not big enough, go to check the next
1618 } // if(totest == tofindb) else if(nsize == 0) else ...
1621 // have enough space in the block, malloc
1625 // no enough space yet, try to append next continuous block
1626 // TODO may consider to go to next local block?
1628 } // if(size > isize) else ...
1630 } // if(nsize < bound)
1632 // no space in the block, go to check the next block
1639 gc_core2block[2*core2test[gccorenum][k]+i]+(NUMCORES4GC*2)*j;
1642 } // if(islocal) else ...
1643 if(totest > gcnumblock-1-bamboo_reserved_smem) {
1644 // no more local mem, do not find suitable block on local mem
1645 // try to malloc shared memory assigned to the neighbour cores
1648 if(k >= NUM_CORES2TEST) {
1649 // no more memory available on either coren or its neighbour cores
1651 goto memsearchresult;
1653 } while(core2test[gccorenum][k] == -1);
1657 gc_core2block[2*core2test[gccorenum][k]+i]+(NUMCORES4GC*2)*j;
1658 } // if(totest > gcnumblock-1-bamboo_reserved_smem) ...
1662 if(foundsmem == 1) {
1663 // find suitable block
1664 mem = gcbaseva+bamboo_smemtbl[tofindb]+((tofindb<NUMCORES4GC) ?
1665 (BAMBOO_SMEM_SIZE_L*tofindb) : (BAMBOO_LARGE_SMEM_BOUND+
1666 (tofindb-NUMCORES4GC)*BAMBOO_SMEM_SIZE));
1668 // set bamboo_smemtbl
1669 for(i = tofindb; i <= totest; i++) {
1670 bamboo_smemtbl[i]=(i<NUMCORES4GC)?BAMBOO_SMEM_SIZE_L:BAMBOO_SMEM_SIZE;
1672 } else if(foundsmem == 2) {
1673 // no suitable block
1678 } // void * fixedmalloc_I(int, int, int *)
1679 #endif // #ifdef SMEMF
1682 // Allocate the local shared memory to each core with the highest priority,
1683 // if a core has used up its local shared memory, try to allocate the
1684 // shared memory that belong to its neighbours first, if failed, check
1685 // current memory allocation rate, if it has already reached the threshold,
1686 // start gc, otherwise, allocate the shared memory globally. If all the
1687 // shared memory has been used up, start gc.
1688 void * mixedmalloc_I(int coren,
1695 int gccorenum = (coren < NUMCORES4GC) ? (coren) : (coren % NUMCORES4GC);
1697 int tofindb = gc_core2block[2*core2test[gccorenum][k]+i]+(NUMCORES4GC*2)*j;
1698 int totest = tofindb;
1699 int bound = BAMBOO_SMEM_SIZE_L;
1703 bound = (totest < NUMCORES4GC) ? BAMBOO_SMEM_SIZE_L : BAMBOO_SMEM_SIZE;
1704 int nsize = bamboo_smemtbl[totest];
1705 bool islocal = true;
1707 bool tocheck = true;
1708 // have some space in the block
1709 if(totest == tofindb) {
1710 // the first partition
1711 size = bound - nsize;
1712 } else if(nsize == 0) {
1713 // an empty partition, can be appended
1716 // not an empty partition, can not be appended
1717 // the last continuous block is not big enough, go to check the next
1721 } // if(totest == tofindb) else if(nsize == 0) else ...
1724 // have enough space in the block, malloc
1728 // no enough space yet, try to append next continuous block
1729 // TODO may consider to go to next local block?
1731 } // if(size > isize) else ...
1733 } // if(nsize < bound)
1735 // no space in the block, go to check the next block
1742 gc_core2block[2*core2test[gccorenum][k]+i]+(NUMCORES4GC*2)*j;
1745 } // if(islocal) else ...
1746 if(totest > gcnumblock-1-bamboo_reserved_smem) {
1747 // no more local mem, do not find suitable block on local mem
1748 // try to malloc shared memory assigned to the neighbour cores
1751 if(k >= NUM_CORES2TEST) {
1752 if(gcmem_mixed_usedmem >= gcmem_mixed_threshold) {
1753 // no more memory available on either coren or its neighbour cores
1755 goto memmixedsearchresult;
1757 // try allocate globally
1758 mem = globalmalloc_I(coren, isize, allocsize);
1762 } while(core2test[gccorenum][k] == -1);
1766 gc_core2block[2*core2test[gccorenum][k]+i]+(NUMCORES4GC*2)*j;
1767 } // if(totest > gcnumblock-1-bamboo_reserved_smem) ...
1770 memmixedsearchresult:
1771 if(foundsmem == 1) {
1772 // find suitable block
1773 mem = gcbaseva+bamboo_smemtbl[tofindb]+((tofindb<NUMCORES4GC) ?
1774 (BAMBOO_SMEM_SIZE_L*tofindb) : (BAMBOO_LARGE_SMEM_BOUND+
1775 (tofindb-NUMCORES4GC)*BAMBOO_SMEM_SIZE));
1777 // set bamboo_smemtbl
1778 for(i = tofindb; i <= totest; i++) {
1779 bamboo_smemtbl[i]=(i<NUMCORES4GC)?BAMBOO_SMEM_SIZE_L:BAMBOO_SMEM_SIZE;
1781 gcmem_mixed_usedmem += size;
1782 if(tofindb == bamboo_free_block) {
1783 bamboo_free_block = totest+1;
1785 } else if(foundsmem == 2) {
1786 // no suitable block
1791 } // void * mixedmalloc_I(int, int, int *)
1792 #endif // #ifdef SMEMM
1794 // Allocate all the memory chunks globally, do not consider the host cores
1795 // When all the shared memory are used up, start gc.
1796 void * globalmalloc_I(int coren,
1800 int tofindb = bamboo_free_block; //0;
1801 int totest = tofindb;
1802 int bound = BAMBOO_SMEM_SIZE_L;
1805 if(tofindb > gcnumblock-1-bamboo_reserved_smem) {
1806 // Out of shared memory
1811 bound = (totest < NUMCORES4GC) ? BAMBOO_SMEM_SIZE_L : BAMBOO_SMEM_SIZE;
1812 int nsize = bamboo_smemtbl[totest];
1813 bool isnext = false;
1815 bool tocheck = true;
1816 // have some space in the block
1817 if(totest == tofindb) {
1818 // the first partition
1819 size = bound - nsize;
1820 } else if(nsize == 0) {
1821 // an empty partition, can be appended
1824 // not an empty partition, can not be appended
1825 // the last continuous block is not big enough, start another block
1828 } // if(totest == tofindb) else if(nsize == 0) else ...
1831 // have enough space in the block, malloc
1834 } // if(size > isize)
1838 } // if(nsize < bound) else ...
1840 if(totest > gcnumblock-1-bamboo_reserved_smem) {
1841 // no more local mem, do not find suitable block
1844 } // if(totest > gcnumblock-1-bamboo_reserved_smem) ...
1846 // start another block
1851 if(foundsmem == 1) {
1852 // find suitable block
1853 mem = gcbaseva+bamboo_smemtbl[tofindb]+((tofindb<NUMCORES4GC) ?
1854 (BAMBOO_SMEM_SIZE_L*tofindb) : (BAMBOO_LARGE_SMEM_BOUND+
1855 (tofindb-NUMCORES4GC)*BAMBOO_SMEM_SIZE));
1857 // set bamboo_smemtbl
1858 for(int i = tofindb; i <= totest; i++) {
1859 bamboo_smemtbl[i]=(i<NUMCORES4GC)?BAMBOO_SMEM_SIZE_L:BAMBOO_SMEM_SIZE;
1861 if(tofindb == bamboo_free_block) {
1862 bamboo_free_block = totest+1;
1864 } else if(foundsmem == 2) {
1865 // no suitable block
1871 } // void * globalmalloc_I(int, int, int *)
1872 #endif // #ifdef MULTICORE_GC
1874 // malloc from the shared memory
1875 void * smemalloc_I(int coren,
1880 int isize = size+(BAMBOO_CACHE_LINE_SIZE);
1882 // go through the bamboo_smemtbl for suitable partitions
1883 switch(bamboo_smem_mode) {
1885 mem = localmalloc_I(coren, isize, allocsize);
1891 mem = fixedmalloc_I(coren, isize, allocsize);
1893 // not supported yet
1894 BAMBOO_EXIT(0xe001);
1901 mem = mixedmalloc_I(coren, isize, allocsize);
1903 // not supported yet
1904 BAMBOO_EXIT(0xe002);
1910 mem = globalmalloc_I(coren, isize, allocsize);
1920 int toallocate = (size>(BAMBOO_SMEM_SIZE)) ? (size) : (BAMBOO_SMEM_SIZE);
1921 if(toallocate > bamboo_free_smem_size) {
1925 mem = (void *)bamboo_free_smemp;
1926 bamboo_free_smemp = ((void*)bamboo_free_smemp) + toallocate;
1927 bamboo_free_smem_size -= toallocate;
1929 *allocsize = toallocate;
1931 #endif // MULTICORE_GC
1932 // no enough shared global memory
1937 // inform other cores to stop and wait for gc
1939 for(int i = 0; i < NUMCORESACTIVE; i++) {
1940 // reuse the gcnumsendobjs & gcnumreceiveobjs
1941 gccorestatus[i] = 1;
1942 gcnumsendobjs[0][i] = 0;
1943 gcnumreceiveobjs[0][i] = 0;
1945 for(int i = 0; i < NUMCORESACTIVE; i++) {
1946 if(i != BAMBOO_NUM_OF_CORE) {
1947 if(BAMBOO_CHECK_SEND_MODE()) {
1948 cache_msg_1(i, GCSTARTPRE);
1950 send_msg_1(i, GCSTARTPRE, true);
1957 BAMBOO_DEBUGPRINT(0xe003);
1958 BAMBOO_EXIT(0xe003);
1962 } // void * smemalloc_I(int, int, int)
1964 INLINE int checkMsgLength_I(int size) {
1967 BAMBOO_DEBUGPRINT(0xcccc);
1970 int type = msgdata[msgdataindex];
1978 case GCSTARTMAPINFO:
1983 #ifdef GC_CACHE_ADAPT
1985 #endif // GC_CACHE_ADAPT
1986 #endif // MULTICORE_GC
1995 case GCSTARTCOMPACT:
1998 case GCFINISHMAPINFO:
2000 #ifdef GC_CACHE_ADAPT
2002 #endif // GC_CACHE_ADAPT
2003 #endif // MULTICORE_GC
2026 case REDIRECTGROUNT:
2028 case REDIRECTRELEASE:
2045 case GCFINISHCOMPACT:
2059 case TRANSOBJ: // nonfixed size
2065 msglength = msgdata[msgdataindex+1];
2074 BAMBOO_DEBUGPRINT_REG(type);
2075 BAMBOO_DEBUGPRINT_REG(size);
2076 BAMBOO_DEBUGPRINT_REG(msgdataindex);
2077 BAMBOO_DEBUGPRINT_REG(msgdatalast);
2078 BAMBOO_DEBUGPRINT_REG(msgdatafull);
2081 BAMBOO_DEBUGPRINT(msgdata[msgdataindex+i]);
2083 BAMBOO_EXIT(0xe004);
2089 BAMBOO_DEBUGPRINT_REG(msgdata[msgdataindex]);
2094 BAMBOO_DEBUGPRINT(0xffff);
2100 INLINE void processmsg_transobj_I() {
2101 #ifdef PROFILE_INTERRUPT
2102 /*if(!interruptInfoOverflow) {
2103 InterruptInfo* intInfo = RUNMALLOC_I(sizeof(struct interrupt_info));
2104 interruptInfoArray[interruptInfoIndex] = intInfo;
2105 intInfo->startTime = BAMBOO_GET_EXE_TIME();
2106 intInfo->endTime = -1;
2110 struct transObjInfo * transObj=RUNMALLOC_I(sizeof(struct transObjInfo));
2114 BAMBOO_DEBUGPRINT(0xe880);
2117 if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) {
2119 BAMBOO_DEBUGPRINT_REG(msgdata[msgdataindex] /*[2]*/);
2121 BAMBOO_EXIT(0xe005);
2123 // store the object and its corresponding queue info, enqueue it later
2124 transObj->objptr = (void *)msgdata[msgdataindex]; //[2]
2126 transObj->length = (msglength - 3) / 2;
2127 transObj->queues = RUNMALLOC_I(sizeof(int)*(msglength - 3));
2128 for(k = 0; k < transObj->length; ++k) {
2129 transObj->queues[2*k] = msgdata[msgdataindex]; //[3+2*k];
2133 //BAMBOO_DEBUGPRINT_REG(transObj->queues[2*k]);
2136 transObj->queues[2*k+1] = msgdata[msgdataindex]; //[3+2*k+1];
2140 //BAMBOO_DEBUGPRINT_REG(transObj->queues[2*k+1]);
2144 // check if there is an existing duplicate item
2146 struct QueueItem * qitem = getHead(&objqueue);
2147 struct QueueItem * prev = NULL;
2148 while(qitem != NULL) {
2149 struct transObjInfo * tmpinfo =
2150 (struct transObjInfo *)(qitem->objectptr);
2151 if(tmpinfo->objptr == transObj->objptr) {
2152 // the same object, remove outdate one
2153 RUNFREE(tmpinfo->queues);
2155 removeItem(&objqueue, qitem);
2161 qitem = getHead(&objqueue);
2163 qitem = getNextQueueItem(prev);
2166 addNewItem_I(&objqueue, (void *)transObj);
2168 ++(self_numreceiveobjs);
2171 if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
2172 // set the gcprecheck to enable checking again
2175 // send a update pregc information msg to the master core
2176 if(BAMBOO_CHECK_SEND_MODE()) {
2177 cache_msg_4(STARTUPCORE, GCFINISHPRE, BAMBOO_NUM_OF_CORE,
2178 self_numsendobjs, self_numreceiveobjs);
2180 send_msg_4(STARTUPCORE, GCFINISHPRE, BAMBOO_NUM_OF_CORE,
2181 self_numsendobjs, self_numreceiveobjs, true);
2186 #ifdef PROFILE_INTERRUPT
2187 /*if(!interruptInfoOverflow) {
2188 interruptInfoArray[interruptInfoIndex]->endTime=BAMBOO_GET_EXE_TIME();
2189 interruptInfoIndex++;
2190 if(interruptInfoIndex == INTERRUPTINFOLENGTH) {
2191 interruptInfoOverflow = true;
2197 INLINE void processmsg_transtall_I() {
2198 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
2199 // non startup core can not receive stall msg
2201 BAMBOO_DEBUGPRINT_REG(msgdata[msgdataindex] /*[1]*/);
2203 BAMBOO_EXIT(0xe006);
2205 int num_core = msgdata[msgdataindex]; //[1]
2207 if(num_core < NUMCORESACTIVE) {
2210 BAMBOO_DEBUGPRINT(0xe881);
2213 corestatus[num_core] = 0;
2214 numsendobjs[num_core] = msgdata[msgdataindex]; //[2];
2216 numreceiveobjs[num_core] = msgdata[msgdataindex]; //[3];
2221 #ifndef MULTICORE_GC
2222 INLINE void processmsg_lockrequest_I() {
2223 // check to see if there is a lock exist for the required obj
2224 // msgdata[1] -> lock type
2225 int locktype = msgdata[msgdataindex]; //[1];
2227 int data2 = msgdata[msgdataindex]; // obj pointer
2229 int data3 = msgdata[msgdataindex]; // lock
2231 int data4 = msgdata[msgdataindex]; // request core
2233 // -1: redirected, 0: approved, 1: denied
2234 int deny=processlockrequest(locktype, data3, data2, data4, data4, true);
2236 // this lock request is redirected
2239 // send response msg
2240 // for 32 bit machine, the size is always 4 words, cache the msg first
2241 int tmp = deny==1 ? LOCKDENY : LOCKGROUNT;
2242 if(BAMBOO_CHECK_SEND_MODE()) {
2243 cache_msg_4(data4, tmp, locktype, data2, data3);
2245 send_msg_4(data4, tmp, locktype, data2, data3, true);
2250 INLINE void processmsg_lockgrount_I() {
2252 if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) {
2254 BAMBOO_DEBUGPRINT_REG(msgdata[msgdataindex] /*[2]*/);
2256 BAMBOO_EXIT(0xe007);
2258 int data2 = msgdata[msgdataindex];
2260 int data3 = msgdata[msgdataindex];
2262 if((lockobj == data2) && (lock2require == data3)) {
2265 BAMBOO_DEBUGPRINT(0xe882);
2274 // conflicts on lockresults
2276 BAMBOO_DEBUGPRINT_REG(data2);
2278 BAMBOO_EXIT(0xe008);
2282 INLINE void processmsg_lockdeny_I() {
2284 int data2 = msgdata[msgdataindex];
2286 int data3 = msgdata[msgdataindex];
2288 if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) {
2290 BAMBOO_DEBUGPRINT_REG(data2);
2292 BAMBOO_EXIT(0xe009);
2294 if((lockobj == data2) && (lock2require == data3)) {
2297 BAMBOO_DEBUGPRINT(0xe883);
2306 // conflicts on lockresults
2308 BAMBOO_DEBUGPRINT_REG(data2);
2310 BAMBOO_EXIT(0xe00a);
2314 INLINE void processmsg_lockrelease_I() {
2315 int data1 = msgdata[msgdataindex];
2317 int data2 = msgdata[msgdataindex];
2319 // receive lock release msg
2320 processlockrelease(data1, data2, 0, false);
2323 INLINE void processmsg_redirectlock_I() {
2324 // check to see if there is a lock exist for the required obj
2325 int data1 = msgdata[msgdataindex];
2326 MSG_INDEXINC_I(); //msgdata[1]; // lock type
2327 int data2 = msgdata[msgdataindex];
2328 MSG_INDEXINC_I(); //msgdata[2]; // obj pointer
2329 int data3 = msgdata[msgdataindex];
2330 MSG_INDEXINC_I(); //msgdata[3]; // redirect lock
2331 int data4 = msgdata[msgdataindex];
2332 MSG_INDEXINC_I(); //msgdata[4]; // root request core
2333 int data5 = msgdata[msgdataindex];
2334 MSG_INDEXINC_I(); //msgdata[5]; // request core
2335 int deny = processlockrequest(data1, data3, data2, data5, data4, true);
2337 // this lock request is redirected
2340 // send response msg
2341 // for 32 bit machine, the size is always 4 words, cache the msg first
2342 if(BAMBOO_CHECK_SEND_MODE()) {
2343 cache_msg_4(data4, deny==1 ? REDIRECTDENY : REDIRECTGROUNT,
2344 data1, data2, data3);
2346 send_msg_4(data4, deny==1?REDIRECTDENY:REDIRECTGROUNT,
2347 data1, data2, data3, true);
2352 INLINE void processmsg_redirectgrount_I() {
2354 int data2 = msgdata[msgdataindex];
2356 if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) {
2358 BAMBOO_DEBUGPRINT_REG(data2);
2360 BAMBOO_EXIT(0xe00b);
2362 if(lockobj == data2) {
2365 BAMBOO_DEBUGPRINT(0xe891);
2368 int data3 = msgdata[msgdataindex];
2372 RuntimeHashadd_I(objRedirectLockTbl, lockobj, data3);
2377 // conflicts on lockresults
2379 BAMBOO_DEBUGPRINT_REG(data2);
2381 BAMBOO_EXIT(0xe00c);
2385 INLINE void processmsg_redirectdeny_I() {
2387 int data2 = msgdata[msgdataindex];
2389 if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) {
2391 BAMBOO_DEBUGPRINT_REG(data2);
2393 BAMBOO_EXIT(0xe00d);
2395 if(lockobj == data2) {
2398 BAMBOO_DEBUGPRINT(0xe892);
2407 // conflicts on lockresults
2409 BAMBOO_DEBUGPRINT_REG(data2);
2411 BAMBOO_EXIT(0xe00e);
2415 INLINE void processmsg_redirectrelease_I() {
2416 int data1 = msgdata[msgdataindex];
2418 int data2 = msgdata[msgdataindex];
2420 int data3 = msgdata[msgdataindex];
2422 processlockrelease(data1, data2, data3, true);
2424 #endif // #ifndef MULTICORE_GC
2427 INLINE void processmsg_profileoutput_I() {
2428 if(BAMBOO_NUM_OF_CORE == STARTUPCORE) {
2429 // startup core can not receive profile output finish msg
2430 BAMBOO_EXIT(0xe00f);
2434 BAMBOO_DEBUGPRINT(0xe885);
2438 totalexetime = msgdata[msgdataindex]; //[1]
2441 BAMBOO_DEBUGPRINT_REG(dot_num);
2443 outputProfileData();
2445 // cache the msg first
2446 if(BAMBOO_CHECK_SEND_MODE()) {
2447 cache_msg_2(STARTUPCORE, PROFILEFINISH, BAMBOO_NUM_OF_CORE);
2449 send_msg_2(STARTUPCORE, PROFILEFINISH, BAMBOO_NUM_OF_CORE, true);
2453 INLINE void processmsg_profilefinish_I() {
2454 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
2455 // non startup core can not receive profile output finish msg
2457 BAMBOO_DEBUGPRINT_REG(msgdata[msgdataindex /*1*/]);
2459 BAMBOO_EXIT(0xe010);
2463 BAMBOO_DEBUGPRINT(0xe886);
2466 int data1 = msgdata[msgdataindex];
2468 profilestatus[data1] = 0;
2470 #endif // #ifdef PROFILE
2472 INLINE void processmsg_statusconfirm_I() {
2473 if((BAMBOO_NUM_OF_CORE == STARTUPCORE)
2474 || (BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1)) {
2475 // wrong core to receive such msg
2476 BAMBOO_EXIT(0xe011);
2478 // send response msg
2481 BAMBOO_DEBUGPRINT(0xe887);
2484 // cache the msg first
2485 if(BAMBOO_CHECK_SEND_MODE()) {
2486 cache_msg_5(STARTUPCORE, STATUSREPORT,
2487 busystatus ? 1 : 0, BAMBOO_NUM_OF_CORE,
2488 self_numsendobjs, self_numreceiveobjs);
2490 send_msg_5(STARTUPCORE, STATUSREPORT, busystatus?1:0,
2491 BAMBOO_NUM_OF_CORE, self_numsendobjs,
2492 self_numreceiveobjs, true);
2497 INLINE void processmsg_statusreport_I() {
2498 int data1 = msgdata[msgdataindex];
2500 int data2 = msgdata[msgdataindex];
2502 int data3 = msgdata[msgdataindex];
2504 int data4 = msgdata[msgdataindex];
2506 // receive a status confirm info
2507 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
2508 // wrong core to receive such msg
2510 BAMBOO_DEBUGPRINT_REG(data2);
2512 BAMBOO_EXIT(0xe012);
2516 BAMBOO_DEBUGPRINT(0xe888);
2522 corestatus[data2] = data1;
2523 numsendobjs[data2] = data3;
2524 numreceiveobjs[data2] = data4;
2528 INLINE void processmsg_terminate_I() {
2531 BAMBOO_DEBUGPRINT(0xe889);
2536 #ifdef GC_CACHE_ADAPT
2537 bamboo_mask_timer_intr(); // disable the TILE_TIMER interrupt
2538 #endif // GC_CACHE_ADAPT
2539 #endif // MULTICORE_GC
2543 INLINE void processmsg_memrequest_I() {
2544 #ifdef PROFILE_INTERRUPT
2545 /*if(!interruptInfoOverflow) {
2546 InterruptInfo* intInfo = RUNMALLOC_I(sizeof(struct interrupt_info));
2547 interruptInfoArray[interruptInfoIndex] = intInfo;
2548 intInfo->startTime = BAMBOO_GET_EXE_TIME();
2549 intInfo->endTime = -1;
2552 int data1 = msgdata[msgdataindex];
2554 int data2 = msgdata[msgdataindex];
2556 // receive a shared memory request msg
2557 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
2558 // wrong core to receive such msg
2560 BAMBOO_DEBUGPRINT_REG(data2);
2562 BAMBOO_EXIT(0xe013);
2566 BAMBOO_DEBUGPRINT(0xe88a);
2573 // is currently doing gc, dump this msg
2574 if(INITPHASE == gcphase) {
2575 // if still in the initphase of gc, send a startinit msg again,
2576 // cache the msg first
2577 if(BAMBOO_CHECK_SEND_MODE()) {
2578 cache_msg_1(data2, GCSTARTINIT);
2580 send_msg_1(data2, GCSTARTINIT, true);
2585 mem = smemalloc_I(data2, data1, &allocsize);
2587 // send the start_va to request core, cache the msg first
2588 if(BAMBOO_CHECK_SEND_MODE()) {
2589 cache_msg_3(data2, MEMRESPONSE, mem, allocsize);
2591 send_msg_3(data2, MEMRESPONSE, mem, allocsize, true);
2594 // if mem == NULL, the gcflag of the startup core has been set
2595 // and all the other cores have been informed to start gc
2600 #ifdef PROFILE_INTERRUPT
2601 /*if(!interruptInfoOverflow) {
2602 interruptInfoArray[interruptInfoIndex]->endTime=BAMBOO_GET_EXE_TIME();
2603 interruptInfoIndex++;
2604 if(interruptInfoIndex == INTERRUPTINFOLENGTH) {
2605 interruptInfoOverflow = true;
2611 INLINE void processmsg_memresponse_I() {
2612 int data1 = msgdata[msgdataindex];
2614 int data2 = msgdata[msgdataindex];
2616 // receive a shared memory response msg
2619 BAMBOO_DEBUGPRINT(0xe88b);
2623 // if is currently doing gc, dump this msg
2627 bamboo_smem_size = 0;
2630 bamboo_smem_zero_top = 0;
2634 // fill header to store the size of this mem block
2635 BAMBOO_MEMSET_WH(data1, '\0', BAMBOO_CACHE_LINE_SIZE);
2636 //memset(data1, 0, BAMBOO_CACHE_LINE_SIZE);
2637 (*((int*)data1)) = data2;
2638 bamboo_smem_size = data2 - BAMBOO_CACHE_LINE_SIZE;
2639 bamboo_cur_msp = data1 + BAMBOO_CACHE_LINE_SIZE;
2640 bamboo_smem_zero_top = bamboo_cur_msp;
2642 bamboo_smem_size = data2;
2643 bamboo_cur_msp =(void*)(data1);
2653 INLINE void processmsg_gcstartpre_I() {
2655 // already stall for gc
2656 // send a update pregc information msg to the master core
2657 if(BAMBOO_CHECK_SEND_MODE()) {
2658 cache_msg_4(STARTUPCORE, GCFINISHPRE, BAMBOO_NUM_OF_CORE,
2659 self_numsendobjs, self_numreceiveobjs);
2661 send_msg_4(STARTUPCORE, GCFINISHPRE, BAMBOO_NUM_OF_CORE,
2662 self_numsendobjs, self_numreceiveobjs, true);
2665 // the first time to be informed to start gc
2668 // is waiting for response of mem request
2669 // let it return NULL and start gc
2670 bamboo_smem_size = 0;
2671 bamboo_cur_msp = NULL;
2673 bamboo_smem_zero_top = NULL;
2678 INLINE void processmsg_gcstartinit_I() {
2679 gcphase = INITPHASE;
2682 INLINE void processmsg_gcstart_I() {
2685 BAMBOO_DEBUGPRINT(0xe88c);
2689 gcphase = MARKPHASE;
2692 INLINE void processmsg_gcstartcompact_I() {
2693 gcblock2fill = msgdata[msgdataindex];
2694 MSG_INDEXINC_I(); //msgdata[1];
2695 gcphase = COMPACTPHASE;
2698 INLINE void processmsg_gcstartmapinfo_I() {
2702 INLINE void processmsg_gcstartflush_I() {
2703 gcphase = FLUSHPHASE;
2706 INLINE void processmsg_gcfinishpre_I() {
2707 int data1 = msgdata[msgdataindex];
2709 int data2 = msgdata[msgdataindex];
2711 int data3 = msgdata[msgdataindex];
2713 // received a init phase finish msg
2714 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
2715 // non startup core can not receive this msg
2717 BAMBOO_DEBUGPRINT_REG(data1);
2719 BAMBOO_EXIT(0xe014);
2721 // All cores should do init GC
2725 gccorestatus[data1] = 0;
2726 gcnumsendobjs[0][data1] = data2;
2727 gcnumreceiveobjs[0][data1] = data3;
2730 INLINE void processmsg_gcfinishinit_I() {
2731 int data1 = msgdata[msgdataindex];
2733 // received a init phase finish msg
2734 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
2735 // non startup core can not receive this msg
2737 BAMBOO_DEBUGPRINT_REG(data1);
2739 BAMBOO_EXIT(0xe015);
2742 BAMBOO_DEBUGPRINT(0xe88c);
2743 BAMBOO_DEBUGPRINT_REG(data1);
2745 // All cores should do init GC
2746 if(data1 < NUMCORESACTIVE) {
2747 gccorestatus[data1] = 0;
2751 INLINE void processmsg_gcfinishmark_I() {
2752 int data1 = msgdata[msgdataindex];
2754 int data2 = msgdata[msgdataindex];
2756 int data3 = msgdata[msgdataindex];
2758 // received a mark phase finish msg
2759 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
2760 // non startup core can not receive this msg
2762 BAMBOO_DEBUGPRINT_REG(data1);
2764 BAMBOO_EXIT(0xe016);
2766 // all cores should do mark
2767 if(data1 < NUMCORESACTIVE) {
2768 gccorestatus[data1] = 0;
2769 int entry_index = 0;
2772 entry_index = (gcnumsrobjs_index == 0) ? 1 : 0;
2775 entry_index = gcnumsrobjs_index;
2777 gcnumsendobjs[entry_index][data1] = data2;
2778 gcnumreceiveobjs[entry_index][data1] = data3;
2782 INLINE void processmsg_gcfinishcompact_I() {
2783 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
2784 // non startup core can not receive this msg
2787 BAMBOO_DEBUGPRINT_REG(msgdata[msgdataindex] /*[1]*/);
2789 BAMBOO_EXIT(0xe017);
2791 int cnum = msgdata[msgdataindex];
2792 MSG_INDEXINC_I(); //msgdata[1];
2793 int filledblocks = msgdata[msgdataindex];
2794 MSG_INDEXINC_I(); //msgdata[2];
2795 int heaptop = msgdata[msgdataindex];
2796 MSG_INDEXINC_I(); //msgdata[3];
2797 int data4 = msgdata[msgdataindex];
2798 MSG_INDEXINC_I(); //msgdata[4];
2799 // only gc cores need to do compact
2800 if(cnum < NUMCORES4GC) {
2801 if(COMPACTPHASE == gcphase) {
2802 gcfilledblocks[cnum] = filledblocks;
2803 gcloads[cnum] = heaptop;
2810 if(gcfindSpareMem_I(&startaddr, &tomove, &dstcore, data4, cnum)) {
2811 // cache the msg first
2812 if(BAMBOO_CHECK_SEND_MODE()) {
2813 cache_msg_4(cnum, GCMOVESTART, dstcore, startaddr, tomove);
2815 send_msg_4(cnum, GCMOVESTART, dstcore, startaddr, tomove, true);
2819 gccorestatus[cnum] = 0;
2821 } // if(cnum < NUMCORES4GC)
2824 INLINE void processmsg_gcfinishmapinfo_I() {
2825 int data1 = msgdata[msgdataindex];
2827 // received a map phase finish msg
2828 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
2829 // non startup core can not receive this msg
2831 BAMBOO_DEBUGPRINT_REG(data1);
2833 BAMBOO_EXIT(0xe018);
2835 // all cores should do flush
2836 if(data1 < NUMCORES4GC) {
2837 gccorestatus[data1] = 0;
2842 INLINE void processmsg_gcfinishflush_I() {
2843 int data1 = msgdata[msgdataindex];
2845 // received a flush phase finish msg
2846 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
2847 // non startup core can not receive this msg
2849 BAMBOO_DEBUGPRINT_REG(data1);
2851 BAMBOO_EXIT(0xe019);
2853 // all cores should do flush
2854 if(data1 < NUMCORESACTIVE) {
2855 gccorestatus[data1] = 0;
2859 INLINE void processmsg_gcmarkconfirm_I() {
2860 if((BAMBOO_NUM_OF_CORE == STARTUPCORE)
2861 || (BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1)) {
2862 // wrong core to receive such msg
2863 BAMBOO_EXIT(0xe01a);
2865 // send response msg, cahce the msg first
2866 if(BAMBOO_CHECK_SEND_MODE()) {
2867 cache_msg_5(STARTUPCORE, GCMARKREPORT, BAMBOO_NUM_OF_CORE,
2868 gcbusystatus, gcself_numsendobjs,
2869 gcself_numreceiveobjs);
2871 send_msg_5(STARTUPCORE, GCMARKREPORT, BAMBOO_NUM_OF_CORE,
2872 gcbusystatus, gcself_numsendobjs,
2873 gcself_numreceiveobjs, true);
2878 INLINE void processmsg_gcmarkreport_I() {
2879 int data1 = msgdata[msgdataindex];
2881 int data2 = msgdata[msgdataindex];
2883 int data3 = msgdata[msgdataindex];
2885 int data4 = msgdata[msgdataindex];
2887 // received a marked phase finish confirm response msg
2888 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
2889 // wrong core to receive such msg
2891 BAMBOO_DEBUGPRINT_REG(data2);
2893 BAMBOO_EXIT(0xe01b);
2895 int entry_index = 0;
2899 entry_index = (gcnumsrobjs_index == 0) ? 1 : 0;
2901 // can never reach here
2903 entry_index = gcnumsrobjs_index;
2905 gccorestatus[data1] = data2;
2906 gcnumsendobjs[entry_index][data1] = data3;
2907 gcnumreceiveobjs[entry_index][data1] = data4;
2911 INLINE void processmsg_gcmarkedobj_I() {
2912 int data1 = msgdata[msgdataindex];
2914 // received a markedObj msg
2915 if(((int *)data1)[6] == INIT) {
2916 // this is the first time that this object is discovered,
2917 // set the flag as DISCOVERED
2918 ((int *)data1)[6] = DISCOVERED;
2919 gc_enqueue_I(data1);
2921 // set the remote flag
2922 ((int *)data1)[6] |= REMOTEM;
2923 gcself_numreceiveobjs++;
2924 gcbusystatus = true;
2927 INLINE void processmsg_gcmovestart_I() {
2929 gcdstcore = msgdata[msgdataindex];
2930 MSG_INDEXINC_I(); //msgdata[1];
2931 gcmovestartaddr = msgdata[msgdataindex];
2932 MSG_INDEXINC_I(); //msgdata[2];
2933 gcblock2fill = msgdata[msgdataindex];
2934 MSG_INDEXINC_I(); //msgdata[3];
2937 INLINE void processmsg_gcmaprequest_I() {
2939 //unsigned long long ttime = BAMBOO_GET_EXE_TIME();
2941 void * dstptr = NULL;
2942 int data1 = msgdata[msgdataindex];
2945 // TODO unsigned long long ttime = BAMBOO_GET_EXE_TIME();
2947 #ifdef LOCALHASHTBL_TEST
2948 RuntimeHashget(gcpointertbl, data1, &dstptr);
2950 dstptr = mgchashSearch(gcpointertbl, data1);
2952 //MGCHashget(gcpointertbl, data1, &dstptr);
2954 // TODO flushstalltime += BAMBOO_GET_EXE_TIME() - ttime;
2956 int data2 = msgdata[msgdataindex];
2959 // TODO unsigned long long ttimei = BAMBOO_GET_EXE_TIME();
2961 if(NULL == dstptr) {
2962 // no such pointer in this core, something is wrong
2964 BAMBOO_DEBUGPRINT_REG(data1);
2965 BAMBOO_DEBUGPRINT_REG(data2);
2967 BAMBOO_EXIT(0xe01c);
2968 //assume that the object was not moved, use the original address
2969 /*if(isMsgSending) {
2970 cache_msg_3(msgdata[2], GCMAPINFO, msgdata[1], msgdata[1]);
2972 send_msg_3(msgdata[2], GCMAPINFO, msgdata[1], msgdata[1]);
2975 // send back the mapping info, cache the msg first
2976 if(BAMBOO_CHECK_SEND_MODE()) {
2977 cache_msg_3(data2, GCMAPINFO, data1, (int)dstptr);
2979 send_msg_3(data2, GCMAPINFO, data1, (int)dstptr, true);
2983 // TODO flushstalltime_i += BAMBOO_GET_EXE_TIME()-ttimei;
2984 //num_mapinforequest_i++;
2988 INLINE void processmsg_gcmapinfo_I() {
2990 //unsigned long long ttime = BAMBOO_GET_EXE_TIME();
2992 int data1 = msgdata[msgdataindex];
2994 gcmappedobj = msgdata[msgdataindex]; // [2]
2996 #ifdef LOCALHASHTBL_TEST
2997 RuntimeHashadd_I(gcpointertbl, data1, gcmappedobj);
2999 mgchashInsert_I(gcpointertbl, data1, gcmappedobj);
3001 //MGCHashadd_I(gcpointertbl, data1, gcmappedobj);
3002 if(data1 == gcobj2map) {
3006 //flushstalltime += BAMBOO_GET_EXE_TIME() - ttime;
3010 INLINE void processmsg_gcmaptbl_I() {
3011 int data1 = msgdata[msgdataindex];
3013 int data2 = msgdata[msgdataindex];
3015 gcrpointertbls[data2] = (mgcsharedhashtbl_t *)data1; //(struct GCSharedHash *)data1;
3018 INLINE void processmsg_gclobjinfo_I() {
3021 int data1 = msgdata[msgdataindex];
3023 int data2 = msgdata[msgdataindex];
3025 if(BAMBOO_NUM_OF_CORE > NUMCORES4GC - 1) {
3027 BAMBOO_DEBUGPRINT_REG(data2);
3029 BAMBOO_EXIT(0xe01d);
3031 // store the mark result info
3033 gcloads[cnum] = msgdata[msgdataindex];
3034 MSG_INDEXINC_I(); // msgdata[3];
3035 int data4 = msgdata[msgdataindex];
3037 if(gcheaptop < data4) {
3040 // large obj info here
3041 for(int k = 5; k < data1; ) {
3042 int lobj = msgdata[msgdataindex];
3043 MSG_INDEXINC_I(); //msgdata[k++];
3044 int length = msgdata[msgdataindex];
3045 MSG_INDEXINC_I(); //msgdata[k++];
3046 gc_lobjenqueue_I(lobj, length, cnum);
3048 } // for(int k = 5; k < msgdata[1];)
3051 INLINE void processmsg_gclobjmapping_I() {
3052 int data1 = msgdata[msgdataindex];
3054 int data2 = msgdata[msgdataindex];
3056 #ifdef LOCALHASHTBL_TEST
3057 RuntimeHashadd_I(gcpointertbl, data1, data2);
3059 mgchashInsert_I(gcpointertbl, data1, data2);
3061 //MGCHashadd_I(gcpointertbl, data1, data2);
3062 mgcsharedhashInsert_I(gcsharedptbl, data1, data2);
3066 INLINE void processmsg_gcprofiles_I() {
3067 int data1 = msgdata[msgdataindex];
3069 int data2 = msgdata[msgdataindex];
3071 int data3 = msgdata[msgdataindex];
3073 gc_num_obj += data1;
3074 gc_num_liveobj += data2;
3075 gc_num_forwardobj += data3;
3078 #endif // GC_PROFILE
3080 #ifdef GC_CACHE_ADAPT
3081 INLINE void processmsg_gcstartpref_I() {
3082 gcphase = PREFINISHPHASE;
3085 INLINE void processmsg_gcfinishpref_I() {
3086 int data1 = msgdata[msgdataindex];
3088 // received a flush phase finish msg
3089 if(BAMBOO_NUM_OF_CORE != STARTUPCORE) {
3090 // non startup core can not receive this msg
3092 BAMBOO_DEBUGPRINT_REG(data1);
3094 BAMBOO_EXIT(0xe01e);
3096 // all cores should do flush
3097 if(data1 < NUMCORESACTIVE) {
3098 gccorestatus[data1] = 0;
3101 #endif // GC_CACHE_ADAPT
3102 #endif // #ifdef MULTICORE_GC
3104 // receive object transferred from other cores
3105 // or the terminate message from other cores
3106 // Should be invoked in critical sections!!
3107 // NOTICE: following format is for threadsimulate version only
3108 // RAW version please see previous description
3109 // format: type + object
3110 // type: -1--stall msg
3112 // return value: 0--received an object
3113 // 1--received nothing
3114 // 2--received a Stall Msg
3115 // 3--received a lock Msg
3116 // RAW version: -1 -- received nothing
3117 // otherwise -- received msg type
3118 int receiveObject(int send_port_pending) {
3119 #ifdef PROFILE_INTERRUPT
3120 if(!interruptInfoOverflow) {
3121 InterruptInfo* intInfo = RUNMALLOC_I(sizeof(struct interrupt_info));
3122 interruptInfoArray[interruptInfoIndex] = intInfo;
3123 intInfo->startTime = BAMBOO_GET_EXE_TIME();
3124 intInfo->endTime = -1;
3128 // get the incoming msgs
3129 if(receiveMsg(send_port_pending) == -1) {
3133 // processing received msgs
3135 MSG_REMAINSIZE_I(&size);
3136 if((size == 0) || (checkMsgLength_I(size) == -1)) {
3138 // have new coming msg
3139 if((BAMBOO_MSG_AVAIL() != 0) && !msgdatafull) {
3146 if(msglength <= size) {
3147 // have some whole msg
3149 type = msgdata[msgdataindex]; //[0]
3151 msgdatafull = false;
3153 //tprintf("msg type: %x\n", type);
3156 // receive a object transfer msg
3157 processmsg_transobj_I();
3162 // receive a stall msg
3163 processmsg_transtall_I();
3167 // GC version have no lock msgs
3168 #ifndef MULTICORE_GC
3170 // receive lock request msg, handle it right now
3171 processmsg_lockrequest_I();
3173 } // case LOCKREQUEST
3176 // receive lock grount msg
3177 processmsg_lockgrount_I();
3179 } // case LOCKGROUNT
3182 // receive lock deny msg
3183 processmsg_lockdeny_I();
3188 processmsg_lockrelease_I();
3190 } // case LOCKRELEASE
3191 #endif // #ifndef MULTICORE_GC
3194 case PROFILEOUTPUT: {
3195 // receive an output profile data request msg
3196 processmsg_profileoutput_I();
3198 } // case PROFILEOUTPUT
3200 case PROFILEFINISH: {
3201 // receive a profile output finish msg
3202 processmsg_profilefinish_I();
3204 } // case PROFILEFINISH
3205 #endif // #ifdef PROFILE
3207 // GC version has no lock msgs
3208 #ifndef MULTICORE_GC
3209 case REDIRECTLOCK: {
3210 // receive a redirect lock request msg, handle it right now
3211 processmsg_redirectlock_I();
3213 } // case REDIRECTLOCK
3215 case REDIRECTGROUNT: {
3216 // receive a lock grant msg with redirect info
3217 processmsg_redirectgrount_I();
3219 } // case REDIRECTGROUNT
3221 case REDIRECTDENY: {
3222 // receive a lock deny msg with redirect info
3223 processmsg_redirectdeny_I();
3225 } // case REDIRECTDENY
3227 case REDIRECTRELEASE: {
3228 // receive a lock release msg with redirect info
3229 processmsg_redirectrelease_I();
3231 } // case REDIRECTRELEASE
3232 #endif // #ifndef MULTICORE_GC
3234 case STATUSCONFIRM: {
3235 // receive a status confirm info
3236 processmsg_statusconfirm_I();
3238 } // case STATUSCONFIRM
3240 case STATUSREPORT: {
3241 processmsg_statusreport_I();
3243 } // case STATUSREPORT
3246 // receive a terminate msg
3247 processmsg_terminate_I();
3252 processmsg_memrequest_I();
3254 } // case MEMREQUEST
3257 processmsg_memresponse_I();
3259 } // case MEMRESPONSE
3264 processmsg_gcstartpre_I();
3266 } // case GCSTARTPRE
3269 processmsg_gcstartinit_I();
3271 } // case GCSTARTINIT
3274 // receive a start GC msg
3275 processmsg_gcstart_I();
3279 case GCSTARTCOMPACT: {
3280 // a compact phase start msg
3281 processmsg_gcstartcompact_I();
3283 } // case GCSTARTCOMPACT
3285 case GCSTARTMAPINFO: {
3286 // received a flush phase start msg
3287 processmsg_gcstartmapinfo_I();
3289 } // case GCSTARTFLUSH
3291 case GCSTARTFLUSH: {
3292 // received a flush phase start msg
3293 processmsg_gcstartflush_I();
3295 } // case GCSTARTFLUSH
3298 processmsg_gcfinishpre_I();
3300 } // case GCFINISHPRE
3302 case GCFINISHINIT: {
3303 processmsg_gcfinishinit_I();
3305 } // case GCFINISHINIT
3307 case GCFINISHMARK: {
3308 processmsg_gcfinishmark_I();
3310 } // case GCFINISHMARK
3312 case GCFINISHCOMPACT: {
3313 // received a compact phase finish msg
3314 processmsg_gcfinishcompact_I();
3316 } // case GCFINISHCOMPACT
3318 case GCFINISHMAPINFO: {
3319 processmsg_gcfinishmapinfo_I();
3321 } // case GCFINISHMAPINFO
3323 case GCFINISHFLUSH: {
3324 processmsg_gcfinishflush_I();
3326 } // case GCFINISHFLUSH
3329 // received a GC finish msg
3330 gcphase = FINISHPHASE;
3334 case GCMARKCONFIRM: {
3335 // received a marked phase finish confirm request msg
3336 // all cores should do mark
3337 processmsg_gcmarkconfirm_I();
3339 } // case GCMARKCONFIRM
3341 case GCMARKREPORT: {
3342 processmsg_gcmarkreport_I();
3344 } // case GCMARKREPORT
3347 processmsg_gcmarkedobj_I();
3349 } // case GCMARKEDOBJ
3352 // received a start moving objs msg
3353 processmsg_gcmovestart_I();
3355 } // case GCMOVESTART
3357 case GCMAPREQUEST: {
3358 // received a mapping info request msg
3359 processmsg_gcmaprequest_I();
3361 } // case GCMAPREQUEST
3364 // received a mapping info response msg
3365 processmsg_gcmapinfo_I();
3370 // received a mapping tbl response msg
3371 processmsg_gcmaptbl_I();
3375 case GCLOBJREQUEST: {
3376 // received a large objs info request msg
3377 transferMarkResults_I();
3379 } // case GCLOBJREQUEST
3382 // received a large objs info response msg
3383 processmsg_gclobjinfo_I();
3385 } // case GCLOBJINFO
3387 case GCLOBJMAPPING: {
3388 // received a large obj mapping info msg
3389 processmsg_gclobjmapping_I();
3391 } // case GCLOBJMAPPING
3395 // received a gcprofiles msg
3396 processmsg_gcprofiles_I();
3399 #endif // GC_PROFILE
3401 #ifdef GC_CACHE_ADAPT
3403 // received a gcstartpref msg
3404 processmsg_gcstartpref_I();
3408 case GCFINISHPREF: {
3409 // received a gcfinishpref msg
3410 processmsg_gcfinishpref_I();
3413 #endif // GC_CACHE_ADAPT
3414 #endif // #ifdef MULTICORE_GC
3419 msglength = BAMBOO_MSG_BUF_LENGTH;
3421 //printf("++ msg: %x \n", type);
3423 if(msgdataindex != msgdatalast) {
3424 // still have available msg
3429 BAMBOO_DEBUGPRINT(0xe88d);
3433 // have new coming msg
3434 if(BAMBOO_MSG_AVAIL() != 0) {
3438 #ifdef PROFILE_INTERRUPT
3439 if(!interruptInfoOverflow) {
3440 interruptInfoArray[interruptInfoIndex]->endTime=BAMBOO_GET_EXE_TIME();
3441 interruptInfoIndex++;
3442 if(interruptInfoIndex == INTERRUPTINFOLENGTH) {
3443 interruptInfoOverflow = true;
3452 BAMBOO_DEBUGPRINT(0xe88e);
3459 int enqueuetasks(struct parameterwrapper *parameter,
3460 struct parameterwrapper *prevptr,
3461 struct ___Object___ *ptr,
3463 int numenterflags) {
3464 void * taskpointerarray[MAXTASKPARAMS];
3466 //int numparams=parameter->task->numParameters;
3467 int numiterators=parameter->task->numTotal-1;
3470 struct taskdescriptor * task=parameter->task;
3472 //this add the object to parameterwrapper
3473 ObjectHashadd(parameter->objectset, (int) ptr, 0, (int) enterflags,
3474 numenterflags, enterflags==NULL);
3476 /* Add enqueued object to parameter vector */
3477 taskpointerarray[parameter->slot]=ptr;
3479 /* Reset iterators */
3480 for(j=0; j<numiterators; j++) {
3481 toiReset(¶meter->iterators[j]);
3484 /* Find initial state */
3485 for(j=0; j<numiterators; j++) {
3487 if(toiHasNext(¶meter->iterators[j],taskpointerarray OPTARG(failed)))
3488 toiNext(¶meter->iterators[j], taskpointerarray OPTARG(failed));
3490 /* Need to backtrack */
3491 toiReset(¶meter->iterators[j]);
3495 /* Nothing to enqueue */
3501 /* Enqueue current state */
3503 struct taskparamdescriptor *tpd=
3504 RUNMALLOC(sizeof(struct taskparamdescriptor));
3506 tpd->numParameters=numiterators+1;
3507 tpd->parameterArray=RUNMALLOC(sizeof(void *)*(numiterators+1));
3509 for(j=0; j<=numiterators; j++) {
3510 //store the actual parameters
3511 tpd->parameterArray[j]=taskpointerarray[j];
3514 if (( /*!gencontains(failedtasks, tpd)&&*/
3515 !gencontains(activetasks,tpd))) {
3516 genputtable(activetasks, tpd, tpd);
3518 RUNFREE(tpd->parameterArray);
3522 /* This loop iterates to the next parameter combination */
3523 if (numiterators==0)
3526 for(j=numiterators-1; j<numiterators; j++) {
3529 ¶meter->iterators[j],taskpointerarray OPTARG(failed)))
3530 toiNext(¶meter->iterators[j], taskpointerarray OPTARG(failed));
3532 /* Need to backtrack */
3533 toiReset(¶meter->iterators[j]);
3537 /* Nothing more to enqueue */
3545 int enqueuetasks_I(struct parameterwrapper *parameter,
3546 struct parameterwrapper *prevptr,
3547 struct ___Object___ *ptr,
3549 int numenterflags) {
3550 void * taskpointerarray[MAXTASKPARAMS];
3552 //int numparams=parameter->task->numParameters;
3553 int numiterators=parameter->task->numTotal-1;
3558 struct taskdescriptor * task=parameter->task;
3560 //this add the object to parameterwrapper
3561 ObjectHashadd_I(parameter->objectset, (int) ptr, 0, (int) enterflags,
3562 numenterflags, enterflags==NULL);
3564 /* Add enqueued object to parameter vector */
3565 taskpointerarray[parameter->slot]=ptr;
3567 /* Reset iterators */
3568 for(j=0; j<numiterators; j++) {
3569 toiReset(¶meter->iterators[j]);
3572 /* Find initial state */
3573 for(j=0; j<numiterators; j++) {
3575 if(toiHasNext(¶meter->iterators[j],taskpointerarray OPTARG(failed)))
3576 toiNext(¶meter->iterators[j], taskpointerarray OPTARG(failed));
3578 /* Need to backtrack */
3579 toiReset(¶meter->iterators[j]);
3583 /* Nothing to enqueue */
3589 /* Enqueue current state */
3591 struct taskparamdescriptor *tpd=
3592 RUNMALLOC_I(sizeof(struct taskparamdescriptor));
3594 tpd->numParameters=numiterators+1;
3595 tpd->parameterArray=RUNMALLOC_I(sizeof(void *)*(numiterators+1));
3597 for(j=0; j<=numiterators; j++) {
3598 //store the actual parameters
3599 tpd->parameterArray[j]=taskpointerarray[j];
3602 if (( /*!gencontains(failedtasks, tpd)&&*/
3603 !gencontains(activetasks,tpd))) {
3604 genputtable_I(activetasks, tpd, tpd);
3606 RUNFREE(tpd->parameterArray);
3610 /* This loop iterates to the next parameter combination */
3611 if (numiterators==0)
3614 for(j=numiterators-1; j<numiterators; j++) {
3617 ¶meter->iterators[j], taskpointerarray OPTARG(failed)))
3618 toiNext(¶meter->iterators[j], taskpointerarray OPTARG(failed));
3620 /* Need to backtrack */
3621 toiReset(¶meter->iterators[j]);
3625 /* Nothing more to enqueue */
3639 int containstag(struct ___Object___ *ptr,
3640 struct ___TagDescriptor___ *tag);
3642 #ifndef MULTICORE_GC
3643 void releasewritelock_r(void * lock, void * redirectlock) {
3645 int reallock = (int)lock;
3646 targetcore = (reallock >> 5) % NUMCORES;
3649 BAMBOO_DEBUGPRINT(0xe671);
3650 BAMBOO_DEBUGPRINT_REG((int)lock);
3651 BAMBOO_DEBUGPRINT_REG(reallock);
3652 BAMBOO_DEBUGPRINT_REG(targetcore);
3655 if(targetcore == BAMBOO_NUM_OF_CORE) {
3656 BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
3658 BAMBOO_DEBUGPRINT(0xf001);
3660 // reside on this core
3661 if(!RuntimeHashcontainskey(locktbl, reallock)) {
3662 // no locks for this object, something is wrong
3663 BAMBOO_EXIT(0xe01f);
3666 struct LockValue * lockvalue = NULL;
3668 BAMBOO_DEBUGPRINT(0xe672);
3670 RuntimeHashget(locktbl, reallock, &rwlock_obj);
3671 lockvalue = (struct LockValue *)rwlock_obj;
3673 BAMBOO_DEBUGPRINT_REG(lockvalue->value);
3676 lockvalue->redirectlock = (int)redirectlock;
3678 BAMBOO_DEBUGPRINT_REG(lockvalue->value);
3681 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
3683 BAMBOO_DEBUGPRINT(0xf000);
3687 // send lock release with redirect info msg
3688 // for 32 bit machine, the size is always 4 words
3689 send_msg_4(targetcore, REDIRECTRELEASE, 1, (int)lock,
3690 (int)redirectlock, false);
3695 void executetasks() {
3696 void * taskpointerarray[MAXTASKPARAMS+OFFSET];
3699 struct ___Object___ * tmpparam = NULL;
3700 struct parameterdescriptor * pd=NULL;
3701 struct parameterwrapper *pw=NULL;
3711 while(hashsize(activetasks)>0) {
3713 if(gcflag) gc(NULL);
3716 BAMBOO_DEBUGPRINT(0xe990);
3719 /* See if there are any active tasks */
3720 //if (hashsize(activetasks)>0) {
3723 #ifdef ACCURATEPROFILE
3724 profileTaskStart("tpd checking");
3728 //clock1 = BAMBOO_GET_EXE_TIME();
3731 currtpd=(struct taskparamdescriptor *) getfirstkey(activetasks);
3732 genfreekey(activetasks, currtpd);
3734 numparams=currtpd->task->numParameters;
3735 numtotal=currtpd->task->numTotal;
3737 // clear the lockRedirectTbl
3738 // (TODO, this table should be empty after all locks are released)
3740 /*for(j = 0; j < MAXTASKPARAMS; j++) {
3741 runtime_locks[j].redirectlock = 0;
3742 runtime_locks[j].value = 0;
3744 // get all required locks
3745 runtime_locklen = 0;
3746 // check which locks are needed
3747 for(i = 0; i < numparams; i++) {
3748 void * param = currtpd->parameterArray[i];
3752 if(((struct ___Object___ *)param)->type == STARTUPTYPE) {
3754 taskpointerarray[i+OFFSET]=param;
3757 if(((struct ___Object___ *)param)->lock == NULL) {
3758 tmplock = (int)param;
3760 tmplock = (int)(((struct ___Object___ *)param)->lock);
3762 // insert into the locks array
3763 for(j = 0; j < runtime_locklen; j++) {
3764 if(runtime_locks[j].value == tmplock) {
3767 } else if(runtime_locks[j].value > tmplock) {
3772 int h = runtime_locklen;
3774 runtime_locks[h].redirectlock = runtime_locks[h-1].redirectlock;
3775 runtime_locks[h].value = runtime_locks[h-1].value;
3777 runtime_locks[j].value = tmplock;
3778 runtime_locks[j].redirectlock = (int)param;
3781 } // line 2713: for(i = 0; i < numparams; i++)
3782 // grab these required locks
3784 BAMBOO_DEBUGPRINT(0xe991);
3787 //clock2 = BAMBOO_GET_EXE_TIME();
3789 for(i = 0; i < runtime_locklen; i++) {
3790 int * lock = (int *)(runtime_locks[i].redirectlock);
3792 // require locks for this parameter if it is not a startup object
3794 BAMBOO_DEBUGPRINT_REG((int)lock);
3795 BAMBOO_DEBUGPRINT_REG((int)(runtime_locks[i].value));
3798 BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
3800 BAMBOO_DEBUGPRINT(0xf001);
3803 //isInterrupt = false;
3806 BAMBOO_WAITING_FOR_LOCK(0);
3810 while(BAMBOO_WAITING_FOR_LOCK(0) != -1) {
3814 grount = lockresult;
3824 //isInterrupt = true;
3826 BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
3828 BAMBOO_DEBUGPRINT(0xf000);
3833 BAMBOO_DEBUGPRINT(0xe992);
3834 BAMBOO_DEBUGPRINT_REG(lock);
3836 // check if has the lock already
3837 // can not get the lock, try later
3838 // release all grabbed locks for previous parameters
3839 for(j = 0; j < i; ++j) {
3840 lock = (int*)(runtime_locks[j].redirectlock);
3841 releasewritelock(lock);
3843 genputtable(activetasks, currtpd, currtpd);
3844 if(hashsize(activetasks) == 1) {
3845 // only one task right now, wait a little while before next try
3851 #ifdef ACCURATEPROFILE
3852 // fail, set the end of the checkTaskInfo
3859 } // line 2752: for(i = 0; i < runtime_locklen; i++)
3862 clock3 = BAMBOO_GET_EXE_TIME();
3863 //tprintf("sort: %d, grab: %d \n", clock2-clock1, clock3-clock2);*/
3866 BAMBOO_DEBUGPRINT(0xe993);
3868 /* Make sure that the parameters are still in the queues */
3869 for(i=0; i<numparams; i++) {
3870 void * parameter=currtpd->parameterArray[i];
3874 BAMBOO_CACHE_FLUSH_RANGE((int)parameter,
3875 classsize[((struct ___Object___ *)parameter)->type]);
3877 tmpparam = (struct ___Object___ *)parameter;
3878 pd=currtpd->task->descriptorarray[i];
3879 pw=(struct parameterwrapper *) pd->queue;
3880 /* Check that object is still in queue */
3882 if (!ObjectHashcontainskey(pw->objectset, (int) parameter)) {
3884 BAMBOO_DEBUGPRINT(0xe994);
3885 BAMBOO_DEBUGPRINT_REG(parameter);
3887 // release grabbed locks
3888 for(j = 0; j < runtime_locklen; ++j) {
3889 int * lock = (int *)(runtime_locks[j].redirectlock);
3890 releasewritelock(lock);
3892 RUNFREE(currtpd->parameterArray);
3898 /* Check if the object's flags still meets requirements */
3902 for(tmpi = 0; tmpi < pw->numberofterms; ++tmpi) {
3903 andmask=pw->intarray[tmpi*2];
3904 checkmask=pw->intarray[tmpi*2+1];
3905 if((((struct ___Object___ *)parameter)->flag&andmask)==checkmask) {
3911 // flags are never suitable
3912 // remove this obj from the queue
3914 int UNUSED, UNUSED2;
3917 BAMBOO_DEBUGPRINT(0xe995);
3918 BAMBOO_DEBUGPRINT_REG(parameter);
3920 ObjectHashget(pw->objectset, (int) parameter, (int *) &next,
3921 (int *) &enterflags, &UNUSED, &UNUSED2);
3922 ObjectHashremove(pw->objectset, (int)parameter);
3923 if (enterflags!=NULL)
3924 RUNFREE(enterflags);
3925 // release grabbed locks
3926 for(j = 0; j < runtime_locklen; ++j) {
3927 int * lock = (int *)(runtime_locks[j].redirectlock);
3928 releasewritelock(lock);
3930 RUNFREE(currtpd->parameterArray);
3934 #ifdef ACCURATEPROFILE
3935 // fail, set the end of the checkTaskInfo
3940 } // line 2878: if (!ismet)
3944 /* Check that object still has necessary tags */
3945 for(j=0; j<pd->numbertags; j++) {
3946 int slotid=pd->tagarray[2*j]+numparams;
3947 struct ___TagDescriptor___ *tagd=currtpd->parameterArray[slotid];
3948 if (!containstag(parameter, tagd)) {
3950 BAMBOO_DEBUGPRINT(0xe996);
3953 // release grabbed locks
3955 for(tmpj = 0; tmpj < runtime_locklen; ++tmpj) {
3956 int * lock = (int *)(runtime_locks[tmpj].redirectlock);
3957 releasewritelock(lock);
3960 RUNFREE(currtpd->parameterArray);
3964 } // line2911: if (!containstag(parameter, tagd))
3965 } // line 2808: for(j=0; j<pd->numbertags; j++)
3967 taskpointerarray[i+OFFSET]=parameter;
3968 } // line 2824: for(i=0; i<numparams; i++)
3970 for(; i<numtotal; i++) {
3971 taskpointerarray[i+OFFSET]=currtpd->parameterArray[i];
3976 /* Actually call task */
3978 ((int *)taskpointerarray)[0]=currtpd->numParameters;
3979 taskpointerarray[1]=NULL;
3982 #ifdef ACCURATEPROFILE
3983 // check finish, set the end of the checkTaskInfo
3986 profileTaskStart(currtpd->task->name);
3990 //clock4 = BAMBOO_GET_EXE_TIME();
3991 //tprintf("sort: %d, grab: %d, check: %d \n", (int)(clock2-clock1), (int)(clock3-clock2), (int)(clock4-clock3));
3994 BAMBOO_DEBUGPRINT(0xe997);
3996 ((void (*)(void **))currtpd->task->taskptr)(taskpointerarray);
3999 //clock5 = BAMBOO_GET_EXE_TIME();
4000 // tprintf("sort: %d, grab: %d, check: %d \n", (int)(clock2-clock1), (int)(clock3-clock2), (int)(clock4-clock3));
4003 #ifdef ACCURATEPROFILE
4004 // task finish, set the end of the checkTaskInfo
4006 // new a PostTaskInfo for the post-task execution
4007 profileTaskStart("post task execution");
4011 BAMBOO_DEBUGPRINT(0xe998);
4012 BAMBOO_DEBUGPRINT_REG(islock);
4017 BAMBOO_DEBUGPRINT(0xe999);
4019 for(i = 0; i < runtime_locklen; ++i) {
4020 void * ptr = (void *)(runtime_locks[i].redirectlock);
4021 int * lock = (int *)(runtime_locks[i].value);
4023 BAMBOO_DEBUGPRINT_REG((int)ptr);
4024 BAMBOO_DEBUGPRINT_REG((int)lock);
4025 BAMBOO_DEBUGPRINT_REG(*((int*)lock+5));
4027 #ifndef MULTICORE_GC
4028 if(RuntimeHashcontainskey(lockRedirectTbl, (int)lock)) {
4030 RuntimeHashget(lockRedirectTbl, (int)lock, &redirectlock);
4031 RuntimeHashremovekey(lockRedirectTbl, (int)lock);
4032 releasewritelock_r(lock, (int *)redirectlock);
4037 releasewritelock(ptr);
4040 } // line 3015: if(islock)
4043 //clock6 = BAMBOO_GET_EXE_TIME();
4044 //tprintf("sort: %d, grab: %d, check: %d \n", (int)(clock2-clock1), (int)(clock3-clock2), (int)(clock4-clock3));
4047 // post task execution finish, set the end of the postTaskInfo
4051 // Free up task parameter descriptor
4052 RUNFREE(currtpd->parameterArray);
4056 BAMBOO_DEBUGPRINT(0xe99a);
4059 //clock7 = BAMBOO_GET_EXE_TIME();
4060 //tprintf("sort: %d, grab: %d, check: %d, release: %d, other %d \n", (int)(clock2-clock1), (int)(clock3-clock2), (int)(clock4-clock3), (int)(clock6-clock5), (int)(clock7-clock6));
4063 //} // if (hashsize(activetasks)>0)
4064 } // while(hashsize(activetasks)>0)
4066 BAMBOO_DEBUGPRINT(0xe99b);
4070 /* This function processes an objects tags */
4071 void processtags(struct parameterdescriptor *pd,
4073 struct parameterwrapper *parameter,
4074 int * iteratorcount,
4079 for(i=0; i<pd->numbertags; i++) {
4080 int slotid=pd->tagarray[2*i];
4081 int tagid=pd->tagarray[2*i+1];
4083 if (statusarray[slotid+numparams]==0) {
4084 parameter->iterators[*iteratorcount].istag=1;
4085 parameter->iterators[*iteratorcount].tagid=tagid;
4086 parameter->iterators[*iteratorcount].slot=slotid+numparams;
4087 parameter->iterators[*iteratorcount].tagobjectslot=index;
4088 statusarray[slotid+numparams]=1;
4095 void processobject(struct parameterwrapper *parameter,
4097 struct parameterdescriptor *pd,
4103 struct ObjectHash * objectset=
4104 ((struct parameterwrapper *)pd->queue)->objectset;
4106 parameter->iterators[*iteratorcount].istag=0;
4107 parameter->iterators[*iteratorcount].slot=index;
4108 parameter->iterators[*iteratorcount].objectset=objectset;
4109 statusarray[index]=1;
4111 for(i=0; i<pd->numbertags; i++) {
4112 int slotid=pd->tagarray[2*i];
4113 //int tagid=pd->tagarray[2*i+1];
4114 if (statusarray[slotid+numparams]!=0) {
4115 /* This tag has already been enqueued, use it to narrow search */
4116 parameter->iterators[*iteratorcount].tagbindings[tagcount]=
4121 parameter->iterators[*iteratorcount].numtags=tagcount;
4126 /* This function builds the iterators for a task & parameter */
4128 void builditerators(struct taskdescriptor * task,
4130 struct parameterwrapper * parameter) {
4131 int statusarray[MAXTASKPARAMS];
4133 int numparams=task->numParameters;
4134 int iteratorcount=0;
4135 for(i=0; i<MAXTASKPARAMS; i++) statusarray[i]=0;
4137 statusarray[index]=1; /* Initial parameter */
4138 /* Process tags for initial iterator */
4140 processtags(task->descriptorarray[index], index, parameter,
4141 &iteratorcount, statusarray, numparams);
4145 /* Check for objects with existing tags */
4146 for(i=0; i<numparams; i++) {
4147 if (statusarray[i]==0) {
4148 struct parameterdescriptor *pd=task->descriptorarray[i];
4150 for(j=0; j<pd->numbertags; j++) {
4151 int slotid=pd->tagarray[2*j];
4152 if(statusarray[slotid+numparams]!=0) {
4153 processobject(parameter,i,pd,&iteratorcount,
4154 statusarray,numparams);
4155 processtags(pd,i,parameter,&iteratorcount,statusarray,numparams);
4162 /* Next do objects w/ unbound tags*/
4164 for(i=0; i<numparams; i++) {
4165 if (statusarray[i]==0) {
4166 struct parameterdescriptor *pd=task->descriptorarray[i];
4167 if (pd->numbertags>0) {
4168 processobject(parameter,i,pd,&iteratorcount,statusarray,numparams);
4169 processtags(pd,i,parameter,&iteratorcount,statusarray,numparams);
4175 /* Nothing with a tag enqueued */
4177 for(i=0; i<numparams; i++) {
4178 if (statusarray[i]==0) {
4179 struct parameterdescriptor *pd=task->descriptorarray[i];
4180 processobject(parameter,i,pd,&iteratorcount,statusarray,numparams);
4181 processtags(pd,i,parameter,&iteratorcount,statusarray,numparams);
4194 if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) {
4197 for(i=0; i<numtasks[BAMBOO_NUM_OF_CORE]; i++) {
4198 struct taskdescriptor * task=taskarray[BAMBOO_NUM_OF_CORE][i];
4200 printf("%s\n", task->name);
4202 for(j=0; j<task->numParameters; j++) {
4203 struct parameterdescriptor *param=task->descriptorarray[j];
4204 struct parameterwrapper *parameter=param->queue;
4205 struct ObjectHash * set=parameter->objectset;
4206 struct ObjectIterator objit;
4208 printf(" Parameter %d\n", j);
4210 ObjectHashiterator(set, &objit);
4211 while(ObjhasNext(&objit)) {
4212 struct ___Object___ * obj=(struct ___Object___ *)Objkey(&objit);
4213 struct ___Object___ * tagptr=obj->___tags___;
4214 int nonfailed=Objdata4(&objit);
4215 int numflags=Objdata3(&objit);
4216 int flags=Objdata2(&objit);
4219 printf(" Contains %lx\n", obj);
4220 printf(" flag=%d\n", obj->flag);
4223 } else if (tagptr->type==TAGTYPE) {
4225 printf(" tag=%lx\n",tagptr);
4231 struct ArrayObject *ao=(struct ArrayObject *)tagptr;
4232 for(; tagindex<ao->___cachedCode___; tagindex++) {
4234 printf(" tag=%lx\n",ARRAYGET(ao,struct ___TagDescriptor___*,
4247 /* This function processes the task information to create queues for
4248 each parameter type. */
4250 void processtasks() {
4252 if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) {
4255 for(i=0; i<numtasks[BAMBOO_NUM_OF_CORE]; i++) {
4256 struct taskdescriptor * task=taskarray[BAMBOO_NUM_OF_CORE][i];
4259 /* Build objectsets */
4260 for(j=0; j<task->numParameters; j++) {
4261 struct parameterdescriptor *param=task->descriptorarray[j];
4262 struct parameterwrapper *parameter=param->queue;
4263 parameter->objectset=allocateObjectHash(10);
4264 parameter->task=task;
4267 /* Build iterators for parameters */
4268 for(j=0; j<task->numParameters; j++) {
4269 struct parameterdescriptor *param=task->descriptorarray[j];
4270 struct parameterwrapper *parameter=param->queue;
4271 builditerators(task, j, parameter);
4276 void toiReset(struct tagobjectiterator * it) {
4279 } else if (it->numtags>0) {
4282 ObjectHashiterator(it->objectset, &it->it);
4286 int toiHasNext(struct tagobjectiterator *it,
4287 void ** objectarray OPTARG(int * failed)) {
4290 /* Get object with tags */
4291 struct ___Object___ *obj=objectarray[it->tagobjectslot];
4292 struct ___Object___ *tagptr=obj->___tags___;
4293 if (tagptr->type==TAGTYPE) {
4294 if ((it->tagobjindex==0)&& /* First object */
4295 (it->tagid==((struct ___TagDescriptor___ *)tagptr)->flag)) /* Right tag type */
4300 struct ArrayObject *ao=(struct ArrayObject *) tagptr;
4301 int tagindex=it->tagobjindex;
4302 for(; tagindex<ao->___cachedCode___; tagindex++) {
4303 struct ___TagDescriptor___ *td=
4304 ARRAYGET(ao, struct ___TagDescriptor___ *, tagindex);
4305 if (td->flag==it->tagid) {
4306 it->tagobjindex=tagindex; /* Found right type of tag */
4312 } else if (it->numtags>0) {
4313 /* Use tags to locate appropriate objects */
4314 struct ___TagDescriptor___ *tag=objectarray[it->tagbindings[0]];
4315 struct ___Object___ *objptr=tag->flagptr;
4317 if (objptr->type!=OBJECTARRAYTYPE) {
4318 if (it->tagobjindex>0)
4320 if (!ObjectHashcontainskey(it->objectset, (int) objptr))
4322 for(i=1; i<it->numtags; i++) {
4323 struct ___TagDescriptor___ *tag2=objectarray[it->tagbindings[i]];
4324 if (!containstag(objptr,tag2))
4329 struct ArrayObject *ao=(struct ArrayObject *) objptr;
4332 for(tagindex=it->tagobjindex;tagindex<ao->___cachedCode___;tagindex++){
4333 struct ___Object___ *objptr=
4334 ARRAYGET(ao,struct ___Object___*,tagindex);
4335 if (!ObjectHashcontainskey(it->objectset, (int) objptr))
4337 for(i=1; i<it->numtags; i++) {
4338 struct ___TagDescriptor___ *tag2=objectarray[it->tagbindings[i]];
4339 if (!containstag(objptr,tag2))
4342 it->tagobjindex=tagindex;
4347 it->tagobjindex=tagindex;
4351 return ObjhasNext(&it->it);
4355 int containstag(struct ___Object___ *ptr,
4356 struct ___TagDescriptor___ *tag) {
4358 struct ___Object___ * objptr=tag->flagptr;
4359 if (objptr->type==OBJECTARRAYTYPE) {
4360 struct ArrayObject *ao=(struct ArrayObject *)objptr;
4361 for(j=0; j<ao->___cachedCode___; j++) {
4362 if (ptr==ARRAYGET(ao, struct ___Object___*, j)) {
4372 void toiNext(struct tagobjectiterator *it,
4373 void ** objectarray OPTARG(int * failed)) {
4374 /* hasNext has all of the intelligence */
4377 /* Get object with tags */
4378 struct ___Object___ *obj=objectarray[it->tagobjectslot];
4379 struct ___Object___ *tagptr=obj->___tags___;
4380 if (tagptr->type==TAGTYPE) {
4382 objectarray[it->slot]=tagptr;
4384 struct ArrayObject *ao=(struct ArrayObject *) tagptr;
4385 objectarray[it->slot]=
4386 ARRAYGET(ao, struct ___TagDescriptor___ *, it->tagobjindex++);
4388 } else if (it->numtags>0) {
4389 /* Use tags to locate appropriate objects */
4390 struct ___TagDescriptor___ *tag=objectarray[it->tagbindings[0]];
4391 struct ___Object___ *objptr=tag->flagptr;
4392 if (objptr->type!=OBJECTARRAYTYPE) {
4394 objectarray[it->slot]=objptr;
4396 struct ArrayObject *ao=(struct ArrayObject *) objptr;
4397 objectarray[it->slot]=
4398 ARRAYGET(ao, struct ___Object___ *, it->tagobjindex++);
4401 /* Iterate object */
4402 objectarray[it->slot]=(void *)Objkey(&it->it);
4408 inline void profileTaskStart(char * taskname) {
4409 if(!taskInfoOverflow) {
4410 TaskInfo* taskInfo = RUNMALLOC(sizeof(struct task_info));
4411 taskInfoArray[taskInfoIndex] = taskInfo;
4412 taskInfo->taskName = taskname;
4413 taskInfo->startTime = BAMBOO_GET_EXE_TIME();
4414 taskInfo->endTime = -1;
4415 taskInfo->exitIndex = -1;
4416 taskInfo->newObjs = NULL;
4420 inline void profileTaskEnd() {
4421 if(!taskInfoOverflow) {
4422 taskInfoArray[taskInfoIndex]->endTime = BAMBOO_GET_EXE_TIME();
4424 if(taskInfoIndex == TASKINFOLENGTH) {
4425 taskInfoOverflow = true;
4426 //taskInfoIndex = 0;
4431 // output the profiling data
4432 void outputProfileData() {
4435 unsigned long long totaltasktime = 0;
4436 unsigned long long preprocessingtime = 0;
4437 unsigned long long objqueuecheckingtime = 0;
4438 unsigned long long postprocessingtime = 0;
4439 //int interruptiontime = 0;
4440 unsigned long long other = 0;
4441 unsigned long long averagetasktime = 0;
4444 printf("Task Name, Start Time, End Time, Duration, Exit Index(, NewObj Name, Num)+\n");
4445 // output task related info
4446 for(i = 0; i < taskInfoIndex; i++) {
4447 TaskInfo* tmpTInfo = taskInfoArray[i];
4448 unsigned long long duration = tmpTInfo->endTime - tmpTInfo->startTime;
4449 printf("%s, %lld, %lld, %lld, %lld",
4450 tmpTInfo->taskName, tmpTInfo->startTime, tmpTInfo->endTime,
4451 duration, tmpTInfo->exitIndex);
4452 // summarize new obj info
4453 if(tmpTInfo->newObjs != NULL) {
4454 struct RuntimeHash * nobjtbl = allocateRuntimeHash(5);
4455 struct RuntimeIterator * iter = NULL;
4456 while(0 == isEmpty(tmpTInfo->newObjs)) {
4457 char * objtype = (char *)(getItem(tmpTInfo->newObjs));
4458 if(RuntimeHashcontainskey(nobjtbl, (int)(objtype))) {
4460 RuntimeHashget(nobjtbl, (int)objtype, &num);
4461 RuntimeHashremovekey(nobjtbl, (int)objtype);
4463 RuntimeHashadd(nobjtbl, (int)objtype, num);
4465 RuntimeHashadd(nobjtbl, (int)objtype, 1);
4467 //printf(stderr, "new obj!\n");
4470 // output all new obj info
4471 iter = RuntimeHashcreateiterator(nobjtbl);
4472 while(RunhasNext(iter)) {
4473 char * objtype = (char *)Runkey(iter);
4474 int num = Runnext(iter);
4475 printf(", %s, %d", objtype, num);
4479 if(strcmp(tmpTInfo->taskName, "tpd checking") == 0) {
4480 preprocessingtime += duration;
4481 } else if(strcmp(tmpTInfo->taskName, "post task execution") == 0) {
4482 postprocessingtime += duration;
4483 } else if(strcmp(tmpTInfo->taskName, "objqueue checking") == 0) {
4484 objqueuecheckingtime += duration;
4486 totaltasktime += duration;
4487 averagetasktime += duration;
4492 if(taskInfoOverflow) {
4493 printf("Caution: task info overflow!\n");
4496 other = totalexetime-totaltasktime-preprocessingtime-postprocessingtime;
4497 averagetasktime /= tasknum;
4499 printf("\nTotal time: %lld\n", totalexetime);
4500 printf("Total task execution time: %lld (%d%%)\n", totaltasktime,
4501 (int)(((double)totaltasktime/(double)totalexetime)*100));
4502 printf("Total objqueue checking time: %lld (%d%%)\n",
4503 objqueuecheckingtime,
4504 (int)(((double)objqueuecheckingtime/(double)totalexetime)*100));
4505 printf("Total pre-processing time: %lld (%d%%)\n", preprocessingtime,
4506 (int)(((double)preprocessingtime/(double)totalexetime)*100));
4507 printf("Total post-processing time: %lld (%d%%)\n", postprocessingtime,
4508 (int)(((double)postprocessingtime/(double)totalexetime)*100));
4509 printf("Other time: %lld (%d%%)\n", other,
4510 (int)(((double)other/(double)totalexetime)*100));
4513 printf("\nAverage task execution time: %lld\n", averagetasktime);
4515 //printf("\nTotal time spent for interruptions: %lld\n", interrupttime);
4520 BAMBOO_DEBUGPRINT(0xdddd);
4521 // output task related info
4522 for(i= 0; i < taskInfoIndex; i++) {
4523 TaskInfo* tmpTInfo = taskInfoArray[i];
4524 char* tmpName = tmpTInfo->taskName;
4525 int nameLen = strlen(tmpName);
4526 BAMBOO_DEBUGPRINT(0xddda);
4527 for(j = 0; j < nameLen; j++) {
4528 BAMBOO_DEBUGPRINT_REG(tmpName[j]);
4530 BAMBOO_DEBUGPRINT(0xdddb);
4531 BAMBOO_DEBUGPRINT_REG(tmpTInfo->startTime);
4532 BAMBOO_DEBUGPRINT_REG(tmpTInfo->endTime);
4533 BAMBOO_DEBUGPRINT_REG(tmpTInfo->exitIndex);
4534 if(tmpTInfo->newObjs != NULL) {
4535 struct RuntimeHash * nobjtbl = allocateRuntimeHash(5);
4536 struct RuntimeIterator * iter = NULL;
4537 while(0 == isEmpty(tmpTInfo->newObjs)) {
4538 char * objtype = (char *)(getItem(tmpTInfo->newObjs));
4539 if(RuntimeHashcontainskey(nobjtbl, (int)(objtype))) {
4541 RuntimeHashget(nobjtbl, (int)objtype, &num);
4542 RuntimeHashremovekey(nobjtbl, (int)objtype);
4544 RuntimeHashadd(nobjtbl, (int)objtype, num);
4546 RuntimeHashadd(nobjtbl, (int)objtype, 1);
4550 // ouput all new obj info
4551 iter = RuntimeHashcreateiterator(nobjtbl);
4552 while(RunhasNext(iter)) {
4553 char * objtype = (char *)Runkey(iter);
4554 int num = Runnext(iter);
4555 int nameLen = strlen(objtype);
4556 BAMBOO_DEBUGPRINT(0xddda);
4557 for(j = 0; j < nameLen; j++) {
4558 BAMBOO_DEBUGPRINT_REG(objtype[j]);
4560 BAMBOO_DEBUGPRINT(0xdddb);
4561 BAMBOO_DEBUGPRINT_REG(num);
4564 BAMBOO_DEBUGPRINT(0xdddc);
4567 if(taskInfoOverflow) {
4568 BAMBOO_DEBUGPRINT(0xefee);
4571 #ifdef PROFILE_INTERRUPT
4572 // output interrupt related info
4573 for(i = 0; i < interruptInfoIndex; i++) {
4574 InterruptInfo* tmpIInfo = interruptInfoArray[i];
4575 BAMBOO_DEBUGPRINT(0xddde);
4576 BAMBOO_DEBUGPRINT_REG(tmpIInfo->startTime);
4577 BAMBOO_DEBUGPRINT_REG(tmpIInfo->endTime);
4578 BAMBOO_DEBUGPRINT(0xdddf);
4581 if(interruptInfoOverflow) {
4582 BAMBOO_DEBUGPRINT(0xefef);
4584 #endif // PROFILE_INTERRUPT
4586 BAMBOO_DEBUGPRINT(0xeeee);
4589 #endif // #ifdef PROFILE