RubySystem.hh revision 9103
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 "mem/ruby/common/Global.hh"
40#include "mem/ruby/eventqueue/RubyEventQueue.hh"
41#include "mem/ruby/recorder/CacheRecorder.hh"
42#include "mem/ruby/slicc_interface/AbstractController.hh"
43#include "mem/ruby/system/MemoryVector.hh"
44#include "mem/ruby/system/SparseMemory.hh"
45#include "params/RubySystem.hh"
46#include "sim/sim_object.hh"
47
48class Network;
49class Profiler;
50class MemoryControl;
51
52class RubySystem : public SimObject
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 int getBlockSizeBytes() { return m_block_size_bytes; }
78    static int getBlockSizeBits() { return m_block_size_bits; }
79    static uint64 getMemorySizeBytes() { return m_memory_size_bytes; }
80    static int getMemorySizeBits() { return m_memory_size_bits; }
81
82    // Public Methods
83    static Network*
84    getNetwork()
85    {
86        assert(m_network_ptr != NULL);
87        return m_network_ptr;
88    }
89
90    static RubyEventQueue*
91    getEventQueue()
92    {
93        return g_eventQueue_ptr;
94    }
95
96    Profiler*
97    getProfiler()
98    {
99        assert(m_profiler_ptr != NULL);
100        return m_profiler_ptr;
101    }
102
103    static MemoryVector*
104    getMemoryVector()
105    {
106        assert(m_mem_vec_ptr != NULL);
107        return m_mem_vec_ptr;
108    }
109
110    static void printConfig(std::ostream& out);
111    static void printStats(std::ostream& out);
112    void clearStats() const;
113
114    uint64 getInstructionCount(int thread) { return 1; }
115    static uint64
116    getCycleCount(int thread)
117    {
118        return g_eventQueue_ptr->getTime();
119    }
120
121    void print(std::ostream& out) const;
122
123    void serialize(std::ostream &os);
124    void unserialize(Checkpoint *cp, const std::string &section);
125    void process();
126    void startup();
127
128    void registerNetwork(Network*);
129    void registerProfiler(Profiler*);
130    void registerAbstractController(AbstractController*);
131    void registerSparseMemory(SparseMemory*);
132    void registerMemController(MemoryControl *mc);
133
134    bool eventQueueEmpty() { return eventq->empty(); }
135    void enqueueRubyEvent(Tick tick)
136    {
137        RubyEvent* e = new RubyEvent(this);
138        schedule(e, tick);
139    }
140
141  private:
142    // Private copy constructor and assignment operator
143    RubySystem(const RubySystem& obj);
144    RubySystem& operator=(const RubySystem& obj);
145
146    void init();
147
148    static void printSystemConfig(std::ostream& out);
149    void readCompressedTrace(std::string filename,
150                             uint8*& raw_data,
151                             uint64& uncompressed_trace_size);
152    void writeCompressedTrace(uint8* raw_data, std::string file,
153                              uint64 uncompressed_trace_size);
154
155  private:
156    // configuration parameters
157    static int m_random_seed;
158    static bool m_randomization;
159    static Tick m_clock;
160    static int m_block_size_bytes;
161    static int m_block_size_bits;
162    static uint64 m_memory_size_bytes;
163    static int m_memory_size_bits;
164    static Network* m_network_ptr;
165
166    MemoryControl *m_memory_controller;
167
168  public:
169    static Profiler* m_profiler_ptr;
170    static MemoryVector* m_mem_vec_ptr;
171    std::vector<AbstractController*> m_abs_cntrl_vec;
172    bool m_warmup_enabled;
173    bool m_cooldown_enabled;
174    CacheRecorder* m_cache_recorder;
175    std::vector<SparseMemory*> m_sparse_memory_vector;
176};
177
178inline std::ostream&
179operator<<(std::ostream& out, const RubySystem& obj)
180{
181    //obj.print(out);
182    out << std::flush;
183    return out;
184}
185
186class RubyExitCallback : public Callback
187{
188  private:
189    std::string stats_filename;
190
191  public:
192    virtual ~RubyExitCallback() {}
193
194    RubyExitCallback(const std::string& _stats_filename)
195    {
196        stats_filename = _stats_filename;
197    }
198
199    virtual void process();
200};
201
202#endif // __MEM_RUBY_SYSTEM_SYSTEM_HH__
203