From 6388b3d75c104f20be66580b083cf422aba056b3 Mon Sep 17 00:00:00 2001 From: Matthias Jung Date: Thu, 22 Aug 2019 22:40:28 +0200 Subject: [PATCH 1/4] DRAM command was not set in trace recorder --- DRAMSys/library/src/common/TlmRecorder.cpp | 5 +++++ DRAMSys/library/src/common/TlmRecorder.h | 1 + 2 files changed, 6 insertions(+) diff --git a/DRAMSys/library/src/common/TlmRecorder.cpp b/DRAMSys/library/src/common/TlmRecorder.cpp index db59e640..b0d21f33 100644 --- a/DRAMSys/library/src/common/TlmRecorder.cpp +++ b/DRAMSys/library/src/common/TlmRecorder.cpp @@ -141,6 +141,8 @@ void TlmRecorder::introduceTransactionSystem(tlm::tlm_generic_payload &trans) { unsigned int id = totalNumTransactions++; currentTransactionsInSystem[&trans].id = id; + currentTransactionsInSystem[&trans].cmd = trans.get_command() == + tlm::TLM_READ_COMMAND ? "R" : "W"; currentTransactionsInSystem[&trans].address = trans.get_address(); currentTransactionsInSystem[&trans].burstlength = trans.get_streaming_width(); currentTransactionsInSystem[&trans].dramExtension = DramExtension::getExtension( @@ -378,8 +380,11 @@ void TlmRecorder::insertTransactionInDB(Transaction &recordingData) recordingData.timeOnDataStrobe.end.value()); sqlite3_bind_int64(insertTransactionStatement, 13, recordingData.timeOfGeneration.value()); + sqlite3_bind_text(insertTransactionStatement, 14, + recordingData.cmd.c_str(), recordingData.cmd.length(), NULL); executeSqlStatement(insertTransactionStatement); + } void TlmRecorder::insertRangeInDB(unsigned int id, const sc_time &begin, diff --git a/DRAMSys/library/src/common/TlmRecorder.h b/DRAMSys/library/src/common/TlmRecorder.h index 31deb14d..8abcb2ac 100644 --- a/DRAMSys/library/src/common/TlmRecorder.h +++ b/DRAMSys/library/src/common/TlmRecorder.h @@ -94,6 +94,7 @@ private: unsigned int id; unsigned int address; unsigned int burstlength; + std::string cmd; DramExtension dramExtension; sc_time timeOfGeneration; TimeInterval timeOnDataStrobe; From 9702d7a8f3053c8b91d629f5f52c535e9f039b96 Mon Sep 17 00:00:00 2001 From: Matthias Jung Date: Thu, 22 Aug 2019 22:59:23 +0200 Subject: [PATCH 2/4] Add compile flag for macOS --- DRAMSys/simulator/simulator.pro | 1 + 1 file changed, 1 insertion(+) diff --git a/DRAMSys/simulator/simulator.pro b/DRAMSys/simulator/simulator.pro index b5b297cf..adf11c06 100644 --- a/DRAMSys/simulator/simulator.pro +++ b/DRAMSys/simulator/simulator.pro @@ -34,6 +34,7 @@ unix:!macx { macx: { CONFIG += c++11 QMAKE_CXXFLAGS += -std=c++0x -stdlib=libc++ -O0 -g + QMAKE_MACOSX_DEPLOYMENT_TARGET=10.14 } INCLUDEPATH += ../library/src/simulation/ From a6f679b86b034e53d330ff242bd251945325b816 Mon Sep 17 00:00:00 2001 From: Matthias Jung Date: Thu, 22 Aug 2019 23:00:38 +0200 Subject: [PATCH 3/4] Add compile flag for macOS --- DRAMSys/library/library.pro | 1 + 1 file changed, 1 insertion(+) diff --git a/DRAMSys/library/library.pro b/DRAMSys/library/library.pro index 84267536..4364debd 100644 --- a/DRAMSys/library/library.pro +++ b/DRAMSys/library/library.pro @@ -63,6 +63,7 @@ unix:!macx { macx: { CONFIG += c++11 QMAKE_CXXFLAGS += -std=c++0x -stdlib=libc++ -O0 -g + QMAKE_MACOSX_DEPLOYMENT_TARGET=10.14 } QMAKE_CXXFLAGS += -isystem $${systemc_home}/include From f6072e9d4f56b260862a9f74f277eb07520af87d Mon Sep 17 00:00:00 2001 From: Matthias Jung Date: Thu, 22 Aug 2019 23:11:48 +0200 Subject: [PATCH 4/4] Fixed Memory Leak As pointed out by @sprado, there was a memory leak in the STL player. The data pointer was allocated, but never deleted again. Some lines for deletion were commented out in the memory manager in the free function. These two lines regarding the deletion of data were moved into the destructor of the memory manager. The allocation of the data is done in the allocate() function of the memory manager when a new payload is generated. --- .../library/src/simulation/MemoryManager.cpp | 21 +++++++++++++------ DRAMSys/library/src/simulation/StlPlayer.h | 13 +++--------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/DRAMSys/library/src/simulation/MemoryManager.cpp b/DRAMSys/library/src/simulation/MemoryManager.cpp index 6f456272..0094a9b4 100644 --- a/DRAMSys/library/src/simulation/MemoryManager.cpp +++ b/DRAMSys/library/src/simulation/MemoryManager.cpp @@ -36,6 +36,7 @@ #include "MemoryManager.h" #include "../common/DebugManager.h" +#include "../controller/core/configuration/Configuration.h" #include using namespace std; @@ -48,20 +49,30 @@ MemoryManager::MemoryManager(): numberOfAllocations(0), numberOfFrees(0) MemoryManager::~MemoryManager() { for (gp *payload : freePayloads) { + delete[] payload->get_data_ptr(); delete payload; numberOfFrees++; } - //Comment in if you are suspecting a memory leak in the manager - //DebugManager::getInstance().printDebugMessage("MemoryManager","Number of allocated payloads: " + to_string(numberOfAllocations)); - //DebugManager::getInstance().printDebugMessage("MemoryManager","Number of freed payloads: " + to_string(numberOfFrees)); + DebugManager::getInstance().printDebugMessage("MemoryManager", + "Number of allocated payloads: " + to_string(numberOfAllocations)); + DebugManager::getInstance().printDebugMessage("MemoryManager", + "Number of freed payloads: " + to_string(numberOfFrees)); } gp *MemoryManager::allocate() { if (freePayloads.empty()) { numberOfAllocations++; - return new gp(this); + gp *payload = new gp(this); + + // Allocate a data buffer and initialize it with zeroes: + unsigned int dataLength = Configuration::getInstance().getBytesPerBurst(); + unsigned char *data = new unsigned char[dataLength]; + std::fill(data, data + dataLength, 0); + + payload->set_data_ptr(data); + return payload; } else { gp *result = freePayloads.back(); freePayloads.pop_back(); @@ -71,8 +82,6 @@ gp *MemoryManager::allocate() void MemoryManager::free(gp *payload) { - //unsigned char *dptr = payload->get_data_ptr(); - //delete[] dptr; payload->reset(); //clears all extensions freePayloads.push_back(payload); } diff --git a/DRAMSys/library/src/simulation/StlPlayer.h b/DRAMSys/library/src/simulation/StlPlayer.h index cace8884..dae8e4ab 100644 --- a/DRAMSys/library/src/simulation/StlPlayer.h +++ b/DRAMSys/library/src/simulation/StlPlayer.h @@ -89,12 +89,7 @@ public: } // Allocate a generic payload for this request. gp *payload = this->allocatePayload(); - - // Allocate a data buffer and initialize it with zeroes. It may be - // overwritten with data from the trace file depending on the storage - // mode. - unsigned char *data = new unsigned char[dataLength]; - std::fill(data, data + dataLength, 0); + unsigned char *data = payload->get_data_ptr(); // Trace files MUST provide timestamp, command and address for every // transaction. The data information depends on the storage mode @@ -170,16 +165,14 @@ public: payload->set_data_ptr(data); payload->set_command(cmd); - if (relative == false) - { + if (relative == false) { // Send the transaction directly or schedule it to be sent in the future. if (sendingTime <= sc_time_stamp()) this->payloadEventQueue.notify(*payload, BEGIN_REQ, SC_ZERO_TIME); else this->payloadEventQueue.notify(*payload, BEGIN_REQ, sendingTime - sc_time_stamp()); - } - else + } else payloadEventQueue.notify(*payload, BEGIN_REQ, sendingTime); }