gem5 v24.0.0.0
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 Addr tag = extractTag(addr);
136 SuperBlk* victim_superblock = nullptr;
137 bool is_co_allocation = false;
138 const uint64_t offset = extractSectorOffset(addr);
139 for (const auto& entry : superblock_entries){
140 SuperBlk* superblock = static_cast<SuperBlk*>(entry);
141 if (superblock->matchTag(tag, is_secure) &&
142 !superblock->blks[offset]->isValid() &&
143 superblock->isCompressed() &&
144 superblock->canCoAllocate(compressed_size))
145 {
146 victim_superblock = superblock;
147 is_co_allocation = true;
148 break;
149 }
150 }
151
152 // If the superblock is not present or cannot be co-allocated a
153 // superblock must be replaced
154 if (victim_superblock == nullptr){
155 // check if partitioning policy limited allocation and if true - return
156 // this assumes that superblock_entries would not be empty if
157 // partitioning policy is not in place
158 if (superblock_entries.size() == 0){
159 return nullptr;
160 }
161
162 // Choose replacement victim from replacement candidates
163 victim_superblock = static_cast<SuperBlk*>(
164 replacementPolicy->getVictim(superblock_entries));
165
166 // The whole superblock must be evicted to make room for the new one
167 for (const auto& blk : victim_superblock->blks){
168 if (blk->isValid()) {
169 evict_blks.push_back(blk);
170 }
171 }
172 }
173
174 // Get the location of the victim block within the superblock
175 SectorSubBlk* victim = victim_superblock->blks[offset];
176
177 // It would be a hit if victim was valid in a co-allocation, and upgrades
178 // do not call findVictim, so it cannot happen
179 if (is_co_allocation){
180 assert(!victim->isValid());
181
182 // Print all co-allocated blocks
183 DPRINTF(CacheComp, "Co-Allocation: offset %d of %s\n", offset,
184 victim_superblock->print());
185 }
186
187 // Update number of sub-blocks evicted due to a replacement
188 sectorStats.evictionsReplacement[evict_blks.size()]++;
189
190 return victim;
191}
192
193bool
194CompressedTags::anyBlk(std::function<bool(CacheBlk &)> visitor)
195{
196 for (CompressionBlk& blk : blks) {
197 if (visitor(blk)) {
198 return true;
199 }
200 }
201 return false;
202}
203
204} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:210
void setEntry(ReplaceableEntry *entry, const uint64_t index)
Associate a pointer to an entry to its physical counterpart.
Definition base.cc:81
virtual std::vector< ReplaceableEntry * > getPossibleEntries(const Addr addr) const =0
Find all possible entries for insertion and replacement of an address.
partitioning_policy::PartitionManager * partitionManager
Partitioning manager.
Definition base.hh:92
virtual Addr extractTag(const Addr addr) const
Generate the tag from the given address.
Definition base.cc:147
const unsigned numBlocks
the number of blocks in the cache
Definition base.hh:103
BaseIndexingPolicy * indexingPolicy
Indexing policy.
Definition base.hh:89
std::unique_ptr< uint8_t[]> dataBlks
The data blocks, 1 per cache block.
Definition base.hh:106
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
virtual bool isValid() const
Checks if the entry is valid.
CompressedTags(const Params &p)
Construct and initialize this tag store.
CacheBlk * findVictim(Addr addr, const bool is_secure, const std::size_t compressed_size, std::vector< CacheBlk * > &evict_blks, const uint64_t partition_id) override
Find replacement victim based on address.
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.
A superblock is composed of sub-blocks, and each sub-block has information regarding its superblock a...
Definition super_blk.hh:52
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 matchTag(Addr tag, bool is_secure) 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
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
Declaration of the Packet class.
statistics::Vector evictionsReplacement
Number of sub-blocks evicted due to a replacement.

Generated on Tue Jun 18 2024 16:24:05 for gem5 by doxygen 1.11.0