void satisfyCpuSideRequest(PacketPtr pkt, BlkType *blk);
bool satisfyMSHR(MSHR *mshr, PacketPtr pkt, BlkType *blk);
- void doTimingSupplyResponse(PacketPtr req_pkt, uint8_t *blk_data);
+ void doTimingSupplyResponse(PacketPtr req_pkt, uint8_t *blk_data,
+ bool already_copied);
/**
* Sets the blk to the new state.
* @param blk The cache block being snooped.
* @param new_state The new coherence state for the block.
*/
- void handleSnoop(PacketPtr ptk, BlkType *blk, bool is_timing);
+ void handleSnoop(PacketPtr ptk, BlkType *blk,
+ bool is_timing, bool is_deferred);
/**
* Create a writeback request for the given block.
} else {
// response to snoop request
DPRINTF(Cache, "processing deferred snoop...\n");
- handleSnoop(target->pkt, blk, true);
+ handleSnoop(target->pkt, blk, true, true);
}
mshr->popTarget();
pkt->getAddr());
BlkType *blk = tags->findBlock(pkt->getAddr());
- if (blk == NULL && pkt->cmd == MemCmd::UpgradeResp) {
- if (!mshr->handleReplacedPendingUpgrade(pkt)) {
- mq->markPending(mshr);
- requestMemSideBus((RequestCause)mq->index, pkt->finishTime);
- return;
- }
+ if (!mshr->handleFill(pkt, blk)) {
+ mq->markPending(mshr);
+ requestMemSideBus((RequestCause)mq->index, pkt->finishTime);
+ return;
}
PacketList writebacks;
template<class TagStore, class Coherence>
void
Cache<TagStore,Coherence>::doTimingSupplyResponse(PacketPtr req_pkt,
- uint8_t *blk_data)
+ uint8_t *blk_data,
+ bool already_copied)
{
- // timing-mode snoop responses require a new packet
- PacketPtr pkt = new Packet(req_pkt);
+ // timing-mode snoop responses require a new packet, unless we
+ // already made a copy...
+ PacketPtr pkt = already_copied ? req_pkt : new Packet(req_pkt);
pkt->allocate();
pkt->makeTimingResponse();
pkt->setDataFromBlock(blk_data, blkSize);
template<class TagStore, class Coherence>
void
Cache<TagStore,Coherence>::handleSnoop(PacketPtr pkt, BlkType *blk,
- bool is_timing)
+ bool is_timing, bool is_deferred)
{
if (!blk || !blk->isValid()) {
return;
}
if (supply) {
+ assert(!pkt->memInhibitAsserted());
pkt->assertMemInhibit();
if (is_timing) {
- doTimingSupplyResponse(pkt, blk->data);
+ doTimingSupplyResponse(pkt, blk->data, is_deferred);
} else {
pkt->makeAtomicResponse();
pkt->setDataFromBlock(blk->data, blkSize);
// better not be snooping a request that conflicts with something
// we have outstanding...
if (mshr && mshr->inService) {
+ DPRINTF(Cache, "Deferring snoop on in-service MSHR to blk %x\n",
+ blk_addr);
mshr->allocateSnoopTarget(pkt, curTick, order++);
if (mshr->getNumTargets() > numTarget)
warn("allocating bonus target for snoop"); //handle later
assert(wb_pkt->cmd == MemCmd::Writeback);
if (pkt->isRead()) {
+ assert(!pkt->memInhibitAsserted());
pkt->assertMemInhibit();
if (!pkt->needsExclusive()) {
pkt->assertShared();
// the packet's invalidate flag is set...
assert(pkt->isInvalidate());
}
- doTimingSupplyResponse(pkt, wb_pkt->getPtr<uint8_t>());
+ doTimingSupplyResponse(pkt, wb_pkt->getPtr<uint8_t>(), false);
}
if (pkt->isInvalidate()) {
}
}
- handleSnoop(pkt, blk, true);
+ handleSnoop(pkt, blk, true, false);
}
}
BlkType *blk = tags->findBlock(pkt->getAddr());
- handleSnoop(pkt, blk, false);
+ handleSnoop(pkt, blk, false, false);
return hitLatency;
}
assert(deferredTargets.empty());
deferredNeedsExclusive = false;
pendingInvalidate = false;
+ pendingShared = false;
replacedPendingUpgrade = false;
data = NULL;
}
}
void
-MSHR::allocateSnoopTarget(PacketPtr target, Tick when, Counter _order)
+MSHR::allocateSnoopTarget(PacketPtr pkt, Tick when, Counter _order)
{
assert(inService); // don't bother to call otherwise
return;
}
- if (needsExclusive) {
- // We're awaiting an exclusive copy, so ownership is pending.
- // It's up to us to respond once the data arrives.
- target->assertMemInhibit();
- }
+ DPRINTF(Cache, "deferred snoop on %x: %s %s\n", addr,
+ needsExclusive ? "needsExclusive" : "",
+ pkt->needsExclusive() ? "pkt->needsExclusive()" : "");
+
+ if (needsExclusive || pkt->needsExclusive()) {
+ // actual target device (typ. PhysicalMemory) will delete the
+ // packet on reception, so we need to save a copy here
+ targets.push_back(Target(new Packet(pkt), when, _order, false));
+ ++ntargets;
+
+ if (needsExclusive) {
+ // We're awaiting an exclusive copy, so ownership is pending.
+ // It's up to us to respond once the data arrives.
+ pkt->assertMemInhibit();
+ }
- if (target->needsExclusive()) {
- // This transaction will take away our pending copy
- pendingInvalidate = true;
+ if (pkt->needsExclusive()) {
+ // This transaction will take away our pending copy
+ pendingInvalidate = true;
+ }
} else {
- // We'll keep our pending copy, but we can't let the other guy
- // think he's getting it exclusive
- target->assertShared();
+ // Read to a read: no conflict, so no need to record as
+ // target, but make sure neither reader thinks he's getting an
+ // exclusive copy
+ pendingShared = true;
+ pkt->assertShared();
}
-
- targets.push_back(Target(target, when, _order, false));
- ++ntargets;
}
needsExclusive = deferredNeedsExclusive;
pendingInvalidate = false;
+ pendingShared = false;
deferredNeedsExclusive = false;
order = targets.front().order;
readyTick = std::max(curTick, targets.front().time);
bool
-MSHR::handleReplacedPendingUpgrade(Packet *pkt)
+MSHR::handleFill(Packet *pkt, CacheBlk *blk)
{
- // @TODO: if upgrade is nacked and replacedPendingUpgradeDirty is true, then we need to writeback the data (or rel
- assert(pkt->cmd == MemCmd::UpgradeResp);
- assert(replacedPendingUpgrade);
- replacedPendingUpgrade = false; // reset
- if (replacedPendingUpgradeDirty) {
- // we wrote back the previous copy; just reissue as a ReadEx
- return false;
+ if (replacedPendingUpgrade) {
+ // block was replaced while upgrade request was in service
+ assert(pkt->cmd == MemCmd::UpgradeResp);
+ assert(blk == NULL);
+ assert(replacedPendingUpgrade);
+ replacedPendingUpgrade = false; // reset
+ if (replacedPendingUpgradeDirty) {
+ // we wrote back the previous copy; just reissue as a ReadEx
+ return false;
+ }
+
+ // previous copy was not dirty, but we are now owner... fake out
+ // cache by taking saved data and converting UpgradeResp to
+ // ReadExResp
+ assert(data);
+ pkt->cmd = MemCmd::ReadExResp;
+ pkt->setData(data);
+ delete [] data;
+ data = NULL;
+ } else if (pendingShared) {
+ // we snooped another read while this read was in
+ // service... assert shared line on its behalf
+ pkt->assertShared();
}
- // previous copy was not dirty, but we are now owner... fake out
- // cache by taking saved data and converting UpgradeResp to
- // ReadExResp
- assert(data);
- pkt->cmd = MemCmd::ReadExResp;
- pkt->setData(data);
- delete [] data;
- data = NULL;
return true;
}
bool deferredNeedsExclusive;
bool pendingInvalidate;
+ bool pendingShared;
/** Is there a pending upgrade that got replaced? */
bool replacedPendingUpgrade;
bool replacedPendingUpgradeDirty;
bool promoteDeferredTargets();
void handleReplacement(CacheBlk *blk, int blkSize);
- bool handleReplacedPendingUpgrade(Packet *pkt);
+ bool handleFill(Packet *pkt, CacheBlk *blk);
/**
* Prints the contents of this MSHR to stderr.
totalRefs += blk->refCount;
++sampledRefs;
blk->refCount = 0;
+
+ DPRINTF(Cache, "set %x: selecting blk %x for replacement\n",
+ set, regenerateBlkAddr(blk->tag, set));
} else if (!blk->isTouched) {
tagsInUse++;
blk->isTouched = true;
}
}
- DPRINTF(Cache, "set %x: selecting blk %x for replacement\n",
- set, regenerateBlkAddr(blk->tag, set));
return blk;
}
// if we ever added it back.
assert(pkt->isRequest());
assert(pkt->result == Packet::Unknown);
+
+ if (pkt->memInhibitAsserted()) {
+ // snooper will supply based on copy of packet
+ // still target's responsibility to delete packet
+ delete pkt->req;
+ delete pkt;
+ return true;
+ }
+
bool needsResponse = pkt->needsResponse();
Tick latency = recvAtomic(pkt);
// turn packet around to go back to requester if response expected
if (needsResponse) {
- // recvAtomic() should already have turned packet into atomic response
+ // recvAtomic() should already have turned packet into
+ // atomic response
assert(pkt->isResponse());
pkt->convertAtomicToTimingResponse();
schedSendTiming(pkt, curTick + latency);
delete pkt->req;
delete pkt;
}
+
return true;
}