e53c755c6c09e1e5528158eaa29966641cd1a8bc
[gem5.git] / configs / common / Simulation.py
1 # Copyright (c) 2012-2013 ARM Limited
2 # All rights reserved
3 #
4 # The license below extends only to copyright in the software and shall
5 # not be construed as granting a license to any other intellectual
6 # property including but not limited to intellectual property relating
7 # to a hardware implementation of the functionality of the software
8 # licensed hereunder. You may use the software subject to the license
9 # terms below provided that you ensure that this notice is replicated
10 # unmodified and in its entirety in all distributions of the software,
11 # modified or unmodified, in source code or in binary form.
12 #
13 # Copyright (c) 2006-2008 The Regents of The University of Michigan
14 # Copyright (c) 2010 Advanced Micro Devices, Inc.
15 # All rights reserved.
16 #
17 # Redistribution and use in source and binary forms, with or without
18 # modification, are permitted provided that the following conditions are
19 # met: redistributions of source code must retain the above copyright
20 # notice, this list of conditions and the following disclaimer;
21 # redistributions in binary form must reproduce the above copyright
22 # notice, this list of conditions and the following disclaimer in the
23 # documentation and/or other materials provided with the distribution;
24 # neither the name of the copyright holders nor the names of its
25 # contributors may be used to endorse or promote products derived from
26 # this software without specific prior written permission.
27 #
28 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
40 from __future__ import print_function
41 from __future__ import absolute_import
42
43 import six
44 import sys
45 from os import getcwd
46 from os.path import join as joinpath
47
48 from common import CpuConfig
49 from common import ObjectList
50
51 import m5
52 from m5.defines import buildEnv
53 from m5.objects import *
54 from m5.util import *
55
56 if six.PY3:
57 long = int
58
59 addToPath('../common')
60
61 def getCPUClass(cpu_type):
62 """Returns the required cpu class and the mode of operation."""
63 cls = ObjectList.cpu_list.get(cpu_type)
64 return cls, cls.memory_mode()
65
66 def setCPUClass(options):
67 """Returns two cpu classes and the initial mode of operation.
68
69 Restoring from a checkpoint or fast forwarding through a benchmark
70 can be done using one type of cpu, and then the actual
71 simulation can be carried out using another type. This function
72 returns these two types of cpus and the initial mode of operation
73 depending on the options provided.
74 """
75
76 TmpClass, test_mem_mode = getCPUClass(options.cpu_type)
77 CPUClass = None
78 if TmpClass.require_caches() and \
79 not options.caches and not options.ruby:
80 fatal("%s must be used with caches" % options.cpu_type)
81
82 if options.checkpoint_restore != None:
83 if options.restore_with_cpu != options.cpu_type:
84 CPUClass = TmpClass
85 TmpClass, test_mem_mode = getCPUClass(options.restore_with_cpu)
86 elif options.fast_forward:
87 CPUClass = TmpClass
88 TmpClass = AtomicSimpleCPU
89 test_mem_mode = 'atomic'
90
91 # Ruby only supports atomic accesses in noncaching mode
92 if test_mem_mode == 'atomic' and options.ruby:
93 warn("Memory mode will be changed to atomic_noncaching")
94 test_mem_mode = 'atomic_noncaching'
95
96 return (TmpClass, test_mem_mode, CPUClass)
97
98 def setMemClass(options):
99 """Returns a memory controller class."""
100
101 return ObjectList.mem_list.get(options.mem_type)
102
103 def setWorkCountOptions(system, options):
104 if options.work_item_id != None:
105 system.work_item_id = options.work_item_id
106 if options.num_work_ids != None:
107 system.num_work_ids = options.num_work_ids
108 if options.work_begin_cpu_id_exit != None:
109 system.work_begin_cpu_id_exit = options.work_begin_cpu_id_exit
110 if options.work_end_exit_count != None:
111 system.work_end_exit_count = options.work_end_exit_count
112 if options.work_end_checkpoint_count != None:
113 system.work_end_ckpt_count = options.work_end_checkpoint_count
114 if options.work_begin_exit_count != None:
115 system.work_begin_exit_count = options.work_begin_exit_count
116 if options.work_begin_checkpoint_count != None:
117 system.work_begin_ckpt_count = options.work_begin_checkpoint_count
118 if options.work_cpus_checkpoint_count != None:
119 system.work_cpus_ckpt_count = options.work_cpus_checkpoint_count
120
121 def findCptDir(options, cptdir, testsys):
122 """Figures out the directory from which the checkpointed state is read.
123
124 There are two different ways in which the directories holding checkpoints
125 can be named --
126 1. cpt.<benchmark name>.<instruction count when the checkpoint was taken>
127 2. cpt.<some number, usually the tick value when the checkpoint was taken>
128
129 This function parses through the options to figure out which one of the
130 above should be used for selecting the checkpoint, and then figures out
131 the appropriate directory.
132 """
133
134 from os.path import isdir, exists
135 from os import listdir
136 import re
137
138 if not isdir(cptdir):
139 fatal("checkpoint dir %s does not exist!", cptdir)
140
141 cpt_starttick = 0
142 if options.at_instruction or options.simpoint:
143 inst = options.checkpoint_restore
144 if options.simpoint:
145 # assume workload 0 has the simpoint
146 if testsys.cpu[0].workload[0].simpoint == 0:
147 fatal('Unable to find simpoint')
148 inst += int(testsys.cpu[0].workload[0].simpoint)
149
150 checkpoint_dir = joinpath(cptdir, "cpt.%s.%s" % (options.bench, inst))
151 if not exists(checkpoint_dir):
152 fatal("Unable to find checkpoint directory %s", checkpoint_dir)
153
154 elif options.restore_simpoint_checkpoint:
155 # Restore from SimPoint checkpoints
156 # Assumes that the checkpoint dir names are formatted as follows:
157 dirs = listdir(cptdir)
158 expr = re.compile('cpt\.simpoint_(\d+)_inst_(\d+)' +
159 '_weight_([\d\.e\-]+)_interval_(\d+)_warmup_(\d+)')
160 cpts = []
161 for dir in dirs:
162 match = expr.match(dir)
163 if match:
164 cpts.append(dir)
165 cpts.sort()
166
167 cpt_num = options.checkpoint_restore
168 if cpt_num > len(cpts):
169 fatal('Checkpoint %d not found', cpt_num)
170 checkpoint_dir = joinpath(cptdir, cpts[cpt_num - 1])
171 match = expr.match(cpts[cpt_num - 1])
172 if match:
173 index = int(match.group(1))
174 start_inst = int(match.group(2))
175 weight_inst = float(match.group(3))
176 interval_length = int(match.group(4))
177 warmup_length = int(match.group(5))
178 print("Resuming from", checkpoint_dir)
179 simpoint_start_insts = []
180 simpoint_start_insts.append(warmup_length)
181 simpoint_start_insts.append(warmup_length + interval_length)
182 testsys.cpu[0].simpoint_start_insts = simpoint_start_insts
183 if testsys.switch_cpus != None:
184 testsys.switch_cpus[0].simpoint_start_insts = simpoint_start_insts
185
186 print("Resuming from SimPoint", end=' ')
187 print("#%d, start_inst:%d, weight:%f, interval:%d, warmup:%d" %
188 (index, start_inst, weight_inst, interval_length, warmup_length))
189
190 else:
191 dirs = listdir(cptdir)
192 expr = re.compile('cpt\.([0-9]+)')
193 cpts = []
194 for dir in dirs:
195 match = expr.match(dir)
196 if match:
197 cpts.append(match.group(1))
198
199 cpts.sort(lambda a,b: cmp(long(a), long(b)))
200
201 cpt_num = options.checkpoint_restore
202 if cpt_num > len(cpts):
203 fatal('Checkpoint %d not found', cpt_num)
204
205 cpt_starttick = int(cpts[cpt_num - 1])
206 checkpoint_dir = joinpath(cptdir, "cpt.%s" % cpts[cpt_num - 1])
207
208 return cpt_starttick, checkpoint_dir
209
210 def scriptCheckpoints(options, maxtick, cptdir):
211 if options.at_instruction or options.simpoint:
212 checkpoint_inst = int(options.take_checkpoints)
213
214 # maintain correct offset if we restored from some instruction
215 if options.checkpoint_restore != None:
216 checkpoint_inst += options.checkpoint_restore
217
218 print("Creating checkpoint at inst:%d" % (checkpoint_inst))
219 exit_event = m5.simulate()
220 exit_cause = exit_event.getCause()
221 print("exit cause = %s" % exit_cause)
222
223 # skip checkpoint instructions should they exist
224 while exit_cause == "checkpoint":
225 exit_event = m5.simulate()
226 exit_cause = exit_event.getCause()
227
228 if exit_cause == "a thread reached the max instruction count":
229 m5.checkpoint(joinpath(cptdir, "cpt.%s.%d" % \
230 (options.bench, checkpoint_inst)))
231 print("Checkpoint written.")
232
233 else:
234 when, period = options.take_checkpoints.split(",", 1)
235 when = int(when)
236 period = int(period)
237 num_checkpoints = 0
238
239 exit_event = m5.simulate(when - m5.curTick())
240 exit_cause = exit_event.getCause()
241 while exit_cause == "checkpoint":
242 exit_event = m5.simulate(when - m5.curTick())
243 exit_cause = exit_event.getCause()
244
245 if exit_cause == "simulate() limit reached":
246 m5.checkpoint(joinpath(cptdir, "cpt.%d"))
247 num_checkpoints += 1
248
249 sim_ticks = when
250 max_checkpoints = options.max_checkpoints
251
252 while num_checkpoints < max_checkpoints and \
253 exit_cause == "simulate() limit reached":
254 if (sim_ticks + period) > maxtick:
255 exit_event = m5.simulate(maxtick - sim_ticks)
256 exit_cause = exit_event.getCause()
257 break
258 else:
259 exit_event = m5.simulate(period)
260 exit_cause = exit_event.getCause()
261 sim_ticks += period
262 while exit_event.getCause() == "checkpoint":
263 exit_event = m5.simulate(sim_ticks - m5.curTick())
264 if exit_event.getCause() == "simulate() limit reached":
265 m5.checkpoint(joinpath(cptdir, "cpt.%d"))
266 num_checkpoints += 1
267
268 return exit_event
269
270 def benchCheckpoints(options, maxtick, cptdir):
271 exit_event = m5.simulate(maxtick - m5.curTick())
272 exit_cause = exit_event.getCause()
273
274 num_checkpoints = 0
275 max_checkpoints = options.max_checkpoints
276
277 while exit_cause == "checkpoint":
278 m5.checkpoint(joinpath(cptdir, "cpt.%d"))
279 num_checkpoints += 1
280 if num_checkpoints == max_checkpoints:
281 exit_cause = "maximum %d checkpoints dropped" % max_checkpoints
282 break
283
284 exit_event = m5.simulate(maxtick - m5.curTick())
285 exit_cause = exit_event.getCause()
286
287 return exit_event
288
289 # Set up environment for taking SimPoint checkpoints
290 # Expecting SimPoint files generated by SimPoint 3.2
291 def parseSimpointAnalysisFile(options, testsys):
292 import re
293
294 simpoint_filename, weight_filename, interval_length, warmup_length = \
295 options.take_simpoint_checkpoints.split(",", 3)
296 print("simpoint analysis file:", simpoint_filename)
297 print("simpoint weight file:", weight_filename)
298 print("interval length:", interval_length)
299 print("warmup length:", warmup_length)
300
301 interval_length = int(interval_length)
302 warmup_length = int(warmup_length)
303
304 # Simpoint analysis output starts interval counts with 0.
305 simpoints = []
306 simpoint_start_insts = []
307
308 # Read in SimPoint analysis files
309 simpoint_file = open(simpoint_filename)
310 weight_file = open(weight_filename)
311 while True:
312 line = simpoint_file.readline()
313 if not line:
314 break
315 m = re.match("(\d+)\s+(\d+)", line)
316 if m:
317 interval = int(m.group(1))
318 else:
319 fatal('unrecognized line in simpoint file!')
320
321 line = weight_file.readline()
322 if not line:
323 fatal('not enough lines in simpoint weight file!')
324 m = re.match("([0-9\.e\-]+)\s+(\d+)", line)
325 if m:
326 weight = float(m.group(1))
327 else:
328 fatal('unrecognized line in simpoint weight file!')
329
330 if (interval * interval_length - warmup_length > 0):
331 starting_inst_count = \
332 interval * interval_length - warmup_length
333 actual_warmup_length = warmup_length
334 else:
335 # Not enough room for proper warmup
336 # Just starting from the beginning
337 starting_inst_count = 0
338 actual_warmup_length = interval * interval_length
339
340 simpoints.append((interval, weight, starting_inst_count,
341 actual_warmup_length))
342
343 # Sort SimPoints by starting inst count
344 simpoints.sort(key=lambda obj: obj[2])
345 for s in simpoints:
346 interval, weight, starting_inst_count, actual_warmup_length = s
347 print(str(interval), str(weight), starting_inst_count,
348 actual_warmup_length)
349 simpoint_start_insts.append(starting_inst_count)
350
351 print("Total # of simpoints:", len(simpoints))
352 testsys.cpu[0].simpoint_start_insts = simpoint_start_insts
353
354 return (simpoints, interval_length)
355
356 def takeSimpointCheckpoints(simpoints, interval_length, cptdir):
357 num_checkpoints = 0
358 index = 0
359 last_chkpnt_inst_count = -1
360 for simpoint in simpoints:
361 interval, weight, starting_inst_count, actual_warmup_length = simpoint
362 if starting_inst_count == last_chkpnt_inst_count:
363 # checkpoint starting point same as last time
364 # (when warmup period longer than starting point)
365 exit_cause = "simpoint starting point found"
366 code = 0
367 else:
368 exit_event = m5.simulate()
369
370 # skip checkpoint instructions should they exist
371 while exit_event.getCause() == "checkpoint":
372 print("Found 'checkpoint' exit event...ignoring...")
373 exit_event = m5.simulate()
374
375 exit_cause = exit_event.getCause()
376 code = exit_event.getCode()
377
378 if exit_cause == "simpoint starting point found":
379 m5.checkpoint(joinpath(cptdir,
380 "cpt.simpoint_%02d_inst_%d_weight_%f_interval_%d_warmup_%d"
381 % (index, starting_inst_count, weight, interval_length,
382 actual_warmup_length)))
383 print("Checkpoint #%d written. start inst:%d weight:%f" %
384 (num_checkpoints, starting_inst_count, weight))
385 num_checkpoints += 1
386 last_chkpnt_inst_count = starting_inst_count
387 else:
388 break
389 index += 1
390
391 print('Exiting @ tick %i because %s' % (m5.curTick(), exit_cause))
392 print("%d checkpoints taken" % num_checkpoints)
393 sys.exit(code)
394
395 def restoreSimpointCheckpoint():
396 exit_event = m5.simulate()
397 exit_cause = exit_event.getCause()
398
399 if exit_cause == "simpoint starting point found":
400 print("Warmed up! Dumping and resetting stats!")
401 m5.stats.dump()
402 m5.stats.reset()
403
404 exit_event = m5.simulate()
405 exit_cause = exit_event.getCause()
406
407 if exit_cause == "simpoint starting point found":
408 print("Done running SimPoint!")
409 sys.exit(exit_event.getCode())
410
411 print('Exiting @ tick %i because %s' % (m5.curTick(), exit_cause))
412 sys.exit(exit_event.getCode())
413
414 def repeatSwitch(testsys, repeat_switch_cpu_list, maxtick, switch_freq):
415 print("starting switch loop")
416 while True:
417 exit_event = m5.simulate(switch_freq)
418 exit_cause = exit_event.getCause()
419
420 if exit_cause != "simulate() limit reached":
421 return exit_event
422
423 m5.switchCpus(testsys, repeat_switch_cpu_list)
424
425 tmp_cpu_list = []
426 for old_cpu, new_cpu in repeat_switch_cpu_list:
427 tmp_cpu_list.append((new_cpu, old_cpu))
428 repeat_switch_cpu_list = tmp_cpu_list
429
430 if (maxtick - m5.curTick()) <= switch_freq:
431 exit_event = m5.simulate(maxtick - m5.curTick())
432 return exit_event
433
434 def run(options, root, testsys, cpu_class):
435 if options.checkpoint_dir:
436 cptdir = options.checkpoint_dir
437 elif m5.options.outdir:
438 cptdir = m5.options.outdir
439 else:
440 cptdir = getcwd()
441
442 if options.fast_forward and options.checkpoint_restore != None:
443 fatal("Can't specify both --fast-forward and --checkpoint-restore")
444
445 if options.standard_switch and not options.caches:
446 fatal("Must specify --caches when using --standard-switch")
447
448 if options.standard_switch and options.repeat_switch:
449 fatal("Can't specify both --standard-switch and --repeat-switch")
450
451 if options.repeat_switch and options.take_checkpoints:
452 fatal("Can't specify both --repeat-switch and --take-checkpoints")
453
454 np = options.num_cpus
455 switch_cpus = None
456
457 if options.prog_interval:
458 for i in range(np):
459 testsys.cpu[i].progress_interval = options.prog_interval
460
461 if options.maxinsts:
462 for i in range(np):
463 testsys.cpu[i].max_insts_any_thread = options.maxinsts
464
465 if cpu_class:
466 switch_cpus = [cpu_class(switched_out=True, cpu_id=(i))
467 for i in range(np)]
468
469 for i in range(np):
470 if options.fast_forward:
471 testsys.cpu[i].max_insts_any_thread = int(options.fast_forward)
472 switch_cpus[i].system = testsys
473 switch_cpus[i].workload = testsys.cpu[i].workload
474 switch_cpus[i].clk_domain = testsys.cpu[i].clk_domain
475 switch_cpus[i].progress_interval = \
476 testsys.cpu[i].progress_interval
477 switch_cpus[i].isa = testsys.cpu[i].isa
478 # simulation period
479 if options.maxinsts:
480 switch_cpus[i].max_insts_any_thread = options.maxinsts
481 # Add checker cpu if selected
482 if options.checker:
483 switch_cpus[i].addCheckerCpu()
484 if options.bp_type:
485 bpClass = ObjectList.bp_list.get(options.bp_type)
486 switch_cpus[i].branchPred = bpClass()
487 if options.indirect_bp_type:
488 IndirectBPClass = ObjectList.indirect_bp_list.get(
489 options.indirect_bp_type)
490 switch_cpus[i].branchPred.indirectBranchPred = \
491 IndirectBPClass()
492
493 # If elastic tracing is enabled attach the elastic trace probe
494 # to the switch CPUs
495 if options.elastic_trace_en:
496 CpuConfig.config_etrace(cpu_class, switch_cpus, options)
497
498 testsys.switch_cpus = switch_cpus
499 switch_cpu_list = [(testsys.cpu[i], switch_cpus[i]) for i in range(np)]
500
501 if options.repeat_switch:
502 switch_class = getCPUClass(options.cpu_type)[0]
503 if switch_class.require_caches() and \
504 not options.caches:
505 print("%s: Must be used with caches" % str(switch_class))
506 sys.exit(1)
507 if not switch_class.support_take_over():
508 print("%s: CPU switching not supported" % str(switch_class))
509 sys.exit(1)
510
511 repeat_switch_cpus = [switch_class(switched_out=True, \
512 cpu_id=(i)) for i in range(np)]
513
514 for i in range(np):
515 repeat_switch_cpus[i].system = testsys
516 repeat_switch_cpus[i].workload = testsys.cpu[i].workload
517 repeat_switch_cpus[i].clk_domain = testsys.cpu[i].clk_domain
518 repeat_switch_cpus[i].isa = testsys.cpu[i].isa
519
520 if options.maxinsts:
521 repeat_switch_cpus[i].max_insts_any_thread = options.maxinsts
522
523 if options.checker:
524 repeat_switch_cpus[i].addCheckerCpu()
525
526 testsys.repeat_switch_cpus = repeat_switch_cpus
527
528 if cpu_class:
529 repeat_switch_cpu_list = [(switch_cpus[i], repeat_switch_cpus[i])
530 for i in range(np)]
531 else:
532 repeat_switch_cpu_list = [(testsys.cpu[i], repeat_switch_cpus[i])
533 for i in range(np)]
534
535 if options.standard_switch:
536 switch_cpus = [TimingSimpleCPU(switched_out=True, cpu_id=(i))
537 for i in range(np)]
538 switch_cpus_1 = [DerivO3CPU(switched_out=True, cpu_id=(i))
539 for i in range(np)]
540
541 for i in range(np):
542 switch_cpus[i].system = testsys
543 switch_cpus_1[i].system = testsys
544 switch_cpus[i].workload = testsys.cpu[i].workload
545 switch_cpus_1[i].workload = testsys.cpu[i].workload
546 switch_cpus[i].clk_domain = testsys.cpu[i].clk_domain
547 switch_cpus_1[i].clk_domain = testsys.cpu[i].clk_domain
548 switch_cpus[i].isa = testsys.cpu[i].isa
549 switch_cpus_1[i].isa = testsys.cpu[i].isa
550
551 # if restoring, make atomic cpu simulate only a few instructions
552 if options.checkpoint_restore != None:
553 testsys.cpu[i].max_insts_any_thread = 1
554 # Fast forward to specified location if we are not restoring
555 elif options.fast_forward:
556 testsys.cpu[i].max_insts_any_thread = int(options.fast_forward)
557 # Fast forward to a simpoint (warning: time consuming)
558 elif options.simpoint:
559 if testsys.cpu[i].workload[0].simpoint == 0:
560 fatal('simpoint not found')
561 testsys.cpu[i].max_insts_any_thread = \
562 testsys.cpu[i].workload[0].simpoint
563 # No distance specified, just switch
564 else:
565 testsys.cpu[i].max_insts_any_thread = 1
566
567 # warmup period
568 if options.warmup_insts:
569 switch_cpus[i].max_insts_any_thread = options.warmup_insts
570
571 # simulation period
572 if options.maxinsts:
573 switch_cpus_1[i].max_insts_any_thread = options.maxinsts
574
575 # attach the checker cpu if selected
576 if options.checker:
577 switch_cpus[i].addCheckerCpu()
578 switch_cpus_1[i].addCheckerCpu()
579
580 testsys.switch_cpus = switch_cpus
581 testsys.switch_cpus_1 = switch_cpus_1
582 switch_cpu_list = [
583 (testsys.cpu[i], switch_cpus[i]) for i in range(np)
584 ]
585 switch_cpu_list1 = [
586 (switch_cpus[i], switch_cpus_1[i]) for i in range(np)
587 ]
588
589 # set the checkpoint in the cpu before m5.instantiate is called
590 if options.take_checkpoints != None and \
591 (options.simpoint or options.at_instruction):
592 offset = int(options.take_checkpoints)
593 # Set an instruction break point
594 if options.simpoint:
595 for i in range(np):
596 if testsys.cpu[i].workload[0].simpoint == 0:
597 fatal('no simpoint for testsys.cpu[%d].workload[0]', i)
598 checkpoint_inst = int(testsys.cpu[i].workload[0].simpoint) + offset
599 testsys.cpu[i].max_insts_any_thread = checkpoint_inst
600 # used for output below
601 options.take_checkpoints = checkpoint_inst
602 else:
603 options.take_checkpoints = offset
604 # Set all test cpus with the right number of instructions
605 # for the upcoming simulation
606 for i in range(np):
607 testsys.cpu[i].max_insts_any_thread = offset
608
609 if options.take_simpoint_checkpoints != None:
610 simpoints, interval_length = parseSimpointAnalysisFile(options, testsys)
611
612 checkpoint_dir = None
613 if options.checkpoint_restore:
614 cpt_starttick, checkpoint_dir = findCptDir(options, cptdir, testsys)
615 root.apply_config(options.param)
616 m5.instantiate(checkpoint_dir)
617
618 # Initialization is complete. If we're not in control of simulation
619 # (that is, if we're a slave simulator acting as a component in another
620 # 'master' simulator) then we're done here. The other simulator will
621 # call simulate() directly. --initialize-only is used to indicate this.
622 if options.initialize_only:
623 return
624
625 # Handle the max tick settings now that tick frequency was resolved
626 # during system instantiation
627 # NOTE: the maxtick variable here is in absolute ticks, so it must
628 # include any simulated ticks before a checkpoint
629 explicit_maxticks = 0
630 maxtick_from_abs = m5.MaxTick
631 maxtick_from_rel = m5.MaxTick
632 maxtick_from_maxtime = m5.MaxTick
633 if options.abs_max_tick:
634 maxtick_from_abs = options.abs_max_tick
635 explicit_maxticks += 1
636 if options.rel_max_tick:
637 maxtick_from_rel = options.rel_max_tick
638 if options.checkpoint_restore:
639 # NOTE: this may need to be updated if checkpoints ever store
640 # the ticks per simulated second
641 maxtick_from_rel += cpt_starttick
642 if options.at_instruction or options.simpoint:
643 warn("Relative max tick specified with --at-instruction or" \
644 " --simpoint\n These options don't specify the " \
645 "checkpoint start tick, so assuming\n you mean " \
646 "absolute max tick")
647 explicit_maxticks += 1
648 if options.maxtime:
649 maxtick_from_maxtime = m5.ticks.fromSeconds(options.maxtime)
650 explicit_maxticks += 1
651 if explicit_maxticks > 1:
652 warn("Specified multiple of --abs-max-tick, --rel-max-tick, --maxtime."\
653 " Using least")
654 maxtick = min([maxtick_from_abs, maxtick_from_rel, maxtick_from_maxtime])
655
656 if options.checkpoint_restore != None and maxtick < cpt_starttick:
657 fatal("Bad maxtick (%d) specified: " \
658 "Checkpoint starts starts from tick: %d", maxtick, cpt_starttick)
659
660 if options.standard_switch or cpu_class:
661 if options.standard_switch:
662 print("Switch at instruction count:%s" %
663 str(testsys.cpu[0].max_insts_any_thread))
664 exit_event = m5.simulate()
665 elif cpu_class and options.fast_forward:
666 print("Switch at instruction count:%s" %
667 str(testsys.cpu[0].max_insts_any_thread))
668 exit_event = m5.simulate()
669 else:
670 print("Switch at curTick count:%s" % str(10000))
671 exit_event = m5.simulate(10000)
672 print("Switched CPUS @ tick %s" % (m5.curTick()))
673
674 m5.switchCpus(testsys, switch_cpu_list)
675
676 if options.standard_switch:
677 print("Switch at instruction count:%d" %
678 (testsys.switch_cpus[0].max_insts_any_thread))
679
680 #warmup instruction count may have already been set
681 if options.warmup_insts:
682 exit_event = m5.simulate()
683 else:
684 exit_event = m5.simulate(options.standard_switch)
685 print("Switching CPUS @ tick %s" % (m5.curTick()))
686 print("Simulation ends instruction count:%d" %
687 (testsys.switch_cpus_1[0].max_insts_any_thread))
688 m5.switchCpus(testsys, switch_cpu_list1)
689
690 # If we're taking and restoring checkpoints, use checkpoint_dir
691 # option only for finding the checkpoints to restore from. This
692 # lets us test checkpointing by restoring from one set of
693 # checkpoints, generating a second set, and then comparing them.
694 if (options.take_checkpoints or options.take_simpoint_checkpoints) \
695 and options.checkpoint_restore:
696
697 if m5.options.outdir:
698 cptdir = m5.options.outdir
699 else:
700 cptdir = getcwd()
701
702 if options.take_checkpoints != None :
703 # Checkpoints being taken via the command line at <when> and at
704 # subsequent periods of <period>. Checkpoint instructions
705 # received from the benchmark running are ignored and skipped in
706 # favor of command line checkpoint instructions.
707 exit_event = scriptCheckpoints(options, maxtick, cptdir)
708
709 # Take SimPoint checkpoints
710 elif options.take_simpoint_checkpoints != None:
711 takeSimpointCheckpoints(simpoints, interval_length, cptdir)
712
713 # Restore from SimPoint checkpoints
714 elif options.restore_simpoint_checkpoint != None:
715 restoreSimpointCheckpoint()
716
717 else:
718 if options.fast_forward:
719 m5.stats.reset()
720 print("**** REAL SIMULATION ****")
721
722 # If checkpoints are being taken, then the checkpoint instruction
723 # will occur in the benchmark code it self.
724 if options.repeat_switch and maxtick > options.repeat_switch:
725 exit_event = repeatSwitch(testsys, repeat_switch_cpu_list,
726 maxtick, options.repeat_switch)
727 else:
728 exit_event = benchCheckpoints(options, maxtick, cptdir)
729
730 print('Exiting @ tick %i because %s' %
731 (m5.curTick(), exit_event.getCause()))
732 if options.checkpoint_at_end:
733 m5.checkpoint(joinpath(cptdir, "cpt.%d"))
734
735 if exit_event.getCode() != 0:
736 print("Simulated exit code not 0! Exit code is", exit_event.getCode())