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