cool simulation manager
This commit is contained in:
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 */
|
||||
|
||||
Reference in New Issue
Block a user