From 21e43468f47daf48d5fdf35dae3a7668749d94e0 Mon Sep 17 00:00:00 2001 From: Matthias Jung Date: Thu, 16 Feb 2017 21:03:43 +0100 Subject: [PATCH] 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; }