RubySystem.hh revision 8688
1/* 2 * Copyright (c) 1999-2012 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/recorder/CacheRecorder.hh" 42#include "mem/ruby/slicc_interface/AbstractController.hh" 43#include "mem/ruby/system/MemoryVector.hh" 44#include "mem/ruby/system/SparseMemory.hh" 45#include "params/RubySystem.hh" 46#include "sim/sim_object.hh" 47 48class Network; 49class Profiler; 50 51class RubySystem : public SimObject 52{ 53 public: 54 class RubyEvent : public Event 55 { 56 public: 57 RubyEvent(RubySystem* _ruby_system) 58 { 59 ruby_system = _ruby_system; 60 } 61 private: 62 void process(); 63 64 RubySystem* ruby_system; 65 }; 66 67 friend class RubyEvent; 68 69 typedef RubySystemParams Params; 70 RubySystem(const Params *p); 71 ~RubySystem(); 72 73 // config accessors 74 static int getRandomSeed() { return m_random_seed; } 75 static int getRandomization() { return m_randomization; } 76 static int getBlockSizeBytes() { return m_block_size_bytes; } 77 static int getBlockSizeBits() { return m_block_size_bits; } 78 static uint64 getMemorySizeBytes() { return m_memory_size_bytes; } 79 static int getMemorySizeBits() { return m_memory_size_bits; } 80 81 // Public Methods 82 static Network* 83 getNetwork() 84 { 85 assert(m_network_ptr != NULL); 86 return m_network_ptr; 87 } 88 89 static RubyEventQueue* 90 getEventQueue() 91 { 92 return g_eventQueue_ptr; 93 } 94 95 Profiler* 96 getProfiler() 97 { 98 assert(m_profiler_ptr != NULL); 99 return m_profiler_ptr; 100 } 101 102 static MemoryVector* 103 getMemoryVector() 104 { 105 assert(m_mem_vec_ptr != NULL); 106 return m_mem_vec_ptr; 107 } 108 109 static void printConfig(std::ostream& out); 110 static void printStats(std::ostream& out); 111 void clearStats() const; 112 113 uint64 getInstructionCount(int thread) { return 1; } 114 static uint64 115 getCycleCount(int thread) 116 { 117 return g_eventQueue_ptr->getTime(); 118 } 119 120 void print(std::ostream& out) const; 121 122 void serialize(std::ostream &os); 123 void unserialize(Checkpoint *cp, const std::string §ion); 124 void process(); 125 void startup(); 126 127 void registerNetwork(Network*); 128 void registerProfiler(Profiler*); 129 void registerAbstractController(AbstractController*); 130 void registerSparseMemory(SparseMemory*); 131 132 private: 133 // Private copy constructor and assignment operator 134 RubySystem(const RubySystem& obj); 135 RubySystem& operator=(const RubySystem& obj); 136 137 void init(); 138 139 static void printSystemConfig(std::ostream& out); 140 void readCompressedTrace(std::string filename, 141 uint8*& raw_data, 142 uint64& uncompressed_trace_size); 143 void writeCompressedTrace(uint8* raw_data, std::string file, 144 uint64 uncompressed_trace_size); 145 146 private: 147 // configuration parameters 148 static int m_random_seed; 149 static bool m_randomization; 150 static Tick m_clock; 151 static int m_block_size_bytes; 152 static int m_block_size_bits; 153 static uint64 m_memory_size_bytes; 154 static int m_memory_size_bits; 155 static Network* m_network_ptr; 156 157 public: 158 static Profiler* m_profiler_ptr; 159 static MemoryVector* m_mem_vec_ptr; 160 std::vector<AbstractController*> m_abs_cntrl_vec; 161 bool m_warmup_enabled; 162 bool m_cooldown_enabled; 163 CacheRecorder* m_cache_recorder; 164 std::vector<SparseMemory*> m_sparse_memory_vector; 165}; 166 167inline std::ostream& 168operator<<(std::ostream& out, const RubySystem& obj) 169{ 170 //obj.print(out); 171 out << std::flush; 172 return out; 173} 174 175class RubyExitCallback : public Callback 176{ 177 private: 178 std::string stats_filename; 179 180 public: 181 virtual ~RubyExitCallback() {} 182 183 RubyExitCallback(const std::string& _stats_filename) 184 { 185 stats_filename = _stats_filename; 186 } 187 188 virtual void process(); 189}; 190 191#endif // __MEM_RUBY_SYSTEM_SYSTEM_HH__ 192