diff --git a/.gitignore b/.gitignore index 626f1e1..56cb284 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,12 @@ **/bin **/obj-pin **/obj-comm -/.classpath -/.cproject -/.project -/.settings +**/.classpath +**/.cproject +**/.project +**/.settings **/hs_err* **/*.swp +**/*.swo +**/*.swn +**/*.trc diff --git a/src/simulator/config/XMLParser.java b/src/simulator/config/XMLParser.java index 7cd6d05..6010067 100755 --- a/src/simulator/config/XMLParser.java +++ b/src/simulator/config/XMLParser.java @@ -246,8 +246,10 @@ public class XMLParser checkIfTraceFileAlreadyExists(); + //Emulator emulator = new Emulator(EmulatorConfig.PinTool, EmulatorConfig.PinInstrumentor, + // Main.getBenchmarkArguments(), EmulatorConfig.basenameForTraceFiles); Emulator emulator = new Emulator(EmulatorConfig.PinTool, EmulatorConfig.PinInstrumentor, - Main.getBenchmarkArguments(), EmulatorConfig.basenameForTraceFiles); + Main.getBenchmarkArguments(), ""); emulator.waitForEmulator(); diff --git a/src/simulator/emulatorinterface/RunnableThread.java b/src/simulator/emulatorinterface/RunnableThread.java index 1c5fc81..fa19192 100755 --- a/src/simulator/emulatorinterface/RunnableThread.java +++ b/src/simulator/emulatorinterface/RunnableThread.java @@ -4,22 +4,30 @@ package emulatorinterface; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStreamReader; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.HashMap; import java.util.TreeMap; import java.util.Vector; +import java.util.zip.GZIPInputStream; import main.ArchitecturalComponent; +import main.CustomObjectPool; import main.Main; import memorysystem.Cache; import memorysystem.MemorySystem; import pipeline.PipelineInterface; +import pipeline.outoforder.OutOrderExecutionEngine; import config.CommunicationType; import config.EmulatorConfig; import config.EmulatorType; import config.MainMemoryConfig; +import config.SimulationConfig; import config.SystemConfig; import emulatorinterface.ThreadBlockState.blockState; import emulatorinterface.communication.Encoding; @@ -32,9 +40,13 @@ import emulatorinterface.translator.x86.objparser.ObjParser; import generic.BarrierTable; import generic.CircularPacketQueue; import generic.Core; +import generic.CustomInstructionPool; import generic.GenericCircularQueue; import generic.GlobalClock; import generic.Instruction; +import generic.Operand; +import generic.OperandType; +import generic.OperationType; import generic.Statistics; /* MaxNumThreads threads are created from this class. Each thread @@ -56,7 +68,7 @@ public class RunnableThread implements Encoding, Runnable { static EmulatorThreadState[] emulatorThreadState;// = new EmulatorThreadState[EMUTHREADS]; static ThreadBlockState[] threadBlockState;//=new ThreadBlockState[EMUTHREADS]; GenericCircularQueue[] inputToPipeline; - FileWrite obj=new FileWrite(1,EmulatorConfig.basenameForTraceFiles); + //FileWrite obj=new FileWrite(1,EmulatorConfig.basenameForTraceFiles); // static long ignoredInstructions = 0; // QQQ re-arrange packets for use by translate instruction. @@ -86,7 +98,8 @@ public class RunnableThread implements Encoding, Runnable { long RAMclock; long CoreClock; - + BufferedReader[] traceReaders; + boolean[] tracesDoneReading; /* * This keeps on reading from the appropriate index in the shared memory @@ -95,206 +108,362 @@ public class RunnableThread implements Encoding, Runnable { * break if the threads which started do not call threadfini in the PIN (in * case of unclean termination). Although the problem is easily fixable. */ + Operand retOp(String str1, String str2){ + //System.out.println(str1.substring(1, str1.length()-1)+" "+str2); + Operand op= new Operand(OperandType.valueOf(str1.substring(1, str1.length()-1)),Long.parseLong(str2)); + return op; + } public void run() { - // create pool for emulator packets - ArrayList fromEmulatorAll = new ArrayList(EMUTHREADS); - for(int i=0; i (SimulationConfig.NumInsToIgnore + SimulationConfig.subsetSimSize)) + { + iNew =Instruction.getInvalidInstruction(); + line = null; + } + else + { + String[] splited = line.split(" "); + iNew = CustomObjectPool.getInstructionPool().borrowObject(); + iNew.setCISCProgramCounter(Long.parseLong(splited[0])); + iNew.setOperationType(OperationType.valueOf(splited[1])); + Operand ops[] = new Operand[9]; + int i=2; + for(int k=0; k<9;k++){ + if(!splited[i].equals("null")){ + ops[k] = retOp(splited[i], splited[i+1]); + if(k!=8) i+=2; + } else{ + ops[k]=null; + if(k!=8) i+=1; + } + } + i+=1; + if(ops[0]!=null){ + ops[0].setMemoryLocationFirstOperand(ops[1]); + ops[0].setMemoryLocationSecondOperand(ops[2]); + } + if(ops[3]!=null){ + ops[3].setMemoryLocationFirstOperand(ops[4]); + ops[3].setMemoryLocationSecondOperand(ops[5]); + } + if(ops[6]!=null){ + ops[6].setMemoryLocationFirstOperand(ops[7]); + ops[6].setMemoryLocationSecondOperand(ops[8]); + } + iNew.setSourceOperand1(ops[0]); + iNew.setSourceOperand2(ops[3]); + iNew.setDestinationOperand(ops[6]); + iNew.setSourceOperand1MemValue(Long.parseLong(splited[i])); + iNew.setSourceOperand2MemValue(Long.parseLong(splited[i+1])); + iNew.setDestinationOperandMemValue(Long.parseLong(splited[i+2])); + iNew.setBranchTargetAddress(Long.parseLong(splited[i+3])); + iNew.setBranchTaken(Boolean.parseBoolean(splited[i+4])); + //iNew.setSerialNo(Long.parseLong(splited[i+6])); + } + } + + inputToPipeline[core].enqueue(iNew); + microOpsSentToPipelines++; + if(line==null) + { + tracesDoneReading[core] = true; + try + { + traceReaders[core].close(); + } + catch(Exception e) + { + e.printStackTrace(); + misc.Error.showErrorAndExit(e.getMessage()); + } + break; + } } - } else { - // there is no space in pipelineBuffer. So don't fetch any more instructions - continue; } } - - // get the number of packets to read. 'continue' and read from - // some other thread if there is nothing. - numReads = ipcBase.fetchManyPackets(tidApplication, fromEmulator); - //System.out.println("numReads = " + numReads); - if (fromEmulator.size() == 0) { - continue; - } - // update the number of read packets - threadParam.totalRead += numReads; - // If java thread itself is terminated then break out from this - // for loop. also update the variable all-over so that I can - // break from the outer while loop also. - if (ipcBase.javaThreadTermination[javaTid] == true) { - allover = true; + runPipelines(); + + boolean allTracesDoneReading = true; + for(int core = 0; core < maxCoreAssign; core++) + { + if(tracesDoneReading[core] == false) + { + allTracesDoneReading = false; + break; + } + } + + if(allTracesDoneReading == true) + { + finishAllPipelines(); break; } - - // need to do this only the first time - if (ipcBase.javaThreadStarted[javaTid]==false) { - //emulatorStarted = true; - //Main.setStartTime(System.currentTimeMillis()); - ipcBase.javaThreadStarted[javaTid] = true; + } + } + + else + { + //PIN-based simulation + + // create pool for emulator packets + ArrayList fromEmulatorAll = new ArrayList(EMUTHREADS); + for(int i=0; i1) + {//System.out.println("live threads :"+liveJavaThreads); + if(inputToPipeline[tidEmulator].size()<=0 || liveJavaThreads>1 && statusOfOtherThreads()) { + //System.out.println("******************************continued2*******************"); + continue; + } + } + } - if(printIPTrace==true) { - System.out.flush(); - } - - // perform error check. - ipcBase.errorCheck(tidApplication, threadParam.totalRead); - - - if (ipcBase.javaThreadTermination[javaTid] == true) { //check if java thread is finished - allover = true; + runPipelines(); + // System.out.println("after execution n= "+n+" Thread finished ? "+threadParams[1].finished); + + // this runnable thread can be stopped in two ways. Either the + // emulator threads from which it was supposed to read never + // started(none of them) so it has to be signalled by the main + // thread. When this happens 'all over' becomes 'true' and it + // breaks out from the loop. The second situation is that all the + // emulator threads which started have now finished, so probably + // this thread should now terminate. + // The second condition handles this situation. + // NOTE this ugly state management cannot be avoided unless we use + // some kind of a signalling mechanism between the emulator and + // simulator(TODO). + // Although this should handle most of the cases. + if (allover || (ipcBase.javaThreadStarted[javaTid]==true && emuThreadsFinished())) { + ipcBase.javaThreadTermination[javaTid] = true; break; } - //System.out.println("here"); - if(liveJavaThreads==1) - {//System.out.println("size :"+inputToPipeline[tidEmulator].size()); - if(inputToPipeline[tidEmulator].size()<=0) - { - //System.out.println("******************************continued*******************"); - continue; - } - } - else if(liveJavaThreads>1) - {//System.out.println("live threads :"+liveJavaThreads); - if(inputToPipeline[tidEmulator].size()<=0 || liveJavaThreads>1 && statusOfOtherThreads()) { - //System.out.println("******************************continued2*******************"); - continue; - } - } - + } + + finishAllPipelines(); + + if(unHandledCount!=null) { + sorted_map.putAll(unHandledCount); + System.out.println(sorted_map); } - runPipelines(); - // System.out.println("after execution n= "+n+" Thread finished ? "+threadParams[1].finished); - - // this runnable thread can be stopped in two ways. Either the - // emulator threads from which it was supposed to read never - // started(none of them) so it has to be signalled by the main - // thread. When this happens 'all over' becomes 'true' and it - // breaks out from the loop. The second situation is that all the - // emulator threads which started have now finished, so probably - // this thread should now terminate. - // The second condition handles this situation. - // NOTE this ugly state management cannot be avoided unless we use - // some kind of a signalling mechanism between the emulator and - // simulator(TODO). - // Although this should handle most of the cases. - if (allover || (ipcBase.javaThreadStarted[javaTid]==true && emuThreadsFinished())) { - ipcBase.javaThreadTermination[javaTid] = true; - break; + if(EmulatorConfig.storeExecutionTraceInAFile == true) + { + for(int rob = 0; rob < ArchitecturalComponent.getCores().length; rob++) + { + try + { + ((OutOrderExecutionEngine)ArchitecturalComponent.getCore(rob).getExecEngine()).getReorderBuffer().bw.close(); + } + catch(Exception e) + { + e.printStackTrace(); + misc.Error.showErrorAndExit(e.getMessage()); + } + } } } - - finishAllPipelines(); - - if(unHandledCount!=null) { - sorted_map.putAll(unHandledCount); - System.out.println(sorted_map); - } } // void errorCheck(int tidApp, int emuid, int queue_size, @@ -389,6 +558,64 @@ public class RunnableThread implements Encoding, Runnable { //added later by kush if(SystemConfig.memControllerToUse==true) RAMclock = (long) (1 / (SystemConfig.mainMemoryConfig.tCK) * 1000000000); + + if (EmulatorConfig.emulatorType == EmulatorType.none + && EmulatorConfig.communicationType == CommunicationType.file) { + //trace-file based simulation + + int numTotalThreads = 0; + for (int benchmark=0; benchmark < Main.getTraceFileBasename().length; benchmark++) + { + for (int tid=0; ;tid++) + { + String inputFileName = Main.getTraceFileBasename()[benchmark] + "_" + tid + ".gz"; + + try + { + File f = new File(inputFileName); + if(f.exists() && !f.isDirectory()) + { + numTotalThreads++; + } + else + { + break; + } + } + catch (Exception e) + { + break; + } + } + } + maxCoreAssign = numTotalThreads; + traceReaders = new BufferedReader[maxCoreAssign]; + tracesDoneReading = new boolean[maxCoreAssign]; + + int index = 0; + for (int benchmark=0; benchmark < Main.getTraceFileBasename().length; benchmark++) + { + for (int tid=0; ;tid++) + { + String inputFileName = Main.getTraceFileBasename()[benchmark] + "_" + tid + ".gz"; + + try { + FileInputStream f = new FileInputStream(inputFileName); + GZIPInputStream g = new GZIPInputStream(f); + InputStreamReader i = new InputStreamReader(g); + traceReaders[index++] = new BufferedReader(i); + } catch (Exception e) { + if(tid==0) { + // not able to find first file is surely an error. + misc.Error.showErrorAndExit("Error in reading input packet file " + inputFileName); + } else { + System.out.println("Number of threads for benchmark " + Main.getTraceFileBasename()[benchmark] + " : " + tid); + break; + } + } + } + } + } } protected void runPipelines() { diff --git a/src/simulator/emulatorinterface/communication/filePacket/FilePacket.java b/src/simulator/emulatorinterface/communication/filePacket/FilePacket.java index 9f824c5..67c09e7 100755 --- a/src/simulator/emulatorinterface/communication/filePacket/FilePacket.java +++ b/src/simulator/emulatorinterface/communication/filePacket/FilePacket.java @@ -36,6 +36,7 @@ public class FilePacket extends IpcBase implements Encoding { String []basenameForBenchmarks; public FilePacket(String []basenameForBenchmarks) { + /* this.maxApplicationThreads = SystemConfig.maxNumJavaThreads*SystemConfig.numEmuThreadsPerJavaThread; this.basenameForBenchmarks = basenameForBenchmarks; @@ -95,6 +96,7 @@ public class FilePacket extends IpcBase implements Encoding { } } } + */ } public void initIpc() { @@ -102,7 +104,7 @@ public class FilePacket extends IpcBase implements Encoding { } public int fetchManyPackets(int tidApp, CircularPacketQueue fromEmulator) { - + /* if(tidApp>=maxApplicationThreads) { misc.Error.showErrorAndExit("FilePacket cannot handle tid = " + tidApp); } @@ -204,6 +206,8 @@ public class FilePacket extends IpcBase implements Encoding { } return maxSize; + */ + return 0; } public void errorCheck(int tidApp, long totalReads) { @@ -211,6 +215,7 @@ public class FilePacket extends IpcBase implements Encoding { } public void finish() { + /* for(int i=0; i