gem5  v21.0.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DirectoryMemory.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017,2019 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-2008 Mark D. Hill and David A. Wood
15  * Copyright (c) 2017 Google 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 
43 
44 #include "base/addr_range.hh"
45 #include "base/intmath.hh"
46 #include "debug/RubyCache.hh"
47 #include "debug/RubyStats.hh"
50 #include "sim/system.hh"
51 
53  : SimObject(p), addrRanges(p.addr_ranges.begin(), p.addr_ranges.end())
54 {
55  m_size_bytes = 0;
56  for (const auto &r: addrRanges) {
57  m_size_bytes += r.size();
58  }
60  m_num_entries = 0;
61 }
62 
63 void
65 {
68  for (int i = 0; i < m_num_entries; i++)
69  m_entries[i] = NULL;
70 }
71 
73 {
74  // free up all the directory entries
75  for (uint64_t i = 0; i < m_num_entries; i++) {
76  if (m_entries[i] != NULL) {
77  delete m_entries[i];
78  }
79  }
80  delete [] m_entries;
81 }
82 
83 bool
85 {
86  for (const auto& r: addrRanges) {
87  if (r.contains(address)) {
88  return true;
89  }
90  }
91  return false;
92 }
93 
94 uint64_t
96 {
97  uint64_t ret = 0;
98  for (const auto& r: addrRanges) {
99  if (r.contains(address)) {
100  ret += r.getOffset(address);
101  break;
102  }
103  ret += r.size();
104  }
105  return ret >> RubySystem::getBlockSizeBits();
106 }
107 
110 {
111  assert(isPresent(address));
112  DPRINTF(RubyCache, "Looking up address: %#x\n", address);
113 
114  uint64_t idx = mapAddressToLocalIdx(address);
115  assert(idx < m_num_entries);
116  return m_entries[idx];
117 }
118 
121 {
122  assert(isPresent(address));
123  uint64_t idx;
124  DPRINTF(RubyCache, "Looking up address: %#x\n", address);
125 
126  idx = mapAddressToLocalIdx(address);
127  assert(idx < m_num_entries);
128  assert(m_entries[idx] == NULL);
129  entry->changePermission(AccessPermission_Read_Only);
130  m_entries[idx] = entry;
131 
132  return entry;
133 }
134 
135 void
137 {
138  assert(isPresent(address));
139  uint64_t idx;
140  DPRINTF(RubyCache, "Removing entry for address: %#x\n", address);
141 
142  idx = mapAddressToLocalIdx(address);
143  assert(idx < m_num_entries);
144  assert(m_entries[idx] != NULL);
145  delete m_entries[idx];
146  m_entries[idx] = NULL;
147 }
148 
149 void
150 DirectoryMemory::print(std::ostream& out) const
151 {
152 }
153 
154 void
155 DirectoryMemory::recordRequestType(DirectoryRequestType requestType) {
156  DPRINTF(RubyStats, "Recorded statistic: %s\n",
157  DirectoryRequestType_to_string(requestType));
158 }
AbstractCacheEntry
Definition: AbstractCacheEntry.hh:57
DirectoryMemory::addrRanges
const AddrRangeList addrRanges
The address range for which the directory responds.
Definition: DirectoryMemory.hh:106
system.hh
RubySystem::getBlockSizeBytes
static uint32_t getBlockSizeBytes()
Definition: RubySystem.hh:61
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
DirectoryMemory::deallocate
void deallocate(Addr address)
Definition: DirectoryMemory.cc:136
DirectoryMemory.hh
DirectoryMemory::mapAddressToLocalIdx
uint64_t mapAddressToLocalIdx(Addr address)
Return the index in the directory based on an address.
Definition: DirectoryMemory.cc:95
DirectoryMemory::recordRequestType
void recordRequestType(DirectoryRequestType requestType)
Definition: DirectoryMemory.cc:155
DirectoryMemory::lookup
AbstractCacheEntry * lookup(Addr address)
Definition: DirectoryMemory.cc:109
DirectoryMemory::allocate
AbstractCacheEntry * allocate(Addr address, AbstractCacheEntry *new_entry)
Definition: DirectoryMemory.cc:120
DirectoryMemory::~DirectoryMemory
~DirectoryMemory()
Definition: DirectoryMemory.cc:72
DirectoryMemory::init
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: DirectoryMemory.cc:64
DirectoryMemory::m_size_bits
uint64_t m_size_bits
Definition: DirectoryMemory.hh:99
DirectoryMemory::m_num_entries
uint64_t m_num_entries
Definition: DirectoryMemory.hh:100
DirectoryMemory::print
void print(std::ostream &out) const
Definition: DirectoryMemory.cc:150
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:237
MipsISA::r
r
Definition: pra_constants.hh:95
RubySlicc_Util.hh
AbstractCacheEntry::changePermission
void changePermission(AccessPermission new_perm)
Definition: AbstractCacheEntry.cc:68
DirectoryMemory::DirectoryMemory
DirectoryMemory(const Params &p)
Definition: DirectoryMemory.cc:52
RubySystem.hh
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:148
DirectoryMemory::Params
RubyDirectoryMemoryParams Params
Definition: DirectoryMemory.hh:57
DirectoryMemory::m_entries
AbstractCacheEntry ** m_entries
Definition: DirectoryMemory.hh:95
addr_range.hh
floorLog2
std::enable_if_t< std::is_integral< T >::value, int > floorLog2(T x)
Definition: intmath.hh:63
DirectoryMemory::isPresent
bool isPresent(Addr address)
Definition: DirectoryMemory.cc:84
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
intmath.hh
RubySystem::getBlockSizeBits
static uint32_t getBlockSizeBits()
Definition: RubySystem.hh:62
DirectoryMemory::m_size_bytes
uint64_t m_size_bytes
Definition: DirectoryMemory.hh:98
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:141

Generated on Tue Jun 22 2021 15:28:30 for gem5 by doxygen 1.8.17