merged conflicts
This commit is contained in:
3
dram/.gitignore
vendored
3
dram/.gitignore
vendored
@@ -2,4 +2,5 @@
|
||||
*.tdb
|
||||
*.tdb-journal
|
||||
*.out
|
||||
*.txt
|
||||
*.txt
|
||||
/release-simulation
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
eclipse.preferences.version=1
|
||||
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/CPATH/delimiter=\:
|
||||
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/CPATH/operation=remove
|
||||
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/CPLUS_INCLUDE_PATH/delimiter=\:
|
||||
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/CPLUS_INCLUDE_PATH/operation=remove
|
||||
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/C_INCLUDE_PATH/delimiter=\:
|
||||
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/C_INCLUDE_PATH/operation=remove
|
||||
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/append=true
|
||||
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/appendContributed=true
|
||||
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443/CPATH/delimiter=\:
|
||||
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443/CPATH/operation=remove
|
||||
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443/CPLUS_INCLUDE_PATH/delimiter=\:
|
||||
@@ -7,6 +15,10 @@ environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647
|
||||
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443/C_INCLUDE_PATH/operation=remove
|
||||
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443/append=true
|
||||
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443/appendContributed=true
|
||||
environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/LIBRARY_PATH/delimiter=\:
|
||||
environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/LIBRARY_PATH/operation=remove
|
||||
environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/append=true
|
||||
environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/appendContributed=true
|
||||
environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.debug.513647443/LIBRARY_PATH/delimiter=\:
|
||||
environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.debug.513647443/LIBRARY_PATH/operation=remove
|
||||
environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.debug.513647443/append=true
|
||||
|
||||
@@ -8,4 +8,4 @@
|
||||
<parameter id="scheduler" type="string" value="FR_FCFS" />
|
||||
<parameter id="capsize" type="uint" value="5" />
|
||||
</memconfig>
|
||||
</memspec>
|
||||
</memspec>
|
||||
14
dram/resources/simulations/first.xml
Normal file
14
dram/resources/simulations/first.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<simulation>
|
||||
<memspec>MICRON_4Gb_DDR4-1866_8bit_A.xml</memspec>
|
||||
<memconfigs>
|
||||
<memconfig>memconfig.xml</memconfig>
|
||||
<!-- <memconfig>fifo.xml</memconfig>
|
||||
<memconfig>fr_fcfs_unaware.xml</memconfig>-->
|
||||
</memconfigs>
|
||||
<trace-setups>
|
||||
<trace-setup>
|
||||
<device >chstone-mips_32.stl</device>
|
||||
<device >empty.stl</device>
|
||||
</trace-setup>
|
||||
</trace-setups>
|
||||
</simulation>
|
||||
@@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
#include "DebugManager.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void DebugManager::printDebugMessage(string sender, string message)
|
||||
|
||||
@@ -255,5 +255,6 @@ void TlmRecorder::closeConnection()
|
||||
printDebugMessage("tlmPhaseRecorder:\tEnd Recording");
|
||||
sqlite3_close(db);
|
||||
db = NULL;
|
||||
std::cout<<"connection closed"<<endl;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ public:
|
||||
}
|
||||
|
||||
void recordPhase(tlm::tlm_generic_payload &trans, tlm::tlm_phase phase, sc_time time);
|
||||
void recordPhase(tlm::tlm_generic_payload &trans, std::string name, sc_time begin, sc_time end);
|
||||
void recordDebugMessage(std::string message, sc_time time);
|
||||
void updateDataStrobe(const sc_time& begin, const sc_time& end, tlm::tlm_generic_payload& trans);
|
||||
void closeConnection();
|
||||
|
||||
@@ -116,6 +116,7 @@ void loadXML(string uri, XMLDocument& doc)
|
||||
|
||||
if (error)
|
||||
{
|
||||
//TODO specify error
|
||||
reportFatal("Configuration", "Error loading xml from: " + uri);
|
||||
}
|
||||
}
|
||||
@@ -152,3 +153,22 @@ void setUpDummy(tlm::tlm_generic_payload& payload, Bank& bank)
|
||||
payload.set_streaming_width(0);
|
||||
payload.set_extension(new DramExtension(Thread(0), bank, bank.getBankGroup(), Row(0), Column(0))); //payload takes ownership
|
||||
}
|
||||
|
||||
std::string getFileName(std::string uri)
|
||||
{
|
||||
// Remove directory if present.
|
||||
// Do this before extension removal incase directory has a period character.
|
||||
const size_t last_slash_idx = uri.find_last_of("\\/");
|
||||
if (std::string::npos != last_slash_idx)
|
||||
{
|
||||
uri.erase(0, last_slash_idx + 1);
|
||||
}
|
||||
|
||||
// Remove extension if present.
|
||||
const size_t period_idx = uri.rfind('.');
|
||||
if (std::string::npos != period_idx)
|
||||
{
|
||||
uri.erase(period_idx);
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <tlm.h>
|
||||
#include "dramExtension.h"
|
||||
#include "third_party/tinyxml2.h"
|
||||
#include <iomanip>
|
||||
|
||||
template<typename Key, typename Val>
|
||||
Val getElementFromMap(std::map<Key, Val>& m, Key key)
|
||||
@@ -38,6 +39,18 @@ bool isIn(const T& value, const std::vector<T>& collection)
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline void loadbar(unsigned int x, unsigned int n, unsigned int w = 50, unsigned int granularity=1)
|
||||
{
|
||||
if ( (x != n) && (x % (n/100*granularity) != 0) ) return;
|
||||
|
||||
float ratio = x/(float)n;
|
||||
unsigned int c = (ratio * w);
|
||||
std::cout << std::setw(3) << round(ratio*100) << "% [";
|
||||
for (unsigned int x=0; x<c; x++) std::cout << "=";
|
||||
for (unsigned int x=c; x<w; x++) std::cout << " ";
|
||||
std::cout << "]\r" << std::flush;
|
||||
}
|
||||
|
||||
void reportFatal(std::string sender, std::string message);
|
||||
std::string phaseNameToString(tlm::tlm_phase phase);
|
||||
bool parameterExists(tinyxml2::XMLElement* node, std::string name);
|
||||
@@ -51,4 +64,6 @@ double queryDoubleParameter(tinyxml2::XMLElement* node, std::string name);
|
||||
|
||||
void setUpDummy(tlm::tlm_generic_payload& payload, Bank& bank);
|
||||
|
||||
std::string getFileName(std::string uri);
|
||||
|
||||
#endif /* UTILS_COMMON_H_ */
|
||||
|
||||
@@ -208,7 +208,6 @@ private:
|
||||
DebugManager& debugManager;
|
||||
|
||||
// --- FRONTEND INTERACTION ------
|
||||
|
||||
tlm_sync_enum nb_transport_fw(tlm_generic_payload& payload, tlm_phase& phase, sc_time& fwDelay)
|
||||
{
|
||||
TlmRecorder::getInstance().recordPhase(payload, phase, sc_time_stamp());
|
||||
@@ -330,7 +329,6 @@ private:
|
||||
}
|
||||
|
||||
// --- DRAM INTERACTION ------
|
||||
|
||||
tlm_sync_enum nb_transport_bw(tlm_generic_payload& payload, tlm_phase& phase, sc_time& bwDelay)
|
||||
{
|
||||
dramPEQ.notify(payload, phase, bwDelay);
|
||||
@@ -343,9 +341,22 @@ private:
|
||||
Bank bank = DramExtension::getExtension(payload).getBank();
|
||||
printDebugMessage("Received " + phaseNameToString(phase) + " from DRAM");
|
||||
|
||||
if (phase == END_RD || phase == END_WR || phase == END_RDA || phase == END_WRA)
|
||||
|
||||
if (phase == BEGIN_RD || phase == BEGIN_WR)
|
||||
{
|
||||
scheduleNextPayload(bank);
|
||||
sendToDram(payload, phase, SC_ZERO_TIME);
|
||||
}
|
||||
else if (phase == END_RD || phase == END_WR)
|
||||
{
|
||||
TlmRecorder::getInstance().recordPhase(payload, BEGIN_RESP, sc_time_stamp());
|
||||
TlmRecorder::getInstance().recordPhase(payload, END_RESP, sc_time_stamp());
|
||||
sendToFrontend(payload, BEGIN_RESP, SC_ZERO_TIME);
|
||||
}
|
||||
else if (phase == END_RDA || phase == END_WRA)
|
||||
{
|
||||
TlmRecorder::getInstance().recordPhase(payload, BEGIN_RESP, sc_time_stamp());
|
||||
TlmRecorder::getInstance().recordPhase(payload, END_RESP, sc_time_stamp());
|
||||
sendToFrontend(payload, BEGIN_RESP, SC_ZERO_TIME);
|
||||
scheduleNextPayload(bank);
|
||||
}
|
||||
@@ -368,7 +379,6 @@ private:
|
||||
|
||||
void sendToDram(tlm_generic_payload& payload, const tlm_phase& phase, const sc_time& delay)
|
||||
{
|
||||
DramExtension::getExtension(payload);
|
||||
tlm_phase TPhase = phase;
|
||||
sc_time TDelay = delay;
|
||||
iSocket->nb_transport_fw(payload, TPhase, TDelay);
|
||||
|
||||
17
dram/src/simulation/ISimulation.h
Normal file
17
dram/src/simulation/ISimulation.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef ISIMULATION_H_
|
||||
#define ISIMULATION_H_
|
||||
|
||||
|
||||
namespace simulation {
|
||||
|
||||
class ISimulation
|
||||
{
|
||||
public:
|
||||
virtual ~ISimulation(){}
|
||||
virtual void transactionFinished() = 0;
|
||||
};
|
||||
|
||||
} // namespace simulation
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,17 +0,0 @@
|
||||
#ifndef ISIMULATIONMANAGER_H_
|
||||
#define ISIMULATIONMANAGER_H_
|
||||
|
||||
|
||||
namespace simulation {
|
||||
|
||||
class ISimulationManager
|
||||
{
|
||||
public:
|
||||
virtual ~ISimulationManager(){}
|
||||
virtual void tracePlayerFinishedCallback(string name) = 0;
|
||||
};
|
||||
|
||||
} // namespace simulation
|
||||
|
||||
|
||||
#endif
|
||||
128
dram/src/simulation/Simulation.cpp
Normal file
128
dram/src/simulation/Simulation.cpp
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* SimulationManager.cpp
|
||||
*
|
||||
* Created on: Apr 4, 2014
|
||||
* Author: jonny
|
||||
*/
|
||||
|
||||
#include "Simulation.h"
|
||||
#include "../common/TlmRecorder.h"
|
||||
#include "../common/DebugManager.h"
|
||||
#include "../common/xmlAddressdecoder.h"
|
||||
#include "../core/ControllerCore.h"
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include "../common/Utils.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace simulation {
|
||||
|
||||
Simulation::Simulation(string name, string pathToResources, string traceName, DramSetup setup,
|
||||
std::vector<Device> devices, bool silent) :
|
||||
traceName(traceName), senderName(name)
|
||||
|
||||
{
|
||||
xmlAddressDecoder::addressConfigURI = pathToResources + string("configs/addressConfig.xml");
|
||||
TlmRecorder::dbName = traceName;
|
||||
TlmRecorder::sqlScriptURI = pathToResources + string("scripts/createTraceDB.sql");
|
||||
Configuration::memconfigUri = pathToResources + string("configs/memconfigs/") + setup.memconfig;
|
||||
Configuration::memspecUri = pathToResources + string("configs/memspecs/") + setup.memspec;
|
||||
|
||||
//setup dram
|
||||
dram = new Dram<>("dram");
|
||||
arbiter = new Arbiter<numberOfTracePlayers, 128>("arbiter");
|
||||
controller = new Controller<>("controller");
|
||||
|
||||
player1 = new TracePlayer<>("player1", pathToResources + string("traces/") + devices[0].trace, devices[0].burstLength, this);
|
||||
player2 = new TracePlayer<>("player2", pathToResources + string("traces/") + devices[1].trace, devices[1].burstLength, this);
|
||||
|
||||
|
||||
player1->iSocket.bind(arbiter->tSockets[0]);
|
||||
player2->iSocket.bind(arbiter->tSockets[1]);
|
||||
arbiter->iSocket.bind(controller->tSocket);
|
||||
controller->iSocket.bind(dram->tSocket);
|
||||
|
||||
vector<string> whiteList;
|
||||
if (!silent)
|
||||
{
|
||||
whiteList.push_back(controller->name());
|
||||
whiteList.push_back(player2->name());
|
||||
whiteList.push_back(player1->name());
|
||||
whiteList.push_back(this->senderName);
|
||||
whiteList.push_back(TlmRecorder::senderName);
|
||||
whiteList.push_back(ControllerCore::senderName);
|
||||
whiteList.push_back(PowerDownManagerBankwise::senderName);
|
||||
}
|
||||
|
||||
auto& dbg = DebugManager::getInstance();
|
||||
dbg.addToWhiteList(whiteList);
|
||||
dbg.setDebugFile(traceName + ".txt");
|
||||
if (silent)
|
||||
{
|
||||
dbg.writeToConsole = false;
|
||||
dbg.writeToFile = false;
|
||||
}
|
||||
|
||||
totalTransactions = getNumberOfLines(pathToResources + string("traces/") + devices[0].trace);
|
||||
totalTransactions += getNumberOfLines(pathToResources + string("traces/") + devices[1].trace);
|
||||
cout << "Total transactions: " << totalTransactions << endl;
|
||||
remainingTransactions = totalTransactions;
|
||||
|
||||
}
|
||||
|
||||
Simulation::~Simulation()
|
||||
{
|
||||
delete dram;
|
||||
delete arbiter;
|
||||
delete controller;
|
||||
delete player1;
|
||||
delete player2;
|
||||
}
|
||||
|
||||
void Simulation::start()
|
||||
{
|
||||
cout << "Starting simulation:" << endl;
|
||||
simulationStartTime = clock();
|
||||
DebugManager::getInstance().printDebugMessage(senderName, "Starting simulation");
|
||||
player1->start();
|
||||
player2->start();
|
||||
sc_set_stop_mode(SC_STOP_FINISH_DELTA);
|
||||
sc_start();
|
||||
}
|
||||
|
||||
void inline Simulation::transactionFinished()
|
||||
{
|
||||
remainingTransactions--;
|
||||
loadbar(totalTransactions - remainingTransactions, totalTransactions);
|
||||
if(remainingTransactions == 0)
|
||||
{
|
||||
stop();
|
||||
}
|
||||
}
|
||||
void Simulation::stop()
|
||||
{
|
||||
controller->terminateSimulation();
|
||||
DebugManager::getInstance().printDebugMessage(senderName, "Terminating simulation");
|
||||
TlmRecorder::getInstance().closeConnection();
|
||||
sc_stop();
|
||||
|
||||
double elapsed_secs = double(clock() - simulationStartTime) / CLOCKS_PER_SEC;
|
||||
DebugManager::getInstance().printDebugMessage(senderName, "Simulation took " + to_string(elapsed_secs) + " seconds");
|
||||
cout << "\nSimulation took: " << (elapsed_secs) << endl;
|
||||
|
||||
}
|
||||
|
||||
unsigned int Simulation::getNumberOfLines(string uri)
|
||||
{
|
||||
std::ifstream file(uri);
|
||||
file.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 lineCount = std::count(std::istream_iterator<char>(file), std::istream_iterator<char>(), '\n');
|
||||
return lineCount;
|
||||
}
|
||||
|
||||
} /* namespace simulation */
|
||||
|
||||
70
dram/src/simulation/Simulation.h
Normal file
70
dram/src/simulation/Simulation.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Simulation.h
|
||||
*
|
||||
* Created on: Apr 4, 2014
|
||||
* Author: jonny
|
||||
*/
|
||||
|
||||
#ifndef SIMULATION_H_
|
||||
#define SIMULATION_H_
|
||||
|
||||
#include "Dram.h"
|
||||
#include "Arbiter.h"
|
||||
#include "TracePlayer.h"
|
||||
#include "Controller.h"
|
||||
#include "ISimulation.h"
|
||||
#include <string>
|
||||
#include <systemc.h>
|
||||
|
||||
namespace simulation {
|
||||
|
||||
struct DramSetup
|
||||
{
|
||||
DramSetup():memconfig(""),memspec(""){}
|
||||
DramSetup(std::string memconfig, std::string memspec) : memconfig(memconfig), memspec(memspec) {}
|
||||
std::string memconfig;
|
||||
std::string memspec;
|
||||
};
|
||||
|
||||
struct Device
|
||||
{
|
||||
Device():trace("empty.stl"), burstLength(0){}
|
||||
Device(std::string trace, unsigned int burstLength = 8) : trace(trace), burstLength(burstLength)
|
||||
{
|
||||
}
|
||||
std::string trace;
|
||||
unsigned int burstLength;
|
||||
};
|
||||
|
||||
class Simulation: public ISimulation
|
||||
{
|
||||
public:
|
||||
Simulation(string name, string pathToResources, string traceName, DramSetup setup,
|
||||
std::vector<Device> devices, bool silent = false);
|
||||
~Simulation();
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
void inline transactionFinished() override;
|
||||
|
||||
private:
|
||||
constexpr static unsigned int numberOfTracePlayers = 2;
|
||||
std::string traceName;
|
||||
std::string senderName;
|
||||
Dram<> *dram;
|
||||
Arbiter<numberOfTracePlayers, 128> *arbiter;
|
||||
Controller<> *controller;
|
||||
|
||||
TracePlayer<> *player1;
|
||||
TracePlayer<> *player2;
|
||||
|
||||
unsigned int totalTransactions;
|
||||
unsigned int remainingTransactions;
|
||||
clock_t simulationStartTime;
|
||||
unsigned int getNumberOfLines(string uri);
|
||||
};
|
||||
|
||||
} /* namespace simulation */
|
||||
|
||||
#endif /* SIMULATIONMANAGER_H_ */
|
||||
@@ -1,128 +1,123 @@
|
||||
/*
|
||||
* SimulationManager.cpp
|
||||
*
|
||||
* Created on: Apr 4, 2014
|
||||
* Created on: Apr 12, 2014
|
||||
* Author: jonny
|
||||
*/
|
||||
|
||||
#include "SimulationManager.h"
|
||||
#include "../common/TlmRecorder.h"
|
||||
#include "../common/DebugManager.h"
|
||||
#include "../common/xmlAddressdecoder.h"
|
||||
#include "../core/ControllerCore.h"
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <sys/wait.h>
|
||||
#include "../common/Utils.h"
|
||||
using namespace std;
|
||||
using namespace tinyxml2;
|
||||
using namespace simulation;
|
||||
|
||||
namespace simulation {
|
||||
|
||||
Simulation::Simulation(sc_module_name name, string pathToResources, string traceName,
|
||||
DramSetup setup, std::vector<Device> devices, bool silent) :
|
||||
traceName(traceName)
|
||||
|
||||
SimulationManager::SimulationManager(string resources) :
|
||||
resources(resources)
|
||||
{
|
||||
SC_THREAD(terminationThread);
|
||||
}
|
||||
|
||||
xmlAddressDecoder::addressConfigURI = pathToResources + string("configs/addressConfig.xml");
|
||||
TlmRecorder::dbName = traceName;
|
||||
TlmRecorder::sqlScriptURI = pathToResources + string("scripts/createTraceDB.sql");
|
||||
Configuration::memconfigUri = pathToResources + string("configs/memconfigs/") + setup.memconfig;
|
||||
Configuration::memspecUri = pathToResources + string("configs/memspecs/") + setup.memspec;
|
||||
SimulationManager::~SimulationManager()
|
||||
{
|
||||
}
|
||||
|
||||
//setup dram
|
||||
dram = new Dram<>("dram");
|
||||
arbiter = new Arbiter<numberOfTracePlayers, 128>("arbiter");
|
||||
controller = new Controller<>("controller");
|
||||
void SimulationManager::loadSimulationFromXML(string uri)
|
||||
{
|
||||
simulationName = getFileName(uri);
|
||||
|
||||
//setup devices
|
||||
for (auto& d : devices)
|
||||
XMLDocument doc;
|
||||
loadXML(uri, doc);
|
||||
|
||||
XMLElement* simulation = doc.FirstChildElement("simulation");
|
||||
|
||||
string memspecUri = simulation->FirstChildElement("memspec")->GetText();
|
||||
|
||||
for (XMLElement* element = simulation->FirstChildElement("memconfigs")->FirstChildElement("memconfig"); element != NULL;
|
||||
element = element->NextSiblingElement("memconfig"))
|
||||
{
|
||||
if (d.burstLength == 0)
|
||||
d.burstLength = Configuration::getInstance().BurstLength;
|
||||
dramSetups.push_back(DramSetup(element->GetText(), memspecUri));
|
||||
}
|
||||
|
||||
player1 = new TracePlayer<>("player1", pathToResources + string("traces/") + devices[0].trace,
|
||||
devices[0].burstLength, this);
|
||||
player2 = new TracePlayer<>("player2", pathToResources + string("traces/") + devices[1].trace,
|
||||
devices[1].burstLength, this);
|
||||
|
||||
player1->iSocket.bind(arbiter->tSockets[0]);
|
||||
player2->iSocket.bind(arbiter->tSockets[1]);
|
||||
arbiter->iSocket.bind(controller->tSocket);
|
||||
controller->iSocket.bind(dram->tSocket);
|
||||
|
||||
vector<string> whiteList;
|
||||
if (!silent)
|
||||
for (XMLElement* element = simulation->FirstChildElement("trace-setups")->FirstChildElement("trace-setup"); element != NULL;
|
||||
element = element->NextSiblingElement("trace-setup"))
|
||||
{
|
||||
whiteList.push_back(controller->name());
|
||||
whiteList.push_back(dram->name());
|
||||
whiteList.push_back(player2->name());
|
||||
whiteList.push_back(player1->name());
|
||||
whiteList.push_back(this->name());
|
||||
whiteList.push_back(TlmRecorder::senderName);
|
||||
whiteList.push_back(ControllerCore::senderName);
|
||||
whiteList.push_back(PowerDownManagerBankwise::senderName);
|
||||
addTraceSetup(element);
|
||||
}
|
||||
|
||||
auto& dbg = DebugManager::getInstance();
|
||||
dbg.addToWhiteList(whiteList);
|
||||
dbg.setDebugFile(traceName + ".txt");
|
||||
if (silent)
|
||||
checkPaths();
|
||||
}
|
||||
|
||||
void SimulationManager::runSimulations()
|
||||
{
|
||||
system(string("mkdir " + simulationName).c_str());
|
||||
printSimulationBatch();
|
||||
int i = 0;
|
||||
for (auto dramSetup : dramSetups)
|
||||
{
|
||||
dbg.writeToConsole = false;
|
||||
dbg.writeToFile = false;
|
||||
for (auto traceSetup : traceSetups)
|
||||
{
|
||||
i++;
|
||||
runSimulation(simulationName+"/tpr" + to_string(i) + ".tdb", dramSetup, traceSetup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Simulation::~Simulation()
|
||||
void SimulationManager::checkPaths()
|
||||
{
|
||||
delete dram;
|
||||
delete arbiter;
|
||||
delete controller;
|
||||
delete player1;
|
||||
delete player2;
|
||||
//reportFatal("Simulation Manager", "Not all paths in xml are valid");
|
||||
}
|
||||
|
||||
void Simulation::startSimulation()
|
||||
void SimulationManager::runSimulation(string traceName, DramSetup dramSetup, vector<Device> traceSetup)
|
||||
{
|
||||
|
||||
clock_t begin = clock();
|
||||
|
||||
cout<<"Starting simulation"<<endl;
|
||||
DebugManager::getInstance().printDebugMessage(name(), "Starting simulation");
|
||||
player1->start();
|
||||
player2->start();
|
||||
sc_start();
|
||||
|
||||
clock_t end = clock();
|
||||
double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
|
||||
DebugManager::getInstance().printDebugMessage(name(),
|
||||
"Simulation took " + to_string(elapsed_secs) + " seconds");
|
||||
cout<<"took "<<(elapsed_secs)<<endl;
|
||||
}
|
||||
|
||||
void Simulation::tracePlayerFinishedCallback(string name)
|
||||
{
|
||||
|
||||
DebugManager::getInstance().printDebugMessage(this->name(), "Traceplayer " + name + " finshed");
|
||||
static int finishedPlayers = 0;
|
||||
finishedPlayers++;
|
||||
if (finishedPlayers == numberOfTracePlayers)
|
||||
int pid = fork();
|
||||
int status = 0;
|
||||
if (pid == 0)
|
||||
{
|
||||
terminateSimulation.notify();
|
||||
Simulation* simulation = new Simulation("sim", resources, traceName, dramSetup, traceSetup);
|
||||
simulation->start();
|
||||
delete simulation;
|
||||
_Exit(0);
|
||||
}
|
||||
|
||||
waitpid(pid, &status, 0);
|
||||
}
|
||||
|
||||
void SimulationManager::printSimulationBatch()
|
||||
{
|
||||
cout << "Simulation Batch:\n##################" << endl;
|
||||
for (DramSetup& s : dramSetups)
|
||||
{
|
||||
cout << s.memspec << " - " << s.memconfig << endl;
|
||||
}
|
||||
cout << endl;
|
||||
for (vector<Device>& s : traceSetups)
|
||||
{
|
||||
cout << "Simulation:\n";
|
||||
for (Device d : s)
|
||||
cout << "\t(" << d.burstLength << ") " << d.trace << ";" << endl;
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Simulation::terminationThread()
|
||||
void SimulationManager::startTraceAnalyzer()
|
||||
{
|
||||
wait(terminateSimulation);
|
||||
DebugManager::getInstance().printDebugMessage(this->name(), "Terminating simulation");
|
||||
controller->terminateSimulation();
|
||||
//waits for the termination of all pending powerdown phases in the dram system
|
||||
wait(sc_time(50, SC_NS));
|
||||
TlmRecorder::getInstance().closeConnection();
|
||||
sc_stop();
|
||||
string p = getenv("trace");
|
||||
string run_tpr = p + " -f " + simulationName;
|
||||
system(run_tpr.c_str());
|
||||
}
|
||||
|
||||
} /* namespace simulation */
|
||||
void SimulationManager::addTraceSetup(tinyxml2::XMLElement* element)
|
||||
{
|
||||
vector<Device> devices;
|
||||
for (XMLElement* device = element->FirstChildElement("device"); device != NULL; device = device->NextSiblingElement("device"))
|
||||
{
|
||||
devices.push_back(Device(device->GetText(), device->IntAttribute("bl")));
|
||||
}
|
||||
traceSetups.push_back(devices);
|
||||
}
|
||||
|
||||
}
|
||||
/* namespace simulation */
|
||||
|
||||
|
||||
@@ -1,62 +1,41 @@
|
||||
/*
|
||||
* SimulationManager.h
|
||||
*
|
||||
* Created on: Apr 4, 2014
|
||||
* Created on: Apr 12, 2014
|
||||
* Author: jonny
|
||||
*/
|
||||
|
||||
#ifndef SIMULATIONMANAGER_H_
|
||||
#define SIMULATIONMANAGER_H_
|
||||
|
||||
#include "Dram.h"
|
||||
#include "Arbiter.h"
|
||||
#include "TracePlayer.h"
|
||||
#include "Controller.h"
|
||||
#include "ISimulationManager.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <systemc.h>
|
||||
#include "Simulation.h"
|
||||
#include "../common/third_party/tinyxml2.h"
|
||||
|
||||
namespace simulation {
|
||||
|
||||
struct DramSetup
|
||||
{
|
||||
DramSetup():memconfig(""),memspec(""){}
|
||||
DramSetup(std::string memconfig, std::string memspec) : memconfig(memconfig), memspec(memspec) {}
|
||||
std::string memconfig;
|
||||
std::string memspec;
|
||||
};
|
||||
|
||||
struct Device
|
||||
{
|
||||
Device():trace("empty.stl"), burstLength(0){}
|
||||
Device(std::string trace, unsigned int burstLength = 8) : trace(trace), burstLength(burstLength)
|
||||
{
|
||||
}
|
||||
std::string trace;
|
||||
unsigned int burstLength;
|
||||
};
|
||||
|
||||
class Simulation: public ISimulationManager, public sc_module
|
||||
class SimulationManager
|
||||
{
|
||||
public:
|
||||
SC_HAS_PROCESS(Simulation);
|
||||
Simulation(sc_module_name name, string pathToResources, string traceName, DramSetup setup,
|
||||
std::vector<Device> devices, bool silent = false);
|
||||
~Simulation();
|
||||
void startSimulation();
|
||||
void tracePlayerFinishedCallback(string name) override;
|
||||
SimulationManager(std::string resources);
|
||||
~SimulationManager();
|
||||
|
||||
void loadSimulationFromXML(std::string uri);
|
||||
void runSimulations();
|
||||
void startTraceAnalyzer();
|
||||
|
||||
private:
|
||||
void terminationThread();
|
||||
sc_event terminateSimulation;
|
||||
constexpr static unsigned int numberOfTracePlayers = 2;
|
||||
std::string traceName;
|
||||
Dram<> *dram;
|
||||
Arbiter<numberOfTracePlayers, 128> *arbiter;
|
||||
Controller<> *controller;
|
||||
std::string simulationName;
|
||||
|
||||
TracePlayer<> *player1;
|
||||
TracePlayer<> *player2;
|
||||
std::vector<simulation::DramSetup> dramSetups;
|
||||
std::vector<std::vector<Device>> traceSetups;
|
||||
std::string resources;
|
||||
|
||||
void runSimulation(std::string traceName, DramSetup dramSetup, std::vector<Device> traceSetup);
|
||||
void addTraceSetup(tinyxml2::XMLElement* element);
|
||||
void checkPaths();
|
||||
void printSimulationBatch();
|
||||
};
|
||||
|
||||
} /* namespace simulation */
|
||||
|
||||
@@ -16,9 +16,11 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "MemoryManager.h"
|
||||
#include "ISimulationManager.h"
|
||||
#include "ISimulation.h"
|
||||
#include "../core/configuration/Configuration.h"
|
||||
#include "../common/DebugManager.h"
|
||||
#include "../common/xmlAddressdecoder.h"
|
||||
#include "../common/TlmRecorder.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace tlm;
|
||||
@@ -28,26 +30,25 @@ struct TracePlayer: public sc_module
|
||||
{
|
||||
public:
|
||||
tlm_utils::simple_initiator_socket<TracePlayer, BUSWIDTH, tlm::tlm_base_protocol_types> iSocket;
|
||||
TracePlayer(sc_module_name name, string pathToTrace, unsigned int burstlength,
|
||||
simulation::ISimulationManager* simulationManager) :
|
||||
payloadEventQueue(this, &TracePlayer::peqCallback), file(pathToTrace), burstlenght(burstlength), numberOfPendingTransactions(
|
||||
TracePlayer(sc_module_name name, string pathToTrace, unsigned int burstLength,
|
||||
simulation::ISimulation* simulationManager) :
|
||||
payloadEventQueue(this, &TracePlayer::peqCallback), file(pathToTrace), burstlenght(burstLength), numberOfPendingTransactions(
|
||||
0), transactionsSent(0), transactionsReceived(0), simulationManager(
|
||||
simulationManager)
|
||||
{
|
||||
if (!file.is_open())
|
||||
SC_REPORT_FATAL(0, (string("Could not open trace ") + pathToTrace).c_str());
|
||||
|
||||
if(burstLength == 0)
|
||||
this->burstlenght = core::Configuration::getInstance().BurstLength;
|
||||
|
||||
iSocket.register_nb_transport_bw(this, &TracePlayer::nb_transport_bw);
|
||||
}
|
||||
|
||||
void start()
|
||||
{
|
||||
bool fileIsEmpty = file.peek() == std::ifstream::traits_type::eof();
|
||||
if (fileIsEmpty)
|
||||
{
|
||||
simulationManager->tracePlayerFinishedCallback(name());
|
||||
}
|
||||
else
|
||||
if (!fileIsEmpty)
|
||||
{
|
||||
scheduleNextPayload();
|
||||
}
|
||||
@@ -61,7 +62,7 @@ private:
|
||||
unsigned int numberOfPendingTransactions;
|
||||
unsigned int transactionsSent;
|
||||
unsigned int transactionsReceived;
|
||||
simulation::ISimulationManager* simulationManager;
|
||||
simulation::ISimulation* simulationManager;
|
||||
|
||||
void scheduleNextPayload()
|
||||
{
|
||||
@@ -124,34 +125,31 @@ private:
|
||||
{
|
||||
payload.acquire();
|
||||
sendToTarget(payload, phase, SC_ZERO_TIME);
|
||||
|
||||
transactionsSent++;
|
||||
DebugManager::getInstance().printDebugMessage(name(),
|
||||
"Sending transaction number: " + std::to_string(transactionsSent));
|
||||
}
|
||||
|
||||
else if (phase == END_REQ)
|
||||
{
|
||||
scheduleNextPayload();
|
||||
}
|
||||
else if (phase == BEGIN_RESP)
|
||||
{
|
||||
payload.release();
|
||||
sendToTarget(payload, END_RESP, SC_ZERO_TIME);
|
||||
payload.release();
|
||||
|
||||
simulationManager->transactionFinished();
|
||||
numberOfPendingTransactions--;
|
||||
transactionsReceived++;
|
||||
|
||||
DebugManager::getInstance().printDebugMessage(name(),
|
||||
"Pending transactions in core: "
|
||||
+ std::to_string(transactionsSent - transactionsReceived));
|
||||
|
||||
if (numberOfPendingTransactions == 0)
|
||||
simulationManager->tracePlayerFinishedCallback(name());
|
||||
}
|
||||
|
||||
else if (phase == END_RESP)
|
||||
{
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
SC_REPORT_FATAL(0, "TracePlayer PEQ was triggered with unknown phase");
|
||||
|
||||
@@ -11,10 +11,11 @@
|
||||
#include "../core/configuration/Configuration.h"
|
||||
|
||||
#include <systemc.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace simulation;
|
||||
|
||||
@@ -25,83 +26,22 @@ string pathOfFile(string file)
|
||||
return file.substr(0, file.find_last_of('/'));
|
||||
}
|
||||
|
||||
void startTraceAnalyzer(string traceName)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
string p = getenv("trace");
|
||||
string run_tpr = p + " " + traceName;
|
||||
system(run_tpr.c_str());
|
||||
return sc_main(argc, argv);
|
||||
}
|
||||
|
||||
bool runSimulation(string resources, string traceName, DramSetup setup, vector<Device> devices)
|
||||
{
|
||||
int pid = fork();
|
||||
int status = 0;
|
||||
if (pid == 0)
|
||||
{
|
||||
Simulation simulation("sim", resources, traceName, setup, devices, false);
|
||||
simulation.startSimulation();
|
||||
return true;
|
||||
}
|
||||
waitpid(pid, &status, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool batchTraces(DramSetup setup, vector<pair<string, string>> tracePairs)
|
||||
{
|
||||
int id = 0;
|
||||
for (pair<string, string> pair : tracePairs)
|
||||
{
|
||||
id++;
|
||||
string traceName = "batch" + to_string(id) + ".tdb";
|
||||
if (runSimulation(resources, traceName, setup, { Device(pair.first), Device(pair.second) }))
|
||||
return true; //kill child
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool batchSetups(pair<string, string> tracePair, vector<DramSetup> setups)
|
||||
{
|
||||
int id = 0;
|
||||
for (auto& setup : setups)
|
||||
{
|
||||
id++;
|
||||
string traceName = "batch0" + to_string(id) + ".tdb";
|
||||
if (runSimulation(resources, traceName, setup,
|
||||
{ Device(tracePair.first), Device(tracePair.second) }))
|
||||
return true; //kill child
|
||||
}
|
||||
return false;
|
||||
}
|
||||
int sc_main(int argc, char **argv)
|
||||
{
|
||||
sc_set_time_resolution(1, SC_PS);
|
||||
|
||||
resources = pathOfFile(argv[0]) + string("/../resources/");
|
||||
string simulationToRun = "first.xml";
|
||||
|
||||
resources = pathOfFile(argv[0]) + string("/../resources/");
|
||||
SimulationManager manager(resources);
|
||||
manager.loadSimulationFromXML(resources + "/simulations/" + simulationToRun);
|
||||
manager.runSimulations();
|
||||
manager.startTraceAnalyzer();
|
||||
|
||||
DramSetup setup;
|
||||
setup.memconfig = "memconfig.xml";
|
||||
setup.memspec = "MatzesWideIO.xml";
|
||||
|
||||
DramSetup setup2;
|
||||
setup2.memconfig = "memconfig.xml";
|
||||
setup2.memspec = "MICRON_4Gb_DDR4-1866_8bit_A.xml";
|
||||
|
||||
vector<pair<string, string>> tracePairs;
|
||||
tracePairs.push_back(pair<string, string>("trace.stl", "empty.stl"));
|
||||
tracePairs.push_back(pair<string, string>("trace2.stl", "empty.stl"));
|
||||
|
||||
//batchTraces(setup, tracePairs);
|
||||
//batchSetups(tracePairs[0], {setup});
|
||||
|
||||
string traceName("tpr5.tdb");
|
||||
|
||||
string trace2 = "empty.stl";
|
||||
string trace1 = "mediabench-g721encode_32.stl";
|
||||
|
||||
|
||||
if (runSimulation(resources, traceName, setup, { Device(trace1), Device(trace2) }))
|
||||
startTraceAnalyzer(traceName);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user