From 83d935c7090b8523268b3ea194055124e9f5b15a Mon Sep 17 00:00:00 2001 From: jzhou Date: Thu, 18 Jun 2009 16:54:43 +0000 Subject: [PATCH] fix bugs in multicore version runtime --- .../Analysis/Scheduling/ScheduleAnalysis.java | 28 +- .../src/Analysis/Scheduling/ScheduleEdge.java | 10 +- .../src/Analysis/Scheduling/ScheduleNode.java | 10 +- .../src/Analysis/TaskStateAnalysis/FEdge.java | 8 +- .../Analysis/TaskStateAnalysis/FlagState.java | 8 +- Robust/src/IR/Flat/BuildCodeMultiCore.java | 6 +- Robust/src/Runtime/Queue.c | 7 + Robust/src/Runtime/Queue.h | 1 + Robust/src/Runtime/RAW/task_arch.c | 170 +++++++++ Robust/src/Runtime/mem.c | 2 +- Robust/src/Runtime/multicoreruntime.c | 7 + Robust/src/Runtime/multicoreruntime.h | 21 +- Robust/src/Runtime/multicoretask.c | 335 +++++++----------- Robust/src/buildscript | 1 + 14 files changed, 362 insertions(+), 252 deletions(-) diff --git a/Robust/src/Analysis/Scheduling/ScheduleAnalysis.java b/Robust/src/Analysis/Scheduling/ScheduleAnalysis.java index 84dbb9f1..793b2fbd 100644 --- a/Robust/src/Analysis/Scheduling/ScheduleAnalysis.java +++ b/Robust/src/Analysis/Scheduling/ScheduleAnalysis.java @@ -98,7 +98,7 @@ public class ScheduleAnalysis { new java.util.Hashtable(); this.readProfileInfo(taskinfos); - int tint = 0; + long tint = 0; Iterator it_classes = state.getClassSymbolTable().getDescriptorsIterator(); while(it_classes.hasNext()) { @@ -265,7 +265,7 @@ public class ScheduleAnalysis { } tmpinindex = tmpinfo.indexOf(','); - tinfo.m_exetime[i] = Integer.parseInt(tmpinfo.substring(0, tmpinindex)); + tinfo.m_exetime[i] = Long.parseLong(tmpinfo.substring(0, tmpinindex)); tmpinfo = tmpinfo.substring(tmpinindex + 1); while(tmpinfo.startsWith(" ")) { tmpinfo = tmpinfo.substring(1); @@ -660,10 +660,10 @@ public class ScheduleAnalysis { FEdge tempfe = fes.elementAt(j); Vector ses = fe2ses.get(tempfe); ScheduleEdge tempse = ses.elementAt(0); - int temptime = tempse.getListExeTime(); + long temptime = tempse.getListExeTime(); // find out the ScheduleEdge with least exeTime for(int k = 1; k < ses.size(); k++) { - int ttemp = ses.elementAt(k).getListExeTime(); + long ttemp = ses.elementAt(k).getListExeTime(); if(ttemp < temptime) { tempse = ses.elementAt(k); temptime = ttemp; @@ -708,10 +708,10 @@ public class ScheduleAnalysis { FEdge tempfe = fes.elementAt(j); Vector ses = fe2ses.get(tempfe); ScheduleEdge tempse = ses.elementAt(0); - int temptime = tempse.getListExeTime(); + long temptime = tempse.getListExeTime(); // find out the ScheduleEdge with least exeTime for(int k = 1; k < ses.size(); k++) { - int ttemp = ses.elementAt(k).getListExeTime(); + long ttemp = ses.elementAt(k).getListExeTime(); if(ttemp < temptime) { tempse = ses.elementAt(k); temptime = ttemp; @@ -748,10 +748,10 @@ public class ScheduleAnalysis { FEdge tempfe = (FEdge)it_keys.next(); Vector ses = fe2ses.get(tempfe); ScheduleEdge tempse = ses.elementAt(0); - int temptime = tempse.getListExeTime(); + long temptime = tempse.getListExeTime(); // find out the ScheduleEdge with least exeTime for(int k = 1; k < ses.size(); k++) { - int ttemp = ses.elementAt(k).getListExeTime(); + long ttemp = ses.elementAt(k).getListExeTime(); if(ttemp < temptime) { tempse = ses.elementAt(k); temptime = ttemp; @@ -957,8 +957,8 @@ public class ScheduleAnalysis { sn2sn = null; } - private int calInExeTime(FlagState fs) throws Exception { - int exeTime = 0; + private long calInExeTime(FlagState fs) throws Exception { + long exeTime = 0; ClassDescriptor cd = fs.getClassDescriptor(); ClassNode cNode = cd2ClassNode.get(cd); exeTime = cNode.getFlagStates().elementAt(0).getExeTime() - fs.getExeTime(); @@ -1032,12 +1032,12 @@ public class ScheduleAnalysis { toiterate.add(fs); while(!toiterate.isEmpty()) { FlagState tfs = toiterate.poll(); - int ttime = tfs.getExeTime(); + long ttime = tfs.getExeTime(); Iterator it_inedges = tfs.inedges(); while(it_inedges.hasNext()) { FEdge fEdge = (FEdge)it_inedges.next(); FlagState temp = (FlagState)fEdge.getSource(); - int time = fEdge.getExeTime() + ttime; + long time = fEdge.getExeTime() + ttime; if(temp.getExeTime() > time) { temp.setExeTime(time); toiterate.add(temp); @@ -1208,14 +1208,14 @@ public class ScheduleAnalysis { static class TaskInfo { public int m_numofexits; - public int[] m_exetime; + public long[] m_exetime; public double[] m_probability; public Vector> m_newobjinfo; public int m_byObj; public TaskInfo(int numofexits) { this.m_numofexits = numofexits; - this.m_exetime = new int[this.m_numofexits]; + this.m_exetime = new long[this.m_numofexits]; this.m_probability = new double[this.m_numofexits]; this.m_newobjinfo = new Vector>(); for(int i = 0; i < this.m_numofexits; i++) { diff --git a/Robust/src/Analysis/Scheduling/ScheduleEdge.java b/Robust/src/Analysis/Scheduling/ScheduleEdge.java index fbda26d1..3d9e7cec 100644 --- a/Robust/src/Analysis/Scheduling/ScheduleEdge.java +++ b/Robust/src/Analysis/Scheduling/ScheduleEdge.java @@ -28,7 +28,7 @@ public class ScheduleEdge extends Edge { private double probability; private int transTime; - private int listExeTime; + private long listExeTime; private FEdge fedge; private int newRate; @@ -175,7 +175,7 @@ public class ScheduleEdge extends Edge { public int hashCode() { int hashcode = gid^uid^label.hashCode()^target.hashCode()^source.hashCode()^fstate.hashCode()^ sourceCNode.hashCode()^targetCNode.hashCode()^newRate^(int)probability^ - type^transTime^listExeTime; + type^transTime^(int)listExeTime; if(targetFState != null) { hashcode ^= targetFState.hashCode(); } @@ -201,17 +201,17 @@ public class ScheduleEdge extends Edge { this.transTime = transTime; } - public int getListExeTime() { + public long getListExeTime() { if(listExeTime == -1) { // calculate the lisExeTime listExeTime = ((ScheduleNode) this.getTarget()).getExeTime() + this.getTransTime() * this.getNewRate(); Iterator it_edges = this.getTarget().edges(); - int temp = 0; + long temp = 0; if(it_edges.hasNext()) { temp = ((ScheduleEdge)it_edges.next()).getListExeTime(); } while(it_edges.hasNext()) { - int tetime = ((ScheduleEdge)it_edges.next()).getListExeTime(); + long tetime = ((ScheduleEdge)it_edges.next()).getListExeTime(); if(temp < tetime) { temp = tetime; } diff --git a/Robust/src/Analysis/Scheduling/ScheduleNode.java b/Robust/src/Analysis/Scheduling/ScheduleNode.java index 2c2d2c24..060d7da1 100644 --- a/Robust/src/Analysis/Scheduling/ScheduleNode.java +++ b/Robust/src/Analysis/Scheduling/ScheduleNode.java @@ -19,7 +19,7 @@ public class ScheduleNode extends GraphNode implements Cloneable { private Vector classNodes; private Vector scheduleEdges; - private int executionTime; + private long executionTime; private int hashcid; @@ -137,7 +137,7 @@ public class ScheduleNode extends GraphNode implements Cloneable { mergedcids = null; } - public int getExeTime() { + public long getExeTime() { if(this.executionTime == -1) { try { calExeTime(); @@ -189,7 +189,7 @@ public class ScheduleNode extends GraphNode implements Cloneable { } public int hashCode() { - int hashcode = gid^uid^cid^executionTime; + int hashcode = gid^uid^cid^(int)executionTime; if(this.classNodes != null) { hashcode ^= classNodes.hashCode(); } @@ -322,12 +322,12 @@ public class ScheduleNode extends GraphNode implements Cloneable { toiterate.add(sfs); while(!toiterate.isEmpty()) { FlagState tmpfs = toiterate.poll(); - int ttime = tmpfs.getExeTime(); + long ttime = tmpfs.getExeTime(); Iterator it_inedges = tmpfs.inedges(); while(it_inedges.hasNext()) { FEdge fEdge = (FEdge)it_inedges.next(); FlagState temp = (FlagState)fEdge.getSource(); - int time = fEdge.getExeTime() + ttime; + long time = fEdge.getExeTime() + ttime; if(temp.getExeTime() > time) { temp.setExeTime(time); toiterate.add(temp); diff --git a/Robust/src/Analysis/TaskStateAnalysis/FEdge.java b/Robust/src/Analysis/TaskStateAnalysis/FEdge.java index c81d8546..751574c7 100644 --- a/Robust/src/Analysis/TaskStateAnalysis/FEdge.java +++ b/Robust/src/Analysis/TaskStateAnalysis/FEdge.java @@ -12,7 +12,7 @@ public class FEdge extends Edge { private int parameterindex; // jzhou - private int executeTime; + private long executeTime; private Hashtable newObjInfos; private double probability; private int invokeNum; @@ -130,7 +130,7 @@ public class FEdge extends Edge { } public int hashCode() { - int hashcode = label.hashCode()^target.hashCode()^source.hashCode()^parameterindex^executeTime; + int hashcode = label.hashCode()^target.hashCode()^source.hashCode()^parameterindex^(int)executeTime; if (td!=null) hashcode^=td.hashCode(); if(newObjInfos != null) { @@ -169,11 +169,11 @@ public class FEdge extends Edge { return false; } - public int getExeTime() { + public long getExeTime() { return this.executeTime; } - public void setExeTime(int eTime) { + public void setExeTime(long eTime) { this.executeTime = eTime; } diff --git a/Robust/src/Analysis/TaskStateAnalysis/FlagState.java b/Robust/src/Analysis/TaskStateAnalysis/FlagState.java index 58bd822f..0270fd5e 100644 --- a/Robust/src/Analysis/TaskStateAnalysis/FlagState.java +++ b/Robust/src/Analysis/TaskStateAnalysis/FlagState.java @@ -30,7 +30,7 @@ public class FlagState extends GraphNode implements Cloneable { // jzhou // for static scheduling - private int executeTime; + private long executeTime; private int visited4time; private int invokeNum; private int byObj; @@ -340,7 +340,7 @@ public class FlagState extends GraphNode implements Cloneable { return tags.keys(); } - public int getExeTime() { + public long getExeTime() { try { if(this.executeTime == -1) { if(this.visited4time == -1) { @@ -360,7 +360,7 @@ public class FlagState extends GraphNode implements Cloneable { return this.executeTime; } - public void setExeTime(int exeTime) { + public void setExeTime(long exeTime) { this.executeTime = exeTime; } @@ -404,7 +404,7 @@ public class FlagState extends GraphNode implements Cloneable { } while(it.hasNext()) { FEdge fe = (FEdge)it.next(); - int temp = fe.getExeTime() + ((FlagState)fe.getTarget()).getExeTime(); + long temp = fe.getExeTime() + ((FlagState)fe.getTarget()).getExeTime(); if(temp < this.executeTime) { this.executeTime = temp; } diff --git a/Robust/src/IR/Flat/BuildCodeMultiCore.java b/Robust/src/IR/Flat/BuildCodeMultiCore.java index afd4a7c2..4d334de3 100644 --- a/Robust/src/IR/Flat/BuildCodeMultiCore.java +++ b/Robust/src/IR/Flat/BuildCodeMultiCore.java @@ -660,16 +660,20 @@ public class BuildCodeMultiCore extends BuildCode { output.println("BAMBOO_DEBUGPRINT(0xAAAA);"); output.println("BAMBOO_DEBUGPRINT_REG(tmpsum);"); } else { + output.println("BAMBOO_START_CRITICAL_SECTION();"); output.println("tprintf(\"Process %x(%d): task %s\\n\", corenum, corenum, \"" + task.getSymbol() + "\");"); + output.println("BAMBOO_CLOSE_CRITICAL_SECTION();"); } - output.println("BAMBOO_DEBUGPRINT(BAMBOO_GET_EXE_TIME());"); + //output.println("BAMBOO_DEBUGPRINT(BAMBOO_GET_EXE_TIME());"); output.println("#endif"); output.println("#ifdef DEBUG"); if(this.state.RAW) { output.println("BAMBOO_DEBUGPRINT(0xAAAA);"); output.println("BAMBOO_DEBUGPRINT_REG(tmpsum);"); } else { + output.println("BAMBOO_START_CRITICAL_SECTION();"); output.println("tprintf(\"Process %x(%d): task %s\\n\", corenum, corenum, \"" + task.getSymbol() + "\");"); + output.println("BAMBOO_CLOSE_CRITICAL_SECTION();"); } output.println("#endif"); if(this.state.RAW) { diff --git a/Robust/src/Runtime/Queue.c b/Robust/src/Runtime/Queue.c index a058d3f1..adb35e8d 100644 --- a/Robust/src/Runtime/Queue.c +++ b/Robust/src/Runtime/Queue.c @@ -101,6 +101,10 @@ struct QueueItem * getTail(struct Queue * queue) { return queue->tail; } +struct QueueItem * getHead(struct Queue * queue) { + return queue->head; +} + struct QueueItem * getNextQueueItem(struct QueueItem * qi) { return qi->next; } @@ -114,6 +118,9 @@ void * getItem(struct Queue * queue) { q->next->prev=NULL; } queue->head=q->next; + if(queue->tail == q) { + queue->tail = NULL; + } RUNFREE(q); return ptr; } diff --git a/Robust/src/Runtime/Queue.h b/Robust/src/Runtime/Queue.h index 27aaa0ee..2e11bc64 100644 --- a/Robust/src/Runtime/Queue.h +++ b/Robust/src/Runtime/Queue.h @@ -25,6 +25,7 @@ struct QueueItem * addNewItem_I(struct Queue * queue, void * ptr); struct QueueItem * findItem(struct Queue * queue, void * ptr); void removeItem(struct Queue * queue, struct QueueItem * item); struct QueueItem * getTail(struct Queue * queue); +struct QueueItem * getHead(struct Queue * queue); struct QueueItem * getNextQueueItem(struct QueueItem * qi); // to implement a double-ended queue diff --git a/Robust/src/Runtime/RAW/task_arch.c b/Robust/src/Runtime/RAW/task_arch.c index 52c00c1c..0b0e6b20 100644 --- a/Robust/src/Runtime/RAW/task_arch.c +++ b/Robust/src/Runtime/RAW/task_arch.c @@ -745,6 +745,176 @@ __attribute__((always_inline)) inline void profileTaskEnd() { } } } + +// output the profiling data +void outputProfileData() { +#ifdef USEIO + FILE * fp; + char fn[50]; + int self_y, self_x; + char c_y, c_x; + int i; + int totaltasktime = 0; + int preprocessingtime = 0; + int objqueuecheckingtime = 0; + int postprocessingtime = 0; + //int interruptiontime = 0; + int other = 0; + int averagetasktime = 0; + int tasknum = 0; + + for(i = 0; i < 50; i++) { + fn[i] = 0; + } + + calCoords(corenum, &self_y, &self_x); + c_y = (char)self_y + '0'; + c_x = (char)self_x + '0'; + strcat(fn, "profile_"); + strcat(fn, &c_x); + strcat(fn, "_"); + strcat(fn, &c_y); + strcat(fn, ".rst"); + + if((fp = fopen(fn, "w+")) == NULL) { + fprintf(stderr, "fopen error\n"); + return; + } + + fprintf(fp, "Task Name, Start Time, End Time, Duration, Exit Index(, NewObj Name, Num)+\n"); + // output task related info + for(i = 0; i < taskInfoIndex; i++) { + TaskInfo* tmpTInfo = taskInfoArray[i]; + int duration = tmpTInfo->endTime - tmpTInfo->startTime; + fprintf(fp, "%s, %d, %d, %d, %d", tmpTInfo->taskName, tmpTInfo->startTime, tmpTInfo->endTime, duration, tmpTInfo->exitIndex); + // summarize new obj info + if(tmpTInfo->newObjs != NULL) { + struct RuntimeHash * nobjtbl = allocateRuntimeHash(5); + struct RuntimeIterator * iter = NULL; + while(0 == isEmpty(tmpTInfo->newObjs)) { + char * objtype = (char *)(getItem(tmpTInfo->newObjs)); + if(RuntimeHashcontainskey(nobjtbl, (int)(objtype))) { + int num = 0; + RuntimeHashget(nobjtbl, (int)objtype, &num); + RuntimeHashremovekey(nobjtbl, (int)objtype); + num++; + RuntimeHashadd(nobjtbl, (int)objtype, num); + } else { + RuntimeHashadd(nobjtbl, (int)objtype, 1); + } + //fprintf(stderr, "new obj!\n"); + } + + // output all new obj info + iter = RuntimeHashcreateiterator(nobjtbl); + while(RunhasNext(iter)) { + char * objtype = (char *)Runkey(iter); + int num = Runnext(iter); + fprintf(fp, ", %s, %d", objtype, num); + } + } + fprintf(fp, "\n"); + if(strcmp(tmpTInfo->taskName, "tpd checking") == 0) { + preprocessingtime += duration; + } else if(strcmp(tmpTInfo->taskName, "post task execution") == 0) { + postprocessingtime += duration; + } else if(strcmp(tmpTInfo->taskName, "objqueue checking") == 0) { + objqueuecheckingtime += duration; + } else { + totaltasktime += duration; + averagetasktime += duration; + tasknum++; + } + } + + if(taskInfoOverflow) { + fprintf(stderr, "Caution: task info overflow!\n"); + } + + other = totalexetime - totaltasktime - preprocessingtime - postprocessingtime; + averagetasktime /= tasknum; + + fprintf(fp, "\nTotal time: %d\n", totalexetime); + fprintf(fp, "Total task execution time: %d (%f%%)\n", totaltasktime, ((double)totaltasktime/(double)totalexetime)*100); + fprintf(fp, "Total objqueue checking time: %d (%f%%)\n", objqueuecheckingtime, ((double)objqueuecheckingtime/(double)totalexetime)*100); + fprintf(fp, "Total pre-processing time: %d (%f%%)\n", preprocessingtime, ((double)preprocessingtime/(double)totalexetime)*100); + fprintf(fp, "Total post-processing time: %d (%f%%)\n", postprocessingtime, ((double)postprocessingtime/(double)totalexetime)*100); + fprintf(fp, "Other time: %d (%f%%)\n", other, ((double)other/(double)totalexetime)*100); + + fprintf(fp, "\nAverage task execution time: %d\n", averagetasktime); + + fclose(fp); +#else + int i = 0; + int j = 0; + + BAMBOO_DEBUGPRINT(0xdddd); + // output task related info + for(i= 0; i < taskInfoIndex; i++) { + TaskInfo* tmpTInfo = taskInfoArray[i]; + char* tmpName = tmpTInfo->taskName; + int nameLen = strlen(tmpName); + BAMBOO_DEBUGPRINT(0xddda); + for(j = 0; j < nameLen; j++) { + BAMBOO_DEBUGPRINT_REG(tmpName[j]); + } + BAMBOO_DEBUGPRINT(0xdddb); + BAMBOO_DEBUGPRINT_REG(tmpTInfo->startTime); + BAMBOO_DEBUGPRINT_REG(tmpTInfo->endTime); + BAMBOO_DEBUGPRINT_REG(tmpTInfo->exitIndex); + if(tmpTInfo->newObjs != NULL) { + struct RuntimeHash * nobjtbl = allocateRuntimeHash(5); + struct RuntimeIterator * iter = NULL; + while(0 == isEmpty(tmpTInfo->newObjs)) { + char * objtype = (char *)(getItem(tmpTInfo->newObjs)); + if(RuntimeHashcontainskey(nobjtbl, (int)(objtype))) { + int num = 0; + RuntimeHashget(nobjtbl, (int)objtype, &num); + RuntimeHashremovekey(nobjtbl, (int)objtype); + num++; + RuntimeHashadd(nobjtbl, (int)objtype, num); + } else { + RuntimeHashadd(nobjtbl, (int)objtype, 1); + } + } + + // ouput all new obj info + iter = RuntimeHashcreateiterator(nobjtbl); + while(RunhasNext(iter)) { + char * objtype = (char *)Runkey(iter); + int num = Runnext(iter); + int nameLen = strlen(objtype); + BAMBOO_DEBUGPRINT(0xddda); + for(j = 0; j < nameLen; j++) { + BAMBOO_DEBUGPRINT_REG(objtype[j]); + } + BAMBOO_DEBUGPRINT(0xdddb); + BAMBOO_DEBUGPRINT_REG(num); + } + } + BAMBOO_DEBUGPRINT(0xdddc); + } + + if(taskInfoOverflow) { + BAMBOO_DEBUGPRINT(0xefee); + } + + // output interrupt related info + /*for(i = 0; i < interruptInfoIndex; i++) { + InterruptInfo* tmpIInfo = interruptInfoArray[i]; + BAMBOO_DEBUGPRINT(0xddde); + BAMBOO_DEBUGPRINT_REG(tmpIInfo->startTime); + BAMBOO_DEBUGPRINT_REG(tmpIInfo->endTime); + BAMBOO_DEBUGPRINT(0xdddf); + } + + if(interruptInfoOverflow) { + BAMBOO_DEBUGPRINT(0xefef); + }*/ + + BAMBOO_DEBUGPRINT(0xeeee); +#endif +} #endif // #ifdef PROFILE #endif // #ifdef TASK diff --git a/Robust/src/Runtime/mem.c b/Robust/src/Runtime/mem.c index 04c8115a..684100bc 100644 --- a/Robust/src/Runtime/mem.c +++ b/Robust/src/Runtime/mem.c @@ -26,7 +26,7 @@ void * mycalloc_share(int m, int size) { void * p = NULL; int isize = 2*BAMBOO_CACHE_LINE_SIZE-4+(size-1)&(~BAMBOO_CACHE_LINE_MASK); BAMBOO_START_CRITICAL_SECTION_MEM(); - p = BAMBOO_SHARE_MEM_CALLOC(m, isize); // calloc(m, isize); + p = BAMBOO_SHARE_MEM_CALLOC_I(m, isize); // calloc(m, isize); BAMBOO_CLOSE_CRITICAL_SECTION_MEM(); return (void *)(BAMBOO_CACHE_LINE_SIZE+((int)p-1)&(~BAMBOO_CACHE_LINE_MASK)); } diff --git a/Robust/src/Runtime/multicoreruntime.c b/Robust/src/Runtime/multicoreruntime.c index d413383d..69dfd479 100644 --- a/Robust/src/Runtime/multicoreruntime.c +++ b/Robust/src/Runtime/multicoreruntime.c @@ -140,6 +140,13 @@ void CALL11(___System______exit____I,int ___status___, int ___status___) { #endif } +//#ifdef D___Vector______removeElement_____AR_L___Object____I_I +void CALL23(___Vector______removeElement_____AR_L___Object____I_I, int ___index___, int ___size___, struct ArrayObject * ___array___, int ___index___, int ___size___) { + char* offset=((char *)(&VAR(___array___)->___length___))+sizeof(unsigned int)+sizeof(void *)*___index___; + memmove(offset, offset+sizeof(void *),(___size___-___index___-1)*sizeof(void *)); +} +//#endif + void CALL11(___System______printI____I,int ___status___, int ___status___) { #ifdef MULTICORE BAMBOO_DEBUGPRINT(0x1111); diff --git a/Robust/src/Runtime/multicoreruntime.h b/Robust/src/Runtime/multicoreruntime.h index e6bf0c63..0c5857b3 100644 --- a/Robust/src/Runtime/multicoreruntime.h +++ b/Robust/src/Runtime/multicoreruntime.h @@ -45,6 +45,20 @@ bool lockflag; // data structures for waiting objs struct Queue objqueue; +// data structures for shared memory allocation +bool smemflag; +struct bamboo_shared_mem { + mspace msp; + struct bamboo_shared_mem * next; +}; +struct bamboo_smem_list { + struct bamboo_shared_mem * head; + struct bamboo_shared_mem * tail; +}; +struct bamboo_smem_list * bamboo_free_msps; +mspace bamboo_cur_msp; +int bamboo_smem_size; + // data structures for profile mode #ifdef PROFILE @@ -57,9 +71,9 @@ int totalexetime; typedef struct task_info { char* taskName; - int startTime; - int endTime; - int exitIndex; + unsigned long long startTime; + unsigned long long endTime; + unsigned long long exitIndex; struct Queue * newObjs; } TaskInfo; @@ -111,6 +125,7 @@ inline int receiveMsg(void) __attribute__((always_inline)); #ifdef PROFILE inline void profileTaskStart(char * taskname) __attribute__((always_inline)); inline void profileTaskEnd(void) __attribute__((always_inline)); +void outputProfileData(); #endif // #ifdef PROFILE /////////////////////////////////////////////////////////// diff --git a/Robust/src/Runtime/multicoretask.c b/Robust/src/Runtime/multicoretask.c index 44e910a7..6b7a2e80 100644 --- a/Robust/src/Runtime/multicoretask.c +++ b/Robust/src/Runtime/multicoretask.c @@ -28,10 +28,6 @@ struct RuntimeHash * forward; struct RuntimeHash * reverse; #endif // if 0: for recovery -#ifdef PROFILE -void outputProfileData(); -#endif - bool getreadlock(void* ptr); void releasereadlock(void* ptr); bool getwritelock(void* ptr); @@ -54,7 +50,6 @@ inline void run(void * arg) { bool sendStall = false; bool isfirst = true; bool tocontinue = false; - struct QueueItem * objitem = NULL; struct transObjInfo * objInfo = NULL; int grount = 0; bool allStall = true; @@ -103,6 +98,10 @@ inline void run(void * arg) { isMsgHanging = false; isMsgSending = false; + smemflag = false; + bamboo_cur_msp = NULL; + bamboo_smem_size = 0; + // create the lock table, lockresult table and obj queue locktable.size = 20; locktable.bucket = (struct RuntimeNode **) RUNMALLOC_I(sizeof(struct RuntimeNode *)*20); @@ -225,8 +224,7 @@ inline void run(void * arg) { #endif sendStall = false; tocontinue = true; - objitem = getTail(&objqueue); - objInfo = (struct transObjInfo *)objitem->objectptr; + objInfo = (struct transObjInfo *)getItem(&objqueue); obj = objInfo->objptr; #ifdef DEBUG BAMBOO_DEBUGPRINT_REG((int)obj); @@ -249,10 +247,12 @@ inline void run(void * arg) { #ifndef INTERRUPT reside = false; #endif + if(grount == 1) { int k = 0; // flush the object #ifdef CACHEFLUSH + BAMBOO_CACHE_FLUSH_RANGE((int)obj,sizeof(int)); BAMBOO_CACHE_FLUSH_RANGE((int)obj, classsize[((struct ___Object___ *)obj)->type]); #endif // enqueue the object @@ -264,27 +264,40 @@ inline void run(void * arg) { 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", corenum, corenum, (int)obj, (long)obj, tmpptr->flag); + tprintf("Process %x(%d): receive obj %x(%lld), ptrflag %x\n", corenum, corenum, (int)obj, (long)obj, tmpptr->flag); #endif - enqueueObject_I(obj, queues, 1); -#ifdef DEBUG - BAMBOO_DEBUGPRINT_REG(hashsize(activetasks)); +#ifdef DEBUG + BAMBOO_DEBUGPRINT_REG(hashsize(activetasks)); #endif } - removeItem(&objqueue, objitem); releasewritelock_I(obj); RUNFREE(objInfo->queues); RUNFREE(objInfo); } else { // can not get lock - // put it at the end of the queue - // and try to execute active tasks already enqueued first - removeItem(&objqueue, objitem); + // put it at the end of the queue if no update version in the queue + struct QueueItem * qitem = getHead(&objqueue); + struct QueueItem * prev = NULL; + while(qitem != NULL) { + 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 + RUNFREE(objInfo->queues); + RUNFREE(objInfo); + goto objqueuebreak; + } else { + prev = qitem; + } + qitem = getNextQueueItem(prev); + } + // try to execute active tasks already enqueued first addNewItem_I(&objqueue, objInfo); #ifdef PROFILE //isInterrupt = true; #endif +objqueuebreak: BAMBOO_CLOSE_CRITICAL_SECTION_OBJ_QUEUE(); #ifdef DEBUG BAMBOO_DEBUGPRINT(0xf000); @@ -385,8 +398,8 @@ inline void run(void * arg) { #ifdef USEIO totalexetime = BAMBOO_GET_EXE_TIME(); #else - BAMBOO_DEBUGPRINT(0xbbbbbbbb); BAMBOO_DEBUGPRINT(BAMBOO_GET_EXE_TIME()); + BAMBOO_DEBUGPRINT(0xbbbbbbbb); #endif // profile mode, send msgs to other cores to request pouring // out progiling data @@ -1060,6 +1073,19 @@ void addAliasLock(void * ptr, int lock) { } } +#ifdef PROFILE +inline void setTaskExitIndex(int index) { + taskInfoArray[taskInfoIndex]->exitIndex = index; +} + +inline void addNewObjInfo(void * nobj) { + if(taskInfoArray[taskInfoIndex]->newObjs == NULL) { + taskInfoArray[taskInfoIndex]->newObjs = createQueue(); + } + addNewItem(taskInfoArray[taskInfoIndex]->newObjs, nobj); +} +#endif + /* Message format: * type + Msgbody * type: 0 -- transfer object @@ -1079,6 +1105,8 @@ void addAliasLock(void * ptr, int lock) { * c -- status confirm request * d -- status report msg * e -- terminate + * f -- requiring for new memory + * 10 -- response for new memory request * * ObjMsg: 0 + size of msg + obj's address + (task index + param index)+ * StallMsg: 1 + corenum + sendobjs + receiveobjs (size is always 4 * sizeof(int)) @@ -1094,191 +1122,10 @@ void addAliasLock(void * ptr, int lock) { * d + status + corenum (size is always 3 * 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)) */ -#ifdef PROFILE -// output the profiling data -void outputProfileData() { -#ifdef USEIO - FILE * fp; - char fn[50]; - int self_y, self_x; - char c_y, c_x; - int i; - int totaltasktime = 0; - int preprocessingtime = 0; - int objqueuecheckingtime = 0; - int postprocessingtime = 0; - //int interruptiontime = 0; - int other = 0; - int averagetasktime = 0; - int tasknum = 0; - - for(i = 0; i < 50; i++) { - fn[i] = 0; - } - - calCoords(corenum, &self_y, &self_x); - c_y = (char)self_y + '0'; - c_x = (char)self_x + '0'; - strcat(fn, "profile_"); - strcat(fn, &c_x); - strcat(fn, "_"); - strcat(fn, &c_y); - strcat(fn, ".rst"); - - if((fp = fopen(fn, "w+")) == NULL) { - fprintf(stderr, "fopen error\n"); - return; - } - - fprintf(fp, "Task Name, Start Time, End Time, Duration, Exit Index(, NewObj Name, Num)+\n"); - // output task related info - for(i = 0; i < taskInfoIndex; i++) { - TaskInfo* tmpTInfo = taskInfoArray[i]; - int duration = tmpTInfo->endTime - tmpTInfo->startTime; - fprintf(fp, "%s, %d, %d, %d, %d", tmpTInfo->taskName, tmpTInfo->startTime, tmpTInfo->endTime, duration, tmpTInfo->exitIndex); - // summarize new obj info - if(tmpTInfo->newObjs != NULL) { - struct RuntimeHash * nobjtbl = allocateRuntimeHash(5); - struct RuntimeIterator * iter = NULL; - while(0 == isEmpty(tmpTInfo->newObjs)) { - char * objtype = (char *)(getItem(tmpTInfo->newObjs)); - if(RuntimeHashcontainskey(nobjtbl, (int)(objtype))) { - int num = 0; - RuntimeHashget(nobjtbl, (int)objtype, &num); - RuntimeHashremovekey(nobjtbl, (int)objtype); - num++; - RuntimeHashadd(nobjtbl, (int)objtype, num); - } else { - RuntimeHashadd(nobjtbl, (int)objtype, 1); - } - //fprintf(stderr, "new obj!\n"); - } - - // output all new obj info - iter = RuntimeHashcreateiterator(nobjtbl); - while(RunhasNext(iter)) { - char * objtype = (char *)Runkey(iter); - int num = Runnext(iter); - fprintf(fp, ", %s, %d", objtype, num); - } - } - fprintf(fp, "\n"); - if(strcmp(tmpTInfo->taskName, "tpd checking") == 0) { - preprocessingtime += duration; - } else if(strcmp(tmpTInfo->taskName, "post task execution") == 0) { - postprocessingtime += duration; - } else if(strcmp(tmpTInfo->taskName, "objqueue checking") == 0) { - objqueuecheckingtime += duration; - } else { - totaltasktime += duration; - averagetasktime += duration; - tasknum++; - } - } - - if(taskInfoOverflow) { - fprintf(stderr, "Caution: task info overflow!\n"); - } - - other = totalexetime - totaltasktime - preprocessingtime - postprocessingtime; - averagetasktime /= tasknum; - - fprintf(fp, "\nTotal time: %d\n", totalexetime); - fprintf(fp, "Total task execution time: %d (%f%%)\n", totaltasktime, ((double)totaltasktime/(double)totalexetime)*100); - fprintf(fp, "Total objqueue checking time: %d (%f%%)\n", objqueuecheckingtime, ((double)objqueuecheckingtime/(double)totalexetime)*100); - fprintf(fp, "Total pre-processing time: %d (%f%%)\n", preprocessingtime, ((double)preprocessingtime/(double)totalexetime)*100); - fprintf(fp, "Total post-processing time: %d (%f%%)\n", postprocessingtime, ((double)postprocessingtime/(double)totalexetime)*100); - fprintf(fp, "Other time: %d (%f%%)\n", other, ((double)other/(double)totalexetime)*100); - - fprintf(fp, "\nAverage task execution time: %d\n", averagetasktime); - - fclose(fp); -#else - int i = 0; - int j = 0; - - BAMBOO_DEBUGPRINT(0xdddd); - // output task related info - for(i= 0; i < taskInfoIndex; i++) { - TaskInfo* tmpTInfo = taskInfoArray[i]; - char* tmpName = tmpTInfo->taskName; - int nameLen = strlen(tmpName); - BAMBOO_DEBUGPRINT(0xddda); - for(j = 0; j < nameLen; j++) { - BAMBOO_DEBUGPRINT_REG(tmpName[j]); - } - BAMBOO_DEBUGPRINT(0xdddb); - BAMBOO_DEBUGPRINT_REG(tmpTInfo->startTime); - BAMBOO_DEBUGPRINT_REG(tmpTInfo->endTime); - BAMBOO_DEBUGPRINT_REG(tmpTInfo->exitIndex); - if(tmpTInfo->newObjs != NULL) { - struct RuntimeHash * nobjtbl = allocateRuntimeHash(5); - struct RuntimeIterator * iter = NULL; - while(0 == isEmpty(tmpTInfo->newObjs)) { - char * objtype = (char *)(getItem(tmpTInfo->newObjs)); - if(RuntimeHashcontainskey(nobjtbl, (int)(objtype))) { - int num = 0; - RuntimeHashget(nobjtbl, (int)objtype, &num); - RuntimeHashremovekey(nobjtbl, (int)objtype); - num++; - RuntimeHashadd(nobjtbl, (int)objtype, num); - } else { - RuntimeHashadd(nobjtbl, (int)objtype, 1); - } - } - - // ouput all new obj info - iter = RuntimeHashcreateiterator(nobjtbl); - while(RunhasNext(iter)) { - char * objtype = (char *)Runkey(iter); - int num = Runnext(iter); - int nameLen = strlen(objtype); - BAMBOO_DEBUGPRINT(0xddda); - for(j = 0; j < nameLen; j++) { - BAMBOO_DEBUGPRINT_REG(objtype[j]); - } - BAMBOO_DEBUGPRINT(0xdddb); - BAMBOO_DEBUGPRINT_REG(num); - } - } - BAMBOO_DEBUGPRINT(0xdddc); - } - - if(taskInfoOverflow) { - BAMBOO_DEBUGPRINT(0xefee); - } - - // output interrupt related info - /*for(i = 0; i < interruptInfoIndex; i++) { - InterruptInfo* tmpIInfo = interruptInfoArray[i]; - BAMBOO_DEBUGPRINT(0xddde); - BAMBOO_DEBUGPRINT_REG(tmpIInfo->startTime); - BAMBOO_DEBUGPRINT_REG(tmpIInfo->endTime); - BAMBOO_DEBUGPRINT(0xdddf); - } - - if(interruptInfoOverflow) { - BAMBOO_DEBUGPRINT(0xefef); - }*/ - - BAMBOO_DEBUGPRINT(0xeeee); -#endif -} - -inline void setTaskExitIndex(int index) { - taskInfoArray[taskInfoIndex]->exitIndex = index; -} - -inline void addNewObjInfo(void * nobj) { - if(taskInfoArray[taskInfoIndex]->newObjs == NULL) { - taskInfoArray[taskInfoIndex]->newObjs = createQueue(); - } - addNewItem(taskInfoArray[taskInfoIndex]->newObjs, nobj); -} -#endif - /* this function is to process lock requests. * can only be invoked in receiveObject() */ // if return -1: the lock request is redirected @@ -1353,18 +1200,19 @@ msg: } // check if there is an existing duplicate item { - struct QueueItem * qitem = getTail(&objqueue); + struct QueueItem * qitem = getHead(&objqueue); struct QueueItem * prev = NULL; while(qitem != NULL) { struct transObjInfo * tmpinfo = (struct transObjInfo *)(qitem->objectptr); if(tmpinfo->objptr == transObj->objptr) { // the same object, remove outdate one removeItem(&objqueue, qitem); + //break; } else { prev = qitem; } if(prev == NULL) { - qitem = getTail(&objqueue); + qitem = getHead(&objqueue); } else { qitem = getNextQueueItem(prev); } @@ -1749,6 +1597,63 @@ msg: BAMBOO_EXIT(0); break; } + + case 0xf: { + // receive a shared memory request msg + if(corenum != STARTUPCORE) { + // wrong core to receive such msg +#ifndef TILERA + BAMBOO_DEBUGPRINT_REG(msgdata[2]); +#endif + BAMBOO_EXIT(0xa015); + } else { +#ifdef DEBUG +#ifndef TILERA + BAMBOO_DEBUGPRINT(0xe88a); +#endif +#endif + struct bamboo_shared_mem * cur_mem = bamboo_free_msps->head; + void * mem = mspace_calloc(cur_mem->msp, 1, msgdata[1]); + struct bamboo_shared_mem * failmem = cur_mem; + while(mem == NULL) { + // move current head to the tail + bamboo_free_msps->tail->next = cur_mem; + bamboo_free_msps->tail = cur_mem; + bamboo_free_msps->head = cur_mem->next; + cur_mem->next = NULL; + cur_mem = bamboo_free_msps->head; + if(cur_mem == failmem) { + BAMBOO_EXIT(0xa016); + } + mem = mspace_calloc(cur_mem->msp, 1, msgdata[1]); + } + // send the start_va to request core + if(isMsgSending) { + cache_msg_3(msgdata[2], 0x10, mem, msgdata[1]); + } else { + send_msg_3(msgdata[2], 0x10, mem, msgdata[1]); + } + } + break; + } + + case 0x10: { + // receive a shared memory response msg +#ifdef DEBUG +#ifndef TILERA + BAMBOO_DEBUGPRINT(0xe88b); +#endif +#endif + if(msgdata[2] == 0) { + bamboo_smem_size = 0; + bamboo_cur_msp = NULL; + } else { + bamboo_smem_size = msgdata[2]; + bamboo_cur_msp = create_mspace_with_base((void*)msgdata[1], msgdata[2], 0); + } + smemflag = true; + break; + } default: break; @@ -1760,7 +1665,7 @@ msg: msglength = 30; #ifdef DEBUG #ifndef TILERA - BAMBOO_DEBUGPRINT(0xe88a); + BAMBOO_DEBUGPRINT(0xe88c); #endif #endif @@ -1777,7 +1682,7 @@ msg: // not a whole msg #ifdef DEBUG #ifndef TILERA - BAMBOO_DEBUGPRINT(0xe88b); + BAMBOO_DEBUGPRINT(0xe88d); #endif #endif #ifdef PROFILE @@ -1803,7 +1708,7 @@ int processlockrequest(int locktype, int lock, int obj, int requestcore, int roo BAMBOO_DEBUGPRINT_REG(lock); BAMBOO_DEBUGPRINT_REG(corenum); #endif - BAMBOO_EXIT(0xa015); + BAMBOO_EXIT(0xa017); } /*if((corenum == STARTUPCORE) && waitconfirm) { waitconfirm = false; @@ -1926,7 +1831,7 @@ bool getreadlock(void * ptr) { #endif } else { // conflicts on lockresults - BAMBOO_EXIT(0xa016); + BAMBOO_EXIT(0xa018); } } return true; @@ -1956,7 +1861,7 @@ void releasereadlock(void * ptr) { // reside on this core if(!RuntimeHashcontainskey(locktbl, reallock)) { // no locks for this object, something is wrong - BAMBOO_EXIT(0xa017); + BAMBOO_EXIT(0xa019); } else { int rwlock_obj = 0; struct LockValue * lockvalue = NULL; @@ -2012,7 +1917,7 @@ bool getreadlock_I_r(void * ptr, void * redirectlock, int core, bool cache) { #endif } else { // conflicts on lockresults - BAMBOO_EXIT(0xa018); + BAMBOO_EXIT(0xa01a); } return true; } else { @@ -2096,7 +2001,7 @@ bool getwritelock(void * ptr) { #endif } else { // conflicts on lockresults - BAMBOO_EXIT(0xa019); + BAMBOO_EXIT(0xa01b); } } return true; @@ -2133,7 +2038,7 @@ void releasewritelock(void * ptr) { // reside on this core if(!RuntimeHashcontainskey(locktbl, reallock)) { // no locks for this object, something is wrong - BAMBOO_EXIT(0xa01a); + BAMBOO_EXIT(0xa01c); } else { int rwlock_obj = 0; struct LockValue * lockvalue = NULL; @@ -2173,7 +2078,7 @@ void releasewritelock_r(void * lock, void * redirectlock) { // reside on this core if(!RuntimeHashcontainskey(locktbl, reallock)) { // no locks for this object, something is wrong - BAMBOO_EXIT(0xa01b); + BAMBOO_EXIT(0xa01d); } else { int rwlock_obj = 0; struct LockValue * lockvalue = NULL; @@ -2250,7 +2155,7 @@ bool getwritelock_I(void * ptr) { #endif } else { // conflicts on lockresults - BAMBOO_EXIT(0xa01c); + BAMBOO_EXIT(0xa01e); } return true; } @@ -2308,7 +2213,7 @@ bool getwritelock_I_r(void * ptr, void * redirectlock, int core, bool cache) { #endif } else { // conflicts on lockresults - BAMBOO_EXIT(0xa01d); + BAMBOO_EXIT(0xa01f); } return true; } else { @@ -2354,7 +2259,7 @@ void releasewritelock_I(void * ptr) { // reside on this core if(!RuntimeHashcontainskey(locktbl, reallock)) { // no locks for this object, something is wrong - BAMBOO_EXIT(0xa01e); + BAMBOO_EXIT(0xa020); } else { int rwlock_obj = 0; struct LockValue * lockvalue = NULL; @@ -2386,7 +2291,7 @@ void releasewritelock_I_r(void * lock, void * redirectlock) { // reside on this core if(!RuntimeHashcontainskey(locktbl, reallock)) { // no locks for this object, something is wrong - BAMBOO_EXIT(0xa01f); + BAMBOO_EXIT(0xa021); } else { int rwlock_obj = 0; struct LockValue * lockvalue = NULL; @@ -2973,7 +2878,7 @@ parameterpresent: reverse=NULL; #endif // #if 0: for recovery BAMBOO_DEBUGPRINT_REG(x); - BAMBOO_EXIT(0xa020); + BAMBOO_EXIT(0xa022); } else { #endif // #ifndef MULTICORE #if 0 diff --git a/Robust/src/buildscript b/Robust/src/buildscript index 020807fb..7429feaf 100755 --- a/Robust/src/buildscript +++ b/Robust/src/buildscript @@ -544,6 +544,7 @@ fi #INTERRUPT version cp $ROBUSTROOT/Tilera/Runtime/$MAKEFILE ./Makefile cp $ROBUSTROOT/Tilera/Runtime/$SIMHVC ./sim.hvc cp $ROBUSTROOT/Tilera/Runtime/$PCIHVC ./pci.hvc +cp $ROBUSTROOT/Tilera/Runtime/bamboo-vmlinux-pci.hvc ./bamboo-vmlinux-pci.hvc cp ../Runtime/multicoretask.c ./ cp ../Runtime/multicoreruntime.c ./ cp ../Runtime/Queue.c ./ -- 2.34.1