se.py revision 8167:f596091c854d
1# Copyright (c) 2006-2008 The Regents of The University of Michigan 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are 6# met: redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer; 8# redistributions in binary form must reproduce the above copyright 9# notice, this list of conditions and the following disclaimer in the 10# documentation and/or other materials provided with the distribution; 11# neither the name of the copyright holders nor the names of its 12# contributors may be used to endorse or promote products derived from 13# this software without specific prior written permission. 14# 15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26# 27# Authors: Steve Reinhardt 28 29# Simple test script 30# 31# "m5 test.py" 32 33import os 34import optparse 35import sys 36from os.path import join as joinpath 37 38import m5 39from m5.defines import buildEnv 40from m5.objects import * 41from m5.util import addToPath, fatal 42 43if buildEnv['FULL_SYSTEM']: 44 fatal("This script requires syscall emulation mode (*_SE).") 45 46addToPath('../common') 47 48import Simulation 49import CacheConfig 50from Caches import * 51from cpu2000 import * 52 53# Get paths we might need. It's expected this file is in m5/configs/example. 54config_path = os.path.dirname(os.path.abspath(__file__)) 55config_root = os.path.dirname(config_path) 56m5_root = os.path.dirname(config_root) 57 58parser = optparse.OptionParser() 59 60# Benchmark options 61parser.add_option("-c", "--cmd", 62 default=joinpath(m5_root, "tests/test-progs/hello/bin/%s/linux/hello" % \ 63 buildEnv['TARGET_ISA']), 64 help="The binary to run in syscall emulation mode.") 65parser.add_option("-o", "--options", default="", 66 help='The options to pass to the binary, use " " around the entire string') 67parser.add_option("-i", "--input", default="", help="Read stdin from a file.") 68parser.add_option("--output", default="", help="Redirect stdout to a file.") 69parser.add_option("--errout", default="", help="Redirect stderr to a file.") 70 71execfile(os.path.join(config_root, "common", "Options.py")) 72 73(options, args) = parser.parse_args() 74 75if args: 76 print "Error: script doesn't take any positional arguments" 77 sys.exit(1) 78 79multiprocesses = [] 80apps = [] 81 82if options.bench: 83 apps = options.bench.split("-") 84 if len(apps) != options.num_cpus: 85 print "number of benchmarks not equal to set num_cpus!" 86 sys.exit(1) 87 88 for app in apps: 89 try: 90 if buildEnv['TARGET_ISA'] != 'alpha': 91 print >>sys.stderr, "Simpoints code only works for Alpha ISA at this time" 92 sys.exit(1) 93 exec("workload = %s('alpha', 'tru64', 'ref')" % app) 94 multiprocesses.append(workload.makeLiveProcess()) 95 except: 96 print >>sys.stderr, "Unable to find workload for %s" % app 97 sys.exit(1) 98else: 99 process = LiveProcess() 100 process.executable = options.cmd 101 process.cmd = [options.cmd] + options.options.split() 102 multiprocesses.append(process) 103 104 105if options.input != "": 106 process.input = options.input 107if options.output != "": 108 process.output = options.output 109if options.errout != "": 110 process.errout = options.errout 111 112 113# By default, set workload to path of user-specified binary 114workloads = options.cmd 115numThreads = 1 116 117if options.detailed or options.inorder: 118 #check for SMT workload 119 workloads = options.cmd.split(';') 120 if len(workloads) > 1: 121 process = [] 122 smt_idx = 0 123 inputs = [] 124 outputs = [] 125 errouts = [] 126 127 if options.input != "": 128 inputs = options.input.split(';') 129 if options.output != "": 130 outputs = options.output.split(';') 131 if options.errout != "": 132 errouts = options.errout.split(';') 133 134 for wrkld in workloads: 135 smt_process = LiveProcess() 136 smt_process.executable = wrkld 137 smt_process.cmd = wrkld + " " + options.options 138 if inputs and inputs[smt_idx]: 139 smt_process.input = inputs[smt_idx] 140 if outputs and outputs[smt_idx]: 141 smt_process.output = outputs[smt_idx] 142 if errouts and errouts[smt_idx]: 143 smt_process.errout = errouts[smt_idx] 144 process += [smt_process, ] 145 smt_idx += 1 146 numThreads = len(workloads) 147 148(CPUClass, test_mem_mode, FutureClass) = Simulation.setCPUClass(options) 149 150CPUClass.clock = '2GHz' 151CPUClass.numThreads = numThreads; 152 153np = options.num_cpus 154 155system = System(cpu = [CPUClass(cpu_id=i) for i in xrange(np)], 156 physmem = PhysicalMemory(range=AddrRange("512MB")), 157 membus = Bus(), mem_mode = test_mem_mode) 158 159system.physmem.port = system.membus.port 160 161CacheConfig.config_cache(options, system) 162 163for i in xrange(np): 164 system.cpu[i].workload = multiprocesses[i] 165 166 if options.fastmem: 167 system.cpu[0].physmem_port = system.physmem.port 168 169root = Root(system = system) 170 171Simulation.run(options, root, system, FutureClass) 172