From 0a4e73ae375198c22450470ab8222266bfe53697 Mon Sep 17 00:00:00 2001 From: jzhou Date: Fri, 10 Oct 2008 19:43:59 +0000 Subject: [PATCH] let scheduling analysis be able to use profile data --- .../Analysis/Scheduling/SchedulingUtil.java | 41 ++- Robust/src/IR/State.java | 1 + Robust/src/Main/Main.java | 266 +++++++++++++----- Robust/src/Runtime/multicoretask.c | 62 ++-- Robust/src/buildscript | 14 + 5 files changed, 284 insertions(+), 100 deletions(-) diff --git a/Robust/src/Analysis/Scheduling/SchedulingUtil.java b/Robust/src/Analysis/Scheduling/SchedulingUtil.java index e474c672..c39791a8 100644 --- a/Robust/src/Analysis/Scheduling/SchedulingUtil.java +++ b/Robust/src/Analysis/Scheduling/SchedulingUtil.java @@ -513,11 +513,48 @@ public class SchedulingUtil { } output.print("\t"); output.print("\t"); + int prev = Integer.parseInt(timeNodes.elementAt(0)); + int next = 0; + int max = 0; + int max2 = 0; + for(j = 1; j < timeNodes.size(); j++) { + next = Integer.parseInt(timeNodes.elementAt(j)); + int delta = next - prev; + if(max < delta) { + max2 = max; + max = delta; + } else if((max != delta) && (max2 < delta)) { + max2 = delta; + } + prev = next; + } + if(max2 == 0) { + max2 = 1; + } else if(max/max2 > 100) { + max2 = max/100; + } output.println("\"Time\"->" + timeNodes.elementAt(0) + "[style=invis];"); - for(j = 0; j < time; j++) { + prev = Integer.parseInt(timeNodes.elementAt(0)); + next = 0; + for(j = 1; j < timeNodes.size(); j++) { + next = Integer.parseInt(timeNodes.elementAt(j)); + if(next - prev > max2) { + do { + output.print(prev + "->"); + prev += max2; + }while(next - prev > max2); + output.println(next + ";"); + } else { + output.println("{rank=same; rankdir=LR; " + prev + "; " + next + "}"); + output.println(prev + "->" + next + "[style=invis];"); + } + prev = next; + } + + /*for(j = 0; j < time; j++) { output.print(j + "->"); } - output.println(timeNodes.lastElement() + ";"); + output.println(timeNodes.lastElement() + ";");*/ output.println("}"); output.close(); } catch (Exception e) { diff --git a/Robust/src/IR/State.java b/Robust/src/IR/State.java index aed4c2d5..157fe003 100644 --- a/Robust/src/IR/State.java +++ b/Robust/src/IR/State.java @@ -61,6 +61,7 @@ public class State { public boolean OPTIONAL=false; public boolean RAW=false; public boolean SCHEDULING=false; + public boolean USEPROFILE=false; public boolean THREAD=false; public boolean CONSCHECK=false; public boolean INSTRUCTIONFAILURE=false; diff --git a/Robust/src/Main/Main.java b/Robust/src/Main/Main.java index 2dd61672..a87f66ae 100644 --- a/Robust/src/Main/Main.java +++ b/Robust/src/Main/Main.java @@ -111,6 +111,8 @@ public class Main { state.RAW=true; else if (option.equals("-scheduling")) state.SCHEDULING=true; + else if (option.equals("-useprofile")) + state.USEPROFILE=true; else if (option.equals("-thread")) state.THREAD=true; else if (option.equals("-dsm")) @@ -283,77 +285,207 @@ public class Main { //System.out.println ("Test output via 'SimulatorResult.out'."); //origOut.println ("Test output via 'origOut' reference."); - // for test - // Randomly set the newRate and probability of FEdges - java.util.Random r=new java.util.Random(); - int tint = 0; - for(Iterator it_classes=state.getClassSymbolTable().getDescriptorsIterator(); it_classes.hasNext();) { - ClassDescriptor cd=(ClassDescriptor) it_classes.next(); - if(cd.hasFlags()) { - Vector rootnodes=ta.getRootNodes(cd); - if(rootnodes!=null) - for(Iterator it_rootnodes=rootnodes.iterator(); it_rootnodes.hasNext();) { - FlagState root=(FlagState)it_rootnodes.next(); - Vector allocatingTasks = root.getAllocatingTasks(); - if(allocatingTasks != null) { - for(int k = 0; k < allocatingTasks.size(); k++) { - TaskDescriptor td = (TaskDescriptor)allocatingTasks.elementAt(k); - Vector fev = (Vector)ta.getFEdgesFromTD(td); - int numEdges = fev.size(); - int total = 100; - for(int j = 0; j < numEdges; j++) { - FEdge pfe = fev.elementAt(j); - if(numEdges - j == 1) { - pfe.setProbability(total); - } else { - if((total != 0) && (total != 1)) { - do { - tint = r.nextInt()%total; - } while(tint <= 0); + if(state.USEPROFILE) { + // read in profile data and set + FileInputStream inStream = new FileInputStream("/scratch/profile.rst"); + byte[] b = new byte[1024 * 100]; + int length = inStream.read(b); + if(length < 0) { + System.out.print("No content in input file: /scratch/profile.rst\n"); + System.exit(-1); + } + String profiledata = new String(b, 0, length); + java.util.Hashtable taskinfo = new java.util.Hashtable(); + + int inindex = profiledata.indexOf('\n'); + while((inindex != -1) ) { + String inline = profiledata.substring(0, inindex); + profiledata = profiledata.substring(inindex + 1); + //System.printString(inline + "\n"); + int tmpinindex = inline.indexOf(','); + if(tmpinindex == -1) { + break; + } + String inname = inline.substring(0, tmpinindex); + String inint = inline.substring(tmpinindex + 1); + while(inint.startsWith(" ")) { + inint = inint.substring(1); + } + int duration = Integer.parseInt(inint); + taskinfo.put(inname, duration); + inindex = profiledata.indexOf('\n'); + } + + java.util.Random r=new java.util.Random(); + int tint = 0; + for(Iterator it_classes=state.getClassSymbolTable().getDescriptorsIterator(); it_classes.hasNext();) { + ClassDescriptor cd=(ClassDescriptor) it_classes.next(); + if(cd.hasFlags()) { + Vector rootnodes=ta.getRootNodes(cd); + if(rootnodes!=null) { + for(Iterator it_rootnodes=rootnodes.iterator(); it_rootnodes.hasNext();) { + FlagState root=(FlagState)it_rootnodes.next(); + Vector allocatingTasks = root.getAllocatingTasks(); + if(allocatingTasks != null) { + for(int k = 0; k < allocatingTasks.size(); k++) { + TaskDescriptor td = (TaskDescriptor)allocatingTasks.elementAt(k); + Vector fev = (Vector)ta.getFEdgesFromTD(td); + int numEdges = fev.size(); + int total = 100; + for(int j = 0; j < numEdges; j++) { + FEdge pfe = fev.elementAt(j); + if(numEdges - j == 1) { + pfe.setProbability(total); + } else { + if((total != 0) && (total != 1)) { + do { + tint = r.nextInt()%total; + } while(tint <= 0); + } + pfe.setProbability(tint); + total -= tint; + } + //do { + // tint = r.nextInt()%10; + // } while(tint <= 0); + //int newRate = tint; + //int newRate = (j+1)%2+1; + int newRate = 1; + String cdname = cd.getSymbol(); + if((cdname.equals("SeriesRunner")) || + (cdname.equals("MDRunner")) || + (cdname.equals("Stage")) || + (cdname.equals("AppDemoRunner")) || + (cdname.equals("FilterBankAtom"))) { + newRate = 16; + } else if(cdname.equals("SentenceParser")) { + newRate = 4; + } + //do { + // tint = r.nextInt()%100; + // } while(tint <= 0); + // int probability = tint; + int probability = 100; + pfe.addNewObjInfo(cd, newRate, probability); + } + } + } + } + } + Iterator it_flags = ta.getFlagStates(cd).iterator(); + while(it_flags.hasNext()) { + FlagState fs = (FlagState)it_flags.next(); + Iterator it_edges = fs.edges(); + int total = 100; + while(it_edges.hasNext()) { + //do { + // tint = r.nextInt()%10; + // } while(tint <= 0); + FEdge edge = (FEdge)it_edges.next(); + tint = taskinfo.get(edge.getTask().getSymbol()).intValue(); + edge.setExeTime(tint); + if(!it_edges.hasNext()) { + edge.setProbability(total); + } else { + if((total != 0) && (total != 1)) { + do { + tint = r.nextInt()%total; + } while(tint <= 0); + } + edge.setProbability(tint); + total -= tint; + } + } + } + } + } + } else { + // for test + // Randomly set the newRate and probability of FEdges + java.util.Random r=new java.util.Random(); + int tint = 0; + for(Iterator it_classes=state.getClassSymbolTable().getDescriptorsIterator(); it_classes.hasNext();) { + ClassDescriptor cd=(ClassDescriptor) it_classes.next(); + if(cd.hasFlags()) { + Vector rootnodes=ta.getRootNodes(cd); + if(rootnodes!=null) { + for(Iterator it_rootnodes=rootnodes.iterator(); it_rootnodes.hasNext();) { + FlagState root=(FlagState)it_rootnodes.next(); + Vector allocatingTasks = root.getAllocatingTasks(); + if(allocatingTasks != null) { + for(int k = 0; k < allocatingTasks.size(); k++) { + TaskDescriptor td = (TaskDescriptor)allocatingTasks.elementAt(k); + Vector fev = (Vector)ta.getFEdgesFromTD(td); + int numEdges = fev.size(); + int total = 100; + for(int j = 0; j < numEdges; j++) { + FEdge pfe = fev.elementAt(j); + if(numEdges - j == 1) { + pfe.setProbability(total); + } else { + if((total != 0) && (total != 1)) { + do { + tint = r.nextInt()%total; + } while(tint <= 0); + } + pfe.setProbability(tint); + total -= tint; + } + //do { + // tint = r.nextInt()%10; + // } while(tint <= 0); + //int newRate = tint; + //int newRate = (j+1)%2+1; + int newRate = 1; + String cdname = cd.getSymbol(); + if((cdname.equals("SeriesRunner")) || + (cdname.equals("MDRunner")) || + (cdname.equals("Stage")) || + (cdname.equals("AppDemoRunner")) || + (cdname.equals("FilterBankAtom"))) { + newRate = 16; + } else if(cdname.equals("SentenceParser")) { + newRate = 4; + } + //do { + // tint = r.nextInt()%100; + // } while(tint <= 0); + // int probability = tint; + int probability = 100; + pfe.addNewObjInfo(cd, newRate, probability); + } + } + } + } + } + + Iterator it_flags = ta.getFlagStates(cd).iterator(); + while(it_flags.hasNext()) { + FlagState fs = (FlagState)it_flags.next(); + Iterator it_edges = fs.edges(); + int total = 100; + while(it_edges.hasNext()) { + //do { + // tint = r.nextInt()%10; + // } while(tint <= 0); + tint = 3; + FEdge edge = (FEdge)it_edges.next(); + edge.setExeTime(tint); + if(!it_edges.hasNext()) { + edge.setProbability(total); + } else { + if((total != 0) && (total != 1)) { + do { + tint = r.nextInt()%total; + } while(tint <= 0); + } + edge.setProbability(tint); + total -= tint; + } } - pfe.setProbability(tint); - total -= tint; - } - /*do { - tint = r.nextInt()%10; - } while(tint <= 0);*/ - //int newRate = tint; - //int newRate = (j+1)%2+1; - int newRate = 1; - String cdname = cd.getSymbol(); - if((cdname.equals("SeriesRunner")) || - (cdname.equals("MDRunner")) || - (cdname.equals("Stage")) || - (cdname.equals("AppDemoRunner")) || - (cdname.equals("FilterBankAtom"))) { - newRate = 16; - } else if(cdname.equals("SentenceParser")) { - newRate = 4; - } - /*do { - tint = r.nextInt()%100; - } while(tint <= 0); - int probability = tint;*/ - int probability = 100; - pfe.addNewObjInfo(cd, newRate, probability); } - } } - } - - Iterator it_flags = ta.getFlagStates(cd).iterator(); - while(it_flags.hasNext()) { - FlagState fs = (FlagState)it_flags.next(); - Iterator it_edges = fs.edges(); - while(it_edges.hasNext()) { - /*do { - tint = r.nextInt()%10; - } while(tint <= 0);*/ - tint = 3; - ((FEdge)it_edges.next()).setExeTime(tint); - } } - } } // generate multiple schedulings diff --git a/Robust/src/Runtime/multicoretask.c b/Robust/src/Runtime/multicoretask.c index 36e3688e..4f629a93 100644 --- a/Robust/src/Runtime/multicoretask.c +++ b/Robust/src/Runtime/multicoretask.c @@ -17,9 +17,11 @@ #endif #ifdef RAW #ifdef RAWPROFILE +#ifdef RAWUSEIO #include "stdio.h" #include "string.h" #endif +#endif #include #include #elif defined THREADSIMULATE @@ -114,14 +116,12 @@ void releasewritelock(void* ptr); // profiling mode of RAW version #ifdef RAWPROFILE -//#include "stdio.h" -//#include "string.h" #define TASKINFOLENGTH 150 -#define INTERRUPTINFOLENGTH 500 +//#define INTERRUPTINFOLENGTH 500 bool stall; -bool isInterrupt; +//bool isInterrupt; int totalexetime; typedef struct task_info { @@ -130,17 +130,17 @@ typedef struct task_info { int endTime; } TaskInfo; -typedef struct interrupt_info { +/*typedef struct interrupt_info { int startTime; int endTime; -} InterruptInfo; +} InterruptInfo;*/ TaskInfo * taskInfoArray[TASKINFOLENGTH]; int taskInfoIndex; bool taskInfoOverflow; -InterruptInfo * interruptInfoArray[INTERRUPTINFOLENGTH]; +/*InterruptInfo * interruptInfoArray[INTERRUPTINFOLENGTH]; int interruptInfoIndex; -bool interruptInfoOverflow; +bool interruptInfoOverflow;*/ int profilestatus[NUMCORES]; // records status of each core // 1: running tasks // 0: stall @@ -149,7 +149,8 @@ void outputProfileData(); #endif #ifdef RAW -#ifdef RAWPROFILE +//#ifdef RAWPROFILE +#ifdef RAWUSEIO int main(void) { #else void begin() { @@ -233,20 +234,18 @@ int main(int argc, char **argv) { #ifdef RAWPROFILE stall = false; - isInterrupt = true; + //isInterrupt = true; totalexetime = -1; taskInfoIndex = 0; - interruptInfoIndex = 0; + /*interruptInfoIndex = 0; taskInfoOverflow = false; - interruptInfoOverflow = false; + interruptInfoOverflow = false;*/ #endif #ifdef INTERRUPT if (corenum < NUMCORES) { // set up interrupts setup_ints(); - //setup_interrupts(); - //start_gdn_avail_ints(recvMsg); raw_user_interrupts_on(); #ifdef RAWDEBUG raw_test_pass(0xee04); @@ -369,7 +368,7 @@ void run(void* arg) { } #endif*/ #ifdef RAWPROFILE - isInterrupt = false; + //isInterrupt = false; #endif while(true) { receiveObject(); @@ -454,7 +453,7 @@ void run(void* arg) { raw_user_interrupts_off(); #endif #ifdef RAWPROFILE - isInterrupt = false; + //isInterrupt = false; #endif #ifdef RAWDEBUG raw_test_pass(0xeee1); @@ -517,7 +516,7 @@ void run(void* arg) { removeItem(&objqueue, objitem); addNewItem_I(&objqueue, objInfo); #ifdef RAWPROFILE - isInterrupt = true; + //isInterrupt = true; #endif #ifdef INTERRUPT raw_user_interrupts_on(); @@ -597,7 +596,8 @@ void run(void* arg) { #ifdef RAWDEBUG raw_test_pass(0xee11); #endif -#ifdef RAWPROFILE +//#ifdef RAWPROFILE +#ifdef RAWUSEIO totalexetime = raw_get_cycle(); #else raw_test_pass(0xbbbbbbbb); @@ -1836,6 +1836,7 @@ bool transProfileRequestMsg(int targetcore) { // output the profiling data void outputProfileData() { +#ifdef RAWUSEIO FILE * fp; char fn[50]; int self_y, self_x; @@ -1904,8 +1905,7 @@ void outputProfileData() { fprintf(fp, "\nAverage task execution time: %d\n", averagetasktime); fclose(fp); - - /* +#else int i = 0; int j = 0; @@ -1930,7 +1930,7 @@ void outputProfileData() { } // output interrupt related info - for(i = 0; i < interruptInfoIndex; i++) { + /*for(i = 0; i < interruptInfoIndex; i++) { InterruptInfo* tmpIInfo = interruptInfoArray[i]; raw_test_pass(0xddde); raw_test_pass_reg(tmpIInfo->startTime); @@ -1940,10 +1940,10 @@ void outputProfileData() { if(interruptInfoOverflow) { raw_test_pass(0xefef); - } + }*/ raw_test_pass(0xeeee); - */ +#endif } #endif @@ -1975,12 +1975,12 @@ int receiveObject() { return -1; } #ifdef RAWPROFILE - if(isInterrupt && (!interruptInfoOverflow)) { + /*if(isInterrupt && (!interruptInfoOverflow)) { // raw_test_pass(0xffff); interruptInfoArray[interruptInfoIndex] = RUNMALLOC_I(sizeof(struct interrupt_info)); interruptInfoArray[interruptInfoIndex]->startTime = raw_get_cycle(); interruptInfoArray[interruptInfoIndex]->endTime = -1; - } + }*/ #endif msg: #ifdef RAWDEBUG @@ -2376,13 +2376,13 @@ msg: goto msg; } #ifdef RAWPROFILE - if(isInterrupt && (!interruptInfoOverflow)) { +/* if(isInterrupt && (!interruptInfoOverflow)) { interruptInfoArray[interruptInfoIndex]->endTime = raw_get_cycle(); interruptInfoIndex++; if(interruptInfoIndex == INTERRUPTINFOLENGTH) { interruptInfoOverflow = true; } - } + }*/ #endif return type; } else { @@ -2391,13 +2391,13 @@ msg: raw_test_pass(0xe889); #endif #ifdef RAWPROFILE - if(isInterrupt && (!interruptInfoOverflow)) { +/* if(isInterrupt && (!interruptInfoOverflow)) { interruptInfoArray[interruptInfoIndex]->endTime = raw_get_cycle(); interruptInfoIndex++; if(interruptInfoIndex == INTERRUPTINFOLENGTH) { interruptInfoOverflow = true; } - } + }*/ #endif return -2; } @@ -3610,7 +3610,7 @@ newtask: raw_user_interrupts_off(); #endif #ifdef RAWPROFILE - isInterrupt = false; + //isInterrupt = false; #endif while(!lockflag) { receiveObject(); @@ -3630,7 +3630,7 @@ newtask: reside = false; #endif #ifdef RAWPROFILE - isInterrupt = true; + //isInterrupt = true; #endif #ifdef INTERRUPT raw_user_interrupts_on(); diff --git a/Robust/src/buildscript b/Robust/src/buildscript index 565d7772..5f2a4a8b 100755 --- a/Robust/src/buildscript +++ b/Robust/src/buildscript @@ -22,6 +22,7 @@ echo "-raw generate raw version binary (should be used together with -multicore) echo "-interrupt generate raw version binary with interruption (should be used togethere with -raw)" echo "-rawconfig config raw simulator as 4xn (should be used together with -raw)" echo "-rawpath print out execute path information for raw version (should be used together with -raw)" +echo "-useprofile use profiling data for scheduling (should be used together with -raw)" echo -threadsimulate generate multi-thread simulate version binary echo -optional enable optional echo -debug generate debug symbols @@ -38,6 +39,7 @@ echo -o binary echo -nojava do not run bristlecone compiler echo -instructionfailures inject code for instructionfailures echo -profile build with profile options +echo "-rawuseio use standard io to output profiling data (should be used together with -raw and -profile), it only works with single core version" echo "-enable-assertions execute assert statements during compilation" echo -help help } @@ -57,6 +59,7 @@ RAWCONFIG='' RAWDEBUGFLAG=false RAWPATHFLAG=false RAWPROFILEFLAG=false +RAWUSEIOFLAG=false INTERRUPTFLAG=false THREADSIMULATEFLAG=false; USEDMALLOC=false @@ -128,6 +131,9 @@ elif [[ $1 = '-profile' ]] then RAWPROFILEFLAG=true EXTRAOPTIONS="$EXTRAOPTIONS -pg" +elif [[ $1 = '-rawuseio' ]] +then +RAWUSEIOFLAG=true elif [[ $1 = '-taskstate' ]] then JAVAOPTS="$JAVAOPTS -taskstate" @@ -170,6 +176,9 @@ elif [[ $1 = '-recover' ]] then RECOVERFLAG=true JAVAOPTS="$JAVAOPTS -task" +elif [[ $1 = '-useprofile' ]] +then +JAVAOPTS="$JAVAOPTS -useprofile" elif [[ $1 = '-webinterface' ]] then JAVAOPTS="$JAVAOPTS -webinterface" @@ -321,6 +330,11 @@ then # profile version RAWRGCCFLAGS="${RAWRGCCFLAGS} -DRAWPROFILE" fi +if $RAWUSEIOFLAG +then # useio version +RAWRGCCFLAGS="${RAWRGCCFLAGS} -DRAWUSEIO" +fi + if $INTERRUPTFLAG then #INTERRUPT version MAKEFILE="$MAKEFILE.i" -- 2.34.1