Simulation.py revision 3410:ef75e2c78b2d
16657Snate@binkert.org# Copyright (c) 2006 The Regents of The University of Michigan 26657Snate@binkert.org# All rights reserved. 36657Snate@binkert.org# 46657Snate@binkert.org# Redistribution and use in source and binary forms, with or without 56657Snate@binkert.org# modification, are permitted provided that the following conditions are 66657Snate@binkert.org# met: redistributions of source code must retain the above copyright 76657Snate@binkert.org# notice, this list of conditions and the following disclaimer; 86657Snate@binkert.org# redistributions in binary form must reproduce the above copyright 96657Snate@binkert.org# notice, this list of conditions and the following disclaimer in the 106657Snate@binkert.org# documentation and/or other materials provided with the distribution; 116657Snate@binkert.org# neither the name of the copyright holders nor the names of its 126657Snate@binkert.org# contributors may be used to endorse or promote products derived from 136657Snate@binkert.org# this software without specific prior written permission. 146657Snate@binkert.org# 156657Snate@binkert.org# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 166657Snate@binkert.org# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 176657Snate@binkert.org# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 186657Snate@binkert.org# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 196657Snate@binkert.org# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 206657Snate@binkert.org# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 216657Snate@binkert.org# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 226657Snate@binkert.org# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 236657Snate@binkert.org# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 246657Snate@binkert.org# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 256657Snate@binkert.org# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 266657Snate@binkert.org# 276657Snate@binkert.org# Authors: Lisa Hsu 286999Snate@binkert.org 296657Snate@binkert.orgfrom os import getcwd 306657Snate@binkert.orgimport m5 316657Snate@binkert.orgfrom m5.objects import * 326657Snate@binkert.orgm5.AddToPath('../common') 338189SLisa.Hsu@amd.comfrom Caches import * 346657Snate@binkert.org 359499Snilay@cs.wisc.edudef run(options, root, testsys): 369499Snilay@cs.wisc.edu if options.maxtick: 379364Snilay@cs.wisc.edu maxtick = options.maxtick 387055Snate@binkert.org elif options.maxtime: 396882SBrad.Beckmann@amd.com simtime = int(options.maxtime * root.clock.value) 406882SBrad.Beckmann@amd.com print "simulating for: ", simtime 418191SLisa.Hsu@amd.com maxtick = simtime 426882SBrad.Beckmann@amd.com else: 436882SBrad.Beckmann@amd.com maxtick = -1 449102SNuwan.Jayasena@amd.com 459366Snilay@cs.wisc.edu if options.checkpoint_dir: 469499Snilay@cs.wisc.edu cptdir = options.checkpoint_dir 479499Snilay@cs.wisc.edu else: 489499Snilay@cs.wisc.edu cptdir = getcwd() 496882SBrad.Beckmann@amd.com 506657Snate@binkert.org np = options.num_cpus 516657Snate@binkert.org max_checkpoints = options.max_checkpoints 526657Snate@binkert.org 536657Snate@binkert.org if options.standard_switch: 546657Snate@binkert.org switch_cpus = [TimingSimpleCPU(defer_registration=True, cpu_id=(np+i)) 559366Snilay@cs.wisc.edu for i in xrange(np)] 567839Snilay@cs.wisc.edu switch_cpus1 = [DerivO3CPU(defer_registration=True, cpu_id=(2*np+i)) 576657Snate@binkert.org for i in xrange(np)] 586882SBrad.Beckmann@amd.com for i in xrange(np): 596882SBrad.Beckmann@amd.com switch_cpus[i].system = testsys 606882SBrad.Beckmann@amd.com switch_cpus1[i].system = testsys 616882SBrad.Beckmann@amd.com if not m5.build_env['FULL_SYSTEM']: 626882SBrad.Beckmann@amd.com switch_cpus[i].workload = testsys.cpu[i].workload 636882SBrad.Beckmann@amd.com switch_cpus1[i].workload = testsys.cpu[i].workload 646657Snate@binkert.org switch_cpus[i].clock = testsys.cpu[0].clock 659366Snilay@cs.wisc.edu switch_cpus1[i].clock = testsys.cpu[0].clock 669366Snilay@cs.wisc.edu if options.caches: 676657Snate@binkert.org switch_cpus[i].addPrivateSplitL1Caches(L1Cache(size = '32kB'), 686657Snate@binkert.org L1Cache(size = '64kB')) 696657Snate@binkert.org 706657Snate@binkert.org switch_cpus[i].mem = testsys.physmem 719104Shestness@cs.utexas.edu switch_cpus1[i].mem = testsys.physmem 726657Snate@binkert.org switch_cpus[i].connectMemPorts(testsys.membus) 736657Snate@binkert.org root.switch_cpus = switch_cpus 746657Snate@binkert.org root.switch_cpus1 = switch_cpus1 756657Snate@binkert.org switch_cpu_list = [(testsys.cpu[i], switch_cpus[i]) for i in xrange(np)] 767839Snilay@cs.wisc.edu switch_cpu_list1 = [(switch_cpus[i], switch_cpus1[i]) for i in xrange(np)] 777839Snilay@cs.wisc.edu 786657Snate@binkert.org m5.instantiate(root) 796657Snate@binkert.org 806657Snate@binkert.org if options.checkpoint_restore: 816657Snate@binkert.org from os.path import isdir 826657Snate@binkert.org from os import listdir 836657Snate@binkert.org import re 846657Snate@binkert.org 856657Snate@binkert.org if not isdir(cptdir): 866657Snate@binkert.org m5.panic("checkpoint dir %s does not exist!" % cptdir) 876657Snate@binkert.org 886657Snate@binkert.org dirs = listdir(cptdir) 896657Snate@binkert.org expr = re.compile('cpt.([0-9]*)') 906657Snate@binkert.org cpts = [] 916657Snate@binkert.org for dir in dirs: 926657Snate@binkert.org match = expr.match(dir) 936657Snate@binkert.org if match: 946657Snate@binkert.org cpts.append(match.group(1)) 956657Snate@binkert.org 966779SBrad.Beckmann@amd.com cpts.sort(lambda a,b: cmp(long(a), long(b))) 976657Snate@binkert.org 986657Snate@binkert.org cpt_num = options.checkpoint_restore 996657Snate@binkert.org 1006657Snate@binkert.org if cpt_num > len(cpts): 1016657Snate@binkert.org m5.panic('Checkpoint %d not found' % cpt_num) 1026657Snate@binkert.org 1036657Snate@binkert.org m5.restoreCheckpoint(root, 1046657Snate@binkert.org "/".join([cptdir, "cpt.%s" % cpts[cpt_num - 1]])) 1056657Snate@binkert.org 1069104Shestness@cs.utexas.edu if options.standard_switch: 1079104Shestness@cs.utexas.edu exit_event = m5.simulate(10000) 1089104Shestness@cs.utexas.edu 1099104Shestness@cs.utexas.edu ## when you change to Timing (or Atomic), you halt the system given 1106657Snate@binkert.org ## as argument. When you are finished with the system changes 1116657Snate@binkert.org ## (including switchCpus), you must resume the system manually. 1126657Snate@binkert.org ## You DON'T need to resume after just switching CPUs if you haven't 1136657Snate@binkert.org ## changed anything on the system level. 1146657Snate@binkert.org 1156657Snate@binkert.org m5.changeToTiming(testsys) 1166657Snate@binkert.org m5.switchCpus(switch_cpu_list) 1176657Snate@binkert.org m5.resume(testsys) 1186657Snate@binkert.org 1196657Snate@binkert.org exit_event = m5.simulate(options.standard_switch) 1206657Snate@binkert.org m5.switchCpus(switch_cpu_list1) 1216657Snate@binkert.org 1226657Snate@binkert.org num_checkpoints = 0 1236657Snate@binkert.org exit_cause = '' 1246657Snate@binkert.org 1257839Snilay@cs.wisc.edu ## Checkpoints being taken via the command line at <when> and at subsequent 1267839Snilay@cs.wisc.edu ## periods of <period>. Checkpoint instructions received from the benchmark running 1277839Snilay@cs.wisc.edu ## are ignored and skipped in favor of command line checkpoint instructions. 1287839Snilay@cs.wisc.edu if options.take_checkpoints: 1297839Snilay@cs.wisc.edu [when, period] = options.take_checkpoints.split(",", 1) 1307839Snilay@cs.wisc.edu when = int(when) 1317839Snilay@cs.wisc.edu period = int(period) 1327839Snilay@cs.wisc.edu 1337839Snilay@cs.wisc.edu print "when is ", when, " period is ", period 1347839Snilay@cs.wisc.edu exit_event = m5.simulate(when) 1357839Snilay@cs.wisc.edu while exit_event.getCause() == "checkpoint": 1367839Snilay@cs.wisc.edu exit_event = m5.simulate(when - m5.curTick()) 1377839Snilay@cs.wisc.edu 1387839Snilay@cs.wisc.edu if exit_event.getCause() == "simulate() limit reached": 1397839Snilay@cs.wisc.edu m5.checkpoint(root, cptdir + "cpt.%d") 1406657Snate@binkert.org num_checkpoints += 1 1416657Snate@binkert.org 1426657Snate@binkert.org sim_ticks = when 1436657Snate@binkert.org exit_cause = "maximum %d checkpoints dropped" % max_checkpoints 1446657Snate@binkert.org while num_checkpoints < max_checkpoints: 1456657Snate@binkert.org if (sim_ticks + period) > maxtick and maxtick != -1: 1466657Snate@binkert.org exit_event = m5.simulate(maxtick - sim_ticks) 1476657Snate@binkert.org exit_cause = exit_event.getCause() 1486657Snate@binkert.org break 1496657Snate@binkert.org else: 1506657Snate@binkert.org exit_event = m5.simulate(period) 1516657Snate@binkert.org sim_ticks += period 1526657Snate@binkert.org while exit_event.getCause() == "checkpoint": 1536657Snate@binkert.org exit_event = m5.simulate(sim_ticks - m5.curTick()) 1546657Snate@binkert.org if exit_event.getCause() == "simulate() limit reached": 1556657Snate@binkert.org m5.checkpoint(root, cptdir + "cpt.%d") 1566657Snate@binkert.org num_checkpoints += 1 1576657Snate@binkert.org 1586657Snate@binkert.org else: #no checkpoints being taken via this script 1596657Snate@binkert.org exit_event = m5.simulate(maxtick) 1606657Snate@binkert.org 1616657Snate@binkert.org while exit_event.getCause() == "checkpoint": 1626657Snate@binkert.org m5.checkpoint(root, cptdir + "cpt.%d") 1636657Snate@binkert.org num_checkpoints += 1 1646657Snate@binkert.org if num_checkpoints == max_checkpoints: 1656657Snate@binkert.org exit_cause = "maximum %d checkpoints dropped" % max_checkpoints 1666657Snate@binkert.org break 1676657Snate@binkert.org 1686657Snate@binkert.org if maxtick == -1: 1696657Snate@binkert.org exit_event = m5.simulate(maxtick) 1709219Spower.jg@gmail.com else: 1716877Ssteve.reinhardt@amd.com exit_event = m5.simulate(maxtick - m5.curTick()) 1726657Snate@binkert.org 1739219Spower.jg@gmail.com exit_cause = exit_event.getCause() 1746657Snate@binkert.org 1759219Spower.jg@gmail.com if exit_cause == '': 1766657Snate@binkert.org exit_cause = exit_event.getCause() 1776877Ssteve.reinhardt@amd.com print 'Exiting @ cycle', m5.curTick(), 'because ', exit_cause 1786999Snate@binkert.org 1796877Ssteve.reinhardt@amd.com