2 * Copyright (c) 2002-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.
28 * Authors: Erik Hallnor
33 * Miss Status and Handling Register (MSHR) declaration.
41 #include "base/printable.hh"
42 #include "mem/packet.hh"
48 * Miss Status and handling Register. This class keeps all the information
49 * needed to handle a cache miss including a list of target requests.
51 class MSHR : public Packet::SenderState, public Printable
65 Tick recvTime; //!< Time when request was received (for stats)
66 Tick readyTime; //!< Time when request is ready to be serviced
67 Counter order; //!< Global order (for memory consistency mgmt)
68 PacketPtr pkt; //!< Pending request packet.
69 Source source; //!< Did request come from cpu, memory, or prefetcher?
70 bool markedPending; //!< Did we mark upstream MSHR
71 //!< as downstreamPending?
73 Target(PacketPtr _pkt, Tick _readyTime, Counter _order,
74 Source _source, bool _markedPending)
75 : recvTime(curTick()), readyTime(_readyTime), order(_order),
76 pkt(_pkt), source(_source), markedPending(_markedPending)
80 class TargetList : public std::list<Target> {
81 /** Target list iterator. */
82 typedef std::list<Target>::iterator Iterator;
83 typedef std::list<Target>::const_iterator ConstIterator;
90 void resetFlags() { needsExclusive = hasUpgrade = false; }
91 bool isReset() { return !needsExclusive && !hasUpgrade; }
92 void add(PacketPtr pkt, Tick readyTime, Counter order,
93 Target::Source source, bool markPending);
94 void replaceUpgrades();
95 void clearDownstreamPending();
96 bool checkFunctional(PacketPtr pkt);
97 void print(std::ostream &os, int verbosity,
98 const std::string &prefix) const;
101 /** A list of MSHRs. */
102 typedef std::list<MSHR *> List;
103 /** MSHR list iterator. */
104 typedef List::iterator Iterator;
105 /** MSHR list const_iterator. */
106 typedef List::const_iterator ConstIterator;
108 /** Pointer to queue containing this MSHR. */
111 /** Cycle when ready to issue */
114 /** Order number assigned by the miss queue. */
117 /** Address of the request. */
120 /** Size of the request. */
123 /** True if the request has been sent to the bus. */
126 /** True if the request is just a simple forward from an upper level */
129 /** True if we need to get an exclusive copy of the block. */
130 bool needsExclusive() const { return targets->needsExclusive; }
132 /** True if the request is uncacheable */
135 bool downstreamPending;
137 /** The pending* and post* flags are only valid if inService is
138 * true. Using the accessor functions lets us detect if these
139 * flags are accessed improperly.
142 /** Will we have a dirty copy after this request? */
144 bool isPendingDirty() const {
145 assert(inService); return pendingDirty;
148 /** Did we snoop an invalidate while waiting for data? */
150 bool hasPostInvalidate() const {
151 assert(inService); return postInvalidate;
154 /** Did we snoop a read while waiting for data? */
156 bool hasPostDowngrade() const {
157 assert(inService); return postDowngrade;
160 /** Thread number of the miss. */
162 /** The number of currently allocated targets. */
163 unsigned short ntargets;
166 /** Data buffer (if needed). Currently used only for pending
167 * upgrade handling. */
171 * Pointer to this MSHR on the ready list.
172 * @sa MissQueue, MSHRQueue::readyList
177 * Pointer to this MSHR on the allocated list.
178 * @sa MissQueue, MSHRQueue::allocatedList
183 /** List of all requests that match the address */
186 TargetList *deferredTargets;
190 bool isUncacheable() { return _isUncacheable; }
193 * Allocate a miss to this MSHR.
194 * @param cmd The requesting command.
195 * @param addr The address of the miss.
196 * @param asid The address space id of the miss.
197 * @param size The number of bytes to request.
198 * @param pkt The original miss.
200 void allocate(Addr addr, int size, PacketPtr pkt,
201 Tick when, Counter _order);
203 bool markInService(PacketPtr pkt);
205 void clearDownstreamPending();
208 * Mark this MSHR as free.
213 * Add a request to the list of targets.
214 * @param target The target.
216 void allocateTarget(PacketPtr target, Tick when, Counter order);
217 bool handleSnoop(PacketPtr target, Counter order);
219 /** A simple constructor. */
221 /** A simple destructor. */
225 * Returns the current number of allocated targets.
226 * @return The current number of allocated targets.
228 int getNumTargets() const { return ntargets; }
231 * Returns a pointer to the target list.
232 * @return a pointer to the target list.
234 TargetList *getTargetList() { return targets; }
237 * Returns true if there are targets left.
238 * @return true if there are targets
240 bool hasTargets() const { return !targets->empty(); }
243 * Returns a reference to the first target.
244 * @return A pointer to the first target.
246 Target *getTarget() const
248 assert(hasTargets());
249 return &targets->front();
258 targets->pop_front();
261 bool isForwardNoResponse() const
263 if (getNumTargets() != 1)
265 Target *tgt = getTarget();
266 return tgt->source == Target::FromCPU && !tgt->pkt->needsResponse();
269 bool promoteDeferredTargets();
271 void handleFill(Packet *pkt, CacheBlk *blk);
273 bool checkFunctional(PacketPtr pkt);
276 * Prints the contents of this MSHR for debugging.
278 void print(std::ostream &os,
280 const std::string &prefix = "") const;