Config: Move setWorkCountOptions() to Simulation.py
[gem5.git] / configs / example / ruby_fs.py
1 # Copyright (c) 2009-2011 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 optparse
34 import os
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, fatal
42
43 addToPath('../common')
44 addToPath('../ruby')
45
46 import Ruby
47
48 from FSConfig import *
49 from SysPaths import *
50 from Benchmarks import *
51 import Simulation
52 from Caches import *
53
54 # Get paths we might need. It's expected this file is in m5/configs/example.
55 config_path = os.path.dirname(os.path.abspath(__file__))
56 config_root = os.path.dirname(config_path)
57
58 parser = optparse.OptionParser()
59 # System options
60 parser.add_option("--kernel", action="store", type="string")
61 parser.add_option("--script", action="store", type="string")
62 # Benchmark options
63 parser.add_option("-b", "--benchmark", action="store", type="string",
64 dest="benchmark",
65 help="Specify the benchmark to run. Available benchmarks: %s"\
66 % DefinedBenchmarks)
67 parser.add_option("-o", "--options", default="",
68 help='The options to pass to the binary, use " " around the entire string')
69 parser.add_option("-i", "--input", default="", help="Read stdin from a file.")
70 parser.add_option("--output", default="", help="Redirect stdout to a file.")
71 parser.add_option("--errout", default="", help="Redirect stderr to a file.")
72
73 #
74 # Add the ruby specific and protocol specific options
75 #
76 Ruby.define_options(parser)
77
78 execfile(os.path.join(config_root, "common", "Options.py"))
79
80 (options, args) = parser.parse_args()
81 options.ruby = True
82
83 if args:
84 print "Error: script doesn't take any positional arguments"
85 sys.exit(1)
86
87 if options.benchmark:
88 try:
89 bm = Benchmarks[options.benchmark]
90 except KeyError:
91 print "Error benchmark %s has not been defined." % options.benchmark
92 print "Valid benchmarks are: %s" % DefinedBenchmarks
93 sys.exit(1)
94 else:
95 bm = [SysConfig()]
96
97 # Check for timing mode because ruby does not support atomic accesses
98 if not (options.cpu_type == "detailed" or options.cpu_type == "timing"):
99 print >> sys.stderr, "Ruby requires TimingSimpleCPU or O3CPU!!"
100 sys.exit(1)
101 (CPUClass, test_mem_mode, FutureClass) = Simulation.setCPUClass(options)
102
103 CPUClass.clock = options.clock
104
105 if buildEnv['TARGET_ISA'] == "alpha":
106 system = makeLinuxAlphaRubySystem(test_mem_mode, bm[0])
107 elif buildEnv['TARGET_ISA'] == "x86":
108 system = makeLinuxX86System(test_mem_mode, options.num_cpus, bm[0], True)
109 Simulation.setWorkCountOptions(system, options)
110 else:
111 fatal("incapable of building non-alpha or non-x86 full system!")
112
113 if options.kernel is not None:
114 system.kernel = binary(options.kernel)
115
116 if options.script is not None:
117 system.readfile = options.script
118
119 system.cpu = [CPUClass(cpu_id=i) for i in xrange(options.num_cpus)]
120 Ruby.create_system(options, system, system.piobus, system._dma_devices)
121
122 for (i, cpu) in enumerate(system.cpu):
123 #
124 # Tie the cpu ports to the correct ruby system ports
125 #
126 cpu.createInterruptController()
127 cpu.icache_port = system.ruby._cpu_ruby_ports[i].slave
128 cpu.dcache_port = system.ruby._cpu_ruby_ports[i].slave
129 if buildEnv['TARGET_ISA'] == "x86":
130 cpu.itb.walker.port = system.ruby._cpu_ruby_ports[i].slave
131 cpu.dtb.walker.port = system.ruby._cpu_ruby_ports[i].slave
132 cpu.interrupts.pio = system.piobus.master
133 cpu.interrupts.int_master = system.piobus.slave
134 cpu.interrupts.int_slave = system.piobus.master
135
136 root = Root(full_system = True, system = system)
137 Simulation.run(options, root, system, FutureClass)