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) 5913892Sgabeblack@google.com : ClockedObject(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 7913784Sgabeblack@google.comPort & 8013784Sgabeblack@google.comBaseXBar::getPort(const std::string &if_name, PortID idx) 812640SN/A{ 828948SN/A if (if_name == "master" && idx < masterPorts.size()) { 838948SN/A // the master port index translates directly to the vector position 848922SN/A return *masterPorts[idx]; 858851SN/A } else if (if_name == "default") { 869031SN/A return *masterPorts[defaultPortID]; 8713784Sgabeblack@google.com } else if (if_name == "slave" && idx < slavePorts.size()) { 888948SN/A // the slave port index translates directly to the vector position 898948SN/A return *slavePorts[idx]; 908922SN/A } else { 9113892Sgabeblack@google.com return ClockedObject::getPort(if_name, idx); 923489SN/A } 932640SN/A} 942640SN/A 959547SN/Avoid 9610719SMarco.Balboni@ARM.comBaseXBar::calcPacketTiming(PacketPtr pkt, Tick header_delay) 972497SN/A{ 9810405Sandreas.hansson@arm.com // the crossbar will be called at a time that is not necessarily 999547SN/A // coinciding with its own clock, so start by determining how long 1009547SN/A // until the next clock edge (could be zero) 1019648SN/A Tick offset = clockEdge() - curTick(); 1025354SN/A 10310719SMarco.Balboni@ARM.com // the header delay depends on the path through the crossbar, and 10410719SMarco.Balboni@ARM.com // we therefore rely on the caller to provide the actual 10510719SMarco.Balboni@ARM.com // value 10610719SMarco.Balboni@ARM.com pkt->headerDelay += offset + header_delay; 1073210SN/A 10810719SMarco.Balboni@ARM.com // note that we add the header delay to the existing value, and 10910719SMarco.Balboni@ARM.com // align it to the crossbar clock 1109549SN/A 11110719SMarco.Balboni@ARM.com // do a quick sanity check to ensure the timings are not being 11210719SMarco.Balboni@ARM.com // ignored, note that this specific value may cause problems for 11310719SMarco.Balboni@ARM.com // slower interconnects 11410719SMarco.Balboni@ARM.com panic_if(pkt->headerDelay > SimClock::Int::us, 11510719SMarco.Balboni@ARM.com "Encountered header delay exceeding 1 us\n"); 1163218SN/A 11710719SMarco.Balboni@ARM.com if (pkt->hasData()) { 11810719SMarco.Balboni@ARM.com // the payloadDelay takes into account the relative time to 11910719SMarco.Balboni@ARM.com // deliver the payload of the packet, after the header delay, 12010719SMarco.Balboni@ARM.com // we take the maximum since the payload delay could already 12110719SMarco.Balboni@ARM.com // be longer than what this parcitular crossbar enforces. 12210719SMarco.Balboni@ARM.com pkt->payloadDelay = std::max<Tick>(pkt->payloadDelay, 12310719SMarco.Balboni@ARM.com divCeil(pkt->getSize(), width) * 12410719SMarco.Balboni@ARM.com clockPeriod()); 12510719SMarco.Balboni@ARM.com } 12610719SMarco.Balboni@ARM.com 12710719SMarco.Balboni@ARM.com // the payload delay is not paying for the clock offset as that is 12810719SMarco.Balboni@ARM.com // already done using the header delay, and the payload delay is 12910719SMarco.Balboni@ARM.com // also used to determine how long the crossbar layer is busy and 13010719SMarco.Balboni@ARM.com // thus regulates throughput 1315354SN/A} 1325354SN/A 1339715SN/Atemplate <typename SrcType, typename DstType> 13413808Sgabeblack@google.comBaseXBar::Layer<SrcType, DstType>::Layer(DstType& _port, BaseXBar& _xbar, 1359715SN/A const std::string& _name) : 13610913Sandreas.sandberg@arm.com port(_port), xbar(_xbar), _name(_name), state(IDLE), 13712084Sspwilson2@wisc.edu waitingForPeer(NULL), releaseEvent([this]{ releaseLayer(); }, name()) 1389092SN/A{ 1399092SN/A} 1409092SN/A 1419715SN/Atemplate <typename SrcType, typename DstType> 14213808Sgabeblack@google.comvoid BaseXBar::Layer<SrcType, DstType>::occupyLayer(Tick until) 1435354SN/A{ 14410405Sandreas.hansson@arm.com // ensure the state is busy at this point, as the layer should 1459612SN/A // transition from idle as soon as it has decided to forward the 1469612SN/A // packet to prevent any follow-on calls to sendTiming seeing an 14710405Sandreas.hansson@arm.com // unoccupied layer 1489612SN/A assert(state == BUSY); 1495354SN/A 15010405Sandreas.hansson@arm.com // until should never be 0 as express snoops never occupy the layer 1519091SN/A assert(until != 0); 15210405Sandreas.hansson@arm.com xbar.schedule(releaseEvent, until); 1539091SN/A 1549712SN/A // account for the occupied ticks 1559712SN/A occupancy += until - curTick(); 1569712SN/A 15710405Sandreas.hansson@arm.com DPRINTF(BaseXBar, "The crossbar layer is now busy from tick %d to %d\n", 1589091SN/A curTick(), until); 1593244SN/A} 1603244SN/A 1619715SN/Atemplate <typename SrcType, typename DstType> 1628948SN/Abool 16313808Sgabeblack@google.comBaseXBar::Layer<SrcType, DstType>::tryTiming(SrcType* src_port) 1648948SN/A{ 1659716SN/A // if we are in the retry state, we will not see anything but the 1669716SN/A // retrying port (or in the case of the snoop ports the snoop 1679716SN/A // response port that mirrors the actual slave port) as we leave 1689716SN/A // this state again in zero time if the peer does not immediately 16910405Sandreas.hansson@arm.com // call the layer when receiving the retry 1709716SN/A 1719716SN/A // first we see if the layer is busy, next we check if the 1729716SN/A // destination port is already engaged in a transaction waiting 1739716SN/A // for a retry from the peer 1749716SN/A if (state == BUSY || waitingForPeer != NULL) { 1759716SN/A // the port should not be waiting already 1769716SN/A assert(std::find(waitingForLayer.begin(), waitingForLayer.end(), 1779716SN/A src_port) == waitingForLayer.end()); 1789716SN/A 1799612SN/A // put the port at the end of the retry list waiting for the 1809612SN/A // layer to be freed up (and in the case of a busy peer, for 18110405Sandreas.hansson@arm.com // that transaction to go through, and then the layer to free 1829612SN/A // up) 1839715SN/A waitingForLayer.push_back(src_port); 1849091SN/A return false; 1858948SN/A } 1869091SN/A 1879612SN/A state = BUSY; 1889611SN/A 1899091SN/A return true; 1908948SN/A} 1918948SN/A 1929715SN/Atemplate <typename SrcType, typename DstType> 1938975SN/Avoid 19413808Sgabeblack@google.comBaseXBar::Layer<SrcType, DstType>::succeededTiming(Tick busy_time) 1958948SN/A{ 1969612SN/A // we should have gone from idle or retry to busy in the tryTiming 1979612SN/A // test 1989091SN/A assert(state == BUSY); 1999091SN/A 20010405Sandreas.hansson@arm.com // occupy the layer accordingly 2019092SN/A occupyLayer(busy_time); 2029091SN/A} 2039091SN/A 2049715SN/Atemplate <typename SrcType, typename DstType> 2059091SN/Avoid 20613808Sgabeblack@google.comBaseXBar::Layer<SrcType, DstType>::failedTiming(SrcType* src_port, 2079715SN/A Tick busy_time) 2089091SN/A{ 2099612SN/A // ensure no one got in between and tried to send something to 2109612SN/A // this port 2119715SN/A assert(waitingForPeer == NULL); 2129091SN/A 2139612SN/A // if the source port is the current retrying one or not, we have 2149612SN/A // failed in forwarding and should track that we are now waiting 2159612SN/A // for the peer to send a retry 2169715SN/A waitingForPeer = src_port; 2179612SN/A 2189612SN/A // we should have gone from idle or retry to busy in the tryTiming 2199612SN/A // test 2209612SN/A assert(state == BUSY); 2219091SN/A 2229091SN/A // occupy the bus accordingly 2239092SN/A occupyLayer(busy_time); 2248948SN/A} 2258948SN/A 2269715SN/Atemplate <typename SrcType, typename DstType> 2278948SN/Avoid 22813808Sgabeblack@google.comBaseXBar::Layer<SrcType, DstType>::releaseLayer() 2292657SN/A{ 2308915SN/A // releasing the bus means we should now be idle 2319091SN/A assert(state == BUSY); 2329092SN/A assert(!releaseEvent.scheduled()); 2339091SN/A 2349091SN/A // update the state 2359091SN/A state = IDLE; 2363252SN/A 2379612SN/A // bus layer is now idle, so if someone is waiting we can retry 2389612SN/A if (!waitingForLayer.empty()) { 23910347SN/A // there is no point in sending a retry if someone is still 24010347SN/A // waiting for the peer 24110347SN/A if (waitingForPeer == NULL) 24210347SN/A retryWaiting(); 24310913Sandreas.sandberg@arm.com } else if (waitingForPeer == NULL && drainState() == DrainState::Draining) { 24410405Sandreas.hansson@arm.com DPRINTF(Drain, "Crossbar done draining, signaling drain manager\n"); 2459091SN/A //If we weren't able to drain before, do it now. 24610913Sandreas.sandberg@arm.com signalDrainDone(); 2473512SN/A } 2482657SN/A} 2492657SN/A 2509715SN/Atemplate <typename SrcType, typename DstType> 2518915SN/Avoid 25213808Sgabeblack@google.comBaseXBar::Layer<SrcType, DstType>::retryWaiting() 2538915SN/A{ 2549612SN/A // this should never be called with no one waiting 2559612SN/A assert(!waitingForLayer.empty()); 2568915SN/A 2579091SN/A // we always go to retrying from idle 2589091SN/A assert(state == IDLE); 2599091SN/A 2609611SN/A // update the state 2619091SN/A state = RETRY; 2628915SN/A 2639611SN/A // set the retrying port to the front of the retry list and pop it 2649611SN/A // off the list 26510347SN/A SrcType* retryingPort = waitingForLayer.front(); 2669612SN/A waitingForLayer.pop_front(); 2679611SN/A 2689612SN/A // tell the port to retry, which in some cases ends up calling the 26910405Sandreas.hansson@arm.com // layer again 27010713Sandreas.hansson@arm.com sendRetry(retryingPort); 2718915SN/A 27210405Sandreas.hansson@arm.com // If the layer is still in the retry state, sendTiming wasn't 27310719SMarco.Balboni@ARM.com // called in zero time (e.g. the cache does this when a writeback 27410719SMarco.Balboni@ARM.com // is squashed) 2759091SN/A if (state == RETRY) { 2769612SN/A // update the state to busy and reset the retrying port, we 2779612SN/A // have done our bit and sent the retry 2789091SN/A state = BUSY; 2799091SN/A 28010719SMarco.Balboni@ARM.com // occupy the crossbar layer until the next clock edge 28110719SMarco.Balboni@ARM.com occupyLayer(xbar.clockEdge()); 2828915SN/A } 2838915SN/A} 2848915SN/A 2859715SN/Atemplate <typename SrcType, typename DstType> 2868915SN/Avoid 28713808Sgabeblack@google.comBaseXBar::Layer<SrcType, DstType>::recvRetry() 2888915SN/A{ 2899612SN/A // we should never get a retry without having failed to forward 2909612SN/A // something to this port 2919715SN/A assert(waitingForPeer != NULL); 2928915SN/A 2939715SN/A // add the port where the failed packet originated to the front of 2949715SN/A // the waiting ports for the layer, this allows us to call retry 29510405Sandreas.hansson@arm.com // on the port immediately if the crossbar layer is idle 2969715SN/A waitingForLayer.push_front(waitingForPeer); 2979612SN/A 2989715SN/A // we are no longer waiting for the peer 2999715SN/A waitingForPeer = NULL; 3009612SN/A 30110405Sandreas.hansson@arm.com // if the layer is idle, retry this port straight away, if we 3029612SN/A // are busy, then simply let the port wait for its turn 3039091SN/A if (state == IDLE) { 3048915SN/A retryWaiting(); 3059612SN/A } else { 3069612SN/A assert(state == BUSY); 3078915SN/A } 3088915SN/A} 3098915SN/A 3109031SN/APortID 31112780Snikos.nikoleris@arm.comBaseXBar::findPort(AddrRange addr_range) 3122497SN/A{ 3139279SN/A // we should never see any address lookups before we've got the 3149279SN/A // ranges of all connected slave modules 3159279SN/A assert(gotAllAddrRanges); 3169279SN/A 3179279SN/A // Check the address map interval tree 31812780Snikos.nikoleris@arm.com auto i = portMap.contains(addr_range); 3197523SN/A if (i != portMap.end()) { 32012778Sgabeblack@google.com return i->second; 3214958SN/A } 3222846SN/A 3232846SN/A // Check if this matches the default range 3247523SN/A if (useDefaultRange) { 32512780Snikos.nikoleris@arm.com if (addr_range.isSubset(defaultRange)) { 32612780Snikos.nikoleris@arm.com DPRINTF(AddrRanges, " found addr %s on default\n", 32712780Snikos.nikoleris@arm.com addr_range.to_string()); 3289279SN/A return defaultPortID; 3292846SN/A } 3309031SN/A } else if (defaultPortID != InvalidPortID) { 33112780Snikos.nikoleris@arm.com DPRINTF(AddrRanges, "Unable to find destination for %s, " 33212780Snikos.nikoleris@arm.com "will use default port\n", addr_range.to_string()); 3339031SN/A return defaultPortID; 3342846SN/A } 3352846SN/A 3368849SN/A // we should use the range for the default port and it did not 3378849SN/A // match, or the default port is not set 33812780Snikos.nikoleris@arm.com fatal("Unable to find destination for %s on %s\n", addr_range.to_string(), 3398849SN/A name()); 3403074SN/A} 3413074SN/A 34210405Sandreas.hansson@arm.com/** Function called by the port when the crossbar is receiving a range change.*/ 3432497SN/Avoid 34410405Sandreas.hansson@arm.comBaseXBar::recvRangeChange(PortID master_port_id) 3452497SN/A{ 34610405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "Received range change from slave port %s\n", 34714192Sgabeblack@google.com masterPorts[master_port_id]->getPeer()); 3489407SN/A 3499279SN/A // remember that we got a range from this master port and thus the 3509279SN/A // connected slave module 3519279SN/A gotAddrRanges[master_port_id] = true; 3522846SN/A 3539279SN/A // update the global flag 3549279SN/A if (!gotAllAddrRanges) { 3559279SN/A // take a logical AND of all the ports and see if we got 3569279SN/A // ranges from everyone 3579279SN/A gotAllAddrRanges = true; 3589279SN/A std::vector<bool>::const_iterator r = gotAddrRanges.begin(); 3599279SN/A while (gotAllAddrRanges && r != gotAddrRanges.end()) { 3609279SN/A gotAllAddrRanges &= *r++; 3619279SN/A } 3629407SN/A if (gotAllAddrRanges) 36310405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "Got address ranges from all slaves\n"); 3649279SN/A } 3652534SN/A 3669279SN/A // note that we could get the range from the default port at any 3679279SN/A // point in time, and we cannot assume that the default range is 3689279SN/A // set before the other ones are, so we do additional checks once 3699279SN/A // all ranges are provided 3709032SN/A if (master_port_id == defaultPortID) { 3719279SN/A // only update if we are indeed checking ranges for the 3729279SN/A // default port since the port might not have a valid range 3739279SN/A // otherwise 3747523SN/A if (useDefaultRange) { 3759279SN/A AddrRangeList ranges = masterPorts[master_port_id]->getAddrRanges(); 3769279SN/A 3779279SN/A if (ranges.size() != 1) 37810405Sandreas.hansson@arm.com fatal("Crossbar %s may only have a single default range", 3799279SN/A name()); 3809279SN/A 3819279SN/A defaultRange = ranges.front(); 3829279SN/A } 3839279SN/A } else { 3849279SN/A // the ports are allowed to update their address ranges 3859279SN/A // dynamically, so remove any existing entries 3869279SN/A if (gotAddrRanges[master_port_id]) { 38710405Sandreas.hansson@arm.com for (auto p = portMap.begin(); p != portMap.end(); ) { 3889279SN/A if (p->second == master_port_id) 3899279SN/A // erasing invalidates the iterator, so advance it 3909279SN/A // before the deletion takes place 3919279SN/A portMap.erase(p++); 3929279SN/A else 3939279SN/A p++; 3943489SN/A } 3952846SN/A } 3962565SN/A 3979279SN/A AddrRangeList ranges = masterPorts[master_port_id]->getAddrRanges(); 3982497SN/A 39910405Sandreas.hansson@arm.com for (const auto& r: ranges) { 40010405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "Adding range %s for id %d\n", 40110405Sandreas.hansson@arm.com r.to_string(), master_port_id); 40210405Sandreas.hansson@arm.com if (portMap.insert(r, master_port_id) == portMap.end()) { 40312776Snikos.nikoleris@arm.com PortID conflict_id = portMap.intersects(r)->second; 40412776Snikos.nikoleris@arm.com fatal("%s has two ports responding within range " 40512776Snikos.nikoleris@arm.com "%s:\n\t%s\n\t%s\n", 4069032SN/A name(), 40710414SCurtis.Dunham@arm.com r.to_string(), 40814192Sgabeblack@google.com masterPorts[master_port_id]->getPeer(), 40914192Sgabeblack@google.com masterPorts[conflict_id]->getPeer()); 4105490SN/A } 4112846SN/A } 4122565SN/A } 4132568SN/A 4149279SN/A // if we have received ranges from all our neighbouring slave 4159279SN/A // modules, go ahead and tell our connected master modules in 4169279SN/A // turn, this effectively assumes a tree structure of the system 4179279SN/A if (gotAllAddrRanges) { 41810405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "Aggregating address ranges\n"); 41910405Sandreas.hansson@arm.com xbarRanges.clear(); 4209564SN/A 4219564SN/A // start out with the default range 4229564SN/A if (useDefaultRange) { 4239564SN/A if (!gotAddrRanges[defaultPortID]) 42410405Sandreas.hansson@arm.com fatal("Crossbar %s uses default range, but none provided", 4259564SN/A name()); 4269564SN/A 42710405Sandreas.hansson@arm.com xbarRanges.push_back(defaultRange); 42810405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "-- Adding default %s\n", 4299564SN/A defaultRange.to_string()); 4309564SN/A } 4319564SN/A 4329564SN/A // merge all interleaved ranges and add any range that is not 4339564SN/A // a subset of the default range 4349564SN/A std::vector<AddrRange> intlv_ranges; 43510405Sandreas.hansson@arm.com for (const auto& r: portMap) { 4369564SN/A // if the range is interleaved then save it for now 43710405Sandreas.hansson@arm.com if (r.first.interleaved()) { 4389564SN/A // if we already got interleaved ranges that are not 4399564SN/A // part of the same range, then first do a merge 4409564SN/A // before we add the new one 4419564SN/A if (!intlv_ranges.empty() && 44210405Sandreas.hansson@arm.com !intlv_ranges.back().mergesWith(r.first)) { 44310405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "-- Merging range from %d ranges\n", 4449564SN/A intlv_ranges.size()); 4459564SN/A AddrRange merged_range(intlv_ranges); 4469564SN/A // next decide if we keep the merged range or not 4479564SN/A if (!(useDefaultRange && 4489564SN/A merged_range.isSubset(defaultRange))) { 44910405Sandreas.hansson@arm.com xbarRanges.push_back(merged_range); 45010405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "-- Adding merged range %s\n", 4519564SN/A merged_range.to_string()); 4529564SN/A } 4539564SN/A intlv_ranges.clear(); 4549564SN/A } 45510405Sandreas.hansson@arm.com intlv_ranges.push_back(r.first); 4569564SN/A } else { 4579564SN/A // keep the current range if not a subset of the default 4589564SN/A if (!(useDefaultRange && 45910405Sandreas.hansson@arm.com r.first.isSubset(defaultRange))) { 46010405Sandreas.hansson@arm.com xbarRanges.push_back(r.first); 46110405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "-- Adding range %s\n", 46210405Sandreas.hansson@arm.com r.first.to_string()); 4639564SN/A } 4649564SN/A } 4659564SN/A } 4669564SN/A 4679564SN/A // if there is still interleaved ranges waiting to be merged, 4689564SN/A // go ahead and do it 4699564SN/A if (!intlv_ranges.empty()) { 47010405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "-- Merging range from %d ranges\n", 4719564SN/A intlv_ranges.size()); 4729564SN/A AddrRange merged_range(intlv_ranges); 4739564SN/A if (!(useDefaultRange && merged_range.isSubset(defaultRange))) { 47410405Sandreas.hansson@arm.com xbarRanges.push_back(merged_range); 47510405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "-- Adding merged range %s\n", 4769564SN/A merged_range.to_string()); 4779564SN/A } 4789564SN/A } 4799564SN/A 48012776Snikos.nikoleris@arm.com // also check that no range partially intersects with the 4819279SN/A // default range, this has to be done after all ranges are set 4829279SN/A // as there are no guarantees for when the default range is 4839279SN/A // update with respect to the other ones 4849279SN/A if (useDefaultRange) { 48510405Sandreas.hansson@arm.com for (const auto& r: xbarRanges) { 4869564SN/A // see if the new range is partially 4879564SN/A // overlapping the default range 48810405Sandreas.hansson@arm.com if (r.intersects(defaultRange) && 48910405Sandreas.hansson@arm.com !r.isSubset(defaultRange)) 4909564SN/A fatal("Range %s intersects the " \ 4919564SN/A "default range of %s but is not a " \ 49210405Sandreas.hansson@arm.com "subset\n", r.to_string(), name()); 4939279SN/A } 4949279SN/A } 4959279SN/A 4969279SN/A // tell all our neighbouring master ports that our address 4979279SN/A // ranges have changed 49810405Sandreas.hansson@arm.com for (const auto& s: slavePorts) 49910405Sandreas.hansson@arm.com s->sendRangeChange(); 5009279SN/A } 5012497SN/A} 5022497SN/A 5038711SN/AAddrRangeList 50410405Sandreas.hansson@arm.comBaseXBar::getAddrRanges() const 5052497SN/A{ 5069279SN/A // we should never be asked without first having sent a range 5079279SN/A // change, and the latter is only done once we have all the ranges 5089279SN/A // of the connected devices 5099279SN/A assert(gotAllAddrRanges); 5102568SN/A 5119407SN/A // at the moment, this never happens, as there are no cycles in 51210405Sandreas.hansson@arm.com // the range queries and no devices on the master side of a crossbar 5139407SN/A // (CPU, cache, bridge etc) actually care about the ranges of the 5149407SN/A // ports they are connected to 5159407SN/A 51610405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "Received address range request\n"); 5172846SN/A 51810405Sandreas.hansson@arm.com return xbarRanges; 5198711SN/A} 5208711SN/A 5219712SN/Avoid 52210405Sandreas.hansson@arm.comBaseXBar::regStats() 5239712SN/A{ 52411522Sstephan.diestelhorst@arm.com ClockedObject::regStats(); 52511522Sstephan.diestelhorst@arm.com 5269712SN/A using namespace Stats; 5279712SN/A 5289712SN/A transDist 5299712SN/A .init(MemCmd::NUM_MEM_CMDS) 5309712SN/A .name(name() + ".trans_dist") 5319712SN/A .desc("Transaction distribution") 5329712SN/A .flags(nozero); 5339712SN/A 5349712SN/A // get the string representation of the commands 5359712SN/A for (int i = 0; i < MemCmd::NUM_MEM_CMDS; i++) { 5369712SN/A MemCmd cmd(i); 5379712SN/A const std::string &cstr = cmd.toString(); 5389712SN/A transDist.subname(i, cstr); 5399712SN/A } 5409712SN/A 5419712SN/A pktCount 5429712SN/A .init(slavePorts.size(), masterPorts.size()) 5439712SN/A .name(name() + ".pkt_count") 5449712SN/A .desc("Packet count per connected master and slave (bytes)") 5459712SN/A .flags(total | nozero | nonan); 5469712SN/A 54710405Sandreas.hansson@arm.com pktSize 5489712SN/A .init(slavePorts.size(), masterPorts.size()) 54910405Sandreas.hansson@arm.com .name(name() + ".pkt_size") 5509712SN/A .desc("Cumulative packet size per connected master and slave (bytes)") 5519712SN/A .flags(total | nozero | nonan); 5529712SN/A 5539712SN/A // both the packet count and total size are two-dimensional 5549712SN/A // vectors, indexed by slave port id and master port id, thus the 5559712SN/A // neighbouring master and slave, they do not differentiate what 5569712SN/A // came from the master and was forwarded to the slave (requests 5579712SN/A // and snoop responses) and what came from the slave and was 5589712SN/A // forwarded to the master (responses and snoop requests) 5599712SN/A for (int i = 0; i < slavePorts.size(); i++) { 56014192Sgabeblack@google.com pktCount.subname(i, slavePorts[i]->getPeer().name()); 56114192Sgabeblack@google.com pktSize.subname(i, slavePorts[i]->getPeer().name()); 5629712SN/A for (int j = 0; j < masterPorts.size(); j++) { 56314192Sgabeblack@google.com pktCount.ysubname(j, masterPorts[j]->getPeer().name()); 56414192Sgabeblack@google.com pktSize.ysubname(j, masterPorts[j]->getPeer().name()); 5659712SN/A } 5669712SN/A } 5679712SN/A} 5689712SN/A 5699715SN/Atemplate <typename SrcType, typename DstType> 57010913Sandreas.sandberg@arm.comDrainState 57113808Sgabeblack@google.comBaseXBar::Layer<SrcType, DstType>::drain() 5723470SN/A{ 5733470SN/A //We should check that we're not "doing" anything, and that noone is 5743470SN/A //waiting. We might be idle but have someone waiting if the device we 5753470SN/A //contacted for a retry didn't actually retry. 5769612SN/A if (state != IDLE) { 57710405Sandreas.hansson@arm.com DPRINTF(Drain, "Crossbar not drained\n"); 57810913Sandreas.sandberg@arm.com return DrainState::Draining; 57910913Sandreas.sandberg@arm.com } else { 58010913Sandreas.sandberg@arm.com return DrainState::Drained; 5813470SN/A } 5823470SN/A} 5839093SN/A 5849715SN/Atemplate <typename SrcType, typename DstType> 5859712SN/Avoid 58613808Sgabeblack@google.comBaseXBar::Layer<SrcType, DstType>::regStats() 5879712SN/A{ 5889712SN/A using namespace Stats; 5899712SN/A 5909712SN/A occupancy 5919712SN/A .name(name() + ".occupancy") 5929712SN/A .desc("Layer occupancy (ticks)") 5939712SN/A .flags(nozero); 5949712SN/A 5959712SN/A utilization 5969712SN/A .name(name() + ".utilization") 5979712SN/A .desc("Layer utilization (%)") 5989712SN/A .precision(1) 5999712SN/A .flags(nozero); 6009712SN/A 6019712SN/A utilization = 100 * occupancy / simTicks; 6029712SN/A} 6039712SN/A 6049093SN/A/** 60510405Sandreas.hansson@arm.com * Crossbar layer template instantiations. Could be removed with _impl.hh 6069093SN/A * file, but since there are only two given options (MasterPort and 6079093SN/A * SlavePort) it seems a bit excessive at this point. 6089093SN/A */ 60913808Sgabeblack@google.comtemplate class BaseXBar::Layer<SlavePort, MasterPort>; 61013808Sgabeblack@google.comtemplate class BaseXBar::Layer<MasterPort, SlavePort>; 611