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


Change subject: mem-cache: Make block status private
......................................................................

mem-cache: Make block status private

Having different derived block caches is difficult due to the
fact that all its members are public.

Status has been modified to private, and its corresponding
setters have been created. A getStatus method has also been
provided.

Change-Id: I8438268d23d4925ed57cdf861896ee0439787963
---
M src/mem/cache/blk.hh
M src/mem/cache/cache.cc
2 files changed, 98 insertions(+), 63 deletions(-)



diff --git a/src/mem/cache/blk.hh b/src/mem/cache/blk.hh
index 65f32ff..64faac6 100644
--- a/src/mem/cache/blk.hh
+++ b/src/mem/cache/blk.hh
@@ -55,30 +55,38 @@
 #include "mem/request.hh"

 /**
- * Cache block status bit assignments
- */
-enum CacheBlkStatusBits : unsigned {
-    /** valid, readable */
-    BlkValid =          0x01,
-    /** write permission */
-    BlkWritable =       0x02,
-    /** read permission (yes, block can be valid but not readable) */
-    BlkReadable =       0x04,
-    /** dirty (modified) */
-    BlkDirty =          0x08,
-    /** block was a hardware prefetch yet unaccessed*/
-    BlkHWPrefetched =   0x20,
-    /** block holds data from the secure memory space */
-    BlkSecure =         0x40,
-};
-
-/**
  * A Basic Cache block.
  * Contains the tag, status, and a pointer to data.
  */
 class CacheBlk
 {
   public:
+    /** Block state: OR of CacheBlkStatusBit. */
+    typedef unsigned State;
+
+  private:
+    /**
+     * Cache block status bit assignments
+     */
+    enum CacheBlkStatusBits : unsigned {
+        /** valid, readable */
+        BlkValid =          0x01,
+        /** write permission */
+        BlkWritable =       0x02,
+        /** read permission (yes, block can be valid but not readable) */
+        BlkReadable =       0x04,
+        /** dirty (modified) */
+        BlkDirty =          0x08,
+        /** block was a hardware prefetch yet unaccessed*/
+        BlkHWPrefetched =   0x20,
+        /** block holds data from the secure memory space */
+        BlkSecure =         0x40,
+    };
+
+    /** The current status of this block. @sa CacheBlockStatusBits */
+    State _status;
+
+  public:
     /** Task Id associated with this block */
     uint32_t task_id;

@@ -93,12 +101,6 @@
      */
     uint8_t *data;

-    /** block state: OR of CacheBlkStatusBit */
-    typedef unsigned State;
-
-    /** The current status of this block. @sa CacheBlockStatusBits */
-    State status;
-
     /** Which curTick() will this block be accessible */
     Tick whenReady;

@@ -194,7 +196,7 @@
     bool isWritable() const
     {
         const State needed_bits = BlkWritable | BlkValid;
-        return (status & needed_bits) == needed_bits;
+        return (_status & needed_bits) == needed_bits;
     }

     /**
@@ -206,7 +208,7 @@
     bool isReadable() const
     {
         const State needed_bits = BlkReadable | BlkValid;
-        return (status & needed_bits) == needed_bits;
+        return (_status & needed_bits) == needed_bits;
     }

     /**
@@ -215,7 +217,7 @@
      */
     bool isValid() const
     {
-        return (status & BlkValid) != 0;
+        return (_status & BlkValid) != 0;
     }

     /**
@@ -225,7 +227,7 @@
     {
         tag = MaxAddr;
         task_id = ContextSwitchTaskId::Unknown;
-        status = 0;
+        _status = 0;
         whenReady = MaxTick;
         isTouched = false;
         refCount = 0;
@@ -240,7 +242,7 @@
      */
     bool isDirty() const
     {
-        return (status & BlkDirty) != 0;
+        return (_status & BlkDirty) != 0;
     }

     /**
@@ -250,7 +252,7 @@
      */
     bool wasPrefetched() const
     {
-        return (status & BlkHWPrefetched) != 0;
+        return (_status & BlkHWPrefetched) != 0;
     }

     /**
@@ -259,7 +261,37 @@
      */
     bool isSecure() const
     {
-        return (status & BlkSecure) != 0;
+        return (_status & BlkSecure) != 0;
+    }
+
+    /**
+     * Functions to set the correspondent flag bit in the block's status.
+     */
+    void setValid()        { _status |= BlkValid; }
+    void setWritable()     { _status |= BlkWritable; }
+    void setReadable()     { _status |= BlkReadable; }
+    void setDirty()        { _status |= BlkDirty; }
+    void setHWPrefetched() { _status |= BlkHWPrefetched; }
+    void setSecure()       { _status |= BlkSecure; }
+
+    /**
+     * Functions to clear the correspondent flag bit in the block's status.
+     */
+    void setNotValid()        { _status &= ~BlkValid; }
+    void setNotWritable()     { _status &= ~BlkWritable; }
+    void setNotReadable()     { _status &= ~BlkReadable; }
+    void setNotDirty()        { _status &= ~BlkDirty; }
+    void setNotHWPrefetched() { _status &= ~BlkHWPrefetched; }
+    void setNotSecure()       { _status &= ~BlkSecure; }
+
+    /**
+     * Get status flag.
+     *
+     * @return status of the block.
+     */
+    State getStatus() const
+    {
+        return _status;
     }

     /**
@@ -339,7 +371,7 @@
           default:    s = 'T'; break; // @TODO add other types
         }
return csprintf("state: %x (%c) valid: %d writable: %d readable: %d "
-                        "dirty: %d tag: %x", status, s, isValid(),
+                        "dirty: %d tag: %x", _status, s, isValid(),
                         isWritable(), isReadable(), isDirty(), tag);
     }

diff --git a/src/mem/cache/cache.cc b/src/mem/cache/cache.cc
index 28c4343..435f8ea 100644
--- a/src/mem/cache/cache.cc
+++ b/src/mem/cache/cache.cc
@@ -142,7 +142,7 @@

     if (overwrite_mem) {
         std::memcpy(blk_data, &overwrite_val, pkt->getSize());
-        blk->status |= BlkDirty;
+        blk->setDirty();
     }
 }

@@ -181,7 +181,7 @@
         // Modified state) even if we are a failed StoreCond so we
         // supply data to any snoops that have appended themselves to
         // this cache before knowing the store will fail.
-        blk->status |= BlkDirty;
+        blk->setDirty();
DPRINTF(CacheVerbose, "%s for %s (write)\n", __func__, pkt->print());
     } else if (pkt->isRead()) {
         if (pkt->isLLSC()) {
@@ -207,7 +207,7 @@
                 // keeps it marked dirty (in the modified state)
                 if (blk->isDirty()) {
                     pkt->setCacheResponding();
-                    blk->status &= ~BlkDirty;
+                    blk->setNotDirty();
                 }
             } else if (blk->isWritable() && !pending_downgrade &&
                        !pkt->hasSharers() &&
@@ -244,7 +244,7 @@
                         // the cache hierarchy through a cache,
                         // and first snoop upwards in all other
                         // branches
-                        blk->status &= ~BlkDirty;
+                        blk->setNotDirty();
                     } else {
                         // if we're responding after our own miss,
                         // there's a window where the recipient didn't
@@ -268,7 +268,7 @@
             // has the line in Shared state needs to be made aware
             // that the data it already has is in fact dirty
             pkt->setCacheResponding();
-            blk->status &= ~BlkDirty;
+            blk->setNotDirty();
         }
     } else {
         assert(pkt->isInvalidate());
@@ -397,22 +397,23 @@
             }
             tags->insertBlock(pkt, blk);

-            blk->status = (BlkValid | BlkReadable);
+            blk->setValid();
+            blk->setReadable();
             if (pkt->isSecure()) {
-                blk->status |= BlkSecure;
+                blk->setSecure();
             }
         }
         // only mark the block dirty if we got a writeback command,
         // and leave it as is for a clean writeback
         if (pkt->cmd == MemCmd::WritebackDirty) {
             assert(!blk->isDirty());
-            blk->status |= BlkDirty;
+            blk->setDirty();
         }
         // if the packet does not have sharers, it is passing
         // writable, and we got the writeback in Modified or Exclusive
         // state, if not we are in the Owned or Shared state
         if (!pkt->hasSharers()) {
-            blk->status |= BlkWritable;
+            blk->setWritable();
         }
         // nothing else to do; writeback doesn't expect response
         assert(!pkt->needsResponse());
@@ -460,9 +461,10 @@
                 }
                 tags->insertBlock(pkt, blk);

-                blk->status = (BlkValid | BlkReadable);
+                blk->setValid();
+                blk->setReadable();
                 if (pkt->isSecure()) {
-                    blk->status |= BlkSecure;
+                    blk->setSecure();
                 }
             }
         }
@@ -473,7 +475,7 @@
         assert(blk);
         assert(!blk->isDirty());
         if (!pkt->writeThrough()) {
-            blk->status |= BlkDirty;
+            blk->setDirty();
         }
         // nothing else to do; writeback doesn't expect response
         assert(!pkt->needsResponse());
@@ -779,7 +781,7 @@
         if (prefetcher && (prefetchOnAccess ||
                            (blk && blk->wasPrefetched()))) {
             if (blk)
-                blk->status &= ~BlkHWPrefetched;
+                blk->setNotHWPrefetched();

             // Don't notify on SWPrefetch
             if (!pkt->cmd.isSWPrefetch()) {
@@ -957,7 +959,7 @@
                     // point it must have seemed like we needed it...
                     assert((pkt->needsWritable() && !blk->isWritable()) ||
                            pkt->req->isCacheMaintenance());
-                    blk->status &= ~BlkReadable;
+                    blk->setNotReadable();
                 }
                 // Here we are using forward_time, modelling the latency of
                 // a miss (outbound) just as forwardLatency, neglecting the
@@ -1140,7 +1142,7 @@
                 bus_pkt->print());

 #if TRACING_ON
-        CacheBlk::State old_state = blk ? blk->status : 0;
+        CacheBlk::State old_state = blk ? blk->getStatus() : 0;
 #endif

         lat += ticksToCycles(memSidePort->sendAtomic(bus_pkt));
@@ -1415,7 +1417,7 @@
     // The block was marked as not readable while there was a pending
     // cache maintenance operation, restore its flag.
     if (pkt->isClean() && !is_invalidate && valid_blk) {
-        blk->status |= BlkReadable;
+        blk->setReadable();
     }

     // First offset for critical word first calculations
@@ -1548,7 +1550,7 @@
           case MSHR::Target::FromPrefetcher:
             assert(tgt_pkt->cmd == MemCmd::HardPFReq);
             if (blk)
-                blk->status |= BlkHWPrefetched;
+                blk->setHWPrefetched();
             delete tgt_pkt->req;
             delete tgt_pkt;
             break;
@@ -1587,7 +1589,7 @@
         if (is_invalidate || mshr->hasPostInvalidate()) {
             invalidateBlock(blk);
         } else if (mshr->hasPostDowngrade()) {
-            blk->status &= ~BlkWritable;
+            blk->setNotWritable();
         }
     }

@@ -1595,7 +1597,7 @@
         // avoid later read getting stale data while write miss is
         // outstanding.. see comment in timingAccess()
         if (blk) {
-            blk->status &= ~BlkReadable;
+            blk->setNotReadable();
         }
         mshrQueue.markPending(mshr);
         schedMemSideSendEvent(clockEdge() + pkt->payloadDelay);
@@ -1674,14 +1676,14 @@
     if (blk->isWritable()) {
         // not asserting shared means we pass the block in modified
         // state, mark our own block non-writeable
-        blk->status &= ~BlkWritable;
+        blk->setNotWritable();
     } else {
         // we are in the Owned state, tell the receiver
         pkt->setHasSharers();
     }

     // make sure the block is not marked dirty
-    blk->status &= ~BlkDirty;
+    blk->setNotDirty();

     pkt->allocate();
     pkt->setDataFromBlock(blk->data, blkSize);
@@ -1712,14 +1714,14 @@
     if (blk->isWritable()) {
         // not asserting shared means we pass the block in modified
         // state, mark our own block non-writeable
-        blk->status &= ~BlkWritable;
+        blk->setNotWritable();
     } else {
         // we are in the Owned state, tell the receiver
         pkt->setHasSharers();
     }

     // make sure the block is not marked dirty
-    blk->status &= ~BlkDirty;
+    blk->setNotDirty();

     pkt->allocate();
     pkt->setDataFromBlock(blk->data, blkSize);
@@ -1790,7 +1792,7 @@

         memSidePort->sendFunctional(&packet);

-        blk.status &= ~BlkDirty;
+        blk.setNotDirty();
     }

     return true;
@@ -1876,7 +1878,7 @@
     Addr addr = pkt->getAddr();
     bool is_secure = pkt->isSecure();
 #if TRACING_ON
-    CacheBlk::State old_state = blk ? blk->status : 0;
+    CacheBlk::State old_state = blk ? blk->getStatus() : 0;
 #endif

     // When handling a fill, we should have no writes to this line.
@@ -1905,7 +1907,7 @@
             tempBlock->set = tags->extractSet(addr);
             tempBlock->tag = tags->extractTag(addr);
             if (is_secure) {
-                tempBlock->status |= BlkSecure;
+                tempBlock->setSecure();
             }
             DPRINTF(Cache, "using temp block for %#llx (%s)\n", addr,
                     is_secure ? "s" : "ns");
@@ -1925,8 +1927,9 @@
     }

     if (is_secure)
-        blk->status |= BlkSecure;
-    blk->status |= BlkValid | BlkReadable;
+        blk->setSecure();
+    blk->setValid();
+    blk->setReadable();

     // sanity check for whole-line writes, which should always be
     // marked as writable as part of the fill, and then later marked
@@ -1946,14 +1949,14 @@
         // we could get a writable line from memory (rather than a
         // cache) even in a read-only cache, note that we set this bit
         // even for a read-only cache, possibly revisit this decision
-        blk->status |= BlkWritable;
+        blk->setWritable();

         // check if we got this via cache-to-cache transfer (i.e., from a
         // cache that had the block in Modified or Owned state)
         if (pkt->cacheResponding()) {
             // we got the block in Modified state, and invalidated the
             // owners copy
-            blk->status |= BlkDirty;
+            blk->setDirty();

chatty_assert(!isReadOnly, "Should never see dirty snoop response "
                           "in read-only cache %s\n", name());
@@ -2186,7 +2189,7 @@
         // below), remain in Owned (and will respond below), from
         // Exclusive to Shared, or remain in Shared
         if (!pkt->req->isUncacheable())
-            blk->status &= ~BlkWritable;
+            blk->setNotWritable();
         DPRINTF(Cache, "new state is %s\n", blk->print());
     }


--
To view, visit https://gem5-review.googlesource.com/9823
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: I8438268d23d4925ed57cdf861896ee0439787963
Gerrit-Change-Number: 9823
Gerrit-PatchSet: 1
Gerrit-Owner: Daniel Carvalho <oda...@yahoo.com.br>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to