se.py revision 6981:aba5f7216636
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/alpha/linux/hello"),
63    help="The binary to run in syscall emulation mode.")
64parser.add_option("-o", "--options", default="",
65    help='The options to pass to the binary, use " " around the entire string')
66parser.add_option("-i", "--input", default="", help="Read stdin from a file.")
67parser.add_option("--output", default="", help="Redirect stdout to a file.")
68parser.add_option("--errout", default="", help="Redirect stderr to a file.")
69
70execfile(os.path.join(config_root, "common", "Options.py"))
71
72(options, args) = parser.parse_args()
73
74if args:
75    print "Error: script doesn't take any positional arguments"
76    sys.exit(1)
77
78if options.bench:
79    try:
80        if buildEnv['TARGET_ISA'] != 'alpha':
81            print >>sys.stderr, "Simpoints code only works for Alpha ISA at this time"
82            sys.exit(1)
83        exec("workload = %s('alpha', 'tru64', 'ref')" % options.bench)
84        process = workload.makeLiveProcess()
85    except:
86        print >>sys.stderr, "Unable to find workload for %s" % options.bench
87        sys.exit(1)
88else:
89    process = LiveProcess()
90    process.executable = options.cmd
91    process.cmd = [options.cmd] + options.options.split()
92
93
94if options.input != "":
95    process.input = options.input
96if options.output != "":
97    process.output = options.output
98if options.errout != "":
99    process.errout = options.errout
100
101
102# By default, set workload to path of user-specified binary
103workloads = options.cmd
104numThreads = 1
105
106if options.detailed or options.inorder:
107    #check for SMT workload
108    workloads = options.cmd.split(';')
109    if len(workloads) > 1:
110        process = []
111        smt_idx = 0
112        inputs = []
113        outputs = []
114        errouts = []
115
116        if options.input != "":
117            inputs = options.input.split(';')
118        if options.output != "":
119            outputs = options.output.split(';')
120        if options.errout != "":
121            errouts = options.errout.split(';')
122
123        for wrkld in workloads:
124            smt_process = LiveProcess()
125            smt_process.executable = wrkld
126            smt_process.cmd = wrkld + " " + options.options
127            if inputs and inputs[smt_idx]:
128                smt_process.input = inputs[smt_idx]
129            if outputs and outputs[smt_idx]:
130                smt_process.output = outputs[smt_idx]
131            if errouts and errouts[smt_idx]:
132                smt_process.errout = errouts[smt_idx]
133            process += [smt_process, ]
134            smt_idx += 1
135    numThreads = len(workloads)
136
137(CPUClass, test_mem_mode, FutureClass) = Simulation.setCPUClass(options)
138
139CPUClass.clock = '2GHz'
140CPUClass.numThreads = numThreads;
141
142np = options.num_cpus
143
144system = System(cpu = [CPUClass(cpu_id=i) for i in xrange(np)],
145                physmem = PhysicalMemory(range=AddrRange("512MB")),
146                membus = Bus(), mem_mode = test_mem_mode)
147
148system.physmem.port = system.membus.port
149
150CacheConfig.config_cache(options, system)
151
152for i in xrange(np):
153    system.cpu[i].workload = process
154
155    if options.fastmem:
156        system.cpu[0].physmem_port = system.physmem.port
157
158root = Root(system = system)
159
160Simulation.run(options, root, system, FutureClass)
161