From d2ea359b505ea2625835921869c6cd2355f49d6a Mon Sep 17 00:00:00 2001 From: Johannes Feldmann Date: Wed, 21 Jun 2017 10:03:56 +0200 Subject: [PATCH] AdjustNumBytesAfterECC function added and used in DRAM.h and errormodel.h --- .../core/configuration/Configuration.cpp | 12 ++++++++ .../core/configuration/Configuration.h | 4 +++ DRAMSys/simulator/src/error/ecchamming.cpp | 28 +------------------ DRAMSys/simulator/src/error/errormodel.cpp | 6 ++-- DRAMSys/simulator/src/simulation/DRAMSys.cpp | 10 +++++-- DRAMSys/simulator/src/simulation/Dram.h | 4 +-- 6 files changed, 29 insertions(+), 35 deletions(-) diff --git a/DRAMSys/simulator/src/controller/core/configuration/Configuration.cpp b/DRAMSys/simulator/src/controller/core/configuration/Configuration.cpp index b5070da2..c77fe1f6 100644 --- a/DRAMSys/simulator/src/controller/core/configuration/Configuration.cpp +++ b/DRAMSys/simulator/src/controller/core/configuration/Configuration.cpp @@ -324,3 +324,15 @@ unsigned int Configuration::getBytesPerBurst() return bytesPerBurst; } +// Changes the number of bytes depeding on the ECC Controller. This function is needed for modules which get data directly or indirectly from the ECC Controller +unsigned int Configuration::adjustNumBytesAfterECC(unsigned nBytes) +{ + // Manipulate the number of bytes only if there is an ECC Controller selected + if(ECCMode == ECCControllerMode::Disabled) + return nBytes; + else + { + assert(pECC != nullptr); + return pECC->AllocationSize(nBytes); + } +} diff --git a/DRAMSys/simulator/src/controller/core/configuration/Configuration.h b/DRAMSys/simulator/src/controller/core/configuration/Configuration.h index 433bf73e..6823e590 100644 --- a/DRAMSys/simulator/src/controller/core/configuration/Configuration.h +++ b/DRAMSys/simulator/src/controller/core/configuration/Configuration.h @@ -45,6 +45,8 @@ #include "thermalSimConfig.h" #include "../../../common/Utils.h" +#include "../../../error/eccbaseclass.h" + enum class StorageMode{NoStorage, Store, ErrorModel}; enum class EPowerDownMode{NoPowerDown, Staggered, TimeoutPDN, TimeoutSREF}; @@ -84,6 +86,7 @@ struct Configuration unsigned int NumberOfDevicesOnDIMM = 1; bool CheckTLM2Protocol = false; ECCControllerMode ECCMode = ECCControllerMode::Disabled; + ECCBaseClass* pECC = nullptr; bool gem5 = false; unsigned long long int AddressOffset = 0; @@ -104,6 +107,7 @@ struct Configuration std::uint64_t getSimMemSizeInBytes(); unsigned int getDataBusWidth(); unsigned int getBytesPerBurst(); + unsigned int adjustNumBytesAfterECC(unsigned bytes); void setPathToResources(std::string path); std::string getPathToResources(); diff --git a/DRAMSys/simulator/src/error/ecchamming.cpp b/DRAMSys/simulator/src/error/ecchamming.cpp index d2427e3b..d2d1e466 100644 --- a/DRAMSys/simulator/src/error/ecchamming.cpp +++ b/DRAMSys/simulator/src/error/ecchamming.cpp @@ -48,18 +48,6 @@ void ECCHamming::Encode(const unsigned char* pDataIn, const unsigned nDataIn, un // Save hamming code + parity bit in the last byte codeword.Copy(&pDataOut[i*(m_nDatawordSize + m_nCodewordSize)+m_nDatawordSize]); } - - cout << "Encode:\r\n"; - for(unsigned i = 0; i < nDataIn; i++) - { - cout << setw(2) << setfill('0') << hex << uppercase << (int)pDataIn[i]; - } - cout << endl; - for(unsigned i = 0; i < nDataOut; i++) - { - cout << setw(2) << setfill('0') << hex << uppercase << (int)pDataOut[i]; - } - cout << endl << endl; } void ECCHamming::Decode(const unsigned char* pDataIn, const unsigned nDataIn, unsigned char* pDataOut, const unsigned nDataOut) @@ -88,9 +76,7 @@ void ECCHamming::Decode(const unsigned char* pDataIn, const unsigned nDataIn, un ECC::InsertCheckbits(dataword, codeword); ECC::InsertParityBit(dataword, codeword[7]); - dataword.Print(); - - // Reset codeword + // Reset codeword codeword = 0; // Calculate Checkbits again @@ -145,16 +131,4 @@ void ECCHamming::Decode(const unsigned char* pDataIn, const unsigned nDataIn, un // Copy data memcpy(&pDataOut[i*m_nDatawordSize], &pDataIn[i*(m_nDatawordSize + m_nCodewordSize)], m_nDatawordSize); } - - cout << "Decode:\r\n"; - for(unsigned i = 0; i < nDataIn; i++) - { - cout << setw(2) << setfill('0') << hex << uppercase << (int)pDataIn[i]; - } - cout << endl; - for(unsigned i = 0; i < nDataOut; i++) - { - cout << setw(2) << setfill('0') << hex << uppercase << (int)pDataOut[i]; - } - cout << endl << endl; } diff --git a/DRAMSys/simulator/src/error/errormodel.cpp b/DRAMSys/simulator/src/error/errormodel.cpp index c213acd9..e1010f6a 100644 --- a/DRAMSys/simulator/src/error/errormodel.cpp +++ b/DRAMSys/simulator/src/error/errormodel.cpp @@ -50,10 +50,8 @@ void errorModel::init() numberOfColumns = Configuration::getInstance().memSpec.NumberOfColumns; bytesPerColumn = xmlAddressDecoder::getInstance().amount["bytes"]; - if(Configuration::getInstance().ECCMode != ECCControllerMode::Disabled) - { - bytesPerColumn += bytesPerColumn>>3; - } + // Adjust number of bytes per column dynamically to the selected ecc controller + bytesPerColumn = Configuration::getInstance().adjustNumBytesAfterECC(bytesPerColumn); numberOfRows = Configuration::getInstance().memSpec.NumberOfRows; numberOfBitErrorEvents = 0; diff --git a/DRAMSys/simulator/src/simulation/DRAMSys.cpp b/DRAMSys/simulator/src/simulation/DRAMSys.cpp index f8b3754f..ac75db5b 100644 --- a/DRAMSys/simulator/src/simulation/DRAMSys.cpp +++ b/DRAMSys/simulator/src/simulation/DRAMSys.cpp @@ -60,7 +60,7 @@ DRAMSys::DRAMSys(sc_module_name __attribute__((unused)) name, string pathToResources) : tSocket("DRAMSys_tSocket") { // Initialize ecc pointer - ecc = 0; + ecc = nullptr; logo(); @@ -196,13 +196,18 @@ void DRAMSys::instantiateModules(const string &traceName, ecc = new ECCHamming("ECCHamming"); break; default: - ecc = 0; + ecc = nullptr; break; } + // Save ECC Controller into the configuration struct to adjust it dynamically + Configuration::getInstance().pECC = ecc; + + // Create arbiter arbiter = new Arbiter("arbiter"); arbiter->setTlmRecorders(tlmRecorders); + // Create DRAM for (size_t i = 0; i < Configuration::getInstance().NumberOfMemChannels; i++) @@ -232,6 +237,7 @@ void DRAMSys::bindSockets() // If ECC Controller enabled, put it between Trace and arbiter if(Configuration::getInstance().ECCMode != ECCControllerMode::Disabled) { + assert(ecc != nullptr); tSocket.bind(ecc->t_socket); ecc->i_socket.bind(arbiter->tSocket); } diff --git a/DRAMSys/simulator/src/simulation/Dram.h b/DRAMSys/simulator/src/simulation/Dram.h index d2759473..a1156096 100644 --- a/DRAMSys/simulator/src/simulation/Dram.h +++ b/DRAMSys/simulator/src/simulation/Dram.h @@ -92,8 +92,8 @@ struct Dram : sc_module SC_CTOR(Dram) : tSocket("socket") { - if(Configuration::getInstance().ECCMode != ECCControllerMode::Disabled) - bytesPerBurst += bytesPerBurst>>3; + // Adjust number of bytes per burst dynamically to the selected ecc controller + bytesPerBurst = Configuration::getInstance().adjustNumBytesAfterECC(bytesPerBurst); std::uint64_t memorySize = Configuration::getInstance().getSimMemSizeInBytes(); // allocate and model storage of one DRAM channel using memory map