diff --git a/DRAMSys/simulator/src/controller/Controller.h b/DRAMSys/simulator/src/controller/Controller.h index 38a8142e..39f05d49 100644 --- a/DRAMSys/simulator/src/controller/Controller.h +++ b/DRAMSys/simulator/src/controller/Controller.h @@ -88,11 +88,16 @@ public: ~Controller() { - delete controllerCore; + delete controllerCore; delete scheduler; } void terminateSimulation(); + + sc_time getIdleTime(); + sc_time getEndTime(); + sc_time getStartTime(); + // ------- CONTROLLER CORE --------- virtual void send(const ScheduledCommand& command, tlm_generic_payload& payload) override; virtual void send(Trigger trigger, sc_time time, tlm_generic_payload& payload) override; @@ -138,6 +143,17 @@ private: DebugManager& debugManager; TlmRecorder *tlmRecorder; + + // Bandwidth realted: + sc_time idleStart; + bool idleState = false; + sc_time idleTime; + sc_time endTime; + sc_time startTime; + int startTimeSet = false; + void startBandwidthIdleCollector(); + void endBandwidthIdleCollector(); + }; // --- IMPLEMENTATION ----- @@ -353,6 +369,11 @@ tlm_sync_enum Controller::nb_transport_fw(tlm_generic_payload &payload tlmRecorder->recordPhase(payload, phase, recTime); frontendPEQ.notify(payload, phase, notDelay); + + //Bandwidth IDLE + if ((getTotalNumberOfPayloadsInSystem()== 0)&& idleState){ + endBandwidthIdleCollector(); + } } else if (phase == END_RESP) { @@ -361,6 +382,11 @@ tlm_sync_enum Controller::nb_transport_fw(tlm_generic_payload &payload printDebugMessage("[fw] Recording " + phaseNameToString(phase) + " at " + recTime.to_string() + " notification in " + notDelay.to_string()); + // Badnwith IDLE + if (getTotalNumberOfPayloadsInSystem()==1){ + startBandwidthIdleCollector(); + } + tlmRecorder->recordPhase(payload, phase, recTime); frontendPEQ.notify(payload, phase, notDelay); } @@ -378,6 +404,7 @@ void Controller::frontendPEQCallback(tlm_generic_payload &payload, con { if (phase == BEGIN_REQ) { + printDebugMessage(string("Payload in system: ") + to_string(getTotalNumberOfPayloadsInSystem())); payload.acquire(); payloadEntersSystem(payload); if (getTotalNumberOfPayloadsInSystem() > controllerCore->config.MaxNrOfTransactions) @@ -422,6 +449,12 @@ void Controller::payloadEntersSystem(tlm_generic_payload &payload) "Payload enters system on bank " + to_string(bank.ID()) + ". Total number of payloads in Controller: " + to_string(getTotalNumberOfPayloadsInSystem())); numberOfPayloadsInSystem[bank]++; + // Set Start Time for Simulation + if (startTimeSet == false){ + printDebugMessage("Simulation Timer Start"); + startTime = sc_time_stamp()-Configuration::getInstance().memSpec.clk; + startTimeSet = true; + } } template @@ -454,7 +487,7 @@ void Controller::scheduleNextFromScheduler(Bank bank) { return; } - + pair nextRequest = scheduler->getNextRequest(bank); if(nextRequest.second != NULL) { @@ -598,5 +631,36 @@ void Controller::terminateSimulation() } } +template +void Controller::startBandwidthIdleCollector(){ + printDebugMessage("IDLE Start"); + idleStart = sc_time_stamp(); + endTime = sc_time_stamp(); + idleState = true; +} + +template +void Controller::endBandwidthIdleCollector(){ + printDebugMessage("IDLE End"); + idleTime += sc_time_stamp()-idleStart+ Configuration::getInstance().memSpec.clk; + idleState = false; +} +template +sc_time Controller::getIdleTime(){ + printDebugMessage("IDLE Time: "+idleTime.to_string()); + return idleTime; +} +template +sc_time Controller::getEndTime(){ + printDebugMessage("End Time: "+endTime.to_string()); + return endTime; +} +template +sc_time Controller::getStartTime(){ + printDebugMessage("Start Time: "+startTime.to_string()); + return startTime; +} + + #endif /* CONTROLLERWRAPPER_H_ */ diff --git a/DRAMSys/simulator/src/simulation/Dram.h b/DRAMSys/simulator/src/simulation/Dram.h index 6125e25f..94b54be7 100644 --- a/DRAMSys/simulator/src/simulation/Dram.h +++ b/DRAMSys/simulator/src/simulation/Dram.h @@ -48,6 +48,7 @@ #include #include "../common/DebugManager.h" #include "../common/dramExtension.h" +#include "../controller/Controller.h" #include "../controller/core/TimingCalculation.h" #include "../controller/core/configuration/Configuration.h" #include "../common/protocol.h" @@ -74,7 +75,7 @@ struct Dram : sc_module libDRAMPower *DRAMPower; double sumOfEnergyWindows = 0.0; - // Bandwith realted: + // Bandwidth realted: unsigned long long int numberOfTransactionsServed; sc_time firstAccess; sc_time lastAccess; @@ -87,6 +88,7 @@ struct Dram : sc_module map< unsigned long int, std::array > memory; TlmRecorder *tlmRecorder; + Controller<>* dramController; SC_CTOR(Dram) : tSocket("socket") { @@ -214,17 +216,26 @@ struct Dram : sc_module double averagePower = (totalEnergy / sc_time_stamp().to_seconds()) / 1e9; // Print the final total energy and the average power for the simulation - cout << name() << string("\tTotal Energy: \t") + to_string(totalEnergy) + string("\t[pJ]") << endl; - cout << name() << string("\tAverage Power: \t") + to_string(averagePower) + string("\t[mW]") << endl; + cout << name() << string("\tTotal Energy: \t") << fixed <getIdleTime(); + sc_time endTime = dramController->getEndTime(); + sc_time startTime = dramController->getStartTime(); + double bandwidth = (activeTime/(endTime-startTime)*100); + double bandwidth_IDLE = ((activeTime)/(endTime-startTime-idleTime)*100); + // | clk in Mhz e.g. 800 [MHz] | * | DataRate e.g. 2 | * | BusWidth e.g. 8 | / | 1024 | + double maxBandwidth = ( (1000000/Configuration::getInstance().memSpec.clk.to_double()) * Configuration::getInstance().memSpec.DataRate * Configuration::getInstance().memSpec.BusWidth ) / ( 1024 ); + cout << name() << string("\tTotal Time: \t") <<(endTime-startTime).to_string() << endl; + //cout << name() << string("\tTotal IDLE: \t") < *contr) + { + dramController = contr; + } }; #endif /* DRAM_H_ */ diff --git a/DRAMSys/simulator/src/simulation/Simulation.cpp b/DRAMSys/simulator/src/simulation/Simulation.cpp index d889e233..964c6fc4 100644 --- a/DRAMSys/simulator/src/simulation/Simulation.cpp +++ b/DRAMSys/simulator/src/simulation/Simulation.cpp @@ -49,6 +49,7 @@ #include "../common/Utils.h" #include "../simulation/StlDataPlayer.h" #include "../simulation/TemperatureController.h" +#include "../controller/Controller.h" using namespace std; @@ -144,6 +145,7 @@ void Simulation::instantiateModules(const string &traceName, const string &pathT str = "dram" + std::to_string(i); Dram<> *dram = new Dram<>(str.c_str()); dram->setTlmRecorder(tlmRecorders[i]); + dram->setDramController(controllers[i]); drams.push_back(dram); } }