simulation manager extended to 4 player, refactoring, porno progress bar

This commit is contained in:
Janik Schlemminger
2014-04-13 01:30:38 +02:00
parent 40d6a0e6f0
commit 8d07af4431
14 changed files with 190 additions and 98 deletions

View File

@@ -4,7 +4,7 @@
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-60060699001507781" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} -E -P -v -dD &quot;${INPUTS}&quot; -std=c++11">
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-2055719358" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} -E -P -v -dD &quot;${INPUTS}&quot; -std=c++11">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
@@ -14,7 +14,7 @@
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-60060699001507781" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} -E -P -v -dD &quot;${INPUTS}&quot; -std=c++11">
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-2055719358" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} -E -P -v -dD &quot;${INPUTS}&quot; -std=c++11">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!--
<dramconfig>
<addressmap length="29">
<channel from="27" to="28" />
<bank from="24" to="26" />
<row from="11" to="23" />
<colum from="4" to="10" />
<bytes from="0" to="3" />
</addressmap>
</dramconfig>
-->
<dramconfig>
<addressmap length="29">
<channel from="27" to="28" />
<row from="14" to="26" />
<bank from="11" to="13" />
<colum from="4" to="10" />
<bytes from="0" to="3" />
<!-- <channel from="27" to="28" />
<row from="14" to="26" />
<bytes from="10" to="13" />
<colum from="3" to="9" />
<bank from="0" to="2" /> -->
</addressmap>
</dramconfig>

View File

@@ -1,13 +1,19 @@
<simulation>
<memspec>MICRON_4Gb_DDR4-1866_8bit_A.xml</memspec>
<addressmapping>am_wideio.xml</addressmapping>
<memconfigs>
<memconfig>memconfig.xml</memconfig>
<!-- <memconfig>fifo.xml</memconfig>
<memconfig>fr_fcfs_unaware.xml</memconfig>-->
<memconfig>fifo.xml</memconfig>
<memconfig>fr_fcfs_unaware.xml</memconfig>
</memconfigs>
<trace-setups>
<trace-setup>
<trace-setup id="1">
<device >chstone-mips_32.stl</device>
</trace-setup>
<trace-setup id="2">
<device >chstone-adpcm_32.stl</device>
<device >empty.stl</device>
<device >empty.stl</device>
<device >empty.stl</device>
</trace-setup>
</trace-setups>

View File

@@ -16,7 +16,7 @@ void DebugManager::printDebugMessage(string sender, string message)
if (writeToConsole)
cout << " at " << sc_time_stamp() << "\t in " << sender << "\t: " << message << endl;
if (writeToFile)
if (writeToFile && debugFile)
debugFile << " at " << sc_time_stamp() << " in " << sender << "\t: " << message << "\n";
}
#endif
@@ -36,7 +36,6 @@ void DebugManager::addToWhiteList(vector<string> senders)
DebugManager::DebugManager() :
writeToConsole(true), writeToFile(true)
{
debugFile.open("debug.txt");
}
void DebugManager::setDebugFile(std::string filename)

View File

@@ -255,6 +255,5 @@ void TlmRecorder::closeConnection()
printDebugMessage("tlmPhaseRecorder:\tEnd Recording");
sqlite3_close(db);
db = NULL;
std::cout<<"connection closed"<<endl;
}

View File

@@ -7,6 +7,7 @@
using namespace std;
using namespace tinyxml2;
void reportFatal(std::string sender, std::string message)
{
SC_REPORT_FATAL(sender.c_str(), message.c_str());

View File

@@ -17,6 +17,8 @@
#include "third_party/tinyxml2.h"
#include <iomanip>
constexpr const char headline[] = "=========================================================";
template<typename Key, typename Val>
Val getElementFromMap(std::map<Key, Val>& m, Key key)
{
@@ -39,16 +41,19 @@ bool isIn(const T& value, const std::vector<T>& collection)
return false;
}
static inline void loadbar(unsigned int x, unsigned int n, unsigned int w = 50, unsigned int granularity=1)
static inline void loadbar(unsigned int x, unsigned int n, unsigned int w = 50, unsigned int granularity = 1)
{
if ( (x != n) && (x % (n/100*granularity) != 0) ) return;
if ((x != n) && (x % (n / 100 * granularity) != 0))
return;
float ratio = x/(float)n;
unsigned int c = (ratio * w);
std::cout << std::setw(3) << round(ratio*100) << "% [";
for (unsigned int x=0; x<c; x++) std::cout << "=";
for (unsigned int x=c; x<w; x++) std::cout << " ";
std::cout << "]\r" << std::flush;
float ratio = x / (float) n;
unsigned int c = (ratio * w);
std::cout << std::setw(3) << round(ratio * 100) << "% [";
for (unsigned int x = 0; x < c; x++)
std::cout << "=";
for (unsigned int x = c; x < w; x++)
std::cout << " ";
std::cout << "]\r" << std::flush;
}
void reportFatal(std::string sender, std::string message);

View File

@@ -6,6 +6,7 @@
*/
#include "MemoryManager.h"
#include "../common/DebugManager.h"
#include <iostream>
using namespace std;
@@ -22,9 +23,8 @@ MemoryManager::~MemoryManager()
delete payload;
numberOfFrees++;
}
cout << "Memory Manager: Number of allocated payloads: " << numberOfAllocations << std::endl;
cout << "Memory Manager: Number of freed payloads: " << numberOfFrees << std::endl;
DebugManager::getInstance().printDebugMessage("MemomryManager","Number of allocated payloads: " + to_string(numberOfAllocations));
DebugManager::getInstance().printDebugMessage("MemomryManager","Number of freed payloads: " + to_string(numberOfFrees));
}
gp* MemoryManager::allocate()

View File

@@ -20,31 +20,8 @@ using namespace std;
namespace simulation {
Simulation::Simulation(string name, string pathToResources, string traceName, DramSetup setup,
std::vector<Device> devices, bool silent) :
traceName(traceName), senderName(name)
void Simulation::setupDebugManager(bool silent, const string& traceName)
{
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;
//setup dram
dram = new Dram<>("dram");
arbiter = new Arbiter<numberOfTracePlayers, 128>("arbiter");
controller = new Controller<>("controller");
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)
{
@@ -56,7 +33,6 @@ Simulation::Simulation(string name, string pathToResources, string traceName, Dr
whiteList.push_back(ControllerCore::senderName);
whiteList.push_back(PowerDownManagerBankwise::senderName);
}
auto& dbg = DebugManager::getInstance();
dbg.addToWhiteList(whiteList);
dbg.setDebugFile(traceName + ".txt");
@@ -65,12 +41,44 @@ Simulation::Simulation(string name, string pathToResources, string traceName, Dr
dbg.writeToConsole = false;
dbg.writeToFile = false;
}
}
Simulation::Simulation(string name, string pathToResources, string traceName, DramSetup setup, std::vector<Device> devices,
bool silent) :
traceName(traceName), senderName(name), dramSetup(setup)
{
xmlAddressDecoder::addressConfigURI = pathToResources + string("configs/amconfigs/") + setup.addressmapping;
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;
dram = new Dram<>("dram");
arbiter = new Arbiter<NumberOfTracePlayers, 128>("arbiter");
controller = new Controller<>("controller");
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);
player3 = new TracePlayer<>("player3", pathToResources + string("traces/") + devices[2].trace, devices[2].burstLength, this);
player4 = new TracePlayer<>("player4", pathToResources + string("traces/") + devices[3].trace, devices[3].burstLength, this);
player1->iSocket.bind(arbiter->tSockets[0]);
player2->iSocket.bind(arbiter->tSockets[1]);
player3->iSocket.bind(arbiter->tSockets[2]);
player4->iSocket.bind(arbiter->tSockets[3]);
arbiter->iSocket.bind(controller->tSocket);
controller->iSocket.bind(dram->tSocket);
setupDebugManager(silent, traceName);
totalTransactions = getNumberOfLines(pathToResources + string("traces/") + devices[0].trace);
totalTransactions += getNumberOfLines(pathToResources + string("traces/") + devices[1].trace);
cout << "Total transactions: " << totalTransactions << endl;
remainingTransactions = totalTransactions;
totalTransactions += getNumberOfLines(pathToResources + string("traces/") + devices[2].trace);
totalTransactions += getNumberOfLines(pathToResources + string("traces/") + devices[3].trace);
remainingTransactions = totalTransactions;
}
Simulation::~Simulation()
@@ -80,16 +88,23 @@ Simulation::~Simulation()
delete controller;
delete player1;
delete player2;
delete player3;
delete player4;
}
void Simulation::start()
{
cout << "Starting simulation:" << endl;
report("\n\nStarting simulation:");
report(headline);
report(" -> setup: \t\t" + getFileName(traceName));
report(" -> memspec: \t\t" + Configuration::getInstance().MemoryId);
report(" -> transactions: \t" + to_string(totalTransactions));
cout<<endl;
simulationStartTime = clock();
DebugManager::getInstance().printDebugMessage(senderName, "Starting simulation");
player1->start();
player2->start();
sc_set_stop_mode(SC_STOP_FINISH_DELTA);
player3->start();
player4->start();
sc_start();
}
@@ -97,22 +112,27 @@ void inline Simulation::transactionFinished()
{
remainingTransactions--;
loadbar(totalTransactions - remainingTransactions, totalTransactions);
if(remainingTransactions == 0)
if (remainingTransactions == 0)
{
cout<<endl;
stop();
}
}
void Simulation::stop()
{
report("\nTerminating simulation");
controller->terminateSimulation();
DebugManager::getInstance().printDebugMessage(senderName, "Terminating simulation");
TlmRecorder::getInstance().closeConnection();
sc_stop();
double elapsed_secs = double(clock() - simulationStartTime) / CLOCKS_PER_SEC;
DebugManager::getInstance().printDebugMessage(senderName, "Simulation took " + to_string(elapsed_secs) + " seconds");
cout << "\nSimulation took: " << (elapsed_secs) << endl;
report("Simulation took " + to_string(elapsed_secs) + " seconds");
}
void Simulation::report(string message)
{
DebugManager::getInstance().printDebugMessage(senderName, message);
cout << message << endl;
}
unsigned int Simulation::getNumberOfLines(string uri)

View File

@@ -21,9 +21,10 @@ namespace simulation {
struct DramSetup
{
DramSetup():memconfig(""),memspec(""){}
DramSetup(std::string memconfig, std::string memspec) : memconfig(memconfig), memspec(memspec) {}
DramSetup(std::string memconfig, std::string memspec, std::string addressmapping) : memconfig(memconfig), memspec(memspec), addressmapping(addressmapping) {}
std::string memconfig;
std::string memspec;
std::string addressmapping;
};
struct Device
@@ -47,22 +48,29 @@ public:
void stop();
void inline transactionFinished() override;
constexpr static unsigned int NumberOfTracePlayers = 4;
private:
constexpr static unsigned int numberOfTracePlayers = 2;
std::string traceName;
std::string senderName;
DramSetup dramSetup;
Dram<> *dram;
Arbiter<numberOfTracePlayers, 128> *arbiter;
Arbiter<NumberOfTracePlayers, 128> *arbiter;
Controller<> *controller;
TracePlayer<> *player1;
TracePlayer<> *player2;
TracePlayer<> *player3;
TracePlayer<> *player4;
unsigned int totalTransactions;
unsigned int remainingTransactions;
clock_t simulationStartTime;
unsigned int getNumberOfLines(string uri);
void report(std::string message);
void setupDebugManager(bool silent, const string& traceName);
};
} /* namespace simulation */

View File

@@ -25,19 +25,47 @@ SimulationManager::~SimulationManager()
void SimulationManager::loadSimulationFromXML(string uri)
{
simulationName = getFileName(uri);
cout << "\n\nLoad Simulation-Batch:"<<endl;
cout << headline<< endl;
cout << "\t-> load simulation from .."<<endl;
XMLDocument doc;
loadXML(uri, doc);
XMLElement* simulation = doc.FirstChildElement("simulation");
cout << "\t-> parsing simulation object .."<<endl;
simulationName = getFileName(uri);
parseXML(doc);
cout << "\t-> checking paths .."<<endl;
checkPaths();
cout << "\t-> simulation loaded successfully!\n"<<endl;
printSimulationBatch();
}
void SimulationManager::runSimulations()
{
system(string("mkdir -p " + simulationName).c_str());
for (auto& dramSetup : dramSetups)
{
string memconfig = getFileName(dramSetup.memconfig);
for (auto& traceSetup : traceSetups)
{
runSimulation(simulationName + "/" + memconfig + "-" + traceSetup.first + ".tdb", dramSetup, traceSetup.second);
}
}
}
void SimulationManager::parseXML(XMLDocument& doc)
{
XMLElement* simulation = doc.FirstChildElement("simulation");
string memspecUri = simulation->FirstChildElement("memspec")->GetText();
string addressmappingUri = simulation->FirstChildElement("addressmapping")->GetText();
for (XMLElement* element = simulation->FirstChildElement("memconfigs")->FirstChildElement("memconfig"); element != NULL;
element = element->NextSiblingElement("memconfig"))
{
dramSetups.push_back(DramSetup(element->GetText(), memspecUri));
dramSetups.push_back(DramSetup(element->GetText(), memspecUri, addressmappingUri));
}
for (XMLElement* element = simulation->FirstChildElement("trace-setups")->FirstChildElement("trace-setup"); element != NULL;
@@ -45,23 +73,6 @@ void SimulationManager::loadSimulationFromXML(string uri)
{
addTraceSetup(element);
}
checkPaths();
}
void SimulationManager::runSimulations()
{
system(string("mkdir " + simulationName).c_str());
printSimulationBatch();
int i = 0;
for (auto dramSetup : dramSetups)
{
for (auto traceSetup : traceSetups)
{
i++;
runSimulation(simulationName+"/tpr" + to_string(i) + ".tdb", dramSetup, traceSetup);
}
}
}
void SimulationManager::checkPaths()
@@ -75,7 +86,7 @@ void SimulationManager::runSimulation(string traceName, DramSetup dramSetup, vec
int status = 0;
if (pid == 0)
{
Simulation* simulation = new Simulation("sim", resources, traceName, dramSetup, traceSetup);
Simulation* simulation = new Simulation("sim", resources, traceName, dramSetup, traceSetup, silent);
simulation->start();
delete simulation;
_Exit(0);
@@ -84,27 +95,10 @@ void SimulationManager::runSimulation(string traceName, DramSetup dramSetup, vec
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 SimulationManager::startTraceAnalyzer()
{
string p = getenv("trace");
string run_tpr = p + " -f " + simulationName;
string run_tpr = p + " -f " + simulationName + "&";
system(run_tpr.c_str());
}
@@ -115,7 +109,34 @@ void SimulationManager::addTraceSetup(tinyxml2::XMLElement* element)
{
devices.push_back(Device(device->GetText(), device->IntAttribute("bl")));
}
traceSetups.push_back(devices);
while(devices.size()<Simulation::NumberOfTracePlayers)
{
devices.push_back(Device());
}
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 SimulationManager::printSimulationBatch()
{
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;
}
}
}

View File

@@ -10,6 +10,7 @@
#include <vector>
#include <string>
#include <map>
#include "Simulation.h"
#include "../common/third_party/tinyxml2.h"
@@ -25,17 +26,21 @@ public:
void runSimulations();
void startTraceAnalyzer();
bool silent = false;
private:
std::string simulationName;
std::vector<simulation::DramSetup> dramSetups;
std::vector<std::vector<Device>> traceSetups;
std::map<std::string, std::vector<Device>> traceSetups;
std::string resources;
void runSimulation(std::string traceName, DramSetup dramSetup, std::vector<Device> traceSetup);
void addTraceSetup(tinyxml2::XMLElement* element);
void parseXML(tinyxml2::XMLDocument& doc);
void checkPaths();
void printSimulationBatch();
void report(std::string message);
};
} /* namespace simulation */

View File

@@ -39,6 +39,7 @@ int sc_main(int argc, char **argv)
SimulationManager manager(resources);
manager.loadSimulationFromXML(resources + "/simulations/" + simulationToRun);
manager.silent = true;
manager.runSimulations();
manager.startTraceAnalyzer();