gem5  [DEVELOP-FOR-23.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 
43 #ifndef __MEM_SNOOP_FILTER_HH__
44 #define __MEM_SNOOP_FILTER_HH__
45 
46 #include <bitset>
47 #include <unordered_map>
48 #include <utility>
49 
50 #include "mem/packet.hh"
51 #include "mem/port.hh"
52 #include "mem/qport.hh"
53 #include "params/SnoopFilter.hh"
54 #include "sim/sim_object.hh"
55 #include "sim/system.hh"
56 
57 namespace gem5
58 {
59 
89 class SnoopFilter : public SimObject
90 {
91  public:
92 
93  // Change for systems with more than 256 ports tracked by this object
94  static const int SNOOP_MASK_SIZE = 256;
95 
97 
98  SnoopFilter (const SnoopFilterParams &p) :
100  linesize(p.system->cacheLineSize()), lookupLatency(p.lookup_latency),
101  maxEntryCount(p.max_capacity / p.system->cacheLineSize()),
102  stats(this)
103  {
104  }
105 
112  void setCPUSidePorts(const SnoopList& _cpu_side_ports) {
113  localResponsePortIds.resize(_cpu_side_ports.size(), InvalidPortID);
114 
115  PortID id = 0;
116  for (const auto& p : _cpu_side_ports) {
117  // no need to track this port if it is not snooping
118  if (p->isSnooping()) {
119  cpuSidePorts.push_back(p);
120  localResponsePortIds[p->getId()] = id++;
121  }
122  }
123 
124  // make sure we can deal with this many ports
126  "Snoop filter only supports %d snooping ports, got %d\n",
127  SNOOP_MASK_SIZE, id);
128  }
129 
143  const ResponsePort& cpu_side_port);
144 
154  void finishRequest(bool will_retry, Addr addr, bool is_secure);
155 
166 
177  void updateSnoopResponse(const Packet *cpkt, const ResponsePort& rsp_port,
178  const ResponsePort& req_port);
179 
189  void updateSnoopForward(const Packet *cpkt, const ResponsePort& rsp_port,
190  const RequestPort& req_port);
191 
201  void updateResponse(const Packet *cpkt, const ResponsePort& cpu_side_port);
202 
203  virtual void regStats();
204 
205  protected:
206 
211  typedef std::bitset<SNOOP_MASK_SIZE> SnoopMask;
212 
218  struct SnoopItem
219  {
222  };
226  typedef std::unordered_map<Addr, SnoopItem> SnoopFilterCache;
227 
232  {
233  return std::make_pair(cpuSidePorts, latency);
234  }
236  _cpu_side_ports, Cycles latency) const
237  {
238  return std::make_pair(_cpu_side_ports, latency);
239  }
241  {
242  SnoopList empty;
243  return std::make_pair(empty , latency);
244  }
245 
251  SnoopMask portToMask(const ResponsePort& port) const;
257  SnoopList maskToPortList(SnoopMask ports) const;
258 
259  private:
260 
264  void eraseIfNullEntry(SnoopFilterCache::iterator& sf_it);
265 
268 
276  {
278  SnoopFilterCache::iterator it;
279 
286 
293  ReqLookupResult(SnoopFilterCache::iterator end_it)
294  : it(end_it), retryItem{0, 0}
295  {
296  }
297  ReqLookupResult() = delete;
298  } reqLookupResult;
299 
305  const unsigned linesize;
309  const unsigned maxEntryCount;
310 
315  {
317  LineSecure = 0x01,
318  };
319 
322  {
324 
328 
332  } stats;
333 };
334 
337 {
338  assert(port.getId() != InvalidPortID);
339  // if this is not a snooping port, return a zero mask
340  return !port.isSnooping() ? 0 :
341  ((SnoopMask)1) << localResponsePortIds[port.getId()];
342 }
343 
346 {
347  SnoopList res;
348  for (const auto& p : cpuSidePorts)
349  if ((port_mask & portToMask(*p)).any())
350  res.push_back(p);
351  return res;
352 }
353 
354 } // namespace gem5
355 
356 #endif // __MEM_SNOOP_FILTER_HH__
gem5::statistics::Scalar
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:1929
gem5::PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:245
gem5::SnoopFilter::linesize
const unsigned linesize
Cache line size.
Definition: snoop_filter.hh:305
gem5::SnoopFilter::ReqLookupResult::ReqLookupResult
ReqLookupResult()=delete
gem5::SnoopFilter::ReqLookupResult
A request lookup must be followed by a call to finishRequest to inform the operation's success.
Definition: snoop_filter.hh:275
gem5::Port::getId
PortID getId() const
Get the port id.
Definition: port.hh:114
gem5::SnoopFilter::reqLookupResult
struct gem5::SnoopFilter::ReqLookupResult reqLookupResult
system.hh
gem5::SnoopFilter::SnoopFilterStats::SnoopFilterStats
SnoopFilterStats(statistics::Group *parent)
Definition: snoop_filter.cc:391
gem5::SnoopFilter::finishRequest
void finishRequest(bool will_retry, Addr addr, bool is_secure)
For an un-successful request, revert the change to the snoop filter.
Definition: snoop_filter.cc:160
gem5::SnoopFilter::updateSnoopResponse
void updateSnoopResponse(const Packet *cpkt, const ResponsePort &rsp_port, const ResponsePort &req_port)
Let the snoop filter see any snoop responses that turn into request responses and indicate cache to c...
Definition: snoop_filter.cc:244
gem5::SnoopFilter
This snoop filter keeps track of which connected port has a particular line of data.
Definition: snoop_filter.hh:89
gem5::SnoopFilter::maskToPortList
SnoopList maskToPortList(SnoopMask ports) const
Converts a bitmask of ports into the corresponing list of ports.
Definition: snoop_filter.hh:345
gem5::SnoopFilter::SnoopFilter
SnoopFilter(const SnoopFilterParams &p)
Definition: snoop_filter.hh:98
gem5::SnoopFilter::lookupSnoop
std::pair< SnoopList, Cycles > lookupSnoop(const Packet *cpkt)
Handle an incoming snoop from below (the memory-side port).
Definition: snoop_filter.cc:184
gem5::SnoopFilter::lookupLatency
const Cycles lookupLatency
Latency for doing a lookup in the filter.
Definition: snoop_filter.hh:307
gem5::SnoopFilter::LineStatus
LineStatus
Use the lower bits of the address to keep track of the line status.
Definition: snoop_filter.hh:314
gem5::SnoopFilter::regStats
virtual void regStats()
Callback to set stat parameters.
Definition: snoop_filter.cc:412
gem5::X86ISA::system
Bitfield< 15 > system
Definition: misc.hh:1004
std::vector< QueuedResponsePort * >
gem5::SnoopFilter::ReqLookupResult::it
SnoopFilterCache::iterator it
Iterator used to store the result from lookupRequest.
Definition: snoop_filter.hh:278
gem5::SnoopFilter::updateResponse
void updateResponse(const Packet *cpkt, const ResponsePort &cpu_side_port)
Update the snoop filter with a response from below (outer / other cache, or memory) and update the tr...
Definition: snoop_filter.cc:338
gem5::InvalidPortID
const PortID InvalidPortID
Definition: types.hh:246
gem5::SnoopFilter::eraseIfNullEntry
void eraseIfNullEntry(SnoopFilterCache::iterator &sf_it)
Removes snoop filter items which have no requestors and no holders.
Definition: snoop_filter.cc:56
gem5::SnoopFilter::SnoopFilterCache
std::unordered_map< Addr, SnoopItem > SnoopFilterCache
HashMap of SnoopItems indexed by line address.
Definition: snoop_filter.hh:226
gem5::SnoopFilter::lookupRequest
std::pair< SnoopList, Cycles > lookupRequest(const Packet *cpkt, const ResponsePort &cpu_side_port)
Lookup a request (from a CPU-side port) in the snoop filter and return a list of other CPU-side ports...
Definition: snoop_filter.cc:67
packet.hh
gem5::SnoopFilter::SnoopList
std::vector< QueuedResponsePort * > SnoopList
Definition: snoop_filter.hh:96
gem5::RequestPort
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition: port.hh:118
gem5::Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:78
gem5::SnoopFilter::SnoopFilterStats::totSnoops
statistics::Scalar totSnoops
Definition: snoop_filter.hh:329
gem5::SnoopFilter::SnoopItem::requested
SnoopMask requested
Definition: snoop_filter.hh:220
gem5::SnoopFilter::updateSnoopForward
void updateSnoopForward(const Packet *cpkt, const ResponsePort &rsp_port, const RequestPort &req_port)
Pass snoop responses that travel downward through the snoop filter and let them update the snoop filt...
Definition: snoop_filter.cc:301
gem5::VegaISA::p
Bitfield< 54 > p
Definition: pagetable.hh:70
gem5::SnoopFilter::SNOOP_MASK_SIZE
static const int SNOOP_MASK_SIZE
Definition: snoop_filter.hh:94
sim_object.hh
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
gem5::ResponsePort::isSnooping
bool isSnooping() const
Find out if the peer request port is snooping or not.
Definition: port.hh:359
gem5::SnoopFilter::SnoopItem::holder
SnoopMask holder
Definition: snoop_filter.hh:221
gem5::SnoopFilter::ReqLookupResult::ReqLookupResult
ReqLookupResult(SnoopFilterCache::iterator end_it)
The constructor must be informed of the internal cache's end iterator, so do not allow the compiler t...
Definition: snoop_filter.hh:293
gem5::SnoopFilter::snoopDown
std::pair< SnoopList, Cycles > snoopDown(Cycles latency) const
Definition: snoop_filter.hh:240
port.hh
gem5::SnoopFilter::LineSecure
@ LineSecure
block holds data from the secure memory space
Definition: snoop_filter.hh:317
gem5::SnoopFilter::cachedLocations
SnoopFilterCache cachedLocations
Simple hash set of cached addresses.
Definition: snoop_filter.hh:267
gem5::SnoopFilter::maxEntryCount
const unsigned maxEntryCount
Max capacity in terms of cache blocks tracked, for sanity checking.
Definition: snoop_filter.hh:309
gem5::SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:146
gem5::SnoopFilter::SnoopFilterStats
Statistics.
Definition: snoop_filter.hh:321
std::pair
STL pair class.
Definition: stl.hh:58
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::SnoopFilter::localResponsePortIds
std::vector< PortID > localResponsePortIds
Track the mapping from port ids to the local mask ids.
Definition: snoop_filter.hh:303
gem5::SnoopFilter::SnoopFilterStats::hitSingleRequests
statistics::Scalar hitSingleRequests
Definition: snoop_filter.hh:326
gem5::SnoopFilter::SnoopItem
Per cache line item tracking a bitmask of ResponsePorts who have an outstanding request to this line ...
Definition: snoop_filter.hh:218
gem5::ResponsePort
A ResponsePort is a specialization of a port.
Definition: port.hh:331
gem5::SnoopFilter::snoopSelected
std::pair< SnoopList, Cycles > snoopSelected(const SnoopList &_cpu_side_ports, Cycles latency) const
Definition: snoop_filter.hh:235
gem5::SnoopFilter::SnoopMask
std::bitset< SNOOP_MASK_SIZE > SnoopMask
The underlying type for the bitmask we use for tracking.
Definition: snoop_filter.hh:211
gem5::SnoopFilter::cpuSidePorts
SnoopList cpuSidePorts
List of all attached snooping CPU-side ports.
Definition: snoop_filter.hh:301
qport.hh
gem5::statistics::Group
Statistics container.
Definition: group.hh:92
gem5::SnoopFilter::portToMask
SnoopMask portToMask(const ResponsePort &port) const
Convert a single port to a corresponding, one-hot bitmask.
Definition: snoop_filter.hh:336
gem5::SnoopFilter::setCPUSidePorts
void setCPUSidePorts(const SnoopList &_cpu_side_ports)
Init a new snoop filter and tell it about all the cpu_sideports of the enclosing bus.
Definition: snoop_filter.hh:112
gem5::SnoopFilter::stats
gem5::SnoopFilter::SnoopFilterStats stats
gem5::SnoopFilter::snoopAll
std::pair< SnoopList, Cycles > snoopAll(Cycles latency) const
Simple factory methods for standard return values.
Definition: snoop_filter.hh:231
gem5::SnoopFilter::ReqLookupResult::retryItem
SnoopItem retryItem
Variable to temporarily store value of snoopfilter entry in case finishRequest needs to undo changes ...
Definition: snoop_filter.hh:285
fatal_if
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:236
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::SnoopFilter::SnoopFilterStats::totRequests
statistics::Scalar totRequests
Definition: snoop_filter.hh:325
gem5::SnoopFilter::SnoopFilterStats::hitMultiRequests
statistics::Scalar hitMultiRequests
Definition: snoop_filter.hh:327
gem5::SnoopFilter::SnoopFilterStats::hitMultiSnoops
statistics::Scalar hitMultiSnoops
Definition: snoop_filter.hh:331
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84
gem5::SnoopFilter::SnoopFilterStats::hitSingleSnoops
statistics::Scalar hitSingleSnoops
Definition: snoop_filter.hh:330

Generated on Sun Jul 30 2023 01:56:59 for gem5 by doxygen 1.8.17