xbar.cc revision 13784
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 8413784Sgabeblack@google.comPort & 8513784Sgabeblack@google.comBaseXBar::getPort(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]; 9213784Sgabeblack@google.com } else if (if_name == "slave" && idx < slavePorts.size()) { 938948SN/A // the slave port index translates directly to the vector position 948948SN/A return *slavePorts[idx]; 958922SN/A } else { 9613784Sgabeblack@google.com return MemObject::getPort(if_name, idx); 973489SN/A } 982640SN/A} 992640SN/A 1009547SN/Avoid 10110719SMarco.Balboni@ARM.comBaseXBar::calcPacketTiming(PacketPtr pkt, Tick header_delay) 1022497SN/A{ 10310405Sandreas.hansson@arm.com // the crossbar will be called at a time that is not necessarily 1049547SN/A // coinciding with its own clock, so start by determining how long 1059547SN/A // until the next clock edge (could be zero) 1069648SN/A Tick offset = clockEdge() - curTick(); 1075354SN/A 10810719SMarco.Balboni@ARM.com // the header delay depends on the path through the crossbar, and 10910719SMarco.Balboni@ARM.com // we therefore rely on the caller to provide the actual 11010719SMarco.Balboni@ARM.com // value 11110719SMarco.Balboni@ARM.com pkt->headerDelay += offset + header_delay; 1123210SN/A 11310719SMarco.Balboni@ARM.com // note that we add the header delay to the existing value, and 11410719SMarco.Balboni@ARM.com // align it to the crossbar clock 1159549SN/A 11610719SMarco.Balboni@ARM.com // do a quick sanity check to ensure the timings are not being 11710719SMarco.Balboni@ARM.com // ignored, note that this specific value may cause problems for 11810719SMarco.Balboni@ARM.com // slower interconnects 11910719SMarco.Balboni@ARM.com panic_if(pkt->headerDelay > SimClock::Int::us, 12010719SMarco.Balboni@ARM.com "Encountered header delay exceeding 1 us\n"); 1213218SN/A 12210719SMarco.Balboni@ARM.com if (pkt->hasData()) { 12310719SMarco.Balboni@ARM.com // the payloadDelay takes into account the relative time to 12410719SMarco.Balboni@ARM.com // deliver the payload of the packet, after the header delay, 12510719SMarco.Balboni@ARM.com // we take the maximum since the payload delay could already 12610719SMarco.Balboni@ARM.com // be longer than what this parcitular crossbar enforces. 12710719SMarco.Balboni@ARM.com pkt->payloadDelay = std::max<Tick>(pkt->payloadDelay, 12810719SMarco.Balboni@ARM.com divCeil(pkt->getSize(), width) * 12910719SMarco.Balboni@ARM.com clockPeriod()); 13010719SMarco.Balboni@ARM.com } 13110719SMarco.Balboni@ARM.com 13210719SMarco.Balboni@ARM.com // the payload delay is not paying for the clock offset as that is 13310719SMarco.Balboni@ARM.com // already done using the header delay, and the payload delay is 13410719SMarco.Balboni@ARM.com // also used to determine how long the crossbar layer is busy and 13510719SMarco.Balboni@ARM.com // thus regulates throughput 1365354SN/A} 1375354SN/A 1389715SN/Atemplate <typename SrcType, typename DstType> 13910405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::Layer(DstType& _port, BaseXBar& _xbar, 1409715SN/A const std::string& _name) : 14110913Sandreas.sandberg@arm.com port(_port), xbar(_xbar), _name(_name), state(IDLE), 14212084Sspwilson2@wisc.edu waitingForPeer(NULL), releaseEvent([this]{ releaseLayer(); }, name()) 1439092SN/A{ 1449092SN/A} 1459092SN/A 1469715SN/Atemplate <typename SrcType, typename DstType> 14710405Sandreas.hansson@arm.comvoid BaseXBar::Layer<SrcType,DstType>::occupyLayer(Tick until) 1485354SN/A{ 14910405Sandreas.hansson@arm.com // ensure the state is busy at this point, as the layer should 1509612SN/A // transition from idle as soon as it has decided to forward the 1519612SN/A // packet to prevent any follow-on calls to sendTiming seeing an 15210405Sandreas.hansson@arm.com // unoccupied layer 1539612SN/A assert(state == BUSY); 1545354SN/A 15510405Sandreas.hansson@arm.com // until should never be 0 as express snoops never occupy the layer 1569091SN/A assert(until != 0); 15710405Sandreas.hansson@arm.com xbar.schedule(releaseEvent, until); 1589091SN/A 1599712SN/A // account for the occupied ticks 1609712SN/A occupancy += until - curTick(); 1619712SN/A 16210405Sandreas.hansson@arm.com DPRINTF(BaseXBar, "The crossbar layer is now busy from tick %d to %d\n", 1639091SN/A curTick(), until); 1643244SN/A} 1653244SN/A 1669715SN/Atemplate <typename SrcType, typename DstType> 1678948SN/Abool 16810405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::tryTiming(SrcType* src_port) 1698948SN/A{ 1709716SN/A // if we are in the retry state, we will not see anything but the 1719716SN/A // retrying port (or in the case of the snoop ports the snoop 1729716SN/A // response port that mirrors the actual slave port) as we leave 1739716SN/A // this state again in zero time if the peer does not immediately 17410405Sandreas.hansson@arm.com // call the layer when receiving the retry 1759716SN/A 1769716SN/A // first we see if the layer is busy, next we check if the 1779716SN/A // destination port is already engaged in a transaction waiting 1789716SN/A // for a retry from the peer 1799716SN/A if (state == BUSY || waitingForPeer != NULL) { 1809716SN/A // the port should not be waiting already 1819716SN/A assert(std::find(waitingForLayer.begin(), waitingForLayer.end(), 1829716SN/A src_port) == waitingForLayer.end()); 1839716SN/A 1849612SN/A // put the port at the end of the retry list waiting for the 1859612SN/A // layer to be freed up (and in the case of a busy peer, for 18610405Sandreas.hansson@arm.com // that transaction to go through, and then the layer to free 1879612SN/A // up) 1889715SN/A waitingForLayer.push_back(src_port); 1899091SN/A return false; 1908948SN/A } 1919091SN/A 1929612SN/A state = BUSY; 1939611SN/A 1949091SN/A return true; 1958948SN/A} 1968948SN/A 1979715SN/Atemplate <typename SrcType, typename DstType> 1988975SN/Avoid 19910405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::succeededTiming(Tick busy_time) 2008948SN/A{ 2019612SN/A // we should have gone from idle or retry to busy in the tryTiming 2029612SN/A // test 2039091SN/A assert(state == BUSY); 2049091SN/A 20510405Sandreas.hansson@arm.com // occupy the layer accordingly 2069092SN/A occupyLayer(busy_time); 2079091SN/A} 2089091SN/A 2099715SN/Atemplate <typename SrcType, typename DstType> 2109091SN/Avoid 21110405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::failedTiming(SrcType* src_port, 2129715SN/A Tick busy_time) 2139091SN/A{ 2149612SN/A // ensure no one got in between and tried to send something to 2159612SN/A // this port 2169715SN/A assert(waitingForPeer == NULL); 2179091SN/A 2189612SN/A // if the source port is the current retrying one or not, we have 2199612SN/A // failed in forwarding and should track that we are now waiting 2209612SN/A // for the peer to send a retry 2219715SN/A waitingForPeer = src_port; 2229612SN/A 2239612SN/A // we should have gone from idle or retry to busy in the tryTiming 2249612SN/A // test 2259612SN/A assert(state == BUSY); 2269091SN/A 2279091SN/A // occupy the bus accordingly 2289092SN/A occupyLayer(busy_time); 2298948SN/A} 2308948SN/A 2319715SN/Atemplate <typename SrcType, typename DstType> 2328948SN/Avoid 23310405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::releaseLayer() 2342657SN/A{ 2358915SN/A // releasing the bus means we should now be idle 2369091SN/A assert(state == BUSY); 2379092SN/A assert(!releaseEvent.scheduled()); 2389091SN/A 2399091SN/A // update the state 2409091SN/A state = IDLE; 2413252SN/A 2429612SN/A // bus layer is now idle, so if someone is waiting we can retry 2439612SN/A if (!waitingForLayer.empty()) { 24410347SN/A // there is no point in sending a retry if someone is still 24510347SN/A // waiting for the peer 24610347SN/A if (waitingForPeer == NULL) 24710347SN/A retryWaiting(); 24810913Sandreas.sandberg@arm.com } else if (waitingForPeer == NULL && drainState() == DrainState::Draining) { 24910405Sandreas.hansson@arm.com DPRINTF(Drain, "Crossbar done draining, signaling drain manager\n"); 2509091SN/A //If we weren't able to drain before, do it now. 25110913Sandreas.sandberg@arm.com signalDrainDone(); 2523512SN/A } 2532657SN/A} 2542657SN/A 2559715SN/Atemplate <typename SrcType, typename DstType> 2568915SN/Avoid 25710405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::retryWaiting() 2588915SN/A{ 2599612SN/A // this should never be called with no one waiting 2609612SN/A assert(!waitingForLayer.empty()); 2618915SN/A 2629091SN/A // we always go to retrying from idle 2639091SN/A assert(state == IDLE); 2649091SN/A 2659611SN/A // update the state 2669091SN/A state = RETRY; 2678915SN/A 2689611SN/A // set the retrying port to the front of the retry list and pop it 2699611SN/A // off the list 27010347SN/A SrcType* retryingPort = waitingForLayer.front(); 2719612SN/A waitingForLayer.pop_front(); 2729611SN/A 2739612SN/A // tell the port to retry, which in some cases ends up calling the 27410405Sandreas.hansson@arm.com // layer again 27510713Sandreas.hansson@arm.com sendRetry(retryingPort); 2768915SN/A 27710405Sandreas.hansson@arm.com // If the layer is still in the retry state, sendTiming wasn't 27810719SMarco.Balboni@ARM.com // called in zero time (e.g. the cache does this when a writeback 27910719SMarco.Balboni@ARM.com // is squashed) 2809091SN/A if (state == RETRY) { 2819612SN/A // update the state to busy and reset the retrying port, we 2829612SN/A // have done our bit and sent the retry 2839091SN/A state = BUSY; 2849091SN/A 28510719SMarco.Balboni@ARM.com // occupy the crossbar layer until the next clock edge 28610719SMarco.Balboni@ARM.com occupyLayer(xbar.clockEdge()); 2878915SN/A } 2888915SN/A} 2898915SN/A 2909715SN/Atemplate <typename SrcType, typename DstType> 2918915SN/Avoid 29210405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::recvRetry() 2938915SN/A{ 2949612SN/A // we should never get a retry without having failed to forward 2959612SN/A // something to this port 2969715SN/A assert(waitingForPeer != NULL); 2978915SN/A 2989715SN/A // add the port where the failed packet originated to the front of 2999715SN/A // the waiting ports for the layer, this allows us to call retry 30010405Sandreas.hansson@arm.com // on the port immediately if the crossbar layer is idle 3019715SN/A waitingForLayer.push_front(waitingForPeer); 3029612SN/A 3039715SN/A // we are no longer waiting for the peer 3049715SN/A waitingForPeer = NULL; 3059612SN/A 30610405Sandreas.hansson@arm.com // if the layer is idle, retry this port straight away, if we 3079612SN/A // are busy, then simply let the port wait for its turn 3089091SN/A if (state == IDLE) { 3098915SN/A retryWaiting(); 3109612SN/A } else { 3119612SN/A assert(state == BUSY); 3128915SN/A } 3138915SN/A} 3148915SN/A 3159031SN/APortID 31612780Snikos.nikoleris@arm.comBaseXBar::findPort(AddrRange addr_range) 3172497SN/A{ 3189279SN/A // we should never see any address lookups before we've got the 3199279SN/A // ranges of all connected slave modules 3209279SN/A assert(gotAllAddrRanges); 3219279SN/A 3229279SN/A // Check the address map interval tree 32312780Snikos.nikoleris@arm.com auto i = portMap.contains(addr_range); 3247523SN/A if (i != portMap.end()) { 32512778Sgabeblack@google.com return i->second; 3264958SN/A } 3272846SN/A 3282846SN/A // Check if this matches the default range 3297523SN/A if (useDefaultRange) { 33012780Snikos.nikoleris@arm.com if (addr_range.isSubset(defaultRange)) { 33112780Snikos.nikoleris@arm.com DPRINTF(AddrRanges, " found addr %s on default\n", 33212780Snikos.nikoleris@arm.com addr_range.to_string()); 3339279SN/A return defaultPortID; 3342846SN/A } 3359031SN/A } else if (defaultPortID != InvalidPortID) { 33612780Snikos.nikoleris@arm.com DPRINTF(AddrRanges, "Unable to find destination for %s, " 33712780Snikos.nikoleris@arm.com "will use default port\n", addr_range.to_string()); 3389031SN/A return defaultPortID; 3392846SN/A } 3402846SN/A 3418849SN/A // we should use the range for the default port and it did not 3428849SN/A // match, or the default port is not set 34312780Snikos.nikoleris@arm.com fatal("Unable to find destination for %s on %s\n", addr_range.to_string(), 3448849SN/A name()); 3453074SN/A} 3463074SN/A 34710405Sandreas.hansson@arm.com/** Function called by the port when the crossbar is receiving a range change.*/ 3482497SN/Avoid 34910405Sandreas.hansson@arm.comBaseXBar::recvRangeChange(PortID master_port_id) 3502497SN/A{ 35110405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "Received range change from slave port %s\n", 3529407SN/A masterPorts[master_port_id]->getSlavePort().name()); 3539407SN/A 3549279SN/A // remember that we got a range from this master port and thus the 3559279SN/A // connected slave module 3569279SN/A gotAddrRanges[master_port_id] = true; 3572846SN/A 3589279SN/A // update the global flag 3599279SN/A if (!gotAllAddrRanges) { 3609279SN/A // take a logical AND of all the ports and see if we got 3619279SN/A // ranges from everyone 3629279SN/A gotAllAddrRanges = true; 3639279SN/A std::vector<bool>::const_iterator r = gotAddrRanges.begin(); 3649279SN/A while (gotAllAddrRanges && r != gotAddrRanges.end()) { 3659279SN/A gotAllAddrRanges &= *r++; 3669279SN/A } 3679407SN/A if (gotAllAddrRanges) 36810405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "Got address ranges from all slaves\n"); 3699279SN/A } 3702534SN/A 3719279SN/A // note that we could get the range from the default port at any 3729279SN/A // point in time, and we cannot assume that the default range is 3739279SN/A // set before the other ones are, so we do additional checks once 3749279SN/A // all ranges are provided 3759032SN/A if (master_port_id == defaultPortID) { 3769279SN/A // only update if we are indeed checking ranges for the 3779279SN/A // default port since the port might not have a valid range 3789279SN/A // otherwise 3797523SN/A if (useDefaultRange) { 3809279SN/A AddrRangeList ranges = masterPorts[master_port_id]->getAddrRanges(); 3819279SN/A 3829279SN/A if (ranges.size() != 1) 38310405Sandreas.hansson@arm.com fatal("Crossbar %s may only have a single default range", 3849279SN/A name()); 3859279SN/A 3869279SN/A defaultRange = ranges.front(); 3879279SN/A } 3889279SN/A } else { 3899279SN/A // the ports are allowed to update their address ranges 3909279SN/A // dynamically, so remove any existing entries 3919279SN/A if (gotAddrRanges[master_port_id]) { 39210405Sandreas.hansson@arm.com for (auto p = portMap.begin(); p != portMap.end(); ) { 3939279SN/A if (p->second == master_port_id) 3949279SN/A // erasing invalidates the iterator, so advance it 3959279SN/A // before the deletion takes place 3969279SN/A portMap.erase(p++); 3979279SN/A else 3989279SN/A p++; 3993489SN/A } 4002846SN/A } 4012565SN/A 4029279SN/A AddrRangeList ranges = masterPorts[master_port_id]->getAddrRanges(); 4032497SN/A 40410405Sandreas.hansson@arm.com for (const auto& r: ranges) { 40510405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "Adding range %s for id %d\n", 40610405Sandreas.hansson@arm.com r.to_string(), master_port_id); 40710405Sandreas.hansson@arm.com if (portMap.insert(r, master_port_id) == portMap.end()) { 40812776Snikos.nikoleris@arm.com PortID conflict_id = portMap.intersects(r)->second; 40912776Snikos.nikoleris@arm.com fatal("%s has two ports responding within range " 41012776Snikos.nikoleris@arm.com "%s:\n\t%s\n\t%s\n", 4119032SN/A name(), 41210414SCurtis.Dunham@arm.com r.to_string(), 4139032SN/A masterPorts[master_port_id]->getSlavePort().name(), 4148922SN/A masterPorts[conflict_id]->getSlavePort().name()); 4155490SN/A } 4162846SN/A } 4172565SN/A } 4182568SN/A 4199279SN/A // if we have received ranges from all our neighbouring slave 4209279SN/A // modules, go ahead and tell our connected master modules in 4219279SN/A // turn, this effectively assumes a tree structure of the system 4229279SN/A if (gotAllAddrRanges) { 42310405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "Aggregating address ranges\n"); 42410405Sandreas.hansson@arm.com xbarRanges.clear(); 4259564SN/A 4269564SN/A // start out with the default range 4279564SN/A if (useDefaultRange) { 4289564SN/A if (!gotAddrRanges[defaultPortID]) 42910405Sandreas.hansson@arm.com fatal("Crossbar %s uses default range, but none provided", 4309564SN/A name()); 4319564SN/A 43210405Sandreas.hansson@arm.com xbarRanges.push_back(defaultRange); 43310405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "-- Adding default %s\n", 4349564SN/A defaultRange.to_string()); 4359564SN/A } 4369564SN/A 4379564SN/A // merge all interleaved ranges and add any range that is not 4389564SN/A // a subset of the default range 4399564SN/A std::vector<AddrRange> intlv_ranges; 44010405Sandreas.hansson@arm.com for (const auto& r: portMap) { 4419564SN/A // if the range is interleaved then save it for now 44210405Sandreas.hansson@arm.com if (r.first.interleaved()) { 4439564SN/A // if we already got interleaved ranges that are not 4449564SN/A // part of the same range, then first do a merge 4459564SN/A // before we add the new one 4469564SN/A if (!intlv_ranges.empty() && 44710405Sandreas.hansson@arm.com !intlv_ranges.back().mergesWith(r.first)) { 44810405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "-- Merging range from %d ranges\n", 4499564SN/A intlv_ranges.size()); 4509564SN/A AddrRange merged_range(intlv_ranges); 4519564SN/A // next decide if we keep the merged range or not 4529564SN/A if (!(useDefaultRange && 4539564SN/A merged_range.isSubset(defaultRange))) { 45410405Sandreas.hansson@arm.com xbarRanges.push_back(merged_range); 45510405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "-- Adding merged range %s\n", 4569564SN/A merged_range.to_string()); 4579564SN/A } 4589564SN/A intlv_ranges.clear(); 4599564SN/A } 46010405Sandreas.hansson@arm.com intlv_ranges.push_back(r.first); 4619564SN/A } else { 4629564SN/A // keep the current range if not a subset of the default 4639564SN/A if (!(useDefaultRange && 46410405Sandreas.hansson@arm.com r.first.isSubset(defaultRange))) { 46510405Sandreas.hansson@arm.com xbarRanges.push_back(r.first); 46610405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "-- Adding range %s\n", 46710405Sandreas.hansson@arm.com r.first.to_string()); 4689564SN/A } 4699564SN/A } 4709564SN/A } 4719564SN/A 4729564SN/A // if there is still interleaved ranges waiting to be merged, 4739564SN/A // go ahead and do it 4749564SN/A if (!intlv_ranges.empty()) { 47510405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "-- Merging range from %d ranges\n", 4769564SN/A intlv_ranges.size()); 4779564SN/A AddrRange merged_range(intlv_ranges); 4789564SN/A if (!(useDefaultRange && merged_range.isSubset(defaultRange))) { 47910405Sandreas.hansson@arm.com xbarRanges.push_back(merged_range); 48010405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "-- Adding merged range %s\n", 4819564SN/A merged_range.to_string()); 4829564SN/A } 4839564SN/A } 4849564SN/A 48512776Snikos.nikoleris@arm.com // also check that no range partially intersects with the 4869279SN/A // default range, this has to be done after all ranges are set 4879279SN/A // as there are no guarantees for when the default range is 4889279SN/A // update with respect to the other ones 4899279SN/A if (useDefaultRange) { 49010405Sandreas.hansson@arm.com for (const auto& r: xbarRanges) { 4919564SN/A // see if the new range is partially 4929564SN/A // overlapping the default range 49310405Sandreas.hansson@arm.com if (r.intersects(defaultRange) && 49410405Sandreas.hansson@arm.com !r.isSubset(defaultRange)) 4959564SN/A fatal("Range %s intersects the " \ 4969564SN/A "default range of %s but is not a " \ 49710405Sandreas.hansson@arm.com "subset\n", r.to_string(), name()); 4989279SN/A } 4999279SN/A } 5009279SN/A 5019279SN/A // tell all our neighbouring master ports that our address 5029279SN/A // ranges have changed 50310405Sandreas.hansson@arm.com for (const auto& s: slavePorts) 50410405Sandreas.hansson@arm.com s->sendRangeChange(); 5059279SN/A } 5062497SN/A} 5072497SN/A 5088711SN/AAddrRangeList 50910405Sandreas.hansson@arm.comBaseXBar::getAddrRanges() const 5102497SN/A{ 5119279SN/A // we should never be asked without first having sent a range 5129279SN/A // change, and the latter is only done once we have all the ranges 5139279SN/A // of the connected devices 5149279SN/A assert(gotAllAddrRanges); 5152568SN/A 5169407SN/A // at the moment, this never happens, as there are no cycles in 51710405Sandreas.hansson@arm.com // the range queries and no devices on the master side of a crossbar 5189407SN/A // (CPU, cache, bridge etc) actually care about the ranges of the 5199407SN/A // ports they are connected to 5209407SN/A 52110405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "Received address range request\n"); 5222846SN/A 52310405Sandreas.hansson@arm.com return xbarRanges; 5248711SN/A} 5258711SN/A 5269712SN/Avoid 52710405Sandreas.hansson@arm.comBaseXBar::regStats() 5289712SN/A{ 52911522Sstephan.diestelhorst@arm.com ClockedObject::regStats(); 53011522Sstephan.diestelhorst@arm.com 5319712SN/A using namespace Stats; 5329712SN/A 5339712SN/A transDist 5349712SN/A .init(MemCmd::NUM_MEM_CMDS) 5359712SN/A .name(name() + ".trans_dist") 5369712SN/A .desc("Transaction distribution") 5379712SN/A .flags(nozero); 5389712SN/A 5399712SN/A // get the string representation of the commands 5409712SN/A for (int i = 0; i < MemCmd::NUM_MEM_CMDS; i++) { 5419712SN/A MemCmd cmd(i); 5429712SN/A const std::string &cstr = cmd.toString(); 5439712SN/A transDist.subname(i, cstr); 5449712SN/A } 5459712SN/A 5469712SN/A pktCount 5479712SN/A .init(slavePorts.size(), masterPorts.size()) 5489712SN/A .name(name() + ".pkt_count") 5499712SN/A .desc("Packet count per connected master and slave (bytes)") 5509712SN/A .flags(total | nozero | nonan); 5519712SN/A 55210405Sandreas.hansson@arm.com pktSize 5539712SN/A .init(slavePorts.size(), masterPorts.size()) 55410405Sandreas.hansson@arm.com .name(name() + ".pkt_size") 5559712SN/A .desc("Cumulative packet size per connected master and slave (bytes)") 5569712SN/A .flags(total | nozero | nonan); 5579712SN/A 5589712SN/A // both the packet count and total size are two-dimensional 5599712SN/A // vectors, indexed by slave port id and master port id, thus the 5609712SN/A // neighbouring master and slave, they do not differentiate what 5619712SN/A // came from the master and was forwarded to the slave (requests 5629712SN/A // and snoop responses) and what came from the slave and was 5639712SN/A // forwarded to the master (responses and snoop requests) 5649712SN/A for (int i = 0; i < slavePorts.size(); i++) { 5659712SN/A pktCount.subname(i, slavePorts[i]->getMasterPort().name()); 56610405Sandreas.hansson@arm.com pktSize.subname(i, slavePorts[i]->getMasterPort().name()); 5679712SN/A for (int j = 0; j < masterPorts.size(); j++) { 5689712SN/A pktCount.ysubname(j, masterPorts[j]->getSlavePort().name()); 56910405Sandreas.hansson@arm.com pktSize.ysubname(j, masterPorts[j]->getSlavePort().name()); 5709712SN/A } 5719712SN/A } 5729712SN/A} 5739712SN/A 5749715SN/Atemplate <typename SrcType, typename DstType> 57510913Sandreas.sandberg@arm.comDrainState 57610913Sandreas.sandberg@arm.comBaseXBar::Layer<SrcType,DstType>::drain() 5773470SN/A{ 5783470SN/A //We should check that we're not "doing" anything, and that noone is 5793470SN/A //waiting. We might be idle but have someone waiting if the device we 5803470SN/A //contacted for a retry didn't actually retry. 5819612SN/A if (state != IDLE) { 58210405Sandreas.hansson@arm.com DPRINTF(Drain, "Crossbar not drained\n"); 58310913Sandreas.sandberg@arm.com return DrainState::Draining; 58410913Sandreas.sandberg@arm.com } else { 58510913Sandreas.sandberg@arm.com return DrainState::Drained; 5863470SN/A } 5873470SN/A} 5889093SN/A 5899715SN/Atemplate <typename SrcType, typename DstType> 5909712SN/Avoid 59110405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::regStats() 5929712SN/A{ 5939712SN/A using namespace Stats; 5949712SN/A 5959712SN/A occupancy 5969712SN/A .name(name() + ".occupancy") 5979712SN/A .desc("Layer occupancy (ticks)") 5989712SN/A .flags(nozero); 5999712SN/A 6009712SN/A utilization 6019712SN/A .name(name() + ".utilization") 6029712SN/A .desc("Layer utilization (%)") 6039712SN/A .precision(1) 6049712SN/A .flags(nozero); 6059712SN/A 6069712SN/A utilization = 100 * occupancy / simTicks; 6079712SN/A} 6089712SN/A 6099093SN/A/** 61010405Sandreas.hansson@arm.com * Crossbar layer template instantiations. Could be removed with _impl.hh 6119093SN/A * file, but since there are only two given options (MasterPort and 6129093SN/A * SlavePort) it seems a bit excessive at this point. 6139093SN/A */ 61410405Sandreas.hansson@arm.comtemplate class BaseXBar::Layer<SlavePort,MasterPort>; 61510405Sandreas.hansson@arm.comtemplate class BaseXBar::Layer<MasterPort,SlavePort>; 616