Added traceplayer that also reads data from the trace
This commit is contained in:
@@ -117,6 +117,7 @@ HEADERS += \
|
||||
src/simulation/ReorderBuffer.h \
|
||||
src/controller/core/configuration/MemSpec.h \
|
||||
src/simulation/StlPlayer.h \
|
||||
src/simulation/StlDataPlayer.h \
|
||||
src/simulation/TracePlayerListener.h \
|
||||
src/simulation/TraceGenerator.h \
|
||||
src/controller/core/powerdown/NoPowerDown.h \
|
||||
|
||||
166
DRAMSys/dramSys/src/simulation/StlDataPlayer.h
Normal file
166
DRAMSys/dramSys/src/simulation/StlDataPlayer.h
Normal file
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
template<unsigned int BUSWIDTH = 128>
|
||||
struct StlDataPlayer: public TracePlayer<BUSWIDTH>
|
||||
{
|
||||
public:
|
||||
StlDataPlayer(sc_module_name /*name*/, string pathToTrace, unsigned int clkMhz,
|
||||
TracePlayerListener* listener);
|
||||
virtual void nextPayload() override
|
||||
{
|
||||
string line;
|
||||
while(line.empty() && file)
|
||||
{
|
||||
std::getline(file, line);
|
||||
}
|
||||
|
||||
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(int 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;
|
||||
};
|
||||
|
||||
|
||||
template<unsigned int BUSWIDTH>
|
||||
StlDataPlayer<BUSWIDTH>::StlDataPlayer(sc_module_name /*name*/, string pathToTrace, unsigned int clkMhz,
|
||||
TracePlayerListener* listener) :
|
||||
TracePlayer<BUSWIDTH>(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->burstlength = Configuration::getInstance().memSpec.BurstLength;
|
||||
this->bytesPerColumn = xmlAddressDecoder::getInstance().amount["bytes"];
|
||||
}
|
||||
|
||||
#endif // STLDATAPLAYER_H
|
||||
Reference in New Issue
Block a user