1/* |
2 * Copyright (c) 2012-2014 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 --- 71 unchanged lines hidden (view full) --- 82 typedef std::list<BlkType*> BlkList; 83 /** Typedef the set type used in this tag store. */ 84 typedef CacheSet<CacheBlk> SetType; 85 86 87 protected: 88 /** The associativity of the cache. */ 89 const unsigned assoc; |
90 /** The allocatable associativity of the cache (alloc mask). */ 91 unsigned allocAssoc; |
92 /** The number of sets in the cache. */ 93 const unsigned numSets; 94 /** Whether tags and data are accessed sequentially. */ 95 const bool sequentialAccess; 96 97 /** The cache sets. */ 98 SetType *sets; 99 --- 43 unchanged lines hidden (view full) --- 143 */ 144 unsigned 145 getSubBlockSize() const 146 { 147 return blkSize; 148 } 149 150 /** |
151 * Return the number of sets this cache has 152 * @return The number of sets. 153 */ 154 unsigned 155 getNumSets() const 156 { 157 return numSets; 158 } 159 160 /** 161 * Return the number of ways this cache has 162 * @return The number of ways. 163 */ 164 unsigned 165 getNumWays() const 166 { 167 return assoc; 168 } 169 170 /** 171 * Find the cache block given set and way 172 * @param set The set of the block. 173 * @param way The way of the block. 174 * @return The cache block. 175 */ 176 CacheBlk *findBlockBySetAndWay(int set, int way) const; 177 178 /** |
179 * Invalidate the given block. 180 * @param blk The block to invalidate. 181 */ 182 void invalidate(CacheBlk *blk) 183 { 184 assert(blk); 185 assert(blk->isValid()); 186 tagsInUse--; --- 21 unchanged lines hidden (view full) --- 208 Addr tag = extractTag(addr); 209 int set = extractSet(addr); 210 BlkType *blk = sets[set].findBlk(tag, is_secure); 211 lat = accessLatency;; 212 213 // Access all tags in parallel, hence one in each way. The data side 214 // either accesses all blocks in parallel, or one block sequentially on 215 // a hit. Sequential access with a miss doesn't access data. |
216 tagAccesses += allocAssoc; |
217 if (sequentialAccess) { 218 if (blk != NULL) { 219 dataAccesses += 1; 220 } 221 } else { |
222 dataAccesses += allocAssoc; |
223 } 224 225 if (blk != NULL) { 226 if (blk->whenReady > curTick() 227 && cache->ticksToCycles(blk->whenReady - curTick()) 228 > accessLatency) { 229 lat = cache->ticksToCycles(blk->whenReady - curTick()); 230 } --- 21 unchanged lines hidden (view full) --- 252 * @return The candidate block. 253 */ 254 CacheBlk* findVictim(Addr addr) 255 { 256 BlkType *blk = NULL; 257 int set = extractSet(addr); 258 259 // prefer to evict an invalid block |
260 for (int i = 0; i < allocAssoc; ++i) { |
261 blk = sets[set].blks[i]; |
262 if (!blk->isValid()) |
263 break; |
264 } 265 266 return blk; 267 } 268 269 /** 270 * Insert the new block into the cache. 271 * @param pkt Packet holding the address to update --- 44 unchanged lines hidden (view full) --- 316 blk->tickInserted = curTick(); 317 318 // We only need to write into one tag and one data block. 319 tagAccesses += 1; 320 dataAccesses += 1; 321 } 322 323 /** |
324 * Limit the allocation for the cache ways. 325 * @param ways The maximum number of ways available for replacement. 326 */ 327 virtual void setWayAllocationMax(int ways) 328 { 329 fatal_if(ways < 1, "Allocation limit must be greater than zero"); 330 allocAssoc = ways; 331 } 332 333 /** 334 * Get the way allocation mask limit. 335 * @return The maximum number of ways available for replacement. 336 */ 337 virtual int getWayAllocationMax() const 338 { 339 return allocAssoc; 340 } 341 342 /** |
343 * Generate the tag from the given address. 344 * @param addr The address to get the tag from. 345 * @return The tag of the address. 346 */ 347 Addr extractTag(Addr addr) const 348 { 349 return (addr >> tagShift); 350 } --- 74 unchanged lines hidden --- |