RubySystem.hh revision 8436
112837Sgabeblack@google.com/*
212837Sgabeblack@google.com * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
312837Sgabeblack@google.com * All rights reserved.
412837Sgabeblack@google.com *
512837Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
612837Sgabeblack@google.com * modification, are permitted provided that the following conditions are
712837Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
812837Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
912837Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
1012837Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1112837Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1212837Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1312837Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1412837Sgabeblack@google.com * this software without specific prior written permission.
1512837Sgabeblack@google.com *
1612837Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1712837Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1812837Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1912837Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2012837Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2112837Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2212837Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2312837Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2412837Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2512837Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2612837Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2712837Sgabeblack@google.com */
2812837Sgabeblack@google.com
2912837Sgabeblack@google.com/*
3012837Sgabeblack@google.com * Contains all of the various parts of the system we are simulating.
3113081Sgabeblack@google.com * Performs allocation, deallocation, and setup of all the major
3212837Sgabeblack@google.com * components of the system
3312862Sgabeblack@google.com */
3412837Sgabeblack@google.com
3512862Sgabeblack@google.com#ifndef __MEM_RUBY_SYSTEM_SYSTEM_HH__
3612956Sgabeblack@google.com#define __MEM_RUBY_SYSTEM_SYSTEM_HH__
3712862Sgabeblack@google.com
3812837Sgabeblack@google.com#include "base/callback.hh"
3912982Sgabeblack@google.com#include "mem/ruby/common/Global.hh"
4013038Sgabeblack@google.com#include "mem/ruby/eventqueue/RubyEventQueue.hh"
4112956Sgabeblack@google.com#include "mem/ruby/system/RubyPort.hh"
4212837Sgabeblack@google.com#include "mem/ruby/slicc_interface/AbstractController.hh"
4312861Sgabeblack@google.com#include "params/RubySystem.hh"
4412837Sgabeblack@google.com#include "sim/sim_object.hh"
4512949Sgabeblack@google.com
4612949Sgabeblack@google.comclass AbstractController;
4712837Sgabeblack@google.comclass AbstractMemory;
4812837Sgabeblack@google.comclass CacheRecorder;
4912837Sgabeblack@google.comclass MemoryVector;
5012837Sgabeblack@google.comclass Network;
5112837Sgabeblack@google.comclass Profiler;
5212837Sgabeblack@google.comclass Tracer;
5312837Sgabeblack@google.com
5412837Sgabeblack@google.com/*
5512837Sgabeblack@google.com * This defines the number of longs (32-bits on 32 bit machines,
5612837Sgabeblack@google.com * 64-bit on 64-bit AMD machines) to use to hold the set...
5712837Sgabeblack@google.com * the default is 4, allowing 128 or 256 different members
5812837Sgabeblack@google.com * of the set.
5912862Sgabeblack@google.com *
6012862Sgabeblack@google.com * This should never need to be changed for correctness reasons,
6113081Sgabeblack@google.com * though increasing it will increase performance for larger
6213081Sgabeblack@google.com * set sizes at the cost of a (much) larger memory footprint
6313081Sgabeblack@google.com *
6413081Sgabeblack@google.com */
6513081Sgabeblack@google.comconst int NUMBER_WORDS_PER_SET = 1;
6613081Sgabeblack@google.com
6712862Sgabeblack@google.comclass RubySystem : public SimObject
6812862Sgabeblack@google.com{
6912862Sgabeblack@google.com  public:
7012949Sgabeblack@google.com    typedef RubySystemParams Params;
7113081Sgabeblack@google.com    RubySystem(const Params *p);
7213081Sgabeblack@google.com    ~RubySystem();
7313081Sgabeblack@google.com
7413081Sgabeblack@google.com    // config accessors
7513081Sgabeblack@google.com    static int getRandomSeed() { return m_random_seed; }
7613081Sgabeblack@google.com    static int getRandomization() { return m_randomization; }
7713081Sgabeblack@google.com    static int getBlockSizeBytes() { return m_block_size_bytes; }
7813081Sgabeblack@google.com    static int getBlockSizeBits() { return m_block_size_bits; }
7913081Sgabeblack@google.com    static uint64 getMemorySizeBytes() { return m_memory_size_bytes; }
8013081Sgabeblack@google.com    static int getMemorySizeBits() { return m_memory_size_bits; }
8113081Sgabeblack@google.com
8213081Sgabeblack@google.com    // Public Methods
8313077Sgabeblack@google.com    static Network*
8413077Sgabeblack@google.com    getNetwork()
8512949Sgabeblack@google.com    {
8612949Sgabeblack@google.com        assert(m_network_ptr != NULL);
8712949Sgabeblack@google.com        return m_network_ptr;
8812949Sgabeblack@google.com    }
8912862Sgabeblack@google.com
9012862Sgabeblack@google.com    static RubyEventQueue*
9112862Sgabeblack@google.com    getEventQueue()
9212862Sgabeblack@google.com    {
9312862Sgabeblack@google.com        return g_eventQueue_ptr;
9412837Sgabeblack@google.com    }
9512837Sgabeblack@google.com
9612837Sgabeblack@google.com    Profiler*
9712837Sgabeblack@google.com    getProfiler()
9812837Sgabeblack@google.com    {
9912837Sgabeblack@google.com        assert(m_profiler_ptr != NULL);
10012837Sgabeblack@google.com        return m_profiler_ptr;
10112837Sgabeblack@google.com    }
10212837Sgabeblack@google.com
10312837Sgabeblack@google.com    static Tracer*
10412837Sgabeblack@google.com    getTracer()
10512837Sgabeblack@google.com    {
10612837Sgabeblack@google.com        assert(m_tracer_ptr != NULL);
10712837Sgabeblack@google.com        return m_tracer_ptr;
10812837Sgabeblack@google.com    }
10912837Sgabeblack@google.com
11012837Sgabeblack@google.com    static MemoryVector*
11112837Sgabeblack@google.com    getMemoryVector()
11212837Sgabeblack@google.com    {
11312837Sgabeblack@google.com        assert(m_mem_vec_ptr != NULL);
11412837Sgabeblack@google.com        return m_mem_vec_ptr;
11512837Sgabeblack@google.com    }
11612837Sgabeblack@google.com
11712837Sgabeblack@google.com    void recordCacheContents(CacheRecorder& tr) const;
11812837Sgabeblack@google.com    static void printConfig(std::ostream& out);
11912837Sgabeblack@google.com    static void printStats(std::ostream& out);
12012837Sgabeblack@google.com    void clearStats() const;
12112837Sgabeblack@google.com
12212837Sgabeblack@google.com    uint64 getInstructionCount(int thread) { return 1; }
12312837Sgabeblack@google.com    static uint64
12412837Sgabeblack@google.com    getCycleCount(int thread)
12512837Sgabeblack@google.com    {
12612837Sgabeblack@google.com        return g_eventQueue_ptr->getTime();
12712837Sgabeblack@google.com    }
12812837Sgabeblack@google.com
12912837Sgabeblack@google.com    void print(std::ostream& out) const;
13012837Sgabeblack@google.com
13112862Sgabeblack@google.com    virtual void serialize(std::ostream &os);
13212837Sgabeblack@google.com    virtual void unserialize(Checkpoint *cp, const std::string &section);
13312837Sgabeblack@google.com
13413081Sgabeblack@google.com    void registerNetwork(Network*);
13513081Sgabeblack@google.com    void registerProfiler(Profiler*);
13613081Sgabeblack@google.com    void registerTracer(Tracer*);
13713081Sgabeblack@google.com    void registerAbstractMemory(AbstractMemory*);
13813081Sgabeblack@google.com    void registerAbstractController(AbstractController*);
13913081Sgabeblack@google.com
14013081Sgabeblack@google.com  private:
14113081Sgabeblack@google.com    // Private copy constructor and assignment operator
14213081Sgabeblack@google.com    RubySystem(const RubySystem& obj);
14313081Sgabeblack@google.com    RubySystem& operator=(const RubySystem& obj);
14413081Sgabeblack@google.com
14513081Sgabeblack@google.com    void init();
14612837Sgabeblack@google.com
14712837Sgabeblack@google.com    static void printSystemConfig(std::ostream& out);
14813038Sgabeblack@google.com
14913038Sgabeblack@google.com  private:
15012837Sgabeblack@google.com    // configuration parameters
15113038Sgabeblack@google.com    static int m_random_seed;
15213038Sgabeblack@google.com    static bool m_randomization;
15313038Sgabeblack@google.com    static Tick m_clock;
15413038Sgabeblack@google.com    static int m_block_size_bytes;
15513081Sgabeblack@google.com    static int m_block_size_bits;
15613081Sgabeblack@google.com    static uint64 m_memory_size_bytes;
15713038Sgabeblack@google.com    static int m_memory_size_bits;
15813038Sgabeblack@google.com
15912837Sgabeblack@google.com    static Network* m_network_ptr;
16012861Sgabeblack@google.com
16112861Sgabeblack@google.com  public:
16212837Sgabeblack@google.com    static Profiler* m_profiler_ptr;
16312837Sgabeblack@google.com    static Tracer* m_tracer_ptr;
16412837Sgabeblack@google.com    static MemoryVector* m_mem_vec_ptr;
16512837Sgabeblack@google.com    std::vector<AbstractController*> m_abs_cntrl_vec;
16612837Sgabeblack@google.com};
16712837Sgabeblack@google.com
16812837Sgabeblack@google.cominline std::ostream&
16912837Sgabeblack@google.comoperator<<(std::ostream& out, const RubySystem& obj)
17012837Sgabeblack@google.com{
17112837Sgabeblack@google.com    //obj.print(out);
17212837Sgabeblack@google.com    out << std::flush;
17312837Sgabeblack@google.com    return out;
17412837Sgabeblack@google.com}
17512837Sgabeblack@google.com
17612860Sgabeblack@google.comclass RubyExitCallback : public Callback
17712860Sgabeblack@google.com{
17812860Sgabeblack@google.com  private:
17912962Sgabeblack@google.com    std::string stats_filename;
18012961Sgabeblack@google.com
18112860Sgabeblack@google.com  public:
18212860Sgabeblack@google.com    virtual ~RubyExitCallback() {}
18312860Sgabeblack@google.com
18412860Sgabeblack@google.com    RubyExitCallback(const std::string& _stats_filename)
18512860Sgabeblack@google.com    {
18612990Sgabeblack@google.com        stats_filename = _stats_filename;
18712961Sgabeblack@google.com    }
18812860Sgabeblack@google.com
18912860Sgabeblack@google.com    virtual void process();
19012860Sgabeblack@google.com};
19112860Sgabeblack@google.com
19212860Sgabeblack@google.com#endif // __MEM_RUBY_SYSTEM_SYSTEM_HH__
19313061Sgabeblack@google.com