Deleted Added
sdiff udiff text old ( 11903:a75e4eae89c0 ) new ( 12065:e3e51756dfef )
full compact
1/*
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;

--- 16 unchanged lines hidden (view full) ---

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
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
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)
48 : SimObject(p)
49{
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;
55 }
56 else {
57 m_size_bytes = p->size;
58 }
59 m_size_bits = floorLog2(m_size_bytes);
60 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;
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
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{
107 bool ret = (mapAddressToDirectoryVersion(address) == m_version);
108 return ret;
109}
110
111uint64_t
112DirectoryMemory::mapAddressToLocalIdx(Addr address)
113{
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;
120 }
121
122 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

--- 36 unchanged lines hidden ---