Simulation.py (9139:ee038fbbe5d2) | Simulation.py (9140:cfd2a8364ea1) |
---|---|
1# Copyright (c) 2006-2008 The Regents of The University of Michigan 2# Copyright (c) 2010 Advanced Micro Devices, Inc. 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions are 7# met: redistributions of source code must retain the above copyright 8# notice, this list of conditions and the following disclaimer; --- 85 unchanged lines hidden (view full) --- 94 system.work_end_ckpt_count = options.work_end_checkpoint_count 95 if options.work_begin_exit_count != None: 96 system.work_begin_exit_count = options.work_begin_exit_count 97 if options.work_begin_checkpoint_count != None: 98 system.work_begin_ckpt_count = options.work_begin_checkpoint_count 99 if options.work_cpus_checkpoint_count != None: 100 system.work_cpus_ckpt_count = options.work_cpus_checkpoint_count 101 | 1# Copyright (c) 2006-2008 The Regents of The University of Michigan 2# Copyright (c) 2010 Advanced Micro Devices, Inc. 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions are 7# met: redistributions of source code must retain the above copyright 8# notice, this list of conditions and the following disclaimer; --- 85 unchanged lines hidden (view full) --- 94 system.work_end_ckpt_count = options.work_end_checkpoint_count 95 if options.work_begin_exit_count != None: 96 system.work_begin_exit_count = options.work_begin_exit_count 97 if options.work_begin_checkpoint_count != None: 98 system.work_begin_ckpt_count = options.work_begin_checkpoint_count 99 if options.work_cpus_checkpoint_count != None: 100 system.work_cpus_ckpt_count = options.work_cpus_checkpoint_count 101 |
102def findCptDir(options, maxtick, cptdir, testsys): 103 """Figures out the directory from which the checkpointed state is read. 104 105 There are two different ways in which the directories holding checkpoints 106 can be named -- 107 1. cpt.<benchmark name>.<instruction count when the checkpoint was taken> 108 2. cpt.<some number, usually the tick value when the checkpoint was taken> 109 110 This function parses through the options to figure out which one of the 111 above should be used for selecting the checkpoint, and then figures out 112 the appropriate directory. 113 114 It also sets the value of the maximum tick value till which the simulation 115 will run. 116 """ 117 118 from os.path import isdir, exists 119 from os import listdir 120 import re 121 122 if not isdir(cptdir): 123 fatal("checkpoint dir %s does not exist!", cptdir) 124 125 if options.at_instruction or options.simpoint: 126 inst = options.checkpoint_restore 127 if options.simpoint: 128 # assume workload 0 has the simpoint 129 if testsys.cpu[0].workload[0].simpoint == 0: 130 fatal('Unable to find simpoint') 131 inst += int(testsys.cpu[0].workload[0].simpoint) 132 133 checkpoint_dir = joinpath(cptdir, "cpt.%s.%s" % (options.bench, inst)) 134 if not exists(checkpoint_dir): 135 fatal("Unable to find checkpoint directory %s", checkpoint_dir) 136 else: 137 dirs = listdir(cptdir) 138 expr = re.compile('cpt\.([0-9]*)') 139 cpts = [] 140 for dir in dirs: 141 match = expr.match(dir) 142 if match: 143 cpts.append(match.group(1)) 144 145 cpts.sort(lambda a,b: cmp(long(a), long(b))) 146 147 cpt_num = options.checkpoint_restore 148 if cpt_num > len(cpts): 149 fatal('Checkpoint %d not found', cpt_num) 150 151 maxtick = maxtick - int(cpts[cpt_num - 1]) 152 checkpoint_dir = joinpath(cptdir, "cpt.%s" % cpts[cpt_num - 1]) 153 154 return maxtick, checkpoint_dir 155 156def scriptCheckpoints(options): 157 if options.at_instruction or options.simpoint: 158 checkpoint_inst = int(options.take_checkpoints) 159 160 # maintain correct offset if we restored from some instruction 161 if options.checkpoint_restore != None: 162 checkpoint_inst += options.checkpoint_restore 163 164 print "Creating checkpoint at inst:%d" % (checkpoint_inst) 165 exit_event = m5.simulate() 166 exit_cause = exit_event.getCause() 167 print "exit cause = %s" % exit_cause 168 169 # skip checkpoint instructions should they exist 170 while exit_cause == "checkpoint": 171 exit_event = m5.simulate() 172 exit_cause = exit_event.getCause() 173 174 if exit_cause == "a thread reached the max instruction count": 175 m5.checkpoint(joinpath(cptdir, "cpt.%s.%d" % \ 176 (options.bench, checkpoint_inst))) 177 print "Checkpoint written." 178 179 else: 180 when, period = options.take_checkpoints.split(",", 1) 181 when = int(when) 182 period = int(period) 183 184 exit_event = m5.simulate(when) 185 exit_cause = exit_event.getCause() 186 while exit_cause == "checkpoint": 187 exit_event = m5.simulate(when - m5.curTick()) 188 exit_cause = exit_event.getCause() 189 190 if exit_cause == "simulate() limit reached": 191 m5.checkpoint(joinpath(cptdir, "cpt.%d")) 192 num_checkpoints += 1 193 194 sim_ticks = when 195 num_checkpoints = 0 196 max_checkpoints = options.max_checkpoints 197 198 while num_checkpoints < max_checkpoints and \ 199 exit_cause == "simulate() limit reached": 200 if (sim_ticks + period) > maxtick: 201 exit_event = m5.simulate(maxtick - sim_ticks) 202 exit_cause = exit_event.getCause() 203 break 204 else: 205 exit_event = m5.simulate(period) 206 exit_cause = exit_event.getCause() 207 sim_ticks += period 208 while exit_event.getCause() == "checkpoint": 209 exit_event = m5.simulate(sim_ticks - m5.curTick()) 210 if exit_event.getCause() == "simulate() limit reached": 211 m5.checkpoint(joinpath(cptdir, "cpt.%d")) 212 num_checkpoints += 1 213 214 return exit_cause 215 216def benchCheckpoints(options, maxtick, cptdir): 217 if options.fast_forward: 218 m5.stats.reset() 219 220 print "**** REAL SIMULATION ****" 221 exit_event = m5.simulate(maxtick) 222 exit_cause = exit_event.getCause() 223 224 num_checkpoints = 0 225 max_checkpoints = options.max_checkpoints 226 227 while exit_cause == "checkpoint": 228 m5.checkpoint(joinpath(cptdir, "cpt.%d")) 229 num_checkpoints += 1 230 if num_checkpoints == max_checkpoints: 231 exit_cause = "maximum %d checkpoints dropped" % max_checkpoints 232 break 233 234 exit_event = m5.simulate(maxtick - m5.curTick()) 235 exit_cause = exit_event.getCause() 236 237 return exit_cause 238 |
|
102def run(options, root, testsys, cpu_class): 103 if options.maxtick: 104 maxtick = options.maxtick 105 elif options.maxtime: 106 simtime = m5.ticks.seconds(simtime) 107 print "simulating for: ", simtime 108 maxtick = simtime 109 else: --- 8 unchanged lines hidden (view full) --- 118 119 if options.fast_forward and options.checkpoint_restore != None: 120 fatal("Can't specify both --fast-forward and --checkpoint-restore") 121 122 if options.standard_switch and not options.caches: 123 fatal("Must specify --caches when using --standard-switch") 124 125 np = options.num_cpus | 239def run(options, root, testsys, cpu_class): 240 if options.maxtick: 241 maxtick = options.maxtick 242 elif options.maxtime: 243 simtime = m5.ticks.seconds(simtime) 244 print "simulating for: ", simtime 245 maxtick = simtime 246 else: --- 8 unchanged lines hidden (view full) --- 255 256 if options.fast_forward and options.checkpoint_restore != None: 257 fatal("Can't specify both --fast-forward and --checkpoint-restore") 258 259 if options.standard_switch and not options.caches: 260 fatal("Must specify --caches when using --standard-switch") 261 262 np = options.num_cpus |
126 max_checkpoints = options.max_checkpoints | |
127 switch_cpus = None 128 129 if options.prog_interval: 130 for i in xrange(np): 131 testsys.cpu[i].progress_interval = options.prog_interval 132 133 if options.maxinsts: 134 for i in xrange(np): --- 89 unchanged lines hidden (view full) --- 224 options.take_checkpoints = offset 225 # Set all test cpus with the right number of instructions 226 # for the upcoming simulation 227 for i in xrange(np): 228 testsys.cpu[i].max_insts_any_thread = offset 229 230 checkpoint_dir = None 231 if options.checkpoint_restore != None: | 263 switch_cpus = None 264 265 if options.prog_interval: 266 for i in xrange(np): 267 testsys.cpu[i].progress_interval = options.prog_interval 268 269 if options.maxinsts: 270 for i in xrange(np): --- 89 unchanged lines hidden (view full) --- 360 options.take_checkpoints = offset 361 # Set all test cpus with the right number of instructions 362 # for the upcoming simulation 363 for i in xrange(np): 364 testsys.cpu[i].max_insts_any_thread = offset 365 366 checkpoint_dir = None 367 if options.checkpoint_restore != None: |
232 from os.path import isdir, exists 233 from os import listdir 234 import re 235 236 if not isdir(cptdir): 237 fatal("checkpoint dir %s does not exist!", cptdir) 238 239 if options.at_instruction or options.simpoint: 240 inst = options.checkpoint_restore 241 if options.simpoint: 242 # assume workload 0 has the simpoint 243 if testsys.cpu[0].workload[0].simpoint == 0: 244 fatal('Unable to find simpoint') 245 inst += int(testsys.cpu[0].workload[0].simpoint) 246 247 checkpoint_dir = joinpath(cptdir, 248 "cpt.%s.%s" % (options.bench, inst)) 249 if not exists(checkpoint_dir): 250 fatal("Unable to find checkpoint directory %s", checkpoint_dir) 251 else: 252 dirs = listdir(cptdir) 253 expr = re.compile('cpt\.([0-9]*)') 254 cpts = [] 255 for dir in dirs: 256 match = expr.match(dir) 257 if match: 258 cpts.append(match.group(1)) 259 260 cpts.sort(lambda a,b: cmp(long(a), long(b))) 261 262 cpt_num = options.checkpoint_restore 263 264 if cpt_num > len(cpts): 265 fatal('Checkpoint %d not found', cpt_num) 266 267 ## Adjust max tick based on our starting tick 268 maxtick = maxtick - int(cpts[cpt_num - 1]) 269 checkpoint_dir = joinpath(cptdir, "cpt.%s" % cpts[cpt_num - 1]) 270 | 368 maxtick, checkpoint_dir = findCptDir(options, maxtick, cptdir, testsys) |
271 m5.instantiate(checkpoint_dir) 272 273 if options.standard_switch or cpu_class: 274 if options.standard_switch: 275 print "Switch at instruction count:%s" % \ 276 str(testsys.cpu[0].max_insts_any_thread) 277 exit_event = m5.simulate() 278 elif cpu_class and options.fast_forward: --- 26 unchanged lines hidden (view full) --- 305 exit_event = m5.simulate(options.warmup) 306 print "Switching CPUS @ tick %s" % (m5.curTick()) 307 print "Simulation ends instruction count:%d" % \ 308 (testsys.switch_cpus_1[0].max_insts_any_thread) 309 m5.drain(testsys) 310 m5.switchCpus(switch_cpu_list1) 311 m5.resume(testsys) 312 | 369 m5.instantiate(checkpoint_dir) 370 371 if options.standard_switch or cpu_class: 372 if options.standard_switch: 373 print "Switch at instruction count:%s" % \ 374 str(testsys.cpu[0].max_insts_any_thread) 375 exit_event = m5.simulate() 376 elif cpu_class and options.fast_forward: --- 26 unchanged lines hidden (view full) --- 403 exit_event = m5.simulate(options.warmup) 404 print "Switching CPUS @ tick %s" % (m5.curTick()) 405 print "Simulation ends instruction count:%d" % \ 406 (testsys.switch_cpus_1[0].max_insts_any_thread) 407 m5.drain(testsys) 408 m5.switchCpus(switch_cpu_list1) 409 m5.resume(testsys) 410 |
313 num_checkpoints = 0 314 exit_cause = '' 315 | |
316 # If we're taking and restoring checkpoints, use checkpoint_dir 317 # option only for finding the checkpoints to restore from. This 318 # lets us test checkpointing by restoring from one set of 319 # checkpoints, generating a second set, and then comparing them. 320 if options.take_checkpoints and options.checkpoint_restore: 321 if m5.options.outdir: 322 cptdir = m5.options.outdir 323 else: 324 cptdir = getcwd() 325 | 411 # If we're taking and restoring checkpoints, use checkpoint_dir 412 # option only for finding the checkpoints to restore from. This 413 # lets us test checkpointing by restoring from one set of 414 # checkpoints, generating a second set, and then comparing them. 415 if options.take_checkpoints and options.checkpoint_restore: 416 if m5.options.outdir: 417 cptdir = m5.options.outdir 418 else: 419 cptdir = getcwd() 420 |
326 # Checkpoints being taken via the command line at <when> and at 327 # subsequent periods of <period>. Checkpoint instructions 328 # received from the benchmark running are ignored and skipped in 329 # favor of command line checkpoint instructions. | |
330 if options.take_checkpoints != None : | 421 if options.take_checkpoints != None : |
331 if options.at_instruction or options.simpoint: 332 checkpoint_inst = int(options.take_checkpoints) | 422 # Checkpoints being taken via the command line at <when> and at 423 # subsequent periods of <period>. Checkpoint instructions 424 # received from the benchmark running are ignored and skipped in 425 # favor of command line checkpoint instructions. 426 exit_cause = scriptCheckpoints(options) 427 else: 428 # If checkpoints are being taken, then the checkpoint instruction 429 # will occur in the benchmark code it self. 430 exit_cause = benchCheckpoints(options, maxtick, cptdir) |
333 | 431 |
334 # maintain correct offset if we restored from some instruction 335 if options.checkpoint_restore != None: 336 checkpoint_inst += options.checkpoint_restore 337 338 print "Creating checkpoint at inst:%d" % (checkpoint_inst) 339 exit_event = m5.simulate() 340 print "exit cause = %s" % (exit_event.getCause()) 341 342 # skip checkpoint instructions should they exist 343 while exit_event.getCause() == "checkpoint": 344 exit_event = m5.simulate() 345 346 if exit_event.getCause() == \ 347 "a thread reached the max instruction count": 348 m5.checkpoint(joinpath(cptdir, "cpt.%s.%d" % \ 349 (options.bench, checkpoint_inst))) 350 print "Checkpoint written." 351 num_checkpoints += 1 352 353 if exit_event.getCause() == "user interrupt received": 354 exit_cause = exit_event.getCause(); 355 else: 356 when, period = options.take_checkpoints.split(",", 1) 357 when = int(when) 358 period = int(period) 359 360 exit_event = m5.simulate(when) 361 while exit_event.getCause() == "checkpoint": 362 exit_event = m5.simulate(when - m5.curTick()) 363 364 if exit_event.getCause() == "simulate() limit reached": 365 m5.checkpoint(joinpath(cptdir, "cpt.%d")) 366 num_checkpoints += 1 367 368 sim_ticks = when 369 exit_cause = "maximum %d checkpoints dropped" % max_checkpoints 370 while num_checkpoints < max_checkpoints and \ 371 exit_event.getCause() == "simulate() limit reached": 372 if (sim_ticks + period) > maxtick: 373 exit_event = m5.simulate(maxtick - sim_ticks) 374 exit_cause = exit_event.getCause() 375 break 376 else: 377 exit_event = m5.simulate(period) 378 sim_ticks += period 379 while exit_event.getCause() == "checkpoint": 380 exit_event = m5.simulate(sim_ticks - m5.curTick()) 381 if exit_event.getCause() == "simulate() limit reached": 382 m5.checkpoint(joinpath(cptdir, "cpt.%d")) 383 num_checkpoints += 1 384 385 if exit_event.getCause() != "simulate() limit reached": 386 exit_cause = exit_event.getCause(); 387 388 else: # no checkpoints being taken via this script 389 if options.fast_forward: 390 m5.stats.reset() 391 print "**** REAL SIMULATION ****" 392 exit_event = m5.simulate(maxtick) 393 394 while exit_event.getCause() == "checkpoint": 395 m5.checkpoint(joinpath(cptdir, "cpt.%d")) 396 num_checkpoints += 1 397 if num_checkpoints == max_checkpoints: 398 exit_cause = "maximum %d checkpoints dropped" % max_checkpoints 399 break 400 401 exit_event = m5.simulate(maxtick - m5.curTick()) 402 exit_cause = exit_event.getCause() 403 404 if exit_cause == '': 405 exit_cause = exit_event.getCause() | |
406 print 'Exiting @ tick %i because %s' % (m5.curTick(), exit_cause) | 432 print 'Exiting @ tick %i because %s' % (m5.curTick(), exit_cause) |
407 | |
408 if options.checkpoint_at_end: 409 m5.checkpoint(joinpath(cptdir, "cpt.%d")) | 433 if options.checkpoint_at_end: 434 m5.checkpoint(joinpath(cptdir, "cpt.%d")) |
410 | |