fs.py revision 3183
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") 452917SN/Aparser.add_option("-m", "--maxtick", type="int") 462948SN/Aparser.add_option("--maxtime", type="float") 472995SN/Aparser.add_option("--dual", action="store_true", 482995SN/A help="Simulate two systems attached with an ethernet link") 492995SN/Aparser.add_option("-b", "--benchmark", action="store", type="string", 502995SN/A dest="benchmark", 512995SN/A help="Specify the benchmark to run. Available benchmarks: %s"\ 523143Shsul@eecs.umich.edu % DefinedBenchmarks) 533025Ssaidi@eecs.umich.eduparser.add_option("--etherdump", action="store", type="string", dest="etherdump", 543143Shsul@eecs.umich.edu help="Specify the filename to dump a pcap capture of the" \ 553143Shsul@eecs.umich.edu "ethernet traffic") 563143Shsul@eecs.umich.eduparser.add_option("--checkpoint_dir", action="store", type="string", 573143Shsul@eecs.umich.edu help="Place all checkpoints in this absolute directory") 583183Shsul@eecs.umich.eduparser.add_option("-c", "--checkpoint", action="store", type="int", 593183Shsul@eecs.umich.edu help="restore from checkpoint <N>") 602710SN/A 612710SN/A(options, args) = parser.parse_args() 622710SN/A 632710SN/Aif args: 642710SN/A print "Error: script doesn't take any positional arguments" 652710SN/A sys.exit(1) 662710SN/A 672934SN/Aif options.detailed: 682934SN/A cpu = DetailedO3CPU() 692934SN/A cpu2 = DetailedO3CPU() 702953SN/A mem_mode = 'timing' 712934SN/Aelif options.timing: 722934SN/A cpu = TimingSimpleCPU() 732934SN/A cpu2 = TimingSimpleCPU() 742953SN/A mem_mode = 'timing' 752934SN/Aelse: 762934SN/A cpu = AtomicSimpleCPU() 772934SN/A cpu2 = AtomicSimpleCPU() 782953SN/A mem_mode = 'atomic' 792566SN/A 803005Sstever@eecs.umich.educpu.clock = '2GHz' 813005Sstever@eecs.umich.educpu2.clock = '2GHz' 823180Sstever@eecs.umich.educpu.cpu_id = 0 833180Sstever@eecs.umich.educpu2.cpu_id = 0 842995SN/A 852995SN/Aif options.benchmark: 862995SN/A if options.benchmark not in Benchmarks: 872995SN/A print "Error benchmark %s has not been defined." % options.benchmark 882995SN/A print "Valid benchmarks are: %s" % DefinedBenchmarks 892995SN/A sys.exit(1) 902995SN/A 912995SN/A bm = Benchmarks[options.benchmark] 922917SN/Aelse: 932995SN/A if options.dual: 943005Sstever@eecs.umich.edu bm = [Machine(), Machine()] 952995SN/A else: 963005Sstever@eecs.umich.edu bm = [Machine()] 973005Sstever@eecs.umich.edu 983005Sstever@eecs.umich.eduif len(bm) == 2: 993005Sstever@eecs.umich.edu s1 = makeLinuxAlphaSystem(mem_mode, bm[0]) 1003005Sstever@eecs.umich.edu s1.cpu = cpu 1013005Sstever@eecs.umich.edu cpu.connectMemPorts(s1.membus) 1023050Sstever@eecs.umich.edu cpu.mem = s1.physmem 1033005Sstever@eecs.umich.edu s2 = makeLinuxAlphaSystem(mem_mode, bm[1]) 1043005Sstever@eecs.umich.edu s2.cpu = cpu2 1053005Sstever@eecs.umich.edu cpu2.connectMemPorts(s2.membus) 1063050Sstever@eecs.umich.edu cpu2.mem = s2.physmem 1073025Ssaidi@eecs.umich.edu root = makeDualRoot(s1, s2, options.etherdump) 1083005Sstever@eecs.umich.eduelif len(bm) == 1: 1093005Sstever@eecs.umich.edu root = Root(clock = '1THz', 1103005Sstever@eecs.umich.edu system = makeLinuxAlphaSystem(mem_mode, bm[0])) 1113005Sstever@eecs.umich.edu root.system.cpu = cpu 1123005Sstever@eecs.umich.edu cpu.connectMemPorts(root.system.membus) 1133050Sstever@eecs.umich.edu cpu.mem = root.system.physmem 1143005Sstever@eecs.umich.eduelse: 1153005Sstever@eecs.umich.edu print "Error I don't know how to create more than 2 systems." 1163005Sstever@eecs.umich.edu sys.exit(1) 1172566SN/A 1182710SN/Am5.instantiate(root) 1192710SN/A 1203183Shsul@eecs.umich.eduif options.checkpoint: 1213183Shsul@eecs.umich.edu from os.path import isdir 1223183Shsul@eecs.umich.edu from os import listdir, getcwd 1233183Shsul@eecs.umich.edu import re 1243183Shsul@eecs.umich.edu if options.checkpoint_dir: 1253183Shsul@eecs.umich.edu cptdir = options.checkpoint_dir 1263183Shsul@eecs.umich.edu else: 1273183Shsul@eecs.umich.edu cptdir = getcwd() 1283183Shsul@eecs.umich.edu 1293183Shsul@eecs.umich.edu if not isdir(cptdir): 1303183Shsul@eecs.umich.edu m5.panic("checkpoint dir %s does not exist!" % cptdir) 1313183Shsul@eecs.umich.edu 1323183Shsul@eecs.umich.edu dirs = listdir(cptdir) 1333183Shsul@eecs.umich.edu expr = re.compile('cpt.([0-9]*)') 1343183Shsul@eecs.umich.edu cpts = [] 1353183Shsul@eecs.umich.edu for dir in dirs: 1363183Shsul@eecs.umich.edu match = expr.match(dir) 1373183Shsul@eecs.umich.edu if match: 1383183Shsul@eecs.umich.edu cpts.append(match.group(1)) 1393183Shsul@eecs.umich.edu 1403183Shsul@eecs.umich.edu if options.checkpoint > len(cpts): 1413183Shsul@eecs.umich.edu m5.panic('Checkpoint %d not found' % options.checkpoint) 1423183Shsul@eecs.umich.edu 1433183Shsul@eecs.umich.edu m5.restoreCheckpoint(root, "/".join([cptdir, "cpt.%s" % cpts[options.checkpoint - 1]])) 1443183Shsul@eecs.umich.edu 1452917SN/Aif options.maxtick: 1463046Sstever@eecs.umich.edu maxtick = options.maxtick 1472948SN/Aelif options.maxtime: 1482948SN/A simtime = int(options.maxtime * root.clock.value) 1492948SN/A print "simulating for: ", simtime 1503046Sstever@eecs.umich.edu maxtick = simtime 1512917SN/Aelse: 1523046Sstever@eecs.umich.edu maxtick = -1 1533022Shsul@eecs.umich.edu 1543046Sstever@eecs.umich.eduexit_event = m5.simulate(maxtick) 1553022Shsul@eecs.umich.edu 1563022Shsul@eecs.umich.eduwhile exit_event.getCause() == "checkpoint": 1573143Shsul@eecs.umich.edu if options.checkpoint_dir: 1583143Shsul@eecs.umich.edu m5.checkpoint(root, "/".join([options.checkpoint_dir, "cpt.%d"])) 1593143Shsul@eecs.umich.edu else: 1603143Shsul@eecs.umich.edu m5.checkpoint(root, "cpt.%d") 1613143Shsul@eecs.umich.edu 1623133Shsul@eecs.umich.edu if maxtick == -1: 1633133Shsul@eecs.umich.edu exit_event = m5.simulate(maxtick) 1643133Shsul@eecs.umich.edu else: 1653133Shsul@eecs.umich.edu exit_event = m5.simulate(maxtick - m5.curTick()) 1662710SN/A 1672740SN/Aprint 'Exiting @ cycle', m5.curTick(), 'because', exit_event.getCause() 168