diff --git a/dram/.gitignore b/dram/.gitignore index 3f6fb6f0..e125a121 100644 --- a/dram/.gitignore +++ b/dram/.gitignore @@ -2,4 +2,5 @@ *.tdb *.tdb-journal *.out -*.txt \ No newline at end of file +*.txt +/release-simulation diff --git a/dram/.settings/org.eclipse.cdt.managedbuilder.core.prefs b/dram/.settings/org.eclipse.cdt.managedbuilder.core.prefs index f2b1ad4b..c9647567 100644 --- a/dram/.settings/org.eclipse.cdt.managedbuilder.core.prefs +++ b/dram/.settings/org.eclipse.cdt.managedbuilder.core.prefs @@ -1,4 +1,12 @@ eclipse.preferences.version=1 +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/CPATH/delimiter=\: +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/CPATH/operation=remove +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/CPLUS_INCLUDE_PATH/delimiter=\: +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/CPLUS_INCLUDE_PATH/operation=remove +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/C_INCLUDE_PATH/delimiter=\: +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/C_INCLUDE_PATH/operation=remove +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/append=true +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/appendContributed=true environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443/CPATH/delimiter=\: environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443/CPATH/operation=remove environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443/CPLUS_INCLUDE_PATH/delimiter=\: @@ -7,6 +15,10 @@ environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647 environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443/C_INCLUDE_PATH/operation=remove environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443/append=true environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443/appendContributed=true +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/LIBRARY_PATH/delimiter=\: +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/LIBRARY_PATH/operation=remove +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/append=true +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/appendContributed=true environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.debug.513647443/LIBRARY_PATH/delimiter=\: environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.debug.513647443/LIBRARY_PATH/operation=remove environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.debug.513647443/append=true diff --git a/dram/resources/configs/memconfigs/memconfig.xml b/dram/resources/configs/memconfigs/memconfig.xml index e21c26b4..708e9b97 100644 --- a/dram/resources/configs/memconfigs/memconfig.xml +++ b/dram/resources/configs/memconfigs/memconfig.xml @@ -8,4 +8,4 @@ - + \ No newline at end of file diff --git a/dram/resources/simulations/first.xml b/dram/resources/simulations/first.xml new file mode 100644 index 00000000..91776355 --- /dev/null +++ b/dram/resources/simulations/first.xml @@ -0,0 +1,14 @@ + + MICRON_4Gb_DDR4-1866_8bit_A.xml + + memconfig.xml + + + + + chstone-mips_32.stl + empty.stl + + + diff --git a/dram/src/common/DebugManager.cpp b/dram/src/common/DebugManager.cpp index f0f4b3b7..2fcad46a 100644 --- a/dram/src/common/DebugManager.cpp +++ b/dram/src/common/DebugManager.cpp @@ -6,7 +6,6 @@ */ #include "DebugManager.h" - using namespace std; void DebugManager::printDebugMessage(string sender, string message) diff --git a/dram/src/common/TlmRecorder.cpp b/dram/src/common/TlmRecorder.cpp index d77184ff..5f6e7b5c 100644 --- a/dram/src/common/TlmRecorder.cpp +++ b/dram/src/common/TlmRecorder.cpp @@ -261,5 +261,6 @@ void TlmRecorder::closeConnection() printDebugMessage("tlmPhaseRecorder:\tEnd Recording"); sqlite3_close(db); db = NULL; + std::cout<<"connection closed"< #include "dramExtension.h" #include "third_party/tinyxml2.h" +#include template Val getElementFromMap(std::map& m, Key key) @@ -38,6 +39,18 @@ bool isIn(const T& value, const std::vector& collection) return false; } +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; + + float ratio = x/(float)n; + unsigned int c = (ratio * w); + std::cout << std::setw(3) << round(ratio*100) << "% ["; + for (unsigned int x=0; x controller->config.MaxNrOfTransactions) @@ -347,11 +347,13 @@ private: else if (phase == END_RD || phase == END_WR) { TlmRecorder::getInstance().recordPhase(payload, BEGIN_RESP, sc_time_stamp()); + TlmRecorder::getInstance().recordPhase(payload, END_RESP, sc_time_stamp()); sendToFrontend(payload, BEGIN_RESP, SC_ZERO_TIME); } else if (phase == END_RDA || phase == END_WRA) { TlmRecorder::getInstance().recordPhase(payload, BEGIN_RESP, sc_time_stamp()); + TlmRecorder::getInstance().recordPhase(payload, END_RESP, sc_time_stamp()); sendToFrontend(payload, BEGIN_RESP, SC_ZERO_TIME); scheduleNextPayload(bank); } diff --git a/dram/src/simulation/ISimulation.h b/dram/src/simulation/ISimulation.h new file mode 100644 index 00000000..2877656f --- /dev/null +++ b/dram/src/simulation/ISimulation.h @@ -0,0 +1,17 @@ +#ifndef ISIMULATION_H_ +#define ISIMULATION_H_ + + +namespace simulation { + +class ISimulation +{ +public: + virtual ~ISimulation(){} + virtual void transactionFinished() = 0; +}; + +} // namespace simulation + + +#endif diff --git a/dram/src/simulation/ISimulationManager.h b/dram/src/simulation/ISimulationManager.h deleted file mode 100644 index 4335496a..00000000 --- a/dram/src/simulation/ISimulationManager.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef ISIMULATIONMANAGER_H_ -#define ISIMULATIONMANAGER_H_ - - -namespace simulation { - -class ISimulationManager -{ -public: - virtual ~ISimulationManager(){} - virtual void tracePlayerFinishedCallback(string name) = 0; -}; - -} // namespace simulation - - -#endif diff --git a/dram/src/simulation/Simulation.cpp b/dram/src/simulation/Simulation.cpp new file mode 100644 index 00000000..f2f6f7ab --- /dev/null +++ b/dram/src/simulation/Simulation.cpp @@ -0,0 +1,128 @@ +/* + * SimulationManager.cpp + * + * Created on: Apr 4, 2014 + * Author: jonny + */ + +#include "Simulation.h" +#include "../common/TlmRecorder.h" +#include "../common/DebugManager.h" +#include "../common/xmlAddressdecoder.h" +#include "../core/ControllerCore.h" +#include +#include +#include +#include +#include "../common/Utils.h" + +using namespace std; + +namespace simulation { + +Simulation::Simulation(string name, string pathToResources, string traceName, DramSetup setup, + std::vector devices, bool silent) : + traceName(traceName), senderName(name) + +{ + 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("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->senderName); + whiteList.push_back(TlmRecorder::senderName); + whiteList.push_back(ControllerCore::senderName); + whiteList.push_back(PowerDownManagerBankwise::senderName); + } + + auto& dbg = DebugManager::getInstance(); + dbg.addToWhiteList(whiteList); + dbg.setDebugFile(traceName + ".txt"); + if (silent) + { + dbg.writeToConsole = false; + dbg.writeToFile = false; + } + + totalTransactions = getNumberOfLines(pathToResources + string("traces/") + devices[0].trace); + totalTransactions += getNumberOfLines(pathToResources + string("traces/") + devices[1].trace); + cout << "Total transactions: " << totalTransactions << endl; + remainingTransactions = totalTransactions; + +} + +Simulation::~Simulation() +{ + delete dram; + delete arbiter; + delete controller; + delete player1; + delete player2; +} + +void Simulation::start() +{ + cout << "Starting simulation:" << endl; + simulationStartTime = clock(); + DebugManager::getInstance().printDebugMessage(senderName, "Starting simulation"); + player1->start(); + player2->start(); + sc_set_stop_mode(SC_STOP_FINISH_DELTA); + sc_start(); +} + +void inline Simulation::transactionFinished() +{ + remainingTransactions--; + loadbar(totalTransactions - remainingTransactions, totalTransactions); + if(remainingTransactions == 0) + { + stop(); + } +} +void Simulation::stop() +{ + 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; + +} + +unsigned int Simulation::getNumberOfLines(string uri) +{ + std::ifstream file(uri); + file.unsetf(std::ios_base::skipws); // new lines will be skipped unless we stop it from happening: + // count the newlines with an algorithm specialized for counting: + unsigned lineCount = std::count(std::istream_iterator(file), std::istream_iterator(), '\n'); + return lineCount; +} + +} /* namespace simulation */ + diff --git a/dram/src/simulation/Simulation.h b/dram/src/simulation/Simulation.h new file mode 100644 index 00000000..87eae6d5 --- /dev/null +++ b/dram/src/simulation/Simulation.h @@ -0,0 +1,70 @@ +/* + * Simulation.h + * + * Created on: Apr 4, 2014 + * Author: jonny + */ + +#ifndef SIMULATION_H_ +#define SIMULATION_H_ + +#include "Dram.h" +#include "Arbiter.h" +#include "TracePlayer.h" +#include "Controller.h" +#include "ISimulation.h" +#include +#include + +namespace simulation { + +struct DramSetup +{ + DramSetup():memconfig(""),memspec(""){} + DramSetup(std::string memconfig, std::string memspec) : memconfig(memconfig), memspec(memspec) {} + std::string memconfig; + std::string memspec; +}; + +struct Device +{ + Device():trace("empty.stl"), burstLength(0){} + Device(std::string trace, unsigned int burstLength = 8) : trace(trace), burstLength(burstLength) + { + } + std::string trace; + unsigned int burstLength; +}; + +class Simulation: public ISimulation +{ +public: + Simulation(string name, string pathToResources, string traceName, DramSetup setup, + std::vector devices, bool silent = false); + ~Simulation(); + + void start(); + void stop(); + + void inline transactionFinished() override; + +private: + constexpr static unsigned int numberOfTracePlayers = 2; + std::string traceName; + std::string senderName; + Dram<> *dram; + Arbiter *arbiter; + Controller<> *controller; + + TracePlayer<> *player1; + TracePlayer<> *player2; + + unsigned int totalTransactions; + unsigned int remainingTransactions; + clock_t simulationStartTime; + unsigned int getNumberOfLines(string uri); +}; + +} /* namespace simulation */ + +#endif /* SIMULATIONMANAGER_H_ */ diff --git a/dram/src/simulation/SimulationManager.cpp b/dram/src/simulation/SimulationManager.cpp index 4099e197..ce16d9d9 100644 --- a/dram/src/simulation/SimulationManager.cpp +++ b/dram/src/simulation/SimulationManager.cpp @@ -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 -#include -#include +#include +#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 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("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 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 traceSetup) { - - clock_t begin = clock(); - - cout<<"Starting simulation"<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)<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& 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 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 */ + diff --git a/dram/src/simulation/SimulationManager.h b/dram/src/simulation/SimulationManager.h index f5b1103c..122e1e2e 100644 --- a/dram/src/simulation/SimulationManager.h +++ b/dram/src/simulation/SimulationManager.h @@ -1,62 +1,41 @@ /* * SimulationManager.h * - * Created on: Apr 4, 2014 + * Created on: Apr 12, 2014 * Author: jonny */ #ifndef SIMULATIONMANAGER_H_ #define SIMULATIONMANAGER_H_ -#include "Dram.h" -#include "Arbiter.h" -#include "TracePlayer.h" -#include "Controller.h" -#include "ISimulationManager.h" +#include #include -#include +#include "Simulation.h" +#include "../common/third_party/tinyxml2.h" namespace simulation { -struct DramSetup -{ - DramSetup():memconfig(""),memspec(""){} - DramSetup(std::string memconfig, std::string memspec) : memconfig(memconfig), memspec(memspec) {} - std::string memconfig; - std::string memspec; -}; - -struct Device -{ - Device():trace("empty.stl"), burstLength(0){} - Device(std::string trace, unsigned int burstLength = 8) : trace(trace), burstLength(burstLength) - { - } - std::string trace; - unsigned int burstLength; -}; - -class Simulation: public ISimulationManager, public sc_module +class SimulationManager { public: - SC_HAS_PROCESS(Simulation); - Simulation(sc_module_name name, string pathToResources, string traceName, DramSetup setup, - std::vector devices, bool silent = false); - ~Simulation(); - void startSimulation(); - void tracePlayerFinishedCallback(string name) override; + SimulationManager(std::string resources); + ~SimulationManager(); + + void loadSimulationFromXML(std::string uri); + void runSimulations(); + void startTraceAnalyzer(); private: - void terminationThread(); - sc_event terminateSimulation; - constexpr static unsigned int numberOfTracePlayers = 2; - std::string traceName; - Dram<> *dram; - Arbiter *arbiter; - Controller<> *controller; + std::string simulationName; - TracePlayer<> *player1; - TracePlayer<> *player2; + std::vector dramSetups; + std::vector> traceSetups; + std::string resources; + + void runSimulation(std::string traceName, DramSetup dramSetup, std::vector traceSetup); + void addTraceSetup(tinyxml2::XMLElement* element); + void checkPaths(); + void printSimulationBatch(); }; } /* namespace simulation */ diff --git a/dram/src/simulation/TracePlayer.h b/dram/src/simulation/TracePlayer.h index c6e7a6f9..daaeaa13 100644 --- a/dram/src/simulation/TracePlayer.h +++ b/dram/src/simulation/TracePlayer.h @@ -16,9 +16,11 @@ #include #include #include "MemoryManager.h" -#include "ISimulationManager.h" +#include "ISimulation.h" +#include "../core/configuration/Configuration.h" #include "../common/DebugManager.h" #include "../common/xmlAddressdecoder.h" +#include "../common/TlmRecorder.h" using namespace std; using namespace tlm; @@ -28,26 +30,25 @@ struct TracePlayer: public sc_module { public: tlm_utils::simple_initiator_socket iSocket; - TracePlayer(sc_module_name name, string pathToTrace, unsigned int burstlength, - simulation::ISimulationManager* simulationManager) : - payloadEventQueue(this, &TracePlayer::peqCallback), file(pathToTrace), burstlenght(burstlength), numberOfPendingTransactions( + TracePlayer(sc_module_name name, string pathToTrace, unsigned int burstLength, + simulation::ISimulation* simulationManager) : + payloadEventQueue(this, &TracePlayer::peqCallback), file(pathToTrace), burstlenght(burstLength), numberOfPendingTransactions( 0), transactionsSent(0), transactionsReceived(0), simulationManager( simulationManager) { if (!file.is_open()) SC_REPORT_FATAL(0, (string("Could not open trace ") + pathToTrace).c_str()); + if(burstLength == 0) + this->burstlenght = core::Configuration::getInstance().BurstLength; + iSocket.register_nb_transport_bw(this, &TracePlayer::nb_transport_bw); } void start() { bool fileIsEmpty = file.peek() == std::ifstream::traits_type::eof(); - if (fileIsEmpty) - { - simulationManager->tracePlayerFinishedCallback(name()); - } - else + if (!fileIsEmpty) { scheduleNextPayload(); } @@ -61,7 +62,7 @@ private: unsigned int numberOfPendingTransactions; unsigned int transactionsSent; unsigned int transactionsReceived; - simulation::ISimulationManager* simulationManager; + simulation::ISimulation* simulationManager; void scheduleNextPayload() { @@ -124,34 +125,31 @@ private: { payload.acquire(); sendToTarget(payload, phase, SC_ZERO_TIME); + transactionsSent++; DebugManager::getInstance().printDebugMessage(name(), "Sending transaction number: " + std::to_string(transactionsSent)); } - else if (phase == END_REQ) { scheduleNextPayload(); } else if (phase == BEGIN_RESP) { - payload.release(); sendToTarget(payload, END_RESP, SC_ZERO_TIME); + payload.release(); + + simulationManager->transactionFinished(); numberOfPendingTransactions--; transactionsReceived++; DebugManager::getInstance().printDebugMessage(name(), "Pending transactions in core: " + std::to_string(transactionsSent - transactionsReceived)); - - if (numberOfPendingTransactions == 0) - simulationManager->tracePlayerFinishedCallback(name()); } - else if (phase == END_RESP) { } - else { SC_REPORT_FATAL(0, "TracePlayer PEQ was triggered with unknown phase"); diff --git a/dram/src/simulation/main.cpp b/dram/src/simulation/main.cpp index 292f89c9..7278c54b 100644 --- a/dram/src/simulation/main.cpp +++ b/dram/src/simulation/main.cpp @@ -11,10 +11,11 @@ #include "../core/configuration/Configuration.h" #include -#include + #include #include + using namespace std; using namespace simulation; @@ -25,88 +26,22 @@ string pathOfFile(string file) return file.substr(0, file.find_last_of('/')); } -void startTraceAnalyzer(string traceName) +int main(int argc, char **argv) { - string p = getenv("trace"); - string run_tpr = p + " " + traceName; - system(run_tpr.c_str()); + return sc_main(argc, argv); } -bool runSimulation(string resources, string traceName, DramSetup setup, vector devices) -{ - int pid = fork(); - int status = 0; - if (pid == 0) - { - Simulation simulation("sim", resources, traceName, setup, devices, false); - simulation.startSimulation(); - return true; - } - waitpid(pid, &status, 0); - return false; -} - -bool batchTraces(DramSetup setup, vector> tracePairs) -{ - int id = 0; - for (pair pair : tracePairs) - { - id++; - string traceName = "batch" + to_string(id) + ".tdb"; - if (runSimulation(resources, traceName, setup, { Device(pair.first), Device(pair.second) })) - return true; //kill child - } - return false; -} - -bool batchSetups(pair tracePair, vector setups) -{ - int id = 0; - for (auto& setup : setups) - { - id++; - string traceName = "batch0" + to_string(id) + ".tdb"; - if (runSimulation(resources, traceName, setup, - { Device(tracePair.first), Device(tracePair.second) })) - return true; //kill child - } - return false; -} int sc_main(int argc, char **argv) { sc_set_time_resolution(1, SC_PS); - - resources = pathOfFile(argv[0]) + string("/../resources/"); - DramSetup setup; - setup.memconfig = "memconfig.xml"; - setup.memspec = "MatzesWideIO.xml"; - setup.memspec = "MICRON_4Gb_DDR4-1866_8bit_A.xml"; + SimulationManager manager(resources); + manager.loadSimulationFromXML("/home/jonny/git/dram.vp.system/dram/resources/simulations/first.xml"); + manager.runSimulations(); - DramSetup setup2; - setup2.memconfig = "memconfig.xml"; - setup2.memspec = "MICRON_4Gb_DDR4-1866_8bit_A.xml"; + manager.startTraceAnalyzer(); - vector> tracePairs; - tracePairs.push_back(pair("trace.stl", "empty.stl")); - tracePairs.push_back(pair("trace2.stl", "empty.stl")); - - //batchTraces(setup, tracePairs); - //batchSetups(tracePairs[0], {setup}); - - string traceName("tpr5.tdb"); - - string trace2 = "empty.stl"; - string trace1 = "chstone-jpeg_32.stl"; - trace1 = "mediabench-adpcmencode_32.stl"; - //trace1 = "mediabench-h263encode_32.stl"; - - //trace1 = "trace.stl"; - - - if (runSimulation(resources, traceName, setup, { Device(trace1), Device(trace2) })) - startTraceAnalyzer(traceName); return 0; }