Daniel Carvalho has uploaded this change for review. ( https://gem5-review.googlesource.com/9961

Change subject: mem-cache: Add block address to CacheBlk
......................................................................

mem-cache: Add block address to CacheBlk

If an address is badly regenerated, it breaks the simulator.
This can happen if a tag or a set are set incorrectly, but
with the addition of skewed caches, sector caches, and compressed
caches, more variables will be taken into account. As the user
will be able to implement different compression techniques, they
will likely modify the address regeneration function.

Besides, as the tempBlock is manually set, it does not need to be
aware of set and tag, as they're only used to regenerate the original
address.

Change-Id: Iaffb10c323509722cd5589fe1030b818d43336d6
---
M src/mem/cache/blk.hh
M src/mem/cache/cache.cc
M src/mem/cache/cache.hh
M src/mem/cache/tags/base.cc
M src/mem/cache/tags/base_set_assoc.hh
M src/mem/cache/tags/fa_lru.hh
6 files changed, 63 insertions(+), 8 deletions(-)



diff --git a/src/mem/cache/blk.hh b/src/mem/cache/blk.hh
index 694e531..f593ad7 100644
--- a/src/mem/cache/blk.hh
+++ b/src/mem/cache/blk.hh
@@ -89,6 +89,12 @@
     /** The current status of this block. @sa CacheBlockStatusBits */
     State _status;

+    /**
+     * Copy of the block's address, used to assert correctness of address
+     * block regeneration and regenerate tmpBlock's address.
+     */
+    Addr _addr;
+
   public:
     /** Task Id associated with this block */
     uint32_t task_id;
@@ -223,6 +229,7 @@
      */
     virtual void invalidate()
     {
+        _addr = MaxAddr;
         tag = MaxAddr;
         task_id = ContextSwitchTaskId::Unknown;
         _status = 0;
@@ -293,6 +300,26 @@
     }

     /**
+     * Set block's address.
+     *
+     * @param addr Address value.
+     */
+    void setAddr(const Addr addr)
+    {
+        _addr = addr;
+    }
+
+    /**
+     * Get block's address.
+     *
+     * @param addr Address value.
+     */
+    Addr getAddr() const
+    {
+        return _addr;
+    }
+
+    /**
      * Track the fact that a local locked was issued to the
      * block. Invalidate any previous LL to the same address.
      */
diff --git a/src/mem/cache/cache.cc b/src/mem/cache/cache.cc
index 435f8ea..6d4b6b6 100644
--- a/src/mem/cache/cache.cc
+++ b/src/mem/cache/cache.cc
@@ -106,6 +106,16 @@
     BaseCache::regStats();
 }

+Addr
+Cache::regenerateBlkAddr(CacheBlk* blk)
+{
+    if (blk != tempBlock) {
+        return tags->regenerateBlkAddr(blk);
+    } else {
+        return tempBlock->getAddr();
+    }
+}
+
 void
 Cache::cmpAndSwap(CacheBlk *blk, PacketPtr pkt)
 {
@@ -1659,7 +1669,7 @@

     writebacks[Request::wbMasterId]++;

-    Request *req = new Request(tags->regenerateBlkAddr(blk), blkSize, 0,
+    Request *req = new Request(regenerateBlkAddr(blk), blkSize, 0,
                                Request::wbMasterId);
     if (blk->isSecure())
         req->setFlags(Request::SECURE);
@@ -1694,7 +1704,7 @@
 PacketPtr
 Cache::writecleanBlk(CacheBlk *blk, Request::Flags dest, PacketId id)
 {
-    Request *req = new Request(tags->regenerateBlkAddr(blk), blkSize, 0,
+    Request *req = new Request(regenerateBlkAddr(blk), blkSize, 0,
                                Request::wbMasterId);
     if (blk->isSecure()) {
         req->setFlags(Request::SECURE);
@@ -1737,7 +1747,7 @@
     assert(blk && blk->isValid() && !blk->isDirty());
     // Creating a zero sized write, a message to the snoop filter
     Request *req =
-        new Request(tags->regenerateBlkAddr(blk), blkSize, 0,
+        new Request(regenerateBlkAddr(blk), blkSize, 0,
                     Request::wbMasterId);
     if (blk->isSecure())
         req->setFlags(Request::SECURE);
@@ -1780,7 +1790,7 @@
     if (blk.isDirty()) {
         assert(blk.isValid());

-        Request request(tags->regenerateBlkAddr(&blk), blkSize, 0,
+        Request request(regenerateBlkAddr(&blk), blkSize, 0,
                         Request::funcMasterId);
         request.taskId(blk.task_id);
         if (blk.isSecure()) {
@@ -1824,7 +1834,7 @@
         return nullptr;

     if (blk->isValid()) {
-        Addr repl_addr = tags->regenerateBlkAddr(blk);
+        Addr repl_addr = regenerateBlkAddr(blk);
         MSHR *repl_mshr = mshrQueue.findMatch(repl_addr, blk->isSecure());
         if (repl_mshr) {
             // must be an outstanding upgrade or clean request
@@ -1904,8 +1914,7 @@
             // current request and then get rid of it
             assert(!tempBlock->isValid());
             blk = tempBlock;
-            tempBlock->set = tags->extractSet(addr);
-            tempBlock->tag = tags->extractTag(addr);
+            tempBlock->setAddr(addr);
             if (is_secure) {
                 tempBlock->setSecure();
             }
diff --git a/src/mem/cache/cache.hh b/src/mem/cache/cache.hh
index 7d28279..e89965a 100644
--- a/src/mem/cache/cache.hh
+++ b/src/mem/cache/cache.hh
@@ -73,6 +73,17 @@
  */
 class Cache : public BaseCache
 {
+  private:
+    /**
+     * Regenerate block address using tags.
+ * Block address regeneration depends on whether we're using a temporary
+     * block or not.
+     *
+     * @param blk The block to regenerate address.
+     * @return The block's address.
+     */
+    Addr regenerateBlkAddr(CacheBlk* blk);
+
   protected:

     /**
diff --git a/src/mem/cache/tags/base.cc b/src/mem/cache/tags/base.cc
index 2f8d428..d37aada 100644
--- a/src/mem/cache/tags/base.cc
+++ b/src/mem/cache/tags/base.cc
@@ -109,6 +109,9 @@
     // to insert the new one
     tagsInUse++;

+    // Set address for new block
+    blk->setAddr(blkAlign(addr));
+
     // Set tag for new block.  Caller is responsible for setting status.
     blk->tag = extractTag(addr);

diff --git a/src/mem/cache/tags/base_set_assoc.hh b/src/mem/cache/tags/base_set_assoc.hh
index eede070..9f5ce90 100644
--- a/src/mem/cache/tags/base_set_assoc.hh
+++ b/src/mem/cache/tags/base_set_assoc.hh
@@ -281,7 +281,10 @@
      */
     Addr regenerateBlkAddr(const CacheBlk* blk) const override
     {
-        return ((blk->tag << tagShift) | ((Addr)blk->set << setShift));
+ Addr addr = ((blk->tag << tagShift) | ((Addr)blk->set << setShift));
+        panic_if(blk->getAddr() != addr,
+            "Regenerated block address does not match original address.");
+        return addr;
     }

     /**
diff --git a/src/mem/cache/tags/fa_lru.hh b/src/mem/cache/tags/fa_lru.hh
index 73d6660..e21ac3e 100644
--- a/src/mem/cache/tags/fa_lru.hh
+++ b/src/mem/cache/tags/fa_lru.hh
@@ -261,6 +261,8 @@
      */
     Addr regenerateBlkAddr(const CacheBlk* blk) const override
     {
+        panic_if(blk->getAddr() != blk->tag,
+            "Regenerated block address does not match original address.");
         return blk->tag;
     }


--
To view, visit https://gem5-review.googlesource.com/9961
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: Iaffb10c323509722cd5589fe1030b818d43336d6
Gerrit-Change-Number: 9961
Gerrit-PatchSet: 1
Gerrit-Owner: Daniel Carvalho <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to