RubySystem.hh revision 10301
1955SN/A/*
2955SN/A * Copyright (c) 1999-2012 Mark D. Hill and David A. Wood
31762SN/A * All rights reserved.
4955SN/A *
5955SN/A * Redistribution and use in source and binary forms, with or without
6955SN/A * modification, are permitted provided that the following conditions are
7955SN/A * met: redistributions of source code must retain the above copyright
8955SN/A * notice, this list of conditions and the following disclaimer;
9955SN/A * redistributions in binary form must reproduce the above copyright
10955SN/A * notice, this list of conditions and the following disclaimer in the
11955SN/A * documentation and/or other materials provided with the distribution;
12955SN/A * neither the name of the copyright holders nor the names of its
13955SN/A * contributors may be used to endorse or promote products derived from
14955SN/A * this software without specific prior written permission.
15955SN/A *
16955SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17955SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18955SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19955SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20955SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21955SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22955SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23955SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24955SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25955SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26955SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27955SN/A */
282665Ssaidi@eecs.umich.edu
294762Snate@binkert.org/*
30955SN/A * Contains all of the various parts of the system we are simulating.
315522Snate@binkert.org * Performs allocation, deallocation, and setup of all the major
326143Snate@binkert.org * components of the system
334762Snate@binkert.org */
345522Snate@binkert.org
35955SN/A#ifndef __MEM_RUBY_SYSTEM_SYSTEM_HH__
365522Snate@binkert.org#define __MEM_RUBY_SYSTEM_SYSTEM_HH__
37955SN/A
385522Snate@binkert.org#include "base/callback.hh"
394202Sbinkertn@umich.edu#include "base/output.hh"
405742Snate@binkert.org#include "mem/ruby/profiler/Profiler.hh"
41955SN/A#include "mem/ruby/slicc_interface/AbstractController.hh"
424381Sbinkertn@umich.edu#include "mem/ruby/structures/MemoryControl.hh"
434381Sbinkertn@umich.edu#include "mem/ruby/structures/MemoryVector.hh"
44955SN/A#include "mem/ruby/structures/SparseMemory.hh"
45955SN/A#include "mem/ruby/system/CacheRecorder.hh"
46955SN/A#include "mem/packet.hh"
474202Sbinkertn@umich.edu#include "params/RubySystem.hh"
48955SN/A#include "sim/clocked_object.hh"
494382Sbinkertn@umich.edu
504382Sbinkertn@umich.educlass Network;
514382Sbinkertn@umich.edu
526654Snate@binkert.orgclass RubySystem : public ClockedObject
535517Snate@binkert.org{
547674Snate@binkert.org  public:
557674Snate@binkert.org    class RubyEvent : public Event
566143Snate@binkert.org    {
576143Snate@binkert.org      public:
586143Snate@binkert.org        RubyEvent(RubySystem* _ruby_system)
596143Snate@binkert.org        {
606143Snate@binkert.org            ruby_system = _ruby_system;
616143Snate@binkert.org        }
626143Snate@binkert.org      private:
636143Snate@binkert.org        void process();
646143Snate@binkert.org
656143Snate@binkert.org        RubySystem* ruby_system;
666143Snate@binkert.org    };
676143Snate@binkert.org
686143Snate@binkert.org    friend class RubyEvent;
696143Snate@binkert.org
706143Snate@binkert.org    typedef RubySystemParams Params;
714762Snate@binkert.org    RubySystem(const Params *p);
726143Snate@binkert.org    ~RubySystem();
736143Snate@binkert.org
746143Snate@binkert.org    // config accessors
756143Snate@binkert.org    static int getRandomSeed() { return m_random_seed; }
766143Snate@binkert.org    static int getRandomization() { return m_randomization; }
776143Snate@binkert.org    static uint32_t getBlockSizeBytes() { return m_block_size_bytes; }
786143Snate@binkert.org    static uint32_t getBlockSizeBits() { return m_block_size_bits; }
796143Snate@binkert.org    static uint64_t getMemorySizeBytes() { return m_memory_size_bytes; }
806143Snate@binkert.org    static uint32_t getMemorySizeBits() { return m_memory_size_bits; }
816143Snate@binkert.org
826143Snate@binkert.org    // Public Methods
836143Snate@binkert.org    Profiler*
846143Snate@binkert.org    getProfiler()
856143Snate@binkert.org    {
866143Snate@binkert.org        assert(m_profiler != NULL);
876143Snate@binkert.org        return m_profiler;
886143Snate@binkert.org    }
896143Snate@binkert.org
906143Snate@binkert.org    MemoryVector*
916143Snate@binkert.org    getMemoryVector()
926143Snate@binkert.org    {
937065Snate@binkert.org        assert(m_mem_vec != NULL);
946143Snate@binkert.org        return m_mem_vec;
956143Snate@binkert.org    }
966143Snate@binkert.org
976143Snate@binkert.org    void regStats() { m_profiler->regStats(name()); }
986143Snate@binkert.org    void collateStats() { m_profiler->collateStats(); }
996143Snate@binkert.org    void resetStats();
1006143Snate@binkert.org
1016143Snate@binkert.org    void serialize(std::ostream &os);
1026143Snate@binkert.org    void unserialize(Checkpoint *cp, const std::string &section);
1036143Snate@binkert.org    void process();
1046143Snate@binkert.org    void startup();
1056143Snate@binkert.org    bool functionalRead(Packet *ptr);
1066143Snate@binkert.org    bool functionalWrite(Packet *ptr);
1076143Snate@binkert.org
1086143Snate@binkert.org    void registerNetwork(Network*);
1096143Snate@binkert.org    void registerAbstractController(AbstractController*);
1106143Snate@binkert.org    void registerSparseMemory(SparseMemory*);
1116143Snate@binkert.org    void registerMemController(MemoryControl *mc);
1126143Snate@binkert.org
1136143Snate@binkert.org    bool eventQueueEmpty() { return eventq->empty(); }
1146143Snate@binkert.org    void enqueueRubyEvent(Tick tick)
1155522Snate@binkert.org    {
1166143Snate@binkert.org        RubyEvent* e = new RubyEvent(this);
1176143Snate@binkert.org        schedule(e, tick);
1186143Snate@binkert.org    }
1196143Snate@binkert.org
1206143Snate@binkert.org  private:
1216143Snate@binkert.org    // Private copy constructor and assignment operator
1226143Snate@binkert.org    RubySystem(const RubySystem& obj);
1236143Snate@binkert.org    RubySystem& operator=(const RubySystem& obj);
1246143Snate@binkert.org
1256143Snate@binkert.org    void readCompressedTrace(std::string filename,
1265522Snate@binkert.org                             uint8_t *&raw_data,
1275522Snate@binkert.org                             uint64& uncompressed_trace_size);
1285522Snate@binkert.org    void writeCompressedTrace(uint8_t *raw_data, std::string file,
1295522Snate@binkert.org                              uint64 uncompressed_trace_size);
1305604Snate@binkert.org
1315604Snate@binkert.org  private:
1326143Snate@binkert.org    // configuration parameters
1336143Snate@binkert.org    static int m_random_seed;
1344762Snate@binkert.org    static bool m_randomization;
1354762Snate@binkert.org    static uint32_t m_block_size_bytes;
1366143Snate@binkert.org    static uint32_t m_block_size_bits;
1376727Ssteve.reinhardt@amd.com    static uint64_t m_memory_size_bytes;
1386727Ssteve.reinhardt@amd.com    static uint32_t m_memory_size_bits;
1396727Ssteve.reinhardt@amd.com
1404762Snate@binkert.org    Network* m_network;
1416143Snate@binkert.org    std::vector<MemoryControl *> m_memory_controller_vec;
1426143Snate@binkert.org    std::vector<AbstractController *> m_abs_cntrl_vec;
1436143Snate@binkert.org
1446143Snate@binkert.org  public:
1456727Ssteve.reinhardt@amd.com    Profiler* m_profiler;
1466143Snate@binkert.org    MemoryVector* m_mem_vec;
1477674Snate@binkert.org    bool m_warmup_enabled;
1487674Snate@binkert.org    bool m_cooldown_enabled;
1495604Snate@binkert.org    CacheRecorder* m_cache_recorder;
1506143Snate@binkert.org    std::vector<SparseMemory*> m_sparse_memory_vector;
1516143Snate@binkert.org};
1526143Snate@binkert.org
1534762Snate@binkert.orgclass RubyStatsCallback : public Callback
1546143Snate@binkert.org{
1554762Snate@binkert.org  private:
1564762Snate@binkert.org    RubySystem *ruby_system;
1574762Snate@binkert.org
1586143Snate@binkert.org  public:
1596143Snate@binkert.org    virtual ~RubyStatsCallback() {}
1604762Snate@binkert.org    RubyStatsCallback(RubySystem *system) : ruby_system(system) {}
1616143Snate@binkert.org    void process() { ruby_system->collateStats(); }
1626143Snate@binkert.org};
1636143Snate@binkert.org
1646143Snate@binkert.org#endif // __MEM_RUBY_SYSTEM_SYSTEM_HH__
1654762Snate@binkert.org