RubySystem.hh revision 10920
16145Snate@binkert.org/*
26145Snate@binkert.org * Copyright (c) 1999-2012 Mark D. Hill and David A. Wood
36145Snate@binkert.org * All rights reserved.
46145Snate@binkert.org *
56145Snate@binkert.org * Redistribution and use in source and binary forms, with or without
66145Snate@binkert.org * modification, are permitted provided that the following conditions are
76145Snate@binkert.org * met: redistributions of source code must retain the above copyright
86145Snate@binkert.org * notice, this list of conditions and the following disclaimer;
96145Snate@binkert.org * redistributions in binary form must reproduce the above copyright
106145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
116145Snate@binkert.org * documentation and/or other materials provided with the distribution;
126145Snate@binkert.org * neither the name of the copyright holders nor the names of its
136145Snate@binkert.org * contributors may be used to endorse or promote products derived from
146145Snate@binkert.org * this software without specific prior written permission.
156145Snate@binkert.org *
166145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276145Snate@binkert.org */
286145Snate@binkert.org
296154Snate@binkert.org/*
306145Snate@binkert.org * Contains all of the various parts of the system we are simulating.
316145Snate@binkert.org * Performs allocation, deallocation, and setup of all the major
326145Snate@binkert.org * components of the system
337039Snate@binkert.org */
347039Snate@binkert.org
357039Snate@binkert.org#ifndef __MEM_RUBY_SYSTEM_SYSTEM_HH__
367039Snate@binkert.org#define __MEM_RUBY_SYSTEM_SYSTEM_HH__
377039Snate@binkert.org
386145Snate@binkert.org#include "base/callback.hh"
396145Snate@binkert.org#include "base/output.hh"
407039Snate@binkert.org#include "mem/ruby/profiler/Profiler.hh"
417039Snate@binkert.org#include "mem/ruby/slicc_interface/AbstractController.hh"
426145Snate@binkert.org#include "mem/ruby/system/CacheRecorder.hh"
437039Snate@binkert.org#include "mem/packet.hh"
447039Snate@binkert.org#include "params/RubySystem.hh"
457039Snate@binkert.org#include "sim/clocked_object.hh"
467039Snate@binkert.org
477039Snate@binkert.orgclass Network;
487039Snate@binkert.orgclass AbstractController;
496145Snate@binkert.org
506145Snate@binkert.orgclass RubySystem : public ClockedObject
517039Snate@binkert.org{
527039Snate@binkert.org  public:
536145Snate@binkert.org    class RubyEvent : public Event
547039Snate@binkert.org    {
557039Snate@binkert.org      public:
567039Snate@binkert.org        RubyEvent(RubySystem* _ruby_system)
577039Snate@binkert.org        {
587039Snate@binkert.org            m_ruby_system = _ruby_system;
597039Snate@binkert.org        }
607039Snate@binkert.org      private:
616145Snate@binkert.org        void process();
626145Snate@binkert.org
637039Snate@binkert.org        RubySystem* m_ruby_system;
647055Snate@binkert.org    };
656145Snate@binkert.org
667039Snate@binkert.org    friend class RubyEvent;
676145Snate@binkert.org
686145Snate@binkert.org    typedef RubySystemParams Params;
696145Snate@binkert.org    RubySystem(const Params *p);
706145Snate@binkert.org    ~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 serializeOld(CheckpointOut &cp) M5_ATTR_OVERRIDE;
98    void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE;
99    void process();
100    void startup();
101    bool functionalRead(Packet *ptr);
102    bool functionalWrite(Packet *ptr);
103
104    void registerNetwork(Network*);
105    void registerAbstractController(AbstractController*);
106
107    bool eventQueueEmpty() { return eventq->empty(); }
108    void enqueueRubyEvent(Tick tick)
109    {
110        RubyEvent* e = new RubyEvent(this);
111        schedule(e, tick);
112    }
113
114  private:
115    // Private copy constructor and assignment operator
116    RubySystem(const RubySystem& obj);
117    RubySystem& operator=(const RubySystem& obj);
118
119    void readCompressedTrace(std::string filename,
120                             uint8_t *&raw_data,
121                             uint64& uncompressed_trace_size);
122    void writeCompressedTrace(uint8_t *raw_data, std::string file,
123                              uint64 uncompressed_trace_size);
124
125  private:
126    // configuration parameters
127    static int m_random_seed;
128    static bool m_randomization;
129    static uint32_t m_block_size_bytes;
130    static uint32_t m_block_size_bits;
131    static uint32_t m_memory_size_bits;
132
133    static bool m_warmup_enabled;
134    static unsigned m_systems_to_warmup;
135    static bool m_cooldown_enabled;
136    SimpleMemory *m_phys_mem;
137    const bool m_access_backing_store;
138
139    Network* m_network;
140    std::vector<AbstractController *> m_abs_cntrl_vec;
141    Cycles m_start_cycle;
142
143  public:
144    Profiler* m_profiler;
145    CacheRecorder* m_cache_recorder;
146    std::vector<std::map<uint32_t, AbstractController *> > m_abstract_controls;
147};
148
149class RubyStatsCallback : public Callback
150{
151  private:
152    RubySystem *m_ruby_system;
153
154  public:
155    virtual ~RubyStatsCallback() {}
156    RubyStatsCallback(RubySystem *system) : m_ruby_system(system) {}
157    void process() { m_ruby_system->collateStats(); }
158};
159
160#endif // __MEM_RUBY_SYSTEM_SYSTEM_HH__
161