summaryrefslogtreecommitdiff
path: root/src/mem/ruby/init.cc
blob: e230bb5916b87a9d510538882e15f2437fa546ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304

/*
 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met: redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer;
 * redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution;
 * neither the name of the copyright holders nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * init.C
 *
 * Description: See init.h
 *
 * $Id$
 *
 */

#include "Global.hh"
#include "EventQueue.hh"
#include "System.hh"
#include "Debug.hh"
#include "Profiler.hh"
#include "Tester.hh"
#include "OpalInterface.hh"
#include "init.hh"
#include "interface.hh"

#ifdef CONTIGUOUS_ADDRESSES
#include "ContiguousAddressTranslator.hh"

/* Declared in interface.C */
extern ContiguousAddressTranslator * g_p_ca_translator;

#endif // #ifdef CONTIGUOUS_ADDRESSES

using namespace std;
#include <string>
#include <map>
#include <stdlib.h>

// Maurice
// extern "C" {
// #include "simics/api.hh"
// };

#include "FakeSimicsDataTypes.hh"

#include "confio.hh"
#include "initvar.hh"

// A generated file containing the default parameters in string form
// The defaults are stored in the variable global_default_param
#include "default_param.hh"

attr_value_t ruby_session_get( void *id, void *obj,
                               attr_value_t *idx ) {
  attr_value_t ret;

  // all session attributes default to return invalid
  ret.kind = Sim_Val_Invalid;
  return ret;
}

set_error_t ruby_session_set( void *id, void *obj,
                              attr_value_t *val, attr_value_t *idx ) {
  const char *command = (const char *) id;
  // Add new ruby commands to this function

#if 0 // Eventually add these commands back in
  if (!strcmp(command, "dump-stats" ) ) {
    char* filename = (char*) val->u.string;
    if(strcmp(filename, "")){
      ruby_dump_stats(filename);
    } else {
      ruby_dump_stats(NULL);
    }
    return Sim_Set_Ok;
  } else if (!strcmp(command, "dump-short-stats" ) ) {
    char* filename = (char*) val->u.string;
    if(strcmp(filename, "")){
      ruby_dump_short_stats(filename);
    } else {
      ruby_dump_short_stats(NULL);
    }
    return Sim_Set_Ok;
  } else if (!strcmp(command, "periodic-stats-file" ) ) {
    char* filename = (char*) val->u.string;
    ruby_set_periodic_stats_file(filename);
    return Sim_Set_Ok;
  } else if (!strcmp(command, "periodic-stats-interval" ) ) {
    int interval = val->u.integer;
    ruby_set_periodic_stats_interval(interval);
    return Sim_Set_Ok;
  } else if (!strcmp(command, "clear-stats" ) ) {
    ruby_clear_stats();
    return Sim_Set_Ok;
  } else if (!strcmp(command, "debug-verb" ) ) {
    char* new_verbosity = (char*) val->u.string;
    ruby_change_debug_verbosity(new_verbosity);
    return Sim_Set_Ok;
  } else if (!strcmp(command, "debug-filter" ) ) {
    char* new_debug_filter = (char*) val->u.string;
    ruby_change_debug_filter(new_debug_filter);
    return Sim_Set_Ok;
  } else if (!strcmp(command, "debug-output-file" ) ) {
    char* new_filename = (char*) val->u.string;
    ruby_set_debug_output_file(new_filename);
    return Sim_Set_Ok;
  } else if (!strcmp(command, "debug-start-time" ) ) {
    char* new_start_time = (char*) val->u.string;
    ruby_set_debug_start_time(new_start_time);
    return Sim_Set_Ok;
  } else if (!strcmp(command, "load-caches" ) ) {
    char* filename = (char*) val->u.string;
    ruby_load_caches(filename);
    return Sim_Set_Ok;
  } else if (!strcmp(command, "save-caches" ) ) {
    char* filename = (char*) val->u.string;
    ruby_save_caches(filename);
    return Sim_Set_Ok;
  } else if (!strcmp(command, "dump-cache" ) ) {
    int cpuNumber = val->u.integer;
    ruby_dump_cache(cpuNumber);
    return Sim_Set_Ok;
  } else if (!strcmp(command, "dump-cache-data" ) ) {
    int   cpuNumber = val->u.list.vector[0].u.integer;
    char *filename  = (char*) val->u.list.vector[1].u.string;
    ruby_dump_cache_data( cpuNumber, filename );
    return Sim_Set_Ok;
  } else if (!strcmp(command, "tracer-output-file" ) ) {
    char* new_filename = (char*) val->u.string;
    ruby_set_tracer_output_file(new_filename);
    return Sim_Set_Ok;
  } else if (!strcmp(command, "xact-visualizer-file" ) ) {
    char* new_filename = (char*) val->u.string;
    ruby_xact_visualizer_file(new_filename);
    return Sim_Set_Ok;
  }
  fprintf( stderr, "error: unrecognized command: %s\n", command );
#endif
  return Sim_Set_Illegal_Value;
}

static  initvar_t  *ruby_initvar_obj = NULL;

//***************************************************************************
static void init_generate_values( void )
{
  /* update generated values, based on input configuration */
}

//***************************************************************************
void init_variables( void )
{
  // allocate the "variable initialization" package
  ruby_initvar_obj = new initvar_t( "ruby", "../../../ruby/",
                                    global_default_param,
                                    &init_simulator,
                                    &init_generate_values,
                                    &ruby_session_get,
                                    &ruby_session_set );
}

void init_simulator()
{
  // Set things to NULL to make sure we don't de-reference them
  // without a seg. fault.
  g_system_ptr = NULL;
  g_debug_ptr = NULL;
  g_eventQueue_ptr = NULL;

  cout << "Ruby Timing Mode" << endl;

  if (g_SIMICS) {
    // LUKE - if we don't set the default SMT threads in condor scripts,
    //        set it now
    if(g_NUM_SMT_THREADS == 0){
      g_NUM_SMT_THREADS = 1;
    }
   if(g_NUM_PROCESSORS == 0){
     //only set to default if value not set in condor scripts
     //  Account for SMT systems also
      g_NUM_PROCESSORS = SIMICS_number_processors()/g_NUM_SMT_THREADS;
    }
  }

  RubyConfig::init();

  g_debug_ptr = new Debug( DEBUG_FILTER_STRING,
                           DEBUG_VERBOSITY_STRING,
                           DEBUG_START_TIME,
                           DEBUG_OUTPUT_FILENAME );

  cout << "Creating event queue..." << endl;
  g_eventQueue_ptr = new EventQueue;
  cout << "Creating event queue done" << endl;

  cout << "Creating system..." << endl;
  cout << "  Processors: " << RubyConfig::numberOfProcessors() << endl;

  g_system_ptr = new RubySystem;
  cout << "Creating system done" << endl;

  // if opal is loaded, its static interface object (inst) will be non-null,
  // and the opal object needs to be notified that ruby is now loaded.
  // "1" indicates a load and should be replaced with an enumerated type.
  if (OpalInterface::inst != NULL) {
    OpalInterface::inst->notify( 1 );
  }

#ifdef CONTIGUOUS_ADDRESSES
  if(g_SIMICS) {
    cout << "Establishing Contiguous Address Space Mappings..." << flush;
    g_p_ca_translator = new ContiguousAddressTranslator();
    assert(g_p_ca_translator!=NULL);
    if(g_p_ca_translator->AddressesAreContiguous()) {
      cout << "Physical Memory Addresses are already contiguous." << endl;
      delete g_p_ca_translator;
      g_p_ca_translator = NULL;
    } else {
      cout << "Done." << endl;
    }
  } else {
    g_p_ca_translator = NULL;
  }
#endif // #ifdef CONTIGUOUS_ADDRESSES

  cout << "Ruby initialization complete" << endl;
}

void init_opal_interface( mf_ruby_api_t *api )
{
  OpalInterface::installInterface( api );
}

int init_use_snoop()
{
  if (g_SIMICS) {
    // The "snoop interface" defined by simics allows ruby to see store
    // data values (from simics). If DATA_BLOCK is defined, we are tracking
    // data, so we need to install the snoop interface.
    return ((DATA_BLOCK == true) || (XACT_MEMORY));
  } else {
    return (0);
  }
}

void destroy_simulator()
{
  cout << "Deleting system..." << endl;
  delete g_system_ptr;
  cout << "Deleting system done" << endl;

  cout << "Deleting event queue..." << endl;
  delete g_eventQueue_ptr;
  cout << "Deleting event queue done" << endl;

  delete g_debug_ptr;
}

/*-------------------------------------------------------------------------+
 | DG: These are the external load and unload hooks that will be called by |
 | M5 in phase 1 integration, and possibly afterwards, too.                |
 +-------------------------------------------------------------------------*/

extern "C"
int OnLoadRuby() {
  init_variables();
  return 0;
}

extern "C"
int OnInitRuby() {
  init_simulator();
  return 0;
}

extern "C"
int OnUnloadRuby() {
  destroy_simulator();
  return 0;
}