DirectoryMemory.cc revision 11025:4872dbdea907
112855Sgabeblack@google.com/* 212855Sgabeblack@google.com * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 312855Sgabeblack@google.com * All rights reserved. 412855Sgabeblack@google.com * 512855Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 612855Sgabeblack@google.com * modification, are permitted provided that the following conditions are 712855Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 812855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 912855Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1012855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1112855Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1212855Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1312855Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1412855Sgabeblack@google.com * this software without specific prior written permission. 1512855Sgabeblack@google.com * 1612855Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712855Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812855Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912855Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012855Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112855Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212855Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312855Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412855Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512855Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612855Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712855Sgabeblack@google.com */ 2812855Sgabeblack@google.com 2912855Sgabeblack@google.com#include "base/intmath.hh" 3012855Sgabeblack@google.com#include "debug/RubyCache.hh" 3112855Sgabeblack@google.com#include "debug/RubyStats.hh" 3212855Sgabeblack@google.com#include "mem/ruby/slicc_interface/RubySlicc_Util.hh" 3312855Sgabeblack@google.com#include "mem/ruby/structures/DirectoryMemory.hh" 3412855Sgabeblack@google.com#include "mem/ruby/system/System.hh" 3512855Sgabeblack@google.com 3612855Sgabeblack@google.comusing namespace std; 3712855Sgabeblack@google.com 3812855Sgabeblack@google.comint DirectoryMemory::m_num_directories = 0; 3912855Sgabeblack@google.comint DirectoryMemory::m_num_directories_bits = 0; 4012855Sgabeblack@google.comuint64_t DirectoryMemory::m_total_size_bytes = 0; 4112855Sgabeblack@google.comint DirectoryMemory::m_numa_high_bit = 0; 4212855Sgabeblack@google.com 4312855Sgabeblack@google.comDirectoryMemory::DirectoryMemory(const Params *p) 4412855Sgabeblack@google.com : SimObject(p) 4512855Sgabeblack@google.com{ 4612855Sgabeblack@google.com m_version = p->version; 4712855Sgabeblack@google.com m_size_bytes = p->size; 4812855Sgabeblack@google.com m_size_bits = floorLog2(m_size_bytes); 4912855Sgabeblack@google.com m_num_entries = 0; 5012855Sgabeblack@google.com m_numa_high_bit = p->numa_high_bit; 5112855Sgabeblack@google.com} 5212855Sgabeblack@google.com 5312855Sgabeblack@google.comvoid 5412855Sgabeblack@google.comDirectoryMemory::init() 5512855Sgabeblack@google.com{ 5612855Sgabeblack@google.com m_num_entries = m_size_bytes / RubySystem::getBlockSizeBytes(); 5712855Sgabeblack@google.com m_entries = new AbstractEntry*[m_num_entries]; 5812855Sgabeblack@google.com for (int i = 0; i < m_num_entries; i++) 5912855Sgabeblack@google.com m_entries[i] = NULL; 6012855Sgabeblack@google.com 6112855Sgabeblack@google.com m_num_directories++; 6212855Sgabeblack@google.com m_num_directories_bits = ceilLog2(m_num_directories); 6312855Sgabeblack@google.com m_total_size_bytes += m_size_bytes; 6412855Sgabeblack@google.com 6512855Sgabeblack@google.com if (m_numa_high_bit == 0) { 6612855Sgabeblack@google.com m_numa_high_bit = RubySystem::getMemorySizeBits() - 1; 6712855Sgabeblack@google.com } 6812855Sgabeblack@google.com assert(m_numa_high_bit != 0); 6912855Sgabeblack@google.com} 7012855Sgabeblack@google.com 7112855Sgabeblack@google.comDirectoryMemory::~DirectoryMemory() 7212855Sgabeblack@google.com{ 7312855Sgabeblack@google.com // free up all the directory entries 7412855Sgabeblack@google.com for (uint64_t i = 0; i < m_num_entries; i++) { 7512855Sgabeblack@google.com if (m_entries[i] != NULL) { 7612855Sgabeblack@google.com delete m_entries[i]; 7712855Sgabeblack@google.com } 7812855Sgabeblack@google.com } 7912855Sgabeblack@google.com delete [] m_entries; 8012855Sgabeblack@google.com} 8112855Sgabeblack@google.com 8212855Sgabeblack@google.comuint64_t 8312855Sgabeblack@google.comDirectoryMemory::mapAddressToDirectoryVersion(Addr address) 8412855Sgabeblack@google.com{ 8512855Sgabeblack@google.com if (m_num_directories_bits == 0) 8612855Sgabeblack@google.com return 0; 8712855Sgabeblack@google.com 8812855Sgabeblack@google.com uint64_t ret = bitSelect(address, 8912855Sgabeblack@google.com m_numa_high_bit - m_num_directories_bits + 1, 9012855Sgabeblack@google.com m_numa_high_bit); 9112855Sgabeblack@google.com return ret; 9212855Sgabeblack@google.com} 9312855Sgabeblack@google.com 9412855Sgabeblack@google.combool 9512855Sgabeblack@google.comDirectoryMemory::isPresent(Addr address) 9612855Sgabeblack@google.com{ 9712855Sgabeblack@google.com bool ret = (mapAddressToDirectoryVersion(address) == m_version); 9812855Sgabeblack@google.com return ret; 9912855Sgabeblack@google.com} 10012855Sgabeblack@google.com 10112855Sgabeblack@google.comuint64_t 10212855Sgabeblack@google.comDirectoryMemory::mapAddressToLocalIdx(Addr address) 10312855Sgabeblack@google.com{ 10412855Sgabeblack@google.com uint64_t ret; 10512855Sgabeblack@google.com if (m_num_directories_bits > 0) { 10612855Sgabeblack@google.com ret = bitRemove(address, m_numa_high_bit - m_num_directories_bits + 1, 10712855Sgabeblack@google.com m_numa_high_bit); 10812855Sgabeblack@google.com } else { 10912855Sgabeblack@google.com ret = address; 11012855Sgabeblack@google.com } 11112855Sgabeblack@google.com 11212855Sgabeblack@google.com return ret >> (RubySystem::getBlockSizeBits()); 11312855Sgabeblack@google.com} 11412855Sgabeblack@google.com 11512855Sgabeblack@google.comAbstractEntry* 11612855Sgabeblack@google.comDirectoryMemory::lookup(Addr address) 11712855Sgabeblack@google.com{ 11812855Sgabeblack@google.com assert(isPresent(address)); 119 DPRINTF(RubyCache, "Looking up address: %s\n", address); 120 121 uint64_t idx = mapAddressToLocalIdx(address); 122 assert(idx < m_num_entries); 123 return m_entries[idx]; 124} 125 126AbstractEntry* 127DirectoryMemory::allocate(Addr address, AbstractEntry *entry) 128{ 129 assert(isPresent(address)); 130 uint64_t idx; 131 DPRINTF(RubyCache, "Looking up address: %s\n", address); 132 133 idx = mapAddressToLocalIdx(address); 134 assert(idx < m_num_entries); 135 entry->changePermission(AccessPermission_Read_Only); 136 m_entries[idx] = entry; 137 138 return entry; 139} 140 141void 142DirectoryMemory::print(ostream& out) const 143{ 144} 145 146void 147DirectoryMemory::recordRequestType(DirectoryRequestType requestType) { 148 DPRINTF(RubyStats, "Recorded statistic: %s\n", 149 DirectoryRequestType_to_string(requestType)); 150} 151 152DirectoryMemory * 153RubyDirectoryMemoryParams::create() 154{ 155 return new DirectoryMemory(this); 156} 157