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; --- 49 unchanged lines hidden (view full) --- 58 // Initialize all blocks 59 unsigned blk_index = 0; // index into blks array 60 for (unsigned superblock_index = 0; superblock_index < numSectors; 61 superblock_index++) 62 { 63 // Locate next cache superblock 64 SuperBlk* superblock = &superBlks[superblock_index]; 65 |
66 // Superblocks must be aware of the block size due to their co- 67 // allocation conditions 68 superblock->setBlkSize(blkSize); 69 |
70 // Link block to indexing policy 71 indexingPolicy->setEntry(superblock, superblock_index); 72 73 // Associate a replacement data entry to the block 74 superblock->replacementData = replacementPolicy->instantiateEntry(); 75 76 // Initialize all blocks in this superblock 77 superblock->blks.resize(numBlocksPerSector, nullptr); --- 17 unchanged lines hidden (view full) --- 95 blk->setSectorOffset(k); 96 97 // Update block index 98 ++blk_index; 99 } 100 } 101} 102 |
103CacheBlk* 104CompressedTags::findVictim(Addr addr, const bool is_secure, 105 const std::size_t compressed_size, 106 std::vector<CacheBlk*>& evict_blks) const 107{ 108 // Get all possible locations of this superblock 109 const std::vector<ReplaceableEntry*> superblock_entries = 110 indexingPolicy->getPossibleEntries(addr); --- 4 unchanged lines hidden (view full) --- 115 SuperBlk* victim_superblock = nullptr; 116 bool is_co_allocation = false; 117 const uint64_t offset = extractSectorOffset(addr); 118 for (const auto& entry : superblock_entries){ 119 SuperBlk* superblock = static_cast<SuperBlk*>(entry); 120 if ((tag == superblock->getTag()) && superblock->isValid() && 121 (is_secure == superblock->isSecure()) && 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 --- 27 unchanged lines hidden (view full) --- 160 } 161 162 return victim; 163} 164 165void 166CompressedTags::insertBlock(const PacketPtr pkt, CacheBlk *blk) 167{ |
168 // We check if block can co-allocate before inserting, because this check 169 // assumes the block is still invalid 170 CompressionBlk* compression_blk = static_cast<CompressionBlk*>(blk); 171 const SuperBlk* superblock = static_cast<const SuperBlk*>( 172 compression_blk->getSectorBlock()); 173 const bool is_co_allocatable = superblock->isCompressed() && 174 superblock->canCoAllocate(compression_blk->getSizeBits()); 175 |
176 // Insert block 177 SectorTags::insertBlock(pkt, blk); 178 |
179 // We always store compressed blocks when possible 180 if (is_co_allocatable) { 181 compression_blk->setCompressed(); 182 } else { 183 compression_blk->setUncompressed(); 184 } |
185} 186 187void 188CompressedTags::forEachBlk(std::function<void(CacheBlk &)> visitor) 189{ 190 for (CompressionBlk& blk : blks) { 191 visitor(blk); 192 } --- 18 unchanged lines hidden --- |