se.py (3402:db60546818d0) se.py (3409:769707cf0664)
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

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

29# Simple test script
30#
31# "m5 test.py"
32
33import m5
34from m5.objects import *
35import os, optparse, sys
36m5.AddToPath('../common')
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

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

29# Simple test script
30#
31# "m5 test.py"
32
33import m5
34from m5.objects import *
35import os, optparse, sys
36m5.AddToPath('../common')
37import Simulation
37
38parser = optparse.OptionParser()
39
40# Benchmark options
41parser.add_option("-c", "--cmd",
38
39parser = optparse.OptionParser()
40
41# Benchmark options
42parser.add_option("-c", "--cmd",
42 default="../tests/test-progs/hello/bin/alpha/linux/hello",
43 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
44 help="The binary to run in syscall emulation mode.")
45parser.add_option("-o", "--options", default="",
46 help="The options to pass to the binary, use \" \" around the entire\
47 string.")
48parser.add_option("-i", "--input", default="",
49 help="A file of input to give to the binary.")
50
50# System options
51parser.add_option("-d", "--detailed", action="store_true")
52parser.add_option("-t", "--timing", action="store_true")
53parser.add_option("--caches", action="store_true")
51execfile("Options.py")
54
52
55# Run duration options
56parser.add_option("-m", "--maxtick", type="int")
57parser.add_option("--maxtime", type="float")
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
79(options, args) = parser.parse_args()
80
81if args:
82 print "Error: script doesn't take any positional arguments"
83 sys.exit(1)
84
53(options, args) = parser.parse_args()
54
55if args:
56 print "Error: script doesn't take any positional arguments"
57 sys.exit(1)
58
85class MyCache(BaseCache):
86 assoc = 2
87 block_size = 64
88 latency = 1
89 mshrs = 10
90 tgts_per_mshr = 5
91
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

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

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, ]
116 smt_idx += 1
117
118
119if options.timing:
59process = LiveProcess()
60process.executable = options.cmd
61process.cmd = options.cmd + " " + options.options
62if options.input != "":
63 process.input = options.input
64
65if options.detailed:
66 #check for SMT workload

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

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