RubySystem.cc revision 6880
113511Sgabeblack@google.com 213511Sgabeblack@google.com/* 313511Sgabeblack@google.com * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 413511Sgabeblack@google.com * All rights reserved. 513511Sgabeblack@google.com * 613511Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 713511Sgabeblack@google.com * modification, are permitted provided that the following conditions are 813511Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 913511Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 1013511Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1113511Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1213511Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1313511Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1413511Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1513511Sgabeblack@google.com * this software without specific prior written permission. 1613511Sgabeblack@google.com * 1713511Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1813511Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1913511Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2013511Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2113511Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2213511Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2313511Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2413513Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2513513Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2613511Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2713513Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2813586Sgabeblack@google.com */ 2913586Sgabeblack@google.com 3013586Sgabeblack@google.com/* 3113586Sgabeblack@google.com * RubySystem.cc 3213586Sgabeblack@google.com * 3313511Sgabeblack@google.com * Description: See System.hh 3413513Sgabeblack@google.com * 3513513Sgabeblack@google.com * $Id$ 3613511Sgabeblack@google.com * 3713511Sgabeblack@google.com */ 3813511Sgabeblack@google.com 3913511Sgabeblack@google.com 4013513Sgabeblack@google.com#include "mem/ruby/system/System.hh" 4113513Sgabeblack@google.com#include "mem/ruby/common/Address.hh" 4213513Sgabeblack@google.com#include "mem/ruby/profiler/Profiler.hh" 4313511Sgabeblack@google.com#include "mem/ruby/network/Network.hh" 4413513Sgabeblack@google.com#include "mem/ruby/recorder/Tracer.hh" 4513513Sgabeblack@google.com#include "mem/protocol/Protocol.hh" 4613511Sgabeblack@google.com#include "mem/ruby/buffers/MessageBuffer.hh" 4713513Sgabeblack@google.com#include "mem/ruby/system/Sequencer.hh" 4813513Sgabeblack@google.com#include "mem/ruby/system/DMASequencer.hh" 4913513Sgabeblack@google.com#include "mem/ruby/system/MemoryVector.hh" 5013513Sgabeblack@google.com#include "mem/ruby/slicc_interface/AbstractController.hh" 5113513Sgabeblack@google.com#include "mem/ruby/system/CacheMemory.hh" 5213513Sgabeblack@google.com#include "mem/ruby/system/DirectoryMemory.hh" 5313511Sgabeblack@google.com#include "mem/ruby/network/simple/Topology.hh" 5413511Sgabeblack@google.com#include "mem/ruby/network/simple/SimpleNetwork.hh" 5513513Sgabeblack@google.com#include "mem/ruby/system/RubyPort.hh" 5613513Sgabeblack@google.com//#include "mem/ruby/network/garnet-flexible-pipeline/GarnetNetwork.hh" 5713513Sgabeblack@google.com//#include "mem/ruby/network/garnet-fixed-pipeline/GarnetNetwork_d.hh" 5813513Sgabeblack@google.com#include "mem/ruby/system/MemoryControl.hh" 5913513Sgabeblack@google.com 6013511Sgabeblack@google.comint RubySystem::m_random_seed; 6113511Sgabeblack@google.combool RubySystem::m_randomization; 6213513Sgabeblack@google.comint RubySystem::m_tech_nm; 6313513Sgabeblack@google.comint RubySystem::m_freq_mhz; 6413513Sgabeblack@google.comint RubySystem::m_block_size_bytes; 6513513Sgabeblack@google.comint RubySystem::m_block_size_bits; 6613513Sgabeblack@google.comuint64 RubySystem::m_memory_size_bytes; 6713513Sgabeblack@google.comint RubySystem::m_memory_size_bits; 6813513Sgabeblack@google.com 6913511Sgabeblack@google.commap< string, RubyPort* > RubySystem::m_ports; 7013513Sgabeblack@google.commap< string, CacheMemory* > RubySystem::m_caches; 7113513Sgabeblack@google.commap< string, DirectoryMemory* > RubySystem::m_directories; 7213513Sgabeblack@google.commap< string, Sequencer* > RubySystem::m_sequencers; 7313513Sgabeblack@google.commap< string, DMASequencer* > RubySystem::m_dma_sequencers; 7413513Sgabeblack@google.commap< string, AbstractController* > RubySystem::m_controllers; 7513513Sgabeblack@google.commap< string, MemoryControl* > RubySystem::m_memorycontrols; 7613511Sgabeblack@google.com 7713513Sgabeblack@google.com 7813511Sgabeblack@google.comNetwork* RubySystem::m_network_ptr; 7913513Sgabeblack@google.commap< string, Topology*> RubySystem::m_topologies; 8013513Sgabeblack@google.comProfiler* RubySystem::m_profiler_ptr; 8113511Sgabeblack@google.comTracer* RubySystem::m_tracer_ptr; 8213513Sgabeblack@google.com 8313513Sgabeblack@google.comMemoryVector* RubySystem::m_mem_vec_ptr; 8413513Sgabeblack@google.com 8513513Sgabeblack@google.com 8613513Sgabeblack@google.comRubySystem::RubySystem(const Params *p) 8713513Sgabeblack@google.com : SimObject(p) 8813513Sgabeblack@google.com{ 8913513Sgabeblack@google.com if (g_system_ptr != NULL) 9013513Sgabeblack@google.com fatal("Only one RubySystem object currently allowed.\n"); 9113513Sgabeblack@google.com 9213513Sgabeblack@google.com m_random_seed = p->random_seed; 9313513Sgabeblack@google.com srandom(m_random_seed); 9413513Sgabeblack@google.com m_randomization = p->randomization; 9513513Sgabeblack@google.com m_tech_nm = p->tech_nm; 9613511Sgabeblack@google.com m_freq_mhz = p->freq_mhz; 9713511Sgabeblack@google.com 9813513Sgabeblack@google.com m_block_size_bytes = p->block_size_bytes; 9913511Sgabeblack@google.com assert(is_power_of_2(m_block_size_bytes)); 10013513Sgabeblack@google.com m_block_size_bits = log_int(m_block_size_bytes); 101 102 m_memory_size_bytes = (uint64_t)p->mem_size_mb * 1024 * 1024; 103 m_memory_size_bits = log_int(m_memory_size_bytes); 104 105 m_network_ptr = p->network; 106 g_debug_ptr = p->debug; 107 m_profiler_ptr = p->profiler; 108 m_tracer_ptr = p->tracer; 109 110 g_system_ptr = this; 111 m_mem_vec_ptr = new MemoryVector; 112 m_mem_vec_ptr->setSize(m_memory_size_bytes); 113} 114 115 116void RubySystem::init() 117{ 118} 119 120 121RubySystem::~RubySystem() 122{ 123 124} 125 126void RubySystem::printSystemConfig(ostream & out) 127{ 128 out << "RubySystem config:" << endl; 129 out << " random_seed: " << m_random_seed << endl; 130 out << " randomization: " << m_randomization << endl; 131 out << " tech_nm: " << m_tech_nm << endl; 132 out << " freq_mhz: " << m_freq_mhz << endl; 133 out << " block_size_bytes: " << m_block_size_bytes << endl; 134 out << " block_size_bits: " << m_block_size_bits << endl; 135 out << " memory_size_bytes: " << m_memory_size_bytes << endl; 136 out << " memory_size_bits: " << m_memory_size_bits << endl; 137 138} 139 140void RubySystem::printConfig(ostream& out) 141{ 142 out << "\n================ Begin RubySystem Configuration Print ================\n\n"; 143 printSystemConfig(out); 144 for (map<string, AbstractController*>::const_iterator it = m_controllers.begin(); 145 it != m_controllers.end(); it++) { 146 (*it).second->printConfig(out); 147 } 148 for (map<string, CacheMemory*>::const_iterator it = m_caches.begin(); 149 it != m_caches.end(); it++) { 150 (*it).second->printConfig(out); 151 } 152 DirectoryMemory::printGlobalConfig(out); 153 for (map<string, DirectoryMemory*>::const_iterator it = m_directories.begin(); 154 it != m_directories.end(); it++) { 155 (*it).second->printConfig(out); 156 } 157 for (map<string, Sequencer*>::const_iterator it = m_sequencers.begin(); 158 it != m_sequencers.end(); it++) { 159 (*it).second->printConfig(out); 160 } 161 162 m_network_ptr->printConfig(out); 163 m_profiler_ptr->printConfig(out); 164 165 out << "\n================ End RubySystem Configuration Print ================\n\n"; 166} 167 168void RubySystem::printStats(ostream& out) 169{ 170 171 const time_t T = time(NULL); 172 tm *localTime = localtime(&T); 173 char buf[100]; 174 strftime(buf, 100, "%b/%d/%Y %H:%M:%S", localTime); 175 176 out << "Real time: " << buf << endl; 177 178 m_profiler_ptr->printStats(out); 179 m_network_ptr->printStats(out); 180 for (map<string, Sequencer*>::const_iterator it = m_sequencers.begin(); 181 it != m_sequencers.end(); it++) { 182 (*it).second->printStats(out); 183 } 184 for (map<string, CacheMemory*>::const_iterator it = m_caches.begin(); 185 it != m_caches.end(); it++) { 186 (*it).second->printStats(out); 187 } 188 for (map<string, AbstractController*>::const_iterator it = m_controllers.begin(); 189 it != m_controllers.end(); it++) { 190 (*it).second->printStats(out); 191 } 192} 193 194void RubySystem::clearStats() const 195{ 196 m_profiler_ptr->clearStats(); 197 m_network_ptr->clearStats(); 198 for (map<string, CacheMemory*>::const_iterator it = m_caches.begin(); 199 it != m_caches.end(); it++) { 200 (*it).second->clearStats(); 201 } 202 for (map<string, AbstractController*>::const_iterator it = m_controllers.begin(); 203 it != m_controllers.end(); it++) { 204 (*it).second->clearStats(); 205 } 206} 207 208void RubySystem::recordCacheContents(CacheRecorder& tr) const 209{ 210 211} 212 213#ifdef CHECK_COHERENCE 214// This code will check for cases if the given cache block is exclusive in 215// one node and shared in another-- a coherence violation 216// 217// To use, the SLICC specification must call sequencer.checkCoherence(address) 218// when the controller changes to a state with new permissions. Do this 219// in setState. The SLICC spec must also define methods "isBlockShared" 220// and "isBlockExclusive" that are specific to that protocol 221// 222void RubySystem::checkGlobalCoherenceInvariant(const Address& addr ) { 223 /* 224 NodeID exclusive = -1; 225 bool sharedDetected = false; 226 NodeID lastShared = -1; 227 228 for (int i = 0; i < m_chip_vector.size(); i++) { 229 230 if (m_chip_vector[i]->isBlockExclusive(addr)) { 231 if (exclusive != -1) { 232 // coherence violation 233 WARN_EXPR(exclusive); 234 WARN_EXPR(m_chip_vector[i]->getID()); 235 WARN_EXPR(addr); 236 WARN_EXPR(g_eventQueue_ptr->getTime()); 237 ERROR_MSG("Coherence Violation Detected -- 2 exclusive chips"); 238 } 239 else if (sharedDetected) { 240 WARN_EXPR(lastShared); 241 WARN_EXPR(m_chip_vector[i]->getID()); 242 WARN_EXPR(addr); 243 WARN_EXPR(g_eventQueue_ptr->getTime()); 244 ERROR_MSG("Coherence Violation Detected -- exclusive chip with >=1 shared"); 245 } 246 else { 247 exclusive = m_chip_vector[i]->getID(); 248 } 249 } 250 else if (m_chip_vector[i]->isBlockShared(addr)) { 251 sharedDetected = true; 252 lastShared = m_chip_vector[i]->getID(); 253 254 if (exclusive != -1) { 255 WARN_EXPR(lastShared); 256 WARN_EXPR(exclusive); 257 WARN_EXPR(addr); 258 WARN_EXPR(g_eventQueue_ptr->getTime()); 259 ERROR_MSG("Coherence Violation Detected -- exclusive chip with >=1 shared"); 260 } 261 } 262 } 263 */ 264} 265#endif 266 267 268RubySystem * 269RubySystemParams::create() 270{ 271 return new RubySystem(this); 272} 273