snoop_filter.cc revision 12334
110399Sstephan.diestelhorst@arm.com/* 211603Sandreas.hansson@arm.com * Copyright (c) 2013-2016 ARM Limited 310399Sstephan.diestelhorst@arm.com * All rights reserved 410399Sstephan.diestelhorst@arm.com * 510399Sstephan.diestelhorst@arm.com * The license below extends only to copyright in the software and shall 610399Sstephan.diestelhorst@arm.com * not be construed as granting a license to any other intellectual 710399Sstephan.diestelhorst@arm.com * property including but not limited to intellectual property relating 810399Sstephan.diestelhorst@arm.com * to a hardware implementation of the functionality of the software 910399Sstephan.diestelhorst@arm.com * licensed hereunder. You may use the software subject to the license 1010399Sstephan.diestelhorst@arm.com * terms below provided that you ensure that this notice is replicated 1110399Sstephan.diestelhorst@arm.com * unmodified and in its entirety in all distributions of the software, 1210399Sstephan.diestelhorst@arm.com * modified or unmodified, in source code or in binary form. 1310399Sstephan.diestelhorst@arm.com * 1410399Sstephan.diestelhorst@arm.com * Redistribution and use in source and binary forms, with or without 1510399Sstephan.diestelhorst@arm.com * modification, are permitted provided that the following conditions are 1610399Sstephan.diestelhorst@arm.com * met: redistributions of source code must retain the above copyright 1710399Sstephan.diestelhorst@arm.com * notice, this list of conditions and the following disclaimer; 1810399Sstephan.diestelhorst@arm.com * redistributions in binary form must reproduce the above copyright 1910399Sstephan.diestelhorst@arm.com * notice, this list of conditions and the following disclaimer in the 2010399Sstephan.diestelhorst@arm.com * documentation and/or other materials provided with the distribution; 2110399Sstephan.diestelhorst@arm.com * neither the name of the copyright holders nor the names of its 2210399Sstephan.diestelhorst@arm.com * contributors may be used to endorse or promote products derived from 2310399Sstephan.diestelhorst@arm.com * this software without specific prior written permission. 2410399Sstephan.diestelhorst@arm.com * 2510399Sstephan.diestelhorst@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2610399Sstephan.diestelhorst@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2710399Sstephan.diestelhorst@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2810399Sstephan.diestelhorst@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2910399Sstephan.diestelhorst@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3010399Sstephan.diestelhorst@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3110399Sstephan.diestelhorst@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3210399Sstephan.diestelhorst@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3310399Sstephan.diestelhorst@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3410399Sstephan.diestelhorst@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3510399Sstephan.diestelhorst@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3610399Sstephan.diestelhorst@arm.com * 3711135Sandreas.hansson@arm.com * Authors: Stephan Diestelhorst 3810399Sstephan.diestelhorst@arm.com */ 3910399Sstephan.diestelhorst@arm.com 4010399Sstephan.diestelhorst@arm.com/** 4110399Sstephan.diestelhorst@arm.com * @file 4211135Sandreas.hansson@arm.com * Implementation of a snoop filter. 4310399Sstephan.diestelhorst@arm.com */ 4410399Sstephan.diestelhorst@arm.com 4511793Sbrandon.potter@amd.com#include "mem/snoop_filter.hh" 4611793Sbrandon.potter@amd.com 4712334Sgabeblack@google.com#include "base/logging.hh" 4810399Sstephan.diestelhorst@arm.com#include "base/trace.hh" 4910399Sstephan.diestelhorst@arm.com#include "debug/SnoopFilter.hh" 5010399Sstephan.diestelhorst@arm.com#include "sim/system.hh" 5110399Sstephan.diestelhorst@arm.com 5211129Sali.jafri@arm.comvoid 5311129Sali.jafri@arm.comSnoopFilter::eraseIfNullEntry(SnoopFilterCache::iterator& sf_it) 5411129Sali.jafri@arm.com{ 5511129Sali.jafri@arm.com SnoopItem& sf_item = sf_it->second; 5611129Sali.jafri@arm.com if (!(sf_item.requested | sf_item.holder)) { 5711129Sali.jafri@arm.com cachedLocations.erase(sf_it); 5811129Sali.jafri@arm.com DPRINTF(SnoopFilter, "%s: Removed SF entry.\n", 5911129Sali.jafri@arm.com __func__); 6011129Sali.jafri@arm.com } 6111129Sali.jafri@arm.com} 6211129Sali.jafri@arm.com 6310399Sstephan.diestelhorst@arm.comstd::pair<SnoopFilter::SnoopList, Cycles> 6410399Sstephan.diestelhorst@arm.comSnoopFilter::lookupRequest(const Packet* cpkt, const SlavePort& slave_port) 6510399Sstephan.diestelhorst@arm.com{ 6611744Snikos.nikoleris@arm.com DPRINTF(SnoopFilter, "%s: src %s packet %s\n", __func__, 6711744Snikos.nikoleris@arm.com slave_port.name(), cpkt->print()); 6810399Sstephan.diestelhorst@arm.com 6911603Sandreas.hansson@arm.com // check if the packet came from a cache 7011603Sandreas.hansson@arm.com bool allocate = !cpkt->req->isUncacheable() && slave_port.isSnooping() && 7111603Sandreas.hansson@arm.com cpkt->fromCache(); 7211128Sali.jafri@arm.com Addr line_addr = cpkt->getBlockAddr(linesize); 7311605Snikos.nikoleris@arm.com if (cpkt->isSecure()) { 7411605Snikos.nikoleris@arm.com line_addr |= LineSecure; 7511605Snikos.nikoleris@arm.com } 7610399Sstephan.diestelhorst@arm.com SnoopMask req_port = portToMask(slave_port); 7711131Sandreas.hansson@arm.com reqLookupResult = cachedLocations.find(line_addr); 7811131Sandreas.hansson@arm.com bool is_hit = (reqLookupResult != cachedLocations.end()); 7911128Sali.jafri@arm.com 8011128Sali.jafri@arm.com // If the snoop filter has no entry, and we should not allocate, 8111128Sali.jafri@arm.com // do not create a new snoop filter entry, simply return a NULL 8211128Sali.jafri@arm.com // portlist. 8311128Sali.jafri@arm.com if (!is_hit && !allocate) 8411128Sali.jafri@arm.com return snoopDown(lookupLatency); 8511128Sali.jafri@arm.com 8611131Sandreas.hansson@arm.com // If no hit in snoop filter create a new element and update iterator 8711131Sandreas.hansson@arm.com if (!is_hit) 8811131Sandreas.hansson@arm.com reqLookupResult = cachedLocations.emplace(line_addr, SnoopItem()).first; 8911131Sandreas.hansson@arm.com SnoopItem& sf_item = reqLookupResult->second; 9010403Sstephan.diestelhorst@arm.com SnoopMask interested = sf_item.holder | sf_item.requested; 9110403Sstephan.diestelhorst@arm.com 9211129Sali.jafri@arm.com // Store unmodified value of snoop filter item in temp storage in 9311129Sali.jafri@arm.com // case we need to revert because of a send retry in 9411129Sali.jafri@arm.com // updateRequest. 9511129Sali.jafri@arm.com retryItem = sf_item; 9611129Sali.jafri@arm.com 9710403Sstephan.diestelhorst@arm.com totRequests++; 9810403Sstephan.diestelhorst@arm.com if (is_hit) { 9910403Sstephan.diestelhorst@arm.com // Single bit set -> value is a power of two 10010403Sstephan.diestelhorst@arm.com if (isPow2(interested)) 10110403Sstephan.diestelhorst@arm.com hitSingleRequests++; 10210403Sstephan.diestelhorst@arm.com else 10310403Sstephan.diestelhorst@arm.com hitMultiRequests++; 10410403Sstephan.diestelhorst@arm.com } 10510399Sstephan.diestelhorst@arm.com 10610399Sstephan.diestelhorst@arm.com DPRINTF(SnoopFilter, "%s: SF value %x.%x\n", 10710399Sstephan.diestelhorst@arm.com __func__, sf_item.requested, sf_item.holder); 10810399Sstephan.diestelhorst@arm.com 10911129Sali.jafri@arm.com // If we are not allocating, we are done 11011129Sali.jafri@arm.com if (!allocate) 11111129Sali.jafri@arm.com return snoopSelected(maskToPortList(interested & ~req_port), 11211129Sali.jafri@arm.com lookupLatency); 11311129Sali.jafri@arm.com 11411129Sali.jafri@arm.com if (cpkt->needsResponse()) { 11511284Sandreas.hansson@arm.com if (!cpkt->cacheResponding()) { 11610399Sstephan.diestelhorst@arm.com // Max one request per address per port 11711129Sali.jafri@arm.com panic_if(sf_item.requested & req_port, "double request :( " \ 11810399Sstephan.diestelhorst@arm.com "SF value %x.%x\n", sf_item.requested, sf_item.holder); 11910399Sstephan.diestelhorst@arm.com 12010399Sstephan.diestelhorst@arm.com // Mark in-flight requests to distinguish later on 12110399Sstephan.diestelhorst@arm.com sf_item.requested |= req_port; 12211129Sali.jafri@arm.com DPRINTF(SnoopFilter, "%s: new SF value %x.%x\n", 12311129Sali.jafri@arm.com __func__, sf_item.requested, sf_item.holder); 12410399Sstephan.diestelhorst@arm.com } else { 12510399Sstephan.diestelhorst@arm.com // NOTE: The memInhibit might have been asserted by a cache closer 12610399Sstephan.diestelhorst@arm.com // to the CPU, already -> the response will not be seen by this 12710399Sstephan.diestelhorst@arm.com // filter -> we do not need to keep the in-flight request, but make 12810399Sstephan.diestelhorst@arm.com // sure that we know that that cluster has a copy 12910399Sstephan.diestelhorst@arm.com panic_if(!(sf_item.holder & req_port), "Need to hold the value!"); 13011129Sali.jafri@arm.com DPRINTF(SnoopFilter, 13111129Sali.jafri@arm.com "%s: not marking request. SF value %x.%x\n", 13210399Sstephan.diestelhorst@arm.com __func__, sf_item.requested, sf_item.holder); 13310399Sstephan.diestelhorst@arm.com } 13411129Sali.jafri@arm.com } else { // if (!cpkt->needsResponse()) 13511199Sandreas.hansson@arm.com assert(cpkt->isEviction()); 13611129Sali.jafri@arm.com // make sure that the sender actually had the line 13711129Sali.jafri@arm.com panic_if(!(sf_item.holder & req_port), "requester %x is not a " \ 13811129Sali.jafri@arm.com "holder :( SF value %x.%x\n", req_port, 13911129Sali.jafri@arm.com sf_item.requested, sf_item.holder); 14011129Sali.jafri@arm.com // CleanEvicts and Writebacks -> the sender and all caches above 14111129Sali.jafri@arm.com // it may not have the line anymore. 14211129Sali.jafri@arm.com if (!cpkt->isBlockCached()) { 14311129Sali.jafri@arm.com sf_item.holder &= ~req_port; 14411129Sali.jafri@arm.com DPRINTF(SnoopFilter, "%s: new SF value %x.%x\n", 14511129Sali.jafri@arm.com __func__, sf_item.requested, sf_item.holder); 14611129Sali.jafri@arm.com } 14710399Sstephan.diestelhorst@arm.com } 14811129Sali.jafri@arm.com 14910403Sstephan.diestelhorst@arm.com return snoopSelected(maskToPortList(interested & ~req_port), lookupLatency); 15010399Sstephan.diestelhorst@arm.com} 15110399Sstephan.diestelhorst@arm.com 15210399Sstephan.diestelhorst@arm.comvoid 15311605Snikos.nikoleris@arm.comSnoopFilter::finishRequest(bool will_retry, Addr addr, bool is_secure) 15410399Sstephan.diestelhorst@arm.com{ 15511131Sandreas.hansson@arm.com if (reqLookupResult != cachedLocations.end()) { 15611131Sandreas.hansson@arm.com // since we rely on the caller, do a basic check to ensure 15711131Sandreas.hansson@arm.com // that finishRequest is being called following lookupRequest 15811605Snikos.nikoleris@arm.com Addr line_addr = (addr & ~(Addr(linesize - 1))); 15911605Snikos.nikoleris@arm.com if (is_secure) { 16011605Snikos.nikoleris@arm.com line_addr |= LineSecure; 16111605Snikos.nikoleris@arm.com } 16211605Snikos.nikoleris@arm.com assert(reqLookupResult->first == line_addr); 16311131Sandreas.hansson@arm.com if (will_retry) { 16411131Sandreas.hansson@arm.com // Undo any changes made in lookupRequest to the snoop filter 16511131Sandreas.hansson@arm.com // entry if the request will come again. retryItem holds 16611131Sandreas.hansson@arm.com // the previous value of the snoopfilter entry. 16711131Sandreas.hansson@arm.com reqLookupResult->second = retryItem; 16810399Sstephan.diestelhorst@arm.com 16911131Sandreas.hansson@arm.com DPRINTF(SnoopFilter, "%s: restored SF value %x.%x\n", 17011131Sandreas.hansson@arm.com __func__, retryItem.requested, retryItem.holder); 17111131Sandreas.hansson@arm.com } 17210821Sandreas.hansson@arm.com 17311131Sandreas.hansson@arm.com eraseIfNullEntry(reqLookupResult); 17410399Sstephan.diestelhorst@arm.com } 17510399Sstephan.diestelhorst@arm.com} 17610399Sstephan.diestelhorst@arm.com 17710399Sstephan.diestelhorst@arm.comstd::pair<SnoopFilter::SnoopList, Cycles> 17810399Sstephan.diestelhorst@arm.comSnoopFilter::lookupSnoop(const Packet* cpkt) 17910399Sstephan.diestelhorst@arm.com{ 18011744Snikos.nikoleris@arm.com DPRINTF(SnoopFilter, "%s: packet %s\n", __func__, cpkt->print()); 18110399Sstephan.diestelhorst@arm.com 18210399Sstephan.diestelhorst@arm.com assert(cpkt->isRequest()); 18310399Sstephan.diestelhorst@arm.com 18411128Sali.jafri@arm.com Addr line_addr = cpkt->getBlockAddr(linesize); 18511605Snikos.nikoleris@arm.com if (cpkt->isSecure()) { 18611605Snikos.nikoleris@arm.com line_addr |= LineSecure; 18711605Snikos.nikoleris@arm.com } 18810403Sstephan.diestelhorst@arm.com auto sf_it = cachedLocations.find(line_addr); 18910403Sstephan.diestelhorst@arm.com bool is_hit = (sf_it != cachedLocations.end()); 19011129Sali.jafri@arm.com 19111132Sali.jafri@arm.com panic_if(!is_hit && (cachedLocations.size() >= maxEntryCount), 19211132Sali.jafri@arm.com "snoop filter exceeded capacity of %d cache blocks\n", 19311132Sali.jafri@arm.com maxEntryCount); 19411132Sali.jafri@arm.com 19511134Sandreas.hansson@arm.com // If the snoop filter has no entry, simply return a NULL 19611134Sandreas.hansson@arm.com // portlist, there is no point creating an entry only to remove it 19711134Sandreas.hansson@arm.com // later 19811134Sandreas.hansson@arm.com if (!is_hit) 19911129Sali.jafri@arm.com return snoopDown(lookupLatency); 20011129Sali.jafri@arm.com 20111129Sali.jafri@arm.com SnoopItem& sf_item = sf_it->second; 20210399Sstephan.diestelhorst@arm.com 20310399Sstephan.diestelhorst@arm.com DPRINTF(SnoopFilter, "%s: old SF value %x.%x\n", 20410399Sstephan.diestelhorst@arm.com __func__, sf_item.requested, sf_item.holder); 20510399Sstephan.diestelhorst@arm.com 20610399Sstephan.diestelhorst@arm.com SnoopMask interested = (sf_item.holder | sf_item.requested); 20710403Sstephan.diestelhorst@arm.com 20810403Sstephan.diestelhorst@arm.com totSnoops++; 20911134Sandreas.hansson@arm.com // Single bit set -> value is a power of two 21011134Sandreas.hansson@arm.com if (isPow2(interested)) 21111134Sandreas.hansson@arm.com hitSingleSnoops++; 21211134Sandreas.hansson@arm.com else 21311134Sandreas.hansson@arm.com hitMultiSnoops++; 21411134Sandreas.hansson@arm.com 21510883Sali.jafri@arm.com // ReadEx and Writes require both invalidation and exlusivity, while reads 21610883Sali.jafri@arm.com // require neither. Writebacks on the other hand require exclusivity but 21710883Sali.jafri@arm.com // not the invalidation. Previously Writebacks did not generate upward 21810883Sali.jafri@arm.com // snoops so this was never an aissue. Now that Writebacks generate snoops 21910883Sali.jafri@arm.com // we need to special case for Writebacks. 22011199Sandreas.hansson@arm.com assert(cpkt->isWriteback() || cpkt->req->isUncacheable() || 22111284Sandreas.hansson@arm.com (cpkt->isInvalidate() == cpkt->needsWritable())); 22210399Sstephan.diestelhorst@arm.com if (cpkt->isInvalidate() && !sf_item.requested) { 22310399Sstephan.diestelhorst@arm.com // Early clear of the holder, if no other request is currently going on 22410399Sstephan.diestelhorst@arm.com // @todo: This should possibly be updated even though we do not filter 22510399Sstephan.diestelhorst@arm.com // upward snoops 22610399Sstephan.diestelhorst@arm.com sf_item.holder = 0; 22710399Sstephan.diestelhorst@arm.com } 22810399Sstephan.diestelhorst@arm.com 22911129Sali.jafri@arm.com eraseIfNullEntry(sf_it); 23010399Sstephan.diestelhorst@arm.com DPRINTF(SnoopFilter, "%s: new SF value %x.%x interest: %x \n", 23110399Sstephan.diestelhorst@arm.com __func__, sf_item.requested, sf_item.holder, interested); 23210399Sstephan.diestelhorst@arm.com 23310399Sstephan.diestelhorst@arm.com return snoopSelected(maskToPortList(interested), lookupLatency); 23410399Sstephan.diestelhorst@arm.com} 23510399Sstephan.diestelhorst@arm.com 23610399Sstephan.diestelhorst@arm.comvoid 23710399Sstephan.diestelhorst@arm.comSnoopFilter::updateSnoopResponse(const Packet* cpkt, 23810399Sstephan.diestelhorst@arm.com const SlavePort& rsp_port, 23910399Sstephan.diestelhorst@arm.com const SlavePort& req_port) 24010399Sstephan.diestelhorst@arm.com{ 24111744Snikos.nikoleris@arm.com DPRINTF(SnoopFilter, "%s: rsp %s req %s packet %s\n", 24211744Snikos.nikoleris@arm.com __func__, rsp_port.name(), req_port.name(), cpkt->print()); 24310399Sstephan.diestelhorst@arm.com 24410821Sandreas.hansson@arm.com assert(cpkt->isResponse()); 24511284Sandreas.hansson@arm.com assert(cpkt->cacheResponding()); 24610821Sandreas.hansson@arm.com 24711603Sandreas.hansson@arm.com // if this snoop response is due to an uncacheable request, or is 24811603Sandreas.hansson@arm.com // being turned into a normal response, there is nothing more to 24911603Sandreas.hansson@arm.com // do 25011603Sandreas.hansson@arm.com if (cpkt->req->isUncacheable() || !req_port.isSnooping()) { 25110821Sandreas.hansson@arm.com return; 25211603Sandreas.hansson@arm.com } 25310821Sandreas.hansson@arm.com 25411128Sali.jafri@arm.com Addr line_addr = cpkt->getBlockAddr(linesize); 25511605Snikos.nikoleris@arm.com if (cpkt->isSecure()) { 25611605Snikos.nikoleris@arm.com line_addr |= LineSecure; 25711605Snikos.nikoleris@arm.com } 25810399Sstephan.diestelhorst@arm.com SnoopMask rsp_mask = portToMask(rsp_port); 25910399Sstephan.diestelhorst@arm.com SnoopMask req_mask = portToMask(req_port); 26010399Sstephan.diestelhorst@arm.com SnoopItem& sf_item = cachedLocations[line_addr]; 26110399Sstephan.diestelhorst@arm.com 26210399Sstephan.diestelhorst@arm.com DPRINTF(SnoopFilter, "%s: old SF value %x.%x\n", 26310399Sstephan.diestelhorst@arm.com __func__, sf_item.requested, sf_item.holder); 26410399Sstephan.diestelhorst@arm.com 26510399Sstephan.diestelhorst@arm.com // The source should have the line 26610399Sstephan.diestelhorst@arm.com panic_if(!(sf_item.holder & rsp_mask), "SF value %x.%x does not have "\ 26710399Sstephan.diestelhorst@arm.com "the line\n", sf_item.requested, sf_item.holder); 26810399Sstephan.diestelhorst@arm.com 26910399Sstephan.diestelhorst@arm.com // The destination should have had a request in 27010399Sstephan.diestelhorst@arm.com panic_if(!(sf_item.requested & req_mask), "SF value %x.%x missing "\ 27110399Sstephan.diestelhorst@arm.com "the original request\n", sf_item.requested, sf_item.holder); 27210399Sstephan.diestelhorst@arm.com 27311287Sandreas.hansson@arm.com // If the snoop response has no sharers the line is passed in 27411287Sandreas.hansson@arm.com // Modified state, and we know that there are no other copies, or 27511287Sandreas.hansson@arm.com // they will all be invalidated imminently 27611287Sandreas.hansson@arm.com if (!cpkt->hasSharers()) { 27711287Sandreas.hansson@arm.com DPRINTF(SnoopFilter, 27811287Sandreas.hansson@arm.com "%s: dropping %x because non-shared snoop " 27911287Sandreas.hansson@arm.com "response SF val: %x.%x\n", __func__, rsp_mask, 28010399Sstephan.diestelhorst@arm.com sf_item.requested, sf_item.holder); 28110399Sstephan.diestelhorst@arm.com sf_item.holder = 0; 28210399Sstephan.diestelhorst@arm.com } 28311199Sandreas.hansson@arm.com assert(!cpkt->isWriteback()); 28411603Sandreas.hansson@arm.com // @todo Deal with invalidating responses 28510399Sstephan.diestelhorst@arm.com sf_item.holder |= req_mask; 28610399Sstephan.diestelhorst@arm.com sf_item.requested &= ~req_mask; 28711129Sali.jafri@arm.com assert(sf_item.requested | sf_item.holder); 28810399Sstephan.diestelhorst@arm.com DPRINTF(SnoopFilter, "%s: new SF value %x.%x\n", 28910399Sstephan.diestelhorst@arm.com __func__, sf_item.requested, sf_item.holder); 29010399Sstephan.diestelhorst@arm.com} 29110399Sstephan.diestelhorst@arm.com 29210399Sstephan.diestelhorst@arm.comvoid 29310399Sstephan.diestelhorst@arm.comSnoopFilter::updateSnoopForward(const Packet* cpkt, 29410399Sstephan.diestelhorst@arm.com const SlavePort& rsp_port, const MasterPort& req_port) 29510399Sstephan.diestelhorst@arm.com{ 29611744Snikos.nikoleris@arm.com DPRINTF(SnoopFilter, "%s: rsp %s req %s packet %s\n", 29711744Snikos.nikoleris@arm.com __func__, rsp_port.name(), req_port.name(), cpkt->print()); 29810399Sstephan.diestelhorst@arm.com 29911134Sandreas.hansson@arm.com assert(cpkt->isResponse()); 30011284Sandreas.hansson@arm.com assert(cpkt->cacheResponding()); 30111134Sandreas.hansson@arm.com 30211128Sali.jafri@arm.com Addr line_addr = cpkt->getBlockAddr(linesize); 30311605Snikos.nikoleris@arm.com if (cpkt->isSecure()) { 30411605Snikos.nikoleris@arm.com line_addr |= LineSecure; 30511605Snikos.nikoleris@arm.com } 30611129Sali.jafri@arm.com auto sf_it = cachedLocations.find(line_addr); 30711134Sandreas.hansson@arm.com bool is_hit = sf_it != cachedLocations.end(); 30811134Sandreas.hansson@arm.com 30911134Sandreas.hansson@arm.com // Nothing to do if it is not a hit 31011134Sandreas.hansson@arm.com if (!is_hit) 31111134Sandreas.hansson@arm.com return; 31211134Sandreas.hansson@arm.com 31311129Sali.jafri@arm.com SnoopItem& sf_item = sf_it->second; 31410399Sstephan.diestelhorst@arm.com 31510399Sstephan.diestelhorst@arm.com DPRINTF(SnoopFilter, "%s: old SF value %x.%x\n", 31610399Sstephan.diestelhorst@arm.com __func__, sf_item.requested, sf_item.holder); 31710399Sstephan.diestelhorst@arm.com 31811287Sandreas.hansson@arm.com // If the snoop response has no sharers the line is passed in 31911287Sandreas.hansson@arm.com // Modified state, and we know that there are no other copies, or 32011287Sandreas.hansson@arm.com // they will all be invalidated imminently 32111287Sandreas.hansson@arm.com if (!cpkt->hasSharers()) { 32210399Sstephan.diestelhorst@arm.com sf_item.holder = 0; 32310399Sstephan.diestelhorst@arm.com } 32410399Sstephan.diestelhorst@arm.com DPRINTF(SnoopFilter, "%s: new SF value %x.%x\n", 32510399Sstephan.diestelhorst@arm.com __func__, sf_item.requested, sf_item.holder); 32611129Sali.jafri@arm.com eraseIfNullEntry(sf_it); 32711134Sandreas.hansson@arm.com 32810399Sstephan.diestelhorst@arm.com} 32910399Sstephan.diestelhorst@arm.com 33010399Sstephan.diestelhorst@arm.comvoid 33110399Sstephan.diestelhorst@arm.comSnoopFilter::updateResponse(const Packet* cpkt, const SlavePort& slave_port) 33210399Sstephan.diestelhorst@arm.com{ 33311744Snikos.nikoleris@arm.com DPRINTF(SnoopFilter, "%s: src %s packet %s\n", 33411744Snikos.nikoleris@arm.com __func__, slave_port.name(), cpkt->print()); 33510399Sstephan.diestelhorst@arm.com 33610821Sandreas.hansson@arm.com assert(cpkt->isResponse()); 33710821Sandreas.hansson@arm.com 33811603Sandreas.hansson@arm.com // we only allocate if the packet actually came from a cache, but 33911603Sandreas.hansson@arm.com // start by checking if the port is snooping 34011603Sandreas.hansson@arm.com if (cpkt->req->isUncacheable() || !slave_port.isSnooping()) 34110821Sandreas.hansson@arm.com return; 34210821Sandreas.hansson@arm.com 34311603Sandreas.hansson@arm.com // next check if we actually allocated an entry 34411128Sali.jafri@arm.com Addr line_addr = cpkt->getBlockAddr(linesize); 34511605Snikos.nikoleris@arm.com if (cpkt->isSecure()) { 34611605Snikos.nikoleris@arm.com line_addr |= LineSecure; 34711605Snikos.nikoleris@arm.com } 34811603Sandreas.hansson@arm.com auto sf_it = cachedLocations.find(line_addr); 34911603Sandreas.hansson@arm.com if (sf_it == cachedLocations.end()) 35011603Sandreas.hansson@arm.com return; 35111603Sandreas.hansson@arm.com 35210399Sstephan.diestelhorst@arm.com SnoopMask slave_mask = portToMask(slave_port); 35311603Sandreas.hansson@arm.com SnoopItem& sf_item = sf_it->second; 35410399Sstephan.diestelhorst@arm.com 35510399Sstephan.diestelhorst@arm.com DPRINTF(SnoopFilter, "%s: old SF value %x.%x\n", 35610399Sstephan.diestelhorst@arm.com __func__, sf_item.requested, sf_item.holder); 35710399Sstephan.diestelhorst@arm.com 35810399Sstephan.diestelhorst@arm.com // Make sure we have seen the actual request, too 35910399Sstephan.diestelhorst@arm.com panic_if(!(sf_item.requested & slave_mask), "SF value %x.%x missing "\ 36010399Sstephan.diestelhorst@arm.com "request bit\n", sf_item.requested, sf_item.holder); 36110399Sstephan.diestelhorst@arm.com 36211748Snikos.nikoleris@arm.com // Update the residency of the cache line. 36310399Sstephan.diestelhorst@arm.com sf_item.holder |= slave_mask; 36410399Sstephan.diestelhorst@arm.com sf_item.requested &= ~slave_mask; 36511129Sali.jafri@arm.com assert(sf_item.holder | sf_item.requested); 36610399Sstephan.diestelhorst@arm.com DPRINTF(SnoopFilter, "%s: new SF value %x.%x\n", 36710399Sstephan.diestelhorst@arm.com __func__, sf_item.requested, sf_item.holder); 36810399Sstephan.diestelhorst@arm.com} 36910399Sstephan.diestelhorst@arm.com 37010403Sstephan.diestelhorst@arm.comvoid 37110403Sstephan.diestelhorst@arm.comSnoopFilter::regStats() 37210403Sstephan.diestelhorst@arm.com{ 37311523Sdavid.guillen@arm.com SimObject::regStats(); 37411523Sdavid.guillen@arm.com 37510403Sstephan.diestelhorst@arm.com totRequests 37610403Sstephan.diestelhorst@arm.com .name(name() + ".tot_requests") 37710403Sstephan.diestelhorst@arm.com .desc("Total number of requests made to the snoop filter."); 37810403Sstephan.diestelhorst@arm.com 37910403Sstephan.diestelhorst@arm.com hitSingleRequests 38010403Sstephan.diestelhorst@arm.com .name(name() + ".hit_single_requests") 38110403Sstephan.diestelhorst@arm.com .desc("Number of requests hitting in the snoop filter with a single "\ 38210403Sstephan.diestelhorst@arm.com "holder of the requested data."); 38310403Sstephan.diestelhorst@arm.com 38410403Sstephan.diestelhorst@arm.com hitMultiRequests 38510403Sstephan.diestelhorst@arm.com .name(name() + ".hit_multi_requests") 38610403Sstephan.diestelhorst@arm.com .desc("Number of requests hitting in the snoop filter with multiple "\ 38710403Sstephan.diestelhorst@arm.com "(>1) holders of the requested data."); 38810403Sstephan.diestelhorst@arm.com 38910403Sstephan.diestelhorst@arm.com totSnoops 39010403Sstephan.diestelhorst@arm.com .name(name() + ".tot_snoops") 39110403Sstephan.diestelhorst@arm.com .desc("Total number of snoops made to the snoop filter."); 39210403Sstephan.diestelhorst@arm.com 39310403Sstephan.diestelhorst@arm.com hitSingleSnoops 39410403Sstephan.diestelhorst@arm.com .name(name() + ".hit_single_snoops") 39510403Sstephan.diestelhorst@arm.com .desc("Number of snoops hitting in the snoop filter with a single "\ 39610403Sstephan.diestelhorst@arm.com "holder of the requested data."); 39710403Sstephan.diestelhorst@arm.com 39810403Sstephan.diestelhorst@arm.com hitMultiSnoops 39910403Sstephan.diestelhorst@arm.com .name(name() + ".hit_multi_snoops") 40010403Sstephan.diestelhorst@arm.com .desc("Number of snoops hitting in the snoop filter with multiple "\ 40110403Sstephan.diestelhorst@arm.com "(>1) holders of the requested data."); 40210403Sstephan.diestelhorst@arm.com} 40310403Sstephan.diestelhorst@arm.com 40410399Sstephan.diestelhorst@arm.comSnoopFilter * 40510399Sstephan.diestelhorst@arm.comSnoopFilterParams::create() 40610399Sstephan.diestelhorst@arm.com{ 40710399Sstephan.diestelhorst@arm.com return new SnoopFilter(this); 40810399Sstephan.diestelhorst@arm.com} 409