se.py revision 8467
12124SN/A# Copyright (c) 2006-2008 The Regents of The University of Michigan 22124SN/A# All rights reserved. 32022SN/A# 42022SN/A# Redistribution and use in source and binary forms, with or without 52022SN/A# modification, are permitted provided that the following conditions are 62022SN/A# met: redistributions of source code must retain the above copyright 72022SN/A# notice, this list of conditions and the following disclaimer; 82135SN/A# redistributions in binary form must reproduce the above copyright 92025SN/A# notice, this list of conditions and the following disclaimer in the 102025SN/A# documentation and/or other materials provided with the distribution; 112022SN/A# neither the name of the copyright holders nor the names of its 122135SN/A# contributors may be used to endorse or promote products derived from 132135SN/A# this software without specific prior written permission. 142135SN/A# 152135SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 162135SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 172026SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 182026SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 192025SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 202026SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 212061SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 222026SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 232026SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 242686Sksewell@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 252686Sksewell@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 262686Sksewell@umich.edu# 272686Sksewell@umich.edu# Authors: Steve Reinhardt 282686Sksewell@umich.edu 292686Sksewell@umich.edu# Simple test script 302029SN/A# 312026SN/A# "m5 test.py" 322686Sksewell@umich.edu 332041SN/Aimport os 342029SN/Aimport optparse 352041SN/Aimport sys 362239SN/Afrom os.path import join as joinpath 372029SN/A 382029SN/Aimport m5 392029SN/Afrom m5.defines import buildEnv 402029SN/Afrom m5.objects import * 412135SN/Afrom m5.util import addToPath, fatal 422135SN/A 432029SN/Aif buildEnv['FULL_SYSTEM']: 442029SN/A fatal("This script requires syscall emulation mode (*_SE).") 452029SN/A 462029SN/AaddToPath('../common') 472029SN/AaddToPath('../ruby') 482029SN/A 492601SN/Aimport Ruby 502601SN/A 512601SN/Aimport Simulation 522601SN/Aimport CacheConfig 532239SN/Afrom Caches import * 542239SN/Afrom cpu2000 import * 552239SN/A 562029SN/A# Get paths we might need. It's expected this file is in m5/configs/example. 572029SN/Aconfig_path = os.path.dirname(os.path.abspath(__file__)) 582025SN/Aconfig_root = os.path.dirname(config_path) 592029SN/Am5_root = os.path.dirname(config_root) 602029SN/A 612025SN/Aparser = optparse.OptionParser() 622124SN/A 632043SN/A# Benchmark options 642135SN/Aparser.add_option("-c", "--cmd", 652025SN/A default=joinpath(m5_root, "tests/test-progs/hello/bin/%s/linux/hello" % \ 662043SN/A buildEnv['TARGET_ISA']), 672043SN/A help="The binary to run in syscall emulation mode.") 682025SN/Aparser.add_option("-o", "--options", default="", 692686Sksewell@umich.edu help='The options to pass to the binary, use " " around the entire string') 702686Sksewell@umich.eduparser.add_option("-i", "--input", default="", help="Read stdin from a file.") 712686Sksewell@umich.eduparser.add_option("--output", default="", help="Redirect stdout to a file.") 722686Sksewell@umich.eduparser.add_option("--errout", default="", help="Redirect stderr to a file.") 732025SN/A 742025SN/Aif 'PROTOCOL' in buildEnv: 75 parser.add_option("--ruby", action="store_true") 76 77execfile(os.path.join(config_root, "common", "Options.py")) 78 79if '--ruby' in sys.argv: 80 Ruby.define_options(parser) 81 82(options, args) = parser.parse_args() 83 84if args: 85 print "Error: script doesn't take any positional arguments" 86 sys.exit(1) 87 88multiprocesses = [] 89apps = [] 90 91if options.bench: 92 apps = options.bench.split("-") 93 if len(apps) != options.num_cpus: 94 print "number of benchmarks not equal to set num_cpus!" 95 sys.exit(1) 96 97 for app in apps: 98 try: 99 if buildEnv['TARGET_ISA'] == 'alpha': 100 exec("workload = %s('alpha', 'tru64', 'ref')" % app) 101 else: 102 exec("workload = %s(buildEnv['TARGET_ISA'], 'linux', 'ref')" % app) 103 multiprocesses.append(workload.makeLiveProcess()) 104 except: 105 print >>sys.stderr, "Unable to find workload for %s: %s" % (buildEnv['TARGET_ISA'], app) 106 sys.exit(1) 107else: 108 process = LiveProcess() 109 process.executable = options.cmd 110 process.cmd = [options.cmd] + options.options.split() 111 multiprocesses.append(process) 112 113 114if options.input != "": 115 process.input = options.input 116if options.output != "": 117 process.output = options.output 118if options.errout != "": 119 process.errout = options.errout 120 121 122# By default, set workload to path of user-specified binary 123workloads = options.cmd 124numThreads = 1 125 126if options.detailed or options.inorder: 127 #check for SMT workload 128 workloads = options.cmd.split(';') 129 if len(workloads) > 1: 130 process = [] 131 smt_idx = 0 132 inputs = [] 133 outputs = [] 134 errouts = [] 135 136 if options.input != "": 137 inputs = options.input.split(';') 138 if options.output != "": 139 outputs = options.output.split(';') 140 if options.errout != "": 141 errouts = options.errout.split(';') 142 143 for wrkld in workloads: 144 smt_process = LiveProcess() 145 smt_process.executable = wrkld 146 smt_process.cmd = wrkld + " " + options.options 147 if inputs and inputs[smt_idx]: 148 smt_process.input = inputs[smt_idx] 149 if outputs and outputs[smt_idx]: 150 smt_process.output = outputs[smt_idx] 151 if errouts and errouts[smt_idx]: 152 smt_process.errout = errouts[smt_idx] 153 process += [smt_process, ] 154 smt_idx += 1 155 numThreads = len(workloads) 156 157if options.ruby: 158 if options.detailed: 159 print >> sys.stderr, "Ruby only works with TimingSimpleCPU!!" 160 sys.exit(1) 161 elif not options.timing: 162 print >> sys.stderr, "****WARN: using Timing CPU since it's needed by Ruby" 163 164 class CPUClass(TimingSimpleCPU): pass 165 test_mem_mode = 'timing' 166 FutureClass = None 167else: 168 (CPUClass, test_mem_mode, FutureClass) = Simulation.setCPUClass(options) 169 170CPUClass.clock = '2GHz' 171CPUClass.numThreads = numThreads; 172 173np = options.num_cpus 174 175system = System(cpu = [CPUClass(cpu_id=i) for i in xrange(np)], 176 physmem = PhysicalMemory(range=AddrRange("512MB")), 177 membus = Bus(), mem_mode = test_mem_mode) 178 179if options.ruby: 180 options.use_map = True 181 Ruby.create_system(options, system) 182 assert(options.num_cpus == len(system.ruby._cpu_ruby_ports)) 183else: 184 system.physmem.port = system.membus.port 185 CacheConfig.config_cache(options, system) 186 187for i in xrange(np): 188 system.cpu[i].workload = multiprocesses[i] 189 190 if options.ruby: 191 system.cpu[i].icache_port = system.ruby._cpu_ruby_ports[i].port 192 system.cpu[i].dcache_port = system.ruby._cpu_ruby_ports[i].port 193 194 if options.fastmem: 195 system.cpu[0].physmem_port = system.physmem.port 196 197root = Root(system = system) 198 199Simulation.run(options, root, system, FutureClass) 200