gem5  v19.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) 1999-2012 Mark D. Hill and David A. Wood
3  * Copyright (c) 2013 Advanced Micro Devices, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met: redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer;
10  * redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution;
13  * neither the name of the copyright holders nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef __MEM_RUBY_STRUCTURES_CACHEMEMORY_HH__
31 #define __MEM_RUBY_STRUCTURES_CACHEMEMORY_HH__
32 
33 #include <string>
34 #include <unordered_map>
35 #include <vector>
36 
37 #include "base/statistics.hh"
41 #include "mem/ruby/protocol/CacheRequestType.hh"
42 #include "mem/ruby/protocol/CacheResourceType.hh"
43 #include "mem/ruby/protocol/RubyRequest.hh"
48 #include "params/RubyCache.hh"
49 #include "sim/sim_object.hh"
50 
51 class CacheMemory : public SimObject
52 {
53  public:
54  typedef RubyCacheParams Params;
55  typedef std::shared_ptr<ReplacementData> ReplData;
56  CacheMemory(const Params *p);
57  ~CacheMemory();
58 
59  void init();
60 
61  // Public Methods
62  // perform a cache access and see if we hit or not. Return true on a hit.
63  bool tryCacheAccess(Addr address, RubyRequestType type,
64  DataBlock*& data_ptr);
65 
66  // similar to above, but doesn't require full access check
67  bool testCacheAccess(Addr address, RubyRequestType type,
68  DataBlock*& data_ptr);
69 
70  // tests to see if an address is present in the cache
71  bool isTagPresent(Addr address) const;
72 
73  // Returns true if there is:
74  // a) a tag match on this address or there is
75  // b) an unused line in the same cache "way"
76  bool cacheAvail(Addr address) const;
77 
78  // find an unused entry and sets the tag appropriate for the address
79  AbstractCacheEntry* allocate(Addr address, AbstractCacheEntry* new_entry);
80  void allocateVoid(Addr address, AbstractCacheEntry* new_entry)
81  {
82  allocate(address, new_entry);
83  }
84 
85  // Explicitly free up this address
86  void deallocate(Addr address);
87 
88  // Returns with the physical address of the conflicting cache line
89  Addr cacheProbe(Addr address) const;
90 
91  // looks an address up in the cache
92  AbstractCacheEntry* lookup(Addr address);
93  const AbstractCacheEntry* lookup(Addr address) const;
94 
95  Cycles getTagLatency() const { return tagArray.getLatency(); }
96  Cycles getDataLatency() const { return dataArray.getLatency(); }
97 
98  bool isBlockInvalid(int64_t cache_set, int64_t loc);
99  bool isBlockNotBusy(int64_t cache_set, int64_t loc);
100 
101  // Hook for checkpointing the contents of the cache
102  void recordCacheContents(int cntrl, CacheRecorder* tr) const;
103 
104  // Set this address to most recently used
105  void setMRU(Addr address);
106  void setMRU(Addr addr, int occupancy);
107  int getReplacementWeight(int64_t set, int64_t loc);
108  void setMRU(const AbstractCacheEntry *e);
109 
110  // Functions for locking and unlocking cache lines corresponding to the
111  // provided address. These are required for supporting atomic memory
112  // accesses. These are to be used when only the address of the cache entry
113  // is available. In case the entry itself is available. use the functions
114  // provided by the AbstractCacheEntry class.
115  void setLocked (Addr addr, int context);
116  void clearLocked (Addr addr);
117  bool isLocked (Addr addr, int context);
118 
119  // Print cache contents
120  void print(std::ostream& out) const;
121  void printData(std::ostream& out) const;
122 
123  void regStats();
124  bool checkResourceAvailable(CacheResourceType res, Addr addr);
125  void recordRequestType(CacheRequestType requestType, Addr addr);
126 
127  public:
131 
135 
137 
142 
145 
146  int getCacheSize() const { return m_cache_size; }
147  int getCacheAssoc() const { return m_cache_assoc; }
148  int getNumBlocks() const { return m_cache_num_sets * m_cache_assoc; }
149  Addr getAddressAtIdx(int idx) const;
150 
151  private:
152  // convert a Address to its location in the cache
153  int64_t addressToCacheSet(Addr address) const;
154 
155  // Given a cache tag: returns the index of the tag in a set.
156  // returns -1 if the tag is not found.
157  int findTagInSet(int64_t line, Addr tag) const;
158  int findTagInSetIgnorePermissions(int64_t cacheSet, Addr tag) const;
159 
160  // Private copy constructor and assignment operator
161  CacheMemory(const CacheMemory& obj);
162  CacheMemory& operator=(const CacheMemory& obj);
163 
164  private:
165  // Data Members (m_prefix)
167 
168  // The first index is the # of cache lines.
169  // The second index is the the amount associativity.
170  std::unordered_map<Addr, int> m_tag_index;
172 
178 
181 
189 
199 
205 };
206 
207 std::ostream& operator<<(std::ostream& out, const CacheMemory& obj);
208 
209 #endif // __MEM_RUBY_STRUCTURES_CACHEMEMORY_HH__
Stats::Scalar m_demand_misses
Definition: CacheMemory.hh:129
Addr cacheProbe(Addr address) const
Definition: CacheMemory.cc:322
BankedArray tagArray
Definition: CacheMemory.hh:180
Stats::Vector m_accessModeType
Definition: CacheMemory.hh:136
void recordCacheContents(int cntrl, CacheRecorder *tr) const
Definition: CacheMemory.cc:420
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
BankedArray dataArray
Definition: CacheMemory.hh:179
void recordRequestType(CacheRequestType requestType, Addr addr)
Definition: CacheMemory.cc:611
Stats::Formula m_demand_accesses
Definition: CacheMemory.hh:130
int m_cache_num_set_bits
Definition: CacheMemory.hh:184
void print(std::ostream &out) const
Definition: CacheMemory.cc:459
bool m_resource_stalls
Definition: CacheMemory.hh:187
bool isBlockNotBusy(int64_t cache_set, int64_t loc)
Definition: CacheMemory.cc:679
int findTagInSetIgnorePermissions(int64_t cacheSet, Addr tag) const
Definition: CacheMemory.cc:138
bool testCacheAccess(Addr address, RubyRequestType type, DataBlock *&data_ptr)
Definition: CacheMemory.cc:201
ip6_addr_t addr
Definition: inet.hh:335
RubyCacheParams Params
Definition: CacheMemory.hh:54
Stats::Scalar m_hw_prefetches
Definition: CacheMemory.hh:133
std::shared_ptr< ReplacementData > ReplData
Definition: CacheMemory.hh:55
void clearLocked(Addr addr)
Definition: CacheMemory.cc:495
A vector of scalar stats.
Definition: statistics.hh:2550
AbstractCacheEntry * allocate(Addr address, AbstractCacheEntry *new_entry)
Definition: CacheMemory.cc:267
bool isLocked(Addr addr, int context)
Definition: CacheMemory.cc:506
void regStats()
Callback to set stat parameters.
Definition: CacheMemory.cc:518
bool m_use_occupancy
Set to true when using WeightedLRU replacement policy, otherwise, set to false.
Definition: CacheMemory.hh:204
Stats::Scalar numTagArrayStalls
Definition: CacheMemory.hh:143
Declaration of Statistics objects.
A common base class of cache replacement policy objects.
Definition: base.hh:48
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2508
void printData(std::ostream &out) const
Definition: CacheMemory.cc:478
STL vector class.
Definition: stl.hh:40
Cycles getLatency() const
Definition: BankedArray.hh:75
void deallocate(Addr address)
Definition: CacheMemory.cc:305
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: CacheMemory.cc:77
bool cacheAvail(Addr address) const
Definition: CacheMemory.cc:245
BaseReplacementPolicy * m_replacementPolicy_ptr
We use BaseReplacementPolicy from Classic system here, hence we can use different replacement policie...
Definition: CacheMemory.hh:177
Cycles getTagLatency() const
Definition: CacheMemory.hh:95
uint8_t type
Definition: inet.hh:333
std::unordered_map< Addr, int > m_tag_index
Definition: CacheMemory.hh:170
int getCacheAssoc() const
Definition: CacheMemory.hh:147
void setMRU(Addr address)
Definition: CacheMemory.cc:364
std::vector< std::vector< ReplData > > replacement_data
We store all the ReplacementData in a 2-dimensional array.
Definition: CacheMemory.hh:198
std::ostream & operator<<(std::ostream &out, const CacheMemory &obj)
CacheMemory(const Params *p)
Definition: CacheMemory.cc:58
bool isBlockInvalid(int64_t cache_set, int64_t loc)
Definition: CacheMemory.cc:673
bool tryCacheAccess(Addr address, RubyRequestType type, DataBlock *&data_ptr)
Definition: CacheMemory.cc:173
Stats::Scalar m_demand_hits
Definition: CacheMemory.hh:128
int findTagInSet(int64_t line, Addr tag) const
Definition: CacheMemory.cc:123
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Cycles getDataLatency() const
Definition: CacheMemory.hh:96
Stats::Scalar numDataArrayWrites
Definition: CacheMemory.hh:139
Addr getAddressAtIdx(int idx) const
Definition: CacheMemory.cc:153
bool m_is_instruction_only_cache
Definition: CacheMemory.hh:166
A formula for statistics that is calculated when printed.
Definition: statistics.hh:3012
Bitfield< 9 > e
CacheMemory & operator=(const CacheMemory &obj)
bool isTagPresent(Addr address) const
Definition: CacheMemory.cc:226
int m_start_index_bit
Definition: CacheMemory.hh:186
Stats::Scalar m_sw_prefetches
Definition: CacheMemory.hh:132
int getReplacementWeight(int64_t set, int64_t loc)
Definition: CacheMemory.cc:406
void setLocked(Addr addr, int context)
Definition: CacheMemory.cc:484
Stats::Scalar numTagArrayWrites
Definition: CacheMemory.hh:141
Stats::Scalar numDataArrayStalls
Definition: CacheMemory.hh:144
Stats::Scalar numDataArrayReads
Definition: CacheMemory.hh:138
Stats::Scalar numTagArrayReads
Definition: CacheMemory.hh:140
Stats::Formula m_prefetches
Definition: CacheMemory.hh:134
Bitfield< 0 > p
bool checkResourceAvailable(CacheResourceType res, Addr addr)
Definition: CacheMemory.cc:643
int getNumBlocks() const
Definition: CacheMemory.hh:148
AbstractCacheEntry * lookup(Addr address)
Definition: CacheMemory.cc:342
Abstract superclass for simulation objects.
Definition: sim_object.hh:96
int64_t addressToCacheSet(Addr address) const
Definition: CacheMemory.cc:113
std::vector< std::vector< AbstractCacheEntry * > > m_cache
Definition: CacheMemory.hh:171
int m_cache_num_sets
Definition: CacheMemory.hh:183
int getCacheSize() const
Definition: CacheMemory.hh:146
void allocateVoid(Addr address, AbstractCacheEntry *new_entry)
Definition: CacheMemory.hh:80

Generated on Fri Feb 28 2020 16:27:02 for gem5 by doxygen 1.8.13