1/* 2 * Copyright (c) 2002-2005 The Regents of The University of Michigan 3 * Copyright (c) 2010 Advanced Micro Devices, Inc. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer; 10 * redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution; 13 * neither the name of the copyright holders nor the names of its 14 * contributors may be used to endorse or promote products derived from 15 * this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * 29 * Authors: Erik Hallnor 30 * Dave Greene 31 */ 32 33/** 34 * @file 35 * Miss Status and Handling Register (MSHR) definitions. 36 */ 37 38#include <algorithm> 39#include <cassert> 40#include <string> 41#include <vector> 42 43#include "base/misc.hh" 44#include "base/types.hh"
| 1/* 2 * Copyright (c) 2002-2005 The Regents of The University of Michigan 3 * Copyright (c) 2010 Advanced Micro Devices, Inc. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer; 10 * redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution; 13 * neither the name of the copyright holders nor the names of its 14 * contributors may be used to endorse or promote products derived from 15 * this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * 29 * Authors: Erik Hallnor 30 * Dave Greene 31 */ 32 33/** 34 * @file 35 * Miss Status and Handling Register (MSHR) definitions. 36 */ 37 38#include <algorithm> 39#include <cassert> 40#include <string> 41#include <vector> 42 43#include "base/misc.hh" 44#include "base/types.hh"
|
45#include "mem/cache/cache.hh" 46#include "mem/cache/mshr.hh" 47#include "sim/core.hh" 48 49using namespace std; 50 51MSHR::MSHR() 52{ 53 inService = false; 54 ntargets = 0; 55 threadNum = InvalidThreadID; 56 targets = new TargetList(); 57 deferredTargets = new TargetList(); 58} 59 60 61MSHR::TargetList::TargetList() 62 : needsExclusive(false), hasUpgrade(false) 63{} 64 65 66inline void 67MSHR::TargetList::add(PacketPtr pkt, Tick readyTime, 68 Counter order, Target::Source source, bool markPending) 69{ 70 if (source != Target::FromSnoop) { 71 if (pkt->needsExclusive()) { 72 needsExclusive = true; 73 } 74 75 // StoreCondReq is effectively an upgrade if it's in an MSHR 76 // since it would have been failed already if we didn't have a 77 // read-only copy 78 if (pkt->isUpgrade() || pkt->cmd == MemCmd::StoreCondReq) { 79 hasUpgrade = true; 80 } 81 } 82 83 if (markPending) { 84 MSHR *mshr = dynamic_cast<MSHR*>(pkt->senderState); 85 if (mshr != NULL) { 86 assert(!mshr->downstreamPending); 87 mshr->downstreamPending = true; 88 } 89 } 90 91 push_back(Target(pkt, readyTime, order, source, markPending)); 92} 93 94 95static void 96replaceUpgrade(PacketPtr pkt) 97{ 98 if (pkt->cmd == MemCmd::UpgradeReq) { 99 pkt->cmd = MemCmd::ReadExReq; 100 DPRINTF(Cache, "Replacing UpgradeReq with ReadExReq\n"); 101 } else if (pkt->cmd == MemCmd::SCUpgradeReq) { 102 pkt->cmd = MemCmd::SCUpgradeFailReq; 103 DPRINTF(Cache, "Replacing SCUpgradeReq with SCUpgradeFailReq\n"); 104 } else if (pkt->cmd == MemCmd::StoreCondReq) { 105 pkt->cmd = MemCmd::StoreCondFailReq; 106 DPRINTF(Cache, "Replacing StoreCondReq with StoreCondFailReq\n"); 107 } 108} 109 110 111void 112MSHR::TargetList::replaceUpgrades() 113{ 114 if (!hasUpgrade) 115 return; 116 117 Iterator end_i = end(); 118 for (Iterator i = begin(); i != end_i; ++i) { 119 replaceUpgrade(i->pkt); 120 } 121 122 hasUpgrade = false; 123} 124 125 126void 127MSHR::TargetList::clearDownstreamPending() 128{ 129 Iterator end_i = end(); 130 for (Iterator i = begin(); i != end_i; ++i) { 131 if (i->markedPending) { 132 MSHR *mshr = dynamic_cast<MSHR*>(i->pkt->senderState); 133 if (mshr != NULL) { 134 mshr->clearDownstreamPending(); 135 } 136 } 137 } 138} 139 140 141bool 142MSHR::TargetList::checkFunctional(PacketPtr pkt) 143{ 144 Iterator end_i = end(); 145 for (Iterator i = begin(); i != end_i; ++i) { 146 if (pkt->checkFunctional(i->pkt)) { 147 return true; 148 } 149 } 150 151 return false; 152} 153 154 155void 156MSHR::TargetList:: 157print(std::ostream &os, int verbosity, const std::string &prefix) const 158{ 159 ConstIterator end_i = end(); 160 for (ConstIterator i = begin(); i != end_i; ++i) { 161 const char *s; 162 switch (i->source) { 163 case Target::FromCPU: s = "FromCPU"; 164 case Target::FromSnoop: s = "FromSnoop"; 165 case Target::FromPrefetcher: s = "FromPrefetcher"; 166 default: s = ""; 167 } 168 ccprintf(os, "%s%s: ", prefix, s); 169 i->pkt->print(os, verbosity, ""); 170 } 171} 172 173 174void 175MSHR::allocate(Addr _addr, int _size, PacketPtr target, 176 Tick whenReady, Counter _order) 177{ 178 addr = _addr; 179 size = _size; 180 readyTime = whenReady; 181 order = _order; 182 assert(target); 183 isForward = false; 184 _isUncacheable = target->req->isUncacheable(); 185 inService = false; 186 downstreamPending = false; 187 threadNum = 0; 188 ntargets = 1; 189 assert(targets->isReset()); 190 // Don't know of a case where we would allocate a new MSHR for a 191 // snoop (mem-side request), so set source according to request here 192 Target::Source source = (target->cmd == MemCmd::HardPFReq) ? 193 Target::FromPrefetcher : Target::FromCPU; 194 targets->add(target, whenReady, _order, source, true); 195 assert(deferredTargets->isReset()); 196 data = NULL; 197} 198 199 200void 201MSHR::clearDownstreamPending() 202{ 203 assert(downstreamPending); 204 downstreamPending = false; 205 // recursively clear flag on any MSHRs we will be forwarding 206 // responses to 207 targets->clearDownstreamPending(); 208} 209 210bool 211MSHR::markInService(PacketPtr pkt) 212{ 213 assert(!inService); 214 if (isForwardNoResponse()) { 215 // we just forwarded the request packet & don't expect a 216 // response, so get rid of it 217 assert(getNumTargets() == 1); 218 popTarget(); 219 return true; 220 } 221 inService = true; 222 pendingDirty = (targets->needsExclusive || 223 (!pkt->sharedAsserted() && pkt->memInhibitAsserted())); 224 postInvalidate = postDowngrade = false; 225 226 if (!downstreamPending) { 227 // let upstream caches know that the request has made it to a 228 // level where it's going to get a response 229 targets->clearDownstreamPending(); 230 } 231 return false; 232} 233 234 235void 236MSHR::deallocate() 237{ 238 assert(targets->empty()); 239 targets->resetFlags(); 240 assert(deferredTargets->isReset()); 241 assert(ntargets == 0); 242 inService = false; 243} 244 245/* 246 * Adds a target to an MSHR 247 */ 248void 249MSHR::allocateTarget(PacketPtr pkt, Tick whenReady, Counter _order) 250{ 251 // if there's a request already in service for this MSHR, we will 252 // have to defer the new target until after the response if any of 253 // the following are true: 254 // - there are other targets already deferred 255 // - there's a pending invalidate to be applied after the response 256 // comes back (but before this target is processed) 257 // - this target requires an exclusive block and either we're not 258 // getting an exclusive block back or we have already snooped 259 // another read request that will downgrade our exclusive block 260 // to shared 261 262 // assume we'd never issue a prefetch when we've got an 263 // outstanding miss 264 assert(pkt->cmd != MemCmd::HardPFReq); 265 266 if (inService && 267 (!deferredTargets->empty() || hasPostInvalidate() || 268 (pkt->needsExclusive() && 269 (!isPendingDirty() || hasPostDowngrade() || isForward)))) { 270 // need to put on deferred list 271 if (hasPostInvalidate()) 272 replaceUpgrade(pkt); 273 deferredTargets->add(pkt, whenReady, _order, Target::FromCPU, true); 274 } else { 275 // No request outstanding, or still OK to append to 276 // outstanding request: append to regular target list. Only 277 // mark pending if current request hasn't been issued yet 278 // (isn't in service). 279 targets->add(pkt, whenReady, _order, Target::FromCPU, !inService); 280 } 281 282 ++ntargets; 283} 284 285bool 286MSHR::handleSnoop(PacketPtr pkt, Counter _order) 287{ 288 if (!inService || (pkt->isExpressSnoop() && downstreamPending)) { 289 // Request has not been issued yet, or it's been issued 290 // locally but is buffered unissued at some downstream cache 291 // which is forwarding us this snoop. Either way, the packet 292 // we're snooping logically precedes this MSHR's request, so 293 // the snoop has no impact on the MSHR, but must be processed 294 // in the standard way by the cache. The only exception is 295 // that if we're an L2+ cache buffering an UpgradeReq from a 296 // higher-level cache, and the snoop is invalidating, then our 297 // buffered upgrades must be converted to read exclusives, 298 // since the upper-level cache no longer has a valid copy. 299 // That is, even though the upper-level cache got out on its 300 // local bus first, some other invalidating transaction 301 // reached the global bus before the upgrade did. 302 if (pkt->needsExclusive()) { 303 targets->replaceUpgrades(); 304 deferredTargets->replaceUpgrades(); 305 } 306 307 return false; 308 } 309 310 // From here on down, the request issued by this MSHR logically 311 // precedes the request we're snooping. 312 if (pkt->needsExclusive()) { 313 // snooped request still precedes the re-request we'll have to 314 // issue for deferred targets, if any... 315 deferredTargets->replaceUpgrades(); 316 } 317 318 if (hasPostInvalidate()) { 319 // a prior snoop has already appended an invalidation, so 320 // logically we don't have the block anymore; no need for 321 // further snooping. 322 return true; 323 } 324 325 if (isPendingDirty() || pkt->isInvalidate()) { 326 // We need to save and replay the packet in two cases: 327 // 1. We're awaiting an exclusive copy, so ownership is pending, 328 // and we need to respond after we receive data. 329 // 2. It's an invalidation (e.g., UpgradeReq), and we need 330 // to forward the snoop up the hierarchy after the current 331 // transaction completes. 332 333 // Actual target device (typ. PhysicalMemory) will delete the 334 // packet on reception, so we need to save a copy here. 335 PacketPtr cp_pkt = new Packet(pkt, true); 336 targets->add(cp_pkt, curTick(), _order, Target::FromSnoop, 337 downstreamPending && targets->needsExclusive); 338 ++ntargets; 339 340 if (isPendingDirty()) { 341 pkt->assertMemInhibit(); 342 pkt->setSupplyExclusive(); 343 } 344 345 if (pkt->needsExclusive()) { 346 // This transaction will take away our pending copy 347 postInvalidate = true; 348 } 349 } 350 351 if (!pkt->needsExclusive()) { 352 // This transaction will get a read-shared copy, downgrading 353 // our copy if we had an exclusive one 354 postDowngrade = true; 355 pkt->assertShared(); 356 } 357 358 return true; 359} 360 361 362bool 363MSHR::promoteDeferredTargets() 364{ 365 assert(targets->empty()); 366 if (deferredTargets->empty()) { 367 return false; 368 } 369 370 // swap targets & deferredTargets lists 371 TargetList *tmp = targets; 372 targets = deferredTargets; 373 deferredTargets = tmp; 374 375 assert(targets->size() == ntargets); 376 377 // clear deferredTargets flags 378 deferredTargets->resetFlags(); 379 380 order = targets->front().order; 381 readyTime = std::max(curTick(), targets->front().readyTime); 382 383 return true; 384} 385 386 387void 388MSHR::handleFill(Packet *pkt, CacheBlk *blk) 389{ 390 if (!pkt->sharedAsserted() 391 && !(hasPostInvalidate() || hasPostDowngrade()) 392 && deferredTargets->needsExclusive) { 393 // We got an exclusive response, but we have deferred targets 394 // which are waiting to request an exclusive copy (not because 395 // of a pending invalidate). This can happen if the original 396 // request was for a read-only (non-exclusive) block, but we 397 // got an exclusive copy anyway because of the E part of the 398 // MOESI/MESI protocol. Since we got the exclusive copy 399 // there's no need to defer the targets, so move them up to 400 // the regular target list. 401 assert(!targets->needsExclusive); 402 targets->needsExclusive = true; 403 // if any of the deferred targets were upper-level cache 404 // requests marked downstreamPending, need to clear that 405 assert(!downstreamPending); // not pending here anymore 406 deferredTargets->clearDownstreamPending(); 407 // this clears out deferredTargets too 408 targets->splice(targets->end(), *deferredTargets); 409 deferredTargets->resetFlags(); 410 } 411} 412 413 414bool 415MSHR::checkFunctional(PacketPtr pkt) 416{ 417 // For printing, we treat the MSHR as a whole as single entity. 418 // For other requests, we iterate over the individual targets 419 // since that's where the actual data lies. 420 if (pkt->isPrint()) { 421 pkt->checkFunctional(this, addr, size, NULL); 422 return false; 423 } else { 424 return (targets->checkFunctional(pkt) || 425 deferredTargets->checkFunctional(pkt)); 426 } 427} 428 429 430void 431MSHR::print(std::ostream &os, int verbosity, const std::string &prefix) const 432{ 433 ccprintf(os, "%s[%x:%x] %s %s %s state: %s %s %s %s\n", 434 prefix, addr, addr+size-1, 435 isForward ? "Forward" : "", 436 isForwardNoResponse() ? "ForwNoResp" : "", 437 needsExclusive() ? "Excl" : "", 438 _isUncacheable ? "Unc" : "", 439 inService ? "InSvc" : "", 440 downstreamPending ? "DwnPend" : "", 441 hasPostInvalidate() ? "PostInv" : "", 442 hasPostDowngrade() ? "PostDowngr" : ""); 443 444 ccprintf(os, "%s Targets:\n", prefix); 445 targets->print(os, verbosity, prefix + " "); 446 if (!deferredTargets->empty()) { 447 ccprintf(os, "%s Deferred Targets:\n", prefix); 448 deferredTargets->print(os, verbosity, prefix + " "); 449 } 450} 451 452MSHR::~MSHR() 453{ 454}
| 46#include "mem/cache/cache.hh" 47#include "mem/cache/mshr.hh" 48#include "sim/core.hh" 49 50using namespace std; 51 52MSHR::MSHR() 53{ 54 inService = false; 55 ntargets = 0; 56 threadNum = InvalidThreadID; 57 targets = new TargetList(); 58 deferredTargets = new TargetList(); 59} 60 61 62MSHR::TargetList::TargetList() 63 : needsExclusive(false), hasUpgrade(false) 64{} 65 66 67inline void 68MSHR::TargetList::add(PacketPtr pkt, Tick readyTime, 69 Counter order, Target::Source source, bool markPending) 70{ 71 if (source != Target::FromSnoop) { 72 if (pkt->needsExclusive()) { 73 needsExclusive = true; 74 } 75 76 // StoreCondReq is effectively an upgrade if it's in an MSHR 77 // since it would have been failed already if we didn't have a 78 // read-only copy 79 if (pkt->isUpgrade() || pkt->cmd == MemCmd::StoreCondReq) { 80 hasUpgrade = true; 81 } 82 } 83 84 if (markPending) { 85 MSHR *mshr = dynamic_cast<MSHR*>(pkt->senderState); 86 if (mshr != NULL) { 87 assert(!mshr->downstreamPending); 88 mshr->downstreamPending = true; 89 } 90 } 91 92 push_back(Target(pkt, readyTime, order, source, markPending)); 93} 94 95 96static void 97replaceUpgrade(PacketPtr pkt) 98{ 99 if (pkt->cmd == MemCmd::UpgradeReq) { 100 pkt->cmd = MemCmd::ReadExReq; 101 DPRINTF(Cache, "Replacing UpgradeReq with ReadExReq\n"); 102 } else if (pkt->cmd == MemCmd::SCUpgradeReq) { 103 pkt->cmd = MemCmd::SCUpgradeFailReq; 104 DPRINTF(Cache, "Replacing SCUpgradeReq with SCUpgradeFailReq\n"); 105 } else if (pkt->cmd == MemCmd::StoreCondReq) { 106 pkt->cmd = MemCmd::StoreCondFailReq; 107 DPRINTF(Cache, "Replacing StoreCondReq with StoreCondFailReq\n"); 108 } 109} 110 111 112void 113MSHR::TargetList::replaceUpgrades() 114{ 115 if (!hasUpgrade) 116 return; 117 118 Iterator end_i = end(); 119 for (Iterator i = begin(); i != end_i; ++i) { 120 replaceUpgrade(i->pkt); 121 } 122 123 hasUpgrade = false; 124} 125 126 127void 128MSHR::TargetList::clearDownstreamPending() 129{ 130 Iterator end_i = end(); 131 for (Iterator i = begin(); i != end_i; ++i) { 132 if (i->markedPending) { 133 MSHR *mshr = dynamic_cast<MSHR*>(i->pkt->senderState); 134 if (mshr != NULL) { 135 mshr->clearDownstreamPending(); 136 } 137 } 138 } 139} 140 141 142bool 143MSHR::TargetList::checkFunctional(PacketPtr pkt) 144{ 145 Iterator end_i = end(); 146 for (Iterator i = begin(); i != end_i; ++i) { 147 if (pkt->checkFunctional(i->pkt)) { 148 return true; 149 } 150 } 151 152 return false; 153} 154 155 156void 157MSHR::TargetList:: 158print(std::ostream &os, int verbosity, const std::string &prefix) const 159{ 160 ConstIterator end_i = end(); 161 for (ConstIterator i = begin(); i != end_i; ++i) { 162 const char *s; 163 switch (i->source) { 164 case Target::FromCPU: s = "FromCPU"; 165 case Target::FromSnoop: s = "FromSnoop"; 166 case Target::FromPrefetcher: s = "FromPrefetcher"; 167 default: s = ""; 168 } 169 ccprintf(os, "%s%s: ", prefix, s); 170 i->pkt->print(os, verbosity, ""); 171 } 172} 173 174 175void 176MSHR::allocate(Addr _addr, int _size, PacketPtr target, 177 Tick whenReady, Counter _order) 178{ 179 addr = _addr; 180 size = _size; 181 readyTime = whenReady; 182 order = _order; 183 assert(target); 184 isForward = false; 185 _isUncacheable = target->req->isUncacheable(); 186 inService = false; 187 downstreamPending = false; 188 threadNum = 0; 189 ntargets = 1; 190 assert(targets->isReset()); 191 // Don't know of a case where we would allocate a new MSHR for a 192 // snoop (mem-side request), so set source according to request here 193 Target::Source source = (target->cmd == MemCmd::HardPFReq) ? 194 Target::FromPrefetcher : Target::FromCPU; 195 targets->add(target, whenReady, _order, source, true); 196 assert(deferredTargets->isReset()); 197 data = NULL; 198} 199 200 201void 202MSHR::clearDownstreamPending() 203{ 204 assert(downstreamPending); 205 downstreamPending = false; 206 // recursively clear flag on any MSHRs we will be forwarding 207 // responses to 208 targets->clearDownstreamPending(); 209} 210 211bool 212MSHR::markInService(PacketPtr pkt) 213{ 214 assert(!inService); 215 if (isForwardNoResponse()) { 216 // we just forwarded the request packet & don't expect a 217 // response, so get rid of it 218 assert(getNumTargets() == 1); 219 popTarget(); 220 return true; 221 } 222 inService = true; 223 pendingDirty = (targets->needsExclusive || 224 (!pkt->sharedAsserted() && pkt->memInhibitAsserted())); 225 postInvalidate = postDowngrade = false; 226 227 if (!downstreamPending) { 228 // let upstream caches know that the request has made it to a 229 // level where it's going to get a response 230 targets->clearDownstreamPending(); 231 } 232 return false; 233} 234 235 236void 237MSHR::deallocate() 238{ 239 assert(targets->empty()); 240 targets->resetFlags(); 241 assert(deferredTargets->isReset()); 242 assert(ntargets == 0); 243 inService = false; 244} 245 246/* 247 * Adds a target to an MSHR 248 */ 249void 250MSHR::allocateTarget(PacketPtr pkt, Tick whenReady, Counter _order) 251{ 252 // if there's a request already in service for this MSHR, we will 253 // have to defer the new target until after the response if any of 254 // the following are true: 255 // - there are other targets already deferred 256 // - there's a pending invalidate to be applied after the response 257 // comes back (but before this target is processed) 258 // - this target requires an exclusive block and either we're not 259 // getting an exclusive block back or we have already snooped 260 // another read request that will downgrade our exclusive block 261 // to shared 262 263 // assume we'd never issue a prefetch when we've got an 264 // outstanding miss 265 assert(pkt->cmd != MemCmd::HardPFReq); 266 267 if (inService && 268 (!deferredTargets->empty() || hasPostInvalidate() || 269 (pkt->needsExclusive() && 270 (!isPendingDirty() || hasPostDowngrade() || isForward)))) { 271 // need to put on deferred list 272 if (hasPostInvalidate()) 273 replaceUpgrade(pkt); 274 deferredTargets->add(pkt, whenReady, _order, Target::FromCPU, true); 275 } else { 276 // No request outstanding, or still OK to append to 277 // outstanding request: append to regular target list. Only 278 // mark pending if current request hasn't been issued yet 279 // (isn't in service). 280 targets->add(pkt, whenReady, _order, Target::FromCPU, !inService); 281 } 282 283 ++ntargets; 284} 285 286bool 287MSHR::handleSnoop(PacketPtr pkt, Counter _order) 288{ 289 if (!inService || (pkt->isExpressSnoop() && downstreamPending)) { 290 // Request has not been issued yet, or it's been issued 291 // locally but is buffered unissued at some downstream cache 292 // which is forwarding us this snoop. Either way, the packet 293 // we're snooping logically precedes this MSHR's request, so 294 // the snoop has no impact on the MSHR, but must be processed 295 // in the standard way by the cache. The only exception is 296 // that if we're an L2+ cache buffering an UpgradeReq from a 297 // higher-level cache, and the snoop is invalidating, then our 298 // buffered upgrades must be converted to read exclusives, 299 // since the upper-level cache no longer has a valid copy. 300 // That is, even though the upper-level cache got out on its 301 // local bus first, some other invalidating transaction 302 // reached the global bus before the upgrade did. 303 if (pkt->needsExclusive()) { 304 targets->replaceUpgrades(); 305 deferredTargets->replaceUpgrades(); 306 } 307 308 return false; 309 } 310 311 // From here on down, the request issued by this MSHR logically 312 // precedes the request we're snooping. 313 if (pkt->needsExclusive()) { 314 // snooped request still precedes the re-request we'll have to 315 // issue for deferred targets, if any... 316 deferredTargets->replaceUpgrades(); 317 } 318 319 if (hasPostInvalidate()) { 320 // a prior snoop has already appended an invalidation, so 321 // logically we don't have the block anymore; no need for 322 // further snooping. 323 return true; 324 } 325 326 if (isPendingDirty() || pkt->isInvalidate()) { 327 // We need to save and replay the packet in two cases: 328 // 1. We're awaiting an exclusive copy, so ownership is pending, 329 // and we need to respond after we receive data. 330 // 2. It's an invalidation (e.g., UpgradeReq), and we need 331 // to forward the snoop up the hierarchy after the current 332 // transaction completes. 333 334 // Actual target device (typ. PhysicalMemory) will delete the 335 // packet on reception, so we need to save a copy here. 336 PacketPtr cp_pkt = new Packet(pkt, true); 337 targets->add(cp_pkt, curTick(), _order, Target::FromSnoop, 338 downstreamPending && targets->needsExclusive); 339 ++ntargets; 340 341 if (isPendingDirty()) { 342 pkt->assertMemInhibit(); 343 pkt->setSupplyExclusive(); 344 } 345 346 if (pkt->needsExclusive()) { 347 // This transaction will take away our pending copy 348 postInvalidate = true; 349 } 350 } 351 352 if (!pkt->needsExclusive()) { 353 // This transaction will get a read-shared copy, downgrading 354 // our copy if we had an exclusive one 355 postDowngrade = true; 356 pkt->assertShared(); 357 } 358 359 return true; 360} 361 362 363bool 364MSHR::promoteDeferredTargets() 365{ 366 assert(targets->empty()); 367 if (deferredTargets->empty()) { 368 return false; 369 } 370 371 // swap targets & deferredTargets lists 372 TargetList *tmp = targets; 373 targets = deferredTargets; 374 deferredTargets = tmp; 375 376 assert(targets->size() == ntargets); 377 378 // clear deferredTargets flags 379 deferredTargets->resetFlags(); 380 381 order = targets->front().order; 382 readyTime = std::max(curTick(), targets->front().readyTime); 383 384 return true; 385} 386 387 388void 389MSHR::handleFill(Packet *pkt, CacheBlk *blk) 390{ 391 if (!pkt->sharedAsserted() 392 && !(hasPostInvalidate() || hasPostDowngrade()) 393 && deferredTargets->needsExclusive) { 394 // We got an exclusive response, but we have deferred targets 395 // which are waiting to request an exclusive copy (not because 396 // of a pending invalidate). This can happen if the original 397 // request was for a read-only (non-exclusive) block, but we 398 // got an exclusive copy anyway because of the E part of the 399 // MOESI/MESI protocol. Since we got the exclusive copy 400 // there's no need to defer the targets, so move them up to 401 // the regular target list. 402 assert(!targets->needsExclusive); 403 targets->needsExclusive = true; 404 // if any of the deferred targets were upper-level cache 405 // requests marked downstreamPending, need to clear that 406 assert(!downstreamPending); // not pending here anymore 407 deferredTargets->clearDownstreamPending(); 408 // this clears out deferredTargets too 409 targets->splice(targets->end(), *deferredTargets); 410 deferredTargets->resetFlags(); 411 } 412} 413 414 415bool 416MSHR::checkFunctional(PacketPtr pkt) 417{ 418 // For printing, we treat the MSHR as a whole as single entity. 419 // For other requests, we iterate over the individual targets 420 // since that's where the actual data lies. 421 if (pkt->isPrint()) { 422 pkt->checkFunctional(this, addr, size, NULL); 423 return false; 424 } else { 425 return (targets->checkFunctional(pkt) || 426 deferredTargets->checkFunctional(pkt)); 427 } 428} 429 430 431void 432MSHR::print(std::ostream &os, int verbosity, const std::string &prefix) const 433{ 434 ccprintf(os, "%s[%x:%x] %s %s %s state: %s %s %s %s\n", 435 prefix, addr, addr+size-1, 436 isForward ? "Forward" : "", 437 isForwardNoResponse() ? "ForwNoResp" : "", 438 needsExclusive() ? "Excl" : "", 439 _isUncacheable ? "Unc" : "", 440 inService ? "InSvc" : "", 441 downstreamPending ? "DwnPend" : "", 442 hasPostInvalidate() ? "PostInv" : "", 443 hasPostDowngrade() ? "PostDowngr" : ""); 444 445 ccprintf(os, "%s Targets:\n", prefix); 446 targets->print(os, verbosity, prefix + " "); 447 if (!deferredTargets->empty()) { 448 ccprintf(os, "%s Deferred Targets:\n", prefix); 449 deferredTargets->print(os, verbosity, prefix + " "); 450 } 451} 452 453MSHR::~MSHR() 454{ 455}
|