gem5  v21.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CacheMemory.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020-2021 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) 1999-2012 Mark D. Hill and David A. Wood
15  * Copyright (c) 2013 Advanced Micro Devices, Inc.
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 
42 #ifndef __MEM_RUBY_STRUCTURES_CACHEMEMORY_HH__
43 #define __MEM_RUBY_STRUCTURES_CACHEMEMORY_HH__
44 
45 #include <string>
46 #include <unordered_map>
47 #include <vector>
48 
49 #include "base/statistics.hh"
53 #include "mem/ruby/protocol/CacheRequestType.hh"
54 #include "mem/ruby/protocol/CacheResourceType.hh"
55 #include "mem/ruby/protocol/RubyRequest.hh"
60 #include "params/RubyCache.hh"
61 #include "sim/sim_object.hh"
62 
63 class CacheMemory : public SimObject
64 {
65  public:
66  typedef RubyCacheParams Params;
67  typedef std::shared_ptr<ReplacementPolicy::ReplacementData> ReplData;
68  CacheMemory(const Params &p);
69  ~CacheMemory();
70 
71  void init();
72 
73  // Public Methods
74  // perform a cache access and see if we hit or not. Return true on a hit.
75  bool tryCacheAccess(Addr address, RubyRequestType type,
76  DataBlock*& data_ptr);
77 
78  // similar to above, but doesn't require full access check
79  bool testCacheAccess(Addr address, RubyRequestType type,
80  DataBlock*& data_ptr);
81 
82  // tests to see if an address is present in the cache
83  bool isTagPresent(Addr address) const;
84 
85  // Returns true if there is:
86  // a) a tag match on this address or there is
87  // b) an unused line in the same cache "way"
88  bool cacheAvail(Addr address) const;
89 
90  // Returns a NULL entry that acts as a placeholder for invalid lines
92  getNullEntry() const
93  {
94  return nullptr;
95  }
96 
97  // find an unused entry and sets the tag appropriate for the address
98  AbstractCacheEntry* allocate(Addr address, AbstractCacheEntry* new_entry);
99  void allocateVoid(Addr address, AbstractCacheEntry* new_entry)
100  {
101  allocate(address, new_entry);
102  }
103 
104  // Explicitly free up this address
105  void deallocate(Addr address);
106 
107  // Returns with the physical address of the conflicting cache line
108  Addr cacheProbe(Addr address) const;
109 
110  // looks an address up in the cache
111  AbstractCacheEntry* lookup(Addr address);
112  const AbstractCacheEntry* lookup(Addr address) const;
113 
114  Cycles getTagLatency() const { return tagArray.getLatency(); }
116 
117  bool isBlockInvalid(int64_t cache_set, int64_t loc);
118  bool isBlockNotBusy(int64_t cache_set, int64_t loc);
119 
120  // Hook for checkpointing the contents of the cache
121  void recordCacheContents(int cntrl, CacheRecorder* tr) const;
122 
123  // Set this address to most recently used
124  void setMRU(Addr address);
125  void setMRU(Addr addr, int occupancy);
126  void setMRU(AbstractCacheEntry* entry);
127  int getReplacementWeight(int64_t set, int64_t loc);
128 
129  // Functions for locking and unlocking cache lines corresponding to the
130  // provided address. These are required for supporting atomic memory
131  // accesses. These are to be used when only the address of the cache entry
132  // is available. In case the entry itself is available. use the functions
133  // provided by the AbstractCacheEntry class.
134  void setLocked (Addr addr, int context);
135  void clearLocked (Addr addr);
136  void clearLockedAll (int context);
137  bool isLocked (Addr addr, int context);
138 
139  // Print cache contents
140  void print(std::ostream& out) const;
141  void printData(std::ostream& out) const;
142 
143  bool checkResourceAvailable(CacheResourceType res, Addr addr);
144  void recordRequestType(CacheRequestType requestType, Addr addr);
145 
146  // hardware transactional memory
147  void htmAbortTransaction();
148  void htmCommitTransaction();
149 
150  public:
151  int getCacheSize() const { return m_cache_size; }
152  int getCacheAssoc() const { return m_cache_assoc; }
153  int getNumBlocks() const { return m_cache_num_sets * m_cache_assoc; }
154  Addr getAddressAtIdx(int idx) const;
155 
156  private:
157  // convert a Address to its location in the cache
158  int64_t addressToCacheSet(Addr address) const;
159 
160  // Given a cache tag: returns the index of the tag in a set.
161  // returns -1 if the tag is not found.
162  int findTagInSet(int64_t line, Addr tag) const;
163  int findTagInSetIgnorePermissions(int64_t cacheSet, Addr tag) const;
164 
165  // Private copy constructor and assignment operator
166  CacheMemory(const CacheMemory& obj);
167  CacheMemory& operator=(const CacheMemory& obj);
168 
169  private:
170  // Data Members (m_prefix)
172 
173  // The first index is the # of cache lines.
174  // The second index is the the amount associativity.
175  std::unordered_map<Addr, int> m_tag_index;
177 
180 
183 
191 
201 
207 
208  private:
210  {
212 
217 
220 
221  // hardware transactional memory
226 
230 
234 
237 
238  public:
239  // These function increment the number of demand hits/misses by one
240  // each time they are called
241  void profileDemandHit();
242  void profileDemandMiss();
243  void profilePrefetchHit();
244  void profilePrefetchMiss();
245 };
246 
247 std::ostream& operator<<(std::ostream& out, const CacheMemory& obj);
248 
249 #endif // __MEM_RUBY_STRUCTURES_CACHEMEMORY_HH__
CacheMemory::recordCacheContents
void recordCacheContents(int cntrl, CacheRecorder *tr) const
Definition: CacheMemory.cc:408
CacheMemory::cacheMemoryStats
CacheMemory::CacheMemoryStats cacheMemoryStats
AbstractCacheEntry
Definition: AbstractCacheEntry.hh:57
CacheMemory::findTagInSetIgnorePermissions
int findTagInSetIgnorePermissions(int64_t cacheSet, Addr tag) const
Definition: CacheMemory.cc:144
CacheMemory::m_cache_size
int m_cache_size
Definition: CacheMemory.hh:184
CacheMemory::Params
RubyCacheParams Params
Definition: CacheMemory.hh:66
CacheMemory::CacheMemoryStats::CacheMemoryStats
CacheMemoryStats(Stats::Group *parent)
Definition: CacheMemory.cc:517
CacheRecorder
Definition: CacheRecorder.hh:66
CacheMemory::CacheMemoryStats::numDataArrayWrites
Stats::Scalar numDataArrayWrites
Definition: CacheMemory.hh:214
CacheMemory::clearLocked
void clearLocked(Addr addr)
Definition: CacheMemory.cc:481
CacheMemory::lookup
AbstractCacheEntry * lookup(Addr address)
Definition: CacheMemory.cc:335
CacheMemory::tagArray
BankedArray tagArray
Definition: CacheMemory.hh:182
CacheMemory::isLocked
bool isLocked(Addr addr, int context)
Definition: CacheMemory.cc:507
CacheMemory::m_cache
std::vector< std::vector< AbstractCacheEntry * > > m_cache
Definition: CacheMemory.hh:176
CacheMemory::dataArray
BankedArray dataArray
Definition: CacheMemory.hh:181
CacheMemory::allocateVoid
void allocateVoid(Addr address, AbstractCacheEntry *new_entry)
Definition: CacheMemory.hh:99
CacheMemory::CacheMemoryStats::m_prefetch_accesses
Stats::Formula m_prefetch_accesses
Definition: CacheMemory.hh:233
BankedArray::getLatency
Cycles getLatency() const
Definition: BankedArray.hh:75
CacheMemory::cacheProbe
Addr cacheProbe(Addr address) const
Definition: CacheMemory.cc:318
CacheMemory::~CacheMemory
~CacheMemory()
Definition: CacheMemory.cc:106
std::vector
STL vector class.
Definition: stl.hh:37
CacheMemory::m_tag_index
std::unordered_map< Addr, int > m_tag_index
Definition: CacheMemory.hh:175
CacheMemory::m_cache_num_set_bits
int m_cache_num_set_bits
Definition: CacheMemory.hh:186
BankedArray.hh
CacheMemory::print
void print(std::ostream &out) const
Definition: CacheMemory.cc:447
CacheMemory::CacheMemoryStats::numDataArrayStalls
Stats::Scalar numDataArrayStalls
Definition: CacheMemory.hh:219
Stats::Vector
A vector of scalar stats.
Definition: statistics.hh:2007
CacheMemory::setMRU
void setMRU(Addr address)
Definition: CacheMemory.cc:357
AbstractCacheEntry.hh
CacheMemory::CacheMemoryStats::numTagArrayReads
Stats::Scalar numTagArrayReads
Definition: CacheMemory.hh:215
CacheMemory::deallocate
void deallocate(Addr address)
Definition: CacheMemory.cc:303
CacheMemory::CacheMemoryStats::htmTransAbortReadSet
Stats::Histogram htmTransAbortReadSet
Definition: CacheMemory.hh:224
CacheMemory::testCacheAccess
bool testCacheAccess(Addr address, RubyRequestType type, DataBlock *&data_ptr)
Definition: CacheMemory.cc:204
CacheMemory::getTagLatency
Cycles getTagLatency() const
Definition: CacheMemory.hh:114
CacheMemory::m_use_occupancy
bool m_use_occupancy
Set to true when using WeightedLRU replacement policy, otherwise, set to false.
Definition: CacheMemory.hh:206
BankedArray
Definition: BankedArray.hh:41
DataBlock
Definition: DataBlock.hh:54
Stats::Histogram
A simple histogram stat.
Definition: statistics.hh:2126
replaceable_entry.hh
CacheMemory::getCacheAssoc
int getCacheAssoc() const
Definition: CacheMemory.hh:152
CacheMemory::CacheMemoryStats::htmTransCommitReadSet
Stats::Histogram htmTransCommitReadSet
Definition: CacheMemory.hh:222
Stats::Scalar
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:1933
CacheMemory::m_replacementPolicy_ptr
ReplacementPolicy::Base * m_replacementPolicy_ptr
We use the replacement policies from the Classic memory system.
Definition: CacheMemory.hh:179
CacheMemory::CacheMemoryStats
Definition: CacheMemory.hh:209
CacheMemory::allocate
AbstractCacheEntry * allocate(Addr address, AbstractCacheEntry *new_entry)
Definition: CacheMemory.cc:262
CacheMemory::init
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: CacheMemory.cc:83
CacheMemory::replacement_data
std::vector< std::vector< ReplData > > replacement_data
We store all the ReplacementData in a 2-dimensional array.
Definition: CacheMemory.hh:200
CacheMemory::CacheMemoryStats::m_prefetch_hits
Stats::Scalar m_prefetch_hits
Definition: CacheMemory.hh:231
sim_object.hh
CacheMemory::printData
void printData(std::ostream &out) const
Definition: CacheMemory.cc:466
DataBlock.hh
statistics.hh
CacheMemory::CacheMemory
CacheMemory(const Params &p)
Definition: CacheMemory.cc:63
CacheMemory::cacheAvail
bool cacheAvail(Addr address) const
Definition: CacheMemory.cc:240
CacheMemory::getNullEntry
AbstractCacheEntry * getNullEntry() const
Definition: CacheMemory.hh:92
CacheMemory
Definition: CacheMemory.hh:63
CacheMemory::operator=
CacheMemory & operator=(const CacheMemory &obj)
CacheMemory::m_cache_assoc
int m_cache_assoc
Definition: CacheMemory.hh:187
CacheMemory::CacheMemoryStats::m_prefetch_misses
Stats::Scalar m_prefetch_misses
Definition: CacheMemory.hh:232
CacheMemory::isBlockInvalid
bool isBlockInvalid(int64_t cache_set, int64_t loc)
Definition: CacheMemory.cc:662
ReplacementPolicy::Base
A common base class of cache replacement policy objects.
Definition: base.hh:48
base.hh
CacheMemory::CacheMemoryStats::htmTransCommitWriteSet
Stats::Histogram htmTransCommitWriteSet
Definition: CacheMemory.hh:223
CacheMemory::CacheMemoryStats::numDataArrayReads
Stats::Scalar numDataArrayReads
Definition: CacheMemory.hh:213
CacheMemory::m_block_size
int m_block_size
Definition: CacheMemory.hh:190
CacheMemory::CacheMemoryStats::m_demand_hits
Stats::Scalar m_demand_hits
Definition: CacheMemory.hh:227
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:148
CacheMemory::findTagInSet
int findTagInSet(int64_t line, Addr tag) const
Definition: CacheMemory.cc:129
CacheMemory::clearLockedAll
void clearLockedAll(int context)
Definition: CacheMemory.cc:490
RubySlicc_ComponentMapping.hh
CacheMemory::CacheMemoryStats::m_demand_misses
Stats::Scalar m_demand_misses
Definition: CacheMemory.hh:228
CacheMemory::m_start_index_bit
int m_start_index_bit
Definition: CacheMemory.hh:188
CacheMemory::getDataLatency
Cycles getDataLatency() const
Definition: CacheMemory.hh:115
operator<<
std::ostream & operator<<(std::ostream &out, const CacheMemory &obj)
Definition: CacheMemory.cc:56
X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:80
CacheMemory::tryCacheAccess
bool tryCacheAccess(Addr address, RubyRequestType type, DataBlock *&data_ptr)
Definition: CacheMemory.cc:179
CacheMemory::htmCommitTransaction
void htmCommitTransaction()
Definition: CacheMemory.cc:710
CacheMemory::setLocked
void setLocked(Addr addr, int context)
Definition: CacheMemory.cc:472
CacheMemory::isTagPresent
bool isTagPresent(Addr address) const
Definition: CacheMemory.cc:224
Stats::Formula
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2538
Stats::Group
Statistics container.
Definition: group.hh:87
CacheMemory::profilePrefetchHit
void profilePrefetchHit()
Definition: CacheMemory.cc:752
CacheMemory::CacheMemoryStats::m_accessModeType
Stats::Vector m_accessModeType
Definition: CacheMemory.hh:235
CacheMemory::getAddressAtIdx
Addr getAddressAtIdx(int idx) const
Definition: CacheMemory.cc:159
Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:79
CacheMemory::m_is_instruction_only_cache
bool m_is_instruction_only_cache
Definition: CacheMemory.hh:171
CacheMemory::addressToCacheSet
int64_t addressToCacheSet(Addr address) const
Definition: CacheMemory.cc:119
CacheMemory::CacheMemoryStats::numTagArrayWrites
Stats::Scalar numTagArrayWrites
Definition: CacheMemory.hh:216
CacheMemory::profileDemandMiss
void profileDemandMiss()
Definition: CacheMemory.cc:746
CacheMemory::getCacheSize
int getCacheSize() const
Definition: CacheMemory.hh:151
X86ISA::type
type
Definition: misc.hh:727
CacheMemory::profileDemandHit
void profileDemandHit()
Definition: CacheMemory.cc:740
CacheMemory::profilePrefetchMiss
void profilePrefetchMiss()
Definition: CacheMemory.cc:758
CacheMemory::checkResourceAvailable
bool checkResourceAvailable(CacheResourceType res, Addr addr)
Definition: CacheMemory.cc:632
CacheMemory::CacheMemoryStats::htmTransAbortWriteSet
Stats::Histogram htmTransAbortWriteSet
Definition: CacheMemory.hh:225
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
CacheMemory::ReplData
std::shared_ptr< ReplacementPolicy::ReplacementData > ReplData
Definition: CacheMemory.hh:67
CacheRecorder.hh
CacheMemory::CacheMemoryStats::m_demand_accesses
Stats::Formula m_demand_accesses
Definition: CacheMemory.hh:229
CacheMemory::CacheMemoryStats::numTagArrayStalls
Stats::Scalar numTagArrayStalls
Definition: CacheMemory.hh:218
CacheMemory::recordRequestType
void recordRequestType(CacheRequestType requestType, Addr addr)
Definition: CacheMemory.cc:600
CacheMemory::htmAbortTransaction
void htmAbortTransaction()
Definition: CacheMemory.cc:676
CacheMemory::getReplacementWeight
int getReplacementWeight(int64_t set, int64_t loc)
Definition: CacheMemory.cc:394
CacheMemory::m_cache_num_sets
int m_cache_num_sets
Definition: CacheMemory.hh:185
CacheMemory::getNumBlocks
int getNumBlocks() const
Definition: CacheMemory.hh:153
CacheMemory::m_resource_stalls
bool m_resource_stalls
Definition: CacheMemory.hh:189
CacheMemory::isBlockNotBusy
bool isBlockNotBusy(int64_t cache_set, int64_t loc)
Definition: CacheMemory.cc:668
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:141

Generated on Tue Mar 23 2021 19:41:28 for gem5 by doxygen 1.8.17