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__
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
44 #include "base/hashmap.hh"
46 #include "mem/cache/tags/base_tags.hh"
51 * A LIFO set of cache blks
55 /** the number of blocks in this set */
58 /** Cache blocks in this set, maintained in LIFO order where
63 /** has the initial "filling" of this set finished? i.e., have you had
64 * 'ways' number of compulsory misses in this set yet? if withValue == ways,
65 * then yes. withValue is meant to be the number of blocks in the set that have
66 * gone through their first compulsory miss.
71 * Find a block matching the tag in this set.
72 * @param asid The address space ID.
73 * @param tag the Tag you are looking for
74 * @return Pointer to the block, if found, NULL otherwise
76 SplitBlk* findBlk(int asid, Addr tag) const;
78 void moveToLastIn(SplitBlk *blk);
79 void moveToFirstIn(SplitBlk *blk);
82 : ways(-1), lastIn(NULL), firstIn(NULL), withValue(0)
87 * A LIFO cache tag store.
89 class SplitLIFO : public BaseTags
92 /** Typedef the block type used in this tag store. */
93 typedef SplitBlk BlkType;
94 /** Typedef for a list of pointers to the local block class. */
95 typedef std::list<SplitBlk*> BlkList;
97 /** The number of bytes in a block. */
99 /** the size of the cache in bytes */
101 /** the number of blocks in the cache */
103 /** the number of sets in the cache */
105 /** the number of ways in the cache */
107 /** The hit latency. */
108 const int hitLatency;
109 /** whether this is a "2 queue" replacement @sa moveToLastIn @sa moveToFirstIn */
111 /** indicator for which partition this is */
114 /** The cache blocks. */
116 /** The Cache sets */
118 /** The data blocks, 1 per cache block. */
121 /** The amount to shift the address to get the set. */
123 /** The amount to shift the address to get the tag. */
125 /** Mask out all bits that aren't part of the set index. */
127 /** Mask out all bits that aren't part of the block offset. */
131 /** the number of hit in this partition */
132 Stats::Scalar<> hits;
133 /** the number of blocks brought into this partition (i.e. misses) */
134 Stats::Scalar<> misses;
135 /** the number of invalidations in this partition */
136 Stats::Scalar<> invalidations;
140 * Construct and initialize this tag store.
141 * @param _numSets The number of sets in the cache.
142 * @param _blkSize The number of bytes in a block.
143 * @param _assoc The associativity of the cache.
144 * @param _hit_latency The latency in cycles for a hit.
146 SplitLIFO(int _blkSize, int _size, int _ways, int _hit_latency, bool twoQueue, int _part);
151 virtual ~SplitLIFO();
154 * Register the statistics for this object
155 * @param name The name to precede the stat
157 void regStats(const std::string &name);
160 * Return the block size.
161 * @return the block size.
169 * Return the subblock size. In the case of LIFO it is always the block
171 * @return The block size.
173 int getSubBlockSize()
179 * Search for the address in the cache.
180 * @param asid The address space ID.
181 * @param addr The address to find.
182 * @return True if the address is in the cache.
184 bool probe(int asid, Addr addr) const;
187 * Invalidate the block containing the given address.
188 * @param asid The address space ID.
189 * @param addr The address to invalidate.
191 void invalidateBlk(int asid, Addr addr);
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 asid, int &lat);
204 * Finds the given address in the cache and update replacement data.
205 * Returns the access latency as a side effect.
206 * @param req The req whose block to find
207 * @param lat The access latency.
208 * @return Pointer to the cache block if found.
210 SplitBlk* findBlock(Packet * &pkt, int &lat);
213 * Finds the given address in the cache, do not update replacement data.
214 * @param addr The address to find.
215 * @param asid The address space ID.
216 * @return Pointer to the cache block if found.
218 SplitBlk* findBlock(Addr addr, int asid) const;
221 * Find a replacement block for the address provided.
222 * @param req The request to a find a replacement candidate for.
223 * @param writebacks List for any writebacks to be performed.
224 * @param compress_blocks List of blocks to compress, for adaptive comp.
225 * @return The block to place the replacement in.
227 SplitBlk* findReplacement(Packet * &pkt, PacketList &writebacks,
228 BlkList &compress_blocks);
231 * Generate the tag from the given address.
232 * @param addr The address to get the tag from.
233 * @return The tag of the address.
235 Addr extractTag(Addr addr) const
237 return (addr >> tagShift);
241 * Generate the tag from the given address.
242 * @param addr The address to get the tag from.
244 * @return The tag of the address.
246 Addr extractTag(Addr addr, SplitBlk *blk) const
248 return (addr >> tagShift);
252 * Calculate the set index from the address.
253 * @param addr The address to get the set from.
254 * @return The set index of the address.
256 int extractSet(Addr addr) const
258 return ((addr >> setShift) & setMask);
262 * Get the block offset from an address.
263 * @param addr The address to get the offset of.
264 * @return The block offset.
266 int extractBlkOffset(Addr addr) const
268 return (addr & blkMask);
272 * Align an address to the block size.
273 * @param addr the address to align.
274 * @return The block address.
276 Addr blkAlign(Addr addr) const
278 return (addr & ~(Addr)blkMask);
282 * Regenerate the block address from the tag.
283 * @param tag The tag of the block.
284 * @param set The set of the block.
285 * @return The block address.
287 Addr regenerateBlkAddr(Addr tag, unsigned set) const
289 return ((tag << tagShift) | ((Addr)set << setShift));
293 * Return the hit latency.
294 * @return the hit latency.
296 int getHitLatency() const
302 * Read the data out of the internal storage of the given cache block.
303 * @param blk The cache block to read.
304 * @param data The buffer to read the data into.
305 * @return The cache block's data.
307 void readData(SplitBlk *blk, uint8_t *data)
309 memcpy(data, blk->data, blk->size);
313 * Write data into the internal storage of the given cache block. Since in
314 * LIFO does not store data differently this just needs to update the size.
315 * @param blk The cache block to write.
316 * @param data The data to write.
317 * @param size The number of bytes to write.
318 * @param writebacks A list for any writebacks to be performed. May be
319 * needed when writing to a compressed block.
321 void writeData(SplitBlk *blk, uint8_t *data, int size,
322 PacketList & writebacks)
324 assert(size <= blkSize);
329 * Perform a block aligned copy from the source address to the destination.
330 * @param source The block-aligned source address.
331 * @param dest The block-aligned destination address.
332 * @param asid The address space DI.
333 * @param writebacks List for any generated writeback requests.
335 void doCopy(Addr source, Addr dest, int asid, PacketList &writebacks);
340 void fixCopy(Packet * &pkt, PacketList &writebacks)
345 * Called at end of simulation to complete average block reference stats.
347 virtual void cleanupRefs();