diff options
Diffstat (limited to 'src/mem/cache/tags')
-rw-r--r-- | src/mem/cache/tags/base.hh | 33 | ||||
-rw-r--r-- | src/mem/cache/tags/base_set_assoc.cc | 2 | ||||
-rw-r--r-- | src/mem/cache/tags/base_set_assoc.hh | 23 | ||||
-rw-r--r-- | src/mem/cache/tags/fa_lru.cc | 16 | ||||
-rw-r--r-- | src/mem/cache/tags/fa_lru.hh | 33 | ||||
-rw-r--r-- | src/mem/cache/tags/lru.cc | 10 | ||||
-rw-r--r-- | src/mem/cache/tags/lru.hh | 6 | ||||
-rw-r--r-- | src/mem/cache/tags/random_repl.cc | 10 | ||||
-rw-r--r-- | src/mem/cache/tags/random_repl.hh | 6 |
9 files changed, 81 insertions, 58 deletions
diff --git a/src/mem/cache/tags/base.hh b/src/mem/cache/tags/base.hh index 03b6cfed8..e4c0f68d8 100644 --- a/src/mem/cache/tags/base.hh +++ b/src/mem/cache/tags/base.hh @@ -53,6 +53,7 @@ #include "base/callback.hh" #include "base/statistics.hh" +#include "mem/cache/blk.hh" #include "params/BaseTags.hh" #include "sim/clocked_object.hh" @@ -179,6 +180,38 @@ class BaseTags : public ClockedObject * Print all tags used */ virtual std::string print() const = 0; + + /** + * Find a block using the memory address + */ + virtual CacheBlk * findBlock(Addr addr, bool is_secure) const = 0; + + /** + * Calculate the block offset of an address. + * @param addr the address to get the offset of. + * @return the block offset. + */ + int extractBlkOffset(Addr addr) const + { + return (addr & (Addr)(blkSize-1)); + } + + virtual void invalidate(CacheBlk *blk) = 0; + + virtual CacheBlk* accessBlock(Addr addr, bool is_secure, Cycles &lat, + int context_src) = 0; + + virtual Addr extractTag(Addr addr) const = 0; + + virtual void insertBlock(PacketPtr pkt, CacheBlk *blk) = 0; + + virtual Addr regenerateBlkAddr(Addr tag, unsigned set) const = 0; + + virtual CacheBlk* findVictim(Addr addr) = 0; + + virtual int extractSet(Addr addr) const = 0; + + virtual void forEachBlk(CacheBlkVisitor &visitor) = 0; }; class BaseTagsCallback : public Callback diff --git a/src/mem/cache/tags/base_set_assoc.cc b/src/mem/cache/tags/base_set_assoc.cc index 3c8371edb..c5ef9cc4b 100644 --- a/src/mem/cache/tags/base_set_assoc.cc +++ b/src/mem/cache/tags/base_set_assoc.cc @@ -119,7 +119,7 @@ BaseSetAssoc::~BaseSetAssoc() delete [] sets; } -BaseSetAssoc::BlkType* +CacheBlk* BaseSetAssoc::findBlock(Addr addr, bool is_secure) const { Addr tag = extractTag(addr); diff --git a/src/mem/cache/tags/base_set_assoc.hh b/src/mem/cache/tags/base_set_assoc.hh index 0107aafaf..79cfe756f 100644 --- a/src/mem/cache/tags/base_set_assoc.hh +++ b/src/mem/cache/tags/base_set_assoc.hh @@ -149,7 +149,7 @@ public: * Invalidate the given block. * @param blk The block to invalidate. */ - void invalidate(BlkType *blk) + void invalidate(CacheBlk *blk) { assert(blk); assert(blk->isValid()); @@ -172,7 +172,7 @@ public: * @param lat The access latency. * @return Pointer to the cache block if found. */ - BlkType* accessBlock(Addr addr, bool is_secure, Cycles &lat, + CacheBlk* accessBlock(Addr addr, bool is_secure, Cycles &lat, int context_src) { Addr tag = extractTag(addr); @@ -212,7 +212,7 @@ public: * @param asid The address space ID. * @return Pointer to the cache block if found. */ - BlkType* findBlock(Addr addr, bool is_secure) const; + CacheBlk* findBlock(Addr addr, bool is_secure) const; /** * Find an invalid block to evict for the address provided. @@ -221,7 +221,7 @@ public: * @param addr The addr to a find a replacement candidate for. * @return The candidate block. */ - BlkType* findVictim(Addr addr) const + CacheBlk* findVictim(Addr addr) { BlkType *blk = NULL; int set = extractSet(addr); @@ -242,7 +242,7 @@ public: * @param pkt Packet holding the address to update * @param blk The block to update. */ - void insertBlock(PacketPtr pkt, BlkType *blk) + void insertBlock(PacketPtr pkt, CacheBlk *blk) { Addr addr = pkt->getAddr(); MasterID master_id = pkt->req->masterId(); @@ -312,16 +312,6 @@ public: } /** - * Get the block offset from an address. - * @param addr The address to get the offset of. - * @return The block offset. - */ - int extractBlkOffset(Addr addr) const - { - return (addr & blkMask); - } - - /** * Align an address to the block size. * @param addr the address to align. * @return The block address. @@ -375,8 +365,7 @@ public: * * \param visitor Visitor to call on each block. */ - template <typename V> - void forEachBlk(V &visitor) { + void forEachBlk(CacheBlkVisitor &visitor) M5_ATTR_OVERRIDE { for (unsigned i = 0; i < numSets * assoc; ++i) { if (!visitor(blks[i])) return; diff --git a/src/mem/cache/tags/fa_lru.cc b/src/mem/cache/tags/fa_lru.cc index ffe2cbf25..8d4f75382 100644 --- a/src/mem/cache/tags/fa_lru.cc +++ b/src/mem/cache/tags/fa_lru.cc @@ -161,13 +161,19 @@ FALRU::hashLookup(Addr addr) const } void -FALRU::invalidate(FALRU::BlkType *blk) +FALRU::invalidate(CacheBlk *blk) { assert(blk); tagsInUse--; } -FALRUBlk* +CacheBlk* +FALRU::accessBlock(Addr addr, bool is_secure, Cycles &lat, int context_src) +{ + return accessBlock(addr, is_secure, lat, context_src, 0); +} + +CacheBlk* FALRU::accessBlock(Addr addr, bool is_secure, Cycles &lat, int context_src, int *inCache) { @@ -206,7 +212,7 @@ FALRU::accessBlock(Addr addr, bool is_secure, Cycles &lat, int context_src, } -FALRUBlk* +CacheBlk* FALRU::findBlock(Addr addr, bool is_secure) const { Addr blkAddr = blkAlign(addr); @@ -220,7 +226,7 @@ FALRU::findBlock(Addr addr, bool is_secure) const return blk; } -FALRUBlk* +CacheBlk* FALRU::findVictim(Addr addr) { FALRUBlk * blk = tail; @@ -243,7 +249,7 @@ FALRU::findVictim(Addr addr) } void -FALRU::insertBlock(PacketPtr pkt, FALRU::BlkType *blk) +FALRU::insertBlock(PacketPtr pkt, CacheBlk *blk) { } diff --git a/src/mem/cache/tags/fa_lru.hh b/src/mem/cache/tags/fa_lru.hh index 07a31c154..fd183ab03 100644 --- a/src/mem/cache/tags/fa_lru.hh +++ b/src/mem/cache/tags/fa_lru.hh @@ -174,7 +174,7 @@ public: * Invalidate a cache block. * @param blk The block to invalidate. */ - void invalidate(BlkType *blk); + void invalidate(CacheBlk *blk); /** * Access block and update replacement data. May not succeed, in which case @@ -188,8 +188,14 @@ public: * @param inCache The FALRUBlk::inCache flags. * @return Pointer to the cache block. */ - FALRUBlk* accessBlock(Addr addr, bool is_secure, Cycles &lat, - int context_src, int *inCache = 0); + CacheBlk* accessBlock(Addr addr, bool is_secure, Cycles &lat, + int context_src, int *inCache); + + /** + * Just a wrapper of above function to conform with the base interface. + */ + CacheBlk* accessBlock(Addr addr, bool is_secure, Cycles &lat, + int context_src); /** * Find the block in the cache, do not update the replacement data. @@ -198,16 +204,16 @@ public: * @param asid The address space ID. * @return Pointer to the cache block. */ - FALRUBlk* findBlock(Addr addr, bool is_secure) const; + CacheBlk* findBlock(Addr addr, bool is_secure) const; /** * Find a replacement block for the address provided. * @param pkt The request to a find a replacement candidate for. * @return The block to place the replacement in. */ - FALRUBlk* findVictim(Addr addr); + CacheBlk* findVictim(Addr addr); - void insertBlock(PacketPtr pkt, BlkType *blk); + void insertBlock(PacketPtr pkt, CacheBlk *blk); /** * Return the block size of this cache. @@ -261,22 +267,12 @@ public: } /** - * Calculate the block offset of an address. - * @param addr the address to get the offset of. - * @return the block offset. - */ - int extractBlkOffset(Addr addr) const - { - return (addr & (Addr)(blkSize-1)); - } - - /** * Regenerate the block address from the tag and the set. * @param tag The tag of the block. * @param set The set the block belongs to. * @return the block address. */ - Addr regenerateBlkAddr(Addr tag, int set) const + Addr regenerateBlkAddr(Addr tag, unsigned set) const { return (tag); } @@ -304,8 +300,7 @@ public: * * \param visitor Visitor to call on each block. */ - template <typename V> - void forEachBlk(V &visitor) { + void forEachBlk(CacheBlkVisitor &visitor) M5_ATTR_OVERRIDE { for (int i = 0; i < numBlocks; i++) { if (!visitor(blks[i])) return; diff --git a/src/mem/cache/tags/lru.cc b/src/mem/cache/tags/lru.cc index 290d1bdd0..f3a286602 100644 --- a/src/mem/cache/tags/lru.cc +++ b/src/mem/cache/tags/lru.cc @@ -54,10 +54,10 @@ LRU::LRU(const Params *p) { } -BaseSetAssoc::BlkType* +CacheBlk* LRU::accessBlock(Addr addr, bool is_secure, Cycles &lat, int master_id) { - BlkType *blk = BaseSetAssoc::accessBlock(addr, is_secure, lat, master_id); + CacheBlk *blk = BaseSetAssoc::accessBlock(addr, is_secure, lat, master_id); if (blk != NULL) { // move this block to head of the MRU list @@ -70,8 +70,8 @@ LRU::accessBlock(Addr addr, bool is_secure, Cycles &lat, int master_id) return blk; } -BaseSetAssoc::BlkType* -LRU::findVictim(Addr addr) const +CacheBlk* +LRU::findVictim(Addr addr) { int set = extractSet(addr); // grab a replacement candidate @@ -95,7 +95,7 @@ LRU::insertBlock(PacketPtr pkt, BlkType *blk) } void -LRU::invalidate(BlkType *blk) +LRU::invalidate(CacheBlk *blk) { BaseSetAssoc::invalidate(blk); diff --git a/src/mem/cache/tags/lru.hh b/src/mem/cache/tags/lru.hh index a034dd6ab..df5a8e39d 100644 --- a/src/mem/cache/tags/lru.hh +++ b/src/mem/cache/tags/lru.hh @@ -69,11 +69,11 @@ class LRU : public BaseSetAssoc */ ~LRU() {} - BlkType* accessBlock(Addr addr, bool is_secure, Cycles &lat, + CacheBlk* accessBlock(Addr addr, bool is_secure, Cycles &lat, int context_src); - BlkType* findVictim(Addr addr) const; + CacheBlk* findVictim(Addr addr); void insertBlock(PacketPtr pkt, BlkType *blk); - void invalidate(BlkType *blk); + void invalidate(CacheBlk *blk); }; #endif // __MEM_CACHE_TAGS_LRU_HH__ diff --git a/src/mem/cache/tags/random_repl.cc b/src/mem/cache/tags/random_repl.cc index 77b379135..e7422a335 100644 --- a/src/mem/cache/tags/random_repl.cc +++ b/src/mem/cache/tags/random_repl.cc @@ -44,16 +44,16 @@ RandomRepl::RandomRepl(const Params *p) { } -BaseSetAssoc::BlkType* +CacheBlk* RandomRepl::accessBlock(Addr addr, bool is_secure, Cycles &lat, int master_id) { return BaseSetAssoc::accessBlock(addr, is_secure, lat, master_id); } -BaseSetAssoc::BlkType* -RandomRepl::findVictim(Addr addr) const +CacheBlk* +RandomRepl::findVictim(Addr addr) { - BlkType *blk = BaseSetAssoc::findVictim(addr); + CacheBlk *blk = BaseSetAssoc::findVictim(addr); // if all blocks are valid, pick a replacement at random if (blk->isValid()) { @@ -77,7 +77,7 @@ RandomRepl::insertBlock(PacketPtr pkt, BlkType *blk) } void -RandomRepl::invalidate(BlkType *blk) +RandomRepl::invalidate(CacheBlk *blk) { BaseSetAssoc::invalidate(blk); } diff --git a/src/mem/cache/tags/random_repl.hh b/src/mem/cache/tags/random_repl.hh index 7f2795379..642c76777 100644 --- a/src/mem/cache/tags/random_repl.hh +++ b/src/mem/cache/tags/random_repl.hh @@ -58,11 +58,11 @@ class RandomRepl : public BaseSetAssoc */ ~RandomRepl() {} - BlkType* accessBlock(Addr addr, bool is_secure, Cycles &lat, + CacheBlk* accessBlock(Addr addr, bool is_secure, Cycles &lat, int context_src); - BlkType* findVictim(Addr addr) const; + CacheBlk* findVictim(Addr addr); void insertBlock(PacketPtr pkt, BlkType *blk); - void invalidate(BlkType *blk); + void invalidate(CacheBlk *blk); }; #endif // __MEM_CACHE_TAGS_RANDOM_REPL_HH__ |