diff --git a/DRAMSys/dramSys/src/error/errormodel.cpp b/DRAMSys/dramSys/src/error/errormodel.cpp index 31f7f7f8..eeb312c1 100644 --- a/DRAMSys/dramSys/src/error/errormodel.cpp +++ b/DRAMSys/dramSys/src/error/errormodel.cpp @@ -36,6 +36,7 @@ #include "errormodel.h" #include #include +#include errorModel::errorModel(const char * name) { @@ -60,6 +61,39 @@ errorModel::errorModel(const char * name) // Parse data input: parseInputData(); prepareWeakCells(); + + // Test 1: + // If you want to test the function that get the number + // of bit errors for a given temperature and time + // uncomment the following lines: + // + //std::cout << "MAXTemp:" << maxTemperature << std::endl; + //std::cout << "MAXTime:" << maxTime << std::endl; + //getNumberOfFlips(45.0,sc_time(200.0,SC_MS)); + //getNumberOfFlips(45.0,sc_time(190.0,SC_MS)); + //getNumberOfFlips(45.0,sc_time(180.0,SC_MS)); + //getNumberOfFlips(75.0,sc_time(200.0,SC_MS)); + //getNumberOfFlips(75.0,sc_time(190.0,SC_MS)); + //getNumberOfFlips(75.0,sc_time(180.0,SC_MS)); + //getNumberOfFlips(85.0,sc_time(200.0,SC_MS)); + //getNumberOfFlips(85.0,sc_time(190.0,SC_MS)); + //getNumberOfFlips(85.0,sc_time(180.0,SC_MS)); + //getNumberOfFlips(88.0,sc_time(200.0,SC_MS)); + //getNumberOfFlips(88.0,sc_time(190.0,SC_MS)); + //getNumberOfFlips(88.0,sc_time(180.0,SC_MS)); + //getNumberOfFlips(89.0,sc_time(64.0,SC_MS)); + //getNumberOfFlips(89.0,sc_time(64.0,SC_MS)); + //getNumberOfFlips(89.0,sc_time(64.0,SC_MS)); + + // Test 2: + // X X X + // X 1 1 + // X 1 1 + //setTemperature(89); + //weakCells[0].bit = 0; + //weakCells[0].col = 0; + //weakCells[0].row = 0; + //weakCells[0].dependent = true; } errorModel::~errorModel() @@ -193,6 +227,7 @@ void errorModel::activate(unsigned int row) // Check if Bit has marked as flipped yet, if yes mark it as flipped if(weakCells[i].flipped == false) { + //std::cout << "Maked weakCell[" << i << "] as flipped" << std::endl; weakCells[i].flipped = true; } } @@ -238,12 +273,76 @@ void errorModel::activate(unsigned int row) // Flip the bit: tempByte = (tempByte & mask); + std::cout << "--- Bit Flipped:" + << " row: " << key.row + << " col: " << key.column + << " bit: " << weakCells[i].bit + << " ---"<< std::endl; + + numberOfBitErrorEvents++; + // Copy the modified byte back to the dataMap: memcpy(dataMap[key]+byte, &tempByte, 1); } else // if(weakCells[i].dependent == true) { - // TODO: dependet + // Get the neighbourhood of the bit and store it in the + // grid variable: + // | 0 1 2 | + // grid = | 3 4 5 | + // | 6 7 8 | + + unsigned int grid[9]; + + grid[0] = getBit(key.row-1,key.column,byte,bitInByte-1); + grid[1] = getBit(key.row-1,key.column,byte,bitInByte ); + grid[2] = getBit(key.row-1,key.column,byte,bitInByte+1); + + grid[3] = getBit(key.row ,key.column,byte,bitInByte-1); + grid[4] = getBit(key.row ,key.column,byte,bitInByte ); + grid[5] = getBit(key.row ,key.column,byte,bitInByte+1); + + grid[6] = getBit(key.row+1,key.column,byte,bitInByte-1); + grid[7] = getBit(key.row+1,key.column,byte,bitInByte ); + grid[8] = getBit(key.row+1,key.column,byte,bitInByte+1); + + unsigned int sum = 0; + for(int s = 0; s < 9; s++) + { + sum += grid[s]; + } + + if(sum <= 4) + { + // Load the affected byte to tempByte + memcpy(&tempByte, dataMap[key]+byte, 1); + + // Flip the bit: + tempByte = (tempByte & mask); + numberOfBitErrorEvents++; + + // Copy the modified byte back to the dataMap: + memcpy(dataMap[key]+byte, &tempByte, 1); + + std::cout << "--- Dependent Bit Flipped:" + << " row: " << key.row + << " col: " << key.column + << " bit: " << weakCells[i].bit + << " sum: " << sum + << " ---"<< std::endl; + std::cout << grid[0] << grid[1] << grid[2] << std::endl; + std::cout << grid[3] << grid[4] << grid[5] << std::endl; + std::cout << grid[6] << grid[7] << grid[8] << std::endl; + } + else + { + std::cout << "--- Dependent Bit NOT Flipped:" + << " row: " << key.row + << " col: " << key.column + << " bit: " << weakCells[i].bit + << " sum: " << sum + << " ---"<< std::endl; + } } } } @@ -252,10 +351,9 @@ void errorModel::activate(unsigned int row) lastRowAccess[row] = sc_time_stamp(); } -unsigned int errorModel::getBit(DecodedAddress key, unsigned int byte, unsigned int bitInByte) +// This method is used to get a bit with a key, usually for independent case: +unsigned int errorModel::getBit(DecodedAddress key, unsigned int byteInColumn, unsigned int bitInByte) { - // TODO: corner cases - // If the data was not writte by the produce yet it is zero: if(dataMap.count(key) == 0) { @@ -266,12 +364,78 @@ unsigned int errorModel::getBit(DecodedAddress key, unsigned int byte, unsigned unsigned char tempByte; // Copy affected byte to a temporal variable: - memcpy(&tempByte, dataMap[key]+byte, 1); + memcpy(&tempByte, dataMap[key]+byteInColumn, 1); unsigned char mask = pow(2, bitInByte); - return (byte & mask) >> bitInByte; + unsigned int result = (tempByte & mask) >> bitInByte; + std::bitset<8> x(mask); + std::cout << "mask = " << x + << " bitInByte = " << bitInByte + << " tempByte = " << (unsigned int)tempByte + << " result = " << result << std::endl; + return result; } } +// This method is used to get neighbourhoods, for the dependent case: +unsigned int errorModel::getBit(int row, int column, int byteInColumn, int bitInByte) +{ + // Border-Exception handling: + + // Switch the byte if bit under/overflow: + if(bitInByte < 0) + { + byteInColumn--; + bitInByte = 7; + } + else if(bitInByte >= 8) + { + byteInColumn++; + bitInByte = 0; + } + + // Switch the column if byte under/overflow + if(byteInColumn < 0) + { + column--; + byteInColumn = bytesPerColumn; + } + else if(byteInColumn >= int(byteInColumn)) + { + column++; + byteInColumn = 0; + } + + // If we switch the row we return 0 (culumn under/overflow) + if(column < 0) + { + return 0; + } + else if(column >= int(numberOfColumns)) + { + return 0; + } + + // Row over/underflow return 0 + if(row < 0) + { + return 0; + } + else if(row >= int(numberOfRows)) + { + return 0; + } + + DecodedAddress key; + key.bank = myBank; + key.bankgroup = myBankgroup; + key.channel = myChannel; + key.rank = myRank; + key.column = column; + key.row = row; + + getBit(key, byteInColumn, bitInByte); +} + void errorModel::setTemperature(double t) { temperature = t; @@ -455,30 +619,6 @@ void errorModel::prepareWeakCells() << "\tflip=" << weakCells[i].flipped << "\tdep=" << weakCells[i].dependent << std::endl; } - - - // Test: - // If you want to test the function that get the number - // of bit errors for a given temperature and time - // uncomment the following lines: - // - //std::cout << "MAXTemp:" << maxTemperature << std::endl; - //std::cout << "MAXTime:" << maxTime << std::endl; - //getNumberOfFlips(45.0,sc_time(200.0,SC_MS)); - //getNumberOfFlips(45.0,sc_time(190.0,SC_MS)); - //getNumberOfFlips(45.0,sc_time(180.0,SC_MS)); - //getNumberOfFlips(75.0,sc_time(200.0,SC_MS)); - //getNumberOfFlips(75.0,sc_time(190.0,SC_MS)); - //getNumberOfFlips(75.0,sc_time(180.0,SC_MS)); - //getNumberOfFlips(85.0,sc_time(200.0,SC_MS)); - //getNumberOfFlips(85.0,sc_time(190.0,SC_MS)); - //getNumberOfFlips(85.0,sc_time(180.0,SC_MS)); - //getNumberOfFlips(88.0,sc_time(200.0,SC_MS)); - //getNumberOfFlips(88.0,sc_time(190.0,SC_MS)); - //getNumberOfFlips(88.0,sc_time(180.0,SC_MS)); - //getNumberOfFlips(89.0,sc_time(64.0,SC_MS)); - //getNumberOfFlips(89.0,sc_time(64.0,SC_MS)); - //getNumberOfFlips(89.0,sc_time(64.0,SC_MS)); } // Retrieve number of flipping bits which fits best to temperature input and time since last refresh @@ -521,13 +661,14 @@ unsigned int errorModel::getNumberOfFlips(double temp, sc_time time) errors e = errorMap[nearestTemperature][nearestTime]; // Find nearest time: - std::cout << "XXX temp:" << temp + /* + std::cout << "ACT/REF temp:" << temp << " time:" << time << " nearestTemp:" << nearestTemperature << " nearestTime:" << nearestTime << " ind:" << e.independent << " dep:" << e.dependent << std::endl; - + */ return e.independent + e.dependent; } } diff --git a/DRAMSys/dramSys/src/error/errormodel.h b/DRAMSys/dramSys/src/error/errormodel.h index 7bba9022..2a729eb8 100644 --- a/DRAMSys/dramSys/src/error/errormodel.h +++ b/DRAMSys/dramSys/src/error/errormodel.h @@ -66,6 +66,7 @@ class errorModel // Online Parameters: double temperature; + unsigned int numberOfBitErrorEvents; // Private Methods: void parseInputData(); @@ -73,6 +74,7 @@ class errorModel unsigned int getNumberOfFlips(double temp, sc_time time); void setContext(DecodedAddress addr); unsigned int getBit(DecodedAddress key, unsigned int byte, unsigned int bitInByte); + unsigned int getBit(int row, int column, int byteInColumn, int bitInByte); // Input related data structures: