diff --git a/DRAMSys/simulator/src/controller/scheduler/ReadyBatch.cpp b/DRAMSys/simulator/src/controller/scheduler/ReadyBatch.cpp index a55c4c40..af218173 100644 --- a/DRAMSys/simulator/src/controller/scheduler/ReadyBatch.cpp +++ b/DRAMSys/simulator/src/controller/scheduler/ReadyBatch.cpp @@ -1 +1,43 @@ #include "ReadyBatch.h" + +ReadyBatch::ReadyBatch() +{ + fifosize = Configuration::getInstance().ReadyBatchSize; + thresholdAge(Configuration::getInstance().ReadyBatchThresholdAge, SC_NS); +} + +unsigned int ReadyBatch::getNumRequests() +{ + return readybatch.size(); +} + +Row ReadyBatch::getRow() +{ + return DramExtension::getExtension(readybatch.front()).getRow(); +} + +sc_time ReadyBatch::getTimeOfOldestRequest() +{ + sc_time oldestTime = sc_time_stamp(); + for (auto reqPayload = readybatch.begin(); reqPayload != readybatch.end(); reqPayload++) + { + sc_time requestTimeOfGeneration = GenerationExtension::getExtension(*reqPayload).TimeOfGeneration(); + if (requestTimeOfGeneration < oldestTime) + { + oldestTime = requestTimeOfGeneration; + } + } + return oldestTime; +} + +bool ReadyBatch::addTransaction(gp* payload) +{ + sc_time currentAge = sc_time_stamp() - getTimeOfOldestRequest(); + Row newRow = DramExtension::getExtension(payload).getRow(); + if (getNumRequests == fifosize || currentAge >= thresholdAge || newRow != getRow()) { + return false; + } else { + readybatch.emplace_back(payload); + return true; + } +} diff --git a/DRAMSys/simulator/src/controller/scheduler/ReadyBatch.h b/DRAMSys/simulator/src/controller/scheduler/ReadyBatch.h index 91fac215..ff9e8e80 100644 --- a/DRAMSys/simulator/src/controller/scheduler/ReadyBatch.h +++ b/DRAMSys/simulator/src/controller/scheduler/ReadyBatch.h @@ -3,6 +3,7 @@ #include "tlm.h" #include "../../common/dramExtension.h" +#include "../core/configuration/Configuration.h" typedef tlm::tlm_generic_payload gp; @@ -11,11 +12,12 @@ using namespace std; class ReadyBatch { public: - ReadyBatch(unsigned int fifosize) : fifosize(fifosize){} + ReadyBatch(); bool addTransaction(gp* payload); private: std::deque readybatch; unsigned int fifosize; + sc_time thresholdAge; Row getRow(); sc_time getTimeOfOldestRequest();