From b00e65a91fd342c2a5e90c8693f13cdd56346544 Mon Sep 17 00:00:00 2001 From: Janik Schlemminger Date: Sat, 12 Apr 2014 21:00:26 +0200 Subject: [PATCH 1/3] burstlength fix ddr4 --- dram/src/core/TimingCalculation.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/dram/src/core/TimingCalculation.cpp b/dram/src/core/TimingCalculation.cpp index 89fb83d5..0e49f8e8 100644 --- a/dram/src/core/TimingCalculation.cpp +++ b/dram/src/core/TimingCalculation.cpp @@ -63,17 +63,22 @@ sc_time getExecutionTime(Command command,tlm::tlm_generic_payload& payload) } else if(command == Command::Write || command == Command::WriteA) { - sc_time lengthOnDataStrobe = getBurstLengthOnDataStrobe(payload.get_streaming_width()); - if(Configuration::getInstance().DataRate == 1) - lengthOnDataStrobe -= Configuration::getInstance().Timings.clk; + sc_time lockTime;; + Configuration& config = Configuration::getInstance(); + if(config.DataRate == 1) + lockTime = getBurstLengthOnDataStrobe(payload.get_streaming_width()) - config.Timings.clk; + else //special case DDR4 -> always 4 clocks + { + lockTime = config.Timings.clk * config.BurstLength / config.DataRate; + } if (command == Command::Write) { - return config.tWL + lengthOnDataStrobe; + return config.Timings.tWL + lockTime; } else { - return config.tWL + lengthOnDataStrobe + config.tWR; + return config.Timings.tWL + lockTime + config.Timings.tWR; } } else if(command == Command::PrechargeAll) From 8d07af4431b35bf238c7e1a1cfd679eff32b37e5 Mon Sep 17 00:00:00 2001 From: Janik Schlemminger Date: Sun, 13 Apr 2014 01:30:38 +0200 Subject: [PATCH 2/3] simulation manager extended to 4 player, refactoring, porno progress bar --- dram/.settings/language.settings.xml | 4 +- .../am_ddr4.xml} | 0 .../resources/configs/amconfigs/am_wideio.xml | 27 +++++ dram/resources/simulations/first.xml | 12 +- dram/src/common/DebugManager.cpp | 3 +- dram/src/common/TlmRecorder.cpp | 1 - dram/src/common/Utils.cpp | 1 + dram/src/common/Utils.h | 21 ++-- dram/src/simulation/MemoryManager.cpp | 6 +- dram/src/simulation/Simulation.cpp | 88 +++++++++------ dram/src/simulation/Simulation.h | 14 ++- dram/src/simulation/SimulationManager.cpp | 103 +++++++++++------- dram/src/simulation/SimulationManager.h | 7 +- dram/src/simulation/main.cpp | 1 + 14 files changed, 190 insertions(+), 98 deletions(-) rename dram/resources/configs/{addressConfig.xml => amconfigs/am_ddr4.xml} (100%) create mode 100755 dram/resources/configs/amconfigs/am_wideio.xml diff --git a/dram/.settings/language.settings.xml b/dram/.settings/language.settings.xml index 26f9f756..d60268a9 100644 --- a/dram/.settings/language.settings.xml +++ b/dram/.settings/language.settings.xml @@ -4,7 +4,7 @@ - + @@ -14,7 +14,7 @@ - + diff --git a/dram/resources/configs/addressConfig.xml b/dram/resources/configs/amconfigs/am_ddr4.xml similarity index 100% rename from dram/resources/configs/addressConfig.xml rename to dram/resources/configs/amconfigs/am_ddr4.xml diff --git a/dram/resources/configs/amconfigs/am_wideio.xml b/dram/resources/configs/amconfigs/am_wideio.xml new file mode 100755 index 00000000..7494e586 --- /dev/null +++ b/dram/resources/configs/amconfigs/am_wideio.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + diff --git a/dram/resources/simulations/first.xml b/dram/resources/simulations/first.xml index 91776355..44906c04 100644 --- a/dram/resources/simulations/first.xml +++ b/dram/resources/simulations/first.xml @@ -1,13 +1,19 @@ MICRON_4Gb_DDR4-1866_8bit_A.xml + am_wideio.xml memconfig.xml - + fifo.xml + fr_fcfs_unaware.xml - + chstone-mips_32.stl + + + chstone-adpcm_32.stl + empty.stl + empty.stl empty.stl diff --git a/dram/src/common/DebugManager.cpp b/dram/src/common/DebugManager.cpp index 2fcad46a..a79c245d 100644 --- a/dram/src/common/DebugManager.cpp +++ b/dram/src/common/DebugManager.cpp @@ -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 senders) DebugManager::DebugManager() : writeToConsole(true), writeToFile(true) { - debugFile.open("debug.txt"); } void DebugManager::setDebugFile(std::string filename) diff --git a/dram/src/common/TlmRecorder.cpp b/dram/src/common/TlmRecorder.cpp index d00a3856..84fb4f2c 100644 --- a/dram/src/common/TlmRecorder.cpp +++ b/dram/src/common/TlmRecorder.cpp @@ -255,6 +255,5 @@ void TlmRecorder::closeConnection() printDebugMessage("tlmPhaseRecorder:\tEnd Recording"); sqlite3_close(db); db = NULL; - std::cout<<"connection closed"< +constexpr const char headline[] = "========================================================="; + template Val getElementFromMap(std::map& m, Key key) { @@ -39,16 +41,19 @@ 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) +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 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() diff --git a/dram/src/simulation/Simulation.cpp b/dram/src/simulation/Simulation.cpp index f2f6f7ab..77ee2b98 100644 --- a/dram/src/simulation/Simulation.cpp +++ b/dram/src/simulation/Simulation.cpp @@ -20,31 +20,8 @@ using namespace std; namespace simulation { -Simulation::Simulation(string name, string pathToResources, string traceName, DramSetup setup, - std::vector 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("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) { @@ -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 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("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<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<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) diff --git a/dram/src/simulation/Simulation.h b/dram/src/simulation/Simulation.h index 87eae6d5..7b1bbd07 100644 --- a/dram/src/simulation/Simulation.h +++ b/dram/src/simulation/Simulation.h @@ -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 *arbiter; + Arbiter *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 */ diff --git a/dram/src/simulation/SimulationManager.cpp b/dram/src/simulation/SimulationManager.cpp index ce16d9d9..9599bf95 100644 --- a/dram/src/simulation/SimulationManager.cpp +++ b/dram/src/simulation/SimulationManager.cpp @@ -25,19 +25,47 @@ SimulationManager::~SimulationManager() void SimulationManager::loadSimulationFromXML(string uri) { - simulationName = getFileName(uri); - + cout << "\n\nLoad Simulation-Batch:"< load simulation from .."< parsing simulation object .."< checking paths .."< simulation loaded successfully!\n"<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& 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()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; + } } } diff --git a/dram/src/simulation/SimulationManager.h b/dram/src/simulation/SimulationManager.h index 122e1e2e..185c4bf9 100644 --- a/dram/src/simulation/SimulationManager.h +++ b/dram/src/simulation/SimulationManager.h @@ -10,6 +10,7 @@ #include #include +#include #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 dramSetups; - std::vector> traceSetups; + std::map> traceSetups; std::string resources; void runSimulation(std::string traceName, DramSetup dramSetup, std::vector traceSetup); void addTraceSetup(tinyxml2::XMLElement* element); + void parseXML(tinyxml2::XMLDocument& doc); void checkPaths(); void printSimulationBatch(); + + void report(std::string message); }; } /* namespace simulation */ diff --git a/dram/src/simulation/main.cpp b/dram/src/simulation/main.cpp index 340881f9..822db596 100644 --- a/dram/src/simulation/main.cpp +++ b/dram/src/simulation/main.cpp @@ -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(); From 2c0f2c95a35288f980ced2845fc6815be3f40a7f Mon Sep 17 00:00:00 2001 From: Janik Schlemminger Date: Sun, 13 Apr 2014 02:17:05 +0200 Subject: [PATCH 3/3] simulation bug fix -> stop after termination delta cycle --- dram/resources/configs/memconfigs/fr_fcfs.xml | 4 ++-- .../configs/memconfigs/fr_fcfs_bankwise.xml | 11 +++++++++++ dram/resources/simulations/first.xml | 13 +++---------- dram/src/simulation/Simulation.cpp | 15 ++++++++++----- dram/src/simulation/Simulation.h | 8 +++++--- 5 files changed, 31 insertions(+), 20 deletions(-) create mode 100644 dram/resources/configs/memconfigs/fr_fcfs_bankwise.xml diff --git a/dram/resources/configs/memconfigs/fr_fcfs.xml b/dram/resources/configs/memconfigs/fr_fcfs.xml index ad54f1e4..ba84ec9e 100644 --- a/dram/resources/configs/memconfigs/fr_fcfs.xml +++ b/dram/resources/configs/memconfigs/fr_fcfs.xml @@ -3,8 +3,8 @@ - - + + diff --git a/dram/resources/configs/memconfigs/fr_fcfs_bankwise.xml b/dram/resources/configs/memconfigs/fr_fcfs_bankwise.xml new file mode 100644 index 00000000..48daa1e8 --- /dev/null +++ b/dram/resources/configs/memconfigs/fr_fcfs_bankwise.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/dram/resources/simulations/first.xml b/dram/resources/simulations/first.xml index 44906c04..619e6e4a 100644 --- a/dram/resources/simulations/first.xml +++ b/dram/resources/simulations/first.xml @@ -2,19 +2,12 @@ MICRON_4Gb_DDR4-1866_8bit_A.xml am_wideio.xml - memconfig.xml - fifo.xml - fr_fcfs_unaware.xml + fr_fcfs.xml + fr_fcfs_bankwise.xml - chstone-mips_32.stl - - - chstone-adpcm_32.stl - empty.stl - empty.stl - empty.stl + mediabench-h263encode_32.stl diff --git a/dram/src/simulation/Simulation.cpp b/dram/src/simulation/Simulation.cpp index 77ee2b98..5bbb31a7 100644 --- a/dram/src/simulation/Simulation.cpp +++ b/dram/src/simulation/Simulation.cpp @@ -22,13 +22,15 @@ namespace simulation { void Simulation::setupDebugManager(bool silent, const string& traceName) { + SC_THREAD(stop); + 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(this->name()); whiteList.push_back(TlmRecorder::senderName); whiteList.push_back(ControllerCore::senderName); whiteList.push_back(PowerDownManagerBankwise::senderName); @@ -43,9 +45,9 @@ void Simulation::setupDebugManager(bool silent, const string& traceName) } } -Simulation::Simulation(string name, string pathToResources, string traceName, DramSetup setup, std::vector devices, +Simulation::Simulation(sc_module_name name, string pathToResources, string traceName, DramSetup setup, std::vector devices, bool silent) : - traceName(traceName), senderName(name), dramSetup(setup) + traceName(traceName), dramSetup(setup) { xmlAddressDecoder::addressConfigURI = pathToResources + string("configs/amconfigs/") + setup.addressmapping; @@ -105,6 +107,7 @@ void Simulation::start() player2->start(); player3->start(); player4->start(); + sc_set_stop_mode(SC_STOP_FINISH_DELTA); sc_start(); } @@ -115,13 +118,15 @@ void inline Simulation::transactionFinished() if (remainingTransactions == 0) { cout<terminateSimulation(); + wait(sc_time(50, SC_NS)); TlmRecorder::getInstance().closeConnection(); sc_stop(); @@ -131,7 +136,7 @@ void Simulation::stop() void Simulation::report(string message) { - DebugManager::getInstance().printDebugMessage(senderName, message); + DebugManager::getInstance().printDebugMessage(this->name(), message); cout << message << endl; } diff --git a/dram/src/simulation/Simulation.h b/dram/src/simulation/Simulation.h index 7b1bbd07..c4c7a589 100644 --- a/dram/src/simulation/Simulation.h +++ b/dram/src/simulation/Simulation.h @@ -37,10 +37,11 @@ struct Device unsigned int burstLength; }; -class Simulation: public ISimulation +class Simulation: public ISimulation, public sc_module { public: - Simulation(string name, string pathToResources, string traceName, DramSetup setup, + SC_HAS_PROCESS(Simulation); + Simulation(sc_module_name name, string pathToResources, string traceName, DramSetup setup, std::vector devices, bool silent = false); ~Simulation(); @@ -52,9 +53,10 @@ public: private: std::string traceName; - std::string senderName; DramSetup dramSetup; + sc_event terminateSimulation; + Dram<> *dram; Arbiter *arbiter; Controller<> *controller;