se.py revision 8467
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')
47addToPath('../ruby')
48
49import Ruby
50
51import Simulation
52import CacheConfig
53from Caches import *
54from cpu2000 import *
55
56# Get paths we might need.  It's expected this file is in m5/configs/example.
57config_path = os.path.dirname(os.path.abspath(__file__))
58config_root = os.path.dirname(config_path)
59m5_root = os.path.dirname(config_root)
60
61parser = optparse.OptionParser()
62
63# Benchmark options
64parser.add_option("-c", "--cmd",
65    default=joinpath(m5_root, "tests/test-progs/hello/bin/%s/linux/hello" % \
66            buildEnv['TARGET_ISA']),
67    help="The binary to run in syscall emulation mode.")
68parser.add_option("-o", "--options", default="",
69    help='The options to pass to the binary, use " " around the entire string')
70parser.add_option("-i", "--input", default="", help="Read stdin from a file.")
71parser.add_option("--output", default="", help="Redirect stdout to a file.")
72parser.add_option("--errout", default="", help="Redirect stderr to a file.")
73
74if '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