diff --git a/DRAMSys/simulator/resources/configs/mcconfigs/fifo.xml b/DRAMSys/simulator/resources/configs/mcconfigs/fifo.xml index 08135f13..b09a4cfa 100644 --- a/DRAMSys/simulator/resources/configs/mcconfigs/fifo.xml +++ b/DRAMSys/simulator/resources/configs/mcconfigs/fifo.xml @@ -8,13 +8,5 @@ - - - - diff --git a/DRAMSys/simulator/resources/configs/mcconfigs/fifoStrict.xml b/DRAMSys/simulator/resources/configs/mcconfigs/fifoStrict.xml index 5c58a9c5..7ca1a824 100644 --- a/DRAMSys/simulator/resources/configs/mcconfigs/fifoStrict.xml +++ b/DRAMSys/simulator/resources/configs/mcconfigs/fifoStrict.xml @@ -8,13 +8,5 @@ - - - - diff --git a/DRAMSys/simulator/resources/configs/mcconfigs/fifo_ecc.xml b/DRAMSys/simulator/resources/configs/mcconfigs/fifo_ecc.xml index d6acf112..b09a4cfa 100644 --- a/DRAMSys/simulator/resources/configs/mcconfigs/fifo_ecc.xml +++ b/DRAMSys/simulator/resources/configs/mcconfigs/fifo_ecc.xml @@ -8,13 +8,5 @@ - - - - diff --git a/DRAMSys/simulator/resources/configs/mcconfigs/fr_fcfs.xml b/DRAMSys/simulator/resources/configs/mcconfigs/fr_fcfs.xml index fad8b021..0ff319b0 100644 --- a/DRAMSys/simulator/resources/configs/mcconfigs/fr_fcfs.xml +++ b/DRAMSys/simulator/resources/configs/mcconfigs/fr_fcfs.xml @@ -8,14 +8,6 @@ - - - - diff --git a/DRAMSys/simulator/resources/configs/mcconfigs/par_bs.xml b/DRAMSys/simulator/resources/configs/mcconfigs/par_bs.xml index 78a8afd7..63fb4a27 100644 --- a/DRAMSys/simulator/resources/configs/mcconfigs/par_bs.xml +++ b/DRAMSys/simulator/resources/configs/mcconfigs/par_bs.xml @@ -8,13 +8,5 @@ - - - - diff --git a/DRAMSys/simulator/resources/configs/simulator/ddr3-single-device.xml b/DRAMSys/simulator/resources/configs/simulator/ddr3-single-device.xml index 35fd3dec..0a19ff35 100644 --- a/DRAMSys/simulator/resources/configs/simulator/ddr3-single-device.xml +++ b/DRAMSys/simulator/resources/configs/simulator/ddr3-single-device.xml @@ -11,4 +11,12 @@ + + + + diff --git a/DRAMSys/simulator/resources/configs/simulator/ddr3.xml b/DRAMSys/simulator/resources/configs/simulator/ddr3.xml index 9e322605..155ab0ff 100644 --- a/DRAMSys/simulator/resources/configs/simulator/ddr3.xml +++ b/DRAMSys/simulator/resources/configs/simulator/ddr3.xml @@ -11,6 +11,14 @@ + + + + + diff --git a/DRAMSys/simulator/resources/configs/simulator/wideio.xml b/DRAMSys/simulator/resources/configs/simulator/wideio.xml index 8ba8f3ba..ba435056 100644 --- a/DRAMSys/simulator/resources/configs/simulator/wideio.xml +++ b/DRAMSys/simulator/resources/configs/simulator/wideio.xml @@ -10,5 +10,13 @@ + + + + diff --git a/DRAMSys/simulator/resources/configs/simulator/wideio_ecc.xml b/DRAMSys/simulator/resources/configs/simulator/wideio_ecc.xml index 4b8ad3d1..3a7c43e5 100644 --- a/DRAMSys/simulator/resources/configs/simulator/wideio_ecc.xml +++ b/DRAMSys/simulator/resources/configs/simulator/wideio_ecc.xml @@ -11,5 +11,13 @@ + + + + diff --git a/DRAMSys/simulator/resources/configs/simulator/wideio_thermal.xml b/DRAMSys/simulator/resources/configs/simulator/wideio_thermal.xml index 42dcda72..880e573d 100644 --- a/DRAMSys/simulator/resources/configs/simulator/wideio_thermal.xml +++ b/DRAMSys/simulator/resources/configs/simulator/wideio_thermal.xml @@ -10,5 +10,13 @@ + + + + diff --git a/DRAMSys/simulator/src/error/error.csv b/DRAMSys/simulator/resources/error/wideio.csv similarity index 100% rename from DRAMSys/simulator/src/error/error.csv rename to DRAMSys/simulator/resources/error/wideio.csv diff --git a/DRAMSys/simulator/resources/resources.pri b/DRAMSys/simulator/resources/resources.pri index ac3384bf..b3f97407 100644 --- a/DRAMSys/simulator/resources/resources.pri +++ b/DRAMSys/simulator/resources/resources.pri @@ -140,3 +140,6 @@ OTHER_FILES += resources/configs/thermalsim/mem.flp OTHER_FILES += resources/configs/thermalsim/powerInfo.xml OTHER_FILES += resources/configs/thermalsim/stack.stk OTHER_FILES += resources/configs/thermalsim/config.xml + +# Error Simulation data +OTHER_FILES += resources/error/wideio.csv diff --git a/DRAMSys/simulator/resources/simulations/sim-batch.xml b/DRAMSys/simulator/resources/simulations/sim-batch.xml new file mode 100644 index 00000000..0752914c --- /dev/null +++ b/DRAMSys/simulator/resources/simulations/sim-batch.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + chstone-adpcm_32.stl + + + + + diff --git a/DRAMSys/simulator/src/error/controllerECC.h b/DRAMSys/simulator/src/error/controllerECC.h index 9ca85fe8..beefe784 100644 --- a/DRAMSys/simulator/src/error/controllerECC.h +++ b/DRAMSys/simulator/src/error/controllerECC.h @@ -194,6 +194,9 @@ public: unsigned char* pDataECC = it->second; + // delete data pointer from map + m_mDataPointer.erase(it); + // Copy data memcpy(pDataECC, pData, nBlocks<<3); @@ -219,7 +222,10 @@ public: trans.set_data_ptr(it->second); - // Change transport data length + // delete data pointer from map + m_mDataPointer.erase(it); + + // Change transport data length trans.set_data_length((nDataLength/9)<<3); } diff --git a/DRAMSys/simulator/src/simulation/SimulationManager.cpp b/DRAMSys/simulator/src/simulation/SimulationManager.cpp new file mode 100644 index 00000000..a3494667 --- /dev/null +++ b/DRAMSys/simulator/src/simulation/SimulationManager.cpp @@ -0,0 +1,310 @@ +/* + * 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 + * Matthias Jung + * Eder F. Zulian + */ + +#include +#include + +#include "SimulationManager.h" +#include "../common/Utils.h" + +using namespace std; +using namespace tinyxml2; + +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) +{ + cout << "\n\nload simulation-batch:" << endl; + cout << headline << endl; + + exportPath = getFileName(uri); + loadXML(uri, simulationdoc); + + cout << "\t-> parsing simulation objects .." << endl; + + XMLElement* simulation = simulationdoc.FirstChildElement("simulation"); + string xmlNodeName(simulation->Name()); + if( xmlNodeName != "simulation") + reportFatal("SimulationManager", "simulation node expected"); + parseSimulationBatch(simulation); + + cout << "\t-> simulation batches loaded successfully!\n" << endl; + + for (auto batch : simulationBatches) + { + batch.print(); + } +} + +void SimulationManager::runSimulations() +{ + for (auto& batch : simulationBatches) + { + boost::filesystem::path dir(exportPath); + boost::filesystem::create_directories(dir); + + for (auto& dramSetup : batch.dramSetups) + { + for (auto& traceSetup : batch.traceSetups) + { + string exportname = exportPath + "/" + traceSetup.first; + instantiateModules(exportname, dramSetup, traceSetup.second); + bindSockets(); + runSimulation(exportname); + } + } + } +} + +void SimulationManager::parseSimulationBatch(XMLElement* simulation) +{ + SimulationBatch batch; + + XMLElement* simconfig = simulation->FirstChildElement("simconfig"); + + XMLElement *thermalsimconfig = simulation->FirstChildElement("thermalsimconfig"); + + XMLElement* memspecs = simulation->FirstChildElement("memspecs"); + if(memspecs == NULL) memspecs = simulation; + + XMLElement* addressmappings = simulation->FirstChildElement("addressmappings"); + if(addressmappings == NULL) addressmappings = simulation; + + XMLElement* mcconfigs = simulation->FirstChildElement("mcconfigs"); + if(mcconfigs == NULL) mcconfigs = simulation; + + for (XMLElement* memspec = memspecs->FirstChildElement("memspec"); memspec != NULL; + memspec = memspec->NextSiblingElement("memspec")) + { + + for (XMLElement* addressmapping = addressmappings->FirstChildElement("addressmapping"); addressmapping != NULL; + addressmapping = addressmapping->NextSiblingElement("addressmapping")) + { + + for (XMLElement* mcconfig = mcconfigs->FirstChildElement("mcconfig"); + mcconfig != NULL; mcconfig = mcconfig->NextSiblingElement("mcconfig")) + { + batch.dramSetups.push_back(DramSetup(memspec, mcconfig, simconfig, addressmapping, thermalsimconfig)); + } + } + } + + addTraceSetups(batch, simulation); + + simulationBatches.push_back(batch); +} + +void SimulationManager::instantiateModules(string traceName, DramSetup dramSetup, vector 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): + // + // + // + // chstone-adpcm_32.stl + // + // + // + // 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) +{ + report("\n\nStarting simulation:"); + report(headline); + report(" -> setup: \t\t" + getFileName(traceName)); + report(" -> memspec: \t\t" + Configuration::getInstance().memSpec.MemoryId); + cout << endl; + simStartTime = clock(); + + for (auto player : players) { + player->nextPayload(); + } + + sc_set_stop_mode(SC_STOP_FINISH_DELTA); + sc_start(); + double elapsed_secs = double(clock() - simStartTime) / CLOCKS_PER_SEC; + report("\nSimulation took " + to_string(elapsed_secs) + " seconds\n"); + delete simulation; +} + +void SimulationManager::startTraceAnalyzer() +{ + string p = getenv("trace"); + string run_tpr = p + " -f "; + run_tpr += "&"; + system(run_tpr.c_str()); +} + +void SimulationManager::addTraceSetups(SimulationBatch &batch, tinyxml2::XMLElement *simulation) +{ + vector devices; + XMLElement *tracesetups = simulation->FirstChildElement("tracesetups"); + XMLElement *simconfig = simulation->FirstChildElement("simconfig"); + unsigned int numberOfTracePlayers = 1; + XMLElement *ntp = simconfig->FirstChildElement("NumberOfTracePlayers"); + if (ntp != NULL) + ntp->QueryUnsignedAttribute("value", &numberOfTracePlayers); + + for (XMLElement *tracesetup = tracesetups->FirstChildElement("tracesetup"); tracesetup != NULL; tracesetup = tracesetup->NextSiblingElement("tracesetup")) { + for (XMLElement *device = tracesetup->FirstChildElement("device"); device != NULL; device = device->NextSiblingElement("device")) { + devices.push_back(Device(device->GetText(), device->IntAttribute("clkMhz"), device->IntAttribute("bl"))); + } + + // This step is done here to add a default device in case the user haven't specified a trace file to be executed by one or more trace players. + while (devices.size() < numberOfTracePlayers) { + devices.push_back(Device()); + } + + batch.traceSetups.emplace(tracesetup->Attribute("id"), devices); + devices.clear(); + } +} + +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; +} + +void SimulationBatch::print() +{ + for (auto& s : traceSetups) + { + cout << "trace-setup " + s.first + ":\n"; + for (Device d : s.second) + cout << "\t(" << d.burstLength << ") " << d.trace << ";" << endl; + cout << endl; + } +}