* unmodified and in its entirety in all distributions of the software,
* modified or unmodified, in source code or in binary form.
*
+ * Copyright (c) 2020 Inria
* Copyright (c) 2007 The Regents of The University of Michigan
* All rights reserved.
*
#include "base/cprintf.hh"
+bool
+CacheBlk::matchTag(Addr tag, bool is_secure) const
+{
+ return isValid() && (getTag() == tag) && (isSecure() == is_secure);
+}
+
void
CacheBlk::insert(const Addr tag, const bool is_secure,
const int src_requestor_ID, const uint32_t task_ID)
assert(status == 0);
// Set block tag
- this->tag = tag;
+ setTag(tag);
// Set source requestor ID
srcRequestorId = src_requestor_ID;
* unmodified and in its entirety in all distributions of the software,
* modified or unmodified, in source code or in binary form.
*
+ * Copyright (c) 2020 Inria
* Copyright (c) 2003-2005 The Regents of The University of Michigan
* All rights reserved.
*
/** Task Id associated with this block */
uint32_t task_id;
- /** Data block tag value. */
- Addr tag;
/**
* Contains a copy of the data in this block for easy access. This is used
* for efficient execution when the data could be actually stored in
*/
virtual void invalidate()
{
- tag = MaxAddr;
+ setTag(MaxAddr);
task_id = ContextSwitchTaskId::Unknown;
status = 0;
whenReady = MaxTick;
return (status & BlkHWPrefetched) != 0;
}
+ /**
+ * Get tag associated to this block.
+ *
+ * @return The tag value.
+ */
+ virtual Addr getTag() const { return _tag; }
+
+ /**
+ * Set tag associated to this block.
+ *
+ * @param The tag value.
+ */
+ virtual void setTag(Addr tag) { _tag = tag; }
+
/**
* Check if this block holds data from the secure memory space.
* @return True if the block holds data from the secure memory space.
whenReady = tick;
}
+ /**
+ * Checks if the given information corresponds to this block's.
+ *
+ * @param tag The tag value to compare to.
+ * @param is_secure Whether secure bit is set.
+ */
+ virtual bool matchTag(Addr tag, bool is_secure) const;
+
/**
* Set member variables when a block insertion occurs. Resets reference
* count to 1 (the insertion counts as a reference), and touch block if
default: s = 'T'; break; // @TODO add other types
}
return csprintf("state: %x (%c) valid: %d writable: %d readable: %d "
- "dirty: %d | tag: %#x %s", status, s,
- isValid(), isWritable(), isReadable(), isDirty(), tag,
- ReplaceableEntry::print());
+ "dirty: %d | tag: %#x %s", status, s, isValid(), isWritable(),
+ isReadable(), isDirty(), getTag(), ReplaceableEntry::print());
}
/**
return true;
}
}
+
+ private:
+ /** Data block tag value. */
+ Addr _tag;
};
/**
// Search for block
for (const auto& location : entries) {
CacheBlk* blk = static_cast<CacheBlk*>(location);
- if ((blk->tag == tag) && blk->isValid() &&
- (blk->isSecure() == is_secure)) {
+ if (blk->matchTag(tag, is_secure)) {
return blk;
}
}
*/
Addr regenerateBlkAddr(const CacheBlk* blk) const override
{
- return indexingPolicy->regenerateAddr(blk->tag, blk);
+ return indexingPolicy->regenerateAddr(blk->getTag(), blk);
}
void forEachBlk(std::function<void(CacheBlk &)> visitor) override {
const uint64_t offset = extractSectorOffset(addr);
for (const auto& entry : superblock_entries){
SuperBlk* superblock = static_cast<SuperBlk*>(entry);
- if ((tag == superblock->getTag()) && superblock->isValid() &&
- (is_secure == superblock->isSecure()) &&
+ if (superblock->matchTag(tag, is_secure) &&
!superblock->blks[offset]->isValid() &&
superblock->isCompressed() &&
superblock->canCoAllocate(compressed_size))
{
// Erase block entry reference in the hash table
M5_VAR_USED auto num_erased =
- tagHash.erase(std::make_pair(blk->tag, blk->isSecure()));
+ tagHash.erase(std::make_pair(blk->getTag(), blk->isSecure()));
// Sanity check; only one block reference should be erased
assert(num_erased == 1);
}
if (blk && blk->isValid()) {
- assert(blk->tag == tag);
+ assert(blk->getTag() == tag);
assert(blk->isSecure() == is_secure);
}
moveToHead(falruBlk);
// Insert new block in the hash table
- tagHash[std::make_pair(blk->tag, blk->isSecure())] = falruBlk;
+ tagHash[std::make_pair(blk->getTag(), blk->isSecure())] = falruBlk;
}
void
*/
Addr regenerateBlkAddr(const CacheBlk* blk) const override
{
- return blk->tag;
+ return blk->getTag();
}
void forEachBlk(std::function<void(CacheBlk &)> visitor) override {
/**
- * Copyright (c) 2018 Inria
+ * Copyright (c) 2018, 2020 Inria
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Addr
SectorSubBlk::getTag() const
{
- return _sectorBlk->getTag();
+ // If the sub-block is valid its tag must match its sector's
+ const Addr tag = _sectorBlk->getTag();
+ assert(!isValid() || (CacheBlk::getTag() == tag));
+ return tag;
+}
+
+void
+SectorSubBlk::setTag(Addr tag)
+{
+ CacheBlk::setTag(tag);
+
+ // The sector block handles its own tag's invalidation
+ if (tag != MaxAddr) {
+ _sectorBlk->setTag(tag);
+ }
}
void
const int src_requestor_ID, const uint32_t task_ID)
{
// Make sure it is not overwriting another sector
- panic_if((_sectorBlk && _sectorBlk->isValid()) &&
- ((_sectorBlk->getTag() != tag) ||
- (_sectorBlk->isSecure() != is_secure)),
- "Overwriting valid sector!");
+ panic_if(_sectorBlk && _sectorBlk->isValid() &&
+ !_sectorBlk->matchTag(tag, is_secure), "Overwriting valid sector!");
CacheBlk::insert(tag, is_secure, src_requestor_ID, task_ID);
-
- // Set sector tag
- _sectorBlk->setTag(tag);
}
std::string
// so clear secure bit
if (--_validCounter == 0) {
_secureBit = false;
+ setTag(MaxAddr);
}
}
blk->setPosition(set, way);
}
}
+
+bool
+SectorBlk::matchTag(Addr tag, bool is_secure) const
+{
+ return isValid() && (getTag() == tag) && (isSecure() == is_secure);
+}
/**
- * Copyright (c) 2018 Inria
+ * Copyright (c) 2018, 2020 Inria
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*/
int getSectorOffset() const;
- /**
- * Get tag associated to this block.
- *
- * @return The tag value.
- */
- Addr getTag() const;
+ Addr getTag() const override;
+ void setTag(Addr tag) override;
/**
* Set valid bit and inform sector block.
* @param way The way of this entry and sub-entries.
*/
void setPosition(const uint32_t set, const uint32_t way) override;
+
+ /**
+ * Checks if the given information corresponds to this block's.
+ *
+ * @param tag The tag value to compare to.
+ * @param is_secure Whether secure bit is set.
+ */
+ virtual bool matchTag(Addr tag, bool is_secure) const;
};
#endif //__MEM_CACHE_TAGS_SECTOR_BLK_HH__
/*
- * Copyright (c) 2018 Inria
+ * Copyright (c) 2018, 2020 Inria
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
// Search for block
for (const auto& sector : entries) {
auto blk = static_cast<SectorBlk*>(sector)->blks[offset];
- if (blk->getTag() == tag && blk->isValid() &&
- blk->isSecure() == is_secure) {
+ if (blk->matchTag(tag, is_secure)) {
return blk;
}
}
SectorBlk* victim_sector = nullptr;
for (const auto& sector : sector_entries) {
SectorBlk* sector_blk = static_cast<SectorBlk*>(sector);
- if ((tag == sector_blk->getTag()) && sector_blk->isValid() &&
- (is_secure == sector_blk->isSecure())){
+ if (sector_blk->matchTag(tag, is_secure)) {
victim_sector = sector_blk;
break;
}
// Get evicted blocks. Blocks are only evicted if the sectors mismatch and
// the currently existing sector is valid.
- if ((tag == victim_sector->getTag()) &&
- (is_secure == victim_sector->isSecure())){
+ if (victim_sector->matchTag(tag, is_secure)) {
// It would be a hit if victim was valid, and upgrades do not call
// findVictim, so it cannot happen
assert(!victim->isValid());
{
const SectorSubBlk* blk_cast = static_cast<const SectorSubBlk*>(blk);
const SectorBlk* sec_blk = blk_cast->getSectorBlock();
- const Addr sec_addr = indexingPolicy->regenerateAddr(blk->tag, sec_blk);
+ const Addr sec_addr =
+ indexingPolicy->regenerateAddr(blk->getTag(), sec_blk);
return sec_addr | ((Addr)blk_cast->getSectorOffset() << sectorShift);
}