xbar.cc revision 11522
15703SN/A/*
25703SN/A * Copyright (c) 2011-2015 ARM Limited
35703SN/A * All rights reserved
45703SN/A *
55703SN/A * The license below extends only to copyright in the software and shall
65703SN/A * not be construed as granting a license to any other intellectual
75703SN/A * property including but not limited to intellectual property relating
85703SN/A * to a hardware implementation of the functionality of the software
95703SN/A * licensed hereunder.  You may use the software subject to the license
105703SN/A * terms below provided that you ensure that this notice is replicated
115703SN/A * unmodified and in its entirety in all distributions of the software,
125703SN/A * modified or unmodified, in source code or in binary form.
135703SN/A *
145703SN/A * Copyright (c) 2006 The Regents of The University of Michigan
155703SN/A * All rights reserved.
165703SN/A *
175703SN/A * Redistribution and use in source and binary forms, with or without
185703SN/A * modification, are permitted provided that the following conditions are
195703SN/A * met: redistributions of source code must retain the above copyright
205703SN/A * notice, this list of conditions and the following disclaimer;
215703SN/A * redistributions in binary form must reproduce the above copyright
225703SN/A * notice, this list of conditions and the following disclaimer in the
235703SN/A * documentation and/or other materials provided with the distribution;
245703SN/A * neither the name of the copyright holders nor the names of its
255703SN/A * contributors may be used to endorse or promote products derived from
265703SN/A * this software without specific prior written permission.
275703SN/A *
285703SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
295703SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3011680SCurtis.Dunham@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
315703SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
325703SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
335703SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
345703SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
355703SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
365703SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
375703SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
385703SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
395703SN/A *
405703SN/A * Authors: Ali Saidi
415703SN/A *          Andreas Hansson
425703SN/A *          William Wang
435703SN/A */
445703SN/A
455703SN/A/**
465703SN/A * @file
475703SN/A * Definition of a crossbar object.
485703SN/A */
495703SN/A
505703SN/A#include "base/misc.hh"
515703SN/A#include "base/trace.hh"
525703SN/A#include "debug/AddrRanges.hh"
535703SN/A#include "debug/Drain.hh"
545703SN/A#include "debug/XBar.hh"
555703SN/A#include "mem/xbar.hh"
565703SN/A
575703SN/ABaseXBar::BaseXBar(const BaseXBarParams *p)
585703SN/A    : MemObject(p),
595703SN/A      frontendLatency(p->frontend_latency),
605703SN/A      forwardLatency(p->forward_latency),
615703SN/A      responseLatency(p->response_latency),
625703SN/A      width(p->width),
635703SN/A      gotAddrRanges(p->port_default_connection_count +
645778SN/A                          p->port_master_connection_count, false),
655703SN/A      gotAllAddrRanges(false), defaultPortID(InvalidPortID),
665703SN/A      useDefaultRange(p->use_default_range)
675703SN/A{}
685703SN/A
695703SN/ABaseXBar::~BaseXBar()
705703SN/A{
715703SN/A    for (auto m: masterPorts)
725703SN/A        delete m;
735703SN/A
745703SN/A    for (auto s: slavePorts)
755703SN/A        delete s;
765778SN/A}
775703SN/A
785703SN/Avoid
795703SN/ABaseXBar::init()
805703SN/A{
815703SN/A}
825703SN/A
835703SN/ABaseMasterPort &
845703SN/ABaseXBar::getMasterPort(const std::string &if_name, PortID idx)
855703SN/A{
865703SN/A    if (if_name == "master" && idx < masterPorts.size()) {
875703SN/A        // the master port index translates directly to the vector position
885703SN/A        return *masterPorts[idx];
895703SN/A    } else  if (if_name == "default") {
905703SN/A        return *masterPorts[defaultPortID];
915703SN/A    } else {
925703SN/A        return MemObject::getMasterPort(if_name, idx);
935703SN/A    }
945703SN/A}
955703SN/A
965703SN/ABaseSlavePort &
975703SN/ABaseXBar::getSlavePort(const std::string &if_name, PortID idx)
985703SN/A{
995703SN/A    if (if_name == "slave" && idx < slavePorts.size()) {
1005703SN/A        // the slave port index translates directly to the vector position
1015703SN/A        return *slavePorts[idx];
1025703SN/A    } else {
1035703SN/A        return MemObject::getSlavePort(if_name, idx);
1045703SN/A    }
1055703SN/A}
1065703SN/A
1075703SN/Avoid
1085703SN/ABaseXBar::calcPacketTiming(PacketPtr pkt, Tick header_delay)
1095703SN/A{
1105703SN/A    // the crossbar will be called at a time that is not necessarily
1115703SN/A    // coinciding with its own clock, so start by determining how long
1125703SN/A    // until the next clock edge (could be zero)
1135703SN/A    Tick offset = clockEdge() - curTick();
11411680SCurtis.Dunham@arm.com
11511680SCurtis.Dunham@arm.com    // the header delay depends on the path through the crossbar, and
11611680SCurtis.Dunham@arm.com    // we therefore rely on the caller to provide the actual
11711680SCurtis.Dunham@arm.com    // value
11811680SCurtis.Dunham@arm.com    pkt->headerDelay += offset + header_delay;
11911680SCurtis.Dunham@arm.com
12011680SCurtis.Dunham@arm.com    // note that we add the header delay to the existing value, and
12111680SCurtis.Dunham@arm.com    // align it to the crossbar clock
12211680SCurtis.Dunham@arm.com
12311680SCurtis.Dunham@arm.com    // do a quick sanity check to ensure the timings are not being
12411680SCurtis.Dunham@arm.com    // ignored, note that this specific value may cause problems for
12511680SCurtis.Dunham@arm.com    // slower interconnects
12611680SCurtis.Dunham@arm.com    panic_if(pkt->headerDelay > SimClock::Int::us,
12711680SCurtis.Dunham@arm.com             "Encountered header delay exceeding 1 us\n");
12811680SCurtis.Dunham@arm.com
12911680SCurtis.Dunham@arm.com    if (pkt->hasData()) {
13011680SCurtis.Dunham@arm.com        // the payloadDelay takes into account the relative time to
13111680SCurtis.Dunham@arm.com        // deliver the payload of the packet, after the header delay,
13211680SCurtis.Dunham@arm.com        // we take the maximum since the payload delay could already
13311680SCurtis.Dunham@arm.com        // be longer than what this parcitular crossbar enforces.
13411680SCurtis.Dunham@arm.com        pkt->payloadDelay = std::max<Tick>(pkt->payloadDelay,
13511680SCurtis.Dunham@arm.com                                           divCeil(pkt->getSize(), width) *
13611680SCurtis.Dunham@arm.com                                           clockPeriod());
13711680SCurtis.Dunham@arm.com    }
13811680SCurtis.Dunham@arm.com
13911680SCurtis.Dunham@arm.com    // the payload delay is not paying for the clock offset as that is
14011680SCurtis.Dunham@arm.com    // already done using the header delay, and the payload delay is
14111680SCurtis.Dunham@arm.com    // also used to determine how long the crossbar layer is busy and
14211680SCurtis.Dunham@arm.com    // thus regulates throughput
14311680SCurtis.Dunham@arm.com}
14411680SCurtis.Dunham@arm.com
14511680SCurtis.Dunham@arm.comtemplate <typename SrcType, typename DstType>
14611680SCurtis.Dunham@arm.comBaseXBar::Layer<SrcType,DstType>::Layer(DstType& _port, BaseXBar& _xbar,
14711680SCurtis.Dunham@arm.com                                       const std::string& _name) :
14811680SCurtis.Dunham@arm.com    port(_port), xbar(_xbar), _name(_name), state(IDLE),
14911680SCurtis.Dunham@arm.com    waitingForPeer(NULL), releaseEvent(this)
15011680SCurtis.Dunham@arm.com{
15111680SCurtis.Dunham@arm.com}
15211680SCurtis.Dunham@arm.com
15311680SCurtis.Dunham@arm.comtemplate <typename SrcType, typename DstType>
15411680SCurtis.Dunham@arm.comvoid BaseXBar::Layer<SrcType,DstType>::occupyLayer(Tick until)
15511680SCurtis.Dunham@arm.com{
15611680SCurtis.Dunham@arm.com    // ensure the state is busy at this point, as the layer should
15711680SCurtis.Dunham@arm.com    // transition from idle as soon as it has decided to forward the
15811680SCurtis.Dunham@arm.com    // packet to prevent any follow-on calls to sendTiming seeing an
15911680SCurtis.Dunham@arm.com    // unoccupied layer
16011680SCurtis.Dunham@arm.com    assert(state == BUSY);
16111680SCurtis.Dunham@arm.com
16211680SCurtis.Dunham@arm.com    // until should never be 0 as express snoops never occupy the layer
16311680SCurtis.Dunham@arm.com    assert(until != 0);
16411680SCurtis.Dunham@arm.com    xbar.schedule(releaseEvent, until);
16511680SCurtis.Dunham@arm.com
16611680SCurtis.Dunham@arm.com    // account for the occupied ticks
16711680SCurtis.Dunham@arm.com    occupancy += until - curTick();
16811680SCurtis.Dunham@arm.com
16911680SCurtis.Dunham@arm.com    DPRINTF(BaseXBar, "The crossbar layer is now busy from tick %d to %d\n",
17011680SCurtis.Dunham@arm.com            curTick(), until);
17111680SCurtis.Dunham@arm.com}
17211680SCurtis.Dunham@arm.com
17311680SCurtis.Dunham@arm.comtemplate <typename SrcType, typename DstType>
17411680SCurtis.Dunham@arm.combool
17511680SCurtis.Dunham@arm.comBaseXBar::Layer<SrcType,DstType>::tryTiming(SrcType* src_port)
17611680SCurtis.Dunham@arm.com{
17711680SCurtis.Dunham@arm.com    // if we are in the retry state, we will not see anything but the
17811680SCurtis.Dunham@arm.com    // retrying port (or in the case of the snoop ports the snoop
17911680SCurtis.Dunham@arm.com    // response port that mirrors the actual slave port) as we leave
18011680SCurtis.Dunham@arm.com    // this state again in zero time if the peer does not immediately
18111680SCurtis.Dunham@arm.com    // call the layer when receiving the retry
18211680SCurtis.Dunham@arm.com
18311680SCurtis.Dunham@arm.com    // first we see if the layer is busy, next we check if the
18411680SCurtis.Dunham@arm.com    // destination port is already engaged in a transaction waiting
18511680SCurtis.Dunham@arm.com    // for a retry from the peer
18611680SCurtis.Dunham@arm.com    if (state == BUSY || waitingForPeer != NULL) {
18711680SCurtis.Dunham@arm.com        // the port should not be waiting already
18811680SCurtis.Dunham@arm.com        assert(std::find(waitingForLayer.begin(), waitingForLayer.end(),
18911680SCurtis.Dunham@arm.com                         src_port) == waitingForLayer.end());
19011680SCurtis.Dunham@arm.com
19111680SCurtis.Dunham@arm.com        // put the port at the end of the retry list waiting for the
19211680SCurtis.Dunham@arm.com        // layer to be freed up (and in the case of a busy peer, for
19311680SCurtis.Dunham@arm.com        // that transaction to go through, and then the layer to free
19411680SCurtis.Dunham@arm.com        // up)
19511680SCurtis.Dunham@arm.com        waitingForLayer.push_back(src_port);
19611680SCurtis.Dunham@arm.com        return false;
19711680SCurtis.Dunham@arm.com    }
19811680SCurtis.Dunham@arm.com
19911680SCurtis.Dunham@arm.com    state = BUSY;
20011680SCurtis.Dunham@arm.com
20111680SCurtis.Dunham@arm.com    return true;
20211680SCurtis.Dunham@arm.com}
20311680SCurtis.Dunham@arm.com
20411680SCurtis.Dunham@arm.comtemplate <typename SrcType, typename DstType>
20511680SCurtis.Dunham@arm.comvoid
20611680SCurtis.Dunham@arm.comBaseXBar::Layer<SrcType,DstType>::succeededTiming(Tick busy_time)
20711680SCurtis.Dunham@arm.com{
20811680SCurtis.Dunham@arm.com    // we should have gone from idle or retry to busy in the tryTiming
20911680SCurtis.Dunham@arm.com    // test
21011680SCurtis.Dunham@arm.com    assert(state == BUSY);
21111680SCurtis.Dunham@arm.com
21211680SCurtis.Dunham@arm.com    // occupy the layer accordingly
21311680SCurtis.Dunham@arm.com    occupyLayer(busy_time);
21411680SCurtis.Dunham@arm.com}
21511680SCurtis.Dunham@arm.com
21611680SCurtis.Dunham@arm.comtemplate <typename SrcType, typename DstType>
21711680SCurtis.Dunham@arm.comvoid
21811680SCurtis.Dunham@arm.comBaseXBar::Layer<SrcType,DstType>::failedTiming(SrcType* src_port,
21911680SCurtis.Dunham@arm.com                                              Tick busy_time)
22011680SCurtis.Dunham@arm.com{
22111680SCurtis.Dunham@arm.com    // ensure no one got in between and tried to send something to
22211680SCurtis.Dunham@arm.com    // this port
22311680SCurtis.Dunham@arm.com    assert(waitingForPeer == NULL);
224
225    // if the source port is the current retrying one or not, we have
226    // failed in forwarding and should track that we are now waiting
227    // for the peer to send a retry
228    waitingForPeer = src_port;
229
230    // we should have gone from idle or retry to busy in the tryTiming
231    // test
232    assert(state == BUSY);
233
234    // occupy the bus accordingly
235    occupyLayer(busy_time);
236}
237
238template <typename SrcType, typename DstType>
239void
240BaseXBar::Layer<SrcType,DstType>::releaseLayer()
241{
242    // releasing the bus means we should now be idle
243    assert(state == BUSY);
244    assert(!releaseEvent.scheduled());
245
246    // update the state
247    state = IDLE;
248
249    // bus layer is now idle, so if someone is waiting we can retry
250    if (!waitingForLayer.empty()) {
251        // there is no point in sending a retry if someone is still
252        // waiting for the peer
253        if (waitingForPeer == NULL)
254            retryWaiting();
255    } else if (waitingForPeer == NULL && drainState() == DrainState::Draining) {
256        DPRINTF(Drain, "Crossbar done draining, signaling drain manager\n");
257        //If we weren't able to drain before, do it now.
258        signalDrainDone();
259    }
260}
261
262template <typename SrcType, typename DstType>
263void
264BaseXBar::Layer<SrcType,DstType>::retryWaiting()
265{
266    // this should never be called with no one waiting
267    assert(!waitingForLayer.empty());
268
269    // we always go to retrying from idle
270    assert(state == IDLE);
271
272    // update the state
273    state = RETRY;
274
275    // set the retrying port to the front of the retry list and pop it
276    // off the list
277    SrcType* retryingPort = waitingForLayer.front();
278    waitingForLayer.pop_front();
279
280    // tell the port to retry, which in some cases ends up calling the
281    // layer again
282    sendRetry(retryingPort);
283
284    // If the layer is still in the retry state, sendTiming wasn't
285    // called in zero time (e.g. the cache does this when a writeback
286    // is squashed)
287    if (state == RETRY) {
288        // update the state to busy and reset the retrying port, we
289        // have done our bit and sent the retry
290        state = BUSY;
291
292        // occupy the crossbar layer until the next clock edge
293        occupyLayer(xbar.clockEdge());
294    }
295}
296
297template <typename SrcType, typename DstType>
298void
299BaseXBar::Layer<SrcType,DstType>::recvRetry()
300{
301    // we should never get a retry without having failed to forward
302    // something to this port
303    assert(waitingForPeer != NULL);
304
305    // add the port where the failed packet originated to the front of
306    // the waiting ports for the layer, this allows us to call retry
307    // on the port immediately if the crossbar layer is idle
308    waitingForLayer.push_front(waitingForPeer);
309
310    // we are no longer waiting for the peer
311    waitingForPeer = NULL;
312
313    // if the layer is idle, retry this port straight away, if we
314    // are busy, then simply let the port wait for its turn
315    if (state == IDLE) {
316        retryWaiting();
317    } else {
318        assert(state == BUSY);
319    }
320}
321
322PortID
323BaseXBar::findPort(Addr addr)
324{
325    // we should never see any address lookups before we've got the
326    // ranges of all connected slave modules
327    assert(gotAllAddrRanges);
328
329    // Check the cache
330    PortID dest_id = checkPortCache(addr);
331    if (dest_id != InvalidPortID)
332        return dest_id;
333
334    // Check the address map interval tree
335    auto i = portMap.find(addr);
336    if (i != portMap.end()) {
337        dest_id = i->second;
338        updatePortCache(dest_id, i->first);
339        return dest_id;
340    }
341
342    // Check if this matches the default range
343    if (useDefaultRange) {
344        if (defaultRange.contains(addr)) {
345            DPRINTF(AddrRanges, "  found addr %#llx on default\n",
346                    addr);
347            return defaultPortID;
348        }
349    } else if (defaultPortID != InvalidPortID) {
350        DPRINTF(AddrRanges, "Unable to find destination for addr %#llx, "
351                "will use default port\n", addr);
352        return defaultPortID;
353    }
354
355    // we should use the range for the default port and it did not
356    // match, or the default port is not set
357    fatal("Unable to find destination for addr %#llx on %s\n", addr,
358          name());
359}
360
361/** Function called by the port when the crossbar is receiving a range change.*/
362void
363BaseXBar::recvRangeChange(PortID master_port_id)
364{
365    DPRINTF(AddrRanges, "Received range change from slave port %s\n",
366            masterPorts[master_port_id]->getSlavePort().name());
367
368    // remember that we got a range from this master port and thus the
369    // connected slave module
370    gotAddrRanges[master_port_id] = true;
371
372    // update the global flag
373    if (!gotAllAddrRanges) {
374        // take a logical AND of all the ports and see if we got
375        // ranges from everyone
376        gotAllAddrRanges = true;
377        std::vector<bool>::const_iterator r = gotAddrRanges.begin();
378        while (gotAllAddrRanges &&  r != gotAddrRanges.end()) {
379            gotAllAddrRanges &= *r++;
380        }
381        if (gotAllAddrRanges)
382            DPRINTF(AddrRanges, "Got address ranges from all slaves\n");
383    }
384
385    // note that we could get the range from the default port at any
386    // point in time, and we cannot assume that the default range is
387    // set before the other ones are, so we do additional checks once
388    // all ranges are provided
389    if (master_port_id == defaultPortID) {
390        // only update if we are indeed checking ranges for the
391        // default port since the port might not have a valid range
392        // otherwise
393        if (useDefaultRange) {
394            AddrRangeList ranges = masterPorts[master_port_id]->getAddrRanges();
395
396            if (ranges.size() != 1)
397                fatal("Crossbar %s may only have a single default range",
398                      name());
399
400            defaultRange = ranges.front();
401        }
402    } else {
403        // the ports are allowed to update their address ranges
404        // dynamically, so remove any existing entries
405        if (gotAddrRanges[master_port_id]) {
406            for (auto p = portMap.begin(); p != portMap.end(); ) {
407                if (p->second == master_port_id)
408                    // erasing invalidates the iterator, so advance it
409                    // before the deletion takes place
410                    portMap.erase(p++);
411                else
412                    p++;
413            }
414        }
415
416        AddrRangeList ranges = masterPorts[master_port_id]->getAddrRanges();
417
418        for (const auto& r: ranges) {
419            DPRINTF(AddrRanges, "Adding range %s for id %d\n",
420                    r.to_string(), master_port_id);
421            if (portMap.insert(r, master_port_id) == portMap.end()) {
422                PortID conflict_id = portMap.find(r)->second;
423                fatal("%s has two ports responding within range %s:\n\t%s\n\t%s\n",
424                      name(),
425                      r.to_string(),
426                      masterPorts[master_port_id]->getSlavePort().name(),
427                      masterPorts[conflict_id]->getSlavePort().name());
428            }
429        }
430    }
431
432    // if we have received ranges from all our neighbouring slave
433    // modules, go ahead and tell our connected master modules in
434    // turn, this effectively assumes a tree structure of the system
435    if (gotAllAddrRanges) {
436        DPRINTF(AddrRanges, "Aggregating address ranges\n");
437        xbarRanges.clear();
438
439        // start out with the default range
440        if (useDefaultRange) {
441            if (!gotAddrRanges[defaultPortID])
442                fatal("Crossbar %s uses default range, but none provided",
443                      name());
444
445            xbarRanges.push_back(defaultRange);
446            DPRINTF(AddrRanges, "-- Adding default %s\n",
447                    defaultRange.to_string());
448        }
449
450        // merge all interleaved ranges and add any range that is not
451        // a subset of the default range
452        std::vector<AddrRange> intlv_ranges;
453        for (const auto& r: portMap) {
454            // if the range is interleaved then save it for now
455            if (r.first.interleaved()) {
456                // if we already got interleaved ranges that are not
457                // part of the same range, then first do a merge
458                // before we add the new one
459                if (!intlv_ranges.empty() &&
460                    !intlv_ranges.back().mergesWith(r.first)) {
461                    DPRINTF(AddrRanges, "-- Merging range from %d ranges\n",
462                            intlv_ranges.size());
463                    AddrRange merged_range(intlv_ranges);
464                    // next decide if we keep the merged range or not
465                    if (!(useDefaultRange &&
466                          merged_range.isSubset(defaultRange))) {
467                        xbarRanges.push_back(merged_range);
468                        DPRINTF(AddrRanges, "-- Adding merged range %s\n",
469                                merged_range.to_string());
470                    }
471                    intlv_ranges.clear();
472                }
473                intlv_ranges.push_back(r.first);
474            } else {
475                // keep the current range if not a subset of the default
476                if (!(useDefaultRange &&
477                      r.first.isSubset(defaultRange))) {
478                    xbarRanges.push_back(r.first);
479                    DPRINTF(AddrRanges, "-- Adding range %s\n",
480                            r.first.to_string());
481                }
482            }
483        }
484
485        // if there is still interleaved ranges waiting to be merged,
486        // go ahead and do it
487        if (!intlv_ranges.empty()) {
488            DPRINTF(AddrRanges, "-- Merging range from %d ranges\n",
489                    intlv_ranges.size());
490            AddrRange merged_range(intlv_ranges);
491            if (!(useDefaultRange && merged_range.isSubset(defaultRange))) {
492                xbarRanges.push_back(merged_range);
493                DPRINTF(AddrRanges, "-- Adding merged range %s\n",
494                        merged_range.to_string());
495            }
496        }
497
498        // also check that no range partially overlaps with the
499        // default range, this has to be done after all ranges are set
500        // as there are no guarantees for when the default range is
501        // update with respect to the other ones
502        if (useDefaultRange) {
503            for (const auto& r: xbarRanges) {
504                // see if the new range is partially
505                // overlapping the default range
506                if (r.intersects(defaultRange) &&
507                    !r.isSubset(defaultRange))
508                    fatal("Range %s intersects the "                    \
509                          "default range of %s but is not a "           \
510                          "subset\n", r.to_string(), name());
511            }
512        }
513
514        // tell all our neighbouring master ports that our address
515        // ranges have changed
516        for (const auto& s: slavePorts)
517            s->sendRangeChange();
518    }
519
520    clearPortCache();
521}
522
523AddrRangeList
524BaseXBar::getAddrRanges() const
525{
526    // we should never be asked without first having sent a range
527    // change, and the latter is only done once we have all the ranges
528    // of the connected devices
529    assert(gotAllAddrRanges);
530
531    // at the moment, this never happens, as there are no cycles in
532    // the range queries and no devices on the master side of a crossbar
533    // (CPU, cache, bridge etc) actually care about the ranges of the
534    // ports they are connected to
535
536    DPRINTF(AddrRanges, "Received address range request\n");
537
538    return xbarRanges;
539}
540
541void
542BaseXBar::regStats()
543{
544    ClockedObject::regStats();
545
546    using namespace Stats;
547
548    transDist
549        .init(MemCmd::NUM_MEM_CMDS)
550        .name(name() + ".trans_dist")
551        .desc("Transaction distribution")
552        .flags(nozero);
553
554    // get the string representation of the commands
555    for (int i = 0; i < MemCmd::NUM_MEM_CMDS; i++) {
556        MemCmd cmd(i);
557        const std::string &cstr = cmd.toString();
558        transDist.subname(i, cstr);
559    }
560
561    pktCount
562        .init(slavePorts.size(), masterPorts.size())
563        .name(name() + ".pkt_count")
564        .desc("Packet count per connected master and slave (bytes)")
565        .flags(total | nozero | nonan);
566
567    pktSize
568        .init(slavePorts.size(), masterPorts.size())
569        .name(name() + ".pkt_size")
570        .desc("Cumulative packet size per connected master and slave (bytes)")
571        .flags(total | nozero | nonan);
572
573    // both the packet count and total size are two-dimensional
574    // vectors, indexed by slave port id and master port id, thus the
575    // neighbouring master and slave, they do not differentiate what
576    // came from the master and was forwarded to the slave (requests
577    // and snoop responses) and what came from the slave and was
578    // forwarded to the master (responses and snoop requests)
579    for (int i = 0; i < slavePorts.size(); i++) {
580        pktCount.subname(i, slavePorts[i]->getMasterPort().name());
581        pktSize.subname(i, slavePorts[i]->getMasterPort().name());
582        for (int j = 0; j < masterPorts.size(); j++) {
583            pktCount.ysubname(j, masterPorts[j]->getSlavePort().name());
584            pktSize.ysubname(j, masterPorts[j]->getSlavePort().name());
585        }
586    }
587}
588
589template <typename SrcType, typename DstType>
590DrainState
591BaseXBar::Layer<SrcType,DstType>::drain()
592{
593    //We should check that we're not "doing" anything, and that noone is
594    //waiting. We might be idle but have someone waiting if the device we
595    //contacted for a retry didn't actually retry.
596    if (state != IDLE) {
597        DPRINTF(Drain, "Crossbar not drained\n");
598        return DrainState::Draining;
599    } else {
600        return DrainState::Drained;
601    }
602}
603
604template <typename SrcType, typename DstType>
605void
606BaseXBar::Layer<SrcType,DstType>::regStats()
607{
608    using namespace Stats;
609
610    occupancy
611        .name(name() + ".occupancy")
612        .desc("Layer occupancy (ticks)")
613        .flags(nozero);
614
615    utilization
616        .name(name() + ".utilization")
617        .desc("Layer utilization (%)")
618        .precision(1)
619        .flags(nozero);
620
621    utilization = 100 * occupancy / simTicks;
622}
623
624/**
625 * Crossbar layer template instantiations. Could be removed with _impl.hh
626 * file, but since there are only two given options (MasterPort and
627 * SlavePort) it seems a bit excessive at this point.
628 */
629template class BaseXBar::Layer<SlavePort,MasterPort>;
630template class BaseXBar::Layer<MasterPort,SlavePort>;
631