bug fix for multicore gc version
authorjzhou <jzhou>
Wed, 20 Apr 2011 01:29:10 +0000 (01:29 +0000)
committerjzhou <jzhou>
Wed, 20 Apr 2011 01:29:10 +0000 (01:29 +0000)
Robust/src/Benchmarks/TileSearch/NoOptional/TileSearch.java
Robust/src/IR/Flat/BuildCode.java
Robust/src/Runtime/bamboo/multicoregarbage.c
Robust/src/Runtime/bamboo/multicoregarbage.h
Robust/src/Runtime/bamboo/multicoreruntime.c
Robust/src/Runtime/mem.c

index 1bb3d41f63574242186bd9894aceb5dc7e7095cd..1b2d1d046d88eb83fba957acccc2f142c48fc484 100644 (file)
@@ -54,7 +54,7 @@
 task Startup( StartupObject s{ initialstate } )
 {
   //System.printString("Top of task Startup\n");
-  SubProblem top = new SubProblem(){ findingNewFits, main };
+  SubProblem top = newflag SubProblem(){ findingNewFits, main };
 
 
     // use this initialization to solve the above example
@@ -111,7 +111,7 @@ task Startup( StartupObject s{ initialstate } )
                          [top.tilesFitted[0].y] = 0;
 
     top.highScore      = 0;
-    GlobalCounter counter = new GlobalCounter() {Init};
+    GlobalCounter counter = newflag GlobalCounter() {Init};
     taskexit( s{ !initialstate } );
 }
 
@@ -150,10 +150,10 @@ task findNewFits(/*optional*/ SubProblem sp{ findingNewFits }, GlobalCounter cou
        //System.printString( "North: \n" );
        SubProblem newSP = null;
        if(sp.tilesToFit.length == 1 ) {
-           newSP = new SubProblem() { !scored, leaf };
+           newSP = newflag SubProblem() { !scored, leaf };
            ++counter.counter;
        } else {
-           newSP = new SubProblem() { findingNewFits };
+           newSP = newflag SubProblem() { findingNewFits };
        }
        sp.initializeSubProblem( newSP, 1 );
        //System.printString( "match! new a SubProblem\n" );
@@ -167,10 +167,10 @@ task findNewFits(/*optional*/ SubProblem sp{ findingNewFits }, GlobalCounter cou
        //System.printString( "South: \n" );
        SubProblem newSP = null;
        if(sp.tilesToFit.length == 1) {
-           newSP = new SubProblem() { !scored, leaf };
+           newSP = newflag SubProblem() { !scored, leaf };
            ++counter.counter;
        } else {
-           newSP = new SubProblem() { findingNewFits };
+           newSP = newflag SubProblem() { findingNewFits };
        }
        sp.initializeSubProblem( newSP, 2 );
        //System.printString( "match! new a SubProblem\n" );
@@ -184,10 +184,10 @@ task findNewFits(/*optional*/ SubProblem sp{ findingNewFits }, GlobalCounter cou
        //System.printString( "East: \n" );
        SubProblem newSP = null; 
        if(sp.tilesToFit.length == 1) {
-           newSP = new SubProblem() { !scored, leaf };
+           newSP = newflag SubProblem() { !scored, leaf };
            ++counter.counter;
        } else {
-           newSP = new SubProblem() { findingNewFits };
+           newSP = newflag SubProblem() { findingNewFits };
        }
        sp.initializeSubProblem( newSP, 3 );
        //System.printString( "match! new a SubProblem\n" );
@@ -201,10 +201,10 @@ task findNewFits(/*optional*/ SubProblem sp{ findingNewFits }, GlobalCounter cou
        //System.printString( "West:\n" );
        SubProblem newSP = null;
        if(sp.tilesToFit.length == 1) {
-           newSP = new SubProblem() { !scored, leaf };
+           newSP = newflag SubProblem() { !scored, leaf };
            ++counter.counter;
        } else {
-           newSP = new SubProblem() { findingNewFits };
+           newSP = newflag SubProblem() { findingNewFits };
        }
        sp.initializeSubProblem( newSP, 4 );
        //System.printString( "match! new a SubProblem\nSpawn finished! Go on find new fits.\n" );
index a608d2e6c85c5b0ee085e20fec0550390c10a36b..03a3d4d424099802a35bac153fd91b0afcac80cc 100644 (file)
@@ -219,6 +219,7 @@ public class BuildCode {
     outmethodheader.close();
     outmethod.close();
     outstructs.println("#endif");
+    outstructs.println();
     outstructs.close();
 
     postCodeGenCleanUp();
@@ -534,8 +535,8 @@ public class BuildCode {
   }
 
   protected void outputStructs(PrintWriter outstructs) {
-    outstructs.println("#ifndef STRUCTDEFS_H");
-    outstructs.println("#define STRUCTDEFS_H");
+    outstructs.println("#ifndef __STRUCTDEFS_H__");
+    outstructs.println("#define __STRUCTDEFS_H__");
     outstructs.println("#include \"classdefs.h\"");
     outstructs.println("#ifndef INTPTR");
     outstructs.println("#ifdef BIT64");
@@ -644,7 +645,6 @@ public class BuildCode {
        outclassdefs.println("  int * lock;");  // lock entry for this obj
        outclassdefs.println("  int mutex;");
        outclassdefs.println("  volatile int lockcount;");
-       outclassdefs.println("  volatile int notifycount;");
        if(state.MULTICOREGC) {
          outclassdefs.println("  int marked;");
        }
@@ -1576,7 +1576,7 @@ public class BuildCode {
        classdefout.println("  int version;");
        classdefout.println("  int * lock;"); // lock entry for this obj
        classdefout.println("  int mutex;");
-       classdefout.println("  int lockcount;");
+       classdefout.println("  volatile int lockcount;");
        if(state.MULTICOREGC) {
          classdefout.println("  int marked;");
        }
index ab4a6d57ce5f102ac3e7f4a81f17bdee94663fa2..7c01d1d53e2ae6d034d36597233e7144b308c6de 100644 (file)
@@ -3628,8 +3628,6 @@ inline void gc_collect(struct garbagelist * stackptr) {
     }
   }
 
-  //gcflag = false;
-  //gcprocessing = false;
 #ifdef RAWPATH // TODO GC_DEBUG
   printf("(%x,%x) Finish gc! \n", udn_tile_coord_x(), udn_tile_coord_y());
 #endif
@@ -3736,15 +3734,13 @@ inline void gc_nocollect(struct garbagelist * stackptr) {
       break;
     }
   }
-  //gcflag = false;
-  //gcprocessing = false;
 #ifdef RAWPATH // TODO GC_DEBUG
   printf("(%x,%x) Finish gc! \n", udn_tile_coord_x(), udn_tile_coord_y());
 #endif
 } // void gc_collect(struct garbagelist * stackptr)
 
 inline void gc_master(struct garbagelist * stackptr) {
-  //tprintf("start GC !!!!!!!!!!!!! \n");
+  tprintf("start GC !!!!!!!!!!!!! \n");
 
   gcphase = INITPHASE;
   int i = 0;
@@ -4147,7 +4143,7 @@ inline void gc_master(struct garbagelist * stackptr) {
   printf("(%x,%x) gc finished   \n", udn_tile_coord_x(), 
                 udn_tile_coord_y());
 #endif
-  //tprintf("finish GC ! \n");
+  tprintf("finish GC ! \n");
 } // void gc_master(struct garbagelist * stackptr)
 
 inline bool gc(struct garbagelist * stackptr) {
index d109346a73d5ba78d6eedfb810d3e8a5ac9ba388..27fe89feb9f9709f15421717ed86926f51061857 100644 (file)
@@ -14,7 +14,7 @@
 #endif
 
 #ifdef TASK
-#define BAMBOOMARKBIT 6
+#define BAMBOOMARKBIT 8
 #elif defined MGC
 #define BAMBOOMARKBIT 5
 #endif // TASK
index af6d61f39b5c2fcfb1e5c0e0b73fa7cebf99bf8d..95173598908761058796ed816a5939ef7a86d677 100644 (file)
@@ -1187,16 +1187,24 @@ INLINE void processmsg_memrequest_I() {
     void * mem = NULL;
 #ifdef MULTICORE_GC
     if(gcprocessing) {
-      // is currently doing gc, dump this msg
-      if(INITPHASE == gcphase) {
-               // if still in the initphase of gc, send a startinit msg again,
-               // cache the msg first
+      // is currently doing gc, dump this msg if at the beginning of the gc
+         // if at the end of the gc, send a msg with a block with size of -1
+         // to ask the request core to send the mem request again
+      if(FINISHPHASE == gcphase) {
+               // if still in the finishphase of gc, send a memresponse msg with 
+               // invalid block: addr 0, size -1
+               if(BAMBOO_CHECK_SEND_MODE()) {
+                 cache_msg_3(data2, MEMRESPONSE, 0, -1);
+               } else {
+                 send_msg_3(data2, MEMRESPONSE, 0, -1, true);
+               }
+      } else if(INITPHASE == gcphase) {
                if(BAMBOO_CHECK_SEND_MODE()) {
                  cache_msg_1(data2, GCSTARTINIT);
                } else {
                  send_msg_1(data2, GCSTARTINIT, true);
                }
-      }
+         }
     } else {
 #endif
     mem = smemalloc_I(data2, data1, &allocsize);
@@ -1235,6 +1243,9 @@ INLINE void processmsg_memresponse_I() {
 #ifdef MULTICORE_GC
        bamboo_smem_zero_top = 0;
 #endif
+  } else if(data2 == -1) {
+       bamboo_smem_size = data2;
+       bamboo_cur_msp = (void *)data1;
   } else {
 #ifdef MULTICORE_GC
     // fill header to store the size of this mem block
@@ -1258,14 +1269,6 @@ INLINE void processmsg_memresponse_I() {
 INLINE void processmsg_gcstartpre_I() {
   if(gcprocessing) {
        // already stall for gc
-       // send a update pregc information msg to the master core
-       /*if(BAMBOO_CHECK_SEND_MODE()) {
-         cache_msg_4(STARTUPCORE, GCFINISHPRE, BAMBOO_NUM_OF_CORE, 
-                 self_numsendobjs, self_numreceiveobjs);
-       } else {
-         send_msg_4(STARTUPCORE, GCFINISHPRE, BAMBOO_NUM_OF_CORE, 
-                 self_numsendobjs, self_numreceiveobjs, true);
-       }*/
   } else {
        // the first time to be informed to start gc
        gcflag = true;
index ef28022c77c5bb9ca48f3378dcb5b35e5507d0da..3ddecd00fbbc661787939c295bf5e885deba901c 100644 (file)
@@ -5,24 +5,31 @@
 #include "runtime_arch.h"
 
 #ifdef MULTICORE_GC
+extern volatile bool gcflag;
 void * mycalloc_share(struct garbagelist * stackptr, 
                              int m, 
                                          int size) {
-       void * p = NULL;
+  void * p = NULL;
   //int isize = 2*BAMBOO_CACHE_LINE_SIZE-4+(size-1)&(~BAMBOO_CACHE_LINE_MASK);
   int isize = (size & (~(BAMBOO_CACHE_LINE_MASK))) + (BAMBOO_CACHE_LINE_SIZE);
-       int hasgc = 0;
+  int hasgc = 0;
 memalloc:
   BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
+  if(gcflag) {
+       BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
+       gc(stackptr);
+       BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
+  }
   p = BAMBOO_SHARE_MEM_CALLOC_I(m, isize); // calloc(m, isize);
   if(p == NULL) {
                // no more global shared memory
                BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
                if(hasgc < 5) {
                    // start gc
-                       if(gc(stackptr)) {
-                         hasgc++;
+                       while(gcflag) {
+                         gc(stackptr);
                        }
+                       hasgc++;
                } else {
                        // no more global shared memory
                        BAMBOO_EXIT(0xc001);