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
58 Tick recvTime; //!< Time when request was received (for stats)
59 Tick readyTime; //!< Time when request is ready to be serviced
60 Counter order; //!< Global order (for memory consistency mgmt)
61 PacketPtr pkt; //!< Pending request packet.
62 bool cpuSide; //!< Did request come from cpu side or mem side?
63 bool markedPending; //!< Did we mark upstream MSHR
64 //!< as downstreamPending?
66 bool isCpuSide() const { return cpuSide; }
68 Target(PacketPtr _pkt, Tick _readyTime, Counter _order,
69 bool _cpuSide, bool _markedPending)
70 : recvTime(curTick), readyTime(_readyTime), order(_order),
71 pkt(_pkt), cpuSide(_cpuSide), markedPending(_markedPending)
75 class TargetList : public std::list<Target> {
76 /** Target list iterator. */
77 typedef std::list<Target>::iterator Iterator;
78 typedef std::list<Target>::const_iterator ConstIterator;
85 void resetFlags() { needsExclusive = hasUpgrade = false; }
86 bool isReset() { return !needsExclusive && !hasUpgrade; }
87 void add(PacketPtr pkt, Tick readyTime, Counter order,
88 bool cpuSide, bool markPending);
89 void replaceUpgrades();
90 void clearDownstreamPending();
91 bool checkFunctional(PacketPtr pkt);
92 void print(std::ostream &os, int verbosity,
93 const std::string &prefix) const;
96 /** A list of MSHRs. */
97 typedef std::list<MSHR *> List;
98 /** MSHR list iterator. */
99 typedef List::iterator Iterator;
100 /** MSHR list const_iterator. */
101 typedef List::const_iterator ConstIterator;
103 /** Pointer to queue containing this MSHR. */
106 /** Cycle when ready to issue */
109 /** Order number assigned by the miss queue. */
112 /** Address of the request. */
115 /** Size of the request. */
118 /** True if the request has been sent to the bus. */
121 /** True if we will be putting the returned block in the cache */
124 /** True if we need to get an exclusive copy of the block. */
125 bool needsExclusive() const { return targets->needsExclusive; }
127 /** True if the request is uncacheable */
130 bool downstreamPending;
132 bool pendingInvalidate;
135 /** Thread number of the miss. */
137 /** The number of currently allocated targets. */
141 /** Data buffer (if needed). Currently used only for pending
142 * upgrade handling. */
146 * Pointer to this MSHR on the ready list.
147 * @sa MissQueue, MSHRQueue::readyList
152 * Pointer to this MSHR on the allocated list.
153 * @sa MissQueue, MSHRQueue::allocatedList
158 /** List of all requests that match the address */
161 TargetList *deferredTargets;
165 bool isUncacheable() { return _isUncacheable; }
168 * Allocate a miss to this MSHR.
169 * @param cmd The requesting command.
170 * @param addr The address of the miss.
171 * @param asid The address space id of the miss.
172 * @param size The number of bytes to request.
173 * @param pkt The original miss.
175 void allocate(Addr addr, int size, PacketPtr pkt,
176 Tick when, Counter _order);
178 bool markInService();
180 void clearDownstreamPending();
183 * Mark this MSHR as free.
188 * Add a request to the list of targets.
189 * @param target The target.
191 void allocateTarget(PacketPtr target, Tick when, Counter order);
192 bool handleSnoop(PacketPtr target, Counter order);
194 /** A simple constructor. */
196 /** A simple destructor. */
200 * Returns the current number of allocated targets.
201 * @return The current number of allocated targets.
203 int getNumTargets() { return ntargets; }
206 * Returns a pointer to the target list.
207 * @return a pointer to the target list.
209 TargetList *getTargetList() { return targets; }
212 * Returns true if there are targets left.
213 * @return true if there are targets
215 bool hasTargets() { return !targets->empty(); }
218 * Returns a reference to the first target.
219 * @return A pointer to the first target.
221 Target *getTarget() { assert(hasTargets()); return &targets->front(); }
229 targets->pop_front();
232 bool isSimpleForward()
234 if (getNumTargets() != 1)
236 Target *tgt = getTarget();
237 return tgt->isCpuSide() && !tgt->pkt->needsResponse();
240 bool promoteDeferredTargets();
242 void handleFill(Packet *pkt, CacheBlk *blk);
244 bool checkFunctional(PacketPtr pkt);
247 * Prints the contents of this MSHR for debugging.
249 void print(std::ostream &os,
251 const std::string &prefix = "") const;