From 17bfb3ec8532265f4f5d399ad3d78d6d0c9bb758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89der=20F=2E=20Zulian?= Date: Thu, 30 Jun 2016 11:48:02 +0200 Subject: [PATCH] Issue#12 - removal of BUSWIDTH from modules --- DRAMSys/simulator/simulator.pro | 4 +- .../simulator/src/simulation/Simulation.cpp | 6 +- DRAMSys/simulator/src/simulation/Simulation.h | 8 +- .../simulator/src/simulation/StlDataPlayer.h | 8 +- .../simulator/src/simulation/StlPlayer.cpp | 55 +++++++++ DRAMSys/simulator/src/simulation/StlPlayer.h | 22 +--- .../simulator/src/simulation/TraceGenerator.h | 31 ++--- .../simulator/src/simulation/TracePlayer.cpp | 108 +++++++++++++++++ .../simulator/src/simulation/TracePlayer.h | 112 ++---------------- 9 files changed, 196 insertions(+), 158 deletions(-) create mode 100644 DRAMSys/simulator/src/simulation/StlPlayer.cpp create mode 100644 DRAMSys/simulator/src/simulation/TracePlayer.cpp diff --git a/DRAMSys/simulator/simulator.pro b/DRAMSys/simulator/simulator.pro index a3ce17e7..66248108 100644 --- a/DRAMSys/simulator/simulator.pro +++ b/DRAMSys/simulator/simulator.pro @@ -104,7 +104,9 @@ SOURCES += \ src/controller/scheduler/IScheduler.cpp \ src/controller/scheduler/FifoStrict.cpp \ src/error/errormodel.cpp \ - src/controller/Controller.cpp + src/controller/Controller.cpp \ + src/simulation/TracePlayer.cpp \ + src/simulation/StlPlayer.cpp HEADERS += \ src/common/third_party/tinyxml2/tinyxml2.h \ diff --git a/DRAMSys/simulator/src/simulation/Simulation.cpp b/DRAMSys/simulator/src/simulation/Simulation.cpp index 19e863ed..04582c68 100644 --- a/DRAMSys/simulator/src/simulation/Simulation.cpp +++ b/DRAMSys/simulator/src/simulation/Simulation.cpp @@ -116,20 +116,20 @@ void Simulation::instantiateModules(const string &traceName, const string &pathT for (size_t i = 0; i < Configuration::getInstance().NumberOfTracePlayers; i++) { std::string playerStr = "tracePlayer" + std::to_string(i); - TracePlayer<> *player; + TracePlayer *player; // When data should be stored during the simulation the StlDataPlayer is needed. // Else: no data should be stored, for instance to get a faster simulation // or if you simply dont care about the data the normal StlPlayer is used. if(Configuration::getInstance().ErrorStoreMode == ErrorStorageMode::NoStorage) { - StlPlayer<> *newPlayer = new StlPlayer<>(playerStr.c_str(), pathToResources + string("traces/") + devices[i].trace, devices[i].clkMhz, this); + StlPlayer *newPlayer = new StlPlayer(playerStr.c_str(), pathToResources + string("traces/") + devices[i].trace, devices[i].clkMhz, this); player = newPlayer; newPlayer->getTraceLength(pathToResources + string("traces/") + devices[i].trace); totalTransactions += newPlayer->getNumberOfLines(pathToResources + string("traces/") + devices[i].trace); } else { - StlDataPlayer<> *newPlayer = new StlDataPlayer<>(playerStr.c_str(), pathToResources + string("traces/") + devices[i].trace, devices[i].clkMhz, this); + StlDataPlayer *newPlayer = new StlDataPlayer(playerStr.c_str(), pathToResources + string("traces/") + devices[i].trace, devices[i].clkMhz, this); player = newPlayer; newPlayer->getTraceLength(pathToResources + string("traces/") + devices[i].trace); totalTransactions += newPlayer->getNumberOfLines(pathToResources + string("traces/") + devices[i].trace); diff --git a/DRAMSys/simulator/src/simulation/Simulation.h b/DRAMSys/simulator/src/simulation/Simulation.h index 96a8abe1..2f4c6bd0 100644 --- a/DRAMSys/simulator/src/simulation/Simulation.h +++ b/DRAMSys/simulator/src/simulation/Simulation.h @@ -96,15 +96,15 @@ private: // A vector of pointers to all trace player (devices which acquire the bus // and initiate transactions targeting the memory) - std::vector*> players; + std::vector players; // All transactions pass through the same arbiter Arbiter *arbiter; // Each DRAM unit has a controller - std::vector controllers; + std::vector controllers; // TODO: Each DRAM has a reorder buffer (check this!) ReorderBuffer *reorder; // DRAM units - std::vector drams; + std::vector drams; // Transaction Recorders (one per channel). They generate the output databases. std::vector tlmRecorders; @@ -116,7 +116,7 @@ private: void setupTlmRecorders(const string &traceName, const string &pathToResources, const std::vector &devices); void instantiateModules(const string &traceName, const string &pathToResources, const std::vector &devices); void bindSockets(); - void setupDebugManager(const string& traceName); + void setupDebugManager(const string &traceName); }; #endif /* SIMULATIONMANAGER_H_ */ diff --git a/DRAMSys/simulator/src/simulation/StlDataPlayer.h b/DRAMSys/simulator/src/simulation/StlDataPlayer.h index 8c29b30b..9c520b4b 100644 --- a/DRAMSys/simulator/src/simulation/StlDataPlayer.h +++ b/DRAMSys/simulator/src/simulation/StlDataPlayer.h @@ -45,8 +45,7 @@ using namespace std; using namespace tlm; -template -struct StlDataPlayer: public TracePlayer +struct StlDataPlayer: public TracePlayer { public: StlDataPlayer(sc_module_name /*name*/, string pathToTrace, unsigned int clkMhz, TracePlayerListener* listener); @@ -199,10 +198,9 @@ private: }; -template -StlDataPlayer::StlDataPlayer(sc_module_name /*name*/, string pathToTrace, unsigned int clkMhz, +StlDataPlayer::StlDataPlayer(sc_module_name /*name*/, string pathToTrace, unsigned int clkMhz, TracePlayerListener* listener) : - TracePlayer(listener),file(pathToTrace) + TracePlayer(listener),file(pathToTrace) { if (!file.is_open()) SC_REPORT_FATAL(0, (string("Could not open trace ") + pathToTrace).c_str()); diff --git a/DRAMSys/simulator/src/simulation/StlPlayer.cpp b/DRAMSys/simulator/src/simulation/StlPlayer.cpp new file mode 100644 index 00000000..b0bb4a00 --- /dev/null +++ b/DRAMSys/simulator/src/simulation/StlPlayer.cpp @@ -0,0 +1,55 @@ +/* + * 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 + */ + +#include "StlPlayer.h" + + +StlPlayer::StlPlayer(sc_module_name /*name*/, string pathToTrace, unsigned int clkMhz, + TracePlayerListener* listener) : + TracePlayer(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"]; +} diff --git a/DRAMSys/simulator/src/simulation/StlPlayer.h b/DRAMSys/simulator/src/simulation/StlPlayer.h index 809a4da7..cb56a556 100644 --- a/DRAMSys/simulator/src/simulation/StlPlayer.h +++ b/DRAMSys/simulator/src/simulation/StlPlayer.h @@ -45,8 +45,7 @@ using namespace std; using namespace tlm; -template -struct StlPlayer: public TracePlayer +struct StlPlayer: public TracePlayer { public: StlPlayer(sc_module_name /*name*/, string pathToTrace, unsigned int clkMhz, TracePlayerListener *listener); @@ -185,23 +184,4 @@ private: sc_time clk; }; - -template -StlPlayer::StlPlayer(sc_module_name /*name*/, string pathToTrace, unsigned int clkMhz, - TracePlayerListener* listener) : - TracePlayer(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 // STLPLAYER_H - diff --git a/DRAMSys/simulator/src/simulation/TraceGenerator.h b/DRAMSys/simulator/src/simulation/TraceGenerator.h index 2f9ade1d..1cb3ccfb 100644 --- a/DRAMSys/simulator/src/simulation/TraceGenerator.h +++ b/DRAMSys/simulator/src/simulation/TraceGenerator.h @@ -44,12 +44,19 @@ using namespace std; using namespace tlm; -template -struct TraceGenerator: public TracePlayer +struct TraceGenerator: public TracePlayer { public: TraceGenerator(sc_module_name /*name*/, unsigned int clkMhz, - TracePlayerListener* listener); + TracePlayerListener* listener) : TracePlayer(listener), transCounter(0) + { + if(clkMhz == 0) + clk = Configuration::getInstance().memSpec.clk; + else + clk = FrequencyToClk(clkMhz); + + this->burstlenght = Configuration::getInstance().memSpec.BurstLength; + } virtual void nextPayload() override { @@ -67,32 +74,18 @@ public: payload->set_dmi_allowed(false); payload->set_byte_enable_length(0); payload->set_streaming_width(this->burstlenght); - this->setDataPointer(payload, dataElement); + this->setDataPointer(payload, dataElement, 16); payload->set_command(TLM_READ_COMMAND); transCounter++; this->payloadEventQueue.notify(*payload, BEGIN_REQ, SC_ZERO_TIME); } - private: unsigned int burstlenght; sc_time clk; unsigned int transCounter; }; - -template -TraceGenerator::TraceGenerator(sc_module_name /*name*/, unsigned int clkMhz, - TracePlayerListener* listener) : - TracePlayer(listener), transCounter(0) -{ - if(clkMhz == 0) - clk = Configuration::getInstance().memSpec.clk; - else - clk = FrequencyToClk(clkMhz); - - this->burstlenght = Configuration::getInstance().memSpec.BurstLength; -} - #endif + diff --git a/DRAMSys/simulator/src/simulation/TracePlayer.cpp b/DRAMSys/simulator/src/simulation/TracePlayer.cpp new file mode 100644 index 00000000..42a726cc --- /dev/null +++ b/DRAMSys/simulator/src/simulation/TracePlayer.cpp @@ -0,0 +1,108 @@ +/* + * 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: + * Robert Gernhardt + * Matthias Jung + */ + +#include "TracePlayer.h" + +TracePlayer::TracePlayer(TracePlayerListener* listener) : + payloadEventQueue(this, &TracePlayer::peqCallback), transactionsSent(0), listener(listener) +{ + iSocket.register_nb_transport_bw(this, &TracePlayer::nb_transport_bw); +} + +gp *TracePlayer::allocatePayload() +{ + return memoryManager.allocate(); +} + +void TracePlayer::terminate() +{ + cout << sc_time_stamp() << " " << this->name() << " terminated " << std::endl; + listener->tracePlayerTerminates(); +} + +void TracePlayer::printDebugMessage(std::string message) +{ + DebugManager::getInstance().printDebugMessage(this->name(), message); +} + +//TODO: this doesn't depend on the tracePlayer, move it somewhere +void TracePlayer::setDataPointer(gp* payload, unsigned char * dataElement, unsigned int size) +{ + //check if payload takes ownership + payload->set_data_length(size); + payload->set_data_ptr(dataElement); + for(unsigned i = 0; i < size; i++) + dataElement[i] = 0; +} + +tlm_sync_enum TracePlayer::nb_transport_bw(tlm_generic_payload &payload, tlm_phase &phase, sc_time &bwDelay) +{ + payloadEventQueue.notify(payload, phase, bwDelay); + return TLM_ACCEPTED; +} + +void TracePlayer::peqCallback(tlm_generic_payload &payload, const tlm_phase &phase) +{ + + 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++; + DebugManager::getInstance().printDebugMessage(name(), "Performing request #" + std::to_string(transactionsSent)); + } + else if (phase == END_REQ) + { + nextPayload(); + } + else if (phase == BEGIN_RESP) + { + sendToTarget(payload, END_RESP, SC_ZERO_TIME); + payload.release(); + if(Configuration::getInstance().SimulationProgressBar) + listener->transactionFinished(); + } + else if (phase == END_RESP) + { + } + else + { + SC_REPORT_FATAL(0, "TracePlayer PEQ was triggered with unknown phase"); + } +} diff --git a/DRAMSys/simulator/src/simulation/TracePlayer.h b/DRAMSys/simulator/src/simulation/TracePlayer.h index 515373a2..7182fc67 100644 --- a/DRAMSys/simulator/src/simulation/TracePlayer.h +++ b/DRAMSys/simulator/src/simulation/TracePlayer.h @@ -55,12 +55,11 @@ using namespace std; using namespace tlm; -template struct TracePlayer: public sc_module { public: tlm_utils::simple_initiator_socket iSocket; - TracePlayer(TracePlayerListener* listener); + TracePlayer(TracePlayerListener *listener); virtual void nextPayload() = 0; protected: @@ -73,112 +72,15 @@ protected: private: tlm_sync_enum nb_transport_bw(tlm_generic_payload& payload, tlm_phase& phase, sc_time& bwDelay); void peqCallback(tlm_generic_payload& payload, const tlm_phase& phase); - void sendToTarget(tlm_generic_payload& payload, const tlm_phase& phase, const sc_time& delay); - + void sendToTarget(tlm_generic_payload &payload, const tlm_phase &phase, const sc_time &delay) + { + tlm_phase TPhase = phase; + sc_time TDelay = delay; + iSocket->nb_transport_fw(payload, TPhase, TDelay); + } MemoryManager memoryManager; unsigned int transactionsSent; TracePlayerListener* listener; }; -template -TracePlayer::TracePlayer(TracePlayerListener* listener) : - payloadEventQueue(this, &TracePlayer::peqCallback), transactionsSent(0), listener(listener) -{ - iSocket.register_nb_transport_bw(this, &TracePlayer::nb_transport_bw); -} - -template -gp *TracePlayer::allocatePayload() -{ - return memoryManager.allocate(); -} - -template -void TracePlayer::terminate() -{ - cout << sc_time_stamp() << " " << this->name() << " terminated " << std::endl; - listener->tracePlayerTerminates(); -} - -template -void TracePlayer::printDebugMessage(std::string message) -{ - DebugManager::getInstance().printDebugMessage(this->name(), message); -} - -template -//TODO: this doesn't depend on the tracePlayer, move it somewhere -void TracePlayer::setDataPointer(gp* payload, unsigned char * dataElement, unsigned int size) -{ - //check if payload takes ownership - payload->set_data_length(size); - payload->set_data_ptr(dataElement); - for(unsigned i = 0; i < size; i++) - dataElement[i] = 0; -} - -template -tlm_sync_enum TracePlayer::nb_transport_bw(tlm_generic_payload &payload, tlm_phase &phase, sc_time &bwDelay) -{ - payloadEventQueue.notify(payload, phase, bwDelay); - return TLM_ACCEPTED; -} - -template -void TracePlayer::peqCallback(tlm_generic_payload &payload, const tlm_phase &phase) -{ - - 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++; - DebugManager::getInstance().printDebugMessage(name(), "Performing request #" + std::to_string(transactionsSent)); - } - else if (phase == END_REQ) - { - nextPayload(); - } - else if (phase == BEGIN_RESP) - { -//TODO: cleanup: -// unsigned char * dataElement = payload.get_data_ptr(); -// -// if(payload.get_command() == TLM_READ_COMMAND) -// { -// cout << "0x"; -// for(int i=0; i < 16*2; i++) -// { -// cout << hex << int(dataElement[i]); -// } -// cout << endl; -// } - - sendToTarget(payload, END_RESP, SC_ZERO_TIME); - payload.release(); - if(Configuration::getInstance().SimulationProgressBar) - listener->transactionFinished(); - - } - else if (phase == END_RESP) - { - } - else - { - SC_REPORT_FATAL(0, "TracePlayer PEQ was triggered with unknown phase"); - } -} - -template -void TracePlayer::sendToTarget(tlm_generic_payload &payload, const tlm_phase &phase, const sc_time &delay) -{ - tlm_phase TPhase = phase; - sc_time TDelay = delay; - iSocket->nb_transport_fw(payload, TPhase, TDelay); -} - #endif /* TRACEPLAYER_H_ */ -