gem5  v22.1.0.0
base.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2014,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  * 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"
58 #include "mem/cache/cache_blk.hh"
59 #include "mem/packet.hh"
60 #include "params/BaseTags.hh"
61 #include "sim/clocked_object.hh"
62 
63 namespace gem5
64 {
65 
66 class System;
67 class IndexingPolicy;
68 class ReplaceableEntry;
69 
73 class BaseTags : public ClockedObject
74 {
75  protected:
77  const unsigned blkSize;
79  const Addr blkMask;
81  const unsigned size;
84 
87 
90 
95  const unsigned warmupBound;
97  bool warmedUp;
98 
100  const unsigned numBlocks;
101 
103  std::unique_ptr<uint8_t[]> dataBlks;
104 
109  {
111 
112  void regStats() override;
113  void preDumpStats() override;
114 
116 
119 
122 
129 
135 
138 
141 
144 
147 
150 
153 
158  } stats;
159 
160  public:
161  typedef BaseTagsParams Params;
162  BaseTags(const Params &p);
163 
167  virtual ~BaseTags() {}
168 
174  virtual void tagsInit() = 0;
175 
180  void cleanupRefs();
181 
185  void computeStats();
186 
190  std::string print();
191 
199  virtual CacheBlk *findBlock(Addr addr, bool is_secure) const;
200 
208  virtual ReplaceableEntry* findBlockBySetAndWay(int set, int way) const;
209 
216  {
217  return addr & ~blkMask;
218  }
219 
226  {
227  return (addr & blkMask);
228  }
229 
234  virtual void setWayAllocationMax(int ways)
235  {
236  panic("This tag class does not implement way allocation limit!\n");
237  }
238 
243  virtual int getWayAllocationMax() const
244  {
245  panic("This tag class does not implement way allocation limit!\n");
246  return -1;
247  }
248 
254  virtual void invalidate(CacheBlk *blk)
255  {
256  assert(blk);
257  assert(blk->isValid());
258 
260  stats.totalRefs += blk->getRefCount();
261  stats.sampledRefs++;
262 
263  blk->invalidate();
264  }
265 
281  virtual CacheBlk* findVictim(Addr addr, const bool is_secure,
282  const std::size_t size,
283  std::vector<CacheBlk*>& evict_blks) = 0;
284 
295  virtual CacheBlk* accessBlock(const PacketPtr pkt, Cycles &lat) = 0;
296 
303  virtual Addr extractTag(const Addr addr) const;
304 
311  virtual void insertBlock(const PacketPtr pkt, CacheBlk *blk);
312 
321  virtual void moveBlock(CacheBlk *src_blk, CacheBlk *dest_blk);
322 
329  virtual Addr regenerateBlkAddr(const CacheBlk* blk) const = 0;
330 
339  virtual void forEachBlk(std::function<void(CacheBlk &)> visitor) = 0;
340 
350  virtual bool anyBlk(std::function<bool(CacheBlk &)> visitor) = 0;
351 
352  private:
358  void cleanupRefsVisitor(CacheBlk &blk);
359 
365  void computeStatsVisitor(CacheBlk &blk);
366 };
367 
368 } // namespace gem5
369 
370 #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
virtual CacheBlk * accessBlock(const PacketPtr pkt, Cycles &lat)=0
Access block and update replacement data.
virtual void insertBlock(const PacketPtr pkt, CacheBlk *blk)
Insert the new block into the cache and update stats.
Definition: base.cc:102
Addr blkAlign(Addr addr) const
Align an address to the block size.
Definition: base.hh:215
virtual Addr extractTag(const Addr addr) const
Generate the tag from the given address.
Definition: base.cc:143
virtual void setWayAllocationMax(int ways)
Limit the allocation for the cache ways.
Definition: base.hh:234
BaseTags(const Params &p)
Definition: base.cc:61
int extractBlkOffset(Addr addr) const
Calculate the block offset of an address.
Definition: base.hh:225
const unsigned warmupBound
The number of tags that need to be touched to meet the warmup percentage.
Definition: base.hh:95
virtual int getWayAllocationMax() const
Get the way allocation mask limit.
Definition: base.hh:243
virtual void tagsInit()=0
Initialize blocks.
virtual ~BaseTags()
Destructor.
Definition: base.hh:167
virtual CacheBlk * findBlock(Addr addr, bool is_secure) const
Finds the block in the cache without touching it.
Definition: base.cc:80
virtual CacheBlk * findVictim(Addr addr, const bool is_secure, const std::size_t size, std::vector< CacheBlk * > &evict_blks)=0
Find replacement victim based on address.
virtual Addr regenerateBlkAddr(const CacheBlk *blk) const =0
Regenerate the block address.
virtual void forEachBlk(std::function< void(CacheBlk &)> visitor)=0
Visit each block in the tags and apply a visitor.
virtual ReplaceableEntry * findBlockBySetAndWay(int set, int way) const
Find a block given set and way.
Definition: base.cc:74
const unsigned size
The size of the cache.
Definition: base.hh:81
std::string print()
Print all tags used.
Definition: base.cc:202
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:100
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:158
virtual void invalidate(CacheBlk *blk)
This function updates the tags when a block is invalidated.
Definition: base.hh:254
gem5::BaseTags::BaseTagStats stats
void computeStats()
Computes stats just prior to dump event.
Definition: base.cc:189
bool warmedUp
Marked true when the cache is warmed up.
Definition: base.hh:97
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:130
void computeStatsVisitor(CacheBlk &blk)
Update the occupancy and age stats using data from the input block.
Definition: base.cc:164
BaseIndexingPolicy * indexingPolicy
Indexing policy.
Definition: base.hh:89
BaseTagsParams Params
Definition: base.hh:161
std::unique_ptr< uint8_t[]> dataBlks
The data blocks, 1 per cache block.
Definition: base.hh:103
const Cycles lookupLatency
The tag lookup latency of the cache.
Definition: base.hh:83
void cleanupRefsVisitor(CacheBlk &blk)
Update the reference stats using data from the input block.
Definition: base.cc:149
const unsigned blkSize
The block size of the cache.
Definition: base.hh:77
A Basic Cache block.
Definition: cache_blk.hh:71
uint32_t getSrcRequestorId() const
Get the requestor id associated to this block.
Definition: cache_blk.hh:288
unsigned getRefCount() const
Get the number of references to this block since insertion.
Definition: cache_blk.hh:291
virtual void invalidate() override
Invalidate the block and clear all state.
Definition: cache_blk.hh:200
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:294
A replaceable entry is a basic entry in a 2d table-like structure that needs to have replacement func...
virtual bool isValid() const
Checks if the entry is valid.
Definition: tagged_entry.hh:57
A vector of Average stats.
Definition: statistics.hh:2033
A stat that calculates the per tick average of a value.
Definition: statistics.hh:1959
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2540
Statistics container.
Definition: group.hh:94
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:1931
A 2-Dimensional vecto of scalar stats.
Definition: statistics.hh:2059
A vector of scalar stats.
Definition: statistics.hh:2007
STL vector class.
Definition: stl.hh:37
ClockedObject declaration and implementation.
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
Bitfield< 12, 11 > set
Definition: misc_types.hh:709
Bitfield< 54 > p
Definition: pagetable.hh:70
Bitfield< 3 > addr
Definition: types.hh:84
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
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:109
statistics::Vector2d ageTaskId
Occupancy of each context/cpu using the cache.
Definition: base.hh:149
statistics::Scalar tagAccesses
Number of tags consulted over all accesses.
Definition: base.hh:155
statistics::Formula avgRefs
Average number of references to a block before is was replaced.
Definition: base.hh:134
statistics::Scalar dataAccesses
Number of data blocks consulted over all accesses.
Definition: base.hh:157
statistics::Formula avgOccs
Average occ % of each requestor using the cache.
Definition: base.hh:143
statistics::Scalar warmupTick
The tick that the warmup percentage was hit.
Definition: base.hh:137
statistics::AverageVector occupancies
Average occupancy of each requestor using the cache.
Definition: base.hh:140
BaseTagStats(BaseTags &tags)
Definition: base.cc:218
void preDumpStats() override
Callback before stats are dumped.
Definition: base.cc:295
statistics::Vector occupanciesTaskId
Occupancy of each context/cpu using the cache.
Definition: base.hh:146
void regStats() override
Callback to set stat parameters.
Definition: base.cc:254
statistics::Scalar totalRefs
The total number of references to a block before it is replaced.
Definition: base.hh:121
statistics::Formula ratioOccsTaskId
Occ ratio of each context/cpu using the cache.
Definition: base.hh:152
statistics::Average tagsInUse
Per tick average of the number of tags that hold valid data.
Definition: base.hh:118
statistics::Scalar sampledRefs
The number of reference counts sampled.
Definition: base.hh:128

Generated on Wed Dec 21 2022 10:22:28 for gem5 by doxygen 1.9.1