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; --- 180 unchanged lines hidden (view full) --- 189 } else { 190 // If a cache miss 191 lat = lookupLatency; 192 } 193 194 return blk; 195} 196 |
197std::vector<ReplaceableEntry*> 198SectorTags::getPossibleLocations(const Addr addr) const |
199{ |
200 std::vector<ReplaceableEntry*> locations; 201 for (const auto& blk : sets[extractSet(addr)]) { 202 locations.push_back(static_cast<ReplaceableEntry*>(blk)); 203 } 204 return locations; |
205} 206 207void 208SectorTags::insertBlock(const Addr addr, const bool is_secure, 209 const int src_master_ID, const uint32_t task_ID, 210 CacheBlk *blk) 211{ 212 // Do common block insertion functionality --- 24 unchanged lines hidden (view full) --- 237 // Extract sector tag 238 const Addr tag = extractTag(addr); 239 240 // The address can only be mapped to a specific location of a sector 241 // due to sectors being composed of contiguous-address entries 242 const Addr offset = extractSectorOffset(addr); 243 244 // Find all possible sector locations for the given address |
245 const std::vector<ReplaceableEntry*> locations = 246 getPossibleLocations(addr); |
247 248 // Search for block 249 for (const auto& sector : locations) { |
250 auto blk = static_cast<SectorBlk*>(sector)->blks[offset]; |
251 if (blk->getTag() == tag && blk->isValid() && 252 blk->isSecure() == is_secure) { 253 return blk; 254 } 255 } 256 257 // Did not find block 258 return nullptr; --- 5 unchanged lines hidden (view full) --- 264 return sets[set][way]; 265} 266 267CacheBlk* 268SectorTags::findVictim(Addr addr, const bool is_secure, 269 std::vector<CacheBlk*>& evict_blks) const 270{ 271 // Get all possible locations of this sector |
272 const std::vector<ReplaceableEntry*> sector_locations = |
273 getPossibleLocations(addr); 274 275 // Check if the sector this address belongs to has been allocated 276 Addr tag = extractTag(addr); 277 SectorBlk* victim_sector = nullptr; |
278 for (const auto& sector : sector_locations) { 279 SectorBlk* sector_blk = static_cast<SectorBlk*>(sector); 280 if ((tag == sector_blk->getTag()) && sector_blk->isValid() && 281 (is_secure == sector_blk->isSecure())){ 282 victim_sector = sector_blk; |
283 break; 284 } 285 } 286 287 // If the sector is not present 288 if (victim_sector == nullptr){ 289 // Choose replacement victim from replacement candidates 290 victim_sector = static_cast<SectorBlk*>(replacementPolicy->getVictim( |
291 sector_locations)); |
292 } 293 294 // Get the location of the victim block within the sector 295 SectorSubBlk* victim = victim_sector->blks[extractSectorOffset(addr)]; 296 297 // Get evicted blocks. Blocks are only evicted if the sectors mismatch and 298 // the currently existing sector is valid. 299 if ((tag == victim_sector->getTag()) && --- 68 unchanged lines hidden --- |