gem5 v24.0.0.0
Loading...
Searching...
No Matches
fa_lru.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023-2024 ARM Limited
3 * Copyright (c) 2012-2013,2016,2018 ARM Limited
4 * All rights reserved.
5 *
6 * The license below extends only to copyright in the software and shall
7 * not be construed as granting a license to any other intellectual
8 * property including but not limited to intellectual property relating
9 * to a hardware implementation of the functionality of the software
10 * licensed hereunder. You may use the software subject to the license
11 * terms below provided that you ensure that this notice is replicated
12 * unmodified and in its entirety in all distributions of the software,
13 * modified or unmodified, in source code or in binary form.
14 *
15 * Copyright (c) 2003-2005 The Regents of The University of Michigan
16 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 */
41
47#ifndef __MEM_CACHE_TAGS_FA_LRU_HH__
48#define __MEM_CACHE_TAGS_FA_LRU_HH__
49
50#include <cstdint>
51#include <functional>
52#include <string>
53#include <unordered_map>
54#include <vector>
55
56#include "base/bitfield.hh"
57#include "base/intmath.hh"
58#include "base/logging.hh"
59#include "base/statistics.hh"
60#include "base/types.hh"
63#include "mem/packet.hh"
64#include "params/FALRU.hh"
65
66namespace gem5
67{
68
69// Uncomment to enable sanity checks for the FALRU cache and the
70// TrackedCaches class
71//#define FALRU_DEBUG
72
73class BaseCache;
74class ReplaceableEntry;
75
76// A bitmask of the caches we are keeping track of. Currently the
77// lowest bit is the smallest cache we are tracking, as it is
78// specified by the corresponding parameter. The rest of the bits are
79// for exponentially growing cache sizes.
80typedef uint32_t CachesMask;
81
85class FALRUBlk : public CacheBlk
86{
87 public:
88 FALRUBlk() : CacheBlk(), prev(nullptr), next(nullptr), inCachesMask(0) {}
89 using CacheBlk::operator=;
90
95
98
104 std::string print() const override;
105};
106
111class FALRU : public BaseTags
112{
113 public:
116
117 protected:
120
125
127 struct PairHash
128 {
129 template <class T1, class T2>
130 std::size_t operator()(const std::pair<T1, T2> &p) const
131 {
132 return std::hash<T1>()(p.first) ^ std::hash<T2>()(p.second);
133 }
134 };
136 typedef std::unordered_map<TagHashKey, FALRUBlk *, PairHash> TagHash;
137
140
146 void moveToHead(FALRUBlk *blk);
147
153 void moveToTail(FALRUBlk *blk);
154
155 public:
156 typedef FALRUParams Params;
157
161 FALRU(const Params &p);
162 ~FALRU();
163
167 void tagsInit() override;
168
173 void invalidate(CacheBlk *blk) override;
174
186 CacheBlk* accessBlock(const PacketPtr pkt, Cycles &lat,
187 CachesMask *in_cache_mask);
188
192 CacheBlk* accessBlock(const PacketPtr pkt, Cycles &lat) override;
193
201 CacheBlk* findBlock(Addr addr, bool is_secure) const override;
202
210 ReplaceableEntry* findBlockBySetAndWay(int set, int way) const override;
211
223 CacheBlk* findVictim(Addr addr, const bool is_secure,
224 const std::size_t size,
225 std::vector<CacheBlk*>& evict_blks,
226 const uint64_t partition_id=0) override;
227
234 void insertBlock(const PacketPtr pkt, CacheBlk *blk) override;
235
236 void moveBlock(CacheBlk *src_blk, CacheBlk *dest_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->getTag();
258 }
259
260 bool anyBlk(std::function<bool(CacheBlk &)> visitor) override {
261 for (int i = 0; i < numBlocks; i++) {
262 if (visitor(blks[i])) {
263 return true;
264 }
265 }
266 return false;
267 }
268
269 private:
277 {
278 public:
279 CacheTracking(unsigned min_size, unsigned max_size,
280 unsigned block_size, statistics::Group *parent);
281
290 void init(FALRUBlk *head, FALRUBlk *tail);
291
301 void moveBlockToHead(FALRUBlk *blk);
302
312 void moveBlockToTail(FALRUBlk *blk);
313
324 void recordAccess(FALRUBlk *blk);
325
336 void check(const FALRUBlk *head, const FALRUBlk *tail) const;
337
338 private:
340 const unsigned blkSize;
342 const unsigned minTrackedSize;
349
350 protected:
364
368 };
370};
371
372} // namespace gem5
373
374#endif // __MEM_CACHE_TAGS_FA_LRU_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
Definitions of a simple cache block class.
A common base class of Cache tagstore objects.
Definition base.hh:74
Addr blkAlign(Addr addr) const
Align an address to the block size.
Definition base.hh:218
const unsigned size
The size of the cache.
Definition base.hh:81
const unsigned numBlocks
the number of blocks in the cache
Definition base.hh:103
A Basic Cache block.
Definition cache_blk.hh:72
virtual Addr getTag() const
Get tag associated to this block.
Cycles is a wrapper class for representing cycle counts, i.e.
Definition types.hh:79
A fully associative cache block.
Definition fa_lru.hh:86
FALRUBlk * next
The next block in LRU order.
Definition fa_lru.hh:94
FALRUBlk * prev
The previous block in LRU order.
Definition fa_lru.hh:92
std::string print() const override
Pretty-print inCachesMask and other CacheBlk information.
Definition fa_lru.cc:63
CachesMask inCachesMask
A bit mask of the caches that fit this block.
Definition fa_lru.hh:97
Mechanism that allows us to simultaneously collect miss statistics for multiple caches.
Definition fa_lru.hh:277
void check(const FALRUBlk *head, const FALRUBlk *tail) const
Check that the tracking mechanism is in consistent state.
Definition fa_lru.cc:339
void recordAccess(FALRUBlk *blk)
Notify of a block access.
Definition fa_lru.cc:445
const CachesMask inAllCachesMask
A mask for all cache being tracked.
Definition fa_lru.hh:346
void moveBlockToHead(FALRUBlk *blk)
Update boundaries as a block will be moved to the MRU.
Definition fa_lru.cc:394
void moveBlockToTail(FALRUBlk *blk)
Update boundaries as a block will be moved to the LRU.
Definition fa_lru.cc:420
std::vector< FALRUBlk * > boundaries
Array of pointers to blocks at the cache boundaries.
Definition fa_lru.hh:348
const unsigned blkSize
The size of the cache block.
Definition fa_lru.hh:340
const unsigned minTrackedSize
The smallest cache we are tracking.
Definition fa_lru.hh:342
CacheTracking(unsigned min_size, unsigned max_size, unsigned block_size, statistics::Group *parent)
Definition fa_lru.cc:302
const int numTrackedCaches
The number of different size caches being tracked.
Definition fa_lru.hh:344
A fully associative LRU cache.
Definition fa_lru.hh:112
std::pair< Addr, bool > TagHashKey
Definition fa_lru.hh:135
void moveToTail(FALRUBlk *blk)
Move a cache block to the LRU position.
Definition fa_lru.cc:264
std::unordered_map< TagHashKey, FALRUBlk *, PairHash > TagHash
Definition fa_lru.hh:136
CacheBlk * accessBlock(const PacketPtr pkt, Cycles &lat, CachesMask *in_cache_mask)
Access block and update replacement data.
Definition fa_lru.cc:143
TagHash tagHash
The address hash table.
Definition fa_lru.hh:139
Addr extractTag(Addr addr) const override
Generate the tag from the addres.
Definition fa_lru.hh:244
FALRU(const Params &p)
Construct and initialize this cache tagstore.
Definition fa_lru.cc:68
bool anyBlk(std::function< bool(CacheBlk &)> visitor) override
Find if any of the blocks satisfies a condition.
Definition fa_lru.hh:260
FALRUBlk BlkType
Typedef the block type used in this class.
Definition fa_lru.hh:115
ReplaceableEntry * findBlockBySetAndWay(int set, int way) const override
Find a block given set and way.
Definition fa_lru.cc:189
void moveBlock(CacheBlk *src_blk, CacheBlk *dest_blk) override
Move a block's metadata to another location decided by the replacement policy.
Definition fa_lru.cc:231
void invalidate(CacheBlk *blk) override
Invalidate a cache block.
Definition fa_lru.cc:117
void moveToHead(FALRUBlk *blk)
Move a cache block to the MRU position.
Definition fa_lru.cc:237
Addr regenerateBlkAddr(const CacheBlk *blk) const override
Regenerate the block address from the tag.
Definition fa_lru.hh:255
CacheBlk * findVictim(Addr addr, const bool is_secure, const std::size_t size, std::vector< CacheBlk * > &evict_blks, const uint64_t partition_id=0) override
Find replacement victim based on address.
Definition fa_lru.cc:196
CacheBlk * findBlock(Addr addr, bool is_secure) const override
Find the block in the cache, do not update the replacement data.
Definition fa_lru.cc:170
CacheTracking cacheTracking
Definition fa_lru.hh:369
void tagsInit() override
Initialize blocks as FALRUBlk instances.
Definition fa_lru.cc:90
FALRUBlk * tail
The LRU block.
Definition fa_lru.hh:124
FALRUParams Params
Definition fa_lru.hh:156
FALRUBlk * head
The MRU block.
Definition fa_lru.hh:122
void insertBlock(const PacketPtr pkt, CacheBlk *blk) override
Insert the new block into the cache and update replacement data.
Definition fa_lru.cc:210
FALRUBlk * blks
The cache blocks.
Definition fa_lru.hh:119
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
A replaceable entry is a basic entry in a 2d table-like structure that needs to have replacement func...
Statistics container.
Definition group.hh:93
This is a simple scalar statistic, like a counter.
A vector of scalar stats.
STL pair class.
Definition stl.hh:58
STL vector class.
Definition stl.hh:37
statistics::Vector hits
Hits in each cache.
Definition fa_lru.hh:359
statistics::Vector misses
Misses in each cache.
Definition fa_lru.hh:361
statistics::Scalar accesses
Total number of accesses.
Definition fa_lru.hh:363
Declaration of a common base class for cache tagstore objects.
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 12, 11 > set
Bitfield< 0 > p
Bitfield< 3 > addr
Definition types.hh:84
const FlagsType init
This Stat is Initialized.
Definition info.hh:55
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
uint32_t CachesMask
Definition fa_lru.hh:80
Declaration of the Packet class.
Declaration of Statistics objects.
Hash table type mapping addresses to cache block pointers.
Definition fa_lru.hh:128
std::size_t operator()(const std::pair< T1, T2 > &p) const
Definition fa_lru.hh:130

Generated on Tue Jun 18 2024 16:24:05 for gem5 by doxygen 1.11.0