200 lines
5.8 KiB
C++
200 lines
5.8 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;
|
|
|
|
|
|
SimulationManager::SimulationManager(string resources) :
|
|
silent(false), resources(resources)
|
|
{
|
|
}
|
|
|
|
SimulationManager::~SimulationManager()
|
|
{
|
|
}
|
|
|
|
void SimulationManager::loadSimulationsFromXML(string uri)
|
|
{
|
|
cout << "\n\nload simulation-batch:" << endl;
|
|
cout << headline << endl;
|
|
|
|
exportPath = getFileName(uri);
|
|
|
|
loadXML(uri, simulationdoc);
|
|
|
|
cout << "\t-> parsing simulation objects .." << endl;
|
|
|
|
XMLElement* simulation = simulationdoc.FirstChildElement("simulation");
|
|
string xmlNodeName(simulation->Name());
|
|
if( xmlNodeName != "simulation")
|
|
reportFatal("SimulationManager", "simulation node expected");
|
|
parseSimulationBatch(simulation);
|
|
|
|
//cout << "\t-> checking paths .." << endl;
|
|
//checkPaths();
|
|
|
|
cout << "\t-> simulation batches loaded successfully!\n" << endl;
|
|
|
|
for (auto batch : simulationBatches)
|
|
{
|
|
batch.print();
|
|
}
|
|
}
|
|
|
|
void SimulationManager::runSimulations()
|
|
{
|
|
for (auto& batch : simulationBatches)
|
|
{
|
|
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)
|
|
{
|
|
// string exportname = exportPath + "/" + batch.simulationName + "/" + traceSetup.first + ".tdb";
|
|
string exportname = exportPath + "/" + traceSetup.first + ".tdb";
|
|
runSimulation(exportname, dramSetup, traceSetup.second);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void SimulationManager::parseSimulationBatch(XMLElement* simulation)
|
|
{
|
|
SimulationBatch batch;
|
|
|
|
//batch.simulationName = simulation->Attribute("id");
|
|
|
|
//string memspecUri;
|
|
//string addressmappingUri;
|
|
|
|
XMLElement* simconfig = simulation->FirstChildElement("simconfig");
|
|
|
|
XMLElement* memspecs = simulation->FirstChildElement("memspecs");
|
|
if(memspecs == NULL) memspecs = simulation;
|
|
|
|
XMLElement* addressmappings = simulation->FirstChildElement("addressmappings");
|
|
if(addressmappings == NULL) addressmappings = simulation;
|
|
|
|
XMLElement* memconfigs = simulation->FirstChildElement("memconfigs");
|
|
if(memconfigs == NULL) memconfigs = simulation;
|
|
|
|
|
|
|
|
for (XMLElement* memspec = memspecs->FirstChildElement("memspec"); memspec != NULL;
|
|
memspec = memspec->NextSiblingElement("memspec"))
|
|
{
|
|
//memspecUri = element->GetText();
|
|
|
|
for (XMLElement* addressmapping = addressmappings->FirstChildElement("addressmapping"); addressmapping != NULL;
|
|
addressmapping = addressmapping->NextSiblingElement("addressmapping"))
|
|
{
|
|
// addressmappingUri = element->GetText();
|
|
|
|
for (XMLElement* memconfig = memconfigs->FirstChildElement("memconfig");
|
|
memconfig != NULL; memconfig = memconfig->NextSiblingElement("memconfig"))
|
|
{
|
|
batch.dramSetups.push_back(DramSetup(memspec, memconfig, simconfig, addressmapping));
|
|
}
|
|
}
|
|
}
|
|
|
|
XMLElement* tracesetups = simulation->FirstChildElement("tracesetups");
|
|
if(tracesetups == NULL) tracesetups = simulation;
|
|
|
|
for (XMLElement* tracesetup = tracesetups->FirstChildElement("tracesetup"); tracesetup != NULL;
|
|
tracesetup = tracesetup->NextSiblingElement("tracesetup"))
|
|
{
|
|
addTraceSetup(batch, tracesetup);
|
|
}
|
|
|
|
simulationBatches.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 : simulationBatches)
|
|
{
|
|
// 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;
|
|
}
|
|
}
|
|
|