se.py revision 8322
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.")
73parser.add_option("--ruby", action="store_true")
74
75execfile(os.path.join(config_root, "common", "Options.py"))
76
77(options, args) = parser.parse_args()
78
79if options.ruby:
80    Ruby.define_options(parser)
81    (options, args) = parser.parse_args()
82
83if args:
84    print "Error: script doesn't take any positional arguments"
85    sys.exit(1)
86
87multiprocesses = []
88apps = []
89
90if options.bench:
91    apps = options.bench.split("-")
92    if len(apps) != options.num_cpus:
93        print "number of benchmarks not equal to set num_cpus!"
94        sys.exit(1)
95
96    for app in apps:
97        try:
98            if buildEnv['TARGET_ISA'] == 'alpha':
99                exec("workload = %s('alpha', 'tru64', 'ref')" % app)
100            else:
101                exec("workload = %s(buildEnv['TARGET_ISA'], 'linux', 'ref')" % app)
102            multiprocesses.append(workload.makeLiveProcess())
103        except:
104            print >>sys.stderr, "Unable to find workload for %s: %s" % (buildEnv['TARGET_ISA'], app)
105            sys.exit(1)
106else:
107    process = LiveProcess()
108    process.executable = options.cmd
109    process.cmd = [options.cmd] + options.options.split()
110    multiprocesses.append(process)
111
112
113if options.input != "":
114    process.input = options.input
115if options.output != "":
116    process.output = options.output
117if options.errout != "":
118    process.errout = options.errout
119
120
121# By default, set workload to path of user-specified binary
122workloads = options.cmd
123numThreads = 1
124
125if options.detailed or options.inorder:
126    #check for SMT workload
127    workloads = options.cmd.split(';')
128    if len(workloads) > 1:
129        process = []
130        smt_idx = 0
131        inputs = []
132        outputs = []
133        errouts = []
134
135        if options.input != "":
136            inputs = options.input.split(';')
137        if options.output != "":
138            outputs = options.output.split(';')
139        if options.errout != "":
140            errouts = options.errout.split(';')
141
142        for wrkld in workloads:
143            smt_process = LiveProcess()
144            smt_process.executable = wrkld
145            smt_process.cmd = wrkld + " " + options.options
146            if inputs and inputs[smt_idx]:
147                smt_process.input = inputs[smt_idx]
148            if outputs and outputs[smt_idx]:
149                smt_process.output = outputs[smt_idx]
150            if errouts and errouts[smt_idx]:
151                smt_process.errout = errouts[smt_idx]
152            process += [smt_process, ]
153            smt_idx += 1
154    numThreads = len(workloads)
155
156if options.ruby:
157    if options.detailed:
158        print >> sys.stderr, "Ruby only works with TimingSimpleCPU!!"
159        sys.exit(1)
160    elif not options.timing:
161        print >> sys.stderr, "****WARN:  using Timing CPU since it's needed by Ruby"
162
163    class CPUClass(TimingSimpleCPU): pass
164    test_mem_mode = 'timing'
165    FutureClass = None
166else:
167    (CPUClass, test_mem_mode, FutureClass) = Simulation.setCPUClass(options)
168
169CPUClass.clock = '2GHz'
170CPUClass.numThreads = numThreads;
171
172np = options.num_cpus
173
174system = System(cpu = [CPUClass(cpu_id=i) for i in xrange(np)],
175                physmem = PhysicalMemory(range=AddrRange("512MB")),
176                membus = Bus(), mem_mode = test_mem_mode)
177
178if options.ruby:
179    options.use_map = True
180    system.ruby = Ruby.create_system(options, system)
181    assert(options.num_cpus == len(system.ruby._cpu_ruby_ports))
182else:
183    system.physmem.port = system.membus.port
184    CacheConfig.config_cache(options, system)
185
186for i in xrange(np):
187    system.cpu[i].workload = multiprocesses[i]
188
189    if options.ruby:
190        system.cpu[i].icache_port = system.ruby._cpu_ruby_ports[i].port
191        system.cpu[i].dcache_port = system.ruby._cpu_ruby_ports[i].port
192
193    if options.fastmem:
194        system.cpu[0].physmem_port = system.physmem.port
195
196root = Root(system = system)
197
198Simulation.run(options, root, system, FutureClass)
199