From 5cd83053a6d178d6e9f00f9891ab2d50f9af08ae Mon Sep 17 00:00:00 2001 From: jzhou Date: Wed, 20 Apr 2011 01:29:10 +0000 Subject: [PATCH] bug fix for multicore gc version --- .../TileSearch/NoOptional/TileSearch.java | 20 ++++++------- Robust/src/IR/Flat/BuildCode.java | 8 ++--- Robust/src/Runtime/bamboo/multicoregarbage.c | 8 ++--- Robust/src/Runtime/bamboo/multicoregarbage.h | 2 +- Robust/src/Runtime/bamboo/multicoreruntime.c | 29 ++++++++++--------- Robust/src/Runtime/mem.c | 15 +++++++--- 6 files changed, 44 insertions(+), 38 deletions(-) diff --git a/Robust/src/Benchmarks/TileSearch/NoOptional/TileSearch.java b/Robust/src/Benchmarks/TileSearch/NoOptional/TileSearch.java index 1bb3d41f..1b2d1d04 100644 --- a/Robust/src/Benchmarks/TileSearch/NoOptional/TileSearch.java +++ b/Robust/src/Benchmarks/TileSearch/NoOptional/TileSearch.java @@ -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" ); diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index a608d2e6..03a3d4d4 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -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;"); } diff --git a/Robust/src/Runtime/bamboo/multicoregarbage.c b/Robust/src/Runtime/bamboo/multicoregarbage.c index ab4a6d57..7c01d1d5 100644 --- a/Robust/src/Runtime/bamboo/multicoregarbage.c +++ b/Robust/src/Runtime/bamboo/multicoregarbage.c @@ -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) { diff --git a/Robust/src/Runtime/bamboo/multicoregarbage.h b/Robust/src/Runtime/bamboo/multicoregarbage.h index d109346a..27fe89fe 100644 --- a/Robust/src/Runtime/bamboo/multicoregarbage.h +++ b/Robust/src/Runtime/bamboo/multicoregarbage.h @@ -14,7 +14,7 @@ #endif #ifdef TASK -#define BAMBOOMARKBIT 6 +#define BAMBOOMARKBIT 8 #elif defined MGC #define BAMBOOMARKBIT 5 #endif // TASK diff --git a/Robust/src/Runtime/bamboo/multicoreruntime.c b/Robust/src/Runtime/bamboo/multicoreruntime.c index af6d61f3..95173598 100644 --- a/Robust/src/Runtime/bamboo/multicoreruntime.c +++ b/Robust/src/Runtime/bamboo/multicoreruntime.c @@ -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; diff --git a/Robust/src/Runtime/mem.c b/Robust/src/Runtime/mem.c index ef28022c..3ddecd00 100644 --- a/Robust/src/Runtime/mem.c +++ b/Robust/src/Runtime/mem.c @@ -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); -- 2.34.1