fs.py (3402:db60546818d0) fs.py (3409:769707cf0664)
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

--- 20 unchanged lines hidden (view full) ---

29import optparse, os, sys
30
31import m5
32from m5.objects import *
33m5.AddToPath('../common')
34from FSConfig import *
35from SysPaths import *
36from Benchmarks import *
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

--- 20 unchanged lines hidden (view full) ---

29import optparse, os, sys
30
31import m5
32from m5.objects import *
33m5.AddToPath('../common')
34from FSConfig import *
35from SysPaths import *
36from Benchmarks import *
37import Simulation
37
38if not m5.build_env['FULL_SYSTEM']:
39 m5.panic("This script requires full-system mode (ALPHA_FS).")
40
41parser = optparse.OptionParser()
42
43# Benchmark options
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
38
39if not m5.build_env['FULL_SYSTEM']:
40 m5.panic("This script requires full-system mode (ALPHA_FS).")
41
42parser = optparse.OptionParser()
43
44# Benchmark options
45parser.add_option("--dual", action="store_true",
46 help="Simulate two systems attached with an ethernet link")
47parser.add_option("-b", "--benchmark", action="store", type="string",
48 dest="benchmark",
49 help="Specify the benchmark to run. Available benchmarks: %s"\
50 % DefinedBenchmarks)
51
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
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
52# Metafile options
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")
56
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)
75parser.add_option("--checkpoint_dir", action="store", type="string",
76 help="Place all checkpoints in this absolute directory")
77parser.add_option("-r", "--checkpoint_restore", action="store", type="int",
78 help="restore from checkpoint <N>")
79
57
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")
58execfile("Options.py")
85
86(options, args) = parser.parse_args()
87
88if args:
89 print "Error: script doesn't take any positional arguments"
90 sys.exit(1)
91
59
60(options, args) = parser.parse_args()
61
62if args:
63 print "Error: script doesn't take any positional arguments"
64 sys.exit(1)
65
92class MyCache(BaseCache):
93 assoc = 2
94 block_size = 64
95 latency = 1
96 mshrs = 10
97 tgts_per_mshr = 5
98 protocol = CoherenceProtocol(protocol='moesi')
99
100# driver system CPU is always simple... note this is an assignment of
101# a class, not an instance.
102DriveCPUClass = AtomicSimpleCPU
103drive_mem_mode = 'atomic'
104
105# system under test can be any of these CPUs
106if options.detailed:
107 TestCPUClass = DerivO3CPU

--- 21 unchanged lines hidden (view full) ---

129 else:
130 bm = [SysConfig()]
131
132test_sys = makeLinuxAlphaSystem(test_mem_mode, bm[0])
133np = options.num_cpus
134test_sys.cpu = [TestCPUClass(cpu_id=i) for i in xrange(np)]
135for i in xrange(np):
136 if options.caches and not options.standard_switch:
66# driver system CPU is always simple... note this is an assignment of
67# a class, not an instance.
68DriveCPUClass = AtomicSimpleCPU
69drive_mem_mode = 'atomic'
70
71# system under test can be any of these CPUs
72if options.detailed:
73 TestCPUClass = DerivO3CPU

--- 21 unchanged lines hidden (view full) ---

95 else:
96 bm = [SysConfig()]
97
98test_sys = makeLinuxAlphaSystem(test_mem_mode, bm[0])
99np = options.num_cpus
100test_sys.cpu = [TestCPUClass(cpu_id=i) for i in xrange(np)]
101for i in xrange(np):
102 if options.caches and not options.standard_switch:
137 test_sys.cpu[i].addPrivateSplitL1Caches(MyCache(size = '32kB'),
138 MyCache(size = '64kB'))
103 test_sys.cpu[i].addPrivateSplitL1Caches(L1Cache(size = '32kB'),
104 L2Cache(size = '64kB'))
139 test_sys.cpu[i].connectMemPorts(test_sys.membus)
105 test_sys.cpu[i].connectMemPorts(test_sys.membus)
106 test_sys.cpu[i].mem = test_sys.physmem
140
141if len(bm) == 2:
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)
107
108if len(bm) == 2:
109 drive_sys = makeLinuxAlphaSystem(drive_mem_mode, bm[1])
110 drive_sys.cpu = DriveCPUClass(cpu_id=0)
111 drive_sys.cpu.connectMemPorts(drive_sys.membus)
112 drive_sys.cpu.mem = drive_sys.physmem
145 root = makeDualRoot(test_sys, drive_sys, options.etherdump)
146elif len(bm) == 1:
147 root = Root(clock = '1THz', system = test_sys)
148else:
149 print "Error I don't know how to create more than 2 systems."
150 sys.exit(1)
151
113 root = makeDualRoot(test_sys, drive_sys, options.etherdump)
114elif len(bm) == 1:
115 root = Root(clock = '1THz', system = test_sys)
116else:
117 print "Error I don't know how to create more than 2 systems."
118 sys.exit(1)
119
152if options.standard_switch:
153 switch_cpus = [TimingSimpleCPU(defer_registration=True, cpu_id=(np+i)) for i in xrange(np)]
154 switch_cpus1 = [DerivO3CPU(defer_registration=True, cpu_id=(2*np+i)) for i in xrange(np)]
155 for i in xrange(np):
156 switch_cpus[i].system = test_sys
157 switch_cpus1[i].system = test_sys
158 switch_cpus[i].clock = TestCPUClass.clock
159 switch_cpus1[i].clock = TestCPUClass.clock
160 if options.caches:
161 switch_cpus[i].addPrivateSplitL1Caches(MyCache(size = '32kB'),
162 MyCache(size = '64kB'))
163
164 switch_cpus[i].connectMemPorts(test_sys.membus)
165 root.switch_cpus = switch_cpus
166 root.switch_cpus1 = switch_cpus1
167 switch_cpu_list = [(test_sys.cpu[i], switch_cpus[i]) for i in xrange(np)]
168 switch_cpu_list1 = [(switch_cpus[i], switch_cpus1[i]) for i in xrange(np)]
169
170m5.instantiate(root)
171
172if options.checkpoint_dir:
173 cptdir = options.checkpoint_dir
174else:
175 cptdir = os.getcwd()
176
177if options.checkpoint_restore:
178 from os.path import isdir
179 from os import listdir, getcwd
180 import re
181
182 if not isdir(cptdir):
183 m5.panic("checkpoint dir %s does not exist!" % cptdir)
184
185 dirs = listdir(cptdir)
186 expr = re.compile('cpt.([0-9]*)')
187 cpts = []
188 for dir in dirs:
189 match = expr.match(dir)
190 if match:
191 cpts.append(match.group(1))
192
193 cpts.sort(lambda a,b: cmp(long(a), long(b)))
194
195 if options.checkpoint_restore > len(cpts):
196 m5.panic('Checkpoint %d not found' % options.checkpoint_restore)
197
198 m5.restoreCheckpoint(root, "/".join([cptdir, "cpt.%s" % cpts[options.checkpoint_restore - 1]]))
199
200if options.standard_switch:
201 exit_event = m5.simulate(1000)
202 ## when you change to Timing (or Atomic), you halt the system given
203 ## as argument. When you are finished with the system changes
204 ## (including switchCpus), you must resume the system manually.
205 ## You DON'T need to resume after just switching CPUs if you haven't
206 ## changed anything on the system level.
207 m5.changeToTiming(test_sys)
208 m5.switchCpus(switch_cpu_list)
209 m5.resume(test_sys)
210
211 exit_event = m5.simulate(500000000000)
212 m5.switchCpus(switch_cpu_list1)
213
214if options.maxtick:
215 maxtick = options.maxtick
216elif options.maxtime:
217 simtime = int(options.maxtime * root.clock.value)
218 print "simulating for: ", simtime
219 maxtick = simtime
220else:
221 maxtick = -1
222
223num_checkpoints = 0
224
225exit_cause = ''
226
227if options.take_checkpoints:
228 [when, period] = options.take_checkpoints.split(",", 1)
229 when = int(when)
230 period = int(period)
231
232 exit_event = m5.simulate(when)
233 while exit_event.getCause() == "checkpoint":
234 exit_event = m5.simulate(when - m5.curTick())
235
236 if exit_event.getCause() == "simulate() limit reached":
237 m5.checkpoint(root, cptdir + "cpt.%d")
238 num_checkpoints += 1
239
240 sim_ticks = when
241 exit_cause = "maximum %d checkpoints dropped" % options.max_checkpoints
242 while num_checkpoints < options.max_checkpoints:
243 if (sim_ticks + period) > maxtick and maxtick != -1:
244 exit_event = m5.simulate(maxtick - sim_ticks)
245 exit_cause = exit_event.getCause()
246 break
247 else:
248 exit_event = m5.simulate(period)
249 sim_ticks += period
250 while exit_event.getCause() == "checkpoint":
251 exit_event = m5.simulate(period - m5.curTick())
252 if exit_event.getCause() == "simulate() limit reached":
253 m5.checkpoint(root, cptdir + "cpt.%d")
254 num_checkpoints += 1
255
256else: #no checkpoints being taken via this script
257 exit_event = m5.simulate(maxtick)
258
259 while exit_event.getCause() == "checkpoint":
260 m5.checkpoint(root, cptdir + "cpt.%d")
261 num_checkpoints += 1
262 if num_checkpoints == options.max_checkpoints:
263 exit_cause = "maximum %d checkpoints dropped" % options.max_checkpoints
264 break
265
266 if maxtick == -1:
267 exit_event = m5.simulate(maxtick)
268 else:
269 exit_event = m5.simulate(maxtick - m5.curTick())
270
271 exit_cause = exit_event.getCause()
272
273if exit_cause == '':
274 exit_cause = exit_event.getCause()
275print 'Exiting @ cycle', m5.curTick(), 'because ', exit_cause
120Simulation.run(options, root, test_sys)