Sparse Memory: Simplify the structure for an entry
The SparseMemEntry structure includes just one void* pointer. It seems unnecessary that we have a structure for this. The patch removes the structure and makes use of a typedef on void* instead.
This commit is contained in:
parent
cfa1d26b43
commit
adff204c97
2 changed files with 15 additions and 30 deletions
|
@ -82,19 +82,19 @@ SparseMemory::recursivelyRemoveTables(SparseMapType* curTable, int curLevel)
|
||||||
SparseMapType::iterator iter;
|
SparseMapType::iterator iter;
|
||||||
|
|
||||||
for (iter = curTable->begin(); iter != curTable->end(); iter++) {
|
for (iter = curTable->begin(); iter != curTable->end(); iter++) {
|
||||||
SparseMemEntry* entryStruct = &((*iter).second);
|
SparseMemEntry entry = (*iter).second;
|
||||||
|
|
||||||
if (curLevel != (m_number_of_levels - 1)) {
|
if (curLevel != (m_number_of_levels - 1)) {
|
||||||
// If the not at the last level, analyze those lower level
|
// If the not at the last level, analyze those lower level
|
||||||
// tables first, then delete those next tables
|
// tables first, then delete those next tables
|
||||||
SparseMapType* nextTable = (SparseMapType*)(entryStruct->entry);
|
SparseMapType* nextTable = (SparseMapType*)(entry);
|
||||||
recursivelyRemoveTables(nextTable, (curLevel + 1));
|
recursivelyRemoveTables(nextTable, (curLevel + 1));
|
||||||
delete nextTable;
|
delete nextTable;
|
||||||
} else {
|
} else {
|
||||||
// If at the last level, delete the directory entry
|
// If at the last level, delete the directory entry
|
||||||
delete (AbstractEntry*)(entryStruct->entry);
|
delete (AbstractEntry*)(entry);
|
||||||
}
|
}
|
||||||
entryStruct->entry = NULL;
|
entry = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Once all entries have been deleted, erase the entries
|
// Once all entries have been deleted, erase the entries
|
||||||
|
@ -134,7 +134,7 @@ SparseMemory::exist(const Address& address) const
|
||||||
// If the address is found, move on to the next level.
|
// If the address is found, move on to the next level.
|
||||||
// Otherwise, return not found
|
// Otherwise, return not found
|
||||||
if (curTable->count(curAddress) != 0) {
|
if (curTable->count(curAddress) != 0) {
|
||||||
curTable = (SparseMapType*)(((*curTable)[curAddress]).entry);
|
curTable = (SparseMapType*)((*curTable)[curAddress]);
|
||||||
} else {
|
} else {
|
||||||
DPRINTF(RubyCache, "Not found\n");
|
DPRINTF(RubyCache, "Not found\n");
|
||||||
return false;
|
return false;
|
||||||
|
@ -156,7 +156,6 @@ SparseMemory::add(const Address& address, AbstractEntry* entry)
|
||||||
|
|
||||||
Address curAddress;
|
Address curAddress;
|
||||||
SparseMapType* curTable = m_map_head;
|
SparseMapType* curTable = m_map_head;
|
||||||
SparseMemEntry* entryStruct = NULL;
|
|
||||||
|
|
||||||
// Initiallize the high bit to be the total number of bits plus
|
// Initiallize the high bit to be the total number of bits plus
|
||||||
// the block offset. However the highest bit index is one less
|
// the block offset. However the highest bit index is one less
|
||||||
|
@ -179,7 +178,7 @@ SparseMemory::add(const Address& address, AbstractEntry* entry)
|
||||||
// if the address exists in the cur table, move on. Otherwise
|
// if the address exists in the cur table, move on. Otherwise
|
||||||
// create a new table.
|
// create a new table.
|
||||||
if (curTable->count(curAddress) != 0) {
|
if (curTable->count(curAddress) != 0) {
|
||||||
curTable = (SparseMapType*)(((*curTable)[curAddress]).entry);
|
curTable = (SparseMapType*)((*curTable)[curAddress]);
|
||||||
} else {
|
} else {
|
||||||
m_adds_per_level[level]++;
|
m_adds_per_level[level]++;
|
||||||
|
|
||||||
|
@ -194,9 +193,7 @@ SparseMemory::add(const Address& address, AbstractEntry* entry)
|
||||||
|
|
||||||
// Create the pointer container SparseMemEntry and add it
|
// Create the pointer container SparseMemEntry and add it
|
||||||
// to the table.
|
// to the table.
|
||||||
entryStruct = new SparseMemEntry;
|
(*curTable)[curAddress] = newEntry;
|
||||||
entryStruct->entry = newEntry;
|
|
||||||
(*curTable)[curAddress] = *entryStruct;
|
|
||||||
|
|
||||||
// Move to the next level of the heirarchy
|
// Move to the next level of the heirarchy
|
||||||
curTable = (SparseMapType*)newEntry;
|
curTable = (SparseMapType*)newEntry;
|
||||||
|
@ -215,7 +212,7 @@ SparseMemory::recursivelyRemoveLevels(const Address& address,
|
||||||
{
|
{
|
||||||
Address curAddress;
|
Address curAddress;
|
||||||
CurNextInfo nextInfo;
|
CurNextInfo nextInfo;
|
||||||
SparseMemEntry* entryStruct;
|
SparseMemEntry entry;
|
||||||
|
|
||||||
// create the appropriate address for this level
|
// create the appropriate address for this level
|
||||||
// Note: that set Address is inclusive of the specified range,
|
// Note: that set Address is inclusive of the specified range,
|
||||||
|
@ -231,11 +228,11 @@ SparseMemory::recursivelyRemoveLevels(const Address& address,
|
||||||
|
|
||||||
assert(curInfo.curTable->count(curAddress) != 0);
|
assert(curInfo.curTable->count(curAddress) != 0);
|
||||||
|
|
||||||
entryStruct = &((*(curInfo.curTable))[curAddress]);
|
entry = (*(curInfo.curTable))[curAddress];
|
||||||
|
|
||||||
if (curInfo.level < (m_number_of_levels - 1)) {
|
if (curInfo.level < (m_number_of_levels - 1)) {
|
||||||
// set up next level's info
|
// set up next level's info
|
||||||
nextInfo.curTable = (SparseMapType*)(entryStruct->entry);
|
nextInfo.curTable = (SparseMapType*)(entry);
|
||||||
nextInfo.level = curInfo.level + 1;
|
nextInfo.level = curInfo.level + 1;
|
||||||
|
|
||||||
nextInfo.highBit = curInfo.highBit -
|
nextInfo.highBit = curInfo.highBit -
|
||||||
|
@ -252,15 +249,15 @@ SparseMemory::recursivelyRemoveLevels(const Address& address,
|
||||||
if (tableSize == 0) {
|
if (tableSize == 0) {
|
||||||
m_removes_per_level[curInfo.level]++;
|
m_removes_per_level[curInfo.level]++;
|
||||||
delete nextInfo.curTable;
|
delete nextInfo.curTable;
|
||||||
entryStruct->entry = NULL;
|
entry = NULL;
|
||||||
curInfo.curTable->erase(curAddress);
|
curInfo.curTable->erase(curAddress);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if this is the last level, we have reached the Directory
|
// if this is the last level, we have reached the Directory
|
||||||
// Entry and thus we should delete it including the
|
// Entry and thus we should delete it including the
|
||||||
// SparseMemEntry container struct.
|
// SparseMemEntry container struct.
|
||||||
delete (AbstractEntry*)(entryStruct->entry);
|
delete (AbstractEntry*)(entry);
|
||||||
entryStruct->entry = NULL;
|
entry = NULL;
|
||||||
curInfo.curTable->erase(curAddress);
|
curInfo.curTable->erase(curAddress);
|
||||||
m_removes_per_level[curInfo.level]++;
|
m_removes_per_level[curInfo.level]++;
|
||||||
}
|
}
|
||||||
|
@ -331,7 +328,7 @@ SparseMemory::lookup(const Address& address)
|
||||||
// If the address is found, move on to the next level.
|
// If the address is found, move on to the next level.
|
||||||
// Otherwise, return not found
|
// Otherwise, return not found
|
||||||
if (curTable->count(curAddress) != 0) {
|
if (curTable->count(curAddress) != 0) {
|
||||||
curTable = (SparseMapType*)(((*curTable)[curAddress]).entry);
|
curTable = (SparseMapType*)((*curTable)[curAddress]);
|
||||||
} else {
|
} else {
|
||||||
DPRINTF(RubyCache, "Not found\n");
|
DPRINTF(RubyCache, "Not found\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -36,11 +36,7 @@
|
||||||
#include "mem/ruby/common/Address.hh"
|
#include "mem/ruby/common/Address.hh"
|
||||||
#include "mem/ruby/common/Global.hh"
|
#include "mem/ruby/common/Global.hh"
|
||||||
|
|
||||||
struct SparseMemEntry
|
typedef void* SparseMemEntry;
|
||||||
{
|
|
||||||
void* entry;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef m5::hash_map<Address, SparseMemEntry> SparseMapType;
|
typedef m5::hash_map<Address, SparseMemEntry> SparseMapType;
|
||||||
|
|
||||||
struct CurNextInfo
|
struct CurNextInfo
|
||||||
|
@ -95,12 +91,4 @@ class SparseMemory
|
||||||
uint64_t* m_removes_per_level;
|
uint64_t* m_removes_per_level;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::ostream&
|
|
||||||
operator<<(std::ostream& out, const SparseMemEntry& obj)
|
|
||||||
{
|
|
||||||
out << "SparseMemEntry";
|
|
||||||
out << std::flush;
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // __MEM_RUBY_SYSTEM_SPARSEMEMORY_HH__
|
#endif // __MEM_RUBY_SYSTEM_SPARSEMEMORY_HH__
|
||||||
|
|
Loading…
Reference in a new issue