se.py revision 13774
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
4512564Sgabeblack@google.comfrom __future__ import print_function
4613774Sandreas.sandberg@arm.comfrom __future__ import absolute_import
4712564Sgabeblack@google.com
486654Snate@binkert.orgimport optparse
496654Snate@binkert.orgimport sys
509907Snilay@cs.wisc.eduimport os
516654Snate@binkert.org
522667SN/Aimport m5
536654Snate@binkert.orgfrom m5.defines import buildEnv
546654Snate@binkert.orgfrom m5.objects import *
5512395Sswapnilster@gmail.comfrom m5.util import addToPath, fatal, warn
565457Ssaidi@eecs.umich.edu
5711670Sandreas.hansson@arm.comaddToPath('../')
5811670Sandreas.hansson@arm.com
5911670Sandreas.hansson@arm.comfrom ruby import Ruby
608169SLisa.Hsu@amd.com
6111682Sandreas.hansson@arm.comfrom common import Options
6211682Sandreas.hansson@arm.comfrom common import Simulation
6311682Sandreas.hansson@arm.comfrom common import CacheConfig
6411682Sandreas.hansson@arm.comfrom common import CpuConfig
6513432Spau.cabre@metempsy.comfrom common import BPConfig
6611682Sandreas.hansson@arm.comfrom common import MemConfig
6711682Sandreas.hansson@arm.comfrom common.Caches import *
6811682Sandreas.hansson@arm.comfrom common.cpu2000 import *
693394Shsul@eecs.umich.edu
709197Snilay@cs.wisc.edudef get_processes(options):
719197Snilay@cs.wisc.edu    """Interprets provided options and returns a list of processes"""
729197Snilay@cs.wisc.edu
739197Snilay@cs.wisc.edu    multiprocesses = []
749197Snilay@cs.wisc.edu    inputs = []
759197Snilay@cs.wisc.edu    outputs = []
769197Snilay@cs.wisc.edu    errouts = []
779197Snilay@cs.wisc.edu    pargs = []
789197Snilay@cs.wisc.edu
799197Snilay@cs.wisc.edu    workloads = options.cmd.split(';')
809197Snilay@cs.wisc.edu    if options.input != "":
819197Snilay@cs.wisc.edu        inputs = options.input.split(';')
829197Snilay@cs.wisc.edu    if options.output != "":
839197Snilay@cs.wisc.edu        outputs = options.output.split(';')
849197Snilay@cs.wisc.edu    if options.errout != "":
859197Snilay@cs.wisc.edu        errouts = options.errout.split(';')
869197Snilay@cs.wisc.edu    if options.options != "":
879197Snilay@cs.wisc.edu        pargs = options.options.split(';')
889197Snilay@cs.wisc.edu
899197Snilay@cs.wisc.edu    idx = 0
909197Snilay@cs.wisc.edu    for wrkld in workloads:
9112146Spau.cabre@metempsy.com        process = Process(pid = 100 + idx)
929197Snilay@cs.wisc.edu        process.executable = wrkld
939907Snilay@cs.wisc.edu        process.cwd = os.getcwd()
949197Snilay@cs.wisc.edu
9510803Sbrandon.potter@amd.com        if options.env:
9610803Sbrandon.potter@amd.com            with open(options.env, 'r') as f:
9710803Sbrandon.potter@amd.com                process.env = [line.rstrip() for line in f]
9810803Sbrandon.potter@amd.com
999197Snilay@cs.wisc.edu        if len(pargs) > idx:
1009217Snilay@cs.wisc.edu            process.cmd = [wrkld] + pargs[idx].split()
1019197Snilay@cs.wisc.edu        else:
1029197Snilay@cs.wisc.edu            process.cmd = [wrkld]
1039197Snilay@cs.wisc.edu
1049197Snilay@cs.wisc.edu        if len(inputs) > idx:
1059197Snilay@cs.wisc.edu            process.input = inputs[idx]
1069197Snilay@cs.wisc.edu        if len(outputs) > idx:
1079197Snilay@cs.wisc.edu            process.output = outputs[idx]
1089197Snilay@cs.wisc.edu        if len(errouts) > idx:
1099197Snilay@cs.wisc.edu            process.errout = errouts[idx]
1109197Snilay@cs.wisc.edu
1119197Snilay@cs.wisc.edu        multiprocesses.append(process)
1129197Snilay@cs.wisc.edu        idx += 1
1139197Snilay@cs.wisc.edu
1149197Snilay@cs.wisc.edu    if options.smt:
11512014Sgabeblack@google.com        assert(options.cpu_type == "DerivO3CPU")
1169197Snilay@cs.wisc.edu        return multiprocesses, idx
1179197Snilay@cs.wisc.edu    else:
1189197Snilay@cs.wisc.edu        return multiprocesses, 1
1199197Snilay@cs.wisc.edu
1209197Snilay@cs.wisc.edu
1212957SN/Aparser = optparse.OptionParser()
1228920Snilay@cs.wisc.eduOptions.addCommonOptions(parser)
1238920Snilay@cs.wisc.eduOptions.addSEOptions(parser)
1242957SN/A
1258862Snilay@cs.wisc.eduif '--ruby' in sys.argv:
1268862Snilay@cs.wisc.edu    Ruby.define_options(parser)
1278467Snilay@cs.wisc.edu
1282957SN/A(options, args) = parser.parse_args()
1292957SN/A
1302957SN/Aif args:
13112564Sgabeblack@google.com    print("Error: script doesn't take any positional arguments")
1322957SN/A    sys.exit(1)
1332957SN/A
1348167SLisa.Hsu@amd.commultiprocesses = []
1359197Snilay@cs.wisc.edunumThreads = 1
1368167SLisa.Hsu@amd.com
1375369Ssaidi@eecs.umich.eduif options.bench:
1388167SLisa.Hsu@amd.com    apps = options.bench.split("-")
1398167SLisa.Hsu@amd.com    if len(apps) != options.num_cpus:
14012564Sgabeblack@google.com        print("number of benchmarks not equal to set num_cpus!")
1418167SLisa.Hsu@amd.com        sys.exit(1)
1428167SLisa.Hsu@amd.com
1438167SLisa.Hsu@amd.com    for app in apps:
1448167SLisa.Hsu@amd.com        try:
1458168SLisa.Hsu@amd.com            if buildEnv['TARGET_ISA'] == 'alpha':
14610037SARM gem5 Developers                exec("workload = %s('alpha', 'tru64', '%s')" % (
14710037SARM gem5 Developers                        app, options.spec_input))
14810037SARM gem5 Developers            elif buildEnv['TARGET_ISA'] == 'arm':
14910037SARM gem5 Developers                exec("workload = %s('arm_%s', 'linux', '%s')" % (
15010037SARM gem5 Developers                        app, options.arm_iset, options.spec_input))
1518168SLisa.Hsu@amd.com            else:
15210037SARM gem5 Developers                exec("workload = %s(buildEnv['TARGET_ISA', 'linux', '%s')" % (
15310037SARM gem5 Developers                        app, options.spec_input))
15411851Sbrandon.potter@amd.com            multiprocesses.append(workload.makeProcess())
1558167SLisa.Hsu@amd.com        except:
15612564Sgabeblack@google.com            print("Unable to find workload for %s: %s" %
15712564Sgabeblack@google.com                  (buildEnv['TARGET_ISA'], app),
15812564Sgabeblack@google.com                  file=sys.stderr)
1595369Ssaidi@eecs.umich.edu            sys.exit(1)
1608920Snilay@cs.wisc.eduelif options.cmd:
1619197Snilay@cs.wisc.edu    multiprocesses, numThreads = get_processes(options)
1628920Snilay@cs.wisc.eduelse:
16312564Sgabeblack@google.com    print("No workload specified. Exiting!\n", file=sys.stderr)
1648920Snilay@cs.wisc.edu    sys.exit(1)
1655369Ssaidi@eecs.umich.edu
1665369Ssaidi@eecs.umich.edu
1678718Snilay@cs.wisc.edu(CPUClass, test_mem_mode, FutureClass) = Simulation.setCPUClass(options)
1689197Snilay@cs.wisc.eduCPUClass.numThreads = numThreads
1699197Snilay@cs.wisc.edu
1709197Snilay@cs.wisc.edu# Check -- do not allow SMT with multiple CPUs
1719197Snilay@cs.wisc.eduif options.smt and options.num_cpus > 1:
1729197Snilay@cs.wisc.edu    fatal("You cannot use SMT with multiple CPUs!")
1733005Sstever@eecs.umich.edu
1743395Shsul@eecs.umich.edunp = options.num_cpus
17513731Sandreas.sandberg@arm.comsystem = System(cpu = [CPUClass(cpu_id=i) for i in range(np)],
1769793Sakash.bagdia@arm.com                mem_mode = test_mem_mode,
1779836Sandreas.hansson@arm.com                mem_ranges = [AddrRange(options.mem_size)],
1789815SAndreas Hansson <andreas.hansson>                cache_line_size = options.cacheline_size)
1799793Sakash.bagdia@arm.com
18011147Smitch.hayenga@arm.comif numThreads > 1:
18111147Smitch.hayenga@arm.com    system.multi_thread = True
18211147Smitch.hayenga@arm.com
1839827Sakash.bagdia@arm.com# Create a top-level voltage domain
1849827Sakash.bagdia@arm.comsystem.voltage_domain = VoltageDomain(voltage = options.sys_voltage)
1859827Sakash.bagdia@arm.com
1869827Sakash.bagdia@arm.com# Create a source clock for the system and set the clock period
1879827Sakash.bagdia@arm.comsystem.clk_domain = SrcClockDomain(clock =  options.sys_clock,
1889827Sakash.bagdia@arm.com                                   voltage_domain = system.voltage_domain)
1899827Sakash.bagdia@arm.com
1909827Sakash.bagdia@arm.com# Create a CPU voltage domain
1919827Sakash.bagdia@arm.comsystem.cpu_voltage_domain = VoltageDomain()
1929827Sakash.bagdia@arm.com
1939793Sakash.bagdia@arm.com# Create a separate clock domain for the CPUs
1949827Sakash.bagdia@arm.comsystem.cpu_clk_domain = SrcClockDomain(clock = options.cpu_clock,
1959827Sakash.bagdia@arm.com                                       voltage_domain =
1969827Sakash.bagdia@arm.com                                       system.cpu_voltage_domain)
1979793Sakash.bagdia@arm.com
19811251Sradhika.jagtap@ARM.com# If elastic tracing is enabled, then configure the cpu and attach the elastic
19911251Sradhika.jagtap@ARM.com# trace probe
20011251Sradhika.jagtap@ARM.comif options.elastic_trace_en:
20111251Sradhika.jagtap@ARM.com    CpuConfig.config_etrace(CPUClass, system.cpu, options)
20211251Sradhika.jagtap@ARM.com
2039793Sakash.bagdia@arm.com# All cpus belong to a common cpu_clk_domain, therefore running at a common
2049793Sakash.bagdia@arm.com# frequency.
2059793Sakash.bagdia@arm.comfor cpu in system.cpu:
2069793Sakash.bagdia@arm.com    cpu.clk_domain = system.cpu_clk_domain
2073395Shsul@eecs.umich.edu
20812941Sandreas.sandberg@arm.comif CpuConfig.is_kvm_cpu(CPUClass) or CpuConfig.is_kvm_cpu(FutureClass):
20910555Salexandru.dutu@amd.com    if buildEnv['TARGET_ISA'] == 'x86':
21011839SCurtis.Dunham@arm.com        system.kvm_vm = KvmVM()
21110555Salexandru.dutu@amd.com        for process in multiprocesses:
21210555Salexandru.dutu@amd.com            process.useArchPT = True
21310555Salexandru.dutu@amd.com            process.kvmInSE = True
21410555Salexandru.dutu@amd.com    else:
21510555Salexandru.dutu@amd.com        fatal("KvmCPU can only be used in SE mode with x86")
21610555Salexandru.dutu@amd.com
2178926Sandreas.hansson@arm.com# Sanity check
2189647Sdam.sunwoo@arm.comif options.simpoint_profile:
21913684Sgiacomo.travaglini@arm.com    if not CpuConfig.is_noncaching_cpu(CPUClass):
22013012Sandreas.sandberg@arm.com        fatal("SimPoint/BPProbe should be done with an atomic cpu")
2219647Sdam.sunwoo@arm.com    if np > 1:
2229647Sdam.sunwoo@arm.com        fatal("SimPoint generation not supported with more than one CPUs")
2239647Sdam.sunwoo@arm.com
22413731Sandreas.sandberg@arm.comfor i in range(np):
2259197Snilay@cs.wisc.edu    if options.smt:
2269197Snilay@cs.wisc.edu        system.cpu[i].workload = multiprocesses
2279197Snilay@cs.wisc.edu    elif len(multiprocesses) == 1:
2288957Sjayneel@cs.wisc.edu        system.cpu[i].workload = multiprocesses[0]
2298957Sjayneel@cs.wisc.edu    else:
2308957Sjayneel@cs.wisc.edu        system.cpu[i].workload = multiprocesses[i]
2313005Sstever@eecs.umich.edu
2329647Sdam.sunwoo@arm.com    if options.simpoint_profile:
23310381Sdam.sunwoo@arm.com        system.cpu[i].addSimPointProbe(options.simpoint_interval)
2349647Sdam.sunwoo@arm.com
2358887Sgeoffrey.blake@arm.com    if options.checker:
2368887Sgeoffrey.blake@arm.com        system.cpu[i].addCheckerCpu()
2378887Sgeoffrey.blake@arm.com
23813432Spau.cabre@metempsy.com    if options.bp_type:
23913432Spau.cabre@metempsy.com        bpClass = BPConfig.get(options.bp_type)
24013432Spau.cabre@metempsy.com        system.cpu[i].branchPred = bpClass()
24113432Spau.cabre@metempsy.com
2429384SAndreas.Sandberg@arm.com    system.cpu[i].createThreads()
2439384SAndreas.Sandberg@arm.com
2448887Sgeoffrey.blake@arm.comif options.ruby:
24510519Snilay@cs.wisc.edu    Ruby.create_system(options, False, system)
24610120Snilay@cs.wisc.edu    assert(options.num_cpus == len(system.ruby._cpu_ports))
2478896Snilay@cs.wisc.edu
24810300Scastilloe@unican.es    system.ruby.clk_domain = SrcClockDomain(clock = options.ruby_clock,
24910300Scastilloe@unican.es                                        voltage_domain = system.voltage_domain)
25013731Sandreas.sandberg@arm.com    for i in range(np):
25110120Snilay@cs.wisc.edu        ruby_port = system.ruby._cpu_ports[i]
2528896Snilay@cs.wisc.edu
2538896Snilay@cs.wisc.edu        # Create the interrupt controller and connect its ports to Ruby
2549268Smalek.musleh@gmail.com        # Note that the interrupt controller is always present but only
2559268Smalek.musleh@gmail.com        # in x86 does it have message ports that need to be connected
2568896Snilay@cs.wisc.edu        system.cpu[i].createInterruptController()
2578896Snilay@cs.wisc.edu
2588896Snilay@cs.wisc.edu        # Connect the cpu's cache ports to Ruby
2598896Snilay@cs.wisc.edu        system.cpu[i].icache_port = ruby_port.slave
2608896Snilay@cs.wisc.edu        system.cpu[i].dcache_port = ruby_port.slave
2619222Shestness@cs.wisc.edu        if buildEnv['TARGET_ISA'] == 'x86':
26211150Smitch.hayenga@arm.com            system.cpu[i].interrupts[0].pio = ruby_port.master
26311150Smitch.hayenga@arm.com            system.cpu[i].interrupts[0].int_master = ruby_port.slave
26411150Smitch.hayenga@arm.com            system.cpu[i].interrupts[0].int_slave = ruby_port.master
2659222Shestness@cs.wisc.edu            system.cpu[i].itb.walker.port = ruby_port.slave
2669222Shestness@cs.wisc.edu            system.cpu[i].dtb.walker.port = ruby_port.slave
2678887Sgeoffrey.blake@arm.comelse:
26810150Snilay@cs.wisc.edu    MemClass = Simulation.setMemClass(options)
26910720Sandreas.hansson@arm.com    system.membus = SystemXBar()
2708887Sgeoffrey.blake@arm.com    system.system_port = system.membus.slave
2718887Sgeoffrey.blake@arm.com    CacheConfig.config_cache(options, system)
2729836Sandreas.hansson@arm.com    MemConfig.config_mem(options, system)
2738887Sgeoffrey.blake@arm.com
2748801Sgblack@eecs.umich.eduroot = Root(full_system = False, system = system)
2753481Shsul@eecs.umich.eduSimulation.run(options, root, system, FutureClass)
276