change to use static mapping of core # and block # in multicore garbage modul
authorjzhou <jzhou>
Wed, 21 Oct 2009 23:19:56 +0000 (23:19 +0000)
committerjzhou <jzhou>
Wed, 21 Oct 2009 23:19:56 +0000 (23:19 +0000)
Robust/src/Analysis/Scheduling/ScheduleAnalysis.java
Robust/src/Runtime/multicoregarbage.c
Robust/src/Runtime/multicoregarbage.h
Robust/src/Runtime/multicorehelper.h [new file with mode: 0644]
Robust/src/Runtime/multicoretask.c
Robust/src/buildscript

index a901b7bbb4fd1879d40e0fd650b69f28f902e5e8..413a54fb0b24f6e31e6fd0314593f461a6b57634 100644 (file)
@@ -395,7 +395,8 @@ public class ScheduleAnalysis {
                       (cdname.equals("Fractal")) ||
                       (cdname.equals("KMeans")) || 
                       (cdname.equals("ZTransform")) ||
-                                                                                       (cdname.equals("TestRunner"))) {
+                                                                                       (cdname.equals("TestRunner")) || 
+                                                                                       (cdname.equals("LinkList"))) {
                     newRate = this.coreNum;
                   } else if(cdname.equals("SentenceParser")) {
                     newRate = 4;
index fb8d743a673f25fee8880c69fdd14edc76f3b122..58491b6225a94642acae8b5204e99c4abc2f395d 100644 (file)
@@ -48,16 +48,17 @@ int gclobjtailindex2=0;
 struct lobjpointerblock *gclobjspare=NULL;
 
 #ifdef GC_DEBUG
+// dump whole mem in blocks
 inline void dumpSMem() {
        int block = 0;
        int sblock = 0;
        int j = 0;
        int i = 0;
-       bool reverse = false;
        int coren = 0;
        int x = 0;
        int y = 0;
        tprintf("Dump shared mem: \n");
+       // reserved blocks for sblocktbl
        tprintf("++++ reserved sblocks ++++ \n");
        for(i=BAMBOO_BASE_VA; i<gcbaseva; i+= 4*16) {
                tprintf("0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x \n",
@@ -68,71 +69,34 @@ inline void dumpSMem() {
        }
        sblock = gcreservedsb;
        bool advanceblock = false;
+       // remaining memory
        for(i=gcbaseva;i<BAMBOO_BASE_VA+BAMBOO_SHARED_MEM_SIZE;i+=4*16){
                advanceblock = false;
+               // computing sblock # and block #, core coordinate (x,y) also
                if(j%((BAMBOO_SMEM_SIZE)/(4*16)) == 0) {
+                       // finished a sblock
                        if(j < ((BAMBOO_LARGE_SMEM_BOUND)/(4*16))) {
                                if((j > 0) && (j%((BAMBOO_SMEM_SIZE_L)/(4*16)) == 0)) {
+                                       // finished a block
                                        block++;
                                        advanceblock = true;
                                }
                        } else {
+                               // finished a block
                                block++;
                                advanceblock = true;
                        }
+                       // compute core #
                        if(advanceblock) {
-                               if(block%NUMCORES == 0) {
-                                       reverse = !reverse;
-                               } else {
-                                       if(((!reverse) && (y%2)) || (reverse && ((y%2)==0))) {
-                                               if((x == 0) || ((x==1)&&(y==6))){
-                                                       if(reverse) {
-                                                               if(coren > 48) {
-                                                                       coren -= bamboo_width - 1;
-                                                               } else {
-                                                                       coren -= bamboo_width;
-                                                               }
-                                                       } else {
-                                                               if(coren > 47) {
-                                                                       coren += bamboo_width - 1;
-                                                               } else {
-                                                                       coren += bamboo_width;
-                                                               }
-                                                       }
-                                               } else {
-                                                       coren--;
-                                               }
-                                       } else {
-                                               if(x==7) {
-                                                       if(reverse) {
-                                                               if(coren > 48) {
-                                                                       coren -= bamboo_width - 1;
-                                                               } else {
-                                                                       coren -= bamboo_width;
-                                                               }
-                                                       } else {
-                                                               if(coren > 47) {
-                                                                       coren += bamboo_width-1;
-                                                               } else {
-                                                                       coren += bamboo_width;
-                                                               }
-                                                       }
-                                               } else {
-                                                       coren++;
-                                               }
-                                       }
-                               }
+                               coren = gc_block2core[block%124];
                        }
+                       // compute core coordinate
                        int tmpcore = coren;
-                       if(NUMCORES==62) {
-                               if(tmpcore > 54) {
-                                       tmpcore+=2;
-                               } else if(tmpcore > 47) {
-                                       tmpcore++;
-                               }
+                       if((NUMCORES==62) && (tmpcore > 5)) {
+                               tmpcore+=2;
                        }
-                       x = tmpcore%bamboo_width;
-                       y = tmpcore/bamboo_width;
+                       x = tmpcore/bamboo_width;
+                       y = tmpcore%bamboo_width;
                        tprintf("==== %d, %d : core (%d,%d), saddr %x====\n", block, sblock++, 
                                            x, y, (sblock-1)*(BAMBOO_SMEM_SIZE)+BAMBOO_BASE_VA);
                }
@@ -344,10 +308,12 @@ inline bool isLarge(void * ptr,
 inline int hostcore(void * ptr) {
        // check the host core of ptr
        int host = 0;
-       int x = 0;
-       int y = 0;
-       RESIDECORE(ptr, &x, &y);
-       host = (x==0)?(x*bamboo_height+y):(x*bamboo_height+y-2);
+       RESIDECORE(ptr, &host);
+#ifdef DEBUG
+       BAMBOO_DEBUGPRINT(0xedd0);
+       BAMBOO_DEBUGPRINT_REG(ptr);
+       BAMBOO_DEBUGPRINT_REG(host);
+#endif
        return host;
 } // int hostcore(void * ptr)
 
@@ -535,7 +501,7 @@ inline void initGC() {
                } // for(i = 0; i < NUMCORES; ++i)
                gcheaptop = 0;
                gctopcore = 0;
-               gcheapdirection = 1;
+               gctopblock = 0;
        }
        gcself_numsendobjs = 0;
        gcself_numreceiveobjs = 0;
@@ -599,14 +565,9 @@ inline int loadbalance() {
        BAMBOO_DEBUGPRINT_REG(b);
        BAMBOO_DEBUGPRINT_REG(numbpc);
 #endif
-       gcheapdirection = (numbpc%2 == 0);
-       int x = 0;
-       int y = 0;
-       RESIDECORE(heaptop, &x, &y);
-       gctopcore = (x == 0 ? y : x * bamboo_height + y - 2);
+       gctopblock = b;
+       RESIDECORE(heaptop, &gctopcore);
 #ifdef DEBUG
-       BAMBOO_DEBUGPRINT_REG(x);
-       BAMBOO_DEBUGPRINT_REG(y);
        BAMBOO_DEBUGPRINT_REG(gctopcore);
 #endif
        return numbpc;
@@ -616,7 +577,7 @@ inline bool cacheLObjs() {
        // check the total mem size need for large objs
        int sumsize = 0;
        int size = 0;
-#ifdef GC_DEBUG
+#ifdef DEBUG
        BAMBOO_DEBUGPRINT(0xe801);
 #endif
        gclobjtail2 = gclobjtail;
@@ -625,7 +586,7 @@ inline bool cacheLObjs() {
                gc_lobjdequeue2();
                size = gclobjtail2->lengths[gclobjtailindex2 - 1];
                sumsize += size;
-#ifdef GC_DEBUG
+#ifdef DEBUG
                BAMBOO_DEBUGPRINT_REG(gclobjtail2->lobjs[gclobjtailindex2-1]);
                BAMBOO_DEBUGPRINT_REG(size);
                BAMBOO_DEBUGPRINT_REG(sumsize);
@@ -638,7 +599,7 @@ inline bool cacheLObjs() {
                // do not have enough room to cache large objs
                return false;
        }
-#ifdef GC_DEBUG
+#ifdef DEBUG
        BAMBOO_DEBUGPRINT(0xe802);
        BAMBOO_DEBUGPRINT_REG(dst);
 #endif
@@ -652,11 +613,9 @@ inline bool cacheLObjs() {
                size = gclobjtail2->lengths[gclobjtailindex2 - 1];
                // set the mark field to 2, indicating that this obj has been moved and need to be flushed
                ((int *)(gclobjtail2->lobjs[gclobjtailindex2-1]))[6] = 2;
-               // TODO
-               BAMBOO_DEBUGPRINT(0xdcdc);
                memcpy(dst, gclobjtail2->lobjs[gclobjtailindex2 - 1], size);
                dst += size;
-#ifdef GC_DEBUG
+#ifdef DEBUG
                BAMBOO_DEBUGPRINT_REG(gclobjtail2->lobjs[gclobjtailindex2-1]);
                BAMBOO_DEBUGPRINT(dst-size);
                BAMBOO_DEBUGPRINT_REG(size);
@@ -777,10 +736,15 @@ inline void moveLObjs() {
 #endif
        for(int i = 1; i < NUMCORES; i++) {
                int tmptop = 0;
+#ifdef DEBUG
+               BAMBOO_DEBUGPRINT(0xf000+i);
+               BAMBOO_DEBUGPRINT_REG(gcloads[i]);
+               BAMBOO_DEBUGPRINT_REG(gcfilledblocks[i]);
+#endif
                if((gcfilledblocks[i] > 0) 
                                && ((gcloads[i] % (BAMBOO_SMEM_SIZE)) == 0)) {
                        // edge of a block, check if this is exactly the heaptop
-                       BASEPTR(0, gcfilledblocks[i]-1, &gcloads[i]);
+                       BASEPTR(i, gcfilledblocks[i]-1, &gcloads[i]);
                        gcloads[i]
                                +=(gcfilledblocks[i]>1?(BAMBOO_SMEM_SIZE):(BAMBOO_SMEM_SIZE_L));
                        tmptop = gcloads[i];
@@ -939,6 +903,8 @@ inline void moveLObjs() {
                        memcpy(tmpheaptop, gcheaptop, size);
                        // fill the remaining space with -2 padding
                        memset(tmpheaptop+size, -2, isize-size);
+                       // zero out original mem caching the lobj
+                       memset(gcheaptop, '\0', size);
 #ifdef DEBUG
                        BAMBOO_DEBUGPRINT(0xea05);
                        BAMBOO_DEBUGPRINT_REG(gcheaptop);
@@ -1189,7 +1155,7 @@ inline void mark(bool isfirst,
                                        // ptr is a large object
                                        if(((int *)ptr)[6] == 0) {
                                                // not marked and not enqueued
-#ifdef GC_DEBUG
+#ifdef DEBUG
                                                BAMBOO_DEBUGPRINT(0xecec);
                                                BAMBOO_DEBUGPRINT_REG(ptr);
 #endif
@@ -1199,7 +1165,7 @@ inline void mark(bool isfirst,
                                                BAMBOO_CLOSE_CRITICAL_SECTION();
                                                // mark this obj
                                                ((int *)ptr)[6] = 1;
-                                       }
+                                       } // if(((int *)ptr)[6] == 0)
                                } else {
                                        bool islocal = isLocal(ptr);
                                        if (islocal && (((int *)ptr)[6] == 0)) {
@@ -1216,7 +1182,7 @@ inline void mark(bool isfirst,
                                                if(ptr + size > gcmarkedptrbound) {
                                                        gcmarkedptrbound = ptr + size;
                                                } // if(ptr + size > gcmarkedptrbound)
-                                       } else if ((!islocal) && (((int *)ptr)[6] == 0)) {
+                                       } else if (!islocal /*&& (((int *)ptr)[6] == 0)*/) {
                                                int host = hostcore(ptr);
 #ifdef DEBUG
                                                BAMBOO_DEBUGPRINT(0xbbbb);
@@ -1261,7 +1227,7 @@ inline void mark(bool isfirst,
                                        }
                                } // if (pointer==0) else if ... else ...
                        } // if(checkfield)
-               } // while(!isEmpty(gctomark))
+               } // while(gc_moreItems2())
 #ifdef DEBUG
                BAMBOO_DEBUGPRINT(0xed07);
 #endif
@@ -1284,12 +1250,12 @@ inline void mark(bool isfirst,
                                                                         gcself_numsendobjs, gcself_numreceiveobjs);
                                sendStall = true;
                        }
-               }
+               } // if(STARTUPCORE == BAMBOO_NUM_OF_CORE) ...
 #ifdef DEBUG
                BAMBOO_DEBUGPRINT(0xed0a);
 #endif
 
-               if(BAMBOO_NUM_OF_CORE == 0) {
+               if(BAMBOO_NUM_OF_CORE == STARTUPCORE) {
 #ifdef DEBUG
                        BAMBOO_DEBUGPRINT(0xed0b);
 #endif
@@ -1338,7 +1304,8 @@ inline void compact2Heaptophelper(int coren,
                gcloads[gctopcore] = newbase;
                gcrequiredmems[coren] -= *remain - BAMBOO_CACHE_LINE_SIZE;
                gcstopblock[gctopcore]++;
-               gctopcore = nextTopcore(gctopcore, gcheapdirection);
+               gctopcore = NEXTTOPCORE(gctopblock);
+               gctopblock++;
                *numblocks = gcstopblock[gctopcore];
                *p = gcloads[gctopcore];
                BLOCKINDEX(*p, &b);
@@ -1411,6 +1378,7 @@ inline void compact2Heaptop() {
 #endif
 } // void compact2Heaptop()
 
+#if 0
 inline int nextTopcore(int topcore, bool direction) {
        int nextopcore = topcore;
        if((NUMCORES == 62) && (nextopcore>5)) {
@@ -1455,6 +1423,7 @@ inline int nextTopcore(int topcore, bool direction) {
        }
        return nextopcore;
 } // int nextTopcore(int topcore, bool direction)
+#endif
 
 inline void resolvePendingMoveRequest() {
 #ifdef DEBUG
@@ -1567,21 +1536,24 @@ struct moveHelper {
        int bound; // bound size of current heap block to check
 }; // struct moveHelper
 
-inline void nextSBlock(struct moveHelper * orig) {
+// if out of boundary of valid shared memory, return false, else return true
+inline bool nextSBlock(struct moveHelper * orig) {
        orig->blockbase = orig->blockbound;
-#ifdef GC_DEBUG
+#ifdef DEBUG
        BAMBOO_DEBUGPRINT(0xecc0);
        BAMBOO_DEBUGPRINT_REG(orig->blockbase);
        BAMBOO_DEBUGPRINT_REG(orig->blockbound);
        BAMBOO_DEBUGPRINT_REG(orig->bound);
        BAMBOO_DEBUGPRINT_REG(orig->ptr);
 #endif
+outernextSBlock:
+       // check if across a big block
        if((orig->blockbase >= orig->bound) || (orig->ptr >= orig->bound) 
                        || ((*((int*)orig->ptr))==0) || ((*((int*)orig->blockbase))==0)) {
 innernextSBlock:
                // end of current heap block, jump to next one
                orig->numblocks++;
-#ifdef GC_DEBUG
+#ifdef DEBUG
                BAMBOO_DEBUGPRINT(0xecc1);
                BAMBOO_DEBUGPRINT_REG(orig->numblocks);
 #endif
@@ -1589,38 +1561,58 @@ innernextSBlock:
 #ifdef DEBUG
                BAMBOO_DEBUGPRINT(orig->base);
 #endif
+               if(orig->base >= BAMBOO_BASE_VA + BAMBOO_SHARED_MEM_SIZE) {
+                       // out of boundary
+                       orig->ptr = orig->base; // set current ptr to out of boundary too
+                       return false;
+               }
                orig->bound = orig->base + BAMBOO_SMEM_SIZE;
                orig->blockbase = orig->base;
                orig->sblockindex = (orig->blockbase-BAMBOO_BASE_VA)/BAMBOO_SMEM_SIZE;
-               if(gcsbstarttbl[orig->sblockindex] == -1) {
-                       // goto next sblock
+       } else if(0 == (orig->blockbase%BAMBOO_SMEM_SIZE)) {
+               orig->sblockindex += 1;
+       } // if((orig->blockbase >= orig->bound) || (orig->ptr >= orig->bound) ...
+
+       // check if this sblock should be omitted or have special start point
+       if(gcsbstarttbl[orig->sblockindex] == -1) {
+               // goto next sblock
 #ifdef DEBUG
-                       BAMBOO_DEBUGPRINT(0xecc2);
+               BAMBOO_DEBUGPRINT(0xecc2);
 #endif
-                       orig->sblockindex += 1;
-                       orig->blockbase += BAMBOO_SMEM_SIZE;
-                       goto innernextSBlock;
-               } else if(gcsbstarttbl[orig->sblockindex] != 0) {
-                       // not start from the very beginning
-                       orig->blockbase = gcsbstarttbl[orig->sblockindex];
-               }
-       }
+               orig->sblockindex += 1;
+               orig->blockbase += BAMBOO_SMEM_SIZE;
+               goto outernextSBlock;
+       } else if(gcsbstarttbl[orig->sblockindex] != 0) {
+#ifdef DEBUG
+               BAMBOO_DEBUGPRINT(0xecc3);
+#endif
+               // not start from the very beginning
+               orig->blockbase = gcsbstarttbl[orig->sblockindex];
+       } // if(gcsbstarttbl[orig->sblockindex] == -1) else ...
+
+       // setup information for this sblock
        orig->blockbound = orig->blockbase + *((int*)(orig->blockbase));
        orig->offset = BAMBOO_CACHE_LINE_SIZE;
        orig->ptr = orig->blockbase + orig->offset;
-#ifdef GC_DEBUG
-       BAMBOO_DEBUGPRINT(0xecc3);
+#ifdef DEBUG
+       BAMBOO_DEBUGPRINT(0xecc4);
        BAMBOO_DEBUGPRINT_REG(orig->base);
        BAMBOO_DEBUGPRINT_REG(orig->bound);
        BAMBOO_DEBUGPRINT_REG(orig->ptr);
+       BAMBOO_DEBUGPRINT_REG(orig->blockbound);
+       BAMBOO_DEBUGPRINT_REG(orig->blockbase);
+       BAMBOO_DEBUGPRINT_REG(orig->offset);
 #endif
        if(orig->ptr >= orig->bound) {
                // met a lobj, move to next block
                goto innernextSBlock;
        }
-} // void nextSBlock(struct moveHelper * orig) 
 
-inline void initOrig_Dst(struct moveHelper * orig, 
+       return true;
+} // bool nextSBlock(struct moveHelper * orig) 
+
+// return false if there are no available data to compact
+inline bool initOrig_Dst(struct moveHelper * orig, 
                                     struct moveHelper * to) {
        // init the dst ptr
        to->numblocks = 0;
@@ -1663,8 +1655,7 @@ inline void initOrig_Dst(struct moveHelper * orig,
                // goto next sblock
                orig->blockbound = 
                        BAMBOO_BASE_VA+BAMBOO_SMEM_SIZE*(orig->sblockindex+1);
-               nextSBlock(orig);
-               return;
+               return nextSBlock(orig);
        } else if(gcsbstarttbl[orig->sblockindex] != 0) {
 #ifdef DEBUG
                BAMBOO_DEBUGPRINT(0xef04);
@@ -1681,7 +1672,8 @@ inline void initOrig_Dst(struct moveHelper * orig,
        BAMBOO_DEBUGPRINT(0xef06);
        BAMBOO_DEBUGPRINT_REG(orig->base);
 #endif
-} // void initOrig_Dst(struct moveHelper * orig, struct moveHelper * to) 
+       return true;
+} // bool initOrig_Dst(struct moveHelper * orig, struct moveHelper * to) 
 
 inline void nextBlock(struct moveHelper * to) {
        to->top = to->bound + BAMBOO_CACHE_LINE_SIZE; // header!
@@ -1715,7 +1707,10 @@ innermoveobj:
                orig->ptr = (int*)(orig->ptr) + 1;
        }
        if((orig->ptr > orig->bound) || (orig->ptr == orig->blockbound)) {
-               nextSBlock(orig);
+               if(!nextSBlock(orig)) {
+                       // finished, no more data
+                       return true;
+               }
                goto innermoveobj;
        }
 #ifdef DEBUG
@@ -1726,7 +1721,10 @@ innermoveobj:
        size = 0;
        if(type == 0) {
                // end of this block, go to next one
-               nextSBlock(orig);
+               if(!nextSBlock(orig)) {
+                       // finished, no more data
+                       return true;
+               }
                goto innermoveobj;
        } else if(type < NUMCLASSES) {
                // a normal object
@@ -1741,6 +1739,7 @@ innermoveobj:
        mark = ((int *)(orig->ptr))[6];
 #ifdef DEBUG
        BAMBOO_DEBUGPRINT(0xe203);
+       BAMBOO_DEBUGPRINT_REG(orig->ptr);
 #endif
        if(mark == 1) {
 #ifdef DEBUG
@@ -1762,8 +1761,6 @@ innermoveobj:
                        nextBlock(to);
                        if(stopblock == to->numblocks) {
                                // already fulfilled the block
-                               to->offset = 0;
-                               to->ptr = to->base;
                                return true;
                        } // if(stopblock == to->numblocks)
                } // if(to->top + isize > to->bound)
@@ -1808,7 +1805,10 @@ innermoveobj:
 #ifdef DEBUG
        BAMBOO_DEBUGPRINT(0xe206);
 #endif
-               nextSBlock(orig);
+               if(!nextSBlock(orig)) {
+                       // finished, no more data
+                       return true;
+               }
        }
 #ifdef DEBUG
        BAMBOO_DEBUGPRINT_REG(orig->ptr);
@@ -2010,7 +2010,12 @@ inline void compact() {
        struct moveHelper * to = 
                (struct moveHelper *)RUNMALLOC(sizeof(struct moveHelper));
 
-       initOrig_Dst(orig, to);
+       if(!initOrig_Dst(orig, to)) {
+               // no available data to compact
+               RUNFREE(orig);
+               RUNFREE(to);
+               return;
+       }
        
        int filledblocks = 0;
        INTPTR heaptopptr = 0;
@@ -2383,12 +2388,8 @@ inline void gc(struct garbagelist * stackptr) {
                tprintf("mark phase finished \n");
                //dumpSMem();
 #endif
-               int tmpn = 0;
                int tmptopptr = 0;
-               if(!gcheapdirection) {
-                       tmpn = 1;
-               }
-               BASEPTR(gctopcore, tmpn, &tmptopptr);
+               BASEPTR(gctopcore, 0, &tmptopptr);
                // TODO
                tmptopptr = (BAMBOO_BASE_VA) + (BAMBOO_SHARED_MEM_SIZE);
 #ifdef DEBUG
@@ -2397,10 +2398,10 @@ inline void gc(struct garbagelist * stackptr) {
 #endif
                for(i = 0; i < NUMCORES; ++i) {
                        int tmpcoreptr = 0;
-                       BASEPTR(i, tmpn, &tmpcoreptr);
+                       BASEPTR(i, 0, &tmpcoreptr);
                        //send start compact messages to all cores
                        if (tmpcoreptr < tmptopptr) {
-                               gcstopblock[i] =numpbc + 1;
+                               gcstopblock[i] = numpbc + 1;
                                if(i != STARTUPCORE) {
                                        send_msg_2(i, GCSTARTCOMPACT, numpbc+1); 
                                } else {
@@ -2516,7 +2517,7 @@ inline void gc(struct garbagelist * stackptr) {
                } // while(COMPACTPHASE == gcphase) 
 #ifdef GC_DEBUG
                tprintf("prepare to move large objs \n");
-               //dumpSMem();
+               dumpSMem();
 #endif
                // move largeObjs
                moveLObjs();
@@ -2538,8 +2539,6 @@ inline void gc(struct garbagelist * stackptr) {
 #endif
                // flush phase
                flush(stackptr);
-               // TODO
-               BAMBOO_DEBUGPRINT(0xefef);
                gccorestatus[BAMBOO_NUM_OF_CORE] = 0;
                while(FLUSHPHASE == gcphase) {
                        // check the status of all cores
index cba9254d2c874430a6c3d9b1e8fec8193eb2b73c..005baecea0d99ea4d1a1226acb963d7c5b2bb2e7 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef MULTICORE_GARBAGE_H
 #define MULTICORE_GARBAGE_H
 #include "multicoregc.h"
+#include "multicorehelper.h"  // for mappins between core # and block #
 #include "structdefs.h"
 
 #ifndef bool
@@ -45,7 +46,7 @@ int gcself_numreceiveobjs;
 INTPTR gcheaptop;
 int gcloads[NUMCORES];
 int gctopcore; // the core host the top of the heap
-bool gcheapdirection; // 0: decrease; 1: increase
+int gctopblock; // the number of current top block
 
 int gcnumlobjs;
 
@@ -82,6 +83,8 @@ int gcbaseva; // base va for shared memory without reserved sblocks
 #define ALIGNSIZE(s, as) \
        (*((int*)as)) = (((s) & (~(BAMBOO_CACHE_LINE_MASK))) + (BAMBOO_CACHE_LINE_SIZE))
 
+// mapping of pointer to block # (start from 0), here the block # is the global
+// index
 #define BLOCKINDEX(p, b) \
   { \
                int t = (p) - gcbaseva; \
@@ -92,8 +95,22 @@ int gcbaseva; // base va for shared memory without reserved sblocks
                } \
        }
 
+// mapping of pointer to core #
+#define RESIDECORE(p, c) \
+{ \
+       if(1 == (NUMCORES)) { \
+               (*((int*)c)) = 0; \
+       } else {\
+               int b; \
+               BLOCKINDEX((p), &b); \
+               (*((int*)c)) = gc_block2core[(b%124)]; \
+       }\
+}
+
+#if 0
+// mapping of pointer to host core (x,y)
 #define RESIDECORE(p, x, y) \
-       { \
+  { \
                if(1 == (NUMCORES)) { \
                        (*((int*)x)) = 0; \
                        (*((int*)y)) = 0; \
@@ -126,8 +143,12 @@ int gcbaseva; // base va for shared memory without reserved sblocks
                        } \
                } \
        }
+#endif
 
 // NOTE: n starts from 0
+// mapping of heaptop (how many bytes there are in the local heap) to the number of
+// the block
+// the number of the block indicates that the block is the xth block on the local heap
 #define NUMBLOCKS(s, n) \
        if(s < (BAMBOO_SMEM_SIZE_L)) { \
                (*((int*)(n))) = 0; \
@@ -142,6 +163,9 @@ int gcbaseva; // base va for shared memory without reserved sblocks
                (*((int*)(o))) = ((s) - (BAMBOO_SMEM_SIZE_L)) % (BAMBOO_SMEM_SIZE); \
        }
 
+// mapping of (core #, index of the block) to the global block index
+#define BLOCKINDEX2(c, n) (gc_core2block[(2*(c))+((n)%2)]+(124*((n)/2))) 
+#if 0
 #define BLOCKINDEX2(c, n, b) \
   { \
                int x; \
@@ -179,12 +203,12 @@ int gcbaseva; // base va for shared memory without reserved sblocks
                t += (NUMCORES) * (n); \
                (*((int*)b)) = t; \
        }
+#endif
 
-
+// mapping of (core #, number of the block) to the base pointer of the block
 #define BASEPTR(c, n, p) \
   { \
-               int b; \
-               BLOCKINDEX2(c, n, &b); \
+               int b = BLOCKINDEX2((c), (n)); \
                if(b < (NUMCORES)) { \
                        (*((int*)p)) = gcbaseva + b * (BAMBOO_SMEM_SIZE_L); \
                } else { \
@@ -192,16 +216,19 @@ int gcbaseva; // base va for shared memory without reserved sblocks
                } \
        }
 
+// the next core in the top of the heap
+#define NEXTTOPCORE(b) (gc_block2core[((b)+1)%124])
+
 inline void gc(struct garbagelist * stackptr); // core coordinator routine
 inline void gc_collect(struct garbagelist* stackptr);//core collector routine
 inline void transferMarkResults_I();
 inline void gc_enqueue_I(void *ptr);
 inline void gc_lobjenqueue_I(void *ptr, int length, int host);
 inline bool gcfindSpareMem_I(int * startaddr, 
-                                      int * tomove,
-                                                                                                int * dstcore,
-                                                                                                int requiredmem,
-                                                                                                int requiredcore);
+                                        int * tomove,
+                                                                                                  int * dstcore,
+                                                                                                  int requiredmem,
+                                                                                                  int requiredcore);
 
 #endif
 
diff --git a/Robust/src/Runtime/multicorehelper.h b/Robust/src/Runtime/multicorehelper.h
new file mode 100644 (file)
index 0000000..bb5e581
--- /dev/null
@@ -0,0 +1,22 @@
+#ifndef MULTICORE_HELPER_H
+#define MULTICORE_HELPER_H
+
+static int gc_core2block[124] = {0,123,  15,108,  16,107,  31,92,  32,91,  47,76,    
+                                 1,122,  14,109,  17,106,  30,93,  33,90,  46,77,  48,75,  61,62,
+                                 2,121,  13,110,  18,105,  29,94,  34,89,  45,78,  49,74,  60,63,
+                                 3,120,  12,111,  19,104,  28,95,  35,88,  44,79,  50,73,  59,64,
+                                 4,119,  11,112,  20,103,  27,96,  36,87,  43,80,  51,72,  58,65,
+                                 5,118,  10,113,  21,102,  26,97,  37,86,  42,81,  52,71,  57,66,
+                                 6,117,   9,114,  22,101,  25,98,  38,85,  41,82,  53,70,  56,67,
+                                 7,116,   8,115,  23,100,  24,99,  39,84,  40,83,  54,69,  55,68};
+
+static int gc_block2core[124] = { 0,  6, 14, 22, 30, 38, 46, 54, 55, 47, 39, 31, 23, 15,  7,  1,
+                                  2,  8, 16, 24, 32, 40, 48, 56, 57, 49, 41, 33, 25, 17,  9,  3,
+                                  4, 10, 18, 26, 34, 42, 50, 58, 59, 51, 43, 35, 27, 19, 11,  5,
+                                     12, 20, 28, 36, 44, 52, 60, 61, 53, 45, 37, 29, 21, 13,    
+                                     13, 21, 29, 37, 45, 53, 61, 60, 52, 44, 36, 28, 20, 12,    
+                                  5, 11, 19, 27, 35, 43, 51, 59, 58, 50, 42, 34, 26, 18, 10,  4,
+                                  3,  9, 17, 25, 33, 41, 49, 57, 56, 48, 40, 32, 24, 16,  8,  2,
+                                  1,  7, 15, 23, 31, 39, 47, 55, 54, 46, 38, 30, 22, 14,  6,  0};
+
+#endif // MULTICORE_HELPER_H
index 9513f49f37c5c239022b1b4205b40a4a16ee6f1c..697599e0d26bf006b12fd99f16e05559037bb9e3 100644 (file)
@@ -88,7 +88,7 @@ void initruntimedata() {
        gcnumlobjs = 0;
        gcheaptop = 0;
        gctopcore = 0;
-       gcheapdirection = 1;
+       gctopblock = 0;
        gcmovestartaddr = 0;
        gctomove = false;
        gcmovepending = 0;
index f15b2f55e40c758b045b7e6f61a3eab915498132..98b24f6abdf9c721937c87bdd6c6a979926b35d8 100755 (executable)
@@ -50,6 +50,7 @@ echo "-tileraconfig config tilera simulator/pci as nxm (should be used together
 echo "-raw generate raw version binary (should be used together with -multicore)"
 echo "-rawconfig config raw simulator as 4xn (should be used together with -raw)"
 echo -threadsimulate generate multi-thread simulate version binary
+echo -multicoregc generate multi-core binary with garbage collection
 echo -optional enable optional
 echo -debug generate debug symbols
 echo -prefetch do prefetch analysis
@@ -107,6 +108,7 @@ ACCURATEPROFILEFLAG=false
 USEIOFLAG=false
 INTERRUPTFLAG=false
 THREADSIMULATEFLAG=false;
+MULTICOREGCFLAG=false;
 USEDMALLOC=false
 THREADFLAG=false
 FASTCHECK=false
@@ -297,6 +299,10 @@ elif [[ $1 = '-optional' ]]
 then
 JAVAOPTS="$JAVAOPTS -optional"
 OPTIONALFLAG=true
+elif [[ $1 = '-multicoregc' ]]
+then
+MULTICOREGCFLAG=true
+JAVAOPTS="$JAVAOPTS -multicoregc"
 elif [[ $1 = '-dmalloc' ]]
 then
 USEDMALLOC=true
@@ -633,6 +639,11 @@ then #INTERRUPT version
 TILERACFLAGS="${TILERACFLAGS} -DINTERRUPT"
 fi #INTERRUPT version
 
+if $MULTICOREGCFLAG
+then #MULTICOREGC version
+TILERACFLAGS="${TILERACFLAGS} -DMULTICORE_GC"
+fi
+
 cp $ROBUSTROOT/Tilera/Runtime/$MAKEFILE ./Makefile
 cp $ROBUSTROOT/Tilera/Runtime/$SIMHVC ./sim.hvc
 cp $ROBUSTROOT/Tilera/Runtime/$PCIHVC ./pci.hvc
@@ -648,6 +659,7 @@ cp ../Runtime/SimpleHash.c ./
 cp ../Runtime/ObjectHash.c ./
 cp ../Runtime/socket.c ./
 cp ../Runtime/mem.c ./
+cp ../Runtime/multicoregarbage.c ./
 cp ../Runtime/GenericHashtable.h ./
 cp ../Runtime/mem.h ./
 cp ../Runtime/multicoreruntime.h ./
@@ -656,6 +668,9 @@ cp ../Runtime/ObjectHash.h ./
 cp ../Runtime/Queue.h ./
 cp ../Runtime/runtime.h ./
 cp ../Runtime/SimpleHash.h ./
+cp ../Runtime/multicoregc.h ./
+cp ../Runtime/multicoregarbage.h ./
+cp ../Runtime/multicorehelper.h ./
 cp ../Tilera/Runtime/*.c ./
 cp ../Tilera/Runtime/*.h ./
 cp ../Tilera/lib/* ./