mshr.hh revision 10503:94d58056729f
1/* 2 * Copyright (c) 2012-2013 ARM Limited 3 * All rights reserved. 4 * 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. 13 * 14 * Copyright (c) 2002-2005 The Regents of The University of Michigan 15 * All rights reserved. 16 * 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. 27 * 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. 39 * 40 * Authors: Erik Hallnor 41 */ 42 43/** 44 * @file 45 * Miss Status and Handling Register (MSHR) declaration. 46 */ 47 48#ifndef __MSHR_HH__ 49#define __MSHR_HH__ 50 51#include <list> 52 53#include "base/printable.hh" 54#include "mem/packet.hh" 55 56class CacheBlk; 57class MSHRQueue; 58 59/** 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" 63 */ 64class MSHR : public Packet::SenderState, public Printable 65{ 66 67 /** 68 * Consider the MSHRQueue a friend to avoid making everything public 69 */ 70 friend class MSHRQueue; 71 72 private: 73 74 /** Cycle when ready to issue */ 75 Tick readyTime; 76 77 /** True if the request is uncacheable */ 78 bool _isUncacheable; 79 80 /** Flag set by downstream caches */ 81 bool downstreamPending; 82 83 /** Will we have a dirty copy after this request? */ 84 bool pendingDirty; 85 86 /** Will we have a clean copy after this request? (i.e. is writeback) */ 87 bool pendingClean; 88 89 /** Did we snoop an invalidate while waiting for data? */ 90 bool postInvalidate; 91 92 /** Did we snoop a read while waiting for data? */ 93 bool postDowngrade; 94 95 /** Did we get WriteInvalidate'd (and therefore obsoleted)? */ 96 bool _isObsolete; 97 98 public: 99 100 class Target { 101 public: 102 103 enum Source { 104 FromCPU, 105 FromSnoop, 106 FromPrefetcher 107 }; 108 109 Tick recvTime; //!< Time when request was received (for stats) 110 Tick readyTime; //!< Time when request is ready to be serviced 111 Counter order; //!< Global order (for memory consistency mgmt) 112 PacketPtr pkt; //!< Pending request packet. 113 Source source; //!< Did request come from cpu, memory, or prefetcher? 114 bool markedPending; //!< Did we mark upstream MSHR 115 //!< as downstreamPending? 116 117 Target(PacketPtr _pkt, Tick _readyTime, Counter _order, 118 Source _source, bool _markedPending) 119 : recvTime(curTick()), readyTime(_readyTime), order(_order), 120 pkt(_pkt), source(_source), markedPending(_markedPending) 121 {} 122 }; 123 124 class TargetList : public std::list<Target> { 125 /** Target list iterator. */ 126 typedef std::list<Target>::iterator Iterator; 127 typedef std::list<Target>::const_iterator ConstIterator; 128 129 public: 130 bool needsExclusive; 131 bool hasUpgrade; 132 133 TargetList(); 134 void resetFlags() { needsExclusive = hasUpgrade = false; } 135 bool isReset() { return !needsExclusive && !hasUpgrade; } 136 void add(PacketPtr pkt, Tick readyTime, Counter order, 137 Target::Source source, bool markPending); 138 void replaceUpgrades(); 139 void clearDownstreamPending(); 140 bool checkFunctional(PacketPtr pkt); 141 void print(std::ostream &os, int verbosity, 142 const std::string &prefix) const; 143 }; 144 145 /** A list of MSHRs. */ 146 typedef std::list<MSHR *> List; 147 /** MSHR list iterator. */ 148 typedef List::iterator Iterator; 149 /** MSHR list const_iterator. */ 150 typedef List::const_iterator ConstIterator; 151 152 /** Pointer to queue containing this MSHR. */ 153 MSHRQueue *queue; 154 155 /** Order number assigned by the miss queue. */ 156 Counter order; 157 158 /** Address of the request. */ 159 Addr addr; 160 161 /** Size of the request. */ 162 int size; 163 164 /** True if the request targets the secure memory space. */ 165 bool isSecure; 166 167 /** True if the request has been sent to the bus. */ 168 bool inService; 169 170 /** True if the request is just a simple forward from an upper level */ 171 bool isForward; 172 173 /** The pending* and post* flags are only valid if inService is 174 * true. Using the accessor functions lets us detect if these 175 * flags are accessed improperly. 176 */ 177 178 /** True if we need to get an exclusive copy of the block. */ 179 bool needsExclusive() const { return targets.needsExclusive; } 180 181 bool isPendingDirty() const { 182 assert(inService); return pendingDirty; 183 } 184 185 bool isPendingClean() const { 186 return pendingClean; 187 } 188 189 bool hasPostInvalidate() const { 190 assert(inService); return postInvalidate; 191 } 192 193 bool hasPostDowngrade() const { 194 assert(inService); return postDowngrade; 195 } 196 197 /** Thread number of the miss. */ 198 ThreadID threadNum; 199 200 private: 201 202 /** Data buffer (if needed). Currently used only for pending 203 * upgrade handling. */ 204 uint8_t *data; 205 206 /** 207 * Pointer to this MSHR on the ready list. 208 * @sa MissQueue, MSHRQueue::readyList 209 */ 210 Iterator readyIter; 211 212 /** 213 * Pointer to this MSHR on the allocated list. 214 * @sa MissQueue, MSHRQueue::allocatedList 215 */ 216 Iterator allocIter; 217 218 /** List of all requests that match the address */ 219 TargetList targets; 220 221 TargetList deferredTargets; 222 223 public: 224 225 bool isUncacheable() const { return _isUncacheable; } 226 227 bool isObsolete() const { return _isObsolete; } 228 229 /** 230 * Allocate a miss to this MSHR. 231 * @param cmd The requesting command. 232 * @param addr The address of the miss. 233 * @param asid The address space id of the miss. 234 * @param size The number of bytes to request. 235 * @param pkt The original miss. 236 */ 237 void allocate(Addr addr, int size, PacketPtr pkt, 238 Tick when, Counter _order); 239 240 bool markInService(PacketPtr pkt); 241 242 void clearDownstreamPending(); 243 244 /** 245 * Mark this MSHR as free. 246 */ 247 void deallocate(); 248 249 /** 250 * Add a request to the list of targets. 251 * @param target The target. 252 */ 253 void allocateTarget(PacketPtr target, Tick when, Counter order); 254 bool handleSnoop(PacketPtr target, Counter order); 255 256 /** A simple constructor. */ 257 MSHR(); 258 259 /** 260 * Returns the current number of allocated targets. 261 * @return The current number of allocated targets. 262 */ 263 int getNumTargets() const 264 { return targets.size() + deferredTargets.size(); } 265 266 /** 267 * Returns true if there are targets left. 268 * @return true if there are targets 269 */ 270 bool hasTargets() const { return !targets.empty(); } 271 272 /** 273 * Returns a reference to the first target. 274 * @return A pointer to the first target. 275 */ 276 Target *getTarget() 277 { 278 assert(hasTargets()); 279 return &targets.front(); 280 } 281 282 /** 283 * Pop first target. 284 */ 285 void popTarget() 286 { 287 targets.pop_front(); 288 } 289 290 bool isForwardNoResponse() const 291 { 292 if (getNumTargets() != 1) 293 return false; 294 const Target *tgt = &targets.front(); 295 return tgt->source == Target::FromCPU && !tgt->pkt->needsResponse(); 296 } 297 298 bool promoteDeferredTargets(); 299 300 void handleFill(Packet *pkt, CacheBlk *blk); 301 302 bool checkFunctional(PacketPtr pkt); 303 304 /** Mark this MSHR as tracking a transaction with obsoleted data. It still 305 * needs to complete its lifecycle, but should not modify the cache. */ 306 void markObsolete() { 307 _isObsolete = true; 308 } 309 310 /** 311 * Prints the contents of this MSHR for debugging. 312 */ 313 void print(std::ostream &os, 314 int verbosity = 0, 315 const std::string &prefix = "") const; 316 /** 317 * A no-args wrapper of print(std::ostream...) meant to be 318 * invoked from DPRINTFs avoiding string overheads in fast mode 319 * 320 * @return string with mshr fields + [deferred]targets 321 */ 322 std::string print() const; 323}; 324 325#endif //__MSHR_HH__ 326