se.py revision 9907
19793Sakash.bagdia@arm.com# Copyright (c) 2012-2013 ARM Limited
28706Sandreas.hansson@arm.com# All rights reserved.
38706Sandreas.hansson@arm.com#
48706Sandreas.hansson@arm.com# The license below extends only to copyright in the software and shall
58706Sandreas.hansson@arm.com# not be construed as granting a license to any other intellectual
68706Sandreas.hansson@arm.com# property including but not limited to intellectual property relating
78706Sandreas.hansson@arm.com# to a hardware implementation of the functionality of the software
88706Sandreas.hansson@arm.com# licensed hereunder.  You may use the software subject to the license
98706Sandreas.hansson@arm.com# terms below provided that you ensure that this notice is replicated
108706Sandreas.hansson@arm.com# unmodified and in its entirety in all distributions of the software,
118706Sandreas.hansson@arm.com# modified or unmodified, in source code or in binary form.
128706Sandreas.hansson@arm.com#
135369Ssaidi@eecs.umich.edu# Copyright (c) 2006-2008 The Regents of The University of Michigan
143005Sstever@eecs.umich.edu# All rights reserved.
153005Sstever@eecs.umich.edu#
163005Sstever@eecs.umich.edu# Redistribution and use in source and binary forms, with or without
173005Sstever@eecs.umich.edu# modification, are permitted provided that the following conditions are
183005Sstever@eecs.umich.edu# met: redistributions of source code must retain the above copyright
193005Sstever@eecs.umich.edu# notice, this list of conditions and the following disclaimer;
203005Sstever@eecs.umich.edu# redistributions in binary form must reproduce the above copyright
213005Sstever@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the
223005Sstever@eecs.umich.edu# documentation and/or other materials provided with the distribution;
233005Sstever@eecs.umich.edu# neither the name of the copyright holders nor the names of its
243005Sstever@eecs.umich.edu# contributors may be used to endorse or promote products derived from
253005Sstever@eecs.umich.edu# this software without specific prior written permission.
263005Sstever@eecs.umich.edu#
273005Sstever@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
283005Sstever@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
293005Sstever@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
303005Sstever@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
313005Sstever@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
323005Sstever@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
333005Sstever@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
343005Sstever@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
353005Sstever@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
363005Sstever@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
373005Sstever@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
383005Sstever@eecs.umich.edu#
393005Sstever@eecs.umich.edu# Authors: Steve Reinhardt
403005Sstever@eecs.umich.edu
412710SN/A# Simple test script
422710SN/A#
433005Sstever@eecs.umich.edu# "m5 test.py"
442889SN/A
456654Snate@binkert.orgimport optparse
466654Snate@binkert.orgimport sys
479907Snilay@cs.wisc.eduimport os
486654Snate@binkert.org
492667SN/Aimport m5
506654Snate@binkert.orgfrom m5.defines import buildEnv
516654Snate@binkert.orgfrom m5.objects import *
526654Snate@binkert.orgfrom m5.util import addToPath, fatal
535457Ssaidi@eecs.umich.edu
546654Snate@binkert.orgaddToPath('../common')
558169SLisa.Hsu@amd.comaddToPath('../ruby')
569100SBrad.Beckmann@amd.comaddToPath('../topologies')
578169SLisa.Hsu@amd.com
588920Snilay@cs.wisc.eduimport Options
598169SLisa.Hsu@amd.comimport Ruby
603395Shsul@eecs.umich.eduimport Simulation
616981SLisa.Hsu@amd.comimport CacheConfig
629836Sandreas.hansson@arm.comimport MemConfig
633448Shsul@eecs.umich.edufrom Caches import *
645369Ssaidi@eecs.umich.edufrom cpu2000 import *
653394Shsul@eecs.umich.edu
669197Snilay@cs.wisc.edudef get_processes(options):
679197Snilay@cs.wisc.edu    """Interprets provided options and returns a list of processes"""
689197Snilay@cs.wisc.edu
699197Snilay@cs.wisc.edu    multiprocesses = []
709197Snilay@cs.wisc.edu    inputs = []
719197Snilay@cs.wisc.edu    outputs = []
729197Snilay@cs.wisc.edu    errouts = []
739197Snilay@cs.wisc.edu    pargs = []
749197Snilay@cs.wisc.edu
759197Snilay@cs.wisc.edu    workloads = options.cmd.split(';')
769197Snilay@cs.wisc.edu    if options.input != "":
779197Snilay@cs.wisc.edu        inputs = options.input.split(';')
789197Snilay@cs.wisc.edu    if options.output != "":
799197Snilay@cs.wisc.edu        outputs = options.output.split(';')
809197Snilay@cs.wisc.edu    if options.errout != "":
819197Snilay@cs.wisc.edu        errouts = options.errout.split(';')
829197Snilay@cs.wisc.edu    if options.options != "":
839197Snilay@cs.wisc.edu        pargs = options.options.split(';')
849197Snilay@cs.wisc.edu
859197Snilay@cs.wisc.edu    idx = 0
869197Snilay@cs.wisc.edu    for wrkld in workloads:
879197Snilay@cs.wisc.edu        process = LiveProcess()
889197Snilay@cs.wisc.edu        process.executable = wrkld
899907Snilay@cs.wisc.edu        process.cwd = os.getcwd()
909197Snilay@cs.wisc.edu
919197Snilay@cs.wisc.edu        if len(pargs) > idx:
929217Snilay@cs.wisc.edu            process.cmd = [wrkld] + pargs[idx].split()
939197Snilay@cs.wisc.edu        else:
949197Snilay@cs.wisc.edu            process.cmd = [wrkld]
959197Snilay@cs.wisc.edu
969197Snilay@cs.wisc.edu        if len(inputs) > idx:
979197Snilay@cs.wisc.edu            process.input = inputs[idx]
989197Snilay@cs.wisc.edu        if len(outputs) > idx:
999197Snilay@cs.wisc.edu            process.output = outputs[idx]
1009197Snilay@cs.wisc.edu        if len(errouts) > idx:
1019197Snilay@cs.wisc.edu            process.errout = errouts[idx]
1029197Snilay@cs.wisc.edu
1039197Snilay@cs.wisc.edu        multiprocesses.append(process)
1049197Snilay@cs.wisc.edu        idx += 1
1059197Snilay@cs.wisc.edu
1069197Snilay@cs.wisc.edu    if options.smt:
1079197Snilay@cs.wisc.edu        assert(options.cpu_type == "detailed" or options.cpu_type == "inorder")
1089197Snilay@cs.wisc.edu        return multiprocesses, idx
1099197Snilay@cs.wisc.edu    else:
1109197Snilay@cs.wisc.edu        return multiprocesses, 1
1119197Snilay@cs.wisc.edu
1129197Snilay@cs.wisc.edu
1132957SN/Aparser = optparse.OptionParser()
1148920Snilay@cs.wisc.eduOptions.addCommonOptions(parser)
1158920Snilay@cs.wisc.eduOptions.addSEOptions(parser)
1162957SN/A
1178862Snilay@cs.wisc.eduif '--ruby' in sys.argv:
1188862Snilay@cs.wisc.edu    Ruby.define_options(parser)
1198467Snilay@cs.wisc.edu
1202957SN/A(options, args) = parser.parse_args()
1212957SN/A
1222957SN/Aif args:
1232957SN/A    print "Error: script doesn't take any positional arguments"
1242957SN/A    sys.exit(1)
1252957SN/A
1268167SLisa.Hsu@amd.commultiprocesses = []
1279197Snilay@cs.wisc.edunumThreads = 1
1288167SLisa.Hsu@amd.com
1295369Ssaidi@eecs.umich.eduif options.bench:
1308167SLisa.Hsu@amd.com    apps = options.bench.split("-")
1318167SLisa.Hsu@amd.com    if len(apps) != options.num_cpus:
1328167SLisa.Hsu@amd.com        print "number of benchmarks not equal to set num_cpus!"
1338167SLisa.Hsu@amd.com        sys.exit(1)
1348167SLisa.Hsu@amd.com
1358167SLisa.Hsu@amd.com    for app in apps:
1368167SLisa.Hsu@amd.com        try:
1378168SLisa.Hsu@amd.com            if buildEnv['TARGET_ISA'] == 'alpha':
1388168SLisa.Hsu@amd.com                exec("workload = %s('alpha', 'tru64', 'ref')" % app)
1398168SLisa.Hsu@amd.com            else:
1408168SLisa.Hsu@amd.com                exec("workload = %s(buildEnv['TARGET_ISA'], 'linux', 'ref')" % app)
1418167SLisa.Hsu@amd.com            multiprocesses.append(workload.makeLiveProcess())
1428167SLisa.Hsu@amd.com        except:
1438168SLisa.Hsu@amd.com            print >>sys.stderr, "Unable to find workload for %s: %s" % (buildEnv['TARGET_ISA'], app)
1445369Ssaidi@eecs.umich.edu            sys.exit(1)
1458920Snilay@cs.wisc.eduelif options.cmd:
1469197Snilay@cs.wisc.edu    multiprocesses, numThreads = get_processes(options)
1478920Snilay@cs.wisc.eduelse:
1488920Snilay@cs.wisc.edu    print >> sys.stderr, "No workload specified. Exiting!\n"
1498920Snilay@cs.wisc.edu    sys.exit(1)
1505369Ssaidi@eecs.umich.edu
1515369Ssaidi@eecs.umich.edu
1528718Snilay@cs.wisc.edu(CPUClass, test_mem_mode, FutureClass) = Simulation.setCPUClass(options)
1539197Snilay@cs.wisc.eduCPUClass.numThreads = numThreads
1549197Snilay@cs.wisc.edu
1559665Sandreas.hansson@arm.comMemClass = Simulation.setMemClass(options)
1569665Sandreas.hansson@arm.com
1579197Snilay@cs.wisc.edu# Check -- do not allow SMT with multiple CPUs
1589197Snilay@cs.wisc.eduif options.smt and options.num_cpus > 1:
1599197Snilay@cs.wisc.edu    fatal("You cannot use SMT with multiple CPUs!")
1603005Sstever@eecs.umich.edu
1613395Shsul@eecs.umich.edunp = options.num_cpus
1623395Shsul@eecs.umich.edusystem = System(cpu = [CPUClass(cpu_id=i) for i in xrange(np)],
1639793Sakash.bagdia@arm.com                mem_mode = test_mem_mode,
1649836Sandreas.hansson@arm.com                mem_ranges = [AddrRange(options.mem_size)],
1659815SAndreas Hansson <andreas.hansson>                cache_line_size = options.cacheline_size)
1669793Sakash.bagdia@arm.com
1679827Sakash.bagdia@arm.com# Create a top-level voltage domain
1689827Sakash.bagdia@arm.comsystem.voltage_domain = VoltageDomain(voltage = options.sys_voltage)
1699827Sakash.bagdia@arm.com
1709827Sakash.bagdia@arm.com# Create a source clock for the system and set the clock period
1719827Sakash.bagdia@arm.comsystem.clk_domain = SrcClockDomain(clock =  options.sys_clock,
1729827Sakash.bagdia@arm.com                                   voltage_domain = system.voltage_domain)
1739827Sakash.bagdia@arm.com
1749827Sakash.bagdia@arm.com# Create a CPU voltage domain
1759827Sakash.bagdia@arm.comsystem.cpu_voltage_domain = VoltageDomain()
1769827Sakash.bagdia@arm.com
1779793Sakash.bagdia@arm.com# Create a separate clock domain for the CPUs
1789827Sakash.bagdia@arm.comsystem.cpu_clk_domain = SrcClockDomain(clock = options.cpu_clock,
1799827Sakash.bagdia@arm.com                                       voltage_domain =
1809827Sakash.bagdia@arm.com                                       system.cpu_voltage_domain)
1819793Sakash.bagdia@arm.com
1829793Sakash.bagdia@arm.com# All cpus belong to a common cpu_clk_domain, therefore running at a common
1839793Sakash.bagdia@arm.com# frequency.
1849793Sakash.bagdia@arm.comfor cpu in system.cpu:
1859793Sakash.bagdia@arm.com    cpu.clk_domain = system.cpu_clk_domain
1863395Shsul@eecs.umich.edu
1878926Sandreas.hansson@arm.com# Sanity check
1889317Sandreas.hansson@arm.comif options.fastmem:
1899317Sandreas.hansson@arm.com    if CPUClass != AtomicSimpleCPU:
1909317Sandreas.hansson@arm.com        fatal("Fastmem can only be used with atomic CPU!")
1919317Sandreas.hansson@arm.com    if (options.caches or options.l2cache):
1929317Sandreas.hansson@arm.com        fatal("You cannot use fastmem in combination with caches!")
1938926Sandreas.hansson@arm.com
1949647Sdam.sunwoo@arm.comif options.simpoint_profile:
1959647Sdam.sunwoo@arm.com    if not options.fastmem:
1969647Sdam.sunwoo@arm.com        # Atomic CPU checked with fastmem option already
1979647Sdam.sunwoo@arm.com        fatal("SimPoint generation should be done with atomic cpu and fastmem")
1989647Sdam.sunwoo@arm.com    if np > 1:
1999647Sdam.sunwoo@arm.com        fatal("SimPoint generation not supported with more than one CPUs")
2009647Sdam.sunwoo@arm.com
2013395Shsul@eecs.umich.edufor i in xrange(np):
2029197Snilay@cs.wisc.edu    if options.smt:
2039197Snilay@cs.wisc.edu        system.cpu[i].workload = multiprocesses
2049197Snilay@cs.wisc.edu    elif len(multiprocesses) == 1:
2058957Sjayneel@cs.wisc.edu        system.cpu[i].workload = multiprocesses[0]
2068957Sjayneel@cs.wisc.edu    else:
2078957Sjayneel@cs.wisc.edu        system.cpu[i].workload = multiprocesses[i]
2083005Sstever@eecs.umich.edu
2094968Sacolyte@umich.edu    if options.fastmem:
2109006Sandreas.hansson@arm.com        system.cpu[i].fastmem = True
2114968Sacolyte@umich.edu
2129647Sdam.sunwoo@arm.com    if options.simpoint_profile:
2139647Sdam.sunwoo@arm.com        system.cpu[i].simpoint_profile = True
2149647Sdam.sunwoo@arm.com        system.cpu[i].simpoint_interval = options.simpoint_interval
2159647Sdam.sunwoo@arm.com
2168887Sgeoffrey.blake@arm.com    if options.checker:
2178887Sgeoffrey.blake@arm.com        system.cpu[i].addCheckerCpu()
2188887Sgeoffrey.blake@arm.com
2199384SAndreas.Sandberg@arm.com    system.cpu[i].createThreads()
2209384SAndreas.Sandberg@arm.com
2218887Sgeoffrey.blake@arm.comif options.ruby:
2228896Snilay@cs.wisc.edu    if not (options.cpu_type == "detailed" or options.cpu_type == "timing"):
2238896Snilay@cs.wisc.edu        print >> sys.stderr, "Ruby requires TimingSimpleCPU or O3CPU!!"
2248896Snilay@cs.wisc.edu        sys.exit(1)
2258896Snilay@cs.wisc.edu
2269577Snilay@cs.wisc.edu    # Set the option for physmem so that it is not allocated any space
2279836Sandreas.hansson@arm.com    system.physmem = MemClass(range=AddrRange(options.mem_size),
2289836Sandreas.hansson@arm.com                              null = True)
2299577Snilay@cs.wisc.edu
2308887Sgeoffrey.blake@arm.com    options.use_map = True
2318887Sgeoffrey.blake@arm.com    Ruby.create_system(options, system)
2328887Sgeoffrey.blake@arm.com    assert(options.num_cpus == len(system.ruby._cpu_ruby_ports))
2338896Snilay@cs.wisc.edu
2348896Snilay@cs.wisc.edu    for i in xrange(np):
2358896Snilay@cs.wisc.edu        ruby_port = system.ruby._cpu_ruby_ports[i]
2368896Snilay@cs.wisc.edu
2378896Snilay@cs.wisc.edu        # Create the interrupt controller and connect its ports to Ruby
2389268Smalek.musleh@gmail.com        # Note that the interrupt controller is always present but only
2399268Smalek.musleh@gmail.com        # in x86 does it have message ports that need to be connected
2408896Snilay@cs.wisc.edu        system.cpu[i].createInterruptController()
2418896Snilay@cs.wisc.edu
2428896Snilay@cs.wisc.edu        # Connect the cpu's cache ports to Ruby
2438896Snilay@cs.wisc.edu        system.cpu[i].icache_port = ruby_port.slave
2448896Snilay@cs.wisc.edu        system.cpu[i].dcache_port = ruby_port.slave
2459222Shestness@cs.wisc.edu        if buildEnv['TARGET_ISA'] == 'x86':
2469268Smalek.musleh@gmail.com            system.cpu[i].interrupts.pio = ruby_port.master
2479268Smalek.musleh@gmail.com            system.cpu[i].interrupts.int_master = ruby_port.slave
2489268Smalek.musleh@gmail.com            system.cpu[i].interrupts.int_slave = ruby_port.master
2499222Shestness@cs.wisc.edu            system.cpu[i].itb.walker.port = ruby_port.slave
2509222Shestness@cs.wisc.edu            system.cpu[i].dtb.walker.port = ruby_port.slave
2518887Sgeoffrey.blake@arm.comelse:
2529756Snilay@cs.wisc.edu    system.membus = CoherentBus()
2538887Sgeoffrey.blake@arm.com    system.system_port = system.membus.slave
2548887Sgeoffrey.blake@arm.com    CacheConfig.config_cache(options, system)
2559836Sandreas.hansson@arm.com    MemConfig.config_mem(options, system)
2568887Sgeoffrey.blake@arm.com
2578801Sgblack@eecs.umich.eduroot = Root(full_system = False, system = system)
2583481Shsul@eecs.umich.eduSimulation.run(options, root, system, FutureClass)
259