__init__.py (2781:b689ee340f27) __init__.py (2797:b5f26b4eacef)
1# Copyright (c) 2005 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) ---

29
30import sys, os, time, atexit, optparse
31
32# import the SWIG-wrapped main C++ functions
33import cc_main
34# import a few SWIG-wrapped items (those that are likely to be used
35# directly by user scripts) completely into this module for
36# convenience
1# Copyright (c) 2005 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) ---

29
30import sys, os, time, atexit, optparse
31
32# import the SWIG-wrapped main C++ functions
33import cc_main
34# import a few SWIG-wrapped items (those that are likely to be used
35# directly by user scripts) completely into this module for
36# convenience
37from cc_main import simulate, SimLoopExitEvent
37from cc_main import simulate, SimLoopExitEvent, setCheckpointDir
38
39# import the m5 compile options
40import defines
41
42# define this here so we can use it right away if necessary
43def panic(string):
44 print >>sys.stderr, 'panic:', string
45 sys.exit(1)

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

112 objects.Trace.dump_on_exit = True
113
114def debugBreak(option, opt_str, value, parser):
115 objects.Debug.break_cycles = value
116
117def statsTextFile(option, opt_str, value, parser):
118 objects.Statistics.text_file = value
119
38
39# import the m5 compile options
40import defines
41
42# define this here so we can use it right away if necessary
43def panic(string):
44 print >>sys.stderr, 'panic:', string
45 sys.exit(1)

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

112 objects.Trace.dump_on_exit = True
113
114def debugBreak(option, opt_str, value, parser):
115 objects.Debug.break_cycles = value
116
117def statsTextFile(option, opt_str, value, parser):
118 objects.Statistics.text_file = value
119
120# Extra list to help for options that are true or false
121TrueOrFalse = ['True', 'False']
122TorF = "True | False"
123
124# Standard optparse options. Need to be explicitly included by the
125# user script when it calls optparse.OptionParser().
126standardOptions = [
127 optparse.make_option("--outdir", type="string", default="."),
128 optparse.make_option("--traceflags", type="string", action="callback",
129 callback=setTraceFlags),
130 optparse.make_option("--tracestart", type="int", action="callback",
131 callback=setTraceStart),

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

211
212# register our C++ exit callback function with Python
213atexit.register(cc_main.doExitCleanup)
214
215# This import allows user scripts to reference 'm5.objects.Foo' after
216# just doing an 'import m5' (without an 'import m5.objects'). May not
217# matter since most scripts will probably 'from m5.objects import *'.
218import objects
120# Standard optparse options. Need to be explicitly included by the
121# user script when it calls optparse.OptionParser().
122standardOptions = [
123 optparse.make_option("--outdir", type="string", default="."),
124 optparse.make_option("--traceflags", type="string", action="callback",
125 callback=setTraceFlags),
126 optparse.make_option("--tracestart", type="int", action="callback",
127 callback=setTraceStart),

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

207
208# register our C++ exit callback function with Python
209atexit.register(cc_main.doExitCleanup)
210
211# This import allows user scripts to reference 'm5.objects.Foo' after
212# just doing an 'import m5' (without an 'import m5.objects'). May not
213# matter since most scripts will probably 'from m5.objects import *'.
214import objects
215
216def doQuiesce(root):
217 quiesce = cc_main.createCountedQuiesce()
218 unready_objects = root.startQuiesce(quiesce, True)
219 # If we've got some objects that can't quiesce immediately, then simulate
220 if unready_objects > 0:
221 quiesce.setCount(unready_objects)
222 simulate()
223 cc_main.cleanupCountedQuiesce(quiesce)
224
225def resume(root):
226 root.resume()
227
228def checkpoint(root):
229 if not isinstance(root, objects.Root):
230 raise TypeError, "Object is not a root object. Checkpoint must be called on a root object."
231 doQuiesce(root)
232 print "Writing checkpoint"
233 cc_main.serializeAll()
234 resume(root)
235
236def restoreCheckpoint(root):
237 print "Restoring from checkpoint"
238 cc_main.unserializeAll()
239
240def changeToAtomic(system):
241 if not isinstance(system, objects.Root) and not isinstance(system, System):
242 raise TypeError, "Object is not a root or system object. Checkpoint must be "
243 "called on a root object."
244 doQuiesce(system)
245 print "Changing memory mode to atomic"
246 system.changeTiming(cc_main.SimObject.Atomic)
247 resume(system)
248
249def changeToTiming(system):
250 if not isinstance(system, objects.Root) and not isinstance(system, System):
251 raise TypeError, "Object is not a root or system object. Checkpoint must be "
252 "called on a root object."
253 doQuiesce(system)
254 print "Changing memory mode to timing"
255 system.changeTiming(cc_main.SimObject.Timing)
256 resume(system)
257
258def switchCpus(cpuList):
259 if not isinstance(cpuList, list):
260 raise RuntimeError, "Must pass a list to this function"
261 for i in cpuList:
262 if not isinstance(i, tuple):
263 raise RuntimeError, "List must have tuples of (oldCPU,newCPU)"
264
265 [old_cpus, new_cpus] = zip(*cpuList)
266
267 for cpu in old_cpus:
268 if not isinstance(cpu, objects.BaseCPU):
269 raise TypeError, "%s is not of type BaseCPU", cpu
270 for cpu in new_cpus:
271 if not isinstance(cpu, objects.BaseCPU):
272 raise TypeError, "%s is not of type BaseCPU", cpu
273
274 # Quiesce all of the individual CPUs
275 quiesce = cc_main.createCountedQuiesce()
276 unready_cpus = 0
277 for old_cpu in old_cpus:
278 unready_cpus += old_cpu.startQuiesce(quiesce, False)
279 # If we've got some objects that can't quiesce immediately, then simulate
280 if unready_cpus > 0:
281 quiesce.setCount(unready_cpus)
282 simulate()
283 cc_main.cleanupCountedQuiesce(quiesce)
284 # Now all of the CPUs are ready to be switched out
285 for old_cpu in old_cpus:
286 old_cpu._ccObject.switchOut()
287 index = 0
288 print "Switching CPUs"
289 for new_cpu in new_cpus:
290 new_cpu.takeOverFrom(old_cpus[index])
291 new_cpu._ccObject.resume()
292 index += 1