From 90de6ec2217a221a215d6e613849cd24c857da92 Mon Sep 17 00:00:00 2001 From: "Daniel R. Carvalho" Date: Thu, 22 Aug 2019 11:50:10 +0200 Subject: [PATCH] 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 Maintainer: Nikos Nikoleris Tested-by: kokoro --- src/mem/cache/base.cc | 29 ++++++--------------------- src/mem/cache/tags/compressed_tags.cc | 22 -------------------- src/mem/cache/tags/compressed_tags.hh | 8 -------- src/mem/cache/tags/super_blk.cc | 21 +++++++++++++++++++ 4 files changed, 27 insertions(+), 53 deletions(-) diff --git a/src/mem/cache/base.cc b/src/mem/cache/base.cc index 09c810a7e..98467ab98 100644 --- a/src/mem/cache/base.cc +++ b/src/mem/cache/base.cc @@ -853,12 +853,6 @@ BaseCache::updateCompressionData(CacheBlk *&blk, const uint64_t* data, CompressionBlk* compression_blk = static_cast(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(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* superblock = static_cast( 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; } diff --git a/src/mem/cache/tags/compressed_tags.cc b/src/mem/cache/tags/compressed_tags.cc index 780c738f9..f71dedacd 100644 --- a/src/mem/cache/tags/compressed_tags.cc +++ b/src/mem/cache/tags/compressed_tags.cc @@ -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(blk); - const SuperBlk* superblock = static_cast( - 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 visitor) { diff --git a/src/mem/cache/tags/compressed_tags.hh b/src/mem/cache/tags/compressed_tags.hh index 73231f2f5..306acd5b7 100644 --- a/src/mem/cache/tags/compressed_tags.hh +++ b/src/mem/cache/tags/compressed_tags.hh @@ -109,14 +109,6 @@ class CompressedTags : public SectorTags const std::size_t compressed_size, std::vector& 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. * diff --git a/src/mem/cache/tags/super_blk.cc b/src/mem/cache/tags/super_blk.cc index 9f7ce6552..09bb2073f 100644 --- a/src/mem/cache/tags/super_blk.cc +++ b/src/mem/cache/tags/super_blk.cc @@ -93,6 +93,27 @@ void CompressionBlk::setSizeBits(const std::size_t size) { _size = size; + + SuperBlk* superblock = static_cast(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 -- 2.30.2