From 0b0629cda6cbb4fdc1c1087c762c27c426e8a1c9 Mon Sep 17 00:00:00 2001 From: "Daniel R. Carvalho" Date: Fri, 13 Apr 2018 17:12:36 +0200 Subject: [PATCH] mem-cache: Create block insertion function Create a block insertion function to be used when inserting blocks. This resets the number of references to 1 (the insertion is taken into account), sets the insertion tick, and set secure state. Change-Id: Ifc34cbbd1c125207ce47912d188809221c7a157e Reviewed-on: https://gem5-review.googlesource.com/9824 Reviewed-by: Nikos Nikoleris Maintainer: Nikos Nikoleris --- src/mem/cache/blk.cc | 30 ++++++++++++++++++++++++++++++ src/mem/cache/blk.hh | 14 ++++++++++++++ src/mem/cache/cache.cc | 10 ++-------- src/mem/cache/tags/base.cc | 14 +++----------- 4 files changed, 49 insertions(+), 19 deletions(-) diff --git a/src/mem/cache/blk.cc b/src/mem/cache/blk.cc index 9475bda31..233f38052 100644 --- a/src/mem/cache/blk.cc +++ b/src/mem/cache/blk.cc @@ -42,6 +42,36 @@ #include "base/cprintf.hh" +void +CacheBlk::insert(const Addr tag, const State is_secure, + const int src_master_ID, const uint32_t task_ID) +{ + // Touch block + isTouched = true; + + // Set block tag + this->tag = tag; + + // Set source requestor ID + srcMasterId = src_master_ID; + + // Set task ID + task_id = task_ID; + + // Set insertion tick as current tick + tickInserted = curTick(); + + // Insertion counts as a reference to the block + refCount = 1; + + // Set secure state + if (is_secure) { + status = BlkSecure; + } else { + status = 0; + } +} + void CacheBlkPrintWrapper::print(std::ostream &os, int verbosity, const std::string &prefix) const diff --git a/src/mem/cache/blk.hh b/src/mem/cache/blk.hh index b57c61b63..b634d21f1 100644 --- a/src/mem/cache/blk.hh +++ b/src/mem/cache/blk.hh @@ -252,6 +252,20 @@ class CacheBlk : public ReplaceableEntry return (status & BlkSecure) != 0; } + /** + * Set member variables when a block insertion occurs. Resets reference + * count to 1 (the insertion counts as a reference), and touch block if + * it hadn't been touched previously. Sets the insertion tick to the + * current tick. Does not make block valid. + * + * @param tag Block address tag. + * @param is_secure Whether the block is in secure space or not. + * @param src_master_ID The source requestor ID. + * @param task_ID The new task ID. + */ + void insert(const Addr tag, const State is_secure, const int src_master_ID, + const uint32_t task_ID); + /** * 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 28c4343d1..2d3ab8312 100644 --- a/src/mem/cache/cache.cc +++ b/src/mem/cache/cache.cc @@ -397,10 +397,7 @@ Cache::access(PacketPtr pkt, CacheBlk *&blk, Cycles &lat, } tags->insertBlock(pkt, blk); - blk->status = (BlkValid | BlkReadable); - if (pkt->isSecure()) { - blk->status |= BlkSecure; - } + blk->status |= (BlkValid | BlkReadable); } // only mark the block dirty if we got a writeback command, // and leave it as is for a clean writeback @@ -460,10 +457,7 @@ Cache::access(PacketPtr pkt, CacheBlk *&blk, Cycles &lat, } tags->insertBlock(pkt, blk); - blk->status = (BlkValid | BlkReadable); - if (pkt->isSecure()) { - blk->status |= BlkSecure; - } + blk->status |= (BlkValid | BlkReadable); } } diff --git a/src/mem/cache/tags/base.cc b/src/mem/cache/tags/base.cc index 2f8d428c7..1d6ed4663 100644 --- a/src/mem/cache/tags/base.cc +++ b/src/mem/cache/tags/base.cc @@ -100,26 +100,18 @@ BaseTags::insertBlock(PacketPtr pkt, CacheBlk *blk) blk->invalidate(); } - // Touch block - blk->isTouched = true; - blk->refCount = 1; - blk->tickInserted = curTick(); - // 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(); + // Insert block with tag, src master id and task id + blk->insert(extractTag(addr), pkt->isSecure(), master_id, + pkt->req->taskId()); // We only need to write into one tag and one data block. tagAccesses += 1; -- 2.30.2