gem5 v24.1.0.1
Loading...
Searching...
No Matches
compressed_tags.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023-2024 ARM Limited
3 * All rights reserved.
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2018 Inria
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 */
40
47
48#include "base/trace.hh"
49#include "debug/CacheComp.hh"
54#include "mem/packet.hh"
55#include "params/CompressedTags.hh"
56
57namespace gem5
58{
59
64
65void
67{
68 // Create blocks and superblocks
71
72 // Initialize all blocks
73 unsigned blk_index = 0; // index into blks array
74 for (unsigned superblock_index = 0; superblock_index < numSectors;
75 superblock_index++)
76 {
77 // Locate next cache superblock
78 SuperBlk* superblock = &superBlks[superblock_index];
79
80 // Superblocks must be aware of the block size due to their co-
81 // allocation conditions
82 superblock->setBlkSize(blkSize);
83
84 // Associate a replacement data entry to the block
86
87 // Initialize all blocks in this superblock
88 superblock->blks.resize(numBlocksPerSector, nullptr);
89 for (unsigned k = 0; k < numBlocksPerSector; ++k){
90 // Select block within the set to be linked
91 SectorSubBlk*& blk = superblock->blks[k];
92
93 // Locate next cache block
94 blk = &blks[blk_index];
95
96 // Associate a data chunk to the block
97 blk->data = &dataBlks[blkSize*blk_index];
98
99 // Associate superblock to this block
100 blk->setSectorBlock(superblock);
101
102 // Associate the superblock replacement data to this block
103 blk->replacementData = superblock->replacementData;
104
105 // Set its index and sector offset
106 blk->setSectorOffset(k);
107
108 // Update block index
109 ++blk_index;
110 }
111
112 // Link block to indexing policy
113 indexingPolicy->setEntry(superblock, superblock_index);
114 }
115}
116
119 const std::size_t compressed_size,
120 std::vector<CacheBlk*>& evict_blks,
121 const uint64_t partition_id=0)
122{
123 // Get all possible locations of this superblock
124 std::vector<ReplaceableEntry*> superblock_entries =
126
127 // Filter entries based on PartitionID
128 if (partitionManager){
129 partitionManager->filterByPartition(superblock_entries,
130 partition_id);
131 }
132
133 // Check if the superblock this address belongs to has been allocated. If
134 // so, try co-allocating
135 SuperBlk* victim_superblock = nullptr;
136 bool is_co_allocation = false;
137 const uint64_t offset = extractSectorOffset(key.address);
138 for (const auto& entry : superblock_entries){
139 SuperBlk* superblock = static_cast<SuperBlk*>(entry);
140 if (superblock->match(key) &&
141 !superblock->blks[offset]->isValid() &&
142 superblock->isCompressed() &&
143 superblock->canCoAllocate(compressed_size))
144 {
145 victim_superblock = superblock;
146 is_co_allocation = true;
147 break;
148 }
149 }
150
151 // If the superblock is not present or cannot be co-allocated a
152 // superblock must be replaced
153 if (victim_superblock == nullptr){
154 // check if partitioning policy limited allocation and if true - return
155 // this assumes that superblock_entries would not be empty if
156 // partitioning policy is not in place
157 if (superblock_entries.size() == 0){
158 return nullptr;
159 }
160
161 // Choose replacement victim from replacement candidates
162 victim_superblock = static_cast<SuperBlk*>(
163 replacementPolicy->getVictim(superblock_entries));
164
165 // The whole superblock must be evicted to make room for the new one
166 for (const auto& blk : victim_superblock->blks){
167 if (blk->isValid()) {
168 evict_blks.push_back(blk);
169 }
170 }
171 }
172
173 // Get the location of the victim block within the superblock
174 SectorSubBlk* victim = victim_superblock->blks[offset];
175
176 // It would be a hit if victim was valid in a co-allocation, and upgrades
177 // do not call findVictim, so it cannot happen
178 if (is_co_allocation){
179 assert(!victim->isValid());
180
181 // Print all co-allocated blocks
182 DPRINTF(CacheComp, "Co-Allocation: offset %d of %s\n", offset,
183 victim_superblock->print());
184 }
185
186 // Update number of sub-blocks evicted due to a replacement
187 sectorStats.evictionsReplacement[evict_blks.size()]++;
188
189 return victim;
190}
191
192bool
193CompressedTags::anyBlk(std::function<bool(CacheBlk &)> visitor)
194{
195 for (CompressionBlk& blk : blks) {
196 if (visitor(blk)) {
197 return true;
198 }
199 }
200 return false;
201}
202
203} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:209
partitioning_policy::PartitionManager * partitionManager
Partitioning manager.
Definition base.hh:92
const unsigned numBlocks
the number of blocks in the cache
Definition base.hh:103
std::unique_ptr< uint8_t[]> dataBlks
The data blocks, 1 per cache block.
Definition base.hh:106
TaggedIndexingPolicy * indexingPolicy
Indexing policy.
Definition base.hh:89
const unsigned blkSize
The block size of the cache.
Definition base.hh:77
A Basic Cache block.
Definition cache_blk.hh:72
uint8_t * data
Contains a copy of the data in this block for easy access.
Definition cache_blk.hh:104
CompressedTags(const Params &p)
Construct and initialize this tag store.
void tagsInit() override
Initialize blocks as SuperBlk and CompressionBlk instances.
std::vector< CompressionBlk > blks
The cache blocks.
bool anyBlk(std::function< bool(CacheBlk &)> visitor) override
Find if any of the sub-blocks satisfies a condition.
CompressedTagsParams Params
Convenience typedef.
std::vector< SuperBlk > superBlks
The cache superblocks.
CacheBlk * findVictim(const CacheBlk::KeyType &key, const std::size_t compressed_size, std::vector< CacheBlk * > &evict_blks, const uint64_t partition_id) override
Find replacement victim based on address.
A superblock is composed of sub-blocks, and each sub-block has information regarding its superblock a...
Definition super_blk.hh:52
virtual std::vector< ReplaceableEntry * > getPossibleEntries(const KeyType &key) const =0
Find all possible entries for insertion and replacement of an address.
void setEntry(ReplaceableEntry *entry, const uint64_t index)
Associate a pointer to an entry to its physical counterpart.
Definition base.hh:142
std::shared_ptr< replacement_policy::ReplacementData > replacementData
Replacement data associated to this entry.
std::vector< SectorSubBlk * > blks
List of blocks associated to this sector.
A sector is composed of sub-blocks, and each sub-block has information regarding its sector and a poi...
Definition sector_blk.hh:52
void setSectorBlock(SectorBlk *sector_blk)
Set sector block associated to this block.
Definition sector_blk.cc:45
void setSectorOffset(const int sector_offset)
Set offset of this sub-block within the sector.
Definition sector_blk.cc:58
A SectorTags cache tag store.
replacement_policy::Base * replacementPolicy
Replacement policy.
gem5::SectorTags::SectorTagsStats sectorStats
int extractSectorOffset(Addr addr) const
Calculate a block's offset in a sector from the address.
const unsigned numSectors
The number of sectors in the cache.
const unsigned numBlocksPerSector
Number of data blocks per sector.
A basic compression superblock.
Definition super_blk.hh:171
std::string print() const override
Print relevant information for this sector block and its sub-blocks.
Definition super_blk.cc:244
bool isCompressed(const CompressionBlk *ignored_blk=nullptr) const
Returns whether the superblock contains compressed blocks or not.
Definition super_blk.cc:184
void setBlkSize(const std::size_t blk_size)
Set block size.
Definition super_blk.cc:207
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
virtual bool isValid() const
Checks if the entry is valid.
bool match(const KeyType &key) const
Checks if the given tag information corresponds to this entry's.
void filterByPartition(std::vector< ReplaceableEntry * > &entries, const uint64_t partition_id) const
virtual ReplaceableEntry * getVictim(const ReplacementCandidates &candidates) const =0
Find replacement victim among candidates.
virtual std::shared_ptr< ReplacementData > instantiateEntry()=0
Instantiate a replacement data entry.
STL vector class.
Definition stl.hh:37
Declaration of a compressed set associative tag store using superblocks.
Declaration of a common framework for indexing policies.
Bitfield< 23, 0 > offset
Definition types.hh:144
Bitfield< 0 > p
Bitfield< 23 > k
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
Declaration of the Packet class.
statistics::Vector evictionsReplacement
Number of sub-blocks evicted due to a replacement.

Generated on Mon Jan 13 2025 04:28:38 for gem5 by doxygen 1.9.8