cache = _cache;
}
+void
+BaseTags::insertBlock(PacketPtr pkt, CacheBlk *blk)
+{
+ // Get address
+ Addr addr = pkt->getAddr();
+
+ // Update warmup data
+ if (!blk->isTouched) {
+ if (!warmedUp && tagsInUse.value() >= warmupBound) {
+ warmedUp = true;
+ warmupCycle = curTick();
+ }
+ }
+
+ // If we're replacing a block that was previously valid update
+ // stats for it. This can't be done in findBlock() because a
+ // found block might not actually be replaced there if the
+ // coherence protocol says it can't be.
+ if (blk->isValid()) {
+ replacements[0]++;
+ totalRefs += blk->refCount;
+ ++sampledRefs;
+
+ invalidate(blk);
+ blk->invalidate();
+ }
+
+ // Previous block, if existed, has been removed, and now we have
+ // to insert the new one
+ tagsInUse++;
+
+ // Set tag for new block. Caller is responsible for setting status.
+ blk->tag = extractTag(addr);
+
+ // Deal with what we are bringing in
+ MasterID master_id = pkt->req->masterId();
+ assert(master_id < cache->system->maxMasters());
+ occupancies[master_id]++;
+ blk->srcMasterId = master_id;
+
+ // Set task id
+ blk->task_id = pkt->req->taskId();
+
+ // We only need to write into one tag and one data block.
+ tagAccesses += 1;
+ dataAccesses += 1;
+}
+
void
BaseTags::regStats()
{
virtual Addr extractTag(Addr addr) const = 0;
- virtual void insertBlock(PacketPtr pkt, CacheBlk *blk) = 0;
+ /**
+ * Insert the new block into the cache and update stats.
+ *
+ * @param pkt Packet holding the address to update
+ * @param blk The block to update.
+ */
+ virtual void insertBlock(PacketPtr pkt, CacheBlk *blk);
/**
* Regenerate the block address.
}
/**
- * Insert the new block into the cache.
+ * Insert the new block into the cache and update replacement data.
+ *
* @param pkt Packet holding the address to update
* @param blk The block to update.
*/
- void insertBlock(PacketPtr pkt, CacheBlk *blk) override
- {
- Addr addr = pkt->getAddr();
- MasterID master_id = pkt->req->masterId();
- uint32_t task_id = pkt->req->taskId();
-
- if (!blk->isTouched) {
- if (!warmedUp && tagsInUse.value() >= warmupBound) {
- warmedUp = true;
- warmupCycle = curTick();
- }
- }
-
- // If we're replacing a block that was previously valid update
- // stats for it. This can't be done in findBlock() because a
- // found block might not actually be replaced there if the
- // coherence protocol says it can't be.
- if (blk->isValid()) {
- replacements[0]++;
- totalRefs += blk->refCount;
- ++sampledRefs;
-
- invalidate(blk);
- blk->invalidate();
- }
-
- // Previous block, if existed, has been removed, and now we have
- // to insert the new one
- tagsInUse++;
-
- // Set tag for new block. Caller is responsible for setting status.
- blk->tag = extractTag(addr);
-
- // deal with what we are bringing in
- assert(master_id < cache->system->maxMasters());
- occupancies[master_id]++;
- blk->srcMasterId = master_id;
- blk->task_id = task_id;
-
- // We only need to write into one tag and one data block.
- tagAccesses += 1;
- dataAccesses += 1;
-
- replacementPolicy->reset(blk);
- }
+ void insertBlock(PacketPtr pkt, CacheBlk *blk) override
+ {
+ // Insert block
+ BaseTags::insertBlock(pkt, blk);
+
+ // Update replacement policy
+ replacementPolicy->reset(blk);
+ }
/**
* Limit the allocation for the cache ways.
{
// TODO: We need to move the block to the tail to make it the next victim
BaseTags::invalidate(blk);
+
+ // Erase block entry in the hash table
+ tagHash.erase(blk->tag);
}
CacheBlk*
CacheBlk*
FALRU::findVictim(Addr addr)
{
- FALRUBlk * blk = tail;
- assert(blk->inCache == 0);
- moveToHead(blk);
- tagHash.erase(blk->tag);
- tagHash[blkAlign(addr)] = blk;
- if (blk->isValid()) {
- replacements[0]++;
- } else {
- tagsInUse++;
- if (!warmedUp && tagsInUse.value() >= warmupBound) {
- warmedUp = true;
- warmupCycle = curTick();
- }
- }
- //assert(check());
-
- return blk;
+ return tail;
}
void
FALRU::insertBlock(PacketPtr pkt, CacheBlk *blk)
{
+ FALRUBlk* falruBlk = static_cast<FALRUBlk*>(blk);
+
+ // Make sure block is not present in the cache
+ assert(falruBlk->inCache == 0);
+
+ // Do common block insertion functionality
+ BaseTags::insertBlock(pkt, blk);
+
+ // New block is the MRU
+ moveToHead(falruBlk);
+
+ // Insert new block in the hash table
+ tagHash[falruBlk->tag] = falruBlk;
+
+ //assert(check());
}
void
*/
class FALRUBlk : public CacheBlk
{
-public:
+ public:
/** The previous block in LRU order. */
FALRUBlk *prev;
/** The next block in LRU order. */
* @}
*/
-public:
-
+ public:
typedef FALRUParams Params;
/**
*/
CacheBlk* findVictim(Addr addr) override;
+ /**
+ * Insert the new block into the cache and update replacement data.
+ *
+ * @param pkt Packet holding the address to update
+ * @param blk The block to update.
+ */
void insertBlock(PacketPtr pkt, CacheBlk *blk) override;
/**
return;
}
}
-
};
#endif // __MEM_CACHE_TAGS_FA_LRU_HH__