gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
snoop_filter.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2016,2019 ARM Limited
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
38  */
39 
45 #ifndef __MEM_SNOOP_FILTER_HH__
46 #define __MEM_SNOOP_FILTER_HH__
47 
48 #include <bitset>
49 #include <unordered_map>
50 #include <utility>
51 
52 #include "mem/packet.hh"
53 #include "mem/port.hh"
54 #include "mem/qport.hh"
55 #include "params/SnoopFilter.hh"
56 #include "sim/sim_object.hh"
57 #include "sim/system.hh"
58 
88 class SnoopFilter : public SimObject {
89  public:
90 
91  // Change for systems with more than 256 ports tracked by this object
92  static const int SNOOP_MASK_SIZE = 256;
93 
95 
96  SnoopFilter (const SnoopFilterParams *p) :
98  linesize(p->system->cacheLineSize()), lookupLatency(p->lookup_latency),
99  maxEntryCount(p->max_capacity / p->system->cacheLineSize())
100  {
101  }
102 
109  void setSlavePorts(const SnoopList& slave_ports) {
110  localSlavePortIds.resize(slave_ports.size(), InvalidPortID);
111 
112  PortID id = 0;
113  for (const auto& p : slave_ports) {
114  // no need to track this port if it is not snooping
115  if (p->isSnooping()) {
116  slavePorts.push_back(p);
117  localSlavePortIds[p->getId()] = id++;
118  }
119  }
120 
121  // make sure we can deal with this many ports
122  fatal_if(id > SNOOP_MASK_SIZE,
123  "Snoop filter only supports %d snooping ports, got %d\n",
124  SNOOP_MASK_SIZE, id);
125  }
126 
140  const SlavePort& slave_port);
141 
151  void finishRequest(bool will_retry, Addr addr, bool is_secure);
152 
163 
174  void updateSnoopResponse(const Packet *cpkt, const SlavePort& rsp_port,
175  const SlavePort& req_port);
176 
186  void updateSnoopForward(const Packet *cpkt, const SlavePort& rsp_port,
187  const MasterPort& req_port);
188 
198  void updateResponse(const Packet *cpkt, const SlavePort& slave_port);
199 
200  virtual void regStats();
201 
202  protected:
203 
208  typedef std::bitset<SNOOP_MASK_SIZE> SnoopMask;
209 
215  struct SnoopItem {
216  SnoopMask requested;
217  SnoopMask holder;
218  };
222  typedef std::unordered_map<Addr, SnoopItem> SnoopFilterCache;
223 
228  {
229  return std::make_pair(slavePorts, latency);
230  }
231  std::pair<SnoopList, Cycles> snoopSelected(const SnoopList& slave_ports,
232  Cycles latency) const
233  {
234  return std::make_pair(slave_ports, latency);
235  }
237  {
238  SnoopList empty;
239  return std::make_pair(empty , latency);
240  }
241 
247  SnoopMask portToMask(const SlavePort& port) const;
253  SnoopList maskToPortList(SnoopMask ports) const;
254 
255  private:
256 
260  void eraseIfNullEntry(SnoopFilterCache::iterator& sf_it);
261 
263  SnoopFilterCache cachedLocations;
264 
273  SnoopFilterCache::iterator it;
274 
281 
288  ReqLookupResult(SnoopFilterCache::iterator end_it)
289  : it(end_it), retryItem{0, 0}
290  {
291  }
292  ReqLookupResult() = delete;
293  } reqLookupResult;
294 
296  SnoopList slavePorts;
300  const unsigned linesize;
304  const unsigned maxEntryCount;
305 
309  enum LineStatus {
311  LineSecure = 0x01,
312  };
313 
318 
322 };
323 
326 {
327  assert(port.getId() != InvalidPortID);
328  // if this is not a snooping port, return a zero mask
329  return !port.isSnooping() ? 0 :
330  ((SnoopMask)1) << localSlavePortIds[port.getId()];
331 }
332 
335 {
336  SnoopList res;
337  for (const auto& p : slavePorts)
338  if ((port_mask & portToMask(*p)).any())
339  res.push_back(p);
340  return res;
341 }
342 
343 #endif // __MEM_SNOOP_FILTER_HH__
A MasterPort is a specialisation of a BaseMasterPort, which implements the default protocol for the t...
Definition: port.hh:75
std::pair< SnoopList, Cycles > snoopAll(Cycles latency) const
Simple factory methods for standard return values.
void updateSnoopForward(const Packet *cpkt, const SlavePort &rsp_port, const MasterPort &req_port)
Pass snoop responses that travel downward through the snoop filter and let them update the snoop filt...
Stats::Scalar hitMultiRequests
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
Stats::Scalar hitMultiSnoops
SnoopMask portToMask(const SlavePort &port) const
Convert a single port to a corresponding, one-hot bitmask.
const PortID InvalidPortID
Definition: types.hh:238
STL pair class.
Definition: stl.hh:61
void finishRequest(bool will_retry, Addr addr, bool is_secure)
For an un-successful request, revert the change to the snoop filter.
PortID getId() const
Get the port id.
Definition: port.hh:109
const unsigned maxEntryCount
Max capacity in terms of cache blocks tracked, for sanity checking.
A request lookup must be followed by a call to finishRequest to inform the operation&#39;s success...
ip6_addr_t addr
Definition: inet.hh:335
void setSlavePorts(const SnoopList &slave_ports)
Init a new snoop filter and tell it about all the slave ports of the enclosing bus.
SnoopList slavePorts
List of all attached snooping slave ports.
std::bitset< SNOOP_MASK_SIZE > SnoopMask
The underlying type for the bitmask we use for tracking.
Stats::Scalar totSnoops
std::pair< SnoopList, Cycles > snoopDown(Cycles latency) const
A SlavePort is a specialisation of a port.
Definition: port.hh:258
block holds data from the secure memory space
SnoopList maskToPortList(SnoopMask ports) const
Converts a bitmask of ports into the corresponing list of ports.
ReqLookupResult(SnoopFilterCache::iterator end_it)
The constructor must be informed of the internal cache&#39;s end iterator, so do not allow the compiler t...
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2508
std::vector< PortID > localSlavePortIds
Track the mapping from port ids to the local mask ids.
Stats::Scalar hitSingleSnoops
SnoopFilterCache::iterator it
Iterator used to store the result from lookupRequest.
std::pair< SnoopList, Cycles > lookupSnoop(const Packet *cpkt)
Handle an incoming snoop from below (the master port).
SnoopFilter(const SnoopFilterParams *p)
Definition: snoop_filter.hh:96
Declaration of the queued port.
struct SnoopFilter::ReqLookupResult reqLookupResult
Stats::Scalar hitSingleRequests
const Cycles lookupLatency
Latency for doing a lookup in the filter.
const unsigned linesize
Cache line size.
LineStatus
Use the lower bits of the address to keep track of the line status.
Stats::Scalar totRequests
Statistics.
void eraseIfNullEntry(SnoopFilterCache::iterator &sf_it)
Removes snoop filter items which have no requesters and no holders.
Definition: snoop_filter.cc:55
std::pair< SnoopList, Cycles > snoopSelected(const SnoopList &slave_ports, Cycles latency) const
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:203
Port Object Declaration.
bool isSnooping() const
Find out if the peer master port is snooping or not.
Definition: port.hh:280
static const int SNOOP_MASK_SIZE
Definition: snoop_filter.hh:92
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:255
void updateResponse(const Packet *cpkt, const SlavePort &slave_port)
Update the snoop filter with a response from below (outer / other cache, or memory) and update the tr...
SnoopFilterCache cachedLocations
Simple hash set of cached addresses.
std::vector< QueuedSlavePort * > SnoopList
Definition: snoop_filter.hh:94
Bitfield< 15 > system
Definition: misc.hh:999
virtual void regStats()
Callback to set stat parameters.
Declaration of the Packet class.
Per cache line item tracking a bitmask of SlavePorts who have an outstanding request to this line (re...
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:237
void updateSnoopResponse(const Packet *cpkt, const SlavePort &rsp_port, const SlavePort &req_port)
Let the snoop filter see any snoop responses that turn into request responses and indicate cache to c...
SnoopItem retryItem
Variable to temporarily store value of snoopfilter entry in case finishRequest needs to undo changes ...
This snoop filter keeps track of which connected port has a particular line of data.
Definition: snoop_filter.hh:88
Bitfield< 0 > p
std::unordered_map< Addr, SnoopItem > SnoopFilterCache
HashMap of SnoopItems indexed by line address.
Abstract superclass for simulation objects.
Definition: sim_object.hh:96
std::pair< SnoopList, Cycles > lookupRequest(const Packet *cpkt, const SlavePort &slave_port)
Lookup a request (from a slave port) in the snoop filter and return a list of other slave ports that ...
Definition: snoop_filter.cc:66

Generated on Fri Feb 28 2020 16:27:02 for gem5 by doxygen 1.8.13