fs.py revision 3314
13005Sstever@eecs.umich.edu# Copyright (c) 2006 The Regents of The University of Michigan
23005Sstever@eecs.umich.edu# All rights reserved.
33005Sstever@eecs.umich.edu#
43005Sstever@eecs.umich.edu# Redistribution and use in source and binary forms, with or without
53005Sstever@eecs.umich.edu# modification, are permitted provided that the following conditions are
63005Sstever@eecs.umich.edu# met: redistributions of source code must retain the above copyright
73005Sstever@eecs.umich.edu# notice, this list of conditions and the following disclaimer;
83005Sstever@eecs.umich.edu# redistributions in binary form must reproduce the above copyright
93005Sstever@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the
103005Sstever@eecs.umich.edu# documentation and/or other materials provided with the distribution;
113005Sstever@eecs.umich.edu# neither the name of the copyright holders nor the names of its
123005Sstever@eecs.umich.edu# contributors may be used to endorse or promote products derived from
133005Sstever@eecs.umich.edu# this software without specific prior written permission.
143005Sstever@eecs.umich.edu#
153005Sstever@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
163005Sstever@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
173005Sstever@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
183005Sstever@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
193005Sstever@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
203005Sstever@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
213005Sstever@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
223005Sstever@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
233005Sstever@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
243005Sstever@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
253005Sstever@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
263005Sstever@eecs.umich.edu#
273005Sstever@eecs.umich.edu# Authors: Ali Saidi
283005Sstever@eecs.umich.edu
292889SN/Aimport optparse, os, sys
302889SN/A
312710SN/Aimport m5
322710SN/Afrom m5.objects import *
332934SN/Am5.AddToPath('../common')
342934SN/Afrom FSConfig import *
352549SN/Afrom SysPaths import *
362995SN/Afrom Benchmarks import *
372549SN/A
383088Sstever@eecs.umich.eduif not m5.build_env['FULL_SYSTEM']:
393088Sstever@eecs.umich.edu    m5.panic("This script requires full-system mode (ALPHA_FS).")
403088Sstever@eecs.umich.edu
412889SN/Aparser = optparse.OptionParser()
422710SN/A
432917SN/Aparser.add_option("-d", "--detailed", action="store_true")
442710SN/Aparser.add_option("-t", "--timing", action="store_true")
453312Sstever@eecs.umich.eduparser.add_option("-n", "--num_cpus", type="int", default=1)
463314Sstever@eecs.umich.eduparser.add_option("--caches", action="store_true")
472917SN/Aparser.add_option("-m", "--maxtick", type="int")
482948SN/Aparser.add_option("--maxtime", type="float")
492995SN/Aparser.add_option("--dual", action="store_true",
502995SN/A                  help="Simulate two systems attached with an ethernet link")
512995SN/Aparser.add_option("-b", "--benchmark", action="store", type="string",
522995SN/A                  dest="benchmark",
532995SN/A                  help="Specify the benchmark to run. Available benchmarks: %s"\
543143Shsul@eecs.umich.edu                  % DefinedBenchmarks)
553025Ssaidi@eecs.umich.eduparser.add_option("--etherdump", action="store", type="string", dest="etherdump",
563143Shsul@eecs.umich.edu                  help="Specify the filename to dump a pcap capture of the" \
573143Shsul@eecs.umich.edu                  "ethernet traffic")
583143Shsul@eecs.umich.eduparser.add_option("--checkpoint_dir", action="store", type="string",
593143Shsul@eecs.umich.edu                  help="Place all checkpoints in this absolute directory")
603183Shsul@eecs.umich.eduparser.add_option("-c", "--checkpoint", action="store", type="int",
613183Shsul@eecs.umich.edu                  help="restore from checkpoint <N>")
622710SN/A
632710SN/A(options, args) = parser.parse_args()
642710SN/A
652710SN/Aif args:
662710SN/A    print "Error: script doesn't take any positional arguments"
672710SN/A    sys.exit(1)
682710SN/A
693314Sstever@eecs.umich.educlass MyCache(BaseCache):
703314Sstever@eecs.umich.edu    assoc = 2
713314Sstever@eecs.umich.edu    block_size = 64
723314Sstever@eecs.umich.edu    latency = 1
733314Sstever@eecs.umich.edu    mshrs = 10
743314Sstever@eecs.umich.edu    tgts_per_mshr = 5
753314Sstever@eecs.umich.edu
763304Sstever@eecs.umich.edu# client system CPU is always simple... note this is an assignment of
773304Sstever@eecs.umich.edu# a class, not an instance.
783304Sstever@eecs.umich.eduClientCPUClass = AtomicSimpleCPU
793304Sstever@eecs.umich.educlient_mem_mode = 'atomic'
803304Sstever@eecs.umich.edu
812934SN/Aif options.detailed:
823304Sstever@eecs.umich.edu    ServerCPUClass = DerivO3CPU
833304Sstever@eecs.umich.edu    server_mem_mode = 'timing'
842934SN/Aelif options.timing:
853304Sstever@eecs.umich.edu    ServerCPUClass = TimingSimpleCPU
863304Sstever@eecs.umich.edu    server_mem_mode = 'timing'
872934SN/Aelse:
883304Sstever@eecs.umich.edu    ServerCPUClass = AtomicSimpleCPU
893304Sstever@eecs.umich.edu    server_mem_mode = 'atomic'
902566SN/A
913304Sstever@eecs.umich.eduServerCPUClass.clock = '2GHz'
923304Sstever@eecs.umich.eduClientCPUClass.clock = '2GHz'
932995SN/A
942995SN/Aif options.benchmark:
953304Sstever@eecs.umich.edu    try:
963304Sstever@eecs.umich.edu        bm = Benchmarks[options.benchmark]
973304Sstever@eecs.umich.edu    except KeyError:
982995SN/A        print "Error benchmark %s has not been defined." % options.benchmark
992995SN/A        print "Valid benchmarks are: %s" % DefinedBenchmarks
1002995SN/A        sys.exit(1)
1012917SN/Aelse:
1022995SN/A    if options.dual:
1033304Sstever@eecs.umich.edu        bm = [SysConfig(), SysConfig()]
1042995SN/A    else:
1053304Sstever@eecs.umich.edu        bm = [SysConfig()]
1063304Sstever@eecs.umich.edu
1073304Sstever@eecs.umich.eduserver_sys = makeLinuxAlphaSystem(server_mem_mode, bm[0])
1083312Sstever@eecs.umich.edunp = options.num_cpus
1093312Sstever@eecs.umich.eduserver_sys.cpu = [ServerCPUClass(cpu_id=i) for i in xrange(np)]
1103312Sstever@eecs.umich.edufor i in xrange(np):
1113314Sstever@eecs.umich.edu    if options.caches:
1123314Sstever@eecs.umich.edu        server_sys.cpu[i].addPrivateSplitL1Caches(MyCache(size = '32kB'),
1133314Sstever@eecs.umich.edu                                                  MyCache(size = '64kB'))
1143312Sstever@eecs.umich.edu    server_sys.cpu[i].connectMemPorts(server_sys.membus)
1153312Sstever@eecs.umich.edu    server_sys.cpu[i].mem = server_sys.physmem
1163005Sstever@eecs.umich.edu
1173005Sstever@eecs.umich.eduif len(bm) == 2:
1183304Sstever@eecs.umich.edu    client_sys = makeLinuxAlphaSystem(client_mem_mode, bm[1])
1193304Sstever@eecs.umich.edu    client_sys.cpu = ClientCPUClass(cpu_id=0)
1203304Sstever@eecs.umich.edu    client_sys.cpu.connectMemPorts(client_sys.membus)
1213304Sstever@eecs.umich.edu    client_sys.cpu.mem = client_sys.physmem
1223304Sstever@eecs.umich.edu    root = makeDualRoot(server_sys, client_sys, options.etherdump)
1233005Sstever@eecs.umich.eduelif len(bm) == 1:
1243304Sstever@eecs.umich.edu    root = Root(clock = '1THz', system = server_sys)
1253005Sstever@eecs.umich.eduelse:
1263005Sstever@eecs.umich.edu    print "Error I don't know how to create more than 2 systems."
1273005Sstever@eecs.umich.edu    sys.exit(1)
1282566SN/A
1292710SN/Am5.instantiate(root)
1302710SN/A
1313183Shsul@eecs.umich.eduif options.checkpoint:
1323183Shsul@eecs.umich.edu    from os.path import isdir
1333183Shsul@eecs.umich.edu    from os import listdir, getcwd
1343183Shsul@eecs.umich.edu    import re
1353183Shsul@eecs.umich.edu    if options.checkpoint_dir:
1363183Shsul@eecs.umich.edu        cptdir = options.checkpoint_dir
1373183Shsul@eecs.umich.edu    else:
1383183Shsul@eecs.umich.edu        cptdir = getcwd()
1393183Shsul@eecs.umich.edu
1403183Shsul@eecs.umich.edu    if not isdir(cptdir):
1413183Shsul@eecs.umich.edu        m5.panic("checkpoint dir %s does not exist!" % cptdir)
1423183Shsul@eecs.umich.edu
1433183Shsul@eecs.umich.edu    dirs = listdir(cptdir)
1443183Shsul@eecs.umich.edu    expr = re.compile('cpt.([0-9]*)')
1453183Shsul@eecs.umich.edu    cpts = []
1463183Shsul@eecs.umich.edu    for dir in dirs:
1473183Shsul@eecs.umich.edu        match = expr.match(dir)
1483183Shsul@eecs.umich.edu        if match:
1493183Shsul@eecs.umich.edu            cpts.append(match.group(1))
1503183Shsul@eecs.umich.edu
1513183Shsul@eecs.umich.edu    if options.checkpoint > len(cpts):
1523183Shsul@eecs.umich.edu        m5.panic('Checkpoint %d not found' % options.checkpoint)
1533183Shsul@eecs.umich.edu
1543183Shsul@eecs.umich.edu    m5.restoreCheckpoint(root, "/".join([cptdir, "cpt.%s" % cpts[options.checkpoint - 1]]))
1553183Shsul@eecs.umich.edu
1562917SN/Aif options.maxtick:
1573046Sstever@eecs.umich.edu    maxtick = options.maxtick
1582948SN/Aelif options.maxtime:
1592948SN/A    simtime = int(options.maxtime * root.clock.value)
1602948SN/A    print "simulating for: ", simtime
1613046Sstever@eecs.umich.edu    maxtick = simtime
1622917SN/Aelse:
1633046Sstever@eecs.umich.edu    maxtick = -1
1643022Shsul@eecs.umich.edu
1653046Sstever@eecs.umich.eduexit_event = m5.simulate(maxtick)
1663022Shsul@eecs.umich.edu
1673022Shsul@eecs.umich.eduwhile exit_event.getCause() == "checkpoint":
1683143Shsul@eecs.umich.edu    if options.checkpoint_dir:
1693143Shsul@eecs.umich.edu        m5.checkpoint(root, "/".join([options.checkpoint_dir, "cpt.%d"]))
1703143Shsul@eecs.umich.edu    else:
1713143Shsul@eecs.umich.edu        m5.checkpoint(root, "cpt.%d")
1723143Shsul@eecs.umich.edu
1733133Shsul@eecs.umich.edu    if maxtick == -1:
1743133Shsul@eecs.umich.edu        exit_event = m5.simulate(maxtick)
1753133Shsul@eecs.umich.edu    else:
1763133Shsul@eecs.umich.edu        exit_event = m5.simulate(maxtick - m5.curTick())
1772710SN/A
1782740SN/Aprint 'Exiting @ cycle', m5.curTick(), 'because', exit_event.getCause()
179