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 LIFO tag store usable in a partitioned cache.
36 #ifndef __SPLIT_LIFO_HH__
37 #define __SPLIT_LIFO_HH__
42 #include "mem/cache/cache_blk.hh" // base class
43 #include "mem/cache/tags/split_blk.hh"
44 #include "mem/packet.hh" // for inlined functions
45 #include "base/hashmap.hh"
47 #include "mem/cache/tags/base_tags.hh"
52 * A LIFO set of cache blks
56 /** the number of blocks in this set */
59 /** Cache blocks in this set, maintained in LIFO order where
64 /** has the initial "filling" of this set finished? i.e., have you had
65 * 'ways' number of compulsory misses in this set yet? if withValue == ways,
66 * then yes. withValue is meant to be the number of blocks in the set that have
67 * gone through their first compulsory miss.
72 * Find a block matching the tag in this set.
73 * @param asid The address space ID.
74 * @param tag the Tag you are looking for
75 * @return Pointer to the block, if found, NULL otherwise
77 SplitBlk* findBlk(Addr tag) const;
79 void moveToLastIn(SplitBlk *blk);
80 void moveToFirstIn(SplitBlk *blk);
83 : ways(-1), lastIn(NULL), firstIn(NULL), withValue(0)
88 * A LIFO cache tag store.
90 class SplitLIFO : public BaseTags
93 /** Typedef the block type used in this tag store. */
94 typedef SplitBlk BlkType;
95 /** Typedef for a list of pointers to the local block class. */
96 typedef std::list<SplitBlk*> BlkList;
98 /** The number of bytes in a block. */
100 /** the size of the cache in bytes */
102 /** the number of blocks in the cache */
104 /** the number of sets in the cache */
106 /** the number of ways in the cache */
108 /** The hit latency. */
109 const int hitLatency;
110 /** whether this is a "2 queue" replacement @sa moveToLastIn @sa moveToFirstIn */
112 /** indicator for which partition this is */
115 /** The cache blocks. */
117 /** The Cache sets */
119 /** The data blocks, 1 per cache block. */
122 /** The amount to shift the address to get the set. */
124 /** The amount to shift the address to get the tag. */
126 /** Mask out all bits that aren't part of the set index. */
128 /** Mask out all bits that aren't part of the block offset. */
132 /** the number of hit in this partition */
133 Stats::Scalar<> hits;
134 /** the number of blocks brought into this partition (i.e. misses) */
135 Stats::Scalar<> misses;
136 /** the number of invalidations in this partition */
137 Stats::Scalar<> invalidations;
141 * Construct and initialize this tag store.
142 * @param _numSets The number of sets in the cache.
143 * @param _blkSize The number of bytes in a block.
144 * @param _assoc The associativity of the cache.
145 * @param _hit_latency The latency in cycles for a hit.
147 SplitLIFO(int _blkSize, int _size, int _ways, int _hit_latency, bool twoQueue, int _part);
152 virtual ~SplitLIFO();
155 * Register the statistics for this object
156 * @param name The name to precede the stat
158 void regStats(const std::string &name);
161 * Return the block size.
162 * @return the block size.
170 * Return the subblock size. In the case of LIFO it is always the block
172 * @return The block size.
174 int getSubBlockSize()
180 * Search for the address in the cache.
181 * @param asid The address space ID.
182 * @param addr The address to find.
183 * @return True if the address is in the cache.
185 bool probe( Addr addr) const;
188 * Invalidate the given block.
189 * @param blk The block to invalidate.
191 void invalidateBlk(BlkType *blk);
194 * Finds the given address in the cache and update replacement data.
195 * Returns the access latency as a side effect.
196 * @param addr The address to find.
197 * @param asid The address space ID.
198 * @param lat The access latency.
199 * @return Pointer to the cache block if found.
201 SplitBlk* findBlock(Addr addr, int &lat);
204 * Finds the given address in the cache, do not update replacement data.
205 * @param addr The address to find.
206 * @param asid The address space ID.
207 * @return Pointer to the cache block if found.
209 SplitBlk* findBlock(Addr addr) const;
212 * Find a replacement block for the address provided.
213 * @param pkt The request to a find a replacement candidate for.
214 * @param writebacks List for any writebacks to be performed.
215 * @param compress_blocks List of blocks to compress, for adaptive comp.
216 * @return The block to place the replacement in.
218 SplitBlk* findReplacement(PacketPtr &pkt, PacketList &writebacks,
219 BlkList &compress_blocks);
222 * Generate the tag from the given address.
223 * @param addr The address to get the tag from.
224 * @return The tag of the address.
226 Addr extractTag(Addr addr) const
228 return (addr >> tagShift);
232 * Generate the tag from the given address.
233 * @param addr The address to get the tag from.
235 * @return The tag of the address.
237 Addr extractTag(Addr addr, SplitBlk *blk) const
239 return (addr >> tagShift);
243 * Calculate the set index from the address.
244 * @param addr The address to get the set from.
245 * @return The set index of the address.
247 int extractSet(Addr addr) const
249 return ((addr >> setShift) & setMask);
253 * Get the block offset from an address.
254 * @param addr The address to get the offset of.
255 * @return The block offset.
257 int extractBlkOffset(Addr addr) const
259 return (addr & blkMask);
263 * Align an address to the block size.
264 * @param addr the address to align.
265 * @return The block address.
267 Addr blkAlign(Addr addr) const
269 return (addr & ~(Addr)blkMask);
273 * Regenerate the block address from the tag.
274 * @param tag The tag of the block.
275 * @param set The set of the block.
276 * @return The block address.
278 Addr regenerateBlkAddr(Addr tag, unsigned set) const
280 return ((tag << tagShift) | ((Addr)set << setShift));
284 * Return the hit latency.
285 * @return the hit latency.
287 int getHitLatency() const
293 * Read the data out of the internal storage of the given cache block.
294 * @param blk The cache block to read.
295 * @param data The buffer to read the data into.
296 * @return The cache block's data.
298 void readData(SplitBlk *blk, uint8_t *data)
300 std::memcpy(data, blk->data, blk->size);
304 * Write data into the internal storage of the given cache block. Since in
305 * LIFO does not store data differently this just needs to update the size.
306 * @param blk The cache block to write.
307 * @param data The data to write.
308 * @param size The number of bytes to write.
309 * @param writebacks A list for any writebacks to be performed. May be
310 * needed when writing to a compressed block.
312 void writeData(SplitBlk *blk, uint8_t *data, int size,
313 PacketList & writebacks)
315 assert(size <= blkSize);
320 * Called at end of simulation to complete average block reference stats.
322 virtual void cleanupRefs();