188 lines
5.2 KiB
C++
188 lines
5.2 KiB
C++
/*
|
|
* SimulationManager.cpp
|
|
*
|
|
* Created on: Apr 12, 2014
|
|
* Author: jonny
|
|
*/
|
|
|
|
#include <sys/wait.h>
|
|
#include <boost/filesystem.hpp>
|
|
#include "SimulationManager.h"
|
|
#include "../common/Utils.h"
|
|
using namespace std;
|
|
using namespace tinyxml2;
|
|
using namespace simulation;
|
|
|
|
namespace simulation {
|
|
|
|
SimulationManager::SimulationManager(string resources) :
|
|
silent(false), resources(resources)
|
|
{
|
|
}
|
|
|
|
SimulationManager::~SimulationManager()
|
|
{
|
|
}
|
|
|
|
void SimulationManager::loadSimulationsFromXML(string uri)
|
|
{
|
|
cout << "\n\nLoad Simulation-Batchs:" << endl;
|
|
cout << headline << endl;
|
|
cout << "\t-> load simulations .." << endl;
|
|
|
|
exportPath = getFileName(uri);
|
|
XMLDocument doc;
|
|
loadXML(uri, doc);
|
|
|
|
cout << "\t-> parsing simulation objects .." << endl;
|
|
|
|
for (XMLElement* element = doc.FirstChildElement("simulation"); element != NULL;
|
|
element = element->NextSiblingElement("simulation"))
|
|
{
|
|
parseSimulationBatch(element);
|
|
}
|
|
|
|
cout << "\t-> checking paths .." << endl;
|
|
checkPaths();
|
|
|
|
cout << "\t-> simulation batches loaded successfully!\n" << endl;
|
|
|
|
for (auto batch : simulationsBatches)
|
|
{
|
|
batch.print();
|
|
}
|
|
}
|
|
|
|
void SimulationManager::runSimulations()
|
|
{
|
|
for (auto& batch : simulationsBatches)
|
|
{
|
|
boost::filesystem::path dir(exportPath + "/" + batch.simulationName);
|
|
boost::filesystem::create_directories(dir);
|
|
|
|
for (auto& dramSetup : batch.dramSetups)
|
|
{
|
|
string memconfig = getFileName(dramSetup.memconfig);
|
|
string memspec = getFileName(dramSetup.memspec);
|
|
string addressmappig = getFileName(dramSetup.addressmapping);
|
|
|
|
for (auto& traceSetup : batch.traceSetups)
|
|
{
|
|
runSimulation(
|
|
exportPath + "/" + batch.simulationName + "/" + traceSetup.first + "-" + memspec + "-" +
|
|
memconfig + ".tdb", dramSetup, traceSetup.second);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void SimulationManager::parseSimulationBatch(XMLElement* simulation)
|
|
{
|
|
SimulationBatch batch;
|
|
|
|
batch.simulationName = simulation->Attribute("id");
|
|
|
|
string memspecUri;
|
|
string addressmappingUri;
|
|
|
|
for (XMLElement* element = simulation->FirstChildElement("memspec"); element != NULL;
|
|
element = element->NextSiblingElement("memspec"))
|
|
{
|
|
memspecUri = element->GetText();
|
|
for (XMLElement* element = simulation->FirstChildElement("addressmapping"); element != NULL;
|
|
element = element->NextSiblingElement("addressmapping"))
|
|
{
|
|
addressmappingUri = element->GetText();
|
|
for (XMLElement* element = simulation->FirstChildElement("memconfigs")->FirstChildElement("memconfig");
|
|
element != NULL; element = element->NextSiblingElement("memconfig"))
|
|
{
|
|
batch.dramSetups.push_back(DramSetup(element->GetText(), memspecUri, addressmappingUri));
|
|
}
|
|
}
|
|
}
|
|
|
|
for (XMLElement* element = simulation->FirstChildElement("trace-setups")->FirstChildElement("trace-setup"); element != NULL;
|
|
element = element->NextSiblingElement("trace-setup"))
|
|
{
|
|
addTraceSetup(batch, element);
|
|
}
|
|
|
|
simulationsBatches.push_back(batch);
|
|
|
|
}
|
|
|
|
void SimulationManager::checkPaths()
|
|
{
|
|
//reportFatal("Simulation Manager", "Not all paths in xml are valid");
|
|
}
|
|
|
|
void SimulationManager::runSimulation(string traceName, DramSetup dramSetup, vector<Device> traceSetup)
|
|
{
|
|
int pid = fork();
|
|
int status = 0;
|
|
if (pid == 0)
|
|
{
|
|
Simulation* simulation = new Simulation("sim", resources, traceName, dramSetup, traceSetup);
|
|
simulation->start();
|
|
delete simulation;
|
|
_Exit(0);
|
|
}
|
|
|
|
waitpid(pid, &status, 0);
|
|
}
|
|
|
|
void SimulationManager::startTraceAnalyzer()
|
|
{
|
|
string p = getenv("trace");
|
|
string run_tpr = p + " -f ";
|
|
for (auto batch : simulationsBatches)
|
|
{
|
|
run_tpr += exportPath + "/" + batch.simulationName + " ";
|
|
|
|
}
|
|
run_tpr += "&";
|
|
system(run_tpr.c_str());
|
|
}
|
|
|
|
void SimulationManager::addTraceSetup(SimulationBatch& batch, 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("clkMhz"), device->IntAttribute("bl")));
|
|
}
|
|
while (devices.size() < Simulation::NumberOfTracePlayers)
|
|
{
|
|
devices.push_back(Device());
|
|
}
|
|
|
|
batch.traceSetups.emplace(element->Attribute("id"), devices);
|
|
}
|
|
|
|
void SimulationManager::report(string message)
|
|
{
|
|
//DebugManager::getInstance().printDebugMessage("Simulation Manager", message);
|
|
//if (DebugManager::getInstance().writeToConsole == false)
|
|
cout << message << endl;
|
|
}
|
|
|
|
void SimulationBatch::print()
|
|
{
|
|
for (DramSetup& s : dramSetups)
|
|
{
|
|
cout << s.memspec << " - " << s.memconfig << endl;
|
|
}
|
|
cout << endl;
|
|
for (auto& s : traceSetups)
|
|
{
|
|
cout << "trace-setup " + s.first + ":\n";
|
|
for (Device d : s.second)
|
|
cout << "\t(" << d.burstLength << ") " << d.trace << ";" << endl;
|
|
cout << endl;
|
|
}
|
|
}
|
|
|
|
}
|
|
/* namespace simulation */
|
|
|