Moved ifs from the method body to the invocation

This commit is contained in:
Jonathan Hager
2025-04-10 10:21:58 +02:00
parent 950dbd690d
commit 8266d825f3
3 changed files with 54 additions and 64 deletions

View File

@@ -11,10 +11,10 @@ namespace DRAMSys
{ {
TlmRecorderController::TlmRecorderController(const sc_core::sc_module_name& name, TlmRecorderController::TlmRecorderController(const sc_core::sc_module_name& name,
const SimConfig& simConfig, const SimConfig& simConfig,
const MemSpec& memSpec, const MemSpec& memSpec,
TlmRecorder& tlmRecorder, TlmRecorder& tlmRecorder,
bool enableBandwidth) : bool enableBandwidth) :
sc_module(name), sc_module(name),
memSpec(memSpec), memSpec(memSpec),
tlmRecorder(tlmRecorder), 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_b_transport(this, &TlmRecorderController::b_transport);
tSocket.register_transport_dbg(this, &TlmRecorderController::transport_dbg); tSocket.register_transport_dbg(this, &TlmRecorderController::transport_dbg);
if (enableBandwidth) if (enableBandwidth && enableWindowing)
{ {
SC_METHOD(recordBandwidth); SC_METHOD(recordBandwidth);
dont_initialize();
sensitive << windowEvent; 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_sync_enum TlmRecorderController::nb_transport_fw(tlm::tlm_generic_payload& trans,
tlm::tlm_phase& phase, tlm::tlm_phase& phase,
sc_core::sc_time& delay) sc_core::sc_time& delay)
{ {
if (enableBandwidth && enableWindowing) 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_sync_enum TlmRecorderController::nb_transport_bw(tlm::tlm_generic_payload& trans,
tlm::tlm_phase& phase, tlm::tlm_phase& phase,
sc_core::sc_time& delay) sc_core::sc_time& delay)
{ {
if (enableBandwidth && enableWindowing) if (enableBandwidth && enableWindowing)
{ {
@@ -84,22 +82,19 @@ unsigned int TlmRecorderController::transport_dbg(tlm::tlm_generic_payload& tran
void TlmRecorderController::recordBandwidth() 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; uint64_t windowNumberOfBytesServed = numberOfBytesServed - lastNumberOfBytesServed;
lastNumberOfBytesServed = numberOfBytesServed; lastNumberOfBytesServed = numberOfBytesServed;
// HBM specific, pseudo channels get averaged // HBM specific, pseudo channels get averaged
if (pseudoChannelMode) if (pseudoChannelMode)
windowNumberOfBytesServed /= ranksPerChannel; windowNumberOfBytesServed /= ranksPerChannel;
double windowBandwidth = double windowBandwidth =
static_cast<double>(windowNumberOfBytesServed) / (windowSizeTime.to_seconds()); static_cast<double>(windowNumberOfBytesServed) / (windowSizeTime.to_seconds());
tlmRecorder.recordBandwidth(sc_core::sc_time_stamp().to_seconds(), windowBandwidth); tlmRecorder.recordBandwidth(sc_core::sc_time_stamp().to_seconds(), windowBandwidth);
}
} }
} // namespace DRAMSys } // namespace DRAMSys

View File

@@ -29,16 +29,14 @@ TlmRecorderDram::TlmRecorderDram(const sc_core::sc_module_name& name,
tSocket.register_b_transport(this, &TlmRecorderDram::b_transport); tSocket.register_b_transport(this, &TlmRecorderDram::b_transport);
tSocket.register_transport_dbg(this, &TlmRecorderDram::transport_dbg); tSocket.register_transport_dbg(this, &TlmRecorderDram::transport_dbg);
if (enableBandwidth) if (enableBandwidth && enableWindowing)
{ {
SC_METHOD(recordBandwidth); SC_METHOD(recordBandwidth);
dont_initialize();
sensitive << windowEvent; 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() 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::uint64_t totalNumberOfBeatsServed =
std::accumulate(numberOfBeatsServed.begin(), numberOfBeatsServed.end(), 0); std::accumulate(numberOfBeatsServed.begin(), numberOfBeatsServed.end(), 0);
uint64_t windowNumberOfBeatsServed = totalNumberOfBeatsServed - lastNumberOfBeatsServed; uint64_t windowNumberOfBeatsServed = totalNumberOfBeatsServed - lastNumberOfBeatsServed;
lastNumberOfBeatsServed = totalNumberOfBeatsServed; lastNumberOfBeatsServed = totalNumberOfBeatsServed;
// HBM specific, pseudo channels get averaged // HBM specific, pseudo channels get averaged
if (pseudoChannelMode) if (pseudoChannelMode)
windowNumberOfBeatsServed /= ranksPerChannel; windowNumberOfBeatsServed /= ranksPerChannel;
sc_core::sc_time windowActiveTime = sc_core::sc_time windowActiveTime =
activeTimeMultiplier * static_cast<double>(windowNumberOfBeatsServed); activeTimeMultiplier * static_cast<double>(windowNumberOfBeatsServed);
double windowAverageBandwidth = windowActiveTime / windowSizeTime; double windowAverageBandwidth = windowActiveTime / windowSizeTime;
tlmRecorder.recordBandwidth(sc_core::sc_time_stamp().to_seconds(), windowAverageBandwidth); tlmRecorder.recordBandwidth(sc_core::sc_time_stamp().to_seconds(), windowAverageBandwidth);
}
} }
} // namespace DRAMSys } // namespace DRAMSys

View File

@@ -102,9 +102,13 @@ Controller::Controller(const sc_module_name& name,
minBytesPerBurst(memSpec.defaultBytesPerBurst), minBytesPerBurst(memSpec.defaultBytesPerBurst),
maxBytesPerBurst(memSpec.maxBytesPerBurst) maxBytesPerBurst(memSpec.maxBytesPerBurst)
{ {
SC_METHOD(recordBufferDepth); if (simConfig.databaseRecording && tlmRecorder != nullptr)
sensitive << windowEvent; {
windowEvent.notify(windowSizeTime); SC_METHOD(recordBufferDepth);
dont_initialize();
sensitive << windowEvent;
windowEvent.notify(windowSizeTime);
}
SC_METHOD(controllerMethod); SC_METHOD(controllerMethod);
sensitive << beginReqEvent << endRespEvent << controllerEvent << dataResponseEvent; sensitive << beginReqEvent << endRespEvent << controllerEvent << dataResponseEvent;
@@ -342,20 +346,16 @@ void Controller::registerIdleCallback(std::function<void()> idleCallback)
void Controller::recordBufferDepth() 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); windowAverageBufferDepth[index] = slidingAverageBufferDepth[index] / windowSizeTime;
nextWindowEventTime += windowSizeTime; slidingAverageBufferDepth[index] = SC_ZERO_TIME;
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);
} }
tlmRecorder->recordBufferDepth(sc_time_stamp().to_seconds(), windowAverageBufferDepth);
} }
void Controller::controllerMethod() void Controller::controllerMethod()