2 * Copyright (c) 2012-2013, 2015 ARM Limited
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
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Copyright (c) 2002-2005 The Regents of The University of Michigan
15 * All rights reserved.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 * Authors: Erik Hallnor
45 * Miss Status and Handling Register (MSHR) declaration.
48 #ifndef __MEM_CACHE_MSHR_HH__
49 #define __MEM_CACHE_MSHR_HH__
53 #include "base/printable.hh"
54 #include "mem/packet.hh"
60 * Miss Status and handling Register. This class keeps all the information
61 * needed to handle a cache miss including a list of target requests.
62 * @sa \ref gem5MemorySystem "gem5 Memory System"
64 class MSHR : public Packet::SenderState, public Printable
68 * Consider the MSHRQueue a friend to avoid making everything public
70 friend class MSHRQueue;
74 /** Cycle when ready to issue */
77 /** True if the request is uncacheable */
80 /** Flag set by downstream caches */
81 bool downstreamPending;
83 /** Will we have a dirty copy after this request? */
86 /** Did we snoop an invalidate while waiting for data? */
89 /** Did we snoop a read while waiting for data? */
103 const Tick recvTime; //!< Time when request was received (for stats)
104 const Tick readyTime; //!< Time when request is ready to be serviced
105 const Counter order; //!< Global order (for memory consistency mgmt)
106 const PacketPtr pkt; //!< Pending request packet.
107 const Source source; //!< Request from cpu, memory, or prefetcher?
108 const bool markedPending; //!< Did we mark upstream MSHR
109 //!< as downstreamPending?
111 Target(PacketPtr _pkt, Tick _readyTime, Counter _order,
112 Source _source, bool _markedPending)
113 : recvTime(curTick()), readyTime(_readyTime), order(_order),
114 pkt(_pkt), source(_source), markedPending(_markedPending)
118 class TargetList : public std::list<Target> {
125 void resetFlags() { needsExclusive = hasUpgrade = false; }
126 bool isReset() const { return !needsExclusive && !hasUpgrade; }
127 void add(PacketPtr pkt, Tick readyTime, Counter order,
128 Target::Source source, bool markPending);
129 void replaceUpgrades();
130 void clearDownstreamPending();
131 bool checkFunctional(PacketPtr pkt);
132 void print(std::ostream &os, int verbosity,
133 const std::string &prefix) const;
136 /** A list of MSHRs. */
137 typedef std::list<MSHR *> List;
138 /** MSHR list iterator. */
139 typedef List::iterator Iterator;
140 /** MSHR list const_iterator. */
141 typedef List::const_iterator ConstIterator;
143 /** Pointer to queue containing this MSHR. */
146 /** Order number assigned by the miss queue. */
149 /** Block aligned address of the MSHR. */
152 /** Block size of the cache. */
155 /** True if the request targets the secure memory space. */
158 /** True if the request has been sent to the bus. */
161 /** True if the request is just a simple forward from an upper level */
164 /** Keep track of whether we should allocate on fill or not */
167 /** The pending* and post* flags are only valid if inService is
168 * true. Using the accessor functions lets us detect if these
169 * flags are accessed improperly.
172 /** True if we need to get an exclusive copy of the block. */
173 bool needsExclusive() const { return targets.needsExclusive; }
175 bool isPendingDirty() const {
176 assert(inService); return pendingDirty;
179 bool hasPostInvalidate() const {
180 assert(inService); return postInvalidate;
183 bool hasPostDowngrade() const {
184 assert(inService); return postDowngrade;
187 /** Thread number of the miss. */
192 /** Data buffer (if needed). Currently used only for pending
193 * upgrade handling. */
197 * Pointer to this MSHR on the ready list.
198 * @sa MissQueue, MSHRQueue::readyList
203 * Pointer to this MSHR on the allocated list.
204 * @sa MissQueue, MSHRQueue::allocatedList
208 /** List of all requests that match the address */
211 TargetList deferredTargets;
215 bool isUncacheable() const { return _isUncacheable; }
218 * Allocate a miss to this MSHR.
219 * @param blk_addr The address of the block.
220 * @param blk_size The number of bytes to request.
221 * @param pkt The original miss.
222 * @param when_ready When should the MSHR be ready to act upon.
223 * @param _order The logical order of this MSHR
224 * @param alloc_on_fill Should the cache allocate a block on fill
226 void allocate(Addr blk_addr, unsigned blk_size, PacketPtr pkt,
227 Tick when_ready, Counter _order, bool alloc_on_fill);
229 bool markInService(bool pending_dirty_resp);
231 void clearDownstreamPending();
234 * Mark this MSHR as free.
239 * Add a request to the list of targets.
240 * @param target The target.
242 void allocateTarget(PacketPtr target, Tick when, Counter order,
244 bool handleSnoop(PacketPtr target, Counter order);
246 /** A simple constructor. */
250 * Returns the current number of allocated targets.
251 * @return The current number of allocated targets.
253 int getNumTargets() const
254 { return targets.size() + deferredTargets.size(); }
257 * Returns true if there are targets left.
258 * @return true if there are targets
260 bool hasTargets() const { return !targets.empty(); }
263 * Returns a reference to the first target.
264 * @return A pointer to the first target.
268 assert(hasTargets());
269 return &targets.front();
280 bool isForwardNoResponse() const
282 if (getNumTargets() != 1)
284 const Target *tgt = &targets.front();
285 return tgt->source == Target::FromCPU && !tgt->pkt->needsResponse();
288 bool promoteDeferredTargets();
290 void promoteExclusive();
292 bool checkFunctional(PacketPtr pkt);
295 * Prints the contents of this MSHR for debugging.
297 void print(std::ostream &os,
299 const std::string &prefix = "") const;
301 * A no-args wrapper of print(std::ostream...) meant to be
302 * invoked from DPRINTFs avoiding string overheads in fast mode
304 * @return string with mshr fields + [deferred]targets
306 std::string print() const;
309 #endif // __MEM_CACHE_MSHR_HH__