Fix LFU implementation
While at it make some alignment changes.
This commit is contained in:
parent
5af8a0c2af
commit
bfcc9d4080
1 changed files with 29 additions and 28 deletions
57
src/mem/cache/tags/lfu.cc
vendored
57
src/mem/cache/tags/lfu.cc
vendored
|
@ -20,36 +20,37 @@ LFU::LFU(const Params *p) : BaseSetAssoc(p)
|
|||
CacheBlk*
|
||||
LFU::accessBlock(Addr addr, bool is_secure, Cycles &lat, int master_id)
|
||||
{
|
||||
CacheBlk *blk = BaseSetAssoc::accessBlock(addr,
|
||||
CacheBlk *blk = BaseSetAssoc::accessBlock(addr,
|
||||
is_secure, lat, master_id);
|
||||
|
||||
return blk;
|
||||
return blk;
|
||||
}
|
||||
|
||||
CacheBlk*
|
||||
LFU::findVictim(Addr addr)
|
||||
{
|
||||
int set = extractSet(addr);
|
||||
int minimum;
|
||||
|
||||
BlkType *blk = nullptr;
|
||||
for (int i = 0; i < allocAssoc; ++i) {
|
||||
BlkType *b = sets[set].blks[i];
|
||||
if (i == 0) {
|
||||
minimum = b->refCount;
|
||||
blk = b;
|
||||
}
|
||||
else if (b->refCount < minimum) {
|
||||
minimum = b->refCount;
|
||||
blk = b;
|
||||
}
|
||||
}
|
||||
assert(!blk || blk->way < allocAssoc);
|
||||
CacheBlk *blk = BaseSetAssoc::findVictim(addr);
|
||||
unsigned set = extractSet(addr);
|
||||
unsigned minimum;
|
||||
|
||||
if (blk && blk->isValid()) {
|
||||
DPRINTF(CacheRepl,
|
||||
"set %x: selecting blk %x for replacement\n",
|
||||
set, regenerateBlkAddr(blk->tag, set));
|
||||
BlkType *blk = nullptr;
|
||||
for (int i = 0; i < allocAssoc; ++i) {
|
||||
BlkType *b = sets[set].blks[i];
|
||||
if (i == 0) {
|
||||
minimum = b->refCount;
|
||||
blk = b;
|
||||
}
|
||||
else if (b->refCount < minimum) {
|
||||
minimum = b->refCount;
|
||||
blk = b;
|
||||
}
|
||||
}
|
||||
assert(!blk || blk->way < allocAssoc);
|
||||
|
||||
DPRINTF(CacheRepl,
|
||||
"set %x: selecting blk %x for replacement\n",
|
||||
set, regenerateBlkAddr(blk->tag, set));
|
||||
}
|
||||
|
||||
return blk;
|
||||
|
@ -58,23 +59,23 @@ LFU::findVictim(Addr addr)
|
|||
void
|
||||
LFU::insertBlock(PacketPtr pkt, BlkType *blk)
|
||||
{
|
||||
BaseSetAssoc::insertBlock(pkt, blk);
|
||||
BaseSetAssoc::insertBlock(pkt, blk);
|
||||
|
||||
int set = extractSet(pkt->getAddr());
|
||||
sets[set].moveToHead(blk);
|
||||
int set = extractSet(pkt->getAddr());
|
||||
sets[set].moveToHead(blk);
|
||||
}
|
||||
|
||||
void
|
||||
LFU::invalidate(CacheBlk *blk)
|
||||
{
|
||||
BaseSetAssoc::invalidate(blk);
|
||||
BaseSetAssoc::invalidate(blk);
|
||||
|
||||
int set = blk->set;
|
||||
sets[set].moveToTail(blk);
|
||||
int set = blk->set;
|
||||
sets[set].moveToTail(blk);
|
||||
}
|
||||
|
||||
LFU*
|
||||
LFUParams::create()
|
||||
{
|
||||
return new LFU(this);
|
||||
return new LFU(this);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue