snoop_filter.cc revision 11129
110399Sstephan.diestelhorst@arm.com/*
211128Sali.jafri@arm.com * Copyright (c) 2013-2015 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 *
3710399Sstephan.diestelhorst@arm.com * Authors: Stephan Diestelhorst <stephan.diestelhorst@arm.com>
3810399Sstephan.diestelhorst@arm.com */
3910399Sstephan.diestelhorst@arm.com
4010399Sstephan.diestelhorst@arm.com/**
4110399Sstephan.diestelhorst@arm.com * @file
4210399Sstephan.diestelhorst@arm.com * Definition of a snoop filter.
4310399Sstephan.diestelhorst@arm.com */
4410399Sstephan.diestelhorst@arm.com
4510399Sstephan.diestelhorst@arm.com#include "base/misc.hh"
4610399Sstephan.diestelhorst@arm.com#include "base/trace.hh"
4710399Sstephan.diestelhorst@arm.com#include "debug/SnoopFilter.hh"
4810399Sstephan.diestelhorst@arm.com#include "mem/snoop_filter.hh"
4910399Sstephan.diestelhorst@arm.com#include "sim/system.hh"
5010399Sstephan.diestelhorst@arm.com
5111129Sali.jafri@arm.comvoid
5211129Sali.jafri@arm.comSnoopFilter::eraseIfNullEntry(SnoopFilterCache::iterator& sf_it)
5311129Sali.jafri@arm.com{
5411129Sali.jafri@arm.com    SnoopItem& sf_item = sf_it->second;
5511129Sali.jafri@arm.com    if (!(sf_item.requested | sf_item.holder)) {
5611129Sali.jafri@arm.com        cachedLocations.erase(sf_it);
5711129Sali.jafri@arm.com        DPRINTF(SnoopFilter, "%s:   Removed SF entry.\n",
5811129Sali.jafri@arm.com                __func__);
5911129Sali.jafri@arm.com    }
6011129Sali.jafri@arm.com}
6111129Sali.jafri@arm.com
6210399Sstephan.diestelhorst@arm.comstd::pair<SnoopFilter::SnoopList, Cycles>
6310399Sstephan.diestelhorst@arm.comSnoopFilter::lookupRequest(const Packet* cpkt, const SlavePort& slave_port)
6410399Sstephan.diestelhorst@arm.com{
6510399Sstephan.diestelhorst@arm.com    DPRINTF(SnoopFilter, "%s: packet src %s addr 0x%x cmd %s\n",
6610399Sstephan.diestelhorst@arm.com            __func__, slave_port.name(), cpkt->getAddr(), cpkt->cmdString());
6710399Sstephan.diestelhorst@arm.com
6811128Sali.jafri@arm.com    // Ultimately we should check if the packet came from an
6911128Sali.jafri@arm.com    // allocating source, not just if the port is snooping
7011128Sali.jafri@arm.com    bool allocate = !cpkt->req->isUncacheable() && slave_port.isSnooping();
7111128Sali.jafri@arm.com    Addr line_addr = cpkt->getBlockAddr(linesize);
7210399Sstephan.diestelhorst@arm.com    SnoopMask req_port = portToMask(slave_port);
7310403Sstephan.diestelhorst@arm.com    auto sf_it = cachedLocations.find(line_addr);
7410403Sstephan.diestelhorst@arm.com    bool is_hit = (sf_it != cachedLocations.end());
7511128Sali.jafri@arm.com
7611128Sali.jafri@arm.com    // If the snoop filter has no entry, and we should not allocate,
7711128Sali.jafri@arm.com    // do not create a new snoop filter entry, simply return a NULL
7811128Sali.jafri@arm.com    // portlist.
7911128Sali.jafri@arm.com    if (!is_hit && !allocate)
8011128Sali.jafri@arm.com        return snoopDown(lookupLatency);
8111128Sali.jafri@arm.com
8210403Sstephan.diestelhorst@arm.com    // Create a new element through operator[] and modify in-place
8310403Sstephan.diestelhorst@arm.com    SnoopItem& sf_item = is_hit ? sf_it->second : cachedLocations[line_addr];
8410403Sstephan.diestelhorst@arm.com    SnoopMask interested = sf_item.holder | sf_item.requested;
8510403Sstephan.diestelhorst@arm.com
8611129Sali.jafri@arm.com    // Store unmodified value of snoop filter item in temp storage in
8711129Sali.jafri@arm.com    // case we need to revert because of a send retry in
8811129Sali.jafri@arm.com    // updateRequest.
8911129Sali.jafri@arm.com    retryItem = sf_item;
9011129Sali.jafri@arm.com
9110403Sstephan.diestelhorst@arm.com    totRequests++;
9210403Sstephan.diestelhorst@arm.com    if (is_hit) {
9310403Sstephan.diestelhorst@arm.com        // Single bit set -> value is a power of two
9410403Sstephan.diestelhorst@arm.com        if (isPow2(interested))
9510403Sstephan.diestelhorst@arm.com            hitSingleRequests++;
9610403Sstephan.diestelhorst@arm.com        else
9710403Sstephan.diestelhorst@arm.com            hitMultiRequests++;
9810403Sstephan.diestelhorst@arm.com    }
9910399Sstephan.diestelhorst@arm.com
10010399Sstephan.diestelhorst@arm.com    DPRINTF(SnoopFilter, "%s:   SF value %x.%x\n",
10110399Sstephan.diestelhorst@arm.com            __func__, sf_item.requested, sf_item.holder);
10210399Sstephan.diestelhorst@arm.com
10311129Sali.jafri@arm.com    // If we are not allocating, we are done
10411129Sali.jafri@arm.com    if (!allocate)
10511129Sali.jafri@arm.com        return snoopSelected(maskToPortList(interested & ~req_port),
10611129Sali.jafri@arm.com                             lookupLatency);
10711129Sali.jafri@arm.com
10811129Sali.jafri@arm.com    if (cpkt->needsResponse()) {
10910399Sstephan.diestelhorst@arm.com        if (!cpkt->memInhibitAsserted()) {
11010399Sstephan.diestelhorst@arm.com            // Max one request per address per port
11111129Sali.jafri@arm.com            panic_if(sf_item.requested & req_port, "double request :( " \
11210399Sstephan.diestelhorst@arm.com                     "SF value %x.%x\n", sf_item.requested, sf_item.holder);
11310399Sstephan.diestelhorst@arm.com
11410399Sstephan.diestelhorst@arm.com            // Mark in-flight requests to distinguish later on
11510399Sstephan.diestelhorst@arm.com            sf_item.requested |= req_port;
11611129Sali.jafri@arm.com            DPRINTF(SnoopFilter, "%s:   new SF value %x.%x\n",
11711129Sali.jafri@arm.com                    __func__,  sf_item.requested, sf_item.holder);
11810399Sstephan.diestelhorst@arm.com        } else {
11910399Sstephan.diestelhorst@arm.com            // NOTE: The memInhibit might have been asserted by a cache closer
12010399Sstephan.diestelhorst@arm.com            // to the CPU, already -> the response will not be seen by this
12110399Sstephan.diestelhorst@arm.com            // filter -> we do not need to keep the in-flight request, but make
12210399Sstephan.diestelhorst@arm.com            // sure that we know that that cluster has a copy
12310399Sstephan.diestelhorst@arm.com            panic_if(!(sf_item.holder & req_port), "Need to hold the value!");
12411129Sali.jafri@arm.com            DPRINTF(SnoopFilter,
12511129Sali.jafri@arm.com                    "%s: not marking request. SF value %x.%x\n",
12610399Sstephan.diestelhorst@arm.com                    __func__,  sf_item.requested, sf_item.holder);
12710399Sstephan.diestelhorst@arm.com        }
12811129Sali.jafri@arm.com    } else { // if (!cpkt->needsResponse())
12911129Sali.jafri@arm.com        assert(cpkt->evictingBlock());
13011129Sali.jafri@arm.com        // make sure that the sender actually had the line
13111129Sali.jafri@arm.com        panic_if(!(sf_item.holder & req_port), "requester %x is not a " \
13211129Sali.jafri@arm.com                 "holder :( SF value %x.%x\n", req_port,
13311129Sali.jafri@arm.com                 sf_item.requested, sf_item.holder);
13411129Sali.jafri@arm.com        // CleanEvicts and Writebacks -> the sender and all caches above
13511129Sali.jafri@arm.com        // it may not have the line anymore.
13611129Sali.jafri@arm.com        if (!cpkt->isBlockCached()) {
13711129Sali.jafri@arm.com            sf_item.holder &= ~req_port;
13811129Sali.jafri@arm.com            DPRINTF(SnoopFilter, "%s:   new SF value %x.%x\n",
13911129Sali.jafri@arm.com                    __func__,  sf_item.requested, sf_item.holder);
14011129Sali.jafri@arm.com        }
14110399Sstephan.diestelhorst@arm.com    }
14211129Sali.jafri@arm.com
14310403Sstephan.diestelhorst@arm.com    return snoopSelected(maskToPortList(interested & ~req_port), lookupLatency);
14410399Sstephan.diestelhorst@arm.com}
14510399Sstephan.diestelhorst@arm.com
14610399Sstephan.diestelhorst@arm.comvoid
14710399Sstephan.diestelhorst@arm.comSnoopFilter::updateRequest(const Packet* cpkt, const SlavePort& slave_port,
14810399Sstephan.diestelhorst@arm.com                           bool will_retry)
14910399Sstephan.diestelhorst@arm.com{
15010399Sstephan.diestelhorst@arm.com    DPRINTF(SnoopFilter, "%s: packet src %s addr 0x%x cmd %s\n",
15110399Sstephan.diestelhorst@arm.com            __func__, slave_port.name(), cpkt->getAddr(), cpkt->cmdString());
15210399Sstephan.diestelhorst@arm.com
15311128Sali.jafri@arm.com    // Ultimately we should check if the packet came from an
15411128Sali.jafri@arm.com    // allocating source, not just if the port is snooping
15511128Sali.jafri@arm.com    bool allocate = !cpkt->req->isUncacheable() && slave_port.isSnooping();
15611128Sali.jafri@arm.com    if (!allocate)
15710821Sandreas.hansson@arm.com        return;
15810821Sandreas.hansson@arm.com
15911128Sali.jafri@arm.com    Addr line_addr = cpkt->getBlockAddr(linesize);
16011129Sali.jafri@arm.com    auto sf_it = cachedLocations.find(line_addr);
16111129Sali.jafri@arm.com    assert(sf_it != cachedLocations.end());
16211129Sali.jafri@arm.com    if (will_retry) {
16311129Sali.jafri@arm.com        // Undo any changes made in lookupRequest to the snoop filter
16411129Sali.jafri@arm.com        // entry if the request will come again. retryItem holds
16511129Sali.jafri@arm.com        // the previous value of the snoopfilter entry.
16611129Sali.jafri@arm.com        sf_it->second = retryItem;
16710399Sstephan.diestelhorst@arm.com
16811129Sali.jafri@arm.com        DPRINTF(SnoopFilter, "%s:   restored SF value %x.%x\n",
16911129Sali.jafri@arm.com                __func__,  retryItem.requested, retryItem.holder);
17010399Sstephan.diestelhorst@arm.com    }
17110399Sstephan.diestelhorst@arm.com
17211129Sali.jafri@arm.com    eraseIfNullEntry(sf_it);
17310399Sstephan.diestelhorst@arm.com}
17410399Sstephan.diestelhorst@arm.com
17510399Sstephan.diestelhorst@arm.comstd::pair<SnoopFilter::SnoopList, Cycles>
17610399Sstephan.diestelhorst@arm.comSnoopFilter::lookupSnoop(const Packet* cpkt)
17710399Sstephan.diestelhorst@arm.com{
17810399Sstephan.diestelhorst@arm.com    DPRINTF(SnoopFilter, "%s: packet addr 0x%x cmd %s\n",
17910399Sstephan.diestelhorst@arm.com            __func__, cpkt->getAddr(), cpkt->cmdString());
18010399Sstephan.diestelhorst@arm.com
18110399Sstephan.diestelhorst@arm.com    assert(cpkt->isRequest());
18210399Sstephan.diestelhorst@arm.com
18310399Sstephan.diestelhorst@arm.com    // Broadcast / filter upward snoops
18410399Sstephan.diestelhorst@arm.com    const bool filter_upward = true;  // @todo: Make configurable
18510399Sstephan.diestelhorst@arm.com
18610399Sstephan.diestelhorst@arm.com    if (!filter_upward)
18710399Sstephan.diestelhorst@arm.com        return snoopAll(lookupLatency);
18810399Sstephan.diestelhorst@arm.com
18911128Sali.jafri@arm.com    Addr line_addr = cpkt->getBlockAddr(linesize);
19010403Sstephan.diestelhorst@arm.com    auto sf_it = cachedLocations.find(line_addr);
19110403Sstephan.diestelhorst@arm.com    bool is_hit = (sf_it != cachedLocations.end());
19211129Sali.jafri@arm.com
19311129Sali.jafri@arm.com    // If the snoop filter has no entry and its an uncacheable
19411129Sali.jafri@arm.com    // request, do not create a new snoop filter entry, simply return
19511129Sali.jafri@arm.com    // a NULL portlist.
19611129Sali.jafri@arm.com    if (!is_hit && cpkt->req->isUncacheable())
19711129Sali.jafri@arm.com        return snoopDown(lookupLatency);
19811129Sali.jafri@arm.com
19911129Sali.jafri@arm.com    // If no hit in snoop filter create a new element and update iterator
20011129Sali.jafri@arm.com    if (!is_hit)
20111129Sali.jafri@arm.com        sf_it = cachedLocations.emplace(line_addr, SnoopItem()).first;
20211129Sali.jafri@arm.com    SnoopItem& sf_item = sf_it->second;
20310399Sstephan.diestelhorst@arm.com
20410399Sstephan.diestelhorst@arm.com    DPRINTF(SnoopFilter, "%s:   old SF value %x.%x\n",
20510399Sstephan.diestelhorst@arm.com            __func__, sf_item.requested, sf_item.holder);
20610399Sstephan.diestelhorst@arm.com
20710399Sstephan.diestelhorst@arm.com    SnoopMask interested = (sf_item.holder | sf_item.requested);
20810403Sstephan.diestelhorst@arm.com
20910403Sstephan.diestelhorst@arm.com    totSnoops++;
21010403Sstephan.diestelhorst@arm.com    if (is_hit) {
21110403Sstephan.diestelhorst@arm.com        // Single bit set -> value is a power of two
21210403Sstephan.diestelhorst@arm.com        if (isPow2(interested))
21310403Sstephan.diestelhorst@arm.com            hitSingleSnoops++;
21410403Sstephan.diestelhorst@arm.com        else
21510403Sstephan.diestelhorst@arm.com            hitMultiSnoops++;
21610403Sstephan.diestelhorst@arm.com    }
21710883Sali.jafri@arm.com    // ReadEx and Writes require both invalidation and exlusivity, while reads
21810883Sali.jafri@arm.com    // require neither. Writebacks on the other hand require exclusivity but
21910883Sali.jafri@arm.com    // not the invalidation. Previously Writebacks did not generate upward
22010883Sali.jafri@arm.com    // snoops so this was never an aissue. Now that Writebacks generate snoops
22110883Sali.jafri@arm.com    // we need to special case for Writebacks.
22211129Sali.jafri@arm.com    assert(cpkt->cmd == MemCmd::Writeback || cpkt->req->isUncacheable() ||
22310883Sali.jafri@arm.com           (cpkt->isInvalidate() == cpkt->needsExclusive()));
22410399Sstephan.diestelhorst@arm.com    if (cpkt->isInvalidate() && !sf_item.requested) {
22510399Sstephan.diestelhorst@arm.com        // Early clear of the holder, if no other request is currently going on
22610399Sstephan.diestelhorst@arm.com        // @todo: This should possibly be updated even though we do not filter
22710399Sstephan.diestelhorst@arm.com        // upward snoops
22810399Sstephan.diestelhorst@arm.com        sf_item.holder = 0;
22910399Sstephan.diestelhorst@arm.com    }
23010399Sstephan.diestelhorst@arm.com
23111129Sali.jafri@arm.com    eraseIfNullEntry(sf_it);
23210399Sstephan.diestelhorst@arm.com    DPRINTF(SnoopFilter, "%s:   new SF value %x.%x interest: %x \n",
23310399Sstephan.diestelhorst@arm.com            __func__, sf_item.requested, sf_item.holder, interested);
23410399Sstephan.diestelhorst@arm.com
23510399Sstephan.diestelhorst@arm.com    return snoopSelected(maskToPortList(interested), lookupLatency);
23610399Sstephan.diestelhorst@arm.com}
23710399Sstephan.diestelhorst@arm.com
23810399Sstephan.diestelhorst@arm.comvoid
23910399Sstephan.diestelhorst@arm.comSnoopFilter::updateSnoopResponse(const Packet* cpkt,
24010399Sstephan.diestelhorst@arm.com                                 const SlavePort& rsp_port,
24110399Sstephan.diestelhorst@arm.com                                 const SlavePort& req_port)
24210399Sstephan.diestelhorst@arm.com{
24310399Sstephan.diestelhorst@arm.com    DPRINTF(SnoopFilter, "%s: packet rsp %s req %s addr 0x%x cmd %s\n",
24410399Sstephan.diestelhorst@arm.com            __func__, rsp_port.name(), req_port.name(), cpkt->getAddr(),
24510399Sstephan.diestelhorst@arm.com            cpkt->cmdString());
24610399Sstephan.diestelhorst@arm.com
24710821Sandreas.hansson@arm.com    assert(cpkt->isResponse());
24810821Sandreas.hansson@arm.com    assert(cpkt->memInhibitAsserted());
24910821Sandreas.hansson@arm.com
25011128Sali.jafri@arm.com    // Ultimately we should check if the packet came from an
25111128Sali.jafri@arm.com    // allocating source, not just if the port is snooping
25211128Sali.jafri@arm.com    bool allocate = !cpkt->req->isUncacheable() && req_port.isSnooping();
25311128Sali.jafri@arm.com    if (!allocate)
25410821Sandreas.hansson@arm.com        return;
25510821Sandreas.hansson@arm.com
25611128Sali.jafri@arm.com    Addr line_addr = cpkt->getBlockAddr(linesize);
25710399Sstephan.diestelhorst@arm.com    SnoopMask rsp_mask = portToMask(rsp_port);
25810399Sstephan.diestelhorst@arm.com    SnoopMask req_mask = portToMask(req_port);
25910399Sstephan.diestelhorst@arm.com    SnoopItem& sf_item = cachedLocations[line_addr];
26010399Sstephan.diestelhorst@arm.com
26110399Sstephan.diestelhorst@arm.com    DPRINTF(SnoopFilter, "%s:   old SF value %x.%x\n",
26210399Sstephan.diestelhorst@arm.com            __func__,  sf_item.requested, sf_item.holder);
26310399Sstephan.diestelhorst@arm.com
26410399Sstephan.diestelhorst@arm.com    // The source should have the line
26510399Sstephan.diestelhorst@arm.com    panic_if(!(sf_item.holder & rsp_mask), "SF value %x.%x does not have "\
26610399Sstephan.diestelhorst@arm.com             "the line\n", sf_item.requested, sf_item.holder);
26710399Sstephan.diestelhorst@arm.com
26810399Sstephan.diestelhorst@arm.com    // The destination should have had a request in
26910399Sstephan.diestelhorst@arm.com    panic_if(!(sf_item.requested & req_mask), "SF value %x.%x missing "\
27010399Sstephan.diestelhorst@arm.com             "the original request\n",  sf_item.requested, sf_item.holder);
27110399Sstephan.diestelhorst@arm.com
27210399Sstephan.diestelhorst@arm.com    // Update the residency of the cache line.
27310399Sstephan.diestelhorst@arm.com    if (cpkt->needsExclusive() || !cpkt->sharedAsserted()) {
27410399Sstephan.diestelhorst@arm.com        DPRINTF(SnoopFilter, "%s:  dropping %x because needs: %i shared: %i "\
27510399Sstephan.diestelhorst@arm.com                "SF val: %x.%x\n", __func__,  rsp_mask,
27610399Sstephan.diestelhorst@arm.com                cpkt->needsExclusive(), cpkt->sharedAsserted(),
27710399Sstephan.diestelhorst@arm.com                sf_item.requested, sf_item.holder);
27810399Sstephan.diestelhorst@arm.com
27910399Sstephan.diestelhorst@arm.com        sf_item.holder &= ~rsp_mask;
28010399Sstephan.diestelhorst@arm.com        // The snoop filter does not see any ACKs from non-responding sharers
28110399Sstephan.diestelhorst@arm.com        // that have been invalidated :(  So below assert would be nice, but..
28210399Sstephan.diestelhorst@arm.com        //assert(sf_item.holder == 0);
28310399Sstephan.diestelhorst@arm.com        sf_item.holder = 0;
28410399Sstephan.diestelhorst@arm.com    }
28510399Sstephan.diestelhorst@arm.com    assert(cpkt->cmd != MemCmd::Writeback);
28610399Sstephan.diestelhorst@arm.com    sf_item.holder |=  req_mask;
28710399Sstephan.diestelhorst@arm.com    sf_item.requested &= ~req_mask;
28811129Sali.jafri@arm.com    assert(sf_item.requested | sf_item.holder);
28910399Sstephan.diestelhorst@arm.com    DPRINTF(SnoopFilter, "%s:   new SF value %x.%x\n",
29010399Sstephan.diestelhorst@arm.com            __func__, sf_item.requested, sf_item.holder);
29110399Sstephan.diestelhorst@arm.com}
29210399Sstephan.diestelhorst@arm.com
29310399Sstephan.diestelhorst@arm.comvoid
29410399Sstephan.diestelhorst@arm.comSnoopFilter::updateSnoopForward(const Packet* cpkt,
29510399Sstephan.diestelhorst@arm.com        const SlavePort& rsp_port, const MasterPort& req_port)
29610399Sstephan.diestelhorst@arm.com{
29710399Sstephan.diestelhorst@arm.com    DPRINTF(SnoopFilter, "%s: packet rsp %s req %s addr 0x%x cmd %s\n",
29810399Sstephan.diestelhorst@arm.com            __func__, rsp_port.name(), req_port.name(), cpkt->getAddr(),
29910399Sstephan.diestelhorst@arm.com            cpkt->cmdString());
30010399Sstephan.diestelhorst@arm.com
30111128Sali.jafri@arm.com    Addr line_addr = cpkt->getBlockAddr(linesize);
30211129Sali.jafri@arm.com    auto sf_it = cachedLocations.find(line_addr);
30311129Sali.jafri@arm.com    if (sf_it == cachedLocations.end())
30411129Sali.jafri@arm.com        sf_it = cachedLocations.emplace(line_addr, SnoopItem()).first;
30511129Sali.jafri@arm.com    SnoopItem& sf_item = sf_it->second;
30610399Sstephan.diestelhorst@arm.com    SnoopMask rsp_mask M5_VAR_USED = portToMask(rsp_port);
30710399Sstephan.diestelhorst@arm.com
30810399Sstephan.diestelhorst@arm.com    assert(cpkt->isResponse());
30910399Sstephan.diestelhorst@arm.com    assert(cpkt->memInhibitAsserted());
31010399Sstephan.diestelhorst@arm.com
31110399Sstephan.diestelhorst@arm.com    DPRINTF(SnoopFilter, "%s:   old SF value %x.%x\n",
31210399Sstephan.diestelhorst@arm.com            __func__,  sf_item.requested, sf_item.holder);
31310399Sstephan.diestelhorst@arm.com
31410399Sstephan.diestelhorst@arm.com    // Remote (to this snoop filter) snoops update the filter already when they
31510399Sstephan.diestelhorst@arm.com    // arrive from below, because we may not see any response.
31610399Sstephan.diestelhorst@arm.com    if (cpkt->needsExclusive()) {
31710399Sstephan.diestelhorst@arm.com        // If the request to this snoop response hit an in-flight transaction,
31810399Sstephan.diestelhorst@arm.com        // the holder was not reset -> no assertion & do that here, now!
31910399Sstephan.diestelhorst@arm.com        //assert(sf_item.holder == 0);
32010399Sstephan.diestelhorst@arm.com        sf_item.holder = 0;
32110399Sstephan.diestelhorst@arm.com    }
32210399Sstephan.diestelhorst@arm.com    DPRINTF(SnoopFilter, "%s:   new SF value %x.%x\n",
32310399Sstephan.diestelhorst@arm.com            __func__, sf_item.requested, sf_item.holder);
32411129Sali.jafri@arm.com    eraseIfNullEntry(sf_it);
32510399Sstephan.diestelhorst@arm.com}
32610399Sstephan.diestelhorst@arm.com
32710399Sstephan.diestelhorst@arm.comvoid
32810399Sstephan.diestelhorst@arm.comSnoopFilter::updateResponse(const Packet* cpkt, const SlavePort& slave_port)
32910399Sstephan.diestelhorst@arm.com{
33010399Sstephan.diestelhorst@arm.com    DPRINTF(SnoopFilter, "%s: packet src %s addr 0x%x cmd %s\n",
33110399Sstephan.diestelhorst@arm.com            __func__, slave_port.name(), cpkt->getAddr(), cpkt->cmdString());
33210399Sstephan.diestelhorst@arm.com
33310821Sandreas.hansson@arm.com    assert(cpkt->isResponse());
33410821Sandreas.hansson@arm.com
33511128Sali.jafri@arm.com    // Ultimately we should check if the packet came from an
33611128Sali.jafri@arm.com    // allocating source, not just if the port is snooping
33711128Sali.jafri@arm.com    bool allocate = !cpkt->req->isUncacheable() && slave_port.isSnooping();
33811128Sali.jafri@arm.com    if (!allocate)
33910821Sandreas.hansson@arm.com        return;
34010821Sandreas.hansson@arm.com
34111128Sali.jafri@arm.com    Addr line_addr = cpkt->getBlockAddr(linesize);
34210399Sstephan.diestelhorst@arm.com    SnoopMask slave_mask = portToMask(slave_port);
34310399Sstephan.diestelhorst@arm.com    SnoopItem& sf_item = cachedLocations[line_addr];
34410399Sstephan.diestelhorst@arm.com
34510399Sstephan.diestelhorst@arm.com    DPRINTF(SnoopFilter, "%s:   old SF value %x.%x\n",
34610399Sstephan.diestelhorst@arm.com            __func__,  sf_item.requested, sf_item.holder);
34710399Sstephan.diestelhorst@arm.com
34810399Sstephan.diestelhorst@arm.com    // Make sure we have seen the actual request, too
34910399Sstephan.diestelhorst@arm.com    panic_if(!(sf_item.requested & slave_mask), "SF value %x.%x missing "\
35010399Sstephan.diestelhorst@arm.com             "request bit\n", sf_item.requested, sf_item.holder);
35110399Sstephan.diestelhorst@arm.com
35211129Sali.jafri@arm.com    // Update the residency of the cache line. Here we assume that the
35311129Sali.jafri@arm.com    // line has been zapped in all caches that are not the responder.
35411129Sali.jafri@arm.com     if (cpkt->needsExclusive() || !cpkt->sharedAsserted())
35510399Sstephan.diestelhorst@arm.com        sf_item.holder = 0;
35610399Sstephan.diestelhorst@arm.com    sf_item.holder |=  slave_mask;
35710399Sstephan.diestelhorst@arm.com    sf_item.requested &= ~slave_mask;
35811129Sali.jafri@arm.com    assert(sf_item.holder | sf_item.requested);
35910399Sstephan.diestelhorst@arm.com    DPRINTF(SnoopFilter, "%s:   new SF value %x.%x\n",
36010399Sstephan.diestelhorst@arm.com            __func__, sf_item.requested, sf_item.holder);
36110399Sstephan.diestelhorst@arm.com}
36210399Sstephan.diestelhorst@arm.com
36310403Sstephan.diestelhorst@arm.comvoid
36410403Sstephan.diestelhorst@arm.comSnoopFilter::regStats()
36510403Sstephan.diestelhorst@arm.com{
36610403Sstephan.diestelhorst@arm.com    totRequests
36710403Sstephan.diestelhorst@arm.com        .name(name() + ".tot_requests")
36810403Sstephan.diestelhorst@arm.com        .desc("Total number of requests made to the snoop filter.");
36910403Sstephan.diestelhorst@arm.com
37010403Sstephan.diestelhorst@arm.com    hitSingleRequests
37110403Sstephan.diestelhorst@arm.com        .name(name() + ".hit_single_requests")
37210403Sstephan.diestelhorst@arm.com        .desc("Number of requests hitting in the snoop filter with a single "\
37310403Sstephan.diestelhorst@arm.com              "holder of the requested data.");
37410403Sstephan.diestelhorst@arm.com
37510403Sstephan.diestelhorst@arm.com    hitMultiRequests
37610403Sstephan.diestelhorst@arm.com        .name(name() + ".hit_multi_requests")
37710403Sstephan.diestelhorst@arm.com        .desc("Number of requests hitting in the snoop filter with multiple "\
37810403Sstephan.diestelhorst@arm.com              "(>1) holders of the requested data.");
37910403Sstephan.diestelhorst@arm.com
38010403Sstephan.diestelhorst@arm.com    totSnoops
38110403Sstephan.diestelhorst@arm.com        .name(name() + ".tot_snoops")
38210403Sstephan.diestelhorst@arm.com        .desc("Total number of snoops made to the snoop filter.");
38310403Sstephan.diestelhorst@arm.com
38410403Sstephan.diestelhorst@arm.com    hitSingleSnoops
38510403Sstephan.diestelhorst@arm.com        .name(name() + ".hit_single_snoops")
38610403Sstephan.diestelhorst@arm.com        .desc("Number of snoops hitting in the snoop filter with a single "\
38710403Sstephan.diestelhorst@arm.com              "holder of the requested data.");
38810403Sstephan.diestelhorst@arm.com
38910403Sstephan.diestelhorst@arm.com    hitMultiSnoops
39010403Sstephan.diestelhorst@arm.com        .name(name() + ".hit_multi_snoops")
39110403Sstephan.diestelhorst@arm.com        .desc("Number of snoops hitting in the snoop filter with multiple "\
39210403Sstephan.diestelhorst@arm.com              "(>1) holders of the requested data.");
39310403Sstephan.diestelhorst@arm.com}
39410403Sstephan.diestelhorst@arm.com
39510399Sstephan.diestelhorst@arm.comSnoopFilter *
39610399Sstephan.diestelhorst@arm.comSnoopFilterParams::create()
39710399Sstephan.diestelhorst@arm.com{
39810399Sstephan.diestelhorst@arm.com    return new SnoopFilter(this);
39910399Sstephan.diestelhorst@arm.com}
400