File cleanup.

This commit is contained in:
Lukas Steiner
2020-10-06 15:51:24 +02:00
parent d40462dcf7
commit 432d37a9d7
12 changed files with 73 additions and 133 deletions

View File

@@ -46,9 +46,8 @@ add_executable(DRAMSys
ExampleInitiator.h
MemoryManager.cpp
StlPlayer.cpp
TraceGenerator.h
TraceGenerator.cpp
TracePlayer.cpp
TracePlayerListener.h
TraceSetup.cpp
)

View File

@@ -42,14 +42,23 @@
using namespace tlm;
MemoryManager::MemoryManager()
: numberOfAllocations(0), numberOfFrees(0) {}
: numberOfAllocations(0), numberOfFrees(0)
{
if (Configuration::getInstance().storeMode == "NoStorage")
storageEnabled = false;
else
storageEnabled = true;
}
MemoryManager::~MemoryManager()
{
for (tlm_generic_payload *payload : freePayloads)
{
// Delete data buffer
delete[] payload->get_data_ptr();
if (storageEnabled)
{
// Delete data buffer
delete[] payload->get_data_ptr();
}
// Delete all extensions
payload->reset();
delete payload;
@@ -68,12 +77,15 @@ tlm_generic_payload *MemoryManager::allocate()
numberOfAllocations++;
tlm_generic_payload *payload = new tlm_generic_payload(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);
if (storageEnabled)
{
// 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);
}
payload->set_data_ptr(data);
return payload;
}
else
@@ -88,4 +100,3 @@ void MemoryManager::free(tlm_generic_payload *payload)
{
freePayloads.push_back(payload);
}

View File

@@ -52,6 +52,7 @@ private:
uint64_t numberOfAllocations;
uint64_t numberOfFrees;
std::vector<tlm::tlm_generic_payload *> freePayloads;
bool storageEnabled = false;
};
#endif // MEMORYMANAGER_H

View File

@@ -39,12 +39,14 @@
#include "StlPlayer.h"
using namespace tlm;
StlPlayer::StlPlayer(sc_module_name name,
std::string pathToTrace,
sc_time playerClk,
TracePlayerListener *listener,
TraceSetup *setup,
bool relative)
: TracePlayer(name, listener), file(pathToTrace),
: TracePlayer(name, setup), file(pathToTrace),
currentBuffer(&lineContents[0]),
parseBuffer(&lineContents[1]),
relative(relative)
@@ -86,12 +88,12 @@ void StlPlayer::nextPayload()
numberOfTransactions++;
// Allocate a generic payload for this request.
tlm::tlm_generic_payload *payload = this->allocatePayload();
tlm_generic_payload *payload = setup->allocatePayload();
payload->acquire();
// Fill up the payload.
payload->set_address(lineIterator->addr);
payload->set_response_status(tlm::TLM_INCOMPLETE_RESPONSE);
payload->set_response_status(TLM_INCOMPLETE_RESPONSE);
payload->set_dmi_allowed(false);
payload->set_byte_enable_length(0);
payload->set_streaming_width(burstlength);
@@ -103,9 +105,9 @@ void StlPlayer::nextPayload()
{
// Send the transaction directly or schedule it to be sent in the future.
if (lineIterator->sendingTime <= sc_time_stamp())
this->payloadEventQueue.notify(*payload, tlm::BEGIN_REQ, SC_ZERO_TIME);
payloadEventQueue.notify(*payload, tlm::BEGIN_REQ, SC_ZERO_TIME);
else
this->payloadEventQueue.notify(*payload, tlm::BEGIN_REQ,
payloadEventQueue.notify(*payload, tlm::BEGIN_REQ,
lineIterator->sendingTime - sc_time_stamp());
}
else

View File

@@ -44,6 +44,7 @@
#include <vector>
#include <array>
#include <thread>
#include "TraceSetup.h"
#include "TracePlayer.h"
struct LineContent
@@ -60,7 +61,7 @@ public:
StlPlayer(sc_module_name name,
std::string pathToTrace,
sc_time playerClk,
TracePlayerListener *listener,
TraceSetup *setup,
bool relative);
virtual ~StlPlayer() override;

View File

@@ -39,43 +39,13 @@
#define TRACEGENERATOR_H
#include "TracePlayer.h"
#include "TraceSetup.h"
struct TraceGenerator : public TracePlayer
class TraceGenerator : public TracePlayer
{
public:
TraceGenerator(sc_module_name name, unsigned int fCKMhz, TracePlayerListener *listener)
: TracePlayer(name, listener), transCounter(0)
{
if (fCKMhz == 0)
tCK = Configuration::getInstance().memSpec->tCK;
else
tCK = sc_time(1.0 / fCKMhz, SC_US);
this->burstlenght = Configuration::getInstance().memSpec->burstLength;
}
virtual void nextPayload() override
{
if (transCounter >= 1000) { // TODO set limit!
this->terminate();
}
tlm::tlm_generic_payload *payload = this->allocatePayload();
payload->acquire();
unsigned char *dataElement = new unsigned
char[16]; // TODO: column / burst breite
payload->set_address(0x0);
payload->set_response_status(tlm::TLM_INCOMPLETE_RESPONSE);
payload->set_dmi_allowed(false);
payload->set_byte_enable_length(0);
payload->set_streaming_width(this->burstlenght);
payload->set_data_ptr(dataElement);
payload->set_data_length(16);
payload->set_command(tlm::TLM_READ_COMMAND);
transCounter++;
this->payloadEventQueue.notify(*payload, tlm::BEGIN_REQ, SC_ZERO_TIME);
}
TraceGenerator(sc_module_name name, unsigned int fCKMhz, TraceSetup *setup);
virtual void nextPayload() override;
private:
unsigned int burstlenght;

View File

@@ -37,13 +37,14 @@
*/
#include "TracePlayer.h"
#include "TraceSetup.h"
using namespace tlm;
TracePlayer::TracePlayer(sc_module_name name, TracePlayerListener *listener) :
TracePlayer::TracePlayer(sc_module_name name, TraceSetup *setup) :
sc_module(name),
payloadEventQueue(this, &TracePlayer::peqCallback),
listener(listener)
setup(setup)
{
iSocket.register_nb_transport_bw(this, &TracePlayer::nb_transport_bw);
@@ -53,11 +54,6 @@ TracePlayer::TracePlayer(sc_module_name name, TracePlayerListener *listener) :
storageEnabled = true;
}
tlm_generic_payload *TracePlayer::allocatePayload()
{
return memoryManager.allocate();
}
void TracePlayer::finish()
{
finished = true;
@@ -66,7 +62,7 @@ void TracePlayer::finish()
void TracePlayer::terminate()
{
cout << sc_time_stamp() << " " << this->name() << " terminated " << std::endl;
listener->tracePlayerTerminates();
setup->tracePlayerTerminates();
}
tlm_sync_enum TracePlayer::nb_transport_bw(tlm_generic_payload &payload,
@@ -94,7 +90,7 @@ void TracePlayer::peqCallback(tlm_generic_payload &payload,
payload.release();
sendToTarget(payload, END_RESP, SC_ZERO_TIME);
if (Configuration::getInstance().simulationProgressBar)
listener->transactionFinished();
setup->transactionFinished();
transactionsReceived++;

View File

@@ -46,26 +46,25 @@
#include <tlm_utils/peq_with_cb_and_phase.h>
#include <iostream>
#include <string>
#include "MemoryManager.h"
#include "configuration/Configuration.h"
#include "common/DebugManager.h"
#include "TracePlayerListener.h"
#include "TraceSetup.h"
struct TracePlayer : public sc_module
class TracePlayer : public sc_module
{
public:
tlm_utils::simple_initiator_socket<TracePlayer> iSocket;
TracePlayer(sc_module_name name, TracePlayerListener *listener);
TracePlayer(sc_module_name name, TraceSetup *setup);
virtual void nextPayload() = 0;
unsigned int getNumberOfLines(std::string pathToTrace);
protected:
tlm::tlm_generic_payload *allocatePayload();
tlm_utils::peq_with_cb_and_phase<TracePlayer> payloadEventQueue;
void finish();
void terminate();
unsigned int numberOfTransactions = 0;
bool storageEnabled = false;
TraceSetup *setup;
private:
tlm::tlm_sync_enum nb_transport_bw(tlm::tlm_generic_payload &payload, tlm::tlm_phase &phase,
@@ -73,10 +72,8 @@ private:
void peqCallback(tlm::tlm_generic_payload &payload, const tlm::tlm_phase &phase);
void sendToTarget(tlm::tlm_generic_payload &payload, const tlm::tlm_phase &phase,
const sc_time &delay);
MemoryManager memoryManager;
unsigned int transactionsSent = 0;
unsigned int transactionsReceived = 0;
TracePlayerListener *listener;
bool finished = false;
};

View File

@@ -1,49 +0,0 @@
/*
* Copyright (c) 2015, Technische Universität 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 TRACEPLAYERLISTENER_H
#define TRACEPLAYERLISTENER_H
class TracePlayerListener
{
public:
virtual void tracePlayerTerminates() = 0;
virtual void transactionFinished() = 0;
virtual ~TracePlayerListener() {}
};
#endif // TRACEPLAYERLISTENER_H

View File

@@ -35,10 +35,13 @@
*/
#include "TraceSetup.h"
#include "StlPlayer.h"
using namespace tlm;
TraceSetup::TraceSetup(std::string uri,
std::string pathToResources,
std::vector<TracePlayer *> *devices)
std::vector<TracePlayer *> *players)
{
// Load Simulation:
nlohmann::json simulationdoc = parseJSON(uri);
@@ -85,7 +88,7 @@ TraceSetup::TraceSetup(std::string uri,
else
throw std::runtime_error("Unsupported file extension in " + name);
devices->push_back(player);
players->push_back(player);
if (Configuration::getInstance().simulationProgressBar)
totalTransactions += player->getNumberOfLines(stlFile);
@@ -93,7 +96,7 @@ TraceSetup::TraceSetup(std::string uri,
}
remainingTransactions = totalTransactions;
numberOfTracePlayers = devices->size();
numberOfTracePlayers = players->size();
}
void TraceSetup::tracePlayerTerminates()
@@ -113,3 +116,8 @@ void TraceSetup::transactionFinished()
if (remainingTransactions == 0)
std::cout << std::endl;
}
tlm_generic_payload *TraceSetup::allocatePayload()
{
return memoryManager.allocate();
}

View File

@@ -38,28 +38,28 @@
#include <vector>
#include <string>
#include <tlm.h>
#include "MemoryManager.h"
#include "common/utils.h"
#include "TracePlayer.h"
#include "StlPlayer.h"
class TracePlayer;
class TraceSetup : public TracePlayerListener
class TraceSetup
{
public:
TraceSetup(std::string uri,
std::string pathToResources,
std::vector<TracePlayer *> *devices);
virtual void tracePlayerTerminates() override;
virtual void transactionFinished() override;
virtual ~TraceSetup() {}
void tracePlayerTerminates();
void transactionFinished();
tlm::tlm_generic_payload *allocatePayload();
private:
unsigned int numberOfTracePlayers;
unsigned int totalTransactions = 0;
unsigned int remainingTransactions;
unsigned int finishedTracePlayers = 0;
MemoryManager memoryManager;
};
#endif // TRACESETUP_H

View File

@@ -45,6 +45,7 @@
#include "simulation/DRAMSys.h"
#include "TraceSetup.h"
#include "TracePlayer.h"
#ifdef RECORDING
#include "simulation/DRAMSysRecordable.h"
@@ -70,21 +71,24 @@ int sc_main(int argc, char **argv)
std::string resources;
std::string simulationJson;
// Run only with default config (ddr3-example.json):
if (argc == 1) {
if (argc == 1)
{
// Get path of resources:
resources = pathOfFile(argv[0])
+ std::string("/../../DRAMSys/library/resources/");
simulationJson = resources + "simulations/ddr3-example.json";
}
// Run with specific config but default resource folders:
else if (argc == 2) {
else if (argc == 2)
{
// Get path of resources:
resources = pathOfFile(argv[0])
+ std::string("/../../DRAMSys/library/resources/");
simulationJson = argv[1];
}
// Run with spefific config and specific resource folder:
else if (argc == 3) {
else if (argc == 3)
{
simulationJson = argv[1];
resources = argv[2];
}
@@ -105,7 +109,7 @@ int sc_main(int argc, char **argv)
dramSys = new DRAMSys("DRAMSys", simulationJson, resources);
// Instantiate STL Players:
TraceSetup *ts = new TraceSetup(simulationJson, resources, &players);
TraceSetup *setup = new TraceSetup(simulationJson, resources, &players);
// Bind STL Players with DRAMSys:
for (size_t i = 0; i < players.size(); i++)
@@ -143,7 +147,7 @@ int sc_main(int argc, char **argv)
delete dramSys;
for (auto player : players)
delete player;
delete ts;
delete setup;
return 0;
}