gem5  v21.1.0.2
super_blk.cc
Go to the documentation of this file.
1 
36 
37 #include <climits>
38 #include <cmath>
39 
40 #include "base/bitfield.hh"
41 
42 namespace gem5
43 {
44 
46  : SectorSubBlk(), _size(0), _decompressionLatency(0), _compressed(false)
47 {
48 }
49 
50 CacheBlk&
52 {
53  operator=(std::move(static_cast<CompressionBlk&&>(other)));
54  return *this;
55 }
56 
59 {
60  // Copy internal variables; if moving, that means we had an expansion or
61  // contraction, and therefore the size is no longer valid, so it is not
62  // moved
63  setDecompressionLatency(other.getDecompressionLatency());
64  if (other.isCompressed()) {
65  setCompressed();
66  } else {
68  }
69 
70  CacheBlk::operator=(std::move(other));
71  return *this;
72 }
73 
74 bool
76 {
77  return _compressed;
78 }
79 
80 void
82 {
83  _compressed = true;
84 }
85 
86 void
88 {
89  _compressed = false;
90 }
91 
92 std::size_t
94 {
95  return _size;
96 }
97 
98 void
99 CompressionBlk::setSizeBits(const std::size_t size)
100 {
101  _size = size;
102 
103  SuperBlk* superblock = static_cast<SuperBlk*>(getSectorBlock());
104  const uint8_t compression_factor =
105  superblock->calculateCompressionFactor(size);
106  superblock->setCompressionFactor(compression_factor);
107 
108  // Either this function is called after an insertion, or an update.
109  // If somebody else is present in the block, keep the superblock's
110  // compressibility. Otherwise, check if it can co-allocate
111  const uint8_t num_valid = superblock->getNumValid();
112  assert(num_valid >= 1);
113  if (num_valid == 1) {
114  if (compression_factor != 1) {
115  setCompressed();
116  } else {
117  setUncompressed();
118  }
119  } else {
120  if (superblock->isCompressed(this)) {
121  setCompressed();
122  } else {
123  setUncompressed();
124  }
125  }
126 }
127 
128 Cycles
130 {
131  return _decompressionLatency;
132 }
133 
134 void
136 {
137  _decompressionLatency = lat;
138 }
139 
140 void
142 {
144  setUncompressed();
145 }
146 
148 CompressionBlk::checkExpansionContraction(const std::size_t size) const
149 {
150  // An expansion happens when a block passes from a compressible state
151  // to a less compressible state (e.g., blkSize/4 to (blkSize/2 or blkSize),
152  // or blkSize/2 to blkSize). A contraction happens when a block passes
153  // from a less compressible state to a more compressible state (i.e., the
154  // opposite of expansion)
155  const SuperBlk* superblock =
156  static_cast<const SuperBlk*>(getSectorBlock());
157  const uint8_t prev_cf = superblock->getCompressionFactor();
158  const uint8_t new_cf = superblock->calculateCompressionFactor(size);
159  return (new_cf < prev_cf) ? DATA_EXPANSION :
160  ((new_cf > prev_cf) ? DATA_CONTRACTION : UNCHANGED);
161 }
162 
163 std::string
165 {
166  return csprintf("%s compressed: %d size: %llu decompression latency: %d",
169 }
170 
172  : SectorBlk(), blkSize(0), compressionFactor(1)
173 {
174 }
175 
176 void
178 {
180  compressionFactor = 1;
181 }
182 
183 bool
184 SuperBlk::isCompressed(const CompressionBlk* ignored_blk) const
185 {
186  for (const auto& blk : blks) {
187  if (blk->isValid() && (blk != ignored_blk)) {
188  return static_cast<CompressionBlk*>(blk)->isCompressed();
189  }
190  }
191 
192  // An invalid block is seen as compressed
193  return true;
194 }
195 
196 bool
197 SuperBlk::canCoAllocate(const std::size_t compressed_size) const
198 {
199  // A YACC-like (Sardashti et al., 2016) co-allocation function: at most
200  // numBlocksPerSector blocks that compress at least to fit in the space
201  // allocated by its compression factor can share a superblock
202  return (getNumValid() < getCompressionFactor()) &&
203  (compressed_size <= (blkSize * CHAR_BIT) / getCompressionFactor());
204 }
205 
206 void
207 SuperBlk::setBlkSize(const std::size_t blk_size)
208 {
209  assert(blkSize == 0);
210  blkSize = blk_size;
211 }
212 
213 uint8_t
214 SuperBlk::calculateCompressionFactor(const std::size_t size) const
215 {
216  // The number of blocks per sector determines the maximum comp factor.
217  // If the compressed size is worse than the uncompressed size, we assume
218  // the size is the uncompressed size, and thus the compression factor is 1
219  const std::size_t blk_size_bits = CHAR_BIT * blkSize;
220  const std::size_t compression_factor = (size > blk_size_bits) ? 1 :
221  ((size == 0) ? blk_size_bits :
222  alignToPowerOfTwo(std::floor(double(blk_size_bits) / size)));
223  return std::min(compression_factor, blks.size());
224 }
225 
226 uint8_t
228 {
229  return compressionFactor;
230 }
231 
232 void
233 SuperBlk::setCompressionFactor(const uint8_t compression_factor)
234 {
235  // Either the block is alone, in which case the compression factor
236  // must be set, or it co-allocates with someone with a worse or
237  // equal compression factor, in which case it should not be updated
238  if (getNumValid() <= 1) {
239  compressionFactor = compression_factor;
240  }
241 }
242 
243 std::string
245 {
246  return csprintf("CF: %d %s", getCompressionFactor(), SectorBlk::print());
247 }
248 
249 } // namespace gem5
gem5::CompressionBlk::setSizeBits
void setSizeBits(const std::size_t size)
Set size, in bits, of this compressed block's data.
Definition: super_blk.cc:99
gem5::SuperBlk::blkSize
std::size_t blkSize
Block size, in bytes.
Definition: super_blk.hh:174
gem5::SuperBlk::compressionFactor
uint8_t compressionFactor
Superblock's compression factor.
Definition: super_blk.hh:181
gem5::SectorBlk
A Basic Sector block.
Definition: sector_blk.hh:134
gem5::CompressionBlk::getSizeBits
std::size_t getSizeBits() const
Definition: super_blk.cc:93
gem5::csprintf
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
gem5::SuperBlk::setCompressionFactor
void setCompressionFactor(const uint8_t compression_factor)
Set the compression factor of this superblock.
Definition: super_blk.cc:233
gem5::SuperBlk::getCompressionFactor
uint8_t getCompressionFactor() const
Get the compression factor of this superblock.
Definition: super_blk.cc:227
gem5::SuperBlk::calculateCompressionFactor
uint8_t calculateCompressionFactor(const std::size_t size) const
Calculate the compression factor (cf) given a compressed size and the maximum compression ratio.
Definition: super_blk.cc:214
gem5::SectorSubBlk::getSectorBlock
SectorBlk * getSectorBlock() const
Get sector block associated to this block.
Definition: sector_blk.cc:52
gem5::CompressionBlk::getDecompressionLatency
Cycles getDecompressionLatency() const
Get number of cycles needed to decompress this block.
Definition: super_blk.cc:129
gem5::SectorBlk::blks
std::vector< SectorSubBlk * > blks
List of blocks associated to this sector.
Definition: sector_blk.hh:147
gem5::CompressionBlk::DATA_EXPANSION
@ DATA_EXPANSION
New data contents are considered larger than previous contents.
Definition: super_blk.hh:81
gem5::CacheBlk
A Basic Cache block.
Definition: cache_blk.hh:70
gem5::Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:78
gem5::SuperBlk::SuperBlk
SuperBlk()
Definition: super_blk.cc:171
gem5::CompressionBlk::UNCHANGED
@ UNCHANGED
New and old contents are considered of similar sizes.
Definition: super_blk.hh:79
bitfield.hh
gem5::CompressionBlk::CompressionBlk
CompressionBlk()
Definition: super_blk.cc:45
gem5::CompressionBlk::print
std::string print() const override
Pretty-print sector offset and other CacheBlk information.
Definition: super_blk.cc:164
gem5::SuperBlk
A basic compression superblock.
Definition: super_blk.hh:170
gem5::CompressionBlk::setUncompressed
void setUncompressed()
Clear compression bit.
Definition: super_blk.cc:87
gem5::CompressionBlk::operator=
CompressionBlk & operator=(const CompressionBlk &)=delete
gem5::CompressionBlk::_decompressionLatency
Cycles _decompressionLatency
Number of cycles needed to decompress this block.
Definition: super_blk.hh:63
gem5::TaggedEntry::invalidate
virtual void invalidate()
Invalidate the block.
Definition: tagged_entry.hh:103
gem5::CompressionBlk::_compressed
bool _compressed
Compression bit.
Definition: super_blk.hh:66
gem5::CompressionBlk::invalidate
void invalidate() override
Invalidate the block and inform sector block.
Definition: super_blk.cc:141
gem5::CompressionBlk::setCompressed
void setCompressed()
Set compression bit.
Definition: super_blk.cc:81
gem5::SectorSubBlk::print
std::string print() const override
Pretty-print sector offset and other CacheBlk information.
Definition: sector_blk.cc:108
gem5::CompressionBlk::isCompressed
bool isCompressed() const
Check if this block holds compressed data.
Definition: super_blk.cc:75
super_blk.hh
Copyright (c) 2018 Inria All rights reserved.
gem5::SectorSubBlk::invalidate
void invalidate() override
Invalidate the block and inform sector block.
Definition: sector_blk.cc:101
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::CompressionBlk::checkExpansionContraction
OverwriteType checkExpansionContraction(const std::size_t size) const
Determines if changing the size of the block will cause a data expansion (new size is bigger) or cont...
Definition: super_blk.cc:148
gem5::SuperBlk::setBlkSize
void setBlkSize(const std::size_t blk_size)
Set block size.
Definition: super_blk.cc:207
gem5::CompressionBlk::DATA_CONTRACTION
@ DATA_CONTRACTION
New data contents are considered smaller than previous contents.
Definition: super_blk.hh:77
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::SuperBlk::invalidate
void invalidate() override
Invalidate the block.
Definition: super_blk.cc:177
gem5::CompressionBlk::OverwriteType
OverwriteType
When an overwrite happens, the data size may change an not fit in its current container any longer.
Definition: super_blk.hh:74
gem5::CompressionBlk::setDecompressionLatency
void setDecompressionLatency(const Cycles lat)
Set number of cycles needed to decompress this block.
Definition: super_blk.cc:135
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::CompressionBlk::_size
std::size_t _size
Set size, in bits, of this compressed block's data.
Definition: super_blk.hh:57
gem5::alignToPowerOfTwo
constexpr uint64_t alignToPowerOfTwo(uint64_t val)
Align to the next highest power of two.
Definition: bitfield.hh:372
gem5::SectorBlk::getNumValid
uint8_t getNumValid() const
Get the number of sub-blocks that have been validated.
Definition: sector_blk.cc:127
gem5::CacheBlk::operator=
CacheBlk & operator=(const CacheBlk &)=delete
gem5::SectorBlk::print
std::string print() const override
Print relevant information for this sector block and its sub-blocks.
Definition: sector_blk.cc:158

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