fs.py (3314:1247da7b4d26) | fs.py (3322:bccece90053b) |
---|---|
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 --- 26 unchanged lines hidden (view full) --- 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 | 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 --- 26 unchanged lines hidden (view full) --- 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("-n", "--num_cpus", type="int", default=1) 46parser.add_option("--caches", action="store_true") 47parser.add_option("-m", "--maxtick", type="int") 48parser.add_option("--maxtime", type="float") | 43# Benchmark options |
49parser.add_option("--dual", action="store_true", 50 help="Simulate two systems attached with an ethernet link") 51parser.add_option("-b", "--benchmark", action="store", type="string", 52 dest="benchmark", 53 help="Specify the benchmark to run. Available benchmarks: %s"\ 54 % DefinedBenchmarks) | 44parser.add_option("--dual", action="store_true", 45 help="Simulate two systems attached with an ethernet link") 46parser.add_option("-b", "--benchmark", action="store", type="string", 47 dest="benchmark", 48 help="Specify the benchmark to run. Available benchmarks: %s"\ 49 % DefinedBenchmarks) |
50 51# system options 52parser.add_option("-d", "--detailed", action="store_true") 53parser.add_option("-t", "--timing", action="store_true") 54parser.add_option("-n", "--num_cpus", type="int", default=1) 55parser.add_option("--caches", action="store_true") 56 57# Run duration options 58parser.add_option("-m", "--maxtick", type="int") 59parser.add_option("--maxtime", type="float") 60 61# Metafile options |
|
55parser.add_option("--etherdump", action="store", type="string", dest="etherdump", 56 help="Specify the filename to dump a pcap capture of the" \ 57 "ethernet traffic") | 62parser.add_option("--etherdump", action="store", type="string", dest="etherdump", 63 help="Specify the filename to dump a pcap capture of the" \ 64 "ethernet traffic") |
65 66# Checkpointing options 67###Note that performing checkpointing via python script files will override 68###checkpoint instructions built into binaries. 69parser.add_option("--take_checkpoints", action="store", type="string", 70 help="<M,N> will take checkpoint at cycle M and every N cycles \ 71 thereafter") 72parser.add_option("--max_checkpoints", action="store", type="int", 73 help="the maximum number of checkpoints to drop", 74 default=5) |
|
58parser.add_option("--checkpoint_dir", action="store", type="string", 59 help="Place all checkpoints in this absolute directory") | 75parser.add_option("--checkpoint_dir", action="store", type="string", 76 help="Place all checkpoints in this absolute directory") |
60parser.add_option("-c", "--checkpoint", action="store", type="int", | 77parser.add_option("-r", "--checkpoint_restore", action="store", type="int", |
61 help="restore from checkpoint <N>") 62 | 78 help="restore from checkpoint <N>") 79 |
80# CPU Switching - default switch model goes from a checkpoint 81# to a timing simple CPU with caches to warm up, then to detailed CPU for 82# data measurement 83parser.add_option("-s", "--standard_switch", action="store_true", 84 help="switch from one cpu mode to another") 85 |
|
63(options, args) = parser.parse_args() 64 65if args: 66 print "Error: script doesn't take any positional arguments" 67 sys.exit(1) 68 69class MyCache(BaseCache): 70 assoc = 2 71 block_size = 64 72 latency = 1 73 mshrs = 10 74 tgts_per_mshr = 5 75 | 86(options, args) = parser.parse_args() 87 88if args: 89 print "Error: script doesn't take any positional arguments" 90 sys.exit(1) 91 92class MyCache(BaseCache): 93 assoc = 2 94 block_size = 64 95 latency = 1 96 mshrs = 10 97 tgts_per_mshr = 5 98 |
76# client system CPU is always simple... note this is an assignment of | 99# driver system CPU is always simple... note this is an assignment of |
77# a class, not an instance. | 100# a class, not an instance. |
78ClientCPUClass = AtomicSimpleCPU 79client_mem_mode = 'atomic' | 101DriveCPUClass = AtomicSimpleCPU 102drive_mem_mode = 'atomic' |
80 | 103 |
104# system under test can be any of these CPUs |
|
81if options.detailed: | 105if options.detailed: |
82 ServerCPUClass = DerivO3CPU 83 server_mem_mode = 'timing' | 106 TestCPUClass = DerivO3CPU 107 test_mem_mode = 'timing' |
84elif options.timing: | 108elif options.timing: |
85 ServerCPUClass = TimingSimpleCPU 86 server_mem_mode = 'timing' | 109 TestCPUClass = TimingSimpleCPU 110 test_mem_mode = 'timing' |
87else: | 111else: |
88 ServerCPUClass = AtomicSimpleCPU 89 server_mem_mode = 'atomic' | 112 TestCPUClass = AtomicSimpleCPU 113 test_mem_mode = 'atomic' |
90 | 114 |
91ServerCPUClass.clock = '2GHz' 92ClientCPUClass.clock = '2GHz' | 115TestCPUClass.clock = '2GHz' 116DriveCPUClass.clock = '2GHz' |
93 94if options.benchmark: 95 try: 96 bm = Benchmarks[options.benchmark] 97 except KeyError: 98 print "Error benchmark %s has not been defined." % options.benchmark 99 print "Valid benchmarks are: %s" % DefinedBenchmarks 100 sys.exit(1) 101else: 102 if options.dual: 103 bm = [SysConfig(), SysConfig()] 104 else: 105 bm = [SysConfig()] 106 | 117 118if options.benchmark: 119 try: 120 bm = Benchmarks[options.benchmark] 121 except KeyError: 122 print "Error benchmark %s has not been defined." % options.benchmark 123 print "Valid benchmarks are: %s" % DefinedBenchmarks 124 sys.exit(1) 125else: 126 if options.dual: 127 bm = [SysConfig(), SysConfig()] 128 else: 129 bm = [SysConfig()] 130 |
107server_sys = makeLinuxAlphaSystem(server_mem_mode, bm[0]) | 131test_sys = makeLinuxAlphaSystem(test_mem_mode, bm[0]) |
108np = options.num_cpus | 132np = options.num_cpus |
109server_sys.cpu = [ServerCPUClass(cpu_id=i) for i in xrange(np)] | 133test_sys.cpu = [TestCPUClass(cpu_id=i) for i in xrange(np)] |
110for i in xrange(np): | 134for i in xrange(np): |
111 if options.caches: 112 server_sys.cpu[i].addPrivateSplitL1Caches(MyCache(size = '32kB'), | 135 if options.caches and not options.standard_switch: 136 test_sys.cpu[i].addPrivateSplitL1Caches(MyCache(size = '32kB'), |
113 MyCache(size = '64kB')) | 137 MyCache(size = '64kB')) |
114 server_sys.cpu[i].connectMemPorts(server_sys.membus) 115 server_sys.cpu[i].mem = server_sys.physmem | 138 test_sys.cpu[i].connectMemPorts(test_sys.membus) 139 test_sys.cpu[i].mem = test_sys.physmem |
116 117if len(bm) == 2: | 140 141if len(bm) == 2: |
118 client_sys = makeLinuxAlphaSystem(client_mem_mode, bm[1]) 119 client_sys.cpu = ClientCPUClass(cpu_id=0) 120 client_sys.cpu.connectMemPorts(client_sys.membus) 121 client_sys.cpu.mem = client_sys.physmem 122 root = makeDualRoot(server_sys, client_sys, options.etherdump) | 142 drive_sys = makeLinuxAlphaSystem(drive_mem_mode, bm[1]) 143 drive_sys.cpu = DriveCPUClass(cpu_id=0) 144 drive_sys.cpu.connectMemPorts(drive_sys.membus) 145 drive_sys.cpu.mem = drive_sys.physmem 146 root = makeDualRoot(test_sys, drive_sys, options.etherdump) |
123elif len(bm) == 1: | 147elif len(bm) == 1: |
124 root = Root(clock = '1THz', system = server_sys) | 148 root = Root(clock = '1THz', system = test_sys) |
125else: 126 print "Error I don't know how to create more than 2 systems." 127 sys.exit(1) 128 | 149else: 150 print "Error I don't know how to create more than 2 systems." 151 sys.exit(1) 152 |
153if options.standard_switch: 154 switch_cpus = [TimingSimpleCPU(defer_registration=True, cpu_id=(np+i) for i in xrange(np))] 155 switch_cpus1 = [DerivO3CPU(defer_registration=True, cpu_id=(2*np+i) for i in xrange(np))] 156 for i in xrange(np): 157 switch_cpus[i].system = test_sys 158 switch_cpus1[i].system = test_sys 159 switch_cpus[i].clock = TestCPUClass.clock 160 switch_cpus1[i].clock = TestCPUClass.clock 161 if options.caches: 162 switch_cpus[i].addPrivateSplitL1Caches(MyCache(size = '32kB'), 163 MyCache(size = '64kB')) 164 165 switch_cpus[i].mem = test_sys.physmem 166 switch_cpus1[i].mem = test_sys.physmem 167 switch_cpus[i].connectMemPorts(test_sys.membus) 168 root.switch_cpus = switch_cpus 169 root.switch_cpus1 = switch_cpus1 170 switch_cpu_list = [(test_sys.cpu[i], switch_cpus[i]) for i in xrange(np)] 171 switch_cpu_list1 = [(switch_cpus[i], switch_cpus1[i]) for i in xrange(np)] 172 |
|
129m5.instantiate(root) 130 | 173m5.instantiate(root) 174 |
131if options.checkpoint: | 175if options.checkpoint_dir: 176 cptdir = options.checkpoint_dir 177else: 178 cptdir = getcwd() 179 180if options.checkpoint_restore: |
132 from os.path import isdir 133 from os import listdir, getcwd 134 import re | 181 from os.path import isdir 182 from os import listdir, getcwd 183 import re |
135 if options.checkpoint_dir: 136 cptdir = options.checkpoint_dir 137 else: 138 cptdir = getcwd() | |
139 140 if not isdir(cptdir): 141 m5.panic("checkpoint dir %s does not exist!" % cptdir) 142 143 dirs = listdir(cptdir) 144 expr = re.compile('cpt.([0-9]*)') 145 cpts = [] 146 for dir in dirs: 147 match = expr.match(dir) 148 if match: 149 cpts.append(match.group(1)) 150 | 184 185 if not isdir(cptdir): 186 m5.panic("checkpoint dir %s does not exist!" % cptdir) 187 188 dirs = listdir(cptdir) 189 expr = re.compile('cpt.([0-9]*)') 190 cpts = [] 191 for dir in dirs: 192 match = expr.match(dir) 193 if match: 194 cpts.append(match.group(1)) 195 |
151 if options.checkpoint > len(cpts): 152 m5.panic('Checkpoint %d not found' % options.checkpoint) | 196 cpts.sort(lambda a,b: cmp(long(a), long(b))) |
153 | 197 |
154 m5.restoreCheckpoint(root, "/".join([cptdir, "cpt.%s" % cpts[options.checkpoint - 1]])) | 198 if options.checkpoint_restore > len(cpts): 199 m5.panic('Checkpoint %d not found' % options.checkpoint_restore) |
155 | 200 |
201 m5.restoreCheckpoint(root, "/".join([cptdir, "cpt.%s" % cpts[options.checkpoint_restore - 1]])) 202 203if options.standard_switch: 204 exit_event = m5.simulate(1000) 205 ## when you change to Timing (or Atomic), you halt the system given 206 ## as argument. When you are finished with the system changes 207 ## (including switchCpus), you must resume the system manually. 208 ## You DON'T need to resume after just switching CPUs if you haven't 209 ## changed anything on the system level. 210 m5.changeToTiming(test_sys) 211 m5.switchCpus(switch_cpu_list) 212 m5.resume(test_sys) 213 214 exit_event = m5.simulate(300000000000) 215 m5.switchCpus(switch_cpu_list1) 216 |
|
156if options.maxtick: 157 maxtick = options.maxtick 158elif options.maxtime: 159 simtime = int(options.maxtime * root.clock.value) 160 print "simulating for: ", simtime 161 maxtick = simtime 162else: 163 maxtick = -1 164 | 217if options.maxtick: 218 maxtick = options.maxtick 219elif options.maxtime: 220 simtime = int(options.maxtime * root.clock.value) 221 print "simulating for: ", simtime 222 maxtick = simtime 223else: 224 maxtick = -1 225 |
165exit_event = m5.simulate(maxtick) | 226num_checkpoints = 0 |
166 | 227 |
167while exit_event.getCause() == "checkpoint": 168 if options.checkpoint_dir: 169 m5.checkpoint(root, "/".join([options.checkpoint_dir, "cpt.%d"])) 170 else: 171 m5.checkpoint(root, "cpt.%d") | 228exit_cause = '' |
172 | 229 |
173 if maxtick == -1: 174 exit_event = m5.simulate(maxtick) 175 else: 176 exit_event = m5.simulate(maxtick - m5.curTick()) | 230if options.take_checkpoints: 231 [when, period] = options.take_checkpoints.split(",", 1) 232 when = int(when) 233 period = int(period) |
177 | 234 |
178print 'Exiting @ cycle', m5.curTick(), 'because', exit_event.getCause() | 235 exit_event = m5.simulate(when) 236 while exit_event.getCause() == "checkpoint": 237 exit_event = m5.simulate(when - m5.curTick()) 238 239 if exit_event.getCause() == "simulate() limit reached": 240 m5.checkpoint(root, cptdir + "cpt.%d") 241 num_checkpoints += 1 242 243 sim_ticks = when 244 exit_cause = "maximum %d checkpoints dropped" % options.max_checkpoints 245 while num_checkpoints < options.max_checkpoints: 246 if (sim_ticks + period) > maxtick and maxtick != -1: 247 exit_event = m5.simulate(maxtick - sim_ticks) 248 exit_cause = exit_event.getCause() 249 break 250 else: 251 exit_event = m5.simulate(period) 252 sim_ticks += period 253 while exit_event.getCause() == "checkpoint": 254 exit_event = m5.simulate(period - m5.curTick()) 255 if exit_event.getCause() == "simulate() limit reached": 256 m5.checkpoint(root, cptdir + "cpt.%d") 257 num_checkpoints += 1 258 259else: #no checkpoints being taken via this script 260 exit_event = m5.simulate(maxtick) 261 262 while exit_event.getCause() == "checkpoint": 263 m5.checkpoint(root, cptdir + "cpt.%d") 264 num_checkpoints += 1 265 if num_checkpoints == options.max_checkpoints: 266 exit_cause = "maximum %d checkpoints dropped" % options.max_checkpoints 267 break 268 269 if maxtick == -1: 270 exit_event = m5.simulate(maxtick) 271 else: 272 exit_event = m5.simulate(maxtick - m5.curTick()) 273 274 exit_cause = exit_event.getCause() 275 276if exit_cause == '': 277 exit_cause = exit_event.getCause() 278print 'Exiting @ cycle', m5.curTick(), 'because ', exit_cause |