From 24654be95220d3341cc7249cfb2a867e2d73085e Mon Sep 17 00:00:00 2001 From: Derek Christ Date: Thu, 27 Jul 2023 11:02:45 +0200 Subject: [PATCH] Fix a timing issue in the traffic initiator When the generator clock did not match the memory clock, the generator always created a constant delay to the next transaction. This is not correct as due to rounding, the delay should be one cycle more or less depending on the current simulation time. --- .../simulator/request/RequestIssuer.cpp | 18 ++++++++++++++---- .../simulator/request/RequestIssuer.h | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/simulator/simulator/request/RequestIssuer.cpp b/src/simulator/simulator/request/RequestIssuer.cpp index 2c96ea37..19796b7b 100644 --- a/src/simulator/simulator/request/RequestIssuer.cpp +++ b/src/simulator/simulator/request/RequestIssuer.cpp @@ -81,13 +81,21 @@ void RequestIssuer::sendNextRequest() tlm::tlm_phase phase = tlm::BEGIN_REQ; sc_core::sc_time delay = request.delay; - // Align to next clock - if (delay < clkPeriod && transactionsSent != 0) + sc_core::sc_time sendingTime = sc_core::sc_time_stamp() + delay; + + bool needsOffset = (sendingTime % clkPeriod) != sc_core::SC_ZERO_TIME; + if (needsOffset) { - delay = delay + clkPeriod; - delay -= delay % clkPeriod; + sendingTime += clkPeriod; + sendingTime -= sendingTime % clkPeriod; } + if (sendingTime == lastEndRequest) + { + sendingTime += clkPeriod; + } + + delay = sendingTime - sc_core::sc_time_stamp(); iSocket->nb_transport_fw(payload, phase, delay); if (request.command == Request::Command::Read) @@ -116,6 +124,8 @@ void RequestIssuer::peqCallback(tlm::tlm_generic_payload &payload, const tlm::tl { if (phase == tlm::END_REQ) { + lastEndRequest = sc_core::sc_time_stamp(); + if (nextRequestSendable()) sendNextRequest(); else diff --git a/src/simulator/simulator/request/RequestIssuer.h b/src/simulator/simulator/request/RequestIssuer.h index 2e318bfc..77af12ba 100644 --- a/src/simulator/simulator/request/RequestIssuer.h +++ b/src/simulator/simulator/request/RequestIssuer.h @@ -71,6 +71,7 @@ private: uint64_t transactionsSent = 0; uint64_t transactionsReceived = 0; + sc_core::sc_time lastEndRequest = sc_core::sc_max_time(); unsigned int pendingReadRequests = 0; unsigned int pendingWriteRequests = 0;