INTPTR curr_heaptop = 0;
INTPTR curr_heapbound = 0;
-bool isLarge(void * ptr, int * ttype, int * tsize) {
+bool isLarge(void * ptr,
+ int * ttype,
+ int * tsize) {
// check if a pointer is referring to a large object
int type = ((int *)ptr)[0];
int size = 0;
int x = 0;
int y = 0;
RESIDECORE(ptr, &x, &y);
- host = (x == 0)?(x * bamboo_height + y) : (x * bamboo_height + y - 2);
+ host = (x==0)?(x*bamboo_height+y):(x*bamboo_height+y-2);
return host;
}
void transferMarkResults() {
// TODO, need distiguish between send and cache
// invoked inside interruptiong handler
+ int msgsize = 4;
+ int i = 0;
+
+ // TODO check large objs here
+
+ isMsgSending = true;
+ DynamicHeader msgHdr = tmc_udn_header_from_cpu(STARTUPCORE);
+
+ // send header
+ __tmc_udn_send_header_with_size_and_tag(msgHdr, msgsize,
+ UDN0_DEMUX_TAG);
+#ifdef DEBUG
+ BAMBOO_DEBUGPRINT(0xbbbb);
+ BAMBOO_DEBUGPRINT(0xb000 + STARTUPCORE); // targetcore
+#endif
+ udn_send(GCLOBJINFO);
+#ifdef DEBUG
+ BAMBOO_DEBUGPRINT(GCLOBJINFO);
+#endif
+ udn_send(msgsize);
+#ifdef DEBUG
+ BAMBOO_DEBUGPRINT_REG(msgsize);
+#endif
+ udn_send(BAMBOO_NUM_OF_CORE);
+#ifdef DEBUG
+ BAMBOO_DEBUGPRINT_REG(BAMBOO_NUM_OF_CORE);
+#endif
+ udn_send(curr_heaptop);
+#ifdef DEBUG
+ BAMBOO_DEBUGPRINT_REG(curr_heaptop);
+#endif
+ // TODO large objs here
+
+#ifdef DEBUG
+ BAMBOO_DEBUGPRINT(0xffff);
+#endif
+
+ // end of sending this msg, set sand msg flag false
+ isMsgSending = false;
+ send_hanging_msg();
}
void transferCompactStart(int core) {
isMsgSending = true;
DynamicHeader msgHdr = tmc_udn_header_from_cpu(core);
- __tmc_udn_send_header_with_size_and_tag(msgHdr, msgsize, UDN0_DEMUX_TAG); // send header
+ // send header
+ __tmc_udn_send_header_with_size_and_tag(msgHdr, msgsize,
+ UDN0_DEMUX_TAG);
#ifdef DEBUG
BAMBOO_DEBUGPRINT(0xbbbb);
BAMBOO_DEBUGPRINT(0xb000 + core); // targetcore
send_msg_1(i, GCFINISH);
}
- // need to create free memory list and invalidate all shared mem pointers TODO
+ // need to create free memory list and invalidate all
+ // shared mem pointers TODO
gcflag = false;
gcprocessing = false;
}
// enqueue objectsets
for(i=0; i<NUMCLASSES; i++) {
- struct parameterwrapper ** queues=objectqueues[BAMBOO_NUM_OF_CORE][i];
+ struct parameterwrapper ** queues =
+ objectqueues[BAMBOO_NUM_OF_CORE][i];
int length = numqueues[BAMBOO_NUM_OF_CORE][i];
for(j = 0; j < length; ++j) {
struct parameterwrapper * parameter = queues[j];
// enqueue cached transferred obj
struct QueueItem * tmpobjptr = getHead(&objqueue);
while(tmpobjptr != NULL) {
- struct transObjInfo * objInfo = (struct transObjInfo *)(tmpobjptr->objectptr);
+ struct transObjInfo * objInfo =
+ (struct transObjInfo *)(tmpobjptr->objectptr);
gc_enqueue(objInfo->objptr);
getNextQueueItem(tmpobjptr);
}
}
-void mark(bool isfirst, struct garbagelist * stackptr) {
+void mark(bool isfirst,
+ struct garbagelist * stackptr) {
if(isfirst) {
// enqueue root objs
tomark(stackptr);
if(isLarge(ptr, &type, &size)) {
// ptr is a large object
struct largeObjItem * loi =
- (struct largeObjItem *)RUNMALLOC(sizeof(struct largeObjItem));
+ (struct largeObjItem*)RUNMALLOC(sizeof(struct largeObjItem));
loi->orig = (INTPTR)ptr;
loi->dst = (INTPTR)0;
loi->length = size;
curr_heaptop += isize;
if(curr_heaptop > curr_heapbound) {
// change to another block
- curr_heaptop = curr_heapbound + BAMBOO_CACHE_LINE_SIZE + isize;
+ curr_heaptop = curr_heapbound+BAMBOO_CACHE_LINE_SIZE+isize;
curr_heapbound += BAMBOO_SMEM_SIZE;
}
// mark this obj
int length=ao->___length___;
int j;
for(j=0; j<length; j++) {
- void *objptr=((void **)(((char *)&ao->___length___)+sizeof(int)))[j];
+ void *objptr =
+ ((void **)(((char *)&ao->___length___)+sizeof(int)))[j];
int host = hostcore(objptr);
if(BAMBOO_NUM_OF_CORE == host) {
// on this core
struct moveHelper {
int numblocks; // block num for heap
- INTPTR base; // real base virtual address of current heap block
- INTPTR ptr; // real virtual address of current heap top
+ INTPTR base; // base virtual address of current heap block
+ INTPTR ptr; // virtual address of current heap top
int offset; // offset in current heap block
- int blockbase; // real virtual address of current small block to check with
- int blockbound; // real bound virtual address of current small blcok to check
+ int blockbase; // virtual address of current small block to check
+ int blockbound; // bound virtual address of current small blcok
int top; // real size of current heap block to check
- int bound; // real bound virtual address of current heap block to check
+ int bound; // bound size of current heap block to check
};
void nextSBlock(struct moveHelper * orig) {
}
// endaddr does not contain spaces for headers
-bool moveobj(struct moveHelper * orig, struct moveHelper * to, INTPTR * endaddr) {
+bool moveobj(struct moveHelper * orig,
+ struct moveHelper * to,
+ INTPTR * endaddr) {
int type = 0;
int size = 0;
int mark = 0;
nextBlock(to);
}
memcpy(to->ptr, orig->ptr, size);
- RuntimeHashadd(pointertbl, orig->ptr, to->ptr); // store the mapping info
+ // store mapping info
+ RuntimeHashadd(pointertbl, orig->ptr, to->ptr);
to->ptr += isize;
to->offset += isize;
to->top += isize;
while(!gctomove) {}
// start moving objects to other cores
gctomove = false;
- struct moveHelper * into = (struct moveHelper *)RUNMALLOC(sizeof(struct moveHelper));
+ struct moveHelper * into =
+ (struct moveHelper *)RUNMALLOC(sizeof(struct moveHelper));
for(int j = 0; j < cinstruction->movenum; j++) {
if(cinstruction->moveflag[j] == 1) {
// can start moving to corresponding core
num_dsts--;
into->ptr = cinstruction->startaddrs[j];
BLOCKINDEX(into->ptr, &(into->numblocks));
- into->bound =
- (into->numblocks==0)?BAMBOO_SMEM_SIZE_L:BAMBOO_SMEM_SIZE_L+BAMBOO_SMEM_SIZE*into->numblocks;
+ into->bound = (into->numblocks==0)?
+ BAMBOO_SMEM_SIZE_L:
+ BAMBOO_SMEM_SIZE_L+BAMBOO_SMEM_SIZE*into->numblocks;
BASEPTR(BAMBOO_NUM_OF_CORE, into->numblocks, &(into->base));
into->offset = into->ptr - into->base;
- into->top = (into->numblocks==0)?(into->offset):(into->bound-BAMBOO_SMEM_SIZE+into->offset);
+ into->top = (into->numblocks==0)?
+ (into->offset):(into->bound-BAMBOO_SMEM_SIZE+into->offset);
into->base = into->ptr;
into->offset = BAMBOO_CACHE_LINE_SIZE;
into->ptr += into->offset; // for header
break;
}
} while(orig->ptr < markedptrbound + 1);
- cinstruction->moveflag[j] = 2; // set the flag indicating move finished
+ // set the flag indicating move finished
+ cinstruction->moveflag[j] = 2;
// fill the header of this blockk
(*((int*)(into->base))) = into->offset;
} // if(cinstruction->moveflag[j] == 1)
INTPTR heaptopptr = 0;
// initialize pointers for comapcting
- struct moveHelper * orig = (struct moveHelper *)RUNMALLOC(sizeof(struct moveHelper));
- struct moveHelper * to = (struct moveHelper *)RUNMALLOC(sizeof(struct moveHelper));
+ struct moveHelper * orig =
+ (struct moveHelper *)RUNMALLOC(sizeof(struct moveHelper));
+ struct moveHelper * to =
+ (struct moveHelper *)RUNMALLOC(sizeof(struct moveHelper));
to->numblocks = 0;
to->top = to->offset = BAMBOO_CACHE_LINE_SIZE;
to->bound = BAMBOO_SMEM_SIZE_L;
// scan over all objs in this block, compact those scheduled to
// reside on this core
- // loop stop when finishing either scanning all active objs or moving
+ // loop stop when finishing either scanning all active objs or moving
// all objs to reside on this core
int endaddr = cinstruction->loads;
do {
}
heaptopptr = to->ptr;
} else {
- // have incoming objs, send messages to corresponding cores to start moving
+ // have incoming objs, send messages to corresponding cores
+ // to start moving
INTPTR startaddr = 0;
INTPTR endaddr = 0;
int heapptr = curr_heapptr;
int bound = curr_heapbound;
for(int j = 0; j < cinstruction->movenum; j++) {
startaddr = heapptr;
- top = top + cinstruction->size2move[j] + BAMBOO_CACHE_LINE_SIZE;
+ top = top+cinstruction->size2move[j]+BAMBOO_CACHE_LINE_SIZE;
if(top > bound) {
// will cross block boundary
int numb = (top - bound) / BAMBOO_SMEM_SIZE + 1;
top += numb * BAMBOO_CACHE_LINE_SIZE;
BASEPTR(BAMBOO_NUM_OF_CORE, numblocks + numb, &endaddr);
- endaddr += (top - bound) % BAMBOO_SMEM_SIZE + BAMBOO_CACHE_LINE_SIZE;
+ endaddr +=
+ (top-bound)%BAMBOO_SMEM_SIZE+BAMBOO_CACHE_LINE_SIZE;
heapptr = endaddr;
bound += BAMBOO_SMEM_SIZE * numb;
} else {
- endaddr = heapptr + cinstruction->size2move[j] + BAMBOO_CACHE_LINE_SIZE;
+ endaddr =
+ heapptr+cinstruction->size2move[j]+BAMBOO_CACHE_LINE_SIZE;
heapptr = endaddr;
}
send_msg_4(cinstruction->dsts[j], GCMOVESTART,
- BAMBOO_NUM_OF_CORE, startaddr, cinstruction->size2move[j]);
+ BAMBOO_NUM_OF_CORE, startaddr,
+ cinstruction->size2move[j]);
}
heaptopptr = heapptr;
} // if(cinstruction->ismove)
}while(cinstruction->largeobjs != NULL);
}*/
// send compact finish message to core coordinator
- send_msg_3(STARTUPCORE, GCFINISHCOMPACT, BAMBOO_NUM_OF_CORE, to->ptr);
+ send_msg_3(STARTUPCORE, GCFINISHCOMPACT,
+ BAMBOO_NUM_OF_CORE, to->ptr);
RUNFREE(orig);
RUNFREE(to);
int length=ao->___length___;
int j;
for(j=0; j<length; j++) {
- void *objptr=((void **)(((char *)&ao->___length___)+sizeof(int)))[j];
+ void *objptr=
+ ((void **)(((char *)&ao->___length___)+sizeof(int)))[j];
// change to new address
void *dstptr = NULL;
RuntimeHashget(pointertbl, objptr, &dstptr);
while(!ismapped) {}
RuntimeHashget(pointertbl, objptr, &dstptr);
}
- ((void **)(((char *)&ao->___length___)+sizeof(int)))[j] = dstptr;
+ ((void **)(((char *)&ao->___length___)+sizeof(int)))[j]=dstptr;
}
} else {
INTPTR size=pointer[0];
* 1f -- large objs info response
*
* ObjMsg: 0 + size of msg + obj's address + (task index + param index)+
- * StallMsg: 1 + corenum + sendobjs + receiveobjs (size is always 4 * sizeof(int))
- * LockMsg: 2 + lock type + obj pointer + lock + request core (size is always 5 * sizeof(int))
- * 3/4/5 + lock type + obj pointer + lock (size is always 4 * sizeof(int))
- * 8 + lock type + obj pointer + redirect lock + root request core + request core (size is always 6 * sizeof(int))
- * 9/a + lock type + obj pointer + redirect lock (size is always 4 * sizeof(int))
- * b + lock type + lock + redirect lock (size is always 4 * sizeof(int))
+ * StallMsg: 1 + corenum + sendobjs + receiveobjs
+ * (size is always 4 * sizeof(int))
+ * LockMsg: 2 + lock type + obj pointer + lock + request core
+ * (size is always 5 * sizeof(int))
+ * 3/4/5 + lock type + obj pointer + lock
+ * (size is always 4 * sizeof(int))
+ * 8 + lock type + obj pointer + redirect lock + root request core
+ * + request core
+ * (size is always 6 * sizeof(int))
+ * 9/a + lock type + obj pointer + redirect lock
+ * (size is always 4 * sizeof(int))
+ * b + lock type + lock + redirect lock
+ * (size is always 4 * sizeof(int))
* lock type: 0 -- read; 1 -- write
- * ProfileMsg: 6 + totalexetime (size is always 2 * sizeof(int))
- * 7 + corenum (size is always 2 * sizeof(int))
+ * ProfileMsg: 6 + totalexetime
+ * (size is always 2 * sizeof(int))
+ * 7 + corenum
+ * (size is always 2 * sizeof(int))
* StatusMsg: c (size is always 1 * sizeof(int))
- * d + status + corenum + sendobjs + receiveobjs (size is always 5 * sizeof(int))
+ * d + status + corenum + sendobjs + receiveobjs
+ * (size is always 5 * sizeof(int))
* status: 0 -- stall; 1 -- busy
* TerminateMsg: e (size is always 1 * sizeof(int)
- * MemoryMsg: f + size + corenum (size is always 3 * sizeof(int))
- * 10 + base_va + size (size is always 3 * sizeof(int))
+ * MemoryMsg: f + size + corenum
+ * (size is always 3 * sizeof(int))
+ * 10 + base_va + size
+ * (size is always 3 * sizeof(int))
* GCMsg: 11 (size is always 1 * sizeof(int))
- * 12 + size of msg + (num of objs to move + (start address + end address + dst core + start dst)+)? + (num of incoming objs + (start dst + orig core)+)? + (num of large obj lists + (start address + lenght + start dst)+)?
+ * 12 + size of msg + (num of objs to move + (start address
+ * + end address + dst core + start dst)+)?
+ * + (num of incoming objs + (start dst + orig core)+)?
+ * + (num of large obj lists + (start address + lenght
+ * + start dst)+)?
* 13 (size is always 1 * sizeof(int))
- * 14 + corenum + gcsendobjs + gcreceiveobjs (size if always 4 * sizeof(int))
- * 15/16 + corenum (size is always 2 * sizeof(int))
+ * 14 + corenum + gcsendobjs + gcreceiveobjs
+ * (size if always 4 * sizeof(int))
+ * 15/16 + corenum
+ * (size is always 2 * sizeof(int))
* 17 (size is always 1 * sizeof(int))
* 18 (size if always 1 * sizeof(int))
- * 19 + size of msg + corenum + gcsendobjs + gcreceiveobjs (size is always 5 * sizeof(int))
- * 1a + obj's address (size is always 2 * sizeof(int))
- * 1b + corenum ( size is always 2 * sizeof(int))
- * 1c + obj's address + corenum (size is always 3 * sizeof(int))
- * 1d + obj's address + dst address (size if always 3 * sizeof(int))
+ * 19 + size of msg + corenum + gcsendobjs + gcreceiveobjs
+ * (size is always 5 * sizeof(int))
+ * 1a + obj's address
+ * (size is always 2 * sizeof(int))
+ * 1b + corenum
+ * ( size is always 2 * sizeof(int))
+ * 1c + obj's address + corenum
+ * (size is always 3 * sizeof(int))
+ * 1d + obj's address + dst address
+ * (size if always 3 * sizeof(int))
* 1e (size is always 1 * sizeof(int))
- * 1f + size of msg + corenum + current heap size + (num of large obj lists + (start address + length)+)?
+ * 1f + size of msg + corenum + current heap size
+ * + (num of large obj lists + (start address + length)+)?
*/
enum MSGTYPE {
TRANSOBJ = 0x0, // 0x0
int redirectlock;
int value;
};
+struct RuntimeHash * lockRedirectTbl;
struct RuntimeHash * objRedirectLockTbl;
int lockobj;
int lock2require;
// data structures for shared memory allocation
#ifdef MULTICORE_GC
#include "multicoregarbage.h"
+
+struct freeMemItem {
+ INTPTR ptr;
+ int size;
+ struct freeMemItem * next;
+};
+
+struct freeMemList {
+ struct freeMemItem * head;
+ struct freeMemItem * tail;
+};
+
+bool smemflag;
+struct freeMemList * bamboo_free_mem_list;
+INTPTR bamboo_cur_msp;
+int bamboo_smem_size;
#else
#define BAMBOO_NUM_PAGES 1024 * 512
#define BAMBOO_PAGE_SIZE 4096
// if return -1: the lock request is redirected
// 0: the lock request is approved
// 1: the lock request is denied
-inline int processlockrequest(int locktype, int lock, int obj, int requestcore, int rootrequestcore, bool cache) __attribute_((always_inline));
-inline void processlockrelease(int locktype, int lock, int redirectlock, bool isredirect) __attribute_((always_inline));
+inline int processlockrequest(int locktype,
+ int lock,
+ int obj,
+ int requestcore,
+ int rootrequestcore,
+ bool cache) __attribute_((always_inline));
+inline void processlockrelease(int locktype,
+ int lock,
+ int redirectlock,
+ bool isredirect) __attribute_((always_inline));
// msg related functions
inline void send_hanging_msg() __attribute__((always_inline));
-inline void send_msg_1(int targetcore, unsigned long n0) __attribute__((always_inline));
-inline void send_msg_2(int targetcore, unsigned long n0, unsigned long n1) __attribute__((always_inline));
-inline void send_msg_3(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2) __attribute__((always_inline));
-inline void send_msg_4(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2, unsigned long n3) __attribute__((always_inline));
-inline void send_msg_5(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2, unsigned long n3, unsigned long n4) __attribute__((always_inline));
-inline void send_msg_6(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2, unsigned long n3, unsigned long n4, unsigned long n5) __attribute__((always_inline));
-inline void cache_msg_2(int targetcore, unsigned long n0, unsigned long n1) __attribute__((always_inline));
-inline void cache_msg_3(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2) __attribute__((always_inline));
-inline void cache_msg_4(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2, unsigned long n3) __attribute__((always_inline));
-inline void cache_msg_5(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2, unsigned long n3, unsigned long n4) __attribute__((always_inline));
-inline void cache_msg_6(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2, unsigned long n3, unsigned long n4, unsigned long n5) __attribute__((always_inline));
+inline void send_msg_1(int targetcore,
+ unsigned long n0) __attribute__((always_inline));
+inline void send_msg_2(int targetcore,
+ unsigned long n0,
+ unsigned long n1) __attribute__((always_inline));
+inline void send_msg_3(int targetcore,
+ unsigned long n0,
+ unsigned long n1,
+ unsigned long n2) __attribute__((always_inline));
+inline void send_msg_4(int targetcore,
+ unsigned long n0,
+ unsigned long n1,
+ unsigned long n2,
+ unsigned long n3) __attribute__((always_inline));
+inline void send_msg_5(int targetcore,
+ unsigned long n0,
+ unsigned long n1,
+ unsigned long n2,
+ unsigned long n3,
+ unsigned long n4) __attribute__((always_inline));
+inline void send_msg_6(int targetcore,
+ unsigned long n0,
+ unsigned long n1,
+ unsigned long n2,
+ unsigned long n3,
+ unsigned long n4,
+ unsigned long n5) __attribute__((always_inline));
+inline void cache_msg_2(int targetcore,
+ unsigned long n0,
+ unsigned long n1) __attribute__((always_inline));
+inline void cache_msg_3(int targetcore,
+ unsigned long n0,
+ unsigned long n1,
+ unsigned long n2) __attribute__((always_inline));
+inline void cache_msg_4(int targetcore,
+ unsigned long n0,
+ unsigned long n1,
+ unsigned long n2,
+ unsigned long n3) __attribute__((always_inline));
+inline void cache_msg_5(int targetcore,
+ unsigned long n0,
+ unsigned long n1,
+ unsigned long n2,
+ unsigned long n3,
+ unsigned long n4) __attribute__((always_inline));
+inline void cache_msg_6(int targetcore,
+ unsigned long n0,
+ unsigned long n1,
+ unsigned long n2,
+ unsigned long n3,
+ unsigned long n4,
+ unsigned long n5) __attribute__((always_inline));
inline void transferObject(struct transObjInfo * transObj);
inline int receiveMsg(void) __attribute__((always_inline));
#endif // #ifdef PROFILE
///////////////////////////////////////////////////////////
-//////////////////////////////////////////////////////////////////////////////////////
-// For each version of BAMBOO runtime, there should be a header file named //
-// runtim_arch.h defining following MARCOS: //
-// BAMBOO_TOTALCORE: the total # of cores available in the processor //
-// BAMBOO_NUM_OF_CORE: the # of current residing core //
-// BAMBOO_GET_NUM_OF_CORE(): compute the # of current residing core //
-// BAMBOO_DEBUGPRINT(x): print out integer x //
-// BAMBOO_DEBUGPRINT_REG(x): print out value of variable x //
-// BAMBOO_LOCAL_MEM_CALLOC(x, y): allocate an array of x elements each of whose //
-// size in bytes is y on local memory //
-// BAMBOO_LOCAL_MEM_FREE(x): free space with ptr x on local memory //
-// BAMBOO_SHARE_MEM_CALLOC(x, y): allocate an array of x elements each of whose //
-// size in bytes is y on shared memory //
-// BAMBOO_START_CRITICAL_SECTION_OBJ_QUEUE() //
-// BAMBOO_CLOSE_CRITICAL_SECTION_OBJ_QUEUE(): locks for global data structures //
-// related to obj queue //
-// BAMBOO_START_CRITICAL_SECTION_STATUS() //
-// BAMBOO_CLOSE_CRITICAL_SECTION_STATUS(): locks for global data structures //
-// related to status data //
-// BAMBOO_START_CRITICAL_SECTION_MSG() //
-// BAMBOO_CLOSE_CRITICAL_SECTION_MSG(): locks for global data structures related //
-// to msg data //
-// BAMBOO_START_CRITICAL_SECTION_LOCK() //
-// BAMBOO_CLOSE_CRITICAL_SECTION_LOCK(): locks for global data structures related //
-// to lock table //
-// BAMBOO_START_CRITICAL_SECTION_MEM() //
-// BAMBOO_CLOSE_CRITICAL_SECTION_MEM(): locks for allocating memory //
-// BAMBOO_START_CRITICAL_SECTION() //
-// BAMBOO_CLOSE_CRITICAL_SECTION(): locks for all global data structures //
-// BAMBOO_WAITING_FOR_LOCK(): routine executed while waiting for lock request //
-// response //
-// BAMBOO_CACHE_LINE_SIZE: the cache line size //
-// BAMBOO_CACHE_LINE_MASK: mask for a cache line //
-// BAMBOO_CACHE_FLUSH_RANGE(x, y): flush cache lines started at x with length y //
-// BAMBOO_CACHE_FLUSH_ALL(): flush the whole cache of a core if necessary //
-// BAMBOO_EXIT(x): exit routine //
-// BAMBOO_MSG_AVAIL(): checking if there are msgs coming in //
-// BAMBOO_GCMSG_AVAIL(): checking if there are gcmsgs coming in //
-// BAMBOO_GET_EXE_TIME(): rountine to get current clock cycle number //
-/////////////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+// For each version of BAMBOO runtime, there should be a header file named //
+// runtim_arch.h defining following MARCOS: //
+// BAMBOO_TOTALCORE: the total # of cores available in the processor //
+// BAMBOO_NUM_OF_CORE: the # of current residing core //
+// BAMBOO_GET_NUM_OF_CORE(): compute the # of current residing core //
+// BAMBOO_DEBUGPRINT(x): print out integer x //
+// BAMBOO_DEBUGPRINT_REG(x): print out value of variable x //
+// BAMBOO_LOCAL_MEM_CALLOC(x, y): allocate an array of x elements each of //
+// whose size in bytes is y on local memory //
+// BAMBOO_LOCAL_MEM_FREE(x): free space with ptr x on local memory //
+// BAMBOO_SHARE_MEM_CALLOC(x, y): allocate an array of x elements each of //
+// whose size in bytes is y on shared memory//
+// BAMBOO_START_CRITICAL_SECTION_OBJ_QUEUE() //
+// BAMBOO_CLOSE_CRITICAL_SECTION_OBJ_QUEUE(): locks for global data //
+// structures related to obj //
+// queue //
+// BAMBOO_START_CRITICAL_SECTION_STATUS() //
+// BAMBOO_CLOSE_CRITICAL_SECTION_STATUS(): locks for global data structures//
+// related to status data //
+// BAMBOO_START_CRITICAL_SECTION_MSG() //
+// BAMBOO_CLOSE_CRITICAL_SECTION_MSG(): locks for global data structures //
+// related to msg data //
+// BAMBOO_START_CRITICAL_SECTION_LOCK() //
+// BAMBOO_CLOSE_CRITICAL_SECTION_LOCK(): locks for global data structures //
+// related to lock table //
+// BAMBOO_START_CRITICAL_SECTION_MEM() //
+// BAMBOO_CLOSE_CRITICAL_SECTION_MEM(): locks for allocating memory //
+// BAMBOO_START_CRITICAL_SECTION() //
+// BAMBOO_CLOSE_CRITICAL_SECTION(): locks for all global data structures //
+// BAMBOO_WAITING_FOR_LOCK(): routine executed while waiting for lock //
+// request response //
+// BAMBOO_CACHE_LINE_SIZE: the cache line size //
+// BAMBOO_CACHE_LINE_MASK: mask for a cache line //
+// BAMBOO_CACHE_FLUSH_RANGE(x, y): flush cache lines started at x with //
+// length y //
+// BAMBOO_CACHE_FLUSH_ALL(): flush the whole cache of a core if necessary //
+// BAMBOO_EXIT(x): exit routine //
+// BAMBOO_MSG_AVAIL(): checking if there are msgs coming in //
+// BAMBOO_GCMSG_AVAIL(): checking if there are gcmsgs coming in //
+// BAMBOO_GET_EXE_TIME(): rountine to get current clock cycle number //
+/////////////////////////////////////////////////////////////////////////////
#endif // #ifdef MULTICORE
#endif // #ifdef TASK
struct taskparamdescriptor * currtpd;
// specific functions used inside critical sections
-void enqueueObject_I(void * ptr, struct parameterwrapper ** queues, int length);
-int enqueuetasks_I(struct parameterwrapper *parameter, struct parameterwrapper *prevptr, struct ___Object___ *ptr, int * enterflags, int numenterflags);
+void enqueueObject_I(void * ptr,
+ struct parameterwrapper ** queues,
+ int length);
+int enqueuetasks_I(struct parameterwrapper *parameter,
+ struct parameterwrapper *prevptr,
+ struct ___Object___ *ptr,
+ int * enterflags,
+ int numenterflags);
inline void initruntimedata() {
// initialize the arrays
// startup core to initialize corestatus[]
for(i = 0; i < NUMCORES; ++i) {
corestatus[i] = 1;
- numsendobjs[i] = 0; // assume all variables are local variables! MAY BE WRONG!!!
+ numsendobjs[i] = 0;
numreceiveobjs[i] = 0;
#ifdef PROFILE
// initialize the profile data arrays
#else
// create the lock table, lockresult table and obj queue
locktable.size = 20;
- locktable.bucket = (struct RuntimeNode **) RUNMALLOC_I(sizeof(struct RuntimeNode *)*20);
+ locktable.bucket =
+ (struct RuntimeNode **) RUNMALLOC_I(sizeof(struct RuntimeNode *)*20);
/* Set allocation blocks*/
locktable.listhead=NULL;
locktable.listtail=NULL;
// flush the object
#ifdef CACHEFLUSH
BAMBOO_CACHE_FLUSH_RANGE((int)obj,sizeof(int));
- BAMBOO_CACHE_FLUSH_RANGE((int)obj, classsize[((struct ___Object___ *)obj)->type]);
+ BAMBOO_CACHE_FLUSH_RANGE((int)obj,
+ classsize[((struct ___Object___ *)obj)->type]);
#endif
// enqueue the object
for(k = 0; k < objInfo->length; ++k) {
int taskindex = objInfo->queues[2 * k];
int paramindex = objInfo->queues[2 * k + 1];
- struct parameterwrapper ** queues = &(paramqueues[BAMBOO_NUM_OF_CORE][taskindex][paramindex]);
+ struct parameterwrapper ** queues =
+ &(paramqueues[BAMBOO_NUM_OF_CORE][taskindex][paramindex]);
#ifdef DEBUG
BAMBOO_DEBUGPRINT_REG(taskindex);
BAMBOO_DEBUGPRINT_REG(paramindex);
struct ___Object___ * tmpptr = (struct ___Object___ *)obj;
- tprintf("Process %x(%d): receive obj %x(%lld), ptrflag %x\n", BAMBOO_NUM_OF_CORE, BAMBOO_NUM_OF_CORE, (int)obj, (long)obj, tmpptr->flag);
+ tprintf("Process %x(%d): receive obj %x(%lld), ptrflag %x\n",
+ BAMBOO_NUM_OF_CORE, BAMBOO_NUM_OF_CORE, (int)obj,
+ (long)obj, tmpptr->flag);
#endif
enqueueObject_I(obj, queues, 1);
#ifdef DEBUG
struct QueueItem * qitem = getHead(&objqueue);
struct QueueItem * prev = NULL;
while(qitem != NULL) {
- struct transObjInfo * tmpinfo = (struct transObjInfo *)(qitem->objectptr);
+ struct transObjInfo * tmpinfo =
+ (struct transObjInfo *)(qitem->objectptr);
if(tmpinfo->objptr == obj) {
// the same object in the queue, which should be enqueued
// recently. Current one is outdate, do not re-enqueue it
fakeExecution();
} else {
/* Create queue of active tasks */
- activetasks=genallocatehashtable((unsigned int(*) (void *)) &hashCodetpd,
- (int(*) (void *,void *)) &comparetpd);
+ activetasks=
+ genallocatehashtable((unsigned int(*) (void *)) &hashCodetpd,
+ (int(*) (void *,void *)) &comparetpd);
/* Process task information */
processtasks();
BAMBOO_DEBUGPRINT(0xee01);
#endif
- // check if there are some pending objects, if yes, enqueue them and executetasks again
+ // check if there are some pending objects,
+ // if yes, enqueue them and executetasks again
tocontinue = checkObjQueue();
if(!tocontinue) {
BAMBOO_DEBUGPRINT(0xee0b);
#endif
// send stall msg
- send_msg_4(STARTUPCORE, 1, BAMBOO_NUM_OF_CORE, self_numsendobjs, self_numreceiveobjs);
+ send_msg_4(STARTUPCORE, 1, BAMBOO_NUM_OF_CORE,
+ self_numsendobjs, self_numreceiveobjs);
sendStall = true;
isfirst = true;
busystatus = false;
} // run()
-void createstartupobject(int argc, char ** argv) {
+void createstartupobject(int argc,
+ char ** argv) {
int i;
/* Allocate startup object */
#ifdef MULTICORE_GC
- struct ___StartupObject___ *startupobject=(struct ___StartupObject___*) allocate_new(NULL, STARTUPTYPE);
- struct ArrayObject * stringarray=allocate_newarray(NULL, STRINGARRAYTYPE, argc-1);
+ struct ___StartupObject___ *startupobject=
+ (struct ___StartupObject___*) allocate_new(NULL, STARTUPTYPE);
+ struct ArrayObject * stringarray=
+ allocate_newarray(NULL, STRINGARRAYTYPE, argc-1);
#else
- struct ___StartupObject___ *startupobject=(struct ___StartupObject___*) allocate_new(STARTUPTYPE);
- struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-1);
+ struct ___StartupObject___ *startupobject=
+ (struct ___StartupObject___*) allocate_new(STARTUPTYPE);
+ struct ArrayObject * stringarray=
+ allocate_newarray(STRINGARRAYTYPE, argc-1);
#endif
/* Build array of strings */
startupobject->___parameters___=stringarray;
#else
struct ___String___ *newstring=NewString(argv[i],length);
#endif
- ((void **)(((char *)&stringarray->___length___)+sizeof(int)))[i-1]=newstring;
+ ((void **)(((char *)&stringarray->___length___)+sizeof(int)))[i-1]=
+ newstring;
}
startupobject->version = 0;
return hash;
}
-int comparetpd(struct taskparamdescriptor *ftd1, struct taskparamdescriptor *ftd2) {
+int comparetpd(struct taskparamdescriptor *ftd1,
+ struct taskparamdescriptor *ftd2) {
int i;
if (ftd1->task!=ftd2->task)
return 0;
/* This function sets a tag. */
#ifdef MULTICORE_GC
-void tagset(void *ptr, struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) {
+void tagset(void *ptr,
+ struct ___Object___ * obj,
+ struct ___TagDescriptor___ * tagd) {
#else
-void tagset(struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) {
+void tagset(struct ___Object___ * obj,
+ struct ___TagDescriptor___ * tagd) {
#endif
struct ArrayObject * ao=NULL;
struct ___Object___ * tagptr=obj->___tags___;
}
#ifdef MULTICORE_GC
int ptrarray[]={2, (int) ptr, (int) obj, (int)tagd};
- struct ArrayObject * ao=allocate_newarray(&ptrarray,TAGARRAYTYPE,TAGARRAYINTERVAL);
+ struct ArrayObject * ao=
+ allocate_newarray(&ptrarray,TAGARRAYTYPE,TAGARRAYINTERVAL);
obj=(struct ___Object___ *)ptrarray[2];
tagd=(struct ___TagDescriptor___ *)ptrarray[3];
td=(struct ___TagDescriptor___ *) obj->___tags___;
int i;
struct ArrayObject *ao=(struct ArrayObject *) tagptr;
for(i=0; i<ao->___cachedCode___; i++) {
- struct ___TagDescriptor___ * td=ARRAYGET(ao, struct ___TagDescriptor___*, i);
+ struct ___TagDescriptor___ * td=
+ ARRAYGET(ao, struct ___TagDescriptor___*, i);
if (td==tagd) {
return;
}
} else {
#ifdef MULTICORE_GC
int ptrarray[]={2,(int) ptr, (int) obj, (int) tagd};
- struct ArrayObject * aonew=allocate_newarray(&ptrarray,TAGARRAYTYPE,TAGARRAYINTERVAL+ao->___length___);
+ struct ArrayObject * aonew=
+ allocate_newarray(&ptrarray,TAGARRAYTYPE,
+ TAGARRAYINTERVAL+ao->___length___);
obj=(struct ___Object___ *)ptrarray[2];
tagd=(struct ___TagDescriptor___ *) ptrarray[3];
ao=(struct ArrayObject *)obj->___tags___;
#else
- struct ArrayObject * aonew=allocate_newarray(TAGARRAYTYPE,TAGARRAYINTERVAL+ao->___length___);
+ struct ArrayObject * aonew=
+ allocate_newarray(TAGARRAYTYPE,TAGARRAYINTERVAL+ao->___length___);
#endif
aonew->___cachedCode___=ao->___length___+1;
for(i=0; i<ao->___length___; i++) {
- ARRAYSET(aonew, struct ___TagDescriptor___*, i, ARRAYGET(ao, struct ___TagDescriptor___*, i));
+ ARRAYSET(aonew, struct ___TagDescriptor___*, i,
+ ARRAYGET(ao, struct ___TagDescriptor___*, i));
}
ARRAYSET(aonew, struct ___TagDescriptor___ *, ao->___length___, tagd);
}
} else if (tagset->type!=OBJECTARRAYTYPE) {
#ifdef MULTICORE_GC
int ptrarray[]={2, (int) ptr, (int) obj, (int)tagd};
- struct ArrayObject * ao=allocate_newarray(&ptrarray,OBJECTARRAYTYPE,OBJECTARRAYINTERVAL);
+ struct ArrayObject * ao=
+ allocate_newarray(&ptrarray,OBJECTARRAYTYPE,OBJECTARRAYINTERVAL);
obj=(struct ___Object___ *)ptrarray[2];
tagd=(struct ___TagDescriptor___ *)ptrarray[3];
#else
- struct ArrayObject * ao=allocate_newarray(OBJECTARRAYTYPE,OBJECTARRAYINTERVAL);
+ struct ArrayObject * ao=
+ allocate_newarray(OBJECTARRAYTYPE,OBJECTARRAYINTERVAL);
#endif
ARRAYSET(ao, struct ___Object___ *, 0, tagd->flagptr);
ARRAYSET(ao, struct ___Object___ *, 1, obj);
int i;
#ifdef MULTICORE_GC
int ptrarray[]={2, (int) ptr, (int) obj, (int)tagd};
- struct ArrayObject * aonew=allocate_newarray(&ptrarray,OBJECTARRAYTYPE,OBJECTARRAYINTERVAL+ao->___length___);
+ struct ArrayObject * aonew=
+ allocate_newarray(&ptrarray,OBJECTARRAYTYPE,
+ OBJECTARRAYINTERVAL+ao->___length___);
obj=(struct ___Object___ *)ptrarray[2];
tagd=(struct ___TagDescriptor___ *)ptrarray[3];
ao=(struct ArrayObject *)tagd->flagptr;
#else
- struct ArrayObject * aonew=allocate_newarray(OBJECTARRAYTYPE,OBJECTARRAYINTERVAL);
+ struct ArrayObject * aonew=
+ allocate_newarray(OBJECTARRAYTYPE,OBJECTARRAYINTERVAL);
#endif
aonew->___cachedCode___=ao->___cachedCode___+1;
for(i=0; i<ao->___length___; i++) {
- ARRAYSET(aonew, struct ___Object___*, i, ARRAYGET(ao, struct ___Object___*, i));
+ ARRAYSET(aonew, struct ___Object___*, i,
+ ARRAYGET(ao, struct ___Object___*, i));
}
ARRAYSET(aonew, struct ___Object___ *, ao->___cachedCode___, obj);
tagd->flagptr=(struct ___Object___ *) aonew;
/* This function clears a tag. */
#ifdef MULTICORE_GC
-void tagclear(void *ptr, struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) {
+void tagclear(void *ptr,
+ struct ___Object___ * obj,
+ struct ___TagDescriptor___ * tagd) {
#else
-void tagclear(struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) {
+void tagclear(struct ___Object___ * obj,
+ struct ___TagDescriptor___ * tagd) {
#endif
/* We'll assume that tag is alway there.
Need to statically check for this of course. */
if (tagptr->type==TAGTYPE) {
if ((struct ___TagDescriptor___ *)tagptr==tagd)
obj->___tags___=NULL;
- else
-#ifndef MULTICORE
- printf("ERROR 1 in tagclear\n");
-#else
- ;
-#endif
} else {
struct ArrayObject *ao=(struct ArrayObject *) tagptr;
int i;
for(i=0; i<ao->___cachedCode___; i++) {
- struct ___TagDescriptor___ * td=ARRAYGET(ao, struct ___TagDescriptor___ *, i);
+ struct ___TagDescriptor___ * td=
+ ARRAYGET(ao, struct ___TagDescriptor___ *, i);
if (td==tagd) {
ao->___cachedCode___--;
if (i<ao->___cachedCode___)
- ARRAYSET(ao, struct ___TagDescriptor___ *, i, ARRAYGET(ao, struct ___TagDescriptor___ *, ao->___cachedCode___));
+ ARRAYSET(ao, struct ___TagDescriptor___ *, i,
+ ARRAYGET(ao, struct ___TagDescriptor___ *, ao->___cachedCode___));
ARRAYSET(ao, struct ___TagDescriptor___ *, ao->___cachedCode___, NULL);
if (ao->___cachedCode___==0)
obj->___tags___=NULL;
goto PROCESSCLEAR;
}
}
-#ifndef MULTICORE
- printf("ERROR 2 in tagclear\n");
-#endif
}
PROCESSCLEAR:
{
if (tagset->type!=OBJECTARRAYTYPE) {
if (tagset==obj)
tagd->flagptr=NULL;
- else
-#ifndef MULTICORE
- printf("ERROR 3 in tagclear\n");
-#else
- ;
-#endif
} else {
struct ArrayObject *ao=(struct ArrayObject *) tagset;
int i;
if (tobj==obj) {
ao->___cachedCode___--;
if (i<ao->___cachedCode___)
- ARRAYSET(ao, struct ___Object___ *, i, ARRAYGET(ao, struct ___Object___ *, ao->___cachedCode___));
+ ARRAYSET(ao, struct ___Object___ *, i,
+ ARRAYGET(ao, struct ___Object___ *, ao->___cachedCode___));
ARRAYSET(ao, struct ___Object___ *, ao->___cachedCode___, NULL);
if (ao->___cachedCode___==0)
tagd->flagptr=NULL;
goto ENDCLEAR;
}
}
-#ifndef MULTICORE
- printf("ERROR 4 in tagclear\n");
-#endif
}
}
ENDCLEAR:
/* This function allocates a new tag. */
#ifdef MULTICORE_GC
-struct ___TagDescriptor___ * allocate_tag(void *ptr, int index) {
- struct ___TagDescriptor___ * v=(struct ___TagDescriptor___ *) FREEMALLOC((struct garbagelist *) ptr, classsize[TAGTYPE]);
+struct ___TagDescriptor___ * allocate_tag(void *ptr,
+ int index) {
+ struct ___TagDescriptor___ * v=
+ (struct ___TagDescriptor___ *) FREEMALLOC((struct garbagelist *) ptr,
+ classsize[TAGTYPE]);
#else
struct ___TagDescriptor___ * allocate_tag(int index) {
struct ___TagDescriptor___ * v=FREEMALLOC(classsize[TAGTYPE]);
/* This function updates the flag for object ptr. It or's the flag
with the or mask and and's it with the andmask. */
-void flagbody(struct ___Object___ *ptr, int flag, struct parameterwrapper ** queues, int length, bool isnew);
+void flagbody(struct ___Object___ *ptr,
+ int flag,
+ struct parameterwrapper ** queues,
+ int length,
+ bool isnew);
int flagcomp(const int *val1, const int *val2) {
return (*val1)-(*val2);
}
-void flagorand(void * ptr, int ormask, int andmask, struct parameterwrapper ** queues, int length) {
+void flagorand(void * ptr,
+ int ormask,
+ int andmask,
+ struct parameterwrapper ** queues,
+ int length) {
{
int oldflag=((int *)ptr)[1];
int flag=ormask|oldflag;
}
}
-bool intflagorand(void * ptr, int ormask, int andmask) {
+bool intflagorand(void * ptr,
+ int ormask,
+ int andmask) {
{
int oldflag=((int *)ptr)[1];
int flag=ormask|oldflag;
}
}
-void flagorandinit(void * ptr, int ormask, int andmask) {
+void flagorandinit(void * ptr,
+ int ormask,
+ int andmask) {
int oldflag=((int *)ptr)[1];
int flag=ormask|oldflag;
flag&=andmask;
flagbody(ptr,flag,NULL,0,true);
}
-void flagbody(struct ___Object___ *ptr, int flag, struct parameterwrapper ** vqueues, int vlength, bool isnew) {
+void flagbody(struct ___Object___ *ptr,
+ int flag,
+ struct parameterwrapper ** vqueues,
+ int vlength,
+ bool isnew) {
struct parameterwrapper * flagptr = NULL;
int i = 0;
struct parameterwrapper ** queues = vqueues;
/*Remove object from all queues */
for(i = 0; i < length; ++i) {
flagptr = queues[i];
- ObjectHashget(flagptr->objectset, (int) ptr, (int *) &next, (int *) &enterflags, &UNUSED, &UNUSED2);
+ ObjectHashget(flagptr->objectset, (int) ptr, (int *) &next,
+ (int *) &enterflags, &UNUSED, &UNUSED2);
ObjectHashremove(flagptr->objectset, (int)ptr);
if (enterflags!=NULL)
RUNFREE(enterflags);
}
}
-void enqueueObject(void * vptr, struct parameterwrapper ** vqueues, int vlength) {
+void enqueueObject(void * vptr,
+ struct parameterwrapper ** vqueues,
+ int vlength) {
struct ___Object___ *ptr = (struct ___Object___ *)vptr;
{
/* Check tags */
if (parameter->numbertags>0) {
if (tagptr==NULL)
- goto nextloop; //that means the object has no tag but that param needs tag
+ goto nextloop; //that means the object has no tag
+ //but that param needs tag
else if(tagptr->type==TAGTYPE) { //one tag
- //struct ___TagDescriptor___ * tag=(struct ___TagDescriptor___*) tagptr;
+ //struct ___TagDescriptor___ * tag=
+ //(struct ___TagDescriptor___*) tagptr;
for(i=0; i<parameter->numbertags; i++) {
//slotid is parameter->tagarray[2*i];
int tagid=parameter->tagarray[2*i+1];
}
}
-void enqueueObject_I(void * vptr, struct parameterwrapper ** vqueues, int vlength) {
+void enqueueObject_I(void * vptr,
+ struct parameterwrapper ** vqueues,
+ int vlength) {
struct ___Object___ *ptr = (struct ___Object___ *)vptr;
{
/* Check tags */
if (parameter->numbertags>0) {
if (tagptr==NULL)
- goto nextloop; //that means the object has no tag but that param needs tag
+ goto nextloop; //that means the object has no tag
+ //but that param needs tag
else if(tagptr->type==TAGTYPE) { //one tag
//struct ___TagDescriptor___ * tag=(struct ___TagDescriptor___*) tagptr;
for(i=0; i<parameter->numbertags; i++) {
}
-int * getAliasLock(void ** ptrs, int length, struct RuntimeHash * tbl) {
+int * getAliasLock(void ** ptrs,
+ int length,
+ struct RuntimeHash * tbl) {
if(length == 0) {
return (int*)(RUNMALLOC(sizeof(int)));
} else {
}
}
-void addAliasLock(void * ptr, int lock) {
+void addAliasLock(void * ptr,
+ int lock) {
struct ___Object___ * obj = (struct ___Object___ *)ptr;
if(((int)ptr != lock) && (obj->lock != (int*)lock)) {
// originally no alias lock associated or have a different alias lock
}
#endif
+void * smemalloc(int size,
+ int * allocsize) {
+ // TODO can not handle large obj which is bigger than a block
+#ifdef MULTICORE_GC
+ // go through free mem list for suitable blocks
+ struct freeMemItem * freemem = bamboo_free_mem_list->head;
+ struct freeMemItem * prev = NULL;
+ do {
+smemsearch:
+ if(freemem->size > size) {
+ // found one
+ break;
+ }
+ prev = freemem;
+ freemem = freemem->next;
+ } while(freemem != NULL);
+ if(freemem != NULL) {
+ void * mem = (void *)(freemem->ptr);
+ int b = 0;
+ BLOCKINDEX(mem, &b);
+ // check the remaining space in this block
+ int remain = BAMBOO_SMEM_SIZE_L+b*BAMBOO_SMEM_SIZE-(mem-BAMBOO_BASE_VA);
+ // TODO how about large objs?
+ if(remain < size) {
+ // not enough space in this block
+ struct freeMemItem * tmp =
+ (struct freeMemItem*)RUNMALLOC(sizeof(struct freeMemItem));
+ tmp->ptr = mem;
+ tmp->size = remain;
+ tmp->next = freemem;
+ if(bamboo_free_mem_list->head == freemem) {
+ bamboo_free_mem_list->head = tmp;
+ } else {
+ prev->next = tmp;
+ }
+ freemem->ptr += size;
+ freemem->size -= size;
+ // continue checking
+ goto smemsearch;
+ } else {
+ *allocsize = size;
+ freemem->ptr += size;
+ freemem->size -= size;
+ }
+ } else {
+#else
+ void * mem = mspace_calloc(bamboo_free_msp, 1, size);
+ *allocsize = size;
+ if(mem == NULL) {
+#endif
+ // no enough shared global memory
+ *allocsize = 0;
+#ifdef MULTICORE_GC
+ gcflag = true;
+ return NULL;
+#else
+ BAMBOO_DEBUGPRINT(0xa016);
+ BAMBOO_EXIT(0xa016);
+#endif
+ }
+ return mem;
+}
+
// receive object transferred from other cores
// or the terminate message from other cores
// Should be invoked in critical sections!!
switch(type) {
case TRANSOBJ: {
// receive a object transfer msg
- struct transObjInfo * transObj = RUNMALLOC_I(sizeof(struct transObjInfo));
+ struct transObjInfo * transObj =
+ RUNMALLOC_I(sizeof(struct transObjInfo));
int k = 0;
#ifdef DEBUG
#ifndef TILERA
BAMBOO_EXIT(0xa005);
}
// store the object and its corresponding queue info, enqueue it later
- transObj->objptr = (void *)msgdata[2]; // data1 is now size of the msg
+ transObj->objptr = (void *)msgdata[2]; // data1 is now size of the msg
transObj->length = (msglength - 3) / 2;
transObj->queues = RUNMALLOC_I(sizeof(int)*(msglength - 3));
for(k = 0; k < transObj->length; ++k) {
int data2 = msgdata[2]; // obj pointer
int data3 = msgdata[3]; // lock
int data4 = msgdata[4]; // request core
- deny = processlockrequest(data1, data3, data2, data4, data4, true); // -1: redirected, 0: approved, 1: denied
+ // -1: redirected, 0: approved, 1: denied
+ deny = processlockrequest(data1, data3, data2, data4, data4, true);
if(deny == -1) {
// this lock request is redirected
break;
break;
}
#endif
- void * mem = mspace_calloc(bamboo_free_msp, 1, msgdata[1]);
- if(mem == NULL) {
- // no enough shared global memory
-#ifdef MULTICORE_GC
- gcflag = true;
+ int allocsize = 0;
+ void * mem = smemalloc(msgdata[1], &allocsize);
+ if(mem == NULL) {
break;
-#else
- BAMBOO_DEBUGPRINT(0xa016);
- BAMBOO_EXIT(0xa016);
-#endif
- }
- // send the start_va to request core
+ }
+ // send the start_va to request core
if(isMsgSending) {
- cache_msg_3(msgdata[2], MEMRESPONSE, mem, msgdata[1]);
+ cache_msg_3(msgdata[2], MEMRESPONSE, mem, allocsize);
} else {
- send_msg_3( msgdata[2], MEMRESPONSE, mem, msgdata[1]);
+ send_msg_3( msgdata[2], MEMRESPONSE, mem, allocsize);
}
}
break;
#endif
if(msgdata[2] == 0) {
bamboo_smem_size = 0;
- bamboo_cur_msp = NULL;
+ bamboo_cur_msp = 0;
} else {
// fill header to store the size of this mem block
(*((int*)msgdata[1])) = msgdata[2];
bamboo_smem_size = msgdata[2] - BAMBOO_CACHE_LINE_SIZE;
- bamboo_cur_msp = create_mspace_with_base((void*)(msgdata[1]+BAMBOO_CACHE_LINE_SIZE),
- msgdata[2] - BAMBOO_CACHE_LINE_SIZE,
- 0);
+#ifdef MULTICORE_GC
+ bamboo_cur_msp = msgdata[1] + BAMBOO_CACHE_LINE_SIZE;
+#else
+ bamboo_cur_msp =
+ create_mspace_with_base((void*)(msgdata[1]+BAMBOO_CACHE_LINE_SIZE),
+ msgdata[2]-BAMBOO_CACHE_LINE_SIZE,
+ 0);
}
smemflag = true;
break;
// send response msg
if(isMsgSending) {
cache_msg_5(STARTUPCORE, GCMARKREPORT, BAMBOO_NUM_OF_CORE,
- gcbusystatus, gcself_numsendobjs, gcself_numreceiveobjs);
+ gcbusystatus, gcself_numsendobjs,
+ gcself_numreceiveobjs);
} else {
send_msg_5(STARTUPCORE, GCMARKREPORT, BAMBOO_NUM_OF_CORE,
gcbusystatus, gcself_numsendobjs, gcself_numreceiveobjs);
case GCLOBJINFO: {
// received a large objs info response msg
- // TODO
gcwaitconfirm--;
+
+ if(BAMBOO_NUM_OF_CORE > NUMCORES - 1) {
+#ifndef TILERA
+ BAMBOO_DEBUGPRINT_REG(msgdata[2]);
+#endif
+ BAMBOO_EXIT(0xa005);
+ }
+ // store the mark result info
+ int cnum = msgdata[2];
+ gcloads[cnum] = msgdata[3];
+ // TODO large obj info here
break;
}
#endif
}
-ent enqueuetasks(struct parameterwrapper *parameter, struct parameterwrapper *prevptr, struct ___Object___ *ptr, int * enterflags, int numenterflags) {
+int enqueuetasks(struct parameterwrapper *parameter,
+ struct parameterwrapper *prevptr,
+ struct ___Object___ *ptr,
+ int * enterflags,
+ int numenterflags) {
void * taskpointerarray[MAXTASKPARAMS];
int j;
//int numparams=parameter->task->numParameters;
struct taskdescriptor * task=parameter->task;
//this add the object to parameterwrapper
- ObjectHashadd(parameter->objectset, (int) ptr, 0, (int) enterflags, numenterflags, enterflags==NULL);
+ ObjectHashadd(parameter->objectset, (int) ptr, 0, (int) enterflags,
+ numenterflags, enterflags==NULL);
/* Add enqueued object to parameter vector */
taskpointerarray[parameter->slot]=ptr;
/* Find initial state */
for(j=0; j<numiterators; j++) {
backtrackinit:
- if(toiHasNext(¶meter->iterators[j], taskpointerarray OPTARG(failed)))
+ if(toiHasNext(¶meter->iterators[j],taskpointerarray OPTARG(failed)))
toiNext(¶meter->iterators[j], taskpointerarray OPTARG(failed));
else if (j>0) {
/* Need to backtrack */
while(1) {
/* Enqueue current state */
//int launch = 0;
- struct taskparamdescriptor *tpd=RUNMALLOC(sizeof(struct taskparamdescriptor));
+ struct taskparamdescriptor *tpd=
+ RUNMALLOC(sizeof(struct taskparamdescriptor));
tpd->task=task;
tpd->numParameters=numiterators+1;
tpd->parameterArray=RUNMALLOC(sizeof(void *)*(numiterators+1));
for(j=0; j<=numiterators; j++) {
- tpd->parameterArray[j]=taskpointerarray[j]; //store the actual parameters
+ //store the actual parameters
+ tpd->parameterArray[j]=taskpointerarray[j];
}
/* Enqueue task */
- if ((/*!gencontains(failedtasks, tpd)&&*/ !gencontains(activetasks,tpd))) {
+ if ((/*!gencontains(failedtasks, tpd)&&*/
+ !gencontains(activetasks,tpd))) {
genputtable(activetasks, tpd, tpd);
} else {
RUNFREE(tpd->parameterArray);
for(j=numiterators-1; j<numiterators; j++) {
backtrackinc:
- if(toiHasNext(¶meter->iterators[j], taskpointerarray OPTARG(failed)))
+ if(toiHasNext(¶meter->iterators[j],taskpointerarray OPTARG(failed)))
toiNext(¶meter->iterators[j], taskpointerarray OPTARG(failed));
else if (j>0) {
/* Need to backtrack */
return retval;
}
-int enqueuetasks_I(struct parameterwrapper *parameter, struct parameterwrapper *prevptr, struct ___Object___ *ptr, int * enterflags, int numenterflags) {
+int enqueuetasks_I(struct parameterwrapper *parameter,
+ struct parameterwrapper *prevptr,
+ struct ___Object___ *ptr,
+ int * enterflags,
+ int numenterflags) {
void * taskpointerarray[MAXTASKPARAMS];
int j;
//int numparams=parameter->task->numParameters;
struct taskdescriptor * task=parameter->task;
//this add the object to parameterwrapper
- ObjectHashadd_I(parameter->objectset, (int) ptr, 0, (int) enterflags, numenterflags, enterflags==NULL);
+ ObjectHashadd_I(parameter->objectset, (int) ptr, 0, (int) enterflags,
+ numenterflags, enterflags==NULL);
/* Add enqueued object to parameter vector */
taskpointerarray[parameter->slot]=ptr;
/* Find initial state */
for(j=0; j<numiterators; j++) {
backtrackinit:
- if(toiHasNext(¶meter->iterators[j], taskpointerarray OPTARG(failed)))
+ if(toiHasNext(¶meter->iterators[j],taskpointerarray OPTARG(failed)))
toiNext(¶meter->iterators[j], taskpointerarray OPTARG(failed));
else if (j>0) {
/* Need to backtrack */
while(1) {
/* Enqueue current state */
//int launch = 0;
- struct taskparamdescriptor *tpd=RUNMALLOC_I(sizeof(struct taskparamdescriptor));
+ struct taskparamdescriptor *tpd=
+ RUNMALLOC_I(sizeof(struct taskparamdescriptor));
tpd->task=task;
tpd->numParameters=numiterators+1;
tpd->parameterArray=RUNMALLOC_I(sizeof(void *)*(numiterators+1));
for(j=0; j<=numiterators; j++) {
- tpd->parameterArray[j]=taskpointerarray[j]; //store the actual parameters
+ //store the actual parameters
+ tpd->parameterArray[j]=taskpointerarray[j];
}
/* Enqueue task */
- if ((/*!gencontains(failedtasks, tpd)&&*/ !gencontains(activetasks,tpd))) {
+ if ((/*!gencontains(failedtasks, tpd)&&*/
+ !gencontains(activetasks,tpd))) {
genputtable_I(activetasks, tpd, tpd);
} else {
RUNFREE(tpd->parameterArray);
return retval;
}
-/* Handler for signals. The signals catch null pointer errors and
- arithmatic errors. */
-#ifndef MULTICORE
-void myhandler(int sig, siginfo_t *info, void *uap) {
- sigset_t toclear;
-#ifdef DEBUG
- printf("sig=%d\n",sig);
- printf("signal\n");
-#endif
- sigemptyset(&toclear);
- sigaddset(&toclear, sig);
- sigprocmask(SIG_UNBLOCK, &toclear,NULL);
- longjmp(error_handler,1);
-}
-#endif
-
-#ifndef MULTICORE
-fd_set readfds;
-int maxreadfd;
-struct RuntimeHash *fdtoobject;
-
-void addreadfd(int fd) {
- if (fd>=maxreadfd)
- maxreadfd=fd+1;
- FD_SET(fd, &readfds);
-}
-
-void removereadfd(int fd) {
- FD_CLR(fd, &readfds);
- if (maxreadfd==(fd+1)) {
- maxreadfd--;
- while(maxreadfd>0&&!FD_ISSET(maxreadfd-1, &readfds))
- maxreadfd--;
- }
-}
-#endif
-
#ifdef MULTICORE_GC
#define OFFSET 2
#else
#define OFFSET 0
#endif
-int containstag(struct ___Object___ *ptr, struct ___TagDescriptor___ *tag);
+int containstag(struct ___Object___ *ptr,
+ struct ___TagDescriptor___ *tag);
void executetasks() {
void * taskpointerarray[MAXTASKPARAMS+OFFSET];
numparams=currtpd->task->numParameters;
numtotal=currtpd->task->numTotal;
- // clear the lockRedirectTbl (TODO, this table should be empty after all locks are released)
+ // clear the lockRedirectTbl
+ // (TODO, this table should be empty after all locks are released)
// reset all locks
for(j = 0; j < MAXTASKPARAMS; j++) {
locks[j].redirectlock = 0;
// flush the object
#ifdef CACHEFLUSH
- BAMBOO_CACHE_FLUSH_RANGE((int)parameter, classsize[((struct ___Object___ *)parameter)->type]);
+ BAMBOO_CACHE_FLUSH_RANGE((int)parameter,
+ classsize[((struct ___Object___ *)parameter)->type]);
#endif
tmpparam = (struct ___Object___ *)parameter;
pd=currtpd->task->descriptorarray[i];
#ifdef DEBUG
BAMBOO_DEBUGPRINT(0xe995);
#endif
- ObjectHashget(pw->objectset, (int) parameter, (int *) &next, (int *) &enterflags, &UNUSED, &UNUSED2);
+ ObjectHashget(pw->objectset, (int) parameter, (int *) &next,
+ (int *) &enterflags, &UNUSED, &UNUSED2);
ObjectHashremove(pw->objectset, (int)parameter);
if (enterflags!=NULL)
RUNFREE(enterflags);
profileTaskStart(currtpd->task->name);
#endif
- if(debugtask) {
-#ifndef MULTICORE
- printf("ENTER %s count=%d\n",currtpd->task->name, (instaccum-instructioncount));
-#endif
- ((void(*) (void **))currtpd->task->taskptr)(taskpointerarray);
-#ifndef MULTICORE
- printf("EXIT %s count=%d\n",currtpd->task->name, (instaccum-instructioncount));
-#endif
- } else {
#ifdef DEBUG
- BAMBOO_DEBUGPRINT(0xe997);
+ BAMBOO_DEBUGPRINT(0xe997);
#endif
- ((void(*) (void **))currtpd->task->taskptr)(taskpointerarray);
- } // line 2990: if(debugtask)
+ ((void(*) (void **))currtpd->task->taskptr)(taskpointerarray);
#ifdef PROFILE
#ifdef ACCURATEPROFILE
// task finish, set the end of the checkTaskInfo
}
/* This function processes an objects tags */
-void processtags(struct parameterdescriptor *pd, int index, struct parameterwrapper *parameter, int * iteratorcount, int *statusarray, int numparams) {
+void processtags(struct parameterdescriptor *pd,
+ int index,
+ struct parameterwrapper *parameter,
+ int * iteratorcount,
+ int *statusarray,
+ int numparams) {
int i;
for(i=0; i<pd->numbertags; i++) {
}
-void processobject(struct parameterwrapper *parameter, int index, struct parameterdescriptor *pd, int *iteratorcount, int * statusarray, int numparams) {
+void processobject(struct parameterwrapper *parameter,
+ int index,
+ struct parameterdescriptor *pd,
+ int *iteratorcount,
+ int * statusarray,
+ int numparams) {
int i;
int tagcount=0;
- struct ObjectHash * objectset=((struct parameterwrapper *)pd->queue)->objectset;
+ struct ObjectHash * objectset=
+ ((struct parameterwrapper *)pd->queue)->objectset;
parameter->iterators[*iteratorcount].istag=0;
parameter->iterators[*iteratorcount].slot=index;
//int tagid=pd->tagarray[2*i+1];
if (statusarray[slotid+numparams]!=0) {
/* This tag has already been enqueued, use it to narrow search */
- parameter->iterators[*iteratorcount].tagbindings[tagcount]=slotid+numparams;
+ parameter->iterators[*iteratorcount].tagbindings[tagcount]=
+ slotid+numparams;
tagcount++;
}
}
/* This function builds the iterators for a task & parameter */
-void builditerators(struct taskdescriptor * task, int index, struct parameterwrapper * parameter) {
+void builditerators(struct taskdescriptor * task,
+ int index,
+ struct parameterwrapper * parameter) {
int statusarray[MAXTASKPARAMS];
int i;
int numparams=task->numParameters;
statusarray[index]=1; /* Initial parameter */
/* Process tags for initial iterator */
- processtags(task->descriptorarray[index], index, parameter, &iteratorcount, statusarray, numparams);
+ processtags(task->descriptorarray[index], index, parameter,
+ &iteratorcount, statusarray, numparams);
while(1) {
loopstart:
for(j=0; j<pd->numbertags; j++) {
int slotid=pd->tagarray[2*j];
if(statusarray[slotid+numparams]!=0) {
- processobject(parameter, i, pd, &iteratorcount, statusarray, numparams);
+ processobject(parameter, i, pd, &iteratorcount, statusarray,
+ numparams);
processtags(pd, i, parameter, &iteratorcount, statusarray, numparams);
goto loopstart;
}
}
for(i=0; i<numtasks[BAMBOO_NUM_OF_CORE]; i++) {
struct taskdescriptor * task=taskarray[BAMBOO_NUM_OF_CORE][i];
-#ifndef MULTICORE
+#ifndef RAW
printf("%s\n", task->name);
#endif
for(j=0; j<task->numParameters; j++) {
struct parameterwrapper *parameter=param->queue;
struct ObjectHash * set=parameter->objectset;
struct ObjectIterator objit;
-#ifndef MULTICORE
+#ifndef RAW
printf(" Parameter %d\n", j);
#endif
ObjectHashiterator(set, &objit);
int numflags=Objdata3(&objit);
int flags=Objdata2(&objit);
Objnext(&objit);
-#ifndef MULTICORE
+#ifndef RAW
printf(" Contains %lx\n", obj);
printf(" flag=%d\n", obj->flag);
#endif
if (tagptr==NULL) {
} else if (tagptr->type==TAGTYPE) {
-#ifndef MULTICORE
+#ifndef RAW
printf(" tag=%lx\n",tagptr);
#else
;
int tagindex=0;
struct ArrayObject *ao=(struct ArrayObject *)tagptr;
for(; tagindex<ao->___cachedCode___; tagindex++) {
-#ifndef MULTICORE
- printf(" tag=%lx\n",ARRAYGET(ao, struct ___TagDescriptor___*, tagindex));
+#ifndef RAW
+ printf(" tag=%lx\n",ARRAYGET(ao, struct ___TagDescriptor___*,
+ tagindex));
#else
;
#endif
}
}
-int toiHasNext(struct tagobjectiterator *it, void ** objectarray OPTARG(int * failed)) {
+int toiHasNext(struct tagobjectiterator *it,
+ void ** objectarray OPTARG(int * failed)) {
if (it->istag) {
/* Iterate tag */
/* Get object with tags */
struct ArrayObject *ao=(struct ArrayObject *) tagptr;
int tagindex=it->tagobjindex;
for(; tagindex<ao->___cachedCode___; tagindex++) {
- struct ___TagDescriptor___ *td=ARRAYGET(ao, struct ___TagDescriptor___ *, tagindex);
+ struct ___TagDescriptor___ *td=
+ ARRAYGET(ao, struct ___TagDescriptor___ *, tagindex);
if (td->flag==it->tagid) {
it->tagobjindex=tagindex; /* Found right type of tag */
return 1;
struct ArrayObject *ao=(struct ArrayObject *) objptr;
int tagindex;
int i;
- for(tagindex=it->tagobjindex; tagindex<ao->___cachedCode___; tagindex++) {
+ for(tagindex=it->tagobjindex;tagindex<ao->___cachedCode___;tagindex++) {
struct ___Object___ *objptr=ARRAYGET(ao, struct ___Object___*, tagindex);
if (!ObjectHashcontainskey(it->objectset, (int) objptr))
continue;
}
}
-int containstag(struct ___Object___ *ptr, struct ___TagDescriptor___ *tag) {
+int containstag(struct ___Object___ *ptr,
+ struct ___TagDescriptor___ *tag) {
int j;
struct ___Object___ * objptr=tag->flagptr;
if (objptr->type==OBJECTARRAYTYPE) {
return objptr==ptr;
}
-void toiNext(struct tagobjectiterator *it, void ** objectarray OPTARG(int * failed)) {
+void toiNext(struct tagobjectiterator *it,
+ void ** objectarray OPTARG(int * failed)) {
/* hasNext has all of the intelligence */
if(it->istag) {
/* Iterate tag */
objectarray[it->slot]=tagptr;
} else {
struct ArrayObject *ao=(struct ArrayObject *) tagptr;
- objectarray[it->slot]=ARRAYGET(ao, struct ___TagDescriptor___ *, it->tagobjindex++);
+ objectarray[it->slot]=
+ ARRAYGET(ao, struct ___TagDescriptor___ *, it->tagobjindex++);
}
} else if (it->numtags>0) {
/* Use tags to locate appropriate objects */
objectarray[it->slot]=objptr;
} else {
struct ArrayObject *ao=(struct ArrayObject *) objptr;
- objectarray[it->slot]=ARRAYGET(ao, struct ___Object___ *, it->tagobjindex++);
+ objectarray[it->slot]=
+ ARRAYGET(ao, struct ___Object___ *, it->tagobjindex++);
}
} else {
/* Iterate object */