diff --git a/DRAMSys/simulator/src/controller/core/configuration/Configuration.cpp b/DRAMSys/simulator/src/controller/core/configuration/Configuration.cpp index 82ab0e7b..1ee8f80d 100644 --- a/DRAMSys/simulator/src/controller/core/configuration/Configuration.cpp +++ b/DRAMSys/simulator/src/controller/core/configuration/Configuration.cpp @@ -226,3 +226,21 @@ void Configuration::setParameters(std::map parameterMa } } +// Returns the total memory size in bytes +unsigned int Configuration::getSimMemSizeInBytes() +{ + // 1. Get number of banks, rows, columns and data width in bits for one die (or chip) + unsigned int banks = memSpec.NumberOfBanks; + unsigned int rows = memSpec.NumberOfRows; + unsigned int columns = memSpec.NumberOfColumns; + unsigned int bitWidth = memSpec.bitWidth; + // 2. Calculate size of one DRAM chip in bits + unsigned int chipBitSize = banks * rows * columns * bitWidth; + // 3. Calculate size of one DRAM chip in bytes + unsigned int chipSize = chipBitSize / 8; + // 4. Total memory size in Bytes of one DIMM (with only support of 1 rank on a DIMM) + unsigned int memorySize = chipSize * NumberOfDevicesOnDIMM; + + return memorySize; +} + diff --git a/DRAMSys/simulator/src/controller/core/configuration/Configuration.h b/DRAMSys/simulator/src/controller/core/configuration/Configuration.h index 7ee50b6d..8866620a 100644 --- a/DRAMSys/simulator/src/controller/core/configuration/Configuration.h +++ b/DRAMSys/simulator/src/controller/core/configuration/Configuration.h @@ -100,6 +100,8 @@ struct Configuration // Temperature Simulation related TemperatureSimConfig temperatureSim; + unsigned int getSimMemSizeInBytes(); + private: Configuration(); unsigned int powerDownTimeoutInClk = 3; diff --git a/DRAMSys/simulator/src/simulation/Dram.h b/DRAMSys/simulator/src/simulation/Dram.h index 8440487b..344d3805 100644 --- a/DRAMSys/simulator/src/simulation/Dram.h +++ b/DRAMSys/simulator/src/simulation/Dram.h @@ -98,19 +98,7 @@ struct Dram : sc_module SC_CTOR(Dram) : tSocket("socket") { - // calculate memory size (in Bytes) - // 1. Get number of banks, rows, columns and data width in bits - unsigned int banks = Configuration::getInstance().memSpec.NumberOfBanks; - unsigned int rows = Configuration::getInstance().memSpec.NumberOfRows; - unsigned int columns = Configuration::getInstance().memSpec.NumberOfColumns; - unsigned int bitWidth = Configuration::getInstance().memSpec.bitWidth; - // 2. Calculate size of one DRAM chip in bits - unsigned int chipBitSize = banks * rows * columns * bitWidth; - // 3. Calculate size of one DRAM chip in bytes - unsigned int chipSize = chipBitSize / 8; - // 4. Total memory size in Bytes of one DIMM (with only support of 1 rank on a DIMM) - unsigned int memorySize = chipSize * Configuration::getInstance().NumberOfDevicesOnDIMM; - + unsigned int memorySize = Configuration::getInstance().getSimMemSizeInBytes(); // 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);