RubySystem.hh revision 9504
12330SN/A/*
22330SN/A * Copyright (c) 1999-2012 Mark D. Hill and David A. Wood
32330SN/A * All rights reserved.
42330SN/A *
52330SN/A * Redistribution and use in source and binary forms, with or without
62330SN/A * modification, are permitted provided that the following conditions are
72330SN/A * met: redistributions of source code must retain the above copyright
82330SN/A * notice, this list of conditions and the following disclaimer;
92330SN/A * redistributions in binary form must reproduce the above copyright
102330SN/A * notice, this list of conditions and the following disclaimer in the
112330SN/A * documentation and/or other materials provided with the distribution;
122330SN/A * neither the name of the copyright holders nor the names of its
132330SN/A * contributors may be used to endorse or promote products derived from
142330SN/A * this software without specific prior written permission.
152330SN/A *
162330SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172330SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182330SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192330SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202330SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212330SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222330SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232330SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242330SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252330SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262330SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272689Sktlim@umich.edu */
282689Sktlim@umich.edu
292330SN/A/*
302292SN/A * Contains all of the various parts of the system we are simulating.
312292SN/A * Performs allocation, deallocation, and setup of all the major
322292SN/A * components of the system
332292SN/A */
342980Sgblack@eecs.umich.edu
356658Snate@binkert.org#ifndef __MEM_RUBY_SYSTEM_SYSTEM_HH__
368229Snate@binkert.org#define __MEM_RUBY_SYSTEM_SYSTEM_HH__
372362SN/A
382680Sktlim@umich.edu#include "base/callback.hh"
392683Sktlim@umich.edu#include "base/output.hh"
402678Sktlim@umich.edu#include "mem/packet.hh"
412292SN/A#include "mem/ruby/common/Global.hh"
422292SN/A#include "mem/ruby/recorder/CacheRecorder.hh"
432292SN/A#include "mem/ruby/slicc_interface/AbstractController.hh"
4413905Sgabeblack@google.com#include "mem/ruby/system/MemoryVector.hh"
4513905Sgabeblack@google.com#include "mem/ruby/system/SparseMemory.hh"
468902Sandreas.hansson@arm.com#include "params/RubySystem.hh"
472292SN/A#include "sim/clocked_object.hh"
482862Sktlim@umich.edu
492862Sktlim@umich.educlass Network;
5014022Sgabeblack@google.comclass Profiler;
5114022Sgabeblack@google.comclass MemoryControl;
5214022Sgabeblack@google.com
532330SN/Aclass RubySystem : public ClockedObject
542330SN/A{
552330SN/A  public:
562330SN/A    class RubyEvent : public Event
572330SN/A    {
582330SN/A      public:
5910905Sandreas.sandberg@arm.com        RubyEvent(RubySystem* _ruby_system)
602683Sktlim@umich.edu        {
612683Sktlim@umich.edu            ruby_system = _ruby_system;
626331Sgblack@eecs.umich.edu        }
632683Sktlim@umich.edu      private:
648735Sandreas.hanson@arm.com        void process();
653486Sktlim@umich.edu
6611168Sandreas.hansson@arm.com        RubySystem* ruby_system;
672862Sktlim@umich.edu    };
6811168Sandreas.hansson@arm.com
692862Sktlim@umich.edu    friend class RubyEvent;
7010110Sandreas.hansson@arm.com
712683Sktlim@umich.edu    typedef RubySystemParams Params;
7210190Sakash.bagdia@arm.com    RubySystem(const Params *p);
7310190Sakash.bagdia@arm.com    ~RubySystem();
7411005Sandreas.sandberg@arm.com
755714Shsul@eecs.umich.edu    // config accessors
7611005Sandreas.sandberg@arm.com    static int getRandomSeed() { return m_random_seed; }
775714Shsul@eecs.umich.edu    static int getRandomization() { return m_randomization; }
786221Snate@binkert.org    static uint32_t getBlockSizeBytes() { return m_block_size_bytes; }
792683Sktlim@umich.edu    static uint32_t getBlockSizeBits() { return m_block_size_bits; }
8010110Sandreas.hansson@arm.com    static uint64_t getMemorySizeBytes() { return m_memory_size_bytes; }
812683Sktlim@umich.edu    static uint32_t getMemorySizeBits() { return m_memory_size_bits; }
8210110Sandreas.hansson@arm.com    Cycles getTime() const { return curCycle(); }
832683Sktlim@umich.edu
8410110Sandreas.hansson@arm.com    // Public Methods
852683Sktlim@umich.edu    Network*
868706Sandreas.hansson@arm.com    getNetwork()
878706Sandreas.hansson@arm.com    {
888706Sandreas.hansson@arm.com        assert(m_network_ptr != NULL);
898706Sandreas.hansson@arm.com        return m_network_ptr;
908921Sandreas.hansson@arm.com    }
918706Sandreas.hansson@arm.com
928706Sandreas.hansson@arm.com    Profiler*
933675Sktlim@umich.edu    getProfiler()
942683Sktlim@umich.edu    {
952683Sktlim@umich.edu        assert(m_profiler_ptr != NULL);
962683Sktlim@umich.edu        return m_profiler_ptr;
972683Sktlim@umich.edu    }
982683Sktlim@umich.edu
992683Sktlim@umich.edu    MemoryVector*
1002683Sktlim@umich.edu    getMemoryVector()
1012683Sktlim@umich.edu    {
10213905Sgabeblack@google.com        assert(m_mem_vec_ptr != NULL);
1032683Sktlim@umich.edu        return m_mem_vec_ptr;
1049101SBrad.Beckmann@amd.com    }
1052690Sktlim@umich.edu
10614022Sgabeblack@google.com    void printStats(std::ostream& out);
1078799Sgblack@eecs.umich.edu    void resetStats();
1082683Sktlim@umich.edu
1092683Sktlim@umich.edu    uint64 getInstructionCount(int thread) { return 1; }
11011886Sbrandon.potter@amd.com
11111886Sbrandon.potter@amd.com    void print(std::ostream& out) const;
11211886Sbrandon.potter@amd.com
11311886Sbrandon.potter@amd.com    void serialize(std::ostream &os);
11411886Sbrandon.potter@amd.com    void unserialize(Checkpoint *cp, const std::string &section);
11511886Sbrandon.potter@amd.com    void process();
11611886Sbrandon.potter@amd.com    void startup();
11711886Sbrandon.potter@amd.com    bool functionalRead(Packet *ptr);
11811886Sbrandon.potter@amd.com    bool functionalWrite(Packet *ptr);
11911886Sbrandon.potter@amd.com
12011886Sbrandon.potter@amd.com    void registerNetwork(Network*);
12111886Sbrandon.potter@amd.com    void registerProfiler(Profiler*);
12211886Sbrandon.potter@amd.com    void registerAbstractController(AbstractController*);
12311886Sbrandon.potter@amd.com    void registerSparseMemory(SparseMemory*);
12411886Sbrandon.potter@amd.com    void registerMemController(MemoryControl *mc);
12514022Sgabeblack@google.com
1262292SN/A    bool eventQueueEmpty() { return eventq->empty(); }
1272683Sktlim@umich.edu    void enqueueRubyEvent(Tick tick)
1282683Sktlim@umich.edu    {
1292683Sktlim@umich.edu        RubyEvent* e = new RubyEvent(this);
13013865Sgabeblack@google.com        schedule(e, tick);
1312683Sktlim@umich.edu    }
1322683Sktlim@umich.edu
1332683Sktlim@umich.edu  private:
1342683Sktlim@umich.edu    // Private copy constructor and assignment operator
1352683Sktlim@umich.edu    RubySystem(const RubySystem& obj);
1362683Sktlim@umich.edu    RubySystem& operator=(const RubySystem& obj);
1372683Sktlim@umich.edu
1382683Sktlim@umich.edu    void init();
1392683Sktlim@umich.edu
1402683Sktlim@umich.edu    void readCompressedTrace(std::string filename,
1412683Sktlim@umich.edu                             uint8_t *&raw_data,
1422683Sktlim@umich.edu                             uint64& uncompressed_trace_size);
1433673Srdreslin@umich.edu    void writeCompressedTrace(uint8_t *raw_data, std::string file,
1443486Sktlim@umich.edu                              uint64 uncompressed_trace_size);
1452683Sktlim@umich.edu
1462683Sktlim@umich.edu  private:
1472683Sktlim@umich.edu    // configuration parameters
1485999Snate@binkert.org    static int m_random_seed;
1498834Satgutier@umich.edu    static bool m_randomization;
1508834Satgutier@umich.edu    static uint32_t m_block_size_bytes;
1518834Satgutier@umich.edu    static uint32_t m_block_size_bits;
1528834Satgutier@umich.edu    static uint64_t m_memory_size_bytes;
1532683Sktlim@umich.edu    static uint32_t m_memory_size_bits;
1545999Snate@binkert.org
1552683Sktlim@umich.edu    Network* m_network_ptr;
1562683Sktlim@umich.edu    std::vector<MemoryControl *> m_memory_controller_vec;
1572683Sktlim@umich.edu    std::vector<AbstractController *> m_abs_cntrl_vec;
1582683Sktlim@umich.edu
1592683Sktlim@umich.edu  public:
1602683Sktlim@umich.edu    Profiler* m_profiler_ptr;
1612683Sktlim@umich.edu    MemoryVector* m_mem_vec_ptr;
1622683Sktlim@umich.edu    bool m_warmup_enabled;
1632683Sktlim@umich.edu    bool m_cooldown_enabled;
1642683Sktlim@umich.edu    CacheRecorder* m_cache_recorder;
1652683Sktlim@umich.edu    std::vector<SparseMemory*> m_sparse_memory_vector;
1662683Sktlim@umich.edu};
1673402Sktlim@umich.edu
1683402Sktlim@umich.eduinline std::ostream&
1693402Sktlim@umich.eduoperator<<(std::ostream& out, const RubySystem& obj)
1705714Shsul@eecs.umich.edu{
17111005Sandreas.sandberg@arm.com    //obj.print(out);
1725714Shsul@eecs.umich.edu    out << std::flush;
1732292SN/A    return out;
1746221Snate@binkert.org}
1752292SN/A
1762690Sktlim@umich.educlass RubyDumpStatsCallback : public Callback
1772683Sktlim@umich.edu{
1782683Sktlim@umich.edu  private:
1792292SN/A    std::ostream *os;
1802683Sktlim@umich.edu    RubySystem *ruby_system;
1812683Sktlim@umich.edu
1822292SN/A  public:
1832683Sktlim@umich.edu    virtual ~RubyDumpStatsCallback() {}
1842292SN/A
1852292SN/A    RubyDumpStatsCallback(const std::string& _stats_filename,
1862292SN/A                          RubySystem *system)
1872292SN/A    {
1882292SN/A        os = simout.create(_stats_filename);
18913905Sgabeblack@google.com        ruby_system = system;
1908777Sgblack@eecs.umich.edu    }
1912683Sktlim@umich.edu
1928229Snate@binkert.org    void process();
1938229Snate@binkert.org};
1948706Sandreas.hansson@arm.com
1952683Sktlim@umich.edu#endif // __MEM_RUBY_SYSTEM_SYSTEM_HH__
1968706Sandreas.hansson@arm.com