Simulation.py revision 6641
15347Ssaidi@eecs.umich.edu# Copyright (c) 2006-2008 The Regents of The University of Michigan
23395Shsul@eecs.umich.edu# All rights reserved.
33395Shsul@eecs.umich.edu#
43395Shsul@eecs.umich.edu# Redistribution and use in source and binary forms, with or without
53395Shsul@eecs.umich.edu# modification, are permitted provided that the following conditions are
63395Shsul@eecs.umich.edu# met: redistributions of source code must retain the above copyright
73395Shsul@eecs.umich.edu# notice, this list of conditions and the following disclaimer;
83395Shsul@eecs.umich.edu# redistributions in binary form must reproduce the above copyright
93395Shsul@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the
103395Shsul@eecs.umich.edu# documentation and/or other materials provided with the distribution;
113395Shsul@eecs.umich.edu# neither the name of the copyright holders nor the names of its
123395Shsul@eecs.umich.edu# contributors may be used to endorse or promote products derived from
133395Shsul@eecs.umich.edu# this software without specific prior written permission.
143395Shsul@eecs.umich.edu#
153395Shsul@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
163395Shsul@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
173395Shsul@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
183395Shsul@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
193395Shsul@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
203395Shsul@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
213395Shsul@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
223395Shsul@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
233395Shsul@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
243395Shsul@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
253395Shsul@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
263395Shsul@eecs.umich.edu#
273395Shsul@eecs.umich.edu# Authors: Lisa Hsu
283395Shsul@eecs.umich.edu
293395Shsul@eecs.umich.edufrom os import getcwd
303509Shsul@eecs.umich.edufrom os.path import join as joinpath
313395Shsul@eecs.umich.eduimport m5
323395Shsul@eecs.umich.edufrom m5.objects import *
333395Shsul@eecs.umich.edum5.AddToPath('../common')
343395Shsul@eecs.umich.edu
353481Shsul@eecs.umich.edudef setCPUClass(options):
363481Shsul@eecs.umich.edu
373481Shsul@eecs.umich.edu    atomic = False
383481Shsul@eecs.umich.edu    if options.timing:
395347Ssaidi@eecs.umich.edu        class TmpClass(TimingSimpleCPU): pass
403481Shsul@eecs.umich.edu    elif options.detailed:
413681Sktlim@umich.edu        if not options.caches:
423681Sktlim@umich.edu            print "O3 CPU must be used with caches"
433681Sktlim@umich.edu            sys.exit(1)
445347Ssaidi@eecs.umich.edu        class TmpClass(DerivO3CPU): pass
455869Sksewell@umich.edu    elif options.inorder:
465869Sksewell@umich.edu        if not options.caches:
475869Sksewell@umich.edu            print "InOrder CPU must be used with caches"
485869Sksewell@umich.edu            sys.exit(1)
495869Sksewell@umich.edu        class TmpClass(InOrderCPU): pass
503481Shsul@eecs.umich.edu    else:
515347Ssaidi@eecs.umich.edu        class TmpClass(AtomicSimpleCPU): pass
523481Shsul@eecs.umich.edu        atomic = True
533481Shsul@eecs.umich.edu
543481Shsul@eecs.umich.edu    CPUClass = None
553481Shsul@eecs.umich.edu    test_mem_mode = 'atomic'
563481Shsul@eecs.umich.edu
573481Shsul@eecs.umich.edu    if not atomic:
585369Ssaidi@eecs.umich.edu        if options.checkpoint_restore != None or options.fast_forward:
593481Shsul@eecs.umich.edu            CPUClass = TmpClass
605347Ssaidi@eecs.umich.edu            class TmpClass(AtomicSimpleCPU): pass
613481Shsul@eecs.umich.edu        else:
623481Shsul@eecs.umich.edu            test_mem_mode = 'timing'
633481Shsul@eecs.umich.edu
643481Shsul@eecs.umich.edu    return (TmpClass, test_mem_mode, CPUClass)
653481Shsul@eecs.umich.edu
663481Shsul@eecs.umich.edu
673481Shsul@eecs.umich.edudef run(options, root, testsys, cpu_class):
683395Shsul@eecs.umich.edu    if options.maxtick:
693395Shsul@eecs.umich.edu        maxtick = options.maxtick
703395Shsul@eecs.umich.edu    elif options.maxtime:
714167Sbinkertn@umich.edu        simtime = m5.ticks.seconds(simtime)
723395Shsul@eecs.umich.edu        print "simulating for: ", simtime
733395Shsul@eecs.umich.edu        maxtick = simtime
743395Shsul@eecs.umich.edu    else:
753511Shsul@eecs.umich.edu        maxtick = m5.MaxTick
763395Shsul@eecs.umich.edu
773395Shsul@eecs.umich.edu    if options.checkpoint_dir:
783395Shsul@eecs.umich.edu        cptdir = options.checkpoint_dir
795211Ssaidi@eecs.umich.edu    elif m5.options.outdir:
805211Ssaidi@eecs.umich.edu        cptdir = m5.options.outdir
813395Shsul@eecs.umich.edu    else:
823395Shsul@eecs.umich.edu        cptdir = getcwd()
833395Shsul@eecs.umich.edu
845370Ssaidi@eecs.umich.edu    if options.fast_forward and options.checkpoint_restore != None:
855822Ssaidi@eecs.umich.edu        m5.fatal("Error: Can't specify both --fast-forward and --checkpoint-restore")
865370Ssaidi@eecs.umich.edu
875371Shsul@eecs.umich.edu    if options.standard_switch and not options.caches:
885822Ssaidi@eecs.umich.edu        m5.fatal("Error: Must specify --caches when using --standard-switch")
895370Ssaidi@eecs.umich.edu
903395Shsul@eecs.umich.edu    np = options.num_cpus
913395Shsul@eecs.umich.edu    max_checkpoints = options.max_checkpoints
923481Shsul@eecs.umich.edu    switch_cpus = None
933481Shsul@eecs.umich.edu
946144Sksewell@umich.edu    if options.prog_intvl:
956144Sksewell@umich.edu        for i in xrange(np):
966144Sksewell@umich.edu            testsys.cpu[i].progress_interval = options.prog_intvl
976144Sksewell@umich.edu
986641Sksewell@umich.edu    if options.maxinsts:
996641Sksewell@umich.edu        for i in xrange(np):
1006641Sksewell@umich.edu            testsys.cpu[i].max_insts_any_thread = options.maxinsts
1016641Sksewell@umich.edu
1023481Shsul@eecs.umich.edu    if cpu_class:
1033481Shsul@eecs.umich.edu        switch_cpus = [cpu_class(defer_registration=True, cpu_id=(np+i))
1043481Shsul@eecs.umich.edu                       for i in xrange(np)]
1053481Shsul@eecs.umich.edu
1063481Shsul@eecs.umich.edu        for i in xrange(np):
1075361Srstrong@cs.ucsd.edu            if options.fast_forward:
1085369Ssaidi@eecs.umich.edu                testsys.cpu[i].max_insts_any_thread = int(options.fast_forward)
1093481Shsul@eecs.umich.edu            switch_cpus[i].system =  testsys
1103481Shsul@eecs.umich.edu            if not m5.build_env['FULL_SYSTEM']:
1113481Shsul@eecs.umich.edu                switch_cpus[i].workload = testsys.cpu[i].workload
1123481Shsul@eecs.umich.edu            switch_cpus[i].clock = testsys.cpu[0].clock
1135369Ssaidi@eecs.umich.edu            # simulation period
1145369Ssaidi@eecs.umich.edu            if options.max_inst:
1155369Ssaidi@eecs.umich.edu                switch_cpus[i].max_insts_any_thread = options.max_inst
1163481Shsul@eecs.umich.edu
1175311Ssaidi@eecs.umich.edu        testsys.switch_cpus = switch_cpus
1183481Shsul@eecs.umich.edu        switch_cpu_list = [(testsys.cpu[i], switch_cpus[i]) for i in xrange(np)]
1193395Shsul@eecs.umich.edu
1203395Shsul@eecs.umich.edu    if options.standard_switch:
1213395Shsul@eecs.umich.edu        switch_cpus = [TimingSimpleCPU(defer_registration=True, cpu_id=(np+i))
1223395Shsul@eecs.umich.edu                       for i in xrange(np)]
1233478Shsul@eecs.umich.edu        switch_cpus_1 = [DerivO3CPU(defer_registration=True, cpu_id=(2*np+i))
1243395Shsul@eecs.umich.edu                        for i in xrange(np)]
1253478Shsul@eecs.umich.edu
1263395Shsul@eecs.umich.edu        for i in xrange(np):
1273395Shsul@eecs.umich.edu            switch_cpus[i].system =  testsys
1283478Shsul@eecs.umich.edu            switch_cpus_1[i].system =  testsys
1293395Shsul@eecs.umich.edu            if not m5.build_env['FULL_SYSTEM']:
1303395Shsul@eecs.umich.edu                switch_cpus[i].workload = testsys.cpu[i].workload
1313478Shsul@eecs.umich.edu                switch_cpus_1[i].workload = testsys.cpu[i].workload
1323395Shsul@eecs.umich.edu            switch_cpus[i].clock = testsys.cpu[0].clock
1333478Shsul@eecs.umich.edu            switch_cpus_1[i].clock = testsys.cpu[0].clock
1343480Shsul@eecs.umich.edu
1355361Srstrong@cs.ucsd.edu            # if restoring, make atomic cpu simulate only a few instructions
1365369Ssaidi@eecs.umich.edu            if options.checkpoint_restore != None:
1375361Srstrong@cs.ucsd.edu                testsys.cpu[i].max_insts_any_thread = 1
1385361Srstrong@cs.ucsd.edu            # Fast forward to specified location if we are not restoring
1395361Srstrong@cs.ucsd.edu            elif options.fast_forward:
1405369Ssaidi@eecs.umich.edu                testsys.cpu[i].max_insts_any_thread = int(options.fast_forward)
1415361Srstrong@cs.ucsd.edu            # Fast forward to a simpoint (warning: time consuming)
1425361Srstrong@cs.ucsd.edu            elif options.simpoint:
1435378Ssaidi@eecs.umich.edu                if testsys.cpu[i].workload[0].simpoint == 0:
1445822Ssaidi@eecs.umich.edu                    m5.fatal('simpoint not found')
1455361Srstrong@cs.ucsd.edu                testsys.cpu[i].max_insts_any_thread = \
1465361Srstrong@cs.ucsd.edu                    testsys.cpu[i].workload[0].simpoint
1475361Srstrong@cs.ucsd.edu            # No distance specified, just switch
1485361Srstrong@cs.ucsd.edu            else:
1495361Srstrong@cs.ucsd.edu                testsys.cpu[i].max_insts_any_thread = 1
1505361Srstrong@cs.ucsd.edu
1515361Srstrong@cs.ucsd.edu            # warmup period
1525361Srstrong@cs.ucsd.edu            if options.warmup_insts:
1535361Srstrong@cs.ucsd.edu                switch_cpus[i].max_insts_any_thread =  options.warmup_insts
1545361Srstrong@cs.ucsd.edu
1555361Srstrong@cs.ucsd.edu            # simulation period
1565353Svilas.sridharan@gmail.com            if options.max_inst:
1575353Svilas.sridharan@gmail.com                switch_cpus_1[i].max_insts_any_thread = options.max_inst
1585353Svilas.sridharan@gmail.com
1593514Sktlim@umich.edu            if not options.caches:
1603481Shsul@eecs.umich.edu                # O3 CPU must have a cache to work.
1616107Ssteve.reinhardt@amd.com                print "O3 CPU must be used with caches"
1626107Ssteve.reinhardt@amd.com                sys.exit(1)
1633395Shsul@eecs.umich.edu
1643514Sktlim@umich.edu            testsys.switch_cpus = switch_cpus
1653514Sktlim@umich.edu            testsys.switch_cpus_1 = switch_cpus_1
1663395Shsul@eecs.umich.edu            switch_cpu_list = [(testsys.cpu[i], switch_cpus[i]) for i in xrange(np)]
1673478Shsul@eecs.umich.edu            switch_cpu_list1 = [(switch_cpus[i], switch_cpus_1[i]) for i in xrange(np)]
1683395Shsul@eecs.umich.edu
1695361Srstrong@cs.ucsd.edu    # set the checkpoint in the cpu before m5.instantiate is called
1705369Ssaidi@eecs.umich.edu    if options.take_checkpoints != None and \
1715361Srstrong@cs.ucsd.edu           (options.simpoint or options.at_instruction):
1725361Srstrong@cs.ucsd.edu        offset = int(options.take_checkpoints)
1735361Srstrong@cs.ucsd.edu        # Set an instruction break point
1745361Srstrong@cs.ucsd.edu        if options.simpoint:
1755361Srstrong@cs.ucsd.edu            for i in xrange(np):
1765378Ssaidi@eecs.umich.edu                if testsys.cpu[i].workload[0].simpoint == 0:
1775822Ssaidi@eecs.umich.edu                    m5.fatal('no simpoint for testsys.cpu[%d].workload[0]', i)
1785369Ssaidi@eecs.umich.edu                checkpoint_inst = int(testsys.cpu[i].workload[0].simpoint) + offset
1795361Srstrong@cs.ucsd.edu                testsys.cpu[i].max_insts_any_thread = checkpoint_inst
1805361Srstrong@cs.ucsd.edu                # used for output below
1815361Srstrong@cs.ucsd.edu                options.take_checkpoints = checkpoint_inst
1825361Srstrong@cs.ucsd.edu        else:
1835361Srstrong@cs.ucsd.edu            options.take_checkpoints = offset
1845361Srstrong@cs.ucsd.edu            # Set all test cpus with the right number of instructions
1855361Srstrong@cs.ucsd.edu            # for the upcoming simulation
1865361Srstrong@cs.ucsd.edu            for i in xrange(np):
1875361Srstrong@cs.ucsd.edu                testsys.cpu[i].max_insts_any_thread = offset
1885361Srstrong@cs.ucsd.edu
1893395Shsul@eecs.umich.edu    m5.instantiate(root)
1903395Shsul@eecs.umich.edu
1915369Ssaidi@eecs.umich.edu    if options.checkpoint_restore != None:
1925361Srstrong@cs.ucsd.edu        from os.path import isdir, exists
1933395Shsul@eecs.umich.edu        from os import listdir
1943395Shsul@eecs.umich.edu        import re
1953395Shsul@eecs.umich.edu
1963395Shsul@eecs.umich.edu        if not isdir(cptdir):
1975822Ssaidi@eecs.umich.edu            m5.fatal("checkpoint dir %s does not exist!", cptdir)
1983395Shsul@eecs.umich.edu
1995361Srstrong@cs.ucsd.edu        if options.at_instruction:
2005361Srstrong@cs.ucsd.edu            checkpoint_dir = joinpath(cptdir, "cpt.%s.%s" % \
2015361Srstrong@cs.ucsd.edu                    (options.bench, options.checkpoint_restore))
2025361Srstrong@cs.ucsd.edu            if not exists(checkpoint_dir):
2035822Ssaidi@eecs.umich.edu                m5.fatal("Unable to find checkpoint directory %s",
2045361Srstrong@cs.ucsd.edu                         checkpoint_dir)
2053395Shsul@eecs.umich.edu
2065361Srstrong@cs.ucsd.edu            print "Restoring checkpoint ..."
2075361Srstrong@cs.ucsd.edu            m5.restoreCheckpoint(root, checkpoint_dir)
2085361Srstrong@cs.ucsd.edu            print "Done."
2095361Srstrong@cs.ucsd.edu        elif options.simpoint:
2105361Srstrong@cs.ucsd.edu            # assume workload 0 has the simpoint
2115378Ssaidi@eecs.umich.edu            if testsys.cpu[0].workload[0].simpoint == 0:
2125822Ssaidi@eecs.umich.edu                m5.fatal('Unable to find simpoint')
2133395Shsul@eecs.umich.edu
2145361Srstrong@cs.ucsd.edu            options.checkpoint_restore += \
2155369Ssaidi@eecs.umich.edu                int(testsys.cpu[0].workload[0].simpoint)
2163395Shsul@eecs.umich.edu
2175361Srstrong@cs.ucsd.edu            checkpoint_dir = joinpath(cptdir, "cpt.%s.%d" % \
2185361Srstrong@cs.ucsd.edu                    (options.bench, options.checkpoint_restore))
2195361Srstrong@cs.ucsd.edu            if not exists(checkpoint_dir):
2205822Ssaidi@eecs.umich.edu                m5.fatal("Unable to find checkpoint directory %s.%s",
2215822Ssaidi@eecs.umich.edu                        options.bench, options.checkpoint_restore)
2223395Shsul@eecs.umich.edu
2235361Srstrong@cs.ucsd.edu            print "Restoring checkpoint ..."
2245361Srstrong@cs.ucsd.edu            m5.restoreCheckpoint(root,checkpoint_dir)
2255361Srstrong@cs.ucsd.edu            print "Done."
2265361Srstrong@cs.ucsd.edu        else:
2275361Srstrong@cs.ucsd.edu            dirs = listdir(cptdir)
2285361Srstrong@cs.ucsd.edu            expr = re.compile('cpt\.([0-9]*)')
2295361Srstrong@cs.ucsd.edu            cpts = []
2305361Srstrong@cs.ucsd.edu            for dir in dirs:
2315361Srstrong@cs.ucsd.edu                match = expr.match(dir)
2325361Srstrong@cs.ucsd.edu                if match:
2335361Srstrong@cs.ucsd.edu                    cpts.append(match.group(1))
2343999Ssaidi@eecs.umich.edu
2355361Srstrong@cs.ucsd.edu            cpts.sort(lambda a,b: cmp(long(a), long(b)))
2365361Srstrong@cs.ucsd.edu
2375361Srstrong@cs.ucsd.edu            cpt_num = options.checkpoint_restore
2385361Srstrong@cs.ucsd.edu
2395361Srstrong@cs.ucsd.edu            if cpt_num > len(cpts):
2405822Ssaidi@eecs.umich.edu                m5.fatal('Checkpoint %d not found', cpt_num)
2415361Srstrong@cs.ucsd.edu
2425361Srstrong@cs.ucsd.edu            ## Adjust max tick based on our starting tick
2435361Srstrong@cs.ucsd.edu            maxtick = maxtick - int(cpts[cpt_num - 1])
2445361Srstrong@cs.ucsd.edu
2455361Srstrong@cs.ucsd.edu            ## Restore the checkpoint
2465361Srstrong@cs.ucsd.edu            m5.restoreCheckpoint(root,
2475361Srstrong@cs.ucsd.edu                    joinpath(cptdir, "cpt.%s" % cpts[cpt_num - 1]))
2483395Shsul@eecs.umich.edu
2493481Shsul@eecs.umich.edu    if options.standard_switch or cpu_class:
2505361Srstrong@cs.ucsd.edu        if options.standard_switch:
2515361Srstrong@cs.ucsd.edu            print "Switch at instruction count:%s" % \
2525361Srstrong@cs.ucsd.edu                    str(testsys.cpu[0].max_insts_any_thread)
2535361Srstrong@cs.ucsd.edu            exit_event = m5.simulate()
2545361Srstrong@cs.ucsd.edu        elif cpu_class and options.fast_forward:
2555361Srstrong@cs.ucsd.edu            print "Switch at instruction count:%s" % \
2565361Srstrong@cs.ucsd.edu                    str(testsys.cpu[0].max_insts_any_thread)
2575361Srstrong@cs.ucsd.edu            exit_event = m5.simulate()
2585361Srstrong@cs.ucsd.edu        else:
2595361Srstrong@cs.ucsd.edu            print "Switch at curTick count:%s" % str(10000)
2605361Srstrong@cs.ucsd.edu            exit_event = m5.simulate(10000)
2615361Srstrong@cs.ucsd.edu        print "Switched CPUS @ cycle = %s" % (m5.curTick())
2623395Shsul@eecs.umich.edu
2635361Srstrong@cs.ucsd.edu        # when you change to Timing (or Atomic), you halt the system
2645361Srstrong@cs.ucsd.edu        # given as argument.  When you are finished with the system
2655361Srstrong@cs.ucsd.edu        # changes (including switchCpus), you must resume the system
2665361Srstrong@cs.ucsd.edu        # manually.  You DON'T need to resume after just switching
2675361Srstrong@cs.ucsd.edu        # CPUs if you haven't changed anything on the system level.
2683395Shsul@eecs.umich.edu
2693395Shsul@eecs.umich.edu        m5.changeToTiming(testsys)
2703395Shsul@eecs.umich.edu        m5.switchCpus(switch_cpu_list)
2713395Shsul@eecs.umich.edu        m5.resume(testsys)
2723395Shsul@eecs.umich.edu
2733481Shsul@eecs.umich.edu        if options.standard_switch:
2745361Srstrong@cs.ucsd.edu            print "Switch at instruction count:%d" % \
2755361Srstrong@cs.ucsd.edu                    (testsys.switch_cpus[0].max_insts_any_thread)
2765361Srstrong@cs.ucsd.edu
2775361Srstrong@cs.ucsd.edu            #warmup instruction count may have already been set
2785361Srstrong@cs.ucsd.edu            if options.warmup_insts:
2795361Srstrong@cs.ucsd.edu                exit_event = m5.simulate()
2805361Srstrong@cs.ucsd.edu            else:
2815353Svilas.sridharan@gmail.com                exit_event = m5.simulate(options.warmup)
2825361Srstrong@cs.ucsd.edu            print "Switching CPUS @ cycle = %s" % (m5.curTick())
2835361Srstrong@cs.ucsd.edu            print "Simulation ends instruction count:%d" % \
2845361Srstrong@cs.ucsd.edu                    (testsys.switch_cpus_1[0].max_insts_any_thread)
2855072Ssaidi@eecs.umich.edu            m5.drain(testsys)
2863481Shsul@eecs.umich.edu            m5.switchCpus(switch_cpu_list1)
2875072Ssaidi@eecs.umich.edu            m5.resume(testsys)
2883395Shsul@eecs.umich.edu
2893395Shsul@eecs.umich.edu    num_checkpoints = 0
2903395Shsul@eecs.umich.edu    exit_cause = ''
2913395Shsul@eecs.umich.edu
2925361Srstrong@cs.ucsd.edu    # Checkpoints being taken via the command line at <when> and at
2935361Srstrong@cs.ucsd.edu    # subsequent periods of <period>.  Checkpoint instructions
2945361Srstrong@cs.ucsd.edu    # received from the benchmark running are ignored and skipped in
2955361Srstrong@cs.ucsd.edu    # favor of command line checkpoint instructions.
2965369Ssaidi@eecs.umich.edu    if options.take_checkpoints != None :
2975361Srstrong@cs.ucsd.edu        if options.at_instruction or options.simpoint:
2985369Ssaidi@eecs.umich.edu            checkpoint_inst = int(options.take_checkpoints)
2993395Shsul@eecs.umich.edu
3005361Srstrong@cs.ucsd.edu            # maintain correct offset if we restored from some instruction
3015369Ssaidi@eecs.umich.edu            if options.checkpoint_restore != None:
3025361Srstrong@cs.ucsd.edu                checkpoint_inst += options.checkpoint_restore
3033395Shsul@eecs.umich.edu
3045361Srstrong@cs.ucsd.edu            print "Creating checkpoint at inst:%d" % (checkpoint_inst)
3055361Srstrong@cs.ucsd.edu            exit_event = m5.simulate()
3065361Srstrong@cs.ucsd.edu            print "exit cause = %s" % (exit_event.getCause())
3073395Shsul@eecs.umich.edu
3085361Srstrong@cs.ucsd.edu            # skip checkpoint instructions should they exist
3095361Srstrong@cs.ucsd.edu            while exit_event.getCause() == "checkpoint":
3105361Srstrong@cs.ucsd.edu                exit_event = m5.simulate()
3113999Ssaidi@eecs.umich.edu
3125361Srstrong@cs.ucsd.edu            if exit_event.getCause() == \
3135361Srstrong@cs.ucsd.edu                   "a thread reached the max instruction count":
3145361Srstrong@cs.ucsd.edu                m5.checkpoint(root, joinpath(cptdir, "cpt.%s.%d" % \
3155361Srstrong@cs.ucsd.edu                        (options.bench, checkpoint_inst)))
3165361Srstrong@cs.ucsd.edu                print "Checkpoint written."
3175361Srstrong@cs.ucsd.edu                num_checkpoints += 1
3183999Ssaidi@eecs.umich.edu
3195361Srstrong@cs.ucsd.edu            if exit_event.getCause() == "user interrupt received":
3205361Srstrong@cs.ucsd.edu                exit_cause = exit_event.getCause();
3215361Srstrong@cs.ucsd.edu        else:
3225369Ssaidi@eecs.umich.edu            when, period = options.take_checkpoints.split(",", 1)
3235369Ssaidi@eecs.umich.edu            when = int(when)
3245369Ssaidi@eecs.umich.edu            period = int(period)
3255369Ssaidi@eecs.umich.edu
3265361Srstrong@cs.ucsd.edu            exit_event = m5.simulate(when)
3275361Srstrong@cs.ucsd.edu            while exit_event.getCause() == "checkpoint":
3285361Srstrong@cs.ucsd.edu                exit_event = m5.simulate(when - m5.curTick())
3295361Srstrong@cs.ucsd.edu
3305361Srstrong@cs.ucsd.edu            if exit_event.getCause() == "simulate() limit reached":
3315361Srstrong@cs.ucsd.edu                m5.checkpoint(root, joinpath(cptdir, "cpt.%d"))
3325361Srstrong@cs.ucsd.edu                num_checkpoints += 1
3335361Srstrong@cs.ucsd.edu
3345361Srstrong@cs.ucsd.edu            sim_ticks = when
3355361Srstrong@cs.ucsd.edu            exit_cause = "maximum %d checkpoints dropped" % max_checkpoints
3365361Srstrong@cs.ucsd.edu            while num_checkpoints < max_checkpoints and \
3375361Srstrong@cs.ucsd.edu                    exit_event.getCause() == "simulate() limit reached":
3385361Srstrong@cs.ucsd.edu                if (sim_ticks + period) > maxtick:
3395361Srstrong@cs.ucsd.edu                    exit_event = m5.simulate(maxtick - sim_ticks)
3405361Srstrong@cs.ucsd.edu                    exit_cause = exit_event.getCause()
3415361Srstrong@cs.ucsd.edu                    break
3425361Srstrong@cs.ucsd.edu                else:
3435361Srstrong@cs.ucsd.edu                    exit_event = m5.simulate(period)
3445361Srstrong@cs.ucsd.edu                    sim_ticks += period
3455361Srstrong@cs.ucsd.edu                    while exit_event.getCause() == "checkpoint":
3465361Srstrong@cs.ucsd.edu                        exit_event = m5.simulate(sim_ticks - m5.curTick())
3475361Srstrong@cs.ucsd.edu                    if exit_event.getCause() == "simulate() limit reached":
3485361Srstrong@cs.ucsd.edu                        m5.checkpoint(root, joinpath(cptdir, "cpt.%d"))
3495361Srstrong@cs.ucsd.edu                        num_checkpoints += 1
3505361Srstrong@cs.ucsd.edu
3515361Srstrong@cs.ucsd.edu            if exit_event.getCause() != "simulate() limit reached":
3525361Srstrong@cs.ucsd.edu                exit_cause = exit_event.getCause();
3535361Srstrong@cs.ucsd.edu
3545361Srstrong@cs.ucsd.edu    else: # no checkpoints being taken via this script
3555361Srstrong@cs.ucsd.edu        if options.fast_forward:
3565361Srstrong@cs.ucsd.edu            m5.stats.reset()
3575361Srstrong@cs.ucsd.edu        print "**** REAL SIMULATION ****"
3583395Shsul@eecs.umich.edu        exit_event = m5.simulate(maxtick)
3593395Shsul@eecs.umich.edu
3603395Shsul@eecs.umich.edu        while exit_event.getCause() == "checkpoint":
3613509Shsul@eecs.umich.edu            m5.checkpoint(root, joinpath(cptdir, "cpt.%d"))
3623395Shsul@eecs.umich.edu            num_checkpoints += 1
3633395Shsul@eecs.umich.edu            if num_checkpoints == max_checkpoints:
3645361Srstrong@cs.ucsd.edu                exit_cause = "maximum %d checkpoints dropped" % max_checkpoints
3653395Shsul@eecs.umich.edu                break
3663395Shsul@eecs.umich.edu
3673511Shsul@eecs.umich.edu            exit_event = m5.simulate(maxtick - m5.curTick())
3683395Shsul@eecs.umich.edu            exit_cause = exit_event.getCause()
3693395Shsul@eecs.umich.edu
3703395Shsul@eecs.umich.edu    if exit_cause == '':
3713395Shsul@eecs.umich.edu        exit_cause = exit_event.getCause()
3723514Sktlim@umich.edu    print 'Exiting @ cycle %i because %s' % (m5.curTick(), exit_cause)
3733395Shsul@eecs.umich.edu
374