gem5 v23.0.0.1
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
63namespace gem5
64{
65
66namespace ruby
67{
68
69class CacheMemory : public SimObject
70{
71 public:
72 typedef RubyCacheParams Params;
73 typedef std::shared_ptr<replacement_policy::ReplacementData> ReplData;
74 CacheMemory(const Params &p);
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
99 {
100 return nullptr;
101 }
102
103 // find an unused entry and sets the tag appropriate for the address
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
118 const AbstractCacheEntry* lookup(Addr address) const;
119
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();
155
156 public:
157 int getCacheSize() const { return m_cache_size; }
158 int getCacheAssoc() const { return 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
253std::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.
A common base class of cache replacement policy objects.
Definition base.hh:55
Cycles getLatency() const
bool isTagPresent(Addr address) const
Addr getAddressAtIdx(int idx) const
void clearLockedAll(int context)
bool testCacheAccess(Addr address, RubyRequestType type, DataBlock *&data_ptr)
AbstractCacheEntry * getNullEntry() const
Cycles getDataLatency() const
bool m_use_occupancy
Set to true when using WeightedLRU replacement policy, otherwise, set to false.
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Cycles getTagLatency() const
std::vector< std::vector< ReplData > > replacement_data
We store all the ReplacementData in a 2-dimensional array.
void print(std::ostream &out) const
CacheMemory & operator=(const CacheMemory &obj)
void recordCacheContents(int cntrl, CacheRecorder *tr) const
void setMRU(Addr address)
gem5::ruby::CacheMemory::CacheMemoryStats cacheMemoryStats
void deallocate(Addr address)
int findTagInSet(int64_t line, Addr tag) const
void setLocked(Addr addr, int context)
int findTagInSetIgnorePermissions(int64_t cacheSet, Addr tag) const
bool isBlockInvalid(int64_t cache_set, int64_t loc)
CacheMemory(const CacheMemory &obj)
int64_t addressToCacheSet(Addr address) const
bool tryCacheAccess(Addr address, RubyRequestType type, DataBlock *&data_ptr)
RubyCacheParams Params
std::shared_ptr< replacement_policy::ReplacementData > ReplData
void clearLocked(Addr addr)
bool isBlockNotBusy(int64_t cache_set, int64_t loc)
Addr cacheProbe(Addr address) const
void allocateVoid(Addr address, AbstractCacheEntry *new_entry)
void recordRequestType(CacheRequestType requestType, Addr addr)
void printData(std::ostream &out) const
bool cacheAvail(Addr address) const
replacement_policy::Base * m_replacementPolicy_ptr
We use the replacement policies from the Classic memory system.
std::unordered_map< Addr, int > m_tag_index
AbstractCacheEntry * allocate(Addr address, AbstractCacheEntry *new_entry)
int getReplacementWeight(int64_t set, int64_t loc)
std::vector< std::vector< AbstractCacheEntry * > > m_cache
bool checkResourceAvailable(CacheResourceType res, Addr addr)
AbstractCacheEntry * lookup(Addr address)
bool isLocked(Addr addr, int context)
A formula for statistics that is calculated when printed.
Statistics container.
Definition group.hh:93
A simple histogram stat.
This is a simple scalar statistic, like a counter.
A vector of scalar stats.
STL vector class.
Definition stl.hh:37
Bitfield< 12, 11 > set
Bitfield< 0 > p
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
std::ostream & operator<<(std::ostream &os, const ArmSemihosting::InPlaceArg &ipa)
Declaration of Statistics objects.

Generated on Mon Jul 10 2023 15:32:05 for gem5 by doxygen 1.9.7