mem-cache: Set compression bit with its size
When setting the size of a compressed block, its compressibility needs to be recalculated based on that, so move such functionality to be done after the block has been inserted, within setSizeBits. As a side effect, insertBlock does not need to be overridden anymore. Change-Id: I608f876cd2110ac5e394ffad5b29941ba458ba91 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/36580 Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com> Maintainer: Nikos Nikoleris <nikos.nikoleris@arm.com> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
committed by
Daniel Carvalho
parent
68698e0bfd
commit
90de6ec221
29
src/mem/cache/base.cc
vendored
29
src/mem/cache/base.cc
vendored
@@ -853,12 +853,6 @@ BaseCache::updateCompressionData(CacheBlk *&blk, const uint64_t* data,
|
||||
CompressionBlk* compression_blk = static_cast<CompressionBlk*>(blk);
|
||||
M5_VAR_USED const std::size_t prev_size = compression_blk->getSizeBits();
|
||||
|
||||
// Check if new data is co-allocatable
|
||||
const SuperBlk* superblock =
|
||||
static_cast<const SuperBlk*>(compression_blk->getSectorBlock());
|
||||
const bool is_co_allocatable = superblock->isCompressed(compression_blk) &&
|
||||
superblock->canCoAllocate(compression_size);
|
||||
|
||||
// If compressed size didn't change enough to modify its co-allocatability
|
||||
// there is nothing to do. Otherwise we may be facing a data expansion
|
||||
// (block passing from more compressed to less compressed state), or a
|
||||
@@ -909,7 +903,7 @@ BaseCache::updateCompressionData(CacheBlk *&blk, const uint64_t* data,
|
||||
} else {
|
||||
// If we do not move the expanded block, we must make room for
|
||||
// the expansion to happen, so evict every co-allocated block
|
||||
superblock = static_cast<const SuperBlk*>(
|
||||
const SuperBlk* superblock = static_cast<const SuperBlk*>(
|
||||
compression_blk->getSectorBlock());
|
||||
for (auto& sub_blk : superblock->blks) {
|
||||
if (sub_blk->isValid() && (blk != sub_blk)) {
|
||||
@@ -945,17 +939,6 @@ BaseCache::updateCompressionData(CacheBlk *&blk, const uint64_t* data,
|
||||
compression_blk->setSizeBits(compression_size);
|
||||
compression_blk->setDecompressionLatency(decompression_lat);
|
||||
|
||||
if (is_data_expansion || is_data_contraction) {
|
||||
// If contracting data, for sure data is compressed. If expanding,
|
||||
// both situations can arise. When no contraction or expansion happens
|
||||
// block keeps its old state
|
||||
if (is_co_allocatable) {
|
||||
compression_blk->setCompressed();
|
||||
} else {
|
||||
compression_blk->setUncompressed();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1503,16 +1486,16 @@ BaseCache::allocateBlock(const PacketPtr pkt, PacketList &writebacks)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// If using a compressor, set compression data. This must be done before
|
||||
// block insertion, as compressed tags use this information.
|
||||
// Insert new block at victimized entry
|
||||
tags->insertBlock(pkt, victim);
|
||||
|
||||
// If using a compressor, set compression data. This must be done after
|
||||
// insertion, as the compression bit may be set.
|
||||
if (compressor) {
|
||||
compressor->setSizeBits(victim, blk_size_bits);
|
||||
compressor->setDecompressionLatency(victim, decompression_lat);
|
||||
}
|
||||
|
||||
// Insert new block at victimized entry
|
||||
tags->insertBlock(pkt, victim);
|
||||
|
||||
return victim;
|
||||
}
|
||||
|
||||
|
||||
22
src/mem/cache/tags/compressed_tags.cc
vendored
22
src/mem/cache/tags/compressed_tags.cc
vendored
@@ -164,28 +164,6 @@ CompressedTags::findVictim(Addr addr, const bool is_secure,
|
||||
return victim;
|
||||
}
|
||||
|
||||
void
|
||||
CompressedTags::insertBlock(const PacketPtr pkt, CacheBlk *blk)
|
||||
{
|
||||
// We check if block can co-allocate before inserting, because this check
|
||||
// assumes the block is still invalid
|
||||
CompressionBlk* compression_blk = static_cast<CompressionBlk*>(blk);
|
||||
const SuperBlk* superblock = static_cast<const SuperBlk*>(
|
||||
compression_blk->getSectorBlock());
|
||||
const bool is_co_allocatable = superblock->isCompressed() &&
|
||||
superblock->canCoAllocate(compression_blk->getSizeBits());
|
||||
|
||||
// Insert block
|
||||
SectorTags::insertBlock(pkt, blk);
|
||||
|
||||
// We always store compressed blocks when possible
|
||||
if (is_co_allocatable) {
|
||||
compression_blk->setCompressed();
|
||||
} else {
|
||||
compression_blk->setUncompressed();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CompressedTags::forEachBlk(std::function<void(CacheBlk &)> visitor)
|
||||
{
|
||||
|
||||
8
src/mem/cache/tags/compressed_tags.hh
vendored
8
src/mem/cache/tags/compressed_tags.hh
vendored
@@ -109,14 +109,6 @@ class CompressedTags : public SectorTags
|
||||
const std::size_t compressed_size,
|
||||
std::vector<CacheBlk*>& evict_blks) override;
|
||||
|
||||
/**
|
||||
* Insert the new block into the cache and update replacement data.
|
||||
*
|
||||
* @param pkt Packet holding the address to update
|
||||
* @param blk The block to update.
|
||||
*/
|
||||
void insertBlock(const PacketPtr pkt, CacheBlk *blk) override;
|
||||
|
||||
/**
|
||||
* Visit each sub-block in the tags and apply a visitor.
|
||||
*
|
||||
|
||||
21
src/mem/cache/tags/super_blk.cc
vendored
21
src/mem/cache/tags/super_blk.cc
vendored
@@ -93,6 +93,27 @@ void
|
||||
CompressionBlk::setSizeBits(const std::size_t size)
|
||||
{
|
||||
_size = size;
|
||||
|
||||
SuperBlk* superblock = static_cast<SuperBlk*>(getSectorBlock());
|
||||
|
||||
// Either this function is called after an insertion, or an update.
|
||||
// If somebody else is present in the block, keep the superblock's
|
||||
// compressibility. Otherwise, check if it can co-allocate
|
||||
const uint8_t num_valid = superblock->getNumValid();
|
||||
assert(num_valid >= 1);
|
||||
if (num_valid == 1) {
|
||||
if (superblock->canCoAllocate(size)) {
|
||||
setCompressed();
|
||||
} else {
|
||||
setUncompressed();
|
||||
}
|
||||
} else {
|
||||
if (superblock->isCompressed(this)) {
|
||||
setCompressed();
|
||||
} else {
|
||||
setUncompressed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Cycles
|
||||
|
||||
Reference in New Issue
Block a user