gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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"
38 #include "mem/protocol/CacheRequestType.hh"
39 #include "mem/protocol/CacheResourceType.hh"
40 #include "mem/protocol/RubyRequest.hh"
47 #include "params/RubyCache.hh"
48 #include "sim/sim_object.hh"
49 
50 class CacheMemory : public SimObject
51 {
52  public:
53  typedef RubyCacheParams Params;
54  CacheMemory(const Params *p);
55  ~CacheMemory();
56 
57  void init();
58 
59  // Public Methods
60  // perform a cache access and see if we hit or not. Return true on a hit.
61  bool tryCacheAccess(Addr address, RubyRequestType type,
62  DataBlock*& data_ptr);
63 
64  // similar to above, but doesn't require full access check
65  bool testCacheAccess(Addr address, RubyRequestType type,
66  DataBlock*& data_ptr);
67 
68  // tests to see if an address is present in the cache
69  bool isTagPresent(Addr address) const;
70 
71  // Returns true if there is:
72  // a) a tag match on this address or there is
73  // b) an unused line in the same cache "way"
74  bool cacheAvail(Addr address) const;
75 
76  // find an unused entry and sets the tag appropriate for the address
78  AbstractCacheEntry* new_entry, bool touch);
80  {
81  return allocate(address, new_entry, true);
82  }
83  void allocateVoid(Addr address, AbstractCacheEntry* new_entry)
84  {
85  allocate(address, new_entry, true);
86  }
87 
88  // Explicitly free up this address
89  void deallocate(Addr address);
90 
91  // Returns with the physical address of the conflicting cache line
92  Addr cacheProbe(Addr address) const;
93 
94  // looks an address up in the cache
95  AbstractCacheEntry* lookup(Addr address);
96  const AbstractCacheEntry* lookup(Addr address) const;
97 
98  Cycles getTagLatency() const { return tagArray.getLatency(); }
99  Cycles getDataLatency() const { return dataArray.getLatency(); }
100 
101  bool isBlockInvalid(int64_t cache_set, int64_t loc);
102  bool isBlockNotBusy(int64_t cache_set, int64_t loc);
103 
104  // Hook for checkpointing the contents of the cache
105  void recordCacheContents(int cntrl, CacheRecorder* tr) const;
106 
107  // Set this address to most recently used
108  void setMRU(Addr address);
109  void setMRU(Addr addr, int occupancy);
110  int getReplacementWeight(int64_t set, int64_t loc);
111  void setMRU(const AbstractCacheEntry *e);
112 
113  // Functions for locking and unlocking cache lines corresponding to the
114  // provided address. These are required for supporting atomic memory
115  // accesses. These are to be used when only the address of the cache entry
116  // is available. In case the entry itself is available. use the functions
117  // provided by the AbstractCacheEntry class.
118  void setLocked (Addr addr, int context);
119  void clearLocked (Addr addr);
120  bool isLocked (Addr addr, int context);
121 
122  // Print cache contents
123  void print(std::ostream& out) const;
124  void printData(std::ostream& out) const;
125 
126  void regStats();
127  bool checkResourceAvailable(CacheResourceType res, Addr addr);
128  void recordRequestType(CacheRequestType requestType, Addr addr);
129 
130  public:
134 
138 
140 
145 
148 
149  int getCacheSize() const { return m_cache_size; }
150  int getCacheAssoc() const { return m_cache_assoc; }
151  int getNumBlocks() const { return m_cache_num_sets * m_cache_assoc; }
152  Addr getAddressAtIdx(int idx) const;
153 
154  private:
155  // convert a Address to its location in the cache
156  int64_t addressToCacheSet(Addr address) const;
157 
158  // Given a cache tag: returns the index of the tag in a set.
159  // returns -1 if the tag is not found.
160  int findTagInSet(int64_t line, Addr tag) const;
161  int findTagInSetIgnorePermissions(int64_t cacheSet, Addr tag) const;
162 
163  // Private copy constructor and assignment operator
164  CacheMemory(const CacheMemory& obj);
165  CacheMemory& operator=(const CacheMemory& obj);
166 
167  private:
168  // Data Members (m_prefix)
170 
171  // The first index is the # of cache lines.
172  // The second index is the the amount associativity.
173  std::unordered_map<Addr, int> m_tag_index;
175 
177 
180 
188 };
189 
190 std::ostream& operator<<(std::ostream& out, const CacheMemory& obj);
191 
192 #endif // __MEM_RUBY_STRUCTURES_CACHEMEMORY_HH__
Stats::Scalar m_demand_misses
Definition: CacheMemory.hh:132
void recordCacheContents(int cntrl, CacheRecorder *tr) const
Definition: CacheMemory.cc:393
BankedArray tagArray
Definition: CacheMemory.hh:179
Stats::Vector m_accessModeType
Definition: CacheMemory.hh:139
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
BankedArray dataArray
Definition: CacheMemory.hh:178
void recordRequestType(CacheRequestType requestType, Addr addr)
Definition: CacheMemory.cc:583
Stats::Formula m_demand_accesses
Definition: CacheMemory.hh:133
int findTagInSet(int64_t line, Addr tag) const
Definition: CacheMemory.cc:112
int m_cache_num_set_bits
Definition: CacheMemory.hh:183
bool cacheAvail(Addr address) const
Definition: CacheMemory.cc:232
bool m_resource_stalls
Definition: CacheMemory.hh:186
bool isBlockNotBusy(int64_t cache_set, int64_t loc)
Definition: CacheMemory.cc:652
bool testCacheAccess(Addr address, RubyRequestType type, DataBlock *&data_ptr)
Definition: CacheMemory.cc:189
ip6_addr_t addr
Definition: inet.hh:335
RubyCacheParams Params
Definition: CacheMemory.hh:53
Stats::Scalar m_hw_prefetches
Definition: CacheMemory.hh:136
void clearLocked(Addr addr)
Definition: CacheMemory.cc:467
A vector of scalar stats.
Definition: statistics.hh:2499
bool isLocked(Addr addr, int context)
Definition: CacheMemory.cc:478
Addr getAddressAtIdx(int idx) const
Definition: CacheMemory.cc:142
void regStats()
Register statistics for this object.
Definition: CacheMemory.cc:490
int getNumBlocks() const
Definition: CacheMemory.hh:151
Stats::Scalar numTagArrayStalls
Definition: CacheMemory.hh:146
Declaration of Statistics objects.
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2475
STL vector class.
Definition: stl.hh:40
void deallocate(Addr address)
Definition: CacheMemory.cc:294
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: CacheMemory.cc:75
int getCacheSize() const
Definition: CacheMemory.hh:149
std::unordered_map< Addr, int > m_tag_index
Definition: CacheMemory.hh:173
void setMRU(Addr address)
Definition: CacheMemory.cc:344
Cycles getTagLatency() const
Definition: CacheMemory.hh:98
std::ostream & operator<<(std::ostream &out, const CacheMemory &obj)
CacheMemory(const Params *p)
Definition: CacheMemory.cc:57
bool isBlockInvalid(int64_t cache_set, int64_t loc)
Definition: CacheMemory.cc:646
Addr cacheProbe(Addr address) const
Definition: CacheMemory.cc:310
bool tryCacheAccess(Addr address, RubyRequestType type, DataBlock *&data_ptr)
Definition: CacheMemory.cc:162
Stats::Scalar m_demand_hits
Definition: CacheMemory.hh:131
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Stats::Scalar numDataArrayWrites
Definition: CacheMemory.hh:142
AbstractReplacementPolicy * m_replacementPolicy_ptr
Definition: CacheMemory.hh:176
AbstractCacheEntry * allocate(Addr address, AbstractCacheEntry *new_entry)
Definition: CacheMemory.hh:79
bool m_is_instruction_only_cache
Definition: CacheMemory.hh:169
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2895
Bitfield< 9 > e
Definition: miscregs.hh:1376
type
Definition: misc.hh:728
CacheMemory & operator=(const CacheMemory &obj)
int m_start_index_bit
Definition: CacheMemory.hh:185
int findTagInSetIgnorePermissions(int64_t cacheSet, Addr tag) const
Definition: CacheMemory.cc:127
AbstractCacheEntry * allocate(Addr address, AbstractCacheEntry *new_entry, bool touch)
Definition: CacheMemory.cc:254
Stats::Scalar m_sw_prefetches
Definition: CacheMemory.hh:135
int getReplacementWeight(int64_t set, int64_t loc)
Definition: CacheMemory.cc:379
void setLocked(Addr addr, int context)
Definition: CacheMemory.cc:456
Stats::Scalar numTagArrayWrites
Definition: CacheMemory.hh:144
Cycles getDataLatency() const
Definition: CacheMemory.hh:99
void print(std::ostream &out) const
Definition: CacheMemory.cc:431
Cycles getLatency() const
Definition: BankedArray.hh:75
Stats::Scalar numDataArrayStalls
Definition: CacheMemory.hh:147
int getCacheAssoc() const
Definition: CacheMemory.hh:150
Stats::Scalar numDataArrayReads
Definition: CacheMemory.hh:141
void printData(std::ostream &out) const
Definition: CacheMemory.cc:450
Stats::Scalar numTagArrayReads
Definition: CacheMemory.hh:143
int64_t addressToCacheSet(Addr address) const
Definition: CacheMemory.cc:102
Stats::Formula m_prefetches
Definition: CacheMemory.hh:137
Bitfield< 0 > p
bool checkResourceAvailable(CacheResourceType res, Addr addr)
Definition: CacheMemory.cc:615
AbstractCacheEntry * lookup(Addr address)
Definition: CacheMemory.cc:322
Abstract superclass for simulation objects.
Definition: sim_object.hh:94
std::vector< std::vector< AbstractCacheEntry * > > m_cache
Definition: CacheMemory.hh:174
bool isTagPresent(Addr address) const
Definition: CacheMemory.cc:213
int m_cache_num_sets
Definition: CacheMemory.hh:182
void allocateVoid(Addr address, AbstractCacheEntry *new_entry)
Definition: CacheMemory.hh:83

Generated on Fri Jun 9 2017 13:03:50 for gem5 by doxygen 1.8.6