1 # Copyright (c) 2012-2013 ARM Limited
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.
13 # Copyright (c) 2006-2008 The Regents of The University of Michigan
14 # Copyright (c) 2010 Advanced Micro Devices, Inc.
15 # All rights reserved.
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.
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.
42 from __future__
import print_function
43 from __future__
import absolute_import
47 from os
.path
import join
as joinpath
49 from . import CpuConfig
50 from . import BPConfig
51 from . import MemConfig
54 from m5
.defines
import buildEnv
55 from m5
.objects
import *
58 addToPath('../common')
60 def getCPUClass(cpu_type
):
61 """Returns the required cpu class and the mode of operation."""
62 cls
= CpuConfig
.get(cpu_type
)
63 return cls
, cls
.memory_mode()
65 def setCPUClass(options
):
66 """Returns two cpu classes and the initial mode of operation.
68 Restoring from a checkpoint or fast forwarding through a benchmark
69 can be done using one type of cpu, and then the actual
70 simulation can be carried out using another type. This function
71 returns these two types of cpus and the initial mode of operation
72 depending on the options provided.
75 TmpClass
, test_mem_mode
= getCPUClass(options
.cpu_type
)
77 if TmpClass
.require_caches() and \
78 not options
.caches
and not options
.ruby
:
79 fatal("%s must be used with caches" % options
.cpu_type
)
81 if options
.checkpoint_restore
!= None:
82 if options
.restore_with_cpu
!= options
.cpu_type
:
84 TmpClass
, test_mem_mode
= getCPUClass(options
.restore_with_cpu
)
85 elif options
.fast_forward
:
87 TmpClass
= AtomicSimpleCPU
88 test_mem_mode
= 'atomic'
90 # Ruby only supports atomic accesses in noncaching mode
91 if test_mem_mode
== 'atomic' and options
.ruby
:
92 warn("Memory mode will be changed to atomic_noncaching")
93 test_mem_mode
= 'atomic_noncaching'
95 return (TmpClass
, test_mem_mode
, CPUClass
)
97 def setMemClass(options
):
98 """Returns a memory controller class."""
100 return MemConfig
.get(options
.mem_type
)
102 def setWorkCountOptions(system
, options
):
103 if options
.work_item_id
!= None:
104 system
.work_item_id
= options
.work_item_id
105 if options
.num_work_ids
!= None:
106 system
.num_work_ids
= options
.num_work_ids
107 if options
.work_begin_cpu_id_exit
!= None:
108 system
.work_begin_cpu_id_exit
= options
.work_begin_cpu_id_exit
109 if options
.work_end_exit_count
!= None:
110 system
.work_end_exit_count
= options
.work_end_exit_count
111 if options
.work_end_checkpoint_count
!= None:
112 system
.work_end_ckpt_count
= options
.work_end_checkpoint_count
113 if options
.work_begin_exit_count
!= None:
114 system
.work_begin_exit_count
= options
.work_begin_exit_count
115 if options
.work_begin_checkpoint_count
!= None:
116 system
.work_begin_ckpt_count
= options
.work_begin_checkpoint_count
117 if options
.work_cpus_checkpoint_count
!= None:
118 system
.work_cpus_ckpt_count
= options
.work_cpus_checkpoint_count
120 def findCptDir(options
, cptdir
, testsys
):
121 """Figures out the directory from which the checkpointed state is read.
123 There are two different ways in which the directories holding checkpoints
125 1. cpt.<benchmark name>.<instruction count when the checkpoint was taken>
126 2. cpt.<some number, usually the tick value when the checkpoint was taken>
128 This function parses through the options to figure out which one of the
129 above should be used for selecting the checkpoint, and then figures out
130 the appropriate directory.
133 from os
.path
import isdir
, exists
134 from os
import listdir
137 if not isdir(cptdir
):
138 fatal("checkpoint dir %s does not exist!", cptdir
)
141 if options
.at_instruction
or options
.simpoint
:
142 inst
= options
.checkpoint_restore
144 # assume workload 0 has the simpoint
145 if testsys
.cpu
[0].workload
[0].simpoint
== 0:
146 fatal('Unable to find simpoint')
147 inst
+= int(testsys
.cpu
[0].workload
[0].simpoint
)
149 checkpoint_dir
= joinpath(cptdir
, "cpt.%s.%s" % (options
.bench
, inst
))
150 if not exists(checkpoint_dir
):
151 fatal("Unable to find checkpoint directory %s", checkpoint_dir
)
153 elif options
.restore_simpoint_checkpoint
:
154 # Restore from SimPoint checkpoints
155 # Assumes that the checkpoint dir names are formatted as follows:
156 dirs
= listdir(cptdir
)
157 expr
= re
.compile('cpt\.simpoint_(\d+)_inst_(\d+)' +
158 '_weight_([\d\.e\-]+)_interval_(\d+)_warmup_(\d+)')
161 match
= expr
.match(dir)
166 cpt_num
= options
.checkpoint_restore
167 if cpt_num
> len(cpts
):
168 fatal('Checkpoint %d not found', cpt_num
)
169 checkpoint_dir
= joinpath(cptdir
, cpts
[cpt_num
- 1])
170 match
= expr
.match(cpts
[cpt_num
- 1])
172 index
= int(match
.group(1))
173 start_inst
= int(match
.group(2))
174 weight_inst
= float(match
.group(3))
175 interval_length
= int(match
.group(4))
176 warmup_length
= int(match
.group(5))
177 print("Resuming from", checkpoint_dir
)
178 simpoint_start_insts
= []
179 simpoint_start_insts
.append(warmup_length
)
180 simpoint_start_insts
.append(warmup_length
+ interval_length
)
181 testsys
.cpu
[0].simpoint_start_insts
= simpoint_start_insts
182 if testsys
.switch_cpus
!= None:
183 testsys
.switch_cpus
[0].simpoint_start_insts
= simpoint_start_insts
185 print("Resuming from SimPoint", end
=' ')
186 print("#%d, start_inst:%d, weight:%f, interval:%d, warmup:%d" %
187 (index
, start_inst
, weight_inst
, interval_length
, warmup_length
))
190 dirs
= listdir(cptdir
)
191 expr
= re
.compile('cpt\.([0-9]+)')
194 match
= expr
.match(dir)
196 cpts
.append(match
.group(1))
198 cpts
.sort(lambda a
,b
: cmp(long(a
), long(b
)))
200 cpt_num
= options
.checkpoint_restore
201 if cpt_num
> len(cpts
):
202 fatal('Checkpoint %d not found', cpt_num
)
204 cpt_starttick
= int(cpts
[cpt_num
- 1])
205 checkpoint_dir
= joinpath(cptdir
, "cpt.%s" % cpts
[cpt_num
- 1])
207 return cpt_starttick
, checkpoint_dir
209 def scriptCheckpoints(options
, maxtick
, cptdir
):
210 if options
.at_instruction
or options
.simpoint
:
211 checkpoint_inst
= int(options
.take_checkpoints
)
213 # maintain correct offset if we restored from some instruction
214 if options
.checkpoint_restore
!= None:
215 checkpoint_inst
+= options
.checkpoint_restore
217 print("Creating checkpoint at inst:%d" % (checkpoint_inst
))
218 exit_event
= m5
.simulate()
219 exit_cause
= exit_event
.getCause()
220 print("exit cause = %s" % exit_cause
)
222 # skip checkpoint instructions should they exist
223 while exit_cause
== "checkpoint":
224 exit_event
= m5
.simulate()
225 exit_cause
= exit_event
.getCause()
227 if exit_cause
== "a thread reached the max instruction count":
228 m5
.checkpoint(joinpath(cptdir
, "cpt.%s.%d" % \
229 (options
.bench
, checkpoint_inst
)))
230 print("Checkpoint written.")
233 when
, period
= options
.take_checkpoints
.split(",", 1)
238 exit_event
= m5
.simulate(when
- m5
.curTick())
239 exit_cause
= exit_event
.getCause()
240 while exit_cause
== "checkpoint":
241 exit_event
= m5
.simulate(when
- m5
.curTick())
242 exit_cause
= exit_event
.getCause()
244 if exit_cause
== "simulate() limit reached":
245 m5
.checkpoint(joinpath(cptdir
, "cpt.%d"))
249 max_checkpoints
= options
.max_checkpoints
251 while num_checkpoints
< max_checkpoints
and \
252 exit_cause
== "simulate() limit reached":
253 if (sim_ticks
+ period
) > maxtick
:
254 exit_event
= m5
.simulate(maxtick
- sim_ticks
)
255 exit_cause
= exit_event
.getCause()
258 exit_event
= m5
.simulate(period
)
259 exit_cause
= exit_event
.getCause()
261 while exit_event
.getCause() == "checkpoint":
262 exit_event
= m5
.simulate(sim_ticks
- m5
.curTick())
263 if exit_event
.getCause() == "simulate() limit reached":
264 m5
.checkpoint(joinpath(cptdir
, "cpt.%d"))
269 def benchCheckpoints(options
, maxtick
, cptdir
):
270 exit_event
= m5
.simulate(maxtick
- m5
.curTick())
271 exit_cause
= exit_event
.getCause()
274 max_checkpoints
= options
.max_checkpoints
276 while exit_cause
== "checkpoint":
277 m5
.checkpoint(joinpath(cptdir
, "cpt.%d"))
279 if num_checkpoints
== max_checkpoints
:
280 exit_cause
= "maximum %d checkpoints dropped" % max_checkpoints
283 exit_event
= m5
.simulate(maxtick
- m5
.curTick())
284 exit_cause
= exit_event
.getCause()
288 # Set up environment for taking SimPoint checkpoints
289 # Expecting SimPoint files generated by SimPoint 3.2
290 def parseSimpointAnalysisFile(options
, testsys
):
293 simpoint_filename
, weight_filename
, interval_length
, warmup_length
= \
294 options
.take_simpoint_checkpoints
.split(",", 3)
295 print("simpoint analysis file:", simpoint_filename
)
296 print("simpoint weight file:", weight_filename
)
297 print("interval length:", interval_length
)
298 print("warmup length:", warmup_length
)
300 interval_length
= int(interval_length
)
301 warmup_length
= int(warmup_length
)
303 # Simpoint analysis output starts interval counts with 0.
305 simpoint_start_insts
= []
307 # Read in SimPoint analysis files
308 simpoint_file
= open(simpoint_filename
)
309 weight_file
= open(weight_filename
)
311 line
= simpoint_file
.readline()
314 m
= re
.match("(\d+)\s+(\d+)", line
)
316 interval
= int(m
.group(1))
318 fatal('unrecognized line in simpoint file!')
320 line
= weight_file
.readline()
322 fatal('not enough lines in simpoint weight file!')
323 m
= re
.match("([0-9\.e\-]+)\s+(\d+)", line
)
325 weight
= float(m
.group(1))
327 fatal('unrecognized line in simpoint weight file!')
329 if (interval
* interval_length
- warmup_length
> 0):
330 starting_inst_count
= \
331 interval
* interval_length
- warmup_length
332 actual_warmup_length
= warmup_length
334 # Not enough room for proper warmup
335 # Just starting from the beginning
336 starting_inst_count
= 0
337 actual_warmup_length
= interval
* interval_length
339 simpoints
.append((interval
, weight
, starting_inst_count
,
340 actual_warmup_length
))
342 # Sort SimPoints by starting inst count
343 simpoints
.sort(key
=lambda obj
: obj
[2])
345 interval
, weight
, starting_inst_count
, actual_warmup_length
= s
346 print(str(interval
), str(weight
), starting_inst_count
,
347 actual_warmup_length
)
348 simpoint_start_insts
.append(starting_inst_count
)
350 print("Total # of simpoints:", len(simpoints
))
351 testsys
.cpu
[0].simpoint_start_insts
= simpoint_start_insts
353 return (simpoints
, interval_length
)
355 def takeSimpointCheckpoints(simpoints
, interval_length
, cptdir
):
358 last_chkpnt_inst_count
= -1
359 for simpoint
in simpoints
:
360 interval
, weight
, starting_inst_count
, actual_warmup_length
= simpoint
361 if starting_inst_count
== last_chkpnt_inst_count
:
362 # checkpoint starting point same as last time
363 # (when warmup period longer than starting point)
364 exit_cause
= "simpoint starting point found"
367 exit_event
= m5
.simulate()
369 # skip checkpoint instructions should they exist
370 while exit_event
.getCause() == "checkpoint":
371 print("Found 'checkpoint' exit event...ignoring...")
372 exit_event
= m5
.simulate()
374 exit_cause
= exit_event
.getCause()
375 code
= exit_event
.getCode()
377 if exit_cause
== "simpoint starting point found":
378 m5
.checkpoint(joinpath(cptdir
,
379 "cpt.simpoint_%02d_inst_%d_weight_%f_interval_%d_warmup_%d"
380 % (index
, starting_inst_count
, weight
, interval_length
,
381 actual_warmup_length
)))
382 print("Checkpoint #%d written. start inst:%d weight:%f" %
383 (num_checkpoints
, starting_inst_count
, weight
))
385 last_chkpnt_inst_count
= starting_inst_count
390 print('Exiting @ tick %i because %s' % (m5
.curTick(), exit_cause
))
391 print("%d checkpoints taken" % num_checkpoints
)
394 def restoreSimpointCheckpoint():
395 exit_event
= m5
.simulate()
396 exit_cause
= exit_event
.getCause()
398 if exit_cause
== "simpoint starting point found":
399 print("Warmed up! Dumping and resetting stats!")
403 exit_event
= m5
.simulate()
404 exit_cause
= exit_event
.getCause()
406 if exit_cause
== "simpoint starting point found":
407 print("Done running SimPoint!")
408 sys
.exit(exit_event
.getCode())
410 print('Exiting @ tick %i because %s' % (m5
.curTick(), exit_cause
))
411 sys
.exit(exit_event
.getCode())
413 def repeatSwitch(testsys
, repeat_switch_cpu_list
, maxtick
, switch_freq
):
414 print("starting switch loop")
416 exit_event
= m5
.simulate(switch_freq
)
417 exit_cause
= exit_event
.getCause()
419 if exit_cause
!= "simulate() limit reached":
422 m5
.switchCpus(testsys
, repeat_switch_cpu_list
)
425 for old_cpu
, new_cpu
in repeat_switch_cpu_list
:
426 tmp_cpu_list
.append((new_cpu
, old_cpu
))
427 repeat_switch_cpu_list
= tmp_cpu_list
429 if (maxtick
- m5
.curTick()) <= switch_freq
:
430 exit_event
= m5
.simulate(maxtick
- m5
.curTick())
433 def run(options
, root
, testsys
, cpu_class
):
434 if options
.checkpoint_dir
:
435 cptdir
= options
.checkpoint_dir
436 elif m5
.options
.outdir
:
437 cptdir
= m5
.options
.outdir
441 if options
.fast_forward
and options
.checkpoint_restore
!= None:
442 fatal("Can't specify both --fast-forward and --checkpoint-restore")
444 if options
.standard_switch
and not options
.caches
:
445 fatal("Must specify --caches when using --standard-switch")
447 if options
.standard_switch
and options
.repeat_switch
:
448 fatal("Can't specify both --standard-switch and --repeat-switch")
450 if options
.repeat_switch
and options
.take_checkpoints
:
451 fatal("Can't specify both --repeat-switch and --take-checkpoints")
453 np
= options
.num_cpus
456 if options
.prog_interval
:
458 testsys
.cpu
[i
].progress_interval
= options
.prog_interval
462 testsys
.cpu
[i
].max_insts_any_thread
= options
.maxinsts
465 switch_cpus
= [cpu_class(switched_out
=True, cpu_id
=(i
))
469 if options
.fast_forward
:
470 testsys
.cpu
[i
].max_insts_any_thread
= int(options
.fast_forward
)
471 switch_cpus
[i
].system
= testsys
472 switch_cpus
[i
].workload
= testsys
.cpu
[i
].workload
473 switch_cpus
[i
].clk_domain
= testsys
.cpu
[i
].clk_domain
474 switch_cpus
[i
].progress_interval
= \
475 testsys
.cpu
[i
].progress_interval
476 switch_cpus
[i
].isa
= testsys
.cpu
[i
].isa
479 switch_cpus
[i
].max_insts_any_thread
= options
.maxinsts
480 # Add checker cpu if selected
482 switch_cpus
[i
].addCheckerCpu()
484 bpClass
= BPConfig
.get(options
.bp_type
)
485 switch_cpus
[i
].branchPred
= bpClass()
487 # If elastic tracing is enabled attach the elastic trace probe
489 if options
.elastic_trace_en
:
490 CpuConfig
.config_etrace(cpu_class
, switch_cpus
, options
)
492 testsys
.switch_cpus
= switch_cpus
493 switch_cpu_list
= [(testsys
.cpu
[i
], switch_cpus
[i
]) for i
in range(np
)]
495 if options
.repeat_switch
:
496 switch_class
= getCPUClass(options
.cpu_type
)[0]
497 if switch_class
.require_caches() and \
499 print("%s: Must be used with caches" % str(switch_class
))
501 if not switch_class
.support_take_over():
502 print("%s: CPU switching not supported" % str(switch_class
))
505 repeat_switch_cpus
= [switch_class(switched_out
=True, \
506 cpu_id
=(i
)) for i
in range(np
)]
509 repeat_switch_cpus
[i
].system
= testsys
510 repeat_switch_cpus
[i
].workload
= testsys
.cpu
[i
].workload
511 repeat_switch_cpus
[i
].clk_domain
= testsys
.cpu
[i
].clk_domain
512 repeat_switch_cpus
[i
].isa
= testsys
.cpu
[i
].isa
515 repeat_switch_cpus
[i
].max_insts_any_thread
= options
.maxinsts
518 repeat_switch_cpus
[i
].addCheckerCpu()
520 testsys
.repeat_switch_cpus
= repeat_switch_cpus
523 repeat_switch_cpu_list
= [(switch_cpus
[i
], repeat_switch_cpus
[i
])
526 repeat_switch_cpu_list
= [(testsys
.cpu
[i
], repeat_switch_cpus
[i
])
529 if options
.standard_switch
:
530 switch_cpus
= [TimingSimpleCPU(switched_out
=True, cpu_id
=(i
))
532 switch_cpus_1
= [DerivO3CPU(switched_out
=True, cpu_id
=(i
))
536 switch_cpus
[i
].system
= testsys
537 switch_cpus_1
[i
].system
= testsys
538 switch_cpus
[i
].workload
= testsys
.cpu
[i
].workload
539 switch_cpus_1
[i
].workload
= testsys
.cpu
[i
].workload
540 switch_cpus
[i
].clk_domain
= testsys
.cpu
[i
].clk_domain
541 switch_cpus_1
[i
].clk_domain
= testsys
.cpu
[i
].clk_domain
542 switch_cpus
[i
].isa
= testsys
.cpu
[i
].isa
543 switch_cpus_1
[i
].isa
= testsys
.cpu
[i
].isa
545 # if restoring, make atomic cpu simulate only a few instructions
546 if options
.checkpoint_restore
!= None:
547 testsys
.cpu
[i
].max_insts_any_thread
= 1
548 # Fast forward to specified location if we are not restoring
549 elif options
.fast_forward
:
550 testsys
.cpu
[i
].max_insts_any_thread
= int(options
.fast_forward
)
551 # Fast forward to a simpoint (warning: time consuming)
552 elif options
.simpoint
:
553 if testsys
.cpu
[i
].workload
[0].simpoint
== 0:
554 fatal('simpoint not found')
555 testsys
.cpu
[i
].max_insts_any_thread
= \
556 testsys
.cpu
[i
].workload
[0].simpoint
557 # No distance specified, just switch
559 testsys
.cpu
[i
].max_insts_any_thread
= 1
562 if options
.warmup_insts
:
563 switch_cpus
[i
].max_insts_any_thread
= options
.warmup_insts
567 switch_cpus_1
[i
].max_insts_any_thread
= options
.maxinsts
569 # attach the checker cpu if selected
571 switch_cpus
[i
].addCheckerCpu()
572 switch_cpus_1
[i
].addCheckerCpu()
574 testsys
.switch_cpus
= switch_cpus
575 testsys
.switch_cpus_1
= switch_cpus_1
577 (testsys
.cpu
[i
], switch_cpus
[i
]) for i
in range(np
)
580 (switch_cpus
[i
], switch_cpus_1
[i
]) for i
in range(np
)
583 # set the checkpoint in the cpu before m5.instantiate is called
584 if options
.take_checkpoints
!= None and \
585 (options
.simpoint
or options
.at_instruction
):
586 offset
= int(options
.take_checkpoints
)
587 # Set an instruction break point
590 if testsys
.cpu
[i
].workload
[0].simpoint
== 0:
591 fatal('no simpoint for testsys.cpu[%d].workload[0]', i
)
592 checkpoint_inst
= int(testsys
.cpu
[i
].workload
[0].simpoint
) + offset
593 testsys
.cpu
[i
].max_insts_any_thread
= checkpoint_inst
594 # used for output below
595 options
.take_checkpoints
= checkpoint_inst
597 options
.take_checkpoints
= offset
598 # Set all test cpus with the right number of instructions
599 # for the upcoming simulation
601 testsys
.cpu
[i
].max_insts_any_thread
= offset
603 if options
.take_simpoint_checkpoints
!= None:
604 simpoints
, interval_length
= parseSimpointAnalysisFile(options
, testsys
)
606 checkpoint_dir
= None
607 if options
.checkpoint_restore
:
608 cpt_starttick
, checkpoint_dir
= findCptDir(options
, cptdir
, testsys
)
609 root
.apply_config(options
.param
)
610 m5
.instantiate(checkpoint_dir
)
612 # Initialization is complete. If we're not in control of simulation
613 # (that is, if we're a slave simulator acting as a component in another
614 # 'master' simulator) then we're done here. The other simulator will
615 # call simulate() directly. --initialize-only is used to indicate this.
616 if options
.initialize_only
:
619 # Handle the max tick settings now that tick frequency was resolved
620 # during system instantiation
621 # NOTE: the maxtick variable here is in absolute ticks, so it must
622 # include any simulated ticks before a checkpoint
623 explicit_maxticks
= 0
624 maxtick_from_abs
= m5
.MaxTick
625 maxtick_from_rel
= m5
.MaxTick
626 maxtick_from_maxtime
= m5
.MaxTick
627 if options
.abs_max_tick
:
628 maxtick_from_abs
= options
.abs_max_tick
629 explicit_maxticks
+= 1
630 if options
.rel_max_tick
:
631 maxtick_from_rel
= options
.rel_max_tick
632 if options
.checkpoint_restore
:
633 # NOTE: this may need to be updated if checkpoints ever store
634 # the ticks per simulated second
635 maxtick_from_rel
+= cpt_starttick
636 if options
.at_instruction
or options
.simpoint
:
637 warn("Relative max tick specified with --at-instruction or" \
638 " --simpoint\n These options don't specify the " \
639 "checkpoint start tick, so assuming\n you mean " \
641 explicit_maxticks
+= 1
643 maxtick_from_maxtime
= m5
.ticks
.fromSeconds(options
.maxtime
)
644 explicit_maxticks
+= 1
645 if explicit_maxticks
> 1:
646 warn("Specified multiple of --abs-max-tick, --rel-max-tick, --maxtime."\
648 maxtick
= min([maxtick_from_abs
, maxtick_from_rel
, maxtick_from_maxtime
])
650 if options
.checkpoint_restore
!= None and maxtick
< cpt_starttick
:
651 fatal("Bad maxtick (%d) specified: " \
652 "Checkpoint starts starts from tick: %d", maxtick
, cpt_starttick
)
654 if options
.standard_switch
or cpu_class
:
655 if options
.standard_switch
:
656 print("Switch at instruction count:%s" %
657 str(testsys
.cpu
[0].max_insts_any_thread
))
658 exit_event
= m5
.simulate()
659 elif cpu_class
and options
.fast_forward
:
660 print("Switch at instruction count:%s" %
661 str(testsys
.cpu
[0].max_insts_any_thread
))
662 exit_event
= m5
.simulate()
664 print("Switch at curTick count:%s" % str(10000))
665 exit_event
= m5
.simulate(10000)
666 print("Switched CPUS @ tick %s" % (m5
.curTick()))
668 m5
.switchCpus(testsys
, switch_cpu_list
)
670 if options
.standard_switch
:
671 print("Switch at instruction count:%d" %
672 (testsys
.switch_cpus
[0].max_insts_any_thread
))
674 #warmup instruction count may have already been set
675 if options
.warmup_insts
:
676 exit_event
= m5
.simulate()
678 exit_event
= m5
.simulate(options
.standard_switch
)
679 print("Switching CPUS @ tick %s" % (m5
.curTick()))
680 print("Simulation ends instruction count:%d" %
681 (testsys
.switch_cpus_1
[0].max_insts_any_thread
))
682 m5
.switchCpus(testsys
, switch_cpu_list1
)
684 # If we're taking and restoring checkpoints, use checkpoint_dir
685 # option only for finding the checkpoints to restore from. This
686 # lets us test checkpointing by restoring from one set of
687 # checkpoints, generating a second set, and then comparing them.
688 if (options
.take_checkpoints
or options
.take_simpoint_checkpoints
) \
689 and options
.checkpoint_restore
:
691 if m5
.options
.outdir
:
692 cptdir
= m5
.options
.outdir
696 if options
.take_checkpoints
!= None :
697 # Checkpoints being taken via the command line at <when> and at
698 # subsequent periods of <period>. Checkpoint instructions
699 # received from the benchmark running are ignored and skipped in
700 # favor of command line checkpoint instructions.
701 exit_event
= scriptCheckpoints(options
, maxtick
, cptdir
)
703 # Take SimPoint checkpoints
704 elif options
.take_simpoint_checkpoints
!= None:
705 takeSimpointCheckpoints(simpoints
, interval_length
, cptdir
)
707 # Restore from SimPoint checkpoints
708 elif options
.restore_simpoint_checkpoint
!= None:
709 restoreSimpointCheckpoint()
712 if options
.fast_forward
:
714 print("**** REAL SIMULATION ****")
716 # If checkpoints are being taken, then the checkpoint instruction
717 # will occur in the benchmark code it self.
718 if options
.repeat_switch
and maxtick
> options
.repeat_switch
:
719 exit_event
= repeatSwitch(testsys
, repeat_switch_cpu_list
,
720 maxtick
, options
.repeat_switch
)
722 exit_event
= benchCheckpoints(options
, maxtick
, cptdir
)
724 print('Exiting @ tick %i because %s' %
725 (m5
.curTick(), exit_event
.getCause()))
726 if options
.checkpoint_at_end
:
727 m5
.checkpoint(joinpath(cptdir
, "cpt.%d"))
729 if exit_event
.getCode() != 0:
730 print("Simulated exit code not 0! Exit code is", exit_event
.getCode())