Now we have just one STL player that works properly for all storage modes.

- StlDataPlayer and StlPlayer merged (less code, less bugs).
- Code improved and commented (easier to maintain).
- In case of corrupted trace file the simulation is aborted and an error
  message is generated with the offensive line (easier to find errors).
This commit is contained in:
Éder F. Zulian
2016-08-12 19:16:53 +02:00
parent c792faa005
commit 9bc848efbc
11 changed files with 141 additions and 270 deletions

View File

@@ -154,7 +154,6 @@ HEADERS += \
src/controller/core/configuration/MemSpec.h \
src/controller/core/configuration/thermalSimConfig.h \
src/simulation/StlPlayer.h \
src/simulation/StlDataPlayer.h \
src/simulation/TracePlayerListener.h \
src/simulation/TraceGenerator.h \
src/simulation/TemperatureController.h \

View File

@@ -47,10 +47,8 @@
class Fifo : public IScheduler
{
public:
Fifo(ControllerCore &controllerCore) : IScheduler(controllerCore)
{}
virtual ~Fifo()
{}
Fifo(ControllerCore &controllerCore) : IScheduler(controllerCore) {}
virtual ~Fifo() {}
void schedule(gp* payload) override;
std::pair<Command, tlm::tlm_generic_payload*> getNextRequest(Bank bank) override;

View File

@@ -33,6 +33,7 @@
* Janik Schlemminger
* Robert Gernhardt
* Matthias Jung
* Éder F. Zulian
*/
#include "FifoStrict.h"

View File

@@ -33,6 +33,7 @@
* Janik Schlemminger
* Robert Gernhardt
* Matthias Jung
* Éder F. Zulian
*/
#ifndef FIFOSTRICT_H

View File

@@ -47,7 +47,6 @@
#include "../controller/core/ControllerCore.h"
#include "../controller/core/configuration/ConfigurationLoader.h"
#include "../common/Utils.h"
#include "../simulation/StlDataPlayer.h"
#include "../simulation/TemperatureController.h"
#include "../controller/Controller.h"
@@ -122,29 +121,34 @@ 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);
sc_time playerClk;
// 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)
{
player = new StlPlayer(playerStr.c_str(), pathToResources + string("traces/") + devices[i].trace, clk, this);
}
// The clock frequency for the player can be specified in the
// configuration file like in the example below (200 MHz):
//
// <tracesetups>
// <tracesetup id="fifo">
// <device clkMhz="200">chstone-adpcm_32.stl</device>
// </tracesetup>
// </tracesetups>
//
// If it is not specified in the configuration, the player will be
// configured to use the memory clock frequency got from the memory
// specs.
if (devices[i].clkMhz == 0)
playerClk = Configuration::getInstance().memSpec.clk;
else
{
player = new StlDataPlayer(playerStr.c_str(), pathToResources + string("traces/") + devices[i].trace, clk, this);
}
player->getTraceLength(pathToResources + string("traces/") + devices[i].trace, clk);
playerClk = FrequencyToClk(devices[i].clkMhz);
player = new StlPlayer(playerStr.c_str(), pathToResources + string("traces/") + devices[i].trace, playerClk, this);
player->getTraceLength(pathToResources + string("traces/") + devices[i].trace, playerClk);
totalTransactions += player->getNumberOfLines(pathToResources + string("traces/") + devices[i].trace);
players.push_back(player);
}
remainingTransactions = totalTransactions;
#endif
#endif /* USE_EXAMPLE_INITIATOR */
// Create and properly initialize TLM recorders. They need to be ready before creating some modules.
setupTlmRecorders(traceName, pathToResources, devices);

View File

@@ -1,157 +0,0 @@
/*
* Copyright (c) 2015, University of Kaiserslautern
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors:
* Janik Schlemminger
* Robert Gernhardt
* Matthias Jung
*/
#ifndef STLDATAPLAYER_H
#define STLDATAPLAYER_H
#include "../common/xmlAddressdecoder.h"
#include "TracePlayer.h"
using namespace std;
using namespace tlm;
struct StlDataPlayer: public TracePlayer
{
public:
StlDataPlayer(sc_module_name /*name*/, string pathToTrace, sc_time clk, TracePlayerListener* listener);
virtual void nextPayload() override
{
std::string line;
while (line.empty() && file) {
std::getline(file, line);
// Ignore lines which begin with '#' (commented lines)
if (!line.empty() && line.at(0) == '#') {
line.clear();
}
}
if(!file) {
this->terminate();
return;
}
std::istringstream iss(line);
string time, command, address, data;
iss >> time >> command >> address >> data;
// check if data length in the trace file is correct:
if((data.length()/2) != (bytesPerColumn*burstlength))
{
SC_REPORT_FATAL("StlDataPlayer", "Data in the trace file has not the right length");
}
unsigned long long parsedAdress = std::stoull(address.c_str(), 0, 16);
gp* payload = this->allocatePayload();
unsigned char * dataElement = new unsigned char[bytesPerColumn*burstlength];
payload->set_address(parsedAdress);
payload->set_response_status(TLM_INCOMPLETE_RESPONSE);
payload->set_dmi_allowed(false);
payload->set_byte_enable_length(0);
payload->set_streaming_width(burstlength);
payload->set_data_length(bytesPerColumn*burstlength);
payload->set_data_ptr(dataElement);
// set data:
for(unsigned i = 0; i < bytesPerColumn*burstlength ; i++)
{
dataElement[i] = (unsigned char)std::stoi(data.substr(i*2,2).c_str(),0,16);
}
if (command == "read")
{
payload->set_command(TLM_READ_COMMAND);
}
else if (command == "write")
{
payload->set_command(TLM_WRITE_COMMAND);
// Parse and set data
string data;
iss >> data;
if(!data.empty())
{
//cout << "parsing write data: " << data << std::endl;
for(int i = 0; i < 16*2; i++) // TODO column / burst breite
{
std::string byteString = "0x";
byteString.append(data.substr(2*(i+1), 2));
//cout << byteString << " " << std::stoi(byteString.c_str(), 0, 16) << endl;
dataElement[i] = std::stoi(byteString.c_str(), 0, 16);
}
}
} else {
SC_REPORT_FATAL(0, (string("Corrupted tracefile, command ") + command + string(" unknown")).c_str());
}
sc_time sendingTime = std::stoull(time.c_str())*clk;
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());
}
}
private:
ifstream file;
unsigned int burstlength;
unsigned int bytesPerColumn;
sc_time clk;
};
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());
this->clk = clk;
this->burstlength = Configuration::getInstance().memSpec.BurstLength;
this->bytesPerColumn = xmlAddressDecoder::getInstance().amount["bytes"];
}
#endif // STLDATAPLAYER_H

View File

@@ -33,19 +33,115 @@
* Janik Schlemminger
* Robert Gernhardt
* Matthias Jung
* Éder F. Zulian
*/
#include "StlPlayer.h"
StlPlayer::StlPlayer(sc_module_name /*name*/, string pathToTrace, sc_time clk,
TracePlayerListener* listener) :
TracePlayer(listener),file(pathToTrace)
StlPlayer::StlPlayer(sc_module_name, string pathToTrace, sc_time playerClk, TracePlayerListener *listener) : TracePlayer(listener), file(pathToTrace)
{
if (!file.is_open())
SC_REPORT_FATAL(0, (string("Could not open trace ") + pathToTrace).c_str());
this->clk = clk;
this->playerClk = playerClk;
this->burstlength = Configuration::getInstance().memSpec.BurstLength;
this->bytesPerColumn = xmlAddressDecoder::getInstance().amount["bytes"];
this->dataLength = bytesPerColumn * burstlength;
this->lineCnt = 0;
}
void StlPlayer::nextPayload()
{
std::string line;
while (line.empty() && file) {
// Get a new line from the input file.
std::getline(file, line);
lineCnt++;
// If the line starts with '#' (commented lines) the transaction is ignored.
if (!line.empty() && line.at(0) == '#')
line.clear();
}
if (!file) {
// The file is empty. Nothing more to do.
this->terminate();
return;
}
// 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);
// Trace files MUST provide timestamp, command and address for every
// transaction. The data information depends on the storage mode
// configuration.
string time;
string command;
string address;
string dataStr;
std::istringstream iss(line);
// Get the timestamp for the transaction.
iss >> time;
if (time.empty())
SC_REPORT_FATAL("StlPlayer", ("Malformed trace file. Timestamp could not be found (line " + to_string(lineCnt) + ").").c_str());
sc_time sendingTime = std::stoull(time.c_str()) * playerClk;
// Get the command.
iss >> command;
if (command.empty())
SC_REPORT_FATAL("StlPlayer", ("Malformed trace file. Command could not be found (line " + to_string(lineCnt) + ").").c_str());
enum tlm_command cmd;
if (command == "read") {
cmd = TLM_READ_COMMAND;
} else if (command == "write") {
cmd = TLM_WRITE_COMMAND;
} else {
SC_REPORT_FATAL("StlPlayer", (string("Corrupted tracefile, command ") + command + string(" unknown")).c_str());
}
// Get the address.
iss >> address;
if (address.empty())
SC_REPORT_FATAL("StlPlayer", ("Malformed trace file. Address could not be found (line " + to_string(lineCnt) + ").").c_str());
unsigned long long addr = std::stoull(address.c_str(), 0, 16);
// Get the data if necessary.
if (Configuration::getInstance().StoreMode != StorageMode::NoStorage) {
// The input trace file must provide the data to be stored into the memory.
iss >> dataStr;
if (dataStr.empty())
SC_REPORT_FATAL("StlPlayer", ("Malformed trace file. Data information could not be found (line " + to_string(lineCnt) + ").").c_str());
// Check if data length in the trace file is correct. We need two characters to represent 1 byte in hexadecimal.
if (dataStr.length() != (dataLength * 2))
SC_REPORT_FATAL("StlPlayer", ("Data in the trace file has an invalid length (line " + to_string(lineCnt) + ").").c_str());
// Set data
for (unsigned i = 0; i < dataLength; i++)
data[i] = (unsigned char)std::stoi(dataStr.substr(i * 2, 2).c_str(), 0, 16);
}
// Fill up the payload.
payload->set_address(addr);
payload->set_response_status(TLM_INCOMPLETE_RESPONSE);
payload->set_dmi_allowed(false);
payload->set_byte_enable_length(0);
payload->set_streaming_width(burstlength);
payload->set_data_length(dataLength);
payload->set_data_ptr(data);
payload->set_command(cmd);
// 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());
}

View File

@@ -33,12 +33,12 @@
* Janik Schlemminger
* Robert Gernhardt
* Matthias Jung
* Éder F. Zulian
*/
#ifndef STLPLAYER_H
#define STLPLAYER_H
#include "../common/xmlAddressdecoder.h"
#include "TracePlayer.h"
@@ -48,82 +48,19 @@ using namespace tlm;
struct StlPlayer: public TracePlayer
{
public:
StlPlayer(sc_module_name /*name*/, string pathToTrace, sc_time clk, TracePlayerListener *listener);
StlPlayer(sc_module_name /*name*/, string pathToTrace, sc_time playerClk, TracePlayerListener *listener);
virtual void nextPayload() override
{
std::string line;
while (line.empty() && file) {
std::getline(file, line);
// Ignore lines which begin with '#' (commented lines)
if (!line.empty() && line.at(0) == '#') {
line.clear();
}
}
if(!file) {
this->terminate();
return;
}
std::istringstream iss(line);
string time, command, address;
iss >> time >> command >> address;
unsigned long long parsedAdress = std::stoull(address.c_str(), 0, 16);
gp* payload = this->allocatePayload();
unsigned char * dataElement = new unsigned char[bytesPerColumn*burstlength];
payload->set_address(parsedAdress);
payload->set_response_status(TLM_INCOMPLETE_RESPONSE);
payload->set_dmi_allowed(false);
payload->set_byte_enable_length(0);
payload->set_streaming_width(burstlength);
this->setDataPointer(payload, dataElement, bytesPerColumn*burstlength);
if (command == "read")
{
payload->set_command(TLM_READ_COMMAND);
}
else if (command == "write")
{
payload->set_command(TLM_WRITE_COMMAND);
// Parse and set data
string data;
iss >> data;
if(!data.empty())
{
//cout << "parsing write data: " << data << std::endl;
for(int i = 0; i < 16*2; i++) // TODO column / burst breite
{
std::string byteString = "0x";
byteString.append(data.substr(2*(i+1), 2));
//cout << byteString << " " << std::stoi(byteString.c_str(), 0, 16) << endl;
dataElement[i] = std::stoi(byteString.c_str(), 0, 16);
}
}
} else {
SC_REPORT_FATAL(0, (string("Corrupted tracefile, command ") + command + string(" unknown")).c_str());
}
sc_time sendingTime = std::stoull(time.c_str())*clk;
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());
}
}
void nextPayload();
private:
ifstream file;
unsigned int lineCnt;
unsigned int burstlength;
unsigned int bytesPerColumn;
sc_time clk;
unsigned int dataLength;
sc_time playerClk; // May be different from from the memory clock!
};
#endif // STLPLAYER_H

View File

@@ -74,9 +74,9 @@ public:
payload->set_dmi_allowed(false);
payload->set_byte_enable_length(0);
payload->set_streaming_width(this->burstlenght);
this->setDataPointer(payload, dataElement, 16);
payload->set_data_ptr(dataElement);
payload->set_data_length(16);
payload->set_command(TLM_READ_COMMAND);
transCounter++;
this->payloadEventQueue.notify(*payload, BEGIN_REQ, SC_ZERO_TIME);
}

View File

@@ -32,12 +32,13 @@
* Authors:
* Robert Gernhardt
* Matthias Jung
* Éder F. Zulian
*/
#include "TracePlayer.h"
TracePlayer::TracePlayer(TracePlayerListener* listener) :
payloadEventQueue(this, &TracePlayer::peqCallback), transactionsSent(0), listener(listener)
payloadEventQueue(this, &TracePlayer::peqCallback), transactionsSent(0), listener(listener)
{
iSocket.register_nb_transport_bw(this, &TracePlayer::nb_transport_bw);
}
@@ -58,16 +59,6 @@ void TracePlayer::printDebugMessage(std::string message)
DebugManager::getInstance().printDebugMessage(this->name(), message);
}
//TODO: this doesn't depend on the tracePlayer, move it somewhere
void TracePlayer::setDataPointer(gp* payload, unsigned char * dataElement, unsigned int size)
{
//check if payload takes ownership
payload->set_data_length(size);
payload->set_data_ptr(dataElement);
for(unsigned i = 0; i < size; i++)
dataElement[i] = 0;
}
tlm_sync_enum TracePlayer::nb_transport_bw(tlm_generic_payload &payload, tlm_phase &phase, sc_time &bwDelay)
{
payloadEventQueue.notify(payload, phase, bwDelay);

View File

@@ -32,6 +32,7 @@
* Authors:
* Robert Gernhardt
* Matthias Jung
* Éder F. Zulian
*/
#ifndef TRACEPLAYER_H_
@@ -68,7 +69,6 @@ protected:
gp* allocatePayload();
tlm_utils::peq_with_cb_and_phase<TracePlayer> payloadEventQueue;
void terminate();
void setDataPointer(gp* p, unsigned char * data, unsigned int size);
void printDebugMessage(std::string message);
private:
@@ -86,3 +86,4 @@ private:
};
#endif /* TRACEPLAYER_H_ */