se.py revision 7787:af976dd0c6e7
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
79if options.bench:
80    try:
81        if buildEnv['TARGET_ISA'] != 'alpha':
82            print >>sys.stderr, "Simpoints code only works for Alpha ISA at this time"
83            sys.exit(1)
84        exec("workload = %s('alpha', 'tru64', 'ref')" % options.bench)
85        process = workload.makeLiveProcess()
86    except:
87        print >>sys.stderr, "Unable to find workload for %s" % options.bench
88        sys.exit(1)
89else:
90    process = LiveProcess()
91    process.executable = options.cmd
92    process.cmd = [options.cmd] + options.options.split()
93
94
95if options.input != "":
96    process.input = options.input
97if options.output != "":
98    process.output = options.output
99if options.errout != "":
100    process.errout = options.errout
101
102
103# By default, set workload to path of user-specified binary
104workloads = options.cmd
105numThreads = 1
106
107if options.detailed or options.inorder:
108    #check for SMT workload
109    workloads = options.cmd.split(';')
110    if len(workloads) > 1:
111        process = []
112        smt_idx = 0
113        inputs = []
114        outputs = []
115        errouts = []
116
117        if options.input != "":
118            inputs = options.input.split(';')
119        if options.output != "":
120            outputs = options.output.split(';')
121        if options.errout != "":
122            errouts = options.errout.split(';')
123
124        for wrkld in workloads:
125            smt_process = LiveProcess()
126            smt_process.executable = wrkld
127            smt_process.cmd = wrkld + " " + options.options
128            if inputs and inputs[smt_idx]:
129                smt_process.input = inputs[smt_idx]
130            if outputs and outputs[smt_idx]:
131                smt_process.output = outputs[smt_idx]
132            if errouts and errouts[smt_idx]:
133                smt_process.errout = errouts[smt_idx]
134            process += [smt_process, ]
135            smt_idx += 1
136    numThreads = len(workloads)
137
138(CPUClass, test_mem_mode, FutureClass) = Simulation.setCPUClass(options)
139
140CPUClass.clock = '2GHz'
141CPUClass.numThreads = numThreads;
142
143np = options.num_cpus
144
145system = System(cpu = [CPUClass(cpu_id=i) for i in xrange(np)],
146                physmem = PhysicalMemory(range=AddrRange("512MB")),
147                membus = Bus(), mem_mode = test_mem_mode)
148
149system.physmem.port = system.membus.port
150
151CacheConfig.config_cache(options, system)
152
153for i in xrange(np):
154    system.cpu[i].workload = process
155
156    if options.fastmem:
157        system.cpu[0].physmem_port = system.physmem.port
158
159root = Root(system = system)
160
161Simulation.run(options, root, system, FutureClass)
162