gem5  v19.0.0.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 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  * Authors: Lena Olson
42  */
43 
45 
46 #include "base/addr_range.hh"
47 #include "base/intmath.hh"
48 #include "debug/RubyCache.hh"
49 #include "debug/RubyStats.hh"
52 #include "sim/system.hh"
53 
54 using namespace std;
55 
57  : SimObject(p), addrRanges(p->addr_ranges.begin(), p->addr_ranges.end())
58 {
59  m_size_bytes = 0;
60  for (const auto &r: addrRanges) {
61  m_size_bytes += r.size();
62  }
64  m_num_entries = 0;
65 }
66 
67 void
69 {
72  for (int i = 0; i < m_num_entries; i++)
73  m_entries[i] = NULL;
74 }
75 
77 {
78  // free up all the directory entries
79  for (uint64_t i = 0; i < m_num_entries; i++) {
80  if (m_entries[i] != NULL) {
81  delete m_entries[i];
82  }
83  }
84  delete [] m_entries;
85 }
86 
87 bool
89 {
90  for (const auto& r: addrRanges) {
91  if (r.contains(address)) {
92  return true;
93  }
94  }
95  return false;
96 }
97 
98 uint64_t
100 {
101  uint64_t ret = 0;
102  for (const auto& r: addrRanges) {
103  if (r.contains(address)) {
104  ret += r.getOffset(address);
105  break;
106  }
107  ret += r.size();
108  }
109  return ret >> RubySystem::getBlockSizeBits();
110 }
111 
114 {
115  assert(isPresent(address));
116  DPRINTF(RubyCache, "Looking up address: %#x\n", address);
117 
118  uint64_t idx = mapAddressToLocalIdx(address);
119  assert(idx < m_num_entries);
120  return m_entries[idx];
121 }
122 
125 {
126  assert(isPresent(address));
127  uint64_t idx;
128  DPRINTF(RubyCache, "Looking up address: %#x\n", address);
129 
130  idx = mapAddressToLocalIdx(address);
131  assert(idx < m_num_entries);
132  entry->changePermission(AccessPermission_Read_Only);
133  m_entries[idx] = entry;
134 
135  return entry;
136 }
137 
138 void
139 DirectoryMemory::print(ostream& out) const
140 {
141 }
142 
143 void
144 DirectoryMemory::recordRequestType(DirectoryRequestType requestType) {
145  DPRINTF(RubyStats, "Recorded statistic: %s\n",
146  DirectoryRequestType_to_string(requestType));
147 }
148 
150 RubyDirectoryMemoryParams::create()
151 {
152  return new DirectoryMemory(this);
153 }
#define DPRINTF(x,...)
Definition: trace.hh:229
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Bitfield< 7 > i
RubyDirectoryMemoryParams Params
void print(std::ostream &out) const
void changePermission(AccessPermission new_perm)
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:586
void recordRequestType(DirectoryRequestType requestType)
uint64_t mapAddressToLocalIdx(Addr address)
Return the index in the directory based on an address.
bool isPresent(Addr address)
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
uint64_t m_num_entries
int floorLog2(unsigned x)
Definition: intmath.hh:61
AbstractCacheEntry ** m_entries
DirectoryMemory(const Params *p)
AbstractCacheEntry * allocate(Addr address, AbstractCacheEntry *new_entry)
const AddrRangeList addrRanges
The address range for which the directory responds.
Bitfield< 0 > p
AbstractCacheEntry * lookup(Addr address)
static uint32_t getBlockSizeBits()
Definition: RubySystem.hh:60
static uint32_t getBlockSizeBytes()
Definition: RubySystem.hh:59
Abstract superclass for simulation objects.
Definition: sim_object.hh:96

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