From 21e43468f47daf48d5fdf35dae3a7668749d94e0 Mon Sep 17 00:00:00 2001 From: Matthias Jung Date: Thu, 16 Feb 2017 21:03:43 +0100 Subject: [PATCH 01/19] First efforts to remove simulation manager --- DRAMSys/simulator/simulator.pro | 6 +- DRAMSys/simulator/src/simulation/dramSys.cpp | 238 +++++++++++++++++++ DRAMSys/simulator/src/simulation/dramSys.h | 155 ++++++++++++ DRAMSys/simulator/src/simulation/main.cpp | 32 +-- 4 files changed, 404 insertions(+), 27 deletions(-) create mode 100644 DRAMSys/simulator/src/simulation/dramSys.cpp create mode 100644 DRAMSys/simulator/src/simulation/dramSys.h diff --git a/DRAMSys/simulator/simulator.pro b/DRAMSys/simulator/simulator.pro index 593718da..2126dd95 100644 --- a/DRAMSys/simulator/simulator.pro +++ b/DRAMSys/simulator/simulator.pro @@ -90,8 +90,7 @@ SOURCES += \ src/controller/core/TimingCalculation.cpp \ src/controller/core/Slots.cpp \ src/controller/core/ControllerCore.cpp \ - src/simulation/SimulationManager.cpp \ - src/simulation/Simulation.cpp \ + src/simulation/dramSys.cpp \ src/simulation/MemoryManager.cpp \ src/simulation/main.cpp \ src/simulation/TemperatureController.cpp \ @@ -144,8 +143,7 @@ HEADERS += \ src/controller/core/Slots.h \ src/controller/core/ControllerCore.h \ src/simulation/TracePlayer.h \ - src/simulation/SimulationManager.h \ - src/simulation/Simulation.h \ + src/simulation/dramSys.h \ src/simulation/MemoryManager.h \ src/simulation/Dram.h \ src/simulation/Arbiter.h \ diff --git a/DRAMSys/simulator/src/simulation/dramSys.cpp b/DRAMSys/simulator/src/simulation/dramSys.cpp new file mode 100644 index 00000000..12058f97 --- /dev/null +++ b/DRAMSys/simulator/src/simulation/dramSys.cpp @@ -0,0 +1,238 @@ +/* + * Copyright (c) 2015, University of Kaiserslautern + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Authors: + * Janik Schlemminger + * Matthias Jung + * Eder F. Zulian + * Felipe S. Prado + */ + +#include +#include +#include +#include + +#include "dramSys.h" +#include "../common/TlmRecorder.h" +#include "../common/DebugManager.h" +#include "../common/xmlAddressdecoder.h" +#include "../controller/core/ControllerCore.h" +#include "../controller/core/configuration/ConfigurationLoader.h" +#include "../common/Utils.h" +#include "../simulation/TemperatureController.h" +#include "../controller/Controller.h" + +using namespace std; + +dramSys::dramSys(sc_module_name __attribute__((unused)) name, + string memspec, + string mcconfig, + string amconfig) +{ + logo(); + + SC_THREAD(stop); + + // TODO: + + cout << memspec << endl; + cout << mcconfig << endl; + cout << amconfig << endl; + + // The xmlAddressDecoder MUST be initialized before calling the + // ConfigurationLoader because some information from the xmlAddressDecoder + // is needed to assure the coherence of the configuration. + xmlAddressDecoder::Initialize(setup.addressmapping); + xmlAddressDecoder::getInstance().print(); + + ConfigurationLoader::loadMCConfig(Configuration::getInstance(), setup.mcconfig); + ConfigurationLoader::loadMemSpec(Configuration::getInstance(), setup.memspec); + ConfigurationLoader::loadSimConfig(Configuration::getInstance(), setup.simconfig); + ConfigurationLoader::loadTemperatureSimConfig(Configuration::getInstance(), setup.thermalsimconfig); + + instantiateModules(traceName, setup.pathToResources); + bindSockets(); + setupDebugManager(traceName); +} + +void dramSys::logo() +{ + #define REDTXT(s) string(("\033[0;31m"+string((s))+"\033[0m")) + #define BOLDBLUETXT(s) string(("\033[1;34m"+string((s))+"\033[0m")) + cout << endl; + cout << REDTXT(" |||") << endl; + cout << REDTXT(" +---+ Microelectronic Systems") << endl; + cout << REDTXT("=| |= Design Research Group") << endl; + cout << REDTXT("=| |= ") << BOLDBLUETXT("University of Kaiserslautern") << endl; + cout << REDTXT(" +---+ ") << endl; + cout << REDTXT(" ||| ") << "DRAMSys - Approximately-Timed TLM Models for DDR and Wide I/0 DRAM -" << endl; + cout << endl; + #undef REDTXT + #undef BOLDBLUETXT +} + +void dramSys::setupDebugManager(const string& traceName) +{ + auto& dbg = DebugManager::getInstance(); + dbg.writeToConsole = true; + dbg.writeToFile = true; + if(dbg.writeToFile) + dbg.openDebugFile(traceName + ".txt"); +} + +void dramSys::setupTlmRecorders(const string &traceName, const string &pathToResources) +{ + // Create TLM Recorders, one per channel. + for (size_t i = 0; i < Configuration::getInstance().NumberOfMemChannels; i++) { + std::string sqlScriptURI = pathToResources + string("scripts/createTraceDB.sql"); + std::string dbName = traceName + string("_channel") + std::to_string(i) + ".tdb"; + std::string recorderName = "tlmRecorder" + std::to_string(i); + TlmRecorder *tlmRecorder = new TlmRecorder(recorderName.c_str(), sqlScriptURI.c_str(), dbName.c_str(), Configuration::getInstance().DatabaseRecording); + + tlmRecorder->recordMCconfig(Configuration::getInstance().mcconfigUri); + tlmRecorder->recordMemspec(Configuration::getInstance().memspecUri); + + tlmRecorders.push_back(tlmRecorder); + + std::string traceNames = "FOO"; /// TODO + //for (size_t i = 0; i < devices.size(); i++) { + // traceNames.append(devices[i].trace); + // if (i == devices.size() - 1) + // continue; + // traceNames.append(","); + //} + tlmRecorder->recordTracenames(traceNames); + } +} + +void dramSys::instantiateModules(const string &traceName, const string &pathToResources) +{ + // The first call to getInstance() creates the Temperature Controller. + // The same instance will be accessed by all other modules. + TemperatureController::getInstance(); + + // Create and properly initialize TLM recorders. They need to be ready before creating some modules. + setupTlmRecorders(traceName, pathToResources); + + arbiter = new Arbiter("arbiter"); + arbiter->setTlmRecorders(tlmRecorders); + + + for (size_t i = 0; i < Configuration::getInstance().NumberOfMemChannels; i++) { + std::string str = "controller" + std::to_string(i); + Controller *controller = new Controller(str.c_str(), tlmRecorders[i]); + controllers.push_back(controller); + + str = "dram" + std::to_string(i); + Dram *dram = new Dram(str.c_str()); + dram->setTlmRecorder(tlmRecorders[i]); + dram->setDramController(controllers[i]); + drams.push_back(dram); + + if(Configuration::getInstance().CheckTLM2Protocol) { + str = "TLMCheckerController"+ std::to_string(i); + tlm_utils::tlm2_base_protocol_checker<> * controllerTlmChecker = new tlm_utils::tlm2_base_protocol_checker<>(str.c_str()); + controllersTlmCheckers.push_back(controllerTlmChecker); + } + } +} + +void dramSys::bindSockets() +{ + tSocket.bind(arbiter->tSocket); + if(Configuration::getInstance().CheckTLM2Protocol) { + + for (size_t i = 0; i < Configuration::getInstance().NumberOfMemChannels; i++) { + arbiter->iSocket.bind(controllersTlmCheckers[i]->target_socket); + controllersTlmCheckers[i]->initiator_socket.bind(controllers[i]->tSocket); + controllers[i]->iSocket.bind(drams[i]->tSocket); + } + } else { + for (size_t i = 0; i < Configuration::getInstance().NumberOfMemChannels; i++) { + arbiter->iSocket.bind(controllers[i]->tSocket); + controllers[i]->iSocket.bind(drams[i]->tSocket); + } + } +} + +dramSys::~dramSys() +{ + + delete arbiter; + + for (auto controller : controllers) { + delete controller; + } + + for (auto dram : drams) { + delete dram; + } + + for (auto rec : tlmRecorders) { + delete rec; + } + + for (auto tlmChecker : controllersTlmCheckers) { + delete tlmChecker; + } +} + + +void dramSys::stop() +{ + wait(terminateSimulation); + + unsigned int pending_payloads = 0; + do { + pending_payloads = 0; + for (auto controller : controllers) { + pending_payloads += controller->getTotalNumberOfPayloadsInSystem(); + } + wait(sc_time(200, SC_NS)); + } while(pending_payloads != 0); + + for (auto controller : controllers) { + controller->terminateSimulation(); + } + wait(sc_time(200, SC_NS)); + for (auto rec : tlmRecorders) { + rec->closeConnection(); + } + sc_stop(); +} + + +void dramSys::report(string message) +{ + DebugManager::getInstance().printDebugMessage(this->name(), message); + cout << message << endl; +} diff --git a/DRAMSys/simulator/src/simulation/dramSys.h b/DRAMSys/simulator/src/simulation/dramSys.h new file mode 100644 index 00000000..f7e8e5b8 --- /dev/null +++ b/DRAMSys/simulator/src/simulation/dramSys.h @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2015, University of Kaiserslautern + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Authors: + * Janik Schlemminger + * Matthias Jung + * Eder F. Zulian + * Felipe S. Prado + */ + +#ifndef DRAMSYS_H_ +#define DRAMSYS_H_ + +#include +#include + +#include "Dram.h" +#include "Arbiter.h" +#include "TraceGenerator.h" +#include "ReorderBuffer.h" +#include "../controller/Controller.h" +#include "../common/third_party/tinyxml2/tinyxml2.h" +#include "../common/tlm2_base_protocol_checker.h" + + +struct DramSetup + +{ + tinyxml2::XMLElement* memspec; + tinyxml2::XMLElement* mcconfig; + tinyxml2::XMLElement* simconfig; + tinyxml2::XMLElement* addressmapping; + tinyxml2::XMLElement* thermalsimconfig; + + string pathToResources; + + DramSetup() : memspec(NULL), + mcconfig(NULL), + simconfig(NULL), + addressmapping(NULL), + thermalsimconfig(NULL) + { + } + + DramSetup(tinyxml2::XMLElement* memspec, + tinyxml2::XMLElement* mcconfig, + tinyxml2::XMLElement* simconfig, + tinyxml2::XMLElement* addressmapping, + tinyxml2::XMLElement *tsc) : + memspec(memspec), + mcconfig(mcconfig), + simconfig(simconfig), + addressmapping(addressmapping), + thermalsimconfig(tsc) + { + } +}; + +struct Device +{ + std::string trace; + unsigned int clkMhz; + unsigned int burstLength; + + Device():trace("empty.stl"), burstLength(0) + { + } + + Device(std::string trace, + unsigned int clkMhz, + unsigned int burstLength = 8) : + trace(trace), + clkMhz (clkMhz), + burstLength(burstLength) + { + } +}; + +class dramSys: public sc_module +{ +public: + tlm_utils::multi_passthrough_target_socket tSocket; + + sc_event terminateSimulation; + + SC_HAS_PROCESS(dramSys); + dramSys(sc_module_name name, + string memspec, + string mcconfig, + string amconfig); + + ~dramSys(); + + void stop(); + void logo(); + + +private: + std::string traceName; + DramSetup setup; + + //TLM 2.0 Protocol Checkers + std::vector*> controllersTlmCheckers; + + // All transactions pass through the same arbiter + Arbiter *arbiter; + + // Each DRAM unit has a controller + std::vector controllers; + + // TODO: Each DRAM has a reorder buffer (check this!) + ReorderBuffer *reorder; + + // DRAM units + std::vector drams; + + // Transaction Recorders (one per channel). They generate the output databases. + std::vector tlmRecorders; + + void report(std::string message); + void setupTlmRecorders(const string &traceName, const string &pathToResources); + void instantiateModules(const string &traceName, const string &pathToResources); + void bindSockets(); + void setupDebugManager(const string &traceName); +}; + +#endif /* SIMULATIONMANAGER_H_ */ diff --git a/DRAMSys/simulator/src/simulation/main.cpp b/DRAMSys/simulator/src/simulation/main.cpp index 207d99db..0f802619 100644 --- a/DRAMSys/simulator/src/simulation/main.cpp +++ b/DRAMSys/simulator/src/simulation/main.cpp @@ -40,7 +40,9 @@ #include #include -#include "SimulationManager.h" +//XXX +//#include "SimulationManager.h" +#include "dramSys.h" using namespace std; @@ -57,41 +59,25 @@ int main(int argc, char **argv) } -void logo() -{ -#define REDTXT(s) string(("\033[0;31m"+string((s))+"\033[0m")) -#define BOLDBLUETXT(s) string(("\033[1;34m"+string((s))+"\033[0m")) - cout << endl; - cout << REDTXT(" |||") << endl; - cout << REDTXT(" +---+ Microelectronic Systems") << endl; - cout << REDTXT("=| |= Design Research Group") << endl; - cout << REDTXT("=| |= ") << BOLDBLUETXT("University of Kaiserslautern") << endl; - cout << REDTXT(" +---+ ") << endl; - cout << REDTXT(" ||| ") << "DRAMSys - Approximately-Timed TLM Models for DDR and Wide I/0 DRAM -" << endl; - cout << endl; -#undef REDTXT -#undef BOLDBLUETXT -} int sc_main(int argc, char **argv) { sc_set_time_resolution(1, SC_PS); + + // Get path of resources: resources = pathOfFile(argv[0]) + string("/../../DRAMSys/simulator/resources/"); - cout << "Resources directory is " << resources << endl; string simulationToRun; if(argc > 1) simulationToRun = argv[1]; else simulationToRun = resources + "simulations/sim-batch.xml"; - cout << "Simulation file is " << simulationToRun << endl; - SimulationManager manager(resources); - logo(); - cout << "Simulation file: \"" << simulationToRun << "\""; - manager.loadSimulationsFromXML(simulationToRun); - manager.runSimulations(); + dramSys dramSystem("dramSystem", + "../../DRAMSys/simulator/resources/memspec/WideIO.xml", + "../../DRAMSys/simulator/resources/fifoStrict.xml", + "../../DRAMSys/simulator/resources/am_wideio.xml"); return 0; } From 813708c77e803bb9e104a39f111d344bb68c5b7e Mon Sep 17 00:00:00 2001 From: Matthias Jung Date: Fri, 17 Feb 2017 20:16:37 +0100 Subject: [PATCH 02/19] Isolated DRAMSys TLM model --- .../resources/configs/mcconfigs/fifo.xml | 1 + .../configs/mcconfigs/fifoStrict.xml | 3 +- .../resources/configs/mcconfigs/fr_fcfs.xml | 8 +- .../resources/configs/mcconfigs/par_bs.xml | 1 + .../memspecs/{WideIO.xml => wideio.xml} | 0 .../resources/configs/simulator/ddr3.xml | 12 ++ .../resources/configs/simulator/wideio.xml | 13 ++ .../resources/configs/thermalsim/config.xml | 14 ++ DRAMSys/simulator/resources/resources.pri | 11 +- .../resources/simulations/ddr3-example.xml | 26 +-- .../simulations/ddr3-single-device.xml | 22 --- .../resources/simulations/sim-batch.xml | 30 +--- DRAMSys/simulator/src/common/Utils.cpp | 1 - DRAMSys/simulator/src/common/Utils.h | 9 + .../src/common/xmlAddressdecoder.cpp | 48 ++++-- .../simulator/src/common/xmlAddressdecoder.h | 35 ++-- .../core/configuration/Configuration.cpp | 5 + .../core/configuration/Configuration.h | 15 +- .../configuration/ConfigurationLoader.cpp | 7 - .../core/configuration/ConfigurationLoader.h | 3 +- DRAMSys/simulator/src/simulation/dramSys.cpp | 162 ++++++++++++------ DRAMSys/simulator/src/simulation/dramSys.h | 71 ++------ DRAMSys/simulator/src/simulation/main.cpp | 26 ++- 23 files changed, 270 insertions(+), 253 deletions(-) rename DRAMSys/simulator/resources/configs/memspecs/{WideIO.xml => wideio.xml} (100%) create mode 100644 DRAMSys/simulator/resources/configs/simulator/ddr3.xml create mode 100644 DRAMSys/simulator/resources/configs/simulator/wideio.xml create mode 100644 DRAMSys/simulator/resources/configs/thermalsim/config.xml diff --git a/DRAMSys/simulator/resources/configs/mcconfigs/fifo.xml b/DRAMSys/simulator/resources/configs/mcconfigs/fifo.xml index 2048948f..86322a2f 100644 --- a/DRAMSys/simulator/resources/configs/mcconfigs/fifo.xml +++ b/DRAMSys/simulator/resources/configs/mcconfigs/fifo.xml @@ -11,4 +11,5 @@ + diff --git a/DRAMSys/simulator/resources/configs/mcconfigs/fifoStrict.xml b/DRAMSys/simulator/resources/configs/mcconfigs/fifoStrict.xml index 164f89f6..9ca4b1b4 100644 --- a/DRAMSys/simulator/resources/configs/mcconfigs/fifoStrict.xml +++ b/DRAMSys/simulator/resources/configs/mcconfigs/fifoStrict.xml @@ -10,6 +10,7 @@ - + + diff --git a/DRAMSys/simulator/resources/configs/mcconfigs/fr_fcfs.xml b/DRAMSys/simulator/resources/configs/mcconfigs/fr_fcfs.xml index 50532f62..b0dc6ba4 100644 --- a/DRAMSys/simulator/resources/configs/mcconfigs/fr_fcfs.xml +++ b/DRAMSys/simulator/resources/configs/mcconfigs/fr_fcfs.xml @@ -11,12 +11,6 @@ - + diff --git a/DRAMSys/simulator/resources/configs/mcconfigs/par_bs.xml b/DRAMSys/simulator/resources/configs/mcconfigs/par_bs.xml index 24418246..a919e8c3 100644 --- a/DRAMSys/simulator/resources/configs/mcconfigs/par_bs.xml +++ b/DRAMSys/simulator/resources/configs/mcconfigs/par_bs.xml @@ -11,5 +11,6 @@ + diff --git a/DRAMSys/simulator/resources/configs/memspecs/WideIO.xml b/DRAMSys/simulator/resources/configs/memspecs/wideio.xml similarity index 100% rename from DRAMSys/simulator/resources/configs/memspecs/WideIO.xml rename to DRAMSys/simulator/resources/configs/memspecs/wideio.xml diff --git a/DRAMSys/simulator/resources/configs/simulator/ddr3.xml b/DRAMSys/simulator/resources/configs/simulator/ddr3.xml new file mode 100644 index 00000000..cc8f9de5 --- /dev/null +++ b/DRAMSys/simulator/resources/configs/simulator/ddr3.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/DRAMSys/simulator/resources/configs/simulator/wideio.xml b/DRAMSys/simulator/resources/configs/simulator/wideio.xml new file mode 100644 index 00000000..607db393 --- /dev/null +++ b/DRAMSys/simulator/resources/configs/simulator/wideio.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/DRAMSys/simulator/resources/configs/thermalsim/config.xml b/DRAMSys/simulator/resources/configs/thermalsim/config.xml new file mode 100644 index 00000000..9c71f8c6 --- /dev/null +++ b/DRAMSys/simulator/resources/configs/thermalsim/config.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/DRAMSys/simulator/resources/resources.pri b/DRAMSys/simulator/resources/resources.pri index 1d6ffe46..2a29a7d0 100644 --- a/DRAMSys/simulator/resources/resources.pri +++ b/DRAMSys/simulator/resources/resources.pri @@ -6,6 +6,9 @@ OTHER_FILES += resources/simulations/sim-batch.xml OTHER_FILES += resources/simulations/ddr3-example.xml OTHER_FILES += resources/simulations/ddr3-single-device.xml +# Simulator Configuration: +OTHER_FILES += + # scripts OTHER_FILES += resources/scripts/address_scrambler.pl OTHER_FILES += resources/scripts/createTraceDB.sql @@ -68,7 +71,7 @@ OTHER_FILES += resources/configs/mcconfigs/par_bs.xml OTHER_FILES += resources/configs/memspecs/memspec.dtd OTHER_FILES += resources/configs/memspecs/MatzesWideIO.xml OTHER_FILES += resources/configs/memspecs/DDR4.xml -OTHER_FILES += resources/configs/memspecs/WideIO.xml +OTHER_FILES += OTHER_FILES += resources/configs/memspecs/MatzesWideIO-short.xml OTHER_FILES += resources/configs/memspecs/MICRON_1Gb_DDR3-1600_8bit_G.xml OTHER_FILES += resources/configs/memspecs/JEDEC_256Mb_WIDEIO_SDR-200_128bit.xml @@ -131,3 +134,9 @@ OTHER_FILES += resources/configs/thermalsim/mem.flp OTHER_FILES += resources/configs/thermalsim/powerInfo.xml OTHER_FILES += resources/configs/thermalsim/stack.stk +DISTFILES += \ + $$PWD/configs/thermalsim/config.xml \ + $$PWD/configs/simulator/wideio.xml \ + $$PWD/configs/simulator/ddr3.xml \ + $$PWD/configs/memspecs/wideio.xml + diff --git a/DRAMSys/simulator/resources/simulations/ddr3-example.xml b/DRAMSys/simulator/resources/simulations/ddr3-example.xml index 643716ef..9c921124 100644 --- a/DRAMSys/simulator/resources/simulations/ddr3-example.xml +++ b/DRAMSys/simulator/resources/simulations/ddr3-example.xml @@ -1,32 +1,10 @@ - - - - - - - - - - - - - - - - - - - - - - @@ -50,12 +28,12 @@ - + - ddr3_example.stl + _128x128_64-Pixelgroesse_scram.stl diff --git a/DRAMSys/simulator/resources/simulations/ddr3-single-device.xml b/DRAMSys/simulator/resources/simulations/ddr3-single-device.xml index e6653583..5181342a 100644 --- a/DRAMSys/simulator/resources/simulations/ddr3-single-device.xml +++ b/DRAMSys/simulator/resources/simulations/ddr3-single-device.xml @@ -1,32 +1,10 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/DRAMSys/simulator/resources/simulations/sim-batch.xml b/DRAMSys/simulator/resources/simulations/sim-batch.xml index 0752914c..84ed962b 100644 --- a/DRAMSys/simulator/resources/simulations/sim-batch.xml +++ b/DRAMSys/simulator/resources/simulations/sim-batch.xml @@ -1,39 +1,15 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + diff --git a/DRAMSys/simulator/src/common/Utils.cpp b/DRAMSys/simulator/src/common/Utils.cpp index a791071b..e5b09fee 100644 --- a/DRAMSys/simulator/src/common/Utils.cpp +++ b/DRAMSys/simulator/src/common/Utils.cpp @@ -44,7 +44,6 @@ using namespace std; using namespace tinyxml2; - bool TimeInterval::timeIsInInterval(sc_time time) { return (start < time && time < end); diff --git a/DRAMSys/simulator/src/common/Utils.h b/DRAMSys/simulator/src/common/Utils.h index 1de06366..c8c8d85e 100644 --- a/DRAMSys/simulator/src/common/Utils.h +++ b/DRAMSys/simulator/src/common/Utils.h @@ -48,6 +48,15 @@ #include "dramExtension.h" #include "third_party/tinyxml2/tinyxml2.h" + +#define DEF_SINGLETON( NAME ) \ +public: \ + static NAME& getInstance() \ + { \ + static NAME _instance; \ + return _instance; \ + } + //TODO : move to timing specific header sc_time getDistance(sc_time a, sc_time b); diff --git a/DRAMSys/simulator/src/common/xmlAddressdecoder.cpp b/DRAMSys/simulator/src/common/xmlAddressdecoder.cpp index 24c3c356..ae790ea8 100644 --- a/DRAMSys/simulator/src/common/xmlAddressdecoder.cpp +++ b/DRAMSys/simulator/src/common/xmlAddressdecoder.cpp @@ -44,32 +44,44 @@ using namespace std; using namespace tinyxml2; -tinyxml2::XMLElement* xmlAddressDecoder::addressmapping = NULL; +//tinyxml2::XMLElement* xmlAddressDecoder::addressmapping = NULL; +//xmlAddressDecoder* xmlAddressDecoder::decoder = NULL; + +xmlAddressDecoder::xmlAddressDecoder() +{ + addressmapping = NULL; +} xmlAddressDecoder::xmlAddressDecoder(string addressConfigURI) { - tinyxml2::XMLDocument doc; - - loadXML(addressConfigURI, doc); - xmlAddressDecoder(doc.FirstChildElement("dramconfig")->FirstChildElement("addressmap")); - + setConfiguration(addressConfigURI); } xmlAddressDecoder::xmlAddressDecoder(XMLElement* addressmap) { - tinyxml2::XMLDocument doc; - string xmlNodeName(addressmap->Name()); - if( xmlNodeName != "addressmapping") - reportFatal("AddressDecorder", "addressmap node expected"); + setConfiguration(addressmap); +} - if(addressmap->Attribute("src")) +void xmlAddressDecoder::setConfiguration(std::string addressConfigURI) +{ + tinyxml2::XMLDocument doc; + loadXML(addressConfigURI, doc); + setConfiguration(doc.RootElement()); +} + +void xmlAddressDecoder::setConfiguration(tinyxml2::XMLElement* addressMap) +{ + tinyxml2::XMLDocument doc; + string xmlNodeName(addressMap->Name()); + + if( xmlNodeName != "addressmapping") { - string src(addressmap->Attribute("src")); - loadXML(src, doc); - addressmap = (doc.FirstChildElement("addressmapping")); + reportFatal("AddressDecorder", "addressmap node expected"); } - for(XMLElement* child = addressmap->FirstChildElement(); child != NULL; child = child->NextSiblingElement()) + for(XMLElement* child = addressMap->FirstChildElement(); + child != NULL; + child = child->NextSiblingElement()) { int from; int to; @@ -80,10 +92,10 @@ xmlAddressDecoder::xmlAddressDecoder(XMLElement* addressmap) shifts[child->Name()] = from; masks[child->Name()] = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); amount[child->Name()] = pow(2.0, to - from + 1.0); - //std::cout << child->Name() << " XXXX " << pow(2.0, to - from + 1.0) <(pair.second)< #include +#include "Utils.h" #include "third_party/tinyxml2/tinyxml2.h" struct DecodedAddress @@ -62,35 +63,27 @@ struct DecodedAddress class xmlAddressDecoder { - public: - - static tinyxml2::XMLElement* addressmapping; - static inline xmlAddressDecoder& getInstance() - { - static xmlAddressDecoder decoder(xmlAddressDecoder::addressmapping); - return decoder; - } - - static inline void Initialize(tinyxml2::XMLElement* mapping) - { - addressmapping = mapping; - xmlAddressDecoder::getInstance(); - addressmapping = NULL; - } - - DecodedAddress decodeAddress(sc_dt::uint64 addr); - sc_dt::uint64 encodeAddress(DecodedAddress n); - - - void print(); private: + + xmlAddressDecoder(); xmlAddressDecoder(std::string URI); xmlAddressDecoder(tinyxml2::XMLElement* addressMap); std::map masks; std::map shifts; + tinyxml2::XMLElement* addressmapping; + public: + DEF_SINGLETON(xmlAddressDecoder); + + DecodedAddress decodeAddress(sc_dt::uint64 addr); + sc_dt::uint64 encodeAddress(DecodedAddress n); + + void setConfiguration(std::string url); + void setConfiguration(tinyxml2::XMLElement* addressMap); + void print(); + std::map amount; }; diff --git a/DRAMSys/simulator/src/controller/core/configuration/Configuration.cpp b/DRAMSys/simulator/src/controller/core/configuration/Configuration.cpp index 594a746b..289682d5 100644 --- a/DRAMSys/simulator/src/controller/core/configuration/Configuration.cpp +++ b/DRAMSys/simulator/src/controller/core/configuration/Configuration.cpp @@ -133,6 +133,8 @@ void Configuration::setParameter(std::string name, std::string value) ReorderBuffer = string2bool(value); //SimConfig------------------------------------------------ + else if(name == "SimulationName") + SimulationName = value; else if(name == "DatabaseRecording") DatabaseRecording = string2bool(value); else if(name == "PowerAnalysis") @@ -264,6 +266,9 @@ unsigned int Configuration::getBytesPerBurst() // offset of the N-byte-wide memory module (DIMM) (a single data word // or burst element has N bytes. N = 2^(# bits for byte offset)). unsigned int burstElementSizeInBytes = xmlAddressDecoder::getInstance().amount["bytes"]; + cout << "burstElementSizeInBytes:" << burstElementSizeInBytes << endl; + cout << "bytesPerBurst:" << bytesPerBurst << endl; + cout << "BurstLength:" << memSpec.BurstLength << endl; assert(bytesPerBurst == (burstElementSizeInBytes * memSpec.BurstLength)); } diff --git a/DRAMSys/simulator/src/controller/core/configuration/Configuration.h b/DRAMSys/simulator/src/controller/core/configuration/Configuration.h index 53437269..29b8d41a 100644 --- a/DRAMSys/simulator/src/controller/core/configuration/Configuration.h +++ b/DRAMSys/simulator/src/controller/core/configuration/Configuration.h @@ -50,18 +50,14 @@ DEFINE_ENUM_CLASS_WITH_STRING_CONVERSIONS(StorageMode, (NoStorage)(Store)(ErrorM enum class EPowerDownMode{NoPowerDown, Staggered, TimeoutPDN, TimeoutSREF}; -struct Configuration +struct Configuration { static std::string memspecUri; static std::string mcconfigUri; - static inline Configuration& getInstance() - { - static Configuration configuration; - return configuration; - } + DEF_SINGLETON(Configuration); - //MCConfig + // MCConfig: bool BankwiseLogic = false; bool OpenPagePolicy = true; unsigned int MaxNrOfTransactions = 8; @@ -72,7 +68,8 @@ struct Configuration bool ReadWriteGrouping = false; bool ReorderBuffer = false; - //SimConfig + // SimConfig + std::string SimulationName = "default"; bool DatabaseRecording = true; bool PowerAnalysis = false; bool EnableWindowing = false; @@ -86,7 +83,7 @@ struct Configuration unsigned int NumberOfDevicesOnDIMM = 1; bool CheckTLM2Protocol = false; - //MemSpec(from DRAM-Power XML) + // MemSpec (from DRAM-Power XML) MemSpec memSpec; void setParameter(std::string name, std::string value); diff --git a/DRAMSys/simulator/src/controller/core/configuration/ConfigurationLoader.cpp b/DRAMSys/simulator/src/controller/core/configuration/ConfigurationLoader.cpp index f948c8db..d717e2d0 100644 --- a/DRAMSys/simulator/src/controller/core/configuration/ConfigurationLoader.cpp +++ b/DRAMSys/simulator/src/controller/core/configuration/ConfigurationLoader.cpp @@ -107,13 +107,6 @@ void ConfigurationLoader::loadMemSpec(Configuration& config, string memspecUri) void ConfigurationLoader::loadMemSpec(Configuration& config, XMLElement* memspec) { - XMLDocument doc; - - string src(memspec->Attribute("src")); - config.memspecUri = src; - loadXML(src, doc); - memspec = doc.FirstChildElement("memspec"); - config.memSpec.MemoryId = queryStringParameter(memspec, "memoryId"); config.memSpec.MemoryType = queryStringParameter(memspec, "memoryType"); diff --git a/DRAMSys/simulator/src/controller/core/configuration/ConfigurationLoader.h b/DRAMSys/simulator/src/controller/core/configuration/ConfigurationLoader.h index 9c319129..d9cf1bc8 100644 --- a/DRAMSys/simulator/src/controller/core/configuration/ConfigurationLoader.h +++ b/DRAMSys/simulator/src/controller/core/configuration/ConfigurationLoader.h @@ -45,7 +45,8 @@ class ConfigurationLoader { public: - static void loadMCConfig(Configuration& config, std::string mcconfigUri); + + static void loadMCConfig(Configuration& config, std::string amconfigUri); static void loadMCConfig(Configuration& config, tinyxml2::XMLElement* mcconfig); static void loadSimConfig(Configuration& config, std::string simconfigUri); diff --git a/DRAMSys/simulator/src/simulation/dramSys.cpp b/DRAMSys/simulator/src/simulation/dramSys.cpp index 12058f97..98e7412c 100644 --- a/DRAMSys/simulator/src/simulation/dramSys.cpp +++ b/DRAMSys/simulator/src/simulation/dramSys.cpp @@ -53,38 +53,59 @@ using namespace std; -dramSys::dramSys(sc_module_name __attribute__((unused)) name, +DRAMSys::DRAMSys(sc_module_name __attribute__((unused)) name, + string pathToResources, string memspec, string mcconfig, - string amconfig) + string amconfig, + string simconfig, + string thermalconfig) { logo(); SC_THREAD(stop); - // TODO: - - cout << memspec << endl; - cout << mcconfig << endl; - cout << amconfig << endl; - // The xmlAddressDecoder MUST be initialized before calling the // ConfigurationLoader because some information from the xmlAddressDecoder // is needed to assure the coherence of the configuration. - xmlAddressDecoder::Initialize(setup.addressmapping); + xmlAddressDecoder::getInstance().setConfiguration(pathToResources + + "configs/amconfigs/" + + amconfig); xmlAddressDecoder::getInstance().print(); - ConfigurationLoader::loadMCConfig(Configuration::getInstance(), setup.mcconfig); - ConfigurationLoader::loadMemSpec(Configuration::getInstance(), setup.memspec); - ConfigurationLoader::loadSimConfig(Configuration::getInstance(), setup.simconfig); - ConfigurationLoader::loadTemperatureSimConfig(Configuration::getInstance(), setup.thermalsimconfig); + // Setup the memory controller with the propriate xml file + ConfigurationLoader::loadMCConfig(Configuration::getInstance(), + pathToResources + + "configs/mcconfigs/" + + mcconfig); - instantiateModules(traceName, setup.pathToResources); + ConfigurationLoader::loadMemSpec(Configuration::getInstance(), + pathToResources + + "configs/memspecs/" + + memspec); + + ConfigurationLoader::loadSimConfig(Configuration::getInstance(), + pathToResources + + "configs/simulator/" + + simconfig); + + ConfigurationLoader::loadTemperatureSimConfig(Configuration::getInstance(), + pathToResources + + "configs/thermalsim/" + + thermalconfig); + + // Instantiate all internal DRAMSys modules: + instantiateModules(Configuration::getInstance().SimulationName, + pathToResources); + + // Connect all internal DRAMSys modules: bindSockets(); - setupDebugManager(traceName); + + // Setup the debug manager: + setupDebugManager(Configuration::getInstance().SimulationName); } -void dramSys::logo() +void DRAMSys::logo() { #define REDTXT(s) string(("\033[0;31m"+string((s))+"\033[0m")) #define BOLDBLUETXT(s) string(("\033[1;34m"+string((s))+"\033[0m")) @@ -92,15 +113,18 @@ void dramSys::logo() cout << REDTXT(" |||") << endl; cout << REDTXT(" +---+ Microelectronic Systems") << endl; cout << REDTXT("=| |= Design Research Group") << endl; - cout << REDTXT("=| |= ") << BOLDBLUETXT("University of Kaiserslautern") << endl; + cout << REDTXT("=| |= ") << BOLDBLUETXT("University of Kaiserslautern") + << endl; cout << REDTXT(" +---+ ") << endl; - cout << REDTXT(" ||| ") << "DRAMSys - Approximately-Timed TLM Models for DDR and Wide I/0 DRAM -" << endl; + cout << REDTXT(" ||| ") << "DRAMSys -" + << " Approximately-Timed TLM Models for DDR and Wide I/0 DRAM -" + << endl; cout << endl; #undef REDTXT #undef BOLDBLUETXT } -void dramSys::setupDebugManager(const string& traceName) +void DRAMSys::setupDebugManager(const string& traceName) { auto& dbg = DebugManager::getInstance(); dbg.writeToConsole = true; @@ -109,21 +133,35 @@ void dramSys::setupDebugManager(const string& traceName) dbg.openDebugFile(traceName + ".txt"); } -void dramSys::setupTlmRecorders(const string &traceName, const string &pathToResources) +void DRAMSys::setupTlmRecorders(const string &traceName, + const string &pathToResources) { // Create TLM Recorders, one per channel. - for (size_t i = 0; i < Configuration::getInstance().NumberOfMemChannels; i++) { - std::string sqlScriptURI = pathToResources + string("scripts/createTraceDB.sql"); - std::string dbName = traceName + string("_channel") + std::to_string(i) + ".tdb"; + for (size_t i = 0; + i < Configuration::getInstance().NumberOfMemChannels; + i++) + { + std::string sqlScriptURI = pathToResources + + string("scripts/createTraceDB.sql"); + + std::string dbName = traceName + + string("_channel") + + std::to_string(i) + + ".tdb"; + std::string recorderName = "tlmRecorder" + std::to_string(i); - TlmRecorder *tlmRecorder = new TlmRecorder(recorderName.c_str(), sqlScriptURI.c_str(), dbName.c_str(), Configuration::getInstance().DatabaseRecording); + TlmRecorder *tlmRecorder = + new TlmRecorder(recorderName.c_str(), + sqlScriptURI.c_str(), + dbName.c_str(), + Configuration::getInstance().DatabaseRecording); tlmRecorder->recordMCconfig(Configuration::getInstance().mcconfigUri); tlmRecorder->recordMemspec(Configuration::getInstance().memspecUri); tlmRecorders.push_back(tlmRecorder); - std::string traceNames = "FOO"; /// TODO + std::string traceNames = "FOO"; // TODO //for (size_t i = 0; i < devices.size(); i++) { // traceNames.append(devices[i].trace); // if (i == devices.size() - 1) @@ -134,20 +172,25 @@ void dramSys::setupTlmRecorders(const string &traceName, const string &pathToRes } } -void dramSys::instantiateModules(const string &traceName, const string &pathToResources) +void DRAMSys::instantiateModules(const string &traceName, + const string &pathToResources) { // The first call to getInstance() creates the Temperature Controller. // The same instance will be accessed by all other modules. TemperatureController::getInstance(); - // Create and properly initialize TLM recorders. They need to be ready before creating some modules. + // Create and properly initialize TLM recorders. + // They need to be ready before creating some modules. setupTlmRecorders(traceName, pathToResources); arbiter = new Arbiter("arbiter"); arbiter->setTlmRecorders(tlmRecorders); - for (size_t i = 0; i < Configuration::getInstance().NumberOfMemChannels; i++) { + for (size_t i = 0; + i < Configuration::getInstance().NumberOfMemChannels; + i++) + { std::string str = "controller" + std::to_string(i); Controller *controller = new Controller(str.c_str(), tlmRecorders[i]); controllers.push_back(controller); @@ -158,80 +201,103 @@ void dramSys::instantiateModules(const string &traceName, const string &pathToRe dram->setDramController(controllers[i]); drams.push_back(dram); - if(Configuration::getInstance().CheckTLM2Protocol) { + if(Configuration::getInstance().CheckTLM2Protocol) + { str = "TLMCheckerController"+ std::to_string(i); - tlm_utils::tlm2_base_protocol_checker<> * controllerTlmChecker = new tlm_utils::tlm2_base_protocol_checker<>(str.c_str()); + tlm_utils::tlm2_base_protocol_checker<> * controllerTlmChecker = + new tlm_utils::tlm2_base_protocol_checker<>(str.c_str()); controllersTlmCheckers.push_back(controllerTlmChecker); } } } -void dramSys::bindSockets() +void DRAMSys::bindSockets() { tSocket.bind(arbiter->tSocket); - if(Configuration::getInstance().CheckTLM2Protocol) { + if(Configuration::getInstance().CheckTLM2Protocol) + { - for (size_t i = 0; i < Configuration::getInstance().NumberOfMemChannels; i++) { + for (size_t i = 0; + i < Configuration::getInstance().NumberOfMemChannels; + i++) + { arbiter->iSocket.bind(controllersTlmCheckers[i]->target_socket); - controllersTlmCheckers[i]->initiator_socket.bind(controllers[i]->tSocket); + controllersTlmCheckers[i]->initiator_socket.bind( + controllers[i]->tSocket); controllers[i]->iSocket.bind(drams[i]->tSocket); } - } else { - for (size_t i = 0; i < Configuration::getInstance().NumberOfMemChannels; i++) { + } + else + { + for (size_t i = 0; + i < Configuration::getInstance().NumberOfMemChannels; + i++) + { arbiter->iSocket.bind(controllers[i]->tSocket); controllers[i]->iSocket.bind(drams[i]->tSocket); } } } -dramSys::~dramSys() +DRAMSys::~DRAMSys() { delete arbiter; - for (auto controller : controllers) { + for (auto controller : controllers) + { delete controller; } - for (auto dram : drams) { + for (auto dram : drams) + { delete dram; } - for (auto rec : tlmRecorders) { + for (auto rec : tlmRecorders) + { delete rec; } - for (auto tlmChecker : controllersTlmCheckers) { + for (auto tlmChecker : controllersTlmCheckers) + { delete tlmChecker; } } -void dramSys::stop() +void DRAMSys::stop() { wait(terminateSimulation); unsigned int pending_payloads = 0; - do { + do + { pending_payloads = 0; - for (auto controller : controllers) { + for (auto controller : controllers) + { pending_payloads += controller->getTotalNumberOfPayloadsInSystem(); } wait(sc_time(200, SC_NS)); - } while(pending_payloads != 0); + } + while(pending_payloads != 0); - for (auto controller : controllers) { + for (auto controller : controllers) + { controller->terminateSimulation(); } + wait(sc_time(200, SC_NS)); - for (auto rec : tlmRecorders) { + + for (auto rec : tlmRecorders) + { rec->closeConnection(); } sc_stop(); } -void dramSys::report(string message) +void DRAMSys::report(string message) { DebugManager::getInstance().printDebugMessage(this->name(), message); cout << message << endl; diff --git a/DRAMSys/simulator/src/simulation/dramSys.h b/DRAMSys/simulator/src/simulation/dramSys.h index f7e8e5b8..0e093b4e 100644 --- a/DRAMSys/simulator/src/simulation/dramSys.h +++ b/DRAMSys/simulator/src/simulation/dramSys.h @@ -50,74 +50,23 @@ #include "../common/third_party/tinyxml2/tinyxml2.h" #include "../common/tlm2_base_protocol_checker.h" - -struct DramSetup - -{ - tinyxml2::XMLElement* memspec; - tinyxml2::XMLElement* mcconfig; - tinyxml2::XMLElement* simconfig; - tinyxml2::XMLElement* addressmapping; - tinyxml2::XMLElement* thermalsimconfig; - - string pathToResources; - - DramSetup() : memspec(NULL), - mcconfig(NULL), - simconfig(NULL), - addressmapping(NULL), - thermalsimconfig(NULL) - { - } - - DramSetup(tinyxml2::XMLElement* memspec, - tinyxml2::XMLElement* mcconfig, - tinyxml2::XMLElement* simconfig, - tinyxml2::XMLElement* addressmapping, - tinyxml2::XMLElement *tsc) : - memspec(memspec), - mcconfig(mcconfig), - simconfig(simconfig), - addressmapping(addressmapping), - thermalsimconfig(tsc) - { - } -}; - -struct Device -{ - std::string trace; - unsigned int clkMhz; - unsigned int burstLength; - - Device():trace("empty.stl"), burstLength(0) - { - } - - Device(std::string trace, - unsigned int clkMhz, - unsigned int burstLength = 8) : - trace(trace), - clkMhz (clkMhz), - burstLength(burstLength) - { - } -}; - -class dramSys: public sc_module +class DRAMSys: public sc_module { public: - tlm_utils::multi_passthrough_target_socket tSocket; + tlm_utils::multi_passthrough_target_socket tSocket; sc_event terminateSimulation; - SC_HAS_PROCESS(dramSys); - dramSys(sc_module_name name, + SC_HAS_PROCESS(DRAMSys); + DRAMSys(sc_module_name name, + string pathToResources, string memspec, string mcconfig, - string amconfig); + string amconfig, + string simconfig, + string thermalconfig); - ~dramSys(); + ~DRAMSys(); void stop(); void logo(); @@ -125,7 +74,7 @@ public: private: std::string traceName; - DramSetup setup; + //DramSetup setup; //TLM 2.0 Protocol Checkers std::vector*> controllersTlmCheckers; diff --git a/DRAMSys/simulator/src/simulation/main.cpp b/DRAMSys/simulator/src/simulation/main.cpp index 0f802619..5fb07b81 100644 --- a/DRAMSys/simulator/src/simulation/main.cpp +++ b/DRAMSys/simulator/src/simulation/main.cpp @@ -43,6 +43,8 @@ //XXX //#include "SimulationManager.h" #include "dramSys.h" +#include "ExampleInitiator.h" + using namespace std; @@ -65,7 +67,8 @@ int sc_main(int argc, char **argv) sc_set_time_resolution(1, SC_PS); // Get path of resources: - resources = pathOfFile(argv[0]) + string("/../../DRAMSys/simulator/resources/"); + resources = pathOfFile(argv[0]) + + string("/../../DRAMSys/simulator/resources/"); string simulationToRun; if(argc > 1) @@ -74,10 +77,23 @@ int sc_main(int argc, char **argv) simulationToRun = resources + "simulations/sim-batch.xml"; - dramSys dramSystem("dramSystem", - "../../DRAMSys/simulator/resources/memspec/WideIO.xml", - "../../DRAMSys/simulator/resources/fifoStrict.xml", - "../../DRAMSys/simulator/resources/am_wideio.xml"); + DRAMSys dramSystem("dramSystem", + "../../DRAMSys/simulator/resources/", + "wideio.xml", + "fifoStrict.xml", + "am_wideio.xml", + "wideio.xml", + "config.xml"); + + ExampleInitiator trageGenerator("traceGenerator"); + + trageGenerator.socket.bind(dramSystem.tSocket); + + SC_REPORT_INFO("sc_main", "Start of Simulation"); + + sc_core::sc_start(); + + SC_REPORT_INFO("sc_main", "End of Simulation"); return 0; } From bf0a71748c9dea1f5839cd186444b5280c3ae97f Mon Sep 17 00:00:00 2001 From: Matthias Jung Date: Sun, 19 Feb 2017 01:21:33 +0100 Subject: [PATCH 03/19] Simulation Manager Removed, Cleanups --- .../mcconfigs/_old/fr_fcfs_bankwise.xml | 15 - .../mcconfigs/_old/fr_fcfs_unaware.xml | 15 - .../configs/mcconfigs/_old/grouper.xml | 14 - .../configs/mcconfigs/_old/par_bs.xml | 14 - .../configs/mcconfigs/_old/par_bs_unaware.xml | 14 - .../resources/configs/mcconfigs/fifo.xml | 7 +- .../configs/mcconfigs/fifoStrict.xml | 12 +- .../resources/configs/mcconfigs/fr_fcfs.xml | 7 +- .../resources/configs/mcconfigs/par_bs.xml | 10 +- .../configs/simulator/ddr3-single-device.xml | 12 + .../resources/configs/simulator/ddr3.xml | 2 +- DRAMSys/simulator/resources/resources.pri | 11 +- .../resources/simulations/ddr3-example.xml | 58 ++-- .../simulations/ddr3-single-device.xml | 53 ++- .../resources/simulations/sim-batch.xml | 28 -- .../resources/simulations/wideio-example.xml | 22 ++ DRAMSys/simulator/simulator.pro | 12 +- DRAMSys/simulator/src/common/DebugManager.h | 9 +- .../src/common/xmlAddressdecoder.cpp | 5 +- .../simulator/src/common/xmlAddressdecoder.h | 11 +- .../simulator/src/controller/Controller.cpp | 7 + DRAMSys/simulator/src/controller/Controller.h | 3 + .../core/configuration/Configuration.cpp | 5 - .../core/configuration/Configuration.h | 1 - DRAMSys/simulator/src/simulation/Arbiter.h | 21 +- .../simulation/{dramSys.cpp => DRAMSys.cpp} | 61 +--- .../src/simulation/{dramSys.h => DRAMSys.h} | 21 +- DRAMSys/simulator/src/simulation/Dram.h | 76 ++++- DRAMSys/simulator/src/simulation/Setup.cpp | 75 +++++ DRAMSys/simulator/src/simulation/Setup.h | 58 ++++ .../simulator/src/simulation/Simulation.cpp | 212 ------------ DRAMSys/simulator/src/simulation/Simulation.h | 117 ------- .../src/simulation/SimulationManager.cpp | 310 ------------------ .../simulator/src/simulation/StlPlayer.cpp | 16 +- DRAMSys/simulator/src/simulation/StlPlayer.h | 5 +- .../simulator/src/simulation/TraceGenerator.h | 32 +- .../simulator/src/simulation/TracePlayer.cpp | 25 +- .../simulator/src/simulation/TracePlayer.h | 5 + .../simulator/src/simulation/TraceSetup.cpp | 122 +++++++ .../{SimulationManager.h => TraceSetup.h} | 69 +--- DRAMSys/simulator/src/simulation/main.cpp | 54 +-- 41 files changed, 599 insertions(+), 1027 deletions(-) delete mode 100644 DRAMSys/simulator/resources/configs/mcconfigs/_old/fr_fcfs_bankwise.xml delete mode 100644 DRAMSys/simulator/resources/configs/mcconfigs/_old/fr_fcfs_unaware.xml delete mode 100644 DRAMSys/simulator/resources/configs/mcconfigs/_old/grouper.xml delete mode 100644 DRAMSys/simulator/resources/configs/mcconfigs/_old/par_bs.xml delete mode 100644 DRAMSys/simulator/resources/configs/mcconfigs/_old/par_bs_unaware.xml create mode 100644 DRAMSys/simulator/resources/configs/simulator/ddr3-single-device.xml delete mode 100644 DRAMSys/simulator/resources/simulations/sim-batch.xml create mode 100644 DRAMSys/simulator/resources/simulations/wideio-example.xml rename DRAMSys/simulator/src/simulation/{dramSys.cpp => DRAMSys.cpp} (90%) rename DRAMSys/simulator/src/simulation/{dramSys.h => DRAMSys.h} (84%) create mode 100644 DRAMSys/simulator/src/simulation/Setup.cpp create mode 100644 DRAMSys/simulator/src/simulation/Setup.h delete mode 100644 DRAMSys/simulator/src/simulation/Simulation.cpp delete mode 100644 DRAMSys/simulator/src/simulation/Simulation.h delete mode 100644 DRAMSys/simulator/src/simulation/SimulationManager.cpp create mode 100644 DRAMSys/simulator/src/simulation/TraceSetup.cpp rename DRAMSys/simulator/src/simulation/{SimulationManager.h => TraceSetup.h} (50%) diff --git a/DRAMSys/simulator/resources/configs/mcconfigs/_old/fr_fcfs_bankwise.xml b/DRAMSys/simulator/resources/configs/mcconfigs/_old/fr_fcfs_bankwise.xml deleted file mode 100644 index b9448e54..00000000 --- a/DRAMSys/simulator/resources/configs/mcconfigs/_old/fr_fcfs_bankwise.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/DRAMSys/simulator/resources/configs/mcconfigs/_old/fr_fcfs_unaware.xml b/DRAMSys/simulator/resources/configs/mcconfigs/_old/fr_fcfs_unaware.xml deleted file mode 100644 index 0e4816cb..00000000 --- a/DRAMSys/simulator/resources/configs/mcconfigs/_old/fr_fcfs_unaware.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/DRAMSys/simulator/resources/configs/mcconfigs/_old/grouper.xml b/DRAMSys/simulator/resources/configs/mcconfigs/_old/grouper.xml deleted file mode 100644 index 2f843ecd..00000000 --- a/DRAMSys/simulator/resources/configs/mcconfigs/_old/grouper.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/DRAMSys/simulator/resources/configs/mcconfigs/_old/par_bs.xml b/DRAMSys/simulator/resources/configs/mcconfigs/_old/par_bs.xml deleted file mode 100644 index af7f33bd..00000000 --- a/DRAMSys/simulator/resources/configs/mcconfigs/_old/par_bs.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/DRAMSys/simulator/resources/configs/mcconfigs/_old/par_bs_unaware.xml b/DRAMSys/simulator/resources/configs/mcconfigs/_old/par_bs_unaware.xml deleted file mode 100644 index c0b02587..00000000 --- a/DRAMSys/simulator/resources/configs/mcconfigs/_old/par_bs_unaware.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/DRAMSys/simulator/resources/configs/mcconfigs/fifo.xml b/DRAMSys/simulator/resources/configs/mcconfigs/fifo.xml index 86322a2f..08135f13 100644 --- a/DRAMSys/simulator/resources/configs/mcconfigs/fifo.xml +++ b/DRAMSys/simulator/resources/configs/mcconfigs/fifo.xml @@ -4,12 +4,17 @@ + - + diff --git a/DRAMSys/simulator/resources/configs/mcconfigs/fifoStrict.xml b/DRAMSys/simulator/resources/configs/mcconfigs/fifoStrict.xml index 9ca4b1b4..5c58a9c5 100644 --- a/DRAMSys/simulator/resources/configs/mcconfigs/fifoStrict.xml +++ b/DRAMSys/simulator/resources/configs/mcconfigs/fifoStrict.xml @@ -4,13 +4,17 @@ - + + - - + + - diff --git a/DRAMSys/simulator/resources/configs/mcconfigs/fr_fcfs.xml b/DRAMSys/simulator/resources/configs/mcconfigs/fr_fcfs.xml index b0dc6ba4..fad8b021 100644 --- a/DRAMSys/simulator/resources/configs/mcconfigs/fr_fcfs.xml +++ b/DRAMSys/simulator/resources/configs/mcconfigs/fr_fcfs.xml @@ -4,12 +4,17 @@ + - + diff --git a/DRAMSys/simulator/resources/configs/mcconfigs/par_bs.xml b/DRAMSys/simulator/resources/configs/mcconfigs/par_bs.xml index a919e8c3..78a8afd7 100644 --- a/DRAMSys/simulator/resources/configs/mcconfigs/par_bs.xml +++ b/DRAMSys/simulator/resources/configs/mcconfigs/par_bs.xml @@ -4,13 +4,17 @@ - + + - + - diff --git a/DRAMSys/simulator/resources/configs/simulator/ddr3-single-device.xml b/DRAMSys/simulator/resources/configs/simulator/ddr3-single-device.xml new file mode 100644 index 00000000..cc8f9de5 --- /dev/null +++ b/DRAMSys/simulator/resources/configs/simulator/ddr3-single-device.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/DRAMSys/simulator/resources/configs/simulator/ddr3.xml b/DRAMSys/simulator/resources/configs/simulator/ddr3.xml index cc8f9de5..e066cefe 100644 --- a/DRAMSys/simulator/resources/configs/simulator/ddr3.xml +++ b/DRAMSys/simulator/resources/configs/simulator/ddr3.xml @@ -1,5 +1,5 @@ - + diff --git a/DRAMSys/simulator/resources/resources.pri b/DRAMSys/simulator/resources/resources.pri index 2a29a7d0..1a58ad75 100644 --- a/DRAMSys/simulator/resources/resources.pri +++ b/DRAMSys/simulator/resources/resources.pri @@ -2,7 +2,7 @@ # "DRAMSys/simulator/simulator.pro" # simulation files -OTHER_FILES += resources/simulations/sim-batch.xml +OTHER_FILES += OTHER_FILES += resources/simulations/ddr3-example.xml OTHER_FILES += resources/simulations/ddr3-single-device.xml @@ -59,11 +59,6 @@ OTHER_FILES += resources/traces/ddr3_SAMSUNG_M471B5674QH0_DIMM_example.stl # mcconfigs OTHER_FILES += resources/configs/mcconfigs/fifoStrict.xml OTHER_FILES += resources/configs/mcconfigs/fifo.xml -OTHER_FILES += resources/configs/mcconfigs/_old/par_bs_unaware.xml -OTHER_FILES += resources/configs/mcconfigs/_old/fr_fcfs_unaware.xml -OTHER_FILES += resources/configs/mcconfigs/_old/grouper.xml -OTHER_FILES += resources/configs/mcconfigs/_old/par_bs.xml -OTHER_FILES += resources/configs/mcconfigs/_old/fr_fcfs_bankwise.xml OTHER_FILES += resources/configs/mcconfigs/fr_fcfs.xml OTHER_FILES += resources/configs/mcconfigs/par_bs.xml @@ -138,5 +133,7 @@ DISTFILES += \ $$PWD/configs/thermalsim/config.xml \ $$PWD/configs/simulator/wideio.xml \ $$PWD/configs/simulator/ddr3.xml \ - $$PWD/configs/memspecs/wideio.xml + $$PWD/configs/memspecs/wideio.xml \ + $$PWD/configs/simulator/ddr3-single-device.xml \ + $$PWD/simulations/wideio-example.xml diff --git a/DRAMSys/simulator/resources/simulations/ddr3-example.xml b/DRAMSys/simulator/resources/simulations/ddr3-example.xml index 9c921124..a9ae4a7d 100644 --- a/DRAMSys/simulator/resources/simulations/ddr3-example.xml +++ b/DRAMSys/simulator/resources/simulations/ddr3-example.xml @@ -1,41 +1,23 @@ - - - - - - - - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - _128x128_64-Pixelgroesse_scram.stl - - - + + + + + + + ddr3_example.stl + - diff --git a/DRAMSys/simulator/resources/simulations/ddr3-single-device.xml b/DRAMSys/simulator/resources/simulations/ddr3-single-device.xml index 5181342a..524742bf 100644 --- a/DRAMSys/simulator/resources/simulations/ddr3-single-device.xml +++ b/DRAMSys/simulator/resources/simulations/ddr3-single-device.xml @@ -1,36 +1,23 @@ - - - - - - - - - - - - - - + + + + + + - - - - - - - - - - - - - - - ddr3_single_dev_example.stl - - - + + + + + + + ddr3_single_dev_example.stl + - diff --git a/DRAMSys/simulator/resources/simulations/sim-batch.xml b/DRAMSys/simulator/resources/simulations/sim-batch.xml deleted file mode 100644 index 84ed962b..00000000 --- a/DRAMSys/simulator/resources/simulations/sim-batch.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - chstone-adpcm_32.stl - - - - - diff --git a/DRAMSys/simulator/resources/simulations/wideio-example.xml b/DRAMSys/simulator/resources/simulations/wideio-example.xml new file mode 100644 index 00000000..87cdcdc1 --- /dev/null +++ b/DRAMSys/simulator/resources/simulations/wideio-example.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + chstone-adpcm_32.stl + + diff --git a/DRAMSys/simulator/simulator.pro b/DRAMSys/simulator/simulator.pro index 2126dd95..a4f0fd90 100644 --- a/DRAMSys/simulator/simulator.pro +++ b/DRAMSys/simulator/simulator.pro @@ -90,7 +90,6 @@ SOURCES += \ src/controller/core/TimingCalculation.cpp \ src/controller/core/Slots.cpp \ src/controller/core/ControllerCore.cpp \ - src/simulation/dramSys.cpp \ src/simulation/MemoryManager.cpp \ src/simulation/main.cpp \ src/simulation/TemperatureController.cpp \ @@ -106,7 +105,10 @@ SOURCES += \ src/controller/Controller.cpp \ src/simulation/TracePlayer.cpp \ src/simulation/StlPlayer.cpp \ - src/controller/core/powerdown/PowerDownManagerTimeoutBankwise.cpp + src/controller/core/powerdown/PowerDownManagerTimeoutBankwise.cpp \ + src/simulation/TraceSetup.cpp \ + src/simulation/DRAMSys.cpp \ + src/simulation/Setup.cpp HEADERS += \ src/common/third_party/tinyxml2/tinyxml2.h \ @@ -143,7 +145,6 @@ HEADERS += \ src/controller/core/Slots.h \ src/controller/core/ControllerCore.h \ src/simulation/TracePlayer.h \ - src/simulation/dramSys.h \ src/simulation/MemoryManager.h \ src/simulation/Dram.h \ src/simulation/Arbiter.h \ @@ -167,7 +168,10 @@ HEADERS += \ src/controller/core/configuration/ConfigurationLoader.h \ src/error/errormodel.h \ src/simulation/ExampleInitiator.h \ - src/controller/core/powerdown/PowerDownManagerTimeoutBankwise.h + src/controller/core/powerdown/PowerDownManagerTimeoutBankwise.h \ + src/simulation/TraceSetup.h \ + src/simulation/DRAMSys.h \ + src/simulation/Setup.h thermalsim = $$(THERMALSIM) isEmpty(thermalsim) { diff --git a/DRAMSys/simulator/src/common/DebugManager.h b/DRAMSys/simulator/src/common/DebugManager.h index 17e55c72..3be8492b 100644 --- a/DRAMSys/simulator/src/common/DebugManager.h +++ b/DRAMSys/simulator/src/common/DebugManager.h @@ -41,15 +41,14 @@ #include #include +#include "Utils.h" + class DebugManager { public: ~DebugManager(); - static inline DebugManager& getInstance() - { - static DebugManager manager; - return manager; - } + + DEF_SINGLETON(DebugManager); bool writeToConsole; bool writeToFile; diff --git a/DRAMSys/simulator/src/common/xmlAddressdecoder.cpp b/DRAMSys/simulator/src/common/xmlAddressdecoder.cpp index ae790ea8..31304f1d 100644 --- a/DRAMSys/simulator/src/common/xmlAddressdecoder.cpp +++ b/DRAMSys/simulator/src/common/xmlAddressdecoder.cpp @@ -44,9 +44,6 @@ using namespace std; using namespace tinyxml2; -//tinyxml2::XMLElement* xmlAddressDecoder::addressmapping = NULL; -//xmlAddressDecoder* xmlAddressDecoder::decoder = NULL; - xmlAddressDecoder::xmlAddressDecoder() { addressmapping = NULL; @@ -125,7 +122,7 @@ sc_dt::uint64 xmlAddressDecoder::encodeAddress(DecodedAddress n) void xmlAddressDecoder::print() { cout << "Used addressmapping:" << endl; - cout << "====================" << endl; + cout << headline << endl; for(auto& pair : masks) { cout<(pair.second)< phases) return false; } +void Controller::end_of_simulation() +{ + terminateSimulation(); +} + void Controller::terminateSimulation() { if(Configuration::getInstance().BankwiseLogic) @@ -508,6 +513,8 @@ void Controller::terminateSimulation() { controllerCore->powerDownManager->wakeUp(0, clkAlign(sc_time_stamp())); } + + endTime = sc_time_stamp(); } void Controller::startBandwidthIdleCollector() diff --git a/DRAMSys/simulator/src/controller/Controller.h b/DRAMSys/simulator/src/controller/Controller.h index a07a8b74..74695fe3 100644 --- a/DRAMSys/simulator/src/controller/Controller.h +++ b/DRAMSys/simulator/src/controller/Controller.h @@ -153,6 +153,9 @@ private: void startBandwidthIdleCollector(); void endBandwidthIdleCollector(); + // SystemC related: + virtual void end_of_simulation() override; + }; #endif /* CONTROLLERWRAPPER_H_ */ diff --git a/DRAMSys/simulator/src/controller/core/configuration/Configuration.cpp b/DRAMSys/simulator/src/controller/core/configuration/Configuration.cpp index 289682d5..03532fa4 100644 --- a/DRAMSys/simulator/src/controller/core/configuration/Configuration.cpp +++ b/DRAMSys/simulator/src/controller/core/configuration/Configuration.cpp @@ -149,8 +149,6 @@ void Configuration::setParameter(std::string name, std::string value) WindowSize = string2int(value); else if(name == "Debug") Debug = string2bool(value); - else if (name == "NumberOfTracePlayers") - NumberOfTracePlayers = string2int(value); else if (name == "NumberOfMemChannels") { NumberOfMemChannels = string2int(value); unsigned int maxNumberofMemChannels = xmlAddressDecoder::getInstance().amount["channel"]; @@ -266,9 +264,6 @@ unsigned int Configuration::getBytesPerBurst() // offset of the N-byte-wide memory module (DIMM) (a single data word // or burst element has N bytes. N = 2^(# bits for byte offset)). unsigned int burstElementSizeInBytes = xmlAddressDecoder::getInstance().amount["bytes"]; - cout << "burstElementSizeInBytes:" << burstElementSizeInBytes << endl; - cout << "bytesPerBurst:" << bytesPerBurst << endl; - cout << "BurstLength:" << memSpec.BurstLength << endl; assert(bytesPerBurst == (burstElementSizeInBytes * memSpec.BurstLength)); } diff --git a/DRAMSys/simulator/src/controller/core/configuration/Configuration.h b/DRAMSys/simulator/src/controller/core/configuration/Configuration.h index 29b8d41a..3a0c1b37 100644 --- a/DRAMSys/simulator/src/controller/core/configuration/Configuration.h +++ b/DRAMSys/simulator/src/controller/core/configuration/Configuration.h @@ -75,7 +75,6 @@ struct Configuration bool EnableWindowing = false; unsigned int WindowSize = 1000; bool Debug = false; - unsigned int NumberOfTracePlayers = 1; unsigned int NumberOfMemChannels = 1; bool ControllerCoreDisableRefresh = false; bool ThermalSimulation = false; diff --git a/DRAMSys/simulator/src/simulation/Arbiter.h b/DRAMSys/simulator/src/simulation/Arbiter.h index 47fb5a1e..c12ff14f 100644 --- a/DRAMSys/simulator/src/simulation/Arbiter.h +++ b/DRAMSys/simulator/src/simulation/Arbiter.h @@ -76,10 +76,6 @@ public: tSocket.register_nb_transport_fw(this, &Arbiter::nb_transport_fw); tSocket.register_transport_dbg(this, &Arbiter::transport_dbg); - - for (size_t i = 0; i < Configuration::getInstance().NumberOfTracePlayers; ++i) { - receivedResponses.push_back(queue()); - } } void setTlmRecorders(std::vector recorders) @@ -97,7 +93,7 @@ private: vector> pendingRequests; //used to account for the response_accept_delay in the initiators (traceplayer,core etc.) // This is a queue of responses comming from the memory side. The phase of these transactions is BEGIN_RESP. - vector> receivedResponses; + std::map> receivedResponses; std::vector tlmRecorders; @@ -109,7 +105,6 @@ private: tlm_sync_enum nb_transport_bw(int channelId, tlm_generic_payload &payload, tlm_phase &phase, sc_time &bwDelay) { // Check channel ID - assert((unsigned int)channelId < iSocket.size()); if ((unsigned int)channelId != DramExtension::getExtension(payload).getChannel().ID()) { SC_REPORT_FATAL("Arbiter", "Payload extension was corrupted"); } @@ -127,8 +122,8 @@ private: // This function is called when an arbiter's target socket receives a transaction from a device tlm_sync_enum nb_transport_fw(int id, tlm_generic_payload& payload, tlm_phase& phase, sc_time& fwDelay) { - assert ((unsigned int)id < tSocket.size()); - if (phase == BEGIN_REQ) { + if (phase == BEGIN_REQ) + { // Map the payload with socket id. routeMap[&payload] = id; // In the begin request phase the socket ID is appended to the payload. @@ -158,7 +153,6 @@ private: unsigned int channelId = DramExtension::getExtension(payload).getChannel().ID(); // Check the valid range of initiatorSocket ID and channel Id - assert(initiatorSocket < Configuration::getInstance().NumberOfTracePlayers); assert(channelId < Configuration::getInstance().NumberOfMemChannels); // Phases initiated by the intiator side from arbiter's point of view (devices performing memory requests to the arbiter) @@ -210,10 +204,15 @@ private: if ((int)initiatorSocket != routeMap[&payload]) { SC_REPORT_FATAL("Arbiter", "Payload extension was corrupted"); } - // The arbiter receives a transaction in BEGIN_RESP phase (that came from the memory side) and forwards it to the requester device + // The arbiter receives a transaction in BEGIN_RESP phase + // (that came from the memory side) and forwards it to the requester + // device if (receivedResponses[initiatorSocket].empty()) + { sendToInitiator(initiatorSocket, payload, phase, SC_ZERO_TIME); - // Enqueue the transaction in BEGIN_RESP phase until the initiator device acknowledge it (phase changes to END_RESP). + } + // Enqueue the transaction in BEGIN_RESP phase until the initiator + // device acknowledge it (phase changes to END_RESP). receivedResponses[initiatorSocket].push(&payload); } else { SC_REPORT_FATAL(0, "Payload event queue in arbiter was triggered with unknown phase"); diff --git a/DRAMSys/simulator/src/simulation/dramSys.cpp b/DRAMSys/simulator/src/simulation/DRAMSys.cpp similarity index 90% rename from DRAMSys/simulator/src/simulation/dramSys.cpp rename to DRAMSys/simulator/src/simulation/DRAMSys.cpp index 98e7412c..2987bf70 100644 --- a/DRAMSys/simulator/src/simulation/dramSys.cpp +++ b/DRAMSys/simulator/src/simulation/DRAMSys.cpp @@ -41,7 +41,8 @@ #include #include -#include "dramSys.h" +#include "DRAMSys.h" +#include "Setup.h" #include "../common/TlmRecorder.h" #include "../common/DebugManager.h" #include "../common/xmlAddressdecoder.h" @@ -54,16 +55,24 @@ using namespace std; DRAMSys::DRAMSys(sc_module_name __attribute__((unused)) name, - string pathToResources, - string memspec, - string mcconfig, - string amconfig, - string simconfig, - string thermalconfig) + string simulationToRun, + string pathToResources) { logo(); - SC_THREAD(stop); + // Read Configuration Setup: + string memspec; + string mcconfig; + string amconfig; + string simconfig; + string thermalconfig; + + Setup setup(simulationToRun, + memspec, + mcconfig, + amconfig, + simconfig, + thermalconfig); // The xmlAddressDecoder MUST be initialized before calling the // ConfigurationLoader because some information from the xmlAddressDecoder @@ -116,9 +125,7 @@ void DRAMSys::logo() cout << REDTXT("=| |= ") << BOLDBLUETXT("University of Kaiserslautern") << endl; cout << REDTXT(" +---+ ") << endl; - cout << REDTXT(" ||| ") << "DRAMSys -" - << " Approximately-Timed TLM Models for DDR and Wide I/0 DRAM -" - << endl; + cout << REDTXT(" ||| ") << "DRAMSys v3.0" << endl; cout << endl; #undef REDTXT #undef BOLDBLUETXT @@ -265,38 +272,6 @@ DRAMSys::~DRAMSys() } } - -void DRAMSys::stop() -{ - wait(terminateSimulation); - - unsigned int pending_payloads = 0; - do - { - pending_payloads = 0; - for (auto controller : controllers) - { - pending_payloads += controller->getTotalNumberOfPayloadsInSystem(); - } - wait(sc_time(200, SC_NS)); - } - while(pending_payloads != 0); - - for (auto controller : controllers) - { - controller->terminateSimulation(); - } - - wait(sc_time(200, SC_NS)); - - for (auto rec : tlmRecorders) - { - rec->closeConnection(); - } - sc_stop(); -} - - void DRAMSys::report(string message) { DebugManager::getInstance().printDebugMessage(this->name(), message); diff --git a/DRAMSys/simulator/src/simulation/dramSys.h b/DRAMSys/simulator/src/simulation/DRAMSys.h similarity index 84% rename from DRAMSys/simulator/src/simulation/dramSys.h rename to DRAMSys/simulator/src/simulation/DRAMSys.h index 0e093b4e..14cbebf4 100644 --- a/DRAMSys/simulator/src/simulation/dramSys.h +++ b/DRAMSys/simulator/src/simulation/DRAMSys.h @@ -59,16 +59,11 @@ public: SC_HAS_PROCESS(DRAMSys); DRAMSys(sc_module_name name, - string pathToResources, - string memspec, - string mcconfig, - string amconfig, - string simconfig, - string thermalconfig); + string simulationToRun, + string pathToResources); ~DRAMSys(); - void stop(); void logo(); @@ -77,7 +72,8 @@ private: //DramSetup setup; //TLM 2.0 Protocol Checkers - std::vector*> controllersTlmCheckers; + std::vector*> + controllersTlmCheckers; // All transactions pass through the same arbiter Arbiter *arbiter; @@ -91,12 +87,15 @@ private: // DRAM units std::vector drams; - // Transaction Recorders (one per channel). They generate the output databases. + // Transaction Recorders (one per channel). + // They generate the output databases. std::vector tlmRecorders; void report(std::string message); - void setupTlmRecorders(const string &traceName, const string &pathToResources); - void instantiateModules(const string &traceName, const string &pathToResources); + void setupTlmRecorders(const string &traceName, + const string &pathToResources); + void instantiateModules(const string &traceName, + const string &pathToResources); void bindSockets(); void setupDebugManager(const string &traceName); }; diff --git a/DRAMSys/simulator/src/simulation/Dram.h b/DRAMSys/simulator/src/simulation/Dram.h index b9f74722..430e96ae 100644 --- a/DRAMSys/simulator/src/simulation/Dram.h +++ b/DRAMSys/simulator/src/simulation/Dram.h @@ -212,39 +212,85 @@ struct Dram : sc_module } } + virtual void end_of_simulation() + { + } + ~Dram() { - if (powerAnalysis == true) { - // Obtain the residual energy which was not covered by previous windows + if (powerAnalysis == true) + { + // Obtain the residual energy which was not covered by + // previous windows DRAMPower->calcEnergy(); - tlmRecorder->recordPower(sc_time_stamp().to_seconds(), DRAMPower->getPower().window_average_power * Configuration::getInstance().NumberOfDevicesOnDIMM); + tlmRecorder->recordPower(sc_time_stamp().to_seconds(), + DRAMPower->getPower().window_average_power + * Configuration::getInstance().NumberOfDevicesOnDIMM); - // Print the final total energy and the average power for the simulation - cout << name() << string("\tTotal Energy: \t") << fixed <getEnergy().total_energy * Configuration::getInstance().NumberOfDevicesOnDIMM << string(" pJ") << endl; - cout << name() << string("\tAverage Power: \t") << fixed <getPower().average_power * Configuration::getInstance().NumberOfDevicesOnDIMM<< string(" mW") << endl; + // Print the final total energy and the average power for + // the simulation: + cout << name() << string(" Total Energy: ") + << fixed <getEnergy().total_energy + * Configuration::getInstance().NumberOfDevicesOnDIMM + << string(" pJ") + << endl; + + cout << name() << string(" Average Power: ") + << fixed <getPower().average_power + * Configuration::getInstance().NumberOfDevicesOnDIMM + << string(" mW") << endl; } // Bandwidth: - sc_time activeTime = numberOfTransactionsServed * Configuration::getInstance().memSpec.BurstLength / Configuration::getInstance().memSpec.DataRate * Configuration::getInstance().memSpec.clk; + sc_time activeTime = numberOfTransactionsServed + * Configuration::getInstance().memSpec.BurstLength + / Configuration::getInstance().memSpec.DataRate + * Configuration::getInstance().memSpec.clk; + sc_time idleTime = dramController->getIdleTime(); sc_time endTime = dramController->getEndTime(); sc_time startTime = dramController->getStartTime(); + double bandwidth = (activeTime/(endTime-startTime)*100); double bandwidth_IDLE = ((activeTime)/(endTime-startTime-idleTime)*100); - // | clk in Mhz e.g. 800 [MHz] | * | DataRate e.g. 2 | * | BusWidth e.g. 8 | * | Number of devices on a DIMM e.g. 8 | / | 1024 | - double maxBandwidth = ( (1000000/Configuration::getInstance().memSpec.clk.to_double()) * Configuration::getInstance().memSpec.DataRate * Configuration::getInstance().memSpec.bitWidth * Configuration::getInstance().NumberOfDevicesOnDIMM ) / ( 1024 ); - cout << name() << string("\tTotal Time: \t") <<(endTime-startTime).to_string() << endl; - //cout << name() << string("\tTotal IDLE: \t") <closeConnection(); } // When working with floats, we have to decide ourselves what is an diff --git a/DRAMSys/simulator/src/simulation/Setup.cpp b/DRAMSys/simulator/src/simulation/Setup.cpp new file mode 100644 index 00000000..53d0eb8d --- /dev/null +++ b/DRAMSys/simulator/src/simulation/Setup.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2017, University of Kaiserslautern + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Authors: + * Matthias Jung + */ + +#include "Setup.h" + +Setup::Setup(std::string uri, + std::string & memspec, + std::string & mcconfig, + std::string & amconfig, + std::string & simconfig, + std::string & thermalconfig) +{ + // Load Simulation: + tinyxml2::XMLDocument simulationdoc; + loadXML(uri, simulationdoc); + + tinyxml2::XMLElement* simulation = + simulationdoc.FirstChildElement("simulation"); + + std::string xmlNodeName(simulation->Name()); + if( xmlNodeName != "simulation") + reportFatal("SimulationManager", + "Cannot load simulation: simulation node expected"); + + // Load all sub-configuration XML files: + tinyxml2::XMLElement* s; + + s = simulation->FirstChildElement("memspec"); + memspec = s->Attribute("src"); + + s = simulation->FirstChildElement("mcconfig"); + mcconfig = s->Attribute("src"); + + s = simulation->FirstChildElement("addressmapping"); + amconfig = s->Attribute("src"); + + s = simulation->FirstChildElement("simconfig"); + simconfig = s->Attribute("src"); + + s = simulation->FirstChildElement("thermalconfig"); + thermalconfig = s->Attribute("src"); + +} diff --git a/DRAMSys/simulator/src/simulation/Setup.h b/DRAMSys/simulator/src/simulation/Setup.h new file mode 100644 index 00000000..88ca5c41 --- /dev/null +++ b/DRAMSys/simulator/src/simulation/Setup.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2017, University of Kaiserslautern + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Authors: + * Matthias Jung + */ + +#ifndef SETUP_H +#define SETUP_H + +#include +#include + +#include "../common/Utils.h" +#include "TracePlayer.h" +#include "StlPlayer.h" + + +class Setup +{ +public: + Setup(std::string uri, + std::string & memspec, + std::string & mcconfig, + std::string & amconfig, + std::string & simconfig, + std::string & thermalconfig); +}; + +#endif // SETUP_H diff --git a/DRAMSys/simulator/src/simulation/Simulation.cpp b/DRAMSys/simulator/src/simulation/Simulation.cpp deleted file mode 100644 index eae30c9a..00000000 --- a/DRAMSys/simulator/src/simulation/Simulation.cpp +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Copyright (c) 2015, University of Kaiserslautern - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Authors: - * Janik Schlemminger - * Matthias Jung - * Eder F. Zulian - * Felipe S. Prado - */ - -#include -#include -#include -#include - -#include "Simulation.h" -#include "../common/TlmRecorder.h" -#include "../common/DebugManager.h" -#include "../common/xmlAddressdecoder.h" -#include "../controller/core/ControllerCore.h" -#include "../controller/core/configuration/ConfigurationLoader.h" -#include "../common/Utils.h" -#include "../simulation/TemperatureController.h" -#include "../controller/Controller.h" - -using namespace std; - -Simulation::Simulation(sc_module_name __attribute__((unused)) name, string pathToResources, string traceName, DramSetup setup, - std::vector devices) : traceName(traceName), dramSetup(setup) -{ - SC_THREAD(stop); - - // XXX: The xmlAddressDecoder MUST be initialized before calling the - // ConfigurationLoader because some information from the xmlAddressDecoder - // is needed to assure the coherence of the configuration. - xmlAddressDecoder::Initialize(setup.addressmapping); - xmlAddressDecoder::getInstance().print(); - - ConfigurationLoader::loadMCConfig(Configuration::getInstance(), setup.mcconfig); - ConfigurationLoader::loadMemSpec(Configuration::getInstance(), setup.memspec); - ConfigurationLoader::loadSimConfig(Configuration::getInstance(), setup.simconfig); - ConfigurationLoader::loadTemperatureSimConfig(Configuration::getInstance(), setup.thermalsimconfig); - - instantiateModules(traceName, pathToResources, devices); - bindSockets(); - setupDebugManager(traceName); -} - -void Simulation::setupDebugManager(const string& traceName) -{ - auto& dbg = DebugManager::getInstance(); - dbg.writeToConsole = true; - dbg.writeToFile = true; - if(dbg.writeToFile) - dbg.openDebugFile(traceName + ".txt"); -} - -void Simulation::setupTlmRecorders(const string &traceName, const string &pathToResources, const std::vector &devices) -{ - // Create TLM Recorders, one per channel. - for (size_t i = 0; i < Configuration::getInstance().NumberOfMemChannels; i++) { - std::string sqlScriptURI = pathToResources + string("scripts/createTraceDB.sql"); - std::string dbName = traceName + string("_channel") + std::to_string(i) + ".tdb"; - std::string recorderName = "tlmRecorder" + std::to_string(i); - TlmRecorder *tlmRecorder = new TlmRecorder(recorderName.c_str(), sqlScriptURI.c_str(), dbName.c_str(), Configuration::getInstance().DatabaseRecording); - - tlmRecorder->recordMCconfig(Configuration::getInstance().mcconfigUri); - tlmRecorder->recordMemspec(Configuration::getInstance().memspecUri); - - tlmRecorders.push_back(tlmRecorder); - - std::string traceNames; - for (size_t i = 0; i < devices.size(); i++) { - traceNames.append(devices[i].trace); - if (i == devices.size() - 1) - continue; - traceNames.append(","); - } - tlmRecorder->recordTracenames(traceNames); - } -} - -void Simulation::instantiateModules(const string &traceName, const string &pathToResources, const std::vector &devices) -{ - // The first call to getInstance() creates the Temperature Controller. - // The same instance will be accessed by all other modules. - TemperatureController::getInstance(); - - // Create and properly initialize TLM recorders. They need to be ready before creating some modules. - setupTlmRecorders(traceName, pathToResources, devices); - - arbiter = new Arbiter("arbiter"); - arbiter->setTlmRecorders(tlmRecorders); - - - for (size_t i = 0; i < Configuration::getInstance().NumberOfMemChannels; i++) { - std::string str = "controller" + std::to_string(i); - Controller *controller = new Controller(str.c_str(), tlmRecorders[i]); - controllers.push_back(controller); - - str = "dram" + std::to_string(i); - Dram *dram = new Dram(str.c_str()); - dram->setTlmRecorder(tlmRecorders[i]); - dram->setDramController(controllers[i]); - drams.push_back(dram); - - if(Configuration::getInstance().CheckTLM2Protocol) { - str = "TLMCheckerController"+ std::to_string(i); - tlm_utils::tlm2_base_protocol_checker<> * controllerTlmChecker = new tlm_utils::tlm2_base_protocol_checker<>(str.c_str()); - controllersTlmCheckers.push_back(controllerTlmChecker); - } - } -} - -void Simulation::bindSockets() -{ - tSocket.bind(arbiter->tSocket); - if(Configuration::getInstance().CheckTLM2Protocol) { - - for (size_t i = 0; i < Configuration::getInstance().NumberOfMemChannels; i++) { - arbiter->iSocket.bind(controllersTlmCheckers[i]->target_socket); - controllersTlmCheckers[i]->initiator_socket.bind(controllers[i]->tSocket); - controllers[i]->iSocket.bind(drams[i]->tSocket); - } - } else { - for (size_t i = 0; i < Configuration::getInstance().NumberOfMemChannels; i++) { - arbiter->iSocket.bind(controllers[i]->tSocket); - controllers[i]->iSocket.bind(drams[i]->tSocket); - } - } -} - -Simulation::~Simulation() -{ - - delete arbiter; - - for (auto controller : controllers) { - delete controller; - } - - for (auto dram : drams) { - delete dram; - } - - for (auto rec : tlmRecorders) { - delete rec; - } - - for (auto tlmChecker : controllersTlmCheckers) { - delete tlmChecker; - } -} - - -void Simulation::stop() -{ - wait(terminateSimulation); - - unsigned int pending_payloads = 0; - do { - pending_payloads = 0; - for (auto controller : controllers) { - pending_payloads += controller->getTotalNumberOfPayloadsInSystem(); - } - wait(sc_time(200, SC_NS)); - } while(pending_payloads != 0); - - for (auto controller : controllers) { - controller->terminateSimulation(); - } - wait(sc_time(200, SC_NS)); - for (auto rec : tlmRecorders) { - rec->closeConnection(); - } - sc_stop(); -} - - -void Simulation::report(string message) -{ - DebugManager::getInstance().printDebugMessage(this->name(), message); - cout << message << endl; -} diff --git a/DRAMSys/simulator/src/simulation/Simulation.h b/DRAMSys/simulator/src/simulation/Simulation.h deleted file mode 100644 index 45890b47..00000000 --- a/DRAMSys/simulator/src/simulation/Simulation.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2015, University of Kaiserslautern - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Authors: - * Janik Schlemminger - * Matthias Jung - * Eder F. Zulian - * Felipe S. Prado - */ - -#ifndef SIMULATION_H_ -#define SIMULATION_H_ - -#include -#include - -#include "Dram.h" -#include "Arbiter.h" -#include "TraceGenerator.h" -#include "ReorderBuffer.h" -#include "../controller/Controller.h" -#include "../common/third_party/tinyxml2/tinyxml2.h" -#include "../common/tlm2_base_protocol_checker.h" - - -struct DramSetup -{ - DramSetup():memspec(NULL),mcconfig(NULL),simconfig(NULL),addressmapping(NULL), thermalsimconfig(NULL) {} - DramSetup(tinyxml2::XMLElement* memspec, tinyxml2::XMLElement* mcconfig, tinyxml2::XMLElement* simconfig, tinyxml2::XMLElement* addressmapping, tinyxml2::XMLElement *tsc) - : memspec(memspec), mcconfig(mcconfig), simconfig(simconfig), addressmapping(addressmapping), thermalsimconfig(tsc) {} - tinyxml2::XMLElement* memspec; - tinyxml2::XMLElement* mcconfig; - tinyxml2::XMLElement* simconfig; - tinyxml2::XMLElement* addressmapping; - tinyxml2::XMLElement* thermalsimconfig; -}; - -struct Device -{ - Device():trace("empty.stl"), burstLength(0){} - Device(std::string trace, unsigned int clkMhz, unsigned int burstLength = 8) : trace(trace), clkMhz (clkMhz), burstLength(burstLength) - { - } - std::string trace; - unsigned int clkMhz; - unsigned int burstLength; -}; - -class Simulation: public sc_module -{ -public: - tlm_utils::multi_passthrough_target_socket tSocket; - - sc_event terminateSimulation; - - SC_HAS_PROCESS(Simulation); - Simulation(sc_module_name name, string pathToResources, string traceName, DramSetup setup, - std::vector devices); - ~Simulation(); - - void stop(); - - -private: - std::string traceName; - DramSetup dramSetup; - - //TLM 2.0 Protocol Checkers - std::vector*> controllersTlmCheckers; - - // All transactions pass through the same arbiter - Arbiter *arbiter; - // Each DRAM unit has a controller - std::vector controllers; - // TODO: Each DRAM has a reorder buffer (check this!) - ReorderBuffer *reorder; - // DRAM units - std::vector drams; - // Transaction Recorders (one per channel). They generate the output databases. - std::vector tlmRecorders; - - void report(std::string message); - void setupTlmRecorders(const string &traceName, const string &pathToResources, const std::vector &devices); - void instantiateModules(const string &traceName, const string &pathToResources, const std::vector &devices); - void bindSockets(); - void setupDebugManager(const string &traceName); -}; - -#endif /* SIMULATIONMANAGER_H_ */ diff --git a/DRAMSys/simulator/src/simulation/SimulationManager.cpp b/DRAMSys/simulator/src/simulation/SimulationManager.cpp deleted file mode 100644 index a3494667..00000000 --- a/DRAMSys/simulator/src/simulation/SimulationManager.cpp +++ /dev/null @@ -1,310 +0,0 @@ -/* - * Copyright (c) 2015, University of Kaiserslautern - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Authors: - * Janik Schlemminger - * Matthias Jung - * Eder F. Zulian - */ - -#include -#include - -#include "SimulationManager.h" -#include "../common/Utils.h" - -using namespace std; -using namespace tinyxml2; - -SimulationManager::SimulationManager(string resources) : resources(resources) -{ -} - -SimulationManager::~SimulationManager() -{ - for (auto player : players) { - delete player; - } -#if USE_EXAMPLE_INITIATOR - delete init; - delete exampleInitiatorTlmChecker; -#endif - - for (auto tlmChecker : playersTlmCheckers) { - delete tlmChecker; - } -} - -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-> simulation batches loaded successfully!\n" << endl; - - for (auto batch : simulationBatches) - { - batch.print(); - } -} - -void SimulationManager::runSimulations() -{ - for (auto& batch : simulationBatches) - { - boost::filesystem::path dir(exportPath); - boost::filesystem::create_directories(dir); - - for (auto& dramSetup : batch.dramSetups) - { - for (auto& traceSetup : batch.traceSetups) - { - string exportname = exportPath + "/" + traceSetup.first; - instantiateModules(exportname, dramSetup, traceSetup.second); - bindSockets(); - runSimulation(exportname); - } - } - } -} - -void SimulationManager::parseSimulationBatch(XMLElement* simulation) -{ - SimulationBatch batch; - - XMLElement* simconfig = simulation->FirstChildElement("simconfig"); - - XMLElement *thermalsimconfig = simulation->FirstChildElement("thermalsimconfig"); - - XMLElement* memspecs = simulation->FirstChildElement("memspecs"); - if(memspecs == NULL) memspecs = simulation; - - XMLElement* addressmappings = simulation->FirstChildElement("addressmappings"); - if(addressmappings == NULL) addressmappings = simulation; - - XMLElement* mcconfigs = simulation->FirstChildElement("mcconfigs"); - if(mcconfigs == NULL) mcconfigs = simulation; - - for (XMLElement* memspec = memspecs->FirstChildElement("memspec"); memspec != NULL; - memspec = memspec->NextSiblingElement("memspec")) - { - - for (XMLElement* addressmapping = addressmappings->FirstChildElement("addressmapping"); addressmapping != NULL; - addressmapping = addressmapping->NextSiblingElement("addressmapping")) - { - - for (XMLElement* mcconfig = mcconfigs->FirstChildElement("mcconfig"); - mcconfig != NULL; mcconfig = mcconfig->NextSiblingElement("mcconfig")) - { - batch.dramSetups.push_back(DramSetup(memspec, mcconfig, simconfig, addressmapping, thermalsimconfig)); - } - } - } - - addTraceSetups(batch, simulation); - - simulationBatches.push_back(batch); -} - -void SimulationManager::instantiateModules(string traceName, DramSetup dramSetup, vector traceSetup) -{ - - simulation = new Simulation("sim", resources, traceName, dramSetup, traceSetup); - -#if USE_EXAMPLE_INITIATOR - init = new ExampleInitiator("init"); - if(Configuration::getInstance().CheckTLM2Protocol) { - string str = "ExampleInitiatorTLMChecker"; - exampleInitiatorTlmChecker = new tlm_utils::tlm2_base_protocol_checker<>(str.c_str()); - } -#else - for (size_t i = 0; i < Configuration::getInstance().NumberOfTracePlayers; i++) { - std::string playerStr = "tracePlayer" + std::to_string(i); - TracePlayer *player; - sc_time playerClk; - - // The clock frequency for the player can be specified in the - // configuration file like in the example below (200 MHz): - // - // - // - // chstone-adpcm_32.stl - // - // - // - // If it is not specified in the configuration, the player will be - // configured to use the memory clock frequency got from the memory - // specs. - if (traceSetup[i].clkMhz == 0) - playerClk = Configuration::getInstance().memSpec.clk; - else - playerClk = FrequencyToClk(traceSetup[i].clkMhz); - const string pathToResources = resources; - player = new StlPlayer(playerStr.c_str(), pathToResources + string("traces/") + traceSetup[i].trace, playerClk, this); - if(Configuration::getInstance().SimulationProgressBar) - { - totalTransactions += player->getNumberOfLines(pathToResources + string("traces/") + traceSetup[i].trace); - } - players.push_back(player); - - if(Configuration::getInstance().CheckTLM2Protocol) { - string str = "TLMCheckerPlayer"+ std::to_string(i); - tlm_utils::tlm2_base_protocol_checker<> * playerTlmChecker = new tlm_utils::tlm2_base_protocol_checker<>(str.c_str()); - playersTlmCheckers.push_back(playerTlmChecker); - } - } - remainingTransactions = totalTransactions; -#endif /* USE_EXAMPLE_INITIATOR */ -} - -void SimulationManager::bindSockets() -{ -#if USE_EXAMPLE_INITIATOR - if(Configuration::getInstance().CheckTLM2Protocol) { - init->socket.bind(exampleInitiatorTlmChecker->target_socket); - exampleInitiatorTlmChecker->initiator_socket.bind(simulation->tSocket); - - } - else { - init->socket.bind(simulation->tSocket); -#else - if(Configuration::getInstance().CheckTLM2Protocol) { - for (size_t i = 0; i < players.size(); i++) { - players[i]->iSocket.bind(playersTlmCheckers[i]->target_socket); - playersTlmCheckers[i]->initiator_socket.bind(simulation->tSocket); - } - - } - else { - for (auto player : players) { - player->iSocket.bind(simulation->tSocket); - } - -#endif - } -} - -void SimulationManager::runSimulation(string traceName) -{ - report("\n\nStarting simulation:"); - report(headline); - report(" -> setup: \t\t" + getFileName(traceName)); - report(" -> memspec: \t\t" + Configuration::getInstance().memSpec.MemoryId); - cout << endl; - simStartTime = clock(); - - for (auto player : players) { - player->nextPayload(); - } - - sc_set_stop_mode(SC_STOP_FINISH_DELTA); - sc_start(); - double elapsed_secs = double(clock() - simStartTime) / CLOCKS_PER_SEC; - report("\nSimulation took " + to_string(elapsed_secs) + " seconds\n"); - delete simulation; -} - -void SimulationManager::startTraceAnalyzer() -{ - string p = getenv("trace"); - string run_tpr = p + " -f "; - run_tpr += "&"; - system(run_tpr.c_str()); -} - -void SimulationManager::addTraceSetups(SimulationBatch &batch, tinyxml2::XMLElement *simulation) -{ - vector devices; - XMLElement *tracesetups = simulation->FirstChildElement("tracesetups"); - XMLElement *simconfig = simulation->FirstChildElement("simconfig"); - unsigned int numberOfTracePlayers = 1; - XMLElement *ntp = simconfig->FirstChildElement("NumberOfTracePlayers"); - if (ntp != NULL) - ntp->QueryUnsignedAttribute("value", &numberOfTracePlayers); - - for (XMLElement *tracesetup = tracesetups->FirstChildElement("tracesetup"); tracesetup != NULL; tracesetup = tracesetup->NextSiblingElement("tracesetup")) { - for (XMLElement *device = tracesetup->FirstChildElement("device"); device != NULL; device = device->NextSiblingElement("device")) { - devices.push_back(Device(device->GetText(), device->IntAttribute("clkMhz"), device->IntAttribute("bl"))); - } - - // This step is done here to add a default device in case the user haven't specified a trace file to be executed by one or more trace players. - while (devices.size() < numberOfTracePlayers) { - devices.push_back(Device()); - } - - batch.traceSetups.emplace(tracesetup->Attribute("id"), devices); - devices.clear(); - } -} - -void inline SimulationManager::tracePlayerTerminates() -{ - static unsigned int finishedTracePlayers = 0; - finishedTracePlayers++; - - if (finishedTracePlayers == Configuration::getInstance().NumberOfTracePlayers) - simulation->terminateSimulation.notify(); -} -void inline SimulationManager::transactionFinished() -{ - remainingTransactions--; - loadbar(totalTransactions - remainingTransactions, totalTransactions); - if (remainingTransactions == 0) - { - cout << endl; - } -} -void SimulationManager::report(string message) -{ - cout << message << endl; -} - -void SimulationBatch::print() -{ - 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/DRAMSys/simulator/src/simulation/StlPlayer.cpp b/DRAMSys/simulator/src/simulation/StlPlayer.cpp index 2ed2dd5f..75817aba 100644 --- a/DRAMSys/simulator/src/simulation/StlPlayer.cpp +++ b/DRAMSys/simulator/src/simulation/StlPlayer.cpp @@ -39,7 +39,12 @@ #include "StlPlayer.h" -StlPlayer::StlPlayer(sc_module_name, string pathToTrace, sc_time playerClk, TracePlayerListener *listener) : TracePlayer(listener), file(pathToTrace) +StlPlayer::StlPlayer(sc_module_name, + string pathToTrace, + sc_time playerClk, + TracePlayerListener *listener) : + TracePlayer(listener), + file(pathToTrace) { if (!file.is_open()) SC_REPORT_FATAL(0, (string("Could not open trace ") + pathToTrace).c_str()); @@ -62,11 +67,16 @@ void StlPlayer::nextPayload() line.clear(); } - if (!file) { + if (!file) + { // The file is empty. Nothing more to do. - this->terminate(); + this->finish(); return; } + else + { + numberOfTransactions++; + } // Allocate a generic payload for this request. gp *payload = this->allocatePayload(); diff --git a/DRAMSys/simulator/src/simulation/StlPlayer.h b/DRAMSys/simulator/src/simulation/StlPlayer.h index b27463bc..a3b12ec4 100644 --- a/DRAMSys/simulator/src/simulation/StlPlayer.h +++ b/DRAMSys/simulator/src/simulation/StlPlayer.h @@ -49,7 +49,10 @@ using namespace tlm; struct StlPlayer: public TracePlayer { public: - StlPlayer(sc_module_name /*name*/, string pathToTrace, sc_time playerClk, TracePlayerListener *listener); + StlPlayer(sc_module_name /*name*/, + string pathToTrace, + sc_time playerClk, + TracePlayerListener *listener); void nextPayload(); diff --git a/DRAMSys/simulator/src/simulation/TraceGenerator.h b/DRAMSys/simulator/src/simulation/TraceGenerator.h index 4e727713..13c2ed72 100644 --- a/DRAMSys/simulator/src/simulation/TraceGenerator.h +++ b/DRAMSys/simulator/src/simulation/TraceGenerator.h @@ -60,25 +60,25 @@ public: virtual void nextPayload() override { - if(transCounter >= 1000) // TODO set limit! - { - this->terminate(); - } + if(transCounter >= 1000) // TODO set limit! + { + this->terminate(); + } - gp* payload = this->allocatePayload(); + gp* payload = this->allocatePayload(); - unsigned char * dataElement = new unsigned char[16]; // TODO: column / burst breite + unsigned char * dataElement = new unsigned char[16]; // TODO: column / burst breite - payload->set_address(0x0); - payload->set_response_status(TLM_INCOMPLETE_RESPONSE); - payload->set_dmi_allowed(false); - payload->set_byte_enable_length(0); - payload->set_streaming_width(this->burstlenght); - payload->set_data_ptr(dataElement); - payload->set_data_length(16); - payload->set_command(TLM_READ_COMMAND); - transCounter++; - this->payloadEventQueue.notify(*payload, BEGIN_REQ, SC_ZERO_TIME); + payload->set_address(0x0); + payload->set_response_status(TLM_INCOMPLETE_RESPONSE); + payload->set_dmi_allowed(false); + payload->set_byte_enable_length(0); + payload->set_streaming_width(this->burstlenght); + payload->set_data_ptr(dataElement); + payload->set_data_length(16); + payload->set_command(TLM_READ_COMMAND); + transCounter++; + this->payloadEventQueue.notify(*payload, BEGIN_REQ, SC_ZERO_TIME); } private: diff --git a/DRAMSys/simulator/src/simulation/TracePlayer.cpp b/DRAMSys/simulator/src/simulation/TracePlayer.cpp index 8965f4a0..d9dfc008 100644 --- a/DRAMSys/simulator/src/simulation/TracePlayer.cpp +++ b/DRAMSys/simulator/src/simulation/TracePlayer.cpp @@ -39,7 +39,12 @@ #include "TracePlayer.h" TracePlayer::TracePlayer(TracePlayerListener* listener) : - payloadEventQueue(this, &TracePlayer::peqCallback), transactionsSent(0), listener(listener) + payloadEventQueue(this, &TracePlayer::peqCallback), + transactionsSent(0), + transactionsReceived(0), + listener(listener), + numberOfTransactions(0), + finished(false) { iSocket.register_nb_transport_bw(this, &TracePlayer::nb_transport_bw); } @@ -49,6 +54,11 @@ gp *TracePlayer::allocatePayload() return memoryManager.allocate(); } +void TracePlayer::finish() +{ + finished = true; +} + void TracePlayer::terminate() { cout << sc_time_stamp() << " " << this->name() << " terminated " << std::endl; @@ -87,6 +97,14 @@ void TracePlayer::peqCallback(tlm_generic_payload &payload, const tlm_phase &pha payload.release(); if(Configuration::getInstance().SimulationProgressBar) listener->transactionFinished(); + + transactionsReceived++; + + // If all answers were received: + if(finished == true && numberOfTransactions == transactionsReceived) + { + this->terminate(); + } } else if (phase == END_RESP) { @@ -97,6 +115,11 @@ void TracePlayer::peqCallback(tlm_generic_payload &payload, const tlm_phase &pha } } +void TracePlayer::setNumberOfTransactions(unsigned int n) +{ + numberOfTransactions = n; +} + unsigned int TracePlayer::getNumberOfLines(string pathToTrace) { ifstream newFile; diff --git a/DRAMSys/simulator/src/simulation/TracePlayer.h b/DRAMSys/simulator/src/simulation/TracePlayer.h index 6d5fccd9..6a022f5e 100644 --- a/DRAMSys/simulator/src/simulation/TracePlayer.h +++ b/DRAMSys/simulator/src/simulation/TracePlayer.h @@ -67,8 +67,11 @@ public: protected: gp* allocatePayload(); tlm_utils::peq_with_cb_and_phase payloadEventQueue; + void finish(); void terminate(); void printDebugMessage(std::string message); + void setNumberOfTransactions(unsigned int n); + unsigned int numberOfTransactions; private: tlm_sync_enum nb_transport_bw(tlm_generic_payload& payload, tlm_phase& phase, sc_time& bwDelay); @@ -81,7 +84,9 @@ private: } MemoryManager memoryManager; unsigned int transactionsSent; + unsigned int transactionsReceived; TracePlayerListener* listener; + bool finished; }; #endif /* TRACEPLAYER_H_ */ diff --git a/DRAMSys/simulator/src/simulation/TraceSetup.cpp b/DRAMSys/simulator/src/simulation/TraceSetup.cpp new file mode 100644 index 00000000..9c26cded --- /dev/null +++ b/DRAMSys/simulator/src/simulation/TraceSetup.cpp @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2017, University of Kaiserslautern + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Authors: + * Matthias Jung + */ + +#include "TraceSetup.h" + +traceSetup::traceSetup(std::string uri, + std::string pathToResources, + std::vector * devices) +{ + // Load Simulation: + tinyxml2::XMLDocument simulationdoc; + loadXML(uri, simulationdoc); + + tinyxml2::XMLElement* simulation = + simulationdoc.FirstChildElement("simulation"); + + std::string xmlNodeName(simulation->Name()); + if( xmlNodeName != "simulation") + reportFatal("traceSetup", + "Cannot load simulation: simulation node expected"); + + // Load TracePlayers: + tinyxml2::XMLElement *tracesetup = + simulation->FirstChildElement("tracesetup"); + + for (tinyxml2::XMLElement *device = + tracesetup->FirstChildElement("device"); + device != NULL; + device = device->NextSiblingElement("device")) + { + sc_time playerClk; + unsigned int frequency = device->IntAttribute("clkMhz"); + + if (frequency == 0) + { + reportFatal("traceSetup","No Frequency Defined"); + } + else + { + playerClk = FrequencyToClk(frequency); + } + + std::string name = device->GetText(); + std::string stlFile = pathToResources + string("traces/") + name; + std::string moduleName = name; + + // replace all '.' to '_' + std::replace( moduleName.begin(), moduleName.end(), '.', '_'); + + StlPlayer * player = new StlPlayer(moduleName.c_str(), + stlFile, + playerClk, + this); + + devices->push_back(player); + + if(Configuration::getInstance().SimulationProgressBar) + { + totalTransactions += player->getNumberOfLines(stlFile); + } + } + remainingTransactions = totalTransactions; + NumberOfTracePlayers = devices->size(); + cout << "NumberOfTracePlayers: " << NumberOfTracePlayers << endl; + cout << "totalTransactions: " << totalTransactions << endl; +} + + + +void traceSetup::tracePlayerTerminates() +{ + finishedTracePlayers++; + + if (finishedTracePlayers == NumberOfTracePlayers) + { + //simulation->terminateSimulation.notify(); + sc_stop(); + } +} +void traceSetup::transactionFinished() +{ + remainingTransactions--; + + loadbar(totalTransactions - remainingTransactions, totalTransactions); + + if (remainingTransactions == 0) + { + cout << endl; + } +} diff --git a/DRAMSys/simulator/src/simulation/SimulationManager.h b/DRAMSys/simulator/src/simulation/TraceSetup.h similarity index 50% rename from DRAMSys/simulator/src/simulation/SimulationManager.h rename to DRAMSys/simulator/src/simulation/TraceSetup.h index 54f564e6..a9f0b8e5 100644 --- a/DRAMSys/simulator/src/simulation/SimulationManager.h +++ b/DRAMSys/simulator/src/simulation/TraceSetup.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, University of Kaiserslautern + * Copyright (c) 2017, University of Kaiserslautern * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -30,80 +30,35 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * Authors: - * Janik Schlemminger * Matthias Jung - * Eder F. Zulian */ -#ifndef SIMULATIONMANAGER_H_ -#define SIMULATIONMANAGER_H_ +#ifndef TRACESETUP_H +#define TRACESETUP_H #include #include -#include -#include "Simulation.h" + +#include "../common/Utils.h" #include "TracePlayer.h" #include "StlPlayer.h" -#include "../controller/core/configuration/ConfigurationLoader.h" -#include "../common/third_party/tinyxml2/tinyxml2.h" -#include "ExampleInitiator.h" -#include "../common/tlm2_base_protocol_checker.h" -#define USE_EXAMPLE_INITIATOR 0 -struct SimulationBatch -{ - std::vector dramSetups; - std::map> traceSetups; - void print(); -}; - -class SimulationManager: public TracePlayerListener +class traceSetup : public TracePlayerListener { public: - SimulationManager(std::string resources); - ~SimulationManager(); - - void loadSimulationsFromXML(std::string uri); - - void runSimulations(); - void startTraceAnalyzer(); + traceSetup(std::string uri, + std::string pathToResources, + std::vector * devices); virtual void tracePlayerTerminates() override; virtual void transactionFinished() override; private: - std::string resources; - std::string exportPath; - std::string basePath; - - tinyxml2::XMLDocument simulationdoc; - - std::vector simulationBatches; - - // A vector of pointers to all trace player (devices which acquire the bus - // and initiate transactions targeting the memory) - std::vector players; - Simulation* simulation; - clock_t simStartTime; - //TLM 2.0 Protocol Checkers - std::vector*> playersTlmCheckers; - + unsigned int NumberOfTracePlayers; unsigned int totalTransactions = 0; unsigned int remainingTransactions; - -#if USE_EXAMPLE_INITIATOR - ExampleInitiator *init; - tlm_utils::tlm2_base_protocol_checker<>* exampleInitiatorTlmChecker; -#endif - void instantiateModules(std::string traceName, DramSetup dramSetup, std::vector traceSetup); - void bindSockets(); - void runSimulation(string traceName); - void parseSimulationBatch(tinyxml2::XMLElement* simulation); - void addTraceSetups(SimulationBatch &batch, tinyxml2::XMLElement *element); - - void report(std::string message); - + unsigned int finishedTracePlayers = 0; }; -#endif /* SIMULATIONMANAGER_H_ */ +#endif // TRACESETUP_H diff --git a/DRAMSys/simulator/src/simulation/main.cpp b/DRAMSys/simulator/src/simulation/main.cpp index 5fb07b81..a592af7b 100644 --- a/DRAMSys/simulator/src/simulation/main.cpp +++ b/DRAMSys/simulator/src/simulation/main.cpp @@ -40,12 +40,10 @@ #include #include -//XXX -//#include "SimulationManager.h" -#include "dramSys.h" +#include "DRAMSys.h" +#include "TraceSetup.h" #include "ExampleInitiator.h" - using namespace std; string resources; @@ -60,8 +58,6 @@ int main(int argc, char **argv) return sc_main(argc, argv); } - - int sc_main(int argc, char **argv) { sc_set_time_resolution(1, SC_PS); @@ -70,31 +66,45 @@ int sc_main(int argc, char **argv) resources = pathOfFile(argv[0]) + string("/../../DRAMSys/simulator/resources/"); - string simulationToRun; + string SimulationXML; if(argc > 1) - simulationToRun = argv[1]; + { + SimulationXML = argv[1]; + } else - simulationToRun = resources + "simulations/sim-batch.xml"; + { + SimulationXML = resources + "simulations/ddr3-example.xml"; + } + std::vector players; - DRAMSys dramSystem("dramSystem", - "../../DRAMSys/simulator/resources/", - "wideio.xml", - "fifoStrict.xml", - "am_wideio.xml", - "wideio.xml", - "config.xml"); + // Instantiate DRAMSys: + DRAMSys dramSys("DRAMSys", SimulationXML, resources); - ExampleInitiator trageGenerator("traceGenerator"); + // Instantiate STL Players: + traceSetup setup = traceSetup(SimulationXML, resources, &players); - trageGenerator.socket.bind(dramSystem.tSocket); + // Bind STL Players with DRAMSys: + for(auto& p : players) + { + p->iSocket.bind(dramSys.tSocket); + } - SC_REPORT_INFO("sc_main", "Start of Simulation"); + // Store the starting of the simulation in wallclock time: + clock_t simStartTime = clock(); - sc_core::sc_start(); + // Kickstart the players: + for (auto& p : players) + { + p->nextPayload(); + } - SC_REPORT_INFO("sc_main", "End of Simulation"); + // Start SystemC Simulation: + sc_set_stop_mode(SC_STOP_FINISH_DELTA); + sc_start(); + + double elapsed_secs = double(clock() - simStartTime) / CLOCKS_PER_SEC; + cout << "Simulation took " + to_string(elapsed_secs) + " seconds" << endl; return 0; } - From 6713046d47d3384c8a53fec2725665d79ffd41cd Mon Sep 17 00:00:00 2001 From: Matthias Jung Date: Sun, 19 Feb 2017 14:57:40 +0100 Subject: [PATCH 04/19] small changes --- .../configs/simulator/ddr3-single-device.xml | 2 +- .../resources/configs/simulator/ddr3.xml | 2 +- .../resources/configs/simulator/wideio.xml | 2 +- DRAMSys/simulator/resources/resources.pri | 18 +++++++----------- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/DRAMSys/simulator/resources/configs/simulator/ddr3-single-device.xml b/DRAMSys/simulator/resources/configs/simulator/ddr3-single-device.xml index cc8f9de5..a366a987 100644 --- a/DRAMSys/simulator/resources/configs/simulator/ddr3-single-device.xml +++ b/DRAMSys/simulator/resources/configs/simulator/ddr3-single-device.xml @@ -4,7 +4,7 @@ - + diff --git a/DRAMSys/simulator/resources/configs/simulator/ddr3.xml b/DRAMSys/simulator/resources/configs/simulator/ddr3.xml index e066cefe..4390ad5c 100644 --- a/DRAMSys/simulator/resources/configs/simulator/ddr3.xml +++ b/DRAMSys/simulator/resources/configs/simulator/ddr3.xml @@ -4,7 +4,7 @@ - + diff --git a/DRAMSys/simulator/resources/configs/simulator/wideio.xml b/DRAMSys/simulator/resources/configs/simulator/wideio.xml index 607db393..b9bc18b9 100644 --- a/DRAMSys/simulator/resources/configs/simulator/wideio.xml +++ b/DRAMSys/simulator/resources/configs/simulator/wideio.xml @@ -4,7 +4,7 @@ - + diff --git a/DRAMSys/simulator/resources/resources.pri b/DRAMSys/simulator/resources/resources.pri index 1a58ad75..ba981845 100644 --- a/DRAMSys/simulator/resources/resources.pri +++ b/DRAMSys/simulator/resources/resources.pri @@ -1,15 +1,11 @@ # Relative paths to "DRAMSys/simulator" because this file is included in # "DRAMSys/simulator/simulator.pro" -# simulation files -OTHER_FILES += +# Simulation Files OTHER_FILES += resources/simulations/ddr3-example.xml OTHER_FILES += resources/simulations/ddr3-single-device.xml -# Simulator Configuration: -OTHER_FILES += - -# scripts +# Scripts OTHER_FILES += resources/scripts/address_scrambler.pl OTHER_FILES += resources/scripts/createTraceDB.sql OTHER_FILES += resources/scripts/stride_detection.pl @@ -18,7 +14,7 @@ OTHER_FILES += resources/scripts/video_rendering/temperatur.job.pl OTHER_FILES += resources/scripts/video_rendering/temperatur.pl OTHER_FILES += resources/scripts/video_rendering/Makefile -# trace files +# Trace Files OTHER_FILES += resources/traces/chstone-aes_32.stl OTHER_FILES += resources/traces/test2.stl OTHER_FILES += resources/traces/voco2.stl @@ -56,17 +52,16 @@ OTHER_FILES += resources/traces/ddr3_example.stl OTHER_FILES += resources/traces/ddr3_single_dev_example.stl OTHER_FILES += resources/traces/ddr3_SAMSUNG_M471B5674QH0_DIMM_example.stl -# mcconfigs +# Mempry Controller Configs OTHER_FILES += resources/configs/mcconfigs/fifoStrict.xml OTHER_FILES += resources/configs/mcconfigs/fifo.xml OTHER_FILES += resources/configs/mcconfigs/fr_fcfs.xml OTHER_FILES += resources/configs/mcconfigs/par_bs.xml -# memspecs +# Memspecs OTHER_FILES += resources/configs/memspecs/memspec.dtd OTHER_FILES += resources/configs/memspecs/MatzesWideIO.xml OTHER_FILES += resources/configs/memspecs/DDR4.xml -OTHER_FILES += OTHER_FILES += resources/configs/memspecs/MatzesWideIO-short.xml OTHER_FILES += resources/configs/memspecs/MICRON_1Gb_DDR3-1600_8bit_G.xml OTHER_FILES += resources/configs/memspecs/JEDEC_256Mb_WIDEIO_SDR-200_128bit.xml @@ -135,5 +130,6 @@ DISTFILES += \ $$PWD/configs/simulator/ddr3.xml \ $$PWD/configs/memspecs/wideio.xml \ $$PWD/configs/simulator/ddr3-single-device.xml \ - $$PWD/simulations/wideio-example.xml + $$PWD/simulations/wideio-example.xml \ + $$PWD/configs/simulator/wideio_thermal.xml From 42887ad0eb957fda198f94e1e7d5ab1a54d5db86 Mon Sep 17 00:00:00 2001 From: Matthias Jung Date: Sun, 19 Feb 2017 14:57:52 +0100 Subject: [PATCH 05/19] Readme updated --- README.md | 379 ++++++++++++++++++++++++++---------------------------- 1 file changed, 180 insertions(+), 199 deletions(-) diff --git a/README.md b/README.md index 5a4ac2a5..e674b867 100644 --- a/README.md +++ b/README.md @@ -474,105 +474,6 @@ The IP address and the port number related to the server shall be informed in DRAMSys' configuration to subsequent use by DRAMSys to access the thermal simulation server. -#### Usage Example - -The DRAMSys' main configuration file is presented below. - -``` xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ../../../tests/error/test_error.stl - - - - -``` - -Enable the error model in fr_fcfs.xml. - -``` xml - - - - - - - - - - - - - - -``` - -Generate the input trace file for DRAMSys. - -``` bash -$ cd DRAMSys/tests/error/ -$ ./generateErrorTest.pl > test_error.stl -``` - -Start the 3D-ICE server providing the stack file and the port number. - -``` bash -$ cd DRAMSys/simulator/resources/configs/thermalsim -$ 3D-ICE-Server stack.stk 11880 -``` - -In another terminal or terminal tab start DRAMSys. Here the program's output -is redirected to a file. - -``` bash -$ cd build/simulator/ -$ ./dramSys > output -``` - ### DRAMSys Configuration The **dramSys** executable supports one argument which is a XML file that @@ -583,72 +484,32 @@ The XML code below shows a typic configuration: ``` xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - voco2.stl - voco2.stl - voco2.stl - - - + + + + + + + + + + + + + + ddr3_example.stl + ddr3_example.stl + ``` - Some configuration fields reference other XML files which contain more specialized chunks of the configuration like memory specification, address mapping and memory configurations. @@ -668,18 +529,25 @@ each of the simulation setups. A single **trace setup** is composed of an id string and one or more **devices**. -The **device** configuration consists of two configuration fields - clkMhz -(operation frequency for this device) and bl (burst length) - and a -**trace file**. +The **device** configuration consists of two parameters - clkMhz +(operation frequency for this device) - and a **trace file**. A **trace file** is a pre-recorded file containing memory transactions. Each memory transaction has a timestamp that tells the simulator when it shall happen, a transaction type (e.g. read, write) and a memory address. -A **trace player** is **equivalent** to a bus master **device** (i.e. a device -that locks a bus and generates memory transactions). By adding device elements -into the trace setup section one can specify the operation frequency, the -burst length and the trace file to be used by trace players. +Here is an example syntax: +``` +31: read 0x400140 +33: read 0x400160 +56: read 0x7fff8000 +81: read 0x400180 +``` + +A **trace player** is **equivalent** to a bus master **device** +(e.g. a processor). By adding device elements into the trace setup section +one can specify the operation frequency, the burst length and the trace file +to be used by trace players. Trace players without a corresponding device configuration do not generate transactions. @@ -689,13 +557,34 @@ providing **flexibility** for **exhaustive explorations.** #### Configuration File Sections -The main configuration file is divided into self-contained sections, each of -these sections is a set of logically related configuration aspects for the -simulation. +The main configuration file is divided into self-contained sections. Each of +these sections refers to sub-configuration files. -Below are listed the configuration sections and configuration fields. +Below, the sub-configurations are listed and explained. - **Simulator Configuration** + + The content of + [ddr3.xml](DRAMSys/simulator/resources/configs/simulator/ddr3.xml) is + presented below as an example. + + ```xml + + + + + + + + + + + + + ``` + + - *SimulationName* (boolean) + - Give the name of the simulation for distingushing from other simulations. - *Debug* (boolean) - "1": enables debug output on console - "0": disables debug output @@ -714,9 +603,6 @@ Below are listed the configuration sections and configuration fields. - Number of trace players - *NumberOfMemChannels* (unsigned int) - Number of memory channels - - *ControllerCoreDisableRefresh* (boolean) - - "1": disables refreshes - - "0": normal operation (refreshes enabled) - *ThermalSimulation* (boolean) - "1": enables thermal simulation - "0": static temperature during simulation @@ -730,6 +616,27 @@ Below are listed the configuration sections and configuration fields. - "0": disables the TLM 2.0 Protocol Checking - **Temperature Simulator Configuration** + + The content of + [config.xml](DRAMSys/simulator/resources/configs/thermalsim/config.xml) is + presented below as an example. + + ```xml + + + + + + + + + + + + + + ``` + - *TemperatureScale* (string) - "Celsius" - "Fahrenheit" @@ -764,8 +671,8 @@ Below are listed the configuration sections and configuration fields. - **Memory Specification** - A file with memory specifications. This information comes from datasheet and - usually does not change. + A file with memory specifications. This information comes from datasheets and + measurements, and usually does not change. - **Address Mapping** @@ -808,19 +715,26 @@ Below are listed the configuration sections and configuration fields. presented below as an example. ``` xml - - - - - - - - - - - - - + + + + + + + + + + + + + + + + ``` - *BankwiseLogic* (boolean) @@ -856,17 +770,13 @@ Below are listed the configuration sections and configuration fields. - "NoStorage": no storage - "Store": store data without error model - "ErrorModel": store data with error model [6] + - *ControllerCoreDisableRefresh* (boolean) + - "1": disables refreshes + - "0": normal operation (refreshes enabled) - **Trace Setups** - - *id* (string) - - Trace setup id. Two kinds of output files are generated by DRAMSys: - SQLite databases containing transactions related to each memory channel - (.tdb) and a text file (.txt) with the program output. The base name for - these files comes from this field. - *clkMhz* (unsigned int) - Speed of the trace player - - *bl* (unsigned int) - - Burst length - *trace file* - A pre-recorded file containing memory transactions to be executed by a trace player. @@ -894,6 +804,77 @@ A description of the content each directory follows. - **traces**: trace files for simulations. They contain accesses to memory in certain known scenarios. +#### Usage Example with Thermal Simulation + +The DRAMSys' main configuration file is presented below. + +``` xml + + + + + + + + + + + + + + + test_error.stl + + +``` + +Enable the error model in fr_fcfs.xml. + +``` xml + + + + + + + + + + + + + + +``` + +Generate the input trace file for DRAMSys. + +``` bash +$ cd DRAMSys/tests/error/ +$ ./generateErrorTest.pl > test_error.stl +``` + +Start the 3D-ICE server providing the stack file and the port number. + +``` bash +$ cd DRAMSys/simulator/resources/configs/thermalsim +$ 3D-ICE-Server stack.stk 11880 +``` + +In another terminal or terminal tab start DRAMSys. Here the program's output +is redirected to a file. + +``` bash +$ cd build/simulator/ +$ ./dramSys > output +``` + #### DRAMsys Diagrams - **Payload Extension information** From e9f29c92eafec7c8713674e5c605164ac2be6851 Mon Sep 17 00:00:00 2001 From: Matthias Jung Date: Sun, 19 Feb 2017 17:49:37 +0100 Subject: [PATCH 06/19] Small Changes --- .../configs/simulator/ddr3-single-device.xml | 1 + .../simulator/resources/configs/simulator/ddr3.xml | 1 + .../resources/configs/simulator/wideio.xml | 1 + .../resources/configs/simulator/wideio_thermal.xml | 14 ++++++++++++++ .../resources/simulations/ddr3-example.xml | 2 +- .../resources/simulations/ddr3-single-device.xml | 2 +- .../resources/simulations/wideio-example.xml | 2 +- DRAMSys/simulator/src/simulation/TraceSetup.cpp | 2 -- DRAMSys/simulator/src/simulation/main.cpp | 2 +- README.md | 4 ++-- 10 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 DRAMSys/simulator/resources/configs/simulator/wideio_thermal.xml diff --git a/DRAMSys/simulator/resources/configs/simulator/ddr3-single-device.xml b/DRAMSys/simulator/resources/configs/simulator/ddr3-single-device.xml index a366a987..3dec948e 100644 --- a/DRAMSys/simulator/resources/configs/simulator/ddr3-single-device.xml +++ b/DRAMSys/simulator/resources/configs/simulator/ddr3-single-device.xml @@ -9,4 +9,5 @@ + diff --git a/DRAMSys/simulator/resources/configs/simulator/ddr3.xml b/DRAMSys/simulator/resources/configs/simulator/ddr3.xml index 4390ad5c..d13a4acc 100644 --- a/DRAMSys/simulator/resources/configs/simulator/ddr3.xml +++ b/DRAMSys/simulator/resources/configs/simulator/ddr3.xml @@ -9,4 +9,5 @@ + diff --git a/DRAMSys/simulator/resources/configs/simulator/wideio.xml b/DRAMSys/simulator/resources/configs/simulator/wideio.xml index b9bc18b9..c811e71a 100644 --- a/DRAMSys/simulator/resources/configs/simulator/wideio.xml +++ b/DRAMSys/simulator/resources/configs/simulator/wideio.xml @@ -9,5 +9,6 @@ + diff --git a/DRAMSys/simulator/resources/configs/simulator/wideio_thermal.xml b/DRAMSys/simulator/resources/configs/simulator/wideio_thermal.xml new file mode 100644 index 00000000..42dcda72 --- /dev/null +++ b/DRAMSys/simulator/resources/configs/simulator/wideio_thermal.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/DRAMSys/simulator/resources/simulations/ddr3-example.xml b/DRAMSys/simulator/resources/simulations/ddr3-example.xml index a9ae4a7d..7fda33e5 100644 --- a/DRAMSys/simulator/resources/simulations/ddr3-example.xml +++ b/DRAMSys/simulator/resources/simulations/ddr3-example.xml @@ -13,7 +13,7 @@ The following trace setup is only used in standalone mode. In library mode e.g. in Platform Architect the trace setup is ignored. --> - + - + - + diff --git a/DRAMSys/simulator/src/simulation/TraceSetup.cpp b/DRAMSys/simulator/src/simulation/TraceSetup.cpp index 9c26cded..aafcdd20 100644 --- a/DRAMSys/simulator/src/simulation/TraceSetup.cpp +++ b/DRAMSys/simulator/src/simulation/TraceSetup.cpp @@ -93,8 +93,6 @@ traceSetup::traceSetup(std::string uri, } remainingTransactions = totalTransactions; NumberOfTracePlayers = devices->size(); - cout << "NumberOfTracePlayers: " << NumberOfTracePlayers << endl; - cout << "totalTransactions: " << totalTransactions << endl; } diff --git a/DRAMSys/simulator/src/simulation/main.cpp b/DRAMSys/simulator/src/simulation/main.cpp index a592af7b..e6a4388d 100644 --- a/DRAMSys/simulator/src/simulation/main.cpp +++ b/DRAMSys/simulator/src/simulation/main.cpp @@ -82,7 +82,7 @@ int sc_main(int argc, char **argv) DRAMSys dramSys("DRAMSys", SimulationXML, resources); // Instantiate STL Players: - traceSetup setup = traceSetup(SimulationXML, resources, &players); + traceSetup(SimulationXML, resources, &players); // Bind STL Players with DRAMSys: for(auto& p : players) diff --git a/README.md b/README.md index e674b867..3c1b7646 100644 --- a/README.md +++ b/README.md @@ -498,7 +498,7 @@ The XML code below shows a typic configuration: The following trace setup is only used in standalone mode. In library mode e.g. in Platform Architect the trace setup is ignored. --> - + - +