diff --git a/DRAMSys/simulator/src/controller/scheduler/SMS.cpp b/DRAMSys/simulator/src/controller/scheduler/SMS.cpp index af4af7be..51b1b2ec 100644 --- a/DRAMSys/simulator/src/controller/scheduler/SMS.cpp +++ b/DRAMSys/simulator/src/controller/scheduler/SMS.cpp @@ -7,12 +7,15 @@ void SMS::schedule(gp *payload) { buffer[DramExtension::getExtension(payload).getThread()].emplace_back(payload); inFlightMemRequestCounter[DramExtension::getExtension(payload).getThread()]++; + newRequest.notify(SC_ZERO_TIME); } std::pair SMS::getNextRequest(Bank bank) { if (bankbuffer[bank].empty()) { + debugManager.printDebugMessage(name(), + "Get next request on bank " + to_string(bank.ID()) + " : EMPTY buffer"); return pair(Command::NOP, NULL); } else @@ -26,6 +29,7 @@ std::pair SMS::getNextRequest(Bank bank) bankbuffer[bank].pop_front(); } + debugManager.printDebugMessage(name(), "Get next request on bank " + to_string(bank.ID())); return pair(command, payload); } @@ -42,7 +46,7 @@ void SMS::batchScheduler() while (true) { - wait(memClk); //TODO: Is this correct??? +// wait(memClk); //TODO: Is this correct??? isSJF = distribution(generator); if (!existReadyBatch()) @@ -50,13 +54,17 @@ void SMS::batchScheduler() // pick & drain a ready batch if (batchFormation()) { - isSJF ? selectSJF() : selectRR(); + isSJF ? selectSJF(memClk) : selectRR(memClk); + } + else + { + wait(newRequest); } } else { // pick & drain a ready batch - isSJF ? selectSJF() : selectRR(); + isSJF ? selectSJF(memClk) : selectRR(memClk); } } } @@ -95,11 +103,23 @@ bool SMS::batchFormation(Thread thread) { buffer[thread].pop_front(); } - return !readybatches[thread]->isEmpty(); + + if (readybatches[thread]->isEmpty()) + { + debugManager.printDebugMessage(name(), + "EMPTY buffer, Ready batch for thread: " + to_string(thread.ID()) + " NOT formed"); + return false; + } + else + { + debugManager.printDebugMessage(name(), + "Form ready batch for thread: " + to_string(thread.ID())); + return true; + } } } -void SMS::selectSJF() +void SMS::selectSJF(sc_time memClk) { // find shorstest thread std::vector threadsWithNonEmptyReadybatches; @@ -121,6 +141,8 @@ void SMS::selectSJF() minThread = thread; } } + debugManager.printDebugMessage(name(), + "[SJF] Select ready batch of thread " + to_string(minThread.ID())); // drain to bank buffers std::deque &requestPtrs = readybatches[minThread]->getTransactions(); @@ -128,6 +150,10 @@ void SMS::selectSJF() { Bank bank = DramExtension::getExtension(*payloadPtrIterator).getBank(); bankbuffer[bank].emplace_back(*payloadPtrIterator); + debugManager.printDebugMessage(name(), + "[SJF] Drain request in the ready batch of thread " + to_string(minThread.ID()) + + " to bankbuffer " + to_string(bank.ID())); + wait(memClk); } requestPtrs.clear(); @@ -137,7 +163,7 @@ void SMS::selectSJF() } -void SMS::selectRR() +void SMS::selectRR(sc_time memClk) { static std::map::iterator next = readybatches.begin(); @@ -151,6 +177,8 @@ void SMS::selectRR() next = readybatches.begin(); } } + debugManager.printDebugMessage(name(), + "[RR] Select ready batch of thread " + to_string((*next).first.ID())); // drain to bank buffers std::deque &requestPtrs = (*next).second->getTransactions(); @@ -158,6 +186,10 @@ void SMS::selectRR() { Bank bank = DramExtension::getExtension(*payloadPtrIterator).getBank(); bankbuffer[bank].emplace_back(*payloadPtrIterator); + debugManager.printDebugMessage(name(), + "[RR] Drained request in the ready batch of thread " + to_string((*next).first.ID()) + + " to bankbuffer " + to_string(bank.ID())); + wait(memClk); } requestPtrs.clear(); @@ -179,5 +211,3 @@ bool SMS::existReadyBatch() return false; } - - diff --git a/DRAMSys/simulator/src/controller/scheduler/SMS.h b/DRAMSys/simulator/src/controller/scheduler/SMS.h index 9d2979f4..a1b7ac70 100644 --- a/DRAMSys/simulator/src/controller/scheduler/SMS.h +++ b/DRAMSys/simulator/src/controller/scheduler/SMS.h @@ -9,6 +9,7 @@ #include "../core/ControllerCore.h" #include "../core/configuration/Configuration.h" #include "../../common/dramExtension.h" +#include "../../common/DebugManager.h" #define MIN_TOTAL_REQ 16 @@ -17,7 +18,7 @@ using namespace std; class SMS: public sc_module, public IScheduler { public: - SMS(sc_module_name /*_name*/, ControllerCore &controllerCore, unsigned int SJFprobability) : IScheduler(controllerCore), SJFprobability(SJFprobability) + SMS(sc_module_name /*_name*/, ControllerCore &controllerCore, unsigned int SJFprobability) : IScheduler(controllerCore), SJFprobability(SJFprobability), debugManager(DebugManager::getInstance()) { // initialize memory request counter & memory request intensity for each thread unsigned int totalNumThreads = Configuration::getInstance().NumberOfTracePlayers; @@ -51,11 +52,15 @@ private: std::map inFlightMemRequestCounter; unsigned int SJFprobability; + DebugManager& debugManager; + sc_event newRequest; + bool batchFormation(); - void selectSJF(); - void selectRR(); + void selectSJF(sc_time memClk); + void selectRR(sc_time memClk); bool existReadyBatch(); bool batchFormation(Thread thread); + }; #endif // SMS_H