From 8266d825f35e478e7fe95f2546197118b7acc409 Mon Sep 17 00:00:00 2001 From: Jonathan Hager Date: Thu, 10 Apr 2025 10:21:58 +0200 Subject: [PATCH] Moved ifs from the method body to the invocation --- .../DRAMSys/common/TlmRecorderController.cpp | 49 +++++++++---------- .../DRAMSys/common/TlmRecorderDram.cpp | 39 +++++++-------- .../DRAMSys/controller/Controller.cpp | 30 ++++++------ 3 files changed, 54 insertions(+), 64 deletions(-) diff --git a/src/libdramsys/DRAMSys/common/TlmRecorderController.cpp b/src/libdramsys/DRAMSys/common/TlmRecorderController.cpp index e9e00b3f..833fa82c 100644 --- a/src/libdramsys/DRAMSys/common/TlmRecorderController.cpp +++ b/src/libdramsys/DRAMSys/common/TlmRecorderController.cpp @@ -11,10 +11,10 @@ namespace DRAMSys { TlmRecorderController::TlmRecorderController(const sc_core::sc_module_name& name, - const SimConfig& simConfig, - const MemSpec& memSpec, - TlmRecorder& tlmRecorder, - bool enableBandwidth) : + const SimConfig& simConfig, + const MemSpec& memSpec, + TlmRecorder& tlmRecorder, + bool enableBandwidth) : sc_module(name), memSpec(memSpec), tlmRecorder(tlmRecorder), @@ -31,22 +31,20 @@ TlmRecorderController::TlmRecorderController(const sc_core::sc_module_name& name tSocket.register_b_transport(this, &TlmRecorderController::b_transport); tSocket.register_transport_dbg(this, &TlmRecorderController::transport_dbg); - if (enableBandwidth) + if (enableBandwidth && enableWindowing) { SC_METHOD(recordBandwidth); + dont_initialize(); sensitive << windowEvent; - if (enableWindowing) - { - windowEvent.notify(windowSizeTime); - nextWindowEventTime = windowSizeTime; - } + windowEvent.notify(windowSizeTime); + nextWindowEventTime = windowSizeTime; } } tlm::tlm_sync_enum TlmRecorderController::nb_transport_fw(tlm::tlm_generic_payload& trans, - tlm::tlm_phase& phase, - sc_core::sc_time& delay) + tlm::tlm_phase& phase, + sc_core::sc_time& delay) { if (enableBandwidth && enableWindowing) { @@ -59,8 +57,8 @@ tlm::tlm_sync_enum TlmRecorderController::nb_transport_fw(tlm::tlm_generic_paylo } tlm::tlm_sync_enum TlmRecorderController::nb_transport_bw(tlm::tlm_generic_payload& trans, - tlm::tlm_phase& phase, - sc_core::sc_time& delay) + tlm::tlm_phase& phase, + sc_core::sc_time& delay) { if (enableBandwidth && enableWindowing) { @@ -84,22 +82,19 @@ unsigned int TlmRecorderController::transport_dbg(tlm::tlm_generic_payload& tran void TlmRecorderController::recordBandwidth() { - if (enableBandwidth && enableWindowing && sc_core::sc_time_stamp() == nextWindowEventTime) - { - windowEvent.notify(windowSizeTime); - nextWindowEventTime += windowSizeTime; + windowEvent.notify(windowSizeTime); + nextWindowEventTime += windowSizeTime; - uint64_t windowNumberOfBytesServed = numberOfBytesServed - lastNumberOfBytesServed; - lastNumberOfBytesServed = numberOfBytesServed; + uint64_t windowNumberOfBytesServed = numberOfBytesServed - lastNumberOfBytesServed; + lastNumberOfBytesServed = numberOfBytesServed; - // HBM specific, pseudo channels get averaged - if (pseudoChannelMode) - windowNumberOfBytesServed /= ranksPerChannel; + // HBM specific, pseudo channels get averaged + if (pseudoChannelMode) + windowNumberOfBytesServed /= ranksPerChannel; - double windowBandwidth = - static_cast(windowNumberOfBytesServed) / (windowSizeTime.to_seconds()); - tlmRecorder.recordBandwidth(sc_core::sc_time_stamp().to_seconds(), windowBandwidth); - } + double windowBandwidth = + static_cast(windowNumberOfBytesServed) / (windowSizeTime.to_seconds()); + tlmRecorder.recordBandwidth(sc_core::sc_time_stamp().to_seconds(), windowBandwidth); } } // namespace DRAMSys diff --git a/src/libdramsys/DRAMSys/common/TlmRecorderDram.cpp b/src/libdramsys/DRAMSys/common/TlmRecorderDram.cpp index 68c2807e..19f27360 100644 --- a/src/libdramsys/DRAMSys/common/TlmRecorderDram.cpp +++ b/src/libdramsys/DRAMSys/common/TlmRecorderDram.cpp @@ -29,16 +29,14 @@ TlmRecorderDram::TlmRecorderDram(const sc_core::sc_module_name& name, tSocket.register_b_transport(this, &TlmRecorderDram::b_transport); tSocket.register_transport_dbg(this, &TlmRecorderDram::transport_dbg); - if (enableBandwidth) + if (enableBandwidth && enableWindowing) { SC_METHOD(recordBandwidth); + dont_initialize(); sensitive << windowEvent; - if (enableWindowing) - { - windowEvent.notify(windowSizeTime); - nextWindowEventTime = windowSizeTime; - } + windowEvent.notify(windowSizeTime); + nextWindowEventTime = windowSizeTime; } } @@ -81,26 +79,23 @@ unsigned int TlmRecorderDram::transport_dbg(tlm::tlm_generic_payload& trans) void TlmRecorderDram::recordBandwidth() { - if (enableBandwidth && enableWindowing && sc_core::sc_time_stamp() == nextWindowEventTime) - { - windowEvent.notify(windowSizeTime); - nextWindowEventTime += windowSizeTime; + windowEvent.notify(windowSizeTime); + nextWindowEventTime += windowSizeTime; - std::uint64_t totalNumberOfBeatsServed = - std::accumulate(numberOfBeatsServed.begin(), numberOfBeatsServed.end(), 0); + std::uint64_t totalNumberOfBeatsServed = + std::accumulate(numberOfBeatsServed.begin(), numberOfBeatsServed.end(), 0); - uint64_t windowNumberOfBeatsServed = totalNumberOfBeatsServed - lastNumberOfBeatsServed; - lastNumberOfBeatsServed = totalNumberOfBeatsServed; + uint64_t windowNumberOfBeatsServed = totalNumberOfBeatsServed - lastNumberOfBeatsServed; + lastNumberOfBeatsServed = totalNumberOfBeatsServed; - // HBM specific, pseudo channels get averaged - if (pseudoChannelMode) - windowNumberOfBeatsServed /= ranksPerChannel; + // HBM specific, pseudo channels get averaged + if (pseudoChannelMode) + windowNumberOfBeatsServed /= ranksPerChannel; - sc_core::sc_time windowActiveTime = - activeTimeMultiplier * static_cast(windowNumberOfBeatsServed); - double windowAverageBandwidth = windowActiveTime / windowSizeTime; - tlmRecorder.recordBandwidth(sc_core::sc_time_stamp().to_seconds(), windowAverageBandwidth); - } + sc_core::sc_time windowActiveTime = + activeTimeMultiplier * static_cast(windowNumberOfBeatsServed); + double windowAverageBandwidth = windowActiveTime / windowSizeTime; + tlmRecorder.recordBandwidth(sc_core::sc_time_stamp().to_seconds(), windowAverageBandwidth); } } // namespace DRAMSys diff --git a/src/libdramsys/DRAMSys/controller/Controller.cpp b/src/libdramsys/DRAMSys/controller/Controller.cpp index 6e7c1484..95d9254b 100644 --- a/src/libdramsys/DRAMSys/controller/Controller.cpp +++ b/src/libdramsys/DRAMSys/controller/Controller.cpp @@ -102,9 +102,13 @@ Controller::Controller(const sc_module_name& name, minBytesPerBurst(memSpec.defaultBytesPerBurst), maxBytesPerBurst(memSpec.maxBytesPerBurst) { - SC_METHOD(recordBufferDepth); - sensitive << windowEvent; - windowEvent.notify(windowSizeTime); + if (simConfig.databaseRecording && tlmRecorder != nullptr) + { + SC_METHOD(recordBufferDepth); + dont_initialize(); + sensitive << windowEvent; + windowEvent.notify(windowSizeTime); + } SC_METHOD(controllerMethod); sensitive << beginReqEvent << endRespEvent << controllerEvent << dataResponseEvent; @@ -342,20 +346,16 @@ void Controller::registerIdleCallback(std::function idleCallback) void Controller::recordBufferDepth() { - if (sc_time_stamp() == nextWindowEventTime) + windowEvent.notify(windowSizeTime); + nextWindowEventTime += windowSizeTime; + + for (std::size_t index = 0; index < slidingAverageBufferDepth.size(); index++) { - windowEvent.notify(windowSizeTime); - nextWindowEventTime += windowSizeTime; - - for (std::size_t index = 0; index < slidingAverageBufferDepth.size(); index++) - { - windowAverageBufferDepth[index] = slidingAverageBufferDepth[index] / windowSizeTime; - slidingAverageBufferDepth[index] = SC_ZERO_TIME; - } - - if (simConfig.databaseRecording && tlmRecorder != nullptr) - tlmRecorder->recordBufferDepth(sc_time_stamp().to_seconds(), windowAverageBufferDepth); + windowAverageBufferDepth[index] = slidingAverageBufferDepth[index] / windowSizeTime; + slidingAverageBufferDepth[index] = SC_ZERO_TIME; } + + tlmRecorder->recordBufferDepth(sc_time_stamp().to_seconds(), windowAverageBufferDepth); } void Controller::controllerMethod()