RubySystem.hh revision 10301
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/ruby/profiler/Profiler.hh" 41#include "mem/ruby/slicc_interface/AbstractController.hh" 42#include "mem/ruby/structures/MemoryControl.hh" 43#include "mem/ruby/structures/MemoryVector.hh" 44#include "mem/ruby/structures/SparseMemory.hh" 45#include "mem/ruby/system/CacheRecorder.hh" 46#include "mem/packet.hh" 47#include "params/RubySystem.hh" 48#include "sim/clocked_object.hh" 49 50class Network; 51 52class RubySystem : public ClockedObject 53{ 54 public: 55 class RubyEvent : public Event 56 { 57 public: 58 RubyEvent(RubySystem* _ruby_system) 59 { 60 ruby_system = _ruby_system; 61 } 62 private: 63 void process(); 64 65 RubySystem* ruby_system; 66 }; 67 68 friend class RubyEvent; 69 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 uint32_t getBlockSizeBytes() { return m_block_size_bytes; } 78 static uint32_t getBlockSizeBits() { return m_block_size_bits; } 79 static uint64_t getMemorySizeBytes() { return m_memory_size_bytes; } 80 static uint32_t getMemorySizeBits() { return m_memory_size_bits; } 81 82 // Public Methods 83 Profiler* 84 getProfiler() 85 { 86 assert(m_profiler != NULL); 87 return m_profiler; 88 } 89 90 MemoryVector* 91 getMemoryVector() 92 { 93 assert(m_mem_vec != NULL); 94 return m_mem_vec; 95 } 96 97 void regStats() { m_profiler->regStats(name()); } 98 void collateStats() { m_profiler->collateStats(); } 99 void resetStats(); 100 101 void serialize(std::ostream &os); 102 void unserialize(Checkpoint *cp, const std::string §ion); 103 void process(); 104 void startup(); 105 bool functionalRead(Packet *ptr); 106 bool functionalWrite(Packet *ptr); 107 108 void registerNetwork(Network*); 109 void registerAbstractController(AbstractController*); 110 void registerSparseMemory(SparseMemory*); 111 void registerMemController(MemoryControl *mc); 112 113 bool eventQueueEmpty() { return eventq->empty(); } 114 void enqueueRubyEvent(Tick tick) 115 { 116 RubyEvent* e = new RubyEvent(this); 117 schedule(e, tick); 118 } 119 120 private: 121 // Private copy constructor and assignment operator 122 RubySystem(const RubySystem& obj); 123 RubySystem& operator=(const RubySystem& obj); 124 125 void readCompressedTrace(std::string filename, 126 uint8_t *&raw_data, 127 uint64& uncompressed_trace_size); 128 void writeCompressedTrace(uint8_t *raw_data, std::string file, 129 uint64 uncompressed_trace_size); 130 131 private: 132 // configuration parameters 133 static int m_random_seed; 134 static bool m_randomization; 135 static uint32_t m_block_size_bytes; 136 static uint32_t m_block_size_bits; 137 static uint64_t m_memory_size_bytes; 138 static uint32_t m_memory_size_bits; 139 140 Network* m_network; 141 std::vector<MemoryControl *> m_memory_controller_vec; 142 std::vector<AbstractController *> m_abs_cntrl_vec; 143 144 public: 145 Profiler* m_profiler; 146 MemoryVector* m_mem_vec; 147 bool m_warmup_enabled; 148 bool m_cooldown_enabled; 149 CacheRecorder* m_cache_recorder; 150 std::vector<SparseMemory*> m_sparse_memory_vector; 151}; 152 153class RubyStatsCallback : public Callback 154{ 155 private: 156 RubySystem *ruby_system; 157 158 public: 159 virtual ~RubyStatsCallback() {} 160 RubyStatsCallback(RubySystem *system) : ruby_system(system) {} 161 void process() { ruby_system->collateStats(); } 162}; 163 164#endif // __MEM_RUBY_SYSTEM_SYSTEM_HH__ 165