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*
|
CacheBlk*
|
||||||
LFU::accessBlock(Addr addr, bool is_secure, Cycles &lat, int master_id)
|
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);
|
is_secure, lat, master_id);
|
||||||
|
|
||||||
return blk;
|
return blk;
|
||||||
}
|
}
|
||||||
|
|
||||||
CacheBlk*
|
CacheBlk*
|
||||||
LFU::findVictim(Addr addr)
|
LFU::findVictim(Addr addr)
|
||||||
{
|
{
|
||||||
int set = extractSet(addr);
|
CacheBlk *blk = BaseSetAssoc::findVictim(addr);
|
||||||
int minimum;
|
unsigned set = extractSet(addr);
|
||||||
|
unsigned 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);
|
|
||||||
|
|
||||||
if (blk && blk->isValid()) {
|
if (blk && blk->isValid()) {
|
||||||
DPRINTF(CacheRepl,
|
BlkType *blk = nullptr;
|
||||||
"set %x: selecting blk %x for replacement\n",
|
for (int i = 0; i < allocAssoc; ++i) {
|
||||||
set, regenerateBlkAddr(blk->tag, set));
|
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;
|
return blk;
|
||||||
|
@ -58,23 +59,23 @@ LFU::findVictim(Addr addr)
|
||||||
void
|
void
|
||||||
LFU::insertBlock(PacketPtr pkt, BlkType *blk)
|
LFU::insertBlock(PacketPtr pkt, BlkType *blk)
|
||||||
{
|
{
|
||||||
BaseSetAssoc::insertBlock(pkt, blk);
|
BaseSetAssoc::insertBlock(pkt, blk);
|
||||||
|
|
||||||
int set = extractSet(pkt->getAddr());
|
int set = extractSet(pkt->getAddr());
|
||||||
sets[set].moveToHead(blk);
|
sets[set].moveToHead(blk);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
LFU::invalidate(CacheBlk *blk)
|
LFU::invalidate(CacheBlk *blk)
|
||||||
{
|
{
|
||||||
BaseSetAssoc::invalidate(blk);
|
BaseSetAssoc::invalidate(blk);
|
||||||
|
|
||||||
int set = blk->set;
|
int set = blk->set;
|
||||||
sets[set].moveToTail(blk);
|
sets[set].moveToTail(blk);
|
||||||
}
|
}
|
||||||
|
|
||||||
LFU*
|
LFU*
|
||||||
LFUParams::create()
|
LFUParams::create()
|
||||||
{
|
{
|
||||||
return new LFU(this);
|
return new LFU(this);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue