mem-cache: Add setters to validate and secure block

In order to allow polymorphism of the block these two
functions have been added, and all direct status
assignments to these bits have been substituted.

We also assert that the block has been invalidated
before insertion. Then the block is validated in
the insertion.

Change-Id: Ie7be42408721ad4c2c9dc880f82a62cb594f8668
Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/14362
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Maintainer: Nikos Nikoleris <nikos.nikoleris@arm.com>
This commit is contained in:
Daniel R. Carvalho
2018-10-25 17:26:02 +02:00
committed by Daniel Carvalho
parent d7409ddbaf
commit 24bfdc36f1
5 changed files with 44 additions and 23 deletions

19
src/mem/cache/base.cc vendored
View File

@@ -1004,7 +1004,7 @@ BaseCache::access(PacketPtr pkt, CacheBlk *&blk, Cycles &lat,
return false;
}
blk->status |= (BlkValid | BlkReadable);
blk->status |= BlkReadable;
}
// only mark the block dirty if we got a writeback command,
// and leave it as is for a clean writeback
@@ -1062,7 +1062,7 @@ BaseCache::access(PacketPtr pkt, CacheBlk *&blk, Cycles &lat,
return false;
}
blk->status |= (BlkValid | BlkReadable);
blk->status |= BlkReadable;
}
}
@@ -1149,26 +1149,23 @@ BaseCache::handleFill(PacketPtr pkt, CacheBlk *blk, PacketList &writebacks,
// No replaceable block or a mostly exclusive
// cache... just use temporary storage to complete the
// current request and then get rid of it
assert(!tempBlock->isValid());
blk = tempBlock;
tempBlock->insert(addr, is_secure);
DPRINTF(Cache, "using temp block for %#llx (%s)\n", addr,
is_secure ? "s" : "ns");
}
// we should never be overwriting a valid block
assert(!blk->isValid());
} else {
// existing block... probably an upgrade
assert(regenerateBlkAddr(blk) == addr);
assert(blk->isSecure() == is_secure);
// either we're getting new data or the block should already be valid
assert(pkt->hasData() || blk->isValid());
// don't clear block status... if block is already dirty we
// don't want to lose that
}
blk->status |= BlkValid | BlkReadable;
// Block is guaranteed to be valid at this point
assert(blk->isValid());
assert(blk->isSecure() == is_secure);
assert(regenerateBlkAddr(blk) == addr);
blk->status |= BlkReadable;
// sanity check for whole-line writes, which should always be
// marked as writable as part of the fill, and then later marked

View File

@@ -46,6 +46,9 @@ void
CacheBlk::insert(const Addr tag, const bool is_secure,
const int src_master_ID, const uint32_t task_ID)
{
// Make sure that the block has been properly invalidated
assert(status == 0);
// Set block tag
this->tag = tag;
@@ -63,10 +66,11 @@ CacheBlk::insert(const Addr tag, const bool is_secure,
// Set secure state
if (is_secure) {
status = BlkSecure;
} else {
status = 0;
setSecure();
}
// Validate block
setValid();
}
void

View File

@@ -243,11 +243,28 @@ class CacheBlk : public ReplaceableEntry
return (status & BlkSecure) != 0;
}
/**
* Set valid bit.
*/
virtual void setValid()
{
assert(!isValid());
status |= BlkValid;
}
/**
* Set secure bit.
*/
virtual void setSecure()
{
status |= BlkSecure;
}
/**
* 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.
* current tick. Marks the block valid.
*
* @param tag Block address tag.
* @param is_secure Whether the block is in secure space or not.
@@ -425,15 +442,19 @@ class TempCacheBlk final : public CacheBlk
void insert(const Addr addr, const bool is_secure,
const int src_master_ID=0, const uint32_t task_ID=0) override
{
// Make sure that the block has been properly invalidated
assert(status == 0);
// Set block address
_addr = addr;
// Set secure state
if (is_secure) {
status = BlkSecure;
} else {
status = 0;
setSecure();
}
// Validate block
setValid();
}
/**

View File

@@ -105,7 +105,7 @@ class SectorSubBlk : public CacheBlk
* 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.
* current tick. Marks the block valid.
*
* @param tag Block address tag.
* @param is_secure Whether the block is in secure space or not.

View File

@@ -171,16 +171,12 @@ SectorTags::insertBlock(const Addr addr, const bool is_secure,
const int src_master_ID, const uint32_t task_ID,
CacheBlk *blk)
{
// Do common block insertion functionality
BaseTags::insertBlock(addr, is_secure, src_master_ID, task_ID, blk);
// Get block's sector
SectorSubBlk* sub_blk = static_cast<SectorSubBlk*>(blk);
const SectorBlk* sector_blk = sub_blk->getSectorBlock();
// When a block is inserted, the tag is only a newly used tag if the
// sector was not previously present in the cache.
// This assumes BaseTags::insertBlock does not set the valid bit.
if (sector_blk->isValid()) {
// An existing entry's replacement data is just updated
replacementPolicy->touch(sector_blk->replacementData);
@@ -191,6 +187,9 @@ SectorTags::insertBlock(const Addr addr, const bool is_secure,
// A new entry resets the replacement data
replacementPolicy->reset(sector_blk->replacementData);
}
// Do common block insertion functionality
BaseTags::insertBlock(addr, is_secure, src_master_ID, task_ID, blk);
}
CacheBlk*