DirectoryMemory.cc revision 6154
1 2/* 3 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 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 30/* 31 * DirectoryMemory.C 32 * 33 * Description: See DirectoryMemory.h 34 * 35 * $Id$ 36 * 37 */ 38 39#include "mem/ruby/system/System.hh" 40#include "mem/ruby/common/Driver.hh" 41#include "mem/ruby/system/DirectoryMemory.hh" 42#include "mem/ruby/slicc_interface/RubySlicc_Util.hh" 43#include "mem/ruby/config/RubyConfig.hh" 44#include "mem/protocol/Chip.hh" 45 46DirectoryMemory::DirectoryMemory(Chip* chip_ptr, int version) 47{ 48 m_chip_ptr = chip_ptr; 49 m_version = version; 50 // THIS DOESN'T SEEM TO WORK -- MRM 51 // m_size = RubyConfig::memoryModuleBlocks()/RubyConfig::numberOfDirectory(); 52 m_size = RubyConfig::memoryModuleBlocks(); 53 assert(m_size > 0); 54 // allocates an array of directory entry pointers & sets them to NULL 55 m_entries = new Directory_Entry*[m_size]; 56 if (m_entries == NULL) { 57 ERROR_MSG("Directory Memory: unable to allocate memory."); 58 } 59 60 for (int i=0; i < m_size; i++) { 61 m_entries[i] = NULL; 62 } 63} 64 65DirectoryMemory::~DirectoryMemory() 66{ 67 // free up all the directory entries 68 for (int i=0; i < m_size; i++) { 69 if (m_entries[i] != NULL) { 70 delete m_entries[i]; 71 m_entries[i] = NULL; 72 } 73 } 74 75 // free up the array of directory entries 76 delete[] m_entries; 77} 78 79// Static method 80void DirectoryMemory::printConfig(ostream& out) 81{ 82 out << "Memory config:" << endl; 83 out << " memory_bits: " << RubyConfig::memorySizeBits() << endl; 84 out << " memory_size_bytes: " << RubyConfig::memorySizeBytes() << endl; 85 out << " memory_size_Kbytes: " << double(RubyConfig::memorySizeBytes()) / (1<<10) << endl; 86 out << " memory_size_Mbytes: " << double(RubyConfig::memorySizeBytes()) / (1<<20) << endl; 87 out << " memory_size_Gbytes: " << double(RubyConfig::memorySizeBytes()) / (1<<30) << endl; 88 89 out << " module_bits: " << RubyConfig::memoryModuleBits() << endl; 90 out << " module_size_lines: " << RubyConfig::memoryModuleBlocks() << endl; 91 out << " module_size_bytes: " << RubyConfig::memoryModuleBlocks() * RubyConfig::dataBlockBytes() << endl; 92 out << " module_size_Kbytes: " << double(RubyConfig::memoryModuleBlocks() * RubyConfig::dataBlockBytes()) / (1<<10) << endl; 93 out << " module_size_Mbytes: " << double(RubyConfig::memoryModuleBlocks() * RubyConfig::dataBlockBytes()) / (1<<20) << endl; 94} 95 96// Public method 97bool DirectoryMemory::isPresent(PhysAddress address) 98{ 99 return (map_Address_to_DirectoryNode(address) == m_chip_ptr->getID()*RubyConfig::numberOfDirectoryPerChip()+m_version); 100} 101 102Directory_Entry& DirectoryMemory::lookup(PhysAddress address) 103{ 104 assert(isPresent(address)); 105 Index index = address.memoryModuleIndex(); 106 107 if (index < 0 || index > m_size) { 108 WARN_EXPR(m_chip_ptr->getID()); 109 WARN_EXPR(address.getAddress()); 110 WARN_EXPR(index); 111 WARN_EXPR(m_size); 112 ERROR_MSG("Directory Memory Assertion: accessing memory out of range."); 113 } 114 Directory_Entry* entry = m_entries[index]; 115 116 // allocate the directory entry on demand. 117 if (entry == NULL) { 118 entry = new Directory_Entry; 119 120 // entry->getProcOwner() = m_chip_ptr->getID(); // FIXME - This should not be hard coded 121 // entry->getDirOwner() = true; // FIXME - This should not be hard-coded 122 123 // load the data from SimICS when first initalizing 124 if (g_SIMULATING) { 125 if (DATA_BLOCK) { 126 //physical_address_t physAddr = address.getAddress(); 127 128 for(int j=0; j < RubyConfig::dataBlockBytes(); j++) { 129 //int8 data_byte = (int8) SIMICS_read_physical_memory( m_chip_ptr->getID(), 130 // physAddr + j, 1 ); 131 //printf("SimICS, byte %d: %lld\n", j, data_byte ); 132 int8 data_byte = 0; 133 entry->getDataBlk().setByte(j, data_byte); 134 } 135 DEBUG_EXPR(NODE_COMP, MedPrio,entry->getDataBlk()); 136 } 137 } 138 139 // store entry to the table 140 m_entries[index] = entry; 141 } 142 143 return (*entry); 144} 145 146/* 147void DirectoryMemory::invalidateBlock(PhysAddress address) 148{ 149 assert(isPresent(address)); 150 151 Index index = address.memoryModuleIndex(); 152 153 if (index < 0 || index > m_size) { 154 ERROR_MSG("Directory Memory Assertion: accessing memory out of range."); 155 } 156 157 if(m_entries[index] != NULL){ 158 delete m_entries[index]; 159 m_entries[index] = NULL; 160 } 161 162} 163*/ 164 165void DirectoryMemory::print(ostream& out) const 166{ 167 out << "Directory dump: " << endl; 168 for (int i=0; i < m_size; i++) { 169 if (m_entries[i] != NULL) { 170 out << i << ": "; 171 out << *m_entries[i] << endl; 172 } 173 } 174} 175 176