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