From 9c690c021c7e5cdadac45e1bdaa068ff9319cdcf Mon Sep 17 00:00:00 2001 From: Jonathan Hager Date: Wed, 19 Mar 2025 14:15:19 +0100 Subject: [PATCH] Fixed nullptr segfault if no database recording Dram and Controller handle this case now and are initialized with a shared_ptr pointing to null --- .../DRAMSys/controller/Controller.cpp | 3 +- src/libdramsys/DRAMSys/simulation/DRAMSys.cpp | 39 +++++++++++-------- src/libdramsys/DRAMSys/simulation/Dram.cpp | 20 ++++++---- 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/src/libdramsys/DRAMSys/controller/Controller.cpp b/src/libdramsys/DRAMSys/controller/Controller.cpp index 2a27bc9c..e18c7ef1 100644 --- a/src/libdramsys/DRAMSys/controller/Controller.cpp +++ b/src/libdramsys/DRAMSys/controller/Controller.cpp @@ -353,7 +353,8 @@ void Controller::recordBufferDepth() slidingAverageBufferDepth[index] = SC_ZERO_TIME; } - tlmRecorder->recordBufferDepth(sc_time_stamp().to_seconds(), windowAverageBufferDepth); + if (simConfig.databaseRecording) + tlmRecorder->recordBufferDepth(sc_time_stamp().to_seconds(), windowAverageBufferDepth); } } diff --git a/src/libdramsys/DRAMSys/simulation/DRAMSys.cpp b/src/libdramsys/DRAMSys/simulation/DRAMSys.cpp index 29d71ba7..00d361cf 100644 --- a/src/libdramsys/DRAMSys/simulation/DRAMSys.cpp +++ b/src/libdramsys/DRAMSys/simulation/DRAMSys.cpp @@ -91,17 +91,17 @@ DRAMSys::DRAMSys(const sc_core::sc_module_name& name, const Config::Configuratio // Setup the debug manager: setupDebugManager(simConfig.simulationName); - std::string traceName = simConfig.simulationName; - // Create and properly initialize TLM recorders. - // They need to be ready before creating some modules. - setupTlmRecorders(traceName, config); - // Instantiate all internal DRAMSys modules: if (simConfig.databaseRecording) { + std::string traceName = simConfig.simulationName; if (!config.simulationid.empty()) traceName = config.simulationid + '_' + traceName; + // Create and properly initialize TLM recorders. + // They need to be ready before creating some modules. + setupTlmRecorders(traceName, config); + // Create controllers and DRAMs for (std::size_t i = 0; i < memSpec->numberOfChannels; i++) { @@ -123,19 +123,19 @@ DRAMSys::DRAMSys(const sc_core::sc_module_name& name, const Config::Configuratio // Not recording bandwidth between Arbiter - Controller tlmRecordersController.emplace_back(std::make_unique( - ("TlmRecorderWrapper" + std::to_string(i)).c_str(), + ("TlmRecorderController" + std::to_string(i)).c_str(), simConfig, *memSpec, tlmRecorders[i], false)); // Recording bandwidth between Controller - DRAM - tlmRecordersDram.emplace_back(std::make_unique( - ("TlmRecorderWrapper" + std::to_string(i)).c_str(), - simConfig, - *memSpec, - tlmRecorders[i], - true)); + tlmRecordersDram.emplace_back( + std::make_unique(("TlmRecorderDram" + std::to_string(i)).c_str(), + simConfig, + *memSpec, + tlmRecorders[i], + true)); } } else @@ -148,10 +148,12 @@ DRAMSys::DRAMSys(const sc_core::sc_module_name& name, const Config::Configuratio *memSpec, simConfig, *addressDecoder, - tlmRecorders[i])); + std::shared_ptr{})); - drams.emplace_back(std::make_unique( - ("dram" + std::to_string(i)).c_str(), simConfig, *memSpec, tlmRecorders[i])); + drams.emplace_back(std::make_unique(("dram" + std::to_string(i)).c_str(), + simConfig, + *memSpec, + std::shared_ptr{})); if (simConfig.checkTLM2Protocol) { @@ -256,8 +258,11 @@ void DRAMSys::end_of_simulation() dram->reportPower(); } - for (auto& tlmRecorder : tlmRecorders) - tlmRecorder->finalize(); + if (simConfig.databaseRecording) + { + for (auto& tlmRecorder : tlmRecorders) + tlmRecorder->finalize(); + } } void DRAMSys::logo() diff --git a/src/libdramsys/DRAMSys/simulation/Dram.cpp b/src/libdramsys/DRAMSys/simulation/Dram.cpp index 13fe2af4..f6ae99e1 100644 --- a/src/libdramsys/DRAMSys/simulation/Dram.cpp +++ b/src/libdramsys/DRAMSys/simulation/Dram.cpp @@ -143,9 +143,12 @@ void Dram::reportPower() << DRAMPower->getPower().average_power * memSpec.devicesPerRank << std::string(" mW") << std::endl; - tlmRecorder->recordPower(sc_time_stamp().to_seconds(), - this->DRAMPower->getPower().window_average_power * - this->memSpec.devicesPerRank); + if (tlmRecorder) + { + tlmRecorder->recordPower(sc_time_stamp().to_seconds(), + this->DRAMPower->getPower().window_average_power * + this->memSpec.devicesPerRank); + } #endif } @@ -301,10 +304,13 @@ void Dram::powerWindow() // During operation the energy should never be zero since the device is always consuming 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(), - this->DRAMPower->getPower().window_average_power * - this->memSpec.devicesPerRank); + if (tlmRecorder) + { + // Store the time (in seconds) and the current average power (in mW) into the database + tlmRecorder->recordPower(sc_time_stamp().to_seconds(), + this->DRAMPower->getPower().window_average_power * + this->memSpec.devicesPerRank); + } // Here considering that DRAMPower provides the energy in pJ and the power in mW PRINTDEBUGMESSAGE(this->name(),