m5: improvements to the ruby_fs.py file
[gem5.git] / configs / example / ruby_fs.py
1 # Copyright (c) 2009 Advanced Micro Devices, Inc.
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met: redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer;
8 # redistributions in binary form must reproduce the above copyright
9 # notice, this list of conditions and the following disclaimer in the
10 # documentation and/or other materials provided with the distribution;
11 # neither the name of the copyright holders nor the names of its
12 # contributors may be used to endorse or promote products derived from
13 # this software without specific prior written permission.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #
27 # Authors: Brad Beckmann
28
29 #
30 # Full system configuraiton for ruby
31 #
32
33 import os
34 import optparse
35 import sys
36 from os.path import join as joinpath
37
38 import m5
39 from m5.defines import buildEnv
40 from m5.objects import *
41 from m5.util import addToPath, panic
42
43 if not buildEnv['FULL_SYSTEM']:
44 panic("This script requires full-system mode (*_FS).")
45
46 addToPath('../../tests/configs/')
47 addToPath('../common')
48
49 import ruby_config
50
51 from FSConfig import *
52 from SysPaths import *
53 from Benchmarks import *
54 import Simulation
55 from Caches import *
56
57 # Get paths we might need. It's expected this file is in m5/configs/example.
58 config_path = os.path.dirname(os.path.abspath(__file__))
59 config_root = os.path.dirname(config_path)
60 m5_root = os.path.dirname(config_root)
61
62 parser = optparse.OptionParser()
63
64 # Benchmark options
65 parser.add_option("-b", "--benchmark", action="store", type="string",
66 dest="benchmark",
67 help="Specify the benchmark to run. Available benchmarks: %s"\
68 % DefinedBenchmarks)
69 parser.add_option("-o", "--options", default="",
70 help='The options to pass to the binary, use " " around the entire string')
71 parser.add_option("-i", "--input", default="", help="Read stdin from a file.")
72 parser.add_option("--output", default="", help="Redirect stdout to a file.")
73 parser.add_option("--errout", default="", help="Redirect stderr to a file.")
74
75 # ruby options
76 parser.add_option("--ruby-debug", action="store_true")
77 parser.add_option("--ruby-debug-file", default="", help="Ruby debug out file (stdout if blank)")
78 parser.add_option("--protocol", default="", help="Ruby protocol compiled into binary")
79
80
81 # ruby host memory experimentation
82 parser.add_option("--cache_size", type="int")
83 parser.add_option("--cache_assoc", type="int")
84 parser.add_option("--map_levels", type="int")
85
86 execfile(os.path.join(config_root, "common", "Options.py"))
87
88 (options, args) = parser.parse_args()
89
90 if args:
91 print "Error: script doesn't take any positional arguments"
92 sys.exit(1)
93
94 if options.benchmark:
95 try:
96 bm = Benchmarks[options.benchmark]
97 except KeyError:
98 print "Error benchmark %s has not been defined." % options.benchmark
99 print "Valid benchmarks are: %s" % DefinedBenchmarks
100 sys.exit(1)
101 else:
102 bm = [SysConfig()]
103
104 #
105 # currently ruby fs only works in simple timing mode because ruby does not
106 # support atomic accesses by devices. Also ruby_fs currently assumes
107 # that is running a checkpoints that were created by ALPHA_FS under atomic
108 # mode. Since switch cpus are not defined in these checkpoints, we don't
109 # fast forward with the atomic cpu and instead set the FutureClass to None.
110 # Therefore the cpus resolve to the correct names and unserialize correctly.
111 #
112 assert(options.timing)
113 class CPUClass(TimingSimpleCPU): pass
114 test_mem_mode = 'timing'
115 FutureClass = None
116
117 CPUClass.clock = '1GHz'
118
119 #
120 # Since we are running in timing mode, set the number of M5 ticks to ruby ticks
121 # to the cpu clock frequency
122 #
123 M5_to_ruby_tick = '1000t'
124
125 np = options.num_cpus
126
127 # check for max instruction count
128 if options.max_inst:
129 max_inst = options.max_inst
130 else:
131 max_inst = 0
132
133 # set cache size
134 if options.cache_size:
135 cache_size = options.cache_size
136 else:
137 cache_size = 32768 # 32 kB is default
138
139 # set cache assoc
140 if options.cache_assoc:
141 cache_assoc = options.cache_assoc
142 else:
143 cache_assoc = 8 # 8 is default
144
145 # set map levels
146 if options.map_levels:
147 map_levels = options.map_levels
148 else:
149 map_levels = 4 # 4 levels is the default
150
151 if options.protocol == "MOESI_hammer":
152 ruby_config_file = "MOESI_hammer-homogeneous.rb"
153 elif options.protocol == "MOESI_CMP_token":
154 ruby_config_file = "TwoLevel_SplitL1UnifiedL2.rb"
155 elif options.protocol == "MI_example":
156 ruby_config_file = "MI_example-homogeneous.rb"
157 else:
158 print "Error: unsupported ruby protocol"
159 sys.exit(1)
160
161 #
162 # Currently, since ruby configuraiton is separate from m5, we need to manually
163 # tell ruby that two dma ports are created by makeLinuxAlphaRubySystem().
164 # Eventually, this will be fix with a unified configuration system.
165 #
166 rubymem = ruby_config.generate(ruby_config_file,
167 np,
168 np,
169 128,
170 False,
171 cache_size,
172 cache_assoc,
173 map_levels,
174 2,
175 M5_to_ruby_tick)
176
177 if options.ruby_debug == True:
178 rubymem.debug = True
179 rubymem.debug_file = options.ruby_debug_file
180
181 system = makeLinuxAlphaRubySystem(test_mem_mode, rubymem, bm[0])
182
183 system.cpu = [CPUClass(cpu_id=i) for i in xrange(np)]
184
185 if options.l2cache:
186 print "Error: -l2cache incompatible with ruby, must configure it ruby-style"
187 sys.exit(1)
188
189 if options.caches:
190 print "Error: -caches incompatible with ruby, must configure it ruby-style"
191 sys.exit(1)
192
193 for i in xrange(np):
194 system.cpu[i].connectMemPorts(system.physmem)
195
196 if options.fastmem:
197 system.cpu[i].physmem_port = system.physmem.port
198
199 root = Root(system = system)
200
201 Simulation.run(options, root, system, FutureClass)