DirectoryMemory.cc (11118:75c1e564a725) DirectoryMemory.cc (11793:ef606668d247)
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include "mem/ruby/structures/DirectoryMemory.hh"
30
29#include "base/intmath.hh"
30#include "debug/RubyCache.hh"
31#include "debug/RubyStats.hh"
32#include "mem/ruby/slicc_interface/RubySlicc_Util.hh"
31#include "base/intmath.hh"
32#include "debug/RubyCache.hh"
33#include "debug/RubyStats.hh"
34#include "mem/ruby/slicc_interface/RubySlicc_Util.hh"
33#include "mem/ruby/structures/DirectoryMemory.hh"
34#include "mem/ruby/system/RubySystem.hh"
35
36using namespace std;
37
38int DirectoryMemory::m_num_directories = 0;
39int DirectoryMemory::m_num_directories_bits = 0;
40int DirectoryMemory::m_numa_high_bit = 0;
41
42DirectoryMemory::DirectoryMemory(const Params *p)
43 : SimObject(p)
44{
45 m_version = p->version;
46 m_size_bytes = p->size;
47 m_size_bits = floorLog2(m_size_bytes);
48 m_num_entries = 0;
49 m_numa_high_bit = p->numa_high_bit;
50}
51
52void
53DirectoryMemory::init()
54{
55 m_num_entries = m_size_bytes / RubySystem::getBlockSizeBytes();
56 m_entries = new AbstractEntry*[m_num_entries];
57 for (int i = 0; i < m_num_entries; i++)
58 m_entries[i] = NULL;
59
60 m_num_directories++;
61 m_num_directories_bits = ceilLog2(m_num_directories);
62
63 if (m_numa_high_bit == 0) {
64 m_numa_high_bit = RubySystem::getMemorySizeBits() - 1;
65 }
66 assert(m_numa_high_bit != 0);
67}
68
69DirectoryMemory::~DirectoryMemory()
70{
71 // free up all the directory entries
72 for (uint64_t i = 0; i < m_num_entries; i++) {
73 if (m_entries[i] != NULL) {
74 delete m_entries[i];
75 }
76 }
77 delete [] m_entries;
78}
79
80uint64_t
81DirectoryMemory::mapAddressToDirectoryVersion(Addr address)
82{
83 if (m_num_directories_bits == 0)
84 return 0;
85
86 uint64_t ret = bitSelect(address,
87 m_numa_high_bit - m_num_directories_bits + 1,
88 m_numa_high_bit);
89 return ret;
90}
91
92bool
93DirectoryMemory::isPresent(Addr address)
94{
95 bool ret = (mapAddressToDirectoryVersion(address) == m_version);
96 return ret;
97}
98
99uint64_t
100DirectoryMemory::mapAddressToLocalIdx(Addr address)
101{
102 uint64_t ret;
103 if (m_num_directories_bits > 0) {
104 ret = bitRemove(address, m_numa_high_bit - m_num_directories_bits + 1,
105 m_numa_high_bit);
106 } else {
107 ret = address;
108 }
109
110 return ret >> (RubySystem::getBlockSizeBits());
111}
112
113AbstractEntry*
114DirectoryMemory::lookup(Addr address)
115{
116 assert(isPresent(address));
117 DPRINTF(RubyCache, "Looking up address: %#x\n", address);
118
119 uint64_t idx = mapAddressToLocalIdx(address);
120 assert(idx < m_num_entries);
121 return m_entries[idx];
122}
123
124AbstractEntry*
125DirectoryMemory::allocate(Addr address, AbstractEntry *entry)
126{
127 assert(isPresent(address));
128 uint64_t idx;
129 DPRINTF(RubyCache, "Looking up address: %#x\n", address);
130
131 idx = mapAddressToLocalIdx(address);
132 assert(idx < m_num_entries);
133 entry->changePermission(AccessPermission_Read_Only);
134 m_entries[idx] = entry;
135
136 return entry;
137}
138
139void
140DirectoryMemory::print(ostream& out) const
141{
142}
143
144void
145DirectoryMemory::recordRequestType(DirectoryRequestType requestType) {
146 DPRINTF(RubyStats, "Recorded statistic: %s\n",
147 DirectoryRequestType_to_string(requestType));
148}
149
150DirectoryMemory *
151RubyDirectoryMemoryParams::create()
152{
153 return new DirectoryMemory(this);
154}
35#include "mem/ruby/system/RubySystem.hh"
36
37using namespace std;
38
39int DirectoryMemory::m_num_directories = 0;
40int DirectoryMemory::m_num_directories_bits = 0;
41int DirectoryMemory::m_numa_high_bit = 0;
42
43DirectoryMemory::DirectoryMemory(const Params *p)
44 : SimObject(p)
45{
46 m_version = p->version;
47 m_size_bytes = p->size;
48 m_size_bits = floorLog2(m_size_bytes);
49 m_num_entries = 0;
50 m_numa_high_bit = p->numa_high_bit;
51}
52
53void
54DirectoryMemory::init()
55{
56 m_num_entries = m_size_bytes / RubySystem::getBlockSizeBytes();
57 m_entries = new AbstractEntry*[m_num_entries];
58 for (int i = 0; i < m_num_entries; i++)
59 m_entries[i] = NULL;
60
61 m_num_directories++;
62 m_num_directories_bits = ceilLog2(m_num_directories);
63
64 if (m_numa_high_bit == 0) {
65 m_numa_high_bit = RubySystem::getMemorySizeBits() - 1;
66 }
67 assert(m_numa_high_bit != 0);
68}
69
70DirectoryMemory::~DirectoryMemory()
71{
72 // free up all the directory entries
73 for (uint64_t i = 0; i < m_num_entries; i++) {
74 if (m_entries[i] != NULL) {
75 delete m_entries[i];
76 }
77 }
78 delete [] m_entries;
79}
80
81uint64_t
82DirectoryMemory::mapAddressToDirectoryVersion(Addr address)
83{
84 if (m_num_directories_bits == 0)
85 return 0;
86
87 uint64_t ret = bitSelect(address,
88 m_numa_high_bit - m_num_directories_bits + 1,
89 m_numa_high_bit);
90 return ret;
91}
92
93bool
94DirectoryMemory::isPresent(Addr address)
95{
96 bool ret = (mapAddressToDirectoryVersion(address) == m_version);
97 return ret;
98}
99
100uint64_t
101DirectoryMemory::mapAddressToLocalIdx(Addr address)
102{
103 uint64_t ret;
104 if (m_num_directories_bits > 0) {
105 ret = bitRemove(address, m_numa_high_bit - m_num_directories_bits + 1,
106 m_numa_high_bit);
107 } else {
108 ret = address;
109 }
110
111 return ret >> (RubySystem::getBlockSizeBits());
112}
113
114AbstractEntry*
115DirectoryMemory::lookup(Addr address)
116{
117 assert(isPresent(address));
118 DPRINTF(RubyCache, "Looking up address: %#x\n", address);
119
120 uint64_t idx = mapAddressToLocalIdx(address);
121 assert(idx < m_num_entries);
122 return m_entries[idx];
123}
124
125AbstractEntry*
126DirectoryMemory::allocate(Addr address, AbstractEntry *entry)
127{
128 assert(isPresent(address));
129 uint64_t idx;
130 DPRINTF(RubyCache, "Looking up address: %#x\n", address);
131
132 idx = mapAddressToLocalIdx(address);
133 assert(idx < m_num_entries);
134 entry->changePermission(AccessPermission_Read_Only);
135 m_entries[idx] = entry;
136
137 return entry;
138}
139
140void
141DirectoryMemory::print(ostream& out) const
142{
143}
144
145void
146DirectoryMemory::recordRequestType(DirectoryRequestType requestType) {
147 DPRINTF(RubyStats, "Recorded statistic: %s\n",
148 DirectoryRequestType_to_string(requestType));
149}
150
151DirectoryMemory *
152RubyDirectoryMemoryParams::create()
153{
154 return new DirectoryMemory(this);
155}