From f27eced780fdcc80e24e6de792133ba7937a88e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89der=20F=2E=20Zulian?= Date: Fri, 7 Sep 2018 13:21:58 +0200 Subject: [PATCH] DRAMSys_gem5 - numumber of transactors from config DRAMSys - new config UseMalloc (default is mmap()) --- DRAMSys/gem5/gem5_se/run.sh | 3 +- DRAMSys/gem5/main.cpp | 53 ++++++++++++------- .../configs/simulator/ddr3-single-device.xml | 1 + .../resources/configs/simulator/ddr3.xml | 1 + .../configs/simulator/ddr3_boot_linux.xml | 2 +- .../resources/configs/simulator/ddr3_ecc.xml | 1 + .../configs/simulator/ddr3_gem5_se.xml | 1 + .../resources/configs/simulator/orgr.xml | 1 + .../simulator/orgr_4b_opt_timings_ddr3.xml | 1 + .../simulator/orgr_4b_std_timings_ddr3.xml | 1 + .../simulator/orgr_8b_opt_timings_ddr3.xml | 1 + .../simulator/orgr_8b_std_timings_ddr3.xml | 1 + .../resources/configs/simulator/orgr_ddr4.xml | 1 + .../configs/simulator/rgrsimcfg-gem5-se.xml | 1 + .../resources/configs/simulator/rgrsimcfg.xml | 1 + .../resources/configs/simulator/sms.xml | 1 + .../resources/configs/simulator/wideio.xml | 1 + .../configs/simulator/wideio_ecc.xml | 1 + .../configs/simulator/wideio_thermal.xml | 1 + .../core/configuration/Configuration.cpp | 2 + .../core/configuration/Configuration.h | 1 + DRAMSys/library/src/simulation/Dram.h | 24 ++++----- README.md | 32 +++++------ 23 files changed, 79 insertions(+), 54 deletions(-) diff --git a/DRAMSys/gem5/gem5_se/run.sh b/DRAMSys/gem5/gem5_se/run.sh index 0a7cda9e..0e8d481f 100755 --- a/DRAMSys/gem5/gem5_se/run.sh +++ b/DRAMSys/gem5/gem5_se/run.sh @@ -85,7 +85,8 @@ for s in $simfiles; do `sed -i s/id=\".*\"/id=\"${sfn}_${bin}\"/g $sf` simulation="${sfpath}/${sfn}_${bin}.${ext}" cp $sf $simulation - LD_PRELOAD=/usr/lib/libtcmalloc.so ./${elf} ${simulation} ../../DRAMSys/gem5/gem5_se/${bin}/config.ini >> out_${sfn}_${bin}.txt & + # LD_PRELOAD=/usr/lib/libtcmalloc.so ./${elf} ${simulation} ../../DRAMSys/gem5/gem5_se/${bin}/config.ini >> out_${sfn}_${bin}.txt & + ./${elf} ${simulation} ../../DRAMSys/gem5/gem5_se/${bin}/config.ini >> out_${sfn}_${bin}.txt & done done diff --git a/DRAMSys/gem5/main.cpp b/DRAMSys/gem5/main.cpp index c152b377..80a5b82a 100644 --- a/DRAMSys/gem5/main.cpp +++ b/DRAMSys/gem5/main.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include "DRAMSys.h" #include "TraceSetup.h" @@ -133,16 +134,21 @@ int sc_main(int argc, char **argv) string SimulationXML; string gem5ConfigFile; string resources; + unsigned int numTransactors; + Gem5SystemC::Gem5SlaveTransactor *t; + std::vector transactors; - if (argc > 1) { + if (argc == 4) { // Get path of resources: resources = pathOfFile(argv[0]) + string("/../../DRAMSys/library/resources/"); SimulationXML = argv[1]; gem5ConfigFile = argv[2]; + numTransactors = atoi(argv[3]); + } else { - SC_REPORT_FATAL("sc_main", "Please provide configuration files"); + SC_REPORT_FATAL("sc_main", "Please provide configuration files and number of ports"); } // Instantiate DRAMSys: @@ -150,25 +156,28 @@ int sc_main(int argc, char **argv) // Instantiate gem5: Gem5SimControlDRAMsys sim_control(gem5ConfigFile); -#define CHOICE1 -//#define CHOICE2 -//#define CHOICE3 -#ifdef CHOICE1 //If only one gem5 port is used - Gem5SystemC::Gem5SlaveTransactor transactor("transactor", "transactor"); - transactor.socket.bind(dramSys.tSocket); - transactor.sim_control.bind(sim_control); -#endif - -#ifdef CHOICE2 - // If there are two ports - Gem5SystemC::Gem5SlaveTransactor transactor1("transactor1", "transactor1"); - Gem5SystemC::Gem5SlaveTransactor transactor2("transactor2", "transactor2"); - transactor1.socket.bind(dramSys.tSocket); - transactor2.socket.bind(dramSys.tSocket); - transactor1.sim_control.bind(sim_control); - transactor2.sim_control.bind(sim_control); -#endif + // XXX: this code assumes: + // - for a single port the port name is "transactor" + // - for multiple ports names are transactor1, transactor2, ..., transactorN + // Names generated here must match port names used by the gem5 config file, e.g., config.ini + if (numTransactors == 1) { + t = new Gem5SystemC::Gem5SlaveTransactor("transactor", "transactor"); + t->socket.bind(dramSys.tSocket); + t->sim_control.bind(sim_control); + transactors.push_back(t); + } else { + for (unsigned i = 0; i < numTransactors; i++) { + // If there are two or more ports + unsigned index = i + 1; + std::string name = "transactor" + std::to_string(index); + std::string portName = "transactor" + std::to_string(index); + t = new Gem5SystemC::Gem5SlaveTransactor(name.c_str(), portName.c_str()); + t->socket.bind(dramSys.tSocket); + t->sim_control.bind(sim_control); + transactors.push_back(t); + } + } #ifdef CHOICE3 // If for example two gem5 ports are used (NVM and DRAM) with @@ -198,6 +207,10 @@ int sc_main(int argc, char **argv) sc_core::sc_stop(); } + for (auto t : transactors) { + delete t; + } + SC_REPORT_INFO("sc_main", "End of Simulation"); return EXIT_SUCCESS; diff --git a/DRAMSys/library/resources/configs/simulator/ddr3-single-device.xml b/DRAMSys/library/resources/configs/simulator/ddr3-single-device.xml index 66dbd2d3..7045a52a 100644 --- a/DRAMSys/library/resources/configs/simulator/ddr3-single-device.xml +++ b/DRAMSys/library/resources/configs/simulator/ddr3-single-device.xml @@ -20,4 +20,5 @@ - ErrorModel (store data with errormodel) --> + diff --git a/DRAMSys/library/resources/configs/simulator/ddr3.xml b/DRAMSys/library/resources/configs/simulator/ddr3.xml index d48f6a8d..1613737f 100644 --- a/DRAMSys/library/resources/configs/simulator/ddr3.xml +++ b/DRAMSys/library/resources/configs/simulator/ddr3.xml @@ -25,4 +25,5 @@ E.g. the DRAM is located at 0x80000000 for gem5 --> + diff --git a/DRAMSys/library/resources/configs/simulator/ddr3_boot_linux.xml b/DRAMSys/library/resources/configs/simulator/ddr3_boot_linux.xml index c34a298d..da5a47a1 100644 --- a/DRAMSys/library/resources/configs/simulator/ddr3_boot_linux.xml +++ b/DRAMSys/library/resources/configs/simulator/ddr3_boot_linux.xml @@ -10,7 +10,6 @@ - @@ -25,4 +24,5 @@ E.g. the DRAM is located at 0x80000000 for gem5 --> + diff --git a/DRAMSys/library/resources/configs/simulator/ddr3_ecc.xml b/DRAMSys/library/resources/configs/simulator/ddr3_ecc.xml index 70a766c4..8e976731 100644 --- a/DRAMSys/library/resources/configs/simulator/ddr3_ecc.xml +++ b/DRAMSys/library/resources/configs/simulator/ddr3_ecc.xml @@ -20,4 +20,5 @@ - ErrorModel (store data with errormodel) --> + diff --git a/DRAMSys/library/resources/configs/simulator/ddr3_gem5_se.xml b/DRAMSys/library/resources/configs/simulator/ddr3_gem5_se.xml index d658d618..ee39f175 100644 --- a/DRAMSys/library/resources/configs/simulator/ddr3_gem5_se.xml +++ b/DRAMSys/library/resources/configs/simulator/ddr3_gem5_se.xml @@ -25,4 +25,5 @@ E.g. the DRAM is located at 0x80000000 for gem5 --> + diff --git a/DRAMSys/library/resources/configs/simulator/orgr.xml b/DRAMSys/library/resources/configs/simulator/orgr.xml index 6598d8f3..0ebb9544 100644 --- a/DRAMSys/library/resources/configs/simulator/orgr.xml +++ b/DRAMSys/library/resources/configs/simulator/orgr.xml @@ -48,4 +48,5 @@ + diff --git a/DRAMSys/library/resources/configs/simulator/orgr_4b_opt_timings_ddr3.xml b/DRAMSys/library/resources/configs/simulator/orgr_4b_opt_timings_ddr3.xml index 5bea53cb..d284a045 100644 --- a/DRAMSys/library/resources/configs/simulator/orgr_4b_opt_timings_ddr3.xml +++ b/DRAMSys/library/resources/configs/simulator/orgr_4b_opt_timings_ddr3.xml @@ -48,4 +48,5 @@ + diff --git a/DRAMSys/library/resources/configs/simulator/orgr_4b_std_timings_ddr3.xml b/DRAMSys/library/resources/configs/simulator/orgr_4b_std_timings_ddr3.xml index ce0d2ea0..3dd9dc0e 100644 --- a/DRAMSys/library/resources/configs/simulator/orgr_4b_std_timings_ddr3.xml +++ b/DRAMSys/library/resources/configs/simulator/orgr_4b_std_timings_ddr3.xml @@ -48,4 +48,5 @@ + diff --git a/DRAMSys/library/resources/configs/simulator/orgr_8b_opt_timings_ddr3.xml b/DRAMSys/library/resources/configs/simulator/orgr_8b_opt_timings_ddr3.xml index bec58f50..784719a1 100644 --- a/DRAMSys/library/resources/configs/simulator/orgr_8b_opt_timings_ddr3.xml +++ b/DRAMSys/library/resources/configs/simulator/orgr_8b_opt_timings_ddr3.xml @@ -48,4 +48,5 @@ + diff --git a/DRAMSys/library/resources/configs/simulator/orgr_8b_std_timings_ddr3.xml b/DRAMSys/library/resources/configs/simulator/orgr_8b_std_timings_ddr3.xml index e8a7bc95..79c60e13 100644 --- a/DRAMSys/library/resources/configs/simulator/orgr_8b_std_timings_ddr3.xml +++ b/DRAMSys/library/resources/configs/simulator/orgr_8b_std_timings_ddr3.xml @@ -48,4 +48,5 @@ + diff --git a/DRAMSys/library/resources/configs/simulator/orgr_ddr4.xml b/DRAMSys/library/resources/configs/simulator/orgr_ddr4.xml index 4aeea8c9..866c0403 100644 --- a/DRAMSys/library/resources/configs/simulator/orgr_ddr4.xml +++ b/DRAMSys/library/resources/configs/simulator/orgr_ddr4.xml @@ -15,4 +15,5 @@ + diff --git a/DRAMSys/library/resources/configs/simulator/rgrsimcfg-gem5-se.xml b/DRAMSys/library/resources/configs/simulator/rgrsimcfg-gem5-se.xml index 9ec65640..215846a6 100644 --- a/DRAMSys/library/resources/configs/simulator/rgrsimcfg-gem5-se.xml +++ b/DRAMSys/library/resources/configs/simulator/rgrsimcfg-gem5-se.xml @@ -15,4 +15,5 @@ + diff --git a/DRAMSys/library/resources/configs/simulator/rgrsimcfg.xml b/DRAMSys/library/resources/configs/simulator/rgrsimcfg.xml index 633da858..569ac4d6 100644 --- a/DRAMSys/library/resources/configs/simulator/rgrsimcfg.xml +++ b/DRAMSys/library/resources/configs/simulator/rgrsimcfg.xml @@ -15,4 +15,5 @@ + diff --git a/DRAMSys/library/resources/configs/simulator/sms.xml b/DRAMSys/library/resources/configs/simulator/sms.xml index deec1b3b..28887877 100644 --- a/DRAMSys/library/resources/configs/simulator/sms.xml +++ b/DRAMSys/library/resources/configs/simulator/sms.xml @@ -10,5 +10,6 @@ + diff --git a/DRAMSys/library/resources/configs/simulator/wideio.xml b/DRAMSys/library/resources/configs/simulator/wideio.xml index e3dc24df..acd95599 100644 --- a/DRAMSys/library/resources/configs/simulator/wideio.xml +++ b/DRAMSys/library/resources/configs/simulator/wideio.xml @@ -19,5 +19,6 @@ - ErrorModel (store data with errormodel) --> + diff --git a/DRAMSys/library/resources/configs/simulator/wideio_ecc.xml b/DRAMSys/library/resources/configs/simulator/wideio_ecc.xml index e325605a..ee16313a 100644 --- a/DRAMSys/library/resources/configs/simulator/wideio_ecc.xml +++ b/DRAMSys/library/resources/configs/simulator/wideio_ecc.xml @@ -19,5 +19,6 @@ - ErrorModel (store data with errormodel) --> + diff --git a/DRAMSys/library/resources/configs/simulator/wideio_thermal.xml b/DRAMSys/library/resources/configs/simulator/wideio_thermal.xml index 9702d72f..fee9e00d 100644 --- a/DRAMSys/library/resources/configs/simulator/wideio_thermal.xml +++ b/DRAMSys/library/resources/configs/simulator/wideio_thermal.xml @@ -19,5 +19,6 @@ - ErrorModel (store data with errormodel) --> + diff --git a/DRAMSys/library/src/controller/core/configuration/Configuration.cpp b/DRAMSys/library/src/controller/core/configuration/Configuration.cpp index e4ae238c..f8c8493f 100644 --- a/DRAMSys/library/src/controller/core/configuration/Configuration.cpp +++ b/DRAMSys/library/src/controller/core/configuration/Configuration.cpp @@ -279,6 +279,8 @@ void Configuration::setParameter(std::string name, std::string value) #else AddressOffset = 0; #endif + } else if (name == "UseMalloc") { + UseMalloc = string2bool(value); } else if (name == "CheckTLM2Protocol") CheckTLM2Protocol = string2bool(value); else if (name == "ECCControllerMode") diff --git a/DRAMSys/library/src/controller/core/configuration/Configuration.h b/DRAMSys/library/src/controller/core/configuration/Configuration.h index 5a4583b4..c20e35f7 100644 --- a/DRAMSys/library/src/controller/core/configuration/Configuration.h +++ b/DRAMSys/library/src/controller/core/configuration/Configuration.h @@ -134,6 +134,7 @@ struct Configuration { ECCControllerMode ECCMode = ECCControllerMode::Disabled; ECCBaseClass *pECC = nullptr; bool gem5 = false; + bool UseMalloc = false; unsigned long long int AddressOffset = 0; // MemSpec (from DRAM-Power XML) diff --git a/DRAMSys/library/src/simulation/Dram.h b/DRAMSys/library/src/simulation/Dram.h index e71fb7d1..7c383498 100644 --- a/DRAMSys/library/src/simulation/Dram.h +++ b/DRAMSys/library/src/simulation/Dram.h @@ -60,8 +60,6 @@ #include "../common/third_party/DRAMPower/src/libdrampower/LibDRAMPower.h" #include "../error/errormodel.h" -//#define USE_MALLOC - using namespace std; using namespace tlm; using namespace Data; @@ -98,15 +96,15 @@ struct Dram : sc_module { dramController = NULL; std::uint64_t memorySize = Configuration::getInstance().getSimMemSizeInBytes(); -#ifdef USE_MALLOC - memory = (unsigned char *)malloc(memorySize); - if (!memory) { - SC_REPORT_FATAL(this->name(), "Memory allocation failed"); + if (Configuration::getInstance().UseMalloc) { + memory = (unsigned char *)malloc(memorySize); + if (!memory) { + SC_REPORT_FATAL(this->name(), "Memory allocation failed"); + } + } else { + // allocate and model storage of one DRAM channel using memory map + memory = (unsigned char *)mmap(NULL, memorySize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, -1, 0); } -#else - // allocate and model storage of one DRAM channel using memory map - memory = (unsigned char *)mmap(NULL, memorySize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, -1, 0); -#endif tSocket.register_nb_transport_fw(this, &Dram::nb_transport_fw); tSocket.register_transport_dbg(this, &Dram::transport_dbg); @@ -309,9 +307,9 @@ struct Dram : sc_module { delete e; } -#ifdef USE_MALLOC - free(memory); -#endif + if (Configuration::getInstance().UseMalloc) { + free(memory); + } } virtual tlm::tlm_sync_enum nb_transport_fw(tlm::tlm_generic_payload &payload, diff --git a/README.md b/README.md index e662bd10..bde439b7 100644 --- a/README.md +++ b/README.md @@ -457,6 +457,7 @@ Below, the sub-configurations are listed and explained. + ``` @@ -498,6 +499,9 @@ Below, the sub-configurations are listed and explained. - *ECCControllerMode* (string) - "Disabled": No ECC Controller is used - "Hamming": Enables an ECC Controller with classic SECDED implementation using Hamming Code + - *UseMalloc* (boolean) + - "0": model storage using mmap() (DEFAULT) + - "1": allocate memory for modeling storage using malloc() - **Temperature Simulator Configuration** @@ -1543,12 +1547,12 @@ in a conf directory of this building directory. Then the simulation can be started with: ```bash -./DRAMSys_gem5 ../../DRAMSys/library/resources/simulations/ddr3-example.xml config.ini +./DRAMSys_gem5 ../../DRAMSys/library/resources/simulations/ddr3-example.xml config.ini 1 ``` Let the simulation run for some seconds and then stop it with **CTRL-C**. Observe the output of the simulation in the trace analyzer. The trace database -file is stored in the gem5 directory in the building directory. +can be found inside the gem5 directory in the building directory. ### Gem5 SE mode and DRAMSys @@ -1634,7 +1638,6 @@ The simconfig should be changed in order to support storage and address offsets: - @@ -1650,13 +1653,14 @@ The simconfig should be changed in order to support storage and address offsets: --> + ``` Then start DRAMSys_gem5 with the following command: ```bash -./DRAMSys_gem5 ../../DRAMSys/library/resources/simulations/ddr3-example.xml config.ini +./DRAMSys_gem5 ../../DRAMSys/library/resources/simulations/ddr3-example.xml config.ini 1 ``` For further sophisticated address mappings or scenarios checkout the file DRAMSys/gem5/main.cpp @@ -1674,7 +1678,7 @@ tar -xaf DRAMSys/gem5/boot_linux/linux-aarch32-ael.img.tar.gz -C DRAMSys/gem5/bo Execute the example: ```bash -./DRAMSys_gem5 ../../DRAMSys/library/resources/simulations/ddr3-boot-linux.xml ../../DRAMSys/gem5/configs/boot_linux.ini +./DRAMSys_gem5 ../../DRAMSys/library/resources/simulations/ddr3-boot-linux.xml ../../DRAMSys/gem5/configs/boot_linux.ini 1 ``` Open a new terminal and connect to gem5: @@ -1697,7 +1701,7 @@ python files are stored [here](DRAMSys/gem5/examples). This is an example for running an elastic trace: ```bash -./DRAMSys_gem5 ../../DRAMSys/library/resources/simulations/ddr3-example.xml ../../DRAMSys/gem5/configs/singleElasticTraceReplay.ini +./DRAMSys_gem5 ../../DRAMSys/library/resources/simulations/ddr3-example.xml ../../DRAMSys/gem5/configs/singleElasticTraceReplay.ini 1 ``` An overview of the architcture being simulated is presented below: @@ -1709,21 +1713,13 @@ Note that the address offset is usually zero for elastic traces. Another example with L2 cache: ```bash -./DRAMSys_gem5 ../../DRAMSys/library/resources/simulations/ddr3-example.xml ../../DRAMSys/gem5/configs/singleElasticTraceReplayWithL2.ini +./DRAMSys_gem5 ../../DRAMSys/library/resources/simulations/ddr3-example.xml ../../DRAMSys/gem5/configs/singleElasticTraceReplayWithL2.ini 1 ``` -If two elastic traces should be used the main.cpp must be modified: - -```c++ -//#define CHOICE1 -#define CHOICE2 -//#define CHOICE3 -``` - -Run the simulation with the following example: +If two elastic traces should be used run the simulation with the following example: ``` -./DRAMSys_gem5 ../../DRAMSys/library/resources/simulations/ddr3-example.xml ../../DRAMSys/gem5/configs/dualElasticTraceReplay.ini +./DRAMSys_gem5 ../../DRAMSys/library/resources/simulations/ddr3-example.xml ../../DRAMSys/gem5/configs/dualElasticTraceReplay.ini 2 ``` An overview of the architcture being simulated is presented below: @@ -1738,8 +1734,6 @@ If you need help please contact Matthias Jung. Users can profit of running multiple simulations automatically with [gem5ilva](DRAMSys/library/resources/scripts/DRAMSylva/gem5ilva.sh). -Enjoy! - ## References [1] TLM Modelling of 3D Stacked Wide I/O DRAM Subsystems, A Virtual Platform for Memory Controller Design Space Exploration