Issue #91(Simulation Crash) fixed and small changes
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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<char>(newFile), std::istream_iterator<char>(), '\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"];
|
||||
}
|
||||
|
||||
@@ -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"];
|
||||
}
|
||||
|
||||
@@ -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<char>(newFile), std::istream_iterator<char>(), '\n');
|
||||
|
||||
newFile.close();
|
||||
return lineCount;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
ifstream file;
|
||||
unsigned int burstlength;
|
||||
|
||||
@@ -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<char>(newFile), std::istream_iterator<char>(), ':');
|
||||
|
||||
newFile.close();
|
||||
return lineCount;
|
||||
}
|
||||
|
||||
@@ -61,6 +61,8 @@ public:
|
||||
tlm_utils::simple_initiator_socket<TracePlayer> iSocket;
|
||||
TracePlayer(TracePlayerListener *listener);
|
||||
virtual void nextPayload() = 0;
|
||||
void getTraceLength(string pathToTrace, sc_time clk);
|
||||
unsigned int getNumberOfLines(string pathToTrace);
|
||||
|
||||
protected:
|
||||
gp* allocatePayload();
|
||||
|
||||
Reference in New Issue
Block a user