Simulation.py revision 10608:427f988fe6e5
17322Sgblack@eecs.umich.edu# Copyright (c) 2012-2013 ARM Limited 27322Sgblack@eecs.umich.edu# All rights reserved 37322Sgblack@eecs.umich.edu# 47322Sgblack@eecs.umich.edu# The license below extends only to copyright in the software and shall 57322Sgblack@eecs.umich.edu# not be construed as granting a license to any other intellectual 67322Sgblack@eecs.umich.edu# property including but not limited to intellectual property relating 77322Sgblack@eecs.umich.edu# to a hardware implementation of the functionality of the software 87322Sgblack@eecs.umich.edu# licensed hereunder. You may use the software subject to the license 97322Sgblack@eecs.umich.edu# terms below provided that you ensure that this notice is replicated 107322Sgblack@eecs.umich.edu# unmodified and in its entirety in all distributions of the software, 117322Sgblack@eecs.umich.edu# modified or unmodified, in source code or in binary form. 127322Sgblack@eecs.umich.edu# 137322Sgblack@eecs.umich.edu# Copyright (c) 2006-2008 The Regents of The University of Michigan 147322Sgblack@eecs.umich.edu# Copyright (c) 2010 Advanced Micro Devices, Inc. 157322Sgblack@eecs.umich.edu# All rights reserved. 167322Sgblack@eecs.umich.edu# 177322Sgblack@eecs.umich.edu# Redistribution and use in source and binary forms, with or without 187322Sgblack@eecs.umich.edu# modification, are permitted provided that the following conditions are 197322Sgblack@eecs.umich.edu# met: redistributions of source code must retain the above copyright 207322Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer; 217322Sgblack@eecs.umich.edu# redistributions in binary form must reproduce the above copyright 227322Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the 237322Sgblack@eecs.umich.edu# documentation and/or other materials provided with the distribution; 247322Sgblack@eecs.umich.edu# neither the name of the copyright holders nor the names of its 257322Sgblack@eecs.umich.edu# contributors may be used to endorse or promote products derived from 267322Sgblack@eecs.umich.edu# this software without specific prior written permission. 277322Sgblack@eecs.umich.edu# 287322Sgblack@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 297322Sgblack@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 307322Sgblack@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 317322Sgblack@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 327322Sgblack@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 337322Sgblack@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 347322Sgblack@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 357322Sgblack@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 367322Sgblack@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 377322Sgblack@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 387322Sgblack@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 397322Sgblack@eecs.umich.edu# 407376Sgblack@eecs.umich.edu# Authors: Lisa Hsu 417376Sgblack@eecs.umich.edu 427376Sgblack@eecs.umich.eduimport sys 437376Sgblack@eecs.umich.edufrom os import getcwd 447376Sgblack@eecs.umich.edufrom os.path import join as joinpath 457376Sgblack@eecs.umich.edu 467376Sgblack@eecs.umich.eduimport CpuConfig 477376Sgblack@eecs.umich.eduimport MemConfig 487376Sgblack@eecs.umich.edu 497376Sgblack@eecs.umich.eduimport m5 507376Sgblack@eecs.umich.edufrom m5.defines import buildEnv 517376Sgblack@eecs.umich.edufrom m5.objects import * 527376Sgblack@eecs.umich.edufrom m5.util import * 537376Sgblack@eecs.umich.edu 547376Sgblack@eecs.umich.eduaddToPath('../common') 557376Sgblack@eecs.umich.edu 567376Sgblack@eecs.umich.edudef getCPUClass(cpu_type): 577376Sgblack@eecs.umich.edu """Returns the required cpu class and the mode of operation.""" 587376Sgblack@eecs.umich.edu cls = CpuConfig.get(cpu_type) 597376Sgblack@eecs.umich.edu return cls, cls.memory_mode() 607376Sgblack@eecs.umich.edu 617376Sgblack@eecs.umich.edudef setCPUClass(options): 627376Sgblack@eecs.umich.edu """Returns two cpu classes and the initial mode of operation. 637376Sgblack@eecs.umich.edu 647376Sgblack@eecs.umich.edu Restoring from a checkpoint or fast forwarding through a benchmark 657376Sgblack@eecs.umich.edu can be done using one type of cpu, and then the actual 667376Sgblack@eecs.umich.edu simulation can be carried out using another type. This function 677376Sgblack@eecs.umich.edu returns these two types of cpus and the initial mode of operation 687376Sgblack@eecs.umich.edu depending on the options provided. 697376Sgblack@eecs.umich.edu """ 707376Sgblack@eecs.umich.edu 717376Sgblack@eecs.umich.edu TmpClass, test_mem_mode = getCPUClass(options.cpu_type) 727376Sgblack@eecs.umich.edu CPUClass = None 737376Sgblack@eecs.umich.edu if TmpClass.require_caches() and \ 747376Sgblack@eecs.umich.edu not options.caches and not options.ruby: 757376Sgblack@eecs.umich.edu fatal("%s must be used with caches" % options.cpu_type) 767376Sgblack@eecs.umich.edu 777376Sgblack@eecs.umich.edu if options.checkpoint_restore != None: 787376Sgblack@eecs.umich.edu if options.restore_with_cpu != options.cpu_type: 797376Sgblack@eecs.umich.edu CPUClass = TmpClass 807376Sgblack@eecs.umich.edu TmpClass, test_mem_mode = getCPUClass(options.restore_with_cpu) 817376Sgblack@eecs.umich.edu elif options.fast_forward: 827376Sgblack@eecs.umich.edu CPUClass = TmpClass 837376Sgblack@eecs.umich.edu TmpClass = AtomicSimpleCPU 847376Sgblack@eecs.umich.edu test_mem_mode = 'atomic' 857376Sgblack@eecs.umich.edu 867376Sgblack@eecs.umich.edu return (TmpClass, test_mem_mode, CPUClass) 877376Sgblack@eecs.umich.edu 887376Sgblack@eecs.umich.edudef setMemClass(options): 897376Sgblack@eecs.umich.edu """Returns a memory controller class.""" 907376Sgblack@eecs.umich.edu 917376Sgblack@eecs.umich.edu return MemConfig.get(options.mem_type) 927376Sgblack@eecs.umich.edu 937376Sgblack@eecs.umich.edudef setWorkCountOptions(system, options): 947376Sgblack@eecs.umich.edu if options.work_item_id != None: 957376Sgblack@eecs.umich.edu system.work_item_id = options.work_item_id 967376Sgblack@eecs.umich.edu if options.num_work_ids != None: 977376Sgblack@eecs.umich.edu system.num_work_ids = options.num_work_ids 987376Sgblack@eecs.umich.edu if options.work_begin_cpu_id_exit != None: 997376Sgblack@eecs.umich.edu system.work_begin_cpu_id_exit = options.work_begin_cpu_id_exit 1007376Sgblack@eecs.umich.edu if options.work_end_exit_count != None: 1017376Sgblack@eecs.umich.edu system.work_end_exit_count = options.work_end_exit_count 1027376Sgblack@eecs.umich.edu if options.work_end_checkpoint_count != None: 1037376Sgblack@eecs.umich.edu system.work_end_ckpt_count = options.work_end_checkpoint_count 1047376Sgblack@eecs.umich.edu if options.work_begin_exit_count != None: 1057376Sgblack@eecs.umich.edu system.work_begin_exit_count = options.work_begin_exit_count 1067376Sgblack@eecs.umich.edu if options.work_begin_checkpoint_count != None: 1077376Sgblack@eecs.umich.edu system.work_begin_ckpt_count = options.work_begin_checkpoint_count 1087376Sgblack@eecs.umich.edu if options.work_cpus_checkpoint_count != None: 1097376Sgblack@eecs.umich.edu system.work_cpus_ckpt_count = options.work_cpus_checkpoint_count 1107376Sgblack@eecs.umich.edu 1117376Sgblack@eecs.umich.edudef findCptDir(options, cptdir, testsys): 1127376Sgblack@eecs.umich.edu """Figures out the directory from which the checkpointed state is read. 1137376Sgblack@eecs.umich.edu 1147376Sgblack@eecs.umich.edu There are two different ways in which the directories holding checkpoints 1157376Sgblack@eecs.umich.edu can be named -- 1167376Sgblack@eecs.umich.edu 1. cpt.<benchmark name>.<instruction count when the checkpoint was taken> 1177376Sgblack@eecs.umich.edu 2. cpt.<some number, usually the tick value when the checkpoint was taken> 1187376Sgblack@eecs.umich.edu 1197376Sgblack@eecs.umich.edu This function parses through the options to figure out which one of the 1207376Sgblack@eecs.umich.edu above should be used for selecting the checkpoint, and then figures out 1217376Sgblack@eecs.umich.edu the appropriate directory. 1227376Sgblack@eecs.umich.edu """ 1237376Sgblack@eecs.umich.edu 1247376Sgblack@eecs.umich.edu from os.path import isdir, exists 1257376Sgblack@eecs.umich.edu from os import listdir 1267376Sgblack@eecs.umich.edu import re 1277376Sgblack@eecs.umich.edu 1287376Sgblack@eecs.umich.edu if not isdir(cptdir): 1297376Sgblack@eecs.umich.edu fatal("checkpoint dir %s does not exist!", cptdir) 1307376Sgblack@eecs.umich.edu 1317376Sgblack@eecs.umich.edu cpt_starttick = 0 1327376Sgblack@eecs.umich.edu if options.at_instruction or options.simpoint: 1337376Sgblack@eecs.umich.edu inst = options.checkpoint_restore 1347376Sgblack@eecs.umich.edu if options.simpoint: 1357376Sgblack@eecs.umich.edu # assume workload 0 has the simpoint 1367376Sgblack@eecs.umich.edu if testsys.cpu[0].workload[0].simpoint == 0: 1377376Sgblack@eecs.umich.edu fatal('Unable to find simpoint') 1387376Sgblack@eecs.umich.edu inst += int(testsys.cpu[0].workload[0].simpoint) 1397376Sgblack@eecs.umich.edu 1407376Sgblack@eecs.umich.edu checkpoint_dir = joinpath(cptdir, "cpt.%s.%s" % (options.bench, inst)) 1417376Sgblack@eecs.umich.edu if not exists(checkpoint_dir): 1427376Sgblack@eecs.umich.edu fatal("Unable to find checkpoint directory %s", checkpoint_dir) 1437376Sgblack@eecs.umich.edu 1447376Sgblack@eecs.umich.edu elif options.restore_simpoint_checkpoint: 1457376Sgblack@eecs.umich.edu # Restore from SimPoint checkpoints 1467376Sgblack@eecs.umich.edu # Assumes that the checkpoint dir names are formatted as follows: 1477376Sgblack@eecs.umich.edu dirs = listdir(cptdir) 1487376Sgblack@eecs.umich.edu expr = re.compile('cpt\.simpoint_(\d+)_inst_(\d+)' + 1497376Sgblack@eecs.umich.edu '_weight_([\d\.e\-]+)_interval_(\d+)_warmup_(\d+)') 1507376Sgblack@eecs.umich.edu cpts = [] 1517376Sgblack@eecs.umich.edu for dir in dirs: 1527376Sgblack@eecs.umich.edu match = expr.match(dir) 1537376Sgblack@eecs.umich.edu if match: 1547376Sgblack@eecs.umich.edu cpts.append(dir) 1557376Sgblack@eecs.umich.edu cpts.sort() 1567376Sgblack@eecs.umich.edu 1577376Sgblack@eecs.umich.edu cpt_num = options.checkpoint_restore 1587376Sgblack@eecs.umich.edu if cpt_num > len(cpts): 1597376Sgblack@eecs.umich.edu fatal('Checkpoint %d not found', cpt_num) 1607376Sgblack@eecs.umich.edu checkpoint_dir = joinpath(cptdir, cpts[cpt_num - 1]) 1617376Sgblack@eecs.umich.edu match = expr.match(cpts[cpt_num - 1]) 1627376Sgblack@eecs.umich.edu if match: 1637376Sgblack@eecs.umich.edu index = int(match.group(1)) 1647376Sgblack@eecs.umich.edu start_inst = int(match.group(2)) 1657376Sgblack@eecs.umich.edu weight_inst = float(match.group(3)) 1667376Sgblack@eecs.umich.edu interval_length = int(match.group(4)) 1677376Sgblack@eecs.umich.edu warmup_length = int(match.group(5)) 1687376Sgblack@eecs.umich.edu print "Resuming from", checkpoint_dir 1697376Sgblack@eecs.umich.edu simpoint_start_insts = [] 1707376Sgblack@eecs.umich.edu simpoint_start_insts.append(warmup_length) 1717376Sgblack@eecs.umich.edu simpoint_start_insts.append(warmup_length + interval_length) 1727376Sgblack@eecs.umich.edu testsys.cpu[0].simpoint_start_insts = simpoint_start_insts 1737376Sgblack@eecs.umich.edu if testsys.switch_cpus != None: 1747376Sgblack@eecs.umich.edu testsys.switch_cpus[0].simpoint_start_insts = simpoint_start_insts 1757376Sgblack@eecs.umich.edu 1767376Sgblack@eecs.umich.edu print "Resuming from SimPoint", 1777376Sgblack@eecs.umich.edu print "#%d, start_inst:%d, weight:%f, interval:%d, warmup:%d" % \ 1787376Sgblack@eecs.umich.edu (index, start_inst, weight_inst, interval_length, warmup_length) 1797376Sgblack@eecs.umich.edu 1807376Sgblack@eecs.umich.edu else: 1817376Sgblack@eecs.umich.edu dirs = listdir(cptdir) 1827376Sgblack@eecs.umich.edu expr = re.compile('cpt\.([0-9]+)') 1837376Sgblack@eecs.umich.edu cpts = [] 1847376Sgblack@eecs.umich.edu for dir in dirs: 1857376Sgblack@eecs.umich.edu match = expr.match(dir) 1867376Sgblack@eecs.umich.edu if match: 1877376Sgblack@eecs.umich.edu cpts.append(match.group(1)) 1887322Sgblack@eecs.umich.edu 1897322Sgblack@eecs.umich.edu cpts.sort(lambda a,b: cmp(long(a), long(b))) 1907322Sgblack@eecs.umich.edu 1917322Sgblack@eecs.umich.edu cpt_num = options.checkpoint_restore 1927322Sgblack@eecs.umich.edu if cpt_num > len(cpts): 1937322Sgblack@eecs.umich.edu fatal('Checkpoint %d not found', cpt_num) 1947375Sgblack@eecs.umich.edu 1957322Sgblack@eecs.umich.edu cpt_starttick = int(cpts[cpt_num - 1]) 1967322Sgblack@eecs.umich.edu checkpoint_dir = joinpath(cptdir, "cpt.%s" % cpts[cpt_num - 1]) 1977375Sgblack@eecs.umich.edu 1987375Sgblack@eecs.umich.edu return cpt_starttick, checkpoint_dir 1997322Sgblack@eecs.umich.edu 2007324Sgblack@eecs.umich.edudef scriptCheckpoints(options, maxtick, cptdir): 2017375Sgblack@eecs.umich.edu if options.at_instruction or options.simpoint: 2027324Sgblack@eecs.umich.edu checkpoint_inst = int(options.take_checkpoints) 2037324Sgblack@eecs.umich.edu 2047375Sgblack@eecs.umich.edu # maintain correct offset if we restored from some instruction 2057375Sgblack@eecs.umich.edu if options.checkpoint_restore != None: 2067324Sgblack@eecs.umich.edu checkpoint_inst += options.checkpoint_restore 2077333Sgblack@eecs.umich.edu 2087333Sgblack@eecs.umich.edu print "Creating checkpoint at inst:%d" % (checkpoint_inst) 2097333Sgblack@eecs.umich.edu exit_event = m5.simulate() 2107333Sgblack@eecs.umich.edu exit_cause = exit_event.getCause() 2117375Sgblack@eecs.umich.edu print "exit cause = %s" % exit_cause 2127333Sgblack@eecs.umich.edu 2137333Sgblack@eecs.umich.edu # skip checkpoint instructions should they exist 2147375Sgblack@eecs.umich.edu while exit_cause == "checkpoint": 2157375Sgblack@eecs.umich.edu exit_event = m5.simulate() 2167333Sgblack@eecs.umich.edu exit_cause = exit_event.getCause() 2177333Sgblack@eecs.umich.edu 2187333Sgblack@eecs.umich.edu if exit_cause == "a thread reached the max instruction count": 2197333Sgblack@eecs.umich.edu m5.checkpoint(joinpath(cptdir, "cpt.%s.%d" % \ 2207333Sgblack@eecs.umich.edu (options.bench, checkpoint_inst))) 2217333Sgblack@eecs.umich.edu print "Checkpoint written." 2227375Sgblack@eecs.umich.edu 2237333Sgblack@eecs.umich.edu else: 2247333Sgblack@eecs.umich.edu when, period = options.take_checkpoints.split(",", 1) 2257375Sgblack@eecs.umich.edu when = int(when) 2267375Sgblack@eecs.umich.edu period = int(period) 2277333Sgblack@eecs.umich.edu num_checkpoints = 0 2287333Sgblack@eecs.umich.edu 2297333Sgblack@eecs.umich.edu exit_event = m5.simulate(when - m5.curTick()) 2307333Sgblack@eecs.umich.edu exit_cause = exit_event.getCause() 2317333Sgblack@eecs.umich.edu while exit_cause == "checkpoint": 2327333Sgblack@eecs.umich.edu exit_event = m5.simulate(when - m5.curTick()) 2337333Sgblack@eecs.umich.edu exit_cause = exit_event.getCause() 2347333Sgblack@eecs.umich.edu 2357375Sgblack@eecs.umich.edu if exit_cause == "simulate() limit reached": 2367333Sgblack@eecs.umich.edu m5.checkpoint(joinpath(cptdir, "cpt.%d")) 2377333Sgblack@eecs.umich.edu num_checkpoints += 1 2387375Sgblack@eecs.umich.edu 2397375Sgblack@eecs.umich.edu sim_ticks = when 2407333Sgblack@eecs.umich.edu max_checkpoints = options.max_checkpoints 2417333Sgblack@eecs.umich.edu 2427333Sgblack@eecs.umich.edu while num_checkpoints < max_checkpoints and \ 2437333Sgblack@eecs.umich.edu exit_cause == "simulate() limit reached": 2447333Sgblack@eecs.umich.edu if (sim_ticks + period) > maxtick: 2457375Sgblack@eecs.umich.edu exit_event = m5.simulate(maxtick - sim_ticks) 2467333Sgblack@eecs.umich.edu exit_cause = exit_event.getCause() 2477333Sgblack@eecs.umich.edu break 2487375Sgblack@eecs.umich.edu else: 2497375Sgblack@eecs.umich.edu exit_event = m5.simulate(period) 2507333Sgblack@eecs.umich.edu exit_cause = exit_event.getCause() 2517333Sgblack@eecs.umich.edu sim_ticks += period 2527333Sgblack@eecs.umich.edu while exit_event.getCause() == "checkpoint": 2537333Sgblack@eecs.umich.edu exit_event = m5.simulate(sim_ticks - m5.curTick()) 2547333Sgblack@eecs.umich.edu if exit_event.getCause() == "simulate() limit reached": 2557333Sgblack@eecs.umich.edu m5.checkpoint(joinpath(cptdir, "cpt.%d")) 2567375Sgblack@eecs.umich.edu num_checkpoints += 1 2577333Sgblack@eecs.umich.edu 2587333Sgblack@eecs.umich.edu return exit_event 2597375Sgblack@eecs.umich.edu 2607375Sgblack@eecs.umich.edudef benchCheckpoints(options, maxtick, cptdir): 2617333Sgblack@eecs.umich.edu exit_event = m5.simulate(maxtick - m5.curTick()) 2627333Sgblack@eecs.umich.edu exit_cause = exit_event.getCause() 2637333Sgblack@eecs.umich.edu 2647333Sgblack@eecs.umich.edu num_checkpoints = 0 2657333Sgblack@eecs.umich.edu max_checkpoints = options.max_checkpoints 2667333Sgblack@eecs.umich.edu 2677333Sgblack@eecs.umich.edu while exit_cause == "checkpoint": 2687333Sgblack@eecs.umich.edu m5.checkpoint(joinpath(cptdir, "cpt.%d")) 2697375Sgblack@eecs.umich.edu num_checkpoints += 1 2707333Sgblack@eecs.umich.edu if num_checkpoints == max_checkpoints: 2717333Sgblack@eecs.umich.edu exit_cause = "maximum %d checkpoints dropped" % max_checkpoints 2727375Sgblack@eecs.umich.edu break 2737375Sgblack@eecs.umich.edu 2747333Sgblack@eecs.umich.edu exit_event = m5.simulate(maxtick - m5.curTick()) 2757333Sgblack@eecs.umich.edu exit_cause = exit_event.getCause() 2767333Sgblack@eecs.umich.edu 2777333Sgblack@eecs.umich.edu return exit_event 2787333Sgblack@eecs.umich.edu 2797375Sgblack@eecs.umich.edu# Set up environment for taking SimPoint checkpoints 2807333Sgblack@eecs.umich.edu# Expecting SimPoint files generated by SimPoint 3.2 2817333Sgblack@eecs.umich.edudef parseSimpointAnalysisFile(options, testsys): 2827375Sgblack@eecs.umich.edu import re 2837375Sgblack@eecs.umich.edu 2847333Sgblack@eecs.umich.edu simpoint_filename, weight_filename, interval_length, warmup_length = \ 2857333Sgblack@eecs.umich.edu options.take_simpoint_checkpoints.split(",", 3) 2867333Sgblack@eecs.umich.edu print "simpoint analysis file:", simpoint_filename 2877333Sgblack@eecs.umich.edu print "simpoint weight file:", weight_filename 2887333Sgblack@eecs.umich.edu print "interval length:", interval_length 2897375Sgblack@eecs.umich.edu print "warmup length:", warmup_length 2907333Sgblack@eecs.umich.edu 2917333Sgblack@eecs.umich.edu interval_length = int(interval_length) 2927375Sgblack@eecs.umich.edu warmup_length = int(warmup_length) 2937375Sgblack@eecs.umich.edu 2947333Sgblack@eecs.umich.edu # Simpoint analysis output starts interval counts with 0. 2957333Sgblack@eecs.umich.edu simpoints = [] 2967333Sgblack@eecs.umich.edu simpoint_start_insts = [] 2977333Sgblack@eecs.umich.edu 2987333Sgblack@eecs.umich.edu # Read in SimPoint analysis files 2997375Sgblack@eecs.umich.edu simpoint_file = open(simpoint_filename) 3007333Sgblack@eecs.umich.edu weight_file = open(weight_filename) 3017333Sgblack@eecs.umich.edu while True: 3027375Sgblack@eecs.umich.edu line = simpoint_file.readline() 3037375Sgblack@eecs.umich.edu if not line: 3047333Sgblack@eecs.umich.edu break 3057333Sgblack@eecs.umich.edu m = re.match("(\d+)\s+(\d+)", line) 3067333Sgblack@eecs.umich.edu if m: 3077333Sgblack@eecs.umich.edu interval = int(m.group(1)) 3087333Sgblack@eecs.umich.edu else: 3097375Sgblack@eecs.umich.edu fatal('unrecognized line in simpoint file!') 3107333Sgblack@eecs.umich.edu 3117333Sgblack@eecs.umich.edu line = weight_file.readline() 3127375Sgblack@eecs.umich.edu if not line: 3137375Sgblack@eecs.umich.edu fatal('not enough lines in simpoint weight file!') 3147333Sgblack@eecs.umich.edu m = re.match("([0-9\.e\-]+)\s+(\d+)", line) 3157333Sgblack@eecs.umich.edu if m: 3167333Sgblack@eecs.umich.edu weight = float(m.group(1)) 3177333Sgblack@eecs.umich.edu else: 3187333Sgblack@eecs.umich.edu fatal('unrecognized line in simpoint weight file!') 3197375Sgblack@eecs.umich.edu 3207333Sgblack@eecs.umich.edu if (interval * interval_length - warmup_length > 0): 3217333Sgblack@eecs.umich.edu starting_inst_count = \ 3227375Sgblack@eecs.umich.edu interval * interval_length - warmup_length 3237375Sgblack@eecs.umich.edu actual_warmup_length = warmup_length 3247333Sgblack@eecs.umich.edu else: 3257333Sgblack@eecs.umich.edu # Not enough room for proper warmup 3267333Sgblack@eecs.umich.edu # Just starting from the beginning 3277333Sgblack@eecs.umich.edu starting_inst_count = 0 3287333Sgblack@eecs.umich.edu actual_warmup_length = interval * interval_length 3297375Sgblack@eecs.umich.edu 3307333Sgblack@eecs.umich.edu simpoints.append((interval, weight, starting_inst_count, 3317333Sgblack@eecs.umich.edu actual_warmup_length)) 3327375Sgblack@eecs.umich.edu 3337375Sgblack@eecs.umich.edu # Sort SimPoints by starting inst count 3347333Sgblack@eecs.umich.edu simpoints.sort(key=lambda obj: obj[2]) 3357333Sgblack@eecs.umich.edu for s in simpoints: 3367333Sgblack@eecs.umich.edu interval, weight, starting_inst_count, actual_warmup_length = s 3377333Sgblack@eecs.umich.edu print str(interval), str(weight), starting_inst_count, \ 3387333Sgblack@eecs.umich.edu actual_warmup_length 3397375Sgblack@eecs.umich.edu simpoint_start_insts.append(starting_inst_count) 3407333Sgblack@eecs.umich.edu 3417333Sgblack@eecs.umich.edu print "Total # of simpoints:", len(simpoints) 3427375Sgblack@eecs.umich.edu testsys.cpu[0].simpoint_start_insts = simpoint_start_insts 3437375Sgblack@eecs.umich.edu 3447333Sgblack@eecs.umich.edu return (simpoints, interval_length) 3457333Sgblack@eecs.umich.edu 3467333Sgblack@eecs.umich.edudef takeSimpointCheckpoints(simpoints, interval_length, cptdir): 3477333Sgblack@eecs.umich.edu num_checkpoints = 0 3487333Sgblack@eecs.umich.edu index = 0 3497375Sgblack@eecs.umich.edu last_chkpnt_inst_count = -1 3507333Sgblack@eecs.umich.edu for simpoint in simpoints: 3517333Sgblack@eecs.umich.edu interval, weight, starting_inst_count, actual_warmup_length = simpoint 3527375Sgblack@eecs.umich.edu if starting_inst_count == last_chkpnt_inst_count: 3537375Sgblack@eecs.umich.edu # checkpoint starting point same as last time 3547333Sgblack@eecs.umich.edu # (when warmup period longer than starting point) 3557333Sgblack@eecs.umich.edu exit_cause = "simpoint starting point found" 3567333Sgblack@eecs.umich.edu code = 0 3577333Sgblack@eecs.umich.edu else: 3587333Sgblack@eecs.umich.edu exit_event = m5.simulate() 3597333Sgblack@eecs.umich.edu 3607375Sgblack@eecs.umich.edu # skip checkpoint instructions should they exist 3617333Sgblack@eecs.umich.edu while exit_event.getCause() == "checkpoint": 3627333Sgblack@eecs.umich.edu print "Found 'checkpoint' exit event...ignoring..." 3637375Sgblack@eecs.umich.edu exit_event = m5.simulate() 3647375Sgblack@eecs.umich.edu 3657333Sgblack@eecs.umich.edu exit_cause = exit_event.getCause() 3667333Sgblack@eecs.umich.edu code = exit_event.getCode() 3677333Sgblack@eecs.umich.edu 3687333Sgblack@eecs.umich.edu if exit_cause == "simpoint starting point found": 3697333Sgblack@eecs.umich.edu m5.checkpoint(joinpath(cptdir, 3707333Sgblack@eecs.umich.edu "cpt.simpoint_%02d_inst_%d_weight_%f_interval_%d_warmup_%d" 3717375Sgblack@eecs.umich.edu % (index, starting_inst_count, weight, interval_length, 3727333Sgblack@eecs.umich.edu actual_warmup_length))) 3737333Sgblack@eecs.umich.edu print "Checkpoint #%d written. start inst:%d weight:%f" % \ 3747375Sgblack@eecs.umich.edu (num_checkpoints, starting_inst_count, weight) 3757375Sgblack@eecs.umich.edu num_checkpoints += 1 3767333Sgblack@eecs.umich.edu last_chkpnt_inst_count = starting_inst_count 3777364Sgblack@eecs.umich.edu else: 3787364Sgblack@eecs.umich.edu break 3797364Sgblack@eecs.umich.edu index += 1 3807364Sgblack@eecs.umich.edu 3817364Sgblack@eecs.umich.edu print 'Exiting @ tick %i because %s' % (m5.curTick(), exit_cause) 3827364Sgblack@eecs.umich.edu print "%d checkpoints taken" % num_checkpoints 3837364Sgblack@eecs.umich.edu sys.exit(code) 3847375Sgblack@eecs.umich.edu 3857364Sgblack@eecs.umich.edudef restoreSimpointCheckpoint(): 3867364Sgblack@eecs.umich.edu exit_event = m5.simulate() 3877375Sgblack@eecs.umich.edu exit_cause = exit_event.getCause() 3887375Sgblack@eecs.umich.edu 3897364Sgblack@eecs.umich.edu if exit_cause == "simpoint starting point found": 3907364Sgblack@eecs.umich.edu print "Warmed up! Dumping and resetting stats!" 3917364Sgblack@eecs.umich.edu m5.stats.dump() 3927364Sgblack@eecs.umich.edu m5.stats.reset() 3937364Sgblack@eecs.umich.edu 3947364Sgblack@eecs.umich.edu exit_event = m5.simulate() 3957364Sgblack@eecs.umich.edu exit_cause = exit_event.getCause() 3967364Sgblack@eecs.umich.edu 3977364Sgblack@eecs.umich.edu if exit_cause == "simpoint starting point found": 3987364Sgblack@eecs.umich.edu print "Done running SimPoint!" 3997364Sgblack@eecs.umich.edu sys.exit(exit_event.getCode()) 4007364Sgblack@eecs.umich.edu 4017364Sgblack@eecs.umich.edu print 'Exiting @ tick %i because %s' % (m5.curTick(), exit_cause) 4027364Sgblack@eecs.umich.edu sys.exit(exit_event.getCode()) 4037375Sgblack@eecs.umich.edu 4047364Sgblack@eecs.umich.edudef repeatSwitch(testsys, repeat_switch_cpu_list, maxtick, switch_freq): 4057364Sgblack@eecs.umich.edu print "starting switch loop" 4067375Sgblack@eecs.umich.edu while True: 4077375Sgblack@eecs.umich.edu exit_event = m5.simulate(switch_freq) 4087364Sgblack@eecs.umich.edu exit_cause = exit_event.getCause() 4097365Sgblack@eecs.umich.edu 4107365Sgblack@eecs.umich.edu if exit_cause != "simulate() limit reached": 4117365Sgblack@eecs.umich.edu return exit_event 4127365Sgblack@eecs.umich.edu 4137375Sgblack@eecs.umich.edu m5.switchCpus(testsys, repeat_switch_cpu_list) 4147365Sgblack@eecs.umich.edu 4157365Sgblack@eecs.umich.edu tmp_cpu_list = [] 4167375Sgblack@eecs.umich.edu for old_cpu, new_cpu in repeat_switch_cpu_list: 4177375Sgblack@eecs.umich.edu tmp_cpu_list.append((new_cpu, old_cpu)) 4187365Sgblack@eecs.umich.edu repeat_switch_cpu_list = tmp_cpu_list 4197365Sgblack@eecs.umich.edu 4207365Sgblack@eecs.umich.edu if (maxtick - m5.curTick()) <= switch_freq: 4217365Sgblack@eecs.umich.edu exit_event = m5.simulate(maxtick - m5.curTick()) 4227365Sgblack@eecs.umich.edu return exit_event 4237365Sgblack@eecs.umich.edu 4247365Sgblack@eecs.umich.edudef run(options, root, testsys, cpu_class): 4257365Sgblack@eecs.umich.edu if options.checkpoint_dir: 4267365Sgblack@eecs.umich.edu cptdir = options.checkpoint_dir 4277375Sgblack@eecs.umich.edu elif m5.options.outdir: 4287365Sgblack@eecs.umich.edu cptdir = m5.options.outdir 4297365Sgblack@eecs.umich.edu else: 4307375Sgblack@eecs.umich.edu cptdir = getcwd() 4317375Sgblack@eecs.umich.edu 4327365Sgblack@eecs.umich.edu if options.fast_forward and options.checkpoint_restore != None: 4337366Sgblack@eecs.umich.edu fatal("Can't specify both --fast-forward and --checkpoint-restore") 4347366Sgblack@eecs.umich.edu 4357366Sgblack@eecs.umich.edu if options.standard_switch and not options.caches: 4367366Sgblack@eecs.umich.edu fatal("Must specify --caches when using --standard-switch") 4377375Sgblack@eecs.umich.edu 4387366Sgblack@eecs.umich.edu if options.standard_switch and options.repeat_switch: 4397366Sgblack@eecs.umich.edu fatal("Can't specify both --standard-switch and --repeat-switch") 4407375Sgblack@eecs.umich.edu 4417375Sgblack@eecs.umich.edu if options.repeat_switch and options.take_checkpoints: 4427366Sgblack@eecs.umich.edu fatal("Can't specify both --repeat-switch and --take-checkpoints") 4437366Sgblack@eecs.umich.edu 4447366Sgblack@eecs.umich.edu np = options.num_cpus 4457366Sgblack@eecs.umich.edu switch_cpus = None 4467366Sgblack@eecs.umich.edu 4477366Sgblack@eecs.umich.edu if options.prog_interval: 4487366Sgblack@eecs.umich.edu for i in xrange(np): 4497366Sgblack@eecs.umich.edu testsys.cpu[i].progress_interval = options.prog_interval 4507366Sgblack@eecs.umich.edu 4517375Sgblack@eecs.umich.edu if options.maxinsts: 4527366Sgblack@eecs.umich.edu for i in xrange(np): 4537366Sgblack@eecs.umich.edu testsys.cpu[i].max_insts_any_thread = options.maxinsts 4547375Sgblack@eecs.umich.edu 4557375Sgblack@eecs.umich.edu if cpu_class: 4567366Sgblack@eecs.umich.edu switch_cpus = [cpu_class(switched_out=True, cpu_id=(i)) 4577367Sgblack@eecs.umich.edu for i in xrange(np)] 4587367Sgblack@eecs.umich.edu 4597367Sgblack@eecs.umich.edu for i in xrange(np): 4607367Sgblack@eecs.umich.edu if options.fast_forward: 4617375Sgblack@eecs.umich.edu testsys.cpu[i].max_insts_any_thread = int(options.fast_forward) 4627367Sgblack@eecs.umich.edu switch_cpus[i].system = testsys 4637367Sgblack@eecs.umich.edu switch_cpus[i].workload = testsys.cpu[i].workload 4647375Sgblack@eecs.umich.edu switch_cpus[i].clk_domain = testsys.cpu[i].clk_domain 4657375Sgblack@eecs.umich.edu # simulation period 4667367Sgblack@eecs.umich.edu if options.maxinsts: 4677367Sgblack@eecs.umich.edu switch_cpus[i].max_insts_any_thread = options.maxinsts 4687367Sgblack@eecs.umich.edu # Add checker cpu if selected 4697367Sgblack@eecs.umich.edu if options.checker: 4707367Sgblack@eecs.umich.edu switch_cpus[i].addCheckerCpu() 4717367Sgblack@eecs.umich.edu 4727367Sgblack@eecs.umich.edu testsys.switch_cpus = switch_cpus 4737367Sgblack@eecs.umich.edu switch_cpu_list = [(testsys.cpu[i], switch_cpus[i]) for i in xrange(np)] 4747367Sgblack@eecs.umich.edu 4757367Sgblack@eecs.umich.edu if options.repeat_switch: 4767375Sgblack@eecs.umich.edu switch_class = getCPUClass(options.cpu_type)[0] 4777367Sgblack@eecs.umich.edu if switch_class.require_caches() and \ 4787367Sgblack@eecs.umich.edu not options.caches: 4797375Sgblack@eecs.umich.edu print "%s: Must be used with caches" % str(switch_class) 4807375Sgblack@eecs.umich.edu sys.exit(1) 4817367Sgblack@eecs.umich.edu if not switch_class.support_take_over(): 4827368Sgblack@eecs.umich.edu print "%s: CPU switching not supported" % str(switch_class) 4837368Sgblack@eecs.umich.edu sys.exit(1) 4847368Sgblack@eecs.umich.edu 4857368Sgblack@eecs.umich.edu repeat_switch_cpus = [switch_class(switched_out=True, \ 4867375Sgblack@eecs.umich.edu cpu_id=(i)) for i in xrange(np)] 4877368Sgblack@eecs.umich.edu 4887368Sgblack@eecs.umich.edu for i in xrange(np): 4897375Sgblack@eecs.umich.edu repeat_switch_cpus[i].system = testsys 4907375Sgblack@eecs.umich.edu repeat_switch_cpus[i].workload = testsys.cpu[i].workload 4917368Sgblack@eecs.umich.edu repeat_switch_cpus[i].clk_domain = testsys.cpu[i].clk_domain 4927368Sgblack@eecs.umich.edu 4937368Sgblack@eecs.umich.edu if options.maxinsts: 4947368Sgblack@eecs.umich.edu repeat_switch_cpus[i].max_insts_any_thread = options.maxinsts 4957368Sgblack@eecs.umich.edu 4967368Sgblack@eecs.umich.edu if options.checker: 4977368Sgblack@eecs.umich.edu repeat_switch_cpus[i].addCheckerCpu() 4987368Sgblack@eecs.umich.edu 4997368Sgblack@eecs.umich.edu testsys.repeat_switch_cpus = repeat_switch_cpus 5007368Sgblack@eecs.umich.edu 5017375Sgblack@eecs.umich.edu if cpu_class: 5027368Sgblack@eecs.umich.edu repeat_switch_cpu_list = [(switch_cpus[i], repeat_switch_cpus[i]) 5037368Sgblack@eecs.umich.edu for i in xrange(np)] 5047375Sgblack@eecs.umich.edu else: 5057375Sgblack@eecs.umich.edu repeat_switch_cpu_list = [(testsys.cpu[i], repeat_switch_cpus[i]) 5067368Sgblack@eecs.umich.edu for i in xrange(np)] 5077369Sgblack@eecs.umich.edu 5087369Sgblack@eecs.umich.edu if options.standard_switch: 5097369Sgblack@eecs.umich.edu switch_cpus = [TimingSimpleCPU(switched_out=True, cpu_id=(i)) 5107369Sgblack@eecs.umich.edu for i in xrange(np)] 5117375Sgblack@eecs.umich.edu switch_cpus_1 = [DerivO3CPU(switched_out=True, cpu_id=(i)) 5127369Sgblack@eecs.umich.edu for i in xrange(np)] 5137369Sgblack@eecs.umich.edu 5147375Sgblack@eecs.umich.edu for i in xrange(np): 5157375Sgblack@eecs.umich.edu switch_cpus[i].system = testsys 5167369Sgblack@eecs.umich.edu switch_cpus_1[i].system = testsys 5177369Sgblack@eecs.umich.edu switch_cpus[i].workload = testsys.cpu[i].workload 5187369Sgblack@eecs.umich.edu switch_cpus_1[i].workload = testsys.cpu[i].workload 5197369Sgblack@eecs.umich.edu switch_cpus[i].clk_domain = testsys.cpu[i].clk_domain 5207369Sgblack@eecs.umich.edu switch_cpus_1[i].clk_domain = testsys.cpu[i].clk_domain 5217369Sgblack@eecs.umich.edu 5227369Sgblack@eecs.umich.edu # if restoring, make atomic cpu simulate only a few instructions 5237369Sgblack@eecs.umich.edu if options.checkpoint_restore != None: 5247369Sgblack@eecs.umich.edu testsys.cpu[i].max_insts_any_thread = 1 5257369Sgblack@eecs.umich.edu # Fast forward to specified location if we are not restoring 5267375Sgblack@eecs.umich.edu elif options.fast_forward: 5277369Sgblack@eecs.umich.edu testsys.cpu[i].max_insts_any_thread = int(options.fast_forward) 5287369Sgblack@eecs.umich.edu # Fast forward to a simpoint (warning: time consuming) 5297375Sgblack@eecs.umich.edu elif options.simpoint: 5307375Sgblack@eecs.umich.edu if testsys.cpu[i].workload[0].simpoint == 0: 5317369Sgblack@eecs.umich.edu fatal('simpoint not found') 5327369Sgblack@eecs.umich.edu testsys.cpu[i].max_insts_any_thread = \ 5337369Sgblack@eecs.umich.edu testsys.cpu[i].workload[0].simpoint 5347369Sgblack@eecs.umich.edu # No distance specified, just switch 5357369Sgblack@eecs.umich.edu else: 5367369Sgblack@eecs.umich.edu testsys.cpu[i].max_insts_any_thread = 1 5377369Sgblack@eecs.umich.edu 5387369Sgblack@eecs.umich.edu # warmup period 5397375Sgblack@eecs.umich.edu if options.warmup_insts: 5407369Sgblack@eecs.umich.edu switch_cpus[i].max_insts_any_thread = options.warmup_insts 5417369Sgblack@eecs.umich.edu 5427375Sgblack@eecs.umich.edu # simulation period 5437375Sgblack@eecs.umich.edu if options.maxinsts: 5447369Sgblack@eecs.umich.edu switch_cpus_1[i].max_insts_any_thread = options.maxinsts 5457369Sgblack@eecs.umich.edu 5467369Sgblack@eecs.umich.edu # attach the checker cpu if selected 5477369Sgblack@eecs.umich.edu if options.checker: 5487369Sgblack@eecs.umich.edu switch_cpus[i].addCheckerCpu() 5497369Sgblack@eecs.umich.edu switch_cpus_1[i].addCheckerCpu() 5507369Sgblack@eecs.umich.edu 5517369Sgblack@eecs.umich.edu testsys.switch_cpus = switch_cpus 5527369Sgblack@eecs.umich.edu testsys.switch_cpus_1 = switch_cpus_1 5537369Sgblack@eecs.umich.edu switch_cpu_list = [(testsys.cpu[i], switch_cpus[i]) for i in xrange(np)] 5547369Sgblack@eecs.umich.edu switch_cpu_list1 = [(switch_cpus[i], switch_cpus_1[i]) for i in xrange(np)] 5557369Sgblack@eecs.umich.edu 5567375Sgblack@eecs.umich.edu # set the checkpoint in the cpu before m5.instantiate is called 5577369Sgblack@eecs.umich.edu if options.take_checkpoints != None and \ 5587369Sgblack@eecs.umich.edu (options.simpoint or options.at_instruction): 5597375Sgblack@eecs.umich.edu offset = int(options.take_checkpoints) 5607375Sgblack@eecs.umich.edu # Set an instruction break point 5617369Sgblack@eecs.umich.edu if options.simpoint: 5627370Sgblack@eecs.umich.edu for i in xrange(np): 5637370Sgblack@eecs.umich.edu if testsys.cpu[i].workload[0].simpoint == 0: 5647370Sgblack@eecs.umich.edu fatal('no simpoint for testsys.cpu[%d].workload[0]', i) 5657370Sgblack@eecs.umich.edu checkpoint_inst = int(testsys.cpu[i].workload[0].simpoint) + offset 5667370Sgblack@eecs.umich.edu testsys.cpu[i].max_insts_any_thread = checkpoint_inst 5677370Sgblack@eecs.umich.edu # used for output below 5687370Sgblack@eecs.umich.edu options.take_checkpoints = checkpoint_inst 5697370Sgblack@eecs.umich.edu else: 5707375Sgblack@eecs.umich.edu options.take_checkpoints = offset 5717370Sgblack@eecs.umich.edu # Set all test cpus with the right number of instructions 5727370Sgblack@eecs.umich.edu # for the upcoming simulation 5737375Sgblack@eecs.umich.edu for i in xrange(np): 5747375Sgblack@eecs.umich.edu testsys.cpu[i].max_insts_any_thread = offset 5757370Sgblack@eecs.umich.edu 5767370Sgblack@eecs.umich.edu if options.take_simpoint_checkpoints != None: 5777370Sgblack@eecs.umich.edu simpoints, interval_length = parseSimpointAnalysisFile(options, testsys) 5787370Sgblack@eecs.umich.edu 5797370Sgblack@eecs.umich.edu checkpoint_dir = None 5807370Sgblack@eecs.umich.edu if options.checkpoint_restore: 5817370Sgblack@eecs.umich.edu cpt_starttick, checkpoint_dir = findCptDir(options, cptdir, testsys) 5827370Sgblack@eecs.umich.edu m5.instantiate(checkpoint_dir) 5837370Sgblack@eecs.umich.edu 5847370Sgblack@eecs.umich.edu # Handle the max tick settings now that tick frequency was resolved 5857370Sgblack@eecs.umich.edu # during system instantiation 5867370Sgblack@eecs.umich.edu # NOTE: the maxtick variable here is in absolute ticks, so it must 5877370Sgblack@eecs.umich.edu # include any simulated ticks before a checkpoint 5887370Sgblack@eecs.umich.edu explicit_maxticks = 0 5897370Sgblack@eecs.umich.edu maxtick_from_abs = m5.MaxTick 5907370Sgblack@eecs.umich.edu maxtick_from_rel = m5.MaxTick 5917375Sgblack@eecs.umich.edu maxtick_from_maxtime = m5.MaxTick 5927370Sgblack@eecs.umich.edu if options.abs_max_tick: 5937370Sgblack@eecs.umich.edu maxtick_from_abs = options.abs_max_tick 5947375Sgblack@eecs.umich.edu explicit_maxticks += 1 5957375Sgblack@eecs.umich.edu if options.rel_max_tick: 5967370Sgblack@eecs.umich.edu maxtick_from_rel = options.rel_max_tick 5977370Sgblack@eecs.umich.edu if options.checkpoint_restore: 5987370Sgblack@eecs.umich.edu # NOTE: this may need to be updated if checkpoints ever store 5997370Sgblack@eecs.umich.edu # the ticks per simulated second 6007370Sgblack@eecs.umich.edu maxtick_from_rel += cpt_starttick 6017370Sgblack@eecs.umich.edu if options.at_instruction or options.simpoint: 6027370Sgblack@eecs.umich.edu warn("Relative max tick specified with --at-instruction or" \ 6037370Sgblack@eecs.umich.edu " --simpoint\n These options don't specify the " \ 6047370Sgblack@eecs.umich.edu "checkpoint start tick, so assuming\n you mean " \ 6057375Sgblack@eecs.umich.edu "absolute max tick") 6067370Sgblack@eecs.umich.edu explicit_maxticks += 1 6077370Sgblack@eecs.umich.edu if options.maxtime: 6087375Sgblack@eecs.umich.edu maxtick_from_maxtime = m5.ticks.fromSeconds(options.maxtime) 6097375Sgblack@eecs.umich.edu explicit_maxticks += 1 6107370Sgblack@eecs.umich.edu if explicit_maxticks > 1: 6117370Sgblack@eecs.umich.edu warn("Specified multiple of --abs-max-tick, --rel-max-tick, --maxtime."\ 6127370Sgblack@eecs.umich.edu " Using least") 6137370Sgblack@eecs.umich.edu maxtick = min([maxtick_from_abs, maxtick_from_rel, maxtick_from_maxtime]) 6147370Sgblack@eecs.umich.edu 6157370Sgblack@eecs.umich.edu if options.checkpoint_restore != None and maxtick < cpt_starttick: 6167370Sgblack@eecs.umich.edu fatal("Bad maxtick (%d) specified: " \ 6177370Sgblack@eecs.umich.edu "Checkpoint starts starts from tick: %d", maxtick, cpt_starttick) 6187370Sgblack@eecs.umich.edu 6197370Sgblack@eecs.umich.edu if options.standard_switch or cpu_class: 6207370Sgblack@eecs.umich.edu if options.standard_switch: 6217370Sgblack@eecs.umich.edu print "Switch at instruction count:%s" % \ 6227370Sgblack@eecs.umich.edu str(testsys.cpu[0].max_insts_any_thread) 6237370Sgblack@eecs.umich.edu exit_event = m5.simulate() 6247370Sgblack@eecs.umich.edu elif cpu_class and options.fast_forward: 6257370Sgblack@eecs.umich.edu print "Switch at instruction count:%s" % \ 6267375Sgblack@eecs.umich.edu str(testsys.cpu[0].max_insts_any_thread) 6277370Sgblack@eecs.umich.edu exit_event = m5.simulate() 6287370Sgblack@eecs.umich.edu else: 6297375Sgblack@eecs.umich.edu print "Switch at curTick count:%s" % str(10000) 6307375Sgblack@eecs.umich.edu exit_event = m5.simulate(10000) 6317370Sgblack@eecs.umich.edu print "Switched CPUS @ tick %s" % (m5.curTick()) 6327371Sgblack@eecs.umich.edu 6337371Sgblack@eecs.umich.edu m5.switchCpus(testsys, switch_cpu_list) 6347371Sgblack@eecs.umich.edu 6357371Sgblack@eecs.umich.edu if options.standard_switch: 6367371Sgblack@eecs.umich.edu print "Switch at instruction count:%d" % \ 6377371Sgblack@eecs.umich.edu (testsys.switch_cpus[0].max_insts_any_thread) 6387371Sgblack@eecs.umich.edu 6397371Sgblack@eecs.umich.edu #warmup instruction count may have already been set 6407375Sgblack@eecs.umich.edu if options.warmup_insts: 6417371Sgblack@eecs.umich.edu exit_event = m5.simulate() 6427371Sgblack@eecs.umich.edu else: 6437375Sgblack@eecs.umich.edu exit_event = m5.simulate(options.standard_switch) 6447375Sgblack@eecs.umich.edu print "Switching CPUS @ tick %s" % (m5.curTick()) 6457371Sgblack@eecs.umich.edu print "Simulation ends instruction count:%d" % \ 6467371Sgblack@eecs.umich.edu (testsys.switch_cpus_1[0].max_insts_any_thread) 6477371Sgblack@eecs.umich.edu m5.switchCpus(testsys, switch_cpu_list1) 6487371Sgblack@eecs.umich.edu 6497371Sgblack@eecs.umich.edu # If we're taking and restoring checkpoints, use checkpoint_dir 6507371Sgblack@eecs.umich.edu # option only for finding the checkpoints to restore from. This 6517371Sgblack@eecs.umich.edu # lets us test checkpointing by restoring from one set of 6527371Sgblack@eecs.umich.edu # checkpoints, generating a second set, and then comparing them. 6537371Sgblack@eecs.umich.edu if (options.take_checkpoints or options.take_simpoint_checkpoints) \ 6547371Sgblack@eecs.umich.edu and options.checkpoint_restore: 6557371Sgblack@eecs.umich.edu 6567371Sgblack@eecs.umich.edu if m5.options.outdir: 6577371Sgblack@eecs.umich.edu cptdir = m5.options.outdir 6587371Sgblack@eecs.umich.edu else: 6597371Sgblack@eecs.umich.edu cptdir = getcwd() 6607371Sgblack@eecs.umich.edu 6617375Sgblack@eecs.umich.edu if options.take_checkpoints != None : 6627371Sgblack@eecs.umich.edu # Checkpoints being taken via the command line at <when> and at 6637371Sgblack@eecs.umich.edu # subsequent periods of <period>. Checkpoint instructions 6647375Sgblack@eecs.umich.edu # received from the benchmark running are ignored and skipped in 6657375Sgblack@eecs.umich.edu # favor of command line checkpoint instructions. 6667371Sgblack@eecs.umich.edu exit_event = scriptCheckpoints(options, maxtick, cptdir) 6677371Sgblack@eecs.umich.edu 6687371Sgblack@eecs.umich.edu # Take SimPoint checkpoints 6697371Sgblack@eecs.umich.edu elif options.take_simpoint_checkpoints != None: 6707371Sgblack@eecs.umich.edu takeSimpointCheckpoints(simpoints, interval_length, cptdir) 6717371Sgblack@eecs.umich.edu 6727371Sgblack@eecs.umich.edu # Restore from SimPoint checkpoints 6737371Sgblack@eecs.umich.edu elif options.restore_simpoint_checkpoint != None: 6747371Sgblack@eecs.umich.edu restoreSimpointCheckpoint() 6757375Sgblack@eecs.umich.edu 6767371Sgblack@eecs.umich.edu else: 6777371Sgblack@eecs.umich.edu if options.fast_forward: 6787375Sgblack@eecs.umich.edu m5.stats.reset() 6797375Sgblack@eecs.umich.edu print "**** REAL SIMULATION ****" 6807371Sgblack@eecs.umich.edu 6817371Sgblack@eecs.umich.edu # If checkpoints are being taken, then the checkpoint instruction 6827371Sgblack@eecs.umich.edu # will occur in the benchmark code it self. 6837371Sgblack@eecs.umich.edu if options.repeat_switch and maxtick > options.repeat_switch: 6847371Sgblack@eecs.umich.edu exit_event = repeatSwitch(testsys, repeat_switch_cpu_list, 6857371Sgblack@eecs.umich.edu maxtick, options.repeat_switch) 6867371Sgblack@eecs.umich.edu else: 6877371Sgblack@eecs.umich.edu exit_event = benchCheckpoints(options, maxtick, cptdir) 6887371Sgblack@eecs.umich.edu 6897371Sgblack@eecs.umich.edu print 'Exiting @ tick %i because %s' % (m5.curTick(), exit_event.getCause()) 6907371Sgblack@eecs.umich.edu if options.checkpoint_at_end: 6917371Sgblack@eecs.umich.edu m5.checkpoint(joinpath(cptdir, "cpt.%d")) 6927371Sgblack@eecs.umich.edu 6937371Sgblack@eecs.umich.edu if not m5.options.interactive: 6947371Sgblack@eecs.umich.edu sys.exit(exit_event.getCode()) 6957371Sgblack@eecs.umich.edu