xbar.cc revision 10719
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) : 14810405Sandreas.hansson@arm.com port(_port), xbar(_xbar), _name(_name), state(IDLE), drainManager(NULL), 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(); 2559710SN/A } else if (waitingForPeer == NULL && drainManager) { 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. 2589342SN/A drainManager->signalDrainDone(); 2593512SN/A // Clear the drain event once we're done with it. 2609342SN/A drainManager = NULL; 2613512SN/A } 2622657SN/A} 2632657SN/A 2649715SN/Atemplate <typename SrcType, typename DstType> 2658915SN/Avoid 26610405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::retryWaiting() 2678915SN/A{ 2689612SN/A // this should never be called with no one waiting 2699612SN/A assert(!waitingForLayer.empty()); 2708915SN/A 2719091SN/A // we always go to retrying from idle 2729091SN/A assert(state == IDLE); 2739091SN/A 2749611SN/A // update the state 2759091SN/A state = RETRY; 2768915SN/A 2779611SN/A // set the retrying port to the front of the retry list and pop it 2789611SN/A // off the list 27910347SN/A SrcType* retryingPort = waitingForLayer.front(); 2809612SN/A waitingForLayer.pop_front(); 2819611SN/A 2829612SN/A // tell the port to retry, which in some cases ends up calling the 28310405Sandreas.hansson@arm.com // layer again 28410713Sandreas.hansson@arm.com sendRetry(retryingPort); 2858915SN/A 28610405Sandreas.hansson@arm.com // If the layer is still in the retry state, sendTiming wasn't 28710719SMarco.Balboni@ARM.com // called in zero time (e.g. the cache does this when a writeback 28810719SMarco.Balboni@ARM.com // is squashed) 2899091SN/A if (state == RETRY) { 2909612SN/A // update the state to busy and reset the retrying port, we 2919612SN/A // have done our bit and sent the retry 2929091SN/A state = BUSY; 2939091SN/A 29410719SMarco.Balboni@ARM.com // occupy the crossbar layer until the next clock edge 29510719SMarco.Balboni@ARM.com occupyLayer(xbar.clockEdge()); 2968915SN/A } 2978915SN/A} 2988915SN/A 2999715SN/Atemplate <typename SrcType, typename DstType> 3008915SN/Avoid 30110405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::recvRetry() 3028915SN/A{ 3039612SN/A // we should never get a retry without having failed to forward 3049612SN/A // something to this port 3059715SN/A assert(waitingForPeer != NULL); 3068915SN/A 3079715SN/A // add the port where the failed packet originated to the front of 3089715SN/A // the waiting ports for the layer, this allows us to call retry 30910405Sandreas.hansson@arm.com // on the port immediately if the crossbar layer is idle 3109715SN/A waitingForLayer.push_front(waitingForPeer); 3119612SN/A 3129715SN/A // we are no longer waiting for the peer 3139715SN/A waitingForPeer = NULL; 3149612SN/A 31510405Sandreas.hansson@arm.com // if the layer is idle, retry this port straight away, if we 3169612SN/A // are busy, then simply let the port wait for its turn 3179091SN/A if (state == IDLE) { 3188915SN/A retryWaiting(); 3199612SN/A } else { 3209612SN/A assert(state == BUSY); 3218915SN/A } 3228915SN/A} 3238915SN/A 3249031SN/APortID 32510405Sandreas.hansson@arm.comBaseXBar::findPort(Addr addr) 3262497SN/A{ 3279279SN/A // we should never see any address lookups before we've got the 3289279SN/A // ranges of all connected slave modules 3299279SN/A assert(gotAllAddrRanges); 3309279SN/A 3319279SN/A // Check the cache 3329031SN/A PortID dest_id = checkPortCache(addr); 3339031SN/A if (dest_id != InvalidPortID) 3347523SN/A return dest_id; 3357523SN/A 3369279SN/A // Check the address map interval tree 33710405Sandreas.hansson@arm.com auto i = portMap.find(addr); 3387523SN/A if (i != portMap.end()) { 3397523SN/A dest_id = i->second; 3409279SN/A updatePortCache(dest_id, i->first); 3417523SN/A return dest_id; 3424958SN/A } 3432846SN/A 3442846SN/A // Check if this matches the default range 3457523SN/A if (useDefaultRange) { 3469405SN/A if (defaultRange.contains(addr)) { 34710405Sandreas.hansson@arm.com DPRINTF(AddrRanges, " found addr %#llx on default\n", 3489279SN/A addr); 3499279SN/A return defaultPortID; 3502846SN/A } 3519031SN/A } else if (defaultPortID != InvalidPortID) { 35210405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "Unable to find destination for addr %#llx, " 3538849SN/A "will use default port\n", addr); 3549031SN/A return defaultPortID; 3552846SN/A } 3562846SN/A 3578849SN/A // we should use the range for the default port and it did not 3588849SN/A // match, or the default port is not set 35910405Sandreas.hansson@arm.com fatal("Unable to find destination for addr %#llx on %s\n", addr, 3608849SN/A name()); 3613074SN/A} 3623074SN/A 36310405Sandreas.hansson@arm.com/** Function called by the port when the crossbar is receiving a range change.*/ 3642497SN/Avoid 36510405Sandreas.hansson@arm.comBaseXBar::recvRangeChange(PortID master_port_id) 3662497SN/A{ 36710405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "Received range change from slave port %s\n", 3689407SN/A masterPorts[master_port_id]->getSlavePort().name()); 3699407SN/A 3709279SN/A // remember that we got a range from this master port and thus the 3719279SN/A // connected slave module 3729279SN/A gotAddrRanges[master_port_id] = true; 3732846SN/A 3749279SN/A // update the global flag 3759279SN/A if (!gotAllAddrRanges) { 3769279SN/A // take a logical AND of all the ports and see if we got 3779279SN/A // ranges from everyone 3789279SN/A gotAllAddrRanges = true; 3799279SN/A std::vector<bool>::const_iterator r = gotAddrRanges.begin(); 3809279SN/A while (gotAllAddrRanges && r != gotAddrRanges.end()) { 3819279SN/A gotAllAddrRanges &= *r++; 3829279SN/A } 3839407SN/A if (gotAllAddrRanges) 38410405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "Got address ranges from all slaves\n"); 3859279SN/A } 3862534SN/A 3879279SN/A // note that we could get the range from the default port at any 3889279SN/A // point in time, and we cannot assume that the default range is 3899279SN/A // set before the other ones are, so we do additional checks once 3909279SN/A // all ranges are provided 3919032SN/A if (master_port_id == defaultPortID) { 3929279SN/A // only update if we are indeed checking ranges for the 3939279SN/A // default port since the port might not have a valid range 3949279SN/A // otherwise 3957523SN/A if (useDefaultRange) { 3969279SN/A AddrRangeList ranges = masterPorts[master_port_id]->getAddrRanges(); 3979279SN/A 3989279SN/A if (ranges.size() != 1) 39910405Sandreas.hansson@arm.com fatal("Crossbar %s may only have a single default range", 4009279SN/A name()); 4019279SN/A 4029279SN/A defaultRange = ranges.front(); 4039279SN/A } 4049279SN/A } else { 4059279SN/A // the ports are allowed to update their address ranges 4069279SN/A // dynamically, so remove any existing entries 4079279SN/A if (gotAddrRanges[master_port_id]) { 40810405Sandreas.hansson@arm.com for (auto p = portMap.begin(); p != portMap.end(); ) { 4099279SN/A if (p->second == master_port_id) 4109279SN/A // erasing invalidates the iterator, so advance it 4119279SN/A // before the deletion takes place 4129279SN/A portMap.erase(p++); 4139279SN/A else 4149279SN/A p++; 4153489SN/A } 4162846SN/A } 4172565SN/A 4189279SN/A AddrRangeList ranges = masterPorts[master_port_id]->getAddrRanges(); 4192497SN/A 42010405Sandreas.hansson@arm.com for (const auto& r: ranges) { 42110405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "Adding range %s for id %d\n", 42210405Sandreas.hansson@arm.com r.to_string(), master_port_id); 42310405Sandreas.hansson@arm.com if (portMap.insert(r, master_port_id) == portMap.end()) { 42410405Sandreas.hansson@arm.com PortID conflict_id = portMap.find(r)->second; 42510414SCurtis.Dunham@arm.com fatal("%s has two ports responding within range %s:\n\t%s\n\t%s\n", 4269032SN/A name(), 42710414SCurtis.Dunham@arm.com r.to_string(), 4289032SN/A masterPorts[master_port_id]->getSlavePort().name(), 4298922SN/A masterPorts[conflict_id]->getSlavePort().name()); 4305490SN/A } 4312846SN/A } 4322565SN/A } 4332568SN/A 4349279SN/A // if we have received ranges from all our neighbouring slave 4359279SN/A // modules, go ahead and tell our connected master modules in 4369279SN/A // turn, this effectively assumes a tree structure of the system 4379279SN/A if (gotAllAddrRanges) { 43810405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "Aggregating address ranges\n"); 43910405Sandreas.hansson@arm.com xbarRanges.clear(); 4409564SN/A 4419564SN/A // start out with the default range 4429564SN/A if (useDefaultRange) { 4439564SN/A if (!gotAddrRanges[defaultPortID]) 44410405Sandreas.hansson@arm.com fatal("Crossbar %s uses default range, but none provided", 4459564SN/A name()); 4469564SN/A 44710405Sandreas.hansson@arm.com xbarRanges.push_back(defaultRange); 44810405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "-- Adding default %s\n", 4499564SN/A defaultRange.to_string()); 4509564SN/A } 4519564SN/A 4529564SN/A // merge all interleaved ranges and add any range that is not 4539564SN/A // a subset of the default range 4549564SN/A std::vector<AddrRange> intlv_ranges; 45510405Sandreas.hansson@arm.com for (const auto& r: portMap) { 4569564SN/A // if the range is interleaved then save it for now 45710405Sandreas.hansson@arm.com if (r.first.interleaved()) { 4589564SN/A // if we already got interleaved ranges that are not 4599564SN/A // part of the same range, then first do a merge 4609564SN/A // before we add the new one 4619564SN/A if (!intlv_ranges.empty() && 46210405Sandreas.hansson@arm.com !intlv_ranges.back().mergesWith(r.first)) { 46310405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "-- Merging range from %d ranges\n", 4649564SN/A intlv_ranges.size()); 4659564SN/A AddrRange merged_range(intlv_ranges); 4669564SN/A // next decide if we keep the merged range or not 4679564SN/A if (!(useDefaultRange && 4689564SN/A merged_range.isSubset(defaultRange))) { 46910405Sandreas.hansson@arm.com xbarRanges.push_back(merged_range); 47010405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "-- Adding merged range %s\n", 4719564SN/A merged_range.to_string()); 4729564SN/A } 4739564SN/A intlv_ranges.clear(); 4749564SN/A } 47510405Sandreas.hansson@arm.com intlv_ranges.push_back(r.first); 4769564SN/A } else { 4779564SN/A // keep the current range if not a subset of the default 4789564SN/A if (!(useDefaultRange && 47910405Sandreas.hansson@arm.com r.first.isSubset(defaultRange))) { 48010405Sandreas.hansson@arm.com xbarRanges.push_back(r.first); 48110405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "-- Adding range %s\n", 48210405Sandreas.hansson@arm.com r.first.to_string()); 4839564SN/A } 4849564SN/A } 4859564SN/A } 4869564SN/A 4879564SN/A // if there is still interleaved ranges waiting to be merged, 4889564SN/A // go ahead and do it 4899564SN/A if (!intlv_ranges.empty()) { 49010405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "-- Merging range from %d ranges\n", 4919564SN/A intlv_ranges.size()); 4929564SN/A AddrRange merged_range(intlv_ranges); 4939564SN/A if (!(useDefaultRange && merged_range.isSubset(defaultRange))) { 49410405Sandreas.hansson@arm.com xbarRanges.push_back(merged_range); 49510405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "-- Adding merged range %s\n", 4969564SN/A merged_range.to_string()); 4979564SN/A } 4989564SN/A } 4999564SN/A 5009279SN/A // also check that no range partially overlaps with the 5019279SN/A // default range, this has to be done after all ranges are set 5029279SN/A // as there are no guarantees for when the default range is 5039279SN/A // update with respect to the other ones 5049279SN/A if (useDefaultRange) { 50510405Sandreas.hansson@arm.com for (const auto& r: xbarRanges) { 5069564SN/A // see if the new range is partially 5079564SN/A // overlapping the default range 50810405Sandreas.hansson@arm.com if (r.intersects(defaultRange) && 50910405Sandreas.hansson@arm.com !r.isSubset(defaultRange)) 5109564SN/A fatal("Range %s intersects the " \ 5119564SN/A "default range of %s but is not a " \ 51210405Sandreas.hansson@arm.com "subset\n", r.to_string(), name()); 5139279SN/A } 5149279SN/A } 5159279SN/A 5169279SN/A // tell all our neighbouring master ports that our address 5179279SN/A // ranges have changed 51810405Sandreas.hansson@arm.com for (const auto& s: slavePorts) 51910405Sandreas.hansson@arm.com s->sendRangeChange(); 5209279SN/A } 5219279SN/A 5229279SN/A clearPortCache(); 5232497SN/A} 5242497SN/A 5258711SN/AAddrRangeList 52610405Sandreas.hansson@arm.comBaseXBar::getAddrRanges() const 5272497SN/A{ 5289279SN/A // we should never be asked without first having sent a range 5299279SN/A // change, and the latter is only done once we have all the ranges 5309279SN/A // of the connected devices 5319279SN/A assert(gotAllAddrRanges); 5322568SN/A 5339407SN/A // at the moment, this never happens, as there are no cycles in 53410405Sandreas.hansson@arm.com // the range queries and no devices on the master side of a crossbar 5359407SN/A // (CPU, cache, bridge etc) actually care about the ranges of the 5369407SN/A // ports they are connected to 5379407SN/A 53810405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "Received address range request\n"); 5392846SN/A 54010405Sandreas.hansson@arm.com return xbarRanges; 5418711SN/A} 5428711SN/A 5439712SN/Avoid 54410405Sandreas.hansson@arm.comBaseXBar::regStats() 5459712SN/A{ 5469712SN/A using namespace Stats; 5479712SN/A 5489712SN/A transDist 5499712SN/A .init(MemCmd::NUM_MEM_CMDS) 5509712SN/A .name(name() + ".trans_dist") 5519712SN/A .desc("Transaction distribution") 5529712SN/A .flags(nozero); 5539712SN/A 5549712SN/A // get the string representation of the commands 5559712SN/A for (int i = 0; i < MemCmd::NUM_MEM_CMDS; i++) { 5569712SN/A MemCmd cmd(i); 5579712SN/A const std::string &cstr = cmd.toString(); 5589712SN/A transDist.subname(i, cstr); 5599712SN/A } 5609712SN/A 5619712SN/A pktCount 5629712SN/A .init(slavePorts.size(), masterPorts.size()) 5639712SN/A .name(name() + ".pkt_count") 5649712SN/A .desc("Packet count per connected master and slave (bytes)") 5659712SN/A .flags(total | nozero | nonan); 5669712SN/A 56710405Sandreas.hansson@arm.com pktSize 5689712SN/A .init(slavePorts.size(), masterPorts.size()) 56910405Sandreas.hansson@arm.com .name(name() + ".pkt_size") 5709712SN/A .desc("Cumulative packet size per connected master and slave (bytes)") 5719712SN/A .flags(total | nozero | nonan); 5729712SN/A 5739712SN/A // both the packet count and total size are two-dimensional 5749712SN/A // vectors, indexed by slave port id and master port id, thus the 5759712SN/A // neighbouring master and slave, they do not differentiate what 5769712SN/A // came from the master and was forwarded to the slave (requests 5779712SN/A // and snoop responses) and what came from the slave and was 5789712SN/A // forwarded to the master (responses and snoop requests) 5799712SN/A for (int i = 0; i < slavePorts.size(); i++) { 5809712SN/A pktCount.subname(i, slavePorts[i]->getMasterPort().name()); 58110405Sandreas.hansson@arm.com pktSize.subname(i, slavePorts[i]->getMasterPort().name()); 5829712SN/A for (int j = 0; j < masterPorts.size(); j++) { 5839712SN/A pktCount.ysubname(j, masterPorts[j]->getSlavePort().name()); 58410405Sandreas.hansson@arm.com pktSize.ysubname(j, masterPorts[j]->getSlavePort().name()); 5859712SN/A } 5869712SN/A } 5879712SN/A} 5889712SN/A 5899715SN/Atemplate <typename SrcType, typename DstType> 5903470SN/Aunsigned int 59110405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::drain(DrainManager *dm) 5923470SN/A{ 5933470SN/A //We should check that we're not "doing" anything, and that noone is 5943470SN/A //waiting. We might be idle but have someone waiting if the device we 5953470SN/A //contacted for a retry didn't actually retry. 5969612SN/A if (state != IDLE) { 59710405Sandreas.hansson@arm.com DPRINTF(Drain, "Crossbar not drained\n"); 5989342SN/A drainManager = dm; 5993470SN/A return 1; 6003470SN/A } 6015057SN/A return 0; 6023470SN/A} 6039093SN/A 6049715SN/Atemplate <typename SrcType, typename DstType> 6059712SN/Avoid 60610405Sandreas.hansson@arm.comBaseXBar::Layer<SrcType,DstType>::regStats() 6079712SN/A{ 6089712SN/A using namespace Stats; 6099712SN/A 6109712SN/A occupancy 6119712SN/A .name(name() + ".occupancy") 6129712SN/A .desc("Layer occupancy (ticks)") 6139712SN/A .flags(nozero); 6149712SN/A 6159712SN/A utilization 6169712SN/A .name(name() + ".utilization") 6179712SN/A .desc("Layer utilization (%)") 6189712SN/A .precision(1) 6199712SN/A .flags(nozero); 6209712SN/A 6219712SN/A utilization = 100 * occupancy / simTicks; 6229712SN/A} 6239712SN/A 6249093SN/A/** 62510405Sandreas.hansson@arm.com * Crossbar layer template instantiations. Could be removed with _impl.hh 6269093SN/A * file, but since there are only two given options (MasterPort and 6279093SN/A * SlavePort) it seems a bit excessive at this point. 6289093SN/A */ 62910405Sandreas.hansson@arm.comtemplate class BaseXBar::Layer<SlavePort,MasterPort>; 63010405Sandreas.hansson@arm.comtemplate class BaseXBar::Layer<MasterPort,SlavePort>; 631