RubySystem.hh revision 12133
16019Shines@cs.fsu.edu/*
27399SAli.Saidi@ARM.com * Copyright (c) 1999-2012 Mark D. Hill and David A. Wood
37399SAli.Saidi@ARM.com * All rights reserved.
47399SAli.Saidi@ARM.com *
57399SAli.Saidi@ARM.com * Redistribution and use in source and binary forms, with or without
67399SAli.Saidi@ARM.com * modification, are permitted provided that the following conditions are
77399SAli.Saidi@ARM.com * met: redistributions of source code must retain the above copyright
87399SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer;
97399SAli.Saidi@ARM.com * redistributions in binary form must reproduce the above copyright
107399SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer in the
117399SAli.Saidi@ARM.com * documentation and/or other materials provided with the distribution;
127399SAli.Saidi@ARM.com * neither the name of the copyright holders nor the names of its
137399SAli.Saidi@ARM.com * contributors may be used to endorse or promote products derived from
146019Shines@cs.fsu.edu * this software without specific prior written permission.
156019Shines@cs.fsu.edu *
166019Shines@cs.fsu.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176019Shines@cs.fsu.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186019Shines@cs.fsu.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196019Shines@cs.fsu.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206019Shines@cs.fsu.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216019Shines@cs.fsu.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226019Shines@cs.fsu.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236019Shines@cs.fsu.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246019Shines@cs.fsu.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256019Shines@cs.fsu.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266019Shines@cs.fsu.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276019Shines@cs.fsu.edu */
286019Shines@cs.fsu.edu
296019Shines@cs.fsu.edu/*
306019Shines@cs.fsu.edu * Contains all of the various parts of the system we are simulating.
316019Shines@cs.fsu.edu * Performs allocation, deallocation, and setup of all the major
326019Shines@cs.fsu.edu * components of the system
336019Shines@cs.fsu.edu */
346019Shines@cs.fsu.edu
356019Shines@cs.fsu.edu#ifndef __MEM_RUBY_SYSTEM_SYSTEM_HH__
366019Shines@cs.fsu.edu#define __MEM_RUBY_SYSTEM_SYSTEM_HH__
376019Shines@cs.fsu.edu
386019Shines@cs.fsu.edu#include "base/callback.hh"
396019Shines@cs.fsu.edu#include "base/output.hh"
407399SAli.Saidi@ARM.com#include "mem/packet.hh"
416019Shines@cs.fsu.edu#include "mem/ruby/profiler/Profiler.hh"
426019Shines@cs.fsu.edu#include "mem/ruby/slicc_interface/AbstractController.hh"
436019Shines@cs.fsu.edu#include "mem/ruby/system/CacheRecorder.hh"
446019Shines@cs.fsu.edu#include "params/RubySystem.hh"
456019Shines@cs.fsu.edu#include "sim/clocked_object.hh"
466019Shines@cs.fsu.edu
476019Shines@cs.fsu.educlass Network;
486019Shines@cs.fsu.educlass AbstractController;
496019Shines@cs.fsu.edu
506019Shines@cs.fsu.educlass RubySystem : public ClockedObject
516019Shines@cs.fsu.edu{
526019Shines@cs.fsu.edu  public:
536019Shines@cs.fsu.edu    typedef RubySystemParams Params;
546116Snate@binkert.org    RubySystem(const Params *p);
556019Shines@cs.fsu.edu    ~RubySystem();
566019Shines@cs.fsu.edu
576019Shines@cs.fsu.edu    // config accessors
586019Shines@cs.fsu.edu    static int getRandomization() { return m_randomization; }
596019Shines@cs.fsu.edu    static uint32_t getBlockSizeBytes() { return m_block_size_bytes; }
606019Shines@cs.fsu.edu    static uint32_t getBlockSizeBits() { return m_block_size_bits; }
616019Shines@cs.fsu.edu    static uint32_t getMemorySizeBits() { return m_memory_size_bits; }
626019Shines@cs.fsu.edu    static bool getWarmupEnabled() { return m_warmup_enabled; }
636019Shines@cs.fsu.edu    static bool getCooldownEnabled() { return m_cooldown_enabled; }
647294Sgblack@eecs.umich.edu
657294Sgblack@eecs.umich.edu    SimpleMemory *getPhysMem() { return m_phys_mem; }
667294Sgblack@eecs.umich.edu    Cycles getStartCycle() { return m_start_cycle; }
677294Sgblack@eecs.umich.edu    bool getAccessBackingStore() { return m_access_backing_store; }
687294Sgblack@eecs.umich.edu
697294Sgblack@eecs.umich.edu    // Public Methods
707294Sgblack@eecs.umich.edu    Profiler*
717294Sgblack@eecs.umich.edu    getProfiler()
727294Sgblack@eecs.umich.edu    {
737294Sgblack@eecs.umich.edu        assert(m_profiler != NULL);
747294Sgblack@eecs.umich.edu        return m_profiler;
757294Sgblack@eecs.umich.edu    }
767294Sgblack@eecs.umich.edu
777294Sgblack@eecs.umich.edu    void regStats() override {
787294Sgblack@eecs.umich.edu        ClockedObject::regStats();
796019Shines@cs.fsu.edu        m_profiler->regStats(name());
806019Shines@cs.fsu.edu    }
816019Shines@cs.fsu.edu    void collateStats() { m_profiler->collateStats(); }
826019Shines@cs.fsu.edu    void resetStats() override;
836019Shines@cs.fsu.edu
846019Shines@cs.fsu.edu    void memWriteback() override;
856019Shines@cs.fsu.edu    void serialize(CheckpointOut &cp) const override;
866019Shines@cs.fsu.edu    void unserialize(CheckpointIn &cp) override;
876019Shines@cs.fsu.edu    void drainResume() override;
886019Shines@cs.fsu.edu    void process();
896019Shines@cs.fsu.edu    void startup() override;
907399SAli.Saidi@ARM.com    bool functionalRead(Packet *ptr);
916020Sgblack@eecs.umich.edu    bool functionalWrite(Packet *ptr);
926020Sgblack@eecs.umich.edu
936020Sgblack@eecs.umich.edu    void registerNetwork(Network*);
946020Sgblack@eecs.umich.edu    void registerAbstractController(AbstractController*);
956020Sgblack@eecs.umich.edu
966020Sgblack@eecs.umich.edu    bool eventQueueEmpty() { return eventq->empty(); }
976020Sgblack@eecs.umich.edu    void enqueueRubyEvent(Tick tick)
986020Sgblack@eecs.umich.edu    {
996019Shines@cs.fsu.edu        auto e = new EventFunctionWrapper(
1006019Shines@cs.fsu.edu            [this]{ processRubyEvent(); }, "RubyEvent");
1016019Shines@cs.fsu.edu        schedule(e, tick);
1026019Shines@cs.fsu.edu    }
1036019Shines@cs.fsu.edu
1046019Shines@cs.fsu.edu  private:
1056019Shines@cs.fsu.edu    // Private copy constructor and assignment operator
1066019Shines@cs.fsu.edu    RubySystem(const RubySystem& obj);
1076019Shines@cs.fsu.edu    RubySystem& operator=(const RubySystem& obj);
1086019Shines@cs.fsu.edu
1096019Shines@cs.fsu.edu    void makeCacheRecorder(uint8_t *uncompressed_trace,
1106019Shines@cs.fsu.edu                           uint64_t cache_trace_size,
1116019Shines@cs.fsu.edu                           uint64_t block_size_bytes);
1126019Shines@cs.fsu.edu
1136019Shines@cs.fsu.edu    static void readCompressedTrace(std::string filename,
1146019Shines@cs.fsu.edu                                    uint8_t *&raw_data,
1156019Shines@cs.fsu.edu                                    uint64_t &uncompressed_trace_size);
1166019Shines@cs.fsu.edu    static void writeCompressedTrace(uint8_t *raw_data, std::string file,
1176019Shines@cs.fsu.edu                                     uint64_t uncompressed_trace_size);
1186019Shines@cs.fsu.edu
1196019Shines@cs.fsu.edu    void processRubyEvent();
1206116Snate@binkert.org  private:
1216116Snate@binkert.org    // configuration parameters
1226116Snate@binkert.org    static bool m_randomization;
1236116Snate@binkert.org    static uint32_t m_block_size_bytes;
1246019Shines@cs.fsu.edu    static uint32_t m_block_size_bits;
1256019Shines@cs.fsu.edu    static uint32_t m_memory_size_bits;
1266019Shines@cs.fsu.edu
1276019Shines@cs.fsu.edu    static bool m_warmup_enabled;
1286019Shines@cs.fsu.edu    static unsigned m_systems_to_warmup;
1296019Shines@cs.fsu.edu    static bool m_cooldown_enabled;
1306019Shines@cs.fsu.edu    SimpleMemory *m_phys_mem;
1316116Snate@binkert.org    const bool m_access_backing_store;
1326019Shines@cs.fsu.edu
1336019Shines@cs.fsu.edu    Network* m_network;
134    std::vector<AbstractController *> m_abs_cntrl_vec;
135    Cycles m_start_cycle;
136
137  public:
138    Profiler* m_profiler;
139    CacheRecorder* m_cache_recorder;
140    std::vector<std::map<uint32_t, AbstractController *> > m_abstract_controls;
141};
142
143class RubyStatsCallback : public Callback
144{
145  private:
146    RubySystem *m_ruby_system;
147
148  public:
149    virtual ~RubyStatsCallback() {}
150    RubyStatsCallback(RubySystem *system) : m_ruby_system(system) {}
151    void process() { m_ruby_system->collateStats(); }
152};
153
154#endif // __MEM_RUBY_SYSTEM_SYSTEM_HH__
155