2 * Copyright (c) 2012-2013, 2015-2016 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/cache/queue_entry.hh"
59 * Miss Status and handling Register. This class keeps all the information
60 * needed to handle a cache miss including a list of target requests.
61 * @sa \ref gem5MemorySystem "gem5 Memory System"
63 class MSHR : public QueueEntry, public Printable
67 * Consider the queues friends to avoid making everything public.
69 template<typename Entry>
71 friend class MSHRQueue;
75 /** Flag set by downstream caches */
76 bool downstreamPending;
79 * Here we use one flag to track both if:
81 * 1. We are going to become owner or not, i.e., we will get the
82 * block in an ownership state (Owned or Modified) with BlkDirty
83 * set. This determines whether or not we are going to become the
84 * responder and ordering point for future requests that we snoop.
86 * 2. We know that we are going to get a writable block, i.e. we
87 * will get the block in writable state (Exclusive or Modified
88 * state) with BlkWritable set. That determines whether additional
89 * targets with needsWritable set will be able to be satisfied, or
90 * if not should be put on the deferred list to possibly wait for
91 * another request that does give us writable access.
93 * Condition 2 is actually just a shortcut that saves us from
94 * possibly building a deferred target list and calling
95 * promoteWritable() every time we get a writable block. Condition
96 * 1, tracking ownership, is what is important. However, we never
97 * receive ownership without marking the block dirty, and
98 * consequently use pendingModified to track both ownership and
99 * writability rather than having separate pendingDirty and
100 * pendingWritable flags.
102 bool pendingModified;
104 /** Did we snoop an invalidate while waiting for data? */
107 /** Did we snoop a read while waiting for data? */
112 /** True if the entry is just a simple forward from an upper level */
124 const Tick recvTime; //!< Time when request was received (for stats)
125 const Tick readyTime; //!< Time when request is ready to be serviced
126 const Counter order; //!< Global order (for memory consistency mgmt)
127 const PacketPtr pkt; //!< Pending request packet.
128 const Source source; //!< Request from cpu, memory, or prefetcher?
131 * We use this flag to track whether we have cleared the
132 * downstreamPending flag for the MSHR of the cache above
133 * where this packet originates from and guard noninitial
134 * attempts to clear it.
136 * The flag markedPending needs to be updated when the
137 * TargetList is in service which can be:
138 * 1) during the Target instantiation if the MSHR is in
139 * service and the target is not deferred,
140 * 2) when the MSHR becomes in service if the target is not
142 * 3) or when the TargetList is promoted (deferredTargets ->
147 const bool allocOnFill; //!< Should the response servicing this
148 //!< target list allocate in the cache?
150 Target(PacketPtr _pkt, Tick _readyTime, Counter _order,
151 Source _source, bool _markedPending, bool alloc_on_fill)
152 : recvTime(curTick()), readyTime(_readyTime), order(_order),
153 pkt(_pkt), source(_source), markedPending(_markedPending),
154 allocOnFill(alloc_on_fill)
158 class TargetList : public std::list<Target> {
163 /** Set when the response should allocate on fill */
169 * Use the provided packet and the source to update the
170 * flags of this TargetList.
172 * @param pkt Packet considered for the flag update
173 * @param source Indicates the source of the packet
174 * @param alloc_on_fill Whether the pkt would allocate on a fill
176 void updateFlags(PacketPtr pkt, Target::Source source,
179 void resetFlags() { needsWritable = hasUpgrade = allocOnFill = false; }
182 * Goes through the list of targets and uses them to populate
183 * the flags of this TargetList. When the function returns the
184 * flags are consistent with the properties of packets in the
187 void populateFlags();
190 * Tests if the flags of this TargetList have their default
193 bool isReset() const {
194 return !needsWritable && !hasUpgrade && !allocOnFill;
198 * Add the specified packet in the TargetList. This function
199 * stores information related to the added packet and updates
200 * accordingly the flags.
202 * @param pkt Packet considered for adding
203 * @param readTime Tick at which the packet is processed by this cache
204 * @param order A counter giving a unique id to each target
205 * @param source Indicates the source agent of the packet
206 * @param markPending Set for deferred targets or pending MSHRs
207 * @param alloc_on_fill Whether it should allocate on a fill
209 void add(PacketPtr pkt, Tick readyTime, Counter order,
210 Target::Source source, bool markPending,
214 * Convert upgrades to the equivalent request if the cache line they
215 * refer to would have been invalid (Upgrade -> ReadEx, SC* -> Fail).
216 * Used to rejig ordering between targets waiting on an MSHR. */
217 void replaceUpgrades();
219 void clearDownstreamPending();
220 bool checkFunctional(PacketPtr pkt);
221 void print(std::ostream &os, int verbosity,
222 const std::string &prefix) const;
225 /** A list of MSHRs. */
226 typedef std::list<MSHR *> List;
227 /** MSHR list iterator. */
228 typedef List::iterator Iterator;
230 /** The pending* and post* flags are only valid if inService is
231 * true. Using the accessor functions lets us detect if these
232 * flags are accessed improperly.
235 /** True if we need to get a writable copy of the block. */
236 bool needsWritable() const { return targets.needsWritable; }
238 bool isPendingModified() const {
239 assert(inService); return pendingModified;
242 bool hasPostInvalidate() const {
243 assert(inService); return postInvalidate;
246 bool hasPostDowngrade() const {
247 assert(inService); return postDowngrade;
250 bool sendPacket(Cache &cache);
252 bool allocOnFill() const {
253 return targets.allocOnFill;
258 * Pointer to this MSHR on the ready list.
259 * @sa MissQueue, MSHRQueue::readyList
264 * Pointer to this MSHR on the allocated list.
265 * @sa MissQueue, MSHRQueue::allocatedList
269 /** List of all requests that match the address */
272 TargetList deferredTargets;
277 * Allocate a miss to this MSHR.
278 * @param blk_addr The address of the block.
279 * @param blk_size The number of bytes to request.
280 * @param pkt The original miss.
281 * @param when_ready When should the MSHR be ready to act upon.
282 * @param _order The logical order of this MSHR
283 * @param alloc_on_fill Should the cache allocate a block on fill
285 void allocate(Addr blk_addr, unsigned blk_size, PacketPtr pkt,
286 Tick when_ready, Counter _order, bool alloc_on_fill);
288 void markInService(bool pending_modified_resp);
290 void clearDownstreamPending();
293 * Mark this MSHR as free.
298 * Add a request to the list of targets.
299 * @param target The target.
301 void allocateTarget(PacketPtr target, Tick when, Counter order,
303 bool handleSnoop(PacketPtr target, Counter order);
305 /** A simple constructor. */
309 * Returns the current number of allocated targets.
310 * @return The current number of allocated targets.
312 int getNumTargets() const
313 { return targets.size() + deferredTargets.size(); }
316 * Extracts the subset of the targets that can be serviced given a
317 * received response. This function returns the targets list
318 * unless the response is a ReadRespWithInvalidate. The
319 * ReadRespWithInvalidate is only invalidating response that its
320 * invalidation was not expected when the request (a
321 * ReadSharedReq) was sent out. For ReadRespWithInvalidate we can
322 * safely service only the first FromCPU target and all FromSnoop
323 * targets (inform all snoopers that we no longer have the block).
325 * @param pkt The response from the downstream memory
327 TargetList extractServiceableTargets(PacketPtr pkt);
330 * Returns true if there are targets left.
331 * @return true if there are targets
333 bool hasTargets() const { return !targets.empty(); }
336 * Returns a reference to the first target.
337 * @return A pointer to the first target.
341 assert(hasTargets());
342 return &targets.front();
353 bool promoteDeferredTargets();
355 void promoteWritable();
357 bool checkFunctional(PacketPtr pkt);
360 * Prints the contents of this MSHR for debugging.
362 void print(std::ostream &os,
364 const std::string &prefix = "") const;
366 * A no-args wrapper of print(std::ostream...) meant to be
367 * invoked from DPRINTFs avoiding string overheads in fast mode
369 * @return string with mshr fields + [deferred]targets
371 std::string print() const;
374 #endif // __MEM_CACHE_MSHR_HH__