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