gem5 v24.0.0.0
Loading...
Searching...
No Matches
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"
61#include "params/RubyCache.hh"
62#include "sim/sim_object.hh"
63
64namespace gem5
65{
66
67namespace ruby
68{
69
70class CacheMemory : public SimObject
71{
72 public:
73 typedef RubyCacheParams Params;
74 typedef std::shared_ptr<replacement_policy::ReplacementData> ReplData;
75 CacheMemory(const Params &p);
77
78 void init();
79
80 // Public Methods
81 // perform a cache access and see if we hit or not. Return true on a hit.
82 bool tryCacheAccess(Addr address, RubyRequestType type,
83 DataBlock*& data_ptr);
84
85 // similar to above, but doesn't require full access check
86 bool testCacheAccess(Addr address, RubyRequestType type,
87 DataBlock*& data_ptr);
88
89 // tests to see if an address is present in the cache
90 bool isTagPresent(Addr address) const;
91
92 // Returns true if there is:
93 // a) a tag match on this address or there is
94 // b) an unused line in the same cache "way"
95 bool cacheAvail(Addr address) const;
96
97 // Returns a NULL entry that acts as a placeholder for invalid lines
100 {
101 return nullptr;
102 }
103
104 // find an unused entry and sets the tag appropriate for the address
106 void allocateVoid(Addr address, AbstractCacheEntry* new_entry)
107 {
108 allocate(address, new_entry);
109 }
110
111 // Explicitly free up this address
112 void deallocate(Addr address);
113
114 // Returns with the physical address of the conflicting cache line
115 Addr cacheProbe(Addr address) const;
116
117 // looks an address up in the cache
119 const AbstractCacheEntry* lookup(Addr address) const;
120
123
124 bool isBlockInvalid(int64_t cache_set, int64_t loc);
125 bool isBlockNotBusy(int64_t cache_set, int64_t loc);
126
127 // Hook for checkpointing the contents of the cache
128 void recordCacheContents(int cntrl, CacheRecorder* tr) const;
129
130 // Set this address to most recently used
131 void setMRU(Addr address);
132 void setMRU(Addr addr, int occupancy);
133 void setMRU(AbstractCacheEntry* entry);
134 int getReplacementWeight(int64_t set, int64_t loc);
135
136 // Functions for locking and unlocking cache lines corresponding to the
137 // provided address. These are required for supporting atomic memory
138 // accesses. These are to be used when only the address of the cache entry
139 // is available. In case the entry itself is available. use the functions
140 // provided by the AbstractCacheEntry class.
141 void setLocked (Addr addr, int context);
142 void clearLocked (Addr addr);
143 void clearLockedAll (int context);
144 bool isLocked (Addr addr, int context);
145
146 // Print cache contents
147 void print(std::ostream& out) const;
148 void printData(std::ostream& out) const;
149
150 bool checkResourceAvailable(CacheResourceType res, Addr addr);
151 void recordRequestType(CacheRequestType requestType, Addr addr);
152
153 // hardware transactional memory
154 void htmAbortTransaction();
156
157 public:
158 int getCacheSize() const { return m_cache_size; }
159 int getCacheAssoc() const { return m_cache_assoc; }
161 Addr getAddressAtIdx(int idx) const;
162
163 private:
164 // convert a Address to its location in the cache
165 int64_t addressToCacheSet(Addr address) const;
166
167 // Given a cache tag: returns the index of the tag in a set.
168 // returns -1 if the tag is not found.
169 int findTagInSet(int64_t line, Addr tag) const;
170 int findTagInSetIgnorePermissions(int64_t cacheSet, Addr tag) const;
171
172 // Private copy constructor and assignment operator
175
176 private:
177 // Data Members (m_prefix)
179
180 // The first index is the # of cache lines.
181 // The second index is the the amount associativity.
182 std::unordered_map<Addr, int> m_tag_index;
184
187
191
199
209
215
216 private:
248
249 public:
250 // These function increment the number of demand hits/misses by one
251 // each time they are called
252 void profileDemandHit();
253 void profileDemandMiss();
254 void profilePrefetchHit();
255 void profilePrefetchMiss();
256};
257
258std::ostream& operator<<(std::ostream& out, const CacheMemory& obj);
259
260} // namespace ruby
261} // namespace gem5
262
263#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
ALUFreeListArray atomicALUArray
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
CacheMemory(const Params &p)
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
std::ostream & operator<<(std::ostream &os, const BoolVec &myvector)
Definition BoolVec.cc:49
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
Declaration of Statistics objects.
CacheMemoryStats(statistics::Group *parent)

Generated on Tue Jun 18 2024 16:24:05 for gem5 by doxygen 1.11.0