RubySystem.hh revision 8436
1/* 2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29/* 30 * Contains all of the various parts of the system we are simulating. 31 * Performs allocation, deallocation, and setup of all the major 32 * components of the system 33 */ 34 35#ifndef __MEM_RUBY_SYSTEM_SYSTEM_HH__ 36#define __MEM_RUBY_SYSTEM_SYSTEM_HH__ 37 38#include "base/callback.hh" 39#include "mem/ruby/common/Global.hh" 40#include "mem/ruby/eventqueue/RubyEventQueue.hh" 41#include "mem/ruby/system/RubyPort.hh" 42#include "mem/ruby/slicc_interface/AbstractController.hh" 43#include "params/RubySystem.hh" 44#include "sim/sim_object.hh" 45 46class AbstractController; 47class AbstractMemory; 48class CacheRecorder; 49class MemoryVector; 50class Network; 51class Profiler; 52class Tracer; 53 54/* 55 * This defines the number of longs (32-bits on 32 bit machines, 56 * 64-bit on 64-bit AMD machines) to use to hold the set... 57 * the default is 4, allowing 128 or 256 different members 58 * of the set. 59 * 60 * This should never need to be changed for correctness reasons, 61 * though increasing it will increase performance for larger 62 * set sizes at the cost of a (much) larger memory footprint 63 * 64 */ 65const int NUMBER_WORDS_PER_SET = 1; 66 67class RubySystem : public SimObject 68{ 69 public: 70 typedef RubySystemParams Params; 71 RubySystem(const Params *p); 72 ~RubySystem(); 73 74 // config accessors 75 static int getRandomSeed() { return m_random_seed; } 76 static int getRandomization() { return m_randomization; } 77 static int getBlockSizeBytes() { return m_block_size_bytes; } 78 static int getBlockSizeBits() { return m_block_size_bits; } 79 static uint64 getMemorySizeBytes() { return m_memory_size_bytes; } 80 static int getMemorySizeBits() { return m_memory_size_bits; } 81 82 // Public Methods 83 static Network* 84 getNetwork() 85 { 86 assert(m_network_ptr != NULL); 87 return m_network_ptr; 88 } 89 90 static RubyEventQueue* 91 getEventQueue() 92 { 93 return g_eventQueue_ptr; 94 } 95 96 Profiler* 97 getProfiler() 98 { 99 assert(m_profiler_ptr != NULL); 100 return m_profiler_ptr; 101 } 102 103 static Tracer* 104 getTracer() 105 { 106 assert(m_tracer_ptr != NULL); 107 return m_tracer_ptr; 108 } 109 110 static MemoryVector* 111 getMemoryVector() 112 { 113 assert(m_mem_vec_ptr != NULL); 114 return m_mem_vec_ptr; 115 } 116 117 void recordCacheContents(CacheRecorder& tr) const; 118 static void printConfig(std::ostream& out); 119 static void printStats(std::ostream& out); 120 void clearStats() const; 121 122 uint64 getInstructionCount(int thread) { return 1; } 123 static uint64 124 getCycleCount(int thread) 125 { 126 return g_eventQueue_ptr->getTime(); 127 } 128 129 void print(std::ostream& out) const; 130 131 virtual void serialize(std::ostream &os); 132 virtual void unserialize(Checkpoint *cp, const std::string §ion); 133 134 void registerNetwork(Network*); 135 void registerProfiler(Profiler*); 136 void registerTracer(Tracer*); 137 void registerAbstractMemory(AbstractMemory*); 138 void registerAbstractController(AbstractController*); 139 140 private: 141 // Private copy constructor and assignment operator 142 RubySystem(const RubySystem& obj); 143 RubySystem& operator=(const RubySystem& obj); 144 145 void init(); 146 147 static void printSystemConfig(std::ostream& out); 148 149 private: 150 // configuration parameters 151 static int m_random_seed; 152 static bool m_randomization; 153 static Tick m_clock; 154 static int m_block_size_bytes; 155 static int m_block_size_bits; 156 static uint64 m_memory_size_bytes; 157 static int m_memory_size_bits; 158 159 static Network* m_network_ptr; 160 161 public: 162 static Profiler* m_profiler_ptr; 163 static Tracer* m_tracer_ptr; 164 static MemoryVector* m_mem_vec_ptr; 165 std::vector<AbstractController*> m_abs_cntrl_vec; 166}; 167 168inline std::ostream& 169operator<<(std::ostream& out, const RubySystem& obj) 170{ 171 //obj.print(out); 172 out << std::flush; 173 return out; 174} 175 176class RubyExitCallback : public Callback 177{ 178 private: 179 std::string stats_filename; 180 181 public: 182 virtual ~RubyExitCallback() {} 183 184 RubyExitCallback(const std::string& _stats_filename) 185 { 186 stats_filename = _stats_filename; 187 } 188 189 virtual void process(); 190}; 191 192#endif // __MEM_RUBY_SYSTEM_SYSTEM_HH__ 193