support added for file interface. microops can be written to trace files in the ROB, and trace files can be read in runnablethread and fed into the pipelines

This commit is contained in:
Rajshekar K K 2020-09-08 23:21:54 +05:30
parent f916ed470d
commit aa5755c34e
6 changed files with 515 additions and 195 deletions

11
.gitignore vendored
View File

@ -1,9 +1,12 @@
**/bin **/bin
**/obj-pin **/obj-pin
**/obj-comm **/obj-comm
/.classpath **/.classpath
/.cproject **/.cproject
/.project **/.project
/.settings **/.settings
**/hs_err* **/hs_err*
**/*.swp **/*.swp
**/*.swo
**/*.swn
**/*.trc

View File

@ -246,8 +246,10 @@ public class XMLParser
checkIfTraceFileAlreadyExists(); checkIfTraceFileAlreadyExists();
//Emulator emulator = new Emulator(EmulatorConfig.PinTool, EmulatorConfig.PinInstrumentor,
// Main.getBenchmarkArguments(), EmulatorConfig.basenameForTraceFiles);
Emulator emulator = new Emulator(EmulatorConfig.PinTool, EmulatorConfig.PinInstrumentor, Emulator emulator = new Emulator(EmulatorConfig.PinTool, EmulatorConfig.PinInstrumentor,
Main.getBenchmarkArguments(), EmulatorConfig.basenameForTraceFiles); Main.getBenchmarkArguments(), "");
emulator.waitForEmulator(); emulator.waitForEmulator();

View File

@ -4,22 +4,30 @@
package emulatorinterface; package emulatorinterface;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.Vector; import java.util.Vector;
import java.util.zip.GZIPInputStream;
import main.ArchitecturalComponent; import main.ArchitecturalComponent;
import main.CustomObjectPool;
import main.Main; import main.Main;
import memorysystem.Cache; import memorysystem.Cache;
import memorysystem.MemorySystem; import memorysystem.MemorySystem;
import pipeline.PipelineInterface; import pipeline.PipelineInterface;
import pipeline.outoforder.OutOrderExecutionEngine;
import config.CommunicationType; import config.CommunicationType;
import config.EmulatorConfig; import config.EmulatorConfig;
import config.EmulatorType; import config.EmulatorType;
import config.MainMemoryConfig; import config.MainMemoryConfig;
import config.SimulationConfig;
import config.SystemConfig; import config.SystemConfig;
import emulatorinterface.ThreadBlockState.blockState; import emulatorinterface.ThreadBlockState.blockState;
import emulatorinterface.communication.Encoding; import emulatorinterface.communication.Encoding;
@ -32,9 +40,13 @@ import emulatorinterface.translator.x86.objparser.ObjParser;
import generic.BarrierTable; import generic.BarrierTable;
import generic.CircularPacketQueue; import generic.CircularPacketQueue;
import generic.Core; import generic.Core;
import generic.CustomInstructionPool;
import generic.GenericCircularQueue; import generic.GenericCircularQueue;
import generic.GlobalClock; import generic.GlobalClock;
import generic.Instruction; import generic.Instruction;
import generic.Operand;
import generic.OperandType;
import generic.OperationType;
import generic.Statistics; import generic.Statistics;
/* MaxNumThreads threads are created from this class. Each thread /* 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 EmulatorThreadState[] emulatorThreadState;// = new EmulatorThreadState[EMUTHREADS];
static ThreadBlockState[] threadBlockState;//=new ThreadBlockState[EMUTHREADS]; static ThreadBlockState[] threadBlockState;//=new ThreadBlockState[EMUTHREADS];
GenericCircularQueue<Instruction>[] inputToPipeline; GenericCircularQueue<Instruction>[] inputToPipeline;
FileWrite obj=new FileWrite(1,EmulatorConfig.basenameForTraceFiles); //FileWrite obj=new FileWrite(1,EmulatorConfig.basenameForTraceFiles);
// static long ignoredInstructions = 0; // static long ignoredInstructions = 0;
// QQQ re-arrange packets for use by translate instruction. // QQQ re-arrange packets for use by translate instruction.
@ -86,7 +98,8 @@ public class RunnableThread implements Encoding, Runnable {
long RAMclock; long RAMclock;
long CoreClock; long CoreClock;
BufferedReader[] traceReaders;
boolean[] tracesDoneReading;
/* /*
* This keeps on reading from the appropriate index in the shared memory * 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 * break if the threads which started do not call threadfini in the PIN (in
* case of unclean termination). Although the problem is easily fixable. * 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() { public void run() {
// create pool for emulator packets if (EmulatorConfig.emulatorType == EmulatorType.none
ArrayList<CircularPacketQueue> fromEmulatorAll = new ArrayList<CircularPacketQueue>(EMUTHREADS); && EmulatorConfig.communicationType == CommunicationType.file) {
for(int i=0; i<EMUTHREADS; i++) { //trace-file based simulation
CircularPacketQueue fromEmulator = new CircularPacketQueue(SharedMem.COUNT);
fromEmulatorAll.add(fromEmulator);
}
if(printIPTrace==true) {
numShmWrites = new long
[SystemConfig.maxNumJavaThreads*SystemConfig.numEmuThreadsPerJavaThread];
}
Packet pnew = new Packet();
boolean allover = false;
//boolean emulatorStarted = false;
// start gets reinitialized when the program actually starts for(int core = 0; core < maxCoreAssign; core++)
//Main.setStartTime(System.currentTimeMillis()); {
EmulatorThreadState threadParam; ArchitecturalComponent.getCore(core).getExecEngine().setExecutionBegun(true);
// keep on looping till there is something to read. iterates on the }
// emulator threads from which it has to read.
// tid is java thread id
// tidEmu is the local notion of pin threads for the current java thread
// tidApp is the actual tid of a pin thread
while (true) {
long microOpsReadFromFile = 0;
for (int tidEmulator = 0; tidEmulator < EMUTHREADS ; tidEmulator++) { long microOpsSentToPipelines = 0;
while(true)
CircularPacketQueue fromEmulator = fromEmulatorAll.get(tidEmulator); {
for(int core = 0; core < maxCoreAssign; core++)
threadParam = emulatorThreadState[tidEmulator]; {
if(tracesDoneReading[core] == false)
// Thread is halted on a barrier or a sleep {
if (threadParam.halted /*|| thread.finished*/) { for(int insCount = 0; insCount < 1000; insCount++)
continue; //one bug need to be fixed to remove this comment {
} if(inputToPipeline[core].spaceLeft()==0)
break;
int tidApplication = javaTid * EMUTHREADS + tidEmulator;
int numReads = 0; Instruction iNew = null;
long v = 0; String line = null;
try {
// add outstanding micro-operations to input to pipeline line = traceReaders[core].readLine();
if (threadParam.outstandingMicroOps.isEmpty() == false) { }
if(threadParam.outstandingMicroOps.size()<inputToPipeline[tidEmulator].spaceLeft()) { catch (Exception e) {
while(threadParam.outstandingMicroOps.isEmpty() == false) { e.printStackTrace();
inputToPipeline[tidEmulator].enqueue(threadParam.outstandingMicroOps.pollFirst()); misc.Error.showErrorAndExit(e.getMessage());
}
if(line==null)
iNew =Instruction.getInvalidInstruction();
else
{
microOpsReadFromFile++;
if(microOpsReadFromFile < SimulationConfig.NumInsToIgnore)
{
continue;
}
if(SimulationConfig.subsetSimulation == true
&& microOpsReadFromFile > (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 runPipelines();
// for loop. also update the variable all-over so that I can
// break from the outer while loop also. boolean allTracesDoneReading = true;
if (ipcBase.javaThreadTermination[javaTid] == true) { for(int core = 0; core < maxCoreAssign; core++)
allover = true; {
if(tracesDoneReading[core] == false)
{
allTracesDoneReading = false;
break;
}
}
if(allTracesDoneReading == true)
{
finishAllPipelines();
break; break;
} }
}
// need to do this only the first time }
if (ipcBase.javaThreadStarted[javaTid]==false) {
//emulatorStarted = true; else
//Main.setStartTime(System.currentTimeMillis()); {
ipcBase.javaThreadStarted[javaTid] = true; //PIN-based simulation
// create pool for emulator packets
ArrayList<CircularPacketQueue> fromEmulatorAll = new ArrayList<CircularPacketQueue>(EMUTHREADS);
for(int i=0; i<EMUTHREADS; i++) {
CircularPacketQueue fromEmulator = new CircularPacketQueue(SharedMem.COUNT);
fromEmulatorAll.add(fromEmulator);
}
if(printIPTrace==true) {
numShmWrites = new long
[SystemConfig.maxNumJavaThreads*SystemConfig.numEmuThreadsPerJavaThread];
}
Packet pnew = new Packet();
boolean allover = false;
//boolean emulatorStarted = false;
// start gets reinitialized when the program actually starts
//Main.setStartTime(System.currentTimeMillis());
EmulatorThreadState threadParam;
// keep on looping till there is something to read. iterates on the
// emulator threads from which it has to read.
// tid is java thread id
// tidEmu is the local notion of pin threads for the current java thread
// tidApp is the actual tid of a pin thread
while (true) {
for (int tidEmulator = 0; tidEmulator < EMUTHREADS ; tidEmulator++) {
CircularPacketQueue fromEmulator = fromEmulatorAll.get(tidEmulator);
} threadParam = emulatorThreadState[tidEmulator];
threadParam.checkStarted(); // Thread is halted on a barrier or a sleep
if (threadParam.halted /*|| thread.finished*/) {
// Process all the packets read from the communication channel continue; //one bug need to be fixed to remove this comment
while(fromEmulator.isEmpty() == false) { }
pnew = fromEmulator.dequeue();
if(EmulatorConfig.emulatorType==EmulatorType.pin && EmulatorConfig.communicationType==CommunicationType.sharedMemory && EmulatorConfig.storeExecutionTraceInAFile==true) { int tidApplication = javaTid * EMUTHREADS + tidEmulator;
try { int numReads = 0;
try { long v = 0;
obj.analysisFn(javaTid, pnew.ip, pnew.value, pnew.tgt,null);
} catch (InvalidInstructionException e) { // add outstanding micro-operations to input to pipeline
// TODO Auto-generated catch block if (threadParam.outstandingMicroOps.isEmpty() == false) {
e.printStackTrace(); if(threadParam.outstandingMicroOps.size()<inputToPipeline[tidEmulator].spaceLeft()) {
while(threadParam.outstandingMicroOps.isEmpty() == false) {
inputToPipeline[tidEmulator].enqueue(threadParam.outstandingMicroOps.pollFirst());
}
} else {
// there is no space in pipelineBuffer. So don't fetch any more instructions
continue;
} }
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }
// 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;
else { // 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) {
v = pnew.value;
if(printIPTrace==true) {
System.out.println("pinTrace["+tidApplication+"] " +
(++numShmWrites[tidApplication]) + " : " + pnew.ip);
}
// if we read -1, this means this emulator thread finished.
if (v == Encoding.THREADCOMPLETE) {
System.out.println("runnableshm : last packetList received for application-thread " +
tidApplication + " numCISC=" + pnew.ip);
//Statistics.setNumPINCISCInsn(pnew.ip, 0, tidEmulator);
threadParam.isFirstPacket = true; //preparing the thread for next packetList in same pipeline
signalFinish(tidApplication);
}
if(v == Encoding.SUBSETSIMCOMPLETE)
{
System.out.println("within SUBSETSIMCOMPLETE ");
ipcBase.javaThreadTermination[javaTid] = true;
liveJavaThreads--;
allover = true; allover = true;
break; break;
} }
// need to do this only the first time
if (ipcBase.javaThreadStarted[javaTid]==false) {
//emulatorStarted = true;
//Main.setStartTime(System.currentTimeMillis());
ipcBase.javaThreadStarted[javaTid] = true;
}
threadParam.checkStarted();
// Process all the packets read from the communication channel
while(fromEmulator.isEmpty() == false) {
pnew = fromEmulator.dequeue();
/*if(EmulatorConfig.emulatorType==EmulatorType.pin && EmulatorConfig.communicationType==CommunicationType.sharedMemory && EmulatorConfig.storeExecutionTraceInAFile==true) {
try {
try {
obj.analysisFn(javaTid, pnew.ip, pnew.value, pnew.tgt,null);
} catch (InvalidInstructionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else {
}*/
v = pnew.value;
if(printIPTrace==true) {
System.out.println("pinTrace["+tidApplication+"] " +
(++numShmWrites[tidApplication]) + " : " + pnew.ip);
}
// if we read -1, this means this emulator thread finished.
if (v == Encoding.THREADCOMPLETE) {
System.out.println("runnableshm : last packetList received for application-thread " +
tidApplication + " numCISC=" + pnew.ip);
//Statistics.setNumPINCISCInsn(pnew.ip, 0, tidEmulator);
threadParam.isFirstPacket = true; //preparing the thread for next packetList in same pipeline
signalFinish(tidApplication);
}
if(v == Encoding.SUBSETSIMCOMPLETE)
{
System.out.println("within SUBSETSIMCOMPLETE ");
ipcBase.javaThreadTermination[javaTid] = true;
liveJavaThreads--;
allover = true;
break;
}
boolean ret = processPacket(threadParam, pnew, tidEmulator);
if(ret==false) {
// There is not enough space in pipeline buffer.
// So don't process any more packets.
break;
}
}
if(printIPTrace==true) {
System.out.flush();
}
boolean ret = processPacket(threadParam, pnew, tidEmulator); // perform error check.
if(ret==false) { ipcBase.errorCheck(tidApplication, threadParam.totalRead);
// There is not enough space in pipeline buffer.
// So don't process any more packets.
if (ipcBase.javaThreadTermination[javaTid] == true) { //check if java thread is finished
allover = true;
break; 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;
}
}
} }
if(printIPTrace==true) { runPipelines();
System.out.flush(); // System.out.println("after execution n= "+n+" Thread finished ? "+threadParams[1].finished);
}
// this runnable thread can be stopped in two ways. Either the
// perform error check. // emulator threads from which it was supposed to read never
ipcBase.errorCheck(tidApplication, threadParam.totalRead); // 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
if (ipcBase.javaThreadTermination[javaTid] == true) { //check if java thread is finished // emulator threads which started have now finished, so probably
allover = true; // 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; break;
} }
//System.out.println("here"); }
if(liveJavaThreads==1)
{//System.out.println("size :"+inputToPipeline[tidEmulator].size()); finishAllPipelines();
if(inputToPipeline[tidEmulator].size()<=0)
{ if(unHandledCount!=null) {
//System.out.println("******************************continued*******************"); sorted_map.putAll(unHandledCount);
continue; System.out.println(sorted_map);
}
}
else if(liveJavaThreads>1)
{//System.out.println("live threads :"+liveJavaThreads);
if(inputToPipeline[tidEmulator].size()<=0 || liveJavaThreads>1 && statusOfOtherThreads()) {
//System.out.println("******************************continued2*******************");
continue;
}
}
} }
runPipelines(); if(EmulatorConfig.storeExecutionTraceInAFile == true)
// System.out.println("after execution n= "+n+" Thread finished ? "+threadParams[1].finished); {
for(int rob = 0; rob < ArchitecturalComponent.getCores().length; rob++)
// this runnable thread can be stopped in two ways. Either the {
// emulator threads from which it was supposed to read never try
// started(none of them) so it has to be signalled by the main {
// thread. When this happens 'all over' becomes 'true' and it ((OutOrderExecutionEngine)ArchitecturalComponent.getCore(rob).getExecEngine()).getReorderBuffer().bw.close();
// breaks out from the loop. The second situation is that all the }
// emulator threads which started have now finished, so probably catch(Exception e)
// this thread should now terminate. {
// The second condition handles this situation. e.printStackTrace();
// NOTE this ugly state management cannot be avoided unless we use misc.Error.showErrorAndExit(e.getMessage());
// 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;
} }
} }
finishAllPipelines();
if(unHandledCount!=null) {
sorted_map.putAll(unHandledCount);
System.out.println(sorted_map);
}
} }
// void errorCheck(int tidApp, int emuid, int queue_size, // void errorCheck(int tidApp, int emuid, int queue_size,
@ -389,6 +558,64 @@ public class RunnableThread implements Encoding, Runnable {
//added later by kush //added later by kush
if(SystemConfig.memControllerToUse==true) if(SystemConfig.memControllerToUse==true)
RAMclock = (long) (1 / (SystemConfig.mainMemoryConfig.tCK) * 1000000000); 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() { protected void runPipelines() {

View File

@ -36,6 +36,7 @@ public class FilePacket extends IpcBase implements Encoding {
String []basenameForBenchmarks; String []basenameForBenchmarks;
public FilePacket(String []basenameForBenchmarks) { public FilePacket(String []basenameForBenchmarks) {
/*
this.maxApplicationThreads = SystemConfig.maxNumJavaThreads*SystemConfig.numEmuThreadsPerJavaThread; this.maxApplicationThreads = SystemConfig.maxNumJavaThreads*SystemConfig.numEmuThreadsPerJavaThread;
this.basenameForBenchmarks = basenameForBenchmarks; this.basenameForBenchmarks = basenameForBenchmarks;
@ -95,6 +96,7 @@ public class FilePacket extends IpcBase implements Encoding {
} }
} }
} }
*/
} }
public void initIpc() { public void initIpc() {
@ -102,7 +104,7 @@ public class FilePacket extends IpcBase implements Encoding {
} }
public int fetchManyPackets(int tidApp, CircularPacketQueue fromEmulator) { public int fetchManyPackets(int tidApp, CircularPacketQueue fromEmulator) {
/*
if(tidApp>=maxApplicationThreads) { if(tidApp>=maxApplicationThreads) {
misc.Error.showErrorAndExit("FilePacket cannot handle tid = " + tidApp); misc.Error.showErrorAndExit("FilePacket cannot handle tid = " + tidApp);
} }
@ -204,6 +206,8 @@ public class FilePacket extends IpcBase implements Encoding {
} }
return maxSize; return maxSize;
*/
return 0;
} }
public void errorCheck(int tidApp, long totalReads) { public void errorCheck(int tidApp, long totalReads) {
@ -211,6 +215,7 @@ public class FilePacket extends IpcBase implements Encoding {
} }
public void finish() { public void finish() {
/*
for(int i=0; i<maxApplicationThreads; i++) { for(int i=0; i<maxApplicationThreads; i++) {
try { try {
if(inputBufferedReader[i] != null) { if(inputBufferedReader[i] != null) {
@ -220,5 +225,6 @@ public class FilePacket extends IpcBase implements Encoding {
e.printStackTrace(); e.printStackTrace();
} }
} }
*/
} }
} }

View File

@ -31,6 +31,7 @@ public class Main {
public static volatile boolean statFileWritten = false; public static volatile boolean statFileWritten = false;
private static String emulatorFile = " "; private static String emulatorFile = " ";
private static String[] traceFileBasename;
public static int pid; public static int pid;
public static IpcBase ipcBase; public static IpcBase ipcBase;
@ -53,23 +54,30 @@ public class Main {
Runtime.getRuntime().addShutdownHook(new ShutDownHook()); Runtime.getRuntime().addShutdownHook(new ShutDownHook());
checkCommandLineArguments(arguments); checkCommandLineArguments(arguments);
setEmulatorFile(arguments[2]);
// Read the command line arguments
String configFileName = arguments[0]; String configFileName = arguments[0];
SimulationConfig.outputFileName = arguments[1]; SimulationConfig.outputFileName = arguments[1];
executableAndArguments = new String[arguments.length-2];
// read the command line arguments for the benchmark (not emulator) here.
for(int i=2; i < arguments.length; i++) {
executableAndArguments[i-2] = arguments[i];
benchmarkArguments = benchmarkArguments + " " + arguments[i];
}
// Parse the command line arguments // Parse the command line arguments
XMLParser.parse(configFileName); XMLParser.parse(configFileName);
printStatisticsOnAsynchronousTermination = true; printStatisticsOnAsynchronousTermination = true;
if(EmulatorConfig.communicationType==CommunicationType.file){
traceFileBasename = new String[arguments.length - 2];
for(int i = 2; i < arguments.length; i++)
setTraceFileBasename(arguments[i], i-2);
}
if(EmulatorConfig.emulatorType==EmulatorType.pin){
//pin mode
setEmulatorFile(arguments[2]);
// Read the command line arguments
executableAndArguments = new String[arguments.length-2];
// read the command line arguments for the benchmark (not emulator) here.
for(int i=2; i < arguments.length; i++) {
executableAndArguments[i-2] = arguments[i];
benchmarkArguments = benchmarkArguments + " " + arguments[i];
}
}
// Initialize the statistics // Initialize the statistics
Statistics.initStatistics(); Statistics.initStatistics();
@ -81,9 +89,9 @@ public class Main {
// Create a hash-table for the static representation of the executable // Create a hash-table for the static representation of the executable
if(EmulatorConfig.emulatorType==EmulatorType.pin) { if(EmulatorConfig.emulatorType==EmulatorType.pin) {
ObjParser.buildStaticInstructionTable(getEmulatorFile()); ObjParser.buildStaticInstructionTable(getEmulatorFile());
} else if(EmulatorConfig.emulatorType==EmulatorType.none) { } /*else if(EmulatorConfig.emulatorType==EmulatorType.none) {
ObjParser.initializeThreadMicroOpsList(SystemConfig.numEmuThreadsPerJavaThread); ObjParser.initializeThreadMicroOpsList(SystemConfig.numEmuThreadsPerJavaThread);
} }*/
ObjParser.initializeDynamicInstructionBuffer(SystemConfig.numEmuThreadsPerJavaThread*SystemConfig.numEmuThreadsPerJavaThread); ObjParser.initializeDynamicInstructionBuffer(SystemConfig.numEmuThreadsPerJavaThread*SystemConfig.numEmuThreadsPerJavaThread);
ObjParser.initializeControlMicroOps(); ObjParser.initializeControlMicroOps();
@ -94,12 +102,10 @@ public class Main {
// Start communication channel before starting emulator // Start communication channel before starting emulator
// PS : communication channel must be started before starting the emulator // PS : communication channel must be started before starting the emulator
ipcBase = startCommunicationChannel(); ipcBase = startCommunicationChannel();
benchmarkThreadMapping = new BenchmarkThreadMapping(getExecutableAndArguments()); benchmarkThreadMapping = new BenchmarkThreadMapping(getTraceFileBasename());
runners = new RunnableThread[SystemConfig.maxNumJavaThreads]; runners = new RunnableThread[SystemConfig.maxNumJavaThreads];
String emulatorArguments = constructEmulatorArguments(benchmarkArguments);
//added by harveenk //added by harveenk
//uncomment for printing debug info //uncomment for printing debug info
//debugPrinter = new DebugPrinter("kush_event_log"); //debugPrinter = new DebugPrinter("kush_event_log");
@ -108,7 +114,10 @@ public class Main {
//outputLog = new DebugPrinter("output_log_CMDQ"); //outputLog = new DebugPrinter("output_log_CMDQ");
// start emulator // start emulator
startEmulator(emulatorArguments, ipcBase); if(EmulatorConfig.emulatorType==EmulatorType.pin){
String emulatorArguments = constructEmulatorArguments(benchmarkArguments);
startEmulator(emulatorArguments, ipcBase);
}
for (int i=0; i<SystemConfig.maxNumJavaThreads; i++) { for (int i=0; i<SystemConfig.maxNumJavaThreads; i++) {
runners[i] = new RunnableThread("thread"+Integer.toString(i),i, ipcBase, ArchitecturalComponent.getCores()); runners[i] = new RunnableThread("thread"+Integer.toString(i),i, ipcBase, ArchitecturalComponent.getCores());
@ -180,7 +189,7 @@ public class Main {
ipcBase = new FilePacket(getExecutableAndArguments()); ipcBase = new FilePacket(getExecutableAndArguments());
} else { } else {
ipcBase = null; ipcBase = null;
misc.Error.showErrorAndExit("Incorrect coomunication type : " + EmulatorConfig.communicationType); misc.Error.showErrorAndExit("Incorrect communication type : " + EmulatorConfig.communicationType);
} }
return ipcBase; return ipcBase;
@ -280,6 +289,14 @@ public class Main {
Main.emulatorFile = emulatorFile; Main.emulatorFile = emulatorFile;
} }
public static String[] getTraceFileBasename() {
return traceFileBasename;
}
public static void setTraceFileBasename(String inputFile, int index) {
traceFileBasename[index] = inputFile;
}
public static String[] getExecutableAndArguments() { public static String[] getExecutableAndArguments() {
return executableAndArguments; return executableAndArguments;
} }

View File

@ -12,10 +12,16 @@ import generic.RequestType;
import generic.SimulationElement; import generic.SimulationElement;
import generic.Statistics; import generic.Statistics;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.zip.GZIPOutputStream;
import main.CustomObjectPool; import main.CustomObjectPool;
import config.EmulatorConfig;
import config.EnergyConfig; import config.EnergyConfig;
import config.SimulationConfig; import config.SimulationConfig;
@ -43,6 +49,8 @@ public class ReorderBuffer extends SimulationElement{
long numAccesses; long numAccesses;
public BufferedWriter bw;
public ReorderBuffer(Core _core, OutOrderExecutionEngine execEngine) public ReorderBuffer(Core _core, OutOrderExecutionEngine execEngine)
{ {
super(PortType.Unlimited, -1, -1, -1, -1); super(PortType.Unlimited, -1, -1, -1, -1);
@ -67,7 +75,25 @@ public class ReorderBuffer extends SimulationElement{
stall5Count = 0; stall5Count = 0;
mispredCount = 0; mispredCount = 0;
branchCount = 0; branchCount = 0;
lastValidIPSeen = -1; lastValidIPSeen = -1;
if(EmulatorConfig.storeExecutionTraceInAFile == true)
{
try
{
File f = new File(EmulatorConfig.basenameForTraceFiles + "_" + core.getCore_number() + ".gz");
if(f.exists() && !f.isDirectory())
{
misc.Error.showErrorAndExit("Trace file already present : " + EmulatorConfig.basenameForTraceFiles + " !!" +
"\nKindly rename the trace file and start collecting trace again.");
}
bw = new BufferedWriter(new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(EmulatorConfig.basenameForTraceFiles + "_" + core.getCore_number() + ".gz"))));
}
catch (IOException e) {
e.printStackTrace();
misc.Error.showErrorAndExit(e.getMessage());
}
}
} }
//creates a new ROB entry, initialises it, and returns it //creates a new ROB entry, initialises it, and returns it
@ -257,6 +283,11 @@ public class ReorderBuffer extends SimulationElement{
execEngine.getCoreMemorySystem().issueLSQCommit(first); execEngine.getCoreMemorySystem().issueLSQCommit(first);
} }
if(EmulatorConfig.storeExecutionTraceInAFile == true)
{
writeInstructionToFile(firstInstruction);
}
//free ROB entry //free ROB entry
retireInstructionAtHead(); retireInstructionAtHead();
@ -358,6 +389,40 @@ public class ReorderBuffer extends SimulationElement{
} }
} }
private void writeInstructionToFile(Instruction instruction) {
try {
Instruction tmp = instruction;
bw.write(tmp.getCISCProgramCounter()+" "+tmp.getOperationType());
if(tmp.getSourceOperand1()!=null) {
bw.write(" "+tmp.getSourceOperand1()+" "+tmp.getSourceOperand1().getMemoryLocationFirstOperand()+" "+
tmp.getSourceOperand1().getMemoryLocationSecondOperand());
}
else bw.write(" null null null");
if(tmp.getSourceOperand2()!=null) {
bw.write(" "+tmp.getSourceOperand2()+" "+tmp.getSourceOperand2().getMemoryLocationFirstOperand()+" "+
tmp.getSourceOperand2().getMemoryLocationSecondOperand());
}
else bw.write(" null null null");
if(tmp.getDestinationOperand()!=null) {
bw.write(" "+tmp.getDestinationOperand()+" "+tmp.getDestinationOperand().getMemoryLocationFirstOperand()+" "+
tmp.getDestinationOperand().getMemoryLocationSecondOperand());
}
else bw.write(" null null null");
bw.write(" "+tmp.getSourceOperand1MemValue()+" "+
tmp.getSourceOperand2MemValue()+" "+tmp.getDestinationOperandMemValue()+" "+
tmp.getBranchTargetAddress()+" "+tmp.isBranchTaken()+" "+tmp.getThreadID()+" "+tmp.getSerialNo()+"\n");
}
catch(Exception e)
{
e.printStackTrace();
misc.Error.showErrorAndExit(e.getMessage());
}
}
//debug helper - print contents of ROB //debug helper - print contents of ROB
public void dump() public void dump()
{ {