fs.py revision 12395:322bb93e5f06
112027Sjungma@eit.uni-kl.de# Copyright (c) 2010-2013, 2016 ARM Limited
212027Sjungma@eit.uni-kl.de# All rights reserved.
312027Sjungma@eit.uni-kl.de#
412027Sjungma@eit.uni-kl.de# The license below extends only to copyright in the software and shall
512027Sjungma@eit.uni-kl.de# not be construed as granting a license to any other intellectual
612027Sjungma@eit.uni-kl.de# property including but not limited to intellectual property relating
712027Sjungma@eit.uni-kl.de# to a hardware implementation of the functionality of the software
812027Sjungma@eit.uni-kl.de# licensed hereunder.  You may use the software subject to the license
912027Sjungma@eit.uni-kl.de# terms below provided that you ensure that this notice is replicated
1012027Sjungma@eit.uni-kl.de# unmodified and in its entirety in all distributions of the software,
1112027Sjungma@eit.uni-kl.de# modified or unmodified, in source code or in binary form.
1212027Sjungma@eit.uni-kl.de#
1312027Sjungma@eit.uni-kl.de# Copyright (c) 2012-2014 Mark D. Hill and David A. Wood
1412027Sjungma@eit.uni-kl.de# Copyright (c) 2009-2011 Advanced Micro Devices, Inc.
1512027Sjungma@eit.uni-kl.de# Copyright (c) 2006-2007 The Regents of The University of Michigan
1612027Sjungma@eit.uni-kl.de# All rights reserved.
1712027Sjungma@eit.uni-kl.de#
1812027Sjungma@eit.uni-kl.de# Redistribution and use in source and binary forms, with or without
1912027Sjungma@eit.uni-kl.de# modification, are permitted provided that the following conditions are
2012027Sjungma@eit.uni-kl.de# met: redistributions of source code must retain the above copyright
2112027Sjungma@eit.uni-kl.de# notice, this list of conditions and the following disclaimer;
2212027Sjungma@eit.uni-kl.de# redistributions in binary form must reproduce the above copyright
2312027Sjungma@eit.uni-kl.de# notice, this list of conditions and the following disclaimer in the
2412027Sjungma@eit.uni-kl.de# documentation and/or other materials provided with the distribution;
2512027Sjungma@eit.uni-kl.de# neither the name of the copyright holders nor the names of its
2612027Sjungma@eit.uni-kl.de# contributors may be used to endorse or promote products derived from
2712027Sjungma@eit.uni-kl.de# this software without specific prior written permission.
2812027Sjungma@eit.uni-kl.de#
2912027Sjungma@eit.uni-kl.de# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3012027Sjungma@eit.uni-kl.de# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3112027Sjungma@eit.uni-kl.de# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3212027Sjungma@eit.uni-kl.de# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3312027Sjungma@eit.uni-kl.de# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3412027Sjungma@eit.uni-kl.de# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3512027Sjungma@eit.uni-kl.de# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3612027Sjungma@eit.uni-kl.de# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3712027Sjungma@eit.uni-kl.de# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3812027Sjungma@eit.uni-kl.de# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3912027Sjungma@eit.uni-kl.de# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4012027Sjungma@eit.uni-kl.de#
4112027Sjungma@eit.uni-kl.de# Authors: Ali Saidi
4212027Sjungma@eit.uni-kl.de#          Brad Beckmann
4312027Sjungma@eit.uni-kl.de
4412027Sjungma@eit.uni-kl.deimport optparse
4512027Sjungma@eit.uni-kl.deimport sys
4612027Sjungma@eit.uni-kl.de
4712027Sjungma@eit.uni-kl.deimport m5
4812027Sjungma@eit.uni-kl.defrom m5.defines import buildEnv
4912027Sjungma@eit.uni-kl.defrom m5.objects import *
5012027Sjungma@eit.uni-kl.defrom m5.util import addToPath, fatal, warn
5112027Sjungma@eit.uni-kl.de
5212027Sjungma@eit.uni-kl.deaddToPath('../')
5312027Sjungma@eit.uni-kl.de
5412027Sjungma@eit.uni-kl.defrom ruby import Ruby
5512027Sjungma@eit.uni-kl.de
5612027Sjungma@eit.uni-kl.defrom common.FSConfig import *
5712027Sjungma@eit.uni-kl.defrom common.SysPaths import *
5812027Sjungma@eit.uni-kl.defrom common.Benchmarks import *
5912027Sjungma@eit.uni-kl.defrom common import Simulation
6012027Sjungma@eit.uni-kl.defrom common import CacheConfig
6112027Sjungma@eit.uni-kl.defrom common import MemConfig
6212027Sjungma@eit.uni-kl.defrom common import CpuConfig
6312027Sjungma@eit.uni-kl.defrom common.Caches import *
6412027Sjungma@eit.uni-kl.defrom common import Options
6512027Sjungma@eit.uni-kl.de
6612027Sjungma@eit.uni-kl.de
6712027Sjungma@eit.uni-kl.de# Check if KVM support has been enabled, we might need to do VM
6812027Sjungma@eit.uni-kl.de# configuration if that's the case.
6912027Sjungma@eit.uni-kl.dehave_kvm_support = 'BaseKvmCPU' in globals()
7012027Sjungma@eit.uni-kl.dedef is_kvm_cpu(cpu_class):
7112027Sjungma@eit.uni-kl.de    return have_kvm_support and cpu_class != None and \
7212027Sjungma@eit.uni-kl.de        issubclass(cpu_class, BaseKvmCPU)
7312027Sjungma@eit.uni-kl.de
7412027Sjungma@eit.uni-kl.dedef cmd_line_template():
7512027Sjungma@eit.uni-kl.de    if options.command_line and options.command_line_file:
7612027Sjungma@eit.uni-kl.de        print "Error: --command-line and --command-line-file are " \
7712027Sjungma@eit.uni-kl.de              "mutually exclusive"
7812027Sjungma@eit.uni-kl.de        sys.exit(1)
7912027Sjungma@eit.uni-kl.de    if options.command_line:
8012027Sjungma@eit.uni-kl.de        return options.command_line
8112027Sjungma@eit.uni-kl.de    if options.command_line_file:
8212027Sjungma@eit.uni-kl.de        return open(options.command_line_file).read().strip()
8312027Sjungma@eit.uni-kl.de    return None
8412027Sjungma@eit.uni-kl.de
8512027Sjungma@eit.uni-kl.dedef build_test_system(np):
8612027Sjungma@eit.uni-kl.de    cmdline = cmd_line_template()
8712027Sjungma@eit.uni-kl.de    if buildEnv['TARGET_ISA'] == "alpha":
8812027Sjungma@eit.uni-kl.de        test_sys = makeLinuxAlphaSystem(test_mem_mode, bm[0], options.ruby,
8912027Sjungma@eit.uni-kl.de                                        cmdline=cmdline)
9012027Sjungma@eit.uni-kl.de    elif buildEnv['TARGET_ISA'] == "mips":
9112027Sjungma@eit.uni-kl.de        test_sys = makeLinuxMipsSystem(test_mem_mode, bm[0], cmdline=cmdline)
9212027Sjungma@eit.uni-kl.de    elif buildEnv['TARGET_ISA'] == "sparc":
9312027Sjungma@eit.uni-kl.de        test_sys = makeSparcSystem(test_mem_mode, bm[0], cmdline=cmdline)
9412027Sjungma@eit.uni-kl.de    elif buildEnv['TARGET_ISA'] == "x86":
9512027Sjungma@eit.uni-kl.de        test_sys = makeLinuxX86System(test_mem_mode, options.num_cpus, bm[0],
9612027Sjungma@eit.uni-kl.de                options.ruby, cmdline=cmdline)
9712027Sjungma@eit.uni-kl.de    elif buildEnv['TARGET_ISA'] == "arm":
9812027Sjungma@eit.uni-kl.de        test_sys = makeArmSystem(test_mem_mode, options.machine_type,
9912027Sjungma@eit.uni-kl.de                                 options.num_cpus, bm[0], options.dtb_filename,
10012027Sjungma@eit.uni-kl.de                                 bare_metal=options.bare_metal,
10112027Sjungma@eit.uni-kl.de                                 cmdline=cmdline,
10212027Sjungma@eit.uni-kl.de                                 external_memory=options.external_memory_system,
10312027Sjungma@eit.uni-kl.de                                 ruby=options.ruby,
10412027Sjungma@eit.uni-kl.de                                 security=options.enable_security_extensions)
10512027Sjungma@eit.uni-kl.de        if options.enable_context_switch_stats_dump:
10612027Sjungma@eit.uni-kl.de            test_sys.enable_context_switch_stats_dump = True
10712027Sjungma@eit.uni-kl.de    else:
10812027Sjungma@eit.uni-kl.de        fatal("Incapable of building %s full system!", buildEnv['TARGET_ISA'])
10912027Sjungma@eit.uni-kl.de
11012027Sjungma@eit.uni-kl.de    # Set the cache line size for the entire system
11112027Sjungma@eit.uni-kl.de    test_sys.cache_line_size = options.cacheline_size
11212027Sjungma@eit.uni-kl.de
11312027Sjungma@eit.uni-kl.de    # Create a top-level voltage domain
11412027Sjungma@eit.uni-kl.de    test_sys.voltage_domain = VoltageDomain(voltage = options.sys_voltage)
11512027Sjungma@eit.uni-kl.de
11612027Sjungma@eit.uni-kl.de    # Create a source clock for the system and set the clock period
11712027Sjungma@eit.uni-kl.de    test_sys.clk_domain = SrcClockDomain(clock =  options.sys_clock,
118            voltage_domain = test_sys.voltage_domain)
119
120    # Create a CPU voltage domain
121    test_sys.cpu_voltage_domain = VoltageDomain()
122
123    # Create a source clock for the CPUs and set the clock period
124    test_sys.cpu_clk_domain = SrcClockDomain(clock = options.cpu_clock,
125                                             voltage_domain =
126                                             test_sys.cpu_voltage_domain)
127
128    if options.kernel is not None:
129        test_sys.kernel = binary(options.kernel)
130
131    if options.script is not None:
132        test_sys.readfile = options.script
133
134    if options.lpae:
135        test_sys.have_lpae = True
136
137    if options.virtualisation:
138        test_sys.have_virtualization = True
139
140    test_sys.init_param = options.init_param
141
142    # For now, assign all the CPUs to the same clock domain
143    test_sys.cpu = [TestCPUClass(clk_domain=test_sys.cpu_clk_domain, cpu_id=i)
144                    for i in xrange(np)]
145
146    if is_kvm_cpu(TestCPUClass) or is_kvm_cpu(FutureClass):
147        test_sys.kvm_vm = KvmVM()
148
149    if options.ruby:
150        Ruby.create_system(options, True, test_sys, test_sys.iobus,
151                           test_sys._dma_ports)
152
153        # Create a seperate clock domain for Ruby
154        test_sys.ruby.clk_domain = SrcClockDomain(clock = options.ruby_clock,
155                                        voltage_domain = test_sys.voltage_domain)
156
157        # Connect the ruby io port to the PIO bus,
158        # assuming that there is just one such port.
159        test_sys.iobus.master = test_sys.ruby._io_port.slave
160
161        for (i, cpu) in enumerate(test_sys.cpu):
162            #
163            # Tie the cpu ports to the correct ruby system ports
164            #
165            cpu.clk_domain = test_sys.cpu_clk_domain
166            cpu.createThreads()
167            cpu.createInterruptController()
168
169            cpu.icache_port = test_sys.ruby._cpu_ports[i].slave
170            cpu.dcache_port = test_sys.ruby._cpu_ports[i].slave
171
172            if buildEnv['TARGET_ISA'] in ("x86", "arm"):
173                cpu.itb.walker.port = test_sys.ruby._cpu_ports[i].slave
174                cpu.dtb.walker.port = test_sys.ruby._cpu_ports[i].slave
175
176            if buildEnv['TARGET_ISA'] in "x86":
177                cpu.interrupts[0].pio = test_sys.ruby._cpu_ports[i].master
178                cpu.interrupts[0].int_master = test_sys.ruby._cpu_ports[i].slave
179                cpu.interrupts[0].int_slave = test_sys.ruby._cpu_ports[i].master
180
181    else:
182        if options.caches or options.l2cache:
183            # By default the IOCache runs at the system clock
184            test_sys.iocache = IOCache(addr_ranges = test_sys.mem_ranges)
185            test_sys.iocache.cpu_side = test_sys.iobus.master
186            test_sys.iocache.mem_side = test_sys.membus.slave
187        elif not options.external_memory_system:
188            test_sys.iobridge = Bridge(delay='50ns', ranges = test_sys.mem_ranges)
189            test_sys.iobridge.slave = test_sys.iobus.master
190            test_sys.iobridge.master = test_sys.membus.slave
191
192        # Sanity check
193        if options.fastmem:
194            if TestCPUClass != AtomicSimpleCPU:
195                fatal("Fastmem can only be used with atomic CPU!")
196            if (options.caches or options.l2cache):
197                fatal("You cannot use fastmem in combination with caches!")
198
199        if options.simpoint_profile:
200            if not options.fastmem:
201                # Atomic CPU checked with fastmem option already
202                fatal("SimPoint generation should be done with atomic cpu and fastmem")
203            if np > 1:
204                fatal("SimPoint generation not supported with more than one CPUs")
205
206        for i in xrange(np):
207            if options.fastmem:
208                test_sys.cpu[i].fastmem = True
209            if options.simpoint_profile:
210                test_sys.cpu[i].addSimPointProbe(options.simpoint_interval)
211            if options.checker:
212                test_sys.cpu[i].addCheckerCpu()
213            test_sys.cpu[i].createThreads()
214
215        # If elastic tracing is enabled when not restoring from checkpoint and
216        # when not fast forwarding using the atomic cpu, then check that the
217        # TestCPUClass is DerivO3CPU or inherits from DerivO3CPU. If the check
218        # passes then attach the elastic trace probe.
219        # If restoring from checkpoint or fast forwarding, the code that does this for
220        # FutureCPUClass is in the Simulation module. If the check passes then the
221        # elastic trace probe is attached to the switch CPUs.
222        if options.elastic_trace_en and options.checkpoint_restore == None and \
223            not options.fast_forward:
224            CpuConfig.config_etrace(TestCPUClass, test_sys.cpu, options)
225
226        CacheConfig.config_cache(options, test_sys)
227
228        MemConfig.config_mem(options, test_sys)
229
230    return test_sys
231
232def build_drive_system(np):
233    # driver system CPU is always simple, so is the memory
234    # Note this is an assignment of a class, not an instance.
235    DriveCPUClass = AtomicSimpleCPU
236    drive_mem_mode = 'atomic'
237    DriveMemClass = SimpleMemory
238
239    cmdline = cmd_line_template()
240    if buildEnv['TARGET_ISA'] == 'alpha':
241        drive_sys = makeLinuxAlphaSystem(drive_mem_mode, bm[1], cmdline=cmdline)
242    elif buildEnv['TARGET_ISA'] == 'mips':
243        drive_sys = makeLinuxMipsSystem(drive_mem_mode, bm[1], cmdline=cmdline)
244    elif buildEnv['TARGET_ISA'] == 'sparc':
245        drive_sys = makeSparcSystem(drive_mem_mode, bm[1], cmdline=cmdline)
246    elif buildEnv['TARGET_ISA'] == 'x86':
247        drive_sys = makeLinuxX86System(drive_mem_mode, np, bm[1],
248                                       cmdline=cmdline)
249    elif buildEnv['TARGET_ISA'] == 'arm':
250        drive_sys = makeArmSystem(drive_mem_mode, options.machine_type, np,
251                                  bm[1], options.dtb_filename, cmdline=cmdline)
252
253    # Create a top-level voltage domain
254    drive_sys.voltage_domain = VoltageDomain(voltage = options.sys_voltage)
255
256    # Create a source clock for the system and set the clock period
257    drive_sys.clk_domain = SrcClockDomain(clock =  options.sys_clock,
258            voltage_domain = drive_sys.voltage_domain)
259
260    # Create a CPU voltage domain
261    drive_sys.cpu_voltage_domain = VoltageDomain()
262
263    # Create a source clock for the CPUs and set the clock period
264    drive_sys.cpu_clk_domain = SrcClockDomain(clock = options.cpu_clock,
265                                              voltage_domain =
266                                              drive_sys.cpu_voltage_domain)
267
268    drive_sys.cpu = DriveCPUClass(clk_domain=drive_sys.cpu_clk_domain,
269                                  cpu_id=0)
270    drive_sys.cpu.createThreads()
271    drive_sys.cpu.createInterruptController()
272    drive_sys.cpu.connectAllPorts(drive_sys.membus)
273    if options.fastmem:
274        drive_sys.cpu.fastmem = True
275    if options.kernel is not None:
276        drive_sys.kernel = binary(options.kernel)
277
278    if is_kvm_cpu(DriveCPUClass):
279        drive_sys.kvm_vm = KvmVM()
280
281    drive_sys.iobridge = Bridge(delay='50ns',
282                                ranges = drive_sys.mem_ranges)
283    drive_sys.iobridge.slave = drive_sys.iobus.master
284    drive_sys.iobridge.master = drive_sys.membus.slave
285
286    # Create the appropriate memory controllers and connect them to the
287    # memory bus
288    drive_sys.mem_ctrls = [DriveMemClass(range = r)
289                           for r in drive_sys.mem_ranges]
290    for i in xrange(len(drive_sys.mem_ctrls)):
291        drive_sys.mem_ctrls[i].port = drive_sys.membus.master
292
293    drive_sys.init_param = options.init_param
294
295    return drive_sys
296
297# Add options
298parser = optparse.OptionParser()
299Options.addCommonOptions(parser)
300Options.addFSOptions(parser)
301
302# Add the ruby specific and protocol specific options
303if '--ruby' in sys.argv:
304    Ruby.define_options(parser)
305
306(options, args) = parser.parse_args()
307
308if args:
309    print "Error: script doesn't take any positional arguments"
310    sys.exit(1)
311
312# system under test can be any CPU
313(TestCPUClass, test_mem_mode, FutureClass) = Simulation.setCPUClass(options)
314
315# Match the memories with the CPUs, based on the options for the test system
316TestMemClass = Simulation.setMemClass(options)
317
318if options.benchmark:
319    try:
320        bm = Benchmarks[options.benchmark]
321    except KeyError:
322        print "Error benchmark %s has not been defined." % options.benchmark
323        print "Valid benchmarks are: %s" % DefinedBenchmarks
324        sys.exit(1)
325else:
326    if options.dual:
327        bm = [SysConfig(disk=options.disk_image, rootdev=options.root_device,
328                        mem=options.mem_size, os_type=options.os_type),
329              SysConfig(disk=options.disk_image, rootdev=options.root_device,
330                        mem=options.mem_size, os_type=options.os_type)]
331    else:
332        bm = [SysConfig(disk=options.disk_image, rootdev=options.root_device,
333                        mem=options.mem_size, os_type=options.os_type)]
334
335np = options.num_cpus
336
337test_sys = build_test_system(np)
338if len(bm) == 2:
339    drive_sys = build_drive_system(np)
340    root = makeDualRoot(True, test_sys, drive_sys, options.etherdump)
341elif len(bm) == 1 and options.dist:
342    # This system is part of a dist-gem5 simulation
343    root = makeDistRoot(test_sys,
344                        options.dist_rank,
345                        options.dist_size,
346                        options.dist_server_name,
347                        options.dist_server_port,
348                        options.dist_sync_repeat,
349                        options.dist_sync_start,
350                        options.ethernet_linkspeed,
351                        options.ethernet_linkdelay,
352                        options.etherdump);
353elif len(bm) == 1:
354    root = Root(full_system=True, system=test_sys)
355else:
356    print "Error I don't know how to create more than 2 systems."
357    sys.exit(1)
358
359if options.timesync:
360    root.time_sync_enable = True
361
362if options.frame_capture:
363    VncServer.frame_capture = True
364
365Simulation.setWorkCountOptions(test_sys, options)
366Simulation.run(options, root, test_sys, FutureClass)
367