coherent_xbar.cc revision 12341
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 432497SN/A */ 442497SN/A 452497SN/A/** 462982SN/A * @file 4710405Sandreas.hansson@arm.com * Definition of a crossbar object. 482497SN/A */ 492497SN/A 5011793Sbrandon.potter@amd.com#include "mem/coherent_xbar.hh" 5111793Sbrandon.potter@amd.com 5212334Sgabeblack@google.com#include "base/logging.hh" 532548SN/A#include "base/trace.hh" 5410405Sandreas.hansson@arm.com#include "debug/AddrRanges.hh" 5510405Sandreas.hansson@arm.com#include "debug/CoherentXBar.hh" 569524SN/A#include "sim/system.hh" 572497SN/A 5810405Sandreas.hansson@arm.comCoherentXBar::CoherentXBar(const CoherentXBarParams *p) 5910719SMarco.Balboni@ARM.com : BaseXBar(p), system(p->system), snoopFilter(p->snoop_filter), 6011334Sandreas.hansson@arm.com snoopResponseLatency(p->snoop_response_latency), 6112341Snikos.nikoleris@arm.com pointOfCoherency(p->point_of_coherency), 6212341Snikos.nikoleris@arm.com pointOfUnification(p->point_of_unification) 637523SN/A{ 648851SN/A // create the ports based on the size of the master and slave 658948SN/A // vector ports, and the presence of the default port, the ports 668948SN/A // are enumerated starting from zero 678851SN/A for (int i = 0; i < p->port_master_connection_count; ++i) { 689095SN/A std::string portName = csprintf("%s.master[%d]", name(), i); 6910405Sandreas.hansson@arm.com MasterPort* bp = new CoherentXBarMasterPort(portName, *this, i); 708922SN/A masterPorts.push_back(bp); 719715SN/A reqLayers.push_back(new ReqLayer(*bp, *this, 729715SN/A csprintf(".reqLayer%d", i))); 7310713Sandreas.hansson@arm.com snoopLayers.push_back(new SnoopRespLayer(*bp, *this, 7410713Sandreas.hansson@arm.com csprintf(".snoopLayer%d", i))); 758851SN/A } 768851SN/A 778948SN/A // see if we have a default slave device connected and if so add 788948SN/A // our corresponding master port 798915SN/A if (p->port_default_connection_count) { 809031SN/A defaultPortID = masterPorts.size(); 819095SN/A std::string portName = name() + ".default"; 8210405Sandreas.hansson@arm.com MasterPort* bp = new CoherentXBarMasterPort(portName, *this, 839036SN/A defaultPortID); 848922SN/A masterPorts.push_back(bp); 859715SN/A reqLayers.push_back(new ReqLayer(*bp, *this, csprintf(".reqLayer%d", 869715SN/A defaultPortID))); 8710713Sandreas.hansson@arm.com snoopLayers.push_back(new SnoopRespLayer(*bp, *this, 8810713Sandreas.hansson@arm.com csprintf(".snoopLayer%d", 8910713Sandreas.hansson@arm.com defaultPortID))); 908915SN/A } 918915SN/A 928948SN/A // create the slave ports, once again starting at zero 938851SN/A for (int i = 0; i < p->port_slave_connection_count; ++i) { 949095SN/A std::string portName = csprintf("%s.slave[%d]", name(), i); 9510888Sandreas.hansson@arm.com QueuedSlavePort* bp = new CoherentXBarSlavePort(portName, *this, i); 968922SN/A slavePorts.push_back(bp); 979715SN/A respLayers.push_back(new RespLayer(*bp, *this, 989715SN/A csprintf(".respLayer%d", i))); 999716SN/A snoopRespPorts.push_back(new SnoopRespPort(*bp, *this)); 1008851SN/A } 1018851SN/A 1027523SN/A clearPortCache(); 1037523SN/A} 1047523SN/A 10510405Sandreas.hansson@arm.comCoherentXBar::~CoherentXBar() 1069715SN/A{ 10710405Sandreas.hansson@arm.com for (auto l: reqLayers) 10810405Sandreas.hansson@arm.com delete l; 10910405Sandreas.hansson@arm.com for (auto l: respLayers) 11010405Sandreas.hansson@arm.com delete l; 11110405Sandreas.hansson@arm.com for (auto l: snoopLayers) 11210405Sandreas.hansson@arm.com delete l; 11310405Sandreas.hansson@arm.com for (auto p: snoopRespPorts) 11410405Sandreas.hansson@arm.com delete p; 1159715SN/A} 1169715SN/A 1172568SN/Avoid 11810405Sandreas.hansson@arm.comCoherentXBar::init() 1192568SN/A{ 12010405Sandreas.hansson@arm.com BaseXBar::init(); 1219278SN/A 1228948SN/A // iterate over our slave ports and determine which of our 1238948SN/A // neighbouring master ports are snooping and add them as snoopers 12410405Sandreas.hansson@arm.com for (const auto& p: slavePorts) { 1259088SN/A // check if the connected master port is snooping 12610405Sandreas.hansson@arm.com if (p->isSnooping()) { 12710405Sandreas.hansson@arm.com DPRINTF(AddrRanges, "Adding snooping master %s\n", 12810405Sandreas.hansson@arm.com p->getMasterPort().name()); 12910405Sandreas.hansson@arm.com snoopPorts.push_back(p); 1308711SN/A } 1318711SN/A } 1322568SN/A 1339036SN/A if (snoopPorts.empty()) 13410405Sandreas.hansson@arm.com warn("CoherentXBar %s has no snooping ports attached!\n", name()); 13511133Sandreas.hansson@arm.com 13611133Sandreas.hansson@arm.com // inform the snoop filter about the slave ports so it can create 13711133Sandreas.hansson@arm.com // its own internal representation 13811133Sandreas.hansson@arm.com if (snoopFilter) 13911133Sandreas.hansson@arm.com snoopFilter->setSlavePorts(slavePorts); 1403244SN/A} 1413244SN/A 1428948SN/Abool 14310405Sandreas.hansson@arm.comCoherentXBar::recvTimingReq(PacketPtr pkt, PortID slave_port_id) 1443244SN/A{ 1458975SN/A // determine the source port based on the id 1469032SN/A SlavePort *src_port = slavePorts[slave_port_id]; 1473244SN/A 1489091SN/A // remember if the packet is an express snoop 1499091SN/A bool is_express_snoop = pkt->isExpressSnoop(); 15011284Sandreas.hansson@arm.com bool cache_responding = pkt->cacheResponding(); 15110656Sandreas.hansson@arm.com // for normal requests, going downstream, the express snoop flag 15211284Sandreas.hansson@arm.com // and the cache responding flag should always be the same 15311284Sandreas.hansson@arm.com assert(is_express_snoop == cache_responding); 1549091SN/A 1559612SN/A // determine the destination based on the address 1569712SN/A PortID master_port_id = findPort(pkt->getAddr()); 1579612SN/A 15810405Sandreas.hansson@arm.com // test if the crossbar should be considered occupied for the current 1599033SN/A // port, and exclude express snoops from the check 1609715SN/A if (!is_express_snoop && !reqLayers[master_port_id]->tryTiming(src_port)) { 16111744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s BUSY\n", __func__, 16211744Snikos.nikoleris@arm.com src_port->name(), pkt->print()); 1633244SN/A return false; 1643244SN/A } 1653244SN/A 16611744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__, 16711744Snikos.nikoleris@arm.com src_port->name(), pkt->print()); 1685197SN/A 1699712SN/A // store size and command as they might be modified when 1709712SN/A // forwarding the packet 1719712SN/A unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0; 1729712SN/A unsigned int pkt_cmd = pkt->cmdToIndex(); 1739712SN/A 17410719SMarco.Balboni@ARM.com // store the old header delay so we can restore it if needed 17510719SMarco.Balboni@ARM.com Tick old_header_delay = pkt->headerDelay; 17610719SMarco.Balboni@ARM.com 17710719SMarco.Balboni@ARM.com // a request sees the frontend and forward latency 17810719SMarco.Balboni@ARM.com Tick xbar_delay = (frontendLatency + forwardLatency) * clockPeriod(); 17910719SMarco.Balboni@ARM.com 18010719SMarco.Balboni@ARM.com // set the packet header and payload delay 18110719SMarco.Balboni@ARM.com calcPacketTiming(pkt, xbar_delay); 18210719SMarco.Balboni@ARM.com 18310719SMarco.Balboni@ARM.com // determine how long to be crossbar layer is busy 18410719SMarco.Balboni@ARM.com Tick packetFinishTime = clockEdge(Cycles(1)) + pkt->payloadDelay; 1854912SN/A 18610821Sandreas.hansson@arm.com if (!system->bypassCaches()) { 18711127Sandreas.hansson@arm.com assert(pkt->snoopDelay == 0); 18811127Sandreas.hansson@arm.com 1898979SN/A // the packet is a memory-mapped request and should be 1908979SN/A // broadcasted to our snoopers but the source 19110402SN/A if (snoopFilter) { 19210402SN/A // check with the snoop filter where to forward this packet 19310402SN/A auto sf_res = snoopFilter->lookupRequest(pkt, *src_port); 19411126Sandreas.hansson@arm.com // the time required by a packet to be delivered through 19511126Sandreas.hansson@arm.com // the xbar has to be charged also with to lookup latency 19611126Sandreas.hansson@arm.com // of the snoop filter 19710719SMarco.Balboni@ARM.com pkt->headerDelay += sf_res.second * clockPeriod(); 19811744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s SF size: %i lat: %i\n", 19911744Snikos.nikoleris@arm.com __func__, src_port->name(), pkt->print(), 20011744Snikos.nikoleris@arm.com sf_res.first.size(), sf_res.second); 20111196Sali.jafri@arm.com 20211199Sandreas.hansson@arm.com if (pkt->isEviction()) { 20311196Sali.jafri@arm.com // for block-evicting packets, i.e. writebacks and 20411196Sali.jafri@arm.com // clean evictions, there is no need to snoop up, as 20511196Sali.jafri@arm.com // all we do is determine if the block is cached or 20611196Sali.jafri@arm.com // not, instead just set it here based on the snoop 20711196Sali.jafri@arm.com // filter result 20811196Sali.jafri@arm.com if (!sf_res.first.empty()) 20911196Sali.jafri@arm.com pkt->setBlockCached(); 21011196Sali.jafri@arm.com } else { 21111196Sali.jafri@arm.com forwardTiming(pkt, slave_port_id, sf_res.first); 21211196Sali.jafri@arm.com } 21310402SN/A } else { 21410402SN/A forwardTiming(pkt, slave_port_id); 21510402SN/A } 21611127Sandreas.hansson@arm.com 21711127Sandreas.hansson@arm.com // add the snoop delay to our header delay, and then reset it 21811127Sandreas.hansson@arm.com pkt->headerDelay += pkt->snoopDelay; 21911127Sandreas.hansson@arm.com pkt->snoopDelay = 0; 2208979SN/A } 2218948SN/A 22211334Sandreas.hansson@arm.com // set up a sensible starting point 22311334Sandreas.hansson@arm.com bool success = true; 22410883Sali.jafri@arm.com 22511284Sandreas.hansson@arm.com // remember if the packet will generate a snoop response by 22611284Sandreas.hansson@arm.com // checking if a cache set the cacheResponding flag during the 22711284Sandreas.hansson@arm.com // snooping above 22811284Sandreas.hansson@arm.com const bool expect_snoop_resp = !cache_responding && pkt->cacheResponding(); 22911334Sandreas.hansson@arm.com bool expect_response = pkt->needsResponse() && !pkt->cacheResponding(); 2308915SN/A 23111334Sandreas.hansson@arm.com const bool sink_packet = sinkPacket(pkt); 23211334Sandreas.hansson@arm.com 23311334Sandreas.hansson@arm.com // in certain cases the crossbar is responsible for responding 23411334Sandreas.hansson@arm.com bool respond_directly = false; 23511544Snikos.nikoleris@arm.com // store the original address as an address mapper could possibly 23611544Snikos.nikoleris@arm.com // modify the address upon a sendTimingRequest 23711544Snikos.nikoleris@arm.com const Addr addr(pkt->getAddr()); 23811334Sandreas.hansson@arm.com if (sink_packet) { 23911744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: Not forwarding %s\n", __func__, 24011744Snikos.nikoleris@arm.com pkt->print()); 24111334Sandreas.hansson@arm.com } else { 24211334Sandreas.hansson@arm.com // determine if we are forwarding the packet, or responding to 24311334Sandreas.hansson@arm.com // it 24411334Sandreas.hansson@arm.com if (!pointOfCoherency || pkt->isRead() || pkt->isWrite()) { 24511334Sandreas.hansson@arm.com // if we are passing on, rather than sinking, a packet to 24611334Sandreas.hansson@arm.com // which an upstream cache has committed to responding, 24711334Sandreas.hansson@arm.com // the line was needs writable, and the responding only 24811334Sandreas.hansson@arm.com // had an Owned copy, so we need to immidiately let the 24911334Sandreas.hansson@arm.com // downstream caches know, bypass any flow control 25011334Sandreas.hansson@arm.com if (pkt->cacheResponding()) { 25111334Sandreas.hansson@arm.com pkt->setExpressSnoop(); 25211334Sandreas.hansson@arm.com } 25311334Sandreas.hansson@arm.com 25411334Sandreas.hansson@arm.com // since it is a normal request, attempt to send the packet 25511334Sandreas.hansson@arm.com success = masterPorts[master_port_id]->sendTimingReq(pkt); 25611334Sandreas.hansson@arm.com } else { 25711334Sandreas.hansson@arm.com // no need to forward, turn this packet around and respond 25811334Sandreas.hansson@arm.com // directly 25911334Sandreas.hansson@arm.com assert(pkt->needsResponse()); 26011334Sandreas.hansson@arm.com 26111334Sandreas.hansson@arm.com respond_directly = true; 26211334Sandreas.hansson@arm.com assert(!expect_snoop_resp); 26311334Sandreas.hansson@arm.com expect_response = false; 26411334Sandreas.hansson@arm.com } 26511334Sandreas.hansson@arm.com } 2668948SN/A 26710821Sandreas.hansson@arm.com if (snoopFilter && !system->bypassCaches()) { 26810402SN/A // Let the snoop filter know about the success of the send operation 26911605Snikos.nikoleris@arm.com snoopFilter->finishRequest(!success, addr, pkt->isSecure()); 27010402SN/A } 27110402SN/A 27210656Sandreas.hansson@arm.com // check if we were successful in sending the packet onwards 27310656Sandreas.hansson@arm.com if (!success) { 27411284Sandreas.hansson@arm.com // express snoops should never be forced to retry 27510656Sandreas.hansson@arm.com assert(!is_express_snoop); 27610656Sandreas.hansson@arm.com 27710719SMarco.Balboni@ARM.com // restore the header delay 27810719SMarco.Balboni@ARM.com pkt->headerDelay = old_header_delay; 27910656Sandreas.hansson@arm.com 28011744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s RETRY\n", __func__, 28111744Snikos.nikoleris@arm.com src_port->name(), pkt->print()); 28210656Sandreas.hansson@arm.com 28310656Sandreas.hansson@arm.com // update the layer state and schedule an idle event 28410656Sandreas.hansson@arm.com reqLayers[master_port_id]->failedTiming(src_port, 28510719SMarco.Balboni@ARM.com clockEdge(Cycles(1))); 2869091SN/A } else { 28710656Sandreas.hansson@arm.com // express snoops currently bypass the crossbar state entirely 28810656Sandreas.hansson@arm.com if (!is_express_snoop) { 28910656Sandreas.hansson@arm.com // if this particular request will generate a snoop 29010656Sandreas.hansson@arm.com // response 29110656Sandreas.hansson@arm.com if (expect_snoop_resp) { 29210656Sandreas.hansson@arm.com // we should never have an exsiting request outstanding 29310656Sandreas.hansson@arm.com assert(outstandingSnoop.find(pkt->req) == 29410656Sandreas.hansson@arm.com outstandingSnoop.end()); 29510656Sandreas.hansson@arm.com outstandingSnoop.insert(pkt->req); 2968948SN/A 29710656Sandreas.hansson@arm.com // basic sanity check on the outstanding snoops 29810656Sandreas.hansson@arm.com panic_if(outstandingSnoop.size() > 512, 29910656Sandreas.hansson@arm.com "Outstanding snoop requests exceeded 512\n"); 30010656Sandreas.hansson@arm.com } 3018948SN/A 30210656Sandreas.hansson@arm.com // remember where to route the normal response to 30310656Sandreas.hansson@arm.com if (expect_response || expect_snoop_resp) { 30410656Sandreas.hansson@arm.com assert(routeTo.find(pkt->req) == routeTo.end()); 30510656Sandreas.hansson@arm.com routeTo[pkt->req] = slave_port_id; 3069549SN/A 30710656Sandreas.hansson@arm.com panic_if(routeTo.size() > 512, 30810656Sandreas.hansson@arm.com "Routing table exceeds 512 packets\n"); 30910656Sandreas.hansson@arm.com } 3108948SN/A 31110405Sandreas.hansson@arm.com // update the layer state and schedule an idle event 3129715SN/A reqLayers[master_port_id]->succeededTiming(packetFinishTime); 3139091SN/A } 3148975SN/A 31510656Sandreas.hansson@arm.com // stats updates only consider packets that were successfully sent 3169712SN/A pktCount[slave_port_id][master_port_id]++; 31710405Sandreas.hansson@arm.com pktSize[slave_port_id][master_port_id] += pkt_size; 3189712SN/A transDist[pkt_cmd]++; 31910656Sandreas.hansson@arm.com 32011564Sdavid.guillen@arm.com if (is_express_snoop) { 32110656Sandreas.hansson@arm.com snoops++; 32211564Sdavid.guillen@arm.com snoopTraffic += pkt_size; 32311564Sdavid.guillen@arm.com } 3249712SN/A } 3259712SN/A 32611334Sandreas.hansson@arm.com if (sink_packet) 32711334Sandreas.hansson@arm.com // queue the packet for deletion 32811334Sandreas.hansson@arm.com pendingDelete.reset(pkt); 32911334Sandreas.hansson@arm.com 33011334Sandreas.hansson@arm.com if (respond_directly) { 33111334Sandreas.hansson@arm.com assert(pkt->needsResponse()); 33211334Sandreas.hansson@arm.com assert(success); 33311334Sandreas.hansson@arm.com 33411334Sandreas.hansson@arm.com pkt->makeResponse(); 33511334Sandreas.hansson@arm.com 33611334Sandreas.hansson@arm.com if (snoopFilter && !system->bypassCaches()) { 33711334Sandreas.hansson@arm.com // let the snoop filter inspect the response and update its state 33811334Sandreas.hansson@arm.com snoopFilter->updateResponse(pkt, *slavePorts[slave_port_id]); 33911334Sandreas.hansson@arm.com } 34011334Sandreas.hansson@arm.com 34111334Sandreas.hansson@arm.com Tick response_time = clockEdge() + pkt->headerDelay; 34211334Sandreas.hansson@arm.com pkt->headerDelay = 0; 34311334Sandreas.hansson@arm.com 34411334Sandreas.hansson@arm.com slavePorts[slave_port_id]->schedTimingResp(pkt, response_time); 34511334Sandreas.hansson@arm.com } 34611334Sandreas.hansson@arm.com 3479091SN/A return success; 3488975SN/A} 3498975SN/A 3508975SN/Abool 35110405Sandreas.hansson@arm.comCoherentXBar::recvTimingResp(PacketPtr pkt, PortID master_port_id) 3528975SN/A{ 3538975SN/A // determine the source port based on the id 3549032SN/A MasterPort *src_port = masterPorts[master_port_id]; 3558975SN/A 35610656Sandreas.hansson@arm.com // determine the destination 35710656Sandreas.hansson@arm.com const auto route_lookup = routeTo.find(pkt->req); 35810656Sandreas.hansson@arm.com assert(route_lookup != routeTo.end()); 35910656Sandreas.hansson@arm.com const PortID slave_port_id = route_lookup->second; 36010572Sandreas.hansson@arm.com assert(slave_port_id != InvalidPortID); 36110572Sandreas.hansson@arm.com assert(slave_port_id < respLayers.size()); 3629713SN/A 36310405Sandreas.hansson@arm.com // test if the crossbar should be considered occupied for the 36410405Sandreas.hansson@arm.com // current port 3659715SN/A if (!respLayers[slave_port_id]->tryTiming(src_port)) { 36611744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s BUSY\n", __func__, 36711744Snikos.nikoleris@arm.com src_port->name(), pkt->print()); 3688975SN/A return false; 3698975SN/A } 3708975SN/A 37111744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__, 37211744Snikos.nikoleris@arm.com src_port->name(), pkt->print()); 3738975SN/A 3749712SN/A // store size and command as they might be modified when 3759712SN/A // forwarding the packet 3769712SN/A unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0; 3779712SN/A unsigned int pkt_cmd = pkt->cmdToIndex(); 3789712SN/A 37910719SMarco.Balboni@ARM.com // a response sees the response latency 38010719SMarco.Balboni@ARM.com Tick xbar_delay = responseLatency * clockPeriod(); 38110719SMarco.Balboni@ARM.com 38210719SMarco.Balboni@ARM.com // set the packet header and payload delay 38310719SMarco.Balboni@ARM.com calcPacketTiming(pkt, xbar_delay); 38410719SMarco.Balboni@ARM.com 38510719SMarco.Balboni@ARM.com // determine how long to be crossbar layer is busy 38610719SMarco.Balboni@ARM.com Tick packetFinishTime = clockEdge(Cycles(1)) + pkt->payloadDelay; 3878975SN/A 38810821Sandreas.hansson@arm.com if (snoopFilter && !system->bypassCaches()) { 38910402SN/A // let the snoop filter inspect the response and update its state 39010402SN/A snoopFilter->updateResponse(pkt, *slavePorts[slave_port_id]); 39110402SN/A } 39210402SN/A 39310888Sandreas.hansson@arm.com // send the packet through the destination slave port and pay for 39410888Sandreas.hansson@arm.com // any outstanding header delay 39510888Sandreas.hansson@arm.com Tick latency = pkt->headerDelay; 39610888Sandreas.hansson@arm.com pkt->headerDelay = 0; 39710888Sandreas.hansson@arm.com slavePorts[slave_port_id]->schedTimingResp(pkt, curTick() + latency); 3988975SN/A 39910656Sandreas.hansson@arm.com // remove the request from the routing table 40010656Sandreas.hansson@arm.com routeTo.erase(route_lookup); 40110656Sandreas.hansson@arm.com 4029715SN/A respLayers[slave_port_id]->succeededTiming(packetFinishTime); 4038975SN/A 4049712SN/A // stats updates 4059712SN/A pktCount[slave_port_id][master_port_id]++; 40610405Sandreas.hansson@arm.com pktSize[slave_port_id][master_port_id] += pkt_size; 4079712SN/A transDist[pkt_cmd]++; 4089712SN/A 4098975SN/A return true; 4108975SN/A} 4118975SN/A 4128975SN/Avoid 41310405Sandreas.hansson@arm.comCoherentXBar::recvTimingSnoopReq(PacketPtr pkt, PortID master_port_id) 4148975SN/A{ 41511744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__, 41611744Snikos.nikoleris@arm.com masterPorts[master_port_id]->name(), pkt->print()); 4178975SN/A 4189712SN/A // update stats here as we know the forwarding will succeed 41911564Sdavid.guillen@arm.com unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0; 4209712SN/A transDist[pkt->cmdToIndex()]++; 42110405Sandreas.hansson@arm.com snoops++; 42211564Sdavid.guillen@arm.com snoopTraffic += pkt_size; 4239712SN/A 4248975SN/A // we should only see express snoops from caches 4258975SN/A assert(pkt->isExpressSnoop()); 4268975SN/A 42711127Sandreas.hansson@arm.com // set the packet header and payload delay, for now use forward latency 42811127Sandreas.hansson@arm.com // @todo Assess the choice of latency further 42911127Sandreas.hansson@arm.com calcPacketTiming(pkt, forwardLatency * clockPeriod()); 43011127Sandreas.hansson@arm.com 43111284Sandreas.hansson@arm.com // remember if a cache has already committed to responding so we 43211284Sandreas.hansson@arm.com // can see if it changes during the snooping 43311284Sandreas.hansson@arm.com const bool cache_responding = pkt->cacheResponding(); 4349032SN/A 43511127Sandreas.hansson@arm.com assert(pkt->snoopDelay == 0); 43611127Sandreas.hansson@arm.com 43710402SN/A if (snoopFilter) { 43810402SN/A // let the Snoop Filter work its magic and guide probing 43910402SN/A auto sf_res = snoopFilter->lookupSnoop(pkt); 44011126Sandreas.hansson@arm.com // the time required by a packet to be delivered through 44111126Sandreas.hansson@arm.com // the xbar has to be charged also with to lookup latency 44211126Sandreas.hansson@arm.com // of the snoop filter 44311126Sandreas.hansson@arm.com pkt->headerDelay += sf_res.second * clockPeriod(); 44411744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s SF size: %i lat: %i\n", 44511744Snikos.nikoleris@arm.com __func__, masterPorts[master_port_id]->name(), pkt->print(), 44611744Snikos.nikoleris@arm.com sf_res.first.size(), sf_res.second); 44710402SN/A 44810402SN/A // forward to all snoopers 44910402SN/A forwardTiming(pkt, InvalidPortID, sf_res.first); 45010402SN/A } else { 45110402SN/A forwardTiming(pkt, InvalidPortID); 45210402SN/A } 4538975SN/A 45411127Sandreas.hansson@arm.com // add the snoop delay to our header delay, and then reset it 45511127Sandreas.hansson@arm.com pkt->headerDelay += pkt->snoopDelay; 45611127Sandreas.hansson@arm.com pkt->snoopDelay = 0; 45711127Sandreas.hansson@arm.com 45810656Sandreas.hansson@arm.com // if we can expect a response, remember how to route it 45911284Sandreas.hansson@arm.com if (!cache_responding && pkt->cacheResponding()) { 46010656Sandreas.hansson@arm.com assert(routeTo.find(pkt->req) == routeTo.end()); 46110656Sandreas.hansson@arm.com routeTo[pkt->req] = master_port_id; 46210656Sandreas.hansson@arm.com } 46310656Sandreas.hansson@arm.com 4648975SN/A // a snoop request came from a connected slave device (one of 4658975SN/A // our master ports), and if it is not coming from the slave 4668975SN/A // device responsible for the address range something is 4678975SN/A // wrong, hence there is nothing further to do as the packet 4688975SN/A // would be going back to where it came from 4699032SN/A assert(master_port_id == findPort(pkt->getAddr())); 4708975SN/A} 4718975SN/A 4728975SN/Abool 47310405Sandreas.hansson@arm.comCoherentXBar::recvTimingSnoopResp(PacketPtr pkt, PortID slave_port_id) 4748975SN/A{ 4758975SN/A // determine the source port based on the id 4769032SN/A SlavePort* src_port = slavePorts[slave_port_id]; 4778975SN/A 47810656Sandreas.hansson@arm.com // get the destination 47910656Sandreas.hansson@arm.com const auto route_lookup = routeTo.find(pkt->req); 48010656Sandreas.hansson@arm.com assert(route_lookup != routeTo.end()); 48110656Sandreas.hansson@arm.com const PortID dest_port_id = route_lookup->second; 48210572Sandreas.hansson@arm.com assert(dest_port_id != InvalidPortID); 4839714SN/A 4849714SN/A // determine if the response is from a snoop request we 4859714SN/A // created as the result of a normal request (in which case it 48610656Sandreas.hansson@arm.com // should be in the outstandingSnoop), or if we merely forwarded 4879714SN/A // someone else's snoop request 48810656Sandreas.hansson@arm.com const bool forwardAsSnoop = outstandingSnoop.find(pkt->req) == 48910656Sandreas.hansson@arm.com outstandingSnoop.end(); 4909714SN/A 49110405Sandreas.hansson@arm.com // test if the crossbar should be considered occupied for the 49210405Sandreas.hansson@arm.com // current port, note that the check is bypassed if the response 49310405Sandreas.hansson@arm.com // is being passed on as a normal response since this is occupying 49410405Sandreas.hansson@arm.com // the response layer rather than the snoop response layer 4959715SN/A if (forwardAsSnoop) { 49610572Sandreas.hansson@arm.com assert(dest_port_id < snoopLayers.size()); 4979715SN/A if (!snoopLayers[dest_port_id]->tryTiming(src_port)) { 49811744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s BUSY\n", __func__, 49911744Snikos.nikoleris@arm.com src_port->name(), pkt->print()); 5009715SN/A return false; 5019715SN/A } 5029716SN/A } else { 5039716SN/A // get the master port that mirrors this slave port internally 5049716SN/A MasterPort* snoop_port = snoopRespPorts[slave_port_id]; 50510572Sandreas.hansson@arm.com assert(dest_port_id < respLayers.size()); 5069716SN/A if (!respLayers[dest_port_id]->tryTiming(snoop_port)) { 50711744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s BUSY\n", __func__, 50811744Snikos.nikoleris@arm.com snoop_port->name(), pkt->print()); 5099716SN/A return false; 5109716SN/A } 5118975SN/A } 5128975SN/A 51311744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__, 51411744Snikos.nikoleris@arm.com src_port->name(), pkt->print()); 5158975SN/A 5169712SN/A // store size and command as they might be modified when 5179712SN/A // forwarding the packet 5189712SN/A unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0; 5199712SN/A unsigned int pkt_cmd = pkt->cmdToIndex(); 5209712SN/A 5218975SN/A // responses are never express snoops 5228975SN/A assert(!pkt->isExpressSnoop()); 5238975SN/A 52410719SMarco.Balboni@ARM.com // a snoop response sees the snoop response latency, and if it is 52510719SMarco.Balboni@ARM.com // forwarded as a normal response, the response latency 52610719SMarco.Balboni@ARM.com Tick xbar_delay = 52710719SMarco.Balboni@ARM.com (forwardAsSnoop ? snoopResponseLatency : responseLatency) * 52810719SMarco.Balboni@ARM.com clockPeriod(); 52910719SMarco.Balboni@ARM.com 53010719SMarco.Balboni@ARM.com // set the packet header and payload delay 53110719SMarco.Balboni@ARM.com calcPacketTiming(pkt, xbar_delay); 53210719SMarco.Balboni@ARM.com 53310719SMarco.Balboni@ARM.com // determine how long to be crossbar layer is busy 53410719SMarco.Balboni@ARM.com Tick packetFinishTime = clockEdge(Cycles(1)) + pkt->payloadDelay; 5358975SN/A 5369714SN/A // forward it either as a snoop response or a normal response 5379714SN/A if (forwardAsSnoop) { 5389714SN/A // this is a snoop response to a snoop request we forwarded, 5399714SN/A // e.g. coming from the L1 and going to the L2, and it should 5409714SN/A // be forwarded as a snoop response 54110402SN/A 54210402SN/A if (snoopFilter) { 54310402SN/A // update the probe filter so that it can properly track the line 54410402SN/A snoopFilter->updateSnoopForward(pkt, *slavePorts[slave_port_id], 54510402SN/A *masterPorts[dest_port_id]); 54610402SN/A } 54710402SN/A 5489712SN/A bool success M5_VAR_USED = 5499712SN/A masterPorts[dest_port_id]->sendTimingSnoopResp(pkt); 5509712SN/A pktCount[slave_port_id][dest_port_id]++; 55110405Sandreas.hansson@arm.com pktSize[slave_port_id][dest_port_id] += pkt_size; 5528975SN/A assert(success); 5539714SN/A 5549715SN/A snoopLayers[dest_port_id]->succeededTiming(packetFinishTime); 5553244SN/A } else { 5568975SN/A // we got a snoop response on one of our slave ports, 55710405Sandreas.hansson@arm.com // i.e. from a coherent master connected to the crossbar, and 55810405Sandreas.hansson@arm.com // since we created the snoop request as part of recvTiming, 55910405Sandreas.hansson@arm.com // this should now be a normal response again 56010656Sandreas.hansson@arm.com outstandingSnoop.erase(pkt->req); 5618948SN/A 56210656Sandreas.hansson@arm.com // this is a snoop response from a coherent master, hence it 56310656Sandreas.hansson@arm.com // should never go back to where the snoop response came from, 56410656Sandreas.hansson@arm.com // but instead to where the original request came from 5659712SN/A assert(slave_port_id != dest_port_id); 5668948SN/A 56710402SN/A if (snoopFilter) { 56810402SN/A // update the probe filter so that it can properly track the line 56910402SN/A snoopFilter->updateSnoopResponse(pkt, *slavePorts[slave_port_id], 57010402SN/A *slavePorts[dest_port_id]); 57110402SN/A } 57210402SN/A 57311744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s FWD RESP\n", __func__, 57411744Snikos.nikoleris@arm.com src_port->name(), pkt->print()); 57510402SN/A 5769714SN/A // as a normal response, it should go back to a master through 57710888Sandreas.hansson@arm.com // one of our slave ports, we also pay for any outstanding 57810888Sandreas.hansson@arm.com // header latency 57910888Sandreas.hansson@arm.com Tick latency = pkt->headerDelay; 58010888Sandreas.hansson@arm.com pkt->headerDelay = 0; 58110888Sandreas.hansson@arm.com slavePorts[dest_port_id]->schedTimingResp(pkt, curTick() + latency); 5829716SN/A 5839716SN/A respLayers[dest_port_id]->succeededTiming(packetFinishTime); 5843244SN/A } 5853244SN/A 58610656Sandreas.hansson@arm.com // remove the request from the routing table 58710656Sandreas.hansson@arm.com routeTo.erase(route_lookup); 58810656Sandreas.hansson@arm.com 5899712SN/A // stats updates 5909712SN/A transDist[pkt_cmd]++; 59110405Sandreas.hansson@arm.com snoops++; 59211564Sdavid.guillen@arm.com snoopTraffic += pkt_size; 5939712SN/A 5948948SN/A return true; 5958948SN/A} 5968948SN/A 5973210SN/A 5988948SN/Avoid 59910405Sandreas.hansson@arm.comCoherentXBar::forwardTiming(PacketPtr pkt, PortID exclude_slave_port_id, 60010888Sandreas.hansson@arm.com const std::vector<QueuedSlavePort*>& dests) 6018948SN/A{ 60211744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s for %s\n", __func__, pkt->print()); 6039663SN/A 6049524SN/A // snoops should only happen if the system isn't bypassing caches 6059524SN/A assert(!system->bypassCaches()); 6069524SN/A 60710401SN/A unsigned fanout = 0; 60810401SN/A 60910405Sandreas.hansson@arm.com for (const auto& p: dests) { 6108948SN/A // we could have gotten this request from a snooping master 6118948SN/A // (corresponding to our own slave port that is also in 6128948SN/A // snoopPorts) and should not send it back to where it came 6138948SN/A // from 6149031SN/A if (exclude_slave_port_id == InvalidPortID || 6158948SN/A p->getId() != exclude_slave_port_id) { 6168948SN/A // cache is not allowed to refuse snoop 6178975SN/A p->sendTimingSnoopReq(pkt); 61810401SN/A fanout++; 6198948SN/A } 6208948SN/A } 62110401SN/A 62210401SN/A // Stats for fanout of this forward operation 62310401SN/A snoopFanout.sample(fanout); 6242497SN/A} 6252497SN/A 6269092SN/Avoid 62710713Sandreas.hansson@arm.comCoherentXBar::recvReqRetry(PortID master_port_id) 6289092SN/A{ 6299093SN/A // responses and snoop responses never block on forwarding them, 6309093SN/A // so the retry will always be coming from a port to which we 6319093SN/A // tried to forward a request 6329715SN/A reqLayers[master_port_id]->recvRetry(); 6339092SN/A} 6349092SN/A 6359036SN/ATick 63610405Sandreas.hansson@arm.comCoherentXBar::recvAtomic(PacketPtr pkt, PortID slave_port_id) 6372657SN/A{ 63811744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__, 63911744Snikos.nikoleris@arm.com slavePorts[slave_port_id]->name(), pkt->print()); 6408915SN/A 64110405Sandreas.hansson@arm.com unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0; 64210405Sandreas.hansson@arm.com unsigned int pkt_cmd = pkt->cmdToIndex(); 6439712SN/A 6448979SN/A MemCmd snoop_response_cmd = MemCmd::InvalidCmd; 6458979SN/A Tick snoop_response_latency = 0; 6468979SN/A 64710821Sandreas.hansson@arm.com if (!system->bypassCaches()) { 6488979SN/A // forward to all snoopers but the source 64910402SN/A std::pair<MemCmd, Tick> snoop_result; 65010402SN/A if (snoopFilter) { 65110402SN/A // check with the snoop filter where to forward this packet 65210402SN/A auto sf_res = 65310402SN/A snoopFilter->lookupRequest(pkt, *slavePorts[slave_port_id]); 65410402SN/A snoop_response_latency += sf_res.second * clockPeriod(); 65511744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s SF size: %i lat: %i\n", 65611744Snikos.nikoleris@arm.com __func__, slavePorts[slave_port_id]->name(), pkt->print(), 65711744Snikos.nikoleris@arm.com sf_res.first.size(), sf_res.second); 65811130Sali.jafri@arm.com 65911130Sali.jafri@arm.com // let the snoop filter know about the success of the send 66011130Sali.jafri@arm.com // operation, and do it even before sending it onwards to 66111130Sali.jafri@arm.com // avoid situations where atomic upward snoops sneak in 66211130Sali.jafri@arm.com // between and change the filter state 66311605Snikos.nikoleris@arm.com snoopFilter->finishRequest(false, pkt->getAddr(), pkt->isSecure()); 66411130Sali.jafri@arm.com 66512241Snikos.nikoleris@arm.com if (pkt->isEviction()) { 66612241Snikos.nikoleris@arm.com // for block-evicting packets, i.e. writebacks and 66712241Snikos.nikoleris@arm.com // clean evictions, there is no need to snoop up, as 66812241Snikos.nikoleris@arm.com // all we do is determine if the block is cached or 66912241Snikos.nikoleris@arm.com // not, instead just set it here based on the snoop 67012241Snikos.nikoleris@arm.com // filter result 67112241Snikos.nikoleris@arm.com if (!sf_res.first.empty()) 67212241Snikos.nikoleris@arm.com pkt->setBlockCached(); 67312241Snikos.nikoleris@arm.com } else { 67412241Snikos.nikoleris@arm.com snoop_result = forwardAtomic(pkt, slave_port_id, InvalidPortID, 67512241Snikos.nikoleris@arm.com sf_res.first); 67612241Snikos.nikoleris@arm.com } 67710402SN/A } else { 67810402SN/A snoop_result = forwardAtomic(pkt, slave_port_id); 67910402SN/A } 6808979SN/A snoop_response_cmd = snoop_result.first; 68110402SN/A snoop_response_latency += snoop_result.second; 6828979SN/A } 6838915SN/A 68411334Sandreas.hansson@arm.com // set up a sensible default value 68511334Sandreas.hansson@arm.com Tick response_latency = 0; 68611334Sandreas.hansson@arm.com 68711334Sandreas.hansson@arm.com const bool sink_packet = sinkPacket(pkt); 68811130Sali.jafri@arm.com 6898948SN/A // even if we had a snoop response, we must continue and also 6908948SN/A // perform the actual request at the destination 69110405Sandreas.hansson@arm.com PortID master_port_id = findPort(pkt->getAddr()); 69210405Sandreas.hansson@arm.com 69311334Sandreas.hansson@arm.com if (sink_packet) { 69411744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: Not forwarding %s\n", __func__, 69511744Snikos.nikoleris@arm.com pkt->print()); 69611334Sandreas.hansson@arm.com } else { 69711334Sandreas.hansson@arm.com if (!pointOfCoherency || pkt->isRead() || pkt->isWrite()) { 69811334Sandreas.hansson@arm.com // forward the request to the appropriate destination 69911334Sandreas.hansson@arm.com response_latency = masterPorts[master_port_id]->sendAtomic(pkt); 70011334Sandreas.hansson@arm.com } else { 70111334Sandreas.hansson@arm.com // if it does not need a response we sink the packet above 70211334Sandreas.hansson@arm.com assert(pkt->needsResponse()); 70311334Sandreas.hansson@arm.com 70411334Sandreas.hansson@arm.com pkt->makeResponse(); 70511334Sandreas.hansson@arm.com } 70611334Sandreas.hansson@arm.com } 70711334Sandreas.hansson@arm.com 70810405Sandreas.hansson@arm.com // stats updates for the request 70910405Sandreas.hansson@arm.com pktCount[slave_port_id][master_port_id]++; 71010405Sandreas.hansson@arm.com pktSize[slave_port_id][master_port_id] += pkt_size; 71110405Sandreas.hansson@arm.com transDist[pkt_cmd]++; 7128948SN/A 7138948SN/A 71411130Sali.jafri@arm.com // if lower levels have replied, tell the snoop filter 71511130Sali.jafri@arm.com if (!system->bypassCaches() && snoopFilter && pkt->isResponse()) { 71610402SN/A snoopFilter->updateResponse(pkt, *slavePorts[slave_port_id]); 71710402SN/A } 71810402SN/A 7198948SN/A // if we got a response from a snooper, restore it here 7208948SN/A if (snoop_response_cmd != MemCmd::InvalidCmd) { 7218948SN/A // no one else should have responded 7228948SN/A assert(!pkt->isResponse()); 7238948SN/A pkt->cmd = snoop_response_cmd; 7248948SN/A response_latency = snoop_response_latency; 7258948SN/A } 7268948SN/A 7279712SN/A // add the response data 72810405Sandreas.hansson@arm.com if (pkt->isResponse()) { 72910405Sandreas.hansson@arm.com pkt_size = pkt->hasData() ? pkt->getSize() : 0; 73010405Sandreas.hansson@arm.com pkt_cmd = pkt->cmdToIndex(); 73110405Sandreas.hansson@arm.com 73210405Sandreas.hansson@arm.com // stats updates 73310405Sandreas.hansson@arm.com pktCount[slave_port_id][master_port_id]++; 73410405Sandreas.hansson@arm.com pktSize[slave_port_id][master_port_id] += pkt_size; 73510405Sandreas.hansson@arm.com transDist[pkt_cmd]++; 73610405Sandreas.hansson@arm.com } 7379712SN/A 73810694SMarco.Balboni@ARM.com // @todo: Not setting header time 73910694SMarco.Balboni@ARM.com pkt->payloadDelay = response_latency; 7408948SN/A return response_latency; 7418948SN/A} 7428948SN/A 7438948SN/ATick 74410405Sandreas.hansson@arm.comCoherentXBar::recvAtomicSnoop(PacketPtr pkt, PortID master_port_id) 7458948SN/A{ 74611744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__, 74711744Snikos.nikoleris@arm.com masterPorts[master_port_id]->name(), pkt->print()); 7488948SN/A 7499712SN/A // add the request snoop data 75011564Sdavid.guillen@arm.com unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0; 75110405Sandreas.hansson@arm.com snoops++; 75211564Sdavid.guillen@arm.com snoopTraffic += pkt_size; 7539712SN/A 7548948SN/A // forward to all snoopers 75510402SN/A std::pair<MemCmd, Tick> snoop_result; 75610402SN/A Tick snoop_response_latency = 0; 75710402SN/A if (snoopFilter) { 75810402SN/A auto sf_res = snoopFilter->lookupSnoop(pkt); 75910402SN/A snoop_response_latency += sf_res.second * clockPeriod(); 76011744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s SF size: %i lat: %i\n", 76111744Snikos.nikoleris@arm.com __func__, masterPorts[master_port_id]->name(), pkt->print(), 76211744Snikos.nikoleris@arm.com sf_res.first.size(), sf_res.second); 76310402SN/A snoop_result = forwardAtomic(pkt, InvalidPortID, master_port_id, 76410402SN/A sf_res.first); 76510402SN/A } else { 76610402SN/A snoop_result = forwardAtomic(pkt, InvalidPortID); 76710402SN/A } 7688948SN/A MemCmd snoop_response_cmd = snoop_result.first; 76910402SN/A snoop_response_latency += snoop_result.second; 7708948SN/A 7718948SN/A if (snoop_response_cmd != MemCmd::InvalidCmd) 7728948SN/A pkt->cmd = snoop_response_cmd; 7738948SN/A 7749712SN/A // add the response snoop data 77510401SN/A if (pkt->isResponse()) { 77610405Sandreas.hansson@arm.com snoops++; 77710401SN/A } 7789712SN/A 77910694SMarco.Balboni@ARM.com // @todo: Not setting header time 78010694SMarco.Balboni@ARM.com pkt->payloadDelay = snoop_response_latency; 7818948SN/A return snoop_response_latency; 7828948SN/A} 7838948SN/A 7848948SN/Astd::pair<MemCmd, Tick> 78510405Sandreas.hansson@arm.comCoherentXBar::forwardAtomic(PacketPtr pkt, PortID exclude_slave_port_id, 78610402SN/A PortID source_master_port_id, 78710888Sandreas.hansson@arm.com const std::vector<QueuedSlavePort*>& dests) 7888948SN/A{ 7899032SN/A // the packet may be changed on snoops, record the original 7909032SN/A // command to enable us to restore it between snoops so that 7918948SN/A // additional snoops can take place properly 7924626SN/A MemCmd orig_cmd = pkt->cmd; 7934879SN/A MemCmd snoop_response_cmd = MemCmd::InvalidCmd; 7944879SN/A Tick snoop_response_latency = 0; 7953662SN/A 7969524SN/A // snoops should only happen if the system isn't bypassing caches 7979524SN/A assert(!system->bypassCaches()); 7989524SN/A 79910401SN/A unsigned fanout = 0; 80010401SN/A 80110405Sandreas.hansson@arm.com for (const auto& p: dests) { 8028915SN/A // we could have gotten this request from a snooping master 8038915SN/A // (corresponding to our own slave port that is also in 8048915SN/A // snoopPorts) and should not send it back to where it came 8058915SN/A // from 80610402SN/A if (exclude_slave_port_id != InvalidPortID && 80710402SN/A p->getId() == exclude_slave_port_id) 80810402SN/A continue; 80910401SN/A 81010402SN/A Tick latency = p->sendAtomicSnoop(pkt); 81110402SN/A fanout++; 81210402SN/A 81310402SN/A // in contrast to a functional access, we have to keep on 81410402SN/A // going as all snoopers must be updated even if we get a 81510402SN/A // response 81610402SN/A if (!pkt->isResponse()) 81710402SN/A continue; 81810402SN/A 81910402SN/A // response from snoop agent 82010402SN/A assert(pkt->cmd != orig_cmd); 82111284Sandreas.hansson@arm.com assert(pkt->cacheResponding()); 82210402SN/A // should only happen once 82310402SN/A assert(snoop_response_cmd == MemCmd::InvalidCmd); 82410402SN/A // save response state 82510402SN/A snoop_response_cmd = pkt->cmd; 82610402SN/A snoop_response_latency = latency; 82710402SN/A 82810402SN/A if (snoopFilter) { 82910402SN/A // Handle responses by the snoopers and differentiate between 83010402SN/A // responses to requests from above and snoops from below 83110402SN/A if (source_master_port_id != InvalidPortID) { 83210402SN/A // Getting a response for a snoop from below 83310402SN/A assert(exclude_slave_port_id == InvalidPortID); 83410402SN/A snoopFilter->updateSnoopForward(pkt, *p, 83510402SN/A *masterPorts[source_master_port_id]); 83610402SN/A } else { 83710402SN/A // Getting a response for a request from above 83810402SN/A assert(source_master_port_id == InvalidPortID); 83910402SN/A snoopFilter->updateSnoopResponse(pkt, *p, 84010402SN/A *slavePorts[exclude_slave_port_id]); 8414626SN/A } 8424626SN/A } 84310402SN/A // restore original packet state for remaining snoopers 84410402SN/A pkt->cmd = orig_cmd; 8454626SN/A } 8464626SN/A 84710401SN/A // Stats for fanout 84810401SN/A snoopFanout.sample(fanout); 84910401SN/A 8508948SN/A // the packet is restored as part of the loop and any potential 8518948SN/A // snoop response is part of the returned pair 8528948SN/A return std::make_pair(snoop_response_cmd, snoop_response_latency); 8532497SN/A} 8542497SN/A 8552497SN/Avoid 85610405Sandreas.hansson@arm.comCoherentXBar::recvFunctional(PacketPtr pkt, PortID slave_port_id) 8572497SN/A{ 8588663SN/A if (!pkt->isPrint()) { 8598663SN/A // don't do DPRINTFs on PrintReq as it clutters up the output 86011744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__, 86111744Snikos.nikoleris@arm.com slavePorts[slave_port_id]->name(), pkt->print()); 8628663SN/A } 8638663SN/A 86410821Sandreas.hansson@arm.com if (!system->bypassCaches()) { 8658979SN/A // forward to all snoopers but the source 8669032SN/A forwardFunctional(pkt, slave_port_id); 8678979SN/A } 8684912SN/A 8698948SN/A // there is no need to continue if the snooping has found what we 8708948SN/A // were looking for and the packet is already a response 8718948SN/A if (!pkt->isResponse()) { 87210888Sandreas.hansson@arm.com // since our slave ports are queued ports we need to check them as well 87310888Sandreas.hansson@arm.com for (const auto& p : slavePorts) { 87410888Sandreas.hansson@arm.com // if we find a response that has the data, then the 87510888Sandreas.hansson@arm.com // downstream caches/memories may be out of date, so simply stop 87610888Sandreas.hansson@arm.com // here 87710888Sandreas.hansson@arm.com if (p->checkFunctional(pkt)) { 87810888Sandreas.hansson@arm.com if (pkt->needsResponse()) 87910888Sandreas.hansson@arm.com pkt->makeResponse(); 88010888Sandreas.hansson@arm.com return; 88110888Sandreas.hansson@arm.com } 88210888Sandreas.hansson@arm.com } 88310888Sandreas.hansson@arm.com 8849031SN/A PortID dest_id = findPort(pkt->getAddr()); 8858948SN/A 8868948SN/A masterPorts[dest_id]->sendFunctional(pkt); 8878948SN/A } 8888948SN/A} 8898948SN/A 8908948SN/Avoid 89110405Sandreas.hansson@arm.comCoherentXBar::recvFunctionalSnoop(PacketPtr pkt, PortID master_port_id) 8928948SN/A{ 8938948SN/A if (!pkt->isPrint()) { 8948948SN/A // don't do DPRINTFs on PrintReq as it clutters up the output 89511744Snikos.nikoleris@arm.com DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__, 89611744Snikos.nikoleris@arm.com masterPorts[master_port_id]->name(), pkt->print()); 8978948SN/A } 8988948SN/A 89911188Sandreas.sandberg@arm.com for (const auto& p : slavePorts) { 90011188Sandreas.sandberg@arm.com if (p->checkFunctional(pkt)) { 90111188Sandreas.sandberg@arm.com if (pkt->needsResponse()) 90211188Sandreas.sandberg@arm.com pkt->makeResponse(); 90311188Sandreas.sandberg@arm.com return; 90411188Sandreas.sandberg@arm.com } 90511188Sandreas.sandberg@arm.com } 90611188Sandreas.sandberg@arm.com 9078948SN/A // forward to all snoopers 9089031SN/A forwardFunctional(pkt, InvalidPortID); 9098948SN/A} 9108948SN/A 9118948SN/Avoid 91210405Sandreas.hansson@arm.comCoherentXBar::forwardFunctional(PacketPtr pkt, PortID exclude_slave_port_id) 9138948SN/A{ 9149524SN/A // snoops should only happen if the system isn't bypassing caches 9159524SN/A assert(!system->bypassCaches()); 9169524SN/A 91710405Sandreas.hansson@arm.com for (const auto& p: snoopPorts) { 9188915SN/A // we could have gotten this request from a snooping master 9198915SN/A // (corresponding to our own slave port that is also in 9208915SN/A // snoopPorts) and should not send it back to where it came 9218915SN/A // from 9229031SN/A if (exclude_slave_port_id == InvalidPortID || 9238948SN/A p->getId() != exclude_slave_port_id) 9248948SN/A p->sendFunctionalSnoop(pkt); 9258915SN/A 9268948SN/A // if we get a response we are done 9278948SN/A if (pkt->isResponse()) { 9288948SN/A break; 9298915SN/A } 9303650SN/A } 9312497SN/A} 9322497SN/A 93311334Sandreas.hansson@arm.combool 93411334Sandreas.hansson@arm.comCoherentXBar::sinkPacket(const PacketPtr pkt) const 93511334Sandreas.hansson@arm.com{ 93611334Sandreas.hansson@arm.com // we can sink the packet if: 93711334Sandreas.hansson@arm.com // 1) the crossbar is the point of coherency, and a cache is 93811334Sandreas.hansson@arm.com // responding after being snooped 93911334Sandreas.hansson@arm.com // 2) the crossbar is the point of coherency, and the packet is a 94011334Sandreas.hansson@arm.com // coherency packet (not a read or a write) that does not 94111334Sandreas.hansson@arm.com // require a response 94211334Sandreas.hansson@arm.com // 3) this is a clean evict or clean writeback, but the packet is 94311334Sandreas.hansson@arm.com // found in a cache above this crossbar 94411334Sandreas.hansson@arm.com // 4) a cache is responding after being snooped, and the packet 94511334Sandreas.hansson@arm.com // either does not need the block to be writable, or the cache 94611334Sandreas.hansson@arm.com // that has promised to respond (setting the cache responding 94711334Sandreas.hansson@arm.com // flag) is providing writable and thus had a Modified block, 94811334Sandreas.hansson@arm.com // and no further action is needed 94911334Sandreas.hansson@arm.com return (pointOfCoherency && pkt->cacheResponding()) || 95011334Sandreas.hansson@arm.com (pointOfCoherency && !(pkt->isRead() || pkt->isWrite()) && 95111334Sandreas.hansson@arm.com !pkt->needsResponse()) || 95211334Sandreas.hansson@arm.com (pkt->isCleanEviction() && pkt->isBlockCached()) || 95311334Sandreas.hansson@arm.com (pkt->cacheResponding() && 95411334Sandreas.hansson@arm.com (!pkt->needsWritable() || pkt->responderHadWritable())); 95511334Sandreas.hansson@arm.com} 95611334Sandreas.hansson@arm.com 9579712SN/Avoid 95810405Sandreas.hansson@arm.comCoherentXBar::regStats() 9599712SN/A{ 96010405Sandreas.hansson@arm.com // register the stats of the base class and our layers 96110405Sandreas.hansson@arm.com BaseXBar::regStats(); 96210405Sandreas.hansson@arm.com for (auto l: reqLayers) 96310405Sandreas.hansson@arm.com l->regStats(); 96410405Sandreas.hansson@arm.com for (auto l: respLayers) 96510405Sandreas.hansson@arm.com l->regStats(); 96610405Sandreas.hansson@arm.com for (auto l: snoopLayers) 96710405Sandreas.hansson@arm.com l->regStats(); 9689712SN/A 96910405Sandreas.hansson@arm.com snoops 97010405Sandreas.hansson@arm.com .name(name() + ".snoops") 97110401SN/A .desc("Total snoops (count)") 97210401SN/A ; 97310401SN/A 97411564Sdavid.guillen@arm.com snoopTraffic 97511564Sdavid.guillen@arm.com .name(name() + ".snoopTraffic") 97611564Sdavid.guillen@arm.com .desc("Total snoop traffic (bytes)") 97711564Sdavid.guillen@arm.com ; 97811564Sdavid.guillen@arm.com 97910401SN/A snoopFanout 98010401SN/A .init(0, snoopPorts.size(), 1) 98110401SN/A .name(name() + ".snoop_fanout") 98210401SN/A .desc("Request fanout histogram") 98310401SN/A ; 9849712SN/A} 9859712SN/A 98610405Sandreas.hansson@arm.comCoherentXBar * 98710405Sandreas.hansson@arm.comCoherentXBarParams::create() 9882497SN/A{ 98910405Sandreas.hansson@arm.com return new CoherentXBar(this); 9902497SN/A} 991