coherent_xbar.cc revision 12351
12497SN/A/* 212241Snikos.nikoleris@arm.com * Copyright (c) 2011-2017 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 4312351Snikos.nikoleris@arm.com * Nikos Nikoleris 442497SN/A */ 452497SN/A 462497SN/A/** 472982SN/A * @file 4810405Sandreas.hansson@arm.com * Definition of a crossbar object. 492497SN/A */ 502497SN/A 5111793Sbrandon.potter@amd.com#include "mem/coherent_xbar.hh" 5211793Sbrandon.potter@amd.com 5312334Sgabeblack@google.com#include "base/logging.hh" 542548SN/A#include "base/trace.hh" 5510405Sandreas.hansson@arm.com#include "debug/AddrRanges.hh" 5610405Sandreas.hansson@arm.com#include "debug/CoherentXBar.hh" 579524SN/A#include "sim/system.hh" 582497SN/A 5910405Sandreas.hansson@arm.comCoherentXBar::CoherentXBar(const CoherentXBarParams *p) 6010719SMarco.Balboni@ARM.com : BaseXBar(p), system(p->system), snoopFilter(p->snoop_filter), 6111334Sandreas.hansson@arm.com snoopResponseLatency(p->snoop_response_latency), 6212341Snikos.nikoleris@arm.com pointOfCoherency(p->point_of_coherency), 6312341Snikos.nikoleris@arm.com pointOfUnification(p->point_of_unification) 647523SN/A{ 658851SN/A // create the ports based on the size of the master and slave 668948SN/A // vector ports, and the presence of the default port, the ports 678948SN/A // are enumerated starting from zero 688851SN/A for (int i = 0; i < p->port_master_connection_count; ++i) { 699095SN/A std::string portName = csprintf("%s.master[%d]", name(), i); 7010405Sandreas.hansson@arm.com MasterPort* bp = new CoherentXBarMasterPort(portName, *this, i); 718922SN/A masterPorts.push_back(bp); 729715SN/A reqLayers.push_back(new ReqLayer(*bp, *this, 739715SN/A csprintf(".reqLayer%d", i))); 7410713Sandreas.hansson@arm.com snoopLayers.push_back(new SnoopRespLayer(*bp, *this, 7510713Sandreas.hansson@arm.com csprintf(".snoopLayer%d", i))); 768851SN/A } 778851SN/A 788948SN/A // see if we have a default slave device connected and if so add 798948SN/A // our corresponding master port 808915SN/A if (p->port_default_connection_count) { 819031SN/A defaultPortID = masterPorts.size(); 829095SN/A std::string portName = name() + ".default"; 8310405Sandreas.hansson@arm.com MasterPort* bp = new CoherentXBarMasterPort(portName, *this, 849036SN/A defaultPortID); 858922SN/A masterPorts.push_back(bp); 869715SN/A reqLayers.push_back(new ReqLayer(*bp, *this, csprintf(".reqLayer%d", 879715SN/A defaultPortID))); 8810713Sandreas.hansson@arm.com snoopLayers.push_back(new SnoopRespLayer(*bp, *this, 8910713Sandreas.hansson@arm.com csprintf(".snoopLayer%d", 9010713Sandreas.hansson@arm.com defaultPortID))); 918915SN/A } 928915SN/A 938948SN/A // create the slave ports, once again starting at zero 948851SN/A for (int i = 0; i < p->port_slave_connection_count; ++i) { 959095SN/A std::string portName = csprintf("%s.slave[%d]", name(), i); 9610888Sandreas.hansson@arm.com QueuedSlavePort* bp = new CoherentXBarSlavePort(portName, *this, i); 978922SN/A slavePorts.push_back(bp); 989715SN/A respLayers.push_back(new RespLayer(*bp, *this, 999715SN/A csprintf(".respLayer%d", i))); 1009716SN/A snoopRespPorts.push_back(new SnoopRespPort(*bp, *this)); 1018851SN/A } 1028851SN/A 1037523SN/A clearPortCache(); 1047523SN/A} 1057523SN/A 10610405Sandreas.hansson@arm.comCoherentXBar::~CoherentXBar() 1079715SN/A{ 10810405Sandreas.hansson@arm.com for (auto l: reqLayers) 10910405Sandreas.hansson@arm.com delete l; 11010405Sandreas.hansson@arm.com for (auto l: respLayers) 11110405Sandreas.hansson@arm.com delete l; 11210405Sandreas.hansson@arm.com for (auto l: snoopLayers) 11310405Sandreas.hansson@arm.com delete l; 11410405Sandreas.hansson@arm.com for (auto p: snoopRespPorts) 11510405Sandreas.hansson@arm.com delete p; 1169715SN/A} 1179715SN/A 1182568SN/Avoid 11910405Sandreas.hansson@arm.comCoherentXBar::init() 1202568SN/A{ 12110405Sandreas.hansson@arm.com BaseXBar::init(); 1229278SN/A 1238948SN/A // iterate over our slave ports and determine which of our 1248948SN/A // neighbouring master ports are snooping and add them as snoopers 12510405Sandreas.hansson@arm.com for (const auto& p: slavePorts) { 1269088SN/A // check if the connected master port is snooping 12710405Sandreas.hansson@arm.com if (p->isSnooping()) { 12810405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "Adding snooping master %s\n", 12910405Sandreas.hansson@arm.com p->getMasterPort().name()); 13010405Sandreas.hansson@arm.com snoopPorts.push_back(p); 1318711SN/A } 1328711SN/A } 1332568SN/A 1349036SN/A if (snoopPorts.empty()) 13510405Sandreas.hansson@arm.com warn("CoherentXBar %s has no snooping ports attached!\n", name()); 13611133Sandreas.hansson@arm.com 13711133Sandreas.hansson@arm.com // inform the snoop filter about the slave ports so it can create 13811133Sandreas.hansson@arm.com // its own internal representation 13911133Sandreas.hansson@arm.com if (snoopFilter) 14011133Sandreas.hansson@arm.com snoopFilter->setSlavePorts(slavePorts); 1413244SN/A} 1423244SN/A 1438948SN/Abool 14410405Sandreas.hansson@arm.comCoherentXBar::recvTimingReq(PacketPtr pkt, PortID slave_port_id) 1453244SN/A{ 1468975SN/A // determine the source port based on the id 1479032SN/A SlavePort *src_port = slavePorts[slave_port_id]; 1483244SN/A 1499091SN/A // remember if the packet is an express snoop 1509091SN/A bool is_express_snoop = pkt->isExpressSnoop(); 15111284Sandreas.hansson@arm.com bool cache_responding = pkt->cacheResponding(); 15210656Sandreas.hansson@arm.com // for normal requests, going downstream, the express snoop flag 15311284Sandreas.hansson@arm.com // and the cache responding flag should always be the same 15411284Sandreas.hansson@arm.com assert(is_express_snoop == cache_responding); 1559091SN/A 1569612SN/A // determine the destination based on the address 1579712SN/A PortID master_port_id = findPort(pkt->getAddr()); 1589612SN/A 15910405Sandreas.hansson@arm.com // test if the crossbar should be considered occupied for the current 1609033SN/A // port, and exclude express snoops from the check 1619715SN/A if (!is_express_snoop && !reqLayers[master_port_id]->tryTiming(src_port)) { 16211744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s BUSY\n", __func__, 16311744Snikos.nikoleris@arm.com src_port->name(), pkt->print()); 1643244SN/A return false; 1653244SN/A } 1663244SN/A 16711744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__, 16811744Snikos.nikoleris@arm.com src_port->name(), pkt->print()); 1695197SN/A 1709712SN/A // store size and command as they might be modified when 1719712SN/A // forwarding the packet 1729712SN/A unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0; 1739712SN/A unsigned int pkt_cmd = pkt->cmdToIndex(); 1749712SN/A 17510719SMarco.Balboni@ARM.com // store the old header delay so we can restore it if needed 17610719SMarco.Balboni@ARM.com Tick old_header_delay = pkt->headerDelay; 17710719SMarco.Balboni@ARM.com 17810719SMarco.Balboni@ARM.com // a request sees the frontend and forward latency 17910719SMarco.Balboni@ARM.com Tick xbar_delay = (frontendLatency + forwardLatency) * clockPeriod(); 18010719SMarco.Balboni@ARM.com 18110719SMarco.Balboni@ARM.com // set the packet header and payload delay 18210719SMarco.Balboni@ARM.com calcPacketTiming(pkt, xbar_delay); 18310719SMarco.Balboni@ARM.com 18410719SMarco.Balboni@ARM.com // determine how long to be crossbar layer is busy 18510719SMarco.Balboni@ARM.com Tick packetFinishTime = clockEdge(Cycles(1)) + pkt->payloadDelay; 1864912SN/A 18712346Snikos.nikoleris@arm.com // is this the destination point for this packet? (e.g. true if 18812346Snikos.nikoleris@arm.com // this xbar is the PoC for a cache maintenance operation to the 18912346Snikos.nikoleris@arm.com // PoC) otherwise the destination is any cache that can satisfy 19012346Snikos.nikoleris@arm.com // the request 19112346Snikos.nikoleris@arm.com const bool is_destination = isDestination(pkt); 19212346Snikos.nikoleris@arm.com 19312345Snikos.nikoleris@arm.com const bool snoop_caches = !system->bypassCaches() && 19412345Snikos.nikoleris@arm.com pkt->cmd != MemCmd::WriteClean; 19512345Snikos.nikoleris@arm.com if (snoop_caches) { 19611127Sandreas.hansson@arm.com assert(pkt->snoopDelay == 0); 19711127Sandreas.hansson@arm.com 19812351Snikos.nikoleris@arm.com if (pkt->isClean() && !is_destination) { 19912351Snikos.nikoleris@arm.com // before snooping we need to make sure that the memory 20012351Snikos.nikoleris@arm.com // below is not busy and the cache clean request can be 20112351Snikos.nikoleris@arm.com // forwarded to it 20212351Snikos.nikoleris@arm.com if (!masterPorts[master_port_id]->tryTiming(pkt)) { 20312351Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s RETRY\n", __func__, 20412351Snikos.nikoleris@arm.com src_port->name(), pkt->print()); 20512351Snikos.nikoleris@arm.com 20612351Snikos.nikoleris@arm.com // update the layer state and schedule an idle event 20712351Snikos.nikoleris@arm.com reqLayers[master_port_id]->failedTiming(src_port, 20812351Snikos.nikoleris@arm.com clockEdge(Cycles(1))); 20912351Snikos.nikoleris@arm.com return false; 21012351Snikos.nikoleris@arm.com } 21112351Snikos.nikoleris@arm.com } 21212351Snikos.nikoleris@arm.com 21312351Snikos.nikoleris@arm.com 2148979SN/A // the packet is a memory-mapped request and should be 2158979SN/A // broadcasted to our snoopers but the source 21610402SN/A if (snoopFilter) { 21710402SN/A // check with the snoop filter where to forward this packet 21810402SN/A auto sf_res = snoopFilter->lookupRequest(pkt, *src_port); 21911126Sandreas.hansson@arm.com // the time required by a packet to be delivered through 22011126Sandreas.hansson@arm.com // the xbar has to be charged also with to lookup latency 22111126Sandreas.hansson@arm.com // of the snoop filter 22210719SMarco.Balboni@ARM.com pkt->headerDelay += sf_res.second * clockPeriod(); 22311744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s SF size: %i lat: %i\n", 22411744Snikos.nikoleris@arm.com __func__, src_port->name(), pkt->print(), 22511744Snikos.nikoleris@arm.com sf_res.first.size(), sf_res.second); 22611196Sali.jafri@arm.com 22711199Sandreas.hansson@arm.com if (pkt->isEviction()) { 22811196Sali.jafri@arm.com // for block-evicting packets, i.e. writebacks and 22911196Sali.jafri@arm.com // clean evictions, there is no need to snoop up, as 23011196Sali.jafri@arm.com // all we do is determine if the block is cached or 23111196Sali.jafri@arm.com // not, instead just set it here based on the snoop 23211196Sali.jafri@arm.com // filter result 23311196Sali.jafri@arm.com if (!sf_res.first.empty()) 23411196Sali.jafri@arm.com pkt->setBlockCached(); 23511196Sali.jafri@arm.com } else { 23611196Sali.jafri@arm.com forwardTiming(pkt, slave_port_id, sf_res.first); 23711196Sali.jafri@arm.com } 23810402SN/A } else { 23910402SN/A forwardTiming(pkt, slave_port_id); 24010402SN/A } 24111127Sandreas.hansson@arm.com 24211127Sandreas.hansson@arm.com // add the snoop delay to our header delay, and then reset it 24311127Sandreas.hansson@arm.com pkt->headerDelay += pkt->snoopDelay; 24411127Sandreas.hansson@arm.com pkt->snoopDelay = 0; 2458979SN/A } 2468948SN/A 24711334Sandreas.hansson@arm.com // set up a sensible starting point 24811334Sandreas.hansson@arm.com bool success = true; 24910883Sali.jafri@arm.com 25011284Sandreas.hansson@arm.com // remember if the packet will generate a snoop response by 25111284Sandreas.hansson@arm.com // checking if a cache set the cacheResponding flag during the 25211284Sandreas.hansson@arm.com // snooping above 25311284Sandreas.hansson@arm.com const bool expect_snoop_resp = !cache_responding && pkt->cacheResponding(); 25411334Sandreas.hansson@arm.com bool expect_response = pkt->needsResponse() && !pkt->cacheResponding(); 2558915SN/A 25611334Sandreas.hansson@arm.com const bool sink_packet = sinkPacket(pkt); 25711334Sandreas.hansson@arm.com 25811334Sandreas.hansson@arm.com // in certain cases the crossbar is responsible for responding 25911334Sandreas.hansson@arm.com bool respond_directly = false; 26011544Snikos.nikoleris@arm.com // store the original address as an address mapper could possibly 26111544Snikos.nikoleris@arm.com // modify the address upon a sendTimingRequest 26211544Snikos.nikoleris@arm.com const Addr addr(pkt->getAddr()); 26311334Sandreas.hansson@arm.com if (sink_packet) { 26411744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: Not forwarding %s\n", __func__, 26511744Snikos.nikoleris@arm.com pkt->print()); 26611334Sandreas.hansson@arm.com } else { 26711334Sandreas.hansson@arm.com // determine if we are forwarding the packet, or responding to 26811334Sandreas.hansson@arm.com // it 26912346Snikos.nikoleris@arm.com if (forwardPacket(pkt)) { 27011334Sandreas.hansson@arm.com // if we are passing on, rather than sinking, a packet to 27111334Sandreas.hansson@arm.com // which an upstream cache has committed to responding, 27211334Sandreas.hansson@arm.com // the line was needs writable, and the responding only 27311334Sandreas.hansson@arm.com // had an Owned copy, so we need to immidiately let the 27411334Sandreas.hansson@arm.com // downstream caches know, bypass any flow control 27511334Sandreas.hansson@arm.com if (pkt->cacheResponding()) { 27611334Sandreas.hansson@arm.com pkt->setExpressSnoop(); 27711334Sandreas.hansson@arm.com } 27811334Sandreas.hansson@arm.com 27912346Snikos.nikoleris@arm.com // make sure that the write request (e.g., WriteClean) 28012346Snikos.nikoleris@arm.com // will stop at the memory below if this crossbar is its 28112346Snikos.nikoleris@arm.com // destination 28212346Snikos.nikoleris@arm.com if (pkt->isWrite() && is_destination) { 28312346Snikos.nikoleris@arm.com pkt->clearWriteThrough(); 28412346Snikos.nikoleris@arm.com } 28512346Snikos.nikoleris@arm.com 28611334Sandreas.hansson@arm.com // since it is a normal request, attempt to send the packet 28711334Sandreas.hansson@arm.com success = masterPorts[master_port_id]->sendTimingReq(pkt); 28811334Sandreas.hansson@arm.com } else { 28911334Sandreas.hansson@arm.com // no need to forward, turn this packet around and respond 29011334Sandreas.hansson@arm.com // directly 29111334Sandreas.hansson@arm.com assert(pkt->needsResponse()); 29211334Sandreas.hansson@arm.com 29311334Sandreas.hansson@arm.com respond_directly = true; 29411334Sandreas.hansson@arm.com assert(!expect_snoop_resp); 29511334Sandreas.hansson@arm.com expect_response = false; 29611334Sandreas.hansson@arm.com } 29711334Sandreas.hansson@arm.com } 2988948SN/A 29912345Snikos.nikoleris@arm.com if (snoopFilter && snoop_caches) { 30010402SN/A // Let the snoop filter know about the success of the send operation 30111605Snikos.nikoleris@arm.com snoopFilter->finishRequest(!success, addr, pkt->isSecure()); 30210402SN/A } 30310402SN/A 30410656Sandreas.hansson@arm.com // check if we were successful in sending the packet onwards 30510656Sandreas.hansson@arm.com if (!success) { 30611284Sandreas.hansson@arm.com // express snoops should never be forced to retry 30710656Sandreas.hansson@arm.com assert(!is_express_snoop); 30810656Sandreas.hansson@arm.com 30910719SMarco.Balboni@ARM.com // restore the header delay 31010719SMarco.Balboni@ARM.com pkt->headerDelay = old_header_delay; 31110656Sandreas.hansson@arm.com 31211744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s RETRY\n", __func__, 31311744Snikos.nikoleris@arm.com src_port->name(), pkt->print()); 31410656Sandreas.hansson@arm.com 31510656Sandreas.hansson@arm.com // update the layer state and schedule an idle event 31610656Sandreas.hansson@arm.com reqLayers[master_port_id]->failedTiming(src_port, 31710719SMarco.Balboni@ARM.com clockEdge(Cycles(1))); 3189091SN/A } else { 31910656Sandreas.hansson@arm.com // express snoops currently bypass the crossbar state entirely 32010656Sandreas.hansson@arm.com if (!is_express_snoop) { 32110656Sandreas.hansson@arm.com // if this particular request will generate a snoop 32210656Sandreas.hansson@arm.com // response 32310656Sandreas.hansson@arm.com if (expect_snoop_resp) { 32410656Sandreas.hansson@arm.com // we should never have an exsiting request outstanding 32510656Sandreas.hansson@arm.com assert(outstandingSnoop.find(pkt->req) == 32610656Sandreas.hansson@arm.com outstandingSnoop.end()); 32710656Sandreas.hansson@arm.com outstandingSnoop.insert(pkt->req); 3288948SN/A 32910656Sandreas.hansson@arm.com // basic sanity check on the outstanding snoops 33010656Sandreas.hansson@arm.com panic_if(outstandingSnoop.size() > 512, 33110656Sandreas.hansson@arm.com "Outstanding snoop requests exceeded 512\n"); 33210656Sandreas.hansson@arm.com } 3338948SN/A 33410656Sandreas.hansson@arm.com // remember where to route the normal response to 33510656Sandreas.hansson@arm.com if (expect_response || expect_snoop_resp) { 33610656Sandreas.hansson@arm.com assert(routeTo.find(pkt->req) == routeTo.end()); 33710656Sandreas.hansson@arm.com routeTo[pkt->req] = slave_port_id; 3389549SN/A 33910656Sandreas.hansson@arm.com panic_if(routeTo.size() > 512, 34010656Sandreas.hansson@arm.com "Routing table exceeds 512 packets\n"); 34110656Sandreas.hansson@arm.com } 3428948SN/A 34310405Sandreas.hansson@arm.com // update the layer state and schedule an idle event 3449715SN/A reqLayers[master_port_id]->succeededTiming(packetFinishTime); 3459091SN/A } 3468975SN/A 34710656Sandreas.hansson@arm.com // stats updates only consider packets that were successfully sent 3489712SN/A pktCount[slave_port_id][master_port_id]++; 34910405Sandreas.hansson@arm.com pktSize[slave_port_id][master_port_id] += pkt_size; 3509712SN/A transDist[pkt_cmd]++; 35110656Sandreas.hansson@arm.com 35211564Sdavid.guillen@arm.com if (is_express_snoop) { 35310656Sandreas.hansson@arm.com snoops++; 35411564Sdavid.guillen@arm.com snoopTraffic += pkt_size; 35511564Sdavid.guillen@arm.com } 3569712SN/A } 3579712SN/A 35811334Sandreas.hansson@arm.com if (sink_packet) 35911334Sandreas.hansson@arm.com // queue the packet for deletion 36011334Sandreas.hansson@arm.com pendingDelete.reset(pkt); 36111334Sandreas.hansson@arm.com 36212351Snikos.nikoleris@arm.com // normally we respond to the packet we just received if we need to 36312351Snikos.nikoleris@arm.com PacketPtr rsp_pkt = pkt; 36412351Snikos.nikoleris@arm.com PortID rsp_port_id = slave_port_id; 36512351Snikos.nikoleris@arm.com 36612351Snikos.nikoleris@arm.com // If this is the destination of the cache clean operation the 36712351Snikos.nikoleris@arm.com // crossbar is responsible for responding. This crossbar will 36812351Snikos.nikoleris@arm.com // respond when the cache clean is complete. A cache clean 36912351Snikos.nikoleris@arm.com // is complete either: 37012351Snikos.nikoleris@arm.com // * direcly, if no cache above had a dirty copy of the block 37112351Snikos.nikoleris@arm.com // as indicated by the satisfied flag of the packet, or 37212351Snikos.nikoleris@arm.com // * when the crossbar has seen both the cache clean request 37312351Snikos.nikoleris@arm.com // (CleanSharedReq, CleanInvalidReq) and the corresponding 37412351Snikos.nikoleris@arm.com // write (WriteClean) which updates the block in the memory 37512351Snikos.nikoleris@arm.com // below. 37612351Snikos.nikoleris@arm.com if (success && 37712351Snikos.nikoleris@arm.com ((pkt->isClean() && pkt->satisfied()) || 37812351Snikos.nikoleris@arm.com pkt->cmd == MemCmd::WriteClean) && 37912351Snikos.nikoleris@arm.com is_destination) { 38012351Snikos.nikoleris@arm.com PacketPtr deferred_rsp = pkt->isWrite() ? nullptr : pkt; 38112351Snikos.nikoleris@arm.com auto cmo_lookup = outstandingCMO.find(pkt->id); 38212351Snikos.nikoleris@arm.com if (cmo_lookup != outstandingCMO.end()) { 38312351Snikos.nikoleris@arm.com // the cache clean request has already reached this xbar 38412351Snikos.nikoleris@arm.com respond_directly = true; 38512351Snikos.nikoleris@arm.com if (pkt->isWrite()) { 38612351Snikos.nikoleris@arm.com rsp_pkt = cmo_lookup->second; 38712351Snikos.nikoleris@arm.com assert(rsp_pkt); 38812351Snikos.nikoleris@arm.com 38912351Snikos.nikoleris@arm.com // determine the destination 39012351Snikos.nikoleris@arm.com const auto route_lookup = routeTo.find(rsp_pkt->req); 39112351Snikos.nikoleris@arm.com assert(route_lookup != routeTo.end()); 39212351Snikos.nikoleris@arm.com rsp_port_id = route_lookup->second; 39312351Snikos.nikoleris@arm.com assert(rsp_port_id != InvalidPortID); 39412351Snikos.nikoleris@arm.com assert(rsp_port_id < respLayers.size()); 39512351Snikos.nikoleris@arm.com // remove the request from the routing table 39612351Snikos.nikoleris@arm.com routeTo.erase(route_lookup); 39712351Snikos.nikoleris@arm.com } 39812351Snikos.nikoleris@arm.com outstandingCMO.erase(cmo_lookup); 39912351Snikos.nikoleris@arm.com } else { 40012351Snikos.nikoleris@arm.com respond_directly = false; 40112351Snikos.nikoleris@arm.com outstandingCMO.emplace(pkt->id, deferred_rsp); 40212351Snikos.nikoleris@arm.com if (!pkt->isWrite()) { 40312351Snikos.nikoleris@arm.com assert(routeTo.find(pkt->req) == routeTo.end()); 40412351Snikos.nikoleris@arm.com routeTo[pkt->req] = slave_port_id; 40512351Snikos.nikoleris@arm.com 40612351Snikos.nikoleris@arm.com panic_if(routeTo.size() > 512, 40712351Snikos.nikoleris@arm.com "Routing table exceeds 512 packets\n"); 40812351Snikos.nikoleris@arm.com } 40912351Snikos.nikoleris@arm.com } 41012351Snikos.nikoleris@arm.com } 41112351Snikos.nikoleris@arm.com 41212351Snikos.nikoleris@arm.com 41311334Sandreas.hansson@arm.com if (respond_directly) { 41412351Snikos.nikoleris@arm.com assert(rsp_pkt->needsResponse()); 41511334Sandreas.hansson@arm.com assert(success); 41611334Sandreas.hansson@arm.com 41712351Snikos.nikoleris@arm.com rsp_pkt->makeResponse(); 41811334Sandreas.hansson@arm.com 41911334Sandreas.hansson@arm.com if (snoopFilter && !system->bypassCaches()) { 42011334Sandreas.hansson@arm.com // let the snoop filter inspect the response and update its state 42112351Snikos.nikoleris@arm.com snoopFilter->updateResponse(rsp_pkt, *slavePorts[rsp_port_id]); 42211334Sandreas.hansson@arm.com } 42311334Sandreas.hansson@arm.com 42412351Snikos.nikoleris@arm.com // we send the response after the current packet, even if the 42512351Snikos.nikoleris@arm.com // response is not for this packet (e.g. cache clean operation 42612351Snikos.nikoleris@arm.com // where both the request and the write packet have to cross 42712351Snikos.nikoleris@arm.com // the destination xbar before the response is sent.) 42811334Sandreas.hansson@arm.com Tick response_time = clockEdge() + pkt->headerDelay; 42912351Snikos.nikoleris@arm.com rsp_pkt->headerDelay = 0; 43011334Sandreas.hansson@arm.com 43112351Snikos.nikoleris@arm.com slavePorts[rsp_port_id]->schedTimingResp(rsp_pkt, response_time); 43211334Sandreas.hansson@arm.com } 43311334Sandreas.hansson@arm.com 4349091SN/A return success; 4358975SN/A} 4368975SN/A 4378975SN/Abool 43810405Sandreas.hansson@arm.comCoherentXBar::recvTimingResp(PacketPtr pkt, PortID master_port_id) 4398975SN/A{ 4408975SN/A // determine the source port based on the id 4419032SN/A MasterPort *src_port = masterPorts[master_port_id]; 4428975SN/A 44310656Sandreas.hansson@arm.com // determine the destination 44410656Sandreas.hansson@arm.com const auto route_lookup = routeTo.find(pkt->req); 44510656Sandreas.hansson@arm.com assert(route_lookup != routeTo.end()); 44610656Sandreas.hansson@arm.com const PortID slave_port_id = route_lookup->second; 44710572Sandreas.hansson@arm.com assert(slave_port_id != InvalidPortID); 44810572Sandreas.hansson@arm.com assert(slave_port_id < respLayers.size()); 4499713SN/A 45010405Sandreas.hansson@arm.com // test if the crossbar should be considered occupied for the 45110405Sandreas.hansson@arm.com // current port 4529715SN/A if (!respLayers[slave_port_id]->tryTiming(src_port)) { 45311744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s BUSY\n", __func__, 45411744Snikos.nikoleris@arm.com src_port->name(), pkt->print()); 4558975SN/A return false; 4568975SN/A } 4578975SN/A 45811744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__, 45911744Snikos.nikoleris@arm.com src_port->name(), pkt->print()); 4608975SN/A 4619712SN/A // store size and command as they might be modified when 4629712SN/A // forwarding the packet 4639712SN/A unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0; 4649712SN/A unsigned int pkt_cmd = pkt->cmdToIndex(); 4659712SN/A 46610719SMarco.Balboni@ARM.com // a response sees the response latency 46710719SMarco.Balboni@ARM.com Tick xbar_delay = responseLatency * clockPeriod(); 46810719SMarco.Balboni@ARM.com 46910719SMarco.Balboni@ARM.com // set the packet header and payload delay 47010719SMarco.Balboni@ARM.com calcPacketTiming(pkt, xbar_delay); 47110719SMarco.Balboni@ARM.com 47210719SMarco.Balboni@ARM.com // determine how long to be crossbar layer is busy 47310719SMarco.Balboni@ARM.com Tick packetFinishTime = clockEdge(Cycles(1)) + pkt->payloadDelay; 4748975SN/A 47510821Sandreas.hansson@arm.com if (snoopFilter && !system->bypassCaches()) { 47610402SN/A // let the snoop filter inspect the response and update its state 47710402SN/A snoopFilter->updateResponse(pkt, *slavePorts[slave_port_id]); 47810402SN/A } 47910402SN/A 48010888Sandreas.hansson@arm.com // send the packet through the destination slave port and pay for 48110888Sandreas.hansson@arm.com // any outstanding header delay 48210888Sandreas.hansson@arm.com Tick latency = pkt->headerDelay; 48310888Sandreas.hansson@arm.com pkt->headerDelay = 0; 48410888Sandreas.hansson@arm.com slavePorts[slave_port_id]->schedTimingResp(pkt, curTick() + latency); 4858975SN/A 48610656Sandreas.hansson@arm.com // remove the request from the routing table 48710656Sandreas.hansson@arm.com routeTo.erase(route_lookup); 48810656Sandreas.hansson@arm.com 4899715SN/A respLayers[slave_port_id]->succeededTiming(packetFinishTime); 4908975SN/A 4919712SN/A // stats updates 4929712SN/A pktCount[slave_port_id][master_port_id]++; 49310405Sandreas.hansson@arm.com pktSize[slave_port_id][master_port_id] += pkt_size; 4949712SN/A transDist[pkt_cmd]++; 4959712SN/A 4968975SN/A return true; 4978975SN/A} 4988975SN/A 4998975SN/Avoid 50010405Sandreas.hansson@arm.comCoherentXBar::recvTimingSnoopReq(PacketPtr pkt, PortID master_port_id) 5018975SN/A{ 50211744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__, 50311744Snikos.nikoleris@arm.com masterPorts[master_port_id]->name(), pkt->print()); 5048975SN/A 5059712SN/A // update stats here as we know the forwarding will succeed 50611564Sdavid.guillen@arm.com unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0; 5079712SN/A transDist[pkt->cmdToIndex()]++; 50810405Sandreas.hansson@arm.com snoops++; 50911564Sdavid.guillen@arm.com snoopTraffic += pkt_size; 5109712SN/A 5118975SN/A // we should only see express snoops from caches 5128975SN/A assert(pkt->isExpressSnoop()); 5138975SN/A 51411127Sandreas.hansson@arm.com // set the packet header and payload delay, for now use forward latency 51511127Sandreas.hansson@arm.com // @todo Assess the choice of latency further 51611127Sandreas.hansson@arm.com calcPacketTiming(pkt, forwardLatency * clockPeriod()); 51711127Sandreas.hansson@arm.com 51811284Sandreas.hansson@arm.com // remember if a cache has already committed to responding so we 51911284Sandreas.hansson@arm.com // can see if it changes during the snooping 52011284Sandreas.hansson@arm.com const bool cache_responding = pkt->cacheResponding(); 5219032SN/A 52211127Sandreas.hansson@arm.com assert(pkt->snoopDelay == 0); 52311127Sandreas.hansson@arm.com 52410402SN/A if (snoopFilter) { 52510402SN/A // let the Snoop Filter work its magic and guide probing 52610402SN/A auto sf_res = snoopFilter->lookupSnoop(pkt); 52711126Sandreas.hansson@arm.com // the time required by a packet to be delivered through 52811126Sandreas.hansson@arm.com // the xbar has to be charged also with to lookup latency 52911126Sandreas.hansson@arm.com // of the snoop filter 53011126Sandreas.hansson@arm.com pkt->headerDelay += sf_res.second * clockPeriod(); 53111744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s SF size: %i lat: %i\n", 53211744Snikos.nikoleris@arm.com __func__, masterPorts[master_port_id]->name(), pkt->print(), 53311744Snikos.nikoleris@arm.com sf_res.first.size(), sf_res.second); 53410402SN/A 53510402SN/A // forward to all snoopers 53610402SN/A forwardTiming(pkt, InvalidPortID, sf_res.first); 53710402SN/A } else { 53810402SN/A forwardTiming(pkt, InvalidPortID); 53910402SN/A } 5408975SN/A 54111127Sandreas.hansson@arm.com // add the snoop delay to our header delay, and then reset it 54211127Sandreas.hansson@arm.com pkt->headerDelay += pkt->snoopDelay; 54311127Sandreas.hansson@arm.com pkt->snoopDelay = 0; 54411127Sandreas.hansson@arm.com 54510656Sandreas.hansson@arm.com // if we can expect a response, remember how to route it 54611284Sandreas.hansson@arm.com if (!cache_responding && pkt->cacheResponding()) { 54710656Sandreas.hansson@arm.com assert(routeTo.find(pkt->req) == routeTo.end()); 54810656Sandreas.hansson@arm.com routeTo[pkt->req] = master_port_id; 54910656Sandreas.hansson@arm.com } 55010656Sandreas.hansson@arm.com 5518975SN/A // a snoop request came from a connected slave device (one of 5528975SN/A // our master ports), and if it is not coming from the slave 5538975SN/A // device responsible for the address range something is 5548975SN/A // wrong, hence there is nothing further to do as the packet 5558975SN/A // would be going back to where it came from 5569032SN/A assert(master_port_id == findPort(pkt->getAddr())); 5578975SN/A} 5588975SN/A 5598975SN/Abool 56010405Sandreas.hansson@arm.comCoherentXBar::recvTimingSnoopResp(PacketPtr pkt, PortID slave_port_id) 5618975SN/A{ 5628975SN/A // determine the source port based on the id 5639032SN/A SlavePort* src_port = slavePorts[slave_port_id]; 5648975SN/A 56510656Sandreas.hansson@arm.com // get the destination 56610656Sandreas.hansson@arm.com const auto route_lookup = routeTo.find(pkt->req); 56710656Sandreas.hansson@arm.com assert(route_lookup != routeTo.end()); 56810656Sandreas.hansson@arm.com const PortID dest_port_id = route_lookup->second; 56910572Sandreas.hansson@arm.com assert(dest_port_id != InvalidPortID); 5709714SN/A 5719714SN/A // determine if the response is from a snoop request we 5729714SN/A // created as the result of a normal request (in which case it 57310656Sandreas.hansson@arm.com // should be in the outstandingSnoop), or if we merely forwarded 5749714SN/A // someone else's snoop request 57510656Sandreas.hansson@arm.com const bool forwardAsSnoop = outstandingSnoop.find(pkt->req) == 57610656Sandreas.hansson@arm.com outstandingSnoop.end(); 5779714SN/A 57810405Sandreas.hansson@arm.com // test if the crossbar should be considered occupied for the 57910405Sandreas.hansson@arm.com // current port, note that the check is bypassed if the response 58010405Sandreas.hansson@arm.com // is being passed on as a normal response since this is occupying 58110405Sandreas.hansson@arm.com // the response layer rather than the snoop response layer 5829715SN/A if (forwardAsSnoop) { 58310572Sandreas.hansson@arm.com assert(dest_port_id < snoopLayers.size()); 5849715SN/A if (!snoopLayers[dest_port_id]->tryTiming(src_port)) { 58511744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s BUSY\n", __func__, 58611744Snikos.nikoleris@arm.com src_port->name(), pkt->print()); 5879715SN/A return false; 5889715SN/A } 5899716SN/A } else { 5909716SN/A // get the master port that mirrors this slave port internally 5919716SN/A MasterPort* snoop_port = snoopRespPorts[slave_port_id]; 59210572Sandreas.hansson@arm.com assert(dest_port_id < respLayers.size()); 5939716SN/A if (!respLayers[dest_port_id]->tryTiming(snoop_port)) { 59411744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s BUSY\n", __func__, 59511744Snikos.nikoleris@arm.com snoop_port->name(), pkt->print()); 5969716SN/A return false; 5979716SN/A } 5988975SN/A } 5998975SN/A 60011744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__, 60111744Snikos.nikoleris@arm.com src_port->name(), pkt->print()); 6028975SN/A 6039712SN/A // store size and command as they might be modified when 6049712SN/A // forwarding the packet 6059712SN/A unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0; 6069712SN/A unsigned int pkt_cmd = pkt->cmdToIndex(); 6079712SN/A 6088975SN/A // responses are never express snoops 6098975SN/A assert(!pkt->isExpressSnoop()); 6108975SN/A 61110719SMarco.Balboni@ARM.com // a snoop response sees the snoop response latency, and if it is 61210719SMarco.Balboni@ARM.com // forwarded as a normal response, the response latency 61310719SMarco.Balboni@ARM.com Tick xbar_delay = 61410719SMarco.Balboni@ARM.com (forwardAsSnoop ? snoopResponseLatency : responseLatency) * 61510719SMarco.Balboni@ARM.com clockPeriod(); 61610719SMarco.Balboni@ARM.com 61710719SMarco.Balboni@ARM.com // set the packet header and payload delay 61810719SMarco.Balboni@ARM.com calcPacketTiming(pkt, xbar_delay); 61910719SMarco.Balboni@ARM.com 62010719SMarco.Balboni@ARM.com // determine how long to be crossbar layer is busy 62110719SMarco.Balboni@ARM.com Tick packetFinishTime = clockEdge(Cycles(1)) + pkt->payloadDelay; 6228975SN/A 6239714SN/A // forward it either as a snoop response or a normal response 6249714SN/A if (forwardAsSnoop) { 6259714SN/A // this is a snoop response to a snoop request we forwarded, 6269714SN/A // e.g. coming from the L1 and going to the L2, and it should 6279714SN/A // be forwarded as a snoop response 62810402SN/A 62910402SN/A if (snoopFilter) { 63010402SN/A // update the probe filter so that it can properly track the line 63110402SN/A snoopFilter->updateSnoopForward(pkt, *slavePorts[slave_port_id], 63210402SN/A *masterPorts[dest_port_id]); 63310402SN/A } 63410402SN/A 6359712SN/A bool success M5_VAR_USED = 6369712SN/A masterPorts[dest_port_id]->sendTimingSnoopResp(pkt); 6379712SN/A pktCount[slave_port_id][dest_port_id]++; 63810405Sandreas.hansson@arm.com pktSize[slave_port_id][dest_port_id] += pkt_size; 6398975SN/A assert(success); 6409714SN/A 6419715SN/A snoopLayers[dest_port_id]->succeededTiming(packetFinishTime); 6423244SN/A } else { 6438975SN/A // we got a snoop response on one of our slave ports, 64410405Sandreas.hansson@arm.com // i.e. from a coherent master connected to the crossbar, and 64510405Sandreas.hansson@arm.com // since we created the snoop request as part of recvTiming, 64610405Sandreas.hansson@arm.com // this should now be a normal response again 64710656Sandreas.hansson@arm.com outstandingSnoop.erase(pkt->req); 6488948SN/A 64910656Sandreas.hansson@arm.com // this is a snoop response from a coherent master, hence it 65010656Sandreas.hansson@arm.com // should never go back to where the snoop response came from, 65110656Sandreas.hansson@arm.com // but instead to where the original request came from 6529712SN/A assert(slave_port_id != dest_port_id); 6538948SN/A 65410402SN/A if (snoopFilter) { 65510402SN/A // update the probe filter so that it can properly track the line 65610402SN/A snoopFilter->updateSnoopResponse(pkt, *slavePorts[slave_port_id], 65710402SN/A *slavePorts[dest_port_id]); 65810402SN/A } 65910402SN/A 66011744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s FWD RESP\n", __func__, 66111744Snikos.nikoleris@arm.com src_port->name(), pkt->print()); 66210402SN/A 6639714SN/A // as a normal response, it should go back to a master through 66410888Sandreas.hansson@arm.com // one of our slave ports, we also pay for any outstanding 66510888Sandreas.hansson@arm.com // header latency 66610888Sandreas.hansson@arm.com Tick latency = pkt->headerDelay; 66710888Sandreas.hansson@arm.com pkt->headerDelay = 0; 66810888Sandreas.hansson@arm.com slavePorts[dest_port_id]->schedTimingResp(pkt, curTick() + latency); 6699716SN/A 6709716SN/A respLayers[dest_port_id]->succeededTiming(packetFinishTime); 6713244SN/A } 6723244SN/A 67310656Sandreas.hansson@arm.com // remove the request from the routing table 67410656Sandreas.hansson@arm.com routeTo.erase(route_lookup); 67510656Sandreas.hansson@arm.com 6769712SN/A // stats updates 6779712SN/A transDist[pkt_cmd]++; 67810405Sandreas.hansson@arm.com snoops++; 67911564Sdavid.guillen@arm.com snoopTraffic += pkt_size; 6809712SN/A 6818948SN/A return true; 6828948SN/A} 6838948SN/A 6843210SN/A 6858948SN/Avoid 68610405Sandreas.hansson@arm.comCoherentXBar::forwardTiming(PacketPtr pkt, PortID exclude_slave_port_id, 68710888Sandreas.hansson@arm.com const std::vector<QueuedSlavePort*>& dests) 6888948SN/A{ 68911744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s for %s\n", __func__, pkt->print()); 6909663SN/A 6919524SN/A // snoops should only happen if the system isn't bypassing caches 6929524SN/A assert(!system->bypassCaches()); 6939524SN/A 69410401SN/A unsigned fanout = 0; 69510401SN/A 69610405Sandreas.hansson@arm.com for (const auto& p: dests) { 6978948SN/A // we could have gotten this request from a snooping master 6988948SN/A // (corresponding to our own slave port that is also in 6998948SN/A // snoopPorts) and should not send it back to where it came 7008948SN/A // from 7019031SN/A if (exclude_slave_port_id == InvalidPortID || 7028948SN/A p->getId() != exclude_slave_port_id) { 7038948SN/A // cache is not allowed to refuse snoop 7048975SN/A p->sendTimingSnoopReq(pkt); 70510401SN/A fanout++; 7068948SN/A } 7078948SN/A } 70810401SN/A 70910401SN/A // Stats for fanout of this forward operation 71010401SN/A snoopFanout.sample(fanout); 7112497SN/A} 7122497SN/A 7139092SN/Avoid 71410713Sandreas.hansson@arm.comCoherentXBar::recvReqRetry(PortID master_port_id) 7159092SN/A{ 7169093SN/A // responses and snoop responses never block on forwarding them, 7179093SN/A // so the retry will always be coming from a port to which we 7189093SN/A // tried to forward a request 7199715SN/A reqLayers[master_port_id]->recvRetry(); 7209092SN/A} 7219092SN/A 7229036SN/ATick 72310405Sandreas.hansson@arm.comCoherentXBar::recvAtomic(PacketPtr pkt, PortID slave_port_id) 7242657SN/A{ 72511744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__, 72611744Snikos.nikoleris@arm.com slavePorts[slave_port_id]->name(), pkt->print()); 7278915SN/A 72810405Sandreas.hansson@arm.com unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0; 72910405Sandreas.hansson@arm.com unsigned int pkt_cmd = pkt->cmdToIndex(); 7309712SN/A 7318979SN/A MemCmd snoop_response_cmd = MemCmd::InvalidCmd; 7328979SN/A Tick snoop_response_latency = 0; 7338979SN/A 73412346Snikos.nikoleris@arm.com // is this the destination point for this packet? (e.g. true if 73512346Snikos.nikoleris@arm.com // this xbar is the PoC for a cache maintenance operation to the 73612346Snikos.nikoleris@arm.com // PoC) otherwise the destination is any cache that can satisfy 73712346Snikos.nikoleris@arm.com // the request 73812346Snikos.nikoleris@arm.com const bool is_destination = isDestination(pkt); 73912346Snikos.nikoleris@arm.com 74012345Snikos.nikoleris@arm.com const bool snoop_caches = !system->bypassCaches() && 74112345Snikos.nikoleris@arm.com pkt->cmd != MemCmd::WriteClean; 74212345Snikos.nikoleris@arm.com if (snoop_caches) { 7438979SN/A // forward to all snoopers but the source 74410402SN/A std::pair<MemCmd, Tick> snoop_result; 74510402SN/A if (snoopFilter) { 74610402SN/A // check with the snoop filter where to forward this packet 74710402SN/A auto sf_res = 74810402SN/A snoopFilter->lookupRequest(pkt, *slavePorts[slave_port_id]); 74910402SN/A snoop_response_latency += sf_res.second * clockPeriod(); 75011744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s SF size: %i lat: %i\n", 75111744Snikos.nikoleris@arm.com __func__, slavePorts[slave_port_id]->name(), pkt->print(), 75211744Snikos.nikoleris@arm.com sf_res.first.size(), sf_res.second); 75311130Sali.jafri@arm.com 75411130Sali.jafri@arm.com // let the snoop filter know about the success of the send 75511130Sali.jafri@arm.com // operation, and do it even before sending it onwards to 75611130Sali.jafri@arm.com // avoid situations where atomic upward snoops sneak in 75711130Sali.jafri@arm.com // between and change the filter state 75811605Snikos.nikoleris@arm.com snoopFilter->finishRequest(false, pkt->getAddr(), pkt->isSecure()); 75911130Sali.jafri@arm.com 76012241Snikos.nikoleris@arm.com if (pkt->isEviction()) { 76112241Snikos.nikoleris@arm.com // for block-evicting packets, i.e. writebacks and 76212241Snikos.nikoleris@arm.com // clean evictions, there is no need to snoop up, as 76312241Snikos.nikoleris@arm.com // all we do is determine if the block is cached or 76412241Snikos.nikoleris@arm.com // not, instead just set it here based on the snoop 76512241Snikos.nikoleris@arm.com // filter result 76612241Snikos.nikoleris@arm.com if (!sf_res.first.empty()) 76712241Snikos.nikoleris@arm.com pkt->setBlockCached(); 76812241Snikos.nikoleris@arm.com } else { 76912241Snikos.nikoleris@arm.com snoop_result = forwardAtomic(pkt, slave_port_id, InvalidPortID, 77012241Snikos.nikoleris@arm.com sf_res.first); 77112241Snikos.nikoleris@arm.com } 77210402SN/A } else { 77310402SN/A snoop_result = forwardAtomic(pkt, slave_port_id); 77410402SN/A } 7758979SN/A snoop_response_cmd = snoop_result.first; 77610402SN/A snoop_response_latency += snoop_result.second; 7778979SN/A } 7788915SN/A 77911334Sandreas.hansson@arm.com // set up a sensible default value 78011334Sandreas.hansson@arm.com Tick response_latency = 0; 78111334Sandreas.hansson@arm.com 78211334Sandreas.hansson@arm.com const bool sink_packet = sinkPacket(pkt); 78311130Sali.jafri@arm.com 7848948SN/A // even if we had a snoop response, we must continue and also 7858948SN/A // perform the actual request at the destination 78610405Sandreas.hansson@arm.com PortID master_port_id = findPort(pkt->getAddr()); 78710405Sandreas.hansson@arm.com 78811334Sandreas.hansson@arm.com if (sink_packet) { 78911744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: Not forwarding %s\n", __func__, 79011744Snikos.nikoleris@arm.com pkt->print()); 79111334Sandreas.hansson@arm.com } else { 79212346Snikos.nikoleris@arm.com if (forwardPacket(pkt)) { 79312346Snikos.nikoleris@arm.com // make sure that the write request (e.g., WriteClean) 79412346Snikos.nikoleris@arm.com // will stop at the memory below if this crossbar is its 79512346Snikos.nikoleris@arm.com // destination 79612346Snikos.nikoleris@arm.com if (pkt->isWrite() && is_destination) { 79712346Snikos.nikoleris@arm.com pkt->clearWriteThrough(); 79812346Snikos.nikoleris@arm.com } 79912346Snikos.nikoleris@arm.com 80011334Sandreas.hansson@arm.com // forward the request to the appropriate destination 80111334Sandreas.hansson@arm.com response_latency = masterPorts[master_port_id]->sendAtomic(pkt); 80211334Sandreas.hansson@arm.com } else { 80311334Sandreas.hansson@arm.com // if it does not need a response we sink the packet above 80411334Sandreas.hansson@arm.com assert(pkt->needsResponse()); 80511334Sandreas.hansson@arm.com 80611334Sandreas.hansson@arm.com pkt->makeResponse(); 80711334Sandreas.hansson@arm.com } 80811334Sandreas.hansson@arm.com } 80911334Sandreas.hansson@arm.com 81010405Sandreas.hansson@arm.com // stats updates for the request 81110405Sandreas.hansson@arm.com pktCount[slave_port_id][master_port_id]++; 81210405Sandreas.hansson@arm.com pktSize[slave_port_id][master_port_id] += pkt_size; 81310405Sandreas.hansson@arm.com transDist[pkt_cmd]++; 8148948SN/A 8158948SN/A 81611130Sali.jafri@arm.com // if lower levels have replied, tell the snoop filter 81711130Sali.jafri@arm.com if (!system->bypassCaches() && snoopFilter && pkt->isResponse()) { 81810402SN/A snoopFilter->updateResponse(pkt, *slavePorts[slave_port_id]); 81910402SN/A } 82010402SN/A 8218948SN/A // if we got a response from a snooper, restore it here 8228948SN/A if (snoop_response_cmd != MemCmd::InvalidCmd) { 8238948SN/A // no one else should have responded 8248948SN/A assert(!pkt->isResponse()); 8258948SN/A pkt->cmd = snoop_response_cmd; 8268948SN/A response_latency = snoop_response_latency; 8278948SN/A } 8288948SN/A 82912351Snikos.nikoleris@arm.com // If this is the destination of the cache clean operation the 83012351Snikos.nikoleris@arm.com // crossbar is responsible for responding. This crossbar will 83112351Snikos.nikoleris@arm.com // respond when the cache clean is complete. An atomic cache clean 83212351Snikos.nikoleris@arm.com // is complete when the crossbars receives the cache clean 83312351Snikos.nikoleris@arm.com // request (CleanSharedReq, CleanInvalidReq), as either: 83412351Snikos.nikoleris@arm.com // * no cache above had a dirty copy of the block as indicated by 83512351Snikos.nikoleris@arm.com // the satisfied flag of the packet, or 83612351Snikos.nikoleris@arm.com // * the crossbar has already seen the corresponding write 83712351Snikos.nikoleris@arm.com // (WriteClean) which updates the block in the memory below. 83812351Snikos.nikoleris@arm.com if (pkt->isClean() && isDestination(pkt) && pkt->satisfied()) { 83912351Snikos.nikoleris@arm.com auto it = outstandingCMO.find(pkt->id); 84012351Snikos.nikoleris@arm.com assert(it != outstandingCMO.end()); 84112351Snikos.nikoleris@arm.com // we are responding right away 84212351Snikos.nikoleris@arm.com outstandingCMO.erase(it); 84312351Snikos.nikoleris@arm.com } else if (pkt->cmd == MemCmd::WriteClean && isDestination(pkt)) { 84412351Snikos.nikoleris@arm.com // if this is the destination of the operation, the xbar 84512351Snikos.nikoleris@arm.com // sends the responce to the cache clean operation only 84612351Snikos.nikoleris@arm.com // after having encountered the cache clean request 84712351Snikos.nikoleris@arm.com auto M5_VAR_USED ret = outstandingCMO.emplace(pkt->id, nullptr); 84812351Snikos.nikoleris@arm.com // in atomic mode we know that the WriteClean packet should 84912351Snikos.nikoleris@arm.com // precede the clean request 85012351Snikos.nikoleris@arm.com assert(ret.second); 85112351Snikos.nikoleris@arm.com } 85212351Snikos.nikoleris@arm.com 8539712SN/A // add the response data 85410405Sandreas.hansson@arm.com if (pkt->isResponse()) { 85510405Sandreas.hansson@arm.com pkt_size = pkt->hasData() ? pkt->getSize() : 0; 85610405Sandreas.hansson@arm.com pkt_cmd = pkt->cmdToIndex(); 85710405Sandreas.hansson@arm.com 85810405Sandreas.hansson@arm.com // stats updates 85910405Sandreas.hansson@arm.com pktCount[slave_port_id][master_port_id]++; 86010405Sandreas.hansson@arm.com pktSize[slave_port_id][master_port_id] += pkt_size; 86110405Sandreas.hansson@arm.com transDist[pkt_cmd]++; 86210405Sandreas.hansson@arm.com } 8639712SN/A 86410694SMarco.Balboni@ARM.com // @todo: Not setting header time 86510694SMarco.Balboni@ARM.com pkt->payloadDelay = response_latency; 8668948SN/A return response_latency; 8678948SN/A} 8688948SN/A 8698948SN/ATick 87010405Sandreas.hansson@arm.comCoherentXBar::recvAtomicSnoop(PacketPtr pkt, PortID master_port_id) 8718948SN/A{ 87211744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__, 87311744Snikos.nikoleris@arm.com masterPorts[master_port_id]->name(), pkt->print()); 8748948SN/A 8759712SN/A // add the request snoop data 87611564Sdavid.guillen@arm.com unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0; 87710405Sandreas.hansson@arm.com snoops++; 87811564Sdavid.guillen@arm.com snoopTraffic += pkt_size; 8799712SN/A 8808948SN/A // forward to all snoopers 88110402SN/A std::pair<MemCmd, Tick> snoop_result; 88210402SN/A Tick snoop_response_latency = 0; 88310402SN/A if (snoopFilter) { 88410402SN/A auto sf_res = snoopFilter->lookupSnoop(pkt); 88510402SN/A snoop_response_latency += sf_res.second * clockPeriod(); 88611744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s SF size: %i lat: %i\n", 88711744Snikos.nikoleris@arm.com __func__, masterPorts[master_port_id]->name(), pkt->print(), 88811744Snikos.nikoleris@arm.com sf_res.first.size(), sf_res.second); 88910402SN/A snoop_result = forwardAtomic(pkt, InvalidPortID, master_port_id, 89010402SN/A sf_res.first); 89110402SN/A } else { 89210402SN/A snoop_result = forwardAtomic(pkt, InvalidPortID); 89310402SN/A } 8948948SN/A MemCmd snoop_response_cmd = snoop_result.first; 89510402SN/A snoop_response_latency += snoop_result.second; 8968948SN/A 8978948SN/A if (snoop_response_cmd != MemCmd::InvalidCmd) 8988948SN/A pkt->cmd = snoop_response_cmd; 8998948SN/A 9009712SN/A // add the response snoop data 90110401SN/A if (pkt->isResponse()) { 90210405Sandreas.hansson@arm.com snoops++; 90310401SN/A } 9049712SN/A 90510694SMarco.Balboni@ARM.com // @todo: Not setting header time 90610694SMarco.Balboni@ARM.com pkt->payloadDelay = snoop_response_latency; 9078948SN/A return snoop_response_latency; 9088948SN/A} 9098948SN/A 9108948SN/Astd::pair<MemCmd, Tick> 91110405Sandreas.hansson@arm.comCoherentXBar::forwardAtomic(PacketPtr pkt, PortID exclude_slave_port_id, 91210402SN/A PortID source_master_port_id, 91310888Sandreas.hansson@arm.com const std::vector<QueuedSlavePort*>& dests) 9148948SN/A{ 9159032SN/A // the packet may be changed on snoops, record the original 9169032SN/A // command to enable us to restore it between snoops so that 9178948SN/A // additional snoops can take place properly 9184626SN/A MemCmd orig_cmd = pkt->cmd; 9194879SN/A MemCmd snoop_response_cmd = MemCmd::InvalidCmd; 9204879SN/A Tick snoop_response_latency = 0; 9213662SN/A 9229524SN/A // snoops should only happen if the system isn't bypassing caches 9239524SN/A assert(!system->bypassCaches()); 9249524SN/A 92510401SN/A unsigned fanout = 0; 92610401SN/A 92710405Sandreas.hansson@arm.com for (const auto& p: dests) { 9288915SN/A // we could have gotten this request from a snooping master 9298915SN/A // (corresponding to our own slave port that is also in 9308915SN/A // snoopPorts) and should not send it back to where it came 9318915SN/A // from 93210402SN/A if (exclude_slave_port_id != InvalidPortID && 93310402SN/A p->getId() == exclude_slave_port_id) 93410402SN/A continue; 93510401SN/A 93610402SN/A Tick latency = p->sendAtomicSnoop(pkt); 93710402SN/A fanout++; 93810402SN/A 93910402SN/A // in contrast to a functional access, we have to keep on 94010402SN/A // going as all snoopers must be updated even if we get a 94110402SN/A // response 94210402SN/A if (!pkt->isResponse()) 94310402SN/A continue; 94410402SN/A 94510402SN/A // response from snoop agent 94610402SN/A assert(pkt->cmd != orig_cmd); 94711284Sandreas.hansson@arm.com assert(pkt->cacheResponding()); 94810402SN/A // should only happen once 94910402SN/A assert(snoop_response_cmd == MemCmd::InvalidCmd); 95010402SN/A // save response state 95110402SN/A snoop_response_cmd = pkt->cmd; 95210402SN/A snoop_response_latency = latency; 95310402SN/A 95410402SN/A if (snoopFilter) { 95510402SN/A // Handle responses by the snoopers and differentiate between 95610402SN/A // responses to requests from above and snoops from below 95710402SN/A if (source_master_port_id != InvalidPortID) { 95810402SN/A // Getting a response for a snoop from below 95910402SN/A assert(exclude_slave_port_id == InvalidPortID); 96010402SN/A snoopFilter->updateSnoopForward(pkt, *p, 96110402SN/A *masterPorts[source_master_port_id]); 96210402SN/A } else { 96310402SN/A // Getting a response for a request from above 96410402SN/A assert(source_master_port_id == InvalidPortID); 96510402SN/A snoopFilter->updateSnoopResponse(pkt, *p, 96610402SN/A *slavePorts[exclude_slave_port_id]); 9674626SN/A } 9684626SN/A } 96910402SN/A // restore original packet state for remaining snoopers 97010402SN/A pkt->cmd = orig_cmd; 9714626SN/A } 9724626SN/A 97310401SN/A // Stats for fanout 97410401SN/A snoopFanout.sample(fanout); 97510401SN/A 9768948SN/A // the packet is restored as part of the loop and any potential 9778948SN/A // snoop response is part of the returned pair 9788948SN/A return std::make_pair(snoop_response_cmd, snoop_response_latency); 9792497SN/A} 9802497SN/A 9812497SN/Avoid 98210405Sandreas.hansson@arm.comCoherentXBar::recvFunctional(PacketPtr pkt, PortID slave_port_id) 9832497SN/A{ 9848663SN/A if (!pkt->isPrint()) { 9858663SN/A // don't do DPRINTFs on PrintReq as it clutters up the output 98611744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__, 98711744Snikos.nikoleris@arm.com slavePorts[slave_port_id]->name(), pkt->print()); 9888663SN/A } 9898663SN/A 99010821Sandreas.hansson@arm.com if (!system->bypassCaches()) { 9918979SN/A // forward to all snoopers but the source 9929032SN/A forwardFunctional(pkt, slave_port_id); 9938979SN/A } 9944912SN/A 9958948SN/A // there is no need to continue if the snooping has found what we 9968948SN/A // were looking for and the packet is already a response 9978948SN/A if (!pkt->isResponse()) { 99810888Sandreas.hansson@arm.com // since our slave ports are queued ports we need to check them as well 99910888Sandreas.hansson@arm.com for (const auto& p : slavePorts) { 100010888Sandreas.hansson@arm.com // if we find a response that has the data, then the 100110888Sandreas.hansson@arm.com // downstream caches/memories may be out of date, so simply stop 100210888Sandreas.hansson@arm.com // here 100310888Sandreas.hansson@arm.com if (p->checkFunctional(pkt)) { 100410888Sandreas.hansson@arm.com if (pkt->needsResponse()) 100510888Sandreas.hansson@arm.com pkt->makeResponse(); 100610888Sandreas.hansson@arm.com return; 100710888Sandreas.hansson@arm.com } 100810888Sandreas.hansson@arm.com } 100910888Sandreas.hansson@arm.com 10109031SN/A PortID dest_id = findPort(pkt->getAddr()); 10118948SN/A 10128948SN/A masterPorts[dest_id]->sendFunctional(pkt); 10138948SN/A } 10148948SN/A} 10158948SN/A 10168948SN/Avoid 101710405Sandreas.hansson@arm.comCoherentXBar::recvFunctionalSnoop(PacketPtr pkt, PortID master_port_id) 10188948SN/A{ 10198948SN/A if (!pkt->isPrint()) { 10208948SN/A // don't do DPRINTFs on PrintReq as it clutters up the output 102111744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__, 102211744Snikos.nikoleris@arm.com masterPorts[master_port_id]->name(), pkt->print()); 10238948SN/A } 10248948SN/A 102511188Sandreas.sandberg@arm.com for (const auto& p : slavePorts) { 102611188Sandreas.sandberg@arm.com if (p->checkFunctional(pkt)) { 102711188Sandreas.sandberg@arm.com if (pkt->needsResponse()) 102811188Sandreas.sandberg@arm.com pkt->makeResponse(); 102911188Sandreas.sandberg@arm.com return; 103011188Sandreas.sandberg@arm.com } 103111188Sandreas.sandberg@arm.com } 103211188Sandreas.sandberg@arm.com 10338948SN/A // forward to all snoopers 10349031SN/A forwardFunctional(pkt, InvalidPortID); 10358948SN/A} 10368948SN/A 10378948SN/Avoid 103810405Sandreas.hansson@arm.comCoherentXBar::forwardFunctional(PacketPtr pkt, PortID exclude_slave_port_id) 10398948SN/A{ 10409524SN/A // snoops should only happen if the system isn't bypassing caches 10419524SN/A assert(!system->bypassCaches()); 10429524SN/A 104310405Sandreas.hansson@arm.com for (const auto& p: snoopPorts) { 10448915SN/A // we could have gotten this request from a snooping master 10458915SN/A // (corresponding to our own slave port that is also in 10468915SN/A // snoopPorts) and should not send it back to where it came 10478915SN/A // from 10489031SN/A if (exclude_slave_port_id == InvalidPortID || 10498948SN/A p->getId() != exclude_slave_port_id) 10508948SN/A p->sendFunctionalSnoop(pkt); 10518915SN/A 10528948SN/A // if we get a response we are done 10538948SN/A if (pkt->isResponse()) { 10548948SN/A break; 10558915SN/A } 10563650SN/A } 10572497SN/A} 10582497SN/A 105911334Sandreas.hansson@arm.combool 106011334Sandreas.hansson@arm.comCoherentXBar::sinkPacket(const PacketPtr pkt) const 106111334Sandreas.hansson@arm.com{ 106211334Sandreas.hansson@arm.com // we can sink the packet if: 106311334Sandreas.hansson@arm.com // 1) the crossbar is the point of coherency, and a cache is 106411334Sandreas.hansson@arm.com // responding after being snooped 106511334Sandreas.hansson@arm.com // 2) the crossbar is the point of coherency, and the packet is a 106611334Sandreas.hansson@arm.com // coherency packet (not a read or a write) that does not 106711334Sandreas.hansson@arm.com // require a response 106811334Sandreas.hansson@arm.com // 3) this is a clean evict or clean writeback, but the packet is 106911334Sandreas.hansson@arm.com // found in a cache above this crossbar 107011334Sandreas.hansson@arm.com // 4) a cache is responding after being snooped, and the packet 107111334Sandreas.hansson@arm.com // either does not need the block to be writable, or the cache 107211334Sandreas.hansson@arm.com // that has promised to respond (setting the cache responding 107311334Sandreas.hansson@arm.com // flag) is providing writable and thus had a Modified block, 107411334Sandreas.hansson@arm.com // and no further action is needed 107511334Sandreas.hansson@arm.com return (pointOfCoherency && pkt->cacheResponding()) || 107611334Sandreas.hansson@arm.com (pointOfCoherency && !(pkt->isRead() || pkt->isWrite()) && 107711334Sandreas.hansson@arm.com !pkt->needsResponse()) || 107811334Sandreas.hansson@arm.com (pkt->isCleanEviction() && pkt->isBlockCached()) || 107911334Sandreas.hansson@arm.com (pkt->cacheResponding() && 108011334Sandreas.hansson@arm.com (!pkt->needsWritable() || pkt->responderHadWritable())); 108111334Sandreas.hansson@arm.com} 108211334Sandreas.hansson@arm.com 108312346Snikos.nikoleris@arm.combool 108412346Snikos.nikoleris@arm.comCoherentXBar::forwardPacket(const PacketPtr pkt) 108512346Snikos.nikoleris@arm.com{ 108612346Snikos.nikoleris@arm.com // we are forwarding the packet if: 108712351Snikos.nikoleris@arm.com // 1) this is a cache clean request to the PoU/PoC and this 108812351Snikos.nikoleris@arm.com // crossbar is above the PoU/PoC 108912351Snikos.nikoleris@arm.com // 2) this is a read or a write 109012351Snikos.nikoleris@arm.com // 3) this crossbar is above the point of coherency 109112351Snikos.nikoleris@arm.com if (pkt->isClean()) { 109212351Snikos.nikoleris@arm.com return !isDestination(pkt); 109312351Snikos.nikoleris@arm.com } 109412346Snikos.nikoleris@arm.com return pkt->isRead() || pkt->isWrite() || !pointOfCoherency; 109512346Snikos.nikoleris@arm.com} 109612346Snikos.nikoleris@arm.com 109712346Snikos.nikoleris@arm.com 10989712SN/Avoid 109910405Sandreas.hansson@arm.comCoherentXBar::regStats() 11009712SN/A{ 110110405Sandreas.hansson@arm.com // register the stats of the base class and our layers 110210405Sandreas.hansson@arm.com BaseXBar::regStats(); 110310405Sandreas.hansson@arm.com for (auto l: reqLayers) 110410405Sandreas.hansson@arm.com l->regStats(); 110510405Sandreas.hansson@arm.com for (auto l: respLayers) 110610405Sandreas.hansson@arm.com l->regStats(); 110710405Sandreas.hansson@arm.com for (auto l: snoopLayers) 110810405Sandreas.hansson@arm.com l->regStats(); 11099712SN/A 111010405Sandreas.hansson@arm.com snoops 111110405Sandreas.hansson@arm.com .name(name() + ".snoops") 111210401SN/A .desc("Total snoops (count)") 111310401SN/A ; 111410401SN/A 111511564Sdavid.guillen@arm.com snoopTraffic 111611564Sdavid.guillen@arm.com .name(name() + ".snoopTraffic") 111711564Sdavid.guillen@arm.com .desc("Total snoop traffic (bytes)") 111811564Sdavid.guillen@arm.com ; 111911564Sdavid.guillen@arm.com 112010401SN/A snoopFanout 112110401SN/A .init(0, snoopPorts.size(), 1) 112210401SN/A .name(name() + ".snoop_fanout") 112310401SN/A .desc("Request fanout histogram") 112410401SN/A ; 11259712SN/A} 11269712SN/A 112710405Sandreas.hansson@arm.comCoherentXBar * 112810405Sandreas.hansson@arm.comCoherentXBarParams::create() 11292497SN/A{ 113010405Sandreas.hansson@arm.com return new CoherentXBar(this); 11312497SN/A} 1132