mshr.cc revision 7667
19646SChris.Emmons@arm.com/*
210839Sandreas.sandberg@arm.com * Copyright (c) 2002-2005 The Regents of The University of Michigan
39646SChris.Emmons@arm.com * Copyright (c) 2010 Advanced Micro Devices, Inc.
49646SChris.Emmons@arm.com * All rights reserved.
59646SChris.Emmons@arm.com *
69646SChris.Emmons@arm.com * Redistribution and use in source and binary forms, with or without
79646SChris.Emmons@arm.com * modification, are permitted provided that the following conditions are
89646SChris.Emmons@arm.com * met: redistributions of source code must retain the above copyright
99646SChris.Emmons@arm.com * notice, this list of conditions and the following disclaimer;
109646SChris.Emmons@arm.com * redistributions in binary form must reproduce the above copyright
119646SChris.Emmons@arm.com * notice, this list of conditions and the following disclaimer in the
129646SChris.Emmons@arm.com * documentation and/or other materials provided with the distribution;
139646SChris.Emmons@arm.com * neither the name of the copyright holders nor the names of its
149646SChris.Emmons@arm.com * contributors may be used to endorse or promote products derived from
159646SChris.Emmons@arm.com * this software without specific prior written permission.
169646SChris.Emmons@arm.com *
179646SChris.Emmons@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
189646SChris.Emmons@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
199646SChris.Emmons@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
209646SChris.Emmons@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
219646SChris.Emmons@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
229646SChris.Emmons@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
239646SChris.Emmons@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
249646SChris.Emmons@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
259646SChris.Emmons@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
269646SChris.Emmons@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
279646SChris.Emmons@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
289646SChris.Emmons@arm.com *
299646SChris.Emmons@arm.com * Authors: Erik Hallnor
309646SChris.Emmons@arm.com *          Dave Greene
319646SChris.Emmons@arm.com */
329646SChris.Emmons@arm.com
339646SChris.Emmons@arm.com/**
349646SChris.Emmons@arm.com * @file
359646SChris.Emmons@arm.com * Miss Status and Handling Register (MSHR) definitions.
369646SChris.Emmons@arm.com */
379646SChris.Emmons@arm.com
3811090Sandreas.sandberg@arm.com#include <algorithm>
399646SChris.Emmons@arm.com#include <cassert>
409646SChris.Emmons@arm.com#include <string>
419646SChris.Emmons@arm.com#include <vector>
429646SChris.Emmons@arm.com
439646SChris.Emmons@arm.com#include "base/misc.hh"
449646SChris.Emmons@arm.com#include "base/types.hh"
459646SChris.Emmons@arm.com#include "mem/cache/cache.hh"
469646SChris.Emmons@arm.com#include "mem/cache/mshr.hh"
479646SChris.Emmons@arm.com#include "sim/core.hh"
489646SChris.Emmons@arm.com
499646SChris.Emmons@arm.comusing namespace std;
509646SChris.Emmons@arm.com
519646SChris.Emmons@arm.comMSHR::MSHR()
529646SChris.Emmons@arm.com{
539646SChris.Emmons@arm.com    inService = false;
549646SChris.Emmons@arm.com    ntargets = 0;
559646SChris.Emmons@arm.com    threadNum = InvalidThreadID;
569646SChris.Emmons@arm.com    targets = new TargetList();
579646SChris.Emmons@arm.com    deferredTargets = new TargetList();
589646SChris.Emmons@arm.com}
599646SChris.Emmons@arm.com
609646SChris.Emmons@arm.com
619646SChris.Emmons@arm.comMSHR::TargetList::TargetList()
629646SChris.Emmons@arm.com    : needsExclusive(false), hasUpgrade(false)
639646SChris.Emmons@arm.com{}
649646SChris.Emmons@arm.com
6511090Sandreas.sandberg@arm.com
6611090Sandreas.sandberg@arm.cominline void
6711090Sandreas.sandberg@arm.comMSHR::TargetList::add(PacketPtr pkt, Tick readyTime,
6811090Sandreas.sandberg@arm.com                      Counter order, Target::Source source, bool markPending)
6911090Sandreas.sandberg@arm.com{
7011090Sandreas.sandberg@arm.com    if (source != Target::FromSnoop) {
7111090Sandreas.sandberg@arm.com        if (pkt->needsExclusive()) {
7211090Sandreas.sandberg@arm.com            needsExclusive = true;
7311090Sandreas.sandberg@arm.com        }
749646SChris.Emmons@arm.com
759646SChris.Emmons@arm.com        if (pkt->isUpgrade()) {
769646SChris.Emmons@arm.com            hasUpgrade = true;
779646SChris.Emmons@arm.com        }
789646SChris.Emmons@arm.com    }
799646SChris.Emmons@arm.com
8010839Sandreas.sandberg@arm.com    if (markPending) {
819646SChris.Emmons@arm.com        MSHR *mshr = dynamic_cast<MSHR*>(pkt->senderState);
8210839Sandreas.sandberg@arm.com        if (mshr != NULL) {
8310839Sandreas.sandberg@arm.com            assert(!mshr->downstreamPending);
849646SChris.Emmons@arm.com            mshr->downstreamPending = true;
8511090Sandreas.sandberg@arm.com        }
869646SChris.Emmons@arm.com    }
879646SChris.Emmons@arm.com
889646SChris.Emmons@arm.com    push_back(Target(pkt, readyTime, order, source, markPending));
8911090Sandreas.sandberg@arm.com}
9011090Sandreas.sandberg@arm.com
919646SChris.Emmons@arm.com
929646SChris.Emmons@arm.comstatic void
939646SChris.Emmons@arm.comreplaceUpgrade(PacketPtr pkt)
9411090Sandreas.sandberg@arm.com{
9511090Sandreas.sandberg@arm.com    if (pkt->cmd == MemCmd::UpgradeReq) {
9611090Sandreas.sandberg@arm.com        pkt->cmd = MemCmd::ReadExReq;
979646SChris.Emmons@arm.com        DPRINTF(Cache, "Replacing UpgradeReq with ReadExReq\n");
9811168Sandreas.hansson@arm.com    } else if (pkt->cmd == MemCmd::SCUpgradeReq) {
9911091Sandreas.sandberg@arm.com        pkt->cmd = MemCmd::SCUpgradeFailReq;
10011168Sandreas.hansson@arm.com        DPRINTF(Cache, "Replacing SCUpgradeReq with SCUpgradeFailReq\n");
10111168Sandreas.hansson@arm.com    }
10211090Sandreas.sandberg@arm.com}
10311168Sandreas.hansson@arm.com
10411090Sandreas.sandberg@arm.com
10511090Sandreas.sandberg@arm.comvoid
10611168Sandreas.hansson@arm.comMSHR::TargetList::replaceUpgrades()
10711168Sandreas.hansson@arm.com{
10811090Sandreas.sandberg@arm.com    if (!hasUpgrade)
10911168Sandreas.hansson@arm.com        return;
11011090Sandreas.sandberg@arm.com
11111090Sandreas.sandberg@arm.com    Iterator end_i = end();
11211090Sandreas.sandberg@arm.com    for (Iterator i = begin(); i != end_i; ++i) {
11311090Sandreas.sandberg@arm.com        replaceUpgrade(i->pkt);
11411090Sandreas.sandberg@arm.com    }
11511090Sandreas.sandberg@arm.com
11611090Sandreas.sandberg@arm.com    hasUpgrade = false;
11711090Sandreas.sandberg@arm.com}
11811090Sandreas.sandberg@arm.com
11911090Sandreas.sandberg@arm.com
1209646SChris.Emmons@arm.comvoid
1219646SChris.Emmons@arm.comMSHR::TargetList::clearDownstreamPending()
1229646SChris.Emmons@arm.com{
1239646SChris.Emmons@arm.com    Iterator end_i = end();
1249646SChris.Emmons@arm.com    for (Iterator i = begin(); i != end_i; ++i) {
1259646SChris.Emmons@arm.com        if (i->markedPending) {
1269646SChris.Emmons@arm.com            MSHR *mshr = dynamic_cast<MSHR*>(i->pkt->senderState);
1279646SChris.Emmons@arm.com            if (mshr != NULL) {
1289646SChris.Emmons@arm.com                mshr->clearDownstreamPending();
1299646SChris.Emmons@arm.com            }
1309646SChris.Emmons@arm.com        }
1319646SChris.Emmons@arm.com    }
1329646SChris.Emmons@arm.com}
1339646SChris.Emmons@arm.com
1349646SChris.Emmons@arm.com
1359646SChris.Emmons@arm.combool
1369646SChris.Emmons@arm.comMSHR::TargetList::checkFunctional(PacketPtr pkt)
1379646SChris.Emmons@arm.com{
1389646SChris.Emmons@arm.com    Iterator end_i = end();
1399646SChris.Emmons@arm.com    for (Iterator i = begin(); i != end_i; ++i) {
1409646SChris.Emmons@arm.com        if (pkt->checkFunctional(i->pkt)) {
1419646SChris.Emmons@arm.com            return true;
1429646SChris.Emmons@arm.com        }
1439646SChris.Emmons@arm.com    }
1449646SChris.Emmons@arm.com
14511090Sandreas.sandberg@arm.com    return false;
14611090Sandreas.sandberg@arm.com}
1479646SChris.Emmons@arm.com
1489646SChris.Emmons@arm.com
14911090Sandreas.sandberg@arm.comvoid
1509646SChris.Emmons@arm.comMSHR::TargetList::
1519646SChris.Emmons@arm.comprint(std::ostream &os, int verbosity, const std::string &prefix) const
15211090Sandreas.sandberg@arm.com{
1539646SChris.Emmons@arm.com    ConstIterator end_i = end();
15411090Sandreas.sandberg@arm.com    for (ConstIterator i = begin(); i != end_i; ++i) {
15511090Sandreas.sandberg@arm.com        const char *s;
1569646SChris.Emmons@arm.com        switch (i->source) {
1579646SChris.Emmons@arm.com          case Target::FromCPU: s = "FromCPU";
15811090Sandreas.sandberg@arm.com          case Target::FromSnoop: s = "FromSnoop";
1599646SChris.Emmons@arm.com          case Target::FromPrefetcher: s = "FromPrefetcher";
16011090Sandreas.sandberg@arm.com          default: s = "";
16111090Sandreas.sandberg@arm.com        }
16210839Sandreas.sandberg@arm.com        ccprintf(os, "%s%s: ", prefix, s);
1639646SChris.Emmons@arm.com        i->pkt->print(os, verbosity, "");
1649646SChris.Emmons@arm.com    }
1659646SChris.Emmons@arm.com}
1669646SChris.Emmons@arm.com
1679646SChris.Emmons@arm.com
1689646SChris.Emmons@arm.comvoid
1699646SChris.Emmons@arm.comMSHR::allocate(Addr _addr, int _size, PacketPtr target,
1709646SChris.Emmons@arm.com               Tick whenReady, Counter _order)
1719646SChris.Emmons@arm.com{
1729646SChris.Emmons@arm.com    addr = _addr;
1739646SChris.Emmons@arm.com    size = _size;
17411090Sandreas.sandberg@arm.com    readyTime = whenReady;
17511090Sandreas.sandberg@arm.com    order = _order;
17611090Sandreas.sandberg@arm.com    assert(target);
17711090Sandreas.sandberg@arm.com    isForward = false;
1789646SChris.Emmons@arm.com    _isUncacheable = target->req->isUncacheable();
1799646SChris.Emmons@arm.com    inService = false;
1809646SChris.Emmons@arm.com    downstreamPending = false;
1819646SChris.Emmons@arm.com    threadNum = 0;
1829646SChris.Emmons@arm.com    ntargets = 1;
1839646SChris.Emmons@arm.com    assert(targets->isReset());
1849646SChris.Emmons@arm.com    // Don't know of a case where we would allocate a new MSHR for a
1859646SChris.Emmons@arm.com    // snoop (mem-side request), so set source according to request here
1869646SChris.Emmons@arm.com    Target::Source source = (target->cmd == MemCmd::HardPFReq) ?
1879646SChris.Emmons@arm.com        Target::FromPrefetcher : Target::FromCPU;
1889646SChris.Emmons@arm.com    targets->add(target, whenReady, _order, source, true);
1899646SChris.Emmons@arm.com    assert(deferredTargets->isReset());
1909646SChris.Emmons@arm.com    data = NULL;
1919646SChris.Emmons@arm.com}
1929646SChris.Emmons@arm.com
1939646SChris.Emmons@arm.com
1949646SChris.Emmons@arm.comvoid
1959646SChris.Emmons@arm.comMSHR::clearDownstreamPending()
1969646SChris.Emmons@arm.com{
1979646SChris.Emmons@arm.com    assert(downstreamPending);
1989646SChris.Emmons@arm.com    downstreamPending = false;
1999646SChris.Emmons@arm.com    // recursively clear flag on any MSHRs we will be forwarding
2009646SChris.Emmons@arm.com    // responses to
2019646SChris.Emmons@arm.com    targets->clearDownstreamPending();
2029646SChris.Emmons@arm.com}
2039646SChris.Emmons@arm.com
2049646SChris.Emmons@arm.combool
2059646SChris.Emmons@arm.comMSHR::markInService(PacketPtr pkt)
2069646SChris.Emmons@arm.com{
2079646SChris.Emmons@arm.com    assert(!inService);
2089646SChris.Emmons@arm.com    if (isForwardNoResponse()) {
2099646SChris.Emmons@arm.com        // we just forwarded the request packet & don't expect a
2109646SChris.Emmons@arm.com        // response, so get rid of it
2119646SChris.Emmons@arm.com        assert(getNumTargets() == 1);
2129646SChris.Emmons@arm.com        popTarget();
2139646SChris.Emmons@arm.com        return true;
2149646SChris.Emmons@arm.com    }
2159646SChris.Emmons@arm.com    inService = true;
2169646SChris.Emmons@arm.com    pendingDirty = (targets->needsExclusive ||
2179646SChris.Emmons@arm.com                    (!pkt->sharedAsserted() && pkt->memInhibitAsserted()));
2189646SChris.Emmons@arm.com    postInvalidate = postDowngrade = false;
2199646SChris.Emmons@arm.com
2209646SChris.Emmons@arm.com    if (!downstreamPending) {
2219646SChris.Emmons@arm.com        // let upstream caches know that the request has made it to a
2229646SChris.Emmons@arm.com        // level where it's going to get a response
2239646SChris.Emmons@arm.com        targets->clearDownstreamPending();
2249646SChris.Emmons@arm.com    }
2259646SChris.Emmons@arm.com    return false;
2269646SChris.Emmons@arm.com}
2279646SChris.Emmons@arm.com
2289646SChris.Emmons@arm.com
2299646SChris.Emmons@arm.comvoid
2309646SChris.Emmons@arm.comMSHR::deallocate()
2319646SChris.Emmons@arm.com{
23211090Sandreas.sandberg@arm.com    assert(targets->empty());
23311090Sandreas.sandberg@arm.com    targets->resetFlags();
23411090Sandreas.sandberg@arm.com    assert(deferredTargets->isReset());
2359646SChris.Emmons@arm.com    assert(ntargets == 0);
2369646SChris.Emmons@arm.com    inService = false;
2379646SChris.Emmons@arm.com}
23811090Sandreas.sandberg@arm.com
2399646SChris.Emmons@arm.com/*
2409646SChris.Emmons@arm.com * Adds a target to an MSHR
2419646SChris.Emmons@arm.com */
2429646SChris.Emmons@arm.comvoid
2439646SChris.Emmons@arm.comMSHR::allocateTarget(PacketPtr pkt, Tick whenReady, Counter _order)
2449646SChris.Emmons@arm.com{
2459646SChris.Emmons@arm.com    // if there's a request already in service for this MSHR, we will
2469646SChris.Emmons@arm.com    // have to defer the new target until after the response if any of
2479646SChris.Emmons@arm.com    // the following are true:
2489646SChris.Emmons@arm.com    // - there are other targets already deferred
2499646SChris.Emmons@arm.com    // - there's a pending invalidate to be applied after the response
2509646SChris.Emmons@arm.com    //   comes back (but before this target is processed)
2519646SChris.Emmons@arm.com    // - this target requires an exclusive block and either we're not
2529646SChris.Emmons@arm.com    //   getting an exclusive block back or we have already snooped
2539646SChris.Emmons@arm.com    //   another read request that will downgrade our exclusive block
2549646SChris.Emmons@arm.com    //   to shared
2559646SChris.Emmons@arm.com
25611090Sandreas.sandberg@arm.com    // assume we'd never issue a prefetch when we've got an
25711090Sandreas.sandberg@arm.com    // outstanding miss
2589646SChris.Emmons@arm.com    assert(pkt->cmd != MemCmd::HardPFReq);
25911090Sandreas.sandberg@arm.com
26011090Sandreas.sandberg@arm.com    if (inService &&
26110839Sandreas.sandberg@arm.com        (!deferredTargets->empty() || hasPostInvalidate() ||
26211090Sandreas.sandberg@arm.com         (pkt->needsExclusive() &&
26311090Sandreas.sandberg@arm.com          (!isPendingDirty() || hasPostDowngrade() || isForward)))) {
26411090Sandreas.sandberg@arm.com        // need to put on deferred list
26511090Sandreas.sandberg@arm.com        if (hasPostInvalidate())
26611090Sandreas.sandberg@arm.com            replaceUpgrade(pkt);
26711090Sandreas.sandberg@arm.com        deferredTargets->add(pkt, whenReady, _order, Target::FromCPU, true);
26811090Sandreas.sandberg@arm.com    } else {
26911090Sandreas.sandberg@arm.com        // No request outstanding, or still OK to append to
27011090Sandreas.sandberg@arm.com        // outstanding request: append to regular target list.  Only
27111090Sandreas.sandberg@arm.com        // mark pending if current request hasn't been issued yet
27211090Sandreas.sandberg@arm.com        // (isn't in service).
27311090Sandreas.sandberg@arm.com        targets->add(pkt, whenReady, _order, Target::FromCPU, !inService);
27411090Sandreas.sandberg@arm.com    }
27511090Sandreas.sandberg@arm.com
27611090Sandreas.sandberg@arm.com    ++ntargets;
27711090Sandreas.sandberg@arm.com}
27811090Sandreas.sandberg@arm.com
27911090Sandreas.sandberg@arm.combool
28011090Sandreas.sandberg@arm.comMSHR::handleSnoop(PacketPtr pkt, Counter _order)
28111090Sandreas.sandberg@arm.com{
28211090Sandreas.sandberg@arm.com    if (!inService || (pkt->isExpressSnoop() && downstreamPending)) {
28311090Sandreas.sandberg@arm.com        // Request has not been issued yet, or it's been issued
28411090Sandreas.sandberg@arm.com        // locally but is buffered unissued at some downstream cache
28511090Sandreas.sandberg@arm.com        // which is forwarding us this snoop.  Either way, the packet
28611090Sandreas.sandberg@arm.com        // we're snooping logically precedes this MSHR's request, so
28711090Sandreas.sandberg@arm.com        // the snoop has no impact on the MSHR, but must be processed
28811090Sandreas.sandberg@arm.com        // in the standard way by the cache.  The only exception is
28911090Sandreas.sandberg@arm.com        // that if we're an L2+ cache buffering an UpgradeReq from a
29011090Sandreas.sandberg@arm.com        // higher-level cache, and the snoop is invalidating, then our
29111090Sandreas.sandberg@arm.com        // buffered upgrades must be converted to read exclusives,
29211090Sandreas.sandberg@arm.com        // since the upper-level cache no longer has a valid copy.
29311090Sandreas.sandberg@arm.com        // That is, even though the upper-level cache got out on its
29411090Sandreas.sandberg@arm.com        // local bus first, some other invalidating transaction
29511090Sandreas.sandberg@arm.com        // reached the global bus before the upgrade did.
29611090Sandreas.sandberg@arm.com        if (pkt->needsExclusive()) {
29711090Sandreas.sandberg@arm.com            targets->replaceUpgrades();
29811090Sandreas.sandberg@arm.com            deferredTargets->replaceUpgrades();
29911090Sandreas.sandberg@arm.com        }
30011090Sandreas.sandberg@arm.com
30111090Sandreas.sandberg@arm.com        return false;
30211090Sandreas.sandberg@arm.com    }
30311090Sandreas.sandberg@arm.com
30411090Sandreas.sandberg@arm.com    // From here on down, the request issued by this MSHR logically
30511090Sandreas.sandberg@arm.com    // precedes the request we're snooping.
30611090Sandreas.sandberg@arm.com    if (pkt->needsExclusive()) {
30711090Sandreas.sandberg@arm.com        // snooped request still precedes the re-request we'll have to
30811090Sandreas.sandberg@arm.com        // issue for deferred targets, if any...
30911090Sandreas.sandberg@arm.com        deferredTargets->replaceUpgrades();
31011090Sandreas.sandberg@arm.com    }
31111090Sandreas.sandberg@arm.com
31211090Sandreas.sandberg@arm.com    if (hasPostInvalidate()) {
31311090Sandreas.sandberg@arm.com        // a prior snoop has already appended an invalidation, so
31411090Sandreas.sandberg@arm.com        // logically we don't have the block anymore; no need for
31511090Sandreas.sandberg@arm.com        // further snooping.
31611090Sandreas.sandberg@arm.com        return true;
31711090Sandreas.sandberg@arm.com    }
31811090Sandreas.sandberg@arm.com
31911294Sandreas.hansson@arm.com    if (isPendingDirty() || pkt->isInvalidate()) {
32011090Sandreas.sandberg@arm.com        // We need to save and replay the packet in two cases:
32111090Sandreas.sandberg@arm.com        // 1. We're awaiting an exclusive copy, so ownership is pending,
32211090Sandreas.sandberg@arm.com        //    and we need to respond after we receive data.
32311090Sandreas.sandberg@arm.com        // 2. It's an invalidation (e.g., UpgradeReq), and we need
32411090Sandreas.sandberg@arm.com        //    to forward the snoop up the hierarchy after the current
32511090Sandreas.sandberg@arm.com        //    transaction completes.
32611090Sandreas.sandberg@arm.com
32711090Sandreas.sandberg@arm.com        // Actual target device (typ. PhysicalMemory) will delete the
32811090Sandreas.sandberg@arm.com        // packet on reception, so we need to save a copy here.
32911090Sandreas.sandberg@arm.com        PacketPtr cp_pkt = new Packet(pkt, true);
33011090Sandreas.sandberg@arm.com        targets->add(cp_pkt, curTick, _order, Target::FromSnoop,
33111168Sandreas.hansson@arm.com                     downstreamPending && targets->needsExclusive);
33211090Sandreas.sandberg@arm.com        ++ntargets;
33311168Sandreas.hansson@arm.com
33411168Sandreas.hansson@arm.com        if (isPendingDirty()) {
33511090Sandreas.sandberg@arm.com            pkt->assertMemInhibit();
33611168Sandreas.hansson@arm.com            pkt->setSupplyExclusive();
33711090Sandreas.sandberg@arm.com        }
33811090Sandreas.sandberg@arm.com
33911090Sandreas.sandberg@arm.com        if (pkt->needsExclusive()) {
34011168Sandreas.hansson@arm.com            // This transaction will take away our pending copy
34111090Sandreas.sandberg@arm.com            postInvalidate = true;
34211090Sandreas.sandberg@arm.com        }
34311090Sandreas.sandberg@arm.com    }
34411090Sandreas.sandberg@arm.com
3459646SChris.Emmons@arm.com    if (!pkt->needsExclusive()) {
3469646SChris.Emmons@arm.com        // This transaction will get a read-shared copy, downgrading
34710839Sandreas.sandberg@arm.com        // our copy if we had an exclusive one
3489646SChris.Emmons@arm.com        postDowngrade = true;
3499646SChris.Emmons@arm.com        pkt->assertShared();
3509646SChris.Emmons@arm.com    }
3519646SChris.Emmons@arm.com
35211090Sandreas.sandberg@arm.com    return true;
35311090Sandreas.sandberg@arm.com}
35411090Sandreas.sandberg@arm.com
35511090Sandreas.sandberg@arm.com
35611090Sandreas.sandberg@arm.combool
35711090Sandreas.sandberg@arm.comMSHR::promoteDeferredTargets()
35811090Sandreas.sandberg@arm.com{
3599646SChris.Emmons@arm.com    assert(targets->empty());
36011090Sandreas.sandberg@arm.com    if (deferredTargets->empty()) {
36111090Sandreas.sandberg@arm.com        return false;
36211090Sandreas.sandberg@arm.com    }
36311090Sandreas.sandberg@arm.com
3649646SChris.Emmons@arm.com    // swap targets & deferredTargets lists
36511090Sandreas.sandberg@arm.com    TargetList *tmp = targets;
36611090Sandreas.sandberg@arm.com    targets = deferredTargets;
36711090Sandreas.sandberg@arm.com    deferredTargets = tmp;
3689646SChris.Emmons@arm.com
36911168Sandreas.hansson@arm.com    assert(targets->size() == ntargets);
37011168Sandreas.hansson@arm.com
3719646SChris.Emmons@arm.com    // clear deferredTargets flags
37211090Sandreas.sandberg@arm.com    deferredTargets->resetFlags();
37311168Sandreas.hansson@arm.com
37411168Sandreas.hansson@arm.com    order = targets->front().order;
3759646SChris.Emmons@arm.com    readyTime = std::max(curTick, targets->front().readyTime);
37611090Sandreas.sandberg@arm.com
37711090Sandreas.sandberg@arm.com    return true;
37811090Sandreas.sandberg@arm.com}
37911090Sandreas.sandberg@arm.com
3809646SChris.Emmons@arm.com
38111090Sandreas.sandberg@arm.comvoid
38211090Sandreas.sandberg@arm.comMSHR::handleFill(Packet *pkt, CacheBlk *blk)
3839646SChris.Emmons@arm.com{
3849646SChris.Emmons@arm.com    if (!pkt->sharedAsserted()
38511090Sandreas.sandberg@arm.com        && !(hasPostInvalidate() || hasPostDowngrade())
38611091Sandreas.sandberg@arm.com        && deferredTargets->needsExclusive) {
38711091Sandreas.sandberg@arm.com        // We got an exclusive response, but we have deferred targets
38811091Sandreas.sandberg@arm.com        // which are waiting to request an exclusive copy (not because
38911091Sandreas.sandberg@arm.com        // of a pending invalidate).  This can happen if the original
39011091Sandreas.sandberg@arm.com        // request was for a read-only (non-exclusive) block, but we
3919646SChris.Emmons@arm.com        // got an exclusive copy anyway because of the E part of the
3929646SChris.Emmons@arm.com        // MOESI/MESI protocol.  Since we got the exclusive copy
3939646SChris.Emmons@arm.com        // there's no need to defer the targets, so move them up to
394        // the regular target list.
395        assert(!targets->needsExclusive);
396        targets->needsExclusive = true;
397        // if any of the deferred targets were upper-level cache
398        // requests marked downstreamPending, need to clear that
399        assert(!downstreamPending);  // not pending here anymore
400        deferredTargets->clearDownstreamPending();
401        // this clears out deferredTargets too
402        targets->splice(targets->end(), *deferredTargets);
403        deferredTargets->resetFlags();
404    }
405}
406
407
408bool
409MSHR::checkFunctional(PacketPtr pkt)
410{
411    // For printing, we treat the MSHR as a whole as single entity.
412    // For other requests, we iterate over the individual targets
413    // since that's where the actual data lies.
414    if (pkt->isPrint()) {
415        pkt->checkFunctional(this, addr, size, NULL);
416        return false;
417    } else {
418        return (targets->checkFunctional(pkt) ||
419                deferredTargets->checkFunctional(pkt));
420    }
421}
422
423
424void
425MSHR::print(std::ostream &os, int verbosity, const std::string &prefix) const
426{
427    ccprintf(os, "%s[%x:%x] %s %s %s state: %s %s %s %s\n",
428             prefix, addr, addr+size-1,
429             isForward ? "Forward" : "",
430             isForwardNoResponse() ? "ForwNoResp" : "",
431             needsExclusive() ? "Excl" : "",
432             _isUncacheable ? "Unc" : "",
433             inService ? "InSvc" : "",
434             downstreamPending ? "DwnPend" : "",
435             hasPostInvalidate() ? "PostInv" : "",
436             hasPostDowngrade() ? "PostDowngr" : "");
437
438    ccprintf(os, "%s  Targets:\n", prefix);
439    targets->print(os, verbosity, prefix + "    ");
440    if (!deferredTargets->empty()) {
441        ccprintf(os, "%s  Deferred Targets:\n", prefix);
442        deferredTargets->print(os, verbosity, prefix + "      ");
443    }
444}
445
446MSHR::~MSHR()
447{
448}
449