From 5b7dcbcc1cd88bb73a1111b95c6d2c054d514acb Mon Sep 17 00:00:00 2001 From: Jonathan Hager Date: Mon, 17 Mar 2025 10:55:05 +0100 Subject: [PATCH] Moved TlmRecorder from reference to smart pointer --- .../DRAMSys/common/TlmRecorderArbiter.cpp | 16 +++++----------- .../DRAMSys/common/TlmRecorderArbiter.h | 5 ++--- .../DRAMSys/common/TlmRecorderDram.cpp | 10 +++++----- .../DRAMSys/common/TlmRecorderDram.h | 5 ++--- .../DRAMSys/controller/Controller.cpp | 6 +++--- src/libdramsys/DRAMSys/controller/Controller.h | 4 ++-- src/libdramsys/DRAMSys/simulation/DRAMSys.cpp | 18 +++++++++--------- src/libdramsys/DRAMSys/simulation/DRAMSys.h | 2 +- src/libdramsys/DRAMSys/simulation/Dram.cpp | 8 ++++---- src/libdramsys/DRAMSys/simulation/Dram.h | 4 ++-- 10 files changed, 35 insertions(+), 43 deletions(-) diff --git a/src/libdramsys/DRAMSys/common/TlmRecorderArbiter.cpp b/src/libdramsys/DRAMSys/common/TlmRecorderArbiter.cpp index 66d3facc..db2c1f98 100644 --- a/src/libdramsys/DRAMSys/common/TlmRecorderArbiter.cpp +++ b/src/libdramsys/DRAMSys/common/TlmRecorderArbiter.cpp @@ -13,11 +13,11 @@ namespace DRAMSys TlmRecorderArbiter::TlmRecorderArbiter(const sc_core::sc_module_name& name, const SimConfig& simConfig, const MemSpec& memSpec, - TlmRecorder& tlmRecorder, + std::shared_ptr tlmRecorder, bool enableBandwidth) : sc_module(name), memSpec(memSpec), - tlmRecorder(tlmRecorder), + tlmRecorder(std::move(tlmRecorder)), enableWindowing(simConfig.enableWindowing), pseudoChannelMode(memSpec.pseudoChannelMode()), ranksPerChannel(memSpec.ranksPerChannel), @@ -52,7 +52,7 @@ tlm::tlm_sync_enum TlmRecorderArbiter::nb_transport_fw(tlm::tlm_generic_payload& numberOfBytesServed += trans.get_data_length(); } - tlmRecorder.recordPhase(trans, phase, delay); + tlmRecorder->recordPhase(trans, phase, delay); return iSocket->nb_transport_fw(trans, phase, delay); } @@ -66,7 +66,7 @@ tlm::tlm_sync_enum TlmRecorderArbiter::nb_transport_bw(tlm::tlm_generic_payload& numberOfBytesServed += trans.get_data_length(); } - tlmRecorder.recordPhase(trans, phase, delay); + tlmRecorder->recordPhase(trans, phase, delay); return tSocket->nb_transport_bw(trans, phase, delay); } @@ -86,13 +86,7 @@ void TlmRecorderArbiter::recordBandwidth() double windowBandwidth = static_cast(windowNumberOfBytesServed) / (windowSizeTime.to_seconds()); - tlmRecorder.recordBandwidth(sc_core::sc_time_stamp().to_seconds(), windowBandwidth); - - // sc_core::sc_time windowActiveTime = - // activeTimeMultiplier * static_cast(windowNumberOfBytesServed); - // double windowAverageBandwidth = windowNumberOfBytesServed / maxBandwidth; - // tlmRecorder.recordBandwidth(sc_core::sc_time_stamp().to_seconds(), - // windowAverageBandwidth); + tlmRecorder->recordBandwidth(sc_core::sc_time_stamp().to_seconds(), windowBandwidth); } } diff --git a/src/libdramsys/DRAMSys/common/TlmRecorderArbiter.h b/src/libdramsys/DRAMSys/common/TlmRecorderArbiter.h index ef3f5416..0c0475e8 100644 --- a/src/libdramsys/DRAMSys/common/TlmRecorderArbiter.h +++ b/src/libdramsys/DRAMSys/common/TlmRecorderArbiter.h @@ -26,7 +26,7 @@ public: TlmRecorderArbiter(const sc_core::sc_module_name& name, const SimConfig& simConfig, const MemSpec& memspec, - TlmRecorder& tlmRecorder, + std::shared_ptr tlmRecorder, bool enableBandwidth); ~TlmRecorderArbiter() = default; @@ -39,8 +39,7 @@ public: private: const MemSpec& memSpec; - // HACK: Refactor with shared pointers? - TlmRecorder& tlmRecorder; + std::shared_ptr tlmRecorder; const bool enableWindowing; const bool pseudoChannelMode; const unsigned int ranksPerChannel; diff --git a/src/libdramsys/DRAMSys/common/TlmRecorderDram.cpp b/src/libdramsys/DRAMSys/common/TlmRecorderDram.cpp index 48856db7..8faf784b 100644 --- a/src/libdramsys/DRAMSys/common/TlmRecorderDram.cpp +++ b/src/libdramsys/DRAMSys/common/TlmRecorderDram.cpp @@ -12,10 +12,10 @@ namespace DRAMSys TlmRecorderDram::TlmRecorderDram(const sc_core::sc_module_name& name, const SimConfig& simConfig, const MemSpec& memSpec, - TlmRecorder& tlmRecorder, + std::shared_ptr tlmRecorder, bool enableBandwidth) : sc_module(name), - tlmRecorder(tlmRecorder), + tlmRecorder(std::move(tlmRecorder)), enableWindowing(simConfig.enableWindowing), pseudoChannelMode(memSpec.pseudoChannelMode()), ranksPerChannel(memSpec.ranksPerChannel), @@ -55,7 +55,7 @@ tlm::tlm_sync_enum TlmRecorderDram::nb_transport_fw(tlm::tlm_generic_payload& tr } } - tlmRecorder.recordPhase(trans, phase, delay); + tlmRecorder->recordPhase(trans, phase, delay); return iSocket->nb_transport_fw(trans, phase, delay); } @@ -63,7 +63,7 @@ tlm::tlm_sync_enum TlmRecorderDram::nb_transport_bw(tlm::tlm_generic_payload& tr tlm::tlm_phase& phase, sc_core::sc_time& delay) { - tlmRecorder.recordPhase(trans, phase, delay); + tlmRecorder->recordPhase(trans, phase, delay); return tSocket->nb_transport_bw(trans, phase, delay); } @@ -87,7 +87,7 @@ void TlmRecorderDram::recordBandwidth() sc_core::sc_time windowActiveTime = activeTimeMultiplier * static_cast(windowNumberOfBeatsServed); double windowAverageBandwidth = windowActiveTime / windowSizeTime; - tlmRecorder.recordBandwidth(sc_core::sc_time_stamp().to_seconds(), windowAverageBandwidth); + tlmRecorder->recordBandwidth(sc_core::sc_time_stamp().to_seconds(), windowAverageBandwidth); } } diff --git a/src/libdramsys/DRAMSys/common/TlmRecorderDram.h b/src/libdramsys/DRAMSys/common/TlmRecorderDram.h index fd5d2aa7..6916eb20 100644 --- a/src/libdramsys/DRAMSys/common/TlmRecorderDram.h +++ b/src/libdramsys/DRAMSys/common/TlmRecorderDram.h @@ -26,7 +26,7 @@ public: TlmRecorderDram(const sc_core::sc_module_name& name, const SimConfig& simConfig, const MemSpec& memspec, - TlmRecorder& tlmRecorder, + std::shared_ptr tlmRecorder, bool enableBandwidth); ~TlmRecorderDram() = default; @@ -38,8 +38,7 @@ public: sc_core::sc_time& delay); private: - // HACK: Refactor with shared pointers? - TlmRecorder& tlmRecorder; + std::shared_ptr tlmRecorder; const bool enableWindowing; const bool pseudoChannelMode; const unsigned int ranksPerChannel; diff --git a/src/libdramsys/DRAMSys/controller/Controller.cpp b/src/libdramsys/DRAMSys/controller/Controller.cpp index 50f86ca8..2a27bc9c 100644 --- a/src/libdramsys/DRAMSys/controller/Controller.cpp +++ b/src/libdramsys/DRAMSys/controller/Controller.cpp @@ -89,13 +89,13 @@ Controller::Controller(const sc_module_name& name, const MemSpec& memSpec, const SimConfig& simConfig, const AddressDecoder& addressDecoder, - TlmRecorder& tlmRecorder) : + std::shared_ptr tlmRecorder) : sc_module(name), config(config), memSpec(memSpec), simConfig(simConfig), addressDecoder(addressDecoder), - tlmRecorder(tlmRecorder), + tlmRecorder(std::move(tlmRecorder)), windowSizeTime(simConfig.windowSize * memSpec.tCK), nextWindowEventTime(windowSizeTime), numberOfBeatsServed(memSpec.ranksPerChannel, 0), @@ -353,7 +353,7 @@ void Controller::recordBufferDepth() slidingAverageBufferDepth[index] = SC_ZERO_TIME; } - tlmRecorder.recordBufferDepth(sc_time_stamp().to_seconds(), windowAverageBufferDepth); + tlmRecorder->recordBufferDepth(sc_time_stamp().to_seconds(), windowAverageBufferDepth); } } diff --git a/src/libdramsys/DRAMSys/controller/Controller.h b/src/libdramsys/DRAMSys/controller/Controller.h index 3f25cf56..4278ed89 100644 --- a/src/libdramsys/DRAMSys/controller/Controller.h +++ b/src/libdramsys/DRAMSys/controller/Controller.h @@ -74,7 +74,7 @@ public: const MemSpec& memSpec, const SimConfig& simConfig, const AddressDecoder& addressDecoder, - TlmRecorder& tlmRecorder); + std::shared_ptr tlmRecorder); SC_HAS_PROCESS(Controller); [[nodiscard]] bool idle() const { return totalNumberOfPayloads == 0; } @@ -102,7 +102,7 @@ protected: const MemSpec& memSpec; const SimConfig& simConfig; const AddressDecoder& addressDecoder; - TlmRecorder& tlmRecorder; + std::shared_ptr tlmRecorder; std::unique_ptr scheduler; diff --git a/src/libdramsys/DRAMSys/simulation/DRAMSys.cpp b/src/libdramsys/DRAMSys/simulation/DRAMSys.cpp index e86da6ef..81be9420 100644 --- a/src/libdramsys/DRAMSys/simulation/DRAMSys.cpp +++ b/src/libdramsys/DRAMSys/simulation/DRAMSys.cpp @@ -223,14 +223,14 @@ void DRAMSys::setupTlmRecorders(const std::string& traceName, const Config::Conf mcconfig[Config::McConfig::KEY] = config.mcconfig; memspec[Config::MemSpec::KEY] = config.memspec; - tlmRecorders.emplace_back(recorderName, - simConfig, - mcConfig, - *memSpec, - dbName, - mcconfig.dump(), - memspec.dump(), - simConfig.simulationName); + tlmRecorders.push_back(std::make_shared(recorderName, + simConfig, + mcConfig, + *memSpec, + dbName, + mcconfig.dump(), + memspec.dump(), + simConfig.simulationName)); } } @@ -258,7 +258,7 @@ void DRAMSys::end_of_simulation() } for (auto& tlmRecorder : tlmRecorders) - tlmRecorder.finalize(); + tlmRecorder->finalize(); } void DRAMSys::logo() diff --git a/src/libdramsys/DRAMSys/simulation/DRAMSys.h b/src/libdramsys/DRAMSys/simulation/DRAMSys.h index e721391c..73000ac6 100644 --- a/src/libdramsys/DRAMSys/simulation/DRAMSys.h +++ b/src/libdramsys/DRAMSys/simulation/DRAMSys.h @@ -127,7 +127,7 @@ private: // Transaction Recorders (one per channel). // They generate the output databases. - std::vector tlmRecorders; + std::vector> tlmRecorders; std::vector> tlmWrappersArbiter; std::vector> tlmWrappersDram; diff --git a/src/libdramsys/DRAMSys/simulation/Dram.cpp b/src/libdramsys/DRAMSys/simulation/Dram.cpp index 5b1e7d4c..13fe2af4 100644 --- a/src/libdramsys/DRAMSys/simulation/Dram.cpp +++ b/src/libdramsys/DRAMSys/simulation/Dram.cpp @@ -72,14 +72,14 @@ namespace DRAMSys Dram::Dram(const sc_module_name& name, const SimConfig& simConfig, const MemSpec& memSpec, - TlmRecorder& tlmRecorder) : + std::shared_ptr tlmRecorder) : sc_module(name), memSpec(memSpec), storeMode(simConfig.storeMode), powerAnalysis(simConfig.powerAnalysis), channelSize(memSpec.getSimMemSizeInBytes() / memSpec.numberOfChannels), useMalloc(simConfig.useMalloc), - tlmRecorder(tlmRecorder), + tlmRecorder(std::move(tlmRecorder)), powerWindowSize(memSpec.tCK * simConfig.windowSize) { if (storeMode == Config::StoreModeType::Store) @@ -143,7 +143,7 @@ void Dram::reportPower() << DRAMPower->getPower().average_power * memSpec.devicesPerRank << std::string(" mW") << std::endl; - tlmRecorder.recordPower(sc_time_stamp().to_seconds(), + tlmRecorder->recordPower(sc_time_stamp().to_seconds(), this->DRAMPower->getPower().window_average_power * this->memSpec.devicesPerRank); #endif @@ -302,7 +302,7 @@ void Dram::powerWindow() assert(!this->DRAMPower->getEnergy().window_energy < 1e-05); // 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 * this->memSpec.devicesPerRank); diff --git a/src/libdramsys/DRAMSys/simulation/Dram.h b/src/libdramsys/DRAMSys/simulation/Dram.h index add46abe..40581fe3 100644 --- a/src/libdramsys/DRAMSys/simulation/Dram.h +++ b/src/libdramsys/DRAMSys/simulation/Dram.h @@ -69,7 +69,7 @@ protected: const uint64_t channelSize; const bool useMalloc; - TlmRecorder& tlmRecorder; + std::shared_ptr tlmRecorder; sc_core::sc_time powerWindowSize; #ifdef DRAMPOWER @@ -93,7 +93,7 @@ public: Dram(const sc_core::sc_module_name& name, const SimConfig& simConfig, const MemSpec& memSpec, - TlmRecorder& tlmRecorder); + std::shared_ptr tlmRecorder); SC_HAS_PROCESS(Dram); Dram(const Dram&) = delete;