diff --git a/DRAMSys/library/src/common/TlmRecorder.cpp b/DRAMSys/library/src/common/TlmRecorder.cpp index 88056e7f..b5f9d568 100644 --- a/DRAMSys/library/src/common/TlmRecorder.cpp +++ b/DRAMSys/library/src/common/TlmRecorder.cpp @@ -221,7 +221,9 @@ void TlmRecorder::terminateRemainingTransactions() { while (!currentTransactionsInSystem.empty()) { - auto transaction = currentTransactionsInSystem.begin(); + auto transaction = std::min_element(currentTransactionsInSystem.begin(), + currentTransactionsInSystem.end(), [](decltype(currentTransactionsInSystem)::value_type& l, + decltype(currentTransactionsInSystem)::value_type& r) -> bool {return l.second.id < r.second.id;}); if (transaction->second.cmd == 'X') { std::string beginPhase = transaction->second.recordedPhases.front().name; diff --git a/DRAMSys/library/src/simulation/DRAMSys.cpp b/DRAMSys/library/src/simulation/DRAMSys.cpp index 5fc0f168..21c9962e 100644 --- a/DRAMSys/library/src/simulation/DRAMSys.cpp +++ b/DRAMSys/library/src/simulation/DRAMSys.cpp @@ -116,6 +116,15 @@ DRAMSys::DRAMSys(const sc_core::sc_module_name &name, } } +void DRAMSys::end_of_simulation() +{ + if (Configuration::getInstance().powerAnalysis) + { + for (auto& dram : drams) + dram->reportPower(); + } +} + void DRAMSys::logo() { #define GREENTXT(s) std::string(("\u001b[38;5;28m"+std::string((s))+"\033[0m")) diff --git a/DRAMSys/library/src/simulation/DRAMSys.h b/DRAMSys/library/src/simulation/DRAMSys.h index 5cda9a9a..f7fbf4ae 100644 --- a/DRAMSys/library/src/simulation/DRAMSys.h +++ b/DRAMSys/library/src/simulation/DRAMSys.h @@ -70,6 +70,8 @@ protected: const std::string &pathToResources, bool initAndBind); + void end_of_simulation() override; + //TLM 2.0 Protocol Checkers std::vector*> controllersTlmCheckers; diff --git a/DRAMSys/library/src/simulation/DRAMSysRecordable.cpp b/DRAMSys/library/src/simulation/DRAMSysRecordable.cpp index 39d9ce17..bc395f60 100644 --- a/DRAMSys/library/src/simulation/DRAMSysRecordable.cpp +++ b/DRAMSys/library/src/simulation/DRAMSysRecordable.cpp @@ -82,7 +82,7 @@ DRAMSysRecordable::DRAMSysRecordable(const sc_module_name &name, void DRAMSysRecordable::end_of_simulation() { - // Report power before TLM recorders are deleted + // Report power before TLM recorders are finalized if (Configuration::getInstance().powerAnalysis) { for (auto& dram : drams) diff --git a/DRAMSys/library/src/simulation/DRAMSysRecordable.h b/DRAMSys/library/src/simulation/DRAMSysRecordable.h index cd5f3f0c..cf4da80b 100644 --- a/DRAMSys/library/src/simulation/DRAMSysRecordable.h +++ b/DRAMSys/library/src/simulation/DRAMSysRecordable.h @@ -46,13 +46,14 @@ public: const std::string &simulationToRun, const std::string &pathToResources); +protected: + void end_of_simulation() override; + private: // Transaction Recorders (one per channel). // They generate the output databases. std::vector tlmRecorders; - void end_of_simulation() override; - void setupTlmRecorders(const std::string &traceName); void instantiateModules(const std::string &traceName, diff --git a/DRAMSys/library/src/simulation/dram/Dram.cpp b/DRAMSys/library/src/simulation/dram/Dram.cpp index a578e6af..0acd95b0 100644 --- a/DRAMSys/library/src/simulation/dram/Dram.cpp +++ b/DRAMSys/library/src/simulation/dram/Dram.cpp @@ -95,38 +95,28 @@ Dram::Dram(const sc_module_name &name) : sc_module(name), tSocket("socket") Dram::~Dram() { - if (Configuration::getInstance().powerAnalysis) - { - Dram::reportPower(); - delete DRAMPower; - } - if (Configuration::getInstance().useMalloc) free(memory); } void Dram::reportPower() { - if (!powerReported) - { - powerReported = true; - DRAMPower->calcEnergy(); + DRAMPower->calcEnergy(); - // Print the final total energy and the average power for - // the simulation: - std::cout << name() << std::string(" Total Energy: ") - << std::fixed << std::setprecision( 2 ) - << DRAMPower->getEnergy().total_energy - * Configuration::getInstance().memSpec->numberOfDevices - << std::string(" pJ") - << std::endl; + // Print the final total energy and the average power for + // the simulation: + std::cout << name() << std::string(" Total Energy: ") + << std::fixed << std::setprecision( 2 ) + << DRAMPower->getEnergy().total_energy + * Configuration::getInstance().memSpec->numberOfDevices + << std::string(" pJ") + << std::endl; - std::cout << name() << std::string(" Average Power: ") - << std::fixed << std::setprecision( 2 ) - << DRAMPower->getPower().average_power - * Configuration::getInstance().memSpec->numberOfDevices - << std::string(" mW") << std::endl; - } + std::cout << name() << std::string(" Average Power: ") + << std::fixed << std::setprecision( 2 ) + << DRAMPower->getPower().average_power + * Configuration::getInstance().memSpec->numberOfDevices + << std::string(" mW") << std::endl; } tlm_sync_enum Dram::nb_transport_fw(tlm_generic_payload &payload, diff --git a/DRAMSys/library/src/simulation/dram/Dram.h b/DRAMSys/library/src/simulation/dram/Dram.h index da7a0ede..dfa0feb4 100644 --- a/DRAMSys/library/src/simulation/dram/Dram.h +++ b/DRAMSys/library/src/simulation/dram/Dram.h @@ -40,6 +40,8 @@ #ifndef DRAM_H #define DRAM_H +#include + #include #include #include @@ -49,9 +51,6 @@ class Dram : public sc_core::sc_module { -private: - bool powerReported = false; - protected: explicit Dram(const sc_core::sc_module_name &name); SC_HAS_PROCESS(Dram); @@ -63,7 +62,7 @@ protected: unsigned char *memory; - libDRAMPower *DRAMPower = nullptr; + std::unique_ptr DRAMPower; virtual tlm::tlm_sync_enum nb_transport_fw(tlm::tlm_generic_payload &payload, tlm::tlm_phase &phase, sc_core::sc_time &delay); diff --git a/DRAMSys/library/src/simulation/dram/DramDDR3.cpp b/DRAMSys/library/src/simulation/dram/DramDDR3.cpp index 347fd817..fe4838d8 100644 --- a/DRAMSys/library/src/simulation/dram/DramDDR3.cpp +++ b/DRAMSys/library/src/simulation/dram/DramDDR3.cpp @@ -138,6 +138,6 @@ DramDDR3::DramDDR3(const sc_module_name &name) : Dram(name) powerSpec.memPowerSpec = memPowerSpec; powerSpec.memArchSpec = memArchSpec; - DRAMPower = new libDRAMPower(powerSpec, false); + DRAMPower = std::unique_ptr(new libDRAMPower(powerSpec, false)); } } diff --git a/DRAMSys/library/src/simulation/dram/DramDDR4.cpp b/DRAMSys/library/src/simulation/dram/DramDDR4.cpp index cbd5454f..e6124e61 100644 --- a/DRAMSys/library/src/simulation/dram/DramDDR4.cpp +++ b/DRAMSys/library/src/simulation/dram/DramDDR4.cpp @@ -138,6 +138,6 @@ DramDDR4::DramDDR4(const sc_module_name &name) : Dram(name) powerSpec.memPowerSpec = memPowerSpec; powerSpec.memArchSpec = memArchSpec; - DRAMPower = new libDRAMPower(powerSpec, false); + DRAMPower = std::unique_ptr(new libDRAMPower(powerSpec, false)); } } diff --git a/DRAMSys/library/src/simulation/dram/DramWideIO.cpp b/DRAMSys/library/src/simulation/dram/DramWideIO.cpp index dacd5ace..eead1c98 100644 --- a/DRAMSys/library/src/simulation/dram/DramWideIO.cpp +++ b/DRAMSys/library/src/simulation/dram/DramWideIO.cpp @@ -139,7 +139,7 @@ DramWideIO::DramWideIO(const sc_module_name &name) : Dram(name) powerSpec.memPowerSpec = memPowerSpec; powerSpec.memArchSpec = memArchSpec; - DRAMPower = new libDRAMPower(powerSpec, false); + DRAMPower = std::unique_ptr(new libDRAMPower(powerSpec, false)); // For each bank in a channel a error Model is created: if (storeMode == Configuration::StoreMode::ErrorModel) @@ -148,7 +148,7 @@ DramWideIO::DramWideIO(const sc_module_name &name) : Dram(name) { errorModel *em; std::string errorModelStr = "errorModel_bank" + std::to_string(i); - em = new errorModel(errorModelStr.c_str(), DRAMPower); + em = new errorModel(errorModelStr.c_str(), DRAMPower.get()); ememory.push_back(em); } }