coherent_xbar.cc revision 11744
12497SN/A/* 211605Snikos.nikoleris@arm.com * Copyright (c) 2011-2016 ARM Limited 38711SN/A * All rights reserved 48711SN/A * 58711SN/A * The license below extends only to copyright in the software and shall 68711SN/A * not be construed as granting a license to any other intellectual 78711SN/A * property including but not limited to intellectual property relating 88711SN/A * to a hardware implementation of the functionality of the software 98711SN/A * licensed hereunder. You may use the software subject to the license 108711SN/A * terms below provided that you ensure that this notice is replicated 118711SN/A * unmodified and in its entirety in all distributions of the software, 128711SN/A * modified or unmodified, in source code or in binary form. 138711SN/A * 142497SN/A * Copyright (c) 2006 The Regents of The University of Michigan 152497SN/A * All rights reserved. 162497SN/A * 172497SN/A * Redistribution and use in source and binary forms, with or without 182497SN/A * modification, are permitted provided that the following conditions are 192497SN/A * met: redistributions of source code must retain the above copyright 202497SN/A * notice, this list of conditions and the following disclaimer; 212497SN/A * redistributions in binary form must reproduce the above copyright 222497SN/A * notice, this list of conditions and the following disclaimer in the 232497SN/A * documentation and/or other materials provided with the distribution; 242497SN/A * neither the name of the copyright holders nor the names of its 252497SN/A * contributors may be used to endorse or promote products derived from 262497SN/A * this software without specific prior written permission. 272497SN/A * 282497SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 292497SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 302497SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 312497SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 322497SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 332497SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 342497SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 352497SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 362497SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 372497SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 382497SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392665SN/A * 402665SN/A * Authors: Ali Saidi 418715SN/A * Andreas Hansson 428922SN/A * William Wang 432497SN/A */ 442497SN/A 452497SN/A/** 462982SN/A * @file 4710405Sandreas.hansson@arm.com * Definition of a crossbar object. 482497SN/A */ 492497SN/A 502846SN/A#include "base/misc.hh" 512548SN/A#include "base/trace.hh" 5210405Sandreas.hansson@arm.com#include "debug/AddrRanges.hh" 5310405Sandreas.hansson@arm.com#include "debug/CoherentXBar.hh" 5410405Sandreas.hansson@arm.com#include "mem/coherent_xbar.hh" 559524SN/A#include "sim/system.hh" 562497SN/A 5710405Sandreas.hansson@arm.comCoherentXBar::CoherentXBar(const CoherentXBarParams *p) 5810719SMarco.Balboni@ARM.com : BaseXBar(p), system(p->system), snoopFilter(p->snoop_filter), 5911334Sandreas.hansson@arm.com snoopResponseLatency(p->snoop_response_latency), 6011334Sandreas.hansson@arm.com pointOfCoherency(p->point_of_coherency) 617523SN/A{ 628851SN/A // create the ports based on the size of the master and slave 638948SN/A // vector ports, and the presence of the default port, the ports 648948SN/A // are enumerated starting from zero 658851SN/A for (int i = 0; i < p->port_master_connection_count; ++i) { 669095SN/A std::string portName = csprintf("%s.master[%d]", name(), i); 6710405Sandreas.hansson@arm.com MasterPort* bp = new CoherentXBarMasterPort(portName, *this, i); 688922SN/A masterPorts.push_back(bp); 699715SN/A reqLayers.push_back(new ReqLayer(*bp, *this, 709715SN/A csprintf(".reqLayer%d", i))); 7110713Sandreas.hansson@arm.com snoopLayers.push_back(new SnoopRespLayer(*bp, *this, 7210713Sandreas.hansson@arm.com csprintf(".snoopLayer%d", i))); 738851SN/A } 748851SN/A 758948SN/A // see if we have a default slave device connected and if so add 768948SN/A // our corresponding master port 778915SN/A if (p->port_default_connection_count) { 789031SN/A defaultPortID = masterPorts.size(); 799095SN/A std::string portName = name() + ".default"; 8010405Sandreas.hansson@arm.com MasterPort* bp = new CoherentXBarMasterPort(portName, *this, 819036SN/A defaultPortID); 828922SN/A masterPorts.push_back(bp); 839715SN/A reqLayers.push_back(new ReqLayer(*bp, *this, csprintf(".reqLayer%d", 849715SN/A defaultPortID))); 8510713Sandreas.hansson@arm.com snoopLayers.push_back(new SnoopRespLayer(*bp, *this, 8610713Sandreas.hansson@arm.com csprintf(".snoopLayer%d", 8710713Sandreas.hansson@arm.com defaultPortID))); 888915SN/A } 898915SN/A 908948SN/A // create the slave ports, once again starting at zero 918851SN/A for (int i = 0; i < p->port_slave_connection_count; ++i) { 929095SN/A std::string portName = csprintf("%s.slave[%d]", name(), i); 9310888Sandreas.hansson@arm.com QueuedSlavePort* bp = new CoherentXBarSlavePort(portName, *this, i); 948922SN/A slavePorts.push_back(bp); 959715SN/A respLayers.push_back(new RespLayer(*bp, *this, 969715SN/A csprintf(".respLayer%d", i))); 979716SN/A snoopRespPorts.push_back(new SnoopRespPort(*bp, *this)); 988851SN/A } 998851SN/A 1007523SN/A clearPortCache(); 1017523SN/A} 1027523SN/A 10310405Sandreas.hansson@arm.comCoherentXBar::~CoherentXBar() 1049715SN/A{ 10510405Sandreas.hansson@arm.com for (auto l: reqLayers) 10610405Sandreas.hansson@arm.com delete l; 10710405Sandreas.hansson@arm.com for (auto l: respLayers) 10810405Sandreas.hansson@arm.com delete l; 10910405Sandreas.hansson@arm.com for (auto l: snoopLayers) 11010405Sandreas.hansson@arm.com delete l; 11110405Sandreas.hansson@arm.com for (auto p: snoopRespPorts) 11210405Sandreas.hansson@arm.com delete p; 1139715SN/A} 1149715SN/A 1152568SN/Avoid 11610405Sandreas.hansson@arm.comCoherentXBar::init() 1172568SN/A{ 11810405Sandreas.hansson@arm.com BaseXBar::init(); 1199278SN/A 1208948SN/A // iterate over our slave ports and determine which of our 1218948SN/A // neighbouring master ports are snooping and add them as snoopers 12210405Sandreas.hansson@arm.com for (const auto& p: slavePorts) { 1239088SN/A // check if the connected master port is snooping 12410405Sandreas.hansson@arm.com if (p->isSnooping()) { 12510405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "Adding snooping master %s\n", 12610405Sandreas.hansson@arm.com p->getMasterPort().name()); 12710405Sandreas.hansson@arm.com snoopPorts.push_back(p); 1288711SN/A } 1298711SN/A } 1302568SN/A 1319036SN/A if (snoopPorts.empty()) 13210405Sandreas.hansson@arm.com warn("CoherentXBar %s has no snooping ports attached!\n", name()); 13311133Sandreas.hansson@arm.com 13411133Sandreas.hansson@arm.com // inform the snoop filter about the slave ports so it can create 13511133Sandreas.hansson@arm.com // its own internal representation 13611133Sandreas.hansson@arm.com if (snoopFilter) 13711133Sandreas.hansson@arm.com snoopFilter->setSlavePorts(slavePorts); 1383244SN/A} 1393244SN/A 1408948SN/Abool 14110405Sandreas.hansson@arm.comCoherentXBar::recvTimingReq(PacketPtr pkt, PortID slave_port_id) 1423244SN/A{ 1438975SN/A // determine the source port based on the id 1449032SN/A SlavePort *src_port = slavePorts[slave_port_id]; 1453244SN/A 1469091SN/A // remember if the packet is an express snoop 1479091SN/A bool is_express_snoop = pkt->isExpressSnoop(); 14811284Sandreas.hansson@arm.com bool cache_responding = pkt->cacheResponding(); 14910656Sandreas.hansson@arm.com // for normal requests, going downstream, the express snoop flag 15011284Sandreas.hansson@arm.com // and the cache responding flag should always be the same 15111284Sandreas.hansson@arm.com assert(is_express_snoop == cache_responding); 1529091SN/A 1539612SN/A // determine the destination based on the address 1549712SN/A PortID master_port_id = findPort(pkt->getAddr()); 1559612SN/A 15610405Sandreas.hansson@arm.com // test if the crossbar should be considered occupied for the current 1579033SN/A // port, and exclude express snoops from the check 1589715SN/A if (!is_express_snoop && !reqLayers[master_port_id]->tryTiming(src_port)) { 15911744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s BUSY\n", __func__, 16011744Snikos.nikoleris@arm.com src_port->name(), pkt->print()); 1613244SN/A return false; 1623244SN/A } 1633244SN/A 16411744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__, 16511744Snikos.nikoleris@arm.com src_port->name(), pkt->print()); 1665197SN/A 1679712SN/A // store size and command as they might be modified when 1689712SN/A // forwarding the packet 1699712SN/A unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0; 1709712SN/A unsigned int pkt_cmd = pkt->cmdToIndex(); 1719712SN/A 17210719SMarco.Balboni@ARM.com // store the old header delay so we can restore it if needed 17310719SMarco.Balboni@ARM.com Tick old_header_delay = pkt->headerDelay; 17410719SMarco.Balboni@ARM.com 17510719SMarco.Balboni@ARM.com // a request sees the frontend and forward latency 17610719SMarco.Balboni@ARM.com Tick xbar_delay = (frontendLatency + forwardLatency) * clockPeriod(); 17710719SMarco.Balboni@ARM.com 17810719SMarco.Balboni@ARM.com // set the packet header and payload delay 17910719SMarco.Balboni@ARM.com calcPacketTiming(pkt, xbar_delay); 18010719SMarco.Balboni@ARM.com 18110719SMarco.Balboni@ARM.com // determine how long to be crossbar layer is busy 18210719SMarco.Balboni@ARM.com Tick packetFinishTime = clockEdge(Cycles(1)) + pkt->payloadDelay; 1834912SN/A 18410821Sandreas.hansson@arm.com if (!system->bypassCaches()) { 18511127Sandreas.hansson@arm.com assert(pkt->snoopDelay == 0); 18611127Sandreas.hansson@arm.com 1878979SN/A // the packet is a memory-mapped request and should be 1888979SN/A // broadcasted to our snoopers but the source 18910402SN/A if (snoopFilter) { 19010402SN/A // check with the snoop filter where to forward this packet 19110402SN/A auto sf_res = snoopFilter->lookupRequest(pkt, *src_port); 19211126Sandreas.hansson@arm.com // the time required by a packet to be delivered through 19311126Sandreas.hansson@arm.com // the xbar has to be charged also with to lookup latency 19411126Sandreas.hansson@arm.com // of the snoop filter 19510719SMarco.Balboni@ARM.com pkt->headerDelay += sf_res.second * clockPeriod(); 19611744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s SF size: %i lat: %i\n", 19711744Snikos.nikoleris@arm.com __func__, src_port->name(), pkt->print(), 19811744Snikos.nikoleris@arm.com sf_res.first.size(), sf_res.second); 19911196Sali.jafri@arm.com 20011199Sandreas.hansson@arm.com if (pkt->isEviction()) { 20111196Sali.jafri@arm.com // for block-evicting packets, i.e. writebacks and 20211196Sali.jafri@arm.com // clean evictions, there is no need to snoop up, as 20311196Sali.jafri@arm.com // all we do is determine if the block is cached or 20411196Sali.jafri@arm.com // not, instead just set it here based on the snoop 20511196Sali.jafri@arm.com // filter result 20611196Sali.jafri@arm.com if (!sf_res.first.empty()) 20711196Sali.jafri@arm.com pkt->setBlockCached(); 20811196Sali.jafri@arm.com } else { 20911196Sali.jafri@arm.com forwardTiming(pkt, slave_port_id, sf_res.first); 21011196Sali.jafri@arm.com } 21110402SN/A } else { 21210402SN/A forwardTiming(pkt, slave_port_id); 21310402SN/A } 21411127Sandreas.hansson@arm.com 21511127Sandreas.hansson@arm.com // add the snoop delay to our header delay, and then reset it 21611127Sandreas.hansson@arm.com pkt->headerDelay += pkt->snoopDelay; 21711127Sandreas.hansson@arm.com pkt->snoopDelay = 0; 2188979SN/A } 2198948SN/A 22011334Sandreas.hansson@arm.com // set up a sensible starting point 22111334Sandreas.hansson@arm.com bool success = true; 22210883Sali.jafri@arm.com 22311284Sandreas.hansson@arm.com // remember if the packet will generate a snoop response by 22411284Sandreas.hansson@arm.com // checking if a cache set the cacheResponding flag during the 22511284Sandreas.hansson@arm.com // snooping above 22611284Sandreas.hansson@arm.com const bool expect_snoop_resp = !cache_responding && pkt->cacheResponding(); 22711334Sandreas.hansson@arm.com bool expect_response = pkt->needsResponse() && !pkt->cacheResponding(); 2288915SN/A 22911334Sandreas.hansson@arm.com const bool sink_packet = sinkPacket(pkt); 23011334Sandreas.hansson@arm.com 23111334Sandreas.hansson@arm.com // in certain cases the crossbar is responsible for responding 23211334Sandreas.hansson@arm.com bool respond_directly = false; 23311544Snikos.nikoleris@arm.com // store the original address as an address mapper could possibly 23411544Snikos.nikoleris@arm.com // modify the address upon a sendTimingRequest 23511544Snikos.nikoleris@arm.com const Addr addr(pkt->getAddr()); 23611334Sandreas.hansson@arm.com if (sink_packet) { 23711744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: Not forwarding %s\n", __func__, 23811744Snikos.nikoleris@arm.com pkt->print()); 23911334Sandreas.hansson@arm.com } else { 24011334Sandreas.hansson@arm.com // determine if we are forwarding the packet, or responding to 24111334Sandreas.hansson@arm.com // it 24211334Sandreas.hansson@arm.com if (!pointOfCoherency || pkt->isRead() || pkt->isWrite()) { 24311334Sandreas.hansson@arm.com // if we are passing on, rather than sinking, a packet to 24411334Sandreas.hansson@arm.com // which an upstream cache has committed to responding, 24511334Sandreas.hansson@arm.com // the line was needs writable, and the responding only 24611334Sandreas.hansson@arm.com // had an Owned copy, so we need to immidiately let the 24711334Sandreas.hansson@arm.com // downstream caches know, bypass any flow control 24811334Sandreas.hansson@arm.com if (pkt->cacheResponding()) { 24911334Sandreas.hansson@arm.com pkt->setExpressSnoop(); 25011334Sandreas.hansson@arm.com } 25111334Sandreas.hansson@arm.com 25211334Sandreas.hansson@arm.com // since it is a normal request, attempt to send the packet 25311334Sandreas.hansson@arm.com success = masterPorts[master_port_id]->sendTimingReq(pkt); 25411334Sandreas.hansson@arm.com } else { 25511334Sandreas.hansson@arm.com // no need to forward, turn this packet around and respond 25611334Sandreas.hansson@arm.com // directly 25711334Sandreas.hansson@arm.com assert(pkt->needsResponse()); 25811334Sandreas.hansson@arm.com 25911334Sandreas.hansson@arm.com respond_directly = true; 26011334Sandreas.hansson@arm.com assert(!expect_snoop_resp); 26111334Sandreas.hansson@arm.com expect_response = false; 26211334Sandreas.hansson@arm.com } 26311334Sandreas.hansson@arm.com } 2648948SN/A 26510821Sandreas.hansson@arm.com if (snoopFilter && !system->bypassCaches()) { 26610402SN/A // Let the snoop filter know about the success of the send operation 26711605Snikos.nikoleris@arm.com snoopFilter->finishRequest(!success, addr, pkt->isSecure()); 26810402SN/A } 26910402SN/A 27010656Sandreas.hansson@arm.com // check if we were successful in sending the packet onwards 27110656Sandreas.hansson@arm.com if (!success) { 27211284Sandreas.hansson@arm.com // express snoops should never be forced to retry 27310656Sandreas.hansson@arm.com assert(!is_express_snoop); 27410656Sandreas.hansson@arm.com 27510719SMarco.Balboni@ARM.com // restore the header delay 27610719SMarco.Balboni@ARM.com pkt->headerDelay = old_header_delay; 27710656Sandreas.hansson@arm.com 27811744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s RETRY\n", __func__, 27911744Snikos.nikoleris@arm.com src_port->name(), pkt->print()); 28010656Sandreas.hansson@arm.com 28110656Sandreas.hansson@arm.com // update the layer state and schedule an idle event 28210656Sandreas.hansson@arm.com reqLayers[master_port_id]->failedTiming(src_port, 28310719SMarco.Balboni@ARM.com clockEdge(Cycles(1))); 2849091SN/A } else { 28510656Sandreas.hansson@arm.com // express snoops currently bypass the crossbar state entirely 28610656Sandreas.hansson@arm.com if (!is_express_snoop) { 28710656Sandreas.hansson@arm.com // if this particular request will generate a snoop 28810656Sandreas.hansson@arm.com // response 28910656Sandreas.hansson@arm.com if (expect_snoop_resp) { 29010656Sandreas.hansson@arm.com // we should never have an exsiting request outstanding 29110656Sandreas.hansson@arm.com assert(outstandingSnoop.find(pkt->req) == 29210656Sandreas.hansson@arm.com outstandingSnoop.end()); 29310656Sandreas.hansson@arm.com outstandingSnoop.insert(pkt->req); 2948948SN/A 29510656Sandreas.hansson@arm.com // basic sanity check on the outstanding snoops 29610656Sandreas.hansson@arm.com panic_if(outstandingSnoop.size() > 512, 29710656Sandreas.hansson@arm.com "Outstanding snoop requests exceeded 512\n"); 29810656Sandreas.hansson@arm.com } 2998948SN/A 30010656Sandreas.hansson@arm.com // remember where to route the normal response to 30110656Sandreas.hansson@arm.com if (expect_response || expect_snoop_resp) { 30210656Sandreas.hansson@arm.com assert(routeTo.find(pkt->req) == routeTo.end()); 30310656Sandreas.hansson@arm.com routeTo[pkt->req] = slave_port_id; 3049549SN/A 30510656Sandreas.hansson@arm.com panic_if(routeTo.size() > 512, 30610656Sandreas.hansson@arm.com "Routing table exceeds 512 packets\n"); 30710656Sandreas.hansson@arm.com } 3088948SN/A 30910405Sandreas.hansson@arm.com // update the layer state and schedule an idle event 3109715SN/A reqLayers[master_port_id]->succeededTiming(packetFinishTime); 3119091SN/A } 3128975SN/A 31310656Sandreas.hansson@arm.com // stats updates only consider packets that were successfully sent 3149712SN/A pktCount[slave_port_id][master_port_id]++; 31510405Sandreas.hansson@arm.com pktSize[slave_port_id][master_port_id] += pkt_size; 3169712SN/A transDist[pkt_cmd]++; 31710656Sandreas.hansson@arm.com 31811564Sdavid.guillen@arm.com if (is_express_snoop) { 31910656Sandreas.hansson@arm.com snoops++; 32011564Sdavid.guillen@arm.com snoopTraffic += pkt_size; 32111564Sdavid.guillen@arm.com } 3229712SN/A } 3239712SN/A 32411334Sandreas.hansson@arm.com if (sink_packet) 32511334Sandreas.hansson@arm.com // queue the packet for deletion 32611334Sandreas.hansson@arm.com pendingDelete.reset(pkt); 32711334Sandreas.hansson@arm.com 32811334Sandreas.hansson@arm.com if (respond_directly) { 32911334Sandreas.hansson@arm.com assert(pkt->needsResponse()); 33011334Sandreas.hansson@arm.com assert(success); 33111334Sandreas.hansson@arm.com 33211334Sandreas.hansson@arm.com pkt->makeResponse(); 33311334Sandreas.hansson@arm.com 33411334Sandreas.hansson@arm.com if (snoopFilter && !system->bypassCaches()) { 33511334Sandreas.hansson@arm.com // let the snoop filter inspect the response and update its state 33611334Sandreas.hansson@arm.com snoopFilter->updateResponse(pkt, *slavePorts[slave_port_id]); 33711334Sandreas.hansson@arm.com } 33811334Sandreas.hansson@arm.com 33911334Sandreas.hansson@arm.com Tick response_time = clockEdge() + pkt->headerDelay; 34011334Sandreas.hansson@arm.com pkt->headerDelay = 0; 34111334Sandreas.hansson@arm.com 34211334Sandreas.hansson@arm.com slavePorts[slave_port_id]->schedTimingResp(pkt, response_time); 34311334Sandreas.hansson@arm.com } 34411334Sandreas.hansson@arm.com 3459091SN/A return success; 3468975SN/A} 3478975SN/A 3488975SN/Abool 34910405Sandreas.hansson@arm.comCoherentXBar::recvTimingResp(PacketPtr pkt, PortID master_port_id) 3508975SN/A{ 3518975SN/A // determine the source port based on the id 3529032SN/A MasterPort *src_port = masterPorts[master_port_id]; 3538975SN/A 35410656Sandreas.hansson@arm.com // determine the destination 35510656Sandreas.hansson@arm.com const auto route_lookup = routeTo.find(pkt->req); 35610656Sandreas.hansson@arm.com assert(route_lookup != routeTo.end()); 35710656Sandreas.hansson@arm.com const PortID slave_port_id = route_lookup->second; 35810572Sandreas.hansson@arm.com assert(slave_port_id != InvalidPortID); 35910572Sandreas.hansson@arm.com assert(slave_port_id < respLayers.size()); 3609713SN/A 36110405Sandreas.hansson@arm.com // test if the crossbar should be considered occupied for the 36210405Sandreas.hansson@arm.com // current port 3639715SN/A if (!respLayers[slave_port_id]->tryTiming(src_port)) { 36411744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s BUSY\n", __func__, 36511744Snikos.nikoleris@arm.com src_port->name(), pkt->print()); 3668975SN/A return false; 3678975SN/A } 3688975SN/A 36911744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__, 37011744Snikos.nikoleris@arm.com src_port->name(), pkt->print()); 3718975SN/A 3729712SN/A // store size and command as they might be modified when 3739712SN/A // forwarding the packet 3749712SN/A unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0; 3759712SN/A unsigned int pkt_cmd = pkt->cmdToIndex(); 3769712SN/A 37710719SMarco.Balboni@ARM.com // a response sees the response latency 37810719SMarco.Balboni@ARM.com Tick xbar_delay = responseLatency * clockPeriod(); 37910719SMarco.Balboni@ARM.com 38010719SMarco.Balboni@ARM.com // set the packet header and payload delay 38110719SMarco.Balboni@ARM.com calcPacketTiming(pkt, xbar_delay); 38210719SMarco.Balboni@ARM.com 38310719SMarco.Balboni@ARM.com // determine how long to be crossbar layer is busy 38410719SMarco.Balboni@ARM.com Tick packetFinishTime = clockEdge(Cycles(1)) + pkt->payloadDelay; 3858975SN/A 38610821Sandreas.hansson@arm.com if (snoopFilter && !system->bypassCaches()) { 38710402SN/A // let the snoop filter inspect the response and update its state 38810402SN/A snoopFilter->updateResponse(pkt, *slavePorts[slave_port_id]); 38910402SN/A } 39010402SN/A 39110888Sandreas.hansson@arm.com // send the packet through the destination slave port and pay for 39210888Sandreas.hansson@arm.com // any outstanding header delay 39310888Sandreas.hansson@arm.com Tick latency = pkt->headerDelay; 39410888Sandreas.hansson@arm.com pkt->headerDelay = 0; 39510888Sandreas.hansson@arm.com slavePorts[slave_port_id]->schedTimingResp(pkt, curTick() + latency); 3968975SN/A 39710656Sandreas.hansson@arm.com // remove the request from the routing table 39810656Sandreas.hansson@arm.com routeTo.erase(route_lookup); 39910656Sandreas.hansson@arm.com 4009715SN/A respLayers[slave_port_id]->succeededTiming(packetFinishTime); 4018975SN/A 4029712SN/A // stats updates 4039712SN/A pktCount[slave_port_id][master_port_id]++; 40410405Sandreas.hansson@arm.com pktSize[slave_port_id][master_port_id] += pkt_size; 4059712SN/A transDist[pkt_cmd]++; 4069712SN/A 4078975SN/A return true; 4088975SN/A} 4098975SN/A 4108975SN/Avoid 41110405Sandreas.hansson@arm.comCoherentXBar::recvTimingSnoopReq(PacketPtr pkt, PortID master_port_id) 4128975SN/A{ 41311744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__, 41411744Snikos.nikoleris@arm.com masterPorts[master_port_id]->name(), pkt->print()); 4158975SN/A 4169712SN/A // update stats here as we know the forwarding will succeed 41711564Sdavid.guillen@arm.com unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0; 4189712SN/A transDist[pkt->cmdToIndex()]++; 41910405Sandreas.hansson@arm.com snoops++; 42011564Sdavid.guillen@arm.com snoopTraffic += pkt_size; 4219712SN/A 4228975SN/A // we should only see express snoops from caches 4238975SN/A assert(pkt->isExpressSnoop()); 4248975SN/A 42511127Sandreas.hansson@arm.com // set the packet header and payload delay, for now use forward latency 42611127Sandreas.hansson@arm.com // @todo Assess the choice of latency further 42711127Sandreas.hansson@arm.com calcPacketTiming(pkt, forwardLatency * clockPeriod()); 42811127Sandreas.hansson@arm.com 42911284Sandreas.hansson@arm.com // remember if a cache has already committed to responding so we 43011284Sandreas.hansson@arm.com // can see if it changes during the snooping 43111284Sandreas.hansson@arm.com const bool cache_responding = pkt->cacheResponding(); 4329032SN/A 43311127Sandreas.hansson@arm.com assert(pkt->snoopDelay == 0); 43411127Sandreas.hansson@arm.com 43510402SN/A if (snoopFilter) { 43610402SN/A // let the Snoop Filter work its magic and guide probing 43710402SN/A auto sf_res = snoopFilter->lookupSnoop(pkt); 43811126Sandreas.hansson@arm.com // the time required by a packet to be delivered through 43911126Sandreas.hansson@arm.com // the xbar has to be charged also with to lookup latency 44011126Sandreas.hansson@arm.com // of the snoop filter 44111126Sandreas.hansson@arm.com pkt->headerDelay += sf_res.second * clockPeriod(); 44211744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s SF size: %i lat: %i\n", 44311744Snikos.nikoleris@arm.com __func__, masterPorts[master_port_id]->name(), pkt->print(), 44411744Snikos.nikoleris@arm.com sf_res.first.size(), sf_res.second); 44510402SN/A 44610402SN/A // forward to all snoopers 44710402SN/A forwardTiming(pkt, InvalidPortID, sf_res.first); 44810402SN/A } else { 44910402SN/A forwardTiming(pkt, InvalidPortID); 45010402SN/A } 4518975SN/A 45211127Sandreas.hansson@arm.com // add the snoop delay to our header delay, and then reset it 45311127Sandreas.hansson@arm.com pkt->headerDelay += pkt->snoopDelay; 45411127Sandreas.hansson@arm.com pkt->snoopDelay = 0; 45511127Sandreas.hansson@arm.com 45610656Sandreas.hansson@arm.com // if we can expect a response, remember how to route it 45711284Sandreas.hansson@arm.com if (!cache_responding && pkt->cacheResponding()) { 45810656Sandreas.hansson@arm.com assert(routeTo.find(pkt->req) == routeTo.end()); 45910656Sandreas.hansson@arm.com routeTo[pkt->req] = master_port_id; 46010656Sandreas.hansson@arm.com } 46110656Sandreas.hansson@arm.com 4628975SN/A // a snoop request came from a connected slave device (one of 4638975SN/A // our master ports), and if it is not coming from the slave 4648975SN/A // device responsible for the address range something is 4658975SN/A // wrong, hence there is nothing further to do as the packet 4668975SN/A // would be going back to where it came from 4679032SN/A assert(master_port_id == findPort(pkt->getAddr())); 4688975SN/A} 4698975SN/A 4708975SN/Abool 47110405Sandreas.hansson@arm.comCoherentXBar::recvTimingSnoopResp(PacketPtr pkt, PortID slave_port_id) 4728975SN/A{ 4738975SN/A // determine the source port based on the id 4749032SN/A SlavePort* src_port = slavePorts[slave_port_id]; 4758975SN/A 47610656Sandreas.hansson@arm.com // get the destination 47710656Sandreas.hansson@arm.com const auto route_lookup = routeTo.find(pkt->req); 47810656Sandreas.hansson@arm.com assert(route_lookup != routeTo.end()); 47910656Sandreas.hansson@arm.com const PortID dest_port_id = route_lookup->second; 48010572Sandreas.hansson@arm.com assert(dest_port_id != InvalidPortID); 4819714SN/A 4829714SN/A // determine if the response is from a snoop request we 4839714SN/A // created as the result of a normal request (in which case it 48410656Sandreas.hansson@arm.com // should be in the outstandingSnoop), or if we merely forwarded 4859714SN/A // someone else's snoop request 48610656Sandreas.hansson@arm.com const bool forwardAsSnoop = outstandingSnoop.find(pkt->req) == 48710656Sandreas.hansson@arm.com outstandingSnoop.end(); 4889714SN/A 48910405Sandreas.hansson@arm.com // test if the crossbar should be considered occupied for the 49010405Sandreas.hansson@arm.com // current port, note that the check is bypassed if the response 49110405Sandreas.hansson@arm.com // is being passed on as a normal response since this is occupying 49210405Sandreas.hansson@arm.com // the response layer rather than the snoop response layer 4939715SN/A if (forwardAsSnoop) { 49410572Sandreas.hansson@arm.com assert(dest_port_id < snoopLayers.size()); 4959715SN/A if (!snoopLayers[dest_port_id]->tryTiming(src_port)) { 49611744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s BUSY\n", __func__, 49711744Snikos.nikoleris@arm.com src_port->name(), pkt->print()); 4989715SN/A return false; 4999715SN/A } 5009716SN/A } else { 5019716SN/A // get the master port that mirrors this slave port internally 5029716SN/A MasterPort* snoop_port = snoopRespPorts[slave_port_id]; 50310572Sandreas.hansson@arm.com assert(dest_port_id < respLayers.size()); 5049716SN/A if (!respLayers[dest_port_id]->tryTiming(snoop_port)) { 50511744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s BUSY\n", __func__, 50611744Snikos.nikoleris@arm.com snoop_port->name(), pkt->print()); 5079716SN/A return false; 5089716SN/A } 5098975SN/A } 5108975SN/A 51111744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__, 51211744Snikos.nikoleris@arm.com src_port->name(), pkt->print()); 5138975SN/A 5149712SN/A // store size and command as they might be modified when 5159712SN/A // forwarding the packet 5169712SN/A unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0; 5179712SN/A unsigned int pkt_cmd = pkt->cmdToIndex(); 5189712SN/A 5198975SN/A // responses are never express snoops 5208975SN/A assert(!pkt->isExpressSnoop()); 5218975SN/A 52210719SMarco.Balboni@ARM.com // a snoop response sees the snoop response latency, and if it is 52310719SMarco.Balboni@ARM.com // forwarded as a normal response, the response latency 52410719SMarco.Balboni@ARM.com Tick xbar_delay = 52510719SMarco.Balboni@ARM.com (forwardAsSnoop ? snoopResponseLatency : responseLatency) * 52610719SMarco.Balboni@ARM.com clockPeriod(); 52710719SMarco.Balboni@ARM.com 52810719SMarco.Balboni@ARM.com // set the packet header and payload delay 52910719SMarco.Balboni@ARM.com calcPacketTiming(pkt, xbar_delay); 53010719SMarco.Balboni@ARM.com 53110719SMarco.Balboni@ARM.com // determine how long to be crossbar layer is busy 53210719SMarco.Balboni@ARM.com Tick packetFinishTime = clockEdge(Cycles(1)) + pkt->payloadDelay; 5338975SN/A 5349714SN/A // forward it either as a snoop response or a normal response 5359714SN/A if (forwardAsSnoop) { 5369714SN/A // this is a snoop response to a snoop request we forwarded, 5379714SN/A // e.g. coming from the L1 and going to the L2, and it should 5389714SN/A // be forwarded as a snoop response 53910402SN/A 54010402SN/A if (snoopFilter) { 54110402SN/A // update the probe filter so that it can properly track the line 54210402SN/A snoopFilter->updateSnoopForward(pkt, *slavePorts[slave_port_id], 54310402SN/A *masterPorts[dest_port_id]); 54410402SN/A } 54510402SN/A 5469712SN/A bool success M5_VAR_USED = 5479712SN/A masterPorts[dest_port_id]->sendTimingSnoopResp(pkt); 5489712SN/A pktCount[slave_port_id][dest_port_id]++; 54910405Sandreas.hansson@arm.com pktSize[slave_port_id][dest_port_id] += pkt_size; 5508975SN/A assert(success); 5519714SN/A 5529715SN/A snoopLayers[dest_port_id]->succeededTiming(packetFinishTime); 5533244SN/A } else { 5548975SN/A // we got a snoop response on one of our slave ports, 55510405Sandreas.hansson@arm.com // i.e. from a coherent master connected to the crossbar, and 55610405Sandreas.hansson@arm.com // since we created the snoop request as part of recvTiming, 55710405Sandreas.hansson@arm.com // this should now be a normal response again 55810656Sandreas.hansson@arm.com outstandingSnoop.erase(pkt->req); 5598948SN/A 56010656Sandreas.hansson@arm.com // this is a snoop response from a coherent master, hence it 56110656Sandreas.hansson@arm.com // should never go back to where the snoop response came from, 56210656Sandreas.hansson@arm.com // but instead to where the original request came from 5639712SN/A assert(slave_port_id != dest_port_id); 5648948SN/A 56510402SN/A if (snoopFilter) { 56610402SN/A // update the probe filter so that it can properly track the line 56710402SN/A snoopFilter->updateSnoopResponse(pkt, *slavePorts[slave_port_id], 56810402SN/A *slavePorts[dest_port_id]); 56910402SN/A } 57010402SN/A 57111744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s FWD RESP\n", __func__, 57211744Snikos.nikoleris@arm.com src_port->name(), pkt->print()); 57310402SN/A 5749714SN/A // as a normal response, it should go back to a master through 57510888Sandreas.hansson@arm.com // one of our slave ports, we also pay for any outstanding 57610888Sandreas.hansson@arm.com // header latency 57710888Sandreas.hansson@arm.com Tick latency = pkt->headerDelay; 57810888Sandreas.hansson@arm.com pkt->headerDelay = 0; 57910888Sandreas.hansson@arm.com slavePorts[dest_port_id]->schedTimingResp(pkt, curTick() + latency); 5809716SN/A 5819716SN/A respLayers[dest_port_id]->succeededTiming(packetFinishTime); 5823244SN/A } 5833244SN/A 58410656Sandreas.hansson@arm.com // remove the request from the routing table 58510656Sandreas.hansson@arm.com routeTo.erase(route_lookup); 58610656Sandreas.hansson@arm.com 5879712SN/A // stats updates 5889712SN/A transDist[pkt_cmd]++; 58910405Sandreas.hansson@arm.com snoops++; 59011564Sdavid.guillen@arm.com snoopTraffic += pkt_size; 5919712SN/A 5928948SN/A return true; 5938948SN/A} 5948948SN/A 5953210SN/A 5968948SN/Avoid 59710405Sandreas.hansson@arm.comCoherentXBar::forwardTiming(PacketPtr pkt, PortID exclude_slave_port_id, 59810888Sandreas.hansson@arm.com const std::vector<QueuedSlavePort*>& dests) 5998948SN/A{ 60011744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s for %s\n", __func__, pkt->print()); 6019663SN/A 6029524SN/A // snoops should only happen if the system isn't bypassing caches 6039524SN/A assert(!system->bypassCaches()); 6049524SN/A 60510401SN/A unsigned fanout = 0; 60610401SN/A 60710405Sandreas.hansson@arm.com for (const auto& p: dests) { 6088948SN/A // we could have gotten this request from a snooping master 6098948SN/A // (corresponding to our own slave port that is also in 6108948SN/A // snoopPorts) and should not send it back to where it came 6118948SN/A // from 6129031SN/A if (exclude_slave_port_id == InvalidPortID || 6138948SN/A p->getId() != exclude_slave_port_id) { 6148948SN/A // cache is not allowed to refuse snoop 6158975SN/A p->sendTimingSnoopReq(pkt); 61610401SN/A fanout++; 6178948SN/A } 6188948SN/A } 61910401SN/A 62010401SN/A // Stats for fanout of this forward operation 62110401SN/A snoopFanout.sample(fanout); 6222497SN/A} 6232497SN/A 6249092SN/Avoid 62510713Sandreas.hansson@arm.comCoherentXBar::recvReqRetry(PortID master_port_id) 6269092SN/A{ 6279093SN/A // responses and snoop responses never block on forwarding them, 6289093SN/A // so the retry will always be coming from a port to which we 6299093SN/A // tried to forward a request 6309715SN/A reqLayers[master_port_id]->recvRetry(); 6319092SN/A} 6329092SN/A 6339036SN/ATick 63410405Sandreas.hansson@arm.comCoherentXBar::recvAtomic(PacketPtr pkt, PortID slave_port_id) 6352657SN/A{ 63611744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__, 63711744Snikos.nikoleris@arm.com slavePorts[slave_port_id]->name(), pkt->print()); 6388915SN/A 63910405Sandreas.hansson@arm.com unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0; 64010405Sandreas.hansson@arm.com unsigned int pkt_cmd = pkt->cmdToIndex(); 6419712SN/A 6428979SN/A MemCmd snoop_response_cmd = MemCmd::InvalidCmd; 6438979SN/A Tick snoop_response_latency = 0; 6448979SN/A 64510821Sandreas.hansson@arm.com if (!system->bypassCaches()) { 6468979SN/A // forward to all snoopers but the source 64710402SN/A std::pair<MemCmd, Tick> snoop_result; 64810402SN/A if (snoopFilter) { 64910402SN/A // check with the snoop filter where to forward this packet 65010402SN/A auto sf_res = 65110402SN/A snoopFilter->lookupRequest(pkt, *slavePorts[slave_port_id]); 65210402SN/A snoop_response_latency += sf_res.second * clockPeriod(); 65311744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s SF size: %i lat: %i\n", 65411744Snikos.nikoleris@arm.com __func__, slavePorts[slave_port_id]->name(), pkt->print(), 65511744Snikos.nikoleris@arm.com sf_res.first.size(), sf_res.second); 65611130Sali.jafri@arm.com 65711130Sali.jafri@arm.com // let the snoop filter know about the success of the send 65811130Sali.jafri@arm.com // operation, and do it even before sending it onwards to 65911130Sali.jafri@arm.com // avoid situations where atomic upward snoops sneak in 66011130Sali.jafri@arm.com // between and change the filter state 66111605Snikos.nikoleris@arm.com snoopFilter->finishRequest(false, pkt->getAddr(), pkt->isSecure()); 66211130Sali.jafri@arm.com 66310402SN/A snoop_result = forwardAtomic(pkt, slave_port_id, InvalidPortID, 66410402SN/A sf_res.first); 66510402SN/A } else { 66610402SN/A snoop_result = forwardAtomic(pkt, slave_port_id); 66710402SN/A } 6688979SN/A snoop_response_cmd = snoop_result.first; 66910402SN/A snoop_response_latency += snoop_result.second; 6708979SN/A } 6718915SN/A 67211334Sandreas.hansson@arm.com // set up a sensible default value 67311334Sandreas.hansson@arm.com Tick response_latency = 0; 67411334Sandreas.hansson@arm.com 67511334Sandreas.hansson@arm.com const bool sink_packet = sinkPacket(pkt); 67611130Sali.jafri@arm.com 6778948SN/A // even if we had a snoop response, we must continue and also 6788948SN/A // perform the actual request at the destination 67910405Sandreas.hansson@arm.com PortID master_port_id = findPort(pkt->getAddr()); 68010405Sandreas.hansson@arm.com 68111334Sandreas.hansson@arm.com if (sink_packet) { 68211744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: Not forwarding %s\n", __func__, 68311744Snikos.nikoleris@arm.com pkt->print()); 68411334Sandreas.hansson@arm.com } else { 68511334Sandreas.hansson@arm.com if (!pointOfCoherency || pkt->isRead() || pkt->isWrite()) { 68611334Sandreas.hansson@arm.com // forward the request to the appropriate destination 68711334Sandreas.hansson@arm.com response_latency = masterPorts[master_port_id]->sendAtomic(pkt); 68811334Sandreas.hansson@arm.com } else { 68911334Sandreas.hansson@arm.com // if it does not need a response we sink the packet above 69011334Sandreas.hansson@arm.com assert(pkt->needsResponse()); 69111334Sandreas.hansson@arm.com 69211334Sandreas.hansson@arm.com pkt->makeResponse(); 69311334Sandreas.hansson@arm.com } 69411334Sandreas.hansson@arm.com } 69511334Sandreas.hansson@arm.com 69610405Sandreas.hansson@arm.com // stats updates for the request 69710405Sandreas.hansson@arm.com pktCount[slave_port_id][master_port_id]++; 69810405Sandreas.hansson@arm.com pktSize[slave_port_id][master_port_id] += pkt_size; 69910405Sandreas.hansson@arm.com transDist[pkt_cmd]++; 7008948SN/A 7018948SN/A 70211130Sali.jafri@arm.com // if lower levels have replied, tell the snoop filter 70311130Sali.jafri@arm.com if (!system->bypassCaches() && snoopFilter && pkt->isResponse()) { 70410402SN/A snoopFilter->updateResponse(pkt, *slavePorts[slave_port_id]); 70510402SN/A } 70610402SN/A 7078948SN/A // if we got a response from a snooper, restore it here 7088948SN/A if (snoop_response_cmd != MemCmd::InvalidCmd) { 7098948SN/A // no one else should have responded 7108948SN/A assert(!pkt->isResponse()); 7118948SN/A pkt->cmd = snoop_response_cmd; 7128948SN/A response_latency = snoop_response_latency; 7138948SN/A } 7148948SN/A 7159712SN/A // add the response data 71610405Sandreas.hansson@arm.com if (pkt->isResponse()) { 71710405Sandreas.hansson@arm.com pkt_size = pkt->hasData() ? pkt->getSize() : 0; 71810405Sandreas.hansson@arm.com pkt_cmd = pkt->cmdToIndex(); 71910405Sandreas.hansson@arm.com 72010405Sandreas.hansson@arm.com // stats updates 72110405Sandreas.hansson@arm.com pktCount[slave_port_id][master_port_id]++; 72210405Sandreas.hansson@arm.com pktSize[slave_port_id][master_port_id] += pkt_size; 72310405Sandreas.hansson@arm.com transDist[pkt_cmd]++; 72410405Sandreas.hansson@arm.com } 7259712SN/A 72610694SMarco.Balboni@ARM.com // @todo: Not setting header time 72710694SMarco.Balboni@ARM.com pkt->payloadDelay = response_latency; 7288948SN/A return response_latency; 7298948SN/A} 7308948SN/A 7318948SN/ATick 73210405Sandreas.hansson@arm.comCoherentXBar::recvAtomicSnoop(PacketPtr pkt, PortID master_port_id) 7338948SN/A{ 73411744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__, 73511744Snikos.nikoleris@arm.com masterPorts[master_port_id]->name(), pkt->print()); 7368948SN/A 7379712SN/A // add the request snoop data 73811564Sdavid.guillen@arm.com unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0; 73910405Sandreas.hansson@arm.com snoops++; 74011564Sdavid.guillen@arm.com snoopTraffic += pkt_size; 7419712SN/A 7428948SN/A // forward to all snoopers 74310402SN/A std::pair<MemCmd, Tick> snoop_result; 74410402SN/A Tick snoop_response_latency = 0; 74510402SN/A if (snoopFilter) { 74610402SN/A auto sf_res = snoopFilter->lookupSnoop(pkt); 74710402SN/A snoop_response_latency += sf_res.second * clockPeriod(); 74811744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s SF size: %i lat: %i\n", 74911744Snikos.nikoleris@arm.com __func__, masterPorts[master_port_id]->name(), pkt->print(), 75011744Snikos.nikoleris@arm.com sf_res.first.size(), sf_res.second); 75110402SN/A snoop_result = forwardAtomic(pkt, InvalidPortID, master_port_id, 75210402SN/A sf_res.first); 75310402SN/A } else { 75410402SN/A snoop_result = forwardAtomic(pkt, InvalidPortID); 75510402SN/A } 7568948SN/A MemCmd snoop_response_cmd = snoop_result.first; 75710402SN/A snoop_response_latency += snoop_result.second; 7588948SN/A 7598948SN/A if (snoop_response_cmd != MemCmd::InvalidCmd) 7608948SN/A pkt->cmd = snoop_response_cmd; 7618948SN/A 7629712SN/A // add the response snoop data 76310401SN/A if (pkt->isResponse()) { 76410405Sandreas.hansson@arm.com snoops++; 76510401SN/A } 7669712SN/A 76710694SMarco.Balboni@ARM.com // @todo: Not setting header time 76810694SMarco.Balboni@ARM.com pkt->payloadDelay = snoop_response_latency; 7698948SN/A return snoop_response_latency; 7708948SN/A} 7718948SN/A 7728948SN/Astd::pair<MemCmd, Tick> 77310405Sandreas.hansson@arm.comCoherentXBar::forwardAtomic(PacketPtr pkt, PortID exclude_slave_port_id, 77410402SN/A PortID source_master_port_id, 77510888Sandreas.hansson@arm.com const std::vector<QueuedSlavePort*>& dests) 7768948SN/A{ 7779032SN/A // the packet may be changed on snoops, record the original 7789032SN/A // command to enable us to restore it between snoops so that 7798948SN/A // additional snoops can take place properly 7804626SN/A MemCmd orig_cmd = pkt->cmd; 7814879SN/A MemCmd snoop_response_cmd = MemCmd::InvalidCmd; 7824879SN/A Tick snoop_response_latency = 0; 7833662SN/A 7849524SN/A // snoops should only happen if the system isn't bypassing caches 7859524SN/A assert(!system->bypassCaches()); 7869524SN/A 78710401SN/A unsigned fanout = 0; 78810401SN/A 78910405Sandreas.hansson@arm.com for (const auto& p: dests) { 7908915SN/A // we could have gotten this request from a snooping master 7918915SN/A // (corresponding to our own slave port that is also in 7928915SN/A // snoopPorts) and should not send it back to where it came 7938915SN/A // from 79410402SN/A if (exclude_slave_port_id != InvalidPortID && 79510402SN/A p->getId() == exclude_slave_port_id) 79610402SN/A continue; 79710401SN/A 79810402SN/A Tick latency = p->sendAtomicSnoop(pkt); 79910402SN/A fanout++; 80010402SN/A 80110402SN/A // in contrast to a functional access, we have to keep on 80210402SN/A // going as all snoopers must be updated even if we get a 80310402SN/A // response 80410402SN/A if (!pkt->isResponse()) 80510402SN/A continue; 80610402SN/A 80710402SN/A // response from snoop agent 80810402SN/A assert(pkt->cmd != orig_cmd); 80911284Sandreas.hansson@arm.com assert(pkt->cacheResponding()); 81010402SN/A // should only happen once 81110402SN/A assert(snoop_response_cmd == MemCmd::InvalidCmd); 81210402SN/A // save response state 81310402SN/A snoop_response_cmd = pkt->cmd; 81410402SN/A snoop_response_latency = latency; 81510402SN/A 81610402SN/A if (snoopFilter) { 81710402SN/A // Handle responses by the snoopers and differentiate between 81810402SN/A // responses to requests from above and snoops from below 81910402SN/A if (source_master_port_id != InvalidPortID) { 82010402SN/A // Getting a response for a snoop from below 82110402SN/A assert(exclude_slave_port_id == InvalidPortID); 82210402SN/A snoopFilter->updateSnoopForward(pkt, *p, 82310402SN/A *masterPorts[source_master_port_id]); 82410402SN/A } else { 82510402SN/A // Getting a response for a request from above 82610402SN/A assert(source_master_port_id == InvalidPortID); 82710402SN/A snoopFilter->updateSnoopResponse(pkt, *p, 82810402SN/A *slavePorts[exclude_slave_port_id]); 8294626SN/A } 8304626SN/A } 83110402SN/A // restore original packet state for remaining snoopers 83210402SN/A pkt->cmd = orig_cmd; 8334626SN/A } 8344626SN/A 83510401SN/A // Stats for fanout 83610401SN/A snoopFanout.sample(fanout); 83710401SN/A 8388948SN/A // the packet is restored as part of the loop and any potential 8398948SN/A // snoop response is part of the returned pair 8408948SN/A return std::make_pair(snoop_response_cmd, snoop_response_latency); 8412497SN/A} 8422497SN/A 8432497SN/Avoid 84410405Sandreas.hansson@arm.comCoherentXBar::recvFunctional(PacketPtr pkt, PortID slave_port_id) 8452497SN/A{ 8468663SN/A if (!pkt->isPrint()) { 8478663SN/A // don't do DPRINTFs on PrintReq as it clutters up the output 84811744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__, 84911744Snikos.nikoleris@arm.com slavePorts[slave_port_id]->name(), pkt->print()); 8508663SN/A } 8518663SN/A 85210821Sandreas.hansson@arm.com if (!system->bypassCaches()) { 8538979SN/A // forward to all snoopers but the source 8549032SN/A forwardFunctional(pkt, slave_port_id); 8558979SN/A } 8564912SN/A 8578948SN/A // there is no need to continue if the snooping has found what we 8588948SN/A // were looking for and the packet is already a response 8598948SN/A if (!pkt->isResponse()) { 86010888Sandreas.hansson@arm.com // since our slave ports are queued ports we need to check them as well 86110888Sandreas.hansson@arm.com for (const auto& p : slavePorts) { 86210888Sandreas.hansson@arm.com // if we find a response that has the data, then the 86310888Sandreas.hansson@arm.com // downstream caches/memories may be out of date, so simply stop 86410888Sandreas.hansson@arm.com // here 86510888Sandreas.hansson@arm.com if (p->checkFunctional(pkt)) { 86610888Sandreas.hansson@arm.com if (pkt->needsResponse()) 86710888Sandreas.hansson@arm.com pkt->makeResponse(); 86810888Sandreas.hansson@arm.com return; 86910888Sandreas.hansson@arm.com } 87010888Sandreas.hansson@arm.com } 87110888Sandreas.hansson@arm.com 8729031SN/A PortID dest_id = findPort(pkt->getAddr()); 8738948SN/A 8748948SN/A masterPorts[dest_id]->sendFunctional(pkt); 8758948SN/A } 8768948SN/A} 8778948SN/A 8788948SN/Avoid 87910405Sandreas.hansson@arm.comCoherentXBar::recvFunctionalSnoop(PacketPtr pkt, PortID master_port_id) 8808948SN/A{ 8818948SN/A if (!pkt->isPrint()) { 8828948SN/A // don't do DPRINTFs on PrintReq as it clutters up the output 88311744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__, 88411744Snikos.nikoleris@arm.com masterPorts[master_port_id]->name(), pkt->print()); 8858948SN/A } 8868948SN/A 88711188Sandreas.sandberg@arm.com for (const auto& p : slavePorts) { 88811188Sandreas.sandberg@arm.com if (p->checkFunctional(pkt)) { 88911188Sandreas.sandberg@arm.com if (pkt->needsResponse()) 89011188Sandreas.sandberg@arm.com pkt->makeResponse(); 89111188Sandreas.sandberg@arm.com return; 89211188Sandreas.sandberg@arm.com } 89311188Sandreas.sandberg@arm.com } 89411188Sandreas.sandberg@arm.com 8958948SN/A // forward to all snoopers 8969031SN/A forwardFunctional(pkt, InvalidPortID); 8978948SN/A} 8988948SN/A 8998948SN/Avoid 90010405Sandreas.hansson@arm.comCoherentXBar::forwardFunctional(PacketPtr pkt, PortID exclude_slave_port_id) 9018948SN/A{ 9029524SN/A // snoops should only happen if the system isn't bypassing caches 9039524SN/A assert(!system->bypassCaches()); 9049524SN/A 90510405Sandreas.hansson@arm.com for (const auto& p: snoopPorts) { 9068915SN/A // we could have gotten this request from a snooping master 9078915SN/A // (corresponding to our own slave port that is also in 9088915SN/A // snoopPorts) and should not send it back to where it came 9098915SN/A // from 9109031SN/A if (exclude_slave_port_id == InvalidPortID || 9118948SN/A p->getId() != exclude_slave_port_id) 9128948SN/A p->sendFunctionalSnoop(pkt); 9138915SN/A 9148948SN/A // if we get a response we are done 9158948SN/A if (pkt->isResponse()) { 9168948SN/A break; 9178915SN/A } 9183650SN/A } 9192497SN/A} 9202497SN/A 92111334Sandreas.hansson@arm.combool 92211334Sandreas.hansson@arm.comCoherentXBar::sinkPacket(const PacketPtr pkt) const 92311334Sandreas.hansson@arm.com{ 92411334Sandreas.hansson@arm.com // we can sink the packet if: 92511334Sandreas.hansson@arm.com // 1) the crossbar is the point of coherency, and a cache is 92611334Sandreas.hansson@arm.com // responding after being snooped 92711334Sandreas.hansson@arm.com // 2) the crossbar is the point of coherency, and the packet is a 92811334Sandreas.hansson@arm.com // coherency packet (not a read or a write) that does not 92911334Sandreas.hansson@arm.com // require a response 93011334Sandreas.hansson@arm.com // 3) this is a clean evict or clean writeback, but the packet is 93111334Sandreas.hansson@arm.com // found in a cache above this crossbar 93211334Sandreas.hansson@arm.com // 4) a cache is responding after being snooped, and the packet 93311334Sandreas.hansson@arm.com // either does not need the block to be writable, or the cache 93411334Sandreas.hansson@arm.com // that has promised to respond (setting the cache responding 93511334Sandreas.hansson@arm.com // flag) is providing writable and thus had a Modified block, 93611334Sandreas.hansson@arm.com // and no further action is needed 93711334Sandreas.hansson@arm.com return (pointOfCoherency && pkt->cacheResponding()) || 93811334Sandreas.hansson@arm.com (pointOfCoherency && !(pkt->isRead() || pkt->isWrite()) && 93911334Sandreas.hansson@arm.com !pkt->needsResponse()) || 94011334Sandreas.hansson@arm.com (pkt->isCleanEviction() && pkt->isBlockCached()) || 94111334Sandreas.hansson@arm.com (pkt->cacheResponding() && 94211334Sandreas.hansson@arm.com (!pkt->needsWritable() || pkt->responderHadWritable())); 94311334Sandreas.hansson@arm.com} 94411334Sandreas.hansson@arm.com 9459712SN/Avoid 94610405Sandreas.hansson@arm.comCoherentXBar::regStats() 9479712SN/A{ 94810405Sandreas.hansson@arm.com // register the stats of the base class and our layers 94910405Sandreas.hansson@arm.com BaseXBar::regStats(); 95010405Sandreas.hansson@arm.com for (auto l: reqLayers) 95110405Sandreas.hansson@arm.com l->regStats(); 95210405Sandreas.hansson@arm.com for (auto l: respLayers) 95310405Sandreas.hansson@arm.com l->regStats(); 95410405Sandreas.hansson@arm.com for (auto l: snoopLayers) 95510405Sandreas.hansson@arm.com l->regStats(); 9569712SN/A 95710405Sandreas.hansson@arm.com snoops 95810405Sandreas.hansson@arm.com .name(name() + ".snoops") 95910401SN/A .desc("Total snoops (count)") 96010401SN/A ; 96110401SN/A 96211564Sdavid.guillen@arm.com snoopTraffic 96311564Sdavid.guillen@arm.com .name(name() + ".snoopTraffic") 96411564Sdavid.guillen@arm.com .desc("Total snoop traffic (bytes)") 96511564Sdavid.guillen@arm.com ; 96611564Sdavid.guillen@arm.com 96710401SN/A snoopFanout 96810401SN/A .init(0, snoopPorts.size(), 1) 96910401SN/A .name(name() + ".snoop_fanout") 97010401SN/A .desc("Request fanout histogram") 97110401SN/A ; 9729712SN/A} 9739712SN/A 97410405Sandreas.hansson@arm.comCoherentXBar * 97510405Sandreas.hansson@arm.comCoherentXBarParams::create() 9762497SN/A{ 97710405Sandreas.hansson@arm.com return new CoherentXBar(this); 9782497SN/A} 979