gem5  v20.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 class System;
64 class IndexingPolicy;
65 class ReplaceableEntry;
66 
70 class BaseTags : public ClockedObject
71 {
72  protected:
74  const unsigned blkSize;
76  const Addr blkMask;
78  const unsigned size;
81 
84 
87 
92  const unsigned warmupBound;
94  bool warmedUp;
95 
97  const unsigned numBlocks;
98 
100  std::unique_ptr<uint8_t[]> dataBlks;
101 
105  struct BaseTagStats : public Stats::Group
106  {
108 
109  void regStats() override;
110  void preDumpStats() override;
111 
113 
116 
119 
126 
132 
135 
138 
141 
144 
147 
150 
155  } stats;
156 
157  public:
158  typedef BaseTagsParams Params;
159  BaseTags(const Params *p);
160 
164  virtual ~BaseTags() {}
165 
171  virtual void tagsInit() = 0;
172 
177  void cleanupRefs();
178 
182  void computeStats();
183 
187  std::string print();
188 
196  virtual CacheBlk *findBlock(Addr addr, bool is_secure) const;
197 
205  virtual ReplaceableEntry* findBlockBySetAndWay(int set, int way) const;
206 
213  {
214  return addr & ~blkMask;
215  }
216 
223  {
224  return (addr & blkMask);
225  }
226 
231  virtual void setWayAllocationMax(int ways)
232  {
233  panic("This tag class does not implement way allocation limit!\n");
234  }
235 
240  virtual int getWayAllocationMax() const
241  {
242  panic("This tag class does not implement way allocation limit!\n");
243  return -1;
244  }
245 
251  virtual void invalidate(CacheBlk *blk)
252  {
253  assert(blk);
254  assert(blk->isValid());
255 
257  stats.totalRefs += blk->refCount;
258  stats.sampledRefs++;
259 
260  blk->invalidate();
261  }
262 
278  virtual CacheBlk* findVictim(Addr addr, const bool is_secure,
279  const std::size_t size,
280  std::vector<CacheBlk*>& evict_blks) = 0;
281 
293  virtual CacheBlk* accessBlock(Addr addr, bool is_secure, Cycles &lat) = 0;
294 
301  virtual Addr extractTag(const Addr addr) const;
302 
309  virtual void insertBlock(const PacketPtr pkt, CacheBlk *blk);
310 
317  virtual Addr regenerateBlkAddr(const CacheBlk* blk) const = 0;
318 
327  virtual void forEachBlk(std::function<void(CacheBlk &)> visitor) = 0;
328 
338  virtual bool anyBlk(std::function<bool(CacheBlk &)> visitor) = 0;
339 
340  private:
346  void cleanupRefsVisitor(CacheBlk &blk);
347 
353  void computeStatsVisitor(CacheBlk &blk);
354 };
355 
356 #endif //__MEM_CACHE_TAGS_BASE_HH__
BaseTags::~BaseTags
virtual ~BaseTags()
Destructor.
Definition: base.hh:164
BaseTags::BaseTagStats::percentOccsTaskId
Stats::Formula percentOccsTaskId
Occ % of each context/cpu using the cache.
Definition: base.hh:149
ReplaceableEntry
A replaceable entry is a basic entry in a 2d table-like structure that needs to have replacement func...
Definition: replaceable_entry.hh:53
BaseTags::dataBlks
std::unique_ptr< uint8_t[]> dataBlks
The data blocks, 1 per cache block.
Definition: base.hh:100
BaseTags::BaseTagStats::occupancies
Stats::AverageVector occupancies
Average occupancy of each requestor using the cache.
Definition: base.hh:137
BaseTags::cleanupRefs
void cleanupRefs()
Average in the reference count for valid blocks when the simulation exits.
Definition: base.cc:143
BaseTags::numBlocks
const unsigned numBlocks
the number of blocks in the cache
Definition: base.hh:97
BaseTags::computeStatsVisitor
void computeStatsVisitor(CacheBlk &blk)
Update the occupancy and age stats using data from the input block.
Definition: base.cc:149
BaseTags::warmupBound
const unsigned warmupBound
The number of tags that need to be touched to meet the warmup percentage.
Definition: base.hh:92
BaseTags::print
std::string print()
Print all tags used.
Definition: base.cc:187
BaseTags::accessBlock
virtual CacheBlk * accessBlock(Addr addr, bool is_secure, Cycles &lat)=0
Access block and update replacement data.
std::vector
STL vector class.
Definition: stl.hh:37
BaseTags::BaseTagStats::preDumpStats
void preDumpStats() override
Callback before stats are dumped.
Definition: base.cc:273
BaseTags::extractTag
virtual Addr extractTag(const Addr addr) const
Generate the tag from the given address.
Definition: base.cc:128
BaseTags::BaseTagStats::BaseTagStats
BaseTagStats(BaseTags &tags)
Definition: base.cc:203
Stats::Vector
A vector of scalar stats.
Definition: statistics.hh:2575
BaseTags::setWayAllocationMax
virtual void setWayAllocationMax(int ways)
Limit the allocation for the cache ways.
Definition: base.hh:231
ClockedObject
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Definition: clocked_object.hh:231
BaseTags::BaseTagStats::occupanciesTaskId
Stats::Vector occupanciesTaskId
Occupancy of each context/cpu using the cache.
Definition: base.hh:143
packet.hh
BaseTags::getWayAllocationMax
virtual int getWayAllocationMax() const
Get the way allocation mask limit.
Definition: base.hh:240
BaseTags::extractBlkOffset
int extractBlkOffset(Addr addr) const
Calculate the block offset of an address.
Definition: base.hh:222
Stats::Scalar
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2533
BaseTags::invalidate
virtual void invalidate(CacheBlk *blk)
This function updates the tags when a block is invalidated.
Definition: base.hh:251
BaseTags::BaseTags
BaseTags(const Params *p)
Definition: base.cc:58
BaseTags::BaseTagStats::tagsInUse
Stats::Average tagsInUse
Per cycle average of the number of tags that hold valid data.
Definition: base.hh:115
BaseTags::BaseTagStats::totalRefs
Stats::Scalar totalRefs
The total number of references to a block before it is replaced.
Definition: base.hh:118
BaseTags::regenerateBlkAddr
virtual Addr regenerateBlkAddr(const CacheBlk *blk) const =0
Regenerate the block address.
BaseTags::tagsInit
virtual void tagsInit()=0
Initialize blocks.
System
Definition: system.hh:73
BaseTags
A common base class of Cache tagstore objects.
Definition: base.hh:70
statistics.hh
BaseTags::insertBlock
virtual void insertBlock(const PacketPtr pkt, CacheBlk *blk)
Insert the new block into the cache and update stats.
Definition: base.cc:100
BaseTags::blkMask
const Addr blkMask
Mask out all bits that aren't part of the block offset.
Definition: base.hh:76
BaseTags::BaseTagStats::warmupCycle
Stats::Scalar warmupCycle
The cycle that the warmup percentage was hit.
Definition: base.hh:134
BaseTags::BaseTagStats::tagAccesses
Stats::Scalar tagAccesses
Number of tags consulted over all accesses.
Definition: base.hh:152
BaseTags::anyBlk
virtual bool anyBlk(std::function< bool(CacheBlk &)> visitor)=0
Find if any of the blocks satisfies a condition.
BaseTags::Params
BaseTagsParams Params
Definition: base.hh:158
BaseTags::BaseTagStats::regStats
void regStats() override
Callback to set stat parameters.
Definition: base.cc:232
BaseTags::blkSize
const unsigned blkSize
The block size of the cache.
Definition: base.hh:74
CacheBlk::invalidate
virtual void invalidate()
Invalidate the block and clear all state.
Definition: cache_blk.hh:211
BaseTags::BaseTagStats
TODO: It would be good if these stats were acquired after warmup.
Definition: base.hh:105
BaseTags::BaseTagStats::ageTaskId
Stats::Vector2d ageTaskId
Occupancy of each context/cpu using the cache.
Definition: base.hh:146
CacheBlk::refCount
unsigned refCount
Number of references to this block since it was brought in.
Definition: cache_blk.hh:114
BaseTags::indexingPolicy
BaseIndexingPolicy * indexingPolicy
Indexing policy.
Definition: base.hh:86
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
BaseTags::BaseTagStats::dataAccesses
Stats::Scalar dataAccesses
Number of data blocks consulted over all accesses.
Definition: base.hh:154
BaseTags::stats
BaseTags::BaseTagStats stats
Stats::Average
A stat that calculates the per tick average of a value.
Definition: statistics.hh:2549
CacheBlk::isValid
bool isValid() const
Checks that a block is valid.
Definition: cache_blk.hh:203
BaseTags::BaseTagStats::avgRefs
Stats::Formula avgRefs
Average number of references to a block before is was replaced.
Definition: base.hh:131
Stats::Vector2d
A 2-Dimensional vecto of scalar stats.
Definition: statistics.hh:2603
cache_blk.hh
BaseTags::BaseTagStats::avgOccs
Stats::Formula avgOccs
Average occ % of each requestor using the cache.
Definition: base.hh:140
CacheBlk
A Basic Cache block.
Definition: cache_blk.hh:84
types.hh
clocked_object.hh
Stats::AverageVector
A vector of Average stats.
Definition: statistics.hh:2589
Stats::Formula
A formula for statistics that is calculated when printed.
Definition: statistics.hh:3037
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
Stats::Group
Statistics container.
Definition: group.hh:83
addr
ip6_addr_t addr
Definition: inet.hh:423
BaseIndexingPolicy
A common base class for indexing table locations.
Definition: base.hh:63
BaseTags::findBlock
virtual CacheBlk * findBlock(Addr addr, bool is_secure) const
Finds the block in the cache without touching it.
Definition: base.cc:77
logging.hh
Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
BaseTags::computeStats
void computeStats()
Computes stats just prior to dump event.
Definition: base.cc:174
BaseTags::lookupLatency
const Cycles lookupLatency
The tag lookup latency of the cache.
Definition: base.hh:80
BaseTags::forEachBlk
virtual void forEachBlk(std::function< void(CacheBlk &)> visitor)=0
Visit each block in the tags and apply a visitor.
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
BaseTags::BaseTagStats::tags
BaseTags & tags
Definition: base.hh:112
BaseTags::findVictim
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.
BaseTags::system
System * system
System we are currently operating in.
Definition: base.hh:83
CacheBlk::srcRequestorId
int srcRequestorId
holds the source requestor ID for this block.
Definition: cache_blk.hh:117
BaseTags::size
const unsigned size
The size of the cache.
Definition: base.hh:78
BaseTags::BaseTagStats::sampledRefs
Stats::Scalar sampledRefs
The number of reference counts sampled.
Definition: base.hh:125
BaseTags::blkAlign
Addr blkAlign(Addr addr) const
Align an address to the block size.
Definition: base.hh:212
BaseTags::warmedUp
bool warmedUp
Marked true when the cache is warmed up.
Definition: base.hh:94
callback.hh
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
BaseTags::findBlockBySetAndWay
virtual ReplaceableEntry * findBlockBySetAndWay(int set, int way) const
Find a block given set and way.
Definition: base.cc:71
BaseTags::cleanupRefsVisitor
void cleanupRefsVisitor(CacheBlk &blk)
Update the reference stats using data from the input block.
Definition: base.cc:134

Generated on Wed Sep 30 2020 14:02:07 for gem5 by doxygen 1.8.17