cool simulation manager
This commit is contained in:
@@ -1,127 +1,123 @@
|
||||
/*
|
||||
* SimulationManager.cpp
|
||||
*
|
||||
* Created on: Apr 4, 2014
|
||||
* Created on: Apr 12, 2014
|
||||
* Author: jonny
|
||||
*/
|
||||
|
||||
#include "SimulationManager.h"
|
||||
#include "../common/TlmRecorder.h"
|
||||
#include "../common/DebugManager.h"
|
||||
#include "../common/xmlAddressdecoder.h"
|
||||
#include "../core/ControllerCore.h"
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <sys/wait.h>
|
||||
#include "../common/Utils.h"
|
||||
using namespace std;
|
||||
using namespace tinyxml2;
|
||||
using namespace simulation;
|
||||
|
||||
namespace simulation {
|
||||
|
||||
Simulation::Simulation(sc_module_name name, string pathToResources, string traceName,
|
||||
DramSetup setup, std::vector<Device> devices, bool silent) :
|
||||
traceName(traceName)
|
||||
|
||||
SimulationManager::SimulationManager(string resources) :
|
||||
resources(resources)
|
||||
{
|
||||
SC_THREAD(terminationThread);
|
||||
}
|
||||
|
||||
xmlAddressDecoder::addressConfigURI = pathToResources + string("configs/addressConfig.xml");
|
||||
TlmRecorder::dbName = traceName;
|
||||
TlmRecorder::sqlScriptURI = pathToResources + string("scripts/createTraceDB.sql");
|
||||
Configuration::memconfigUri = pathToResources + string("configs/memconfigs/") + setup.memconfig;
|
||||
Configuration::memspecUri = pathToResources + string("configs/memspecs/") + setup.memspec;
|
||||
SimulationManager::~SimulationManager()
|
||||
{
|
||||
}
|
||||
|
||||
//setup dram
|
||||
dram = new Dram<>("dram");
|
||||
arbiter = new Arbiter<numberOfTracePlayers, 128>("arbiter");
|
||||
controller = new Controller<>("controller");
|
||||
void SimulationManager::loadSimulationFromXML(string uri)
|
||||
{
|
||||
simulationName = getFileName(uri);
|
||||
|
||||
//setup devices
|
||||
for (auto& d : devices)
|
||||
XMLDocument doc;
|
||||
loadXML(uri, doc);
|
||||
|
||||
XMLElement* simulation = doc.FirstChildElement("simulation");
|
||||
|
||||
string memspecUri = simulation->FirstChildElement("memspec")->GetText();
|
||||
|
||||
for (XMLElement* element = simulation->FirstChildElement("memconfigs")->FirstChildElement("memconfig"); element != NULL;
|
||||
element = element->NextSiblingElement("memconfig"))
|
||||
{
|
||||
if (d.burstLength == 0)
|
||||
d.burstLength = Configuration::getInstance().BurstLength;
|
||||
dramSetups.push_back(DramSetup(element->GetText(), memspecUri));
|
||||
}
|
||||
|
||||
player1 = new TracePlayer<>("player1", pathToResources + string("traces/") + devices[0].trace,
|
||||
devices[0].burstLength, this);
|
||||
player2 = new TracePlayer<>("player2", pathToResources + string("traces/") + devices[1].trace,
|
||||
devices[1].burstLength, this);
|
||||
|
||||
player1->iSocket.bind(arbiter->tSockets[0]);
|
||||
player2->iSocket.bind(arbiter->tSockets[1]);
|
||||
arbiter->iSocket.bind(controller->tSocket);
|
||||
controller->iSocket.bind(dram->tSocket);
|
||||
|
||||
vector<string> whiteList;
|
||||
if (!silent)
|
||||
for (XMLElement* element = simulation->FirstChildElement("trace-setups")->FirstChildElement("trace-setup"); element != NULL;
|
||||
element = element->NextSiblingElement("trace-setup"))
|
||||
{
|
||||
whiteList.push_back(controller->name());
|
||||
whiteList.push_back(player2->name());
|
||||
whiteList.push_back(player1->name());
|
||||
whiteList.push_back(this->name());
|
||||
whiteList.push_back(TlmRecorder::senderName);
|
||||
whiteList.push_back(ControllerCore::senderName);
|
||||
whiteList.push_back(PowerDownManagerBankwise::senderName);
|
||||
addTraceSetup(element);
|
||||
}
|
||||
|
||||
auto& dbg = DebugManager::getInstance();
|
||||
dbg.addToWhiteList(whiteList);
|
||||
dbg.setDebugFile(traceName + ".txt");
|
||||
if (silent)
|
||||
checkPaths();
|
||||
}
|
||||
|
||||
void SimulationManager::runSimulations()
|
||||
{
|
||||
system(string("mkdir " + simulationName).c_str());
|
||||
printSimulationBatch();
|
||||
int i = 0;
|
||||
for (auto dramSetup : dramSetups)
|
||||
{
|
||||
dbg.writeToConsole = false;
|
||||
dbg.writeToFile = false;
|
||||
for (auto traceSetup : traceSetups)
|
||||
{
|
||||
i++;
|
||||
runSimulation(simulationName+"/tpr" + to_string(i) + ".tdb", dramSetup, traceSetup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Simulation::~Simulation()
|
||||
void SimulationManager::checkPaths()
|
||||
{
|
||||
delete dram;
|
||||
delete arbiter;
|
||||
delete controller;
|
||||
delete player1;
|
||||
delete player2;
|
||||
//reportFatal("Simulation Manager", "Not all paths in xml are valid");
|
||||
}
|
||||
|
||||
void Simulation::startSimulation()
|
||||
void SimulationManager::runSimulation(string traceName, DramSetup dramSetup, vector<Device> traceSetup)
|
||||
{
|
||||
|
||||
clock_t begin = clock();
|
||||
|
||||
cout<<"Starting simulation"<<endl;
|
||||
DebugManager::getInstance().printDebugMessage(name(), "Starting simulation");
|
||||
player1->start();
|
||||
player2->start();
|
||||
sc_start();
|
||||
|
||||
clock_t end = clock();
|
||||
double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
|
||||
DebugManager::getInstance().printDebugMessage(name(),
|
||||
"Simulation took " + to_string(elapsed_secs) + " seconds");
|
||||
cout<<"took "<<(elapsed_secs)<<endl;
|
||||
}
|
||||
|
||||
void Simulation::tracePlayerFinishedCallback(string name)
|
||||
{
|
||||
|
||||
DebugManager::getInstance().printDebugMessage(this->name(), "Traceplayer " + name + " finshed");
|
||||
static int finishedPlayers = 0;
|
||||
finishedPlayers++;
|
||||
if (finishedPlayers == numberOfTracePlayers)
|
||||
int pid = fork();
|
||||
int status = 0;
|
||||
if (pid == 0)
|
||||
{
|
||||
terminateSimulation.notify();
|
||||
Simulation* simulation = new Simulation("sim", resources, traceName, dramSetup, traceSetup);
|
||||
simulation->start();
|
||||
delete simulation;
|
||||
_Exit(0);
|
||||
}
|
||||
|
||||
waitpid(pid, &status, 0);
|
||||
}
|
||||
|
||||
void SimulationManager::printSimulationBatch()
|
||||
{
|
||||
cout << "Simulation Batch:\n##################" << endl;
|
||||
for (DramSetup& s : dramSetups)
|
||||
{
|
||||
cout << s.memspec << " - " << s.memconfig << endl;
|
||||
}
|
||||
cout << endl;
|
||||
for (vector<Device>& s : traceSetups)
|
||||
{
|
||||
cout << "Simulation:\n";
|
||||
for (Device d : s)
|
||||
cout << "\t(" << d.burstLength << ") " << d.trace << ";" << endl;
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Simulation::terminationThread()
|
||||
void SimulationManager::startTraceAnalyzer()
|
||||
{
|
||||
wait(terminateSimulation);
|
||||
DebugManager::getInstance().printDebugMessage(this->name(), "Terminating simulation");
|
||||
controller->terminateSimulation();
|
||||
//waits for the termination of all pending powerdown phases in the dram system
|
||||
wait(sc_time(50, SC_NS));
|
||||
TlmRecorder::getInstance().closeConnection();
|
||||
sc_stop();
|
||||
string p = getenv("trace");
|
||||
string run_tpr = p + " -f " + simulationName;
|
||||
system(run_tpr.c_str());
|
||||
}
|
||||
|
||||
} /* namespace simulation */
|
||||
void SimulationManager::addTraceSetup(tinyxml2::XMLElement* element)
|
||||
{
|
||||
vector<Device> devices;
|
||||
for (XMLElement* device = element->FirstChildElement("device"); device != NULL; device = device->NextSiblingElement("device"))
|
||||
{
|
||||
devices.push_back(Device(device->GetText(), device->IntAttribute("bl")));
|
||||
}
|
||||
traceSetups.push_back(devices);
|
||||
}
|
||||
|
||||
}
|
||||
/* namespace simulation */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user