se.py (3230:e86a03911728) se.py (3323:ca667530b8a0)
1# Copyright (c) 2006 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

--- 23 unchanged lines hidden (view full) ---

32
33import m5
34from m5.objects import *
35import os, optparse, sys
36m5.AddToPath('../common')
37
38parser = optparse.OptionParser()
39
1# Copyright (c) 2006 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

--- 23 unchanged lines hidden (view full) ---

32
33import m5
34from m5.objects import *
35import os, optparse, sys
36m5.AddToPath('../common')
37
38parser = optparse.OptionParser()
39
40# Benchmark options
40parser.add_option("-c", "--cmd",
41 default="../../tests/test-progs/hello/bin/alpha/linux/hello",
42 help="The binary to run in syscall emulation mode.")
43parser.add_option("-o", "--options", default="",
44 help="The options to pass to the binary, use \" \" around the entire\
45 string.")
46parser.add_option("-i", "--input", default="",
47 help="A file of input to give to the binary.")
41parser.add_option("-c", "--cmd",
42 default="../../tests/test-progs/hello/bin/alpha/linux/hello",
43 help="The binary to run in syscall emulation mode.")
44parser.add_option("-o", "--options", default="",
45 help="The options to pass to the binary, use \" \" around the entire\
46 string.")
47parser.add_option("-i", "--input", default="",
48 help="A file of input to give to the binary.")
49
50# System options
48parser.add_option("-d", "--detailed", action="store_true")
49parser.add_option("-t", "--timing", action="store_true")
51parser.add_option("-d", "--detailed", action="store_true")
52parser.add_option("-t", "--timing", action="store_true")
53parser.add_option("--caches", action="store_true")
54
55# Run duration options
50parser.add_option("-m", "--maxtick", type="int")
56parser.add_option("-m", "--maxtick", type="int")
57parser.add_option("--maxtime", type="float")
51
58
59#Checkpointing options
60###Note that performing checkpointing via python script files will override
61###checkpoint instructions built into binaries.
62parser.add_option("--take_checkpoints", action="store", type="string",
63 help="<M,N> will take checkpoint at cycle M and every N cycles \
64 thereafter")
65parser.add_option("--max_checkpoints", action="store", type="int",
66 help="the maximum number of checkpoints to drop",
67 default=5)
68parser.add_option("--checkpoint_dir", action="store", type="string",
69 help="Place all checkpoints in this absolute directory")
70parser.add_option("-r", "--checkpoint_restore", action="store", type="int",
71 help="restore from checkpoint <N>")
72
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
75#data measurement
76parser.add_option("-s", "--standard_switch", action="store_true",
77 help="switch from one cpu mode to another")
78
52(options, args) = parser.parse_args()
53
54if args:
55 print "Error: script doesn't take any positional arguments"
56 sys.exit(1)
57
79(options, args) = parser.parse_args()
80
81if args:
82 print "Error: script doesn't take any positional arguments"
83 sys.exit(1)
84
85class MyCache(BaseCache):
86 assoc = 2
87 block_size = 64
88 latency = 1
89 mshrs = 10
90 tgts_per_mshr = 5
91
58process = LiveProcess()
59process.executable = options.cmd
60process.cmd = options.cmd + " " + options.options
61if options.input != "":
62 process.input = options.input
63
64if options.detailed:
65 #check for SMT workload

--- 22 unchanged lines hidden (view full) ---

88 cpu = DerivO3CPU()
89else:
90 cpu = AtomicSimpleCPU()
91
92cpu.workload = process
93cpu.cpu_id = 0
94
95system = System(cpu = cpu,
92process = LiveProcess()
93process.executable = options.cmd
94process.cmd = options.cmd + " " + options.options
95if options.input != "":
96 process.input = options.input
97
98if options.detailed:
99 #check for SMT workload

--- 22 unchanged lines hidden (view full) ---

122 cpu = DerivO3CPU()
123else:
124 cpu = AtomicSimpleCPU()
125
126cpu.workload = process
127cpu.cpu_id = 0
128
129system = System(cpu = cpu,
96 physmem = PhysicalMemory(),
130 physmem = PhysicalMemory(range=AddrRange("512MB")),
97 membus = Bus())
98system.physmem.port = system.membus.port
99system.cpu.connectMemPorts(system.membus)
100system.cpu.mem = system.physmem
131 membus = Bus())
132system.physmem.port = system.membus.port
133system.cpu.connectMemPorts(system.membus)
134system.cpu.mem = system.physmem
135system.cpu.clock = '2GHz'
136if options.caches and not options.standard_switch:
137 system.cpu.addPrivateSplitL1Caches(MyCache(size = '32kB'),
138 MyCache(size = '64kB'))
101
102root = Root(system = system)
103
104if options.timing or options.detailed:
105 root.system.mem_mode = 'timing'
106
139
140root = Root(system = system)
141
142if options.timing or options.detailed:
143 root.system.mem_mode = 'timing'
144
145if options.standard_switch:
146 switch_cpu = TimingSimpleCPU(defer_registration=True, cpu_id=1)
147 switch_cpu1 = DerivO3CPU(defer_registration=True, cpu_id=2)
148 switch_cpu.system = system
149 switch_cpu1.system = system
150 switch_cpu.clock = cpu.clock
151 switch_cpu1.clock = cpu.clock
152 if options.caches:
153 switch_cpu.addPrivateSplitL1Caches(MyCache(size = '32kB'),
154 MyCache(size = '64kB'))
155
156 switch_cpu.workload = process
157 switch_cpu1.workload = process
158 switch_cpu.mem = system.physmem
159 switch_cpu1.mem = system.physmem
160 switch_cpu.connectMemPorts(system.membus)
161 root.switch_cpu = switch_cpu
162 root.switch_cpu1 = switch_cpu1
163 switch_cpu_list = [(system.cpu, switch_cpu)]
164 switch_cpu_list1 = [(switch_cpu, switch_cpu1)]
165
107# instantiate configuration
108m5.instantiate(root)
109
166# instantiate configuration
167m5.instantiate(root)
168
110# simulate until program terminates
169if options.checkpoint_dir:
170 cptdir = options.checkpoint_dir
171else:
172 cptdir = getcwd()
173
174if options.checkpoint_restore:
175 from os.path import isdir
176 from os import listdir, getcwd
177 import re
178
179 if not isdir(cptdir):
180 m5.panic("checkpoint dir %s does not exist!" % cptdir)
181
182 dirs = listdir(cptdir)
183 expr = re.compile('cpt.([0-9]*)')
184 cpts = []
185 for dir in dirs:
186 match = expr.match(dir)
187 if match:
188 cpts.append(match.group(1))
189
190 cpts.sort(lambda a,b: cmp(long(a), long(b)))
191
192 if options.checkpoint_restore > len(cpts):
193 m5.panic('Checkpoint %d not found' % options.checkpoint_restore)
194
195 print "restoring checkpoint from ","/".join([cptdir, "cpt.%s" % cpts[options.checkpoint_restore - 1]])
196 m5.restoreCheckpoint(root, "/".join([cptdir, "cpt.%s" % cpts[options.checkpoint_restore - 1]]))
197
198if options.standard_switch:
199 exit_event = m5.simulate(10000)
200 ## when you change to Timing (or Atomic), you halt the system given
201 ## as argument. When you are finished with the system changes
202 ## (including switchCpus), you must resume the system manually.
203 ## You DON'T need to resume after just switching CPUs if you haven't
204 ## changed anything on the system level.
205 m5.changeToTiming(system)
206 m5.switchCpus(switch_cpu_list)
207 m5.resume(system)
208
209 exit_event = m5.simulate(3000000)
210 m5.switchCpus(switch_cpu_list1)
211
111if options.maxtick:
212if options.maxtick:
112 exit_event = m5.simulate(options.maxtick)
213 maxtick = options.maxtick
214elif options.maxtime:
215 simtime = int(options.maxtime * root.clock.value)
216 print "simulating for: ", simtime
217 maxtick = simtime
113else:
218else:
114 exit_event = m5.simulate()
219 maxtick = -1
115
220
116print 'Exiting @ tick', m5.curTick(), 'because', exit_event.getCause()
221num_checkpoints = 0
117
222
223exit_cause = ''
224
225if options.take_checkpoints:
226 [when, period] = options.take_checkpoints.split(",", 1)
227 when = int(when)
228 period = int(period)
229
230 exit_event = m5.simulate(when)
231 while exit_event.getCause() == "checkpoint":
232 exit_event = m5.simulate(when - m5.curTick())
233
234 if exit_event.getCause() == "simulate() limit reached":
235 m5.checkpoint(root, cptdir + "cpt.%d")
236 num_checkpoints += 1
237
238 sim_ticks = when
239 exit_cause = "maximum %d checkpoints dropped" % options.max_checkpoints
240 while num_checkpoints < options.max_checkpoints:
241 if (sim_ticks + period) > maxtick and maxtick != -1:
242 exit_event = m5.simulate(maxtick - sim_ticks)
243 exit_cause = exit_event.getCause()
244 break
245 else:
246 exit_event = m5.simulate(period)
247 sim_ticks += period
248 while exit_event.getCause() == "checkpoint":
249 exit_event = m5.simulate(period - m5.curTick())
250 if exit_event.getCause() == "simulate() limit reached":
251 m5.checkpoint(root, cptdir + "cpt.%d")
252 num_checkpoints += 1
253
254else: #no checkpoints being taken via this script
255 exit_event = m5.simulate(maxtick)
256
257 while exit_event.getCause() == "checkpoint":
258 m5.checkpoint(root, cptdir + "cpt.%d")
259 num_checkpoints += 1
260 if num_checkpoints == options.max_checkpoints:
261 exit_cause = "maximum %d checkpoints dropped" % options.max_checkpoints
262 break
263
264 if maxtick == -1:
265 exit_event = m5.simulate(maxtick)
266 else:
267 exit_event = m5.simulate(maxtick - m5.curTick())
268
269 exit_cause = exit_event.getCause()
270
271if exit_cause == '':
272 exit_cause = exit_event.getCause()
273print 'Exiting @ cycle', m5.curTick(), 'because ', exit_cause
274
275