2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
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;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * Declaration of a LRU tag store for a partitioned cache.
36 #ifndef __SPLIT_LRU_HH__
37 #define __SPLIT_LRU_HH__
41 #include "mem/cache/cache_blk.hh" // base class
42 #include "mem/cache/tags/split_blk.hh"
43 #include "mem/packet.hh" // for inlined functions
45 #include "mem/cache/tags/base_tags.hh"
50 * An associative set of cache blocks.
56 /** The associativity of this set. */
59 /** Cache blocks in this set, maintained in LRU order 0 = MRU. */
63 * Find a block matching the tag in this set.
64 * @param asid The address space ID.
65 * @param tag The Tag to find.
66 * @return Pointer to the block if found.
68 SplitBlk* findBlk(Addr tag) const;
71 * Move the given block to the head of the list.
72 * @param blk The block to move.
74 void moveToHead(SplitBlk *blk);
78 * A LRU cache tag store.
80 class SplitLRU : public BaseTags
83 /** Typedef the block type used in this tag store. */
84 typedef SplitBlk BlkType;
85 /** Typedef for a list of pointers to the local block class. */
86 typedef std::list<SplitBlk*> BlkList;
88 /** The number of sets in the cache. */
90 /** The number of bytes in a block. */
92 /** The associativity of the cache. */
94 /** The hit latency. */
96 /** indicator for which partition this is */
99 /** The cache sets. */
102 /** The cache blocks. */
104 /** The data blocks, 1 per cache block. */
107 /** The amount to shift the address to get the set. */
109 /** The amount to shift the address to get the tag. */
111 /** Mask out all bits that aren't part of the set index. */
113 /** Mask out all bits that aren't part of the block offset. */
116 /** number of hits in this partition */
117 Stats::Scalar<> hits;
118 /** number of blocks brought into this partition (i.e. misses) */
119 Stats::Scalar<> misses;
123 * Construct and initialize this tag store.
124 * @param _numSets The number of sets in the cache.
125 * @param _blkSize The number of bytes in a block.
126 * @param _assoc The associativity of the cache.
127 * @param _hit_latency The latency in cycles for a hit.
129 SplitLRU(int _numSets, int _blkSize, int _assoc, int _hit_latency, int _part);
137 * Register the statistics for this object
138 * @param name The name to precede the stat
140 void regStats(const std::string &name);
143 * Return the block size.
144 * @return the block size.
152 * Return the subblock size. In the case of LRU it is always the block
154 * @return The block size.
156 int getSubBlockSize()
162 * Search for the address in the cache.
163 * @param asid The address space ID.
164 * @param addr The address to find.
165 * @return True if the address is in the cache.
167 bool probe(Addr addr) const;
170 * Invalidate the block containing the given address.
171 * @param asid The address space ID.
172 * @param addr The address to invalidate.
174 void invalidateBlk(Addr addr);
177 * Finds the given address in the cache and update replacement data.
178 * Returns the access latency as a side effect.
179 * @param addr The address to find.
180 * @param asid The address space ID.
181 * @param lat The access latency.
182 * @return Pointer to the cache block if found.
184 SplitBlk* findBlock(Addr addr, int &lat);
187 * Finds the given address in the cache and update replacement data.
188 * Returns the access latency as a side effect.
189 * @param pkt The req whose block to find.
190 * @param lat The access latency.
191 * @return Pointer to the cache block if found.
193 SplitBlk* findBlock(PacketPtr &pkt, int &lat);
196 * Finds the given address in the cache, do not update replacement data.
197 * @param addr The address to find.
198 * @param asid The address space ID.
199 * @return Pointer to the cache block if found.
201 SplitBlk* findBlock(Addr addr) const;
204 * Find a replacement block for the address provided.
205 * @param pkt The request to a find a replacement candidate for.
206 * @param writebacks List for any writebacks to be performed.
207 * @param compress_blocks List of blocks to compress, for adaptive comp.
208 * @return The block to place the replacement in.
210 SplitBlk* findReplacement(PacketPtr &pkt, PacketList &writebacks,
211 BlkList &compress_blocks);
214 * Generate the tag from the given address.
215 * @param addr The address to get the tag from.
216 * @return The tag of the address.
218 Addr extractTag(Addr addr) const
220 return (addr >> tagShift);
224 * Generate the tag from the given address.
225 * @param addr The address to get the tag from.
226 * @param blk Ignored.
227 * @return The tag of the address.
229 Addr extractTag(Addr addr, SplitBlk *blk) const
231 return (addr >> tagShift);
235 * Calculate the set index from the address.
236 * @param addr The address to get the set from.
237 * @return The set index of the address.
239 int extractSet(Addr addr) const
241 return ((addr >> setShift) & setMask);
245 * Get the block offset from an address.
246 * @param addr The address to get the offset of.
247 * @return The block offset.
249 int extractBlkOffset(Addr addr) const
251 return (addr & blkMask);
255 * Align an address to the block size.
256 * @param addr the address to align.
257 * @return The block address.
259 Addr blkAlign(Addr addr) const
261 return (addr & ~(Addr)blkMask);
265 * Regenerate the block address from the tag.
266 * @param tag The tag of the block.
267 * @param set The set of the block.
268 * @return The block address.
270 Addr regenerateBlkAddr(Addr tag, unsigned set) const
272 return ((tag << tagShift) | ((Addr)set << setShift));
276 * Return the hit latency.
277 * @return the hit latency.
279 int getHitLatency() const
285 * Read the data out of the internal storage of the given cache block.
286 * @param blk The cache block to read.
287 * @param data The buffer to read the data into.
288 * @return The cache block's data.
290 void readData(SplitBlk *blk, uint8_t *data)
292 memcpy(data, blk->data, blk->size);
296 * Write data into the internal storage of the given cache block. Since in
297 * LRU does not store data differently this just needs to update the size.
298 * @param blk The cache block to write.
299 * @param data The data to write.
300 * @param size The number of bytes to write.
301 * @param writebacks A list for any writebacks to be performed. May be
302 * needed when writing to a compressed block.
304 void writeData(SplitBlk *blk, uint8_t *data, int size,
305 PacketList & writebacks)
307 assert(size <= blkSize);
312 * Called at end of simulation to complete average block reference stats.
314 virtual void cleanupRefs();