gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
fa_lru.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2013,2016,2018 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  * Copyright (c) 2003-2005 The Regents of The University of Michigan
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  *
40  * Authors: Erik Hallnor
41  * Nikos Nikoleris
42  */
43 
49 #ifndef __MEM_CACHE_TAGS_FA_LRU_HH__
50 #define __MEM_CACHE_TAGS_FA_LRU_HH__
51 
52 #include <cstdint>
53 #include <functional>
54 #include <string>
55 #include <unordered_map>
56 #include <vector>
57 
58 #include "base/bitfield.hh"
59 #include "base/intmath.hh"
60 #include "base/logging.hh"
61 #include "base/statistics.hh"
62 #include "base/types.hh"
63 #include "mem/cache/cache_blk.hh"
64 #include "mem/cache/tags/base.hh"
65 #include "mem/packet.hh"
66 #include "params/FALRU.hh"
67 
68 // Uncomment to enable sanity checks for the FALRU cache and the
69 // TrackedCaches class
70 //#define FALRU_DEBUG
71 
72 class BaseCache;
74 
75 // A bitmask of the caches we are keeping track of. Currently the
76 // lowest bit is the smallest cache we are tracking, as it is
77 // specified by the corresponding parameter. The rest of the bits are
78 // for exponentially growing cache sizes.
79 typedef uint32_t CachesMask;
80 
84 class FALRUBlk : public CacheBlk
85 {
86  public:
87  FALRUBlk() : CacheBlk(), prev(nullptr), next(nullptr), inCachesMask(0) {}
88 
93 
96 
102  std::string print() const override;
103 };
104 
109 class FALRU : public BaseTags
110 {
111  public:
113  typedef FALRUBlk BlkType;
114 
115  protected:
118 
123 
125  struct PairHash
126  {
127  template <class T1, class T2>
128  std::size_t operator()(const std::pair<T1, T2> &p) const
129  {
130  return std::hash<T1>()(p.first) ^ std::hash<T2>()(p.second);
131  }
132  };
134  typedef std::unordered_map<TagHashKey, FALRUBlk *, PairHash> TagHash;
135 
137  TagHash tagHash;
138 
144  void moveToHead(FALRUBlk *blk);
145 
151  void moveToTail(FALRUBlk *blk);
152 
153  public:
154  typedef FALRUParams Params;
155 
159  FALRU(const Params *p);
160  ~FALRU();
161 
165  void tagsInit() override;
166 
170  void regStats() override;
171 
176  void invalidate(CacheBlk *blk) override;
177 
190  CacheBlk* accessBlock(Addr addr, bool is_secure, Cycles &lat,
191  CachesMask *in_cache_mask);
192 
196  CacheBlk* accessBlock(Addr addr, bool is_secure, Cycles &lat) override;
197 
205  CacheBlk* findBlock(Addr addr, bool is_secure) const override;
206 
214  ReplaceableEntry* findBlockBySetAndWay(int set, int way) const override;
215 
226  CacheBlk* findVictim(Addr addr, const bool is_secure,
227  const std::size_t size,
228  std::vector<CacheBlk*>& evict_blks) override;
229 
236  void insertBlock(const PacketPtr pkt, CacheBlk *blk) override;
237 
244  Addr extractTag(Addr addr) const override
245  {
246  return blkAlign(addr);
247  }
248 
255  Addr regenerateBlkAddr(const CacheBlk* blk) const override
256  {
257  return blk->tag;
258  }
259 
260  void forEachBlk(std::function<void(CacheBlk &)> visitor) override {
261  for (int i = 0; i < numBlocks; i++) {
262  visitor(blks[i]);
263  }
264  }
265 
266  bool anyBlk(std::function<bool(CacheBlk &)> visitor) override {
267  for (int i = 0; i < numBlocks; i++) {
268  if (visitor(blks[i])) {
269  return true;
270  }
271  }
272  return false;
273  }
274 
275  private:
283  {
284  public:
285  CacheTracking(unsigned min_size, unsigned max_size,
286  unsigned block_size)
287  : blkSize(block_size),
288  minTrackedSize(min_size),
289  numTrackedCaches(max_size > min_size ?
290  floorLog2(max_size) - floorLog2(min_size) : 0),
291  inAllCachesMask(mask(numTrackedCaches)),
292  boundaries(numTrackedCaches)
293  {
294  fatal_if(numTrackedCaches > sizeof(CachesMask) * 8,
295  "Not enough bits (%s) in type CachesMask type to keep "
296  "track of %d caches\n", sizeof(CachesMask),
297  numTrackedCaches);
298  }
299 
308  void init(FALRUBlk *head, FALRUBlk *tail);
309 
319  void moveBlockToHead(FALRUBlk *blk);
320 
330  void moveBlockToTail(FALRUBlk *blk);
331 
342  void recordAccess(FALRUBlk *blk);
343 
354  void check(const FALRUBlk *head, const FALRUBlk *tail) const;
355 
359  void regStats(std::string name);
360 
361  private:
363  const unsigned blkSize;
365  const unsigned minTrackedSize;
367  const int numTrackedCaches;
372 
373  protected:
387 
391  };
393 };
394 
395 #endif // __MEM_CACHE_TAGS_FA_LRU_HH__
std::string print() const override
Pretty-print inCachesMask and other CacheBlk information.
Definition: fa_lru.cc:62
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
std::size_t operator()(const std::pair< T1, T2 > &p) const
Definition: fa_lru.hh:128
const std::string & name()
Definition: trace.cc:54
Bitfield< 7 > i
STL pair class.
Definition: stl.hh:61
Addr tag
Data block tag value.
Definition: cache_blk.hh:94
CacheTracking cacheTracking
Definition: fa_lru.hh:392
ip6_addr_t addr
Definition: inet.hh:335
FALRUBlk * head
The MRU block.
Definition: fa_lru.hh:120
A fully associative LRU cache.
Definition: fa_lru.hh:109
std::pair< Addr, bool > TagHashKey
Definition: fa_lru.hh:133
A vector of scalar stats.
Definition: statistics.hh:2550
std::unordered_map< TagHashKey, FALRUBlk *, PairHash > TagHash
Definition: fa_lru.hh:134
FALRUBlk * next
The next block in LRU order.
Definition: fa_lru.hh:92
const int numTrackedCaches
The number of different size caches being tracked.
Definition: fa_lru.hh:367
std::vector< FALRUBlk * > boundaries
Array of pointers to blocks at the cache boundaries.
Definition: fa_lru.hh:371
Declaration of Statistics objects.
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2508
STL vector class.
Definition: stl.hh:40
FALRUBlk * tail
The LRU block.
Definition: fa_lru.hh:122
Declaration of a common base class for cache tagstore objects.
A Basic Cache block.
Definition: cache_blk.hh:87
Mechanism that allows us to simultaneously collect miss statistics for multiple caches.
Definition: fa_lru.hh:282
A fully associative cache block.
Definition: fa_lru.hh:84
void forEachBlk(std::function< void(CacheBlk &)> visitor) override
Visit each block in the tags and apply a visitor.
Definition: fa_lru.hh:260
A basic cache interface.
Definition: base.hh:93
#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
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
const unsigned minTrackedSize
The smallest cache we are tracking.
Definition: fa_lru.hh:365
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:255
Hash table type mapping addresses to cache block pointers.
Definition: fa_lru.hh:125
CacheTracking(unsigned min_size, unsigned max_size, unsigned block_size)
Definition: fa_lru.hh:285
Stats::Scalar accesses
Total number of accesses.
Definition: fa_lru.hh:386
TagHash tagHash
The address hash table.
Definition: fa_lru.hh:137
int floorLog2(unsigned x)
Definition: intmath.hh:61
Definitions of a simple cache block class.
Stats::Vector misses
Misses in each cache.
Definition: fa_lru.hh:384
Stats::Vector hits
Hits in each cache.
Definition: fa_lru.hh:382
Declaration of the Packet class.
bool anyBlk(std::function< bool(CacheBlk &)> visitor) override
Find if any of the blocks satisfies a condition.
Definition: fa_lru.hh:266
Addr extractTag(Addr addr) const override
Generate the tag from the addres.
Definition: fa_lru.hh:244
A replaceable entry is a basic entry in a 2d table-like structure that needs to have replacement func...
FALRUBlk * blks
The cache blocks.
Definition: fa_lru.hh:117
FALRUBlk * prev
The previous block in LRU order.
Definition: fa_lru.hh:90
FALRUBlk()
Definition: fa_lru.hh:87
const unsigned blkSize
The size of the cache block.
Definition: fa_lru.hh:363
Bitfield< 3, 0 > mask
Definition: types.hh:64
FALRUParams Params
Definition: fa_lru.hh:154
uint32_t CachesMask
Definition: fa_lru.hh:73
const CachesMask inAllCachesMask
A mask for all cache being tracked.
Definition: fa_lru.hh:369
FALRUBlk BlkType
Typedef the block type used in this class.
Definition: fa_lru.hh:113
Bitfield< 0 > p
A common base class of Cache tagstore objects.
Definition: base.hh:73
Addr regenerateBlkAddr(const CacheBlk *blk) const override
Regenerate the block address from the tag.
Definition: fa_lru.hh:255
CachesMask inCachesMask
A bit mask of the caches that fit this block.
Definition: fa_lru.hh:95
const FlagsType init
This Stat is Initialized.
Definition: info.hh:47
virtual void invalidate()
Invalidate the block and clear all state.
Definition: cache_blk.hh:214

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