From 39a14b11885e29459bb5d0b970a33c35b7ba0b73 Mon Sep 17 00:00:00 2001 From: Felipe Salerno Prado Date: Wed, 13 Jul 2016 15:11:19 +0200 Subject: [PATCH] Issue #91(Simulation Crash) fixed and small changes --- .../simulator/src/simulation/Simulation.cpp | 18 ++--- .../simulator/src/simulation/StlDataPlayer.h | 67 +------------------ .../simulator/src/simulation/StlPlayer.cpp | 8 +-- DRAMSys/simulator/src/simulation/StlPlayer.h | 60 +---------------- .../simulator/src/simulation/TracePlayer.cpp | 59 ++++++++++++++++ .../simulator/src/simulation/TracePlayer.h | 2 + 6 files changed, 77 insertions(+), 137 deletions(-) diff --git a/DRAMSys/simulator/src/simulation/Simulation.cpp b/DRAMSys/simulator/src/simulation/Simulation.cpp index 1aa5d831..0310bea0 100644 --- a/DRAMSys/simulator/src/simulation/Simulation.cpp +++ b/DRAMSys/simulator/src/simulation/Simulation.cpp @@ -122,23 +122,25 @@ void Simulation::instantiateModules(const string &traceName, const string &pathT for (size_t i = 0; i < Configuration::getInstance().NumberOfTracePlayers; i++) { std::string playerStr = "tracePlayer" + std::to_string(i); TracePlayer *player; + sc_time clk; + if(devices[i].clkMhz == 0) + clk = Configuration::getInstance().memSpec.clk; + else + clk = FrequencyToClk(devices[i].clkMhz); + // When data should be stored during the simulation the StlDataPlayer is needed. // Else: no data should be stored, for instance to get a faster simulation // or if you simply dont care about the data the normal StlPlayer is used. if(Configuration::getInstance().StoreMode == StorageMode::NoStorage) { - StlPlayer *newPlayer = new StlPlayer(playerStr.c_str(), pathToResources + string("traces/") + devices[i].trace, devices[i].clkMhz, this); - player = newPlayer; - newPlayer->getTraceLength(pathToResources + string("traces/") + devices[i].trace); - totalTransactions += newPlayer->getNumberOfLines(pathToResources + string("traces/") + devices[i].trace); + player = new StlPlayer(playerStr.c_str(), pathToResources + string("traces/") + devices[i].trace, clk, this); } else { - StlDataPlayer *newPlayer = new StlDataPlayer(playerStr.c_str(), pathToResources + string("traces/") + devices[i].trace, devices[i].clkMhz, this); - player = newPlayer; - newPlayer->getTraceLength(pathToResources + string("traces/") + devices[i].trace); - totalTransactions += newPlayer->getNumberOfLines(pathToResources + string("traces/") + devices[i].trace); + player = new StlDataPlayer(playerStr.c_str(), pathToResources + string("traces/") + devices[i].trace, clk, this); } + player->getTraceLength(pathToResources + string("traces/") + devices[i].trace, clk); + totalTransactions += player->getNumberOfLines(pathToResources + string("traces/") + devices[i].trace); players.push_back(player); } remainingTransactions = totalTransactions; diff --git a/DRAMSys/simulator/src/simulation/StlDataPlayer.h b/DRAMSys/simulator/src/simulation/StlDataPlayer.h index 9c520b4b..4f918b5b 100644 --- a/DRAMSys/simulator/src/simulation/StlDataPlayer.h +++ b/DRAMSys/simulator/src/simulation/StlDataPlayer.h @@ -48,7 +48,7 @@ using namespace tlm; struct StlDataPlayer: public TracePlayer { public: - StlDataPlayer(sc_module_name /*name*/, string pathToTrace, unsigned int clkMhz, TracePlayerListener* listener); + StlDataPlayer(sc_module_name /*name*/, string pathToTrace, sc_time clk, TracePlayerListener* listener); virtual void nextPayload() override { @@ -133,63 +133,6 @@ public: } } - void getTraceLength(string pathToTrace) - { - ifstream newFile; - newFile.open(pathToTrace); - if(newFile.is_open()) { - newFile.seekg(-1,ios_base::end);// go to one spot before the EOF - char ch; - newFile.get(ch); - - if(ch == file.eof()) - SC_REPORT_FATAL(0, (string("Empty Trace ") + pathToTrace).c_str()); - - if(ch == '\n') - newFile.seekg(-2,ios_base::end); - - bool keepLooping = true; - while(keepLooping) { - - newFile.get(ch); // Get current byte's data - - if((int)newFile.tellg() <= 1) { // If the data was at or before the 0th byte - newFile.seekg(0); // The first line is the last line - keepLooping = false; // So stop there - } - else if(ch == '\n') { // If the data was a newline - keepLooping = false; // Stop at the current position. - } - else { // If the data was neither a newline nor at the 0 byte - newFile.seekg(-2,ios_base::cur); // Move to the front of that data, then to the front of the data before it - } - } - - string lastLine; - getline(newFile,lastLine); // Read the current line - std::istringstream iss(lastLine); - string time; - iss >> time; - Configuration::getInstance().TraceLength = std::stoull(time.c_str())*clk; - newFile.close(); - } - - } - - unsigned int getNumberOfLines(string pathToTrace) - { - ifstream newFile; - newFile.open(pathToTrace); - newFile.unsetf(std::ios_base::skipws); // new lines will be skipped unless we stop it from happening: - // count the newlines with an algorithm specialized for counting: - unsigned int lineCount = std::count(std::istream_iterator(newFile), std::istream_iterator(), '\n'); - - newFile.close(); - return lineCount; - } - - - private: ifstream file; unsigned int burstlength; @@ -198,18 +141,14 @@ private: }; -StlDataPlayer::StlDataPlayer(sc_module_name /*name*/, string pathToTrace, unsigned int clkMhz, +StlDataPlayer::StlDataPlayer(sc_module_name /*name*/, string pathToTrace,sc_time clk, TracePlayerListener* listener) : TracePlayer(listener),file(pathToTrace) { if (!file.is_open()) SC_REPORT_FATAL(0, (string("Could not open trace ") + pathToTrace).c_str()); - if(clkMhz == 0) - clk = Configuration::getInstance().memSpec.clk; - else - clk = FrequencyToClk(clkMhz); - + this->clk = clk; this->burstlength = Configuration::getInstance().memSpec.BurstLength; this->bytesPerColumn = xmlAddressDecoder::getInstance().amount["bytes"]; } diff --git a/DRAMSys/simulator/src/simulation/StlPlayer.cpp b/DRAMSys/simulator/src/simulation/StlPlayer.cpp index b0bb4a00..07a6d587 100644 --- a/DRAMSys/simulator/src/simulation/StlPlayer.cpp +++ b/DRAMSys/simulator/src/simulation/StlPlayer.cpp @@ -38,18 +38,14 @@ #include "StlPlayer.h" -StlPlayer::StlPlayer(sc_module_name /*name*/, string pathToTrace, unsigned int clkMhz, +StlPlayer::StlPlayer(sc_module_name /*name*/, string pathToTrace, sc_time clk, TracePlayerListener* listener) : TracePlayer(listener),file(pathToTrace) { if (!file.is_open()) SC_REPORT_FATAL(0, (string("Could not open trace ") + pathToTrace).c_str()); - if(clkMhz == 0) - clk = Configuration::getInstance().memSpec.clk; - else - clk = FrequencyToClk(clkMhz); - + this->clk = clk; this->burstlength = Configuration::getInstance().memSpec.BurstLength; this->bytesPerColumn = xmlAddressDecoder::getInstance().amount["bytes"]; } diff --git a/DRAMSys/simulator/src/simulation/StlPlayer.h b/DRAMSys/simulator/src/simulation/StlPlayer.h index cb56a556..bdc33661 100644 --- a/DRAMSys/simulator/src/simulation/StlPlayer.h +++ b/DRAMSys/simulator/src/simulation/StlPlayer.h @@ -48,7 +48,7 @@ using namespace tlm; struct StlPlayer: public TracePlayer { public: - StlPlayer(sc_module_name /*name*/, string pathToTrace, unsigned int clkMhz, TracePlayerListener *listener); + StlPlayer(sc_module_name /*name*/, string pathToTrace, sc_time clk, TracePlayerListener *listener); virtual void nextPayload() override { @@ -119,64 +119,6 @@ public: } } - - - void getTraceLength(string pathToTrace) - { - ifstream newFile; - newFile.open(pathToTrace); - if(newFile.is_open()) { - newFile.seekg(-1,ios_base::end);// go to one spot before the EOF - char ch; - newFile.get(ch); - - if(ch == file.eof()) - SC_REPORT_FATAL(0, (string("Empty Trace ") + pathToTrace).c_str()); - - if(ch == '\n') - newFile.seekg(-2,ios_base::end); - - bool keepLooping = true; - while(keepLooping) { - - newFile.get(ch); // Get current byte's data - - if((int)newFile.tellg() <= 1) { // If the data was at or before the 0th byte - newFile.seekg(0); // The first line is the last line - keepLooping = false; // So stop there - } - else if(ch == '\n') { // If the data was a newline - keepLooping = false; // Stop at the current position. - } - else { // If the data was neither a newline nor at the 0 byte - newFile.seekg(-2,ios_base::cur); // Move to the front of that data, then to the front of the data before it - } - } - - string lastLine; - getline(newFile,lastLine); // Read the current line - std::istringstream iss(lastLine); - string time; - iss >> time; - Configuration::getInstance().TraceLength = std::stoull(time.c_str())*clk; - newFile.close(); - } - - } - - unsigned int getNumberOfLines(string pathToTrace) - { - ifstream newFile; - newFile.open(pathToTrace); - newFile.unsetf(std::ios_base::skipws); // new lines will be skipped unless we stop it from happening: - // count the newlines with an algorithm specialized for counting: - unsigned int lineCount = std::count(std::istream_iterator(newFile), std::istream_iterator(), '\n'); - - newFile.close(); - return lineCount; - } - - private: ifstream file; unsigned int burstlength; diff --git a/DRAMSys/simulator/src/simulation/TracePlayer.cpp b/DRAMSys/simulator/src/simulation/TracePlayer.cpp index 42a726cc..015e3af8 100644 --- a/DRAMSys/simulator/src/simulation/TracePlayer.cpp +++ b/DRAMSys/simulator/src/simulation/TracePlayer.cpp @@ -106,3 +106,62 @@ void TracePlayer::peqCallback(tlm_generic_payload &payload, const tlm_phase &pha SC_REPORT_FATAL(0, "TracePlayer PEQ was triggered with unknown phase"); } } + +void TracePlayer::getTraceLength(string pathToTrace, sc_time clk) +{ + ifstream newFile; + newFile.open(pathToTrace); + if(newFile.is_open()) { + newFile.seekg(-1,ios_base::end);// go to one spot before the EOF + char ch; + newFile.get(ch); + + if(ch == newFile.eof()) + SC_REPORT_FATAL(0, (string("Empty Trace ") + pathToTrace).c_str()); + + while(ch == '\n') + { + newFile.seekg(-2,ios_base::cur); + newFile.get(ch); + } + + bool keepLooping = true; + while(keepLooping) { + + newFile.clear(); + if((int)newFile.tellg() <= 1) { // If the data was at or before the 0th byte + newFile.seekg(0); // The first line is the last line + keepLooping = false; // So stop there + } + else if(ch == '\n') { // If the data was a newline + keepLooping = false; // Stop at the current position. + } + else { // If the data was neither a newline nor at the 0 byte + newFile.seekg(-2,ios_base::cur); // Move to the front of that data, then to the front of the data before it + newFile.get(ch); + } + } + + string lastLine; + getline(newFile,lastLine); // Read the current line + std::istringstream iss(lastLine); + string time; + iss >> time; + Configuration::getInstance().TraceLength = std::stoull(time.c_str())*clk; + newFile.close(); + } + +} + +unsigned int TracePlayer::getNumberOfLines(string pathToTrace) +{ + ifstream newFile; + newFile.open(pathToTrace); + // new lines will be skipped unless we stop it from happening: + newFile.unsetf(std::ios_base::skipws); + // count the lines with an algorithm specialized for counting: + unsigned int lineCount = std::count(std::istream_iterator(newFile), std::istream_iterator(), ':'); + + newFile.close(); + return lineCount; +} diff --git a/DRAMSys/simulator/src/simulation/TracePlayer.h b/DRAMSys/simulator/src/simulation/TracePlayer.h index 7182fc67..2c9a7ae0 100644 --- a/DRAMSys/simulator/src/simulation/TracePlayer.h +++ b/DRAMSys/simulator/src/simulation/TracePlayer.h @@ -61,6 +61,8 @@ public: tlm_utils::simple_initiator_socket iSocket; TracePlayer(TracePlayerListener *listener); virtual void nextPayload() = 0; + void getTraceLength(string pathToTrace, sc_time clk); + unsigned int getNumberOfLines(string pathToTrace); protected: gp* allocatePayload();