3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software 9 * licensed hereunder. You may use the software subject to the license 10 * terms below provided that you ensure that this notice is replicated 11 * unmodified and in its entirety in all distributions of the software, 12 * modified or unmodified, in source code or in binary form. 13 * 14 * Redistribution and use in source and binary forms, with or without 15 * modification, are permitted provided that the following conditions are 16 * met: redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer; 18 * redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution; 21 * neither the name of the copyright holders nor the names of its 22 * contributors may be used to endorse or promote products derived from 23 * this software without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 * 37 * Authors: Stephan Diestelhorst <stephan.diestelhorst@arm.com> 38 */ 39 40/** 41 * @file 42 * Definition of a snoop filter. 43 */ 44 45#ifndef __MEM_SNOOP_FILTER_HH__ 46#define __MEM_SNOOP_FILTER_HH__ 47 48#include <utility> 49 50#include "base/hashmap.hh" 51#include "mem/packet.hh" 52#include "mem/port.hh" 53#include "mem/qport.hh" 54#include "params/SnoopFilter.hh" 55#include "sim/sim_object.hh" 56#include "sim/system.hh" 57 58/** 59 * This snoop filter keeps track of which connected port has a 60 * particular line of data. It can be queried (through lookup*) on 61 * memory requests from above (reads / writes / ...); and also from 62 * below (snoops). The snoop filter precisely knows about the location 63 * of lines "above" it through a map from cache line address to 64 * sharers/ports. The snoop filter ties into the flows of requests 65 * (when they succeed at the lower interface), regular responses from 66 * below and also responses from sideway's caches (in update*). This 67 * allows the snoop filter to model cache-line residency by snooping 68 * the messages. 69 * 70 * The tracking happens in two fields to be able to distinguish 71 * between in-flight requests (in requested) and already pulled in 72 * lines (in holder). This distinction is used for producing tighter 73 * assertions and tracking request completion. For safety, (requested 74 * | holder) should be notified and the requesting MSHRs will take 75 * care of ordering. 76 * 77 * Overall, some trickery is required because: 78 * (1) snoops are not followed by an ACK, but only evoke a response if 79 * they need to (hit dirty) 80 * (2) side-channel information is funnelled through direct modifications of 81 * pkt, instead of proper messages through the bus 82 * (3) there are no clean evict messages telling the snoop filter that a local, 83 * upper cache dropped a line, making the snoop filter pessimistic for now 84 * (4) ordering: there is no single point of order in the system. Instead, 85 * requesting MSHRs track order between local requests and remote snoops 86 */ 87class SnoopFilter : public SimObject { 88 public: 89 typedef std::vector<QueuedSlavePort*> SnoopList; 90 91 SnoopFilter (const SnoopFilterParams *p) : SimObject(p), 92 linesize(p->system->cacheLineSize()), lookupLatency(p->lookup_latency) 93 { 94 } 95 96 /** 97 * Init a new snoop filter and tell it about all the slave ports of the 98 * enclosing bus. 99 * 100 * @param bus_slave_ports Vector of slave ports that the bus is attached to. 101 */ 102 void setSlavePorts(const SnoopList& bus_slave_ports) { 103 slavePorts = bus_slave_ports; 104 } 105 106 /** 107 * Lookup a request (from a slave port) in the snoop filter and return a 108 * list of other slave ports that need forwarding of the resulting snoops. 109 * Additionally, update the tracking structures with new request 110 * information. 111 * 112 * @param cpkt Pointer to the request packet. Not changed. 113 * @param slave_port Slave port where the request came from. 114 * @return Pair of a vector of snoop target ports and lookup latency. 115 */ 116 std::pair<SnoopList, Cycles> lookupRequest(const Packet* cpkt, 117 const SlavePort& slave_port); 118 119 /** 120 * For a successful request, update all data structures in the snoop filter 121 * reflecting the changes caused by that request 122 * 123 * @param cpkt Pointer to the request packet. Not changed. 124 * @param slave_port Slave port where the request came from. 125 * @param will_retry This request will retry on this bus / snoop filter 126 */ 127 void updateRequest(const Packet* cpkt, const SlavePort& slave_port, 128 bool will_retry); 129 130 /** 131 * Handle an incoming snoop from below (the master port). These can upgrade the 132 * tracking logic and may also benefit from additional steering thanks to the 133 * snoop filter. 134 * @param cpkt Pointer to const Packet containing the snoop. 135 * @return Pair with a vector of SlavePorts that need snooping and a lookup 136 * latency. 137 */ 138 std::pair<SnoopList, Cycles> lookupSnoop(const Packet* cpkt); 139 140 /** 141 * Let the snoop filter see any snoop responses that turn into request responses 142 * and indicate cache to cache transfers. These will update the corresponding 143 * state in the filter. 144 * 145 * @param cpkt Pointer to const Packet holding the snoop response. 146 * @param rsp_port SlavePort that sends the response. 147 * @param req_port SlavePort that made the original request and is the 148 * destination of the snoop response. 149 */ 150 void updateSnoopResponse(const Packet *cpkt, const SlavePort& rsp_port, 151 const SlavePort& req_port); 152 153 /** 154 * Pass snoop responses that travel downward through the snoop filter and let 155 * them update the snoop filter state. No additional routing happens. 156 * 157 * @param cpkt Pointer to const Packet holding the snoop response. 158 * @param rsp_port SlavePort that sends the response. 159 * @param req_port MasterPort through which the response leaves this cluster. 160 */ 161 void updateSnoopForward(const Packet *cpkt, const SlavePort& rsp_port, 162 const MasterPort& req_port); 163 164 /** 165 * Update the snoop filter with a response from below (outer / other cache, 166 * or memory) and update the tracking information in the snoop filter. 167 * 168 * @param cpkt Pointer to const Packet holding the snoop response. 169 * @param slave_port SlavePort that made the original request and is the target 170 * of this response. 171 */ 172 void updateResponse(const Packet *cpkt, const SlavePort& slave_port); 173 174 /** 175 * Simple factory methods for standard return values for lookupRequest 176 */ 177 std::pair<SnoopList, Cycles> snoopAll(Cycles latency) const 178 { 179 return std::make_pair(slavePorts, latency); 180 } 181 std::pair<SnoopList, Cycles> snoopSelected(const SnoopList& slave_ports, 182 Cycles latency) const 183 { 184 return std::make_pair(slave_ports, latency); 185 } 186 std::pair<SnoopList, Cycles> snoopDown(Cycles latency) const 187 { 188 SnoopList empty; 189 return std::make_pair(empty , latency); 190 } 191 192 virtual void regStats(); 193 194 protected: 195 typedef uint64_t SnoopMask; 196 /** 197 * Per cache line item tracking a bitmask of SlavePorts who have an 198 * outstanding request to this line (requested) or already share a cache line 199 * with this address (holder). 200 */ 201 struct SnoopItem { 202 SnoopMask requested; 203 SnoopMask holder; 204 }; 205 /**
| 3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software 9 * licensed hereunder. You may use the software subject to the license 10 * terms below provided that you ensure that this notice is replicated 11 * unmodified and in its entirety in all distributions of the software, 12 * modified or unmodified, in source code or in binary form. 13 * 14 * Redistribution and use in source and binary forms, with or without 15 * modification, are permitted provided that the following conditions are 16 * met: redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer; 18 * redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution; 21 * neither the name of the copyright holders nor the names of its 22 * contributors may be used to endorse or promote products derived from 23 * this software without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 * 37 * Authors: Stephan Diestelhorst <stephan.diestelhorst@arm.com> 38 */ 39 40/** 41 * @file 42 * Definition of a snoop filter. 43 */ 44 45#ifndef __MEM_SNOOP_FILTER_HH__ 46#define __MEM_SNOOP_FILTER_HH__ 47 48#include <utility> 49 50#include "base/hashmap.hh" 51#include "mem/packet.hh" 52#include "mem/port.hh" 53#include "mem/qport.hh" 54#include "params/SnoopFilter.hh" 55#include "sim/sim_object.hh" 56#include "sim/system.hh" 57 58/** 59 * This snoop filter keeps track of which connected port has a 60 * particular line of data. It can be queried (through lookup*) on 61 * memory requests from above (reads / writes / ...); and also from 62 * below (snoops). The snoop filter precisely knows about the location 63 * of lines "above" it through a map from cache line address to 64 * sharers/ports. The snoop filter ties into the flows of requests 65 * (when they succeed at the lower interface), regular responses from 66 * below and also responses from sideway's caches (in update*). This 67 * allows the snoop filter to model cache-line residency by snooping 68 * the messages. 69 * 70 * The tracking happens in two fields to be able to distinguish 71 * between in-flight requests (in requested) and already pulled in 72 * lines (in holder). This distinction is used for producing tighter 73 * assertions and tracking request completion. For safety, (requested 74 * | holder) should be notified and the requesting MSHRs will take 75 * care of ordering. 76 * 77 * Overall, some trickery is required because: 78 * (1) snoops are not followed by an ACK, but only evoke a response if 79 * they need to (hit dirty) 80 * (2) side-channel information is funnelled through direct modifications of 81 * pkt, instead of proper messages through the bus 82 * (3) there are no clean evict messages telling the snoop filter that a local, 83 * upper cache dropped a line, making the snoop filter pessimistic for now 84 * (4) ordering: there is no single point of order in the system. Instead, 85 * requesting MSHRs track order between local requests and remote snoops 86 */ 87class SnoopFilter : public SimObject { 88 public: 89 typedef std::vector<QueuedSlavePort*> SnoopList; 90 91 SnoopFilter (const SnoopFilterParams *p) : SimObject(p), 92 linesize(p->system->cacheLineSize()), lookupLatency(p->lookup_latency) 93 { 94 } 95 96 /** 97 * Init a new snoop filter and tell it about all the slave ports of the 98 * enclosing bus. 99 * 100 * @param bus_slave_ports Vector of slave ports that the bus is attached to. 101 */ 102 void setSlavePorts(const SnoopList& bus_slave_ports) { 103 slavePorts = bus_slave_ports; 104 } 105 106 /** 107 * Lookup a request (from a slave port) in the snoop filter and return a 108 * list of other slave ports that need forwarding of the resulting snoops. 109 * Additionally, update the tracking structures with new request 110 * information. 111 * 112 * @param cpkt Pointer to the request packet. Not changed. 113 * @param slave_port Slave port where the request came from. 114 * @return Pair of a vector of snoop target ports and lookup latency. 115 */ 116 std::pair<SnoopList, Cycles> lookupRequest(const Packet* cpkt, 117 const SlavePort& slave_port); 118 119 /** 120 * For a successful request, update all data structures in the snoop filter 121 * reflecting the changes caused by that request 122 * 123 * @param cpkt Pointer to the request packet. Not changed. 124 * @param slave_port Slave port where the request came from. 125 * @param will_retry This request will retry on this bus / snoop filter 126 */ 127 void updateRequest(const Packet* cpkt, const SlavePort& slave_port, 128 bool will_retry); 129 130 /** 131 * Handle an incoming snoop from below (the master port). These can upgrade the 132 * tracking logic and may also benefit from additional steering thanks to the 133 * snoop filter. 134 * @param cpkt Pointer to const Packet containing the snoop. 135 * @return Pair with a vector of SlavePorts that need snooping and a lookup 136 * latency. 137 */ 138 std::pair<SnoopList, Cycles> lookupSnoop(const Packet* cpkt); 139 140 /** 141 * Let the snoop filter see any snoop responses that turn into request responses 142 * and indicate cache to cache transfers. These will update the corresponding 143 * state in the filter. 144 * 145 * @param cpkt Pointer to const Packet holding the snoop response. 146 * @param rsp_port SlavePort that sends the response. 147 * @param req_port SlavePort that made the original request and is the 148 * destination of the snoop response. 149 */ 150 void updateSnoopResponse(const Packet *cpkt, const SlavePort& rsp_port, 151 const SlavePort& req_port); 152 153 /** 154 * Pass snoop responses that travel downward through the snoop filter and let 155 * them update the snoop filter state. No additional routing happens. 156 * 157 * @param cpkt Pointer to const Packet holding the snoop response. 158 * @param rsp_port SlavePort that sends the response. 159 * @param req_port MasterPort through which the response leaves this cluster. 160 */ 161 void updateSnoopForward(const Packet *cpkt, const SlavePort& rsp_port, 162 const MasterPort& req_port); 163 164 /** 165 * Update the snoop filter with a response from below (outer / other cache, 166 * or memory) and update the tracking information in the snoop filter. 167 * 168 * @param cpkt Pointer to const Packet holding the snoop response. 169 * @param slave_port SlavePort that made the original request and is the target 170 * of this response. 171 */ 172 void updateResponse(const Packet *cpkt, const SlavePort& slave_port); 173 174 /** 175 * Simple factory methods for standard return values for lookupRequest 176 */ 177 std::pair<SnoopList, Cycles> snoopAll(Cycles latency) const 178 { 179 return std::make_pair(slavePorts, latency); 180 } 181 std::pair<SnoopList, Cycles> snoopSelected(const SnoopList& slave_ports, 182 Cycles latency) const 183 { 184 return std::make_pair(slave_ports, latency); 185 } 186 std::pair<SnoopList, Cycles> snoopDown(Cycles latency) const 187 { 188 SnoopList empty; 189 return std::make_pair(empty , latency); 190 } 191 192 virtual void regStats(); 193 194 protected: 195 typedef uint64_t SnoopMask; 196 /** 197 * Per cache line item tracking a bitmask of SlavePorts who have an 198 * outstanding request to this line (requested) or already share a cache line 199 * with this address (holder). 200 */ 201 struct SnoopItem { 202 SnoopMask requested; 203 SnoopMask holder; 204 }; 205 /**
|