RubySystem.hh revision 8688
16657Snate@binkert.org/* 26657Snate@binkert.org * Copyright (c) 1999-2012 Mark D. Hill and David A. Wood 36657Snate@binkert.org * All rights reserved. 46657Snate@binkert.org * 56657Snate@binkert.org * Redistribution and use in source and binary forms, with or without 66657Snate@binkert.org * modification, are permitted provided that the following conditions are 76657Snate@binkert.org * met: redistributions of source code must retain the above copyright 86657Snate@binkert.org * notice, this list of conditions and the following disclaimer; 96657Snate@binkert.org * redistributions in binary form must reproduce the above copyright 106657Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 116657Snate@binkert.org * documentation and/or other materials provided with the distribution; 126657Snate@binkert.org * neither the name of the copyright holders nor the names of its 136657Snate@binkert.org * contributors may be used to endorse or promote products derived from 146657Snate@binkert.org * this software without specific prior written permission. 156657Snate@binkert.org * 166657Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176657Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186657Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196657Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206657Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216657Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226657Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236657Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246657Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256657Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266657Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276657Snate@binkert.org */ 286657Snate@binkert.org 296657Snate@binkert.org/* 306657Snate@binkert.org * Contains all of the various parts of the system we are simulating. 316657Snate@binkert.org * Performs allocation, deallocation, and setup of all the major 326657Snate@binkert.org * components of the system 336657Snate@binkert.org */ 346657Snate@binkert.org 356657Snate@binkert.org#ifndef __MEM_RUBY_SYSTEM_SYSTEM_HH__ 366657Snate@binkert.org#define __MEM_RUBY_SYSTEM_SYSTEM_HH__ 376657Snate@binkert.org 386657Snate@binkert.org#include "base/callback.hh" 396657Snate@binkert.org#include "mem/ruby/common/Global.hh" 406657Snate@binkert.org#include "mem/ruby/eventqueue/RubyEventQueue.hh" 416657Snate@binkert.org#include "mem/ruby/recorder/CacheRecorder.hh" 426657Snate@binkert.org#include "mem/ruby/slicc_interface/AbstractController.hh" 436714Ssteve.reinhardt@amd.com#include "mem/ruby/system/MemoryVector.hh" 446714Ssteve.reinhardt@amd.com#include "mem/ruby/system/SparseMemory.hh" 456714Ssteve.reinhardt@amd.com#include "params/RubySystem.hh" 466714Ssteve.reinhardt@amd.com#include "sim/sim_object.hh" 476714Ssteve.reinhardt@amd.com 486714Ssteve.reinhardt@amd.comclass Network; 496714Ssteve.reinhardt@amd.comclass Profiler; 506657Snate@binkert.org 516714Ssteve.reinhardt@amd.comclass RubySystem : public SimObject 526714Ssteve.reinhardt@amd.com{ 536657Snate@binkert.org public: 546657Snate@binkert.org class RubyEvent : public Event 556657Snate@binkert.org { 566657Snate@binkert.org public: 576657Snate@binkert.org RubyEvent(RubySystem* _ruby_system) 586657Snate@binkert.org { 596657Snate@binkert.org ruby_system = _ruby_system; 606657Snate@binkert.org } 616657Snate@binkert.org private: 626657Snate@binkert.org void process(); 636657Snate@binkert.org 646657Snate@binkert.org RubySystem* ruby_system; 656657Snate@binkert.org }; 666657Snate@binkert.org 676657Snate@binkert.org friend class RubyEvent; 686657Snate@binkert.org 696657Snate@binkert.org typedef RubySystemParams Params; 706657Snate@binkert.org RubySystem(const Params *p); 716657Snate@binkert.org ~RubySystem(); 726657Snate@binkert.org 736657Snate@binkert.org // config accessors 746657Snate@binkert.org static int getRandomSeed() { return m_random_seed; } 756657Snate@binkert.org static int getRandomization() { return m_randomization; } 766657Snate@binkert.org static int getBlockSizeBytes() { return m_block_size_bytes; } 776657Snate@binkert.org static int getBlockSizeBits() { return m_block_size_bits; } 786657Snate@binkert.org static uint64 getMemorySizeBytes() { return m_memory_size_bytes; } 796657Snate@binkert.org static int getMemorySizeBits() { return m_memory_size_bits; } 806657Snate@binkert.org 816657Snate@binkert.org // 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