1/* 2 * Copyright (c) 2011-2015, 2018 ARM Limited 3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software 9 * licensed hereunder. You may use the software subject to the license 10 * terms below provided that you ensure that this notice is replicated 11 * unmodified and in its entirety in all distributions of the software, 12 * modified or unmodified, in source code or in binary form. 13 * 14 * Copyright (c) 2006 The Regents of The University of Michigan 15 * All rights reserved. 16 * 17 * Redistribution and use in source and binary forms, with or without 18 * modification, are permitted provided that the following conditions are 19 * met: redistributions of source code must retain the above copyright 20 * notice, this list of conditions and the following disclaimer; 21 * redistributions in binary form must reproduce the above copyright 22 * notice, this list of conditions and the following disclaimer in the 23 * documentation and/or other materials provided with the distribution; 24 * neither the name of the copyright holders nor the names of its 25 * contributors may be used to endorse or promote products derived from 26 * this software without specific prior written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 * 40 * Authors: Ali Saidi 41 * Andreas Hansson 42 * William Wang 43 */ 44 45/** 46 * @file 47 * Definition of a crossbar object. 48 */ 49 50#include "mem/xbar.hh" 51 52#include "base/logging.hh" 53#include "base/trace.hh" 54#include "debug/AddrRanges.hh" 55#include "debug/Drain.hh" 56#include "debug/XBar.hh" 57 58BaseXBar::BaseXBar(const BaseXBarParams *p) 59 : MemObject(p), 60 frontendLatency(p->frontend_latency), 61 forwardLatency(p->forward_latency), 62 responseLatency(p->response_latency), 63 width(p->width), 64 gotAddrRanges(p->port_default_connection_count + 65 p->port_master_connection_count, false), 66 gotAllAddrRanges(false), defaultPortID(InvalidPortID), 67 useDefaultRange(p->use_default_range) 68{} 69 70BaseXBar::~BaseXBar() 71{ 72 for (auto m: masterPorts) 73 delete m; 74 75 for (auto s: slavePorts) 76 delete s; 77} 78
| 1/* 2 * Copyright (c) 2011-2015, 2018 ARM Limited 3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software 9 * licensed hereunder. You may use the software subject to the license 10 * terms below provided that you ensure that this notice is replicated 11 * unmodified and in its entirety in all distributions of the software, 12 * modified or unmodified, in source code or in binary form. 13 * 14 * Copyright (c) 2006 The Regents of The University of Michigan 15 * All rights reserved. 16 * 17 * Redistribution and use in source and binary forms, with or without 18 * modification, are permitted provided that the following conditions are 19 * met: redistributions of source code must retain the above copyright 20 * notice, this list of conditions and the following disclaimer; 21 * redistributions in binary form must reproduce the above copyright 22 * notice, this list of conditions and the following disclaimer in the 23 * documentation and/or other materials provided with the distribution; 24 * neither the name of the copyright holders nor the names of its 25 * contributors may be used to endorse or promote products derived from 26 * this software without specific prior written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 * 40 * Authors: Ali Saidi 41 * Andreas Hansson 42 * William Wang 43 */ 44 45/** 46 * @file 47 * Definition of a crossbar object. 48 */ 49 50#include "mem/xbar.hh" 51 52#include "base/logging.hh" 53#include "base/trace.hh" 54#include "debug/AddrRanges.hh" 55#include "debug/Drain.hh" 56#include "debug/XBar.hh" 57 58BaseXBar::BaseXBar(const BaseXBarParams *p) 59 : MemObject(p), 60 frontendLatency(p->frontend_latency), 61 forwardLatency(p->forward_latency), 62 responseLatency(p->response_latency), 63 width(p->width), 64 gotAddrRanges(p->port_default_connection_count + 65 p->port_master_connection_count, false), 66 gotAllAddrRanges(false), defaultPortID(InvalidPortID), 67 useDefaultRange(p->use_default_range) 68{} 69 70BaseXBar::~BaseXBar() 71{ 72 for (auto m: masterPorts) 73 delete m; 74 75 for (auto s: slavePorts) 76 delete s; 77} 78
|
79void 80BaseXBar::init() 81{ 82} 83
| |
84Port & 85BaseXBar::getPort(const std::string &if_name, PortID idx) 86{ 87 if (if_name == "master" && idx < masterPorts.size()) { 88 // the master port index translates directly to the vector position 89 return *masterPorts[idx]; 90 } else if (if_name == "default") { 91 return *masterPorts[defaultPortID]; 92 } else if (if_name == "slave" && idx < slavePorts.size()) { 93 // the slave port index translates directly to the vector position 94 return *slavePorts[idx]; 95 } else { 96 return MemObject::getPort(if_name, idx); 97 } 98} 99 100void 101BaseXBar::calcPacketTiming(PacketPtr pkt, Tick header_delay) 102{ 103 // the crossbar will be called at a time that is not necessarily 104 // coinciding with its own clock, so start by determining how long 105 // until the next clock edge (could be zero) 106 Tick offset = clockEdge() - curTick(); 107 108 // the header delay depends on the path through the crossbar, and 109 // we therefore rely on the caller to provide the actual 110 // value 111 pkt->headerDelay += offset + header_delay; 112 113 // note that we add the header delay to the existing value, and 114 // align it to the crossbar clock 115 116 // do a quick sanity check to ensure the timings are not being 117 // ignored, note that this specific value may cause problems for 118 // slower interconnects 119 panic_if(pkt->headerDelay > SimClock::Int::us, 120 "Encountered header delay exceeding 1 us\n"); 121 122 if (pkt->hasData()) { 123 // the payloadDelay takes into account the relative time to 124 // deliver the payload of the packet, after the header delay, 125 // we take the maximum since the payload delay could already 126 // be longer than what this parcitular crossbar enforces. 127 pkt->payloadDelay = std::max<Tick>(pkt->payloadDelay, 128 divCeil(pkt->getSize(), width) * 129 clockPeriod()); 130 } 131 132 // the payload delay is not paying for the clock offset as that is 133 // already done using the header delay, and the payload delay is 134 // also used to determine how long the crossbar layer is busy and 135 // thus regulates throughput 136} 137 138template <typename SrcType, typename DstType>
| 79Port & 80BaseXBar::getPort(const std::string &if_name, PortID idx) 81{ 82 if (if_name == "master" && idx < masterPorts.size()) { 83 // the master port index translates directly to the vector position 84 return *masterPorts[idx]; 85 } else if (if_name == "default") { 86 return *masterPorts[defaultPortID]; 87 } else if (if_name == "slave" && idx < slavePorts.size()) { 88 // the slave port index translates directly to the vector position 89 return *slavePorts[idx]; 90 } else { 91 return MemObject::getPort(if_name, idx); 92 } 93} 94 95void 96BaseXBar::calcPacketTiming(PacketPtr pkt, Tick header_delay) 97{ 98 // the crossbar will be called at a time that is not necessarily 99 // coinciding with its own clock, so start by determining how long 100 // until the next clock edge (could be zero) 101 Tick offset = clockEdge() - curTick(); 102 103 // the header delay depends on the path through the crossbar, and 104 // we therefore rely on the caller to provide the actual 105 // value 106 pkt->headerDelay += offset + header_delay; 107 108 // note that we add the header delay to the existing value, and 109 // align it to the crossbar clock 110 111 // do a quick sanity check to ensure the timings are not being 112 // ignored, note that this specific value may cause problems for 113 // slower interconnects 114 panic_if(pkt->headerDelay > SimClock::Int::us, 115 "Encountered header delay exceeding 1 us\n"); 116 117 if (pkt->hasData()) { 118 // the payloadDelay takes into account the relative time to 119 // deliver the payload of the packet, after the header delay, 120 // we take the maximum since the payload delay could already 121 // be longer than what this parcitular crossbar enforces. 122 pkt->payloadDelay = std::max<Tick>(pkt->payloadDelay, 123 divCeil(pkt->getSize(), width) * 124 clockPeriod()); 125 } 126 127 // the payload delay is not paying for the clock offset as that is 128 // already done using the header delay, and the payload delay is 129 // also used to determine how long the crossbar layer is busy and 130 // thus regulates throughput 131} 132 133template <typename SrcType, typename DstType>
|
139BaseXBar::Layer::Layer(DstType& _port, BaseXBar& _xbar,
| 134BaseXBar::Layer<SrcType, DstType>::Layer(DstType& _port, BaseXBar& _xbar,
|
140 const std::string& _name) : 141 port(_port), xbar(_xbar), _name(_name), state(IDLE), 142 waitingForPeer(NULL), releaseEvent([this]{ releaseLayer(); }, name()) 143{ 144} 145 146template <typename SrcType, typename DstType>
| 135 const std::string& _name) : 136 port(_port), xbar(_xbar), _name(_name), state(IDLE), 137 waitingForPeer(NULL), releaseEvent([this]{ releaseLayer(); }, name()) 138{ 139} 140 141template <typename SrcType, typename DstType>
|
147void BaseXBar::Layer::occupyLayer(Tick until)
| 142void BaseXBar::Layer<SrcType, DstType>::occupyLayer(Tick until)
|
148{ 149 // ensure the state is busy at this point, as the layer should 150 // transition from idle as soon as it has decided to forward the 151 // packet to prevent any follow-on calls to sendTiming seeing an 152 // unoccupied layer 153 assert(state == BUSY); 154 155 // until should never be 0 as express snoops never occupy the layer 156 assert(until != 0); 157 xbar.schedule(releaseEvent, until); 158 159 // account for the occupied ticks 160 occupancy += until - curTick(); 161 162 DPRINTF(BaseXBar, "The crossbar layer is now busy from tick %d to %d\n", 163 curTick(), until); 164} 165 166template <typename SrcType, typename DstType> 167bool
| 143{ 144 // ensure the state is busy at this point, as the layer should 145 // transition from idle as soon as it has decided to forward the 146 // packet to prevent any follow-on calls to sendTiming seeing an 147 // unoccupied layer 148 assert(state == BUSY); 149 150 // until should never be 0 as express snoops never occupy the layer 151 assert(until != 0); 152 xbar.schedule(releaseEvent, until); 153 154 // account for the occupied ticks 155 occupancy += until - curTick(); 156 157 DPRINTF(BaseXBar, "The crossbar layer is now busy from tick %d to %d\n", 158 curTick(), until); 159} 160 161template <typename SrcType, typename DstType> 162bool
|
168BaseXBar::Layer::tryTiming(SrcType* src_port)
| 163BaseXBar::Layer<SrcType, DstType>::tryTiming(SrcType* src_port)
|
169{ 170 // if we are in the retry state, we will not see anything but the 171 // retrying port (or in the case of the snoop ports the snoop 172 // response port that mirrors the actual slave port) as we leave 173 // this state again in zero time if the peer does not immediately 174 // call the layer when receiving the retry 175 176 // first we see if the layer is busy, next we check if the 177 // destination port is already engaged in a transaction waiting 178 // for a retry from the peer 179 if (state == BUSY || waitingForPeer != NULL) { 180 // the port should not be waiting already 181 assert(std::find(waitingForLayer.begin(), waitingForLayer.end(), 182 src_port) == waitingForLayer.end()); 183 184 // put the port at the end of the retry list waiting for the 185 // layer to be freed up (and in the case of a busy peer, for 186 // that transaction to go through, and then the layer to free 187 // up) 188 waitingForLayer.push_back(src_port); 189 return false; 190 } 191 192 state = BUSY; 193 194 return true; 195} 196 197template <typename SrcType, typename DstType> 198void
| 164{ 165 // if we are in the retry state, we will not see anything but the 166 // retrying port (or in the case of the snoop ports the snoop 167 // response port that mirrors the actual slave port) as we leave 168 // this state again in zero time if the peer does not immediately 169 // call the layer when receiving the retry 170 171 // first we see if the layer is busy, next we check if the 172 // destination port is already engaged in a transaction waiting 173 // for a retry from the peer 174 if (state == BUSY || waitingForPeer != NULL) { 175 // the port should not be waiting already 176 assert(std::find(waitingForLayer.begin(), waitingForLayer.end(), 177 src_port) == waitingForLayer.end()); 178 179 // put the port at the end of the retry list waiting for the 180 // layer to be freed up (and in the case of a busy peer, for 181 // that transaction to go through, and then the layer to free 182 // up) 183 waitingForLayer.push_back(src_port); 184 return false; 185 } 186 187 state = BUSY; 188 189 return true; 190} 191 192template <typename SrcType, typename DstType> 193void
|
199BaseXBar::Layer::succeededTiming(Tick busy_time)
| 194BaseXBar::Layer<SrcType, DstType>::succeededTiming(Tick busy_time)
|
200{ 201 // we should have gone from idle or retry to busy in the tryTiming 202 // test 203 assert(state == BUSY); 204 205 // occupy the layer accordingly 206 occupyLayer(busy_time); 207} 208 209template <typename SrcType, typename DstType> 210void
| 195{ 196 // we should have gone from idle or retry to busy in the tryTiming 197 // test 198 assert(state == BUSY); 199 200 // occupy the layer accordingly 201 occupyLayer(busy_time); 202} 203 204template <typename SrcType, typename DstType> 205void
|
211BaseXBar::Layer::failedTiming(SrcType* src_port,
| 206BaseXBar::Layer<SrcType, DstType>::failedTiming(SrcType* src_port,
|
212 Tick busy_time) 213{ 214 // ensure no one got in between and tried to send something to 215 // this port 216 assert(waitingForPeer == NULL); 217 218 // if the source port is the current retrying one or not, we have 219 // failed in forwarding and should track that we are now waiting 220 // for the peer to send a retry 221 waitingForPeer = src_port; 222 223 // we should have gone from idle or retry to busy in the tryTiming 224 // test 225 assert(state == BUSY); 226 227 // occupy the bus accordingly 228 occupyLayer(busy_time); 229} 230 231template <typename SrcType, typename DstType> 232void
| 207 Tick busy_time) 208{ 209 // ensure no one got in between and tried to send something to 210 // this port 211 assert(waitingForPeer == NULL); 212 213 // if the source port is the current retrying one or not, we have 214 // failed in forwarding and should track that we are now waiting 215 // for the peer to send a retry 216 waitingForPeer = src_port; 217 218 // we should have gone from idle or retry to busy in the tryTiming 219 // test 220 assert(state == BUSY); 221 222 // occupy the bus accordingly 223 occupyLayer(busy_time); 224} 225 226template <typename SrcType, typename DstType> 227void
|
233BaseXBar::Layer::releaseLayer()
| 228BaseXBar::Layer<SrcType, DstType>::releaseLayer()
|
234{ 235 // releasing the bus means we should now be idle 236 assert(state == BUSY); 237 assert(!releaseEvent.scheduled()); 238 239 // update the state 240 state = IDLE; 241 242 // bus layer is now idle, so if someone is waiting we can retry 243 if (!waitingForLayer.empty()) { 244 // there is no point in sending a retry if someone is still 245 // waiting for the peer 246 if (waitingForPeer == NULL) 247 retryWaiting(); 248 } else if (waitingForPeer == NULL && drainState() == DrainState::Draining) { 249 DPRINTF(Drain, "Crossbar done draining, signaling drain manager\n"); 250 //If we weren't able to drain before, do it now. 251 signalDrainDone(); 252 } 253} 254 255template <typename SrcType, typename DstType> 256void
| 229{ 230 // releasing the bus means we should now be idle 231 assert(state == BUSY); 232 assert(!releaseEvent.scheduled()); 233 234 // update the state 235 state = IDLE; 236 237 // bus layer is now idle, so if someone is waiting we can retry 238 if (!waitingForLayer.empty()) { 239 // there is no point in sending a retry if someone is still 240 // waiting for the peer 241 if (waitingForPeer == NULL) 242 retryWaiting(); 243 } else if (waitingForPeer == NULL && drainState() == DrainState::Draining) { 244 DPRINTF(Drain, "Crossbar done draining, signaling drain manager\n"); 245 //If we weren't able to drain before, do it now. 246 signalDrainDone(); 247 } 248} 249 250template <typename SrcType, typename DstType> 251void
|
257BaseXBar::Layer::retryWaiting()
| 252BaseXBar::Layer<SrcType, DstType>::retryWaiting()
|
258{ 259 // this should never be called with no one waiting 260 assert(!waitingForLayer.empty()); 261 262 // we always go to retrying from idle 263 assert(state == IDLE); 264 265 // update the state 266 state = RETRY; 267 268 // set the retrying port to the front of the retry list and pop it 269 // off the list 270 SrcType* retryingPort = waitingForLayer.front(); 271 waitingForLayer.pop_front(); 272 273 // tell the port to retry, which in some cases ends up calling the 274 // layer again 275 sendRetry(retryingPort); 276 277 // If the layer is still in the retry state, sendTiming wasn't 278 // called in zero time (e.g. the cache does this when a writeback 279 // is squashed) 280 if (state == RETRY) { 281 // update the state to busy and reset the retrying port, we 282 // have done our bit and sent the retry 283 state = BUSY; 284 285 // occupy the crossbar layer until the next clock edge 286 occupyLayer(xbar.clockEdge()); 287 } 288} 289 290template <typename SrcType, typename DstType> 291void
| 253{ 254 // this should never be called with no one waiting 255 assert(!waitingForLayer.empty()); 256 257 // we always go to retrying from idle 258 assert(state == IDLE); 259 260 // update the state 261 state = RETRY; 262 263 // set the retrying port to the front of the retry list and pop it 264 // off the list 265 SrcType* retryingPort = waitingForLayer.front(); 266 waitingForLayer.pop_front(); 267 268 // tell the port to retry, which in some cases ends up calling the 269 // layer again 270 sendRetry(retryingPort); 271 272 // If the layer is still in the retry state, sendTiming wasn't 273 // called in zero time (e.g. the cache does this when a writeback 274 // is squashed) 275 if (state == RETRY) { 276 // update the state to busy and reset the retrying port, we 277 // have done our bit and sent the retry 278 state = BUSY; 279 280 // occupy the crossbar layer until the next clock edge 281 occupyLayer(xbar.clockEdge()); 282 } 283} 284 285template <typename SrcType, typename DstType> 286void
|
292BaseXBar::Layer::recvRetry()
| 287BaseXBar::Layer<SrcType, DstType>::recvRetry()
|
293{ 294 // we should never get a retry without having failed to forward 295 // something to this port 296 assert(waitingForPeer != NULL); 297 298 // add the port where the failed packet originated to the front of 299 // the waiting ports for the layer, this allows us to call retry 300 // on the port immediately if the crossbar layer is idle 301 waitingForLayer.push_front(waitingForPeer); 302 303 // we are no longer waiting for the peer 304 waitingForPeer = NULL; 305 306 // if the layer is idle, retry this port straight away, if we 307 // are busy, then simply let the port wait for its turn 308 if (state == IDLE) { 309 retryWaiting(); 310 } else { 311 assert(state == BUSY); 312 } 313} 314 315PortID 316BaseXBar::findPort(AddrRange addr_range) 317{ 318 // we should never see any address lookups before we've got the 319 // ranges of all connected slave modules 320 assert(gotAllAddrRanges); 321 322 // Check the address map interval tree 323 auto i = portMap.contains(addr_range); 324 if (i != portMap.end()) { 325 return i->second; 326 } 327 328 // Check if this matches the default range 329 if (useDefaultRange) { 330 if (addr_range.isSubset(defaultRange)) { 331 DPRINTF(AddrRanges, " found addr %s on default\n", 332 addr_range.to_string()); 333 return defaultPortID; 334 } 335 } else if (defaultPortID != InvalidPortID) { 336 DPRINTF(AddrRanges, "Unable to find destination for %s, " 337 "will use default port\n", addr_range.to_string()); 338 return defaultPortID; 339 } 340 341 // we should use the range for the default port and it did not 342 // match, or the default port is not set 343 fatal("Unable to find destination for %s on %s\n", addr_range.to_string(), 344 name()); 345} 346 347/** Function called by the port when the crossbar is receiving a range change.*/ 348void 349BaseXBar::recvRangeChange(PortID master_port_id) 350{ 351 DPRINTF(AddrRanges, "Received range change from slave port %s\n", 352 masterPorts[master_port_id]->getSlavePort().name()); 353 354 // remember that we got a range from this master port and thus the 355 // connected slave module 356 gotAddrRanges[master_port_id] = true; 357 358 // update the global flag 359 if (!gotAllAddrRanges) { 360 // take a logical AND of all the ports and see if we got 361 // ranges from everyone 362 gotAllAddrRanges = true; 363 std::vector<bool>::const_iterator r = gotAddrRanges.begin(); 364 while (gotAllAddrRanges && r != gotAddrRanges.end()) { 365 gotAllAddrRanges &= *r++; 366 } 367 if (gotAllAddrRanges) 368 DPRINTF(AddrRanges, "Got address ranges from all slaves\n"); 369 } 370 371 // note that we could get the range from the default port at any 372 // point in time, and we cannot assume that the default range is 373 // set before the other ones are, so we do additional checks once 374 // all ranges are provided 375 if (master_port_id == defaultPortID) { 376 // only update if we are indeed checking ranges for the 377 // default port since the port might not have a valid range 378 // otherwise 379 if (useDefaultRange) { 380 AddrRangeList ranges = masterPorts[master_port_id]->getAddrRanges(); 381 382 if (ranges.size() != 1) 383 fatal("Crossbar %s may only have a single default range", 384 name()); 385 386 defaultRange = ranges.front(); 387 } 388 } else { 389 // the ports are allowed to update their address ranges 390 // dynamically, so remove any existing entries 391 if (gotAddrRanges[master_port_id]) { 392 for (auto p = portMap.begin(); p != portMap.end(); ) { 393 if (p->second == master_port_id) 394 // erasing invalidates the iterator, so advance it 395 // before the deletion takes place 396 portMap.erase(p++); 397 else 398 p++; 399 } 400 } 401 402 AddrRangeList ranges = masterPorts[master_port_id]->getAddrRanges(); 403 404 for (const auto& r: ranges) { 405 DPRINTF(AddrRanges, "Adding range %s for id %d\n", 406 r.to_string(), master_port_id); 407 if (portMap.insert(r, master_port_id) == portMap.end()) { 408 PortID conflict_id = portMap.intersects(r)->second; 409 fatal("%s has two ports responding within range " 410 "%s:\n\t%s\n\t%s\n", 411 name(), 412 r.to_string(), 413 masterPorts[master_port_id]->getSlavePort().name(), 414 masterPorts[conflict_id]->getSlavePort().name()); 415 } 416 } 417 } 418 419 // if we have received ranges from all our neighbouring slave 420 // modules, go ahead and tell our connected master modules in 421 // turn, this effectively assumes a tree structure of the system 422 if (gotAllAddrRanges) { 423 DPRINTF(AddrRanges, "Aggregating address ranges\n"); 424 xbarRanges.clear(); 425 426 // start out with the default range 427 if (useDefaultRange) { 428 if (!gotAddrRanges[defaultPortID]) 429 fatal("Crossbar %s uses default range, but none provided", 430 name()); 431 432 xbarRanges.push_back(defaultRange); 433 DPRINTF(AddrRanges, "-- Adding default %s\n", 434 defaultRange.to_string()); 435 } 436 437 // merge all interleaved ranges and add any range that is not 438 // a subset of the default range 439 std::vector<AddrRange> intlv_ranges; 440 for (const auto& r: portMap) { 441 // if the range is interleaved then save it for now 442 if (r.first.interleaved()) { 443 // if we already got interleaved ranges that are not 444 // part of the same range, then first do a merge 445 // before we add the new one 446 if (!intlv_ranges.empty() && 447 !intlv_ranges.back().mergesWith(r.first)) { 448 DPRINTF(AddrRanges, "-- Merging range from %d ranges\n", 449 intlv_ranges.size()); 450 AddrRange merged_range(intlv_ranges); 451 // next decide if we keep the merged range or not 452 if (!(useDefaultRange && 453 merged_range.isSubset(defaultRange))) { 454 xbarRanges.push_back(merged_range); 455 DPRINTF(AddrRanges, "-- Adding merged range %s\n", 456 merged_range.to_string()); 457 } 458 intlv_ranges.clear(); 459 } 460 intlv_ranges.push_back(r.first); 461 } else { 462 // keep the current range if not a subset of the default 463 if (!(useDefaultRange && 464 r.first.isSubset(defaultRange))) { 465 xbarRanges.push_back(r.first); 466 DPRINTF(AddrRanges, "-- Adding range %s\n", 467 r.first.to_string()); 468 } 469 } 470 } 471 472 // if there is still interleaved ranges waiting to be merged, 473 // go ahead and do it 474 if (!intlv_ranges.empty()) { 475 DPRINTF(AddrRanges, "-- Merging range from %d ranges\n", 476 intlv_ranges.size()); 477 AddrRange merged_range(intlv_ranges); 478 if (!(useDefaultRange && merged_range.isSubset(defaultRange))) { 479 xbarRanges.push_back(merged_range); 480 DPRINTF(AddrRanges, "-- Adding merged range %s\n", 481 merged_range.to_string()); 482 } 483 } 484 485 // also check that no range partially intersects with the 486 // default range, this has to be done after all ranges are set 487 // as there are no guarantees for when the default range is 488 // update with respect to the other ones 489 if (useDefaultRange) { 490 for (const auto& r: xbarRanges) { 491 // see if the new range is partially 492 // overlapping the default range 493 if (r.intersects(defaultRange) && 494 !r.isSubset(defaultRange)) 495 fatal("Range %s intersects the " \ 496 "default range of %s but is not a " \ 497 "subset\n", r.to_string(), name()); 498 } 499 } 500 501 // tell all our neighbouring master ports that our address 502 // ranges have changed 503 for (const auto& s: slavePorts) 504 s->sendRangeChange(); 505 } 506} 507 508AddrRangeList 509BaseXBar::getAddrRanges() const 510{ 511 // we should never be asked without first having sent a range 512 // change, and the latter is only done once we have all the ranges 513 // of the connected devices 514 assert(gotAllAddrRanges); 515 516 // at the moment, this never happens, as there are no cycles in 517 // the range queries and no devices on the master side of a crossbar 518 // (CPU, cache, bridge etc) actually care about the ranges of the 519 // ports they are connected to 520 521 DPRINTF(AddrRanges, "Received address range request\n"); 522 523 return xbarRanges; 524} 525 526void 527BaseXBar::regStats() 528{ 529 ClockedObject::regStats(); 530 531 using namespace Stats; 532 533 transDist 534 .init(MemCmd::NUM_MEM_CMDS) 535 .name(name() + ".trans_dist") 536 .desc("Transaction distribution") 537 .flags(nozero); 538 539 // get the string representation of the commands 540 for (int i = 0; i < MemCmd::NUM_MEM_CMDS; i++) { 541 MemCmd cmd(i); 542 const std::string &cstr = cmd.toString(); 543 transDist.subname(i, cstr); 544 } 545 546 pktCount 547 .init(slavePorts.size(), masterPorts.size()) 548 .name(name() + ".pkt_count") 549 .desc("Packet count per connected master and slave (bytes)") 550 .flags(total | nozero | nonan); 551 552 pktSize 553 .init(slavePorts.size(), masterPorts.size()) 554 .name(name() + ".pkt_size") 555 .desc("Cumulative packet size per connected master and slave (bytes)") 556 .flags(total | nozero | nonan); 557 558 // both the packet count and total size are two-dimensional 559 // vectors, indexed by slave port id and master port id, thus the 560 // neighbouring master and slave, they do not differentiate what 561 // came from the master and was forwarded to the slave (requests 562 // and snoop responses) and what came from the slave and was 563 // forwarded to the master (responses and snoop requests) 564 for (int i = 0; i < slavePorts.size(); i++) { 565 pktCount.subname(i, slavePorts[i]->getMasterPort().name()); 566 pktSize.subname(i, slavePorts[i]->getMasterPort().name()); 567 for (int j = 0; j < masterPorts.size(); j++) { 568 pktCount.ysubname(j, masterPorts[j]->getSlavePort().name()); 569 pktSize.ysubname(j, masterPorts[j]->getSlavePort().name()); 570 } 571 } 572} 573 574template <typename SrcType, typename DstType> 575DrainState
| 288{ 289 // we should never get a retry without having failed to forward 290 // something to this port 291 assert(waitingForPeer != NULL); 292 293 // add the port where the failed packet originated to the front of 294 // the waiting ports for the layer, this allows us to call retry 295 // on the port immediately if the crossbar layer is idle 296 waitingForLayer.push_front(waitingForPeer); 297 298 // we are no longer waiting for the peer 299 waitingForPeer = NULL; 300 301 // if the layer is idle, retry this port straight away, if we 302 // are busy, then simply let the port wait for its turn 303 if (state == IDLE) { 304 retryWaiting(); 305 } else { 306 assert(state == BUSY); 307 } 308} 309 310PortID 311BaseXBar::findPort(AddrRange addr_range) 312{ 313 // we should never see any address lookups before we've got the 314 // ranges of all connected slave modules 315 assert(gotAllAddrRanges); 316 317 // Check the address map interval tree 318 auto i = portMap.contains(addr_range); 319 if (i != portMap.end()) { 320 return i->second; 321 } 322 323 // Check if this matches the default range 324 if (useDefaultRange) { 325 if (addr_range.isSubset(defaultRange)) { 326 DPRINTF(AddrRanges, " found addr %s on default\n", 327 addr_range.to_string()); 328 return defaultPortID; 329 } 330 } else if (defaultPortID != InvalidPortID) { 331 DPRINTF(AddrRanges, "Unable to find destination for %s, " 332 "will use default port\n", addr_range.to_string()); 333 return defaultPortID; 334 } 335 336 // we should use the range for the default port and it did not 337 // match, or the default port is not set 338 fatal("Unable to find destination for %s on %s\n", addr_range.to_string(), 339 name()); 340} 341 342/** Function called by the port when the crossbar is receiving a range change.*/ 343void 344BaseXBar::recvRangeChange(PortID master_port_id) 345{ 346 DPRINTF(AddrRanges, "Received range change from slave port %s\n", 347 masterPorts[master_port_id]->getSlavePort().name()); 348 349 // remember that we got a range from this master port and thus the 350 // connected slave module 351 gotAddrRanges[master_port_id] = true; 352 353 // update the global flag 354 if (!gotAllAddrRanges) { 355 // take a logical AND of all the ports and see if we got 356 // ranges from everyone 357 gotAllAddrRanges = true; 358 std::vector<bool>::const_iterator r = gotAddrRanges.begin(); 359 while (gotAllAddrRanges && r != gotAddrRanges.end()) { 360 gotAllAddrRanges &= *r++; 361 } 362 if (gotAllAddrRanges) 363 DPRINTF(AddrRanges, "Got address ranges from all slaves\n"); 364 } 365 366 // note that we could get the range from the default port at any 367 // point in time, and we cannot assume that the default range is 368 // set before the other ones are, so we do additional checks once 369 // all ranges are provided 370 if (master_port_id == defaultPortID) { 371 // only update if we are indeed checking ranges for the 372 // default port since the port might not have a valid range 373 // otherwise 374 if (useDefaultRange) { 375 AddrRangeList ranges = masterPorts[master_port_id]->getAddrRanges(); 376 377 if (ranges.size() != 1) 378 fatal("Crossbar %s may only have a single default range", 379 name()); 380 381 defaultRange = ranges.front(); 382 } 383 } else { 384 // the ports are allowed to update their address ranges 385 // dynamically, so remove any existing entries 386 if (gotAddrRanges[master_port_id]) { 387 for (auto p = portMap.begin(); p != portMap.end(); ) { 388 if (p->second == master_port_id) 389 // erasing invalidates the iterator, so advance it 390 // before the deletion takes place 391 portMap.erase(p++); 392 else 393 p++; 394 } 395 } 396 397 AddrRangeList ranges = masterPorts[master_port_id]->getAddrRanges(); 398 399 for (const auto& r: ranges) { 400 DPRINTF(AddrRanges, "Adding range %s for id %d\n", 401 r.to_string(), master_port_id); 402 if (portMap.insert(r, master_port_id) == portMap.end()) { 403 PortID conflict_id = portMap.intersects(r)->second; 404 fatal("%s has two ports responding within range " 405 "%s:\n\t%s\n\t%s\n", 406 name(), 407 r.to_string(), 408 masterPorts[master_port_id]->getSlavePort().name(), 409 masterPorts[conflict_id]->getSlavePort().name()); 410 } 411 } 412 } 413 414 // if we have received ranges from all our neighbouring slave 415 // modules, go ahead and tell our connected master modules in 416 // turn, this effectively assumes a tree structure of the system 417 if (gotAllAddrRanges) { 418 DPRINTF(AddrRanges, "Aggregating address ranges\n"); 419 xbarRanges.clear(); 420 421 // start out with the default range 422 if (useDefaultRange) { 423 if (!gotAddrRanges[defaultPortID]) 424 fatal("Crossbar %s uses default range, but none provided", 425 name()); 426 427 xbarRanges.push_back(defaultRange); 428 DPRINTF(AddrRanges, "-- Adding default %s\n", 429 defaultRange.to_string()); 430 } 431 432 // merge all interleaved ranges and add any range that is not 433 // a subset of the default range 434 std::vector<AddrRange> intlv_ranges; 435 for (const auto& r: portMap) { 436 // if the range is interleaved then save it for now 437 if (r.first.interleaved()) { 438 // if we already got interleaved ranges that are not 439 // part of the same range, then first do a merge 440 // before we add the new one 441 if (!intlv_ranges.empty() && 442 !intlv_ranges.back().mergesWith(r.first)) { 443 DPRINTF(AddrRanges, "-- Merging range from %d ranges\n", 444 intlv_ranges.size()); 445 AddrRange merged_range(intlv_ranges); 446 // next decide if we keep the merged range or not 447 if (!(useDefaultRange && 448 merged_range.isSubset(defaultRange))) { 449 xbarRanges.push_back(merged_range); 450 DPRINTF(AddrRanges, "-- Adding merged range %s\n", 451 merged_range.to_string()); 452 } 453 intlv_ranges.clear(); 454 } 455 intlv_ranges.push_back(r.first); 456 } else { 457 // keep the current range if not a subset of the default 458 if (!(useDefaultRange && 459 r.first.isSubset(defaultRange))) { 460 xbarRanges.push_back(r.first); 461 DPRINTF(AddrRanges, "-- Adding range %s\n", 462 r.first.to_string()); 463 } 464 } 465 } 466 467 // if there is still interleaved ranges waiting to be merged, 468 // go ahead and do it 469 if (!intlv_ranges.empty()) { 470 DPRINTF(AddrRanges, "-- Merging range from %d ranges\n", 471 intlv_ranges.size()); 472 AddrRange merged_range(intlv_ranges); 473 if (!(useDefaultRange && merged_range.isSubset(defaultRange))) { 474 xbarRanges.push_back(merged_range); 475 DPRINTF(AddrRanges, "-- Adding merged range %s\n", 476 merged_range.to_string()); 477 } 478 } 479 480 // also check that no range partially intersects with the 481 // default range, this has to be done after all ranges are set 482 // as there are no guarantees for when the default range is 483 // update with respect to the other ones 484 if (useDefaultRange) { 485 for (const auto& r: xbarRanges) { 486 // see if the new range is partially 487 // overlapping the default range 488 if (r.intersects(defaultRange) && 489 !r.isSubset(defaultRange)) 490 fatal("Range %s intersects the " \ 491 "default range of %s but is not a " \ 492 "subset\n", r.to_string(), name()); 493 } 494 } 495 496 // tell all our neighbouring master ports that our address 497 // ranges have changed 498 for (const auto& s: slavePorts) 499 s->sendRangeChange(); 500 } 501} 502 503AddrRangeList 504BaseXBar::getAddrRanges() const 505{ 506 // we should never be asked without first having sent a range 507 // change, and the latter is only done once we have all the ranges 508 // of the connected devices 509 assert(gotAllAddrRanges); 510 511 // at the moment, this never happens, as there are no cycles in 512 // the range queries and no devices on the master side of a crossbar 513 // (CPU, cache, bridge etc) actually care about the ranges of the 514 // ports they are connected to 515 516 DPRINTF(AddrRanges, "Received address range request\n"); 517 518 return xbarRanges; 519} 520 521void 522BaseXBar::regStats() 523{ 524 ClockedObject::regStats(); 525 526 using namespace Stats; 527 528 transDist 529 .init(MemCmd::NUM_MEM_CMDS) 530 .name(name() + ".trans_dist") 531 .desc("Transaction distribution") 532 .flags(nozero); 533 534 // get the string representation of the commands 535 for (int i = 0; i < MemCmd::NUM_MEM_CMDS; i++) { 536 MemCmd cmd(i); 537 const std::string &cstr = cmd.toString(); 538 transDist.subname(i, cstr); 539 } 540 541 pktCount 542 .init(slavePorts.size(), masterPorts.size()) 543 .name(name() + ".pkt_count") 544 .desc("Packet count per connected master and slave (bytes)") 545 .flags(total | nozero | nonan); 546 547 pktSize 548 .init(slavePorts.size(), masterPorts.size()) 549 .name(name() + ".pkt_size") 550 .desc("Cumulative packet size per connected master and slave (bytes)") 551 .flags(total | nozero | nonan); 552 553 // both the packet count and total size are two-dimensional 554 // vectors, indexed by slave port id and master port id, thus the 555 // neighbouring master and slave, they do not differentiate what 556 // came from the master and was forwarded to the slave (requests 557 // and snoop responses) and what came from the slave and was 558 // forwarded to the master (responses and snoop requests) 559 for (int i = 0; i < slavePorts.size(); i++) { 560 pktCount.subname(i, slavePorts[i]->getMasterPort().name()); 561 pktSize.subname(i, slavePorts[i]->getMasterPort().name()); 562 for (int j = 0; j < masterPorts.size(); j++) { 563 pktCount.ysubname(j, masterPorts[j]->getSlavePort().name()); 564 pktSize.ysubname(j, masterPorts[j]->getSlavePort().name()); 565 } 566 } 567} 568 569template <typename SrcType, typename DstType> 570DrainState
|
576BaseXBar::Layer::drain()
| 571BaseXBar::Layer<SrcType, DstType>::drain()
|
577{ 578 //We should check that we're not "doing" anything, and that noone is 579 //waiting. We might be idle but have someone waiting if the device we 580 //contacted for a retry didn't actually retry. 581 if (state != IDLE) { 582 DPRINTF(Drain, "Crossbar not drained\n"); 583 return DrainState::Draining; 584 } else { 585 return DrainState::Drained; 586 } 587} 588 589template <typename SrcType, typename DstType> 590void
| 572{ 573 //We should check that we're not "doing" anything, and that noone is 574 //waiting. We might be idle but have someone waiting if the device we 575 //contacted for a retry didn't actually retry. 576 if (state != IDLE) { 577 DPRINTF(Drain, "Crossbar not drained\n"); 578 return DrainState::Draining; 579 } else { 580 return DrainState::Drained; 581 } 582} 583 584template <typename SrcType, typename DstType> 585void
|
591BaseXBar::Layer::regStats()
| 586BaseXBar::Layer<SrcType, DstType>::regStats()
|
592{ 593 using namespace Stats; 594 595 occupancy 596 .name(name() + ".occupancy") 597 .desc("Layer occupancy (ticks)") 598 .flags(nozero); 599 600 utilization 601 .name(name() + ".utilization") 602 .desc("Layer utilization (%)") 603 .precision(1) 604 .flags(nozero); 605 606 utilization = 100 * occupancy / simTicks; 607} 608 609/** 610 * Crossbar layer template instantiations. Could be removed with _impl.hh 611 * file, but since there are only two given options (MasterPort and 612 * SlavePort) it seems a bit excessive at this point. 613 */
| 587{ 588 using namespace Stats; 589 590 occupancy 591 .name(name() + ".occupancy") 592 .desc("Layer occupancy (ticks)") 593 .flags(nozero); 594 595 utilization 596 .name(name() + ".utilization") 597 .desc("Layer utilization (%)") 598 .precision(1) 599 .flags(nozero); 600 601 utilization = 100 * occupancy / simTicks; 602} 603 604/** 605 * Crossbar layer template instantiations. Could be removed with _impl.hh 606 * file, but since there are only two given options (MasterPort and 607 * SlavePort) it seems a bit excessive at this point. 608 */
|
614template class BaseXBar::Layer; 615template class BaseXBar::Layer;
| 609template class BaseXBar::Layer<SlavePort, MasterPort>; 610template class BaseXBar::Layer<MasterPort, SlavePort>;
|
| |