gem5  v21.1.0.2
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__
gem5::BaseTags::findBlockBySetAndWay
virtual ReplaceableEntry * findBlockBySetAndWay(int set, int way) const
Find a block given set and way.
Definition: base.cc:74
gem5::statistics::Scalar
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:1927
gem5::BaseTags::computeStats
void computeStats()
Computes stats just prior to dump event.
Definition: base.cc:189
gem5::BaseTags::BaseTagStats::occupancies
statistics::AverageVector occupancies
Average occupancy of each requestor using the cache.
Definition: base.hh:140
gem5::BaseTags::blkMask
const Addr blkMask
Mask out all bits that aren't part of the block offset.
Definition: base.hh:79
gem5::BaseIndexingPolicy
A common base class for indexing table locations.
Definition: base.hh:66
gem5::BaseTags::getWayAllocationMax
virtual int getWayAllocationMax() const
Get the way allocation mask limit.
Definition: base.hh:243
gem5::BaseTags::lookupLatency
const Cycles lookupLatency
The tag lookup latency of the cache.
Definition: base.hh:83
gem5::BaseTags::cleanupRefsVisitor
void cleanupRefsVisitor(CacheBlk &blk)
Update the reference stats using data from the input block.
Definition: base.cc:149
gem5::BaseTags::setWayAllocationMax
virtual void setWayAllocationMax(int ways)
Limit the allocation for the cache ways.
Definition: base.hh:234
gem5::BaseTags::BaseTagStats::occupanciesTaskId
statistics::Vector occupanciesTaskId
Occupancy of each context/cpu using the cache.
Definition: base.hh:146
gem5::BaseTags::system
System * system
System we are currently operating in.
Definition: base.hh:86
gem5::BaseTags::BaseTagStats::preDumpStats
void preDumpStats() override
Callback before stats are dumped.
Definition: base.cc:295
gem5::BaseTags::stats
gem5::BaseTags::BaseTagStats stats
gem5::BaseTags::BaseTagStats
TODO: It would be good if these stats were acquired after warmup.
Definition: base.hh:108
gem5::statistics::Average
A stat that calculates the per tick average of a value.
Definition: statistics.hh:1955
gem5::statistics::Vector2d
A 2-Dimensional vecto of scalar stats.
Definition: statistics.hh:2055
gem5::statistics::Vector
A vector of scalar stats.
Definition: statistics.hh:2003
gem5::statistics::Formula
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2536
std::vector
STL vector class.
Definition: stl.hh:37
gem5::BaseTags::numBlocks
const unsigned numBlocks
the number of blocks in the cache
Definition: base.hh:100
gem5::BaseTags::moveBlock
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
gem5::BaseTags::BaseTagStats::regStats
void regStats() override
Callback to set stat parameters.
Definition: base.cc:254
gem5::BaseTags::BaseTags
BaseTags(const Params &p)
Definition: base.cc:61
gem5::BaseTags::blkAlign
Addr blkAlign(Addr addr) const
Align an address to the block size.
Definition: base.hh:215
gem5::CacheBlk
A Basic Cache block.
Definition: cache_blk.hh:70
packet.hh
gem5::BaseTags::BaseTagStats::dataAccesses
statistics::Scalar dataAccesses
Number of data blocks consulted over all accesses.
Definition: base.hh:157
gem5::Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:78
gem5::BaseTags::Params
BaseTagsParams Params
Definition: base.hh:161
gem5::BaseTags::cleanupRefs
void cleanupRefs()
Average in the reference count for valid blocks when the simulation exits.
Definition: base.cc:158
gem5::BaseTags::BaseTagStats::sampledRefs
statistics::Scalar sampledRefs
The number of reference counts sampled.
Definition: base.hh:128
gem5::BaseTags::size
const unsigned size
The size of the cache.
Definition: base.hh:81
gem5::BaseTags::~BaseTags
virtual ~BaseTags()
Destructor.
Definition: base.hh:167
gem5::statistics::AverageVector
A vector of Average stats.
Definition: statistics.hh:2029
gem5::System
Definition: system.hh:77
gem5::BaseTags::warmupBound
const unsigned warmupBound
The number of tags that need to be touched to meet the warmup percentage.
Definition: base.hh:95
gem5::BaseTags::BaseTagStats::avgRefs
statistics::Formula avgRefs
Average number of references to a block before is was replaced.
Definition: base.hh:134
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:283
gem5::CacheBlk::getSrcRequestorId
uint32_t getSrcRequestorId() const
Get the requestor id associated to this block.
Definition: cache_blk.hh:288
gem5::BaseTags::BaseTagStats::tags
BaseTags & tags
Definition: base.hh:115
gem5::BaseTags::tagsInit
virtual void tagsInit()=0
Initialize blocks.
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
statistics.hh
gem5::BaseTags::BaseTagStats::avgOccs
statistics::Formula avgOccs
Average occ % of each requestor using the cache.
Definition: base.hh:143
gem5::BaseTags::BaseTagStats::totalRefs
statistics::Scalar totalRefs
The total number of references to a block before it is replaced.
Definition: base.hh:121
gem5::BaseTags::regenerateBlkAddr
virtual Addr regenerateBlkAddr(const CacheBlk *blk) const =0
Regenerate the block address.
gem5::BaseTags::accessBlock
virtual CacheBlk * accessBlock(const PacketPtr pkt, Cycles &lat)=0
Access block and update replacement data.
gem5::BaseTags::computeStatsVisitor
void computeStatsVisitor(CacheBlk &blk)
Update the occupancy and age stats using data from the input block.
Definition: base.cc:164
gem5::BaseTags::extractTag
virtual Addr extractTag(const Addr addr) const
Generate the tag from the given address.
Definition: base.cc:143
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::BaseTags::print
std::string print()
Print all tags used.
Definition: base.cc:202
gem5::BaseTags::BaseTagStats::warmupTick
statistics::Scalar warmupTick
The tick that the warmup percentage was hit.
Definition: base.hh:137
gem5::ClockedObject
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Definition: clocked_object.hh:234
gem5::BaseTags::forEachBlk
virtual void forEachBlk(std::function< void(CacheBlk &)> visitor)=0
Visit each block in the tags and apply a visitor.
gem5::BaseTags::insertBlock
virtual void insertBlock(const PacketPtr pkt, CacheBlk *blk)
Insert the new block into the cache and update stats.
Definition: base.cc:102
gem5::BaseTags::anyBlk
virtual bool anyBlk(std::function< bool(CacheBlk &)> visitor)=0
Find if any of the blocks satisfies a condition.
cache_blk.hh
types.hh
gem5::BaseTags::BaseTagStats::tagsInUse
statistics::Average tagsInUse
Per tick average of the number of tags that hold valid data.
Definition: base.hh:118
clocked_object.hh
gem5::ReplaceableEntry
A replaceable entry is a basic entry in a 2d table-like structure that needs to have replacement func...
Definition: replaceable_entry.hh:63
gem5::BaseTags::warmedUp
bool warmedUp
Marked true when the cache is warmed up.
Definition: base.hh:97
gem5::BaseTags::blkSize
const unsigned blkSize
The block size of the cache.
Definition: base.hh:77
logging.hh
gem5::statistics::Group
Statistics container.
Definition: group.hh:93
gem5::BaseTags::findBlock
virtual CacheBlk * findBlock(Addr addr, bool is_secure) const
Finds the block in the cache without touching it.
Definition: base.cc:80
gem5::BaseTags::invalidate
virtual void invalidate(CacheBlk *blk)
This function updates the tags when a block is invalidated.
Definition: base.hh:254
gem5::BaseTags::indexingPolicy
BaseIndexingPolicy * indexingPolicy
Indexing policy.
Definition: base.hh:89
gem5::BaseTags::extractBlkOffset
int extractBlkOffset(Addr addr) const
Calculate the block offset of an address.
Definition: base.hh:225
gem5::BaseTags::BaseTagStats::ratioOccsTaskId
statistics::Formula ratioOccsTaskId
Occ ratio of each context/cpu using the cache.
Definition: base.hh:152
gem5::CacheBlk::invalidate
virtual void invalidate() override
Invalidate the block and clear all state.
Definition: cache_blk.hh:200
gem5::BaseTags
A common base class of Cache tagstore objects.
Definition: base.hh:73
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::BaseTags::dataBlks
std::unique_ptr< uint8_t[]> dataBlks
The data blocks, 1 per cache block.
Definition: base.hh:103
gem5::BaseTags::BaseTagStats::tagAccesses
statistics::Scalar tagAccesses
Number of tags consulted over all accesses.
Definition: base.hh:155
gem5::CacheBlk::getRefCount
unsigned getRefCount() const
Get the number of references to this block since insertion.
Definition: cache_blk.hh:291
gem5::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.
gem5::BaseTags::BaseTagStats::BaseTagStats
BaseTagStats(BaseTags &tags)
Definition: base.cc:218
callback.hh
gem5::BaseTags::BaseTagStats::ageTaskId
statistics::Vector2d ageTaskId
Occupancy of each context/cpu using the cache.
Definition: base.hh:149
gem5::TaggedEntry::isValid
virtual bool isValid() const
Checks if the entry is valid.
Definition: tagged_entry.hh:57
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:177
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84

Generated on Tue Sep 21 2021 12:24:57 for gem5 by doxygen 1.8.17