Merge pull request #131 from tranan/master

Separate TracePlayer from Simulation module
This commit is contained in:
fzeder
2016-10-28 18:38:59 +02:00
committed by GitHub Enterprise
8 changed files with 198 additions and 186 deletions

View File

@@ -236,6 +236,10 @@ private:
void appendDramExtension(int socketId, tlm_generic_payload& payload)
{
// Append Generation Extension
GenerationExtension* genExtension = new GenerationExtension(sc_time_stamp());
payload.set_auto_extension(genExtension);
unsigned int burstlength = payload.get_streaming_width();
DecodedAddress decodedAddress = xmlAddressDecoder::getInstance().decodeAddress(payload.get_address());
// Check the valid range of decodedAddress
@@ -274,4 +278,3 @@ private:
};
#endif /* ARBITER_H_ */

View File

@@ -114,51 +114,6 @@ void Simulation::instantiateModules(const string &traceName, const string &pathT
// The same instance will be accessed by all other modules.
TemperatureController::getInstance();
#if USE_EXAMPLE_INITIATOR
init = new ExampleInitiator("init");
if(Configuration::getInstance().CheckTLM2Protocol) {
string str = "ExampleInitiatorTLMChecker";
exampleInitiatorTlmChecker = new tlm_utils::tlm2_base_protocol_checker<>(str.c_str());
}
#else
for (size_t i = 0; i < Configuration::getInstance().NumberOfTracePlayers; i++) {
std::string playerStr = "tracePlayer" + std::to_string(i);
TracePlayer *player;
sc_time playerClk;
// 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
playerClk = FrequencyToClk(devices[i].clkMhz);
player = new StlPlayer(playerStr.c_str(), pathToResources + string("traces/") + devices[i].trace, playerClk, this);
if(Configuration::getInstance().SimulationProgressBar)
{
totalTransactions += player->getNumberOfLines(pathToResources + string("traces/") + devices[i].trace);
}
players.push_back(player);
if(Configuration::getInstance().CheckTLM2Protocol) {
string str = "TLMCheckerPlayer"+ std::to_string(i);
tlm_utils::tlm2_base_protocol_checker<> * playerTlmChecker = new tlm_utils::tlm2_base_protocol_checker<>(str.c_str());
playersTlmCheckers.push_back(playerTlmChecker);
}
}
remainingTransactions = totalTransactions;
#endif /* USE_EXAMPLE_INITIATOR */
// Create and properly initialize TLM recorders. They need to be ready before creating some modules.
setupTlmRecorders(traceName, pathToResources, devices);
@@ -187,57 +142,24 @@ void Simulation::instantiateModules(const string &traceName, const string &pathT
void Simulation::bindSockets()
{
#if USE_EXAMPLE_INITIATOR
if(Configuration::getInstance().CheckTLM2Protocol) {
init->socket.bind(exampleInitiatorTlmChecker->target_socket);
exampleInitiatorTlmChecker->initiator_socket.bind(arbiter->tSocket);
tSocket.bind(arbiter->tSocket);
if(Configuration::getInstance().CheckTLM2Protocol) {
for (size_t i = 0; i < Configuration::getInstance().NumberOfMemChannels; i++) {
arbiter->iSocket.bind(controllersTlmCheckers[i]->target_socket);
controllersTlmCheckers[i]->initiator_socket.bind(controllers[i]->tSocket);
controllers[i]->iSocket.bind(drams[i]->tSocket);
for (size_t i = 0; i < Configuration::getInstance().NumberOfMemChannels; i++) {
arbiter->iSocket.bind(controllersTlmCheckers[i]->target_socket);
controllersTlmCheckers[i]->initiator_socket.bind(controllers[i]->tSocket);
controllers[i]->iSocket.bind(drams[i]->tSocket);
}
} else {
for (size_t i = 0; i < Configuration::getInstance().NumberOfMemChannels; i++) {
arbiter->iSocket.bind(controllers[i]->tSocket);
controllers[i]->iSocket.bind(drams[i]->tSocket);
}
}
}
else {
init->socket.bind(arbiter->tSocket);
#else
if(Configuration::getInstance().CheckTLM2Protocol) {
for (size_t i = 0; i < players.size(); i++) {
players[i]->iSocket.bind(playersTlmCheckers[i]->target_socket);
playersTlmCheckers[i]->initiator_socket.bind(arbiter->tSocket);
}
for (size_t i = 0; i < Configuration::getInstance().NumberOfMemChannels; i++) {
arbiter->iSocket.bind(controllersTlmCheckers[i]->target_socket);
controllersTlmCheckers[i]->initiator_socket.bind(controllers[i]->tSocket);
controllers[i]->iSocket.bind(drams[i]->tSocket);
}
}
else {
for (auto player : players) {
player->iSocket.bind(arbiter->tSocket);
}
#endif
for (size_t i = 0; i < Configuration::getInstance().NumberOfMemChannels; i++) {
arbiter->iSocket.bind(controllers[i]->tSocket);
controllers[i]->iSocket.bind(drams[i]->tSocket);
}
}
}
Simulation::~Simulation()
{
for (auto player : players) {
delete player;
}
#if USE_EXAMPLE_INITIATOR
delete init;
delete exampleInitiatorTlmChecker;
#endif
delete arbiter;
@@ -253,40 +175,11 @@ Simulation::~Simulation()
delete rec;
}
for (auto tlmChecker : playersTlmCheckers) {
delete tlmChecker;
}
for (auto tlmChecker : controllersTlmCheckers) {
delete tlmChecker;
}
}
void Simulation::start()
{
report("\n\nStarting simulation:");
report(headline);
report(" -> setup: \t\t" + getFileName(traceName));
report(" -> memspec: \t\t" + Configuration::getInstance().memSpec.MemoryId);
cout << endl;
simulationStartTime = clock();
for (auto player : players) {
player->nextPayload();
}
sc_set_stop_mode(SC_STOP_FINISH_DELTA);
sc_start();
}
void inline Simulation::tracePlayerTerminates()
{
static unsigned int finishedTracePlayers = 0;
finishedTracePlayers++;
if (finishedTracePlayers == Configuration::getInstance().NumberOfTracePlayers)
terminateSimulation.notify();
}
void Simulation::stop()
{
@@ -316,16 +209,6 @@ void Simulation::stop()
}
void inline Simulation::transactionFinished()
{
remainingTransactions--;
loadbar(totalTransactions - remainingTransactions, totalTransactions);
if (remainingTransactions == 0)
{
cout << endl;
}
}
void Simulation::report(string message)
{
DebugManager::getInstance().printDebugMessage(this->name(), message);

View File

@@ -44,17 +44,12 @@
#include "Dram.h"
#include "Arbiter.h"
#include "TracePlayer.h"
#include "TraceGenerator.h"
#include "ReorderBuffer.h"
#include "TracePlayerListener.h"
#include "StlPlayer.h"
#include "../controller/Controller.h"
#include "../common/third_party/tinyxml2/tinyxml2.h"
#include "ExampleInitiator.h"
#include "../common/tlm2_base_protocol_checker.h"
#define USE_EXAMPLE_INITIATOR 0
struct DramSetup
{
@@ -79,36 +74,28 @@ struct Device
unsigned int burstLength;
};
class Simulation: public sc_module, public TracePlayerListener
class Simulation: public sc_module
{
public:
tlm_utils::multi_passthrough_target_socket<Simulation> tSocket;
sc_event terminateSimulation;
SC_HAS_PROCESS(Simulation);
Simulation(sc_module_name name, string pathToResources, string traceName, DramSetup setup,
std::vector<Device> devices);
~Simulation();
void start();
void stop();
virtual void tracePlayerTerminates() override;
virtual void transactionFinished() override;
private:
std::string traceName;
DramSetup dramSetup;
sc_event terminateSimulation;
// A vector of pointers to all trace player (devices which acquire the bus
// and initiate transactions targeting the memory)
std::vector<TracePlayer*> players;
//TLM 2.0 Protocol Checkers
std::vector<tlm_utils::tlm2_base_protocol_checker<>*> playersTlmCheckers;
std::vector<tlm_utils::tlm2_base_protocol_checker<>*> controllersTlmCheckers;
#if USE_EXAMPLE_INITIATOR
ExampleInitiator *init;
tlm_utils::tlm2_base_protocol_checker<>* exampleInitiatorTlmChecker;
#endif
// All transactions pass through the same arbiter
Arbiter *arbiter;
// Each DRAM unit has a controller
@@ -120,9 +107,6 @@ private:
// Transaction Recorders (one per channel). They generate the output databases.
std::vector<TlmRecorder*> tlmRecorders;
unsigned int totalTransactions = 0;
unsigned int remainingTransactions;
clock_t simulationStartTime;
void report(std::string message);
void setupTlmRecorders(const string &traceName, const string &pathToResources, const std::vector<Device> &devices);

View File

@@ -50,6 +50,17 @@ SimulationManager::SimulationManager(string resources) : resources(resources)
SimulationManager::~SimulationManager()
{
for (auto player : players) {
delete player;
}
#if USE_EXAMPLE_INITIATOR
delete init;
delete exampleInitiatorTlmChecker;
#endif
for (auto tlmChecker : playersTlmCheckers) {
delete tlmChecker;
}
}
void SimulationManager::loadSimulationsFromXML(string uri)
@@ -88,7 +99,9 @@ void SimulationManager::runSimulations()
for (auto& traceSetup : batch.traceSetups)
{
string exportname = exportPath + "/" + traceSetup.first;
runSimulation(exportname, dramSetup, traceSetup.second);
instantiateModules(exportname, dramSetup, traceSetup.second);
bindSockets();
runSimulation(exportname);
}
}
}
@@ -132,15 +145,106 @@ void SimulationManager::parseSimulationBatch(XMLElement* simulation)
simulationBatches.push_back(batch);
}
void SimulationManager::runSimulation(string traceName, DramSetup dramSetup, vector<Device> traceSetup)
void SimulationManager::instantiateModules(string traceName, DramSetup dramSetup, vector<Device> traceSetup)
{
simulation = new Simulation("sim", resources, traceName, dramSetup, traceSetup);
#if USE_EXAMPLE_INITIATOR
init = new ExampleInitiator("init");
if(Configuration::getInstance().CheckTLM2Protocol) {
string str = "ExampleInitiatorTLMChecker";
exampleInitiatorTlmChecker = new tlm_utils::tlm2_base_protocol_checker<>(str.c_str());
}
#else
for (size_t i = 0; i < Configuration::getInstance().NumberOfTracePlayers; i++) {
std::string playerStr = "tracePlayer" + std::to_string(i);
TracePlayer *player;
sc_time playerClk;
// 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 (traceSetup[i].clkMhz == 0)
playerClk = Configuration::getInstance().memSpec.clk;
else
playerClk = FrequencyToClk(traceSetup[i].clkMhz);
const string pathToResources = resources;
player = new StlPlayer(playerStr.c_str(), pathToResources + string("traces/") + traceSetup[i].trace, playerClk, this);
if(Configuration::getInstance().SimulationProgressBar)
{
totalTransactions += player->getNumberOfLines(pathToResources + string("traces/") + traceSetup[i].trace);
}
players.push_back(player);
if(Configuration::getInstance().CheckTLM2Protocol) {
string str = "TLMCheckerPlayer"+ std::to_string(i);
tlm_utils::tlm2_base_protocol_checker<> * playerTlmChecker = new tlm_utils::tlm2_base_protocol_checker<>(str.c_str());
playersTlmCheckers.push_back(playerTlmChecker);
}
}
remainingTransactions = totalTransactions;
#endif /* USE_EXAMPLE_INITIATOR */
}
void SimulationManager::bindSockets()
{
#if USE_EXAMPLE_INITIATOR
if(Configuration::getInstance().CheckTLM2Protocol) {
init->socket.bind(exampleInitiatorTlmChecker->target_socket);
exampleInitiatorTlmChecker->initiator_socket.bind(simulation->tSocket);
}
else {
init->socket.bind(simulation->tSocket);
#else
if(Configuration::getInstance().CheckTLM2Protocol) {
for (size_t i = 0; i < players.size(); i++) {
players[i]->iSocket.bind(playersTlmCheckers[i]->target_socket);
playersTlmCheckers[i]->initiator_socket.bind(simulation->tSocket);
}
}
else {
for (auto player : players) {
player->iSocket.bind(simulation->tSocket);
}
#endif
}
}
void SimulationManager::runSimulation(string traceName)
{
// int pid = fork();
// int status = 0;
// if (pid == 0)
// {
Simulation* simulation = new Simulation("sim", resources, traceName, dramSetup, traceSetup);
simulation->start();
delete simulation;
report("\n\nStarting simulation:");
report(headline);
report(" -> setup: \t\t" + getFileName(traceName));
report(" -> memspec: \t\t" + Configuration::getInstance().memSpec.MemoryId);
cout << endl;
//simulationStartTime = clock();
for (auto player : players) {
player->nextPayload();
}
sc_set_stop_mode(SC_STOP_FINISH_DELTA);
sc_start();
delete simulation;
// _Exit(0);
//}
@@ -181,6 +285,23 @@ void SimulationManager::addTraceSetups(SimulationBatch &batch, tinyxml2::XMLElem
}
}
void inline SimulationManager::tracePlayerTerminates()
{
static unsigned int finishedTracePlayers = 0;
finishedTracePlayers++;
if (finishedTracePlayers == Configuration::getInstance().NumberOfTracePlayers)
simulation->terminateSimulation.notify();
}
void inline SimulationManager::transactionFinished()
{
remainingTransactions--;
loadbar(totalTransactions - remainingTransactions, totalTransactions);
if (remainingTransactions == 0)
{
cout << endl;
}
}
void SimulationManager::report(string message)
{
cout << message << endl;
@@ -196,4 +317,3 @@ void SimulationBatch::print()
cout << endl;
}
}

View File

@@ -42,40 +42,67 @@
#include <string>
#include <map>
#include "Simulation.h"
#include "TracePlayer.h"
#include "StlPlayer.h"
#include "../controller/core/configuration/ConfigurationLoader.h"
#include "../common/third_party/tinyxml2/tinyxml2.h"
#include "ExampleInitiator.h"
#include "../common/tlm2_base_protocol_checker.h"
#define USE_EXAMPLE_INITIATOR 0
struct SimulationBatch
{
std::vector<DramSetup> dramSetups;
std::map<std::string, std::vector<Device>> traceSetups;
void print();
std::map<std::string, std::vector<Device>> traceSetups;
void print();
};
class SimulationManager
class SimulationManager: public TracePlayerListener
{
public:
SimulationManager(std::string resources);
~SimulationManager();
SimulationManager(std::string resources);
~SimulationManager();
void loadSimulationsFromXML(std::string uri);
void loadSimulationsFromXML(std::string uri);
void runSimulations();
void startTraceAnalyzer();
void runSimulations();
void startTraceAnalyzer();
virtual void tracePlayerTerminates() override;
virtual void transactionFinished() override;
private:
std::string resources;
std::string exportPath;
std::string resources;
std::string exportPath;
std::string basePath;
tinyxml2::XMLDocument simulationdoc;
std::vector<SimulationBatch> simulationBatches;
std::vector<SimulationBatch> simulationBatches;
void runSimulation(std::string traceName, DramSetup dramSetup, std::vector<Device> traceSetup);
void parseSimulationBatch(tinyxml2::XMLElement* simulation);
// A vector of pointers to all trace player (devices which acquire the bus
// and initiate transactions targeting the memory)
std::vector<TracePlayer*> players;
Simulation* simulation;
//TLM 2.0 Protocol Checkers
std::vector<tlm_utils::tlm2_base_protocol_checker<>*> playersTlmCheckers;
unsigned int totalTransactions = 0;
unsigned int remainingTransactions;
#if USE_EXAMPLE_INITIATOR
ExampleInitiator *init;
tlm_utils::tlm2_base_protocol_checker<>* exampleInitiatorTlmChecker;
#endif
void instantiateModules(std::string traceName, DramSetup dramSetup, std::vector<Device> traceSetup);
void bindSockets();
void runSimulation(string traceName);
void parseSimulationBatch(tinyxml2::XMLElement* simulation);
void addTraceSetups(SimulationBatch &batch, tinyxml2::XMLElement *element);
void report(std::string message);
void report(std::string message);
};
#endif /* SIMULATIONMANAGER_H_ */

View File

@@ -72,8 +72,6 @@ void TracePlayer::peqCallback(tlm_generic_payload &payload, const tlm_phase &pha
if (phase == BEGIN_REQ)
{
payload.acquire();
GenerationExtension* genExtension = new GenerationExtension(sc_time_stamp());
payload.set_auto_extension(genExtension);
sendToTarget(payload, phase, SC_ZERO_TIME);
transactionsSent++;

View File

@@ -50,7 +50,6 @@
#include "../controller/core/configuration/Configuration.h"
#include "../common/DebugManager.h"
#include "../common/xmlAddressdecoder.h"
#include "../common/dramExtension.h"
#include "../controller/core/TimingCalculation.h"
#include "TracePlayerListener.h"
@@ -86,4 +85,3 @@ private:
};
#endif /* TRACEPLAYER_H_ */

View File

@@ -1,22 +1,22 @@
#!/usr/bin/perl -w
# 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
@@ -28,7 +28,7 @@
# 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:
# Matthias Jung, Felipe S. Prado
#
@@ -42,10 +42,10 @@ $numberOfCores = `cat /proc/cpuinfo | grep processor | wc -l`;
chdir("../../../build/simulator/");
$exampleInitiatorLine = `grep -n '#define USE_EXAMPLE_INITIATOR' ../../DRAMSys/simulator/src/simulation/Simulation.h | cut -d: -f 1`;
$exampleInitiatorLine = `grep -n '#define USE_EXAMPLE_INITIATOR' ../../DRAMSys/simulator/src/simulation/SimulationManager.h | cut -d: -f 1`;
chomp $exampleInitiatorLine;
system("sed -i '" . $exampleInitiatorLine . "s^.*^#define USE_EXAMPLE_INITIATOR 1^' ../../DRAMSys/simulator/src/simulation/Simulation.h");
system("sed -i '" . $exampleInitiatorLine . "s^.*^#define USE_EXAMPLE_INITIATOR 1^' ../../DRAMSys/simulator/src/simulation/SimulationManager.h");
`make -j$numberOfCores > /dev/null 2>&1`;
@@ -61,7 +61,7 @@ if("" ne `grep "Error: tlm2_protocol_checker" ../../DRAMSys/tests/TLM_compliance
exit -1;
}
system("sed -i '" . $exampleInitiatorLine . "s^.*^#define USE_EXAMPLE_INITIATOR 0^' ../../DRAMSys/simulator/src/simulation/Simulation.h");
system("sed -i '" . $exampleInitiatorLine . "s^.*^#define USE_EXAMPLE_INITIATOR 0^' ../../DRAMSys/simulator/src/simulation/SimulationManager.h");
`make -j$numberOfCores > /dev/null 2>&1`;
@@ -85,4 +85,3 @@ exit 0;