RubySystem.hh revision 9350
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 "base/output.hh" 40#include "mem/packet.hh" 41#include "mem/ruby/common/Global.hh" 42#include "mem/ruby/recorder/CacheRecorder.hh" 43#include "mem/ruby/slicc_interface/AbstractController.hh" 44#include "mem/ruby/system/MemoryVector.hh" 45#include "mem/ruby/system/SparseMemory.hh" 46#include "params/RubySystem.hh" 47#include "sim/clocked_object.hh" 48 49class Network; 50class Profiler; 51class MemoryControl; 52 53class RubySystem : public ClockedObject 54{ 55 public: 56 class RubyEvent : public Event 57 { 58 public: 59 RubyEvent(RubySystem* _ruby_system) 60 { 61 ruby_system = _ruby_system; 62 } 63 private: 64 void process(); 65 66 RubySystem* ruby_system; 67 }; 68 69 friend class RubyEvent; 70 71 typedef RubySystemParams Params; 72 RubySystem(const Params *p); 73 ~RubySystem(); 74 75 // config accessors 76 static int getRandomSeed() { return m_random_seed; } 77 static int getRandomization() { return m_randomization; } 78 static int getBlockSizeBytes() { return m_block_size_bytes; } 79 static int getBlockSizeBits() { return m_block_size_bits; } 80 static uint64 getMemorySizeBytes() { return m_memory_size_bytes; } 81 static int getMemorySizeBits() { return m_memory_size_bits; } 82 Cycles getTime() const { return curCycle(); } 83 84 // Public Methods 85 Network* 86 getNetwork() 87 { 88 assert(m_network_ptr != NULL); 89 return m_network_ptr; 90 } 91 92 Profiler* 93 getProfiler() 94 { 95 assert(m_profiler_ptr != NULL); 96 return m_profiler_ptr; 97 } 98 99 MemoryVector* 100 getMemoryVector() 101 { 102 assert(m_mem_vec_ptr != NULL); 103 return m_mem_vec_ptr; 104 } 105 106 void printStats(std::ostream& out); 107 void resetStats(); 108 109 uint64 getInstructionCount(int thread) { return 1; } 110 111 void print(std::ostream& out) const; 112 113 void serialize(std::ostream &os); 114 void unserialize(Checkpoint *cp, const std::string §ion); 115 void process(); 116 void startup(); 117 bool functionalRead(Packet *ptr); 118 bool functionalWrite(Packet *ptr); 119 120 void registerNetwork(Network*); 121 void registerProfiler(Profiler*); 122 void registerAbstractController(AbstractController*); 123 void registerSparseMemory(SparseMemory*); 124 void registerMemController(MemoryControl *mc); 125 126 bool eventQueueEmpty() { return eventq->empty(); } 127 void enqueueRubyEvent(Tick tick) 128 { 129 RubyEvent* e = new RubyEvent(this); 130 schedule(e, tick); 131 } 132 133 private: 134 // Private copy constructor and assignment operator 135 RubySystem(const RubySystem& obj); 136 RubySystem& operator=(const RubySystem& obj); 137 138 void init(); 139 140 void readCompressedTrace(std::string filename, 141 uint8_t *&raw_data, 142 uint64& uncompressed_trace_size); 143 void writeCompressedTrace(uint8_t *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 int m_block_size_bytes; 151 static int m_block_size_bits; 152 static uint64 m_memory_size_bytes; 153 static int m_memory_size_bits; 154 155 Network* m_network_ptr; 156 std::vector<MemoryControl *> m_memory_controller_vec; 157 std::vector<AbstractController *> m_abs_cntrl_vec; 158 159 public: 160 Profiler* m_profiler_ptr; 161 MemoryVector* m_mem_vec_ptr; 162 bool m_warmup_enabled; 163 bool m_cooldown_enabled; 164 CacheRecorder* m_cache_recorder; 165 std::vector<SparseMemory*> m_sparse_memory_vector; 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 RubyDumpStatsCallback : public Callback 177{ 178 private: 179 std::ostream *os; 180 RubySystem *ruby_system; 181 182 public: 183 virtual ~RubyDumpStatsCallback() {} 184 185 RubyDumpStatsCallback(const std::string& _stats_filename, 186 RubySystem *system) 187 { 188 os = simout.create(_stats_filename); 189 ruby_system = system; 190 } 191 192 void process(); 193}; 194 195#endif // __MEM_RUBY_SYSTEM_SYSTEM_HH__ 196