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