xbar.cc revision 10913
12497SN/A/* 210713Sandreas.hansson@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" 539152SN/A#include "debug/Drain.hh" 5410405Sandreas.hansson@arm.com#include "debug/XBar.hh" 5510405Sandreas.hansson@arm.com#include "mem/xbar.hh" 562497SN/A 5710405Sandreas.hansson@arm.comBaseXBar::BaseXBar(const BaseXBarParams *p) 589157SN/A : MemObject(p), 5910719SMarco.Balboni@ARM.com frontendLatency(p->frontend_latency), 6010719SMarco.Balboni@ARM.com forwardLatency(p->forward_latency), 6110719SMarco.Balboni@ARM.com responseLatency(p->response_latency), 6210719SMarco.Balboni@ARM.com width(p->width), 639279SN/A gotAddrRanges(p->port_default_connection_count + 649279SN/A p->port_master_connection_count, false), 659279SN/A gotAllAddrRanges(false), defaultPortID(InvalidPortID), 669814SN/A useDefaultRange(p->use_default_range) 679240SN/A{} 688851SN/A 6910405Sandreas.hansson@arm.comBaseXBar::~BaseXBar() 709036SN/A{ 7110405Sandreas.hansson@arm.com for (auto m: masterPorts) 7210405Sandreas.hansson@arm.com delete m; 738851SN/A 7410405Sandreas.hansson@arm.com for (auto s: slavePorts) 7510405Sandreas.hansson@arm.com delete s; 767523SN/A} 777523SN/A 789278SN/Avoid 7910405Sandreas.hansson@arm.comBaseXBar::init() 809278SN/A{ 819278SN/A} 829278SN/A 839294SN/ABaseMasterPort & 8410405Sandreas.hansson@arm.comBaseXBar::getMasterPort(const std::string &if_name, PortID idx) 852640SN/A{ 868948SN/A if (if_name == "master" && idx < masterPorts.size()) { 878948SN/A // the master port index translates directly to the vector position 888922SN/A return *masterPorts[idx]; 898851SN/A } else if (if_name == "default") { 909031SN/A return *masterPorts[defaultPortID]; 918715SN/A } else { 928922SN/A return MemObject::getMasterPort(if_name, idx); 938922SN/A } 948922SN/A} 958922SN/A 969294SN/ABaseSlavePort & 9710405Sandreas.hansson@arm.comBaseXBar::getSlavePort(const std::string &if_name, PortID idx) 988922SN/A{ 998948SN/A if (if_name == "slave" && idx < slavePorts.size()) { 1008948SN/A // the slave port index translates directly to the vector position 1018948SN/A return *slavePorts[idx]; 1028922SN/A } else { 1038922SN/A return MemObject::getSlavePort(if_name, idx); 1043489SN/A } 1052640SN/A} 1062640SN/A 1079547SN/Avoid 10810719SMarco.Balboni@ARM.comBaseXBar::calcPacketTiming(PacketPtr pkt, Tick header_delay) 1092497SN/A{ 11010405Sandreas.hansson@arm.com // the crossbar will be called at a time that is not necessarily 1119547SN/A // coinciding with its own clock, so start by determining how long 1129547SN/A // until the next clock edge (could be zero) 1139648SN/A Tick offset = clockEdge() - curTick(); 1145354SN/A 11510719SMarco.Balboni@ARM.com // the header delay depends on the path through the crossbar, and 11610719SMarco.Balboni@ARM.com // we therefore rely on the caller to provide the actual 11710719SMarco.Balboni@ARM.com // value 11810719SMarco.Balboni@ARM.com pkt->headerDelay += offset + header_delay; 1193210SN/A 12010719SMarco.Balboni@ARM.com // note that we add the header delay to the existing value, and 12110719SMarco.Balboni@ARM.com // align it to the crossbar clock 1229549SN/A 12310719SMarco.Balboni@ARM.com // do a quick sanity check to ensure the timings are not being 12410719SMarco.Balboni@ARM.com // ignored, note that this specific value may cause problems for 12510719SMarco.Balboni@ARM.com // slower interconnects 12610719SMarco.Balboni@ARM.com panic_if(pkt->headerDelay > SimClock::Int::us, 12710719SMarco.Balboni@ARM.com "Encountered header delay exceeding 1 us\n"); 1283218SN/A 12910719SMarco.Balboni@ARM.com if (pkt->hasData()) { 13010719SMarco.Balboni@ARM.com // the payloadDelay takes into account the relative time to 13110719SMarco.Balboni@ARM.com // deliver the payload of the packet, after the header delay, 13210719SMarco.Balboni@ARM.com // we take the maximum since the payload delay could already 13310719SMarco.Balboni@ARM.com // be longer than what this parcitular crossbar enforces. 13410719SMarco.Balboni@ARM.com pkt->payloadDelay = std::max<Tick>(pkt->payloadDelay, 13510719SMarco.Balboni@ARM.com divCeil(pkt->getSize(), width) * 13610719SMarco.Balboni@ARM.com clockPeriod()); 13710719SMarco.Balboni@ARM.com } 13810719SMarco.Balboni@ARM.com 13910719SMarco.Balboni@ARM.com // the payload delay is not paying for the clock offset as that is 14010719SMarco.Balboni@ARM.com // already done using the header delay, and the payload delay is 14110719SMarco.Balboni@ARM.com // also used to determine how long the crossbar layer is busy and 14210719SMarco.Balboni@ARM.com // thus regulates throughput 1435354SN/A} 1445354SN/A 1459715SN/Atemplate <typename SrcType, typename DstType> 14610405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::Layer(DstType& _port, BaseXBar& _xbar, 1479715SN/A const std::string& _name) : 14810913Sandreas.sandberg@arm.com port(_port), xbar(_xbar), _name(_name), state(IDLE), 14910347SN/A waitingForPeer(NULL), releaseEvent(this) 1509092SN/A{ 1519092SN/A} 1529092SN/A 1539715SN/Atemplate <typename SrcType, typename DstType> 15410405Sandreas.hansson@arm.comvoid BaseXBar::Layer<SrcType,DstType>::occupyLayer(Tick until) 1555354SN/A{ 15610405Sandreas.hansson@arm.com // ensure the state is busy at this point, as the layer should 1579612SN/A // transition from idle as soon as it has decided to forward the 1589612SN/A // packet to prevent any follow-on calls to sendTiming seeing an 15910405Sandreas.hansson@arm.com // unoccupied layer 1609612SN/A assert(state == BUSY); 1615354SN/A 16210405Sandreas.hansson@arm.com // until should never be 0 as express snoops never occupy the layer 1639091SN/A assert(until != 0); 16410405Sandreas.hansson@arm.com xbar.schedule(releaseEvent, until); 1659091SN/A 1669712SN/A // account for the occupied ticks 1679712SN/A occupancy += until - curTick(); 1689712SN/A 16910405Sandreas.hansson@arm.com DPRINTF(BaseXBar, "The crossbar layer is now busy from tick %d to %d\n", 1709091SN/A curTick(), until); 1713244SN/A} 1723244SN/A 1739715SN/Atemplate <typename SrcType, typename DstType> 1748948SN/Abool 17510405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::tryTiming(SrcType* src_port) 1768948SN/A{ 1779716SN/A // if we are in the retry state, we will not see anything but the 1789716SN/A // retrying port (or in the case of the snoop ports the snoop 1799716SN/A // response port that mirrors the actual slave port) as we leave 1809716SN/A // this state again in zero time if the peer does not immediately 18110405Sandreas.hansson@arm.com // call the layer when receiving the retry 1829716SN/A 1839716SN/A // first we see if the layer is busy, next we check if the 1849716SN/A // destination port is already engaged in a transaction waiting 1859716SN/A // for a retry from the peer 1869716SN/A if (state == BUSY || waitingForPeer != NULL) { 1879716SN/A // the port should not be waiting already 1889716SN/A assert(std::find(waitingForLayer.begin(), waitingForLayer.end(), 1899716SN/A src_port) == waitingForLayer.end()); 1909716SN/A 1919612SN/A // put the port at the end of the retry list waiting for the 1929612SN/A // layer to be freed up (and in the case of a busy peer, for 19310405Sandreas.hansson@arm.com // that transaction to go through, and then the layer to free 1949612SN/A // up) 1959715SN/A waitingForLayer.push_back(src_port); 1969091SN/A return false; 1978948SN/A } 1989091SN/A 1999612SN/A state = BUSY; 2009611SN/A 2019091SN/A return true; 2028948SN/A} 2038948SN/A 2049715SN/Atemplate <typename SrcType, typename DstType> 2058975SN/Avoid 20610405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::succeededTiming(Tick busy_time) 2078948SN/A{ 2089612SN/A // we should have gone from idle or retry to busy in the tryTiming 2099612SN/A // test 2109091SN/A assert(state == BUSY); 2119091SN/A 21210405Sandreas.hansson@arm.com // occupy the layer accordingly 2139092SN/A occupyLayer(busy_time); 2149091SN/A} 2159091SN/A 2169715SN/Atemplate <typename SrcType, typename DstType> 2179091SN/Avoid 21810405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::failedTiming(SrcType* src_port, 2199715SN/A Tick busy_time) 2209091SN/A{ 2219612SN/A // ensure no one got in between and tried to send something to 2229612SN/A // this port 2239715SN/A assert(waitingForPeer == NULL); 2249091SN/A 2259612SN/A // if the source port is the current retrying one or not, we have 2269612SN/A // failed in forwarding and should track that we are now waiting 2279612SN/A // for the peer to send a retry 2289715SN/A waitingForPeer = src_port; 2299612SN/A 2309612SN/A // we should have gone from idle or retry to busy in the tryTiming 2319612SN/A // test 2329612SN/A assert(state == BUSY); 2339091SN/A 2349091SN/A // occupy the bus accordingly 2359092SN/A occupyLayer(busy_time); 2368948SN/A} 2378948SN/A 2389715SN/Atemplate <typename SrcType, typename DstType> 2398948SN/Avoid 24010405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::releaseLayer() 2412657SN/A{ 2428915SN/A // releasing the bus means we should now be idle 2439091SN/A assert(state == BUSY); 2449092SN/A assert(!releaseEvent.scheduled()); 2459091SN/A 2469091SN/A // update the state 2479091SN/A state = IDLE; 2483252SN/A 2499612SN/A // bus layer is now idle, so if someone is waiting we can retry 2509612SN/A if (!waitingForLayer.empty()) { 25110347SN/A // there is no point in sending a retry if someone is still 25210347SN/A // waiting for the peer 25310347SN/A if (waitingForPeer == NULL) 25410347SN/A retryWaiting(); 25510913Sandreas.sandberg@arm.com } else if (waitingForPeer == NULL && drainState() == DrainState::Draining) { 25610405Sandreas.hansson@arm.com DPRINTF(Drain, "Crossbar done draining, signaling drain manager\n"); 2579091SN/A //If we weren't able to drain before, do it now. 25810913Sandreas.sandberg@arm.com signalDrainDone(); 2593512SN/A } 2602657SN/A} 2612657SN/A 2629715SN/Atemplate <typename SrcType, typename DstType> 2638915SN/Avoid 26410405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::retryWaiting() 2658915SN/A{ 2669612SN/A // this should never be called with no one waiting 2679612SN/A assert(!waitingForLayer.empty()); 2688915SN/A 2699091SN/A // we always go to retrying from idle 2709091SN/A assert(state == IDLE); 2719091SN/A 2729611SN/A // update the state 2739091SN/A state = RETRY; 2748915SN/A 2759611SN/A // set the retrying port to the front of the retry list and pop it 2769611SN/A // off the list 27710347SN/A SrcType* retryingPort = waitingForLayer.front(); 2789612SN/A waitingForLayer.pop_front(); 2799611SN/A 2809612SN/A // tell the port to retry, which in some cases ends up calling the 28110405Sandreas.hansson@arm.com // layer again 28210713Sandreas.hansson@arm.com sendRetry(retryingPort); 2838915SN/A 28410405Sandreas.hansson@arm.com // If the layer is still in the retry state, sendTiming wasn't 28510719SMarco.Balboni@ARM.com // called in zero time (e.g. the cache does this when a writeback 28610719SMarco.Balboni@ARM.com // is squashed) 2879091SN/A if (state == RETRY) { 2889612SN/A // update the state to busy and reset the retrying port, we 2899612SN/A // have done our bit and sent the retry 2909091SN/A state = BUSY; 2919091SN/A 29210719SMarco.Balboni@ARM.com // occupy the crossbar layer until the next clock edge 29310719SMarco.Balboni@ARM.com occupyLayer(xbar.clockEdge()); 2948915SN/A } 2958915SN/A} 2968915SN/A 2979715SN/Atemplate <typename SrcType, typename DstType> 2988915SN/Avoid 29910405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::recvRetry() 3008915SN/A{ 3019612SN/A // we should never get a retry without having failed to forward 3029612SN/A // something to this port 3039715SN/A assert(waitingForPeer != NULL); 3048915SN/A 3059715SN/A // add the port where the failed packet originated to the front of 3069715SN/A // the waiting ports for the layer, this allows us to call retry 30710405Sandreas.hansson@arm.com // on the port immediately if the crossbar layer is idle 3089715SN/A waitingForLayer.push_front(waitingForPeer); 3099612SN/A 3109715SN/A // we are no longer waiting for the peer 3119715SN/A waitingForPeer = NULL; 3129612SN/A 31310405Sandreas.hansson@arm.com // if the layer is idle, retry this port straight away, if we 3149612SN/A // are busy, then simply let the port wait for its turn 3159091SN/A if (state == IDLE) { 3168915SN/A retryWaiting(); 3179612SN/A } else { 3189612SN/A assert(state == BUSY); 3198915SN/A } 3208915SN/A} 3218915SN/A 3229031SN/APortID 32310405Sandreas.hansson@arm.comBaseXBar::findPort(Addr addr) 3242497SN/A{ 3259279SN/A // we should never see any address lookups before we've got the 3269279SN/A // ranges of all connected slave modules 3279279SN/A assert(gotAllAddrRanges); 3289279SN/A 3299279SN/A // Check the cache 3309031SN/A PortID dest_id = checkPortCache(addr); 3319031SN/A if (dest_id != InvalidPortID) 3327523SN/A return dest_id; 3337523SN/A 3349279SN/A // Check the address map interval tree 33510405Sandreas.hansson@arm.com auto i = portMap.find(addr); 3367523SN/A if (i != portMap.end()) { 3377523SN/A dest_id = i->second; 3389279SN/A updatePortCache(dest_id, i->first); 3397523SN/A return dest_id; 3404958SN/A } 3412846SN/A 3422846SN/A // Check if this matches the default range 3437523SN/A if (useDefaultRange) { 3449405SN/A if (defaultRange.contains(addr)) { 34510405Sandreas.hansson@arm.com DPRINTF(AddrRanges, " found addr %#llx on default\n", 3469279SN/A addr); 3479279SN/A return defaultPortID; 3482846SN/A } 3499031SN/A } else if (defaultPortID != InvalidPortID) { 35010405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "Unable to find destination for addr %#llx, " 3518849SN/A "will use default port\n", addr); 3529031SN/A return defaultPortID; 3532846SN/A } 3542846SN/A 3558849SN/A // we should use the range for the default port and it did not 3568849SN/A // match, or the default port is not set 35710405Sandreas.hansson@arm.com fatal("Unable to find destination for addr %#llx on %s\n", addr, 3588849SN/A name()); 3593074SN/A} 3603074SN/A 36110405Sandreas.hansson@arm.com/** Function called by the port when the crossbar is receiving a range change.*/ 3622497SN/Avoid 36310405Sandreas.hansson@arm.comBaseXBar::recvRangeChange(PortID master_port_id) 3642497SN/A{ 36510405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "Received range change from slave port %s\n", 3669407SN/A masterPorts[master_port_id]->getSlavePort().name()); 3679407SN/A 3689279SN/A // remember that we got a range from this master port and thus the 3699279SN/A // connected slave module 3709279SN/A gotAddrRanges[master_port_id] = true; 3712846SN/A 3729279SN/A // update the global flag 3739279SN/A if (!gotAllAddrRanges) { 3749279SN/A // take a logical AND of all the ports and see if we got 3759279SN/A // ranges from everyone 3769279SN/A gotAllAddrRanges = true; 3779279SN/A std::vector<bool>::const_iterator r = gotAddrRanges.begin(); 3789279SN/A while (gotAllAddrRanges && r != gotAddrRanges.end()) { 3799279SN/A gotAllAddrRanges &= *r++; 3809279SN/A } 3819407SN/A if (gotAllAddrRanges) 38210405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "Got address ranges from all slaves\n"); 3839279SN/A } 3842534SN/A 3859279SN/A // note that we could get the range from the default port at any 3869279SN/A // point in time, and we cannot assume that the default range is 3879279SN/A // set before the other ones are, so we do additional checks once 3889279SN/A // all ranges are provided 3899032SN/A if (master_port_id == defaultPortID) { 3909279SN/A // only update if we are indeed checking ranges for the 3919279SN/A // default port since the port might not have a valid range 3929279SN/A // otherwise 3937523SN/A if (useDefaultRange) { 3949279SN/A AddrRangeList ranges = masterPorts[master_port_id]->getAddrRanges(); 3959279SN/A 3969279SN/A if (ranges.size() != 1) 39710405Sandreas.hansson@arm.com fatal("Crossbar %s may only have a single default range", 3989279SN/A name()); 3999279SN/A 4009279SN/A defaultRange = ranges.front(); 4019279SN/A } 4029279SN/A } else { 4039279SN/A // the ports are allowed to update their address ranges 4049279SN/A // dynamically, so remove any existing entries 4059279SN/A if (gotAddrRanges[master_port_id]) { 40610405Sandreas.hansson@arm.com for (auto p = portMap.begin(); p != portMap.end(); ) { 4079279SN/A if (p->second == master_port_id) 4089279SN/A // erasing invalidates the iterator, so advance it 4099279SN/A // before the deletion takes place 4109279SN/A portMap.erase(p++); 4119279SN/A else 4129279SN/A p++; 4133489SN/A } 4142846SN/A } 4152565SN/A 4169279SN/A AddrRangeList ranges = masterPorts[master_port_id]->getAddrRanges(); 4172497SN/A 41810405Sandreas.hansson@arm.com for (const auto& r: ranges) { 41910405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "Adding range %s for id %d\n", 42010405Sandreas.hansson@arm.com r.to_string(), master_port_id); 42110405Sandreas.hansson@arm.com if (portMap.insert(r, master_port_id) == portMap.end()) { 42210405Sandreas.hansson@arm.com PortID conflict_id = portMap.find(r)->second; 42310414SCurtis.Dunham@arm.com fatal("%s has two ports responding within range %s:\n\t%s\n\t%s\n", 4249032SN/A name(), 42510414SCurtis.Dunham@arm.com r.to_string(), 4269032SN/A masterPorts[master_port_id]->getSlavePort().name(), 4278922SN/A masterPorts[conflict_id]->getSlavePort().name()); 4285490SN/A } 4292846SN/A } 4302565SN/A } 4312568SN/A 4329279SN/A // if we have received ranges from all our neighbouring slave 4339279SN/A // modules, go ahead and tell our connected master modules in 4349279SN/A // turn, this effectively assumes a tree structure of the system 4359279SN/A if (gotAllAddrRanges) { 43610405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "Aggregating address ranges\n"); 43710405Sandreas.hansson@arm.com xbarRanges.clear(); 4389564SN/A 4399564SN/A // start out with the default range 4409564SN/A if (useDefaultRange) { 4419564SN/A if (!gotAddrRanges[defaultPortID]) 44210405Sandreas.hansson@arm.com fatal("Crossbar %s uses default range, but none provided", 4439564SN/A name()); 4449564SN/A 44510405Sandreas.hansson@arm.com xbarRanges.push_back(defaultRange); 44610405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "-- Adding default %s\n", 4479564SN/A defaultRange.to_string()); 4489564SN/A } 4499564SN/A 4509564SN/A // merge all interleaved ranges and add any range that is not 4519564SN/A // a subset of the default range 4529564SN/A std::vector<AddrRange> intlv_ranges; 45310405Sandreas.hansson@arm.com for (const auto& r: portMap) { 4549564SN/A // if the range is interleaved then save it for now 45510405Sandreas.hansson@arm.com if (r.first.interleaved()) { 4569564SN/A // if we already got interleaved ranges that are not 4579564SN/A // part of the same range, then first do a merge 4589564SN/A // before we add the new one 4599564SN/A if (!intlv_ranges.empty() && 46010405Sandreas.hansson@arm.com !intlv_ranges.back().mergesWith(r.first)) { 46110405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "-- Merging range from %d ranges\n", 4629564SN/A intlv_ranges.size()); 4639564SN/A AddrRange merged_range(intlv_ranges); 4649564SN/A // next decide if we keep the merged range or not 4659564SN/A if (!(useDefaultRange && 4669564SN/A merged_range.isSubset(defaultRange))) { 46710405Sandreas.hansson@arm.com xbarRanges.push_back(merged_range); 46810405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "-- Adding merged range %s\n", 4699564SN/A merged_range.to_string()); 4709564SN/A } 4719564SN/A intlv_ranges.clear(); 4729564SN/A } 47310405Sandreas.hansson@arm.com intlv_ranges.push_back(r.first); 4749564SN/A } else { 4759564SN/A // keep the current range if not a subset of the default 4769564SN/A if (!(useDefaultRange && 47710405Sandreas.hansson@arm.com r.first.isSubset(defaultRange))) { 47810405Sandreas.hansson@arm.com xbarRanges.push_back(r.first); 47910405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "-- Adding range %s\n", 48010405Sandreas.hansson@arm.com r.first.to_string()); 4819564SN/A } 4829564SN/A } 4839564SN/A } 4849564SN/A 4859564SN/A // if there is still interleaved ranges waiting to be merged, 4869564SN/A // go ahead and do it 4879564SN/A if (!intlv_ranges.empty()) { 48810405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "-- Merging range from %d ranges\n", 4899564SN/A intlv_ranges.size()); 4909564SN/A AddrRange merged_range(intlv_ranges); 4919564SN/A if (!(useDefaultRange && merged_range.isSubset(defaultRange))) { 49210405Sandreas.hansson@arm.com xbarRanges.push_back(merged_range); 49310405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "-- Adding merged range %s\n", 4949564SN/A merged_range.to_string()); 4959564SN/A } 4969564SN/A } 4979564SN/A 4989279SN/A // also check that no range partially overlaps with the 4999279SN/A // default range, this has to be done after all ranges are set 5009279SN/A // as there are no guarantees for when the default range is 5019279SN/A // update with respect to the other ones 5029279SN/A if (useDefaultRange) { 50310405Sandreas.hansson@arm.com for (const auto& r: xbarRanges) { 5049564SN/A // see if the new range is partially 5059564SN/A // overlapping the default range 50610405Sandreas.hansson@arm.com if (r.intersects(defaultRange) && 50710405Sandreas.hansson@arm.com !r.isSubset(defaultRange)) 5089564SN/A fatal("Range %s intersects the " \ 5099564SN/A "default range of %s but is not a " \ 51010405Sandreas.hansson@arm.com "subset\n", r.to_string(), name()); 5119279SN/A } 5129279SN/A } 5139279SN/A 5149279SN/A // tell all our neighbouring master ports that our address 5159279SN/A // ranges have changed 51610405Sandreas.hansson@arm.com for (const auto& s: slavePorts) 51710405Sandreas.hansson@arm.com s->sendRangeChange(); 5189279SN/A } 5199279SN/A 5209279SN/A clearPortCache(); 5212497SN/A} 5222497SN/A 5238711SN/AAddrRangeList 52410405Sandreas.hansson@arm.comBaseXBar::getAddrRanges() const 5252497SN/A{ 5269279SN/A // we should never be asked without first having sent a range 5279279SN/A // change, and the latter is only done once we have all the ranges 5289279SN/A // of the connected devices 5299279SN/A assert(gotAllAddrRanges); 5302568SN/A 5319407SN/A // at the moment, this never happens, as there are no cycles in 53210405Sandreas.hansson@arm.com // the range queries and no devices on the master side of a crossbar 5339407SN/A // (CPU, cache, bridge etc) actually care about the ranges of the 5349407SN/A // ports they are connected to 5359407SN/A 53610405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "Received address range request\n"); 5372846SN/A 53810405Sandreas.hansson@arm.com return xbarRanges; 5398711SN/A} 5408711SN/A 5419712SN/Avoid 54210405Sandreas.hansson@arm.comBaseXBar::regStats() 5439712SN/A{ 5449712SN/A using namespace Stats; 5459712SN/A 5469712SN/A transDist 5479712SN/A .init(MemCmd::NUM_MEM_CMDS) 5489712SN/A .name(name() + ".trans_dist") 5499712SN/A .desc("Transaction distribution") 5509712SN/A .flags(nozero); 5519712SN/A 5529712SN/A // get the string representation of the commands 5539712SN/A for (int i = 0; i < MemCmd::NUM_MEM_CMDS; i++) { 5549712SN/A MemCmd cmd(i); 5559712SN/A const std::string &cstr = cmd.toString(); 5569712SN/A transDist.subname(i, cstr); 5579712SN/A } 5589712SN/A 5599712SN/A pktCount 5609712SN/A .init(slavePorts.size(), masterPorts.size()) 5619712SN/A .name(name() + ".pkt_count") 5629712SN/A .desc("Packet count per connected master and slave (bytes)") 5639712SN/A .flags(total | nozero | nonan); 5649712SN/A 56510405Sandreas.hansson@arm.com pktSize 5669712SN/A .init(slavePorts.size(), masterPorts.size()) 56710405Sandreas.hansson@arm.com .name(name() + ".pkt_size") 5689712SN/A .desc("Cumulative packet size per connected master and slave (bytes)") 5699712SN/A .flags(total | nozero | nonan); 5709712SN/A 5719712SN/A // both the packet count and total size are two-dimensional 5729712SN/A // vectors, indexed by slave port id and master port id, thus the 5739712SN/A // neighbouring master and slave, they do not differentiate what 5749712SN/A // came from the master and was forwarded to the slave (requests 5759712SN/A // and snoop responses) and what came from the slave and was 5769712SN/A // forwarded to the master (responses and snoop requests) 5779712SN/A for (int i = 0; i < slavePorts.size(); i++) { 5789712SN/A pktCount.subname(i, slavePorts[i]->getMasterPort().name()); 57910405Sandreas.hansson@arm.com pktSize.subname(i, slavePorts[i]->getMasterPort().name()); 5809712SN/A for (int j = 0; j < masterPorts.size(); j++) { 5819712SN/A pktCount.ysubname(j, masterPorts[j]->getSlavePort().name()); 58210405Sandreas.hansson@arm.com pktSize.ysubname(j, masterPorts[j]->getSlavePort().name()); 5839712SN/A } 5849712SN/A } 5859712SN/A} 5869712SN/A 5879715SN/Atemplate <typename SrcType, typename DstType> 58810913Sandreas.sandberg@arm.comDrainState 58910913Sandreas.sandberg@arm.comBaseXBar::Layer<SrcType,DstType>::drain() 5903470SN/A{ 5913470SN/A //We should check that we're not "doing" anything, and that noone is 5923470SN/A //waiting. We might be idle but have someone waiting if the device we 5933470SN/A //contacted for a retry didn't actually retry. 5949612SN/A if (state != IDLE) { 59510405Sandreas.hansson@arm.com DPRINTF(Drain, "Crossbar not drained\n"); 59610913Sandreas.sandberg@arm.com return DrainState::Draining; 59710913Sandreas.sandberg@arm.com } else { 59810913Sandreas.sandberg@arm.com return DrainState::Drained; 5993470SN/A } 6003470SN/A} 6019093SN/A 6029715SN/Atemplate <typename SrcType, typename DstType> 6039712SN/Avoid 60410405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::regStats() 6059712SN/A{ 6069712SN/A using namespace Stats; 6079712SN/A 6089712SN/A occupancy 6099712SN/A .name(name() + ".occupancy") 6109712SN/A .desc("Layer occupancy (ticks)") 6119712SN/A .flags(nozero); 6129712SN/A 6139712SN/A utilization 6149712SN/A .name(name() + ".utilization") 6159712SN/A .desc("Layer utilization (%)") 6169712SN/A .precision(1) 6179712SN/A .flags(nozero); 6189712SN/A 6199712SN/A utilization = 100 * occupancy / simTicks; 6209712SN/A} 6219712SN/A 6229093SN/A/** 62310405Sandreas.hansson@arm.com * Crossbar layer template instantiations. Could be removed with _impl.hh 6249093SN/A * file, but since there are only two given options (MasterPort and 6259093SN/A * SlavePort) it seems a bit excessive at this point. 6269093SN/A */ 62710405Sandreas.hansson@arm.comtemplate class BaseXBar::Layer<SlavePort,MasterPort>; 62810405Sandreas.hansson@arm.comtemplate class BaseXBar::Layer<MasterPort,SlavePort>; 629