gem5  v22.1.0.0
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 namespace gem5
64 {
65 
66 namespace ruby
67 {
68 
69 class CacheMemory : public SimObject
70 {
71  public:
72  typedef RubyCacheParams Params;
73  typedef std::shared_ptr<replacement_policy::ReplacementData> ReplData;
74  CacheMemory(const Params &p);
75  ~CacheMemory();
76 
77  void init();
78 
79  // Public Methods
80  // perform a cache access and see if we hit or not. Return true on a hit.
81  bool tryCacheAccess(Addr address, RubyRequestType type,
82  DataBlock*& data_ptr);
83 
84  // similar to above, but doesn't require full access check
85  bool testCacheAccess(Addr address, RubyRequestType type,
86  DataBlock*& data_ptr);
87 
88  // tests to see if an address is present in the cache
89  bool isTagPresent(Addr address) const;
90 
91  // Returns true if there is:
92  // a) a tag match on this address or there is
93  // b) an unused line in the same cache "way"
94  bool cacheAvail(Addr address) const;
95 
96  // Returns a NULL entry that acts as a placeholder for invalid lines
98  getNullEntry() const
99  {
100  return nullptr;
101  }
102 
103  // find an unused entry and sets the tag appropriate for the address
104  AbstractCacheEntry* allocate(Addr address, AbstractCacheEntry* new_entry);
105  void allocateVoid(Addr address, AbstractCacheEntry* new_entry)
106  {
107  allocate(address, new_entry);
108  }
109 
110  // Explicitly free up this address
111  void deallocate(Addr address);
112 
113  // Returns with the physical address of the conflicting cache line
114  Addr cacheProbe(Addr address) const;
115 
116  // looks an address up in the cache
117  AbstractCacheEntry* lookup(Addr address);
118  const AbstractCacheEntry* lookup(Addr address) const;
119 
120  Cycles getTagLatency() const { return tagArray.getLatency(); }
122 
123  bool isBlockInvalid(int64_t cache_set, int64_t loc);
124  bool isBlockNotBusy(int64_t cache_set, int64_t loc);
125 
126  // Hook for checkpointing the contents of the cache
127  void recordCacheContents(int cntrl, CacheRecorder* tr) const;
128 
129  // Set this address to most recently used
130  void setMRU(Addr address);
131  void setMRU(Addr addr, int occupancy);
132  void setMRU(AbstractCacheEntry* entry);
133  int getReplacementWeight(int64_t set, int64_t loc);
134 
135  // Functions for locking and unlocking cache lines corresponding to the
136  // provided address. These are required for supporting atomic memory
137  // accesses. These are to be used when only the address of the cache entry
138  // is available. In case the entry itself is available. use the functions
139  // provided by the AbstractCacheEntry class.
140  void setLocked (Addr addr, int context);
141  void clearLocked (Addr addr);
142  void clearLockedAll (int context);
143  bool isLocked (Addr addr, int context);
144 
145  // Print cache contents
146  void print(std::ostream& out) const;
147  void printData(std::ostream& out) const;
148 
149  bool checkResourceAvailable(CacheResourceType res, Addr addr);
150  void recordRequestType(CacheRequestType requestType, Addr addr);
151 
152  // hardware transactional memory
153  void htmAbortTransaction();
154  void htmCommitTransaction();
155 
156  public:
157  int getCacheSize() const { return m_cache_size; }
158  int getCacheAssoc() const { return m_cache_assoc; }
159  int getNumBlocks() const { return m_cache_num_sets * m_cache_assoc; }
160  Addr getAddressAtIdx(int idx) const;
161 
162  private:
163  // convert a Address to its location in the cache
164  int64_t addressToCacheSet(Addr address) const;
165 
166  // Given a cache tag: returns the index of the tag in a set.
167  // returns -1 if the tag is not found.
168  int findTagInSet(int64_t line, Addr tag) const;
169  int findTagInSetIgnorePermissions(int64_t cacheSet, Addr tag) const;
170 
171  // Private copy constructor and assignment operator
174 
175  private:
176  // Data Members (m_prefix)
178 
179  // The first index is the # of cache lines.
180  // The second index is the the amount associativity.
181  std::unordered_map<Addr, int> m_tag_index;
183 
186 
189 
197 
207 
213 
214  private:
216  {
218 
223 
226 
227  // hardware transactional memory
232 
236 
240 
243 
244  public:
245  // These function increment the number of demand hits/misses by one
246  // each time they are called
247  void profileDemandHit();
248  void profileDemandMiss();
249  void profilePrefetchHit();
250  void profilePrefetchMiss();
251 };
252 
253 std::ostream& operator<<(std::ostream& out, const CacheMemory& obj);
254 
255 } // namespace ruby
256 } // namespace gem5
257 
258 #endif // __MEM_RUBY_STRUCTURES_CACHEMEMORY_HH__
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:79
Abstract superclass for simulation objects.
Definition: sim_object.hh:148
A common base class of cache replacement policy objects.
Definition: base.hh:56
Cycles getLatency() const
Definition: BankedArray.hh:80
bool isTagPresent(Addr address) const
Definition: CacheMemory.cc:231
Addr getAddressAtIdx(int idx) const
Definition: CacheMemory.cc:166
void clearLockedAll(int context)
Definition: CacheMemory.cc:497
bool testCacheAccess(Addr address, RubyRequestType type, DataBlock *&data_ptr)
Definition: CacheMemory.cc:211
CacheMemory & operator=(const CacheMemory &obj)
Cycles getDataLatency() const
Definition: CacheMemory.hh:121
bool m_use_occupancy
Set to true when using WeightedLRU replacement policy, otherwise, set to false.
Definition: CacheMemory.hh:212
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: CacheMemory.cc:90
Cycles getTagLatency() const
Definition: CacheMemory.hh:120
std::vector< std::vector< ReplData > > replacement_data
We store all the ReplacementData in a 2-dimensional array.
Definition: CacheMemory.hh:206
void print(std::ostream &out) const
Definition: CacheMemory.cc:454
void recordCacheContents(int cntrl, CacheRecorder *tr) const
Definition: CacheMemory.cc:415
void setMRU(Addr address)
Definition: CacheMemory.cc:364
gem5::ruby::CacheMemory::CacheMemoryStats cacheMemoryStats
void deallocate(Addr address)
Definition: CacheMemory.cc:310
int findTagInSet(int64_t line, Addr tag) const
Definition: CacheMemory.cc:136
void setLocked(Addr addr, int context)
Definition: CacheMemory.cc:479
int findTagInSetIgnorePermissions(int64_t cacheSet, Addr tag) const
Definition: CacheMemory.cc:151
bool isBlockInvalid(int64_t cache_set, int64_t loc)
Definition: CacheMemory.cc:673
CacheMemory(const CacheMemory &obj)
int64_t addressToCacheSet(Addr address) const
Definition: CacheMemory.cc:126
bool tryCacheAccess(Addr address, RubyRequestType type, DataBlock *&data_ptr)
Definition: CacheMemory.cc:186
RubyCacheParams Params
Definition: CacheMemory.hh:72
std::shared_ptr< replacement_policy::ReplacementData > ReplData
Definition: CacheMemory.hh:73
void clearLocked(Addr addr)
Definition: CacheMemory.cc:488
bool isBlockNotBusy(int64_t cache_set, int64_t loc)
Definition: CacheMemory.cc:679
Addr cacheProbe(Addr address) const
Definition: CacheMemory.cc:325
void allocateVoid(Addr address, AbstractCacheEntry *new_entry)
Definition: CacheMemory.hh:105
void recordRequestType(CacheRequestType requestType, Addr addr)
Definition: CacheMemory.cc:611
void printData(std::ostream &out) const
Definition: CacheMemory.cc:473
bool cacheAvail(Addr address) const
Definition: CacheMemory.cc:247
AbstractCacheEntry * getNullEntry() const
Definition: CacheMemory.hh:98
CacheMemory(const Params &p)
Definition: CacheMemory.cc:70
replacement_policy::Base * m_replacementPolicy_ptr
We use the replacement policies from the Classic memory system.
Definition: CacheMemory.hh:185
std::unordered_map< Addr, int > m_tag_index
Definition: CacheMemory.hh:181
AbstractCacheEntry * allocate(Addr address, AbstractCacheEntry *new_entry)
Definition: CacheMemory.cc:269
int getReplacementWeight(int64_t set, int64_t loc)
Definition: CacheMemory.cc:401
std::vector< std::vector< AbstractCacheEntry * > > m_cache
Definition: CacheMemory.hh:182
bool checkResourceAvailable(CacheResourceType res, Addr addr)
Definition: CacheMemory.cc:643
AbstractCacheEntry * lookup(Addr address)
Definition: CacheMemory.cc:342
bool isLocked(Addr addr, int context)
Definition: CacheMemory.cc:514
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2540
Statistics container.
Definition: group.hh:94
A simple histogram stat.
Definition: statistics.hh:2127
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:1931
A vector of scalar stats.
Definition: statistics.hh:2007
STL vector class.
Definition: stl.hh:37
Bitfield< 12, 11 > set
Definition: misc_types.hh:709
Bitfield< 54 > p
Definition: pagetable.hh:70
Bitfield< 3 > addr
Definition: types.hh:84
std::ostream & operator<<(std::ostream &os, const BoolVec &myvector)
Definition: BoolVec.cc:49
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 Statistics objects.
statistics::Histogram htmTransCommitWriteSet
Definition: CacheMemory.hh:229
statistics::Histogram htmTransCommitReadSet
Definition: CacheMemory.hh:228
statistics::Histogram htmTransAbortWriteSet
Definition: CacheMemory.hh:231
statistics::Histogram htmTransAbortReadSet
Definition: CacheMemory.hh:230
CacheMemoryStats(statistics::Group *parent)
Definition: CacheMemory.cc:524

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