/* * SimulationManager.cpp * * Created on: Apr 4, 2014 * Author: jonny */ #include "SimulationManager.h" #include "../common/TlmRecorder.h" #include "../common/DebugManager.h" #include "../common/xmlAddressdecoder.h" #include "../core/ControllerCore.h" #include #include #include using namespace std; namespace simulation { Simulation::Simulation(sc_module_name name, string pathToResources, string traceName, DramSetup setup, std::vector devices, bool silent) : traceName(traceName) { 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; TlmRecorder::getInstance().recordTracenames(devices[0].trace + "," + devices[1].trace); TlmRecorder::getInstance().recordMemspec(Configuration::memspecUri); TlmRecorder::getInstance().recordMemconfig(loadTextFileContents(Configuration::memconfigUri)); //setup dram dram = new Dram<>("dram"); arbiter = new Arbiter("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 whiteList; if (!silent) { 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(PowerDownManager::senderName); } auto& dbg = DebugManager::getInstance(); dbg.addToWhiteList(whiteList); dbg.setDebugFile(traceName + ".txt"); } Simulation::~Simulation() { delete dram; delete arbiter; delete controller; delete player1; delete player2; } void Simulation::startSimulation() { clock_t begin = clock(); 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"); } void Simulation::tracePlayerFinishedCallback(string name) { DebugManager::getInstance().printDebugMessage(this->name(), "Traceplayer " + name + " finshed"); static int finishedPlayers = 0; finishedPlayers++; if (finishedPlayers == numberOfTracePlayers) { terminateSimulation.notify(); } } void Simulation::terminationThread() { 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(); } } /* namespace simulation */