DirectoryMemory.cc (11903:a75e4eae89c0) DirectoryMemory.cc (12065:e3e51756dfef)
1/*
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 *
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * Copyright (c) 2017 Google 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 * Authors: Lena Olson
30 */
31
32#include "mem/ruby/structures/DirectoryMemory.hh"
33
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
44#include "mem/ruby/structures/DirectoryMemory.hh"
45
46#include "base/addr_range.hh"
34#include "base/intmath.hh"
35#include "debug/RubyCache.hh"
36#include "debug/RubyStats.hh"
37#include "mem/ruby/slicc_interface/RubySlicc_Util.hh"
38#include "mem/ruby/system/RubySystem.hh"
39#include "sim/system.hh"
40
41using namespace std;
42
47#include "base/intmath.hh"
48#include "debug/RubyCache.hh"
49#include "debug/RubyStats.hh"
50#include "mem/ruby/slicc_interface/RubySlicc_Util.hh"
51#include "mem/ruby/system/RubySystem.hh"
52#include "sim/system.hh"
53
54using namespace std;
55
43int DirectoryMemory::m_num_directories = 0;
44int DirectoryMemory::m_num_directories_bits = 0;
45int DirectoryMemory::m_numa_high_bit = 0;
46
47DirectoryMemory::DirectoryMemory(const Params *p)
56DirectoryMemory::DirectoryMemory(const Params *p)
48 : SimObject(p)
57 : SimObject(p), addrRanges(p->addr_ranges.begin(), p->addr_ranges.end())
49{
58{
50 m_version = p->version;
51 // In X86, there is an IO gap in the 3-4GB range.
52 if (p->system->getArch() == Arch::X86ISA && p->size > 0xc0000000){
53 // We need to add 1GB to the size for the gap
54 m_size_bytes = p->size + 0x40000000;
59 m_size_bytes = 0;
60 for (const auto &r: addrRanges) {
61 m_size_bytes += r.size();
55 }
62 }
56 else {
57 m_size_bytes = p->size;
58 }
59 m_size_bits = floorLog2(m_size_bytes);
60 m_num_entries = 0;
63 m_size_bits = floorLog2(m_size_bytes);
64 m_num_entries = 0;
61 m_numa_high_bit = p->numa_high_bit;
62}
63
64void
65DirectoryMemory::init()
66{
67 m_num_entries = m_size_bytes / RubySystem::getBlockSizeBytes();
68 m_entries = new AbstractEntry*[m_num_entries];
69 for (int i = 0; i < m_num_entries; i++)
70 m_entries[i] = NULL;
65}
66
67void
68DirectoryMemory::init()
69{
70 m_num_entries = m_size_bytes / RubySystem::getBlockSizeBytes();
71 m_entries = new AbstractEntry*[m_num_entries];
72 for (int i = 0; i < m_num_entries; i++)
73 m_entries[i] = NULL;
71
72 m_num_directories++;
73 m_num_directories_bits = ceilLog2(m_num_directories);
74
75 if (m_numa_high_bit == 0) {
76 m_numa_high_bit = RubySystem::getMemorySizeBits() - 1;
77 }
78 assert(m_numa_high_bit != 0);
79}
80
81DirectoryMemory::~DirectoryMemory()
82{
83 // free up all the directory entries
84 for (uint64_t i = 0; i < m_num_entries; i++) {
85 if (m_entries[i] != NULL) {
86 delete m_entries[i];
87 }
88 }
89 delete [] m_entries;
90}
91
74}
75
76DirectoryMemory::~DirectoryMemory()
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
92uint64_t
93DirectoryMemory::mapAddressToDirectoryVersion(Addr address)
94{
95 if (m_num_directories_bits == 0)
96 return 0;
97
98 uint64_t ret = bitSelect(address,
99 m_numa_high_bit - m_num_directories_bits + 1,
100 m_numa_high_bit);
101 return ret;
102}
103
104bool
105DirectoryMemory::isPresent(Addr address)
106{
87bool
88DirectoryMemory::isPresent(Addr address)
89{
107 bool ret = (mapAddressToDirectoryVersion(address) == m_version);
108 return ret;
90 for (const auto& r: addrRanges) {
91 if (r.contains(address)) {
92 return true;
93 }
94 }
95 return false;
109}
110
111uint64_t
112DirectoryMemory::mapAddressToLocalIdx(Addr address)
113{
96}
97
98uint64_t
99DirectoryMemory::mapAddressToLocalIdx(Addr address)
100{
114 uint64_t ret;
115 if (m_num_directories_bits > 0) {
116 ret = bitRemove(address, m_numa_high_bit - m_num_directories_bits + 1,
117 m_numa_high_bit);
118 } else {
119 ret = address;
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();
120 }
108 }
121
122 return ret >> (RubySystem::getBlockSizeBits());
109 return ret >> RubySystem::getBlockSizeBits();
123}
124
125AbstractEntry*
126DirectoryMemory::lookup(Addr address)
127{
128 assert(isPresent(address));
129 DPRINTF(RubyCache, "Looking up address: %#x\n", address);
130
131 uint64_t idx = mapAddressToLocalIdx(address);
132 assert(idx < m_num_entries);
133 return m_entries[idx];
134}
135
136AbstractEntry*
137DirectoryMemory::allocate(Addr address, AbstractEntry *entry)
138{
139 assert(isPresent(address));
140 uint64_t idx;
141 DPRINTF(RubyCache, "Looking up address: %#x\n", address);
142
143 idx = mapAddressToLocalIdx(address);
144 assert(idx < m_num_entries);
145 entry->changePermission(AccessPermission_Read_Only);
146 m_entries[idx] = entry;
147
148 return entry;
149}
150
151void
152DirectoryMemory::print(ostream& out) const
153{
154}
155
156void
157DirectoryMemory::recordRequestType(DirectoryRequestType requestType) {
158 DPRINTF(RubyStats, "Recorded statistic: %s\n",
159 DirectoryRequestType_to_string(requestType));
160}
161
162DirectoryMemory *
163RubyDirectoryMemoryParams::create()
164{
165 return new DirectoryMemory(this);
166}
110}
111
112AbstractEntry*
113DirectoryMemory::lookup(Addr address)
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
123AbstractEntry*
124DirectoryMemory::allocate(Addr address, AbstractEntry *entry)
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
138void
139DirectoryMemory::print(ostream& out) const
140{
141}
142
143void
144DirectoryMemory::recordRequestType(DirectoryRequestType requestType) {
145 DPRINTF(RubyStats, "Recorded statistic: %s\n",
146 DirectoryRequestType_to_string(requestType));
147}
148
149DirectoryMemory *
150RubyDirectoryMemoryParams::create()
151{
152 return new DirectoryMemory(this);
153}