1 # Copyright (c) 2006 The Regents of The University of Michigan
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.
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.
27 # Authors: Steve Reinhardt
34 from m5
.objects
import *
35 import os
, optparse
, sys
36 m5
.AddToPath('../common')
38 parser
= optparse
.OptionParser()
41 parser
.add_option("-c", "--cmd",
42 default
="../../tests/test-progs/hello/bin/alpha/linux/hello",
43 help="The binary to run in syscall emulation mode.")
44 parser
.add_option("-o", "--options", default
="",
45 help="The options to pass to the binary, use \" \" around the entire\
47 parser
.add_option("-i", "--input", default
="",
48 help="A file of input to give to the binary.")
51 parser
.add_option("-d", "--detailed", action
="store_true")
52 parser
.add_option("-t", "--timing", action
="store_true")
53 parser
.add_option("--caches", action
="store_true")
55 # Run duration options
56 parser
.add_option("-m", "--maxtick", type="int")
57 parser
.add_option("--maxtime", type="float")
59 #Checkpointing options
60 ###Note that performing checkpointing via python script files will override
61 ###checkpoint instructions built into binaries.
62 parser
.add_option("--take_checkpoints", action
="store", type="string",
63 help="<M,N> will take checkpoint at cycle M and every N cycles \
65 parser
.add_option("--max_checkpoints", action
="store", type="int",
66 help="the maximum number of checkpoints to drop",
68 parser
.add_option("--checkpoint_dir", action
="store", type="string",
69 help="Place all checkpoints in this absolute directory")
70 parser
.add_option("-r", "--checkpoint_restore", action
="store", type="int",
71 help="restore from checkpoint <N>")
73 #CPU Switching - default switch model generally goes from a checkpoint
74 #to a timing simple CPU with caches to warm up, then to detailed CPU for
76 parser
.add_option("-s", "--standard_switch", action
="store_true",
77 help="switch from one cpu mode to another")
79 (options
, args
) = parser
.parse_args()
82 print "Error: script doesn't take any positional arguments"
85 class MyCache(BaseCache
):
92 process
= LiveProcess()
93 process
.executable
= options
.cmd
94 process
.cmd
= options
.cmd
+ " " + options
.options
95 if options
.input != "":
96 process
.input = options
.input
99 #check for SMT workload
100 workloads
= options
.cmd
.split(';')
101 if len(workloads
) > 1:
106 if options
.input != "":
107 inputs
= options
.input.split(';')
109 for wrkld
in workloads
:
110 smt_process
= LiveProcess()
111 smt_process
.executable
= wrkld
112 smt_process
.cmd
= wrkld
+ " " + options
.options
113 if inputs
and inputs
[smt_idx
]:
114 smt_process
.input = inputs
[smt_idx
]
115 process
+= [smt_process
, ]
120 cpu
= TimingSimpleCPU()
121 elif options
.detailed
:
124 cpu
= AtomicSimpleCPU()
126 cpu
.workload
= process
129 system
= System(cpu
= cpu
,
130 physmem
= PhysicalMemory(range=AddrRange("512MB")),
133 if options
.caches
and not options
.standard_switch
:
134 system
.cpu
.addPrivateSplitL1Caches(MyCache(size
= '32kB'),
135 MyCache(size
= '64kB'))
137 system
.physmem
.port
= system
.membus
.port
138 system
.cpu
.connectMemPorts(system
.membus
)
139 system
.cpu
.mem
= system
.physmem
140 system
.cpu
.clock
= '2GHz'
141 root
= Root(system
= system
)
143 if options
.timing
or options
.detailed
:
144 root
.system
.mem_mode
= 'timing'
146 if options
.standard_switch
:
147 switch_cpu
= TimingSimpleCPU(defer_registration
=True, cpu_id
=1)
148 switch_cpu1
= DerivO3CPU(defer_registration
=True, cpu_id
=2)
149 switch_cpu
.system
= system
150 switch_cpu1
.system
= system
151 switch_cpu
.clock
= cpu
.clock
152 switch_cpu1
.clock
= cpu
.clock
154 switch_cpu
.addPrivateSplitL1Caches(MyCache(size
= '32kB'),
155 MyCache(size
= '64kB'))
157 switch_cpu
.workload
= process
158 switch_cpu1
.workload
= process
159 switch_cpu
.mem
= system
.physmem
160 switch_cpu1
.mem
= system
.physmem
161 switch_cpu
.connectMemPorts(system
.membus
)
162 root
.switch_cpu
= switch_cpu
163 root
.switch_cpu1
= switch_cpu1
164 switch_cpu_list
= [(system
.cpu
, switch_cpu
)]
165 switch_cpu_list1
= [(switch_cpu
, switch_cpu1
)]
167 # instantiate configuration
170 if options
.checkpoint_dir
:
171 cptdir
= options
.checkpoint_dir
175 if options
.checkpoint_restore
:
176 from os
.path
import isdir
177 from os
import listdir
, getcwd
180 if not isdir(cptdir
):
181 m5
.panic("checkpoint dir %s does not exist!" % cptdir
)
183 dirs
= listdir(cptdir
)
184 expr
= re
.compile('cpt.([0-9]*)')
187 match
= expr
.match(dir)
189 cpts
.append(match
.group(1))
191 cpts
.sort(lambda a
,b
: cmp(long(a
), long(b
)))
193 if options
.checkpoint_restore
> len(cpts
):
194 m5
.panic('Checkpoint %d not found' % options
.checkpoint_restore
)
196 print "restoring checkpoint from ","/".join([cptdir
, "cpt.%s" % cpts
[options
.checkpoint_restore
- 1]])
197 m5
.restoreCheckpoint(root
, "/".join([cptdir
, "cpt.%s" % cpts
[options
.checkpoint_restore
- 1]]))
199 if options
.standard_switch
:
200 exit_event
= m5
.simulate(10000)
201 ## when you change to Timing (or Atomic), you halt the system given
202 ## as argument. When you are finished with the system changes
203 ## (including switchCpus), you must resume the system manually.
204 ## You DON'T need to resume after just switching CPUs if you haven't
205 ## changed anything on the system level.
206 m5
.changeToTiming(system
)
207 m5
.switchCpus(switch_cpu_list
)
210 exit_event
= m5
.simulate(500000000000)
211 m5
.switchCpus(switch_cpu_list1
)
214 maxtick
= options
.maxtick
215 elif options
.maxtime
:
216 simtime
= int(options
.maxtime
* root
.clock
.value
)
217 print "simulating for: ", simtime
226 if options
.take_checkpoints
:
227 [when
, period
] = options
.take_checkpoints
.split(",", 1)
231 exit_event
= m5
.simulate(when
)
232 while exit_event
.getCause() == "checkpoint":
233 exit_event
= m5
.simulate(when
- m5
.curTick())
235 if exit_event
.getCause() == "simulate() limit reached":
236 m5
.checkpoint(root
, cptdir
+ "cpt.%d")
240 exit_cause
= "maximum %d checkpoints dropped" % options
.max_checkpoints
241 while num_checkpoints
< options
.max_checkpoints
:
242 if (sim_ticks
+ period
) > maxtick
and maxtick
!= -1:
243 exit_event
= m5
.simulate(maxtick
- sim_ticks
)
244 exit_cause
= exit_event
.getCause()
247 exit_event
= m5
.simulate(period
)
249 while exit_event
.getCause() == "checkpoint":
250 exit_event
= m5
.simulate(period
- m5
.curTick())
251 if exit_event
.getCause() == "simulate() limit reached":
252 m5
.checkpoint(root
, cptdir
+ "cpt.%d")
255 else: #no checkpoints being taken via this script
256 exit_event
= m5
.simulate(maxtick
)
258 while exit_event
.getCause() == "checkpoint":
259 m5
.checkpoint(root
, cptdir
+ "cpt.%d")
261 if num_checkpoints
== options
.max_checkpoints
:
262 exit_cause
= "maximum %d checkpoints dropped" % options
.max_checkpoints
266 exit_event
= m5
.simulate(maxtick
)
268 exit_event
= m5
.simulate(maxtick
- m5
.curTick())
270 exit_cause
= exit_event
.getCause()
273 exit_cause
= exit_event
.getCause()
274 print 'Exiting @ cycle', m5
.curTick(), 'because ', exit_cause