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