fs.py revision 5457:08bd3709d482
1# Copyright (c) 2006-2007 The Regents of The University of Michigan
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: Ali Saidi
28
29import optparse, os, sys
30
31import m5
32
33if not m5.build_env['FULL_SYSTEM']:
34    m5.panic("This script requires full-system mode (*_FS).")
35
36from m5.objects import *
37m5.AddToPath('../common')
38from FSConfig import *
39from SysPaths import *
40from Benchmarks import *
41import Simulation
42from Caches import *
43
44# Get paths we might need.  It's expected this file is in m5/configs/example.
45config_path = os.path.dirname(os.path.abspath(__file__))
46config_root = os.path.dirname(config_path)
47
48parser = optparse.OptionParser()
49
50# System options
51parser.add_option("--kernel", action="store", type="string")
52parser.add_option("--script", action="store", type="string")
53
54# Benchmark options
55parser.add_option("--dual", action="store_true",
56                  help="Simulate two systems attached with an ethernet link")
57parser.add_option("-b", "--benchmark", action="store", type="string",
58                  dest="benchmark",
59                  help="Specify the benchmark to run. Available benchmarks: %s"\
60                  % DefinedBenchmarks)
61
62# Metafile options
63parser.add_option("--etherdump", action="store", type="string", dest="etherdump",
64                  help="Specify the filename to dump a pcap capture of the" \
65                  "ethernet traffic")
66
67execfile(os.path.join(config_root, "common", "Options.py"))
68
69(options, args) = parser.parse_args()
70
71if args:
72    print "Error: script doesn't take any positional arguments"
73    sys.exit(1)
74
75# driver system CPU is always simple... note this is an assignment of
76# a class, not an instance.
77DriveCPUClass = AtomicSimpleCPU
78drive_mem_mode = 'atomic'
79
80# system under test can be any CPU
81(TestCPUClass, test_mem_mode, FutureClass) = Simulation.setCPUClass(options)
82
83TestCPUClass.clock = '2GHz'
84DriveCPUClass.clock = '2GHz'
85
86if options.benchmark:
87    try:
88        bm = Benchmarks[options.benchmark]
89    except KeyError:
90        print "Error benchmark %s has not been defined." % options.benchmark
91        print "Valid benchmarks are: %s" % DefinedBenchmarks
92        sys.exit(1)
93else:
94    if options.dual:
95        bm = [SysConfig(), SysConfig()]
96    else:
97        bm = [SysConfig()]
98
99if m5.build_env['TARGET_ISA'] == "alpha":
100    test_sys = makeLinuxAlphaSystem(test_mem_mode, bm[0])
101elif m5.build_env['TARGET_ISA'] == "mips":
102    test_sys = makeLinuxMipsSystem(test_mem_mode, bm[0])
103elif m5.build_env['TARGET_ISA'] == "sparc":
104    test_sys = makeSparcSystem(test_mem_mode, bm[0])
105elif m5.build_env['TARGET_ISA'] == "x86":
106    test_sys = makeLinuxX86System(test_mem_mode, bm[0])
107else:
108    m5.panic("incapable of building non-alpha or non-sparc full system!")
109
110if options.kernel is not None:
111    test_sys.kernel = binary(options.kernel)
112
113if options.script is not None:
114    test_sys.readfile = options.script
115
116np = options.num_cpus
117
118if options.l2cache:
119    test_sys.l2 = L2Cache(size = '2MB')
120    test_sys.tol2bus = Bus()
121    test_sys.l2.cpu_side = test_sys.tol2bus.port
122    test_sys.l2.mem_side = test_sys.membus.port
123
124test_sys.cpu = [TestCPUClass(cpu_id=i) for i in xrange(np)]
125
126if options.caches:
127    test_sys.bridge.filter_ranges_a=[AddrRange(0, Addr.max)]
128    test_sys.bridge.filter_ranges_b=[AddrRange(0, size='8GB')]
129    test_sys.iocache = IOCache(mem_side_filter_ranges=[AddrRange(0, Addr.max)],
130                       cpu_side_filter_ranges=[AddrRange(0x8000000000, Addr.max)])
131    test_sys.iocache.cpu_side = test_sys.iobus.port
132    test_sys.iocache.mem_side = test_sys.membus.port
133
134for i in xrange(np):
135    if options.caches:
136        test_sys.cpu[i].addPrivateSplitL1Caches(L1Cache(size = '32kB'),
137                                                L1Cache(size = '64kB'))
138    if options.l2cache:
139        test_sys.cpu[i].connectMemPorts(test_sys.tol2bus)
140    else:
141        test_sys.cpu[i].connectMemPorts(test_sys.membus)
142
143    if options.fastmem:
144        test_sys.cpu[i].physmem_port = test_sys.physmem.port
145
146if m5.build_env['TARGET_ISA'] == 'mips':
147    setMipsOptions(TestCPUClass)
148
149if len(bm) == 2:
150    if m5.build_env['TARGET_ISA'] == 'alpha':
151        drive_sys = makeLinuxAlphaSystem(drive_mem_mode, bm[1])
152    elif m5.build_env['TARGET_ISA'] == 'mips':
153        drive_sys = makeLinuxMipsSystem(drive_mem_mode, bm[1])
154    elif m5.build_env['TARGET_ISA'] == 'sparc':
155        drive_sys = makeSparcSystem(drive_mem_mode, bm[1])
156    elif m5.build.env['TARGET_ISA'] == 'x86':
157        drive_sys = makeX86System(drive_mem_mode, bm[1])
158    drive_sys.cpu = DriveCPUClass(cpu_id=0)
159    drive_sys.cpu.connectMemPorts(drive_sys.membus)
160    if options.fastmem:
161        drive_sys.cpu.physmem_port = drive_sys.physmem.port
162    if options.kernel is not None:
163        drive_sys.kernel = binary(options.kernel)
164
165    root = makeDualRoot(test_sys, drive_sys, options.etherdump)
166elif len(bm) == 1:
167    root = Root(system=test_sys)
168else:
169    print "Error I don't know how to create more than 2 systems."
170    sys.exit(1)
171
172Simulation.run(options, root, test_sys, FutureClass)
173