DirectoryMemory.cc revision 10301:44839e8febbd
16019Shines@cs.fsu.edu/* 26019Shines@cs.fsu.edu * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 310037SARM gem5 Developers * All rights reserved. 47100Sgblack@eecs.umich.edu * 57100Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 67100Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are 77100Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright 87100Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 97100Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 107100Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 117100Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution; 127100Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its 137100Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 147100Sgblack@eecs.umich.edu * this software without specific prior written permission. 156019Shines@cs.fsu.edu * 166019Shines@cs.fsu.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176019Shines@cs.fsu.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186019Shines@cs.fsu.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196019Shines@cs.fsu.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206019Shines@cs.fsu.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216019Shines@cs.fsu.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226019Shines@cs.fsu.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236019Shines@cs.fsu.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246019Shines@cs.fsu.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256019Shines@cs.fsu.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266019Shines@cs.fsu.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276019Shines@cs.fsu.edu */ 286019Shines@cs.fsu.edu 296019Shines@cs.fsu.edu#include "base/intmath.hh" 306019Shines@cs.fsu.edu#include "debug/RubyCache.hh" 316019Shines@cs.fsu.edu#include "debug/RubyStats.hh" 326019Shines@cs.fsu.edu#include "mem/ruby/slicc_interface/RubySlicc_Util.hh" 336019Shines@cs.fsu.edu#include "mem/ruby/structures/DirectoryMemory.hh" 346019Shines@cs.fsu.edu#include "mem/ruby/system/System.hh" 356019Shines@cs.fsu.edu 366019Shines@cs.fsu.eduusing namespace std; 376019Shines@cs.fsu.edu 386019Shines@cs.fsu.eduint DirectoryMemory::m_num_directories = 0; 396019Shines@cs.fsu.eduint DirectoryMemory::m_num_directories_bits = 0; 406019Shines@cs.fsu.eduuint64_t DirectoryMemory::m_total_size_bytes = 0; 416019Shines@cs.fsu.eduint DirectoryMemory::m_numa_high_bit = 0; 426757SAli.Saidi@ARM.com 436019Shines@cs.fsu.eduDirectoryMemory::DirectoryMemory(const Params *p) 446019Shines@cs.fsu.edu : SimObject(p) 456019Shines@cs.fsu.edu{ 466019Shines@cs.fsu.edu m_version = p->version; 476019Shines@cs.fsu.edu m_size_bytes = p->size; 4811320Ssteve.reinhardt@amd.com m_size_bits = floorLog2(m_size_bytes); 496019Shines@cs.fsu.edu m_num_entries = 0; 509022Sgblack@eecs.umich.edu m_use_map = p->use_map; 516019Shines@cs.fsu.edu m_map_levels = p->map_levels; 5210037SARM gem5 Developers m_numa_high_bit = p->numa_high_bit; 5310037SARM gem5 Developers} 547170Sgblack@eecs.umich.edu 556253Sgblack@eecs.umich.eduvoid 5610037SARM gem5 DevelopersDirectoryMemory::init() 577202Sgblack@eecs.umich.edu{ 5810037SARM gem5 Developers m_num_entries = m_size_bytes / RubySystem::getBlockSizeBytes(); 596253Sgblack@eecs.umich.edu 6010611SAndreas.Sandberg@ARM.com if (m_use_map) { 616253Sgblack@eecs.umich.edu m_sparseMemory = new SparseMemory(m_map_levels); 627396Sgblack@eecs.umich.edu g_system_ptr->registerSparseMemory(m_sparseMemory); 6310037SARM gem5 Developers } else { 648745Sgblack@eecs.umich.edu m_entries = new AbstractEntry*[m_num_entries]; 657405SAli.Saidi@ARM.com for (int i = 0; i < m_num_entries; i++) 6610461SAndreas.Sandberg@ARM.com m_entries[i] = NULL; 678782Sgblack@eecs.umich.edu m_ram = g_system_ptr->getMemoryVector(); 688782Sgblack@eecs.umich.edu } 698782Sgblack@eecs.umich.edu 7010810Sbr@bsdpad.com m_num_directories++; 7110810Sbr@bsdpad.com m_num_directories_bits = ceilLog2(m_num_directories); 7210810Sbr@bsdpad.com m_total_size_bytes += m_size_bytes; 737259Sgblack@eecs.umich.edu 748757Sgblack@eecs.umich.edu if (m_numa_high_bit == 0) { 7510461SAndreas.Sandberg@ARM.com m_numa_high_bit = RubySystem::getMemorySizeBits() - 1; 768782Sgblack@eecs.umich.edu } 778757Sgblack@eecs.umich.edu assert(m_numa_high_bit != 0); 7812531Sandreas.sandberg@arm.com} 798777Sgblack@eecs.umich.edu 808782Sgblack@eecs.umich.eduDirectoryMemory::~DirectoryMemory() 818756Sgblack@eecs.umich.edu{ 8210037SARM gem5 Developers // free up all the directory entries 8310037SARM gem5 Developers if (m_entries != NULL) { 846019Shines@cs.fsu.edu for (uint64 i = 0; i < m_num_entries; i++) { 8512605Sgiacomo.travaglini@arm.com if (m_entries[i] != NULL) { 866757SAli.Saidi@ARM.com delete m_entries[i]; 878757Sgblack@eecs.umich.edu } 886019Shines@cs.fsu.edu } 898745Sgblack@eecs.umich.edu delete [] m_entries; 909384SAndreas.Sandberg@arm.com } else if (m_use_map) { 916397Sgblack@eecs.umich.edu delete m_sparseMemory; 9212531Sandreas.sandberg@arm.com } 938782Sgblack@eecs.umich.edu} 946019Shines@cs.fsu.edu 9510461SAndreas.Sandberg@ARM.comuint64 966397Sgblack@eecs.umich.eduDirectoryMemory::mapAddressToDirectoryVersion(PhysAddress address) 978335Snate@binkert.org{ 9812531Sandreas.sandberg@arm.com if (m_num_directories_bits == 0) 999023Sgblack@eecs.umich.edu return 0; 1009023Sgblack@eecs.umich.edu 10110461SAndreas.Sandberg@ARM.com uint64 ret = address.bitSelect(m_numa_high_bit - m_num_directories_bits + 1, 1028335Snate@binkert.org m_numa_high_bit); 1036019Shines@cs.fsu.edu return ret; 10410196SCurtis.Dunham@arm.com} 10512222Sgabeblack@google.com 106bool 107DirectoryMemory::isPresent(PhysAddress address) 108{ 109 bool ret = (mapAddressToDirectoryVersion(address) == m_version); 110 return ret; 111} 112 113uint64 114DirectoryMemory::mapAddressToLocalIdx(PhysAddress address) 115{ 116 uint64 ret; 117 if (m_num_directories_bits > 0) { 118 ret = address.bitRemove(m_numa_high_bit - m_num_directories_bits + 1, 119 m_numa_high_bit); 120 } else { 121 ret = address.getAddress(); 122 } 123 124 return ret >> (RubySystem::getBlockSizeBits()); 125} 126 127AbstractEntry* 128DirectoryMemory::lookup(PhysAddress address) 129{ 130 assert(isPresent(address)); 131 DPRINTF(RubyCache, "Looking up address: %s\n", address); 132 133 if (m_use_map) { 134 return m_sparseMemory->lookup(address); 135 } else { 136 uint64_t idx = mapAddressToLocalIdx(address); 137 assert(idx < m_num_entries); 138 return m_entries[idx]; 139 } 140} 141 142AbstractEntry* 143DirectoryMemory::allocate(const PhysAddress& address, AbstractEntry* entry) 144{ 145 assert(isPresent(address)); 146 uint64 idx; 147 DPRINTF(RubyCache, "Looking up address: %s\n", address); 148 149 if (m_use_map) { 150 m_sparseMemory->add(address, entry); 151 entry->changePermission(AccessPermission_Read_Write); 152 } else { 153 idx = mapAddressToLocalIdx(address); 154 assert(idx < m_num_entries); 155 entry->getDataBlk().assign(m_ram->getBlockPtr(address)); 156 entry->changePermission(AccessPermission_Read_Only); 157 m_entries[idx] = entry; 158 } 159 160 return entry; 161} 162 163void 164DirectoryMemory::invalidateBlock(PhysAddress address) 165{ 166 if (m_use_map) { 167 assert(m_sparseMemory->exist(address)); 168 m_sparseMemory->remove(address); 169 } 170#if 0 171 else { 172 assert(isPresent(address)); 173 174 Index index = address.memoryModuleIndex(); 175 176 if (index < 0 || index > m_size) { 177 ERROR_MSG("Directory Memory Assertion: " 178 "accessing memory out of range."); 179 } 180 181 if (m_entries[index] != NULL){ 182 delete m_entries[index]; 183 m_entries[index] = NULL; 184 } 185 } 186#endif 187} 188 189void 190DirectoryMemory::print(ostream& out) const 191{ 192} 193 194void 195DirectoryMemory::regStats() 196{ 197 if (m_use_map) { 198 m_sparseMemory->regStats(name()); 199 } 200} 201 202void 203DirectoryMemory::recordRequestType(DirectoryRequestType requestType) { 204 DPRINTF(RubyStats, "Recorded statistic: %s\n", 205 DirectoryRequestType_to_string(requestType)); 206} 207 208DirectoryMemory * 209RubyDirectoryMemoryParams::create() 210{ 211 return new DirectoryMemory(this); 212} 213