coherent_xbar.cc revision 10821
12497SN/A/*
210719SMarco.Balboni@ARM.com * Copyright (c) 2011-2015 ARM Limited
38711SN/A * All rights reserved
48711SN/A *
58711SN/A * The license below extends only to copyright in the software and shall
68711SN/A * not be construed as granting a license to any other intellectual
78711SN/A * property including but not limited to intellectual property relating
88711SN/A * to a hardware implementation of the functionality of the software
98711SN/A * licensed hereunder.  You may use the software subject to the license
108711SN/A * terms below provided that you ensure that this notice is replicated
118711SN/A * unmodified and in its entirety in all distributions of the software,
128711SN/A * modified or unmodified, in source code or in binary form.
138711SN/A *
142497SN/A * Copyright (c) 2006 The Regents of The University of Michigan
152497SN/A * All rights reserved.
162497SN/A *
172497SN/A * Redistribution and use in source and binary forms, with or without
182497SN/A * modification, are permitted provided that the following conditions are
192497SN/A * met: redistributions of source code must retain the above copyright
202497SN/A * notice, this list of conditions and the following disclaimer;
212497SN/A * redistributions in binary form must reproduce the above copyright
222497SN/A * notice, this list of conditions and the following disclaimer in the
232497SN/A * documentation and/or other materials provided with the distribution;
242497SN/A * neither the name of the copyright holders nor the names of its
252497SN/A * contributors may be used to endorse or promote products derived from
262497SN/A * this software without specific prior written permission.
272497SN/A *
282497SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
292497SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
302497SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
312497SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
322497SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332497SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
342497SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
352497SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
362497SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
372497SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
382497SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
392665SN/A *
402665SN/A * Authors: Ali Saidi
418715SN/A *          Andreas Hansson
428922SN/A *          William Wang
432497SN/A */
442497SN/A
452497SN/A/**
462982SN/A * @file
4710405Sandreas.hansson@arm.com * Definition of a crossbar object.
482497SN/A */
492497SN/A
502846SN/A#include "base/misc.hh"
512548SN/A#include "base/trace.hh"
5210405Sandreas.hansson@arm.com#include "debug/AddrRanges.hh"
5310405Sandreas.hansson@arm.com#include "debug/CoherentXBar.hh"
5410405Sandreas.hansson@arm.com#include "mem/coherent_xbar.hh"
559524SN/A#include "sim/system.hh"
562497SN/A
5710405Sandreas.hansson@arm.comCoherentXBar::CoherentXBar(const CoherentXBarParams *p)
5810719SMarco.Balboni@ARM.com    : BaseXBar(p), system(p->system), snoopFilter(p->snoop_filter),
5910719SMarco.Balboni@ARM.com      snoopResponseLatency(p->snoop_response_latency)
607523SN/A{
618851SN/A    // create the ports based on the size of the master and slave
628948SN/A    // vector ports, and the presence of the default port, the ports
638948SN/A    // are enumerated starting from zero
648851SN/A    for (int i = 0; i < p->port_master_connection_count; ++i) {
659095SN/A        std::string portName = csprintf("%s.master[%d]", name(), i);
6610405Sandreas.hansson@arm.com        MasterPort* bp = new CoherentXBarMasterPort(portName, *this, i);
678922SN/A        masterPorts.push_back(bp);
689715SN/A        reqLayers.push_back(new ReqLayer(*bp, *this,
699715SN/A                                         csprintf(".reqLayer%d", i)));
7010713Sandreas.hansson@arm.com        snoopLayers.push_back(new SnoopRespLayer(*bp, *this,
7110713Sandreas.hansson@arm.com                                                 csprintf(".snoopLayer%d", i)));
728851SN/A    }
738851SN/A
748948SN/A    // see if we have a default slave device connected and if so add
758948SN/A    // our corresponding master port
768915SN/A    if (p->port_default_connection_count) {
779031SN/A        defaultPortID = masterPorts.size();
789095SN/A        std::string portName = name() + ".default";
7910405Sandreas.hansson@arm.com        MasterPort* bp = new CoherentXBarMasterPort(portName, *this,
809036SN/A                                                   defaultPortID);
818922SN/A        masterPorts.push_back(bp);
829715SN/A        reqLayers.push_back(new ReqLayer(*bp, *this, csprintf(".reqLayer%d",
839715SN/A                                             defaultPortID)));
8410713Sandreas.hansson@arm.com        snoopLayers.push_back(new SnoopRespLayer(*bp, *this,
8510713Sandreas.hansson@arm.com                                                 csprintf(".snoopLayer%d",
8610713Sandreas.hansson@arm.com                                                          defaultPortID)));
878915SN/A    }
888915SN/A
898948SN/A    // create the slave ports, once again starting at zero
908851SN/A    for (int i = 0; i < p->port_slave_connection_count; ++i) {
919095SN/A        std::string portName = csprintf("%s.slave[%d]", name(), i);
9210405Sandreas.hansson@arm.com        SlavePort* bp = new CoherentXBarSlavePort(portName, *this, i);
938922SN/A        slavePorts.push_back(bp);
949715SN/A        respLayers.push_back(new RespLayer(*bp, *this,
959715SN/A                                           csprintf(".respLayer%d", i)));
969716SN/A        snoopRespPorts.push_back(new SnoopRespPort(*bp, *this));
978851SN/A    }
988851SN/A
9910402SN/A    if (snoopFilter)
10010402SN/A        snoopFilter->setSlavePorts(slavePorts);
10110402SN/A
1027523SN/A    clearPortCache();
1037523SN/A}
1047523SN/A
10510405Sandreas.hansson@arm.comCoherentXBar::~CoherentXBar()
1069715SN/A{
10710405Sandreas.hansson@arm.com    for (auto l: reqLayers)
10810405Sandreas.hansson@arm.com        delete l;
10910405Sandreas.hansson@arm.com    for (auto l: respLayers)
11010405Sandreas.hansson@arm.com        delete l;
11110405Sandreas.hansson@arm.com    for (auto l: snoopLayers)
11210405Sandreas.hansson@arm.com        delete l;
11310405Sandreas.hansson@arm.com    for (auto p: snoopRespPorts)
11410405Sandreas.hansson@arm.com        delete p;
1159715SN/A}
1169715SN/A
1172568SN/Avoid
11810405Sandreas.hansson@arm.comCoherentXBar::init()
1192568SN/A{
1209278SN/A    // the base class is responsible for determining the block size
12110405Sandreas.hansson@arm.com    BaseXBar::init();
1229278SN/A
1238948SN/A    // iterate over our slave ports and determine which of our
1248948SN/A    // neighbouring master ports are snooping and add them as snoopers
12510405Sandreas.hansson@arm.com    for (const auto& p: slavePorts) {
1269088SN/A        // check if the connected master port is snooping
12710405Sandreas.hansson@arm.com        if (p->isSnooping()) {
12810405Sandreas.hansson@arm.com            DPRINTF(AddrRanges, "Adding snooping master %s\n",
12910405Sandreas.hansson@arm.com                    p->getMasterPort().name());
13010405Sandreas.hansson@arm.com            snoopPorts.push_back(p);
1318711SN/A        }
1328711SN/A    }
1332568SN/A
1349036SN/A    if (snoopPorts.empty())
13510405Sandreas.hansson@arm.com        warn("CoherentXBar %s has no snooping ports attached!\n", name());
1363244SN/A}
1373244SN/A
1388948SN/Abool
13910405Sandreas.hansson@arm.comCoherentXBar::recvTimingReq(PacketPtr pkt, PortID slave_port_id)
1403244SN/A{
1418975SN/A    // determine the source port based on the id
1429032SN/A    SlavePort *src_port = slavePorts[slave_port_id];
1433244SN/A
1449091SN/A    // remember if the packet is an express snoop
1459091SN/A    bool is_express_snoop = pkt->isExpressSnoop();
14610656Sandreas.hansson@arm.com    bool is_inhibited = pkt->memInhibitAsserted();
14710656Sandreas.hansson@arm.com    // for normal requests, going downstream, the express snoop flag
14810656Sandreas.hansson@arm.com    // and the inhibited flag should always be the same
14910656Sandreas.hansson@arm.com    assert(is_express_snoop == is_inhibited);
1509091SN/A
1519612SN/A    // determine the destination based on the address
1529712SN/A    PortID master_port_id = findPort(pkt->getAddr());
1539612SN/A
15410405Sandreas.hansson@arm.com    // test if the crossbar should be considered occupied for the current
1559033SN/A    // port, and exclude express snoops from the check
1569715SN/A    if (!is_express_snoop && !reqLayers[master_port_id]->tryTiming(src_port)) {
15710405Sandreas.hansson@arm.com        DPRINTF(CoherentXBar, "recvTimingReq: src %s %s 0x%x BUSY\n",
1588949SN/A                src_port->name(), pkt->cmdString(), pkt->getAddr());
1593244SN/A        return false;
1603244SN/A    }
1613244SN/A
16210405Sandreas.hansson@arm.com    DPRINTF(CoherentXBar, "recvTimingReq: src %s %s expr %d 0x%x\n",
1639091SN/A            src_port->name(), pkt->cmdString(), is_express_snoop,
1649091SN/A            pkt->getAddr());
1655197SN/A
1669712SN/A    // store size and command as they might be modified when
1679712SN/A    // forwarding the packet
1689712SN/A    unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0;
1699712SN/A    unsigned int pkt_cmd = pkt->cmdToIndex();
1709712SN/A
17110719SMarco.Balboni@ARM.com    // store the old header delay so we can restore it if needed
17210719SMarco.Balboni@ARM.com    Tick old_header_delay = pkt->headerDelay;
17310719SMarco.Balboni@ARM.com
17410719SMarco.Balboni@ARM.com    // a request sees the frontend and forward latency
17510719SMarco.Balboni@ARM.com    Tick xbar_delay = (frontendLatency + forwardLatency) * clockPeriod();
17610719SMarco.Balboni@ARM.com
17710719SMarco.Balboni@ARM.com    // set the packet header and payload delay
17810719SMarco.Balboni@ARM.com    calcPacketTiming(pkt, xbar_delay);
17910719SMarco.Balboni@ARM.com
18010719SMarco.Balboni@ARM.com    // determine how long to be crossbar layer is busy
18110719SMarco.Balboni@ARM.com    Tick packetFinishTime = clockEdge(Cycles(1)) + pkt->payloadDelay;
1824912SN/A
18310821Sandreas.hansson@arm.com    if (!system->bypassCaches()) {
1848979SN/A        // the packet is a memory-mapped request and should be
1858979SN/A        // broadcasted to our snoopers but the source
18610402SN/A        if (snoopFilter) {
18710402SN/A            // check with the snoop filter where to forward this packet
18810402SN/A            auto sf_res = snoopFilter->lookupRequest(pkt, *src_port);
18910719SMarco.Balboni@ARM.com            // If SnoopFilter is enabled, the total time required by a packet
19010719SMarco.Balboni@ARM.com            // to be delivered through the xbar has to be charged also with
19110719SMarco.Balboni@ARM.com            // to lookup latency of the snoop filter (sf_res.second).
19210719SMarco.Balboni@ARM.com            pkt->headerDelay += sf_res.second * clockPeriod();
19310402SN/A            packetFinishTime += sf_res.second * clockPeriod();
19410405Sandreas.hansson@arm.com            DPRINTF(CoherentXBar, "recvTimingReq: src %s %s 0x%x"\
19510402SN/A                    " SF size: %i lat: %i\n", src_port->name(),
19610402SN/A                    pkt->cmdString(), pkt->getAddr(), sf_res.first.size(),
19710402SN/A                    sf_res.second);
19810402SN/A            forwardTiming(pkt, slave_port_id, sf_res.first);
19910402SN/A        } else {
20010402SN/A            forwardTiming(pkt, slave_port_id);
20110402SN/A        }
2028979SN/A    }
2038948SN/A
20410656Sandreas.hansson@arm.com    // remember if the packet will generate a snoop response
20510656Sandreas.hansson@arm.com    const bool expect_snoop_resp = !is_inhibited && pkt->memInhibitAsserted();
20610656Sandreas.hansson@arm.com    const bool expect_response = pkt->needsResponse() &&
20710656Sandreas.hansson@arm.com        !pkt->memInhibitAsserted();
2088915SN/A
20910402SN/A    // Note: Cannot create a copy of the full packet, here.
21010402SN/A    MemCmd orig_cmd(pkt->cmd);
21110402SN/A
2129612SN/A    // since it is a normal request, attempt to send the packet
2139712SN/A    bool success = masterPorts[master_port_id]->sendTimingReq(pkt);
2148948SN/A
21510821Sandreas.hansson@arm.com    if (snoopFilter && !system->bypassCaches()) {
21610402SN/A        // The packet may already be overwritten by the sendTimingReq function.
21710402SN/A        // The snoop filter needs to see the original request *and* the return
21810402SN/A        // status of the send operation, so we need to recreate the original
21910402SN/A        // request.  Atomic mode does not have the issue, as there the send
22010402SN/A        // operation and the response happen instantaneously and don't need two
22110402SN/A        // phase tracking.
22210402SN/A        MemCmd tmp_cmd(pkt->cmd);
22310402SN/A        pkt->cmd = orig_cmd;
22410402SN/A        // Let the snoop filter know about the success of the send operation
22510402SN/A        snoopFilter->updateRequest(pkt, *src_port, !success);
22610402SN/A        pkt->cmd = tmp_cmd;
22710402SN/A    }
22810402SN/A
22910656Sandreas.hansson@arm.com    // check if we were successful in sending the packet onwards
23010656Sandreas.hansson@arm.com    if (!success)  {
23110656Sandreas.hansson@arm.com        // express snoops and inhibited packets should never be forced
23210656Sandreas.hansson@arm.com        // to retry
23310656Sandreas.hansson@arm.com        assert(!is_express_snoop);
23410656Sandreas.hansson@arm.com        assert(!pkt->memInhibitAsserted());
23510656Sandreas.hansson@arm.com
23610719SMarco.Balboni@ARM.com        // restore the header delay
23710719SMarco.Balboni@ARM.com        pkt->headerDelay = old_header_delay;
23810656Sandreas.hansson@arm.com
23910656Sandreas.hansson@arm.com        DPRINTF(CoherentXBar, "recvTimingReq: src %s %s 0x%x RETRY\n",
24010656Sandreas.hansson@arm.com                src_port->name(), pkt->cmdString(), pkt->getAddr());
24110656Sandreas.hansson@arm.com
24210656Sandreas.hansson@arm.com        // update the layer state and schedule an idle event
24310656Sandreas.hansson@arm.com        reqLayers[master_port_id]->failedTiming(src_port,
24410719SMarco.Balboni@ARM.com                                                clockEdge(Cycles(1)));
2459091SN/A    } else {
24610656Sandreas.hansson@arm.com        // express snoops currently bypass the crossbar state entirely
24710656Sandreas.hansson@arm.com        if (!is_express_snoop) {
24810656Sandreas.hansson@arm.com            // if this particular request will generate a snoop
24910656Sandreas.hansson@arm.com            // response
25010656Sandreas.hansson@arm.com            if (expect_snoop_resp) {
25110656Sandreas.hansson@arm.com                // we should never have an exsiting request outstanding
25210656Sandreas.hansson@arm.com                assert(outstandingSnoop.find(pkt->req) ==
25310656Sandreas.hansson@arm.com                       outstandingSnoop.end());
25410656Sandreas.hansson@arm.com                outstandingSnoop.insert(pkt->req);
2558948SN/A
25610656Sandreas.hansson@arm.com                // basic sanity check on the outstanding snoops
25710656Sandreas.hansson@arm.com                panic_if(outstandingSnoop.size() > 512,
25810656Sandreas.hansson@arm.com                         "Outstanding snoop requests exceeded 512\n");
25910656Sandreas.hansson@arm.com            }
2608948SN/A
26110656Sandreas.hansson@arm.com            // remember where to route the normal response to
26210656Sandreas.hansson@arm.com            if (expect_response || expect_snoop_resp) {
26310656Sandreas.hansson@arm.com                assert(routeTo.find(pkt->req) == routeTo.end());
26410656Sandreas.hansson@arm.com                routeTo[pkt->req] = slave_port_id;
2659549SN/A
26610656Sandreas.hansson@arm.com                panic_if(routeTo.size() > 512,
26710656Sandreas.hansson@arm.com                         "Routing table exceeds 512 packets\n");
26810656Sandreas.hansson@arm.com            }
2698948SN/A
27010405Sandreas.hansson@arm.com            // update the layer state and schedule an idle event
2719715SN/A            reqLayers[master_port_id]->succeededTiming(packetFinishTime);
2729091SN/A        }
2738975SN/A
27410656Sandreas.hansson@arm.com        // stats updates only consider packets that were successfully sent
2759712SN/A        pktCount[slave_port_id][master_port_id]++;
27610405Sandreas.hansson@arm.com        pktSize[slave_port_id][master_port_id] += pkt_size;
2779712SN/A        transDist[pkt_cmd]++;
27810656Sandreas.hansson@arm.com
27910656Sandreas.hansson@arm.com        if (is_express_snoop)
28010656Sandreas.hansson@arm.com            snoops++;
2819712SN/A    }
2829712SN/A
2839091SN/A    return success;
2848975SN/A}
2858975SN/A
2868975SN/Abool
28710405Sandreas.hansson@arm.comCoherentXBar::recvTimingResp(PacketPtr pkt, PortID master_port_id)
2888975SN/A{
2898975SN/A    // determine the source port based on the id
2909032SN/A    MasterPort *src_port = masterPorts[master_port_id];
2918975SN/A
29210656Sandreas.hansson@arm.com    // determine the destination
29310656Sandreas.hansson@arm.com    const auto route_lookup = routeTo.find(pkt->req);
29410656Sandreas.hansson@arm.com    assert(route_lookup != routeTo.end());
29510656Sandreas.hansson@arm.com    const PortID slave_port_id = route_lookup->second;
29610572Sandreas.hansson@arm.com    assert(slave_port_id != InvalidPortID);
29710572Sandreas.hansson@arm.com    assert(slave_port_id < respLayers.size());
2989713SN/A
29910405Sandreas.hansson@arm.com    // test if the crossbar should be considered occupied for the
30010405Sandreas.hansson@arm.com    // current port
3019715SN/A    if (!respLayers[slave_port_id]->tryTiming(src_port)) {
30210405Sandreas.hansson@arm.com        DPRINTF(CoherentXBar, "recvTimingResp: src %s %s 0x%x BUSY\n",
3038975SN/A                src_port->name(), pkt->cmdString(), pkt->getAddr());
3048975SN/A        return false;
3058975SN/A    }
3068975SN/A
30710405Sandreas.hansson@arm.com    DPRINTF(CoherentXBar, "recvTimingResp: src %s %s 0x%x\n",
3088975SN/A            src_port->name(), pkt->cmdString(), pkt->getAddr());
3098975SN/A
3109712SN/A    // store size and command as they might be modified when
3119712SN/A    // forwarding the packet
3129712SN/A    unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0;
3139712SN/A    unsigned int pkt_cmd = pkt->cmdToIndex();
3149712SN/A
31510719SMarco.Balboni@ARM.com    // a response sees the response latency
31610719SMarco.Balboni@ARM.com    Tick xbar_delay = responseLatency * clockPeriod();
31710719SMarco.Balboni@ARM.com
31810719SMarco.Balboni@ARM.com    // set the packet header and payload delay
31910719SMarco.Balboni@ARM.com    calcPacketTiming(pkt, xbar_delay);
32010719SMarco.Balboni@ARM.com
32110719SMarco.Balboni@ARM.com    // determine how long to be crossbar layer is busy
32210719SMarco.Balboni@ARM.com    Tick packetFinishTime = clockEdge(Cycles(1)) + pkt->payloadDelay;
3238975SN/A
32410821Sandreas.hansson@arm.com    if (snoopFilter && !system->bypassCaches()) {
32510402SN/A        // let the snoop filter inspect the response and update its state
32610402SN/A        snoopFilter->updateResponse(pkt, *slavePorts[slave_port_id]);
32710402SN/A    }
32810402SN/A
3299712SN/A    // send the packet through the destination slave port
3309712SN/A    bool success M5_VAR_USED = slavePorts[slave_port_id]->sendTimingResp(pkt);
3318975SN/A
3328975SN/A    // currently it is illegal to block responses... can lead to
3338975SN/A    // deadlock
3348975SN/A    assert(success);
3358975SN/A
33610656Sandreas.hansson@arm.com    // remove the request from the routing table
33710656Sandreas.hansson@arm.com    routeTo.erase(route_lookup);
33810656Sandreas.hansson@arm.com
3399715SN/A    respLayers[slave_port_id]->succeededTiming(packetFinishTime);
3408975SN/A
3419712SN/A    // stats updates
3429712SN/A    pktCount[slave_port_id][master_port_id]++;
34310405Sandreas.hansson@arm.com    pktSize[slave_port_id][master_port_id] += pkt_size;
3449712SN/A    transDist[pkt_cmd]++;
3459712SN/A
3468975SN/A    return true;
3478975SN/A}
3488975SN/A
3498975SN/Avoid
35010405Sandreas.hansson@arm.comCoherentXBar::recvTimingSnoopReq(PacketPtr pkt, PortID master_port_id)
3518975SN/A{
35210405Sandreas.hansson@arm.com    DPRINTF(CoherentXBar, "recvTimingSnoopReq: src %s %s 0x%x\n",
3539032SN/A            masterPorts[master_port_id]->name(), pkt->cmdString(),
3548975SN/A            pkt->getAddr());
3558975SN/A
3569712SN/A    // update stats here as we know the forwarding will succeed
3579712SN/A    transDist[pkt->cmdToIndex()]++;
35810405Sandreas.hansson@arm.com    snoops++;
3599712SN/A
3608975SN/A    // we should only see express snoops from caches
3618975SN/A    assert(pkt->isExpressSnoop());
3628975SN/A
36310656Sandreas.hansson@arm.com    // remeber if the packet is inhibited so we can see if it changes
36410656Sandreas.hansson@arm.com    const bool is_inhibited = pkt->memInhibitAsserted();
3659032SN/A
36610402SN/A    if (snoopFilter) {
36710402SN/A        // let the Snoop Filter work its magic and guide probing
36810402SN/A        auto sf_res = snoopFilter->lookupSnoop(pkt);
36910402SN/A        // No timing here: packetFinishTime += sf_res.second * clockPeriod();
37010405Sandreas.hansson@arm.com        DPRINTF(CoherentXBar, "recvTimingSnoopReq: src %s %s 0x%x"\
37110402SN/A                " SF size: %i lat: %i\n", masterPorts[master_port_id]->name(),
37210402SN/A                pkt->cmdString(), pkt->getAddr(), sf_res.first.size(),
37310402SN/A                sf_res.second);
37410402SN/A
37510402SN/A        // forward to all snoopers
37610402SN/A        forwardTiming(pkt, InvalidPortID, sf_res.first);
37710402SN/A    } else {
37810402SN/A        forwardTiming(pkt, InvalidPortID);
37910402SN/A    }
3808975SN/A
38110656Sandreas.hansson@arm.com    // if we can expect a response, remember how to route it
38210656Sandreas.hansson@arm.com    if (!is_inhibited && pkt->memInhibitAsserted()) {
38310656Sandreas.hansson@arm.com        assert(routeTo.find(pkt->req) == routeTo.end());
38410656Sandreas.hansson@arm.com        routeTo[pkt->req] = master_port_id;
38510656Sandreas.hansson@arm.com    }
38610656Sandreas.hansson@arm.com
3878975SN/A    // a snoop request came from a connected slave device (one of
3888975SN/A    // our master ports), and if it is not coming from the slave
3898975SN/A    // device responsible for the address range something is
3908975SN/A    // wrong, hence there is nothing further to do as the packet
3918975SN/A    // would be going back to where it came from
3929032SN/A    assert(master_port_id == findPort(pkt->getAddr()));
3938975SN/A}
3948975SN/A
3958975SN/Abool
39610405Sandreas.hansson@arm.comCoherentXBar::recvTimingSnoopResp(PacketPtr pkt, PortID slave_port_id)
3978975SN/A{
3988975SN/A    // determine the source port based on the id
3999032SN/A    SlavePort* src_port = slavePorts[slave_port_id];
4008975SN/A
40110656Sandreas.hansson@arm.com    // get the destination
40210656Sandreas.hansson@arm.com    const auto route_lookup = routeTo.find(pkt->req);
40310656Sandreas.hansson@arm.com    assert(route_lookup != routeTo.end());
40410656Sandreas.hansson@arm.com    const PortID dest_port_id = route_lookup->second;
40510572Sandreas.hansson@arm.com    assert(dest_port_id != InvalidPortID);
4069714SN/A
4079714SN/A    // determine if the response is from a snoop request we
4089714SN/A    // created as the result of a normal request (in which case it
40910656Sandreas.hansson@arm.com    // should be in the outstandingSnoop), or if we merely forwarded
4109714SN/A    // someone else's snoop request
41110656Sandreas.hansson@arm.com    const bool forwardAsSnoop = outstandingSnoop.find(pkt->req) ==
41210656Sandreas.hansson@arm.com        outstandingSnoop.end();
4139714SN/A
41410405Sandreas.hansson@arm.com    // test if the crossbar should be considered occupied for the
41510405Sandreas.hansson@arm.com    // current port, note that the check is bypassed if the response
41610405Sandreas.hansson@arm.com    // is being passed on as a normal response since this is occupying
41710405Sandreas.hansson@arm.com    // the response layer rather than the snoop response layer
4189715SN/A    if (forwardAsSnoop) {
41910572Sandreas.hansson@arm.com        assert(dest_port_id < snoopLayers.size());
4209715SN/A        if (!snoopLayers[dest_port_id]->tryTiming(src_port)) {
42110405Sandreas.hansson@arm.com            DPRINTF(CoherentXBar, "recvTimingSnoopResp: src %s %s 0x%x BUSY\n",
4229715SN/A                    src_port->name(), pkt->cmdString(), pkt->getAddr());
4239715SN/A            return false;
4249715SN/A        }
4259716SN/A    } else {
4269716SN/A        // get the master port that mirrors this slave port internally
4279716SN/A        MasterPort* snoop_port = snoopRespPorts[slave_port_id];
42810572Sandreas.hansson@arm.com        assert(dest_port_id < respLayers.size());
4299716SN/A        if (!respLayers[dest_port_id]->tryTiming(snoop_port)) {
43010405Sandreas.hansson@arm.com            DPRINTF(CoherentXBar, "recvTimingSnoopResp: src %s %s 0x%x BUSY\n",
4319716SN/A                    snoop_port->name(), pkt->cmdString(), pkt->getAddr());
4329716SN/A            return false;
4339716SN/A        }
4348975SN/A    }
4358975SN/A
43610405Sandreas.hansson@arm.com    DPRINTF(CoherentXBar, "recvTimingSnoopResp: src %s %s 0x%x\n",
4378975SN/A            src_port->name(), pkt->cmdString(), pkt->getAddr());
4388975SN/A
4399712SN/A    // store size and command as they might be modified when
4409712SN/A    // forwarding the packet
4419712SN/A    unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0;
4429712SN/A    unsigned int pkt_cmd = pkt->cmdToIndex();
4439712SN/A
4448975SN/A    // responses are never express snoops
4458975SN/A    assert(!pkt->isExpressSnoop());
4468975SN/A
44710719SMarco.Balboni@ARM.com    // a snoop response sees the snoop response latency, and if it is
44810719SMarco.Balboni@ARM.com    // forwarded as a normal response, the response latency
44910719SMarco.Balboni@ARM.com    Tick xbar_delay =
45010719SMarco.Balboni@ARM.com        (forwardAsSnoop ? snoopResponseLatency : responseLatency) *
45110719SMarco.Balboni@ARM.com        clockPeriod();
45210719SMarco.Balboni@ARM.com
45310719SMarco.Balboni@ARM.com    // set the packet header and payload delay
45410719SMarco.Balboni@ARM.com    calcPacketTiming(pkt, xbar_delay);
45510719SMarco.Balboni@ARM.com
45610719SMarco.Balboni@ARM.com    // determine how long to be crossbar layer is busy
45710719SMarco.Balboni@ARM.com    Tick packetFinishTime = clockEdge(Cycles(1)) + pkt->payloadDelay;
4588975SN/A
4599714SN/A    // forward it either as a snoop response or a normal response
4609714SN/A    if (forwardAsSnoop) {
4619714SN/A        // this is a snoop response to a snoop request we forwarded,
4629714SN/A        // e.g. coming from the L1 and going to the L2, and it should
4639714SN/A        // be forwarded as a snoop response
46410402SN/A
46510402SN/A        if (snoopFilter) {
46610402SN/A            // update the probe filter so that it can properly track the line
46710402SN/A            snoopFilter->updateSnoopForward(pkt, *slavePorts[slave_port_id],
46810402SN/A                                            *masterPorts[dest_port_id]);
46910402SN/A        }
47010402SN/A
4719712SN/A        bool success M5_VAR_USED =
4729712SN/A            masterPorts[dest_port_id]->sendTimingSnoopResp(pkt);
4739712SN/A        pktCount[slave_port_id][dest_port_id]++;
47410405Sandreas.hansson@arm.com        pktSize[slave_port_id][dest_port_id] += pkt_size;
4758975SN/A        assert(success);
4769714SN/A
4779715SN/A        snoopLayers[dest_port_id]->succeededTiming(packetFinishTime);
4783244SN/A    } else {
4798975SN/A        // we got a snoop response on one of our slave ports,
48010405Sandreas.hansson@arm.com        // i.e. from a coherent master connected to the crossbar, and
48110405Sandreas.hansson@arm.com        // since we created the snoop request as part of recvTiming,
48210405Sandreas.hansson@arm.com        // this should now be a normal response again
48310656Sandreas.hansson@arm.com        outstandingSnoop.erase(pkt->req);
4848948SN/A
48510656Sandreas.hansson@arm.com        // this is a snoop response from a coherent master, hence it
48610656Sandreas.hansson@arm.com        // should never go back to where the snoop response came from,
48710656Sandreas.hansson@arm.com        // but instead to where the original request came from
4889712SN/A        assert(slave_port_id != dest_port_id);
4898948SN/A
49010402SN/A        if (snoopFilter) {
49110402SN/A            // update the probe filter so that it can properly track the line
49210402SN/A            snoopFilter->updateSnoopResponse(pkt, *slavePorts[slave_port_id],
49310402SN/A                                    *slavePorts[dest_port_id]);
49410402SN/A        }
49510402SN/A
49610405Sandreas.hansson@arm.com        DPRINTF(CoherentXBar, "recvTimingSnoopResp: src %s %s 0x%x"\
49710402SN/A                " FWD RESP\n", src_port->name(), pkt->cmdString(),
49810402SN/A                pkt->getAddr());
49910402SN/A
5009714SN/A        // as a normal response, it should go back to a master through
5019714SN/A        // one of our slave ports, at this point we are ignoring the
5029714SN/A        // fact that the response layer could be busy and do not touch
5039714SN/A        // its state
5049712SN/A        bool success M5_VAR_USED =
5059712SN/A            slavePorts[dest_port_id]->sendTimingResp(pkt);
5068975SN/A
5079714SN/A        // @todo Put the response in an internal FIFO and pass it on
5089714SN/A        // to the response layer from there
5099714SN/A
5108975SN/A        // currently it is illegal to block responses... can lead
5118975SN/A        // to deadlock
5128948SN/A        assert(success);
5139716SN/A
5149716SN/A        respLayers[dest_port_id]->succeededTiming(packetFinishTime);
5153244SN/A    }
5163244SN/A
51710656Sandreas.hansson@arm.com    // remove the request from the routing table
51810656Sandreas.hansson@arm.com    routeTo.erase(route_lookup);
51910656Sandreas.hansson@arm.com
5209712SN/A    // stats updates
5219712SN/A    transDist[pkt_cmd]++;
52210405Sandreas.hansson@arm.com    snoops++;
5239712SN/A
5248948SN/A    return true;
5258948SN/A}
5268948SN/A
5273210SN/A
5288948SN/Avoid
52910405Sandreas.hansson@arm.comCoherentXBar::forwardTiming(PacketPtr pkt, PortID exclude_slave_port_id,
53010402SN/A                           const std::vector<SlavePort*>& dests)
5318948SN/A{
53210405Sandreas.hansson@arm.com    DPRINTF(CoherentXBar, "%s for %s address %x size %d\n", __func__,
5339663SN/A            pkt->cmdString(), pkt->getAddr(), pkt->getSize());
5349663SN/A
5359524SN/A    // snoops should only happen if the system isn't bypassing caches
5369524SN/A    assert(!system->bypassCaches());
5379524SN/A
53810401SN/A    unsigned fanout = 0;
53910401SN/A
54010405Sandreas.hansson@arm.com    for (const auto& p: dests) {
5418948SN/A        // we could have gotten this request from a snooping master
5428948SN/A        // (corresponding to our own slave port that is also in
5438948SN/A        // snoopPorts) and should not send it back to where it came
5448948SN/A        // from
5459031SN/A        if (exclude_slave_port_id == InvalidPortID ||
5468948SN/A            p->getId() != exclude_slave_port_id) {
5478948SN/A            // cache is not allowed to refuse snoop
5488975SN/A            p->sendTimingSnoopReq(pkt);
54910401SN/A            fanout++;
5508948SN/A        }
5518948SN/A    }
55210401SN/A
55310401SN/A    // Stats for fanout of this forward operation
55410401SN/A    snoopFanout.sample(fanout);
5552497SN/A}
5562497SN/A
5579092SN/Avoid
55810713Sandreas.hansson@arm.comCoherentXBar::recvReqRetry(PortID master_port_id)
5599092SN/A{
5609093SN/A    // responses and snoop responses never block on forwarding them,
5619093SN/A    // so the retry will always be coming from a port to which we
5629093SN/A    // tried to forward a request
5639715SN/A    reqLayers[master_port_id]->recvRetry();
5649092SN/A}
5659092SN/A
5669036SN/ATick
56710405Sandreas.hansson@arm.comCoherentXBar::recvAtomic(PacketPtr pkt, PortID slave_port_id)
5682657SN/A{
56910405Sandreas.hansson@arm.com    DPRINTF(CoherentXBar, "recvAtomic: packet src %s addr 0x%x cmd %s\n",
5709032SN/A            slavePorts[slave_port_id]->name(), pkt->getAddr(),
5718949SN/A            pkt->cmdString());
5728915SN/A
57310405Sandreas.hansson@arm.com    unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0;
57410405Sandreas.hansson@arm.com    unsigned int pkt_cmd = pkt->cmdToIndex();
5759712SN/A
5768979SN/A    MemCmd snoop_response_cmd = MemCmd::InvalidCmd;
5778979SN/A    Tick snoop_response_latency = 0;
5788979SN/A
57910821Sandreas.hansson@arm.com    if (!system->bypassCaches()) {
5808979SN/A        // forward to all snoopers but the source
58110402SN/A        std::pair<MemCmd, Tick> snoop_result;
58210402SN/A        if (snoopFilter) {
58310402SN/A            // check with the snoop filter where to forward this packet
58410402SN/A            auto sf_res =
58510402SN/A                snoopFilter->lookupRequest(pkt, *slavePorts[slave_port_id]);
58610402SN/A            snoop_response_latency += sf_res.second * clockPeriod();
58710405Sandreas.hansson@arm.com            DPRINTF(CoherentXBar, "%s: src %s %s 0x%x"\
58810402SN/A                    " SF size: %i lat: %i\n", __func__,
58910402SN/A                    slavePorts[slave_port_id]->name(), pkt->cmdString(),
59010402SN/A                    pkt->getAddr(), sf_res.first.size(), sf_res.second);
59110402SN/A            snoop_result = forwardAtomic(pkt, slave_port_id, InvalidPortID,
59210402SN/A                                         sf_res.first);
59310402SN/A        } else {
59410402SN/A            snoop_result = forwardAtomic(pkt, slave_port_id);
59510402SN/A        }
5968979SN/A        snoop_response_cmd = snoop_result.first;
59710402SN/A        snoop_response_latency += snoop_result.second;
5988979SN/A    }
5998915SN/A
6008948SN/A    // even if we had a snoop response, we must continue and also
6018948SN/A    // perform the actual request at the destination
60210405Sandreas.hansson@arm.com    PortID master_port_id = findPort(pkt->getAddr());
60310405Sandreas.hansson@arm.com
60410405Sandreas.hansson@arm.com    // stats updates for the request
60510405Sandreas.hansson@arm.com    pktCount[slave_port_id][master_port_id]++;
60610405Sandreas.hansson@arm.com    pktSize[slave_port_id][master_port_id] += pkt_size;
60710405Sandreas.hansson@arm.com    transDist[pkt_cmd]++;
6088948SN/A
6098948SN/A    // forward the request to the appropriate destination
61010405Sandreas.hansson@arm.com    Tick response_latency = masterPorts[master_port_id]->sendAtomic(pkt);
6118948SN/A
61210402SN/A    // Lower levels have replied, tell the snoop filter
61310821Sandreas.hansson@arm.com    if (snoopFilter && !system->bypassCaches() && pkt->isResponse()) {
61410402SN/A        snoopFilter->updateResponse(pkt, *slavePorts[slave_port_id]);
61510402SN/A    }
61610402SN/A
6178948SN/A    // if we got a response from a snooper, restore it here
6188948SN/A    if (snoop_response_cmd != MemCmd::InvalidCmd) {
6198948SN/A        // no one else should have responded
6208948SN/A        assert(!pkt->isResponse());
6218948SN/A        pkt->cmd = snoop_response_cmd;
6228948SN/A        response_latency = snoop_response_latency;
6238948SN/A    }
6248948SN/A
6259712SN/A    // add the response data
62610405Sandreas.hansson@arm.com    if (pkt->isResponse()) {
62710405Sandreas.hansson@arm.com        pkt_size = pkt->hasData() ? pkt->getSize() : 0;
62810405Sandreas.hansson@arm.com        pkt_cmd = pkt->cmdToIndex();
62910405Sandreas.hansson@arm.com
63010405Sandreas.hansson@arm.com        // stats updates
63110405Sandreas.hansson@arm.com        pktCount[slave_port_id][master_port_id]++;
63210405Sandreas.hansson@arm.com        pktSize[slave_port_id][master_port_id] += pkt_size;
63310405Sandreas.hansson@arm.com        transDist[pkt_cmd]++;
63410405Sandreas.hansson@arm.com    }
6359712SN/A
63610694SMarco.Balboni@ARM.com    // @todo: Not setting header time
63710694SMarco.Balboni@ARM.com    pkt->payloadDelay = response_latency;
6388948SN/A    return response_latency;
6398948SN/A}
6408948SN/A
6418948SN/ATick
64210405Sandreas.hansson@arm.comCoherentXBar::recvAtomicSnoop(PacketPtr pkt, PortID master_port_id)
6438948SN/A{
64410405Sandreas.hansson@arm.com    DPRINTF(CoherentXBar, "recvAtomicSnoop: packet src %s addr 0x%x cmd %s\n",
6459032SN/A            masterPorts[master_port_id]->name(), pkt->getAddr(),
6468949SN/A            pkt->cmdString());
6478948SN/A
6489712SN/A    // add the request snoop data
64910405Sandreas.hansson@arm.com    snoops++;
6509712SN/A
6518948SN/A    // forward to all snoopers
65210402SN/A    std::pair<MemCmd, Tick> snoop_result;
65310402SN/A    Tick snoop_response_latency = 0;
65410402SN/A    if (snoopFilter) {
65510402SN/A        auto sf_res = snoopFilter->lookupSnoop(pkt);
65610402SN/A        snoop_response_latency += sf_res.second * clockPeriod();
65710405Sandreas.hansson@arm.com        DPRINTF(CoherentXBar, "%s: src %s %s 0x%x SF size: %i lat: %i\n",
65810402SN/A                __func__, masterPorts[master_port_id]->name(), pkt->cmdString(),
65910402SN/A                pkt->getAddr(), sf_res.first.size(), sf_res.second);
66010402SN/A        snoop_result = forwardAtomic(pkt, InvalidPortID, master_port_id,
66110402SN/A                                     sf_res.first);
66210402SN/A    } else {
66310402SN/A        snoop_result = forwardAtomic(pkt, InvalidPortID);
66410402SN/A    }
6658948SN/A    MemCmd snoop_response_cmd = snoop_result.first;
66610402SN/A    snoop_response_latency += snoop_result.second;
6678948SN/A
6688948SN/A    if (snoop_response_cmd != MemCmd::InvalidCmd)
6698948SN/A        pkt->cmd = snoop_response_cmd;
6708948SN/A
6719712SN/A    // add the response snoop data
67210401SN/A    if (pkt->isResponse()) {
67310405Sandreas.hansson@arm.com        snoops++;
67410401SN/A    }
6759712SN/A
67610694SMarco.Balboni@ARM.com    // @todo: Not setting header time
67710694SMarco.Balboni@ARM.com    pkt->payloadDelay = snoop_response_latency;
6788948SN/A    return snoop_response_latency;
6798948SN/A}
6808948SN/A
6818948SN/Astd::pair<MemCmd, Tick>
68210405Sandreas.hansson@arm.comCoherentXBar::forwardAtomic(PacketPtr pkt, PortID exclude_slave_port_id,
68310402SN/A                           PortID source_master_port_id,
68410402SN/A                           const std::vector<SlavePort*>& dests)
6858948SN/A{
6869032SN/A    // the packet may be changed on snoops, record the original
6879032SN/A    // command to enable us to restore it between snoops so that
6888948SN/A    // additional snoops can take place properly
6894626SN/A    MemCmd orig_cmd = pkt->cmd;
6904879SN/A    MemCmd snoop_response_cmd = MemCmd::InvalidCmd;
6914879SN/A    Tick snoop_response_latency = 0;
6923662SN/A
6939524SN/A    // snoops should only happen if the system isn't bypassing caches
6949524SN/A    assert(!system->bypassCaches());
6959524SN/A
69610401SN/A    unsigned fanout = 0;
69710401SN/A
69810405Sandreas.hansson@arm.com    for (const auto& p: dests) {
6998915SN/A        // we could have gotten this request from a snooping master
7008915SN/A        // (corresponding to our own slave port that is also in
7018915SN/A        // snoopPorts) and should not send it back to where it came
7028915SN/A        // from
70310402SN/A        if (exclude_slave_port_id != InvalidPortID &&
70410402SN/A            p->getId() == exclude_slave_port_id)
70510402SN/A            continue;
70610401SN/A
70710402SN/A        Tick latency = p->sendAtomicSnoop(pkt);
70810402SN/A        fanout++;
70910402SN/A
71010402SN/A        // in contrast to a functional access, we have to keep on
71110402SN/A        // going as all snoopers must be updated even if we get a
71210402SN/A        // response
71310402SN/A        if (!pkt->isResponse())
71410402SN/A            continue;
71510402SN/A
71610402SN/A        // response from snoop agent
71710402SN/A        assert(pkt->cmd != orig_cmd);
71810402SN/A        assert(pkt->memInhibitAsserted());
71910402SN/A        // should only happen once
72010402SN/A        assert(snoop_response_cmd == MemCmd::InvalidCmd);
72110402SN/A        // save response state
72210402SN/A        snoop_response_cmd = pkt->cmd;
72310402SN/A        snoop_response_latency = latency;
72410402SN/A
72510402SN/A        if (snoopFilter) {
72610402SN/A            // Handle responses by the snoopers and differentiate between
72710402SN/A            // responses to requests from above and snoops from below
72810402SN/A            if (source_master_port_id != InvalidPortID) {
72910402SN/A                // Getting a response for a snoop from below
73010402SN/A                assert(exclude_slave_port_id == InvalidPortID);
73110402SN/A                snoopFilter->updateSnoopForward(pkt, *p,
73210402SN/A                             *masterPorts[source_master_port_id]);
73310402SN/A            } else {
73410402SN/A                // Getting a response for a request from above
73510402SN/A                assert(source_master_port_id == InvalidPortID);
73610402SN/A                snoopFilter->updateSnoopResponse(pkt, *p,
73710402SN/A                             *slavePorts[exclude_slave_port_id]);
7384626SN/A            }
7394626SN/A        }
74010402SN/A        // restore original packet state for remaining snoopers
74110402SN/A        pkt->cmd = orig_cmd;
7424626SN/A    }
7434626SN/A
74410401SN/A    // Stats for fanout
74510401SN/A    snoopFanout.sample(fanout);
74610401SN/A
7478948SN/A    // the packet is restored as part of the loop and any potential
7488948SN/A    // snoop response is part of the returned pair
7498948SN/A    return std::make_pair(snoop_response_cmd, snoop_response_latency);
7502497SN/A}
7512497SN/A
7522497SN/Avoid
75310405Sandreas.hansson@arm.comCoherentXBar::recvFunctional(PacketPtr pkt, PortID slave_port_id)
7542497SN/A{
7558663SN/A    if (!pkt->isPrint()) {
7568663SN/A        // don't do DPRINTFs on PrintReq as it clutters up the output
75710405Sandreas.hansson@arm.com        DPRINTF(CoherentXBar,
7588949SN/A                "recvFunctional: packet src %s addr 0x%x cmd %s\n",
7599032SN/A                slavePorts[slave_port_id]->name(), pkt->getAddr(),
7608663SN/A                pkt->cmdString());
7618663SN/A    }
7628663SN/A
76310821Sandreas.hansson@arm.com    if (!system->bypassCaches()) {
7648979SN/A        // forward to all snoopers but the source
7659032SN/A        forwardFunctional(pkt, slave_port_id);
7668979SN/A    }
7674912SN/A
7688948SN/A    // there is no need to continue if the snooping has found what we
7698948SN/A    // were looking for and the packet is already a response
7708948SN/A    if (!pkt->isResponse()) {
7719031SN/A        PortID dest_id = findPort(pkt->getAddr());
7728948SN/A
7738948SN/A        masterPorts[dest_id]->sendFunctional(pkt);
7748948SN/A    }
7758948SN/A}
7768948SN/A
7778948SN/Avoid
77810405Sandreas.hansson@arm.comCoherentXBar::recvFunctionalSnoop(PacketPtr pkt, PortID master_port_id)
7798948SN/A{
7808948SN/A    if (!pkt->isPrint()) {
7818948SN/A        // don't do DPRINTFs on PrintReq as it clutters up the output
78210405Sandreas.hansson@arm.com        DPRINTF(CoherentXBar,
7838949SN/A                "recvFunctionalSnoop: packet src %s addr 0x%x cmd %s\n",
7849032SN/A                masterPorts[master_port_id]->name(), pkt->getAddr(),
7858948SN/A                pkt->cmdString());
7868948SN/A    }
7878948SN/A
7888948SN/A    // forward to all snoopers
7899031SN/A    forwardFunctional(pkt, InvalidPortID);
7908948SN/A}
7918948SN/A
7928948SN/Avoid
79310405Sandreas.hansson@arm.comCoherentXBar::forwardFunctional(PacketPtr pkt, PortID exclude_slave_port_id)
7948948SN/A{
7959524SN/A    // snoops should only happen if the system isn't bypassing caches
7969524SN/A    assert(!system->bypassCaches());
7979524SN/A
79810405Sandreas.hansson@arm.com    for (const auto& p: snoopPorts) {
7998915SN/A        // we could have gotten this request from a snooping master
8008915SN/A        // (corresponding to our own slave port that is also in
8018915SN/A        // snoopPorts) and should not send it back to where it came
8028915SN/A        // from
8039031SN/A        if (exclude_slave_port_id == InvalidPortID ||
8048948SN/A            p->getId() != exclude_slave_port_id)
8058948SN/A            p->sendFunctionalSnoop(pkt);
8068915SN/A
8078948SN/A        // if we get a response we are done
8088948SN/A        if (pkt->isResponse()) {
8098948SN/A            break;
8108915SN/A        }
8113650SN/A    }
8122497SN/A}
8132497SN/A
8149092SN/Aunsigned int
81510405Sandreas.hansson@arm.comCoherentXBar::drain(DrainManager *dm)
8169092SN/A{
8179093SN/A    // sum up the individual layers
8189715SN/A    unsigned int total = 0;
81910405Sandreas.hansson@arm.com    for (auto l: reqLayers)
82010405Sandreas.hansson@arm.com        total += l->drain(dm);
82110405Sandreas.hansson@arm.com    for (auto l: respLayers)
82210405Sandreas.hansson@arm.com        total += l->drain(dm);
82310405Sandreas.hansson@arm.com    for (auto l: snoopLayers)
82410405Sandreas.hansson@arm.com        total += l->drain(dm);
8259715SN/A    return total;
8269092SN/A}
8279092SN/A
8289712SN/Avoid
82910405Sandreas.hansson@arm.comCoherentXBar::regStats()
8309712SN/A{
83110405Sandreas.hansson@arm.com    // register the stats of the base class and our layers
83210405Sandreas.hansson@arm.com    BaseXBar::regStats();
83310405Sandreas.hansson@arm.com    for (auto l: reqLayers)
83410405Sandreas.hansson@arm.com        l->regStats();
83510405Sandreas.hansson@arm.com    for (auto l: respLayers)
83610405Sandreas.hansson@arm.com        l->regStats();
83710405Sandreas.hansson@arm.com    for (auto l: snoopLayers)
83810405Sandreas.hansson@arm.com        l->regStats();
8399712SN/A
84010405Sandreas.hansson@arm.com    snoops
84110405Sandreas.hansson@arm.com        .name(name() + ".snoops")
84210401SN/A        .desc("Total snoops (count)")
84310401SN/A    ;
84410401SN/A
84510401SN/A    snoopFanout
84610401SN/A        .init(0, snoopPorts.size(), 1)
84710401SN/A        .name(name() + ".snoop_fanout")
84810401SN/A        .desc("Request fanout histogram")
84910401SN/A    ;
8509712SN/A}
8519712SN/A
85210405Sandreas.hansson@arm.comCoherentXBar *
85310405Sandreas.hansson@arm.comCoherentXBarParams::create()
8542497SN/A{
85510405Sandreas.hansson@arm.com    return new CoherentXBar(this);
8562497SN/A}
857