se.py revision 8467
19793Sakash.bagdia@arm.com# Copyright (c) 2006-2008 The Regents of The University of Michigan 29518SAndreas.Sandberg@ARM.com# All rights reserved. 311320Ssteve.reinhardt@amd.com# 49518SAndreas.Sandberg@ARM.com# Redistribution and use in source and binary forms, with or without 59518SAndreas.Sandberg@ARM.com# modification, are permitted provided that the following conditions are 69518SAndreas.Sandberg@ARM.com# met: redistributions of source code must retain the above copyright 79518SAndreas.Sandberg@ARM.com# notice, this list of conditions and the following disclaimer; 89518SAndreas.Sandberg@ARM.com# redistributions in binary form must reproduce the above copyright 99518SAndreas.Sandberg@ARM.com# notice, this list of conditions and the following disclaimer in the 109518SAndreas.Sandberg@ARM.com# documentation and/or other materials provided with the distribution; 119518SAndreas.Sandberg@ARM.com# neither the name of the copyright holders nor the names of its 129518SAndreas.Sandberg@ARM.com# contributors may be used to endorse or promote products derived from 135347Ssaidi@eecs.umich.edu# this software without specific prior written permission. 147534Ssteve.reinhardt@amd.com# 153395Shsul@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 163395Shsul@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 173395Shsul@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 183395Shsul@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 193395Shsul@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 203395Shsul@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 213395Shsul@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 223395Shsul@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 233395Shsul@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 243395Shsul@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 253395Shsul@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 263395Shsul@eecs.umich.edu# 273395Shsul@eecs.umich.edu# Authors: Steve Reinhardt 283395Shsul@eecs.umich.edu 293395Shsul@eecs.umich.edu# Simple test script 303395Shsul@eecs.umich.edu# 313395Shsul@eecs.umich.edu# "m5 test.py" 323395Shsul@eecs.umich.edu 333395Shsul@eecs.umich.eduimport os 343395Shsul@eecs.umich.eduimport optparse 353395Shsul@eecs.umich.eduimport sys 363395Shsul@eecs.umich.edufrom os.path import join as joinpath 373395Shsul@eecs.umich.edu 383395Shsul@eecs.umich.eduimport m5 393395Shsul@eecs.umich.edufrom m5.defines import buildEnv 403395Shsul@eecs.umich.edufrom m5.objects import * 413395Shsul@eecs.umich.edufrom m5.util import addToPath, fatal 4212564Sgabeblack@google.com 4312564Sgabeblack@google.comif buildEnv['FULL_SYSTEM']: 449457Svilanova@ac.upc.edu fatal("This script requires syscall emulation mode (*_SE).") 453395Shsul@eecs.umich.edu 463509Shsul@eecs.umich.eduaddToPath('../common') 476654Snate@binkert.orgaddToPath('../ruby') 4811688Sandreas.hansson@arm.com 4913432Spau.cabre@metempsy.comimport Ruby 5011688Sandreas.hansson@arm.com 519520SAndreas.Sandberg@ARM.comimport Simulation 523395Shsul@eecs.umich.eduimport CacheConfig 536654Snate@binkert.orgfrom Caches import * 543395Shsul@eecs.umich.edufrom cpu2000 import * 556654Snate@binkert.org 566654Snate@binkert.org# Get paths we might need. It's expected this file is in m5/configs/example. 576654Snate@binkert.orgconfig_path = os.path.dirname(os.path.abspath(__file__)) 583395Shsul@eecs.umich.educonfig_root = os.path.dirname(config_path) 599139Snilay@cs.wisc.edum5_root = os.path.dirname(config_root) 609520SAndreas.Sandberg@ARM.com 619520SAndreas.Sandberg@ARM.comparser = optparse.OptionParser() 629520SAndreas.Sandberg@ARM.com 639139Snilay@cs.wisc.edu# Benchmark options 643481Shsul@eecs.umich.eduparser.add_option("-c", "--cmd", 659139Snilay@cs.wisc.edu default=joinpath(m5_root, "tests/test-progs/hello/bin/%s/linux/hello" % \ 663481Shsul@eecs.umich.edu buildEnv['TARGET_ISA']), 679139Snilay@cs.wisc.edu help="The binary to run in syscall emulation mode.") 689139Snilay@cs.wisc.eduparser.add_option("-o", "--options", default="", 699139Snilay@cs.wisc.edu help='The options to pass to the binary, use " " around the entire string') 709139Snilay@cs.wisc.eduparser.add_option("-i", "--input", default="", help="Read stdin from a file.") 719139Snilay@cs.wisc.eduparser.add_option("--output", default="", help="Redirect stdout to a file.") 729139Snilay@cs.wisc.eduparser.add_option("--errout", default="", help="Redirect stderr to a file.") 739139Snilay@cs.wisc.edu 749139Snilay@cs.wisc.eduif 'PROTOCOL' in buildEnv: 753481Shsul@eecs.umich.edu parser.add_option("--ruby", action="store_true") 769518SAndreas.Sandberg@ARM.com 779518SAndreas.Sandberg@ARM.comexecfile(os.path.join(config_root, "common", "Options.py")) 789518SAndreas.Sandberg@ARM.com 793481Shsul@eecs.umich.eduif '--ruby' in sys.argv: 809139Snilay@cs.wisc.edu Ruby.define_options(parser) 819139Snilay@cs.wisc.edu 823481Shsul@eecs.umich.edu(options, args) = parser.parse_args() 839139Snilay@cs.wisc.edu 849139Snilay@cs.wisc.eduif args: 859139Snilay@cs.wisc.edu print "Error: script doesn't take any positional arguments" 869139Snilay@cs.wisc.edu sys.exit(1) 879139Snilay@cs.wisc.edu 883481Shsul@eecs.umich.edumultiprocesses = [] 8912395Sswapnilster@gmail.comapps = [] 9012395Sswapnilster@gmail.com 9112395Sswapnilster@gmail.comif options.bench: 9212395Sswapnilster@gmail.com apps = options.bench.split("-") 9312395Sswapnilster@gmail.com if len(apps) != options.num_cpus: 943481Shsul@eecs.umich.edu print "number of benchmarks not equal to set num_cpus!" 953481Shsul@eecs.umich.edu sys.exit(1) 969665Sandreas.hansson@arm.com 979665Sandreas.hansson@arm.com for app in apps: 989665Sandreas.hansson@arm.com try: 999665Sandreas.hansson@arm.com if buildEnv['TARGET_ISA'] == 'alpha': 1009665Sandreas.hansson@arm.com exec("workload = %s('alpha', 'tru64', 'ref')" % app) 1018919Snilay@cs.wisc.edu else: 1028919Snilay@cs.wisc.edu exec("workload = %s(buildEnv['TARGET_ISA'], 'linux', 'ref')" % app) 1038919Snilay@cs.wisc.edu multiprocesses.append(workload.makeLiveProcess()) 10410159Sgedare@rtems.org except: 10510159Sgedare@rtems.org print >>sys.stderr, "Unable to find workload for %s: %s" % (buildEnv['TARGET_ISA'], app) 1068919Snilay@cs.wisc.edu sys.exit(1) 1078919Snilay@cs.wisc.eduelse: 1088919Snilay@cs.wisc.edu process = LiveProcess() 1098919Snilay@cs.wisc.edu process.executable = options.cmd 1108919Snilay@cs.wisc.edu process.cmd = [options.cmd] + options.options.split() 1118919Snilay@cs.wisc.edu multiprocesses.append(process) 1128919Snilay@cs.wisc.edu 1138919Snilay@cs.wisc.edu 1148919Snilay@cs.wisc.eduif options.input != "": 1158919Snilay@cs.wisc.edu process.input = options.input 1168919Snilay@cs.wisc.eduif options.output != "": 1178919Snilay@cs.wisc.edu process.output = options.output 1183481Shsul@eecs.umich.eduif options.errout != "": 1199816Sjthestness@gmail.com process.errout = options.errout 1209140Snilay@cs.wisc.edu 1219140Snilay@cs.wisc.edu 1229140Snilay@cs.wisc.edu# By default, set workload to path of user-specified binary 1239140Snilay@cs.wisc.eduworkloads = options.cmd 1249140Snilay@cs.wisc.edunumThreads = 1 1259140Snilay@cs.wisc.edu 1269140Snilay@cs.wisc.eduif options.detailed or options.inorder: 1279140Snilay@cs.wisc.edu #check for SMT workload 1289140Snilay@cs.wisc.edu workloads = options.cmd.split(';') 1299140Snilay@cs.wisc.edu if len(workloads) > 1: 1309140Snilay@cs.wisc.edu process = [] 1319140Snilay@cs.wisc.edu smt_idx = 0 1329140Snilay@cs.wisc.edu inputs = [] 1339140Snilay@cs.wisc.edu outputs = [] 1349140Snilay@cs.wisc.edu errouts = [] 1359140Snilay@cs.wisc.edu 1369140Snilay@cs.wisc.edu if options.input != "": 1379140Snilay@cs.wisc.edu inputs = options.input.split(';') 1389140Snilay@cs.wisc.edu if options.output != "": 1399867Sjthestness@gmail.com outputs = options.output.split(';') 1409140Snilay@cs.wisc.edu if options.errout != "": 1419140Snilay@cs.wisc.edu errouts = options.errout.split(';') 1429140Snilay@cs.wisc.edu 1439140Snilay@cs.wisc.edu for wrkld in workloads: 1449140Snilay@cs.wisc.edu smt_process = LiveProcess() 1459140Snilay@cs.wisc.edu smt_process.executable = wrkld 1469140Snilay@cs.wisc.edu smt_process.cmd = wrkld + " " + options.options 1479140Snilay@cs.wisc.edu if inputs and inputs[smt_idx]: 1489140Snilay@cs.wisc.edu smt_process.input = inputs[smt_idx] 1499140Snilay@cs.wisc.edu if outputs and outputs[smt_idx]: 1509140Snilay@cs.wisc.edu smt_process.output = outputs[smt_idx] 15110608Sdam.sunwoo@arm.com if errouts and errouts[smt_idx]: 15210608Sdam.sunwoo@arm.com smt_process.errout = errouts[smt_idx] 15310608Sdam.sunwoo@arm.com process += [smt_process, ] 15410608Sdam.sunwoo@arm.com smt_idx += 1 15510608Sdam.sunwoo@arm.com numThreads = len(workloads) 15610608Sdam.sunwoo@arm.com 15710608Sdam.sunwoo@arm.comif options.ruby: 15810608Sdam.sunwoo@arm.com if options.detailed: 15910608Sdam.sunwoo@arm.com print >> sys.stderr, "Ruby only works with TimingSimpleCPU!!" 16010608Sdam.sunwoo@arm.com sys.exit(1) 16110608Sdam.sunwoo@arm.com elif not options.timing: 16210608Sdam.sunwoo@arm.com print >> sys.stderr, "****WARN: using Timing CPU since it's needed by Ruby" 16310608Sdam.sunwoo@arm.com 16410608Sdam.sunwoo@arm.com class CPUClass(TimingSimpleCPU): pass 16510608Sdam.sunwoo@arm.com test_mem_mode = 'timing' 16610608Sdam.sunwoo@arm.com FutureClass = None 16710608Sdam.sunwoo@arm.comelse: 16810608Sdam.sunwoo@arm.com (CPUClass, test_mem_mode, FutureClass) = Simulation.setCPUClass(options) 16910608Sdam.sunwoo@arm.com 17010608Sdam.sunwoo@arm.comCPUClass.clock = '2GHz' 17110608Sdam.sunwoo@arm.comCPUClass.numThreads = numThreads; 17210608Sdam.sunwoo@arm.com 17310608Sdam.sunwoo@arm.comnp = options.num_cpus 17410608Sdam.sunwoo@arm.com 17510608Sdam.sunwoo@arm.comsystem = System(cpu = [CPUClass(cpu_id=i) for i in xrange(np)], 17612564Sgabeblack@google.com physmem = PhysicalMemory(range=AddrRange("512MB")), 17710608Sdam.sunwoo@arm.com membus = Bus(), mem_mode = test_mem_mode) 17810608Sdam.sunwoo@arm.com 17910608Sdam.sunwoo@arm.comif options.ruby: 18010608Sdam.sunwoo@arm.com options.use_map = True 18110608Sdam.sunwoo@arm.com Ruby.create_system(options, system) 18210608Sdam.sunwoo@arm.com assert(options.num_cpus == len(system.ruby._cpu_ruby_ports)) 18310608Sdam.sunwoo@arm.comelse: 18412564Sgabeblack@google.com system.physmem.port = system.membus.port 18512564Sgabeblack@google.com CacheConfig.config_cache(options, system) 18612564Sgabeblack@google.com 18710608Sdam.sunwoo@arm.comfor i in xrange(np): 1889140Snilay@cs.wisc.edu system.cpu[i].workload = multiprocesses[i] 1899140Snilay@cs.wisc.edu 19010608Sdam.sunwoo@arm.com if options.ruby: 1919140Snilay@cs.wisc.edu system.cpu[i].icache_port = system.ruby._cpu_ruby_ports[i].port 1929140Snilay@cs.wisc.edu system.cpu[i].dcache_port = system.ruby._cpu_ruby_ports[i].port 1939140Snilay@cs.wisc.edu 1949140Snilay@cs.wisc.edu if options.fastmem: 1959140Snilay@cs.wisc.edu system.cpu[0].physmem_port = system.physmem.port 1969140Snilay@cs.wisc.edu 1979140Snilay@cs.wisc.eduroot = Root(system = system) 1989140Snilay@cs.wisc.edu 1999140Snilay@cs.wisc.eduSimulation.run(options, root, system, FutureClass) 2009140Snilay@cs.wisc.edu