xbar.cc revision 12780
12497SN/A/*
212776Snikos.nikoleris@arm.com * Copyright (c) 2011-2015, 2018 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
5011793Sbrandon.potter@amd.com#include "mem/xbar.hh"
5111793Sbrandon.potter@amd.com
5212334Sgabeblack@google.com#include "base/logging.hh"
532548SN/A#include "base/trace.hh"
5410405Sandreas.hansson@arm.com#include "debug/AddrRanges.hh"
559152SN/A#include "debug/Drain.hh"
5610405Sandreas.hansson@arm.com#include "debug/XBar.hh"
572497SN/A
5810405Sandreas.hansson@arm.comBaseXBar::BaseXBar(const BaseXBarParams *p)
599157SN/A    : MemObject(p),
6010719SMarco.Balboni@ARM.com      frontendLatency(p->frontend_latency),
6110719SMarco.Balboni@ARM.com      forwardLatency(p->forward_latency),
6210719SMarco.Balboni@ARM.com      responseLatency(p->response_latency),
6310719SMarco.Balboni@ARM.com      width(p->width),
649279SN/A      gotAddrRanges(p->port_default_connection_count +
659279SN/A                          p->port_master_connection_count, false),
669279SN/A      gotAllAddrRanges(false), defaultPortID(InvalidPortID),
679814SN/A      useDefaultRange(p->use_default_range)
689240SN/A{}
698851SN/A
7010405Sandreas.hansson@arm.comBaseXBar::~BaseXBar()
719036SN/A{
7210405Sandreas.hansson@arm.com    for (auto m: masterPorts)
7310405Sandreas.hansson@arm.com        delete m;
748851SN/A
7510405Sandreas.hansson@arm.com    for (auto s: slavePorts)
7610405Sandreas.hansson@arm.com        delete s;
777523SN/A}
787523SN/A
799278SN/Avoid
8010405Sandreas.hansson@arm.comBaseXBar::init()
819278SN/A{
829278SN/A}
839278SN/A
849294SN/ABaseMasterPort &
8510405Sandreas.hansson@arm.comBaseXBar::getMasterPort(const std::string &if_name, PortID idx)
862640SN/A{
878948SN/A    if (if_name == "master" && idx < masterPorts.size()) {
888948SN/A        // the master port index translates directly to the vector position
898922SN/A        return *masterPorts[idx];
908851SN/A    } else  if (if_name == "default") {
919031SN/A        return *masterPorts[defaultPortID];
928715SN/A    } else {
938922SN/A        return MemObject::getMasterPort(if_name, idx);
948922SN/A    }
958922SN/A}
968922SN/A
979294SN/ABaseSlavePort &
9810405Sandreas.hansson@arm.comBaseXBar::getSlavePort(const std::string &if_name, PortID idx)
998922SN/A{
1008948SN/A    if (if_name == "slave" && idx < slavePorts.size()) {
1018948SN/A        // the slave port index translates directly to the vector position
1028948SN/A        return *slavePorts[idx];
1038922SN/A    } else {
1048922SN/A        return MemObject::getSlavePort(if_name, idx);
1053489SN/A    }
1062640SN/A}
1072640SN/A
1089547SN/Avoid
10910719SMarco.Balboni@ARM.comBaseXBar::calcPacketTiming(PacketPtr pkt, Tick header_delay)
1102497SN/A{
11110405Sandreas.hansson@arm.com    // the crossbar will be called at a time that is not necessarily
1129547SN/A    // coinciding with its own clock, so start by determining how long
1139547SN/A    // until the next clock edge (could be zero)
1149648SN/A    Tick offset = clockEdge() - curTick();
1155354SN/A
11610719SMarco.Balboni@ARM.com    // the header delay depends on the path through the crossbar, and
11710719SMarco.Balboni@ARM.com    // we therefore rely on the caller to provide the actual
11810719SMarco.Balboni@ARM.com    // value
11910719SMarco.Balboni@ARM.com    pkt->headerDelay += offset + header_delay;
1203210SN/A
12110719SMarco.Balboni@ARM.com    // note that we add the header delay to the existing value, and
12210719SMarco.Balboni@ARM.com    // align it to the crossbar clock
1239549SN/A
12410719SMarco.Balboni@ARM.com    // do a quick sanity check to ensure the timings are not being
12510719SMarco.Balboni@ARM.com    // ignored, note that this specific value may cause problems for
12610719SMarco.Balboni@ARM.com    // slower interconnects
12710719SMarco.Balboni@ARM.com    panic_if(pkt->headerDelay > SimClock::Int::us,
12810719SMarco.Balboni@ARM.com             "Encountered header delay exceeding 1 us\n");
1293218SN/A
13010719SMarco.Balboni@ARM.com    if (pkt->hasData()) {
13110719SMarco.Balboni@ARM.com        // the payloadDelay takes into account the relative time to
13210719SMarco.Balboni@ARM.com        // deliver the payload of the packet, after the header delay,
13310719SMarco.Balboni@ARM.com        // we take the maximum since the payload delay could already
13410719SMarco.Balboni@ARM.com        // be longer than what this parcitular crossbar enforces.
13510719SMarco.Balboni@ARM.com        pkt->payloadDelay = std::max<Tick>(pkt->payloadDelay,
13610719SMarco.Balboni@ARM.com                                           divCeil(pkt->getSize(), width) *
13710719SMarco.Balboni@ARM.com                                           clockPeriod());
13810719SMarco.Balboni@ARM.com    }
13910719SMarco.Balboni@ARM.com
14010719SMarco.Balboni@ARM.com    // the payload delay is not paying for the clock offset as that is
14110719SMarco.Balboni@ARM.com    // already done using the header delay, and the payload delay is
14210719SMarco.Balboni@ARM.com    // also used to determine how long the crossbar layer is busy and
14310719SMarco.Balboni@ARM.com    // thus regulates throughput
1445354SN/A}
1455354SN/A
1469715SN/Atemplate <typename SrcType, typename DstType>
14710405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::Layer(DstType& _port, BaseXBar& _xbar,
1489715SN/A                                       const std::string& _name) :
14910913Sandreas.sandberg@arm.com    port(_port), xbar(_xbar), _name(_name), state(IDLE),
15012084Sspwilson2@wisc.edu    waitingForPeer(NULL), releaseEvent([this]{ releaseLayer(); }, name())
1519092SN/A{
1529092SN/A}
1539092SN/A
1549715SN/Atemplate <typename SrcType, typename DstType>
15510405Sandreas.hansson@arm.comvoid BaseXBar::Layer<SrcType,DstType>::occupyLayer(Tick until)
1565354SN/A{
15710405Sandreas.hansson@arm.com    // ensure the state is busy at this point, as the layer should
1589612SN/A    // transition from idle as soon as it has decided to forward the
1599612SN/A    // packet to prevent any follow-on calls to sendTiming seeing an
16010405Sandreas.hansson@arm.com    // unoccupied layer
1619612SN/A    assert(state == BUSY);
1625354SN/A
16310405Sandreas.hansson@arm.com    // until should never be 0 as express snoops never occupy the layer
1649091SN/A    assert(until != 0);
16510405Sandreas.hansson@arm.com    xbar.schedule(releaseEvent, until);
1669091SN/A
1679712SN/A    // account for the occupied ticks
1689712SN/A    occupancy += until - curTick();
1699712SN/A
17010405Sandreas.hansson@arm.com    DPRINTF(BaseXBar, "The crossbar layer is now busy from tick %d to %d\n",
1719091SN/A            curTick(), until);
1723244SN/A}
1733244SN/A
1749715SN/Atemplate <typename SrcType, typename DstType>
1758948SN/Abool
17610405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::tryTiming(SrcType* src_port)
1778948SN/A{
1789716SN/A    // if we are in the retry state, we will not see anything but the
1799716SN/A    // retrying port (or in the case of the snoop ports the snoop
1809716SN/A    // response port that mirrors the actual slave port) as we leave
1819716SN/A    // this state again in zero time if the peer does not immediately
18210405Sandreas.hansson@arm.com    // call the layer when receiving the retry
1839716SN/A
1849716SN/A    // first we see if the layer is busy, next we check if the
1859716SN/A    // destination port is already engaged in a transaction waiting
1869716SN/A    // for a retry from the peer
1879716SN/A    if (state == BUSY || waitingForPeer != NULL) {
1889716SN/A        // the port should not be waiting already
1899716SN/A        assert(std::find(waitingForLayer.begin(), waitingForLayer.end(),
1909716SN/A                         src_port) == waitingForLayer.end());
1919716SN/A
1929612SN/A        // put the port at the end of the retry list waiting for the
1939612SN/A        // layer to be freed up (and in the case of a busy peer, for
19410405Sandreas.hansson@arm.com        // that transaction to go through, and then the layer to free
1959612SN/A        // up)
1969715SN/A        waitingForLayer.push_back(src_port);
1979091SN/A        return false;
1988948SN/A    }
1999091SN/A
2009612SN/A    state = BUSY;
2019611SN/A
2029091SN/A    return true;
2038948SN/A}
2048948SN/A
2059715SN/Atemplate <typename SrcType, typename DstType>
2068975SN/Avoid
20710405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::succeededTiming(Tick busy_time)
2088948SN/A{
2099612SN/A    // we should have gone from idle or retry to busy in the tryTiming
2109612SN/A    // test
2119091SN/A    assert(state == BUSY);
2129091SN/A
21310405Sandreas.hansson@arm.com    // occupy the layer accordingly
2149092SN/A    occupyLayer(busy_time);
2159091SN/A}
2169091SN/A
2179715SN/Atemplate <typename SrcType, typename DstType>
2189091SN/Avoid
21910405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::failedTiming(SrcType* src_port,
2209715SN/A                                              Tick busy_time)
2219091SN/A{
2229612SN/A    // ensure no one got in between and tried to send something to
2239612SN/A    // this port
2249715SN/A    assert(waitingForPeer == NULL);
2259091SN/A
2269612SN/A    // if the source port is the current retrying one or not, we have
2279612SN/A    // failed in forwarding and should track that we are now waiting
2289612SN/A    // for the peer to send a retry
2299715SN/A    waitingForPeer = src_port;
2309612SN/A
2319612SN/A    // we should have gone from idle or retry to busy in the tryTiming
2329612SN/A    // test
2339612SN/A    assert(state == BUSY);
2349091SN/A
2359091SN/A    // occupy the bus accordingly
2369092SN/A    occupyLayer(busy_time);
2378948SN/A}
2388948SN/A
2399715SN/Atemplate <typename SrcType, typename DstType>
2408948SN/Avoid
24110405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::releaseLayer()
2422657SN/A{
2438915SN/A    // releasing the bus means we should now be idle
2449091SN/A    assert(state == BUSY);
2459092SN/A    assert(!releaseEvent.scheduled());
2469091SN/A
2479091SN/A    // update the state
2489091SN/A    state = IDLE;
2493252SN/A
2509612SN/A    // bus layer is now idle, so if someone is waiting we can retry
2519612SN/A    if (!waitingForLayer.empty()) {
25210347SN/A        // there is no point in sending a retry if someone is still
25310347SN/A        // waiting for the peer
25410347SN/A        if (waitingForPeer == NULL)
25510347SN/A            retryWaiting();
25610913Sandreas.sandberg@arm.com    } else if (waitingForPeer == NULL && drainState() == DrainState::Draining) {
25710405Sandreas.hansson@arm.com        DPRINTF(Drain, "Crossbar done draining, signaling drain manager\n");
2589091SN/A        //If we weren't able to drain before, do it now.
25910913Sandreas.sandberg@arm.com        signalDrainDone();
2603512SN/A    }
2612657SN/A}
2622657SN/A
2639715SN/Atemplate <typename SrcType, typename DstType>
2648915SN/Avoid
26510405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::retryWaiting()
2668915SN/A{
2679612SN/A    // this should never be called with no one waiting
2689612SN/A    assert(!waitingForLayer.empty());
2698915SN/A
2709091SN/A    // we always go to retrying from idle
2719091SN/A    assert(state == IDLE);
2729091SN/A
2739611SN/A    // update the state
2749091SN/A    state = RETRY;
2758915SN/A
2769611SN/A    // set the retrying port to the front of the retry list and pop it
2779611SN/A    // off the list
27810347SN/A    SrcType* retryingPort = waitingForLayer.front();
2799612SN/A    waitingForLayer.pop_front();
2809611SN/A
2819612SN/A    // tell the port to retry, which in some cases ends up calling the
28210405Sandreas.hansson@arm.com    // layer again
28310713Sandreas.hansson@arm.com    sendRetry(retryingPort);
2848915SN/A
28510405Sandreas.hansson@arm.com    // If the layer is still in the retry state, sendTiming wasn't
28610719SMarco.Balboni@ARM.com    // called in zero time (e.g. the cache does this when a writeback
28710719SMarco.Balboni@ARM.com    // is squashed)
2889091SN/A    if (state == RETRY) {
2899612SN/A        // update the state to busy and reset the retrying port, we
2909612SN/A        // have done our bit and sent the retry
2919091SN/A        state = BUSY;
2929091SN/A
29310719SMarco.Balboni@ARM.com        // occupy the crossbar layer until the next clock edge
29410719SMarco.Balboni@ARM.com        occupyLayer(xbar.clockEdge());
2958915SN/A    }
2968915SN/A}
2978915SN/A
2989715SN/Atemplate <typename SrcType, typename DstType>
2998915SN/Avoid
30010405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::recvRetry()
3018915SN/A{
3029612SN/A    // we should never get a retry without having failed to forward
3039612SN/A    // something to this port
3049715SN/A    assert(waitingForPeer != NULL);
3058915SN/A
3069715SN/A    // add the port where the failed packet originated to the front of
3079715SN/A    // the waiting ports for the layer, this allows us to call retry
30810405Sandreas.hansson@arm.com    // on the port immediately if the crossbar layer is idle
3099715SN/A    waitingForLayer.push_front(waitingForPeer);
3109612SN/A
3119715SN/A    // we are no longer waiting for the peer
3129715SN/A    waitingForPeer = NULL;
3139612SN/A
31410405Sandreas.hansson@arm.com    // if the layer is idle, retry this port straight away, if we
3159612SN/A    // are busy, then simply let the port wait for its turn
3169091SN/A    if (state == IDLE) {
3178915SN/A        retryWaiting();
3189612SN/A    } else {
3199612SN/A        assert(state == BUSY);
3208915SN/A    }
3218915SN/A}
3228915SN/A
3239031SN/APortID
32412780Snikos.nikoleris@arm.comBaseXBar::findPort(AddrRange addr_range)
3252497SN/A{
3269279SN/A    // we should never see any address lookups before we've got the
3279279SN/A    // ranges of all connected slave modules
3289279SN/A    assert(gotAllAddrRanges);
3299279SN/A
3309279SN/A    // Check the address map interval tree
33112780Snikos.nikoleris@arm.com    auto i = portMap.contains(addr_range);
3327523SN/A    if (i != portMap.end()) {
33312778Sgabeblack@google.com        return i->second;
3344958SN/A    }
3352846SN/A
3362846SN/A    // Check if this matches the default range
3377523SN/A    if (useDefaultRange) {
33812780Snikos.nikoleris@arm.com        if (addr_range.isSubset(defaultRange)) {
33912780Snikos.nikoleris@arm.com            DPRINTF(AddrRanges, "  found addr %s on default\n",
34012780Snikos.nikoleris@arm.com                    addr_range.to_string());
3419279SN/A            return defaultPortID;
3422846SN/A        }
3439031SN/A    } else if (defaultPortID != InvalidPortID) {
34412780Snikos.nikoleris@arm.com        DPRINTF(AddrRanges, "Unable to find destination for %s, "
34512780Snikos.nikoleris@arm.com                "will use default port\n", addr_range.to_string());
3469031SN/A        return defaultPortID;
3472846SN/A    }
3482846SN/A
3498849SN/A    // we should use the range for the default port and it did not
3508849SN/A    // match, or the default port is not set
35112780Snikos.nikoleris@arm.com    fatal("Unable to find destination for %s on %s\n", addr_range.to_string(),
3528849SN/A          name());
3533074SN/A}
3543074SN/A
35510405Sandreas.hansson@arm.com/** Function called by the port when the crossbar is receiving a range change.*/
3562497SN/Avoid
35710405Sandreas.hansson@arm.comBaseXBar::recvRangeChange(PortID master_port_id)
3582497SN/A{
35910405Sandreas.hansson@arm.com    DPRINTF(AddrRanges, "Received range change from slave port %s\n",
3609407SN/A            masterPorts[master_port_id]->getSlavePort().name());
3619407SN/A
3629279SN/A    // remember that we got a range from this master port and thus the
3639279SN/A    // connected slave module
3649279SN/A    gotAddrRanges[master_port_id] = true;
3652846SN/A
3669279SN/A    // update the global flag
3679279SN/A    if (!gotAllAddrRanges) {
3689279SN/A        // take a logical AND of all the ports and see if we got
3699279SN/A        // ranges from everyone
3709279SN/A        gotAllAddrRanges = true;
3719279SN/A        std::vector<bool>::const_iterator r = gotAddrRanges.begin();
3729279SN/A        while (gotAllAddrRanges &&  r != gotAddrRanges.end()) {
3739279SN/A            gotAllAddrRanges &= *r++;
3749279SN/A        }
3759407SN/A        if (gotAllAddrRanges)
37610405Sandreas.hansson@arm.com            DPRINTF(AddrRanges, "Got address ranges from all slaves\n");
3779279SN/A    }
3782534SN/A
3799279SN/A    // note that we could get the range from the default port at any
3809279SN/A    // point in time, and we cannot assume that the default range is
3819279SN/A    // set before the other ones are, so we do additional checks once
3829279SN/A    // all ranges are provided
3839032SN/A    if (master_port_id == defaultPortID) {
3849279SN/A        // only update if we are indeed checking ranges for the
3859279SN/A        // default port since the port might not have a valid range
3869279SN/A        // otherwise
3877523SN/A        if (useDefaultRange) {
3889279SN/A            AddrRangeList ranges = masterPorts[master_port_id]->getAddrRanges();
3899279SN/A
3909279SN/A            if (ranges.size() != 1)
39110405Sandreas.hansson@arm.com                fatal("Crossbar %s may only have a single default range",
3929279SN/A                      name());
3939279SN/A
3949279SN/A            defaultRange = ranges.front();
3959279SN/A        }
3969279SN/A    } else {
3979279SN/A        // the ports are allowed to update their address ranges
3989279SN/A        // dynamically, so remove any existing entries
3999279SN/A        if (gotAddrRanges[master_port_id]) {
40010405Sandreas.hansson@arm.com            for (auto p = portMap.begin(); p != portMap.end(); ) {
4019279SN/A                if (p->second == master_port_id)
4029279SN/A                    // erasing invalidates the iterator, so advance it
4039279SN/A                    // before the deletion takes place
4049279SN/A                    portMap.erase(p++);
4059279SN/A                else
4069279SN/A                    p++;
4073489SN/A            }
4082846SN/A        }
4092565SN/A
4109279SN/A        AddrRangeList ranges = masterPorts[master_port_id]->getAddrRanges();
4112497SN/A
41210405Sandreas.hansson@arm.com        for (const auto& r: ranges) {
41310405Sandreas.hansson@arm.com            DPRINTF(AddrRanges, "Adding range %s for id %d\n",
41410405Sandreas.hansson@arm.com                    r.to_string(), master_port_id);
41510405Sandreas.hansson@arm.com            if (portMap.insert(r, master_port_id) == portMap.end()) {
41612776Snikos.nikoleris@arm.com                PortID conflict_id = portMap.intersects(r)->second;
41712776Snikos.nikoleris@arm.com                fatal("%s has two ports responding within range "
41812776Snikos.nikoleris@arm.com                      "%s:\n\t%s\n\t%s\n",
4199032SN/A                      name(),
42010414SCurtis.Dunham@arm.com                      r.to_string(),
4219032SN/A                      masterPorts[master_port_id]->getSlavePort().name(),
4228922SN/A                      masterPorts[conflict_id]->getSlavePort().name());
4235490SN/A            }
4242846SN/A        }
4252565SN/A    }
4262568SN/A
4279279SN/A    // if we have received ranges from all our neighbouring slave
4289279SN/A    // modules, go ahead and tell our connected master modules in
4299279SN/A    // turn, this effectively assumes a tree structure of the system
4309279SN/A    if (gotAllAddrRanges) {
43110405Sandreas.hansson@arm.com        DPRINTF(AddrRanges, "Aggregating address ranges\n");
43210405Sandreas.hansson@arm.com        xbarRanges.clear();
4339564SN/A
4349564SN/A        // start out with the default range
4359564SN/A        if (useDefaultRange) {
4369564SN/A            if (!gotAddrRanges[defaultPortID])
43710405Sandreas.hansson@arm.com                fatal("Crossbar %s uses default range, but none provided",
4389564SN/A                      name());
4399564SN/A
44010405Sandreas.hansson@arm.com            xbarRanges.push_back(defaultRange);
44110405Sandreas.hansson@arm.com            DPRINTF(AddrRanges, "-- Adding default %s\n",
4429564SN/A                    defaultRange.to_string());
4439564SN/A        }
4449564SN/A
4459564SN/A        // merge all interleaved ranges and add any range that is not
4469564SN/A        // a subset of the default range
4479564SN/A        std::vector<AddrRange> intlv_ranges;
44810405Sandreas.hansson@arm.com        for (const auto& r: portMap) {
4499564SN/A            // if the range is interleaved then save it for now
45010405Sandreas.hansson@arm.com            if (r.first.interleaved()) {
4519564SN/A                // if we already got interleaved ranges that are not
4529564SN/A                // part of the same range, then first do a merge
4539564SN/A                // before we add the new one
4549564SN/A                if (!intlv_ranges.empty() &&
45510405Sandreas.hansson@arm.com                    !intlv_ranges.back().mergesWith(r.first)) {
45610405Sandreas.hansson@arm.com                    DPRINTF(AddrRanges, "-- Merging range from %d ranges\n",
4579564SN/A                            intlv_ranges.size());
4589564SN/A                    AddrRange merged_range(intlv_ranges);
4599564SN/A                    // next decide if we keep the merged range or not
4609564SN/A                    if (!(useDefaultRange &&
4619564SN/A                          merged_range.isSubset(defaultRange))) {
46210405Sandreas.hansson@arm.com                        xbarRanges.push_back(merged_range);
46310405Sandreas.hansson@arm.com                        DPRINTF(AddrRanges, "-- Adding merged range %s\n",
4649564SN/A                                merged_range.to_string());
4659564SN/A                    }
4669564SN/A                    intlv_ranges.clear();
4679564SN/A                }
46810405Sandreas.hansson@arm.com                intlv_ranges.push_back(r.first);
4699564SN/A            } else {
4709564SN/A                // keep the current range if not a subset of the default
4719564SN/A                if (!(useDefaultRange &&
47210405Sandreas.hansson@arm.com                      r.first.isSubset(defaultRange))) {
47310405Sandreas.hansson@arm.com                    xbarRanges.push_back(r.first);
47410405Sandreas.hansson@arm.com                    DPRINTF(AddrRanges, "-- Adding range %s\n",
47510405Sandreas.hansson@arm.com                            r.first.to_string());
4769564SN/A                }
4779564SN/A            }
4789564SN/A        }
4799564SN/A
4809564SN/A        // if there is still interleaved ranges waiting to be merged,
4819564SN/A        // go ahead and do it
4829564SN/A        if (!intlv_ranges.empty()) {
48310405Sandreas.hansson@arm.com            DPRINTF(AddrRanges, "-- Merging range from %d ranges\n",
4849564SN/A                    intlv_ranges.size());
4859564SN/A            AddrRange merged_range(intlv_ranges);
4869564SN/A            if (!(useDefaultRange && merged_range.isSubset(defaultRange))) {
48710405Sandreas.hansson@arm.com                xbarRanges.push_back(merged_range);
48810405Sandreas.hansson@arm.com                DPRINTF(AddrRanges, "-- Adding merged range %s\n",
4899564SN/A                        merged_range.to_string());
4909564SN/A            }
4919564SN/A        }
4929564SN/A
49312776Snikos.nikoleris@arm.com        // also check that no range partially intersects with the
4949279SN/A        // default range, this has to be done after all ranges are set
4959279SN/A        // as there are no guarantees for when the default range is
4969279SN/A        // update with respect to the other ones
4979279SN/A        if (useDefaultRange) {
49810405Sandreas.hansson@arm.com            for (const auto& r: xbarRanges) {
4999564SN/A                // see if the new range is partially
5009564SN/A                // overlapping the default range
50110405Sandreas.hansson@arm.com                if (r.intersects(defaultRange) &&
50210405Sandreas.hansson@arm.com                    !r.isSubset(defaultRange))
5039564SN/A                    fatal("Range %s intersects the "                    \
5049564SN/A                          "default range of %s but is not a "           \
50510405Sandreas.hansson@arm.com                          "subset\n", r.to_string(), name());
5069279SN/A            }
5079279SN/A        }
5089279SN/A
5099279SN/A        // tell all our neighbouring master ports that our address
5109279SN/A        // ranges have changed
51110405Sandreas.hansson@arm.com        for (const auto& s: slavePorts)
51210405Sandreas.hansson@arm.com            s->sendRangeChange();
5139279SN/A    }
5142497SN/A}
5152497SN/A
5168711SN/AAddrRangeList
51710405Sandreas.hansson@arm.comBaseXBar::getAddrRanges() const
5182497SN/A{
5199279SN/A    // we should never be asked without first having sent a range
5209279SN/A    // change, and the latter is only done once we have all the ranges
5219279SN/A    // of the connected devices
5229279SN/A    assert(gotAllAddrRanges);
5232568SN/A
5249407SN/A    // at the moment, this never happens, as there are no cycles in
52510405Sandreas.hansson@arm.com    // the range queries and no devices on the master side of a crossbar
5269407SN/A    // (CPU, cache, bridge etc) actually care about the ranges of the
5279407SN/A    // ports they are connected to
5289407SN/A
52910405Sandreas.hansson@arm.com    DPRINTF(AddrRanges, "Received address range request\n");
5302846SN/A
53110405Sandreas.hansson@arm.com    return xbarRanges;
5328711SN/A}
5338711SN/A
5349712SN/Avoid
53510405Sandreas.hansson@arm.comBaseXBar::regStats()
5369712SN/A{
53711522Sstephan.diestelhorst@arm.com    ClockedObject::regStats();
53811522Sstephan.diestelhorst@arm.com
5399712SN/A    using namespace Stats;
5409712SN/A
5419712SN/A    transDist
5429712SN/A        .init(MemCmd::NUM_MEM_CMDS)
5439712SN/A        .name(name() + ".trans_dist")
5449712SN/A        .desc("Transaction distribution")
5459712SN/A        .flags(nozero);
5469712SN/A
5479712SN/A    // get the string representation of the commands
5489712SN/A    for (int i = 0; i < MemCmd::NUM_MEM_CMDS; i++) {
5499712SN/A        MemCmd cmd(i);
5509712SN/A        const std::string &cstr = cmd.toString();
5519712SN/A        transDist.subname(i, cstr);
5529712SN/A    }
5539712SN/A
5549712SN/A    pktCount
5559712SN/A        .init(slavePorts.size(), masterPorts.size())
5569712SN/A        .name(name() + ".pkt_count")
5579712SN/A        .desc("Packet count per connected master and slave (bytes)")
5589712SN/A        .flags(total | nozero | nonan);
5599712SN/A
56010405Sandreas.hansson@arm.com    pktSize
5619712SN/A        .init(slavePorts.size(), masterPorts.size())
56210405Sandreas.hansson@arm.com        .name(name() + ".pkt_size")
5639712SN/A        .desc("Cumulative packet size per connected master and slave (bytes)")
5649712SN/A        .flags(total | nozero | nonan);
5659712SN/A
5669712SN/A    // both the packet count and total size are two-dimensional
5679712SN/A    // vectors, indexed by slave port id and master port id, thus the
5689712SN/A    // neighbouring master and slave, they do not differentiate what
5699712SN/A    // came from the master and was forwarded to the slave (requests
5709712SN/A    // and snoop responses) and what came from the slave and was
5719712SN/A    // forwarded to the master (responses and snoop requests)
5729712SN/A    for (int i = 0; i < slavePorts.size(); i++) {
5739712SN/A        pktCount.subname(i, slavePorts[i]->getMasterPort().name());
57410405Sandreas.hansson@arm.com        pktSize.subname(i, slavePorts[i]->getMasterPort().name());
5759712SN/A        for (int j = 0; j < masterPorts.size(); j++) {
5769712SN/A            pktCount.ysubname(j, masterPorts[j]->getSlavePort().name());
57710405Sandreas.hansson@arm.com            pktSize.ysubname(j, masterPorts[j]->getSlavePort().name());
5789712SN/A        }
5799712SN/A    }
5809712SN/A}
5819712SN/A
5829715SN/Atemplate <typename SrcType, typename DstType>
58310913Sandreas.sandberg@arm.comDrainState
58410913Sandreas.sandberg@arm.comBaseXBar::Layer<SrcType,DstType>::drain()
5853470SN/A{
5863470SN/A    //We should check that we're not "doing" anything, and that noone is
5873470SN/A    //waiting. We might be idle but have someone waiting if the device we
5883470SN/A    //contacted for a retry didn't actually retry.
5899612SN/A    if (state != IDLE) {
59010405Sandreas.hansson@arm.com        DPRINTF(Drain, "Crossbar not drained\n");
59110913Sandreas.sandberg@arm.com        return DrainState::Draining;
59210913Sandreas.sandberg@arm.com    } else {
59310913Sandreas.sandberg@arm.com        return DrainState::Drained;
5943470SN/A    }
5953470SN/A}
5969093SN/A
5979715SN/Atemplate <typename SrcType, typename DstType>
5989712SN/Avoid
59910405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::regStats()
6009712SN/A{
6019712SN/A    using namespace Stats;
6029712SN/A
6039712SN/A    occupancy
6049712SN/A        .name(name() + ".occupancy")
6059712SN/A        .desc("Layer occupancy (ticks)")
6069712SN/A        .flags(nozero);
6079712SN/A
6089712SN/A    utilization
6099712SN/A        .name(name() + ".utilization")
6109712SN/A        .desc("Layer utilization (%)")
6119712SN/A        .precision(1)
6129712SN/A        .flags(nozero);
6139712SN/A
6149712SN/A    utilization = 100 * occupancy / simTicks;
6159712SN/A}
6169712SN/A
6179093SN/A/**
61810405Sandreas.hansson@arm.com * Crossbar layer template instantiations. Could be removed with _impl.hh
6199093SN/A * file, but since there are only two given options (MasterPort and
6209093SN/A * SlavePort) it seems a bit excessive at this point.
6219093SN/A */
62210405Sandreas.hansson@arm.comtemplate class BaseXBar::Layer<SlavePort,MasterPort>;
62310405Sandreas.hansson@arm.comtemplate class BaseXBar::Layer<MasterPort,SlavePort>;
624