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