se.py revision 8801
112855Sgabeblack@google.com# Copyright (c) 2012 ARM Limited
212855Sgabeblack@google.com# All rights reserved.
312855Sgabeblack@google.com#
412855Sgabeblack@google.com# The license below extends only to copyright in the software and shall
512855Sgabeblack@google.com# not be construed as granting a license to any other intellectual
612855Sgabeblack@google.com# property including but not limited to intellectual property relating
712855Sgabeblack@google.com# to a hardware implementation of the functionality of the software
812855Sgabeblack@google.com# licensed hereunder.  You may use the software subject to the license
912855Sgabeblack@google.com# terms below provided that you ensure that this notice is replicated
1012855Sgabeblack@google.com# unmodified and in its entirety in all distributions of the software,
1112855Sgabeblack@google.com# modified or unmodified, in source code or in binary form.
1212855Sgabeblack@google.com#
1312855Sgabeblack@google.com# Copyright (c) 2006-2008 The Regents of The University of Michigan
1412855Sgabeblack@google.com# All rights reserved.
1512855Sgabeblack@google.com#
1612855Sgabeblack@google.com# Redistribution and use in source and binary forms, with or without
1712855Sgabeblack@google.com# modification, are permitted provided that the following conditions are
1812855Sgabeblack@google.com# met: redistributions of source code must retain the above copyright
1912855Sgabeblack@google.com# notice, this list of conditions and the following disclaimer;
2012855Sgabeblack@google.com# redistributions in binary form must reproduce the above copyright
2112855Sgabeblack@google.com# notice, this list of conditions and the following disclaimer in the
2212855Sgabeblack@google.com# documentation and/or other materials provided with the distribution;
2312855Sgabeblack@google.com# neither the name of the copyright holders nor the names of its
2412855Sgabeblack@google.com# contributors may be used to endorse or promote products derived from
2512855Sgabeblack@google.com# this software without specific prior written permission.
2612855Sgabeblack@google.com#
2712855Sgabeblack@google.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2812855Sgabeblack@google.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2912855Sgabeblack@google.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3012855Sgabeblack@google.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3112855Sgabeblack@google.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3212855Sgabeblack@google.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3312855Sgabeblack@google.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3412855Sgabeblack@google.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3512855Sgabeblack@google.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3612855Sgabeblack@google.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3712855Sgabeblack@google.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3812855Sgabeblack@google.com#
3912855Sgabeblack@google.com# Authors: Steve Reinhardt
4012855Sgabeblack@google.com
4112855Sgabeblack@google.com# Simple test script
4212855Sgabeblack@google.com#
4312855Sgabeblack@google.com# "m5 test.py"
4412855Sgabeblack@google.com
4512855Sgabeblack@google.comimport os
4612855Sgabeblack@google.comimport optparse
4712855Sgabeblack@google.comimport sys
4812855Sgabeblack@google.comfrom os.path import join as joinpath
4912855Sgabeblack@google.com
5012855Sgabeblack@google.comimport m5
5112855Sgabeblack@google.comfrom m5.defines import buildEnv
5212855Sgabeblack@google.comfrom m5.objects import *
5312855Sgabeblack@google.comfrom m5.util import addToPath, fatal
5412855Sgabeblack@google.com
5512855Sgabeblack@google.comif buildEnv['FULL_SYSTEM']:
5612855Sgabeblack@google.com    fatal("This script requires syscall emulation mode (*_SE).")
5712855Sgabeblack@google.com
5812855Sgabeblack@google.comaddToPath('../common')
5912855Sgabeblack@google.comaddToPath('../ruby')
6012855Sgabeblack@google.com
6112855Sgabeblack@google.comimport Ruby
6212855Sgabeblack@google.com
6312855Sgabeblack@google.comimport Simulation
6412855Sgabeblack@google.comimport CacheConfig
6512855Sgabeblack@google.comfrom Caches import *
6612855Sgabeblack@google.comfrom cpu2000 import *
6712855Sgabeblack@google.com
6812855Sgabeblack@google.com# Get paths we might need.  It's expected this file is in m5/configs/example.
6912855Sgabeblack@google.comconfig_path = os.path.dirname(os.path.abspath(__file__))
7012855Sgabeblack@google.comconfig_root = os.path.dirname(config_path)
7112855Sgabeblack@google.comm5_root = os.path.dirname(config_root)
7212855Sgabeblack@google.com
7312855Sgabeblack@google.comparser = optparse.OptionParser()
7412855Sgabeblack@google.com
7512855Sgabeblack@google.com# Benchmark options
7612855Sgabeblack@google.comparser.add_option("-c", "--cmd",
7712855Sgabeblack@google.com    default=joinpath(m5_root, "tests/test-progs/hello/bin/%s/linux/hello" % \
7812855Sgabeblack@google.com            buildEnv['TARGET_ISA']),
7912855Sgabeblack@google.com    help="The binary to run in syscall emulation mode.")
8012855Sgabeblack@google.comparser.add_option("-o", "--options", default="",
8112855Sgabeblack@google.com    help='The options to pass to the binary, use " " around the entire string')
8212855Sgabeblack@google.comparser.add_option("-i", "--input", default="", help="Read stdin from a file.")
8312855Sgabeblack@google.comparser.add_option("--output", default="", help="Redirect stdout to a file.")
8412855Sgabeblack@google.comparser.add_option("--errout", default="", help="Redirect stderr to a file.")
8512855Sgabeblack@google.com
8612855Sgabeblack@google.comexecfile(os.path.join(config_root, "common", "Options.py"))
8712855Sgabeblack@google.com
8812855Sgabeblack@google.comif buildEnv['PROTOCOL'] != 'None':
8912855Sgabeblack@google.com    parser.add_option("--ruby", action="store_true")
9012855Sgabeblack@google.com    if '--ruby' in sys.argv:
9112855Sgabeblack@google.com        Ruby.define_options(parser)
9212855Sgabeblack@google.com
9312855Sgabeblack@google.com(options, args) = parser.parse_args()
9412855Sgabeblack@google.com
9512855Sgabeblack@google.comif args:
9612855Sgabeblack@google.com    print "Error: script doesn't take any positional arguments"
9712855Sgabeblack@google.com    sys.exit(1)
9812855Sgabeblack@google.com
9912855Sgabeblack@google.commultiprocesses = []
10012855Sgabeblack@google.comapps = []
10112855Sgabeblack@google.com
10212855Sgabeblack@google.comif options.bench:
10312855Sgabeblack@google.com    apps = options.bench.split("-")
10412855Sgabeblack@google.com    if len(apps) != options.num_cpus:
10512855Sgabeblack@google.com        print "number of benchmarks not equal to set num_cpus!"
10612855Sgabeblack@google.com        sys.exit(1)
10712855Sgabeblack@google.com
10812855Sgabeblack@google.com    for app in apps:
10912855Sgabeblack@google.com        try:
11012855Sgabeblack@google.com            if buildEnv['TARGET_ISA'] == 'alpha':
11112855Sgabeblack@google.com                exec("workload = %s('alpha', 'tru64', 'ref')" % app)
11212855Sgabeblack@google.com            else:
11312855Sgabeblack@google.com                exec("workload = %s(buildEnv['TARGET_ISA'], 'linux', 'ref')" % app)
11412855Sgabeblack@google.com            multiprocesses.append(workload.makeLiveProcess())
11512855Sgabeblack@google.com        except:
11612855Sgabeblack@google.com            print >>sys.stderr, "Unable to find workload for %s: %s" % (buildEnv['TARGET_ISA'], app)
11712855Sgabeblack@google.com            sys.exit(1)
11812855Sgabeblack@google.comelse:
11912855Sgabeblack@google.com    process = LiveProcess()
12012855Sgabeblack@google.com    process.executable = options.cmd
12112855Sgabeblack@google.com    process.cmd = [options.cmd] + options.options.split()
12212855Sgabeblack@google.com    multiprocesses.append(process)
12312855Sgabeblack@google.com
12412855Sgabeblack@google.com
12512855Sgabeblack@google.comif options.input != "":
12612855Sgabeblack@google.com    process.input = options.input
12712855Sgabeblack@google.comif options.output != "":
12812855Sgabeblack@google.com    process.output = options.output
12912855Sgabeblack@google.comif options.errout != "":
13012855Sgabeblack@google.com    process.errout = options.errout
13112855Sgabeblack@google.com
13212855Sgabeblack@google.com
13312855Sgabeblack@google.com# By default, set workload to path of user-specified binary
13412855Sgabeblack@google.comworkloads = options.cmd
13512855Sgabeblack@google.comnumThreads = 1
13612855Sgabeblack@google.com
13712855Sgabeblack@google.comif options.cpu_type == "detailed" or options.cpu_type == "inorder":
13812855Sgabeblack@google.com    #check for SMT workload
13912855Sgabeblack@google.com    workloads = options.cmd.split(';')
14012855Sgabeblack@google.com    if len(workloads) > 1:
14112855Sgabeblack@google.com        process = []
14212855Sgabeblack@google.com        smt_idx = 0
14312855Sgabeblack@google.com        inputs = []
14412855Sgabeblack@google.com        outputs = []
14512855Sgabeblack@google.com        errouts = []
14612855Sgabeblack@google.com
14712855Sgabeblack@google.com        if options.input != "":
14812855Sgabeblack@google.com            inputs = options.input.split(';')
14912855Sgabeblack@google.com        if options.output != "":
15012855Sgabeblack@google.com            outputs = options.output.split(';')
15112855Sgabeblack@google.com        if options.errout != "":
15212855Sgabeblack@google.com            errouts = options.errout.split(';')
15312855Sgabeblack@google.com
15412855Sgabeblack@google.com        for wrkld in workloads:
15512855Sgabeblack@google.com            smt_process = LiveProcess()
15612855Sgabeblack@google.com            smt_process.executable = wrkld
15712855Sgabeblack@google.com            smt_process.cmd = wrkld + " " + options.options
15812855Sgabeblack@google.com            if inputs and inputs[smt_idx]:
15912855Sgabeblack@google.com                smt_process.input = inputs[smt_idx]
16012855Sgabeblack@google.com            if outputs and outputs[smt_idx]:
16112855Sgabeblack@google.com                smt_process.output = outputs[smt_idx]
16212855Sgabeblack@google.com            if errouts and errouts[smt_idx]:
16312855Sgabeblack@google.com                smt_process.errout = errouts[smt_idx]
16412855Sgabeblack@google.com            process += [smt_process, ]
16512855Sgabeblack@google.com            smt_idx += 1
16612855Sgabeblack@google.com    numThreads = len(workloads)
16712855Sgabeblack@google.com
16812855Sgabeblack@google.comif options.ruby:
16912855Sgabeblack@google.com    if not (options.cpu_type == "detailed" or options.cpu_type == "timing"):
17012855Sgabeblack@google.com        print >> sys.stderr, "Ruby requires TimingSimpleCPU or O3CPU!!"
17112855Sgabeblack@google.com        sys.exit(1)
17212855Sgabeblack@google.com
17312855Sgabeblack@google.com(CPUClass, test_mem_mode, FutureClass) = Simulation.setCPUClass(options)
17412855Sgabeblack@google.comCPUClass.clock = '2GHz'
17512855Sgabeblack@google.comCPUClass.numThreads = numThreads;
17612855Sgabeblack@google.com
17712855Sgabeblack@google.comnp = options.num_cpus
17812855Sgabeblack@google.com
17912855Sgabeblack@google.comsystem = System(cpu = [CPUClass(cpu_id=i) for i in xrange(np)],
18012855Sgabeblack@google.com                physmem = PhysicalMemory(range=AddrRange("512MB")),
18112855Sgabeblack@google.com                membus = Bus(), mem_mode = test_mem_mode)
18212855Sgabeblack@google.com
18312855Sgabeblack@google.comif options.ruby:
18412855Sgabeblack@google.com    options.use_map = True
18512855Sgabeblack@google.com    Ruby.create_system(options, system)
18612855Sgabeblack@google.com    assert(options.num_cpus == len(system.ruby._cpu_ruby_ports))
18712855Sgabeblack@google.com    system.system_port = system.ruby._sys_port_proxy.port
18812855Sgabeblack@google.comelse:
18912855Sgabeblack@google.com    system.system_port = system.membus.port
19012855Sgabeblack@google.com    system.physmem.port = system.membus.port
19112855Sgabeblack@google.com    CacheConfig.config_cache(options, system)
19212855Sgabeblack@google.com
19312855Sgabeblack@google.comfor i in xrange(np):
19412855Sgabeblack@google.com    system.cpu[i].workload = multiprocesses[i]
19512855Sgabeblack@google.com
19612855Sgabeblack@google.com    if options.ruby:
19712855Sgabeblack@google.com        system.cpu[i].icache_port = system.ruby._cpu_ruby_ports[i].port
19812855Sgabeblack@google.com        system.cpu[i].dcache_port = system.ruby._cpu_ruby_ports[i].port
19912855Sgabeblack@google.com
20012855Sgabeblack@google.com    if options.fastmem:
20112855Sgabeblack@google.com        system.cpu[0].physmem_port = system.physmem.port
20212855Sgabeblack@google.com
20312855Sgabeblack@google.comroot = Root(full_system = False, system = system)
204
205Simulation.run(options, root, system, FutureClass)
206