Simulation.py (12395:322bb93e5f06) Simulation.py (12564:2778478ca882)
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

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

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# Authors: Lisa Hsu
41
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

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

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# Authors: Lisa Hsu
41
42from __future__ import print_function
43
42import sys
43from os import getcwd
44from os.path import join as joinpath
45
46from common import CpuConfig
47from common import MemConfig
48
49import m5

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

165 checkpoint_dir = joinpath(cptdir, cpts[cpt_num - 1])
166 match = expr.match(cpts[cpt_num - 1])
167 if match:
168 index = int(match.group(1))
169 start_inst = int(match.group(2))
170 weight_inst = float(match.group(3))
171 interval_length = int(match.group(4))
172 warmup_length = int(match.group(5))
44import sys
45from os import getcwd
46from os.path import join as joinpath
47
48from common import CpuConfig
49from common import MemConfig
50
51import m5

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

167 checkpoint_dir = joinpath(cptdir, cpts[cpt_num - 1])
168 match = expr.match(cpts[cpt_num - 1])
169 if match:
170 index = int(match.group(1))
171 start_inst = int(match.group(2))
172 weight_inst = float(match.group(3))
173 interval_length = int(match.group(4))
174 warmup_length = int(match.group(5))
173 print "Resuming from", checkpoint_dir
175 print("Resuming from", checkpoint_dir)
174 simpoint_start_insts = []
175 simpoint_start_insts.append(warmup_length)
176 simpoint_start_insts.append(warmup_length + interval_length)
177 testsys.cpu[0].simpoint_start_insts = simpoint_start_insts
178 if testsys.switch_cpus != None:
179 testsys.switch_cpus[0].simpoint_start_insts = simpoint_start_insts
180
176 simpoint_start_insts = []
177 simpoint_start_insts.append(warmup_length)
178 simpoint_start_insts.append(warmup_length + interval_length)
179 testsys.cpu[0].simpoint_start_insts = simpoint_start_insts
180 if testsys.switch_cpus != None:
181 testsys.switch_cpus[0].simpoint_start_insts = simpoint_start_insts
182
181 print "Resuming from SimPoint",
182 print "#%d, start_inst:%d, weight:%f, interval:%d, warmup:%d" % \
183 (index, start_inst, weight_inst, interval_length, warmup_length)
183 print("Resuming from SimPoint", end=' ')
184 print("#%d, start_inst:%d, weight:%f, interval:%d, warmup:%d" %
185 (index, start_inst, weight_inst, interval_length, warmup_length))
184
185 else:
186 dirs = listdir(cptdir)
187 expr = re.compile('cpt\.([0-9]+)')
188 cpts = []
189 for dir in dirs:
190 match = expr.match(dir)
191 if match:

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

205def scriptCheckpoints(options, maxtick, cptdir):
206 if options.at_instruction or options.simpoint:
207 checkpoint_inst = int(options.take_checkpoints)
208
209 # maintain correct offset if we restored from some instruction
210 if options.checkpoint_restore != None:
211 checkpoint_inst += options.checkpoint_restore
212
186
187 else:
188 dirs = listdir(cptdir)
189 expr = re.compile('cpt\.([0-9]+)')
190 cpts = []
191 for dir in dirs:
192 match = expr.match(dir)
193 if match:

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

207def scriptCheckpoints(options, maxtick, cptdir):
208 if options.at_instruction or options.simpoint:
209 checkpoint_inst = int(options.take_checkpoints)
210
211 # maintain correct offset if we restored from some instruction
212 if options.checkpoint_restore != None:
213 checkpoint_inst += options.checkpoint_restore
214
213 print "Creating checkpoint at inst:%d" % (checkpoint_inst)
215 print("Creating checkpoint at inst:%d" % (checkpoint_inst))
214 exit_event = m5.simulate()
215 exit_cause = exit_event.getCause()
216 exit_event = m5.simulate()
217 exit_cause = exit_event.getCause()
216 print "exit cause = %s" % exit_cause
218 print("exit cause = %s" % exit_cause)
217
218 # skip checkpoint instructions should they exist
219 while exit_cause == "checkpoint":
220 exit_event = m5.simulate()
221 exit_cause = exit_event.getCause()
222
223 if exit_cause == "a thread reached the max instruction count":
224 m5.checkpoint(joinpath(cptdir, "cpt.%s.%d" % \
225 (options.bench, checkpoint_inst)))
219
220 # skip checkpoint instructions should they exist
221 while exit_cause == "checkpoint":
222 exit_event = m5.simulate()
223 exit_cause = exit_event.getCause()
224
225 if exit_cause == "a thread reached the max instruction count":
226 m5.checkpoint(joinpath(cptdir, "cpt.%s.%d" % \
227 (options.bench, checkpoint_inst)))
226 print "Checkpoint written."
228 print("Checkpoint written.")
227
228 else:
229 when, period = options.take_checkpoints.split(",", 1)
230 when = int(when)
231 period = int(period)
232 num_checkpoints = 0
233
234 exit_event = m5.simulate(when - m5.curTick())

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

283
284# Set up environment for taking SimPoint checkpoints
285# Expecting SimPoint files generated by SimPoint 3.2
286def parseSimpointAnalysisFile(options, testsys):
287 import re
288
289 simpoint_filename, weight_filename, interval_length, warmup_length = \
290 options.take_simpoint_checkpoints.split(",", 3)
229
230 else:
231 when, period = options.take_checkpoints.split(",", 1)
232 when = int(when)
233 period = int(period)
234 num_checkpoints = 0
235
236 exit_event = m5.simulate(when - m5.curTick())

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

285
286# Set up environment for taking SimPoint checkpoints
287# Expecting SimPoint files generated by SimPoint 3.2
288def parseSimpointAnalysisFile(options, testsys):
289 import re
290
291 simpoint_filename, weight_filename, interval_length, warmup_length = \
292 options.take_simpoint_checkpoints.split(",", 3)
291 print "simpoint analysis file:", simpoint_filename
292 print "simpoint weight file:", weight_filename
293 print "interval length:", interval_length
294 print "warmup length:", warmup_length
293 print("simpoint analysis file:", simpoint_filename)
294 print("simpoint weight file:", weight_filename)
295 print("interval length:", interval_length)
296 print("warmup length:", warmup_length)
295
296 interval_length = int(interval_length)
297 warmup_length = int(warmup_length)
298
299 # Simpoint analysis output starts interval counts with 0.
300 simpoints = []
301 simpoint_start_insts = []
302

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

334
335 simpoints.append((interval, weight, starting_inst_count,
336 actual_warmup_length))
337
338 # Sort SimPoints by starting inst count
339 simpoints.sort(key=lambda obj: obj[2])
340 for s in simpoints:
341 interval, weight, starting_inst_count, actual_warmup_length = s
297
298 interval_length = int(interval_length)
299 warmup_length = int(warmup_length)
300
301 # Simpoint analysis output starts interval counts with 0.
302 simpoints = []
303 simpoint_start_insts = []
304

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

336
337 simpoints.append((interval, weight, starting_inst_count,
338 actual_warmup_length))
339
340 # Sort SimPoints by starting inst count
341 simpoints.sort(key=lambda obj: obj[2])
342 for s in simpoints:
343 interval, weight, starting_inst_count, actual_warmup_length = s
342 print str(interval), str(weight), starting_inst_count, \
343 actual_warmup_length
344 print(str(interval), str(weight), starting_inst_count,
345 actual_warmup_length)
344 simpoint_start_insts.append(starting_inst_count)
345
346 simpoint_start_insts.append(starting_inst_count)
347
346 print "Total # of simpoints:", len(simpoints)
348 print("Total # of simpoints:", len(simpoints))
347 testsys.cpu[0].simpoint_start_insts = simpoint_start_insts
348
349 return (simpoints, interval_length)
350
351def takeSimpointCheckpoints(simpoints, interval_length, cptdir):
352 num_checkpoints = 0
353 index = 0
354 last_chkpnt_inst_count = -1

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

359 # (when warmup period longer than starting point)
360 exit_cause = "simpoint starting point found"
361 code = 0
362 else:
363 exit_event = m5.simulate()
364
365 # skip checkpoint instructions should they exist
366 while exit_event.getCause() == "checkpoint":
349 testsys.cpu[0].simpoint_start_insts = simpoint_start_insts
350
351 return (simpoints, interval_length)
352
353def takeSimpointCheckpoints(simpoints, interval_length, cptdir):
354 num_checkpoints = 0
355 index = 0
356 last_chkpnt_inst_count = -1

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

361 # (when warmup period longer than starting point)
362 exit_cause = "simpoint starting point found"
363 code = 0
364 else:
365 exit_event = m5.simulate()
366
367 # skip checkpoint instructions should they exist
368 while exit_event.getCause() == "checkpoint":
367 print "Found 'checkpoint' exit event...ignoring..."
369 print("Found 'checkpoint' exit event...ignoring...")
368 exit_event = m5.simulate()
369
370 exit_cause = exit_event.getCause()
371 code = exit_event.getCode()
372
373 if exit_cause == "simpoint starting point found":
374 m5.checkpoint(joinpath(cptdir,
375 "cpt.simpoint_%02d_inst_%d_weight_%f_interval_%d_warmup_%d"
376 % (index, starting_inst_count, weight, interval_length,
377 actual_warmup_length)))
370 exit_event = m5.simulate()
371
372 exit_cause = exit_event.getCause()
373 code = exit_event.getCode()
374
375 if exit_cause == "simpoint starting point found":
376 m5.checkpoint(joinpath(cptdir,
377 "cpt.simpoint_%02d_inst_%d_weight_%f_interval_%d_warmup_%d"
378 % (index, starting_inst_count, weight, interval_length,
379 actual_warmup_length)))
378 print "Checkpoint #%d written. start inst:%d weight:%f" % \
379 (num_checkpoints, starting_inst_count, weight)
380 print("Checkpoint #%d written. start inst:%d weight:%f" %
381 (num_checkpoints, starting_inst_count, weight))
380 num_checkpoints += 1
381 last_chkpnt_inst_count = starting_inst_count
382 else:
383 break
384 index += 1
385
382 num_checkpoints += 1
383 last_chkpnt_inst_count = starting_inst_count
384 else:
385 break
386 index += 1
387
386 print 'Exiting @ tick %i because %s' % (m5.curTick(), exit_cause)
387 print "%d checkpoints taken" % num_checkpoints
388 print('Exiting @ tick %i because %s' % (m5.curTick(), exit_cause))
389 print("%d checkpoints taken" % num_checkpoints)
388 sys.exit(code)
389
390def restoreSimpointCheckpoint():
391 exit_event = m5.simulate()
392 exit_cause = exit_event.getCause()
393
394 if exit_cause == "simpoint starting point found":
390 sys.exit(code)
391
392def restoreSimpointCheckpoint():
393 exit_event = m5.simulate()
394 exit_cause = exit_event.getCause()
395
396 if exit_cause == "simpoint starting point found":
395 print "Warmed up! Dumping and resetting stats!"
397 print("Warmed up! Dumping and resetting stats!")
396 m5.stats.dump()
397 m5.stats.reset()
398
399 exit_event = m5.simulate()
400 exit_cause = exit_event.getCause()
401
402 if exit_cause == "simpoint starting point found":
398 m5.stats.dump()
399 m5.stats.reset()
400
401 exit_event = m5.simulate()
402 exit_cause = exit_event.getCause()
403
404 if exit_cause == "simpoint starting point found":
403 print "Done running SimPoint!"
405 print("Done running SimPoint!")
404 sys.exit(exit_event.getCode())
405
406 sys.exit(exit_event.getCode())
407
406 print 'Exiting @ tick %i because %s' % (m5.curTick(), exit_cause)
408 print('Exiting @ tick %i because %s' % (m5.curTick(), exit_cause))
407 sys.exit(exit_event.getCode())
408
409def repeatSwitch(testsys, repeat_switch_cpu_list, maxtick, switch_freq):
409 sys.exit(exit_event.getCode())
410
411def repeatSwitch(testsys, repeat_switch_cpu_list, maxtick, switch_freq):
410 print "starting switch loop"
412 print("starting switch loop")
411 while True:
412 exit_event = m5.simulate(switch_freq)
413 exit_cause = exit_event.getCause()
414
415 if exit_cause != "simulate() limit reached":
416 return exit_event
417
418 m5.switchCpus(testsys, repeat_switch_cpu_list)

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

484
485 testsys.switch_cpus = switch_cpus
486 switch_cpu_list = [(testsys.cpu[i], switch_cpus[i]) for i in xrange(np)]
487
488 if options.repeat_switch:
489 switch_class = getCPUClass(options.cpu_type)[0]
490 if switch_class.require_caches() and \
491 not options.caches:
413 while True:
414 exit_event = m5.simulate(switch_freq)
415 exit_cause = exit_event.getCause()
416
417 if exit_cause != "simulate() limit reached":
418 return exit_event
419
420 m5.switchCpus(testsys, repeat_switch_cpu_list)

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

486
487 testsys.switch_cpus = switch_cpus
488 switch_cpu_list = [(testsys.cpu[i], switch_cpus[i]) for i in xrange(np)]
489
490 if options.repeat_switch:
491 switch_class = getCPUClass(options.cpu_type)[0]
492 if switch_class.require_caches() and \
493 not options.caches:
492 print "%s: Must be used with caches" % str(switch_class)
494 print("%s: Must be used with caches" % str(switch_class))
493 sys.exit(1)
494 if not switch_class.support_take_over():
495 sys.exit(1)
496 if not switch_class.support_take_over():
495 print "%s: CPU switching not supported" % str(switch_class)
497 print("%s: CPU switching not supported" % str(switch_class))
496 sys.exit(1)
497
498 repeat_switch_cpus = [switch_class(switched_out=True, \
499 cpu_id=(i)) for i in xrange(np)]
500
501 for i in xrange(np):
502 repeat_switch_cpus[i].system = testsys
503 repeat_switch_cpus[i].workload = testsys.cpu[i].workload

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

636 maxtick = min([maxtick_from_abs, maxtick_from_rel, maxtick_from_maxtime])
637
638 if options.checkpoint_restore != None and maxtick < cpt_starttick:
639 fatal("Bad maxtick (%d) specified: " \
640 "Checkpoint starts starts from tick: %d", maxtick, cpt_starttick)
641
642 if options.standard_switch or cpu_class:
643 if options.standard_switch:
498 sys.exit(1)
499
500 repeat_switch_cpus = [switch_class(switched_out=True, \
501 cpu_id=(i)) for i in xrange(np)]
502
503 for i in xrange(np):
504 repeat_switch_cpus[i].system = testsys
505 repeat_switch_cpus[i].workload = testsys.cpu[i].workload

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

638 maxtick = min([maxtick_from_abs, maxtick_from_rel, maxtick_from_maxtime])
639
640 if options.checkpoint_restore != None and maxtick < cpt_starttick:
641 fatal("Bad maxtick (%d) specified: " \
642 "Checkpoint starts starts from tick: %d", maxtick, cpt_starttick)
643
644 if options.standard_switch or cpu_class:
645 if options.standard_switch:
644 print "Switch at instruction count:%s" % \
645 str(testsys.cpu[0].max_insts_any_thread)
646 print("Switch at instruction count:%s" %
647 str(testsys.cpu[0].max_insts_any_thread))
646 exit_event = m5.simulate()
647 elif cpu_class and options.fast_forward:
648 exit_event = m5.simulate()
649 elif cpu_class and options.fast_forward:
648 print "Switch at instruction count:%s" % \
649 str(testsys.cpu[0].max_insts_any_thread)
650 print("Switch at instruction count:%s" %
651 str(testsys.cpu[0].max_insts_any_thread))
650 exit_event = m5.simulate()
651 else:
652 exit_event = m5.simulate()
653 else:
652 print "Switch at curTick count:%s" % str(10000)
654 print("Switch at curTick count:%s" % str(10000))
653 exit_event = m5.simulate(10000)
655 exit_event = m5.simulate(10000)
654 print "Switched CPUS @ tick %s" % (m5.curTick())
656 print("Switched CPUS @ tick %s" % (m5.curTick()))
655
656 m5.switchCpus(testsys, switch_cpu_list)
657
658 if options.standard_switch:
657
658 m5.switchCpus(testsys, switch_cpu_list)
659
660 if options.standard_switch:
659 print "Switch at instruction count:%d" % \
660 (testsys.switch_cpus[0].max_insts_any_thread)
661 print("Switch at instruction count:%d" %
662 (testsys.switch_cpus[0].max_insts_any_thread))
661
662 #warmup instruction count may have already been set
663 if options.warmup_insts:
664 exit_event = m5.simulate()
665 else:
666 exit_event = m5.simulate(options.standard_switch)
663
664 #warmup instruction count may have already been set
665 if options.warmup_insts:
666 exit_event = m5.simulate()
667 else:
668 exit_event = m5.simulate(options.standard_switch)
667 print "Switching CPUS @ tick %s" % (m5.curTick())
668 print "Simulation ends instruction count:%d" % \
669 (testsys.switch_cpus_1[0].max_insts_any_thread)
669 print("Switching CPUS @ tick %s" % (m5.curTick()))
670 print("Simulation ends instruction count:%d" %
671 (testsys.switch_cpus_1[0].max_insts_any_thread))
670 m5.switchCpus(testsys, switch_cpu_list1)
671
672 # If we're taking and restoring checkpoints, use checkpoint_dir
673 # option only for finding the checkpoints to restore from. This
674 # lets us test checkpointing by restoring from one set of
675 # checkpoints, generating a second set, and then comparing them.
676 if (options.take_checkpoints or options.take_simpoint_checkpoints) \
677 and options.checkpoint_restore:

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

694
695 # Restore from SimPoint checkpoints
696 elif options.restore_simpoint_checkpoint != None:
697 restoreSimpointCheckpoint()
698
699 else:
700 if options.fast_forward:
701 m5.stats.reset()
672 m5.switchCpus(testsys, switch_cpu_list1)
673
674 # If we're taking and restoring checkpoints, use checkpoint_dir
675 # option only for finding the checkpoints to restore from. This
676 # lets us test checkpointing by restoring from one set of
677 # checkpoints, generating a second set, and then comparing them.
678 if (options.take_checkpoints or options.take_simpoint_checkpoints) \
679 and options.checkpoint_restore:

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

696
697 # Restore from SimPoint checkpoints
698 elif options.restore_simpoint_checkpoint != None:
699 restoreSimpointCheckpoint()
700
701 else:
702 if options.fast_forward:
703 m5.stats.reset()
702 print "**** REAL SIMULATION ****"
704 print("**** REAL SIMULATION ****")
703
704 # If checkpoints are being taken, then the checkpoint instruction
705 # will occur in the benchmark code it self.
706 if options.repeat_switch and maxtick > options.repeat_switch:
707 exit_event = repeatSwitch(testsys, repeat_switch_cpu_list,
708 maxtick, options.repeat_switch)
709 else:
710 exit_event = benchCheckpoints(options, maxtick, cptdir)
711
705
706 # If checkpoints are being taken, then the checkpoint instruction
707 # will occur in the benchmark code it self.
708 if options.repeat_switch and maxtick > options.repeat_switch:
709 exit_event = repeatSwitch(testsys, repeat_switch_cpu_list,
710 maxtick, options.repeat_switch)
711 else:
712 exit_event = benchCheckpoints(options, maxtick, cptdir)
713
712 print 'Exiting @ tick %i because %s' % (m5.curTick(), exit_event.getCause())
714 print('Exiting @ tick %i because %s' %
715 (m5.curTick(), exit_event.getCause()))
713 if options.checkpoint_at_end:
714 m5.checkpoint(joinpath(cptdir, "cpt.%d"))
715
716 if not m5.options.interactive:
717 sys.exit(exit_event.getCode())
716 if options.checkpoint_at_end:
717 m5.checkpoint(joinpath(cptdir, "cpt.%d"))
718
719 if not m5.options.interactive:
720 sys.exit(exit_event.getCode())