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