From fcdd96c19e685cec56c05a57368b50cd3199fbe3 Mon Sep 17 00:00:00 2001 From: Lukas Steiner Date: Tue, 15 Feb 2022 09:39:06 +0100 Subject: [PATCH] Use smart pointers. --- DRAMSys/library/src/common/TlmRecorder.cpp | 3 +- DRAMSys/library/src/common/TlmRecorder.h | 7 +- .../src/controller/ControllerRecordable.cpp | 10 +- .../src/controller/ControllerRecordable.h | 4 +- DRAMSys/library/src/simulation/DRAMSys.cpp | 77 +++++---------- DRAMSys/library/src/simulation/DRAMSys.h | 20 ++-- .../src/simulation/DRAMSysRecordable.cpp | 93 ++++++------------- .../src/simulation/DRAMSysRecordable.h | 8 +- .../src/simulation}/LengthConverter.cpp | 0 .../src/simulation}/LengthConverter.h | 0 .../src/simulation/dram/DramRecordable.cpp | 10 +- .../src/simulation/dram/DramRecordable.h | 4 +- DRAMSys/simulator/StlPlayer.cpp | 3 +- DRAMSys/simulator/StlPlayer.h | 1 - DRAMSys/simulator/TraceSetup.cpp | 15 +-- DRAMSys/simulator/TrafficGenerator.cpp | 11 +-- DRAMSys/simulator/TrafficGenerator.h | 3 - DRAMSys/simulator/TrafficInitiator.cpp | 10 +- DRAMSys/simulator/TrafficInitiator.h | 4 +- DRAMSys/simulator/main.cpp | 40 +------- 20 files changed, 95 insertions(+), 228 deletions(-) rename DRAMSys/{simulator => library/src/simulation}/LengthConverter.cpp (100%) rename DRAMSys/{simulator => library/src/simulation}/LengthConverter.h (100%) diff --git a/DRAMSys/library/src/common/TlmRecorder.cpp b/DRAMSys/library/src/common/TlmRecorder.cpp index c056de77..83d062c0 100644 --- a/DRAMSys/library/src/common/TlmRecorder.cpp +++ b/DRAMSys/library/src/common/TlmRecorder.cpp @@ -34,6 +34,7 @@ * Robert Gernhardt * Matthias Jung * Eder F. Zulian + * Lukas Steiner */ #include @@ -69,7 +70,7 @@ TlmRecorder::TlmRecorder(const std::string &name, const std::string &dbName) : PRINTDEBUGMESSAGE(name, "Starting new database transaction"); } -TlmRecorder::~TlmRecorder() +void TlmRecorder::finalize() { if (db) closeConnection(); diff --git a/DRAMSys/library/src/common/TlmRecorder.h b/DRAMSys/library/src/common/TlmRecorder.h index 6b92859d..dabe3ec5 100644 --- a/DRAMSys/library/src/common/TlmRecorder.h +++ b/DRAMSys/library/src/common/TlmRecorder.h @@ -34,6 +34,7 @@ * Robert Gernhardt * Matthias Jung * Eder F. Zulian + * Lukas Steiner */ #ifndef TLMRECORDER_H @@ -54,7 +55,8 @@ class TlmRecorder { public: TlmRecorder(const std::string &name, const std::string &dbName); - ~TlmRecorder(); + TlmRecorder(const TlmRecorder&) = delete; + TlmRecorder(TlmRecorder&&) = default; void recordMcConfig(std::string _mcconfig) { @@ -78,7 +80,7 @@ public: void recordDebugMessage(const std::string &message, const sc_core::sc_time &time); void updateDataStrobe(const sc_core::sc_time &begin, const sc_core::sc_time &end, tlm::tlm_generic_payload &trans); - void closeConnection(); + void finalize(); private: struct Transaction @@ -113,6 +115,7 @@ private: static void executeSqlStatement(sqlite3_stmt *statement); void openDB(const std::string &dbName); + void closeConnection(); void introduceTransactionSystem(tlm::tlm_generic_payload &trans); void removeTransactionFromSystem(tlm::tlm_generic_payload &trans); diff --git a/DRAMSys/library/src/controller/ControllerRecordable.cpp b/DRAMSys/library/src/controller/ControllerRecordable.cpp index 254155e3..eb168cbb 100644 --- a/DRAMSys/library/src/controller/ControllerRecordable.cpp +++ b/DRAMSys/library/src/controller/ControllerRecordable.cpp @@ -39,7 +39,7 @@ using namespace sc_core; using namespace tlm; -ControllerRecordable::ControllerRecordable(const sc_module_name &name, TlmRecorder *tlmRecorder) +ControllerRecordable::ControllerRecordable(const sc_module_name &name, TlmRecorder& tlmRecorder) : Controller(name), tlmRecorder(tlmRecorder) { if (Configuration::getInstance().enableWindowing) @@ -78,7 +78,7 @@ void ControllerRecordable::sendToDram(Command command, tlm_generic_payload *payl if (command.isCasCommand()) { TimeInterval dataStrobe = Configuration::getInstance().memSpec->getIntervalOnDataStrobe(command, *payload); - tlmRecorder->updateDataStrobe(sc_time_stamp() + delay + dataStrobe.start, + tlmRecorder.updateDataStrobe(sc_time_stamp() + delay + dataStrobe.start, sc_time_stamp() + delay + dataStrobe.end, *payload); } tlm_phase phase = command.toPhase(); @@ -103,7 +103,7 @@ void ControllerRecordable::recordPhase(tlm_generic_payload &trans, const tlm_pha bg) + " bank " + std::to_string(bank) + " row " + std::to_string(row) + " column " + std::to_string(col) + " id " + std::to_string(id) + " at " + recTime.to_string()); - tlmRecorder->recordPhase(trans, phase, recTime); + tlmRecorder.recordPhase(trans, phase, recTime); } void ControllerRecordable::controllerMethod() @@ -128,7 +128,7 @@ void ControllerRecordable::controllerMethod() slidingAverageBufferDepth[index] = SC_ZERO_TIME; } - tlmRecorder->recordBufferDepth(sc_time_stamp().to_seconds(), windowAverageBufferDepth); + tlmRecorder.recordBufferDepth(sc_time_stamp().to_seconds(), windowAverageBufferDepth); Controller::controllerMethod(); @@ -136,7 +136,7 @@ void ControllerRecordable::controllerMethod() lastNumberOfBeatsServed = numberOfBeatsServed; sc_time windowActiveTime = activeTimeMultiplier * static_cast(windowNumberOfBeatsServed); double windowAverageBandwidth = windowActiveTime / windowSizeTime; - tlmRecorder->recordBandwidth(sc_time_stamp().to_seconds(), windowAverageBandwidth); + tlmRecorder.recordBandwidth(sc_time_stamp().to_seconds(), windowAverageBandwidth); } else { diff --git a/DRAMSys/library/src/controller/ControllerRecordable.h b/DRAMSys/library/src/controller/ControllerRecordable.h index d2300f71..f0f0ae57 100644 --- a/DRAMSys/library/src/controller/ControllerRecordable.h +++ b/DRAMSys/library/src/controller/ControllerRecordable.h @@ -43,7 +43,7 @@ class ControllerRecordable final : public Controller { public: - ControllerRecordable(const sc_core::sc_module_name &name, TlmRecorder *tlmRecorder); + ControllerRecordable(const sc_core::sc_module_name &name, TlmRecorder& tlmRecorder); ~ControllerRecordable() override = default; protected: @@ -59,7 +59,7 @@ protected: private: void recordPhase(tlm::tlm_generic_payload &trans, const tlm::tlm_phase &phase, const sc_core::sc_time &delay); - TlmRecorder *tlmRecorder; + TlmRecorder& tlmRecorder; sc_core::sc_event windowEvent; sc_core::sc_time windowSizeTime; diff --git a/DRAMSys/library/src/simulation/DRAMSys.cpp b/DRAMSys/library/src/simulation/DRAMSys.cpp index f4b7f96d..5fc0f168 100644 --- a/DRAMSys/library/src/simulation/DRAMSys.cpp +++ b/DRAMSys/library/src/simulation/DRAMSys.cpp @@ -116,23 +116,6 @@ DRAMSys::DRAMSys(const sc_core::sc_module_name &name, } } -DRAMSys::~DRAMSys() -{ - delete arbiter; - - for (auto dram : drams) - delete dram; - - for (auto controller : controllers) - delete controller; - - for (auto tlmChecker : playersTlmCheckers) - delete tlmChecker; - - for (auto tlmChecker : controllersTlmCheckers) - delete tlmChecker; -} - void DRAMSys::logo() { #define GREENTXT(s) std::string(("\u001b[38;5;28m"+std::string((s))+"\033[0m")) @@ -179,57 +162,45 @@ void DRAMSys::instantiateModules(const std::string &pathToResources, // Create arbiter if (config.arbiter == Configuration::Arbiter::Simple) - arbiter = new ArbiterSimple("arbiter", pathToResources + "configs/amconfigs/" + amconfig); + arbiter = std::unique_ptr(new ArbiterSimple("arbiter", pathToResources + "configs/amconfigs/" + amconfig)); else if (config.arbiter == Configuration::Arbiter::Fifo) - arbiter = new ArbiterFifo("arbiter", pathToResources + "configs/amconfigs/" + amconfig); + arbiter = std::unique_ptr(new ArbiterFifo("arbiter", pathToResources + "configs/amconfigs/" + amconfig)); else if (config.arbiter == Configuration::Arbiter::Reorder) - arbiter = new ArbiterReorder("arbiter", pathToResources + "configs/amconfigs/" + amconfig); + arbiter = std::unique_ptr(new ArbiterReorder("arbiter", pathToResources + "configs/amconfigs/" + amconfig)); // Create controllers and DRAMs MemSpec::MemoryType memoryType = config.memSpec->memoryType; for (std::size_t i = 0; i < config.memSpec->numberOfChannels; i++) { - std::string str = "controller" + std::to_string(i); - - ControllerIF *controller = new Controller(str.c_str()); - controllers.push_back(controller); - - str = "dram" + std::to_string(i); - Dram *dram; + controllers.emplace_back(new Controller(("controller" + std::to_string(i)).c_str())); if (memoryType == MemSpec::MemoryType::DDR3) - dram = new DramDDR3(str.c_str()); + drams.emplace_back(new DramDDR3(("dram" + std::to_string(i)).c_str())); else if (memoryType == MemSpec::MemoryType::DDR4) - dram = new DramDDR4(str.c_str()); + drams.emplace_back(new DramDDR4(("dram" + std::to_string(i)).c_str())); else if (memoryType == MemSpec::MemoryType::DDR5) - dram = new DramDDR5(str.c_str()); + drams.emplace_back(new DramDDR5(("dram" + std::to_string(i)).c_str())); else if (memoryType == MemSpec::MemoryType::WideIO) - dram = new DramWideIO(str.c_str()); + drams.emplace_back(new DramWideIO(("dram" + std::to_string(i)).c_str())); else if (memoryType == MemSpec::MemoryType::LPDDR4) - dram = new DramLPDDR4(str.c_str()); + drams.emplace_back(new DramLPDDR4(("dram" + std::to_string(i)).c_str())); else if (memoryType == MemSpec::MemoryType::LPDDR5) - dram = new DramLPDDR5(str.c_str()); + drams.emplace_back(new DramLPDDR5(("dram" + std::to_string(i)).c_str())); else if (memoryType == MemSpec::MemoryType::WideIO2) - dram = new DramWideIO2(str.c_str()); + drams.emplace_back(new DramWideIO2(("dram" + std::to_string(i)).c_str())); else if (memoryType == MemSpec::MemoryType::HBM2) - dram = new DramHBM2(str.c_str()); + drams.emplace_back(new DramHBM2(("dram" + std::to_string(i)).c_str())); else if (memoryType == MemSpec::MemoryType::GDDR5) - dram = new DramGDDR5(str.c_str()); + drams.emplace_back(new DramGDDR5(("dram" + std::to_string(i)).c_str())); else if (memoryType == MemSpec::MemoryType::GDDR5X) - dram = new DramGDDR5X(str.c_str()); + drams.emplace_back(new DramGDDR5X(("dram" + std::to_string(i)).c_str())); else if (memoryType == MemSpec::MemoryType::GDDR6) - dram = new DramGDDR6(str.c_str()); + drams.emplace_back(new DramGDDR6(("dram" + std::to_string(i)).c_str())); else if (memoryType == MemSpec::MemoryType::STTMRAM) - dram = new DramSTTMRAM(str.c_str()); + drams.emplace_back(new DramSTTMRAM(("dram" + std::to_string(i)).c_str())); - drams.push_back(dram); - - if (Configuration::getInstance().checkTLM2Protocol) - { - str = "TLMCheckerController" + std::to_string(i); - auto* controllerTlmChecker = new tlm_utils::tlm2_base_protocol_checker<>(str.c_str()); - controllersTlmCheckers.push_back(controllerTlmChecker); - } + if (config.checkTLM2Protocol) + controllersTlmCheckers.push_back(new tlm_utils::tlm2_base_protocol_checker<>(("TlmCheckerController" + std::to_string(i)).c_str())); } } @@ -239,22 +210,18 @@ void DRAMSys::bindSockets() tSocket.bind(arbiter->tSocket); - if (config.checkTLM2Protocol) + for (unsigned i = 0; i < config.memSpec->numberOfChannels; i++) { - for (std::size_t i = 0; i < config.memSpec->numberOfChannels; i++) + if (config.checkTLM2Protocol) { arbiter->iSocket.bind(controllersTlmCheckers[i]->target_socket); controllersTlmCheckers[i]->initiator_socket.bind(controllers[i]->tSocket); - controllers[i]->iSocket.bind(drams[i]->tSocket); } - } - else - { - for (std::size_t i = 0; i < config.memSpec->numberOfChannels; i++) + else { arbiter->iSocket.bind(controllers[i]->tSocket); - controllers[i]->iSocket.bind(drams[i]->tSocket); } + controllers[i]->iSocket.bind(drams[i]->tSocket); } } diff --git a/DRAMSys/library/src/simulation/DRAMSys.h b/DRAMSys/library/src/simulation/DRAMSys.h index 1f17d9a6..5cda9a9a 100644 --- a/DRAMSys/library/src/simulation/DRAMSys.h +++ b/DRAMSys/library/src/simulation/DRAMSys.h @@ -41,6 +41,8 @@ #define DRAMSYS_H #include +#include +#include #include #include "dram/Dram.h" @@ -57,16 +59,11 @@ class DRAMSys : public sc_core::sc_module public: tlm_utils::multi_passthrough_target_socket tSocket; - std::vector*> - playersTlmCheckers; - SC_HAS_PROCESS(DRAMSys); DRAMSys(const sc_core::sc_module_name &name, const std::string &simulationToRun, const std::string &pathToResources); - ~DRAMSys() override; - protected: DRAMSys(const sc_core::sc_module_name &name, const std::string &simulationToRun, @@ -74,29 +71,28 @@ protected: bool initAndBind); //TLM 2.0 Protocol Checkers - std::vector*> - controllersTlmCheckers; + std::vector*> controllersTlmCheckers; // TODO: Each DRAM has a reorder buffer (check this!) - ReorderBuffer *reorder; + std::unique_ptr reorder; // All transactions pass through the same arbiter - Arbiter *arbiter; + std::unique_ptr arbiter; // Each DRAM unit has a controller - std::vector controllers; + std::vector> controllers; // DRAM units - std::vector drams; + std::vector> drams; void report(const std::string &message); + void bindSockets(); private: static void logo(); void instantiateModules(const std::string &pathToResources, const std::string &amconfig); - void bindSockets(); static void setupDebugManager(const std::string &traceName); }; diff --git a/DRAMSys/library/src/simulation/DRAMSysRecordable.cpp b/DRAMSys/library/src/simulation/DRAMSysRecordable.cpp index a11dc841..39d9ce17 100644 --- a/DRAMSys/library/src/simulation/DRAMSysRecordable.cpp +++ b/DRAMSys/library/src/simulation/DRAMSysRecordable.cpp @@ -80,17 +80,17 @@ DRAMSysRecordable::DRAMSysRecordable(const sc_module_name &name, report(headline); } -DRAMSysRecordable::~DRAMSysRecordable() +void DRAMSysRecordable::end_of_simulation() { // Report power before TLM recorders are deleted if (Configuration::getInstance().powerAnalysis) { - for (auto dram : drams) + for (auto& dram : drams) dram->reportPower(); } - for (auto rec : tlmRecorders) - delete rec; + for (auto& tlmRecorder : tlmRecorders) + tlmRecorder.finalize(); } void DRAMSysRecordable::setupTlmRecorders(const std::string &traceName) @@ -99,17 +99,12 @@ void DRAMSysRecordable::setupTlmRecorders(const std::string &traceName) for (std::size_t i = 0; i < Configuration::getInstance().memSpec->numberOfChannels; i++) { std::string dbName = traceName + std::string("_ch") + std::to_string(i) + ".tdb"; - std::string recorderName = "tlmRecorder" + std::to_string(i); - auto* tlmRecorder = new TlmRecorder(recorderName, dbName); - tlmRecorder->recordMcConfig(Configuration::mcconfigUri); - tlmRecorder->recordMemspec(Configuration::memspecUri); - - std::string traceNames = Configuration::getInstance().simulationName; - tlmRecorder->recordTraceNames(traceNames); - - tlmRecorders.push_back(tlmRecorder); + tlmRecorders.emplace_back(recorderName, dbName); + tlmRecorders.back().recordMcConfig(Configuration::mcconfigUri); + tlmRecorders.back().recordMemspec(Configuration::memspecUri); + tlmRecorders.back().recordTraceNames(Configuration::getInstance().simulationName); } } @@ -129,81 +124,45 @@ void DRAMSysRecordable::instantiateModules(const std::string &traceName, // Create arbiter if (config.arbiter == Configuration::Arbiter::Simple) - arbiter = new ArbiterSimple("arbiter", pathToResources + "configs/amconfigs/" + amconfig); + arbiter = std::unique_ptr(new ArbiterSimple("arbiter", pathToResources + "configs/amconfigs/" + amconfig)); else if (config.arbiter == Configuration::Arbiter::Fifo) - arbiter = new ArbiterFifo("arbiter", pathToResources + "configs/amconfigs/" + amconfig); + arbiter = std::unique_ptr(new ArbiterFifo("arbiter", pathToResources + "configs/amconfigs/" + amconfig)); else if (config.arbiter == Configuration::Arbiter::Reorder) - arbiter = new ArbiterReorder("arbiter", pathToResources + "configs/amconfigs/" + amconfig); + arbiter = std::unique_ptr(new ArbiterReorder("arbiter", pathToResources + "configs/amconfigs/" + amconfig)); // Create controllers and DRAMs MemSpec::MemoryType memoryType = config.memSpec->memoryType; for (std::size_t i = 0; i < config.memSpec->numberOfChannels; i++) { - std::string str = "controller" + std::to_string(i); - - ControllerIF *controller = new ControllerRecordable(str.c_str(), tlmRecorders[i]); - controllers.push_back(controller); - - str = "dram" + std::to_string(i); - Dram *dram; + controllers.emplace_back(new ControllerRecordable(("controller" + std::to_string(i)).c_str(), tlmRecorders[i])); if (memoryType == MemSpec::MemoryType::DDR3) - dram = new DramRecordable(str.c_str(), tlmRecorders[i]); + drams.emplace_back(new DramRecordable(("dram" + std::to_string(i)).c_str(), tlmRecorders[i])); else if (memoryType == MemSpec::MemoryType::DDR4) - dram = new DramRecordable(str.c_str(), tlmRecorders[i]); + drams.emplace_back(new DramRecordable(("dram" + std::to_string(i)).c_str(), tlmRecorders[i])); else if (memoryType == MemSpec::MemoryType::DDR5) - dram = new DramRecordable(str.c_str(), tlmRecorders[i]); + drams.emplace_back(new DramRecordable(("dram" + std::to_string(i)).c_str(), tlmRecorders[i])); else if (memoryType == MemSpec::MemoryType::WideIO) - dram = new DramRecordable(str.c_str(), tlmRecorders[i]); + drams.emplace_back(new DramRecordable(("dram" + std::to_string(i)).c_str(), tlmRecorders[i])); else if (memoryType == MemSpec::MemoryType::LPDDR4) - dram = new DramRecordable(str.c_str(), tlmRecorders[i]); + drams.emplace_back(new DramRecordable(("dram" + std::to_string(i)).c_str(), tlmRecorders[i])); else if (memoryType == MemSpec::MemoryType::LPDDR5) - dram = new DramRecordable(str.c_str(), tlmRecorders[i]); + drams.emplace_back(new DramRecordable(("dram" + std::to_string(i)).c_str(), tlmRecorders[i])); else if (memoryType == MemSpec::MemoryType::WideIO2) - dram = new DramRecordable(str.c_str(), tlmRecorders[i]); + drams.emplace_back(new DramRecordable(("dram" + std::to_string(i)).c_str(), tlmRecorders[i])); else if (memoryType == MemSpec::MemoryType::HBM2) - dram = new DramRecordable(str.c_str(), tlmRecorders[i]); + drams.emplace_back(new DramRecordable(("dram" + std::to_string(i)).c_str(), tlmRecorders[i])); else if (memoryType == MemSpec::MemoryType::GDDR5) - dram = new DramRecordable(str.c_str(), tlmRecorders[i]); + drams.emplace_back(new DramRecordable(("dram" + std::to_string(i)).c_str(), tlmRecorders[i])); else if (memoryType == MemSpec::MemoryType::GDDR5X) - dram = new DramRecordable(str.c_str(), tlmRecorders[i]); + drams.emplace_back(new DramRecordable(("dram" + std::to_string(i)).c_str(), tlmRecorders[i])); else if (memoryType == MemSpec::MemoryType::GDDR6) - dram = new DramRecordable(str.c_str(), tlmRecorders[i]); + drams.emplace_back(new DramRecordable(("dram" + std::to_string(i)).c_str(), tlmRecorders[i])); else if (memoryType == MemSpec::MemoryType::STTMRAM) - dram = new DramRecordable(str.c_str(), tlmRecorders[i]); - - drams.push_back(dram); + drams.emplace_back(new DramRecordable(("dram" + std::to_string(i)).c_str(), tlmRecorders[i])); if (config.checkTLM2Protocol) - { - str = "TLMCheckerController" + std::to_string(i); - auto* controllerTlmChecker = new tlm_utils::tlm2_base_protocol_checker<>(str.c_str()); - controllersTlmCheckers.push_back(controllerTlmChecker); - } - } -} - -void DRAMSysRecordable::bindSockets() -{ - Configuration &config = Configuration::getInstance(); - - tSocket.bind(arbiter->tSocket); - - if (config.checkTLM2Protocol) - { - for (std::size_t i = 0; i < config.memSpec->numberOfChannels; 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 (std::size_t i = 0; i < config.memSpec->numberOfChannels; i++) - { - arbiter->iSocket.bind(controllers[i]->tSocket); - controllers[i]->iSocket.bind(drams[i]->tSocket); - } + controllersTlmCheckers.emplace_back(new tlm_utils::tlm2_base_protocol_checker<>(("TLMCheckerController" + + std::to_string(i)).c_str())); } } diff --git a/DRAMSys/library/src/simulation/DRAMSysRecordable.h b/DRAMSys/library/src/simulation/DRAMSysRecordable.h index 876b3d6f..cd5f3f0c 100644 --- a/DRAMSys/library/src/simulation/DRAMSysRecordable.h +++ b/DRAMSys/library/src/simulation/DRAMSysRecordable.h @@ -46,20 +46,18 @@ public: const std::string &simulationToRun, const std::string &pathToResources); - ~DRAMSysRecordable() override; - private: // Transaction Recorders (one per channel). // They generate the output databases. - std::vector tlmRecorders; + std::vector tlmRecorders; + + void end_of_simulation() override; void setupTlmRecorders(const std::string &traceName); void instantiateModules(const std::string &traceName, const std::string &pathToResources, const std::string &amconfig); - - void bindSockets(); }; #endif // DRAMSYSRECORDABLE_H diff --git a/DRAMSys/simulator/LengthConverter.cpp b/DRAMSys/library/src/simulation/LengthConverter.cpp similarity index 100% rename from DRAMSys/simulator/LengthConverter.cpp rename to DRAMSys/library/src/simulation/LengthConverter.cpp diff --git a/DRAMSys/simulator/LengthConverter.h b/DRAMSys/library/src/simulation/LengthConverter.h similarity index 100% rename from DRAMSys/simulator/LengthConverter.h rename to DRAMSys/library/src/simulation/LengthConverter.h diff --git a/DRAMSys/library/src/simulation/dram/DramRecordable.cpp b/DRAMSys/library/src/simulation/dram/DramRecordable.cpp index 0638adb3..330d868c 100644 --- a/DRAMSys/library/src/simulation/dram/DramRecordable.cpp +++ b/DRAMSys/library/src/simulation/dram/DramRecordable.cpp @@ -55,7 +55,7 @@ using namespace sc_core; using namespace tlm; template -DramRecordable::DramRecordable(const sc_module_name &name, TlmRecorder *tlmRecorder) +DramRecordable::DramRecordable(const sc_module_name &name, TlmRecorder& tlmRecorder) : BaseDram(name), tlmRecorder(tlmRecorder) { // Create a thread that is triggered every $powerWindowSize @@ -68,7 +68,7 @@ template void DramRecordable::reportPower() { BaseDram::reportPower(); - tlmRecorder->recordPower(sc_time_stamp().to_seconds(), + tlmRecorder.recordPower(sc_time_stamp().to_seconds(), this->DRAMPower->getPower().window_average_power * Configuration::getInstance().memSpec->numberOfDevices); } @@ -103,12 +103,12 @@ void DramRecordable::recordPhase(tlm_generic_payload &trans, const tlm bg) + " bank " + std::to_string(bank) + " row " + std::to_string(row) + " column " + std::to_string(col) + " at " + recTime.to_string()); - tlmRecorder->recordPhase(trans, phase, recTime); + tlmRecorder.recordPhase(trans, phase, recTime); if (phaseNeedsEnd(phase)) { recTime += this->memSpec->getExecutionTime(Command(phase), trans); - tlmRecorder->recordPhase(trans, getEndPhase(phase), recTime); + tlmRecorder.recordPhase(trans, getEndPhase(phase), recTime); } } @@ -134,7 +134,7 @@ void DramRecordable::powerWindow() assert(!isEqual(this->DRAMPower->getEnergy().window_energy, 0.0)); // Store the time (in seconds) and the current average power (in mW) into the database - tlmRecorder->recordPower(sc_time_stamp().to_seconds(), + tlmRecorder.recordPower(sc_time_stamp().to_seconds(), this->DRAMPower->getPower().window_average_power * Configuration::getInstance().memSpec->numberOfDevices); diff --git a/DRAMSys/library/src/simulation/dram/DramRecordable.h b/DRAMSys/library/src/simulation/dram/DramRecordable.h index 4e456536..02dff955 100644 --- a/DRAMSys/library/src/simulation/dram/DramRecordable.h +++ b/DRAMSys/library/src/simulation/dram/DramRecordable.h @@ -46,7 +46,7 @@ template class DramRecordable final : public BaseDram { public: - DramRecordable(const sc_core::sc_module_name &name, TlmRecorder *); + DramRecordable(const sc_core::sc_module_name &name, TlmRecorder& tlmRecorder); SC_HAS_PROCESS(DramRecordable); void reportPower() override; @@ -57,7 +57,7 @@ private: void recordPhase(tlm::tlm_generic_payload &trans, const tlm::tlm_phase &phase, const sc_core::sc_time &delay); - TlmRecorder *tlmRecorder; + TlmRecorder& tlmRecorder; sc_core::sc_time powerWindowSize = Configuration::getInstance().memSpec->tCK * Configuration::getInstance().windowSize; diff --git a/DRAMSys/simulator/StlPlayer.cpp b/DRAMSys/simulator/StlPlayer.cpp index b864c899..fb309182 100644 --- a/DRAMSys/simulator/StlPlayer.cpp +++ b/DRAMSys/simulator/StlPlayer.cpp @@ -48,10 +48,9 @@ StlPlayer::StlPlayer(const sc_module_name &name, const sc_time &playerClk, unsigned int maxPendingReadRequests, unsigned int maxPendingWriteRequests, - bool needsLengthConverter, TraceSetup *setup, bool relative) : - TrafficInitiator(name, setup, maxPendingReadRequests, maxPendingWriteRequests, needsLengthConverter), + TrafficInitiator(name, setup, maxPendingReadRequests, maxPendingWriteRequests), file(pathToTrace), relative(relative), playerClk(playerClk) { currentBuffer = &lineContents[0]; diff --git a/DRAMSys/simulator/StlPlayer.h b/DRAMSys/simulator/StlPlayer.h index 9858eba9..8f6af2af 100644 --- a/DRAMSys/simulator/StlPlayer.h +++ b/DRAMSys/simulator/StlPlayer.h @@ -69,7 +69,6 @@ public: const sc_core::sc_time &playerClk, unsigned int maxPendingReadRequests, unsigned int maxPendingWriteRequests, - bool needsLengthConverter, TraceSetup *setup, bool relative); diff --git a/DRAMSys/simulator/TraceSetup.cpp b/DRAMSys/simulator/TraceSetup.cpp index fc800dd5..b76ed6bf 100644 --- a/DRAMSys/simulator/TraceSetup.cpp +++ b/DRAMSys/simulator/TraceSetup.cpp @@ -83,11 +83,6 @@ TraceSetup::TraceSetup(const std::string &uri, if (value["maxPendingWriteRequests"].is_number_unsigned()) maxPendingWriteRequests = value["maxPendingWriteRequests"]; - bool needsLengthConverter = false; - - if (value["needsLengthConverter"].is_boolean()) - needsLengthConverter = value["needsLengthConverter"]; - std::string type; // Defaulting to type "player" when not specified @@ -117,12 +112,10 @@ TraceSetup::TraceSetup(const std::string &uri, StlPlayer *player; if (ext == "stl") player = new StlPlayer(moduleName.c_str(), stlFile, playerClk, - maxPendingReadRequests, maxPendingWriteRequests, needsLengthConverter, - this, false); + maxPendingReadRequests, maxPendingWriteRequests, this, false); else if (ext == "rstl") player = new StlPlayer(moduleName.c_str(), stlFile, playerClk, - maxPendingReadRequests, maxPendingWriteRequests, needsLengthConverter, - this, true); + maxPendingReadRequests, maxPendingWriteRequests, this, true); else throw std::runtime_error("Unsupported file extension in " + name); @@ -196,13 +189,13 @@ TraceSetup::TraceSetup(const std::string &uri, players.push_back(std::unique_ptr(new TrafficGeneratorSequential(name.c_str(), playerClk, numRequests, maxPendingReadRequests, maxPendingWriteRequests, - needsLengthConverter, minAddress, maxAddress, rwRatio, addressIncrement, seed, this))); + minAddress, maxAddress, rwRatio, addressIncrement, seed, this))); } else { players.push_back(std::unique_ptr(new TrafficGeneratorRandom(name.c_str(), playerClk, numRequests, maxPendingReadRequests, maxPendingWriteRequests, - needsLengthConverter, minAddress, maxAddress, rwRatio, seed, this))); + minAddress, maxAddress, rwRatio, seed, this))); } totalTransactions += numRequests; diff --git a/DRAMSys/simulator/TrafficGenerator.cpp b/DRAMSys/simulator/TrafficGenerator.cpp index 71cd48dc..de18bc1a 100644 --- a/DRAMSys/simulator/TrafficGenerator.cpp +++ b/DRAMSys/simulator/TrafficGenerator.cpp @@ -46,11 +46,10 @@ TrafficGenerator::TrafficGenerator(const sc_module_name &name, uint64_t numRequests, unsigned int maxPendingReadRequests, unsigned int maxPendingWriteRequests, - bool needsLengthConverter, float rwRatio, unsigned int seed, TraceSetup *setup) : - TrafficInitiator(name, setup, maxPendingReadRequests, maxPendingWriteRequests, needsLengthConverter), + TrafficInitiator(name, setup, maxPendingReadRequests, maxPendingWriteRequests), generatorClk(generatorClk), numRequests(numRequests), rwRatio(rwRatio) { defaultDataLength = Configuration::getInstance().memSpec->bytesPerBurst; @@ -110,14 +109,13 @@ TrafficGeneratorRandom::TrafficGeneratorRandom(const sc_core::sc_module_name &na uint64_t numRequests, unsigned int maxPendingReadRequests, unsigned int maxPendingWriteRequests, - bool needsLengthConverter, uint64_t minAddress, uint64_t maxAddress, float rwRatio, unsigned int seed, TraceSetup *setup) : TrafficGenerator(name, generatorClk, numRequests, maxPendingReadRequests, maxPendingWriteRequests, - needsLengthConverter, rwRatio, seed, setup) + rwRatio, seed, setup) { randomAddressDistribution = std::uniform_int_distribution (minAddress, maxAddress); } @@ -132,7 +130,6 @@ TrafficGeneratorSequential::TrafficGeneratorSequential(const sc_core::sc_module_ uint64_t numRequests, unsigned int maxPendingReadRequests, unsigned int maxPendingWriteRequests, - bool needsLengthConverter, uint64_t minAddress, uint64_t maxAddress, float rwRatio, @@ -140,7 +137,7 @@ TrafficGeneratorSequential::TrafficGeneratorSequential(const sc_core::sc_module_ unsigned int seed, TraceSetup *setup) : TrafficGenerator(name, generatorClk, numRequests, maxPendingReadRequests, maxPendingWriteRequests, - needsLengthConverter, rwRatio, seed, setup), + rwRatio, seed, setup), minAddress(minAddress), maxAddress(maxAddress), addressIncrement(addressIncrement), currentAddress(minAddress) { @@ -161,7 +158,7 @@ TrafficGeneratorHammer::TrafficGeneratorHammer(const sc_core::sc_module_name &na uint64_t numRequests, uint64_t rowIncrement, TraceSetup *setup) : - TrafficGenerator(name, generatorClk, numRequests, 1, 1, false, 1.0f, 1, setup), rowIncrement(rowIncrement) + TrafficGenerator(name, generatorClk, numRequests, 1, 1, 1.0f, 1, setup), rowIncrement(rowIncrement) { } diff --git a/DRAMSys/simulator/TrafficGenerator.h b/DRAMSys/simulator/TrafficGenerator.h index f7036f65..394e1d81 100644 --- a/DRAMSys/simulator/TrafficGenerator.h +++ b/DRAMSys/simulator/TrafficGenerator.h @@ -52,7 +52,6 @@ protected: uint64_t numRequests, unsigned int maxPendingReadRequests, unsigned int maxPendingWriteRequests, - bool needsLengthConverter, float rwRatio, unsigned int seed, TraceSetup *setup); @@ -79,7 +78,6 @@ public: uint64_t numRequests, unsigned int maxPendingReadRequests, unsigned int maxPendingWriteRequests, - bool needsLengthConverter, uint64_t minAddress, uint64_t maxAddress, float rwRatio, @@ -100,7 +98,6 @@ public: uint64_t numRequests, unsigned int maxPendingReadRequests, unsigned int maxPendingWriteRequests, - bool needsLengthConverter, uint64_t minAddress, uint64_t maxAddress, float rwRatio, diff --git a/DRAMSys/simulator/TrafficInitiator.cpp b/DRAMSys/simulator/TrafficInitiator.cpp index 93a05c39..2a7c783e 100644 --- a/DRAMSys/simulator/TrafficInitiator.cpp +++ b/DRAMSys/simulator/TrafficInitiator.cpp @@ -44,11 +44,10 @@ using namespace sc_core; using namespace tlm; TrafficInitiator::TrafficInitiator(const sc_module_name &name, TraceSetup *setup, - unsigned int maxPendingReadRequests, unsigned int maxPendingWriteRequests, bool needsLengthConverter) : + unsigned int maxPendingReadRequests, unsigned int maxPendingWriteRequests) : sc_module(name), payloadEventQueue(this, &TrafficInitiator::peqCallback), setup(setup), - maxPendingReadRequests(maxPendingReadRequests), maxPendingWriteRequests(maxPendingWriteRequests), - mNeedsLengthConverter(needsLengthConverter) + maxPendingReadRequests(maxPendingReadRequests), maxPendingWriteRequests(maxPendingWriteRequests) { SC_METHOD(sendNextPayload); iSocket.register_nb_transport_bw(this, &TrafficInitiator::nb_transport_bw); @@ -130,8 +129,3 @@ bool TrafficInitiator::nextPayloadSendable() const else return true; } - -bool TrafficInitiator::needsLengthConverter() const -{ - return mNeedsLengthConverter; -} diff --git a/DRAMSys/simulator/TrafficInitiator.h b/DRAMSys/simulator/TrafficInitiator.h index 5d7553ed..91ca118d 100644 --- a/DRAMSys/simulator/TrafficInitiator.h +++ b/DRAMSys/simulator/TrafficInitiator.h @@ -57,10 +57,9 @@ class TrafficInitiator : public sc_core::sc_module public: tlm_utils::simple_initiator_socket iSocket; TrafficInitiator(const sc_core::sc_module_name &name, TraceSetup *setup, - unsigned int maxPendingReadRequests, unsigned int maxPendingWriteRequests, bool needsLengthConverter); + unsigned int maxPendingReadRequests, unsigned int maxPendingWriteRequests); SC_HAS_PROCESS(TrafficInitiator); virtual void sendNextPayload() = 0; - bool needsLengthConverter() const; protected: tlm_utils::peq_with_cb_and_phase payloadEventQueue; @@ -76,7 +75,6 @@ protected: unsigned int pendingWriteRequests = 0; const unsigned int maxPendingReadRequests = 0; const unsigned int maxPendingWriteRequests = 0; - const bool mNeedsLengthConverter = false; bool payloadPostponed = false; bool finished = false; diff --git a/DRAMSys/simulator/main.cpp b/DRAMSys/simulator/main.cpp index 8ff4d46a..93539a0c 100644 --- a/DRAMSys/simulator/main.cpp +++ b/DRAMSys/simulator/main.cpp @@ -48,7 +48,6 @@ #include "simulation/DRAMSys.h" #include "TraceSetup.h" #include "TrafficInitiator.h" -#include "LengthConverter.h" #ifdef RECORDING #include "simulation/DRAMSysRecordable.h" @@ -99,7 +98,6 @@ int sc_main(int argc, char **argv) } std::vector> players; - std::list lengthConverters; // Instantiate DRAMSys: std::unique_ptr dramSys; @@ -114,44 +112,12 @@ int sc_main(int argc, char **argv) #endif dramSys = std::unique_ptr(new DRAMSys("DRAMSys", simulationJson, resources)); - // Instantiate STL Players: + // Instantiate STL Players (config of DRAMSys required!): TraceSetup setup(simulationJson, resources, players); // Bind STL Players with DRAMSys: - for (size_t i = 0; i < players.size(); i++) - { - if (Configuration::getInstance().checkTLM2Protocol) - { - std::string str = "TLMCheckerPlayer" + std::to_string(i); - auto* playerTlmChecker = - new tlm_utils::tlm2_base_protocol_checker<>(("TLMCheckerPlayer" + std::to_string(i)).c_str()); - dramSys->playersTlmCheckers.push_back(playerTlmChecker); - if (players[i]->needsLengthConverter()) - { - lengthConverters.emplace_back(("LengthConverter" + std::to_string(i)).c_str(), 64, false); - players[i]->iSocket.bind(lengthConverters.back().tSocket); - lengthConverters.back().iSocket.bind(dramSys->playersTlmCheckers.back()->target_socket); - } - else - { - players[i]->iSocket.bind(dramSys->playersTlmCheckers[i]->target_socket); - } - dramSys->playersTlmCheckers.back()->initiator_socket.bind(dramSys->tSocket); - } - else - { - if (players[i]->needsLengthConverter()) - { - lengthConverters.emplace_back(("LengthConverter" + std::to_string(i)).c_str(), 64, false); - players[i]->iSocket.bind(lengthConverters.back().tSocket); - lengthConverters.back().iSocket.bind(dramSys->tSocket); - } - else - { - players[i]->iSocket.bind(dramSys->tSocket); - } - } - } + for (auto& player : players) + player->iSocket.bind(dramSys->tSocket); // Store the starting of the simulation in wallclock time: auto start = std::chrono::high_resolution_clock::now();