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