From: bdemsky Date: Mon, 20 Jun 2011 09:38:02 +0000 (+0000) Subject: more changes X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=4d184dc4859e2b6a26b82c07c14ad89ee931db66;p=IRC.git more changes --- diff --git a/Robust/src/Runtime/bamboo/multicoregarbage.c b/Robust/src/Runtime/bamboo/multicoregarbage.c index a253b8a1..6d37942f 100644 --- a/Robust/src/Runtime/bamboo/multicoregarbage.c +++ b/Robust/src/Runtime/bamboo/multicoregarbage.c @@ -1,4 +1,3 @@ -// TODO: DO NOT support tag!!! #ifdef MULTICORE_GC #include "runtime.h" #include "multicoreruntime.h" @@ -9,6 +8,7 @@ #include "multicoregcflush.h" #include "multicoregcprofile.h" #include "gcqueue.h" +#include "multicoremem_helper.h" volatile bool gcflag; gc_status_t gc_status_info; @@ -111,6 +111,7 @@ void initmulticoregcdata() { else allocationinfo.blocktable[i].corenum=gc_block2core[(i%(NUMCORES4GC*2))]; } + buildCore2Test(); } INIT_MULTICORE_GCPROFILE_DATA(); @@ -251,18 +252,19 @@ void checkMarkStatus() { } // compute load balance for all cores -int loadbalance(void ** heaptop) { +int loadbalance() { // compute load balance // get the total loads + void * heaptop; unsigned int tloads = 0; for(int i = 0; i < NUMCORES4GC; i++) { tloads += gcloads[i]; } - *heaptop = gcbaseva + tloads; + heaptop = gcbaseva + tloads; unsigned int topblockindex; - BLOCKINDEX(topblockindex, *heaptop); + BLOCKINDEX(topblockindex, heaptop); // num of blocks per core unsigned int numbpc = (topblockindex+NUMCORES4GC-1)/NUMCORES4GC; diff --git a/Robust/src/Runtime/bamboo/multicoregarbage.h b/Robust/src/Runtime/bamboo/multicoregarbage.h index 1e5b6989..a3f6890c 100644 --- a/Robust/src/Runtime/bamboo/multicoregarbage.h +++ b/Robust/src/Runtime/bamboo/multicoregarbage.h @@ -19,6 +19,8 @@ m#ifndef BAMBOO_MULTICORE_GARBAGE_H // let each gc core to have one big block, this is very important // for the computation of NUMBLOCKS(s, n), DO NOT change this! +typedef int block_t; + typedef enum { INITPHASE = 0x0, // 0x0 MARKPHASE, // 0x1 @@ -61,7 +63,7 @@ unsigned int gcself_numreceiveobjs; // for load balancing unsigned int gcheaptop; unsigned INTPTR gcloads[NUMCORES4GC]; -unsigned INTPTR numblockspercore; +block_t numblockspercore; //Top of each core's heap void * topptrs[NUMCORES4GC]; @@ -98,8 +100,8 @@ void * gcbaseva; // base va for shared memory without reserved sblocks /* Structure to keep track of free space in block */ enum blockstatus { - /* BS_INIT indicates that we don't have information for this block yet */ - BS_INIT, + /* BS_USED indicates that we don't have information for this block yet */ + BS_USED, /* BS_LARGEOBJECT indicates that the beginning of this block has a large object*/ BS_LARGEOBJECT, /* BS_FREE indicates that the block is at least partially free */ @@ -109,8 +111,8 @@ enum blockstatus { struct blockrecord { enum blockstatus status; unsigned INTPTR usedspace; + unsigned INTPTR freespace; unsigned int corenum; - }; #define NOFREEBLOCK 0xffffffff diff --git a/Robust/src/Runtime/bamboo/multicoregccompact.c b/Robust/src/Runtime/bamboo/multicoregccompact.c index 62021194..050b4d15 100644 --- a/Robust/src/Runtime/bamboo/multicoregccompact.c +++ b/Robust/src/Runtime/bamboo/multicoregccompact.c @@ -5,6 +5,16 @@ #include "multicoregarbage.h" #include "markbit.h" +int gc_countRunningCores() { + int count=0; + for(int i = 0; i < NUMCORES4GC; ++i) { + if(gccorestatus[i] != 0) { + count++; + } + } + return count; +} + bool gc_checkCoreStatus() { for(int i = 0; i < NUMCORES4GC; ++i) { if(gccorestatus[i] != 0) { @@ -99,29 +109,80 @@ void compacthelper(struct moveHelper * orig,struct moveHelper * to) { send_msg_3(STARTUPCORE,GCFINISHCOMPACT,BAMBOO_NUM_OF_CORE, 0); } -/* Should be invoked with interrupt turned off. */ - -void * assignSpareMem_I(unsigned int sourcecore, unsigned int requiredmem) { +void * checkNeighbors(int corenum, unsigned INTPTR requiredmem) { + int minblockindex=allocation.lowestfreeblock/NUMCORES4GC; + block_t toplocalblock=topblock/NUMCORES4GC; + for(int i=0;istatus==BS_FREE) { + unsigned INTPTR freespace=block->freespace&~BAMBOO_CACHE_LINE_MASK; + if (requiredmemstatus=BS_USED; + void *blockptr=OFFSET2BASEVA(globalblockindex)+gcbaseva; + unsigned INTPTR usedspace=((block->usedspace-1)&~BAMBOO_CACHE_LINE_MASK)+BAMBOO_CACHE_LINE_SIZE; + return blockptr+usedspace; + } + } + } + } + } return NULL; } -void * assignSpareMem(unsigned int sourcecore,unsigned int requiredmem) { - BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT(); - void * retval=assignSpareMem_I(sourcecore, requiredmem); - BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME(); - return retval; +void * globalSearch(unsigned int topblock) { + unsigned int firstfree=NOFREEBLOCK; + for(block_t i=allocationinfo.lowestfreeblock;istatus==BS_FREE) { + if(firstfree==NOFREEBLOCK) + firstfree=i; + unsigned INTPTR freespace=block->freespace&~BAMBOO_CACHE_LINE_MASK; + if (requiredmemstatus=BS_USED; + void *blockptr=OFFSET2BASEVA(globalblockindex)+gcbaseva; + unsigned INTPTR usedspace=((block->usedspace-1)&~BAMBOO_CACHE_LINE_MASK)+BAMBOO_CACHE_LINE_SIZE; + allocationinfo.lowestfreeblock=firstfree; + return blockptr+usedspace; + } + } + } + allocationinfo.lowestfreeblock=firstfree; + return NULL; } /* should be invoked with interrupt turned off */ void * gcfindSpareMem_I(unsigned int requiredmem,unsigned int requiredcore) { - void * startaddr; - for(int k = 0; k < NUMCORES4GC; k++) { + if (allocationinfo.lowestfreeblock!=NOFREEBLOCK) { + //There are spare blocks + unsigned int topblock=numblockspercore*NUMCORES4GC; + void *memblock; + if (memblock=checkNeighbors(requiredcore, requiredmem)) { + return memblock; + } else if (memblock=globalSearch(topblock, requiredmem)) { + return memblock; + } } + // If we cannot find spare mem right now, hold the request gcrequiredmems[requiredcore] = requiredmem; gcmovepending++; + + int count=gc_countRunningCores(); + if (gcmovepending==count) { + // All cores have stopped...hand out memory as necessary to handle all requests + + } + return NULL; } @@ -199,8 +260,7 @@ void compact() { void master_compact() { // predict number of blocks to fill for each core - void * tmpheaptop = 0; - numblockspercore = loadbalance(&tmpheaptop); + numblockspercore = loadbalance()+1; GC_PRINTF("mark phase finished \n"); @@ -211,13 +271,15 @@ void master_compact() { //assigned blocks for(int i=0;istatus=BS_FREE; blockrecord->usedspace=(unsigned INTPTR)(heaptop-OFFSET2BASEVA(blockindex)); + blockrecord->freespace=BLOCKSIZE(localblocknum)-blockrecord->usedspace; /* Update the lowest free block */ if (blockindex < allocationinfo.lowestfreeblock) { blockindex=allocationinfo.lowestfreeblock; @@ -514,12 +518,14 @@ void processmsg_returnmem_I() { /* This is our own block...means we should mark other blocks above us as free*/ if (cnum==blockrecord->corenum) { - unsigned INTPTR nextlocalblocknum=GLOBALBLOCK2LOCK(blockindex)+1; + unsigned INTPTR nextlocalblocknum=localblocknum+1; for(;nextlocalblocknumstatus=BS_FREE; nextblockrecord->usedspace=0; + //this is true because this cannot be the lowest block + nextblockrecord->freespace=BLOCKSIZE(1); } } }