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