1# Copyright (c) 2006 The Regents of The University of Michigan 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are 6# met: redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer; 8# redistributions in binary form must reproduce the above copyright 9# notice, this list of conditions and the following disclaimer in the 10# documentation and/or other materials provided with the distribution; 11# neither the name of the copyright holders nor the names of its 12# contributors may be used to endorse or promote products derived from 13# this software without specific prior written permission. 14# 15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26# 27# Authors: Ali Saidi 28 29import optparse, os, sys 30 31import m5 32from m5.objects import * 33m5.AddToPath('../common') 34from FSConfig import * 35from SysPaths import * 36from Benchmarks import * 37 38if not m5.build_env['FULL_SYSTEM']: 39 m5.panic("This script requires full-system mode (ALPHA_FS).") 40 41parser = optparse.OptionParser() 42 43parser.add_option("-d", "--detailed", action="store_true") 44parser.add_option("-t", "--timing", action="store_true") 45parser.add_option("-m", "--maxtick", type="int") 46parser.add_option("--maxtime", type="float") 47parser.add_option("--dual", action="store_true", 48 help="Simulate two systems attached with an ethernet link") 49parser.add_option("-b", "--benchmark", action="store", type="string", 50 dest="benchmark", 51 help="Specify the benchmark to run. Available benchmarks: %s"\ 52 % DefinedBenchmarks) 53parser.add_option("--etherdump", action="store", type="string", dest="etherdump", 54 help="Specify the filename to dump a pcap capture of the" \ 55 "ethernet traffic") 56parser.add_option("--checkpoint_dir", action="store", type="string", 57 help="Place all checkpoints in this absolute directory") 58parser.add_option("-c", "--checkpoint", action="store", type="int", 59 help="restore from checkpoint <N>") 60 61(options, args) = parser.parse_args() 62 63if args: 64 print "Error: script doesn't take any positional arguments" 65 sys.exit(1) 66
|
67# client system CPU is always simple... note this is an assignment of 68# a class, not an instance. 69ClientCPUClass = AtomicSimpleCPU 70client_mem_mode = 'atomic' 71 |
72if options.detailed:
|
68 cpu = DerivO3CPU()
69 cpu2 = DerivO3CPU()
70 mem_mode = 'timing'
|
73 ServerCPUClass = DerivO3CPU 74 server_mem_mode = 'timing' |
75elif options.timing:
|
72 cpu = TimingSimpleCPU()
73 cpu2 = TimingSimpleCPU()
74 mem_mode = 'timing'
|
76 ServerCPUClass = TimingSimpleCPU 77 server_mem_mode = 'timing' |
78else:
|
76 cpu = AtomicSimpleCPU()
77 cpu2 = AtomicSimpleCPU()
78 mem_mode = 'atomic'
|
79 ServerCPUClass = AtomicSimpleCPU 80 server_mem_mode = 'atomic' |
81
|
80cpu.clock = '2GHz'
81cpu2.clock = '2GHz'
82cpu.cpu_id = 0
83cpu2.cpu_id = 0
|
82ServerCPUClass.clock = '2GHz' 83ClientCPUClass.clock = '2GHz' |
84 85if options.benchmark:
|
86 if options.benchmark not in Benchmarks:
|
86 try: 87 bm = Benchmarks[options.benchmark] 88 except KeyError: |
89 print "Error benchmark %s has not been defined." % options.benchmark 90 print "Valid benchmarks are: %s" % DefinedBenchmarks 91 sys.exit(1)
|
90
91 bm = Benchmarks[options.benchmark]
|
92else: 93 if options.dual:
|
94 bm = [Machine(), Machine()]
|
94 bm = [SysConfig(), SysConfig()] |
95 else:
|
96 bm = [Machine()]
|
96 bm = [SysConfig()] |
97
|
98server_sys = makeLinuxAlphaSystem(server_mem_mode, bm[0]) 99server_sys.cpu = ServerCPUClass(cpu_id=0) 100server_sys.cpu.connectMemPorts(server_sys.membus) 101server_sys.cpu.mem = server_sys.physmem 102 |
103if len(bm) == 2:
|
99 s1 = makeLinuxAlphaSystem(mem_mode, bm[0])
100 s1.cpu = cpu
101 cpu.connectMemPorts(s1.membus)
102 cpu.mem = s1.physmem
103 s2 = makeLinuxAlphaSystem(mem_mode, bm[1])
104 s2.cpu = cpu2
105 cpu2.connectMemPorts(s2.membus)
106 cpu2.mem = s2.physmem
107 root = makeDualRoot(s1, s2, options.etherdump)
|
104 client_sys = makeLinuxAlphaSystem(client_mem_mode, bm[1]) 105 client_sys.cpu = ClientCPUClass(cpu_id=0) 106 client_sys.cpu.connectMemPorts(client_sys.membus) 107 client_sys.cpu.mem = client_sys.physmem 108 root = makeDualRoot(server_sys, client_sys, options.etherdump) |
109elif len(bm) == 1:
|
109 root = Root(clock = '1THz',
110 system = makeLinuxAlphaSystem(mem_mode, bm[0]))
111 root.system.cpu = cpu
112 cpu.connectMemPorts(root.system.membus)
113 cpu.mem = root.system.physmem
|
110 root = Root(clock = '1THz', system = server_sys) |
111else: 112 print "Error I don't know how to create more than 2 systems." 113 sys.exit(1) 114 115m5.instantiate(root) 116 117if options.checkpoint: 118 from os.path import isdir 119 from os import listdir, getcwd 120 import re 121 if options.checkpoint_dir: 122 cptdir = options.checkpoint_dir 123 else: 124 cptdir = getcwd() 125 126 if not isdir(cptdir): 127 m5.panic("checkpoint dir %s does not exist!" % cptdir) 128 129 dirs = listdir(cptdir) 130 expr = re.compile('cpt.([0-9]*)') 131 cpts = [] 132 for dir in dirs: 133 match = expr.match(dir) 134 if match: 135 cpts.append(match.group(1)) 136 137 if options.checkpoint > len(cpts): 138 m5.panic('Checkpoint %d not found' % options.checkpoint) 139 140 m5.restoreCheckpoint(root, "/".join([cptdir, "cpt.%s" % cpts[options.checkpoint - 1]])) 141 142if options.maxtick: 143 maxtick = options.maxtick 144elif options.maxtime: 145 simtime = int(options.maxtime * root.clock.value) 146 print "simulating for: ", simtime 147 maxtick = simtime 148else: 149 maxtick = -1 150 151exit_event = m5.simulate(maxtick) 152 153while exit_event.getCause() == "checkpoint": 154 if options.checkpoint_dir: 155 m5.checkpoint(root, "/".join([options.checkpoint_dir, "cpt.%d"])) 156 else: 157 m5.checkpoint(root, "cpt.%d") 158 159 if maxtick == -1: 160 exit_event = m5.simulate(maxtick) 161 else: 162 exit_event = m5.simulate(maxtick - m5.curTick()) 163 164print 'Exiting @ cycle', m5.curTick(), 'because', exit_event.getCause()
|