fs.py revision 12014
12686Sksewell@umich.edu# Copyright (c) 2010-2013, 2016 ARM Limited
22686Sksewell@umich.edu# All rights reserved.
35254Sksewell@umich.edu#
45254Sksewell@umich.edu# The license below extends only to copyright in the software and shall
55254Sksewell@umich.edu# not be construed as granting a license to any other intellectual
65254Sksewell@umich.edu# property including but not limited to intellectual property relating
75254Sksewell@umich.edu# to a hardware implementation of the functionality of the software
85254Sksewell@umich.edu# licensed hereunder.  You may use the software subject to the license
95254Sksewell@umich.edu# terms below provided that you ensure that this notice is replicated
105254Sksewell@umich.edu# unmodified and in its entirety in all distributions of the software,
115254Sksewell@umich.edu# modified or unmodified, in source code or in binary form.
125254Sksewell@umich.edu#
135254Sksewell@umich.edu# Copyright (c) 2012-2014 Mark D. Hill and David A. Wood
145254Sksewell@umich.edu# Copyright (c) 2009-2011 Advanced Micro Devices, Inc.
155254Sksewell@umich.edu# Copyright (c) 2006-2007 The Regents of The University of Michigan
165254Sksewell@umich.edu# All rights reserved.
175254Sksewell@umich.edu#
185254Sksewell@umich.edu# Redistribution and use in source and binary forms, with or without
195254Sksewell@umich.edu# modification, are permitted provided that the following conditions are
205254Sksewell@umich.edu# met: redistributions of source code must retain the above copyright
215254Sksewell@umich.edu# notice, this list of conditions and the following disclaimer;
225254Sksewell@umich.edu# redistributions in binary form must reproduce the above copyright
235254Sksewell@umich.edu# notice, this list of conditions and the following disclaimer in the
245254Sksewell@umich.edu# documentation and/or other materials provided with the distribution;
255254Sksewell@umich.edu# neither the name of the copyright holders nor the names of its
265254Sksewell@umich.edu# contributors may be used to endorse or promote products derived from
275254Sksewell@umich.edu# this software without specific prior written permission.
285254Sksewell@umich.edu#
295254Sksewell@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
305254Sksewell@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
312706Sksewell@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
322023SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
332023SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
342023SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
352124SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
362124SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
372023SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
382023SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
392084SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
402084SN/A#
412023SN/A# Authors: Ali Saidi
422023SN/A#          Brad Beckmann
432023SN/A
442023SN/Aimport optparse
452023SN/Aimport sys
462616SN/A
472077SN/Aimport m5
482077SN/Afrom m5.defines import buildEnv
492077SN/Afrom m5.objects import *
502616SN/Afrom m5.util import addToPath, fatal
514661Sksewell@umich.edu
524661Sksewell@umich.eduaddToPath('../')
534661Sksewell@umich.edu
542616SN/Afrom ruby import Ruby
552616SN/A
562562SN/Afrom common.FSConfig import *
572041SN/Afrom common.SysPaths import *
582616SN/Afrom common.Benchmarks import *
594661Sksewell@umich.edufrom common import Simulation
604661Sksewell@umich.edufrom common import CacheConfig
612616SN/Afrom common import MemConfig
624661Sksewell@umich.edufrom common import CpuConfig
634661Sksewell@umich.edufrom common.Caches import *
644661Sksewell@umich.edufrom common import Options
654661Sksewell@umich.edu
664661Sksewell@umich.edu
674661Sksewell@umich.edu# Check if KVM support has been enabled, we might need to do VM
684661Sksewell@umich.edu# configuration if that's the case.
694661Sksewell@umich.eduhave_kvm_support = 'BaseKvmCPU' in globals()
704661Sksewell@umich.edudef is_kvm_cpu(cpu_class):
714661Sksewell@umich.edu    return have_kvm_support and cpu_class != None and \
724661Sksewell@umich.edu        issubclass(cpu_class, BaseKvmCPU)
734661Sksewell@umich.edu
744661Sksewell@umich.edudef cmd_line_template():
754661Sksewell@umich.edu    if options.command_line and options.command_line_file:
764661Sksewell@umich.edu        print "Error: --command-line and --command-line-file are " \
774661Sksewell@umich.edu              "mutually exclusive"
784661Sksewell@umich.edu        sys.exit(1)
794661Sksewell@umich.edu    if options.command_line:
804661Sksewell@umich.edu        return options.command_line
814661Sksewell@umich.edu    if options.command_line_file:
822041SN/A        return open(options.command_line_file).read().strip()
832616SN/A    return None
842077SN/A
852077SN/Adef build_test_system(np):
862077SN/A    cmdline = cmd_line_template()
872239SN/A    if buildEnv['TARGET_ISA'] == "alpha":
882041SN/A        test_sys = makeLinuxAlphaSystem(test_mem_mode, bm[0], options.ruby,
894661Sksewell@umich.edu                                        cmdline=cmdline)
902754Sksewell@umich.edu    elif buildEnv['TARGET_ISA'] == "mips":
912754Sksewell@umich.edu        test_sys = makeLinuxMipsSystem(test_mem_mode, bm[0], cmdline=cmdline)
922754Sksewell@umich.edu    elif buildEnv['TARGET_ISA'] == "sparc":
932754Sksewell@umich.edu        test_sys = makeSparcSystem(test_mem_mode, bm[0], cmdline=cmdline)
942754Sksewell@umich.edu    elif buildEnv['TARGET_ISA'] == "x86":
952616SN/A        test_sys = makeLinuxX86System(test_mem_mode, options.num_cpus, bm[0],
964661Sksewell@umich.edu                options.ruby, cmdline=cmdline)
972607SN/A    elif buildEnv['TARGET_ISA'] == "arm":
982607SN/A        test_sys = makeArmSystem(test_mem_mode, options.machine_type,
992607SN/A                                 options.num_cpus, bm[0], options.dtb_filename,
1002607SN/A                                 bare_metal=options.bare_metal,
1012607SN/A                                 cmdline=cmdline,
1022607SN/A                                 external_memory=options.external_memory_system,
1032607SN/A                                 ruby=options.ruby)
1042607SN/A        if options.enable_context_switch_stats_dump:
1052607SN/A            test_sys.enable_context_switch_stats_dump = True
1064661Sksewell@umich.edu    else:
1074661Sksewell@umich.edu        fatal("Incapable of building %s full system!", buildEnv['TARGET_ISA'])
1084661Sksewell@umich.edu
1095222Sksewell@umich.edu    # Set the cache line size for the entire system
1105222Sksewell@umich.edu    test_sys.cache_line_size = options.cacheline_size
1115222Sksewell@umich.edu
1125222Sksewell@umich.edu    # Create a top-level voltage domain
1135222Sksewell@umich.edu    test_sys.voltage_domain = VoltageDomain(voltage = options.sys_voltage)
1145222Sksewell@umich.edu
1155222Sksewell@umich.edu    # Create a source clock for the system and set the clock period
1166338Sgblack@eecs.umich.edu    test_sys.clk_domain = SrcClockDomain(clock =  options.sys_clock,
1174661Sksewell@umich.edu            voltage_domain = test_sys.voltage_domain)
1184661Sksewell@umich.edu
1194661Sksewell@umich.edu    # Create a CPU voltage domain
1204661Sksewell@umich.edu    test_sys.cpu_voltage_domain = VoltageDomain()
1214661Sksewell@umich.edu
1224661Sksewell@umich.edu    # Create a source clock for the CPUs and set the clock period
1234661Sksewell@umich.edu    test_sys.cpu_clk_domain = SrcClockDomain(clock = options.cpu_clock,
1244661Sksewell@umich.edu                                             voltage_domain =
1254661Sksewell@umich.edu                                             test_sys.cpu_voltage_domain)
1264661Sksewell@umich.edu
1274661Sksewell@umich.edu    if options.kernel is not None:
1285222Sksewell@umich.edu        test_sys.kernel = binary(options.kernel)
1295222Sksewell@umich.edu
1305222Sksewell@umich.edu    if options.script is not None:
1315222Sksewell@umich.edu        test_sys.readfile = options.script
1325222Sksewell@umich.edu
1335222Sksewell@umich.edu    if options.lpae:
1345222Sksewell@umich.edu        test_sys.have_lpae = True
1355222Sksewell@umich.edu
1365222Sksewell@umich.edu    if options.virtualisation:
1375222Sksewell@umich.edu        test_sys.have_virtualization = True
1385222Sksewell@umich.edu
1395222Sksewell@umich.edu    test_sys.init_param = options.init_param
1405222Sksewell@umich.edu
1415222Sksewell@umich.edu    # For now, assign all the CPUs to the same clock domain
1425222Sksewell@umich.edu    test_sys.cpu = [TestCPUClass(clk_domain=test_sys.cpu_clk_domain, cpu_id=i)
1435222Sksewell@umich.edu                    for i in xrange(np)]
1445222Sksewell@umich.edu
1454661Sksewell@umich.edu    if is_kvm_cpu(TestCPUClass) or is_kvm_cpu(FutureClass):
1464661Sksewell@umich.edu        test_sys.kvm_vm = KvmVM()
1474661Sksewell@umich.edu
1484661Sksewell@umich.edu    if options.ruby:
1495222Sksewell@umich.edu        # Check for timing mode because ruby does not support atomic accesses
1504661Sksewell@umich.edu        if not (options.cpu_type == "DerivO3CPU" or
1514661Sksewell@umich.edu                options.cpu_type == "TimingSimpleCPU"):
1524661Sksewell@umich.edu            print >> sys.stderr, "Ruby requires TimingSimpleCPU or O3CPU!!"
1534661Sksewell@umich.edu            sys.exit(1)
1544661Sksewell@umich.edu
1554661Sksewell@umich.edu        Ruby.create_system(options, True, test_sys, test_sys.iobus,
1564661Sksewell@umich.edu                           test_sys._dma_ports)
1574661Sksewell@umich.edu
1585222Sksewell@umich.edu        # Create a seperate clock domain for Ruby
1595222Sksewell@umich.edu        test_sys.ruby.clk_domain = SrcClockDomain(clock = options.ruby_clock,
1605222Sksewell@umich.edu                                        voltage_domain = test_sys.voltage_domain)
1615222Sksewell@umich.edu
1625222Sksewell@umich.edu        # Connect the ruby io port to the PIO bus,
1635222Sksewell@umich.edu        # assuming that there is just one such port.
1645222Sksewell@umich.edu        test_sys.iobus.master = test_sys.ruby._io_port.slave
1655222Sksewell@umich.edu
1665222Sksewell@umich.edu        for (i, cpu) in enumerate(test_sys.cpu):
1675222Sksewell@umich.edu            #
1685222Sksewell@umich.edu            # Tie the cpu ports to the correct ruby system ports
1695222Sksewell@umich.edu            #
1705222Sksewell@umich.edu            cpu.clk_domain = test_sys.cpu_clk_domain
1715222Sksewell@umich.edu            cpu.createThreads()
1725222Sksewell@umich.edu            cpu.createInterruptController()
1735222Sksewell@umich.edu
1745222Sksewell@umich.edu            cpu.icache_port = test_sys.ruby._cpu_ports[i].slave
1755222Sksewell@umich.edu            cpu.dcache_port = test_sys.ruby._cpu_ports[i].slave
1764661Sksewell@umich.edu
1774661Sksewell@umich.edu            if buildEnv['TARGET_ISA'] in ("x86", "arm"):
1784661Sksewell@umich.edu                cpu.itb.walker.port = test_sys.ruby._cpu_ports[i].slave
1794661Sksewell@umich.edu                cpu.dtb.walker.port = test_sys.ruby._cpu_ports[i].slave
1804661Sksewell@umich.edu
1812616SN/A            if buildEnv['TARGET_ISA'] in "x86":
1822495SN/A                cpu.interrupts[0].pio = test_sys.ruby._cpu_ports[i].master
1832041SN/A                cpu.interrupts[0].int_master = test_sys.ruby._cpu_ports[i].slave
1842616SN/A                cpu.interrupts[0].int_slave = test_sys.ruby._cpu_ports[i].master
1854661Sksewell@umich.edu
1864661Sksewell@umich.edu    else:
1872023SN/A        if options.caches or options.l2cache:
188            # By default the IOCache runs at the system clock
189            test_sys.iocache = IOCache(addr_ranges = test_sys.mem_ranges)
190            test_sys.iocache.cpu_side = test_sys.iobus.master
191            test_sys.iocache.mem_side = test_sys.membus.slave
192        elif not options.external_memory_system:
193            test_sys.iobridge = Bridge(delay='50ns', ranges = test_sys.mem_ranges)
194            test_sys.iobridge.slave = test_sys.iobus.master
195            test_sys.iobridge.master = test_sys.membus.slave
196
197        # Sanity check
198        if options.fastmem:
199            if TestCPUClass != AtomicSimpleCPU:
200                fatal("Fastmem can only be used with atomic CPU!")
201            if (options.caches or options.l2cache):
202                fatal("You cannot use fastmem in combination with caches!")
203
204        if options.simpoint_profile:
205            if not options.fastmem:
206                # Atomic CPU checked with fastmem option already
207                fatal("SimPoint generation should be done with atomic cpu and fastmem")
208            if np > 1:
209                fatal("SimPoint generation not supported with more than one CPUs")
210
211        for i in xrange(np):
212            if options.fastmem:
213                test_sys.cpu[i].fastmem = True
214            if options.simpoint_profile:
215                test_sys.cpu[i].addSimPointProbe(options.simpoint_interval)
216            if options.checker:
217                test_sys.cpu[i].addCheckerCpu()
218            test_sys.cpu[i].createThreads()
219
220        # If elastic tracing is enabled when not restoring from checkpoint and
221        # when not fast forwarding using the atomic cpu, then check that the
222        # TestCPUClass is DerivO3CPU or inherits from DerivO3CPU. If the check
223        # passes then attach the elastic trace probe.
224        # If restoring from checkpoint or fast forwarding, the code that does this for
225        # FutureCPUClass is in the Simulation module. If the check passes then the
226        # elastic trace probe is attached to the switch CPUs.
227        if options.elastic_trace_en and options.checkpoint_restore == None and \
228            not options.fast_forward:
229            CpuConfig.config_etrace(TestCPUClass, test_sys.cpu, options)
230
231        CacheConfig.config_cache(options, test_sys)
232
233        MemConfig.config_mem(options, test_sys)
234
235    return test_sys
236
237def build_drive_system(np):
238    # driver system CPU is always simple, so is the memory
239    # Note this is an assignment of a class, not an instance.
240    DriveCPUClass = AtomicSimpleCPU
241    drive_mem_mode = 'atomic'
242    DriveMemClass = SimpleMemory
243
244    cmdline = cmd_line_template()
245    if buildEnv['TARGET_ISA'] == 'alpha':
246        drive_sys = makeLinuxAlphaSystem(drive_mem_mode, bm[1], cmdline=cmdline)
247    elif buildEnv['TARGET_ISA'] == 'mips':
248        drive_sys = makeLinuxMipsSystem(drive_mem_mode, bm[1], cmdline=cmdline)
249    elif buildEnv['TARGET_ISA'] == 'sparc':
250        drive_sys = makeSparcSystem(drive_mem_mode, bm[1], cmdline=cmdline)
251    elif buildEnv['TARGET_ISA'] == 'x86':
252        drive_sys = makeLinuxX86System(drive_mem_mode, np, bm[1],
253                                       cmdline=cmdline)
254    elif buildEnv['TARGET_ISA'] == 'arm':
255        drive_sys = makeArmSystem(drive_mem_mode, options.machine_type, np,
256                                  bm[1], options.dtb_filename, cmdline=cmdline)
257
258    # Create a top-level voltage domain
259    drive_sys.voltage_domain = VoltageDomain(voltage = options.sys_voltage)
260
261    # Create a source clock for the system and set the clock period
262    drive_sys.clk_domain = SrcClockDomain(clock =  options.sys_clock,
263            voltage_domain = drive_sys.voltage_domain)
264
265    # Create a CPU voltage domain
266    drive_sys.cpu_voltage_domain = VoltageDomain()
267
268    # Create a source clock for the CPUs and set the clock period
269    drive_sys.cpu_clk_domain = SrcClockDomain(clock = options.cpu_clock,
270                                              voltage_domain =
271                                              drive_sys.cpu_voltage_domain)
272
273    drive_sys.cpu = DriveCPUClass(clk_domain=drive_sys.cpu_clk_domain,
274                                  cpu_id=0)
275    drive_sys.cpu.createThreads()
276    drive_sys.cpu.createInterruptController()
277    drive_sys.cpu.connectAllPorts(drive_sys.membus)
278    if options.fastmem:
279        drive_sys.cpu.fastmem = True
280    if options.kernel is not None:
281        drive_sys.kernel = binary(options.kernel)
282
283    if is_kvm_cpu(DriveCPUClass):
284        drive_sys.kvm_vm = KvmVM()
285
286    drive_sys.iobridge = Bridge(delay='50ns',
287                                ranges = drive_sys.mem_ranges)
288    drive_sys.iobridge.slave = drive_sys.iobus.master
289    drive_sys.iobridge.master = drive_sys.membus.slave
290
291    # Create the appropriate memory controllers and connect them to the
292    # memory bus
293    drive_sys.mem_ctrls = [DriveMemClass(range = r)
294                           for r in drive_sys.mem_ranges]
295    for i in xrange(len(drive_sys.mem_ctrls)):
296        drive_sys.mem_ctrls[i].port = drive_sys.membus.master
297
298    drive_sys.init_param = options.init_param
299
300    return drive_sys
301
302# Add options
303parser = optparse.OptionParser()
304Options.addCommonOptions(parser)
305Options.addFSOptions(parser)
306
307# Add the ruby specific and protocol specific options
308if '--ruby' in sys.argv:
309    Ruby.define_options(parser)
310
311(options, args) = parser.parse_args()
312
313if args:
314    print "Error: script doesn't take any positional arguments"
315    sys.exit(1)
316
317# system under test can be any CPU
318(TestCPUClass, test_mem_mode, FutureClass) = Simulation.setCPUClass(options)
319
320# Match the memories with the CPUs, based on the options for the test system
321TestMemClass = Simulation.setMemClass(options)
322
323if options.benchmark:
324    try:
325        bm = Benchmarks[options.benchmark]
326    except KeyError:
327        print "Error benchmark %s has not been defined." % options.benchmark
328        print "Valid benchmarks are: %s" % DefinedBenchmarks
329        sys.exit(1)
330else:
331    if options.dual:
332        bm = [SysConfig(disk=options.disk_image, rootdev=options.root_device,
333                        mem=options.mem_size, os_type=options.os_type),
334              SysConfig(disk=options.disk_image, rootdev=options.root_device,
335                        mem=options.mem_size, os_type=options.os_type)]
336    else:
337        bm = [SysConfig(disk=options.disk_image, rootdev=options.root_device,
338                        mem=options.mem_size, os_type=options.os_type)]
339
340np = options.num_cpus
341
342test_sys = build_test_system(np)
343if len(bm) == 2:
344    drive_sys = build_drive_system(np)
345    root = makeDualRoot(True, test_sys, drive_sys, options.etherdump)
346elif len(bm) == 1 and options.dist:
347    # This system is part of a dist-gem5 simulation
348    root = makeDistRoot(test_sys,
349                        options.dist_rank,
350                        options.dist_size,
351                        options.dist_server_name,
352                        options.dist_server_port,
353                        options.dist_sync_repeat,
354                        options.dist_sync_start,
355                        options.ethernet_linkspeed,
356                        options.ethernet_linkdelay,
357                        options.etherdump);
358elif len(bm) == 1:
359    root = Root(full_system=True, system=test_sys)
360else:
361    print "Error I don't know how to create more than 2 systems."
362    sys.exit(1)
363
364if options.timesync:
365    root.time_sync_enable = True
366
367if options.frame_capture:
368    VncServer.frame_capture = True
369
370Simulation.setWorkCountOptions(test_sys, options)
371Simulation.run(options, root, test_sys, FutureClass)
372