RubySystem.hh revision 6895
1
2/*
3 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/*
31 * System.hh
32 *
33 * Description: Contains all of the various parts of the system we are
34 * simulating.  Performs allocation, deallocation, and setup of all
35 * the major components of the system
36 *
37 * $Id$
38 *
39 */
40
41#ifndef SYSTEM_H
42#define SYSTEM_H
43
44#include "mem/ruby/system/RubyPort.hh"
45#include "mem/ruby/common/Global.hh"
46#include "mem/gems_common/Vector.hh"
47#include "mem/ruby/eventqueue/RubyEventQueue.hh"
48#include <map>
49#include "sim/sim_object.hh"
50#include "params/RubySystem.hh"
51#include "base/callback.hh"
52
53class Profiler;
54class Network;
55class CacheRecorder;
56class Tracer;
57class Sequencer;
58class DMASequencer;
59class MemoryVector;
60class AbstractController;
61class MessageBuffer;
62class CacheMemory;
63class DirectoryMemory;
64class Topology;
65class MemoryControl;
66
67/*
68 * This defines the number of longs (32-bits on 32 bit machines,
69 * 64-bit on 64-bit AMD machines) to use to hold the set...
70 * the default is 4, allowing 128 or 256 different members
71 * of the set.
72 *
73 * This should never need to be changed for correctness reasons,
74 * though increasing it will increase performance for larger
75 * set sizes at the cost of a (much) larger memory footprint
76 *
77 */
78const int NUMBER_WORDS_PER_SET = 4;
79
80
81struct RubyObjConf {
82  string type;
83  string name;
84  vector<string> argv;
85  RubyObjConf(string _type, string _name, vector<string> _argv)
86    : type(_type), name(_name), argv(_argv)
87  {}
88};
89
90class RubySystem : public SimObject {
91public:
92    typedef RubySystemParams Params;
93    RubySystem(const Params *p);
94  // Destructor
95  ~RubySystem();
96
97  // config accessors
98  static int getRandomSeed() { return m_random_seed; }
99  static int getRandomization() { return m_randomization; }
100  static int getBlockSizeBytes() { return m_block_size_bytes; }
101  static int getBlockSizeBits() { return m_block_size_bits; }
102  static uint64 getMemorySizeBytes() { return m_memory_size_bytes; }
103  static int getMemorySizeBits() { return m_memory_size_bits; }
104
105  // Public Methods
106  static RubyPort* getPortOnly(const string & name) {
107    assert(m_ports.count(name) == 1); return m_ports[name]; }
108  static RubyPort* getPort(const string & name, void (*hit_callback)(int64_t)) {
109    if (m_ports.count(name) != 1){
110      cerr << "Port " << name << " has " << m_ports.count(name) << " instances" << endl;
111    }
112    assert(m_ports.count(name) == 1);
113    m_ports[name]->registerHitCallback(hit_callback);
114    return m_ports[name];
115  }
116  static Network* getNetwork() { assert(m_network_ptr != NULL); return m_network_ptr; }
117  static Topology* getTopology(const string & name) { assert(m_topologies.count(name) == 1); return m_topologies[name]; }
118  static CacheMemory* getCache(const string & name) { assert(m_caches.count(name) == 1); return m_caches[name]; }
119  static DirectoryMemory* getDirectory(const string & name) { assert(m_directories.count(name) == 1); return m_directories[name]; }
120  static MemoryControl* getMemoryControl(const string & name) { assert(m_memorycontrols.count(name) == 1); return m_memorycontrols[name]; }
121  static Sequencer* getSequencer(const string & name) { assert(m_sequencers.count(name) == 1); return m_sequencers[name]; }
122  static DMASequencer* getDMASequencer(const string & name) { assert(m_dma_sequencers.count(name) == 1); return m_dma_sequencers[name]; }
123  static AbstractController* getController(const string & name) { assert(m_controllers.count(name) == 1); return m_controllers[name]; }
124
125  static RubyEventQueue* getEventQueue() { return g_eventQueue_ptr; }
126
127  static int getNumberOfDirectories() { return m_directories.size(); }
128  static int getNumberOfSequencers() { return m_sequencers.size(); }
129
130  Profiler* getProfiler() {assert(m_profiler_ptr != NULL); return m_profiler_ptr; }
131  static Tracer* getTracer() { assert(m_tracer_ptr != NULL); return m_tracer_ptr; }
132  static MemoryVector* getMemoryVector() { assert(m_mem_vec_ptr != NULL); return m_mem_vec_ptr;}
133
134  void recordCacheContents(CacheRecorder& tr) const;
135  static void printConfig(ostream& out);
136  static void printStats(ostream& out);
137  void clearStats() const;
138
139  uint64 getInstructionCount(int thread) { return 1; }
140  static uint64 getCycleCount(int thread) { return g_eventQueue_ptr->getTime(); }
141
142  void print(ostream& out) const;
143  /*
144#ifdef CHECK_COHERENCE
145  void checkGlobalCoherenceInvariant(const Address& addr);
146#endif
147  */
148
149private:
150  // Constructors
151  RubySystem(const vector <RubyObjConf> & cfg_file);
152
153  // Private copy constructor and assignment operator
154  RubySystem(const RubySystem& obj);
155  RubySystem& operator=(const RubySystem& obj);
156
157  void init();
158
159  static void printSystemConfig(ostream& out);
160
161private:
162  // configuration parameters
163  static int m_random_seed;
164  static bool m_randomization;
165  static Tick m_clock;
166  static int m_block_size_bytes;
167  static int m_block_size_bits;
168  static uint64 m_memory_size_bytes;
169  static int m_memory_size_bits;
170
171  // Data Members (m_ prefix)
172  static Network* m_network_ptr;
173  static map< string, Topology* > m_topologies;
174  static map< string, RubyPort* > m_ports;
175  static map< string, CacheMemory* > m_caches;
176  static map< string, DirectoryMemory* > m_directories;
177  static map< string, Sequencer* > m_sequencers;
178  static map< string, DMASequencer* > m_dma_sequencers;
179  static map< string, AbstractController* > m_controllers;
180  static map< string, MemoryControl* > m_memorycontrols;
181
182  //added by SS
183  //static map< string, Tracer* > m_tracers;
184
185public:
186  static Profiler* m_profiler_ptr;
187  static Tracer* m_tracer_ptr;
188  static MemoryVector* m_mem_vec_ptr;
189};
190
191// Output operator declaration
192ostream& operator<<(ostream& out, const RubySystem& obj);
193
194// ******************* Definitions *******************
195
196// Output operator definition
197inline
198ostream& operator<<(ostream& out, const RubySystem& obj)
199{
200//  obj.print(out);
201  out << flush;
202  return out;
203}
204
205class RubyExitCallback : public Callback
206{
207  private:
208    string stats_filename;
209
210  public:
211    /**
212     * virtualize the destructor to make sure that the correct one
213     * gets called.
214     */
215
216    virtual ~RubyExitCallback() {}
217
218    RubyExitCallback(const string& _stats_filename)
219    {
220      stats_filename = _stats_filename;
221    }
222
223    virtual void process();
224};
225
226#endif //SYSTEM_H
227
228
229
230