gem5  v21.1.0.2
compressed_tags.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Inria
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
35 
36 #include "base/trace.hh"
37 #include "debug/CacheComp.hh"
41 #include "mem/packet.hh"
42 #include "params/CompressedTags.hh"
43 
44 namespace gem5
45 {
46 
48  : SectorTags(p)
49 {
50 }
51 
52 void
54 {
55  // Create blocks and superblocks
58 
59  // Initialize all blocks
60  unsigned blk_index = 0; // index into blks array
61  for (unsigned superblock_index = 0; superblock_index < numSectors;
62  superblock_index++)
63  {
64  // Locate next cache superblock
65  SuperBlk* superblock = &superBlks[superblock_index];
66 
67  // Superblocks must be aware of the block size due to their co-
68  // allocation conditions
69  superblock->setBlkSize(blkSize);
70 
71  // Associate a replacement data entry to the block
73 
74  // Initialize all blocks in this superblock
75  superblock->blks.resize(numBlocksPerSector, nullptr);
76  for (unsigned k = 0; k < numBlocksPerSector; ++k){
77  // Select block within the set to be linked
78  SectorSubBlk*& blk = superblock->blks[k];
79 
80  // Locate next cache block
81  blk = &blks[blk_index];
82 
83  // Associate a data chunk to the block
84  blk->data = &dataBlks[blkSize*blk_index];
85 
86  // Associate superblock to this block
87  blk->setSectorBlock(superblock);
88 
89  // Associate the superblock replacement data to this block
90  blk->replacementData = superblock->replacementData;
91 
92  // Set its index and sector offset
93  blk->setSectorOffset(k);
94 
95  // Update block index
96  ++blk_index;
97  }
98 
99  // Link block to indexing policy
100  indexingPolicy->setEntry(superblock, superblock_index);
101  }
102 }
103 
104 CacheBlk*
105 CompressedTags::findVictim(Addr addr, const bool is_secure,
106  const std::size_t compressed_size,
107  std::vector<CacheBlk*>& evict_blks)
108 {
109  // Get all possible locations of this superblock
110  const std::vector<ReplaceableEntry*> superblock_entries =
112 
113  // Check if the superblock this address belongs to has been allocated. If
114  // so, try co-allocating
115  Addr tag = extractTag(addr);
116  SuperBlk* victim_superblock = nullptr;
117  bool is_co_allocation = false;
118  const uint64_t offset = extractSectorOffset(addr);
119  for (const auto& entry : superblock_entries){
120  SuperBlk* superblock = static_cast<SuperBlk*>(entry);
121  if (superblock->matchTag(tag, is_secure) &&
122  !superblock->blks[offset]->isValid() &&
123  superblock->isCompressed() &&
124  superblock->canCoAllocate(compressed_size))
125  {
126  victim_superblock = superblock;
127  is_co_allocation = true;
128  break;
129  }
130  }
131 
132  // If the superblock is not present or cannot be co-allocated a
133  // superblock must be replaced
134  if (victim_superblock == nullptr){
135  // Choose replacement victim from replacement candidates
136  victim_superblock = static_cast<SuperBlk*>(
137  replacementPolicy->getVictim(superblock_entries));
138 
139  // The whole superblock must be evicted to make room for the new one
140  for (const auto& blk : victim_superblock->blks){
141  if (blk->isValid()) {
142  evict_blks.push_back(blk);
143  }
144  }
145  }
146 
147  // Get the location of the victim block within the superblock
148  SectorSubBlk* victim = victim_superblock->blks[offset];
149 
150  // It would be a hit if victim was valid in a co-allocation, and upgrades
151  // do not call findVictim, so it cannot happen
152  if (is_co_allocation){
153  assert(!victim->isValid());
154 
155  // Print all co-allocated blocks
156  DPRINTF(CacheComp, "Co-Allocation: offset %d of %s\n", offset,
157  victim_superblock->print());
158  }
159 
160  // Update number of sub-blocks evicted due to a replacement
161  sectorStats.evictionsReplacement[evict_blks.size()]++;
162 
163  return victim;
164 }
165 
166 void
167 CompressedTags::forEachBlk(std::function<void(CacheBlk &)> visitor)
168 {
169  for (CompressionBlk& blk : blks) {
170  visitor(blk);
171  }
172 }
173 
174 bool
175 CompressedTags::anyBlk(std::function<bool(CacheBlk &)> visitor)
176 {
177  for (CompressionBlk& blk : blks) {
178  if (visitor(blk)) {
179  return true;
180  }
181  }
182  return false;
183 }
184 
185 } // namespace gem5
compressed_tags.hh
gem5::SectorSubBlk::setSectorBlock
void setSectorBlock(SectorBlk *sector_blk)
Set sector block associated to this block.
Definition: sector_blk.cc:45
gem5::CompressedTags::CompressedTags
CompressedTags(const Params &p)
Construct and initialize this tag store.
Definition: compressed_tags.cc:47
gem5::SectorSubBlk::setSectorOffset
void setSectorOffset(const int sector_offset)
Set offset of this sub-block within the sector.
Definition: sector_blk.cc:58
gem5::TaggedEntry::matchTag
virtual bool matchTag(Addr tag, bool is_secure) const
Checks if the given tag information corresponds to this entry's.
Definition: tagged_entry.hh:81
std::vector
STL vector class.
Definition: stl.hh:37
gem5::BaseTags::numBlocks
const unsigned numBlocks
the number of blocks in the cache
Definition: base.hh:100
gem5::SectorBlk::blks
std::vector< SectorSubBlk * > blks
List of blocks associated to this sector.
Definition: sector_blk.hh:147
gem5::SectorTags::numBlocksPerSector
const unsigned numBlocksPerSector
Number of data blocks per sector.
Definition: sector_tags.hh:84
gem5::CacheBlk
A Basic Cache block.
Definition: cache_blk.hh:70
gem5::replacement_policy::Base::instantiateEntry
virtual std::shared_ptr< ReplacementData > instantiateEntry()=0
Instantiate a replacement data entry.
gem5::BaseIndexingPolicy::getPossibleEntries
virtual std::vector< ReplaceableEntry * > getPossibleEntries(const Addr addr) const =0
Find all possible entries for insertion and replacement of an address.
packet.hh
gem5::BaseTags::Params
BaseTagsParams Params
Definition: base.hh:161
base.hh
replaceable_entry.hh
gem5::SectorTags::sectorStats
gem5::SectorTags::SectorTagsStats sectorStats
gem5::CompressedTags::tagsInit
void tagsInit() override
Initialize blocks as SuperBlk and CompressionBlk instances.
Definition: compressed_tags.cc:53
gem5::SuperBlk
A basic compression superblock.
Definition: super_blk.hh:170
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:186
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
gem5::replacement_policy::Base::getVictim
virtual ReplaceableEntry * getVictim(const ReplacementCandidates &candidates) const =0
Find replacement victim among candidates.
gem5::CompressedTags::superBlks
std::vector< SuperBlk > superBlks
The cache superblocks.
Definition: compressed_tags.hh:76
gem5::SectorTags::replacementPolicy
replacement_policy::Base * replacementPolicy
Replacement policy.
Definition: sector_tags.hh:81
gem5::ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:144
gem5::BaseTags::extractTag
virtual Addr extractTag(const Addr addr) const
Generate the tag from the given address.
Definition: base.cc:143
gem5::CompressedTags::findVictim
CacheBlk * findVictim(Addr addr, const bool is_secure, const std::size_t compressed_size, std::vector< CacheBlk * > &evict_blks) override
Find replacement victim based on address.
Definition: compressed_tags.cc:105
base.hh
gem5::SectorTags::SectorTagsStats::evictionsReplacement
statistics::Vector evictionsReplacement
Number of sub-blocks evicted due to a replacement.
Definition: sector_tags.hh:106
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::CompressedTags::forEachBlk
void forEachBlk(std::function< void(CacheBlk &)> visitor) override
Visit each sub-block in the tags and apply a visitor.
Definition: compressed_tags.cc:167
gem5::CacheBlk::data
uint8_t * data
Contains a copy of the data in this block for easy access.
Definition: cache_blk.hh:103
gem5::SectorTags
A SectorTags cache tag store.
Definition: sector_tags.hh:65
gem5::SuperBlk::canCoAllocate
bool canCoAllocate(const std::size_t compressed_size) const
Checks whether a superblock can co-allocate given compressed data block.
Definition: super_blk.cc:197
gem5::CompressionBlk
A superblock is composed of sub-blocks, and each sub-block has information regarding its superblock a...
Definition: super_blk.hh:51
gem5::SectorSubBlk
A sector is composed of sub-blocks, and each sub-block has information regarding its sector and a poi...
Definition: sector_blk.hh:51
gem5::SuperBlk::print
std::string print() const override
Print relevant information for this sector block and its sub-blocks.
Definition: super_blk.cc:244
gem5::BaseIndexingPolicy::setEntry
void setEntry(ReplaceableEntry *entry, const uint64_t index)
Associate a pointer to an entry to its physical counterpart.
Definition: base.cc:81
gem5::SuperBlk::setBlkSize
void setBlkSize(const std::size_t blk_size)
Set block size.
Definition: super_blk.cc:207
gem5::CompressedTags::blks
std::vector< CompressionBlk > blks
The cache blocks.
Definition: compressed_tags.hh:74
gem5::BaseTags::blkSize
const unsigned blkSize
The block size of the cache.
Definition: base.hh:77
gem5::MipsISA::k
Bitfield< 23 > k
Definition: dt_constants.hh:81
gem5::ReplaceableEntry::replacementData
std::shared_ptr< replacement_policy::ReplacementData > replacementData
Replacement data associated to this entry.
Definition: replaceable_entry.hh:84
trace.hh
gem5::BaseTags::indexingPolicy
BaseIndexingPolicy * indexingPolicy
Indexing policy.
Definition: base.hh:89
gem5::SuperBlk::isCompressed
bool isCompressed(const CompressionBlk *ignored_blk=nullptr) const
Returns whether the superblock contains compressed blocks or not.
Definition: super_blk.cc:184
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::BaseTags::dataBlks
std::unique_ptr< uint8_t[]> dataBlks
The data blocks, 1 per cache block.
Definition: base.hh:103
gem5::SectorTags::numSectors
const unsigned numSectors
The number of sectors in the cache.
Definition: sector_tags.hh:87
gem5::SectorTags::extractSectorOffset
int extractSectorOffset(Addr addr) const
Calculate a block's offset in a sector from the address.
Definition: sector_tags.cc:326
gem5::TaggedEntry::isValid
virtual bool isValid() const
Checks if the entry is valid.
Definition: tagged_entry.hh:57
gem5::CompressedTags::anyBlk
bool anyBlk(std::function< bool(CacheBlk &)> visitor) override
Find if any of the sub-blocks satisfies a condition.
Definition: compressed_tags.cc:175
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84

Generated on Tue Sep 21 2021 12:25:30 for gem5 by doxygen 1.8.17