diff options
author | Stephan Diestelhorst <stephan.diestelhorst@ARM.com> | 2015-03-17 11:50:55 +0000 |
---|---|---|
committer | Stephan Diestelhorst <stephan.diestelhorst@ARM.com> | 2015-03-17 11:50:55 +0000 |
commit | 2847d5f5177304236dcdbab112a0369f0bd96aea (patch) | |
tree | ec99cb6bb885cd97a6eb81cb07bc1710b3e348fb /src | |
parent | 706597f021811511e71fddeeab7dcfc33bfd5f35 (diff) | |
download | gem5-2847d5f5177304236dcdbab112a0369f0bd96aea.tar.xz |
mem: Create a request copy for deferred snoops
Sometimes, we need to defer an express snoop in an MSHR, but the original
request might complete and deallocate the original pkt->req. In those cases,
create a copy of the request so that someone who is inspecting the delayed
snoop can also inspect the request still. All of this is rather hacky, but the
allocation / linking and general life-time management of Packet and Request is
rather tricky. Deleting the copy is another tricky area, testing so far has
shown that the right copy is deleted at the right time.
Diffstat (limited to 'src')
-rw-r--r-- | src/mem/cache/cache_impl.hh | 12 | ||||
-rw-r--r-- | src/mem/cache/mshr.cc | 17 |
2 files changed, 24 insertions, 5 deletions
diff --git a/src/mem/cache/cache_impl.hh b/src/mem/cache/cache_impl.hh index d36195fe9..734ca826c 100644 --- a/src/mem/cache/cache_impl.hh +++ b/src/mem/cache/cache_impl.hh @@ -1713,8 +1713,16 @@ Cache::handleSnoop(PacketPtr pkt, CacheBlk *blk, bool is_timing, if (!respond && is_timing && is_deferred) { // if it's a deferred timing snoop then we've made a copy of - // the packet, and so if we're not using that copy to respond - // then we need to delete it here. + // both the request and the packet, and so if we're not using + // those copies to respond and delete them here + DPRINTF(Cache, "Deleting pkt %p and request %p for cmd %s addr: %p\n", + pkt, pkt->req, pkt->cmdString(), pkt->getAddr()); + + // the packets needs a response (just not from us), so we also + // need to delete the request and not rely on the packet + // destructor + assert(pkt->needsResponse()); + delete pkt->req; delete pkt; } diff --git a/src/mem/cache/mshr.cc b/src/mem/cache/mshr.cc index c59fa0020..78900ed4e 100644 --- a/src/mem/cache/mshr.cc +++ b/src/mem/cache/mshr.cc @@ -365,17 +365,28 @@ MSHR::handleSnoop(PacketPtr pkt, Counter _order) // Clear flags and also allocate new data as the original // packet data storage may have been deleted by the time we // get to send this packet. - PacketPtr cp_pkt = new Packet(pkt, true, true); - targets.add(cp_pkt, curTick(), _order, Target::FromSnoop, - downstreamPending && targets.needsExclusive); + PacketPtr cp_pkt = nullptr; if (isPendingDirty()) { + // Case 1: The new packet will need to get the response from the + // MSHR already queued up here + cp_pkt = new Packet(pkt, true, true); pkt->assertMemInhibit(); // in the case of an uncacheable request there is no need // to set the exclusive flag, but since the recipient does // not care there is no harm in doing so pkt->setSupplyExclusive(); + } else { + // Case 2: We only need to buffer the packet for information + // purposes; the original request can proceed without waiting + // => Create a copy of the request, as that may get deallocated as + // well + cp_pkt = new Packet(new Request(*pkt->req), pkt->cmd); + DPRINTF(Cache, "Copying packet %p -> %p and request %p -> %p\n", + pkt, cp_pkt, pkt->req, cp_pkt->req); } + targets.add(cp_pkt, curTick(), _order, Target::FromSnoop, + downstreamPending && targets.needsExclusive); if (pkt->needsExclusive()) { // This transaction will take away our pending copy |