gem5 v24.0.0.0
Loading...
Searching...
No Matches
base.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-2014, 2016-2019, 2023-2024 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
46#ifndef __MEM_CACHE_TAGS_BASE_HH__
47#define __MEM_CACHE_TAGS_BASE_HH__
48
49#include <cassert>
50#include <cstdint>
51#include <functional>
52#include <string>
53
54#include "base/callback.hh"
55#include "base/logging.hh"
56#include "base/statistics.hh"
57#include "base/types.hh"
59#include "mem/packet.hh"
60#include "params/BaseTags.hh"
61#include "sim/clocked_object.hh"
62
63namespace gem5
64{
65
66class System;
67class IndexingPolicy;
68class ReplaceableEntry;
69
73class BaseTags : public ClockedObject
74{
75 protected:
77 const unsigned blkSize;
81 const unsigned size;
84
87
90
93
98 const unsigned warmupBound;
101
103 const unsigned numBlocks;
104
106 std::unique_ptr<uint8_t[]> dataBlks;
107
162
163 public:
164 typedef BaseTagsParams Params;
165 BaseTags(const Params &p);
166
170 virtual ~BaseTags() {}
171
177 virtual void tagsInit() = 0;
178
183 void cleanupRefs();
184
188 void computeStats();
189
193 std::string print();
194
202 virtual CacheBlk *findBlock(Addr addr, bool is_secure) const;
203
211 virtual ReplaceableEntry* findBlockBySetAndWay(int set, int way) const;
212
219 {
220 return addr & ~blkMask;
221 }
222
229 {
230 return (addr & blkMask);
231 }
232
237 virtual void setWayAllocationMax(int ways)
238 {
239 panic("This tag class does not implement way allocation limit!\n");
240 }
241
246 virtual int getWayAllocationMax() const
247 {
248 panic("This tag class does not implement way allocation limit!\n");
249 return -1;
250 }
251
257 virtual void invalidate(CacheBlk *blk)
258 {
259 assert(blk);
260 assert(blk->isValid());
261
263 stats.totalRefs += blk->getRefCount();
265
266 blk->invalidate();
267 }
268
285 virtual CacheBlk* findVictim(Addr addr, const bool is_secure,
286 const std::size_t size,
287 std::vector<CacheBlk*>& evict_blks,
288 const uint64_t partition_id=0) = 0;
289
300 virtual CacheBlk* accessBlock(const PacketPtr pkt, Cycles &lat) = 0;
301
308 virtual Addr extractTag(const Addr addr) const;
309
316 virtual void insertBlock(const PacketPtr pkt, CacheBlk *blk);
317
326 virtual void moveBlock(CacheBlk *src_blk, CacheBlk *dest_blk);
327
334 virtual Addr regenerateBlkAddr(const CacheBlk* blk) const = 0;
335
344 void forEachBlk(std::function<void(CacheBlk &)> visitor);
345
355 virtual bool anyBlk(std::function<bool(CacheBlk &)> visitor) = 0;
356
357 private:
363 void cleanupRefsVisitor(CacheBlk &blk);
364
370 void computeStatsVisitor(CacheBlk &blk);
371};
372
373} // namespace gem5
374
375#endif //__MEM_CACHE_TAGS_BASE_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
Definitions of a simple cache block class.
A common base class for indexing table locations.
Definition base.hh:67
A common base class of Cache tagstore objects.
Definition base.hh:74
partitioning_policy::PartitionManager * partitionManager
Partitioning manager.
Definition base.hh:92
virtual void insertBlock(const PacketPtr pkt, CacheBlk *blk)
Insert the new block into the cache and update stats.
Definition base.cc:104
Addr blkAlign(Addr addr) const
Align an address to the block size.
Definition base.hh:218
virtual Addr extractTag(const Addr addr) const
Generate the tag from the given address.
Definition base.cc:147
virtual void setWayAllocationMax(int ways)
Limit the allocation for the cache ways.
Definition base.hh:237
BaseTags(const Params &p)
Definition base.cc:62
int extractBlkOffset(Addr addr) const
Calculate the block offset of an address.
Definition base.hh:228
const unsigned warmupBound
The number of tags that need to be touched to meet the warmup percentage.
Definition base.hh:98
virtual int getWayAllocationMax() const
Get the way allocation mask limit.
Definition base.hh:246
virtual void tagsInit()=0
Initialize blocks.
virtual ~BaseTags()
Destructor.
Definition base.hh:170
virtual CacheBlk * findBlock(Addr addr, bool is_secure) const
Finds the block in the cache without touching it.
Definition base.cc:82
virtual Addr regenerateBlkAddr(const CacheBlk *blk) const =0
Regenerate the block address.
virtual ReplaceableEntry * findBlockBySetAndWay(int set, int way) const
Find a block given set and way.
Definition base.cc:76
const unsigned size
The size of the cache.
Definition base.hh:81
std::string print()
Print all tags used.
Definition base.cc:206
const Addr blkMask
Mask out all bits that aren't part of the block offset.
Definition base.hh:79
const unsigned numBlocks
the number of blocks in the cache
Definition base.hh:103
System * system
System we are currently operating in.
Definition base.hh:86
virtual bool anyBlk(std::function< bool(CacheBlk &)> visitor)=0
Find if any of the blocks satisfies a condition.
void cleanupRefs()
Average in the reference count for valid blocks when the simulation exits.
Definition base.cc:162
void forEachBlk(std::function< void(CacheBlk &)> visitor)
Visit each block in the tags and apply a visitor.
Definition base.cc:223
virtual void invalidate(CacheBlk *blk)
This function updates the tags when a block is invalidated.
Definition base.hh:257
gem5::BaseTags::BaseTagStats stats
void computeStats()
Computes stats just prior to dump event.
Definition base.cc:193
bool warmedUp
Marked true when the cache is warmed up.
Definition base.hh:100
virtual void moveBlock(CacheBlk *src_blk, CacheBlk *dest_blk)
Move a block's metadata to another location decided by the replacement policy.
Definition base.cc:134
void computeStatsVisitor(CacheBlk &blk)
Update the occupancy and age stats using data from the input block.
Definition base.cc:168
BaseIndexingPolicy * indexingPolicy
Indexing policy.
Definition base.hh:89
virtual CacheBlk * accessBlock(const PacketPtr pkt, Cycles &lat)=0
Access block and update replacement data.
BaseTagsParams Params
Definition base.hh:164
std::unique_ptr< uint8_t[]> dataBlks
The data blocks, 1 per cache block.
Definition base.hh:106
const Cycles lookupLatency
The tag lookup latency of the cache.
Definition base.hh:83
virtual CacheBlk * findVictim(Addr addr, const bool is_secure, const std::size_t size, std::vector< CacheBlk * > &evict_blks, const uint64_t partition_id=0)=0
Find replacement victim based on address.
void cleanupRefsVisitor(CacheBlk &blk)
Update the reference stats using data from the input block.
Definition base.cc:153
const unsigned blkSize
The block size of the cache.
Definition base.hh:77
A Basic Cache block.
Definition cache_blk.hh:72
uint32_t getSrcRequestorId() const
Get the requestor id associated to this block.
Definition cache_blk.hh:291
unsigned getRefCount() const
Get the number of references to this block since insertion.
Definition cache_blk.hh:297
virtual void invalidate() override
Invalidate the block and clear all state.
Definition cache_blk.hh:202
virtual bool isValid() const
Checks if the entry is valid.
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Cycles is a wrapper class for representing cycle counts, i.e.
Definition types.hh:79
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...
A vector of Average stats.
A stat that calculates the per tick average of a value.
A formula for statistics that is calculated when printed.
Statistics container.
Definition group.hh:93
This is a simple scalar statistic, like a counter.
A 2-Dimensional vecto of scalar stats.
A vector of scalar stats.
STL vector class.
Definition stl.hh:37
ClockedObject declaration and implementation.
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
Bitfield< 12, 11 > set
Bitfield< 0 > p
Bitfield< 3 > addr
Definition types.hh:84
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
Declaration of the Packet class.
Declaration of Statistics objects.
TODO: It would be good if these stats were acquired after warmup.
Definition base.hh:112
statistics::Vector2d ageTaskId
Occupancy of each context/cpu using the cache.
Definition base.hh:152
statistics::Scalar tagAccesses
Number of tags consulted over all accesses.
Definition base.hh:158
statistics::Formula avgRefs
Average number of references to a block before is was replaced.
Definition base.hh:137
statistics::Scalar dataAccesses
Number of data blocks consulted over all accesses.
Definition base.hh:160
statistics::Formula avgOccs
Average occ % of each requestor using the cache.
Definition base.hh:146
statistics::Scalar warmupTick
The tick that the warmup percentage was hit.
Definition base.hh:140
statistics::AverageVector occupancies
Average occupancy of each requestor using the cache.
Definition base.hh:143
BaseTagStats(BaseTags &tags)
Definition base.cc:231
void preDumpStats() override
Callback before stats are dumped.
Definition base.cc:308
statistics::Vector occupanciesTaskId
Occupancy of each context/cpu using the cache.
Definition base.hh:149
void regStats() override
Callback to set stat parameters.
Definition base.cc:267
statistics::Scalar totalRefs
The total number of references to a block before it is replaced.
Definition base.hh:124
statistics::Formula ratioOccsTaskId
Occ ratio of each context/cpu using the cache.
Definition base.hh:155
statistics::Average tagsInUse
Per tick average of the number of tags that hold valid data.
Definition base.hh:121
statistics::Scalar sampledRefs
The number of reference counts sampled.
Definition base.hh:131

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